From 339c7f6f0e0291802e62ca4597ea17709d21feb2 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sun, 6 Jul 2003 10:22:23 +0000 Subject: [PATCH] new files for updated configuration system --- lam/config/config.cfg_sample | 5 + lam/templates/config/profmanage.php | 337 ++++++++++++++++++++++++++++ lam/tests/conf-main-test.php | 62 +++++ 3 files changed, 404 insertions(+) create mode 100644 lam/config/config.cfg_sample create mode 100644 lam/templates/config/profmanage.php create mode 100644 lam/tests/conf-main-test.php diff --git a/lam/config/config.cfg_sample b/lam/config/config.cfg_sample new file mode 100644 index 00000000..120aed1c --- /dev/null +++ b/lam/config/config.cfg_sample @@ -0,0 +1,5 @@ +# password to add/delete/rename configuration profiles +password: lam + +# default profile, without ".conf" +default: lam diff --git a/lam/templates/config/profmanage.php b/lam/templates/config/profmanage.php new file mode 100644 index 00000000..c069569b --- /dev/null +++ b/lam/templates/config/profmanage.php @@ -0,0 +1,337 @@ +"); +echo (""); + +?> + + + + + <?php + echo _("Profile management"); + ?> + + + + +

+ LDAP Account Manager +

+

+ +password != $_POST['passwd']) { + $error = _("Master password is wrong!"); + } + // add new profile + elseif ($_POST['action'] == "add") { + if (eregi("^[a-z0-9\-_]+$", $_POST['addprofile']) && !in_array($_POST['addprofile'], getConfigProfiles())) { + // check profile password + if ($_POST['addpassword'] && $_POST['addpassword2'] && ($_POST['addpassword'] == $_POST['addpassword2'])) { + // create new profile file + @touch("../../config/" . $_POST['addprofile'] . ".conf"); + @chmod ("../../config/" . $_POST['addprofile'] . ".conf", 0600); + $file = fopen("../../config/" . $_POST['addprofile'] . ".conf", "w"); + if ($file) { + $input = "# password to change these preferences via webfrontend\n"; + $input = $input . "passwd: " . $_POST['addpassword'] . "\n\n"; + fwrite ($file, $input); + fclose($file); + $msg = _("Created new profile."); + } + else $error = _("Unable to create new profile!"); + } + else $error = _("Profile passwords are different or empty!"); + } + else $error = _("Profile name is invalid!"); + } + // rename profile + elseif ($_POST['action'] == "rename") { + if (eregi("^[a-z0-9\-_]+$", $_POST['renfilename']) && !in_array($_POST['renprofile'], getConfigProfiles())) { + if (rename("../../config/" . $_POST['oldfilename'] . ".conf", + "../../config/" . $_POST['renfilename'] . ".conf")) { + $msg = _("Renamed profile."); + } + else $error = _("Could not rename file!"); + } + else $error = _("Profile name is invalid!"); + } + // delete profile + elseif ($_POST['action'] == "delete") { + if (@unlink("../../config/" . $_POST['delfilename'] . ".conf")) { + $msg = _("Profile deleted."); + } + else $error = _("Unable to delete profile!"); + } + // set new profile password + elseif ($_POST['action'] == "setpass") { + if ($_POST['setpassword'] && $_POST['setpassword2'] && ($_POST['setpassword'] == $_POST['setpassword2'])) { + $config = new Config($_POST['setprofile']); + $config->set_Passwd($_POST['setpassword']); + $config->save(); + $msg = _("New password set successfully."); + } + else $error = _("Profile passwords are different or empty!"); + } + // set master password + elseif ($_POST['action'] == "setmasterpass") { + if ($_POST['masterpassword'] && $_POST['masterpassword2'] && ($_POST['masterpassword'] == $_POST['masterpassword2'])) { + $config = new CfgMain(); + $config->password = $_POST['masterpassword']; + $config->save(); + $msg = _("New master password set successfully."); + } + else $error = _("Master passwords are different or empty!"); + } + // set default profile + elseif ($_POST['action'] == "setdefault") { + $config = new CfgMain(); + $config->default = $_POST['defaultfilename']; + $config->save(); + $msg = _("New default profile set successfully."); + } + // print messages + if ($error || $msg) { + if ($error) StatusMessage("ERROR", "", $error); + if ($msg) StatusMessage("INFO", "", $msg); + } + else exit; +} + +?> + +
+ +
+
+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +   + +   + + + +
+ + +   + +
 
+ + + + + +   + + + + +
 
+ + + + + + + + +
 
+ + + + + + + + +
+ + +   + +
 
 
+ + + + + + + + +
+ + + + + +   + +   + + + +
+

+

 

+ + + + + +   + +   + "> + +
+


+ + +

+ +

+ + + + diff --git a/lam/tests/conf-main-test.php b/lam/tests/conf-main-test.php new file mode 100644 index 00000000..152886b5 --- /dev/null +++ b/lam/tests/conf-main-test.php @@ -0,0 +1,62 @@ +"; +echo (" Current Values

"); +echo "Password: " . $conf->password . "
\n"; +echo "Default: " . $conf->default . "
\n"; +echo ("

Starting Test...

"); +// now all prferences are loaded +echo ("Loading preferences..."); +$password = $conf->password; +$default = $conf->default; +echo ("done
"); +// next we modify them and save config.cfg +echo ("Changing preferences..."); +$conf->password = "123456"; +$conf->default = "lam"; +$conf->save(); +echo ("done
"); +// at last all preferences are read from lam.conf and compared +echo ("Loading and comparing..."); +$conf = new CfgMain(); +if ($conf->password != "123456") echo ("
Saving password failed!
"); +if ($conf->default != "lam") echo ("
Saving Default failed!
"); +echo ("done
"); +// restore old values +echo ("Restoring old preferences..."); +$conf->password = $password; +$conf->default = $default; +$conf->save(); +echo ("done
"); +// finished +echo ("
Test is complete."); +echo ("

Current Config

"); +echo "Password: " . $conf->password . "
\n"; +echo "Default: " . $conf->default . "
\n"; + +?>