wizard to change settings

This commit is contained in:
Roland Gruber 2003-02-25 21:28:17 +00:00
parent 67b340f33c
commit cea46df0a2
4 changed files with 210 additions and 27 deletions

View File

@ -25,22 +25,24 @@ $Id$
// Config supplies access to the configuration data.
class Config {
// boolean: use SSL-connection?
// string: can be "True" or "False"
// use SSL-connection?
var $SSL;
// string: hostname
var $Host;
// int: port number
// string: port number
var $Port;
// array of strings: users with admin rights
var $Admins;
// string: password to edit preferences
var $Passwd;
// single line with the names of all admin users
var $Adminstring;
// constructor, loads preferences from ../lam.conf
function Config() {
$this->reload();
$this->save();
}
// reloads preferences from ../lam.conf
@ -52,23 +54,24 @@ class Config {
$line = fgets($file, 1024);
if (($line == "\n")||($line[0] == "#")) continue;
if (substr($line, 0, 5) == "ssl: ") {
$this->SSL = substr($line, 5, strlen($line)-5);
$this->SSL = chop(substr($line, 5, strlen($line)-5));
continue;
}
if (substr($line, 0, 6) == "host: ") {
$this->Host = substr($line, 6, strlen($line)-6);
$this->Host = chop(substr($line, 6, strlen($line)-6));
continue;
}
if (substr($line, 0, 6) == "port: ") {
$this->Port = substr($line, 6, strlen($line)-6);
$this->Port = chop(substr($line, 6, strlen($line)-6));
continue;
}
if (substr($line, 0, 8) == "passwd: ") {
$this->Passwd = substr($line, 8, strlen($line)-8);
$this->Passwd = chop(substr($line, 8, strlen($line)-8));
continue;
}
if (substr($line, 0, 8) == "admins: ") {
$adminstr = substr($line, 8, strlen($line)-8);
$adminstr = chop(substr($line, 8, strlen($line)-8));
$this->Adminstring = $adminstr;
$this->Admins = explode(";", $adminstr);
continue;
}
@ -94,27 +97,27 @@ class Config {
for ($i = 0; $i < sizeof($file_array); $i++) {
if (($file_array[$i] == "\n")||($file_array[$i][0] == "#")) continue;
if (substr($file_array[$i], 0, 5) == "ssl: ") {
$file_array[$i] = "ssl: " . $this->SSL;
$file_array[$i] = "ssl: " . $this->SSL . "\n";
$save_ssl = True;
continue;
}
if (substr($file_array[$i], 0, 6) == "host: ") {
$file_array[$i] = "host: " . $this->Host;
$file_array[$i] = "host: " . $this->Host . "\n";
$save_host = True;
continue;
}
if (substr($file_array[$i], 0, 6) == "port: ") {
$file_array[$i] = "port: " . $this->Port;
$file_array[$i] = "port: " . $this->Port . "\n";
$save_port = True;
continue;
}
if (substr($file_array[$i], 0, 8) == "passwd: ") {
$file_array[$i] = "passwd: " . $this->Passwd;
$file_array[$i] = "passwd: " . $this->Passwd . "\n";
$save_passwd = True;
continue;
}
if (substr($file_array[$i], 0, 8) == "admins: ") {
$file_array[$i] = "admins: " . implode(";", $this->Admins);
$file_array[$i] = "admins: " . implode(";", $this->Admins) . "\n";
$save_admins = True;
continue;
}
@ -133,19 +136,6 @@ class Config {
}
}
// used by configuration wizard to save new preferences
function input() {
if (is_numeric($Port) && $Host!="" && $Admins!="") {
$this->SSL = $SSL;
$this->Host = $Host;
$this->Port = $Port;
$this->Admins = $Admins;
$this->Passwd = $Passwd;
$this->save();
}
else echo _("Portnumber must be a number!");
}
// prints current preferences
function printconf() {
echo _("SSL: " ) . $this->SSL . "</br>";
@ -160,7 +150,8 @@ class Config {
}
function set_SSL($value) {
if (is_bool($value)) $this->SSL = $value;
if (($value == "True") || ($value == "False")) $this->SSL = $value;
else echo _("Config->set_SSL failed!");
}
function get_Host() {
@ -169,6 +160,7 @@ class Config {
function set_Host($value) {
if (is_string($value)) $this->Host = $value;
else echo _("Config->set_Host failed!");
}
function get_Port() {
@ -177,6 +169,7 @@ class Config {
function set_Port($value) {
if (is_numeric($value)) $this->Port = $value;
else echo _("Config->set_Port failed!");
}
function get_Admins() {
@ -196,12 +189,25 @@ class Config {
}
}
function get_Adminstring() {
return $this->Adminstring;
}
function set_Adminstring($value) {
if (is_string($value)) {
$this->Adminstring = $value;
$this->Admins = explode(";", $value);
}
else echo _("Config->set_Adminstring failed!");
}
function get_Passwd() {
return $this->Passwd;
}
function set_Passwd($value) {
if (is_string($value)) $this->Passwd = $value;
else echo _("Config->set_Passwd failed!");
}
}

42
lam/config/conflogin.php Normal file
View File

@ -0,0 +1,42 @@
<?
/*
$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
Login page to change the preferences.
*/
?>
<html>
<head>
<title>
<?
echo _("Login");
?>
</title>
</head>
<body>
<b> <? echo _("Password to enter preferences:"); ?> </b><br><br>
<form action="confmain.php" method="post">
<input type="password" name="passwd">
<input type="submit" name="submit" value=<? echo _("Ok"); ?> >
</form>
</body>
</html>

64
lam/config/confmain.php Normal file
View File

@ -0,0 +1,64 @@
<?
/*
$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
*/
// check if password was entered
if (! $passwd) {
require('conflogin.php');
exit;
}
// check if password is valid
include_once ('config.php');
$conf = new Config();
if (!(($conf->get_Passwd()) == $passwd)) {
require('conflogin.php');
exit;
}
echo ("<html>\n");
echo ("<head>\n");
echo ("<title>" . _("LDAP Account Manager Configuration") . "</title>\n");
echo ("</head>\n");
echo ("<body>\n");
echo ("<form action=\"confsave.php\" method=\"post\">\n");
echo ("<b>" . _("Hostname") . ": </b> <input type=\"text\" name=\"host\" value=\"" . $conf->get_Host() . "\"><br>\n");
echo ("<b>" . _("Portnumber") . ": </b> <input type=\"text\" name=\"port\" value=\"" . $conf->get_Port() . "\"><br>\n");
if ($conf->get_SSL() == "True") echo ("<b>" . _("Use SSL") . ": </b> <input type=\"checkbox\" name=\"ssl\" checked><br><br>\n");
else echo ("<b>" . _("Use SSL") . ": </b> <input type=\"checkbox\" name=\"ssl\"><br><br>\n");
echo ("<b>" . _("List of valid users") . ": </b> <input type=\"text\" name=\"admins\" value=\"" . $conf->get_Adminstring() . "\"><br>\n");
echo _("Usernames must be seperated by semicolons (e.g. cn=admin,dc=yourcompany,dc=com ; uid=root,ou=people,dc=yourcompany,cd=com)\n");
echo ("<br><br><br>\n");
echo ("<b>" . _("New Password") . ": </b> <input type=\"password\" name=\"pass1\"><br>\n");
echo ("<b>" . _("Reenter Password") . ": </b> <input type=\"password\" name=\"pass2\"><br>\n");
echo ("<input type=\"hidden\" name=\"passwd\" value=\"" . $passwd . "\"><br>\n");
echo ("<br><br><br>\n");
echo ("<input type=\"submit\" name=\"submitconf\" value=\"" . _("Ok") . ">\n");
echo ("</form>\n");
echo ("</body>\n");
echo ("</html>\n");
?>

71
lam/config/confsave.php Normal file
View File

@ -0,0 +1,71 @@
<?
/*
$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
*/
include_once ('config.php');
$conf = new Config();
// check if password is correct
if ($passwd != $conf->get_Passwd()) {
require('confmain.php');
exit;
}
// check new preferences
if (chop($host) == "") {
echo _("<b>" . _("Hostname is empty!") . "</b>");
exit;
}
if (chop($port) == "") {
echo _("<b>" . _("Portnumber is empty!") . "</b>");
exit;
}
if (chop($admins) == "") {
echo _("<b>" . _("List of admin users is empty!") . "</b>");
exit;
}
// set new preferences
$conf->set_Host($host);
$conf->set_Port($port);
$conf->set_Adminstring($admins);
if ($ssl == "on") $conf->set_SSL("True");
else $conf->set_SSL("False");
// check if password was changed
if ($pass1 != $pass2) {
echo _("<b>" . _("Passwords are different!") . "</b>");
exit;
}
if ($pass1 != "") {
$conf->set_Passwd($pass1);
echo ("<b>" . _("Password changed!") . "</b><br><br>");
}
// save settings
echo ("<b>" . _("Saving the following settings:") . "</b><br><br>");
$conf->printconf();
if ($conf->save()) echo ("<br><br><b>" . _("Failed!") . "</b>");
else echo ("<br><br><b>" . _("Successfully saved!") . "</b>");
?>