diff --git a/lam/lib/config.inc b/lam/lib/config.inc index 9f485c3b..fd271e2c 100644 --- a/lam/lib/config.inc +++ b/lam/lib/config.inc @@ -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; + } + } + +} + ?> diff --git a/lam/templates/config/conflogin.php b/lam/templates/config/conflogin.php index 60d0173e..b69b88af 100644 --- a/lam/templates/config/conflogin.php +++ b/lam/templates/config/conflogin.php @@ -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 ("




+
- + "); + if ($message) echo (""); ?> + - + + + + + + +
" . $message . "
" . $message . "
+ + + +
 
+ +
+ +








+ + +

+ +

+ diff --git a/lam/templates/config/confmain.php b/lam/templates/config/confmain.php index 105e023f..ebf3cd53 100644 --- a/lam/templates/config/confmain.php +++ b/lam/templates/config/confmain.php @@ -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(""); } // 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 ("

"); // password for configuration echo ("

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

\n"); + echo ("\n"); echo ("\n"); echo ("\n"); diff --git a/lam/templates/config/confsave.php b/lam/templates/config/confsave.php index e66a1d86..3dad826b 100644 --- a/lam/templates/config/confsave.php +++ b/lam/templates/config/confsave.php @@ -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 ("" . _("The following settings were saved:") . "

"); +echo ("" . _("The following settings were saved to profile:") . " " . $filename . "

"); $conf->printconf(); echo ("




" . _("Back to Login") . ""); @@ -237,5 +238,6 @@ unset($_SESSION['scriptpath']); unset($_SESSION['scriptserver']); unset($_SESSION['samba3']); unset($_SESSION['domainSID']); +unset($_SESSION['filename']); ?> diff --git a/lam/tests/conf-test.php b/lam/tests/conf-test.php index 7c556974..52c9e29f 100644 --- a/lam/tests/conf-test.php +++ b/lam/tests/conf-test.php @@ -24,7 +24,7 @@ $Id$ */ include ("../lib/config.inc"); -$conf = new Config(); +$conf = new Config('default'); echo ""; echo (" Current Config

"); $conf->printconf(); @@ -82,7 +82,7 @@ $conf->save(); echo ("done
"); // 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 ("
Saving ServerURL failed!
"); $adm_arr = $conf->get_Admins(); if ($adm_arr[0] != "uid=test,o=test,dc=org") echo ("
Saving admins failed!" . $adm_arr[0] . "
");