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 )
2003-02-21 22:01:01 +00:00
Copyright ( C ) 2003 Roland Gruber
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
2003-03-15 11:42:08 +00:00
Config supplies access to the configuration data .
2003-02-21 22:01:01 +00:00
*/
2003-05-14 13:45:52 +00:00
include_once ( " status.inc " );
2003-05-09 16:22:46 +00:00
// sets language settings for automatic translation
2003-05-06 15:17:09 +00:00
function setlanguage () {
if ( $_SESSION [ 'language' ]) {
$language = explode ( " : " , $_SESSION [ 'language' ]);
2003-10-11 12:17:28 +00:00
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
2003-05-10 11:17:28 +00:00
bindtextdomain ( " messages " , $locdir );
textdomain ( " messages " );
2003-05-06 15:17:09 +00:00
}
else echo _ ( " Language not defined in session! " );
}
2003-02-21 22:01:01 +00:00
2003-10-11 12:17:28 +00:00
// returns an array of string with all available configuration profiles (without .conf)
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
2003-08-28 12:41:47 +00:00
// print meta refresh
2003-10-11 12:17:28 +00:00
// $page is 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
/*
// class Config
*/
// manages .conf files
2003-02-17 18:21:44 +00:00
class Config {
2003-03-05 18:38:19 +00:00
2003-05-06 23:52:00 +00:00
// server address (e.g. ldap://127.0.0.1:389)
var $ServerURL ;
2003-04-18 15:50:01 +00:00
2003-05-06 23:52:00 +00:00
// array of strings: users with admin rights
var $Admins ;
2003-05-14 13:45:52 +00:00
2003-05-06 23:52:00 +00:00
// string: password to edit preferences
var $Passwd ;
2003-02-17 18:21:44 +00:00
2003-05-06 23:52:00 +00:00
// suffix for users
2003-09-19 19:49:45 +00:00
var $usersuffix ;
2003-05-14 13:45:52 +00:00
2003-05-06 23:52:00 +00:00
// suffix for groups
2003-09-19 19:49:45 +00:00
var $groupsuffix ;
2003-05-14 13:45:52 +00:00
2003-05-06 23:52:00 +00:00
// suffix for Samba hosts
2003-09-19 19:49:45 +00:00
var $hostsuffix ;
2003-03-05 18:38:19 +00:00
2003-07-25 14:12:07 +00:00
// suffix for domains (Samba 3)
2003-09-19 19:49:45 +00:00
var $domainsuffix ;
2003-07-25 14:12:07 +00:00
2003-05-06 23:52:00 +00:00
// minimum/maximum numbers for UID, GID and UID of Samba Hosts
var $MinUID ;
var $MaxUID ;
var $MinGID ;
var $MaxGID ;
var $MinMachine ;
var $MaxMachine ;
2003-03-30 19:51:47 +00:00
2003-05-06 23:52:00 +00:00
// attributes that are shown in the user/group/host tables
var $userlistAttributes ;
var $grouplistAttributes ;
var $hostlistAttributes ;
2003-05-07 14:29:44 +00:00
// maximum number of rows shown in user/group/host list
2003-05-06 23:52:00 +00:00
var $maxlistentries ;
2003-03-30 19:51:47 +00:00
2003-05-09 16:22:46 +00:00
// default language
var $defaultLanguage ;
2003-05-12 17:52:54 +00:00
// Path to external script and server where it is executed
2003-10-11 12:17:28 +00:00
// used for managing quota and home directories
2003-05-12 17:52:54 +00:00
// optional settings, may not be defined
var $scriptPath ;
var $scriptServer ;
2003-05-28 15:37:48 +00:00
// if "yes" use the new LDAP schema for Samba 3.x
var $samba3 ;
2003-08-18 15:21:27 +00:00
// LDAP cache timeout
2003-09-19 19:29:02 +00:00
var $cachetimeout ;
2003-08-18 15:21:27 +00:00
2003-10-04 12:34:19 +00:00
// password hash algorithm
var $pwdhash ;
2003-11-08 10:33:12 +00:00
// text to include in user PDF files
2003-11-16 09:20:31 +00:00
var $pdftext = " " ;
2003-11-08 10:33:12 +00:00
2003-07-06 10:24:41 +00:00
// name of configuration file
var $file ;
2003-09-21 20:10:52 +00:00
// list of all settings in config file
var $settings = array ( " ServerURL " , " Passwd " , " Admins " , " usersuffix " , " groupsuffix " , " hostsuffix " ,
" domainsuffix " , " MinUID " , " MaxUID " , " MinGID " , " MaxGID " , " MinMachine " , " MaxMachine " ,
" userlistAttributes " , " grouplistAttributes " , " hostlistAttributes " , " maxlistentries " ,
2003-10-04 12:34:19 +00:00
" defaultLanguage " , " scriptPath " , " scriptServer " , " samba3 " , " cachetimeout " , " pwdhash " );
2003-09-21 20:10:52 +00:00
// constructor, loads preferences from config file
function Config ( $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
2003-09-15 16:24:44 +00:00
// reloads preferences from config file
function reload () {
$conffile = substr ( __FILE__ , 0 , strlen ( __FILE__ ) - 15 ) . " /config/ " . $this -> file . " .conf " ;
if ( is_file ( $conffile ) == True ) {
$file = fopen ( $conffile , " r " );
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 . " : " )) {
2003-10-11 12:17:28 +00:00
$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 );
}
else {
StatusMessage ( " ERROR " , " " , _ ( " Unable to load configuration! " ) . " ( " . $conffile . " ) " );
}
2003-11-08 10:33:12 +00:00
// load user PDF text
$pdffile = substr ( __FILE__ , 0 , strlen ( __FILE__ ) - 15 ) . " /config/pdf/ " . $this -> file . " .txt " ;
if ( is_file ( $pdffile ) == True ) {
$pdfstring = @ file ( $pdffile );
$pdfstring = @ implode ( " " , $pdfstring );
if ( $pdfstring ) $this -> pdftext = $pdfstring ;
else $this -> pdftext = " " ;
}
2003-09-15 16:24:44 +00:00
}
2003-05-14 13:45:52 +00:00
2003-08-18 15:21:27 +00:00
// saves preferences to config file
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
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 . " : " )) {
2003-09-21 20:10:52 +00:00
$file_array [ $i ] = $keyword . " : " . $this -> $keyword . " \n " ;
$saved [] = $keyword ; // mark keyword as saved
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-21 20:10:52 +00:00
if ( ! in_array ( " MinUID " , $saved )) array_push ( $file_array , " \n \n # minimum UID number \n " . " minUID: " . $this -> MinUID . " \n " );
2003-09-30 18:42:14 +00:00
if ( ! in_array ( " MaxUID " , $saved )) array_push ( $file_array , " \n \n # maximum UID number \n " . " maxUID: " . $this -> MaxUID . " \n " );
if ( ! in_array ( " MinGID " , $saved )) array_push ( $file_array , " \n \n # minimum GID number \n " . " minGID: " . $this -> MinGID . " \n " );
if ( ! in_array ( " MaxGID " , $saved )) array_push ( $file_array , " \n \n # maximum GID number \n " . " maxGID: " . $this -> MaxGID . " \n " );
if ( ! in_array ( " MinMachine " , $saved )) array_push ( $file_array , " \n \n # minimum UID number for Samba hosts \n " . " minMachine: " . $this -> MinMachine . " \n " );
if ( ! in_array ( " MaxMachine " , $saved )) array_push ( $file_array , " \n \n # maximum UID number for Samba hosts \n " . " maxMachine: " . $this -> MaxMachine . " \n " );
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 ( " samba3 " , $saved )) array_push ( $file_array , " \n \n # Set to \" yes \" only if you use the new Samba 3.x schema. \n " . " samba3: " . $this -> samba3 . " \n " );
if ( ! in_array ( " cachetimeout " , $saved )) array_push ( $file_array , " \n \n # Number of minutes LAM caches LDAP searches. \n " . " cacheTimeout: " . $this -> cachetimeout . " \n " );
2003-10-05 10:51:01 +00:00
if ( ! in_array ( " pwdhash " , $saved )) array_push ( $file_array , " \n \n # Password hash algorithm (CRYPT/MD5/SMD5/SHA/SSHA/PLAIN). \n " . " pwdhash: " . $this -> pwdhash . " \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 );
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
}
}
2003-03-30 19:51:47 +00:00
2003-08-18 15:21:27 +00:00
// prints current preferences
function printconf () {
echo " <b> " . _ ( " Server address " ) . " : </b> " . $this -> ServerURL . " <br> " ;
2003-10-04 12:34:19 +00:00
echo " <b> " . _ ( " Password hash type " ) . " : </b> " . $this -> pwdhash . " <br> " ;
2003-09-19 19:29:02 +00:00
echo " <b> " . _ ( " Cache timeout " ) . " : </b> " . $this -> cachetimeout . " <br> " ;
2003-08-18 15:21:27 +00:00
echo " <b> " . _ ( " Samba 3.x schema " ) . " : </b> " . $this -> samba3 . " <br> " ;
2003-09-19 19:49:45 +00:00
echo " <b> " . _ ( " UserSuffix " ) . " : </b> " . $this -> usersuffix . " <br> " ;
echo " <b> " . _ ( " GroupSuffix " ) . " : </b> " . $this -> groupsuffix . " <br> " ;
echo " <b> " . _ ( " HostSuffix " ) . " : </b> " . $this -> hostsuffix . " <br> " ;
echo " <b> " . _ ( " DomainSuffix " ) . " : </b> " . $this -> domainsuffix . " <br> " ;
2003-08-18 15:21:27 +00:00
echo " <b> " . _ ( " Minimum UID number " ) . " : </b> " . $this -> MinUID . " <br> " ;
echo " <b> " . _ ( " Maximum UID number " ) . " : </b> " . $this -> MaxUID . " <br> " ;
echo " <b> " . _ ( " Minimum GID number " ) . " : </b> " . $this -> MinGID . " <br> " ;
echo " <b> " . _ ( " Maximum GID number " ) . " : </b> " . $this -> MaxGID . " <br> " ;
echo " <b> " . _ ( " Minimum Machine number " ) . " : </b> " . $this -> MinMachine . " <br> " ;
echo " <b> " . _ ( " Maximum Machine number " ) . " : </b> " . $this -> MaxMachine . " <br> " ;
echo " <b> " . _ ( " Attributes in User List " ) . " : </b> " . $this -> userlistAttributes . " <br> " ;
echo " <b> " . _ ( " Attributes in Group List " ) . " : </b> " . $this -> grouplistAttributes . " <br> " ;
echo " <b> " . _ ( " Attributes in Host List " ) . " : </b> " . $this -> hostlistAttributes . " <br> " ;
echo " <b> " . _ ( " Maximum list entries " ) . " : </b> " . $this -> maxlistentries . " <br> " ;
echo " <b> " . _ ( " Default language " ) . " : </b> " . $this -> defaultLanguage . " <br> " ;
echo " <b> " . _ ( " Path to external script " ) . " : </b> " . $this -> scriptPath . " <br> " ;
echo " <b> " . _ ( " Server of external script " ) . " : </b> " . $this -> scriptServer . " <br> " ;
2003-11-15 10:35:58 +00:00
echo " <b> " . _ ( " List of valid users " ) . " : </b> " . $this -> Admins . " <br><br> " ;
echo " <b> " . _ ( " Text for user PDF " ) . " : </b> " . $this -> get_pdftext ();
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
2003-08-18 15:21:27 +00:00
// returns the server address as string
function get_ServerURL () {
return $this -> ServerURL ;
}
2003-04-18 15:50:01 +00:00
2003-07-30 21:23:48 +00:00
// sets the server address
2003-10-11 12:17:28 +00:00
// $value: new server address
// returns 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
2003-07-30 21:23:48 +00:00
// returns an array of string with all admin names
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
2003-07-30 21:23:48 +00:00
// returns all admin users seperated by semicolons
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
2003-07-30 21:23:48 +00:00
// needs a string that contains all admin users seperated by semicolons
2003-10-11 12:17:28 +00:00
// $value: new admin string
// returns true if $value has correct format
2003-07-30 21:23:48 +00:00
function set_Adminstring ( $value ) {
if ( is_string ( $value ) &&
2003-11-06 22:02:58 +00:00
eregi ( " ^[a-z0-9 \\ -]+=[a-z0-9 \\ -]+(,[a-z0-9 \\ -]+=[a-z0-9 \\ -]+)+(;[a-z0-9 \\ -]+=[a-z0-9 \\ -]+(,[a-z0-9 \\ -]+=[a-z0-9 \\ -]+)+)* $ " , $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
2003-07-30 21:23:48 +00:00
// returns the password to access the preferences wizard
function get_Passwd () {
return $this -> Passwd ;
}
2003-05-14 13:45:52 +00:00
2003-07-30 21:23:48 +00:00
// sets the preferences wizard password
2003-10-11 12:17:28 +00:00
// $value: new password
// returns 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 ;
}
2003-05-14 13:45:52 +00:00
2003-07-30 21:23:48 +00:00
// returns the LDAP suffix where users are saved
function get_UserSuffix () {
2003-09-19 19:49:45 +00:00
return $this -> usersuffix ;
2003-07-30 21:23:48 +00:00
}
2003-05-14 13:45:52 +00:00
2003-07-30 21:23:48 +00:00
// sets the LDAP suffix where users are saved
2003-10-11 12:17:28 +00:00
// $value: new user suffix
// returns true if $value has correct format
2003-07-30 21:23:48 +00:00
function set_UserSuffix ( $value ) {
2003-11-06 22:02:58 +00:00
if ( is_string ( $value ) && ( eregi ( " ^(([a-z0-9 \\ -])*=([a-z0-9 \\ -])*)(,([a-z0-9 \\ -])*=([a-z0-9 \\ -])*)* $ " , $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 ;
2003-05-14 13:45:52 +00:00
}
2003-07-30 21:23:48 +00:00
// returns the LDAP suffix where groups are saved
function get_GroupSuffix () {
2003-09-19 19:49:45 +00:00
return $this -> groupsuffix ;
2003-07-30 21:23:48 +00:00
}
2003-05-14 13:45:52 +00:00
2003-07-30 21:23:48 +00:00
// sets the LDAP suffix where groups are saved
2003-10-11 12:17:28 +00:00
// $value: new group suffix
// returns true if $value has correct format
2003-07-30 21:23:48 +00:00
function set_GroupSuffix ( $value ) {
2003-11-06 22:02:58 +00:00
if ( is_string ( $value ) && ( eregi ( " ^(([a-z0-9 \\ -])*=([a-z0-9 \\ -])*)(,([a-z0-9 \\ -])*=([a-z0-9 \\ -])*)* $ " , $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 ;
2003-05-14 13:45:52 +00:00
}
2003-07-25 14:12:07 +00:00
// returns the LDAP suffix where hosts are saved
function get_HostSuffix () {
2003-09-19 19:49:45 +00:00
return $this -> hostsuffix ;
2003-07-25 14:12:07 +00:00
}
2003-05-14 13:45:52 +00:00
2003-07-25 14:12:07 +00:00
// sets the LDAP suffix where hosts are saved
2003-10-11 12:17:28 +00:00
// $value: new host suffix
// returns true if $value has correct format
2003-07-25 14:12:07 +00:00
function set_HostSuffix ( $value ) {
2003-11-06 22:02:58 +00:00
if ( is_string ( $value ) && ( eregi ( " ^(([a-z0-9 \\ -])*=([a-z0-9 \\ -])*)(,([a-z0-9 \\ -])*=([a-z0-9 \\ -])*)* $ " , $value ))) {
2003-09-19 19:49:45 +00:00
$this -> hostsuffix = $value ;
2003-05-14 13:45:52 +00:00
}
2003-07-30 21:23:48 +00:00
else return false ;
return true ;
2003-07-25 14:12:07 +00:00
}
// returns the LDAP suffix where domains are saved
function get_DomainSuffix () {
2003-09-19 19:49:45 +00:00
return $this -> domainsuffix ;
2003-07-25 14:12:07 +00:00
}
// sets the LDAP suffix where domains are saved
2003-10-11 12:17:28 +00:00
// $value: new domain suffix
// returns true if $value has correct format
2003-07-25 14:12:07 +00:00
function set_DomainSuffix ( $value ) {
2003-09-19 19:49:45 +00:00
if ( ! $value && ( $this -> get_Samba3 () == " no " )) $this -> domainsuffix = " " ;
2003-11-06 22:02:58 +00:00
elseif ( is_string ( $value ) && ( eregi ( " ^(([a-z0-9 \\ -])*=([a-z0-9 \\ -])*)(,([a-z0-9 \\ -])*=([a-z0-9 \\ -])*)* $ " , $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
}
2003-07-30 21:23:48 +00:00
// returns the minimum UID to use when creating new users
function get_minUID () {
return $this -> MinUID ;
}
2003-03-13 14:40:19 +00:00
2003-07-30 21:23:48 +00:00
// sets the minimum UID to use when creating new users
2003-10-11 12:17:28 +00:00
// $value: new minimum UID number
// returns true if $value has correct format
2003-07-30 21:23:48 +00:00
function set_minUID ( $value ) {
if ( is_numeric ( $value )) $this -> MinUID = $value ;
else return false ;
return true ;
}
2003-05-14 13:45:52 +00:00
2003-07-30 21:23:48 +00:00
// returns the maximum UID to use when creating new users
function get_maxUID () {
return $this -> MaxUID ;
}
2003-03-13 14:40:19 +00:00
2003-07-30 21:23:48 +00:00
// sets the maximum UID to use when creating new users
2003-10-11 12:17:28 +00:00
// $value: new maximum UID number
// returns true if $value has correct format
2003-07-30 21:23:48 +00:00
function set_maxUID ( $value ) {
if ( is_numeric ( $value )) $this -> MaxUID = $value ;
else return false ;
return true ;
}
2003-05-14 13:45:52 +00:00
2003-07-30 21:23:48 +00:00
// returns the minimum GID to use when creating new groups
function get_minGID () {
return $this -> MinGID ;
}
2003-03-13 14:40:19 +00:00
2003-07-30 21:23:48 +00:00
// sets the minimum GID to use when creating new groups
2003-10-11 12:17:28 +00:00
// $value: new minimum GID number
// returns true if $value has correct format
2003-07-30 21:23:48 +00:00
function set_minGID ( $value ) {
if ( is_numeric ( $value )) $this -> MinGID = $value ;
else return false ;
return true ;
}
2003-05-14 13:45:52 +00:00
2003-07-30 21:23:48 +00:00
// returns the maximum GID to use when creating new groups
function get_maxGID () {
return $this -> MaxGID ;
}
2003-03-13 14:40:19 +00:00
2003-07-30 21:23:48 +00:00
// sets the maximum GID to use when creating new groups
2003-10-11 12:17:28 +00:00
// $value: new maximum GID number
// returns true if $value has correct format
2003-07-30 21:23:48 +00:00
function set_maxGID ( $value ) {
if ( is_numeric ( $value )) $this -> MaxGID = $value ;
else return false ;
return true ;
}
2003-05-14 13:45:52 +00:00
2003-07-30 21:23:48 +00:00
// returns the minimum UID to use when creating new Samba hosts
function get_minMachine () {
return $this -> MinMachine ;
}
2003-03-13 14:40:19 +00:00
2003-07-30 21:23:48 +00:00
// sets the minimum UID to use when creating new Samba hosts
2003-10-11 12:17:28 +00:00
// $value: new minimum machine number
// returns true if $value has correct format
2003-07-30 21:23:48 +00:00
function set_minMachine ( $value ) {
if ( is_numeric ( $value )) $this -> MinMachine = $value ;
else return false ;
return true ;
}
2003-05-14 13:45:52 +00:00
2003-07-30 21:23:48 +00:00
// returns the maximum UID to use when creating new Samba hosts
function get_maxMachine () {
return $this -> MaxMachine ;
}
2003-05-14 13:45:52 +00:00
2003-07-30 21:23:48 +00:00
// sets the maximum UID to use when creating new Samba hosts
2003-10-11 12:17:28 +00:00
// $value: new maximum machine number
// returns true if $value has correct format
2003-07-30 21:23:48 +00:00
function set_maxMachine ( $value ) {
if ( is_numeric ( $value )) $this -> MaxMachine = $value ;
else return false ;
return true ;
}
2003-03-30 19:51:47 +00:00
2003-07-30 21:23:48 +00:00
// returns the list of attributes to show in user list
function get_userlistAttributes () {
return $this -> userlistAttributes ;
2003-05-14 13:45:52 +00:00
}
2003-03-30 19:51:47 +00:00
2003-07-30 21:23:48 +00:00
// sets the list of attributes to show in user list
2003-10-11 12:17:28 +00:00
// $value: new attribute string
// returns true if $value has correct format
2003-07-30 21:23:48 +00:00
function set_userlistAttributes ( $value ) {
2004-01-05 17:23:49 +00:00
if ( is_string ( $value ) && eregi ( " ^((#[^:;]+)|([^:;]*:[^:;]+))(;((#[^:;]+)|([^:;]*:[^:;]+)))* $ " , $value )) {
2003-07-30 21:23:48 +00:00
$this -> userlistAttributes = $value ;
}
else return false ;
return true ;
}
2003-03-30 19:51:47 +00:00
2003-07-30 21:23:48 +00:00
// returns the list of attributes to show in group list
function get_grouplistAttributes () {
return $this -> grouplistAttributes ;
2003-05-14 13:45:52 +00:00
}
2003-03-30 19:51:47 +00:00
2003-07-30 21:23:48 +00:00
// sets the list of attributes to show in group list
2003-10-11 12:17:28 +00:00
// $value: new attribute string
// returns true if $value has correct format
2003-07-30 21:23:48 +00:00
function set_grouplistAttributes ( $value ) {
2004-01-05 17:23:49 +00:00
if ( is_string ( $value ) && eregi ( " ^((#[^:;]+)|([^:;]*:[^:;]+))(;((#[^:;]+)|([^:;]*:[^:;]+)))* $ " , $value )) {
2003-07-30 21:23:48 +00:00
$this -> grouplistAttributes = $value ;
}
else return false ;
return true ;
}
2003-05-06 23:52:00 +00:00
2003-07-30 21:23:48 +00:00
// returns the list of attributes to show in host list
function get_hostlistAttributes () {
return $this -> hostlistAttributes ;
2003-05-14 13:45:52 +00:00
}
2003-05-06 23:52:00 +00:00
2003-07-30 21:23:48 +00:00
// sets the list of attributes to show in host list
2003-10-11 12:17:28 +00:00
// $value: new attribute string
// returns true if $value has correct format
2003-07-30 21:23:48 +00:00
function set_hostlistAttributes ( $value ) {
2004-01-05 17:23:49 +00:00
if ( 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
2003-07-30 21:23:48 +00:00
// returns the maximum number of rows in user/group/host lists
function get_MaxListEntries () {
return $this -> maxlistentries ;
}
2003-05-09 16:22:46 +00:00
2003-07-30 21:23:48 +00:00
// sets the maximum number of rows in user/group/host lists
2003-10-11 12:17:28 +00:00
// $value: new attribute string
// returns 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
2003-07-30 21:23:48 +00:00
// returns the default language string
function get_defaultLanguage () {
return $this -> defaultLanguage ;
}
2003-05-12 17:52:54 +00:00
2003-07-30 21:23:48 +00:00
// sets the default language string
2003-10-11 12:17:28 +00:00
// $value: new default language
// returns 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 ;
}
2003-05-12 17:52:54 +00:00
2003-07-30 21:23:48 +00:00
// returns the path to the external script
function get_scriptPath () {
return $this -> scriptPath ;
}
2003-05-12 17:52:54 +00:00
2003-07-30 21:23:48 +00:00
// sets the path to the external script
2003-10-11 12:17:28 +00:00
// $value: new script path
// returns 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 ;
}
2003-05-12 17:52:54 +00:00
2003-07-30 21:23:48 +00:00
// returns the server of the external script
function get_scriptServer () {
return $this -> scriptServer ;
2003-05-14 13:45:52 +00:00
}
2003-03-30 19:51:47 +00:00
2003-07-30 21:23:48 +00:00
// sets the server of the external script
2003-10-11 12:17:28 +00:00
// $value: new script server
// returns true if $value has correct format
2003-07-30 21:23:48 +00:00
function set_scriptServer ( $value ) {
2003-10-11 12:17:28 +00:00
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
2003-07-30 21:23:48 +00:00
// returns "yes" if Samba 3.x schema is used, otherwise "no"
function get_samba3 () {
return $this -> samba3 ;
2003-05-28 15:37:48 +00:00
}
2003-09-15 16:24:44 +00:00
// returns true if Samba 3, else false
function is_samba3 () {
if ( $this -> samba3 == " yes " ) return true ;
else return false ;
}
2003-07-30 21:23:48 +00:00
// set Samba version: "yes" means 3.x schema, "no" means 2.2.x schema
2003-10-11 12:17:28 +00:00
// $value: "yes"/"no"
// returns true if $value has correct format
2003-07-30 21:23:48 +00:00
function set_samba3 ( $value ) {
if ( is_string ( $value ) && eregi ( " ^(yes|no) $ " , $value )) {
$this -> samba3 = $value ;
}
else return false ;
return true ;
}
2003-06-19 19:01:00 +00:00
2003-08-18 15:21:27 +00:00
// returns the LDAP cache timeout in minutes
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
}
2003-08-18 16:38:41 +00:00
// returns the LDAP cache timeout in seconds
function get_cacheTimeoutSec () {
2003-09-19 19:29:02 +00:00
return $this -> cachetimeout * 60 ;
2003-08-18 16:38:41 +00:00
}
2003-10-04 12:34:19 +00:00
// sets the LDAP cache timeout in minutes (0,1,2,5,10,15)
2003-10-11 12:17:28 +00:00
// $value: new cache timeout
// returns true if $value has correct format
2003-08-18 15:21:27 +00:00
function set_cacheTimeout ( $value ) {
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
2003-10-04 12:34:19 +00:00
// returns the password hash type
function get_pwdhash () {
if ( $this -> pwdhash ) return strtoupper ( $this -> pwdhash );
else return " SSHA " ;
}
// set the password hash type (CRYPT/SHA/SSHA/MD5/SMD5)
2003-10-11 12:17:28 +00:00
// $value: new password hash algorithm
// returns true if $value has correct format
2003-10-04 12:34:19 +00:00
function set_pwdhash ( $value ) {
2003-10-05 10:51:01 +00:00
if ( is_string ( $value ) && eregi ( " ^(crypt|sha|ssha|md5|smd5|plain) $ " , $value )) {
2003-10-04 12:34:19 +00:00
$this -> pwdhash = $value ;
}
else return false ;
return true ;
}
2003-11-10 18:36:10 +00:00
// returns text for user PDF files
function get_pdftext () {
if ( $this -> pdftext ) return $this -> pdftext ;
else return " " ;
}
// set the text for user PDF files
// $value: string containing the text
// returns true if $value has correct format and could be saved
function set_pdftext ( $value ) {
2003-11-16 09:20:31 +00:00
// check if text changed
if ( $value == $this -> pdftext ) return true ;
2003-11-10 18:36:10 +00:00
if ( is_string ( $value )) {
2003-11-16 09:20:31 +00:00
// save to file
2003-11-10 18:36:10 +00:00
$pdffile = substr ( __FILE__ , 0 , strlen ( __FILE__ ) - 15 ) . " /config/pdf/ " . $this -> file . " .txt " ;
2003-11-15 10:35:58 +00:00
$file = @ fopen ( $pdffile , " w " );
if ( $file ) {
@ fputs ( $file , $value );
fclose ( $file );
$this -> pdftext = $value ;
2003-11-10 18:36:10 +00:00
}
else return false ;
$this -> pdftext = $value ;
}
else return false ;
return true ;
}
2003-02-17 21:38:54 +00:00
}
2003-03-05 16:05:23 +00:00
2003-07-06 10:24:41 +00:00
/*
// class CfgMain
*/
// manages config.cfg
class CfgMain {
// default profile
var $default ;
// password to change config.cfg
var $password ;
// constructor, loads preferences from config file
function CfgMain () {
$this -> reload ();
}
// reloads preferences from config file config.cfg
function reload () {
$conffile = substr ( __FILE__ , 0 , strlen ( __FILE__ ) - 15 ) . " /config/config.cfg " ;
if ( is_file ( $conffile ) == True ) {
$file = fopen ( $conffile , " r " );
while ( ! feof ( $file )) {
$line = fgets ( $file , 1024 );
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
if ( substr ( $line , 0 , 10 ) == " password: " ) {
2003-10-11 12:17:28 +00:00
$this -> password = substr ( $line , 10 , strlen ( $line ) - 10 );
2003-07-06 10:24:41 +00:00
continue ;
}
if ( substr ( $line , 0 , 9 ) == " default: " ) {
2003-10-11 12:17:28 +00:00
$this -> default = substr ( $line , 9 , strlen ( $line ) - 9 );
2003-07-06 10:24:41 +00:00
continue ;
}
}
fclose ( $file );
}
else {
StatusMessage ( " ERROR " , " " , _ ( " Unable to load configuration! " ) . " ( " . $conffile . " ) " );
}
}
// saves preferences to config file config.cfg
function save () {
$conffile = substr ( __FILE__ , 0 , strlen ( __FILE__ ) - 15 ) . " /config/config.cfg " ;
if ( is_file ( $conffile ) == True ) {
// booleans to check if value was already saved
$save_password = $save_default = False ;
$file = fopen ( $conffile , " r " );
$file_array = array ();
// read config file
while ( ! feof ( $file )) {
array_push ( $file_array , fgets ( $file , 1024 ));
}
fclose ( $file );
// generate new configuration file
for ( $i = 0 ; $i < sizeof ( $file_array ); $i ++ ) {
if (( $file_array [ $i ] == " \n " ) || ( $file_array [ $i ][ 0 ] == " # " )) continue ; // ignore comments
// search for keywords
if ( substr ( $file_array [ $i ], 0 , 10 ) == " password: " ) {
$file_array [ $i ] = " password: " . $this -> password . " \n " ;
$save_password = True ;
continue ;
}
if ( substr ( $file_array [ $i ], 0 , 9 ) == " default: " ) {
$file_array [ $i ] = " default: " . $this -> default . " \n " ;
$save_default = True ;
continue ;
}
}
}
// check if we have to add new entries (e.g. if user upgraded LAM and has an old config file)
if ( ! $save_password == True ) array_push ( $file_array , " \n \n # password to add/delete/rename configuration profiles \n " . " password: " . $this -> password );
if ( ! $save_default == True ) array_push ( $file_array , " \n \n # default profile, without \" .conf \" \n " . " default: " . $this -> default );
$file = fopen ( $conffile , " w " );
if ( $file ) {
for ( $i = 0 ; $i < sizeof ( $file_array ); $i ++ ) fputs ( $file , $file_array [ $i ]);
fclose ( $file );
}
else {
StatusMessage ( " ERROR " , " " , _ ( " Cannot open config file! " ) . " ( " . $conffile . " ) " );
exit ;
}
}
}
2003-03-05 18:38:19 +00:00
?>