LDAPAccountManager/lam/lib/config.inc

903 lines
27 KiB
PHP
Raw Normal View History

2003-02-17 18:21:44 +00:00
<?php
2003-02-21 22:01:01 +00:00
/*
$Id$
2003-02-21 22:09:59 +00:00
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
2004-02-01 12:33:21 +00:00
Copyright (C) 2003 - 2004 Roland Gruber
2003-02-21 22:01:01 +00:00
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.
2003-02-21 22:01:01 +00:00
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.
2003-02-21 22:01:01 +00:00
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
2004-05-31 14:04:00 +00:00
*/
2003-03-15 11:42:08 +00:00
2004-05-31 14:04:00 +00:00
/**
* This file includes functions to manage the configuration files.
*
* @package configuration
* @author Roland Gruber
2003-02-21 22:01:01 +00:00
*/
2004-05-31 14:04:00 +00:00
/** Used to print messages. */
include_once("status.inc");
2004-05-31 14:04:00 +00:00
/** Used to get module information. */
2004-02-01 12:33:21 +00:00
include_once("modules.inc");
/**
2004-05-31 14:04:00 +00:00
* Sets language settings for automatic translation
*/
function setlanguage() {
if (!isset($_SESSION['language'])) {
$_SESSION['language'] = "en_GB.utf8:UTF-8:English (Great Britain)";
}
$language = explode(":", $_SESSION['language']);
putenv("LANG=" . $language[0]); // e.g. LANG=de_DE
setlocale(LC_ALL, $language[0]); // set LC_ALL to de_DE
$locdir = substr(__FILE__, 0, strlen(__FILE__) - 15) . "/locale"; // set path to translations
bindtextdomain("messages", $locdir);
textdomain("messages");
header("Content-type: text/html; charset=" . $language[1], true);
}
2003-02-21 22:01:01 +00:00
/**
2004-05-31 14:04:00 +00:00
* Returns an array of string with all available configuration profiles (without .conf)
*
* @return array profile names
*/
2003-07-06 10:24:41 +00:00
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);
// check if extension is right, add to profile list
2003-07-06 10:24:41 +00:00
if ($ext == ".conf") {
$ret[$pos] = $name;
$pos ++;
}
}
sort($ret);
return $ret;
}
2003-02-17 18:21:44 +00:00
/**
2004-05-31 14:04:00 +00:00
* Prints a meta refresh page
*
2004-05-31 14:04:00 +00:00
* @param string $page the URL of the target page
*/
2003-08-28 12:41:47 +00:00
function metaRefresh($page) {
echo $_SESSION['header'];
echo "<meta http-equiv=\"refresh\" content=\"0; URL=" . $page . "\">\n";
2003-11-29 12:54:00 +00:00
echo "<title></title>\n";
2003-08-28 12:41:47 +00:00
echo "</head>\n";
echo "<body>\n";
// print link if refresh does not work
echo "<p>\n";
echo "<a href=\"" . $page . "\">" . _("Click here if you are not directed to the next page.") . "</a>\n";
echo "</p>\n";
echo "</body>\n";
echo "</html>\n";
}
2003-07-06 10:24:41 +00:00
/**
* This class manages .conf files.
2004-05-31 14:04:00 +00:00
*
* @package configuration
2003-07-06 10:24:41 +00:00
*/
2003-02-17 18:21:44 +00:00
class Config {
2004-05-31 14:04:00 +00:00
/** Server address (e.g. ldap://127.0.0.1:389) */
2004-01-30 17:06:28 +00:00
var $ServerURL;
2004-05-31 14:04:00 +00:00
/** Array of string: users with admin rights */
2004-01-30 17:06:28 +00:00
var $Admins;
2004-05-31 14:04:00 +00:00
/** Password to edit preferences */
2004-01-30 17:06:28 +00:00
var $Passwd;
2003-02-17 18:21:44 +00:00
2004-05-31 14:04:00 +00:00
/** LDAP suffix for users */
2004-01-30 17:06:28 +00:00
var $usersuffix;
2004-05-31 14:04:00 +00:00
/** LDAP suffix for groups */
2004-01-30 17:06:28 +00:00
var $groupsuffix;
2004-05-31 14:04:00 +00:00
/** LDAP suffix for Samba hosts */
2004-01-30 17:06:28 +00:00
var $hostsuffix;
2004-05-31 14:04:00 +00:00
/** LDAP suffix for Samba 3 domains */
2004-01-30 17:06:28 +00:00
var $domainsuffix;
2003-07-25 14:12:07 +00:00
2004-05-31 14:04:00 +00:00
/** Attributes that are shown in the user list */
2004-01-30 17:06:28 +00:00
var $userlistAttributes;
2004-05-31 14:04:00 +00:00
/** Attributes that are shown in the group list */
2004-01-30 17:06:28 +00:00
var $grouplistAttributes;
2004-05-31 14:04:00 +00:00
/** Attributes that are shown in the host list */
2004-01-30 17:06:28 +00:00
var $hostlistAttributes;
2003-05-07 14:29:44 +00:00
2004-05-31 14:04:00 +00:00
/** Maximum number of rows shown in user/group/host lists */
2004-01-30 17:06:28 +00:00
var $maxlistentries;
2004-05-31 14:04:00 +00:00
/** Default language */
2004-01-30 17:06:28 +00:00
var $defaultLanguage;
2003-05-09 16:22:46 +00:00
2004-07-18 10:18:25 +00:00
/** module settings */
var $moduleSettings = array();
/**
* Path to external lamdaemon script on server where it is executed
2004-05-31 14:04:00 +00:00
*
* This is used for managing quota and home directories.
* optional setting, may not be defined
*/
2004-01-30 17:06:28 +00:00
var $scriptPath;
/**
2004-05-31 14:04:00 +00:00
* Server where lamdaemon script is executed
*
* This is used for managing quota and home directories.
* optional setting, may not be defined
*/
var $scriptServer;
2003-05-28 15:37:48 +00:00
/** LDAP cache timeout */
2004-01-30 17:06:28 +00:00
var $cachetimeout;
2003-08-18 15:21:27 +00:00
var $usermodules = "posixAccount,shadowAccount,quota";
/** Account modules for groups */
var $groupmodules = "posixGroup,quota";
/** Account modules for hosts */
var $hostmodules = "account,sambaSamAccount";
2004-01-30 17:06:28 +00:00
2004-05-31 14:04:00 +00:00
/** Name of configuration file */
2004-01-30 17:06:28 +00:00
var $file;
2003-07-06 10:24:41 +00:00
2004-05-31 14:04:00 +00:00
/** List of all settings in config file */
2003-09-21 20:10:52 +00:00
var $settings = array("ServerURL", "Passwd", "Admins", "usersuffix", "groupsuffix", "hostsuffix",
"domainsuffix", "userlistAttributes", "grouplistAttributes", "hostlistAttributes", "maxlistentries",
"defaultLanguage", "scriptPath", "scriptServer", "cachetimeout",
2004-07-18 10:18:25 +00:00
"usermodules", "groupmodules", "hostmodules", "modules");
2003-09-21 20:10:52 +00:00
/**
2004-05-31 14:04:00 +00:00
* Loads preferences from config file
*
2004-09-26 08:46:56 +00:00
* @param integer $file Index number in config file array
*/
function Config($file = 0) {
// load first profile if none is given
2003-09-21 20:10:52 +00:00
if (!is_string($file)) {
$profiles = getConfigProfiles();
$file = $profiles[0];
}
$this->file = $file;
$this->reload();
2003-07-06 10:24:41 +00:00
}
2004-07-18 10:18:25 +00:00
/**
* Reloads preferences from config file
*
* @return boolean true if file was readable
*/
2003-09-15 16:24:44 +00:00
function reload() {
$conffile = substr(__FILE__, 0, strlen(__FILE__) - 15) . "/config/" . $this->file . ".conf";
if (is_file($conffile) == True) {
2004-07-18 10:18:25 +00:00
$file = @fopen($conffile, "r");
if (!$file) return false; // abort if file is not readable
2003-09-15 16:24:44 +00:00
while (!feof($file)) {
$line = fgets($file, 1024);
$line = trim($line); // remove spaces at the beginning and end
if (($line == "")||($line[0] == "#")) continue; // ignore comments and empty lines
2003-09-15 16:24:44 +00:00
// search keywords
2003-09-21 20:10:52 +00:00
for ($i = 0; $i < sizeof($this->settings); $i++) {
$keyword = $this->settings[$i];
$keylen = strlen($keyword);
if (strtolower(substr($line, 0, $keylen + 2)) == strtolower($keyword . ": ")) {
2004-07-18 10:18:25 +00:00
// module settings
if (strtolower(substr($line, 0, $keylen + 2)) == "modules: ") {
$option = substr($line, $keylen + 2, strlen($line) - $keylen - 2);
$pos = strpos($option, ":");
$this->moduleSettings[substr($option, 0, $pos)] = explode("+::+", substr($option, $pos + 2, strlen($option) - $pos - 2));
2004-07-18 10:18:25 +00:00
}
// general settings
else {
$this->$keyword = substr($line, $keylen + 2, strlen($line) - $keylen - 2);
}
2003-09-21 20:10:52 +00:00
break;
}
2003-09-15 16:24:44 +00:00
}
}
fclose($file);
}
// check modules
$scopes = array('user', 'group', 'host');
for ($s = 0; $s < sizeof($scopes); $s++) {
$scope = $scopes[$s];
$moduleVar = $scope . "modules";
$modules = explode(",", $this->$moduleVar);
$available = getAvailableModules($scope);
// only return available modules
$ret = array();
for ($i = 0; $i < sizeof($modules); $i++) {
if (in_array($modules[$i], $available)) $ret[] = $modules[$i];
}
$this->$moduleVar = implode(",", $ret);
}
2004-07-18 10:18:25 +00:00
return true;
2003-09-15 16:24:44 +00:00
}
2004-05-31 14:04:00 +00:00
/** Saves preferences to config file */
2003-08-18 15:21:27 +00:00
function save() {
$conffile = substr(__FILE__, 0, strlen(__FILE__) - 15) . "/config/" . $this->file . ".conf";
if (is_file($conffile) == True) {
$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
2003-09-21 20:10:52 +00:00
$saved = array(); // includes all settings which have been saved
2004-07-18 10:18:25 +00:00
$mod_saved = array(); // includes all module settings which have been saved
2003-08-18 15:21:27 +00:00
for ($i = 0; $i < sizeof($file_array); $i++) {
2003-09-21 20:10:52 +00:00
$line = trim($file_array[$i]);
if (($line == "")||($line[0] == "#")) continue; // ignore comments and empty lines
2003-08-18 15:21:27 +00:00
// search for keywords
2003-09-21 20:10:52 +00:00
for ($k = 0; $k < sizeof($this->settings); $k++) {
$keyword = $this->settings[$k];
$keylen = strlen($keyword);
2003-09-30 18:42:14 +00:00
if (strtolower(substr($line, 0, $keylen + 1)) == strtolower($keyword . ":")) {
2004-07-18 10:18:25 +00:00
// module settings
if (strtolower(substr($line, 0, $keylen + 2)) == "modules: ") {
$option = substr($line, $keylen + 2, strlen($line) - $keylen - 2);
$pos = strpos($option, ":");
$name = substr($option, 0, $pos);
2004-07-26 15:15:30 +00:00
if (!isset($this->moduleSettings[$name])) continue;
$file_array[$i] = "modules: " . $name . ": " . implode("+::+", $this->moduleSettings[$name]) . "\n";
2004-07-18 10:18:25 +00:00
$mod_saved[] = $name; // mark keyword as saved
}
// general settings
else {
$file_array[$i] = $keyword . ": " . $this->$keyword . "\n";
$saved[] = $keyword; // mark keyword as saved
}
2003-09-21 20:10:52 +00:00
break;
}
2003-08-18 15:21:27 +00:00
}
}
// check if we have to add new entries (e.g. if user upgraded LAM and has an old config file)
2003-09-21 20:10:52 +00:00
if (!in_array("ServerURL", $saved)) array_push($file_array, "\n\n# server address (e.g. ldap://localhost:389 or ldaps://localhost:636)\n" . "serverURL: " . $this->ServerURL . "\n");
if (!in_array("Passwd", $saved)) array_push($file_array, "\n\n# password to change these preferences via webfrontend\n" . "passwd: " . $this->Passwd . "\n");
if (!in_array("Admins", $saved)) array_push($file_array, "\n\n# list of users who are allowed to use LDAP Account Manager\n" .
2003-08-18 15:21:27 +00:00
"# names have to be seperated by semicolons\n" .
2003-09-21 20:10:52 +00:00
"# e.g. admins: cn=admin,dc=yourdomain,dc=org;cn=root,dc=yourdomain,dc=org\n" . "admins: " . $this->Admins . "\n");
if (!in_array("usersuffix", $saved)) array_push($file_array, "\n\n# suffix of users\n" .
2003-09-19 19:49:45 +00:00
"# e.g. ou=People,dc=yourdomain,dc=org\n" . "usersuffix: " . $this->usersuffix . "\n");
2003-09-21 20:10:52 +00:00
if (!in_array("groupsuffix", $saved)) array_push($file_array, "\n\n# suffix of groups\n" .
2003-09-19 19:49:45 +00:00
"# e.g. ou=Groups,dc=yourdomain,dc=org\n" . "groupsuffix: " . $this->groupsuffix . "\n");
2003-09-21 20:10:52 +00:00
if (!in_array("hostsuffix", $saved)) array_push($file_array, "\n\n# suffix of Samba hosts\n" .
2003-09-19 19:49:45 +00:00
"# e.g. ou=machines,dc=yourdomain,dc=org\n" . "hostsuffix: " . $this->hostsuffix . "\n");
2003-09-21 20:10:52 +00:00
if (!in_array("domainsuffix", $saved)) array_push($file_array, "\n\n# suffix of Samba 3 domains\n" .
2003-09-19 19:49:45 +00:00
"# e.g. ou=domains,dc=yourdomain,dc=org\n" . "domainsuffix: " . $this->domainsuffix . "\n");
2003-09-30 18:42:14 +00:00
if (!in_array("userlistAttributes", $saved)) 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')" .
2003-08-18 15:21:27 +00:00
"\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");
2003-09-30 18:42:14 +00:00
if (!in_array("grouplistAttributes", $saved)) 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')" .
2003-08-18 15:21:27 +00:00
"\n# or individual ones (e.g. 'cn:Group Name')\n# values have to be seperated by semicolons\n" . "grouplistAttributes: " . $this->grouplistAttributes . "\n");
2003-09-30 18:42:14 +00:00
if (!in_array("hostlistAttributes", $saved)) 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')" .
2003-08-18 15:21:27 +00:00
"\n# or individual ones (e.g. 'cn:Host Name')\n# values have to be seperated by semicolons\n" . "hostlistAttributes: " . $this->hostlistAttributes . "\n");
2003-09-30 18:42:14 +00:00
if (!in_array("maxlistentries", $saved)) array_push($file_array, "\n\n# maximum number of rows to show in user/group/host lists\n" . "maxlistentries: " . $this->maxlistentries . "\n");
if (!in_array("defaultLanguage", $saved)) array_push($file_array, "\n\n# default language (a line from config/language)\n" . "defaultLanguage: " . $this->defaultLanguage . "\n");
if (!in_array("scriptPath", $saved)) array_push($file_array, "\n\n# Path to external Script\n" . "scriptPath: " . $this->scriptPath . "\n");
if (!in_array("scriptServer", $saved)) array_push($file_array, "\n\n# Server of external Script\n" . "scriptServer: " . $this->scriptServer . "\n");
if (!in_array("cachetimeout", $saved)) array_push($file_array, "\n\n# Number of minutes LAM caches LDAP searches.\n" . "cacheTimeout: " . $this->cachetimeout . "\n");
2004-02-01 12:33:21 +00:00
if (!in_array("usermodules", $saved)) array_push($file_array, "\n\n# List of used user modules\n" . "usermodules: " . $this->usermodules . "\n");
if (!in_array("groupmodules", $saved)) array_push($file_array, "\n\n# List of used group modules\n" . "groupmodules: " . $this->groupmodules . "\n");
if (!in_array("hostmodules", $saved)) array_push($file_array, "\n\n# List of used host modules\n" . "hostmodules: " . $this->hostmodules . "\n");
2004-07-18 10:18:25 +00:00
// check if all module settings were added
$m_settings = array_keys($this->moduleSettings);
for ($i = 0; $i < sizeof($m_settings); $i++) {
if (!in_array($m_settings[$i], $mod_saved)) {
2004-07-24 11:50:44 +00:00
array_push($file_array, "modules: " . $m_settings[$i] . ": " . implode("+::+", $this->moduleSettings[$m_settings[$i]]) . "\n");
2004-07-18 10:18:25 +00:00
}
}
2003-08-18 15:21:27 +00:00
$file = fopen($conffile, "w");
if ($file) {
for ($i = 0; $i < sizeof($file_array); $i++) fputs($file, $file_array[$i]);
fclose($file);
2003-10-01 15:01:29 +00:00
@chmod ($conffile, 0600);
2003-08-18 15:21:27 +00:00
}
else {
StatusMessage("ERROR", "", _("Cannot open config file!") . " (" . $conffile . ")");
exit;
}
2003-06-24 15:50:38 +00:00
}
}
2004-05-31 14:04:00 +00:00
/** Prints current preferences */
2003-08-18 15:21:27 +00:00
function printconf() {
2004-07-18 10:18:25 +00:00
echo "<b>" . _("Server address") . ": </b>" . $this->ServerURL . "<br>\n";
echo "<b>" . _("Cache timeout") . ": </b>" . $this->cachetimeout . "<br>\n";
echo "<b>" . _("UserSuffix") . ": </b>" . $this->usersuffix . "<br>\n";
echo "<b>" . _("GroupSuffix") . ": </b>" . $this->groupsuffix . "<br>\n";
echo "<b>" . _("HostSuffix") . ": </b>" . $this->hostsuffix . "<br>\n";
echo "<b>" . _("DomainSuffix") . ": </b>" . $this->domainsuffix . "<br>\n";
echo "<b>" . _("Attributes in User List") . ": </b>" . $this->userlistAttributes . "<br>\n";
echo "<b>" . _("Attributes in Group List") . ": </b>" . $this->grouplistAttributes . "<br>\n";
echo "<b>" . _("Attributes in Host List") . ": </b>" . $this->hostlistAttributes . "<br>\n";
echo "<b>" . _("Maximum list entries") . ": </b>" . $this->maxlistentries . "<br>\n";
echo "<b>" . _("Default language") . ": </b>" . $this->defaultLanguage . "<br>\n";
echo "<b>" . _("Path to external script") . ": </b>" . $this->scriptPath . "<br>\n";
echo "<b>" . _("Server of external script") . ": </b>" . $this->scriptServer . "<br>\n";
echo "<b>" . _("List of valid users") . ": </b>" . $this->Admins . "<br>\n";
echo "<b>" . _("User modules") . ": </b>" . $this->usermodules . "<br>\n";
echo "<b>" . _("Group modules") . ": </b>" . $this->groupmodules . "<br>\n";
echo "<b>" . _("Host modules") . ": </b>" . $this->hostmodules . "<br><br>\n";
echo "<b>" . _("Module settings") . ": </b><br>\n";
echo "<ul>\n";
$names = array_keys($this->moduleSettings);
$descriptions = getConfigDescriptions();
$descriptions = $descriptions['descriptions'];
for ($i = 0; $i < sizeof($names); $i++) {
echo "<li><b>";
// print description if available
if (isset($descriptions[$names[$i]])) echo $descriptions[$names[$i]];
else echo $names[$i];
echo ": </b>" . implode(", ", $this->moduleSettings[$names[$i]]) . "</li>\n";
}
2004-07-18 10:18:25 +00:00
echo "</ul>\n";
2003-08-18 15:21:27 +00:00
}
2003-03-08 10:10:19 +00:00
2003-08-18 15:21:27 +00:00
// functions to read/write preferences
2003-05-09 16:22:46 +00:00
/**
2004-05-31 14:04:00 +00:00
* Returns the server address as string
*
2004-09-26 08:46:56 +00:00
* @return string server address
*/
2003-08-18 15:21:27 +00:00
function get_ServerURL() {
return $this->ServerURL;
}
/**
2004-05-31 14:04:00 +00:00
* Sets the server address
*
2004-09-26 08:46:56 +00:00
* @param string $value new server address
* @return boolean true if $value has correct format
*/
2003-07-30 21:23:48 +00:00
function set_ServerURL($value) {
if (is_string($value)) $this->ServerURL = $value;
else return false;
return true;
}
2003-05-09 16:22:46 +00:00
/**
2004-05-31 14:04:00 +00:00
* Returns an array of string with all admin names
*
2004-09-26 08:46:56 +00:00
* @return array the admin names
*/
2003-07-30 21:23:48 +00:00
function get_Admins() {
2003-09-21 20:10:52 +00:00
return explode(";", $this->Admins);
}
/**
2004-05-31 14:04:00 +00:00
* Returns all admin users seperated by semicolons
*
2004-09-26 08:46:56 +00:00
* @return string the admin string
*/
2003-07-30 21:23:48 +00:00
function get_Adminstring() {
2003-09-21 20:10:52 +00:00
return $this->Admins;
2003-07-30 21:23:48 +00:00
}
/**
2004-05-31 14:04:00 +00:00
* Sets the admin string
*
2004-09-26 08:46:56 +00:00
* @param string $value new admin string that contains all admin users seperated by semicolons
* @return boolean true if $value has correct format
*/
2003-07-30 21:23:48 +00:00
function set_Adminstring($value) {
if (is_string($value) &&
2004-08-18 19:20:29 +00:00
eregi("^[^;]+(;[^;]+)*$", $value)) {
2003-09-21 20:10:52 +00:00
$this->Admins = $value;
2003-07-30 21:23:48 +00:00
}
else return false;
return true;
}
/**
2004-05-31 14:04:00 +00:00
* Returns the password to access the preferences wizard
*
2004-09-26 08:46:56 +00:00
* @return string the password
*/
2003-07-30 21:23:48 +00:00
function get_Passwd() {
return $this->Passwd;
}
/**
2004-05-31 14:04:00 +00:00
* Sets the preferences wizard password
*
2004-09-26 08:46:56 +00:00
* @param string $value new password
* @return boolean true if $value has correct format
*/
2003-07-30 21:23:48 +00:00
function set_Passwd($value) {
if (is_string($value)) $this->Passwd = $value;
else return false;
return true;
}
/**
2004-05-31 14:04:00 +00:00
* Returns the LDAP suffix where users are saved
*
2004-09-26 08:46:56 +00:00
* @return string the user suffix
*/
2003-07-30 21:23:48 +00:00
function get_UserSuffix() {
2003-09-19 19:49:45 +00:00
return $this->usersuffix;
2003-07-30 21:23:48 +00:00
}
/**
2004-05-31 14:04:00 +00:00
* Sets the LDAP suffix where users are saved
*
2004-09-26 08:46:56 +00:00
* @param string $value new user suffix
* @return boolean true if $value has correct format
*/
2003-07-30 21:23:48 +00:00
function set_UserSuffix($value) {
2004-08-14 12:39:36 +00:00
if (is_string($value)) {
2003-09-19 19:49:45 +00:00
$this->usersuffix = $value;
2003-07-30 21:23:48 +00:00
}
else return false;
return true;
}
/**
* returns the LDAP suffix where groups are saved
*
2004-09-26 08:46:56 +00:00
* @return string the group suffix
*/
2003-07-30 21:23:48 +00:00
function get_GroupSuffix() {
2003-09-19 19:49:45 +00:00
return $this->groupsuffix;
2003-07-30 21:23:48 +00:00
}
/**
2004-05-31 14:04:00 +00:00
* Sets the LDAP suffix where groups are saved
*
2004-09-26 08:46:56 +00:00
* @param string $value new group suffix
* @return boolean true if $value has correct format
*/
2003-07-30 21:23:48 +00:00
function set_GroupSuffix($value) {
2004-08-14 12:39:36 +00:00
if (is_string($value)) {
2003-09-19 19:49:45 +00:00
$this->groupsuffix = $value;
2003-07-30 21:23:48 +00:00
}
else return false;
return true;
}
/**
* returns the LDAP suffix where hosts are saved
*
2004-09-26 08:46:56 +00:00
* @return string the host suffix
*/
2003-07-25 14:12:07 +00:00
function get_HostSuffix() {
2003-09-19 19:49:45 +00:00
return $this->hostsuffix;
2003-07-25 14:12:07 +00:00
}
/**
2004-05-31 14:04:00 +00:00
* Sets the LDAP suffix where hosts are saved
*
2004-09-26 08:46:56 +00:00
* @param string $value new host suffix
* @return boolean true if $value has correct format
*/
2003-07-25 14:12:07 +00:00
function set_HostSuffix($value) {
2004-01-27 18:05:35 +00:00
if (! $value) $this->hostsuffix = "";
2004-08-14 12:39:36 +00:00
elseif (is_string($value)) {
2003-09-19 19:49:45 +00:00
$this->hostsuffix = $value;
}
2003-07-30 21:23:48 +00:00
else return false;
return true;
2003-07-25 14:12:07 +00:00
}
/**
2004-05-31 14:04:00 +00:00
* Returns the LDAP suffix where domains are saved
*
2004-09-26 08:46:56 +00:00
* @return string the domain suffix
*/
2003-07-25 14:12:07 +00:00
function get_DomainSuffix() {
2003-09-19 19:49:45 +00:00
return $this->domainsuffix;
2003-07-25 14:12:07 +00:00
}
/**
2004-05-31 14:04:00 +00:00
* Sets the LDAP suffix where domains are saved
*
2004-09-26 08:46:56 +00:00
* @param string $value new domain suffix
* @return boolean true if $value has correct format
*/
2003-07-25 14:12:07 +00:00
function set_DomainSuffix($value) {
2004-06-02 13:20:19 +00:00
if (!$value) $this->domainsuffix = "";
2004-08-14 12:39:36 +00:00
elseif (is_string($value)) {
2003-09-19 19:49:45 +00:00
$this->domainsuffix = $value;
2003-07-25 14:12:07 +00:00
}
2003-07-30 21:23:48 +00:00
else return false;
return true;
2003-07-25 14:12:07 +00:00
}
/**
2004-05-31 14:04:00 +00:00
* Returns the list of attributes to show in user list
*
2004-09-26 08:46:56 +00:00
* @return string the attribute list
*/
2003-07-30 21:23:48 +00:00
function get_userlistAttributes() {
return $this->userlistAttributes;
}
/**
2004-05-31 14:04:00 +00:00
* Sets the list of attributes to show in user list
*
2004-09-26 08:46:56 +00:00
* @param string $value new attribute string
* @return boolean true if $value has correct format
*/
2003-07-30 21:23:48 +00:00
function set_userlistAttributes($value) {
if (is_string($value) && eregi("^((#[^:;]+)|([^:;]*:[^:;]+))(;((#[^:;]+)|([^:;]*:[^:;]+)))*$", $value)) {
2003-07-30 21:23:48 +00:00
$this->userlistAttributes = $value;
}
else return false;
return true;
}
/**
2004-05-31 14:04:00 +00:00
* Returns the list of attributes to show in group list
*
2004-09-26 08:46:56 +00:00
* @return string the attribute list
*/
2003-07-30 21:23:48 +00:00
function get_grouplistAttributes() {
return $this->grouplistAttributes;
}
/**
2004-05-31 14:04:00 +00:00
* Sets the list of attributes to show in group list
*
2004-09-26 08:46:56 +00:00
* @param string $value new attribute string
* @return boolean true if $value has correct format
*/
2003-07-30 21:23:48 +00:00
function set_grouplistAttributes($value) {
if (is_string($value) && eregi("^((#[^:;]+)|([^:;]*:[^:;]+))(;((#[^:;]+)|([^:;]*:[^:;]+)))*$", $value)) {
2003-07-30 21:23:48 +00:00
$this->grouplistAttributes = $value;
}
else return false;
return true;
}
/**
2004-05-31 14:04:00 +00:00
* Returns the list of attributes to show in host list
*
2004-09-26 08:46:56 +00:00
* @return string the attribute list
*/
2003-07-30 21:23:48 +00:00
function get_hostlistAttributes() {
return $this->hostlistAttributes;
}
/**
2004-05-31 14:04:00 +00:00
* Sets the list of attributes to show in host list
*
2004-09-26 08:46:56 +00:00
* @param string $value new attribute string
* @return boolean true if $value has correct format
*/
2003-07-30 21:23:48 +00:00
function set_hostlistAttributes($value) {
2004-01-27 18:05:35 +00:00
if (! $value && ($this->hostsuffix == "")) $this->hostlistAttributes = "";
elseif (is_string($value) && eregi("^((#[^:;]+)|([^:;]*:[^:;]+))(;((#[^:;]+)|([^:;]*:[^:;]+)))*$", $value)) {
2003-07-30 21:23:48 +00:00
$this->hostlistAttributes = $value;
}
else return false;
return true;
}
2003-05-09 16:22:46 +00:00
/**
2004-05-31 14:04:00 +00:00
* Returns the maximum number of rows in user/group/host lists
*
2004-09-26 08:46:56 +00:00
* @return integer maximum number
*/
2003-07-30 21:23:48 +00:00
function get_MaxListEntries() {
return $this->maxlistentries;
}
2003-05-09 16:22:46 +00:00
/**
2004-05-31 14:04:00 +00:00
* Sets the maximum number of rows in user/group/host lists
*
2004-09-26 08:46:56 +00:00
* @param integer $value new maximum value
* @return boolean true if $value has correct format
*/
2003-07-30 21:23:48 +00:00
function set_MaxListEntries ($value) {
if (is_numeric($value)) $this->maxlistentries = $value;
else return false;
return true;
}
2003-05-09 16:22:46 +00:00
/**
2004-05-31 14:04:00 +00:00
* Returns the default language string
*
2004-09-26 08:46:56 +00:00
* @return string default language
*/
2003-07-30 21:23:48 +00:00
function get_defaultLanguage() {
return $this->defaultLanguage;
}
/**
2004-05-31 14:04:00 +00:00
* Sets the default language string
*
2004-09-26 08:46:56 +00:00
* @param string $value new default language
* @return boolean true if $value has correct format
*/
2003-07-30 21:23:48 +00:00
function set_defaultLanguage($value) {
if (is_string($value)) $this->defaultLanguage = $value;
else return false;
return true;
}
/**
2004-05-31 14:04:00 +00:00
* Returns the path to the external script
*
2004-09-26 08:46:56 +00:00
* @return string script path
*/
2003-07-30 21:23:48 +00:00
function get_scriptPath() {
return $this->scriptPath;
}
/**
2004-05-31 14:04:00 +00:00
* Sets the path to the external script
*
2004-09-26 08:46:56 +00:00
* @param string $value new script path
* @return boolean true if $value has correct format
*/
2003-07-30 21:23:48 +00:00
function set_scriptPath($value) {
if (!$value) $this->scriptPath = ""; // optional parameter
2003-08-03 13:29:44 +00:00
elseif (is_string($value) && eregi("^/([a-z0-9_\\-])+(/([a-z0-9_\\.\\-])+)+$", $value)) $this->scriptPath = $value;
2003-07-30 21:23:48 +00:00
else return false;
return true;
}
/**
2004-05-31 14:04:00 +00:00
* Returns the server of the external script
*
2004-09-26 08:46:56 +00:00
* @return string script server
*/
2003-07-30 21:23:48 +00:00
function get_scriptServer() {
return $this->scriptServer;
}
/**
2004-05-31 14:04:00 +00:00
* Sets the server of the external script
*
2004-09-26 08:46:56 +00:00
* @param string $value new script server
* @return boolean true if $value has correct format
*/
2003-07-30 21:23:48 +00:00
function set_scriptServer($value) {
if (!$value) $this->scriptServer = ""; // optional parameter
elseif (is_string($value) && eregi("^[a-z0-9\\-]+(\\.[a-z0-9\\-]+)*$", $value)) {
2003-07-30 21:23:48 +00:00
$this->scriptServer = $value;
}
else return false;
return true;
}
2003-05-28 15:37:48 +00:00
2004-05-31 14:04:00 +00:00
/**
* Returns the LDAP cache timeout in minutes
*
2004-09-26 08:46:56 +00:00
* @return integer cache time
2004-05-31 14:04:00 +00:00
*/
2003-08-18 15:21:27 +00:00
function get_cacheTimeout() {
if (isset($this->cachetimeout)) return $this->cachetimeout;
2003-10-04 12:34:19 +00:00
else return 5;
2003-08-18 15:21:27 +00:00
}
2004-05-31 14:04:00 +00:00
/**
* Returns the LDAP cache timeout in seconds
*
2004-09-26 08:46:56 +00:00
* @return integer cache time
2004-05-31 14:04:00 +00:00
*/
2003-08-18 16:38:41 +00:00
function get_cacheTimeoutSec() {
return $this->cachetimeout * 60;
2003-08-18 16:38:41 +00:00
}
2004-05-31 14:04:00 +00:00
/**
* Sets the LDAP cache timeout in minutes (0,1,2,5,10,15)
*
2004-09-26 08:46:56 +00:00
* @param integer $value new cache timeout
* @return boolean true if $value has correct format
2004-05-31 14:04:00 +00:00
*/
2003-08-18 15:21:27 +00:00
function set_cacheTimeout($value) {
if (is_numeric($value) && ($value > -1)) {
$this->cachetimeout = $value;
2003-08-18 15:21:27 +00:00
}
else return false;
return true;
}
2004-05-31 14:04:00 +00:00
/**
* Returns an array of all selected account modules
2004-05-31 14:04:00 +00:00
*
* @param string $scope account type
2004-09-26 08:46:56 +00:00
* @return array user modules
2004-05-31 14:04:00 +00:00
*/
function get_AccountModules($scope) {
switch ($scope) {
case 'user':
return explode(",", $this->usermodules);
break;
case 'group':
return explode(",", $this->groupmodules);
break;
case 'host':
return explode(",", $this->hostmodules);
break;
default:
return array();
break;
2004-02-01 12:33:21 +00:00
}
2004-01-30 17:06:28 +00:00
}
2004-05-31 14:04:00 +00:00
/**
* Sets the selected account modules
2004-05-31 14:04:00 +00:00
*
2004-09-26 08:46:56 +00:00
* @param array $modules array with module names (not aliases!)
* @param string $scope account type
2004-09-26 08:46:56 +00:00
* @return boolean true if $modules has correct format
2004-05-31 14:04:00 +00:00
*/
function set_AccountModules($modules, $scope) {
2004-01-30 17:06:28 +00:00
if (! is_array($modules)) return false;
// check module names
$available = getAvailableModules($scope);
2004-02-01 12:33:21 +00:00
for ($i = 0; $i < sizeof($modules); $i++) {
if (! in_array($modules[$i], $available)) return false;
}
// check depends/conflicts
if (check_module_conflicts($modules, getModulesDependencies($scope)) != false) return false;
if (check_module_depends($modules, getModulesDependencies($scope)) != false) return false;
switch ($scope) {
case 'user':
$this->usermodules = implode(",", $modules);
break;
case 'group':
$this->groupmodules = implode(",", $modules);
break;
case 'host':
$this->hostmodules = implode(",", $modules);
break;
default:
break;
2004-02-01 12:33:21 +00:00
}
return true;
2004-01-30 17:06:28 +00:00
}
2004-07-18 10:18:25 +00:00
/**
* Sets the settings for the account modules.
*
* @param array $settings list of module setting array(name => value)
2004-09-26 08:46:56 +00:00
* @return boolean true if $settings has correct format
2004-07-18 10:18:25 +00:00
*/
function set_moduleSettings($settings) {
if (!is_array($settings)) return false;
$this->moduleSettings = $settings;
return true;
}
/**
* Returns a list of saved module settings
*
* @return array list of settings: array(name => value)
*/
function get_moduleSettings() {
return $this->moduleSettings;
}
2003-02-17 21:38:54 +00:00
}
2004-01-30 17:06:28 +00:00
2004-05-31 14:04:00 +00:00
/**
* This class manages config.cfg.
*
* @package configuration
2003-07-06 10:24:41 +00:00
*/
class CfgMain {
2004-05-31 14:04:00 +00:00
/** Default profile */
2003-07-06 10:24:41 +00:00
var $default;
2004-05-31 14:04:00 +00:00
/** Password to change config.cfg */
2003-07-06 10:24:41 +00:00
var $password;
2004-05-31 14:04:00 +00:00
/**
* Loads preferences from config file
*/
2003-07-06 10:24:41 +00:00
function CfgMain() {
$this->reload();
}
2004-05-31 14:04:00 +00:00
/**
* Reloads preferences from config file config.cfg
2004-07-18 10:18:25 +00:00
*
* @return boolean true if file was readable
2004-05-31 14:04:00 +00:00
*/
2003-07-06 10:24:41 +00:00
function reload() {
$conffile = substr(__FILE__, 0, strlen(__FILE__) - 15) . "/config/config.cfg";
if (is_file($conffile) == True) {
2004-07-18 10:18:25 +00:00
$file = @fopen($conffile, "r");
if (!$file) return false; // abort if file is not readable
2003-07-06 10:24:41 +00:00
while (!feof($file)) {
$line = fgets($file, 1024);
$line = trim($line); // remove spaces at the beginning and end
if (($line == "")||($line[0] == "#")) continue; // ignore comments
2003-07-06 10:24:41 +00:00
// search keywords
if (substr($line, 0, 10) == "password: ") {
$this->password = substr($line, 10, strlen($line)-10);
2003-07-06 10:24:41 +00:00
continue;
}
if (substr($line, 0, 9) == "default: ") {
$this->default = substr($line, 9, strlen($line)-9);
2003-07-06 10:24:41 +00:00
continue;
}
}
fclose($file);
}
2004-07-18 10:18:25 +00:00
return true;
2003-07-06 10:24:41 +00:00
}
2004-05-31 14:04:00 +00:00
/**
* Saves preferences to config file config.cfg
*/
2003-07-06 10:24:41 +00:00
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;
}
}
}
?>