LDAPAccountManager/lam/lib/config.inc

832 lines
24 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)
2006-03-03 17:30:35 +00:00
Copyright (C) 2003 - 2006 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");
2006-01-01 16:30:05 +00:00
/** Used to get type information. */
include_once("types.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);
2005-12-04 10:27:19 +00:00
bind_textdomain_codeset("messages", $language[1]);
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
2005-04-07 13:12:38 +00:00
/**
* Returns the version number of this LAM installation.
* Format: <major version>.<minor version>.<patch level>
* <br> Major/minor version are always numbers, patch level may contain letters for inofficial releases only (e.g. 0.5.alpha1).
*
* @return string version number
*/
function LAMVersion() {
$file = substr(__FILE__, 0, strlen(__FILE__) - 15) . "/VERSION";
if (is_readable($file)) {
$handle = fopen($file, "r");
if (!feof($handle)) {
return trim(fgets($handle, 20));
}
}
// file was not readable
return '0.0.unknown';
}
/**
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
2005-02-27 12:40:06 +00:00
/** LDAP suffix for tree view */
var $treesuffix;
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();
2006-01-01 16:30:05 +00:00
/** type settings */
var $typeSettings = 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
2006-01-01 16:30:05 +00:00
/** Active account types */
var $activeTypes = "user,group,host,smbDomain";
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 */
2006-01-01 16:30:05 +00:00
var $settings = array("ServerURL", "Passwd", "Admins", "treesuffix", "maxlistentries",
"defaultLanguage", "scriptPath", "scriptServer", "cachetimeout",
2006-01-01 16:30:05 +00:00
"modules", "activeTypes", "types");
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, ":");
2006-01-01 16:30:05 +00:00
$this->moduleSettings[substr($option, 0, $pos)] = explode("+::+", substr($option, $pos + 2));
}
// type settings
elseif (strtolower(substr($line, 0, $keylen + 2)) == "types: ") {
$option = substr($line, $keylen + 2, strlen($line) - $keylen - 2);
$pos = strpos($option, ":");
$this->typeSettings[substr($option, 0, $pos)] = substr($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;
}
2006-02-03 15:36:39 +00:00
elseif (strtolower($line) == strtolower($keyword . ":")) {
// set empty options
$this->$keyword = '';
}
2003-09-15 16:24:44 +00:00
}
}
fclose($file);
}
// check modules
2006-01-01 16:30:05 +00:00
$scopes = $this->get_ActiveTypes();
for ($s = 0; $s < sizeof($scopes); $s++) {
$scope = $scopes[$s];
2006-01-24 14:23:42 +00:00
$moduleVar = "modules_" . $scope;
$modules = explode(",", $this->typeSettings[$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
}
2006-01-01 16:30:05 +00:00
// type settings
elseif (strtolower(substr($line, 0, $keylen + 2)) == "types: ") {
$option = substr($line, $keylen + 2, strlen($line) - $keylen - 2);
$pos = strpos($option, ":");
$name = substr($option, 0, $pos);
if (!isset($this->typeSettings[$name])) continue;
$file_array[$i] = "types: " . $name . ": " . $this->typeSettings[$name] . "\n";
$mod_saved[] = $name; // mark keyword as saved
}
2004-07-18 10:18:25 +00:00
// 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");
2005-02-27 12:40:06 +00:00
if (!in_array("treesuffix", $saved)) array_push($file_array, "\n\n# suffix of tree view\n" .
"# e.g. dc=yourdomain,dc=org\n" . "treesuffix: " . $this->treesuffix . "\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");
2006-01-01 16:30:05 +00:00
if (!in_array("activeTypes", $saved)) array_push($file_array, "\n\n# List of active account types.\n" . "activeTypes: " . $this->activeTypes . "\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
}
}
2006-01-01 16:30:05 +00:00
// check if all type settings were added
$t_settings = array_keys($this->typeSettings);
for ($i = 0; $i < sizeof($t_settings); $i++) {
if (!in_array($t_settings[$i], $mod_saved)) {
array_push($file_array, "types: " . $t_settings[$i] . ": " . $this->typeSettings[$t_settings[$i]] . "\n");
}
}
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);
2006-01-01 16:30:05 +00:00
StatusMessage("INFO", _("Your settings were successfully saved.") , " (" . $conffile . ")");
2003-08-18 15:21:27 +00:00
}
else {
2006-01-01 16:30:05 +00:00
StatusMessage("ERROR", _("Cannot open config file!") . " (" . $conffile . ")");
2003-08-18 15:21:27 +00:00
exit;
}
2003-06-24 15:50:38 +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;
}
2005-02-27 12:40:06 +00:00
/**
* Returns the LDAP suffix for the given account type
*
* @param string $scope account type
* @return string the LDAP suffix
*/
function get_Suffix($scope) {
2006-01-01 16:30:05 +00:00
if ($scope == "tree") {
return $this->treesuffix;
}
else {
return $this->typeSettings['suffix_' . $scope];
2005-02-27 12:40:06 +00:00
}
}
/**
* Sets the LDAP suffix where accounts are saved
*
* @param string $scope account type
* @param string $value new LDAP suffix
* @return boolean true if $value has correct format
*/
function set_Suffix($scope, $value) {
if (!$value) $value = "";
elseif (!is_string($value)) {
return false;
}
2006-01-01 16:30:05 +00:00
if ($scope == "tree") {
$this->treesuffix = $value;
}
else {
$this->typeSettings['suffix_' . $scope] = $value;
2005-02-27 12:40:06 +00:00
}
return true;
}
/**
2004-05-31 14:04:00 +00:00
* Returns the list of attributes to show in user list
*
* @param string $scope account type
2004-09-26 08:46:56 +00:00
* @return string the attribute list
*/
function get_listAttributes($scope) {
2006-01-01 16:30:05 +00:00
return $this->typeSettings['attr_' . $scope];
}
/**
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
* @param string $scope account type
2004-09-26 08:46:56 +00:00
* @return boolean true if $value has correct format
*/
function set_listAttributes($value, $scope) {
if (is_string($value) && eregi("^((#[^:;]+)|([^:;]*:[^:;]+))(;((#[^:;]+)|([^:;]*:[^:;]+)))*$", $value)) {
2006-01-01 16:30:05 +00:00
$this->typeSettings['attr_' . $scope] = $value;
return true;
}
else {
return false;
2003-07-30 21:23:48 +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) {
2006-01-01 16:30:05 +00:00
if (isset($this->typeSettings["modules_" . $scope])) {
return explode(",", $this->typeSettings["modules_" . $scope]);
}
else {
return array();
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;
2006-01-01 16:30:05 +00:00
$this->typeSettings["modules_" . $scope] = implode(",", $modules);
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;
}
2006-01-01 16:30:05 +00:00
/**
* Returns a list of active account types.
*
* @return array list of types
*/
function get_ActiveTypes() {
2006-02-03 15:36:39 +00:00
if (($this->activeTypes == '') || !isset($this->activeTypes)) return array();
else return explode(",", $this->activeTypes);
2006-01-01 16:30:05 +00:00
}
/**
* Sets the list of active types.
*
* @param array list of types
*/
function set_ActiveTypes($types) {
$this->activeTypes = implode(",", $types);
}
/**
* Sets the settings for the account types.
*
* @param array $settings list of type setting array(name => value)
* @return boolean true if $settings has correct format
*/
function set_typeSettings($settings) {
if (!is_array($settings)) return false;
$this->typeSettings = $settings;
return true;
}
/**
* Returns a list of saved type settings
*
* @return array list of settings: array(name => value)
*/
function get_typeSettings() {
return $this->typeSettings;
}
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;
2006-04-18 10:57:16 +00:00
/** Time of inactivity before session times out (minutes) */
var $sessionTimeout;
2006-04-23 16:33:25 +00:00
/** log level */
var $logLevel;
/** log destination ("SYSLOG":syslog, "/...":file, "NONE":none) */
var $logDestination;
2006-04-25 11:25:07 +00:00
/** list of hosts which may access LAM */
var $allowedHosts;
2006-04-23 16:33:25 +00:00
/** list of data fields to save in config file */
2006-04-25 11:25:07 +00:00
var $settings = array("password", "default", "sessionTimeout",
"logLevel", "logDestination", "allowedHosts");
2006-04-23 16:33:25 +00:00
2004-05-31 14:04:00 +00:00
/**
* Loads preferences from config file
*/
2003-07-06 10:24:41 +00:00
function CfgMain() {
2006-04-23 16:33:25 +00:00
// set default values
2006-04-18 10:57:16 +00:00
$this->sessionTimeout = 30;
2006-04-23 16:33:25 +00:00
$this->logLevel = LOG_NOTICE;
$this->logDestination = "SYSLOG";
2006-04-25 11:25:07 +00:00
$this->allowedHosts = "";
2003-07-06 10:24:41 +00:00
$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
2006-04-23 16:33:25 +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 . ": ")) {
$this->$keyword = substr($line, $keylen + 2, strlen($line) - $keylen - 2);
break;
}
2003-07-06 10:24:41 +00:00
}
}
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
2006-04-23 16:33:25 +00:00
$saved = array();
2003-07-06 10:24:41 +00:00
for ($i = 0; $i < sizeof($file_array); $i++) {
2006-04-23 16:33:25 +00:00
$line = trim($file_array[$i]);
if (($line == "")||($line[0] == "#")) continue; // ignore comments and empty lines
// search keywords
for ($k = 0; $k < sizeof($this->settings); $k++) {
$keyword = $this->settings[$k];
$keylen = strlen($keyword);
if (strtolower(substr($line, 0, $keylen + 1)) == strtolower($keyword . ":")) {
$file_array[$i] = $keyword . ": " . $this->$keyword . "\n";
$saved[] = $keyword; // mark keyword as saved
break;
}
2006-04-18 10:57:16 +00:00
}
2003-07-06 10:24:41 +00:00
}
}
// check if we have to add new entries (e.g. if user upgraded LAM and has an old config file)
2006-04-23 16:33:25 +00:00
if (!in_array("password", $saved)) array_push($file_array, "\n\n# password to add/delete/rename configuration profiles\n" . "password: " . $this->password);
if (!in_array("default", $saved)) array_push($file_array, "\n\n# default profile, without \".conf\"\n" . "default: " . $this->default);
if (!in_array("sessionTimeout", $saved)) array_push($file_array, "\n\n# session timeout in minutes\n" . "sessionTimeout: " . $this->sessionTimeout);
if (!in_array("logLevel", $saved)) array_push($file_array, "\n\n# log level\n" . "logLevel: " . $this->logLevel);
if (!in_array("logDestination", $saved)) array_push($file_array, "\n\n# log destination\n" . "logDestination: " . $this->logDestination);
2006-04-25 11:25:07 +00:00
if (!in_array("allowedHosts", $saved)) array_push($file_array, "\n\n# list of hosts which may access LAM\n" . "allowedHosts: " . $this->allowedHosts);
2006-04-16 12:42:40 +00:00
$file = @fopen($conffile, "w");
2003-07-06 10:24:41 +00:00
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;
}
}
2006-04-23 16:33:25 +00:00
2003-07-06 10:24:41 +00:00
}
?>