diff --git a/TODO b/TODO index 10f1db0..1fb4f90 100755 --- a/TODO +++ b/TODO @@ -3,7 +3,7 @@ * tokens + ban system * remember me * Display names -* htmlspecialchars +* htmlspecialchars => on users objects install.php : ============= diff --git a/data/notice b/data/notice new file mode 100755 index 0000000..e69de29 diff --git a/inc/Storage.class.php b/inc/Storage.class.php index 1539e59..ae5e598 100644 --- a/inc/Storage.class.php +++ b/inc/Storage.class.php @@ -1,5 +1,5 @@ assign('instance_title', htmlspecialchars(INSTANCE_TITLE)); $tpl->assign('connection', false); - $tpl->assign('notice', ''); + $tpl->assign('notice', nl2br(getNotice())); $tpl->assign('error', ''); + $tpl->assign('base_url', htmlspecialchars(BASE_URL)); + $tpl->assign('currency', htmlspecialchars(CURRENCY)); // Handle current user status session_start(); @@ -42,8 +45,10 @@ header('location: index.php'); } if(!empty($_POST['login']) && !empty($_POST['password'])) { - if($current_user->exists($_POST['login']) && $current_user->checkPassword($_POST['password'])) { - $_SESSION['current_user'] = $current_user->sessionStore(); + $user = new User(); + $user->setLogin($_POST['login']); + if($user->exists($_POST['login']) && $user->checkPassword($_POST['password'])) { + $_SESSION['current_user'] = $user->sessionStore(); header('location: index.php'); exit(); } @@ -109,7 +114,7 @@ $user->load_user(array('id'=>$user_id)); $tpl->assign('user_data', $user); } - $tpl->assign('user_id', (!empty($user_id) ? $user_id : -1)); + $tpl->assign('user_id', (!empty($user_id) ? (int) $user_id : -1)); $tpl->assign('view', 'edit_user'); } else { @@ -135,6 +140,62 @@ } break; + case 'edit_notice': + if(isset($_POST['notice'])) { + setNotice($_POST['notice']); + + header('location: index.php'); + exit(); + } + + $tpl->assign('notice', getNotice()); + $tpl->assign('show_settings', false); + $tpl->draw('settings'); + break; + + case 'settings': + if(!empty($_POST['mysql_host']) && !empty($_POST['mysql_login']) && !empty($_POST['mysql_db']) && !empty($_POST['currency']) && !empty($_POST['instance_title']) && !empty($_POST['base_url'])) { + if(!is_writable('data/')) { + $tpl>assign('error', 'The script can\'t write in data/ dir, check permissions set on this folder.'); + } + $config = file('data/config.php'); + + foreach($config as $line_number=>$line) { + if(strpos($line, "MYSQL_HOST") !== FALSE) + $config[$line_number] = "\tdefine('".$_POST['mysql_host']."');\n"; + elseif(strpos($line, "MYSQL_LOGIN") !== FALSE) + $config[$line_number] = "\tdefine('".$_POST['mysql_login']."');\n"; + elseif(strpos($line, "MYSQL_PASSWORD") !== FALSE && !empty($_POST['mysql_password'])) + $config[$line_number] = "\tdefine('".$_POST['mysql_password']."');\n"; + elseif(strpos($line, "MYSQL_DB") !== FALSE) + $config[$line_number] = "\tdefine('".$_POST['mysql_db']."');\n"; + elseif(strpos($line, "MYSQL_PREFIX") !== FALSE && !empty($_POST['mysql_prefix'])) + $config[$line_number] = "\tdefine('".$_POST['mysql_prefix']."');\n"; + elseif(strpos($line, "INSTANCE_TITLE") !== FALSE) + $config[$line_number] = "\tdefine('".$_POST['instance_title']."');\n"; + elseif(strpos($line, "BASE_URL") !== FALSE) + $config[$line_number] = "\tdefine('".$_POST['base_url']."');\n"; + elseif(strpos($line, "CURRENCY") !== FALSE) + $config[$line_number] = "\tdefine('".$_POST['currency']."');\n"; + } + + if(file_put_contents("data/config.php", $config)) { + header('location: index.php'); + exit(); + } + else { + $tpl->assign('error', 'Unable to write data/config.php file.'); + } + } + + $tpl->assign('mysql_host', MYSQL_HOST); + $tpl->assign('mysql_login', MYSQL_LOGIN); + $tpl->assign('mysql_db', MYSQL_DB); + $tpl->assign('mysql_prefix', MYSQL_PREFIX); + $tpl->assign('show_settings', true); + $tpl->draw('settings'); + break; + default: $users_list = new User(); $users_list = $users_list->load_users(); diff --git a/install.php b/install.php index 0eed6fb..ce8e61a 100644 --- a/install.php +++ b/install.php @@ -1,17 +1,17 @@ file_get_contents and file_put_contents seems to not be available on your PHP installation. You should enable them first."; $block_form = true; } - if(!is_writable('inc/')) { - $error = "The script seems to be unable to write to inc/ folder (to write the inc/config.php configuration file). You should give write access during install and disable them after (chmod 777 -R inc/ to install and chmod 755 -R inc/ after installation for example)."; + if(!is_writable('data/')) { + $error = "The script seems to be unable to write to data/ folder (to write the data/config.php configuration file). You should give write access during install and disable them after (chmod 777 -R data/ to install and chmod 755 -R data/ after installation for example)."; $block_form = true; } - if(!empty($_POST['mysql_host']) && !empty($_POST['mysql_login']) && !empty($_POST['mysql_db']) && !empty($_POST['admin_login']) && !empty($_POST['admin_password']) && !empty($_POST['currency'])) { + if(!empty($_POST['mysql_host']) && !empty($_POST['mysql_login']) && !empty($_POST['mysql_db']) && !empty($_POST['admin_login']) && !empty($_POST['admin_password']) && !empty($_POST['currency']) && !empty($_POST['instance_title']) && !empty($_POST['base_url'])) { $mysql_host = $_POST['mysql_host']; $mysql_login = $_POST['mysql_login']; $mysql_db = $_POST['mysql_db']; @@ -53,7 +53,7 @@ define('SALT', '".$salt."'); define('CURRENCY', '".$_POST['currency']."');"; - if(file_put_contents("inc/config.php", $config)) { + if(file_put_contents("data/config.php", $config) && file_put_contents("data/notice", '')) { try { require_once('inc/User.class.php'); $admin = new User(); @@ -68,7 +68,7 @@ } } else - $error = 'Unable to write configuration to config file inc/config.php.'; + $error = 'Unable to write configuration to config file data/config.php.'; } } ?> diff --git a/tmp/header.36ba0f7e771a8681573a91518b54b424.rtpl.php b/tmp/header.36ba0f7e771a8681573a91518b54b424.rtpl.php index 119aa57..1f64560 100644 --- a/tmp/header.36ba0f7e771a8681573a91518b54b424.rtpl.php +++ b/tmp/header.36ba0f7e771a8681573a91518b54b424.rtpl.php @@ -9,13 +9,7 @@ -

- - - -

- - +