From 97ae8f3d4261c216e9bb481f0c663a6536bff899 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Tue, 31 Jan 2006 16:57:12 +0000 Subject: [PATCH] removed confsave.php and use less session variables --- lam/templates/config/conflogin.php | 4 +- lam/templates/config/confmain.php | 221 +++++++++++++++++++-------- lam/templates/config/confmodules.php | 17 ++- lam/templates/config/confsave.php | 202 ------------------------ lam/templates/config/conftypes.php | 11 +- 5 files changed, 176 insertions(+), 279 deletions(-) delete mode 100644 lam/templates/config/confsave.php diff --git a/lam/templates/config/conflogin.php b/lam/templates/config/conflogin.php index 1b07f1b6..80f9427a 100644 --- a/lam/templates/config/conflogin.php +++ b/lam/templates/config/conflogin.php @@ -41,6 +41,9 @@ session_save_path("../../sess"); setlanguage(); +// get error message from confmain.php +if (isset($_SESSION['conf_message'])) $message = $_SESSION['conf_message']; + // remove settings from session $sessionKeys = array_keys($_SESSION); for ($i = 0; $i < sizeof($sessionKeys); $i++) { @@ -87,7 +90,6 @@ echo $_SESSION['header'];   get_Passwd(); // check if password was entered // if not: load login page if (! $passwd) { - $message = _("No password was entered!"); + $_SESSION['conf_message'] = _("No password was entered!"); /** go back to login if password is empty */ require('conflogin.php'); exit; } -$filename = $_POST['filename']; -if (isset($_GET["modulesback"]) || isset($_GET["typesback"])) $filename = $_SESSION['conf_filename']; -$conf = new Config($filename); +if (!isset($_SESSION['conf_config']) && isset($_POST['filename'])) { + $_SESSION['conf_config'] = new Config($_POST['filename']); +} +$conf = &$_SESSION['conf_config']; // check if password is valid // if not: load login page if (!(($conf->get_Passwd()) == $passwd)) { - $message = _("The password is invalid! Please try again."); + $sessionKeys = array_keys($_SESSION); + for ($i = 0; $i < sizeof($sessionKeys); $i++) { + if (substr($sessionKeys[$i], 0, 5) == "conf_") unset($_SESSION[$sessionKeys[$i]]); + } + $_SESSION['conf_message'] = _("The password is invalid! Please try again."); /** go back to login if password is invalid */ require('conflogin.php'); exit; } -// check if user comes from modules page -if (isset($_GET["modulesback"])) { - // load config values from session - $conf->set_ServerURL($_SESSION['conf_serverurl']); - $conf->set_cacheTimeout($_SESSION['conf_cachetimeout']); - $conf->set_Adminstring($_SESSION['conf_admins']); - $conf->set_Suffix('tree', $_SESSION['conf_sufftree']); - $conf->set_MaxListEntries($_SESSION['conf_maxlistentries']); - $conf->set_defaultLanguage($_SESSION['conf_lang']); - $conf->set_scriptpath($_SESSION['conf_scriptpath']); - $conf->set_scriptserver($_SESSION['conf_scriptserver']); +// check if button was pressed and if we have to save the setting or go back to login +if (isset($_POST['back']) || isset($_POST['submitconf']) || isset($_POST['editmodules']) || isset($_POST['edittypes'])){ + // go to final page + if ($_POST['submitconf']){ + saveSettings(); + } + // go to modules page + elseif ($_POST['editmodules']){ + metaRefresh("confmodules.php"); + exit; + } + // go to types page + elseif ($_POST['edittypes']){ + metaRefresh("conftypes.php"); + exit; + } + // back to login + else if ($_POST['back']){ + metaRefresh("../login.php"); + exit; + } } + // check if user comes from types page if (isset($_GET["typesback"])) { // check if a new account type was added @@ -147,6 +124,14 @@ echo ("\n"); echo ("

". "\"LDAP

\n
\n

\n"); +// display error messages +if (isset($_SESSION['conf_errors'])) { + for ($i = 0; $i < sizeof($_SESSION['conf_errors']); $i++) { + call_user_func_array('StatusMessage', $_SESSION['conf_errors'][$i]); + } + echo "
"; +} + // display formular echo ("
\n"); @@ -207,7 +192,7 @@ echo ("

"); echo ("
" . _("Account types and modules") . ""); // Account modules -$types = $_SESSION['conf_accountTypes']; +$types = $conf->get_ActiveTypes(); for ($i = 0; $i < sizeof($types); $i++) { echo "" . getTypeAlias($types[$i]) . ": " . implode(", ", $conf->get_AccountModules($types[$i])) . "
\n"; } @@ -241,18 +226,16 @@ $old_options = $conf->get_moduleSettings(); // get module descriptions $moduleDescriptions = getConfigDescriptions(); -// save scopes -$_SESSION['config_scopes'] = $scopes; // display module boxes $modules = array_keys($options); -$_SESSION['config_types'] = array(); +$_SESSION['conf_types'] = array(); for ($i = 0; $i < sizeof($modules); $i++) { if (sizeof($options[$modules[$i]]) < 1) continue; echo "
\n"; echo "" . $moduleDescriptions['legend'][$modules[$i]] . "\n"; $configTypes = parseHtml($modules[$i], $options[$modules[$i]], $old_options, true, $tabindex, $tabindexLink, 'config'); - $_SESSION['config_types'] = array_merge($configTypes, $_SESSION['config_types']); + $_SESSION['conf_types'] = array_merge($configTypes, $_SESSION['conf_types']); echo "
\n"; echo "
"; } @@ -417,13 +400,121 @@ echo ("

** = ". _("required for Samba 3 accounts") . "

"); // password for configuration echo ("

\n"); -// config file -echo ("

\n"); - echo ("\n"); echo ("\n"); echo ("\n"); +/** + * Saves the entered settings. + * + */ +function saveSettings() { + $conf = &$_SESSION['conf_config']; + $types = $conf->get_ActiveTypes(); + + // remove double slashes if magic quotes are on + if (get_magic_quotes_gpc() == 1) { + $postKeys = array_keys($_POST); + for ($i = 0; $i < sizeof($postKeys); $i++) { + if (is_string($_POST[$postKeys[$i]])) $_POST[$postKeys[$i]] = stripslashes($_POST[$postKeys[$i]]); + } + } + // check new preferences + $errors = array(); + if (!$conf->set_ServerURL($_POST['serverurl'])) { + $errors[] = array("ERROR", _("Server Address is empty!")); + } + if (!$conf->set_cacheTimeout($_POST['cachetimeout'])) { + $errors[] = array("ERROR", _("Cache timeout is invalid!")); + } + if (!$conf->set_Adminstring($_POST['admins'])) { + $errors[] = array("ERROR", _("List of admin users is empty or invalid!")); + } + if (!$conf->set_Suffix("tree", $_POST['sufftree'])) { + $errors[] = array("ERROR", _("TreeSuffix is invalid!")); + } + if (!$conf->set_MaxListEntries($_POST['maxlistentries'])) { + $errors[] = array("ERROR", _("Max list entries is invalid!")); + } + if (!$conf->set_defaultLanguage($_POST['lang'])) { + $errors[] = array("ERROR", _("Language is not defined!")); + } + if (!$conf->set_scriptpath($_POST['scriptpath'])) { + $errors[] = array("ERROR", _("Script path is invalid!")); + } + if (!$conf->set_scriptserver($_POST['scriptserver'])) { + $errors[] = array("ERROR", _("Script server is invalid!")); + } + // check if password was changed + if (isset($_POST['passwd1']) && ($_POST['passwd1'] != '')) { + if ($_POST['passwd1'] != $_POST['passwd2']) { + $errors[] = array("ERROR", _("Passwords are different!")); + } + else { + // set new password + $conf->set_Passwd($_POST['passwd1']); + } + } + + // check module options + // create option array to check and save + $options = array(); + $opt_keys = array_keys($_SESSION['conf_types']); + for ($i = 0; $i < sizeof($opt_keys); $i++) { + $element = $opt_keys[$i]; + // text fields + if ($_SESSION['conf_types'][$element] == "text") { + $options[$element] = array($_POST[$element]); + } + // checkboxes + elseif ($_SESSION['conf_types'][$element] == "checkbox") { + if ($_POST[$element] == "on") $options[$element] = array('true'); + else $options[$element] = array('false'); + } + // dropdownbox + elseif ($_SESSION['conf_types'][$element] == "select") { + $options[$element] = array($_POST[$element]); + } + // multiselect + elseif ($_SESSION['conf_types'][$element] == "multiselect") { + $options[$element] = $_POST[$element]; // value is already an array + } + } + + // get list of scopes of modules + $scopes = array(); + for ($m = 0; $m < sizeof($types); $m++) { + $mods = $conf->get_AccountModules($types[$m]); + for ($i = 0; $i < sizeof($mods); $i++) $scopes[$mods[$i]][] = $types[$m]; + } + // check options + $errors = array_merge($errors, checkConfigOptions($scopes, $options)); + // print error messages if any + if (sizeof($errors) > 0) { + $_SESSION['conf_errors'] = $errors; + } + // save settings if no errors occured + else { + // page head + echo $_SESSION['header']; + echo "" . _("LDAP Account Manager Configuration") . "\n"; + echo "\n"; + echo "\n"; + echo ("

". + "\"LDAP




"); + $conf->set_moduleSettings($options); + $conf->save(); + echo ("




" . _("Back to Login") . ""); + echo(""); + // remove settings from session + $sessionKeys = array_keys($_SESSION); + for ($i = 0; $i < sizeof($sessionKeys); $i++) { + if (substr($sessionKeys[$i], 0, 5) == "conf_") unset($_SESSION[$sessionKeys[$i]]); + } + exit(); + } +} + ?> diff --git a/lam/templates/config/confmodules.php b/lam/templates/config/confmodules.php index ca529b8a..9404296d 100644 --- a/lam/templates/config/confmodules.php +++ b/lam/templates/config/confmodules.php @@ -41,30 +41,35 @@ session_save_path("../../sess"); setlanguage(); -$conf = new Config($_SESSION['conf_filename']); -$passwd = $_SESSION['conf_passwd']; -// check if password is correct +// check if config is set // if not: load login page -if ($passwd != $conf->get_Passwd()) { +if (!isset($_SESSION['conf_config'])) { /** go back to login if password is invalid */ require('conflogin.php'); exit; } +$conf = &$_SESSION['conf_config']; + + // user pressed submit/abort button if ($_POST['submit']) { + // save new module settings + $_SESSION['conf_accountTypesOld'] = $_SESSION['conf_accountTypes']; + $conf->set_typeSettings($_SESSION['conf_typeSettings']); //selection ok, back to other settings - metarefresh('confmain.php?modulesback=true&moduleschanged=true'); + metarefresh('confmain.php?modulesback=true'); exit; } elseif ($_POST['abort']) { // no changes + $_SESSION['conf_accountTypes'] = $_SESSION['conf_accountTypesOld']; metarefresh('confmain.php?modulesback=true'); exit; } -$types = $_SESSION['conf_accountTypes']; +$types = $conf->get_ActiveTypes(); echo $_SESSION['header']; diff --git a/lam/templates/config/confsave.php b/lam/templates/config/confsave.php deleted file mode 100644 index 55cb92fc..00000000 --- a/lam/templates/config/confsave.php +++ /dev/null @@ -1,202 +0,0 @@ -get_Passwd()) { - /** go back to login if password is invalid */ - require('conflogin.php'); - exit; -} - -echo $_SESSION['header']; - -echo "" . _("LDAP Account Manager Configuration") . "\n"; -echo "\n"; -echo "\n"; - -echo ("

". - "\"LDAP




"); - -// remove double slashes if magic quotes are on -if (get_magic_quotes_gpc() == 1) { - $sufftree = stripslashes($sufftree); -} - -// check new preferences -if (!$conf->set_ServerURL($serverurl)) { - echo ("" . _("Server Address is empty!") . ""); - echo ("\n


" . _("Back to preferences...") . ""); - exit; -} -if (!$conf->set_cacheTimeout($cachetimeout)) { - echo ("" . _("Cache timeout is invalid!") . ""); - echo ("\n


" . _("Back to preferences...") . ""); - exit; -} -if (!$conf->set_Adminstring($admins)) { - echo ("" . _("List of admin users is empty or invalid!") . ""); - echo ("\n


" . _("Back to preferences...") . ""); - exit; -} -if (!$conf->set_Suffix("tree", $sufftree)) { - echo ("" . _("TreeSuffix is invalid!") . ""); - echo ("\n


" . _("Back to preferences...") . ""); - exit; -} -if (!$conf->set_MaxListEntries($maxlistentries)) { - echo ("" . _("Max list entries is invalid!") . ""); - echo ("\n


" . _("Back to preferences...") . ""); - exit; -} - -if (!$conf->set_defaultLanguage($lang)) { - echo ("" . _("Language is not defined!") . ""); - echo ("\n


" . _("Back to preferences...") . ""); - exit; -} - -if (!$conf->set_scriptpath($scriptpath)) { - echo ("" . _("Script path is invalid!") . ""); - echo ("\n


" . _("Back to preferences...") . ""); - exit; -} - -if (!$conf->set_scriptserver($scriptserver)) { - echo ("" . _("Script server is invalid!") . ""); - echo ("\n


" . _("Back to preferences...") . ""); - exit; -} - -$conf->set_typeSettings($_SESSION['conf_typeSettings']); -$conf->set_ActiveTypes($_SESSION['conf_accountTypes']); - -// check module options -// create option array to check and save -$options = array(); -$opt_keys = array_keys($_SESSION['config_types']); -foreach ($opt_keys as $element) { - // text fields - if ($_SESSION['config_types'][$element] == "text") { - $options[$element] = array($_SESSION['config_moduleSettings'][$element]); - } - // checkboxes - elseif ($_SESSION['config_types'][$element] == "checkbox") { - if ($_SESSION['config_moduleSettings'][$element] == "on") $options[$element] = array('true'); - else $options[$element] = array('false'); - } - // dropdownbox - elseif ($_SESSION['config_types'][$element] == "select") { - $options[$element] = array($_SESSION['config_moduleSettings'][$element]); - } - // multiselect - elseif ($_SESSION['config_types'][$element] == "multiselect") { - $options[$element] = $_SESSION['config_moduleSettings'][$element]; // value is already an array - } -} - -// remove double slashes if magic quotes are on -if (get_magic_quotes_gpc() == 1) { - foreach ($opt_keys as $element) { - if (is_string($options[$element][0])) $options[$element][0] = stripslashes($options[$element][0]); - } -} - -// check options -$errors = checkConfigOptions($_SESSION['config_scopes'], $options); -// print error messages if any -if (sizeof($errors) > 0) { - for ($i = 0; $i < sizeof($errors); $i++) { - if (sizeof($errors[$i]) > 3) { // messages with additional variables - StatusMessage($errors[$i][0], $errors[$i][1], $errors[$i][2], $errors[$i][3]); - } - else { - StatusMessage($errors[$i][0], $errors[$i][1], $errors[$i][2]); - } - } - echo ("\n


" . _("Back to preferences...") . ""); - exit; -} -// save module setting -$conf->set_moduleSettings($options); - -// check if password was changed -if ($passwd1) { - if ($passwd1 != $passwd2) { - echo ("" . _("Passwords are different!") . ""); - exit; - } - // set new password - if ($passwd1 != "") { - $conf->set_Passwd($passwd1); - echo ("" . _("Password changed!") . "

"); - } -} - -// save settings and display new settings -$conf->save(); -echo ("




" . _("Back to Login") . ""); - -echo(""); - -// remove settings from session -$sessionKeys = array_keys($_SESSION); -for ($i = 0; $i < sizeof($sessionKeys); $i++) { - if (substr($sessionKeys[$i], 0, 5) == "conf_") unset($_SESSION[$sessionKeys[$i]]); -} - -?> diff --git a/lam/templates/config/conftypes.php b/lam/templates/config/conftypes.php index 7feeec35..43436317 100644 --- a/lam/templates/config/conftypes.php +++ b/lam/templates/config/conftypes.php @@ -41,17 +41,16 @@ session_save_path("../../sess"); setlanguage(); -$conf = new Config($_SESSION['conf_filename']); - -$passwd = $_SESSION['conf_passwd']; -// check if password is correct +// check if config is set // if not: load login page -if ($passwd != $conf->get_Passwd()) { +if (!isset($_SESSION['conf_config'])) { /** go back to login if password is invalid */ require('conflogin.php'); exit; } +$conf = &$_SESSION['conf_config']; + // update type settings if (isset($_POST['postAvailable'])) { $postKeys = array_keys($_POST); @@ -100,6 +99,8 @@ if ($_POST['submit']) { } } $_SESSION['conf_accountTypesOld'] = $_SESSION['conf_accountTypes']; + $conf->set_ActiveTypes($_SESSION['conf_accountTypes']); + $conf->set_typeSettings($_SESSION['conf_typeSettings']); if ($addedType) { metarefresh('confmain.php?typesback=true&typeschanged=true'); }