updated to new configuration system

This commit is contained in:
Roland Gruber 2003-07-06 10:24:41 +00:00
parent 339c7f6f0e
commit cd08a7b923
5 changed files with 198 additions and 41 deletions

View File

@ -39,7 +39,28 @@ function setlanguage() {
else echo _("Language not defined in session!");
}
// returns an array of String with all available configuration profiles (without .conf)
function getConfigProfiles() {
$dir = dir(substr(__FILE__, 0, strlen(__FILE__) - 15) . "/config");
$ret = array();
$pos = 0;
while ($entry = $dir->read()){
$ext = substr($entry, strlen($entry)-5, 5);
$name = substr($entry, 0, strlen($entry)-5);
if ($ext == ".conf") {
$ret[$pos] = $name;
$pos ++;
}
}
sort($ret);
return $ret;
}
/*
// class Config
*/
// manages .conf files
class Config {
// server address (e.g. ldap://127.0.0.1:389)
@ -93,14 +114,22 @@ class Config {
// Samba 3 domain SIDs
var $domainSID;
// constructor, loads preferences from ../config/lam.conf
function Config() {
// name of configuration file
var $file;
// constructor, loads preferences from config file
function Config($file=0) {
if (!is_string($file)) {
$profiles = getConfigProfiles();
$file = $profiles[0];
}
$this->file = $file;
$this->reload();
}
// reloads preferences from ../config/lam.conf
// reloads preferences from config file
function reload() {
$conffile = substr(__FILE__, 0, strlen(__FILE__) - 15) . "/config/lam.conf";
$conffile = substr(__FILE__, 0, strlen(__FILE__) - 15) . "/config/" . $this->file . ".conf";
if (is_file($conffile) == True) {
$file = fopen($conffile, "r");
while (!feof($file)) {
@ -197,13 +226,13 @@ class Config {
fclose($file);
}
else {
StatusMessage("ERROR", "", _("Unable to load lam.conf!") . " (" . $conffile . ")");
StatusMessage("ERROR", "", _("Unable to load configuration!") . " (" . $conffile . ")");
}
}
// saves preferences to ../config/lam.conf
// saves preferences to config file
function save() {
$conffile = substr(__FILE__, 0, strlen(__FILE__) - 15) . "/config/lam.conf";
$conffile = substr(__FILE__, 0, strlen(__FILE__) - 15) . "/config/" . $this->file . ".conf";
if (is_file($conffile) == True) {
// booleans to check if value was already saved
$save_serverURL = $save_passwd = $save_admins = $save_suffusr = $save_suffgrp = $save_suffhst =
@ -212,12 +241,12 @@ class Config {
$save_scriptPath = $save_scriptServer = $save_samba3 = $save_domainSID = False;
$file = fopen($conffile, "r");
$file_array = array();
// read lam.conf
// read config file
while (!feof($file)) {
array_push($file_array, fgets($file, 1024));
}
fclose($file);
// generate new lam.conf
// generate new configuration file
for ($i = 0; $i < sizeof($file_array); $i++) {
if (($file_array[$i] == "\n")||($file_array[$i][0] == "#")) continue; // ignore comments
// search for keywords
@ -327,36 +356,36 @@ class Config {
continue;
}
}
// check if we have to add new entries (e.g. if user upgraded LAM and has an old lam.conf)
if (!$save_serverURL == True) array_push($file_array, "\n\n# server address (e.g. ldap://localhost:389 or ldaps://localhost:636)\n" . "serverURL: " . $this->ServerURL);
if (!$save_passwd == True) array_push($file_array, "\n\n# password to change these preferences via webfrontend\n" . "passwd: " . $this->Passwd);
// check if we have to add new entries (e.g. if user upgraded LAM and has an old config file)
if (!$save_serverURL == True) array_push($file_array, "\n\n# server address (e.g. ldap://localhost:389 or ldaps://localhost:636)\n" . "serverURL: " . $this->ServerURL . "\n");
if (!$save_passwd == True) array_push($file_array, "\n\n# password to change these preferences via webfrontend\n" . "passwd: " . $this->Passwd . "\n");
if (!$save_admins == True) array_push($file_array, "\n\n# list of users who are allowed to use LDAP Account Manager\n" .
"# names have to be seperated by semicolons\n" .
"# e.g. admins: cn=admin,dc=yourdomain,dc=org;cn=root,dc=yourdomain,dc=org\n" . "admins: " . $this->Admins);
"# e.g. admins: cn=admin,dc=yourdomain,dc=org;cn=root,dc=yourdomain,dc=org\n" . "admins: " . $this->Admins . "\n");
if (!$save_suffusr == True) array_push($file_array, "\n\n# suffix of users\n" .
"# e.g. ou=People,dc=yourdomain,dc=org\n" . "usersuffix: " . $this->Suff_users);
"# e.g. ou=People,dc=yourdomain,dc=org\n" . "usersuffix: " . $this->Suff_users . "\n");
if (!$save_suffgrp == True) array_push($file_array, "\n\n# suffix of groups\n" .
"# e.g. ou=Groups,dc=yourdomain,dc=org\n" . "groupsuffix: " . $this->Suff_groups);
"# e.g. ou=Groups,dc=yourdomain,dc=org\n" . "groupsuffix: " . $this->Suff_groups . "\n");
if (!$save_suffhst == True) array_push($file_array, "\n\n# suffix of Samba hosts\n" .
"# e.g. ou=machines,dc=yourdomain,dc=org\n" . "hostsuffix: " . $this->Suff_hosts);
if (!$save_minUID == True) array_push($file_array, "\n\n# minimum UID number\n" . "minUID: " . $this->MinUID);
if (!$save_maxUID == True) array_push($file_array, "\n\n# maximum UID number\n" . "maxUID: " . $this->MaxUID);
if (!$save_minGID == True) array_push($file_array, "\n\n# minimum GID number\n" . "minGID: " . $this->MinGID);
if (!$save_maxGID == True) array_push($file_array, "\n\n# maximum GID number\n" . "maxGID: " . $this->MaxGID);
if (!$save_minMach == True) array_push($file_array, "\n\n# minimum UID number for Samba hosts\n" . "minMachine: " . $this->MinMachine);
if (!$save_maxMach == True) array_push($file_array, "\n\n# maximum UID number for Samba hosts\n" . "maxMachine: " . $this->MaxMachine);
"# e.g. ou=machines,dc=yourdomain,dc=org\n" . "hostsuffix: " . $this->Suff_hosts . "\n");
if (!$save_minUID == True) array_push($file_array, "\n\n# minimum UID number\n" . "minUID: " . $this->MinUID . "\n");
if (!$save_maxUID == True) array_push($file_array, "\n\n# maximum UID number\n" . "maxUID: " . $this->MaxUID . "\n");
if (!$save_minGID == True) array_push($file_array, "\n\n# minimum GID number\n" . "minGID: " . $this->MinGID . "\n");
if (!$save_maxGID == True) array_push($file_array, "\n\n# maximum GID number\n" . "maxGID: " . $this->MaxGID . "\n");
if (!$save_minMach == True) array_push($file_array, "\n\n# minimum UID number for Samba hosts\n" . "minMachine: " . $this->MinMachine . "\n");
if (!$save_maxMach == True) array_push($file_array, "\n\n# maximum UID number for Samba hosts\n" . "maxMachine: " . $this->MaxMachine . "\n");
if (!$save_usrlstattr == True) array_push($file_array, "\n\n# list of attributes to show in user list\n# entries can either be predefined values (e.g. '#cn' or '#uid')" .
"\n# or individual ones (e.g. 'uid:User ID' or 'host:Host Name')\n# values have to be seperated by semicolons\n" . "userlistAttributes: " . $this->userlistAttributes);
"\n# or individual ones (e.g. 'uid:User ID' or 'host:Host Name')\n# values have to be seperated by semicolons\n" . "userlistAttributes: " . $this->userlistAttributes . "\n");
if (!$save_grplstattr == True) array_push($file_array, "\n\n# list of attributes to show in group list\n# entries can either be predefined values (e.g. '#cn' or '#gidNumber')" .
"\n# or individual ones (e.g. 'cn:Group Name')\n# values have to be seperated by semicolons\n" . "grouplistAttributes: " . $this->grouplistAttributes);
"\n# or individual ones (e.g. 'cn:Group Name')\n# values have to be seperated by semicolons\n" . "grouplistAttributes: " . $this->grouplistAttributes . "\n");
if (!$save_hstlstattr == True) array_push($file_array, "\n\n# list of attributes to show in host list\n# entries can either be predefined values (e.g. '#cn' or '#uid')" .
"\n# or individual ones (e.g. 'cn:Host Name')\n# values have to be seperated by semicolons\n" . "hostlistAttributes: " . $this->hostlistAttributes);
if (!$save_maxlstent == True) array_push($file_array, "\n\n# maximum number of rows to show in user/group/host lists\n" . "maxlistentries: " . $this->maxlistentries);
if (!$save_deflang == True) array_push($file_array, "\n\n# default language (a line from language.conf)\n" . "defaultLanguage: " . $this->defaultLanguage);
if (!$save_scriptPath == True) array_push($file_array, "\n\n# Path to external Script\n" . "scriptPath: " . $this->scriptPath);
if (!$save_scriptServer == True) array_push($file_array, "\n\n# Server of external Script\n" . "scriptServer: " . $this->scriptServer);
if (!$save_samba3 == True) array_push($file_array, "\n\n# Set to \"yes\" only if you use the new Samba 3.x schema.\n" . "samba3: " . $this->samba3);
if (!$save_domainSID == True) array_push($file_array, "\n\n# Samba 3 domain SID. Set only if you use the new Samba 3.x schema.\n" . "domainSID: " . $this->domainSID);
"\n# or individual ones (e.g. 'cn:Host Name')\n# values have to be seperated by semicolons\n" . "hostlistAttributes: " . $this->hostlistAttributes . "\n");
if (!$save_maxlstent == True) array_push($file_array, "\n\n# maximum number of rows to show in user/group/host lists\n" . "maxlistentries: " . $this->maxlistentries . "\n");
if (!$save_deflang == True) array_push($file_array, "\n\n# default language (a line from language.conf)\n" . "defaultLanguage: " . $this->defaultLanguage . "\n");
if (!$save_scriptPath == True) array_push($file_array, "\n\n# Path to external Script\n" . "scriptPath: " . $this->scriptPath . "\n");
if (!$save_scriptServer == True) array_push($file_array, "\n\n# Server of external Script\n" . "scriptServer: " . $this->scriptServer . "\n");
if (!$save_samba3 == True) array_push($file_array, "\n\n# Set to \"yes\" only if you use the new Samba 3.x schema.\n" . "samba3: " . $this->samba3 . "\n");
if (!$save_domainSID == True) array_push($file_array, "\n\n# Samba 3 domain SID. Set only if you use the new Samba 3.x schema.\n" . "domainSID: " . $this->domainSID . "\n");
$file = fopen($conffile, "w");
if ($file) {
for ($i = 0; $i < sizeof($file_array); $i++) fputs($file, $file_array[$i]);
@ -677,4 +706,91 @@ class Config {
}
/*
// class CfgMain
*/
// manages config.cfg
class CfgMain {
// default profile
var $default;
// password to change config.cfg
var $password;
// constructor, loads preferences from config file
function CfgMain() {
$this->reload();
}
// reloads preferences from config file config.cfg
function reload() {
$conffile = substr(__FILE__, 0, strlen(__FILE__) - 15) . "/config/config.cfg";
if (is_file($conffile) == True) {
$file = fopen($conffile, "r");
while (!feof($file)) {
$line = fgets($file, 1024);
if (($line == "\n")||($line[0] == "#")) continue; // ignore comments
// search keywords
if (substr($line, 0, 10) == "password: ") {
$this->password = chop(substr($line, 10, strlen($line)-10));
continue;
}
if (substr($line, 0, 9) == "default: ") {
$this->default = chop(substr($line, 9, strlen($line)-9));
continue;
}
}
fclose($file);
}
else {
StatusMessage("ERROR", "", _("Unable to load configuration!") . " (" . $conffile . ")");
}
}
// saves preferences to config file config.cfg
function save() {
$conffile = substr(__FILE__, 0, strlen(__FILE__) - 15) . "/config/config.cfg";
if (is_file($conffile) == True) {
// booleans to check if value was already saved
$save_password = $save_default = False;
$file = fopen($conffile, "r");
$file_array = array();
// read config file
while (!feof($file)) {
array_push($file_array, fgets($file, 1024));
}
fclose($file);
// generate new configuration file
for ($i = 0; $i < sizeof($file_array); $i++) {
if (($file_array[$i] == "\n")||($file_array[$i][0] == "#")) continue; // ignore comments
// search for keywords
if (substr($file_array[$i], 0, 10) == "password: ") {
$file_array[$i] = "password: " . $this->password . "\n";
$save_password = True;
continue;
}
if (substr($file_array[$i], 0, 9) == "default: ") {
$file_array[$i] = "default: " . $this->default . "\n";
$save_default = True;
continue;
}
}
}
// check if we have to add new entries (e.g. if user upgraded LAM and has an old config file)
if (!$save_password == True) array_push($file_array, "\n\n# password to add/delete/rename configuration profiles\n" . "password: " . $this->password);
if (!$save_default == True) array_push($file_array, "\n\n# default profile, without \".conf\"\n" . "default: " . $this->default);
$file = fopen($conffile, "w");
if ($file) {
for ($i = 0; $i < sizeof($file_array); $i++) fputs($file, $file_array[$i]);
fclose($file);
}
else {
StatusMessage("ERROR", "", _("Cannot open config file!") . " (" . $conffile . ")");
exit;
}
}
}
?>

View File

@ -14,7 +14,7 @@ $Id$
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
@ -23,6 +23,9 @@ $Id$
Login page to change the preferences.
*/
include_once('../../lib/config.inc');
include_once('../../lib/status.inc');
// start session
session_save_path("../../sess");
@session_start();
@ -46,21 +49,53 @@ echo ("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http:/
<img src="../../graphics/banner.jpg" border=1 alt="LDAP Account Manager"></a>
</p>
<hr><br><br>
<!-- form to change existing profiles -->
<form action="confmain.php" method="post">
<table border=0 align="center">
<tr>
<td colspan=3 align="center"><b> <?php echo _("Password to enter preferences:"); ?> </b></td>
<td colspan=4 align="center"><b> <?php echo _("Please enter password to change preferences:"); ?> </b></td>
</tr>
<?php
// print message if login was incorrect
if ($message) echo ("<tr><td colspan=3 align=\"center\"><font color=red>" . $message . "</font></td></tr>");
if ($message) echo ("<tr><td colspan=4 align=\"center\"><font color=red>" . $message . "</font></td></tr>");
?>
<tr>
<td>
<select size=1 name="filename">
<?php
$files = getConfigProfiles();
$conf = new CfgMain();
$defaultprofile = $conf->default;
for ($i = 0; $i < sizeof($files); $i++) {
if ($files[$i] == $defaultprofile) echo ("<option selected>" . $files[$i] . "</option>\n");
else echo ("<option>" . $files[$i] . "</option>\n");
}
?>
</select>
</td>
<td align="center"><input type="password" name="passwd"></td>
<td><input type="submit" name="submit" value= <?php echo _("Ok"); ?> </td>
<td>
<input type="submit" name="submit" value= <?php echo _("Ok"); ?>
</td>
<td><a href="../help.php?HelpNumber=200" target="lamhelp"><?php echo _("Help") ?></a></td>
</tr>
<tr>
<td colspan=3>&nbsp;</td>
</tr>
<tr>
<td colspan=3 align="center">
<b><a href="profmanage.php"><?php echo _("Manage profiles") ?></a></b>
</td>
</tr>
</table>
</form>
<p><br><br><br><br><br><br><br></p>
<!-- back to login page -->
<p>
<a href="../login.php"> <?php echo _("Back to Login"); ?> </a>
</p>
</body>
</html>

View File

@ -62,10 +62,11 @@ if ($_POST['back'] || $_POST['submitconf']){
else $scriptpath = "";
if ($_POST['scriptserver']) $scriptserver = $_POST['scriptserver'];
else $scriptserver = "";
if ($_POST['filename']) $filename = $_POST['filename'];
session_register('passwd', 'passwd1', 'passwd2', 'serverurl', 'admins', 'suffusers',
'suffgroups', 'suffhosts', 'minUID', 'maxUID', 'minGID', 'maxGID', 'minMach',
'maxMach', 'usrlstattr', 'grplstattr', 'hstlstattr', 'maxlistentries', 'language',
'scriptpath', 'scriptserver', 'samba3', 'domainSID');
'scriptpath', 'scriptserver', 'samba3', 'domainSID', 'filename');
echo("<meta http-equiv=\"refresh\" content=\"0; URL=confsave.php\">");
}
// back to login
@ -89,7 +90,7 @@ if (! $passwd) {
// check if password is valid
// if not: load login page
include_once ('../../lib/config.inc');
$conf = new Config();
$conf = new Config($_POST['filename']);
if (!(($conf->get_Passwd()) == $passwd)) {
$message = _("The password is invalid! Please try again.");
require('conflogin.php');
@ -340,6 +341,9 @@ echo ("<p></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=\"" . $_POST['filename'] . "\"></p>\n");
echo ("</form>\n");
echo ("</body>\n");
echo ("</html>\n");

View File

@ -29,7 +29,7 @@ session_save_path("../../sess");
session_start();
include_once ('../../lib/config.inc');
$conf = new Config();
$conf = new Config($_SESSION['filename']);
// get data from session
if ($_SESSION['passwd']) $passwd = $_SESSION['passwd'];
@ -55,6 +55,7 @@ if ($_SESSION['scriptpath']) $scriptpath = $_SESSION['scriptpath'];
if ($_SESSION['scriptserver']) $scriptserver = $_SESSION['scriptserver'];
if ($_SESSION['samba3']) $samba3 = $_SESSION['samba3'];
if ($_SESSION['domainSID']) $domainSID = $_SESSION['domainSID'];
if ($_SESSION['filename']) $filename = $_SESSION['filename'];
// check if password is correct
// if not: load login page
@ -207,7 +208,7 @@ if ($pass1 != "") {
}
// save settings and display new settings
$conf->save();
echo ("<b>" . _("The following settings were saved:") . "</b><br><br>");
echo ("<b>" . _("The following settings were saved to profile:") . " </b>" . $filename . "<br><br>");
$conf->printconf();
echo ("<br><br><br><br><br><a href=\"../login.php\" target=\"_top\">" . _("Back to Login") . "</a>");
@ -237,5 +238,6 @@ unset($_SESSION['scriptpath']);
unset($_SESSION['scriptserver']);
unset($_SESSION['samba3']);
unset($_SESSION['domainSID']);
unset($_SESSION['filename']);
?>

View File

@ -24,7 +24,7 @@ $Id$
*/
include ("../lib/config.inc");
$conf = new Config();
$conf = new Config('default');
echo "<html><head><title></title><link rel=\"stylesheet\" type=\"text/css\" href=\"../style/layout.css\"></head><body>";
echo ("<b> Current Config</b><br><br>");
$conf->printconf();
@ -82,7 +82,7 @@ $conf->save();
echo ("done<br>");
// at last all preferences are read from lam.conf and compared
echo ("Loading and comparing...");
$conf = new Config();
$conf = new Config('default');
if ($conf->get_ServerURL() != "ldap://123.345.678.123:777") echo ("<br><font color=\"#FF0000\">Saving ServerURL failed!</font><br>");
$adm_arr = $conf->get_Admins();
if ($adm_arr[0] != "uid=test,o=test,dc=org") echo ("<br><font color=\"#FF0000\">Saving admins failed!" . $adm_arr[0] . "</font><br>");