2003-12-21 14:52:23 +00:00
< ? php
/*
$Id $
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 Tilo Lutz
2003-12-21 14:52:23 +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 .
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 .
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
*/
2005-07-21 10:33:02 +00:00
/**
* Manages the object class " account " for users and hosts.
*
* @ package modules
*
* @ author Tilo Lutz
* @ author Roland Gruber
* @ author Michael Duergner
*/
/**
* Manages the object class " account " for users and hosts.
*
* @ package modules
*/
2004-06-08 18:54:37 +00:00
class account extends baseModule {
2004-06-13 19:58:58 +00:00
/**
* Returns meta data that is interpreted by parent class
*
* @ return array array with meta data
*/
function get_metaData () {
2005-08-13 16:38:56 +00:00
if ( $_SESSION [ 'loggedIn' ]) {
$modules = $_SESSION [ 'config' ] -> get_AccountModules ( $this -> get_scope ());
}
2004-06-13 19:58:58 +00:00
$return = array ();
// manages host accounts
2004-10-17 09:44:21 +00:00
$return [ " account_types " ] = array ( " host " , " user " );
2004-06-14 16:05:36 +00:00
// alias name
$return [ " alias " ] = _ ( 'Account' );
2005-01-10 10:41:38 +00:00
// this is a base module
$return [ " is_base " ] = true ;
2005-08-13 12:21:30 +00:00
// LDAP filter
$return [ " ldap_filter " ] = array ( 'or' => " (objectClass=account) " );
// RDN attribute
$return [ " RDN " ] = array ( " uid " => " low " );
2004-06-20 17:32:02 +00:00
// module dependencies
2005-01-10 10:41:38 +00:00
$return [ 'dependencies' ] = array ( 'depends' => array (), 'conflicts' => array ());
2006-04-05 15:48:27 +00:00
// managed object classes
$return [ 'objectClasses' ] = array ( 'account' );
2006-05-01 16:18:16 +00:00
// LDAP aliases
$return [ 'LDAPaliases' ] = array ( 'userid' => 'uid' );
2006-05-13 08:55:31 +00:00
// managed attributes
$return [ 'attributes' ] = array ( 'uid' , 'description' );
2004-08-17 15:16:17 +00:00
// available PDF fields
2004-10-30 16:46:06 +00:00
$return [ 'PDF_fields' ] = array (
'description'
);
2005-08-13 16:38:56 +00:00
if ( $_SESSION [ 'loggedIn' ] && ! in_array ( 'posixAccount' , $modules )) {
2005-08-13 12:21:30 +00:00
$return [ 'PDF_fields' ][] = 'uid' ;
}
2004-09-08 17:39:06 +00:00
// help Entries
2004-10-30 16:46:06 +00:00
$return [ 'help' ] = array (
'host' => array (
'description' => array (
2005-11-03 12:14:28 +00:00
" Headline " => _ ( " Description " ),
2004-10-30 16:46:06 +00:00
" Text " => _ ( " Host description. If left empty host name will be used. " )
)
)
);
2004-11-05 16:53:38 +00:00
// upload columns
if ( $_SESSION [ 'loggedIn' ]) {
if ( $this -> get_scope () == 'user' ) {
$return [ 'upload_columns' ][] = array (
'name' => 'account_hosts' ,
'description' => _ ( 'Host list' ),
'help' => 'host'
);
}
if ( ! in_array ( 'posixAccount' , $modules )) {
$return [ 'upload_columns' ][] = array (
'name' => 'account_uid' ,
'description' => _ ( 'User name' ),
'help' => 'uid' ,
'required' => true
);
$return [ 'upload_columns' ] = array (
array (
'name' => 'account_description' ,
'description' => _ ( 'Description' ),
'help' => 'description'
)
);
}
}
2004-06-13 19:58:58 +00:00
return $return ;
}
2005-08-13 12:21:30 +00:00
/**
* This function fills the message array .
*/
2004-09-28 16:46:53 +00:00
function load_Messages () {
2005-08-13 12:21:30 +00:00
$this -> messages [ 'uid' ][ 0 ] = array ( 'ERROR' , _ ( 'User name' ), _ ( 'User name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !' ));
$this -> messages [ 'uid' ][ 1 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' posixAccount_userName' , _ ( 'User name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !' ));
$this -> messages [ 'uid' ][ 2 ] = array ( 'WARN' , _ ( 'User name' ), _ ( 'You are using a capital letters. This can cause problems because windows isn\'t case-sensitive.' ));
$this -> messages [ 'uid' ][ 3 ] = array ( 'ERROR' , _ ( 'User name' ), _ ( 'User name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !' ));
2004-09-28 16:46:53 +00:00
}
2005-08-13 12:21:30 +00:00
/**
* This functions returns true if all needed settings are done .
*
* @ return boolean true if LDAP operation can be done
2004-02-09 18:11:01 +00:00
*/
function module_complete () {
2005-08-26 08:53:16 +00:00
$modules = $_SESSION [ 'config' ] -> get_AccountModules ( $this -> get_scope ());
if ( ! in_array ( 'posixAccount' , $modules ) && $this -> attributes [ 'uid' ][ 0 ] == '' ) return false ;
2004-02-09 18:11:01 +00:00
return true ;
2005-08-13 09:19:40 +00:00
}
2004-02-09 18:11:01 +00:00
2005-08-26 08:53:16 +00:00
/**
* Controls if the module button the account page is visible and activated .
*
* @ return string status ( " enabled " , " disabled " , " hidden " )
*/
function getButtonStatus () {
if ( ! $_SESSION [ $this -> base ] -> isNewAccount ) {
// check if account is based on our object class
$objectClasses = $_SESSION [ $this -> base ] -> attributes_orig [ 'objectClass' ];
if ( is_array ( $objectClasses ) && ! in_array ( 'account' , $objectClasses )) {
return " disabled " ;
}
}
return " enabled " ;
}
2003-12-27 11:21:00 +00:00
/* This function returns an array with 4 entries :
* array ( DN1 ( 'add' => array ( $attr ), 'remove' => array ( $attr ), 'modify' => array ( $attr ), 'lamdaemon' => array ( cmds )), DN2 .... )
2003-12-21 14:52:23 +00:00
* DN is the DN to change . It may be possible to change several DNs ,
* e . g . create a new user and add him to some groups via attribute memberUid
* add are attributes which have to be added to ldap entry
* remove are attributes which have to be removed from ldap entry
2003-12-27 11:21:00 +00:00
* lamdaemon are lamdaemon commands to modify homedir , quotas , ...
2003-12-21 14:52:23 +00:00
*/
function save_attributes () {
2005-08-26 08:53:16 +00:00
// skip saving if account is based on another structural object class
if ( ! $_SESSION [ $this -> base ] -> isNewAccount && ! in_array ( 'account' , $_SESSION [ $this -> base ] -> attributes_orig [ 'objectClass' ])) {
return array ();
}
2003-12-27 11:21:00 +00:00
// Get easy attributes
2003-12-21 14:52:23 +00:00
$return = $_SESSION [ $this -> base ] -> save_module_attributes ( $this -> attributes , $this -> orig );
2003-12-27 11:21:00 +00:00
// Return attributes
2003-12-21 14:52:23 +00:00
return $return ;
2005-08-26 08:53:16 +00:00
}
2003-12-21 14:52:23 +00:00
2005-09-07 12:58:34 +00:00
/**
* Processes user input of the primary module page .
* It checks if all input values are correct and updates the associated LDAP attributes .
*
* @ param array $post HTTP - POST values
* @ return array list of info / error messages
2003-12-21 14:52:23 +00:00
*/
2005-03-10 18:35:04 +00:00
function process_attributes ( & $post ) {
2003-12-30 15:36:30 +00:00
// Load attributes
$this -> attributes [ 'description' ][ 0 ] = $post [ 'description' ];
2005-08-26 08:53:16 +00:00
// user name if no posixAccount
$modules = $_SESSION [ 'config' ] -> get_AccountModules ( $this -> get_scope ());
if ( ! in_array ( 'posixAccount' , $modules )) {
$this -> attributes [ 'uid' ][ 0 ] = $post [ 'uid' ];
if ( ! get_preg ( $this -> attributes [ 'uid' ][ 0 ], '!upper' )) $triggered_messages [ 'uid' ][] = $this -> messages [ 'uid' ][ 2 ];
if ( ! get_preg ( $this -> attributes [ 'uid' ][ 0 ], 'username' )) $triggered_messages [ 'uid' ][] = $this -> messages [ 'uid' ][ 3 ];
2003-12-21 14:52:23 +00:00
}
2005-08-26 08:53:16 +00:00
}
2003-12-21 14:52:23 +00:00
/* This function will create the html - page
* to show a page with all attributes .
* It will output a complete html - table
*/
2005-02-16 21:00:19 +00:00
function display_html_attributes ( & $post ) {
2005-08-13 12:21:30 +00:00
// user name if no posixAccount
$modules = $_SESSION [ 'config' ] -> get_AccountModules ( $this -> get_scope ());
if ( ! in_array ( 'posixAccount' , $modules )) {
$return [] = array (
0 => array ( 'kind' => 'text' , 'text' => _ ( " User name " ) . '*' ),
1 => array ( 'kind' => 'input' , 'name' => 'uid' , 'type' => 'text' , 'size' => '30' , 'maxlength' => '20' ,
'value' => $this -> attributes [ 'uid' ][ 0 ]),
2 => array ( 'kind' => 'help' , 'value' => 'uid' ));
}
// description
2004-01-18 12:52:52 +00:00
$return [] = array ( 0 => array ( 'kind' => 'text' , 'text' => _ ( 'Description' ) ),
1 => array ( 'kind' => 'input' , 'name' => 'description' , 'type' => 'text' , 'size' => '30' ,
'maxlength' => '255' , 'value' => $this -> attributes [ 'description' ][ 0 ] ),
2 => array ( 'kind' => 'help' , 'value' => 'description' ));
return $return ;
2005-08-13 12:21:30 +00:00
}
2003-12-21 14:52:23 +00:00
2005-10-09 18:05:32 +00:00
/**
* Returns the PDF entries for this module .
*
* @ return array list of possible PDF entries
*/
function get_pdfEntries () {
2005-08-13 12:21:30 +00:00
$return = array ();
$return [ 'account_description' ] = array ( '<block><key>' . _ ( 'Description' ) . '</key><value>' . $this -> attributes [ 'description' ][ 0 ] . '</value></block>' );
$return [ 'account_uid' ] = array ( '<block><key>' . _ ( 'User name' ) . '</key><value>' . $this -> attributes [ 'uid' ][ 0 ] . '</value></block>' );
return $return ;
2004-05-24 21:39:57 +00:00
}
2004-03-14 17:33:05 +00:00
2004-11-05 16:53:38 +00:00
/**
* In this function the LDAP account is built up .
*
* @ param array $rawAccounts list of hash arrays ( name => value ) from user input
* @ param array $partialAccounts list of hash arrays ( name => value ) which are later added to LDAP
* @ param array $ids list of IDs for column position ( e . g . " posixAccount_uid " => 5 )
* @ return array list of error messages if any
*/
function build_uploadAccounts ( $rawAccounts , $ids , & $partialAccounts ) {
$messages = array ();
for ( $i = 0 ; $i < sizeof ( $rawAccounts ); $i ++ ) {
// add object class
if ( ! in_array ( " account " , $partialAccounts [ $i ][ 'objectClass' ])) $partialAccounts [ $i ][ 'objectClass' ][] = " account " ;
$modules = $_SESSION [ 'config' ] -> get_AccountModules ( $this -> get_scope ());
if ( ! in_array ( 'posixAccount' , $modules )) {
// description
if ( $rawAccounts [ $i ][ $ids [ 'account_description' ]] && ( $rawAccounts [ $i ][ $ids [ 'account_description' ]] != '' )) {
$partialAccounts [ $i ][ 'description' ] = $rawAccounts [ $i ][ $ids [ 'account_description' ]];
}
else {
$partialAccounts [ $i ][ 'description' ] = $rawAccounts [ $i ][ $ids [ 'account_uid' ]];
}
// user name
if ( get_preg ( $rawAccounts [ $i ][ $ids [ 'account_uid' ]], 'username' )) {
$partialAccounts [ $i ][ 'uid' ] = $rawAccounts [ $i ][ $ids [ 'account_uid' ]];
}
else {
2005-08-13 12:21:30 +00:00
$errMsg = $this -> messages [ 'uid' ][ 1 ];
2004-11-05 16:53:38 +00:00
array_push ( $errMsg , array ( $i ));
$triggered_messages [] = $errMsg ;
}
}
}
return $messages ;
}
2004-03-09 12:03:39 +00:00
}
2003-12-21 14:52:23 +00:00
?>