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 )
2007-02-22 17:16:14 +00:00
Copyright ( C ) 2003 - 2007 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-03-30 19:51:47 +00:00
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-05-14 13:45:52 +00:00
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
2003-05-14 13:45:52 +00:00
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
2007-02-22 17:16:14 +00:00
* @ author Thomas Manninger
2003-02-21 22:01:01 +00:00
*/
2004-05-31 14:04:00 +00:00
/** Used to print messages. */
2003-05-14 13:45:52 +00:00
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 " );
2003-05-14 13:45:52 +00:00
2004-05-30 12:16:01 +00:00
/**
2004-05-31 14:04:00 +00:00
* Sets language settings for automatic translation
2004-05-30 12:16:01 +00:00
*/
2003-05-06 15:17:09 +00:00
function setlanguage () {
2004-10-07 09:48:31 +00:00
if ( ! isset ( $_SESSION [ 'language' ])) {
$_SESSION [ 'language' ] = " en_GB.utf8:UTF-8:English (Great Britain) " ;
2003-05-06 15:17:09 +00:00
}
2004-10-07 09:48:31 +00:00
$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 ]);
2004-10-07 09:48:31 +00:00
textdomain ( " messages " );
header ( " Content-type: text/html; charset= " . $language [ 1 ], true );
2003-05-06 15:17:09 +00:00
}
2003-02-21 22:01:01 +00:00
2007-02-22 17:16:14 +00:00
/**
2007-11-03 13:22:12 +00:00
* Checks whether a specific flag in the rights string is set .
2007-02-22 17:16:14 +00:00
*
2007-11-03 13:17:39 +00:00
* @ param $right read , write or execute
* @ param $target owner , group or other
* @ param $chmod the chmod rights
2007-02-22 17:16:14 +00:00
*
* @ return true , if the chmod $right for $target were set
*/
function checkChmod ( $right , $target , $chmod ) {
$right_arr = array ( " read " , " write " , " execute " );
$target_arr = array ( " owner " , " group " , " other " );
// Check, if $right and $target has right parameters
if ( ! in_array ( $right , $right_arr ) ||! in_array ( $target , $target_arr )) {
return false ;
}
$chmod_num = - 1 ;
// owner:
if ( $target == " owner " ) $chmod_num = 0 ;
if ( $target == " group " ) $chmod_num = 1 ;
if ( $target == " other " ) $chmod_num = 2 ;
// Cut the number from the chmod:
$chmod_num = $chmod { $chmod_num };
// Now check, if the chmod_num can be right with the $right
// What numbers allow "read"
$read = array ( 4 , 5 , 6 , 7 );
// What numbers allow "write"
$write = array ( 2 , 3 , 6 , 7 );
// What numbers allow "execute"
$execute = array ( 1 , 3 , 5 , 7 );
if (( $right == " read " ) && in_array ( $chmod_num , $read )) return true ;
elseif (( $right == " write " ) && in_array ( $chmod_num , $write )) return true ;
elseif (( $right == " execute " ) && in_array ( $chmod_num , $execute )) return true ;
else return false ;
}
2004-05-30 12:16: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
2004-05-30 12:16:01 +00:00
*/
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 );
2003-10-11 12:17:28 +00:00
// 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-30 12:16:01 +00:00
/**
2004-05-31 14:04:00 +00:00
* Prints a meta refresh page
2004-05-30 12:16:01 +00:00
*
2004-05-31 14:04:00 +00:00
* @ param string $page the URL of the target page
2004-05-30 12:16:01 +00:00
*/
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
2004-05-30 12:16:01 +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
*/
2006-09-24 14:19:50 +00:00
class LAMConfig {
2007-12-30 12:32:48 +00:00
const ACCESS_ALL = 100 ;
const ACCESS_PASSWORD_CHANGE = 20 ;
const ACCESS_READ_ONLY = 0 ;
2003-03-05 18:38:19 +00:00
2004-05-31 14:04:00 +00:00
/** Server address (e.g. ldap://127.0.0.1:389) */
2007-12-29 18:59:09 +00:00
private $ServerURL ;
2003-04-18 15:50:01 +00:00
2004-05-31 14:04:00 +00:00
/** Array of string: users with admin rights */
2007-12-29 18:59:09 +00:00
private $Admins ;
2003-05-14 13:45:52 +00:00
2004-05-31 14:04:00 +00:00
/** Password to edit preferences */
2007-11-07 21:02:13 +00:00
private $Passwd ;
2003-02-17 18:21:44 +00:00
2005-02-27 12:40:06 +00:00
/** LDAP suffix for tree view */
2007-12-29 18:59:09 +00:00
private $treesuffix ;
2005-02-27 12:40:06 +00:00
2004-05-31 14:04:00 +00:00
/** Default language */
2007-12-29 18:59:09 +00:00
private $defaultLanguage ;
2003-05-09 16:22:46 +00:00
2004-07-18 10:18:25 +00:00
/** module settings */
2007-12-29 18:59:09 +00:00
private $moduleSettings = array ();
2004-07-18 10:18:25 +00:00
2006-01-01 16:30:05 +00:00
/** type settings */
2007-12-29 18:59:09 +00:00
private $typeSettings = array ();
2006-01-01 16:30:05 +00:00
2004-05-30 12:16:01 +00:00
/**
* 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 .
2004-05-30 12:16:01 +00:00
* optional setting , may not be defined
*/
2007-12-29 18:59:09 +00:00
private $scriptPath ;
2003-05-12 17:52:54 +00:00
2004-05-30 12:16:01 +00:00
/**
2007-02-22 17:16:14 +00:00
* The rights for the home directory
*/
2007-12-29 18:59:09 +00:00
private $scriptRights = '750' ;
2007-02-22 17:16:14 +00:00
/**
* Servers where lamdaemon script is executed
2004-05-31 14:04:00 +00:00
*
* This is used for managing quota and home directories .
2004-05-30 12:16:01 +00:00
* optional setting , may not be defined
*/
2007-12-29 18:59:09 +00:00
private $scriptServer ;
2003-05-28 15:37:48 +00:00
2004-05-30 12:16:01 +00:00
/** LDAP cache timeout */
2007-12-29 18:59:09 +00:00
private $cachetimeout ;
2003-08-18 15:21:27 +00:00
2006-01-01 16:30:05 +00:00
/** Active account types */
2007-12-29 18:59:09 +00:00
private $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 */
2007-12-29 18:59:09 +00:00
private $file ;
2007-12-30 12:32:48 +00:00
private $accessLevel = 100 ;
2003-07-06 10:24:41 +00:00
2004-05-31 14:04:00 +00:00
/** List of all settings in config file */
2007-12-09 10:45:04 +00:00
private $settings = array ( " ServerURL " , " Passwd " , " Admins " , " treesuffix " ,
2007-02-25 14:15:08 +00:00
" defaultLanguage " , " scriptPath " , " scriptServer " , " scriptRights " , " cachetimeout " ,
2007-12-30 12:32:48 +00:00
" modules " , " activeTypes " , " types " , " accessLevel " );
2003-09-21 20:10:52 +00:00
2004-05-30 12:16:01 +00:00
/**
2004-05-31 14:04:00 +00:00
* Loads preferences from config file
2004-05-30 12:16:01 +00:00
*
2004-09-26 08:46:56 +00:00
* @ param integer $file Index number in config file array
2004-05-30 12:16:01 +00:00
*/
2007-12-28 16:08:56 +00:00
function __construct ( $file = 0 ) {
2003-10-11 12:17:28 +00:00
// 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
}
2003-05-14 13:45:52 +00:00
2004-07-18 10:18:25 +00:00
/**
* Reloads preferences from config file
*
* @ return boolean true if file was readable
*/
2007-10-26 17:51:56 +00:00
private function reload () {
$conffile = $this -> getPath ();
2003-09-15 16:24:44 +00:00
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 );
2003-10-11 12:17:28 +00:00
$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 );
}
2004-10-14 18:59:26 +00:00
// check modules
2006-01-01 16:30:05 +00:00
$scopes = $this -> get_ActiveTypes ();
2004-10-14 18:59:26 +00:00
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 ]);
2004-10-14 18:59:26 +00:00
$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
}
2003-05-14 13:45:52 +00:00
2004-05-31 14:04:00 +00:00
/** Saves preferences to config file */
2007-10-26 17:51:56 +00:00
public function save () {
$conffile = $this -> getPath ();
2003-08-18 15:21:27 +00:00
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 ]);
2003-10-11 12:17:28 +00:00
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 ;
2004-07-24 09:26:44 +00:00
$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 ( " 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 " );
2007-02-25 14:15:08 +00:00
if ( ! in_array ( " scriptServer " , $saved )) array_push ( $file_array , " \n \n # Servers of external script \n " . " scriptServer: " . $this -> scriptServer . " \n " );
2007-02-22 17:16:14 +00:00
if ( ! in_array ( " scriptRights " , $saved )) array_push ( $file_array , " \n \n # Access rights for home directories \n " . " scriptRights: " . $this -> scriptRights . " \n " );
2003-09-30 18:42:14 +00:00
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 " );
2007-12-30 12:32:48 +00:00
if ( ! in_array ( " accessLevel " , $saved )) array_push ( $file_array , " \n \n # Access level for this profile. \n " . " accessLevel: " . $this -> accessLevel . " \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
}
}
2007-10-26 17:51:56 +00:00
2007-12-29 18:59:09 +00:00
/**
* Returns the name of the config file
*
* @ return String name
*/
public function getName () {
return $this -> file ;
}
2007-10-26 17:51:56 +00:00
/**
* Returns if the file can be written on the filesystem .
*
* @ return boolean true if file is writable
*/
public function isWritable () {
return is_writeable ( $this -> getPath ());
}
/**
* Returns the path to the config file .
*
* @ return string path on filesystem
*/
private function getPath () {
return substr ( __FILE__ , 0 , strlen ( __FILE__ ) - 15 ) . " /config/ " . $this -> file . " .conf " ;
}
2003-03-30 19:51:47 +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-30 12:16:01 +00:00
/**
2004-05-31 14:04:00 +00:00
* Returns the server address as string
2004-05-30 12:16:01 +00:00
*
2004-09-26 08:46:56 +00:00
* @ return string server address
2004-05-30 12:16:01 +00:00
*/
2007-10-26 17:51:56 +00:00
public function get_ServerURL () {
2003-08-18 15:21:27 +00:00
return $this -> ServerURL ;
}
2003-04-18 15:50:01 +00:00
2004-05-30 12:16:01 +00:00
/**
2004-05-31 14:04:00 +00:00
* Sets the server address
2004-05-30 12:16:01 +00:00
*
2004-09-26 08:46:56 +00:00
* @ param string $value new server address
* @ return boolean true if $value has correct format
2004-05-30 12:16:01 +00:00
*/
2007-10-26 17:51:56 +00:00
public function set_ServerURL ( $value ) {
2003-07-30 21:23:48 +00:00
if ( is_string ( $value )) $this -> ServerURL = $value ;
else return false ;
return true ;
}
2003-05-09 16:22:46 +00:00
2004-05-30 12:16:01 +00:00
/**
2004-05-31 14:04:00 +00:00
* Returns an array of string with all admin names
2004-05-30 12:16:01 +00:00
*
2004-09-26 08:46:56 +00:00
* @ return array the admin names
2004-05-30 12:16:01 +00:00
*/
2007-10-26 17:51:56 +00:00
public function get_Admins () {
2003-09-21 20:10:52 +00:00
return explode ( " ; " , $this -> Admins );
2003-05-06 23:52:00 +00:00
}
2003-05-14 13:45:52 +00:00
2004-05-30 12:16:01 +00:00
/**
2004-05-31 14:04:00 +00:00
* Returns all admin users seperated by semicolons
2004-05-30 12:16:01 +00:00
*
2004-09-26 08:46:56 +00:00
* @ return string the admin string
2004-05-30 12:16:01 +00:00
*/
2007-10-26 17:51:56 +00:00
public function get_Adminstring () {
2003-09-21 20:10:52 +00:00
return $this -> Admins ;
2003-07-30 21:23:48 +00:00
}
2003-05-14 13:45:52 +00:00
2004-05-30 12:16:01 +00:00
/**
2004-05-31 14:04:00 +00:00
* Sets the admin string
2004-05-30 12:16:01 +00:00
*
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
2004-05-30 12:16:01 +00:00
*/
2007-10-26 17:51:56 +00:00
public function set_Adminstring ( $value ) {
2003-07-30 21:23:48 +00:00
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 ;
}
2003-05-14 13:45:52 +00:00
2004-05-30 12:16:01 +00:00
/**
2007-11-08 19:19:50 +00:00
* Checks if the given password matches .
*
* @ param String $password
* @ return boolean true , if matches
*/
public function check_Passwd ( $password ) {
if ( substr ( $this -> Passwd , 0 , 6 ) == " { SSHA} " ) {
// check hashed password
$value = substr ( $this -> Passwd , 6 );
$parts = explode ( " " , $value );
$salt = base64_decode ( $parts [ 1 ]);
return ( $this -> hashPassword ( $password , $salt ) === $this -> Passwd );
}
else {
// old nonhashed password
return ( $password === $this -> Passwd );
}
2003-07-30 21:23:48 +00:00
}
2003-05-14 13:45:52 +00:00
2004-05-30 12:16:01 +00:00
/**
2004-05-31 14:04:00 +00:00
* Sets the preferences wizard password
2004-05-30 12:16:01 +00:00
*
2004-09-26 08:46:56 +00:00
* @ param string $value new password
* @ return boolean true if $value has correct format
2004-05-30 12:16:01 +00:00
*/
2007-10-26 17:51:56 +00:00
public function set_Passwd ( $value ) {
2007-11-08 19:19:50 +00:00
if ( is_string ( $value )) {
mt_srand (( microtime () * 1000000 ));
$rand = mt_rand ();
$salt0 = substr ( pack ( " h* " , md5 ( $rand )), 0 , 8 );
$salt = substr ( pack ( " H* " , sha1 ( $salt0 . $value )), 0 , 4 );
$this -> Passwd = $this -> hashPassword ( $value , $salt );
return true ;
}
else {
return false ;
}
}
/**
* Returns the hashed password .
*
* @ param String $password password
* @ param String $salt salt
* @ return String hash value
*/
private function hashPassword ( $password , $salt ) {
return " { SSHA} " . base64_encode ( hex2bin ( sha1 ( $password . $salt ))) . " " . base64_encode ( $salt );
2003-07-30 21:23:48 +00:00
}
2003-05-14 13:45:52 +00:00
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
*/
2007-10-26 17:51:56 +00:00
public 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
*/
2007-10-26 17:51:56 +00:00
public function set_Suffix ( $scope , $value ) {
2005-02-27 12:40:06 +00:00
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-30 12:16:01 +00:00
/**
2004-05-31 14:04:00 +00:00
* Returns the list of attributes to show in user list
2004-05-30 12:16:01 +00:00
*
2005-04-14 17:42:15 +00:00
* @ param string $scope account type
2004-09-26 08:46:56 +00:00
* @ return string the attribute list
2004-05-30 12:16:01 +00:00
*/
2007-10-26 17:51:56 +00:00
public function get_listAttributes ( $scope ) {
2006-01-01 16:30:05 +00:00
return $this -> typeSettings [ 'attr_' . $scope ];
2003-05-14 13:45:52 +00:00
}
2003-03-30 19:51:47 +00:00
2004-05-30 12:16:01 +00:00
/**
2004-05-31 14:04:00 +00:00
* Sets the list of attributes to show in user list
2004-05-30 12:16:01 +00:00
*
2004-09-26 08:46:56 +00:00
* @ param string $value new attribute string
2005-04-14 17:42:15 +00:00
* @ param string $scope account type
2004-09-26 08:46:56 +00:00
* @ return boolean true if $value has correct format
2004-05-30 12:16:01 +00:00
*/
2007-10-26 17:51:56 +00:00
public function set_listAttributes ( $value , $scope ) {
2004-01-05 17:23:49 +00:00
if ( is_string ( $value ) && eregi ( " ^((#[^:;]+)|([^:;]*:[^:;]+))(;((#[^:;]+)|([^:;]*:[^:;]+)))* $ " , $value )) {
2006-01-01 16:30:05 +00:00
$this -> typeSettings [ 'attr_' . $scope ] = $value ;
2005-04-14 17:42:15 +00:00
return true ;
}
else {
return false ;
2003-07-30 21:23:48 +00:00
}
2003-05-14 13:45:52 +00:00
}
2003-03-30 19:51:47 +00:00
2004-05-30 12:16:01 +00:00
/**
2004-05-31 14:04:00 +00:00
* Returns the default language string
2004-05-30 12:16:01 +00:00
*
2004-09-26 08:46:56 +00:00
* @ return string default language
2004-05-30 12:16:01 +00:00
*/
2007-10-26 17:51:56 +00:00
public function get_defaultLanguage () {
2003-07-30 21:23:48 +00:00
return $this -> defaultLanguage ;
}
2003-05-12 17:52:54 +00:00
2004-05-30 12:16:01 +00:00
/**
2004-05-31 14:04:00 +00:00
* Sets the default language string
2004-05-30 12:16:01 +00:00
*
2004-09-26 08:46:56 +00:00
* @ param string $value new default language
* @ return boolean true if $value has correct format
2004-05-30 12:16:01 +00:00
*/
2007-10-26 17:51:56 +00:00
public function set_defaultLanguage ( $value ) {
2003-07-30 21:23:48 +00:00
if ( is_string ( $value )) $this -> defaultLanguage = $value ;
else return false ;
return true ;
}
2003-05-12 17:52:54 +00:00
2004-05-30 12:16:01 +00:00
/**
2004-05-31 14:04:00 +00:00
* Returns the path to the external script
2004-05-30 12:16:01 +00:00
*
2004-09-26 08:46:56 +00:00
* @ return string script path
2004-05-30 12:16:01 +00:00
*/
2007-10-26 17:51:56 +00:00
public function get_scriptPath () {
2003-07-30 21:23:48 +00:00
return $this -> scriptPath ;
}
2003-05-12 17:52:54 +00:00
2004-05-30 12:16:01 +00:00
/**
2004-05-31 14:04:00 +00:00
* Sets the path to the external script
2004-05-30 12:16:01 +00:00
*
2004-09-26 08:46:56 +00:00
* @ param string $value new script path
* @ return boolean true if $value has correct format
2004-05-30 12:16:01 +00:00
*/
2007-10-26 17:51:56 +00:00
public function set_scriptPath ( $value ) {
2003-07-30 21:23:48 +00:00
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 ;
}
2007-02-22 17:16:14 +00:00
2004-05-30 12:16:01 +00:00
/**
2007-02-22 17:16:14 +00:00
* Returns the servers of the external script as a Array
2004-05-30 12:16:01 +00:00
*
2007-02-22 17:16:14 +00:00
* @ return string script servers
2004-05-30 12:16:01 +00:00
*/
2007-10-26 17:51:56 +00:00
public function get_scriptServers () {
2007-02-25 14:15:08 +00:00
return $this -> scriptServer ;
2003-05-14 13:45:52 +00:00
}
2007-02-22 17:16:14 +00:00
2004-05-30 12:16:01 +00:00
/**
2007-02-22 17:16:14 +00:00
* Sets the servers of the external script
2004-05-30 12:16:01 +00:00
*
2007-02-22 17:16:14 +00:00
* @ param string $value new script servers
2004-09-26 08:46:56 +00:00
* @ return boolean true if $value has correct format
2004-05-30 12:16:01 +00:00
*/
2007-10-26 17:51:56 +00:00
public function set_scriptServers ( $value ) {
2007-02-22 17:16:14 +00:00
if ( ! $value ) {
2007-02-25 14:15:08 +00:00
$this -> scriptServer = " " ; // optional parameter
2007-02-22 17:16:14 +00:00
return true ;
}
// Explode the value to an array
$array_string = explode ( " ; " , $value );
if ( count ( $array_string ) > 0 ) {
// Check all IPs in the exploded Array
$valid_ips = array ();
foreach ( $array_string as $arr_value ) {
// Explode name and IP, if a name exists
if ( eregi ( " : " , $arr_value )) {
$arr_value_explode = explode ( " : " , $arr_value );
$ip = $arr_value_explode [ 1 ];
$servername = $arr_value_explode [ 0 ];
}
else {
$ip = $arr_value ;
$servername = " " ;
}
if ( isset ( $ip ) && is_string ( $ip ) && eregi ( " ^[a-z0-9 \\ -]+( \\ .[a-z0-9 \\ -]+)* $ " , $ip )) {
// Check if the IP has a server name
if ( ! empty ( $servername )) {
$valid_ips [] = $servername . " : " . $ip ;
}
else {
$valid_ips [] = $ip ;
}
}
}
// Check that the array is not empty
if ( $array_string > 0 ) {
2007-02-25 14:15:08 +00:00
$this -> scriptServer = implode ( " ; " , $valid_ips );
2007-02-22 17:16:14 +00:00
return true ;
}
else {
// The array is empty, there was no valid IP
return false ;
}
}
else {
return false ;
}
}
/**
* Returns the chmod value for new home directories .
*
* @ return string rights
*/
2007-10-26 17:51:56 +00:00
public function get_scriptRights () {
2007-02-22 17:16:14 +00:00
if ( ! isset ( $this -> scriptRights )) return '755' ;
return $this -> scriptRights ;
}
/**
* Sets the rights for the home directory .
*
* @ param string $chmod the rights
* @ return boolean true if values has correct format
*/
2007-10-26 17:51:56 +00:00
public function set_scriptRights ( $chmod ) {
2007-02-22 17:16:14 +00:00
// check if the chmod is correct:
if ( $chmod > 0 && $chmod <= 777 ) {
$this -> scriptRights = $chmod ;
return true ;
}
else {
return false ;
2003-07-30 21:23:48 +00:00
}
}
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
*/
2007-10-26 17:51:56 +00:00
public function get_cacheTimeout () {
2003-10-11 12:17:28 +00:00
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
*/
2007-10-26 17:51:56 +00:00
public function get_cacheTimeoutSec () {
2003-09-19 19:29:02 +00:00
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
*/
2007-10-26 17:51:56 +00:00
public function set_cacheTimeout ( $value ) {
2003-08-18 15:21:27 +00:00
if ( is_numeric ( $value ) && ( $value > - 1 )) {
2003-09-19 19:29:02 +00:00
$this -> cachetimeout = $value ;
2003-08-18 15:21:27 +00:00
}
else return false ;
return true ;
}
2003-03-30 19:51:47 +00:00
2004-05-31 14:04:00 +00:00
/**
2004-10-17 09:36:36 +00:00
* Returns an array of all selected account modules
2004-05-31 14:04:00 +00:00
*
2004-10-17 09:36:36 +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
*/
2007-10-26 17:51:56 +00:00
public 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
/**
2004-10-17 09:36:36 +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 ! )
2004-10-17 09:36:36 +00:00
* @ 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
*/
2007-10-26 17:51:56 +00:00
public function set_AccountModules ( $modules , $scope ) {
2004-01-30 17:06:28 +00:00
if ( ! is_array ( $modules )) return false ;
// check module names
2004-10-17 09:36:36 +00:00
$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 ;
}
2004-10-02 17:16:39 +00:00
// check depends/conflicts
2004-10-17 09:36:36 +00:00
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
*/
2007-10-26 17:51:56 +00:00
public function set_moduleSettings ( $settings ) {
2004-07-18 10:18:25 +00:00
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 )
*/
2007-10-26 17:51:56 +00:00
public function get_moduleSettings () {
2004-07-18 10:18:25 +00:00
return $this -> moduleSettings ;
}
2006-01-01 16:30:05 +00:00
/**
* Returns a list of active account types .
*
* @ return array list of types
*/
2007-10-26 17:51:56 +00:00
public 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
}
2006-09-24 14:19:50 +00:00
2006-01-01 16:30:05 +00:00
/**
* Sets the list of active types .
*
* @ param array list of types
*/
2007-10-26 17:51:56 +00:00
public function set_ActiveTypes ( $types ) {
2006-01-01 16:30:05 +00:00
$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
*/
2007-10-26 17:51:56 +00:00
public function set_typeSettings ( $settings ) {
2006-01-01 16:30:05 +00:00
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 )
*/
2007-10-26 17:51:56 +00:00
public function get_typeSettings () {
2006-01-01 16:30:05 +00:00
return $this -> typeSettings ;
}
2007-12-30 12:32:48 +00:00
/**
* Returns the access level for this profile .
*
* @ return int level
*/
public function getAccessLevel () {
return $this -> accessLevel ;
}
/**
* Sets the access level for this profile .
*
* @ param int $level level
*/
public function setAccessLevel ( $level ) {
$this -> accessLevel = $level ;
}
2003-02-17 21:38:54 +00:00
}
2003-03-05 16:05:23 +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
*/
2006-09-24 14:19:50 +00:00
class LAMCfgMain {
2003-07-06 10:24:41 +00:00
2004-05-31 14:04:00 +00:00
/** Default profile */
2007-10-26 17:51:56 +00:00
public $default ;
2003-07-06 10:24:41 +00:00
2004-05-31 14:04:00 +00:00
/** Password to change config.cfg */
2007-11-07 21:02:13 +00:00
private $password ;
2006-09-24 14:19:50 +00:00
2006-04-18 10:57:16 +00:00
/** Time of inactivity before session times out (minutes) */
2007-10-26 17:51:56 +00:00
public $sessionTimeout ;
2006-09-24 14:19:50 +00:00
2006-04-23 16:33:25 +00:00
/** log level */
2007-10-26 17:51:56 +00:00
public $logLevel ;
2006-09-24 14:19:50 +00:00
2006-04-23 16:33:25 +00:00
/** log destination ("SYSLOG":syslog, "/...":file, "NONE":none) */
2007-10-26 17:51:56 +00:00
public $logDestination ;
2006-09-24 14:19:50 +00:00
2006-04-25 11:25:07 +00:00
/** list of hosts which may access LAM */
2007-10-26 17:51:56 +00:00
public $allowedHosts ;
2006-09-24 14:19:50 +00:00
2006-04-23 16:33:25 +00:00
/** list of data fields to save in config file */
2007-10-26 17:51:56 +00:00
private $settings = array ( " password " , " default " , " sessionTimeout " ,
2006-04-25 11:25:07 +00:00
" logLevel " , " logDestination " , " allowedHosts " );
2006-09-24 14:19:50 +00:00
2004-05-31 14:04:00 +00:00
/**
* Loads preferences from config file
*/
2007-12-28 16:08:56 +00:00
function __construct () {
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
*/
2007-10-26 17:51:56 +00:00
private function reload () {
2003-07-06 10:24:41 +00:00
$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 );
2003-10-11 12:17:28 +00:00
$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
*/
2007-10-26 17:51:56 +00:00
public function save () {
2003-07-06 10:24:41 +00:00
$conffile = substr ( __FILE__ , 0 , strlen ( __FILE__ ) - 15 ) . " /config/config.cfg " ;
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
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 ;
}
}
2007-11-07 21:02:13 +00:00
/**
* Sets a new config password .
*
* @ param String $password new password
*/
public function setPassword ( $password ) {
mt_srand (( microtime () * 1000000 ));
$rand = mt_rand ();
$salt0 = substr ( pack ( " h* " , md5 ( $rand )), 0 , 8 );
$salt = substr ( pack ( " H* " , sha1 ( $salt0 . $password )), 0 , 4 );
$this -> password = $this -> hashPassword ( $password , $salt );
}
/**
* Checks if the given password matches .
*
* @ param String $password password
* @ return boolean true , if password matches
*/
public function checkPassword ( $password ) {
if ( substr ( $this -> password , 0 , 6 ) == " { SSHA} " ) {
// check hashed password
$value = substr ( $this -> password , 6 );
$parts = explode ( " " , $value );
$salt = base64_decode ( $parts [ 1 ]);
return ( $this -> hashPassword ( $password , $salt ) === $this -> password );
}
else {
// old nonhashed password
return ( $password === $this -> password );
}
}
/**
* Returns the hashed password .
*
* @ param String $password password
* @ param String $salt salt
* @ return String hash value
*/
private function hashPassword ( $password , $salt ) {
return " { SSHA} " . base64_encode ( hex2bin ( sha1 ( $password . $salt ))) . " " . base64_encode ( $salt );
}
2007-12-30 12:32:48 +00:00
2003-07-06 10:24:41 +00:00
}
2003-03-05 18:38:19 +00:00
?>