removed confsave.php and use less session variables

This commit is contained in:
Roland Gruber 2006-01-31 16:57:12 +00:00
parent e097c82a87
commit 97ae8f3d42
5 changed files with 176 additions and 279 deletions

View File

@ -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'];
</tr>
<tr><td style="border-style:none" >&nbsp;</td></tr>
<?php
if (!isset($message)) $message = "";
$files = getConfigProfiles();
if (sizeof($files) < 1) $message = _("No configuration profiles found. Please create one.");
// print message if login was incorrect or no config profiles are present

View File

@ -42,84 +42,61 @@ session_save_path("../../sess");
setlanguage();
// 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'])){
// save settings
if ($_POST['submitconf'] || $_POST['editmodules'] || $_POST['edittypes']){
// save HTTP-POST variables in session
$_SESSION['conf_passwd'] = $_POST['passwd'];
$_SESSION['conf_passwd1'] = $_POST['passwd1'];
$_SESSION['conf_passwd2'] = $_POST['passwd2'];
$_SESSION['conf_serverurl'] = $_POST['serverurl'];
$_SESSION['conf_cachetimeout'] = $_POST['cachetimeout'];
$_SESSION['conf_admins'] = $_POST['admins'];
$_SESSION['conf_sufftree'] = $_POST['sufftree'];
$_SESSION['conf_maxlistentries'] = $_POST['maxlistentries'];
$_SESSION['conf_lang'] = $_POST['lang'];
$_SESSION['conf_scriptpath'] = $_POST['scriptpath'];
$_SESSION['conf_scriptserver'] = $_POST['scriptserver'];
$_SESSION['conf_filename'] = $_POST['filename'];
$modSettings = array_keys($_SESSION['config_types']);
for ($i = 0; $i < sizeof($modSettings); $i++) $_SESSION['config_moduleSettings'][$modSettings[$i]] = $_POST[$modSettings[$i]];
}
// go to final page
if ($_POST['submitconf']){
metaRefresh("confsave.php");
}
// go to modules page
elseif ($_POST['editmodules']){
metaRefresh("confmodules.php");
}
// go to types page
elseif ($_POST['edittypes']){
metaRefresh("conftypes.php");
}
// back to login
else if ($_POST['back']){
metaRefresh("../login.php");
}
exit;
}
// get password if register_globals is off
// get password
if (isset($_POST['passwd'])) $passwd = $_POST['passwd'];
if (isset($_GET["modulesback"]) || isset($_GET["typesback"])) $passwd = $_SESSION['conf_passwd'];
if (isset($_GET["modulesback"]) || isset($_GET["typesback"])) $passwd = $_SESSION['conf_config']->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 ("<body>\n");
echo ("<p align=\"center\"><a href=\"http://lam.sourceforge.net\" target=\"new_window\">".
"<img src=\"../../graphics/banner.jpg\" border=1 alt=\"LDAP Account Manager\"></a></p>\n<hr>\n<p></p>\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 "<br>";
}
// display formular
echo ("<form action=\"confmain.php\" method=\"post\">\n");
@ -207,7 +192,7 @@ echo ("<p></p>");
echo ("<fieldset><legend><b>" . _("Account types and modules") . "</b></legend>");
// Account modules
$types = $_SESSION['conf_accountTypes'];
$types = $conf->get_ActiveTypes();
for ($i = 0; $i < sizeof($types); $i++) {
echo "<b>" . getTypeAlias($types[$i]) . ": </b>" . implode(", ", $conf->get_AccountModules($types[$i])) . "<br>\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 "<fieldset>\n";
echo "<legend><b>" . $moduleDescriptions['legend'][$modules[$i]] . "</b></legend>\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 "</fieldset>\n";
echo "<br>";
}
@ -417,13 +400,121 @@ echo ("<p>** = ". _("required for Samba 3 accounts") . "</p>");
// password for configuration
echo ("<p><input type=\"hidden\" name=\"passwd\" value=\"" . $passwd . "\"></p>\n");
// config file
echo ("<p><input type=\"hidden\" name=\"filename\" value=\"" . $filename . "\"></p>\n");
echo ("</form>\n");
echo ("</body>\n");
echo ("</html>\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 "<title>" . _("LDAP Account Manager Configuration") . "</title>\n";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../../style/layout.css\">\n";
echo "</head><body>\n";
echo ("<p align=\"center\"><a href=\"http://lam.sourceforge.net\" target=\"new_window\">".
"<img src=\"../../graphics/banner.jpg\" border=1 alt=\"LDAP Account Manager\"></a></p><hr><br><br>");
$conf->set_moduleSettings($options);
$conf->save();
echo ("<br><br><br><br><br><a href=\"../login.php\" target=\"_top\">" . _("Back to Login") . "</a>");
echo("</body></html>");
// 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();
}
}
?>

View File

@ -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&amp;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'];

View File

@ -1,202 +0,0 @@
<?php
/*
$Id$
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
Copyright (C) 2003 Roland Gruber
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* confsave saves the new preferences to lam.conf
*
* @package configuration
* @author Roland Gruber
*/
/** Access to config functions */
include_once ('../../lib/config.inc');
// start session
session_save_path("../../sess");
@session_start();
setlanguage();
$conf = new Config($_SESSION['conf_filename']);
// get data from session
$passwd = $_SESSION['conf_passwd'];
$passwd1 = $_SESSION['conf_passwd1'];
$passwd2 = $_SESSION['conf_passwd2'];
$serverurl = $_SESSION['conf_serverurl'];
$cachetimeout = $_SESSION['conf_cachetimeout'];
$admins = $_SESSION['conf_admins'];
$sufftree = $_SESSION['conf_sufftree'];
$maxlistentries = $_SESSION['conf_maxlistentries'];
$lang = $_SESSION['conf_lang'];
$scriptpath = $_SESSION['conf_scriptpath'];
$scriptserver = $_SESSION['conf_scriptserver'];
$filename = $_SESSION['conf_filename'];
// check if password is correct
// if not: load login page
if ($passwd != $conf->get_Passwd()) {
/** go back to login if password is invalid */
require('conflogin.php');
exit;
}
echo $_SESSION['header'];
echo "<title>" . _("LDAP Account Manager Configuration") . "</title>\n";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../../style/layout.css\">\n";
echo "</head><body>\n";
echo ("<p align=\"center\"><a href=\"http://lam.sourceforge.net\" target=\"new_window\">".
"<img src=\"../../graphics/banner.jpg\" border=1 alt=\"LDAP Account Manager\"></a></p><hr><br><br>");
// 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 ("<font color=\"red\"><b>" . _("Server Address is empty!") . "</b></font>");
echo ("\n<br><br><br><a href=\"javascript:history.back()\">" . _("Back to preferences...") . "</a>");
exit;
}
if (!$conf->set_cacheTimeout($cachetimeout)) {
echo ("<font color=\"red\"><b>" . _("Cache timeout is invalid!") . "</b></font>");
echo ("\n<br><br><br><a href=\"javascript:history.back()\">" . _("Back to preferences...") . "</a>");
exit;
}
if (!$conf->set_Adminstring($admins)) {
echo ("<font color=\"red\"><b>" . _("List of admin users is empty or invalid!") . "</b></font>");
echo ("\n<br><br><br><a href=\"javascript:history.back()\">" . _("Back to preferences...") . "</a>");
exit;
}
if (!$conf->set_Suffix("tree", $sufftree)) {
echo ("<font color=\"red\"><b>" . _("TreeSuffix is invalid!") . "</b></font>");
echo ("\n<br><br><br><a href=\"javascript:history.back()\">" . _("Back to preferences...") . "</a>");
exit;
}
if (!$conf->set_MaxListEntries($maxlistentries)) {
echo ("<font color=\"red\"><b>" . _("Max list entries is invalid!") . "</b></font>");
echo ("\n<br><br><br><a href=\"javascript:history.back()\">" . _("Back to preferences...") . "</a>");
exit;
}
if (!$conf->set_defaultLanguage($lang)) {
echo ("<font color=\"red\"><b>" . _("Language is not defined!") . "</b></font>");
echo ("\n<br><br><br><a href=\"javascript:history.back()\">" . _("Back to preferences...") . "</a>");
exit;
}
if (!$conf->set_scriptpath($scriptpath)) {
echo ("<font color=\"red\"><b>" . _("Script path is invalid!") . "</b></font>");
echo ("\n<br><br><br><a href=\"javascript:history.back()\">" . _("Back to preferences...") . "</a>");
exit;
}
if (!$conf->set_scriptserver($scriptserver)) {
echo ("<font color=\"red\"><b>" . _("Script server is invalid!") . "</b></font>");
echo ("\n<br><br><br><a href=\"javascript:history.back()\">" . _("Back to preferences...") . "</a>");
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<br><br><br><a href=\"javascript:history.back()\">" . _("Back to preferences...") . "</a>");
exit;
}
// save module setting
$conf->set_moduleSettings($options);
// check if password was changed
if ($passwd1) {
if ($passwd1 != $passwd2) {
echo ("<b>" . _("Passwords are different!") . "</b>");
exit;
}
// set new password
if ($passwd1 != "") {
$conf->set_Passwd($passwd1);
echo ("<b>" . _("Password changed!") . "</b><br><br>");
}
}
// save settings and display new settings
$conf->save();
echo ("<br><br><br><br><br><a href=\"../login.php\" target=\"_top\">" . _("Back to Login") . "</a>");
echo("</body></html>");
// 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]]);
}
?>

View File

@ -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&amp;typeschanged=true');
}