2003-12-09 18:42:50 +00:00
< ? php
/*
2004-10-16 14:28:06 +00:00
$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
2004-10-16 14:28:06 +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
2003-12-09 18:42:50 +00:00
*/
2005-07-21 10:33:02 +00:00
/**
* Manages Unix accounts for users and hosts .
*
* @ package modules
*
* @ author Tilo Lutz
* @ author Roland Gruber
* @ author Michael Duergner
*/
/**
* Manages the object class " posixAccount " for users and hosts.
*
* @ package modules
*/
2004-06-08 18:54:37 +00:00
class posixAccount extends baseModule {
2004-09-27 15:45:12 +00:00
function dynamic_Message ( $attribute , $id ) {
2004-10-12 13:34:00 +00:00
switch ( $attribute ) {
case 'homeDirectory' : switch ( $id ) {
case 2 : return array ( 'INFO' , _ ( 'Home directory' ), sprintf ( _ ( 'Home directory changed. To keep home directory you have to run the following command as root: \'mv %s %s\'' ), $this -> orig [ 'homeDirectory' ][ 0 ], $this -> attributes [ 'homeDirectory' ][ 0 ]));
break ;
2004-09-27 15:45:12 +00:00
}
break ;
2004-10-12 13:34:00 +00:00
case 'gidNumber' : switch ( $id ) {
case 0 : return array ( 'INFO' , _ ( 'GID number' ), sprintf ( _ ( 'GID number has changed. To keep file ownership you have to run the following command as root: \'find / -gid %s -uid %s -exec chgrp %s {} \;\'' ), $this -> orig [ 'gidNumber' ][ 0 ], $this -> orig [ 'uidNumber' ][ 0 ], $_SESSION [ 'cache' ] -> getgid ( $this -> attribtues [ 'gidNumber' ][ 0 ])));
break ;
2004-09-27 15:45:12 +00:00
}
break ;
2004-10-12 13:34:00 +00:00
case 'uidNumber' : switch ( $id ) {
case 0 : return array ( 'INFO' , _ ( 'UID number' ), sprintf ( _ ( 'UID number has changed. To keep file ownership you have to run the following command as root: \'find / -uid %s -exec chown %s {} \;\'' ), $this -> orig [ 'uidNumber' ][ 0 ], $this -> attributes [ 'uidNumber' ][ 0 ]));
break ;
2004-09-27 15:45:12 +00:00
}
2004-10-12 13:34:00 +00:00
break ;
2004-09-27 15:45:12 +00:00
}
}
2004-10-12 13:34:00 +00:00
2004-09-26 13:48:52 +00:00
/** this functin fills the error message array with messages
**/
function load_Messages () {
2004-10-12 13:34:00 +00:00
// error messages for input checks
$this -> messages [ 'minUID' ][ 0 ] = array ( 'ERROR' , _ ( 'Users' ) . ': ' . _ ( 'Minimum UID number' ), _ ( " Minimum UID number is invalid! " ));
$this -> messages [ 'maxUID' ][ 0 ] = array ( 'ERROR' , _ ( 'Users' ) . ': ' . _ ( 'Maximum UID number' ), _ ( " Maximum UID number is invalid! " ));
$this -> messages [ 'minMachine' ][ 0 ] = array ( 'ERROR' , _ ( 'Hosts' ) . ': ' . _ ( 'Minimum UID number' ), _ ( " Minimum UID number is invalid! " ));
$this -> messages [ 'maxMachine' ][ 0 ] = array ( 'ERROR' , _ ( 'Hosts' ) . ': ' . _ ( 'Maximum UID number' ), _ ( " Maximum UID number is invalid! " ));
$this -> messages [ 'cmp_UID' ][ 0 ] = array ( 'ERROR' , _ ( 'Users' ) . ': ' . _ ( 'Maximum UID number' ), _ ( " Maximum UID number must be greater than minimum UID number! " ));
$this -> messages [ 'cmp_Machine' ][ 0 ] = array ( 'ERROR' , _ ( 'Hosts' ) . ': ' . _ ( 'Maximum UID number' ), _ ( " Maximum UID number must be greater than minimum UID number! " ));
2004-10-25 18:40:18 +00:00
$this -> messages [ 'cmp_both' ][ 0 ] = array ( 'ERROR' , _ ( 'UID ranges for Unix accounts' ), _ ( " The UID ranges for users and hosts overlap! This is a problem because LAM uses the highest UID in use + 1 for new accounts. Please set the minimum UID to equal values or use independent ranges. " ));
2004-10-12 13:34:00 +00:00
$this -> messages [ 'homeDirectory' ][ 0 ] = array ( 'ERROR' , _ ( 'Home directory' ), _ ( 'Homedirectory contains invalid characters.' ));
$this -> messages [ 'homeDirectory' ][ 1 ] = array ( 'INFO' , _ ( 'Home directory' ), _ ( 'Replaced $user or $group in homedir.' ));
2004-10-17 18:29:39 +00:00
$this -> messages [ 'homeDirectory' ][ 2 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' posixAccount_homedir' , _ ( 'Homedirectory contains invalid characters.' ));
2004-10-12 13:34:00 +00:00
$this -> messages [ 'uidNumber' ][ 1 ] = array ( 'ERROR' , _ ( 'ID-Number' ), _ ( 'No free ID-Number!' ));
$this -> messages [ 'uidNumber' ][ 2 ] = array ( 'WARN' , _ ( 'ID-Number' ), _ ( 'It is possible that this ID-number is reused. This can cause several problems because files with old permissions might still exist. To avoid this warning set maxUID to a higher value.' ));
$this -> messages [ 'uidNumber' ][ 3 ] = array ( 'ERROR' , _ ( 'ID-Number' ), _ ( 'ID is already in use' ));
2004-10-23 11:54:44 +00:00
$this -> messages [ 'uidNumber' ][ 4 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' posixAccount_uid' , _ ( 'UID must be a number. It has to be inside the UID range which is defined in your configuration profile.' ));
2005-08-15 18:10:38 +00:00
$this -> messages [ 'userPassword' ][ 0 ] = array ( 'ERROR' , _ ( 'Password' ), _ ( 'Please enter the same password in both password fields.' ));
2004-10-12 13:34:00 +00:00
$this -> messages [ 'userPassword' ][ 1 ] = array ( 'ERROR' , _ ( 'Password' ), _ ( 'Password contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and #*,.;:_-+!$%&/|?{[()]}= !' ));
2005-08-15 18:10:38 +00:00
$this -> messages [ 'userPassword' ][ 3 ] = array ( 'ERROR' , _ ( 'Password' ), _ ( 'You cannot use these password options at the same time.' ));
2004-10-17 18:29:39 +00:00
$this -> messages [ 'userPassword' ][ 4 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' posixAccount_password' , _ ( 'Password contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and #*,.;:_-+!$%&/|?{[()]}= !' ));
2004-10-12 13:34:00 +00:00
$this -> messages [ 'uid' ][ 0 ] = array ( 'INFO' , _ ( 'UID' ), _ ( 'UID has changed. Do you want to change home directory?' ));
2005-06-19 09:38:44 +00:00
$this -> messages [ 'uid' ][ 1 ] = array ( 'WARN' , _ ( 'User name' ), _ ( 'You are using a capital letters. This can cause problems because windows isn\'t case-sensitive.' ));
$this -> messages [ 'uid' ][ 2 ] = array ( 'ERROR' , _ ( 'User name' ), _ ( 'User name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !' ));
$this -> messages [ 'uid' ][ 3 ] = array ( 'WARN' , _ ( 'Host name' ), _ ( 'You are using a capital letters. This can cause problems because windows isn\'t case-sensitive.' ));
$this -> messages [ 'uid' ][ 4 ] = array ( 'ERROR' , _ ( 'Host name' ), _ ( 'Host name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ ! Host name must end with $ !' ));
$this -> messages [ 'uid' ][ 5 ] = array ( 'WARN' , _ ( 'User name' ), _ ( 'User name in use. Selected next free user name.' ));
$this -> messages [ 'uid' ][ 6 ] = array ( 'WARN' , _ ( 'Host name' ), _ ( 'Host name in use. Selected next free host name.' ));
2005-06-08 21:02:01 +00:00
$this -> messages [ 'uid' ][ 7 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' posixAccount_userName' , _ ( 'User name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !' ));
$this -> messages [ 'uid' ][ 8 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' posixAccount_hostName' , _ ( 'Host name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !' ));
$this -> messages [ 'uid' ][ 9 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' posixAccount_userName' , _ ( 'User name already exists!' ));
$this -> messages [ 'uid' ][ 10 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' posixAccount_hostName' , _ ( 'Host name already exists!' ));
2004-10-17 18:29:39 +00:00
$this -> messages [ 'gidNumber' ][ 0 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' posixAccount_group' , _ ( 'LAM was unable to find a group with this name!' ));
$this -> messages [ 'gidNumber' ][ 1 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' posixAccount_group' , _ ( 'This GID number is invalid! Please provide either a number or a group name.' ));
2004-10-23 11:54:44 +00:00
$this -> messages [ 'gecos' ][ 0 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' posixAccount_gecos' , _ ( 'This gecos value is invalid!' ));
2004-10-17 18:29:39 +00:00
$this -> messages [ 'shell' ][ 0 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' posixAccount_shell' , _ ( 'This login shell is invalid!' ));
$this -> messages [ 'passwordDisabled' ][ 0 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' posixAccount_passwordDisabled' , _ ( 'This value can only be \"true\" or \"false\".' ));
2005-06-19 09:38:44 +00:00
$this -> messages [ 'cn' ][ 0 ] = array ( 'ERROR' , _ ( 'Common name' ), _ ( 'Please enter a valid common name!' ));
$this -> messages [ 'cn' ][ 1 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' inetOrgPerson_cn' , _ ( 'Please enter a valid common name!' ));
2004-09-26 13:48:52 +00:00
}
2004-06-08 18:54:37 +00:00
/**
* Returns meta data that is interpreted by parent class
*
* @ return array array with meta data
*/
function get_metaData () {
$return = array ();
2004-06-13 19:58:58 +00:00
// manages user and host accounts
$return [ " account_types " ] = array ( " user " , " host " );
// user specific data
2004-06-08 18:54:37 +00:00
if ( $this -> get_scope () == " user " ) {
2004-06-11 15:44:49 +00:00
// LDAP filter
$return [ " ldap_filter " ] = array ( 'or' => " (objectClass=posixAccount) " , 'and' => " (!(uid=* $ )) " );
2004-06-20 17:32:02 +00:00
// module dependencies
2005-04-04 15:57:35 +00:00
$return [ 'dependencies' ] = array ( 'depends' => array (), 'conflicts' => array ());
2004-06-20 17:32:02 +00:00
}
elseif ( $this -> get_scope () == " host " ) {
// module dependencies
2005-04-04 15:57:35 +00:00
$return [ 'dependencies' ] = array ( 'depends' => array (), 'conflicts' => array ());
2004-06-08 18:54:37 +00:00
}
2004-06-14 16:05:36 +00:00
// alias name
$return [ " alias " ] = _ ( " Unix " );
2004-10-06 18:17:22 +00:00
// RDN attributes
$return [ " RDN " ] = array ( " uid " => " normal " , " cn " => " low " );
2004-07-02 16:09:44 +00:00
// profile checks
2005-01-16 12:41:38 +00:00
$return [ 'profile_checks' ][ 'posixAccount_homeDirectory' ] = array ( 'type' => 'ext_preg' , 'regex' => 'homeDirectory' ,
2004-10-12 13:34:00 +00:00
'error_message' => $this -> messages [ 'homeDirectory' ][ 0 ]);
2005-01-16 12:41:38 +00:00
// profile mappings
$return [ 'profile_mappings' ] = array (
'posixAccount_homeDirectory' => 'homeDirectory' ,
'posixAccount_loginShell' => 'loginShell'
);
2004-08-01 09:39:24 +00:00
// configuration options
$return [ 'config_options' ][ 'user' ] = array (
2004-10-12 13:34:00 +00:00
array (
2004-10-16 14:28:06 +00:00
0 => array ( 'kind' => 'text' , 'text' => '<b>' . _ ( " Users " ) . ': </b>' . _ ( 'Minimum UID number' ) . " : " ),
1 => array ( 'kind' => 'input' , 'name' => 'posixAccount_minUID' , 'type' => 'text' , 'size' => '10' , 'maxlength' => '255' ),
2 => array ( 'kind' => 'text' , 'value' => ' ' ),
3 => array ( 'kind' => 'text' , 'text' => _ ( 'Maximum UID number' ) . " : " ),
4 => array ( 'kind' => 'input' , 'name' => 'posixAccount_maxUID' , 'type' => 'text' , 'size' => '10' , 'maxlength' => '255' ),
5 => array ( 'kind' => 'help' , 'value' => 'minMaxUser' ))
2004-08-01 09:39:24 +00:00
);
$return [ 'config_options' ][ 'host' ] = array (
2004-10-12 13:34:00 +00:00
array (
2004-10-16 14:28:06 +00:00
0 => array ( 'kind' => 'text' , 'text' => '<b>' . _ ( " Hosts " ) . ': </b>' . _ ( 'Minimum UID number' ) . " : " ),
1 => array ( 'kind' => 'input' , 'name' => 'posixAccount_minMachine' , 'type' => 'text' , 'size' => '10' , 'maxlength' => '255' ),
2 => array ( 'kind' => 'text' , 'value' => ' ' ),
3 => array ( 'kind' => 'text' , 'text' => _ ( 'Maximum UID number' ) . " : " ),
4 => array ( 'kind' => 'input' , 'name' => 'posixAccount_maxMachine' , 'type' => 'text' , 'size' => '10' , 'maxlength' => '255' ),
5 => array ( 'kind' => 'help' , 'value' => 'minMaxHost' ))
2004-08-01 09:39:24 +00:00
);
2004-08-03 18:49:19 +00:00
$return [ 'config_options' ][ 'all' ] = array (
2004-10-12 13:34:00 +00:00
array (
2004-10-16 14:28:06 +00:00
0 => array ( 'kind' => 'text' , 'text' => '<b>' . _ ( " Password hash type " ) . ': </b>' ),
1 => array ( 'kind' => 'select' , 'name' => 'posixAccount_pwdHash' , 'size' => '1' ,
'options' => array ( " CRYPT " , " SHA " , " SSHA " , " MD5 " , " SMD5 " , " PLAIN " ), 'options_selected' => array ( 'SSHA' )),
2 => array ( 'kind' => 'text' , 'value' => ' ' ),
3 => array ( 'kind' => 'text' , 'value' => ' ' ),
4 => array ( 'kind' => 'text' , 'value' => ' ' ),
5 => array ( 'kind' => 'help' , 'value' => 'pwdHash' ))
2004-08-03 18:49:19 +00:00
);
2004-08-01 09:39:24 +00:00
// configuration descriptions
$return [ 'config_descriptions' ] = array (
2004-10-16 14:28:06 +00:00
'legend' => _ ( " UID ranges for Unix accounts " ),
'descriptions' => array (
'posixAccount_minUID' => _ ( " Minimum UID number for Unix accounts (users) " ),
'posixAccount_maxUID' => _ ( " Maximum UID number for Unix accounts (users) " ),
'posixAccount_minMachine' => _ ( " Minimum UID number for Unix accounts (hosts) " ),
'posixAccount_maxMachine' => _ ( " Maximum UID number for Unix accounts (hosts) " ),
2004-10-23 11:54:44 +00:00
'posixAccount_pwdHash' => _ ( " Password hash type for Unix accounts " ),
2004-10-12 13:34:00 +00:00
)
2004-08-01 09:39:24 +00:00
);
2004-10-16 14:28:06 +00:00
// upload
$return [ 'upload_preDepends' ] = array ( 'inetOrgPerson' );
// user specific upload options
if ( $this -> scope == 'user' ) {
$return [ 'upload_columns' ] = array (
array (
'name' => 'posixAccount_userName' ,
'description' => _ ( 'User name' ),
2005-06-02 20:30:18 +00:00
'help' => 'uid' ,
2004-10-16 14:28:06 +00:00
'example' => _ ( 'smiller' ),
'required' => true ,
'unique' => true
),
2005-06-19 09:38:44 +00:00
array (
'name' => 'posixAccount_cn' ,
'description' => _ ( 'Common name' ),
'help' => 'cn' ,
'example' => _ ( 'Steve Miller' )
),
2004-10-16 14:28:06 +00:00
array (
'name' => 'posixAccount_uid' ,
'description' => _ ( 'UID number' ),
2005-06-02 20:30:18 +00:00
'help' => 'uidNumber' ,
2004-10-23 11:54:44 +00:00
'example' => '1234'
2004-10-16 14:28:06 +00:00
),
array (
'name' => 'posixAccount_group' ,
'description' => _ ( 'Primary group' ),
2005-06-02 20:30:18 +00:00
'help' => 'group_upload' ,
2004-10-16 14:28:06 +00:00
'example' => _ ( 'users' ),
'required' => true
),
array (
'name' => 'posixAccount_additionalGroups' ,
'description' => _ ( 'Additional groups' ),
2005-06-02 20:30:18 +00:00
'help' => 'addgroup_upload' ,
2004-10-16 14:28:06 +00:00
'example' => _ ( 'group01,group02' )
),
array (
'name' => 'posixAccount_homedir' ,
'description' => _ ( 'Home directory' ),
2005-06-02 20:30:18 +00:00
'help' => 'homeDirectory_upload' ,
2004-10-16 14:28:06 +00:00
'example' => _ ( '/home/smiller' ),
'default' => '/home/<i><posixAccount_userName></i>'
),
array (
'name' => 'posixAccount_shell' ,
'description' => _ ( 'Login shell' ),
2005-06-02 20:30:18 +00:00
'help' => 'loginShell' ,
2004-10-23 11:54:44 +00:00
'example' => '/bin/bash' ,
2004-10-16 14:28:06 +00:00
'values' => implode ( " , " , getshells ()),
'default' => '/bin/bash'
),
array (
'name' => 'posixAccount_password' ,
'description' => _ ( 'Password' ),
2005-06-02 20:30:18 +00:00
'help' => 'userPassword' ,
2004-10-16 14:28:06 +00:00
'example' => _ ( 'secret' )
),
array (
'name' => 'posixAccount_passwordDisabled' ,
'description' => _ ( 'Lock password' ),
2005-06-02 20:30:18 +00:00
'help' => 'userPassword_lock' ,
2004-10-24 20:36:02 +00:00
'example' => 'false' ,
2004-10-16 14:28:06 +00:00
'values' => 'true, false' ,
'default' => 'false'
),
array (
'name' => 'posixAccount_gecos' ,
2004-10-23 11:54:44 +00:00
'description' => _ ( 'Gecos' ),
2004-10-16 14:28:06 +00:00
'help' => 'gecos' ,
'example' => _ ( 'Steve Miller,Room 2.14,123-123-1234,123-123-1234' )
)
);
}
// host specific upload options
elseif ( $this -> scope == 'host' ) {
$return [ 'upload_columns' ] = array (
array (
'name' => 'posixAccount_hostName' ,
'description' => _ ( 'Host name' ),
2005-06-02 20:30:18 +00:00
'help' => 'uid' ,
2004-10-16 14:28:06 +00:00
'example' => _ ( 'pc01$' ),
'required' => true ,
'unique' => true
),
array (
'name' => 'posixAccount_uid' ,
'description' => _ ( 'UID number' ),
2005-06-02 20:30:18 +00:00
'help' => 'uidNumber' ,
2004-10-23 11:54:44 +00:00
'example' => '1234'
2004-10-16 14:28:06 +00:00
),
array (
'name' => 'posixAccount_group' ,
'description' => _ ( 'Primary group' ),
2005-06-02 20:30:18 +00:00
'help' => 'group_upload' ,
2004-10-16 14:28:06 +00:00
'example' => _ ( 'machines' ),
'required' => true
),
array (
'name' => 'posixAccount_gecos' ,
2004-10-23 11:54:44 +00:00
'description' => _ ( 'Gecos' ),
2004-10-16 14:28:06 +00:00
'help' => 'gecos' ,
'example' => _ ( 'pc01,Room 2.34' )
)
);
}
2004-11-05 16:53:38 +00:00
if ( $_SESSION [ 'loggedIn' ]) {
$modules = $_SESSION [ 'config' ] -> get_AccountModules ( $this -> get_scope ());
if ( ! in_array ( 'inetOrgPerson' , $modules )) {
$return [ 'upload_columns' ][] =
array (
'name' => 'posixAccount_description' ,
'description' => _ ( 'Description' ),
'help' => 'description'
);
}
}
2004-08-17 15:16:17 +00:00
// available PDF fields
2004-10-16 14:28:06 +00:00
$return [ 'PDF_fields' ] = array (
'uid' ,
'uidNumber' ,
'gidNumber' ,
'gecos' ,
'primaryGroup' ,
'additionalGroups' ,
'homeDirectory' ,
'userPassword' ,
2005-06-19 09:38:44 +00:00
'loginShell' ,
'cn'
2004-10-30 16:46:06 +00:00
);
2004-09-08 14:41:57 +00:00
// help Entries
2004-10-02 18:45:11 +00:00
$return [ 'help' ] = array (
2004-10-30 16:46:06 +00:00
'minMaxUser' => array (
'Headline' => _ ( 'UID number' ),
'Text' => _ ( 'These are the minimum and maximum numbers to use for user IDs when creating new user accounts. The range should be different from that of machines. New user accounts will always get the highest number in use plus one.' )
),
'minMaxHost' => array (
'Headline' => _ ( 'UID number' ),
'Text' => _ ( 'These are the minimum and maximum numbers to use for machine IDs when creating new accounts for Samba hosts. The range should be different from that of users. New host accounts will always get the highest number in use plus one.' )
),
'pwdHash' => array (
" Headline " => _ ( " Password hash type " ),
" Text " => _ ( " LAM supports CRYPT, SHA, SSHA, MD5 and SMD5 to generate the hash value of passwords. SSHA and CRYPT are the most common but CRYPT does not support passwords greater than 8 letters. We do not recommend to use plain text passwords. " )
),
'uidNumber' => array (
" Headline " => _ ( " UID number " ),
" Text " => _ ( " If empty UID number will be generated automaticly. " )
),
2005-06-02 20:30:18 +00:00
'group_upload' => array (
" Headline " => _ ( " Primary group " ),
" Text " => _ ( " The primary group for this account. You can insert a GID number or a group name. " )
),
'addgroup_upload' => array (
" Headline " => _ ( " Additional groups " ),
" Text " => _ ( " Here you can enter a list of additional group memberships. The group names are separated by commas. " )
),
'homeDirectory_upload' => array (
" Headline " => _ ( " Home directory " ),
" Text " => _ ( " Please enter the path to the user's home directory. " )
),
2005-08-30 16:05:16 +00:00
'deletehomedir' => array (
" Headline " => _ ( " Home directory " ),
" Text " => _ ( " Activating this checkbox will remove the user's home directory. " )
),
2004-10-30 16:46:06 +00:00
'user' => array (
'uid' => array (
2005-06-19 09:38:44 +00:00
" Headline " => _ ( " User name " ),
" Text " => _ ( " User name of the user who should be created. Valid characters are: a-z,0-9, .-_. LAM does not allow a number as first character because useradd also does not allow it. LAM does not allow capital letters A-Z because it can cause several problems. If user name is already used user name will be expanded with a number. The next free number will be used. Warning: Older systems have problems with user names longer than 8 characters. You can not log in to Windows if user name is longer than 16 characters. " )
2004-10-30 16:46:06 +00:00
),
'gecos' => array (
" Headline " => _ ( " Gecos " ),
2005-06-07 18:28:28 +00:00
" Text " => _ ( " User description. If left empty first and last name will be used. " )
2004-10-30 16:46:06 +00:00
),
'gidNumber' => array (
" Headline " => _ ( " Primary group " ),
2005-06-19 09:38:44 +00:00
" Text " => _ ( " The primary group the user should be member of. " )
2004-10-30 16:46:06 +00:00
),
'homeDirectory' => array (
" Headline " => _ ( " Home directory " ),
2005-06-02 20:30:18 +00:00
" Text " => _ ( '$user and $group are replaced with user name or primary group name.' )
2004-10-30 16:46:06 +00:00
),
2005-05-03 14:46:06 +00:00
'userPassword' => array (
" Headline " => _ ( " Password " ),
" Text " => _ ( " Please enter the password which you want to set for this account. " )
),
2004-10-30 16:46:06 +00:00
'userPassword_no' => array (
" Headline " => _ ( " Use no password " ),
" Text " => _ ( " If checked no password will be used. " )
),
2005-06-02 20:30:18 +00:00
'userPassword_lock' => array (
" Headline " => _ ( " Account deactivated " ),
" Text " => _ ( " If checked account will be deactivated by putting a \" ! \" before the encrypted password. " )
),
2005-09-03 10:59:50 +00:00
'userPassword_invalid' => array (
" Headline " => _ ( " Invalid password " ),
" Text " => _ ( " This will set an invalid password which prevents logins with this account. " )
),
2004-10-30 16:46:06 +00:00
'loginShell' => array (
" Headline " => _ ( " Login shell " ),
2005-06-02 20:30:18 +00:00
" Text " => _ ( " To disable login use /bin/false. The list of shells is read from lam/config/shells " )
2004-10-30 16:46:06 +00:00
),
'addgroup' => array (
" Headline " => _ ( " Additional groups " ),
" Text " => _ ( " Hold the CTRL-key to (de)select multiple groups. " ) . ' ' . _ ( " Can be left empty. " )
2005-06-19 09:38:44 +00:00
),
'cn' => array (
" Headline " => _ ( " Common name " ),
" Text " => _ ( " This is the natural name of the user. If empty, the first and last name or user name is used. " )
2004-10-30 16:46:06 +00:00
)
),
'host' => array (
'uid' => array (
" Headline " => _ ( " Host name " ),
2005-06-19 09:38:44 +00:00
" Text " => _ ( " Host name of the host which should be created. Valid characters are: a-z,0-9, .-_ $ . LAM does not allow a number as first character because useradd also does not allow it. LAM does not allow capital letters A-Z because it can cause several problems. Host names are always ending with $ . If last character is not $ it will be added. If host name is already used host name will be expanded with a number. The next free number will be used. " )
2004-10-30 16:46:06 +00:00
),
'gecos' => array (
" Headline " => _ ( " Gecos " ),
" Text " => _ ( " Host description. If left empty host name will be used. " )
),
'gidNumber' => array (
" Headline " => _ ( " Primary group " ),
2005-06-02 20:30:18 +00:00
" Text " => _ ( " The primary group the host should be member of. " )
),
'description' => array (
" Headline " => _ ( " Description " ),
" Text " => _ ( " Host description. If left empty host name will be used. " )
2004-10-30 16:46:06 +00:00
)
)
);
2004-10-02 18:45:11 +00:00
2004-06-08 18:54:37 +00:00
return $return ;
}
2003-12-09 18:42:50 +00:00
// Constructor
2004-06-08 18:54:37 +00:00
function init ( $base ) {
2004-09-01 20:53:06 +00:00
// call parent init
parent :: init ( $base );
2003-12-20 21:42:52 +00:00
$this -> createhomedir = false ;
2005-10-08 14:35:30 +00:00
$this -> groups = array ();
$this -> groups_orig = array ();
$groups = $_SESSION [ 'cache' ] -> findgroups (); // list of all groupnames
2005-04-12 19:38:32 +00:00
if ( count ( $groups ) == 0 ) {
StatusMessage ( " ERROR " , _ ( 'No Unix groups found in LDAP! Please create one first.' ), '' );
return ;
}
2004-10-12 13:34:00 +00:00
}
2003-12-09 18:42:50 +00:00
// Variables
2003-12-21 14:52:23 +00:00
// Use a unix password?
2004-10-12 13:34:00 +00:00
var $userPassword_nopassword ;
// Use invalid password, '*', e.g. * for services
var $userPassword_invalid ;
// Lock password
2003-12-21 14:52:23 +00:00
var $userPassword_lock ;
2003-12-15 15:11:44 +00:00
/* These two variables keep an array of groups the
* user is also member of .
*/
var $groups ;
var $groups_orig ;
2003-12-20 21:42:52 +00:00
var $createhomedir ;
2003-12-09 18:42:50 +00:00
2004-02-09 18:11:01 +00:00
/* This functions return true
* if all needed settings are done
*/
function module_complete () {
if ( $this -> attributes [ 'uid' ][ 0 ] == '' ) return false ;
if ( $this -> attributes [ 'uidNumber' ][ 0 ] == '' ) return false ;
if ( $this -> attributes [ 'gidNumber' ][ 0 ] == '' ) return false ;
if ( $this -> attributes [ 'homeDirectory' ][ 0 ] == '' ) return false ;
if ( $this -> attributes [ 'loginShell' ][ 0 ] == '' ) return false ;
return true ;
2004-10-12 13:34:00 +00:00
}
2003-12-09 18:42:50 +00:00
/* This function loads all attributes into the object
* $attr is an array as it ' s retured from ldap_get_attributes
*/
function load_attributes ( $attr ) {
2005-04-16 13:41:17 +00:00
parent :: load_attributes ( $attr );
2005-09-04 16:53:43 +00:00
// get additional group memberships
$dn_groups = $_SESSION [ 'cache' ] -> get_cache ( array ( 'memberUid' , 'cn' ), 'posixGroup' , 'group' );
2004-10-12 13:34:00 +00:00
if ( is_array ( $dn_groups )) {
$DNs = array_keys ( $dn_groups );
2005-09-04 16:53:43 +00:00
for ( $i = 0 ; $i < sizeof ( $DNs ); $i ++ ) {
if ( isset ( $dn_groups [ $DNs [ $i ]][ 'memberUid' ][ 0 ])) {
if ( in_array ( $attr [ 'uid' ][ 0 ], $dn_groups [ $DNs [ $i ]][ 'memberUid' ])) $this -> groups [] = $dn_groups [ $DNs [ $i ]][ 'cn' ][ 0 ];
2003-12-27 11:21:00 +00:00
}
2003-12-12 00:51:23 +00:00
}
2003-12-09 18:42:50 +00:00
}
2005-10-08 14:35:30 +00:00
$this -> groups_orig = $this -> groups ;
2004-10-12 13:34:00 +00:00
return 0 ;
}
2003-12-09 18:42:50 +00:00
/* This function returns an array with 3 entries :
2003-12-12 00:51:23 +00:00
* array ( DN1 ( 'add' => array ( $attr ), 'remove' => array ( $attr ), 'modify' => array ( $attr )), DN2 .... )
* 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
2003-12-09 18:42:50 +00:00
* add are attributes which have to be added to ldap entry
* remove are attributes which have to be removed from ldap entry
* modify are attributes which have to been modified in ldap entry
*/
function save_attributes () {
2003-12-20 19:24:01 +00:00
$return = $_SESSION [ $this -> base ] -> save_module_attributes ( $this -> attributes , $this -> orig );
2004-10-12 13:34:00 +00:00
// unset password when needed
if ( isset ( $return [ $_SESSION [ $this -> base ] -> dn ][ 'add' ][ 'userPassword' ]))
unset ( $return [ $_SESSION [ $this -> base ] -> dn ][ 'add' ][ 'userPassword' ]);
2003-12-21 14:52:23 +00:00
if ( isset ( $return [ $_SESSION [ $this -> base ] -> dn ][ 'modify' ][ 'userPassword' ]))
2004-10-12 13:34:00 +00:00
unset ( $return [ $_SESSION [ $this -> base ] -> dn ][ 'modify' ][ 'userPassword' ]);
if ( isset ( $return [ $_SESSION [ $this -> base ] -> dn ][ 'notchanged' ][ 'userPassword' ]))
unset ( $return [ $_SESSION [ $this -> base ] -> dn ][ 'notchanged' ][ 'userPassword' ]);
2003-12-21 14:52:23 +00:00
// Set unix password
2004-10-12 13:34:00 +00:00
if ( isset ( $this -> orig [ 'userPassword' ][ 0 ])) {
2005-08-06 08:04:36 +00:00
// use no password, do nothing
if ( $this -> userPassword_nopassword ) {}
// invalid, use '*' as password
elseif ( $this -> userPassword_invalid )
2004-10-12 13:34:00 +00:00
$return [ $_SESSION [ $this -> base ] -> dn ][ 'modify' ][ 'userPassword' ][ 0 ] = '*' ;
2005-08-06 08:04:36 +00:00
// set password if set
elseif (( $this -> attributes [ 'userPassword' ][ 0 ] != $this -> orig [ 'userPassword' ][ 0 ]) && $this -> attributes [ 'userPassword' ][ 0 ] != '' )
$return [ $_SESSION [ $this -> base ] -> dn ][ 'modify' ][ 'userPassword' ][ 0 ] = pwd_hash ( $this -> attributes [ 'userPassword' ][ 0 ], ! $this -> userPassword_lock , $this -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ]);
// lock account if required
elseif ( $this -> userPassword_lock && ( pwd_disable ( $this -> orig [ 'userPassword' ][ 0 ]) != $this -> orig [ 'userPassword' ][ 0 ]))
2004-10-12 13:34:00 +00:00
$return [ $_SESSION [ $this -> base ] -> dn ][ 'modify' ][ 'userPassword' ][ 0 ] = pwd_disable ( $this -> orig [ 'userPassword' ][ 0 ]);
2005-08-06 08:04:36 +00:00
// unlock account if required
elseif ( ! $this -> userPassword_lock && ( pwd_enable ( $this -> orig [ 'userPassword' ][ 0 ]) != $this -> orig [ 'userPassword' ][ 0 ]))
$return [ $_SESSION [ $this -> base ] -> dn ][ 'modify' ][ 'userPassword' ][ 0 ] = pwd_enable ( $this -> orig [ 'userPassword' ][ 0 ]);
// password has not changed
else
2004-10-12 13:34:00 +00:00
$return [ $_SESSION [ $this -> base ] -> dn ][ 'notchanged' ][ 'userPassword' ][ 0 ] = $this -> orig [ 'userPassword' ][ 0 ];
}
2003-12-21 14:52:23 +00:00
else {
2004-10-12 13:34:00 +00:00
// New user or no old password set
if ( $this -> userPassword_nopassword ) // use no password
$return [ $_SESSION [ $this -> base ] -> dn ][ 'add' ][ 'userPassword' ][ 0 ] = pwd_hash ( '' , ! $this -> userPassword_lock , $this -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ]);
else if ( $this -> userPassword_invalid ) // use '*' as password
$return [ $_SESSION [ $this -> base ] -> dn ][ 'add' ][ 'userPassword' ][ 0 ] = '*' ;
2005-08-06 08:04:36 +00:00
else if ( $this -> attributes [ 'userPassword' ][ 0 ] != '' ) // set password if set
$return [ $_SESSION [ $this -> base ] -> dn ][ 'add' ][ 'userPassword' ][ 0 ] = pwd_hash ( $this -> attributes [ 'userPassword' ][ 0 ], ! $this -> userPassword_lock , $this -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ]);
2004-02-21 13:26:52 +00:00
}
2003-12-21 14:52:23 +00:00
2003-12-15 15:11:44 +00:00
// Remove primary group from additional groups
for ( $i = 0 ; $i < count ( $this -> groups ); $i ++ ) {
2004-09-14 11:53:33 +00:00
if ( $this -> groups [ $i ] == $_SESSION [ 'cache' ] -> getgrnam ( $this -> attributes [ 'gidNumber' ][ 0 ])) unset ( $this -> groups [ $i ]);
2004-10-12 13:34:00 +00:00
}
2003-12-15 15:11:44 +00:00
2003-12-12 00:51:23 +00:00
// Set additional group memberships
2003-12-27 11:21:00 +00:00
if ( $this -> orig [ 'uid' ][ 0 ] != '' && $this -> attributes [ 'uid' ][ 0 ] != $this -> orig [ 'uid' ][ 0 ]) {
// remove old memberships
2004-09-14 11:53:33 +00:00
$dn_groups = $_SESSION [ 'cache' ] -> get_cache ( 'memberUid' , 'posixGroup' , 'group' );
2003-12-27 11:21:00 +00:00
$DNs = array_keys ( $dn_groups );
foreach ( $DNs as $DN )
2004-10-12 13:34:00 +00:00
if ( in_array ( $this -> orig [ 'uid' ][ 0 ], $dn_groups [ $DN ]))
$return [ $DN ][ 'remove' ][ 'memberUid' ][ 0 ] = $this -> orig [ 'uid' ][ 0 ];
2003-12-27 11:21:00 +00:00
// Add new memberships
if ( is_array ( $this -> groups ))
2004-10-12 13:34:00 +00:00
foreach ( $this -> groups as $group ) {
2006-03-15 17:41:27 +00:00
$dn = $_SESSION [ 'cache' ] -> in_cache ( $group , 'cn' , 'group' );
2004-10-12 13:34:00 +00:00
$return [ $dn ][ 'add' ][ 'memberUid' ][ 0 ] = $this -> attributes [ 'uid' ][ 0 ];
2003-12-12 00:51:23 +00:00
}
2004-10-12 13:34:00 +00:00
}
2003-12-12 00:51:23 +00:00
else {
2005-10-08 14:35:30 +00:00
// update groups.
$add = array_delete ( $this -> groups_orig , $this -> groups );
$remove = array_delete ( $this -> groups , $this -> groups_orig );
$dn_cns = $_SESSION [ 'cache' ] -> get_cache ( 'cn' , 'posixGroup' , 'group' );
// get_cache will return an array ( dn1 => array(cn1), dn2 => array(cn2), ... )
$DNs = array_keys ( $dn_cns );
foreach ( $DNs as $DN ) {
if ( is_array ( $add )) {
if ( in_array ( $dn_cns [ $DN ][ 0 ], $add )) $return [ $DN ][ 'add' ][ 'memberUid' ][] = $this -> attributes [ 'uid' ][ 0 ];
2004-10-12 13:34:00 +00:00
}
2005-10-08 14:35:30 +00:00
if ( is_array ( $remove )) {
if ( in_array ( $dn_cns [ $DN ][ 0 ], $remove )) $return [ $DN ][ 'remove' ][ 'memberUid' ][] = $this -> attributes [ 'uid' ][ 0 ];
2003-12-12 00:51:23 +00:00
}
}
2004-10-12 13:34:00 +00:00
}
2004-10-16 18:41:39 +00:00
// fixme TODO lamdeamon without DN
2003-12-27 11:21:00 +00:00
if ( $this -> createhomedir ) $return [ $_SESSION [ $this -> base ] -> dn ][ 'lamdaemon' ][ 'command' ][] = $this -> attributes [ 'uid' ][ 0 ] . " home add " ;
2003-12-15 15:11:44 +00:00
return $return ;
2004-10-12 13:34:00 +00:00
}
2003-12-09 18:42:50 +00:00
2003-12-30 15:36:30 +00:00
function delete_attributes ( $post ) {
$return = array ();
// remove memberUids if set
2004-09-14 11:53:33 +00:00
$groups = $_SESSION [ 'cache' ] -> get_cache ( 'memberUid' , 'posixGroup' , 'group' );
2005-07-26 09:49:31 +00:00
if ( ! is_array ( $groups )) return $return ;
2003-12-30 15:36:30 +00:00
$DNs = array_keys ( $groups );
for ( $i = 0 ; $i < count ( $DNs ); $i ++ ) {
2004-01-10 11:47:48 +00:00
if ( in_array ( $this -> attributes [ 'uid' ][ 0 ], $groups [ $DNs [ $i ]])) $return [ $DNs [ $i ]][ 'remove' ][ 'memberUid' ][] = $this -> attributes [ 'uid' ][ 0 ];
2004-10-12 13:34:00 +00:00
}
2004-01-10 11:47:48 +00:00
if ( $post [ 'deletehomedir' ]) $return [ $_SESSION [ $this -> base ] -> dn_orig ][ 'lamdaemon' ][ 'command' ][] = $this -> attributes [ 'uid' ][ 0 ] . " home rem " ;
2003-12-30 15:36:30 +00:00
return $return ;
2004-10-12 13:34:00 +00:00
}
2003-12-15 15:11:44 +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-30 15:36:30 +00:00
*/
2005-03-10 18:35:04 +00:00
function process_attributes ( & $post ) {
2005-08-11 18:33:32 +00:00
$triggered_messages = array ();
2005-04-12 19:38:32 +00:00
$groups = $_SESSION [ 'cache' ] -> findgroups (); // list of all groupnames
if ( count ( $groups ) == 0 ) {
2005-10-03 10:48:13 +00:00
return array ( array ( array ( " ERROR " , _ ( 'No Unix groups found in LDAP! Please create one first.' ), '' )));
2005-04-12 19:38:32 +00:00
}
2003-12-30 15:36:30 +00:00
$this -> attributes [ 'homeDirectory' ][ 0 ] = $post [ 'homeDirectory' ];
$this -> attributes [ 'loginShell' ][ 0 ] = $post [ 'loginShell' ];
2004-10-17 09:33:24 +00:00
if ( isset ( $post [ 'gecos' ])) $this -> attributes [ 'gecos' ][ 0 ] = $post [ 'gecos' ];
2003-12-30 15:36:30 +00:00
if ( $post [ 'createhomedir' ]) $this -> createhomedir = true ;
2004-10-12 13:34:00 +00:00
else $this -> createhomedir = false ;
2004-10-16 19:51:36 +00:00
if ( $this -> orig [ 'uid' ][ 0 ] != '' && $post [ 'uid' ] != $this -> attributes [ 'uid' ][ 0 ])
$triggered_messages [ 'uid' ][] = $this -> messages [ 'uid' ][ 0 ];
if ( $this -> orig [ 'gidNumber' ][ 0 ] != '' && $_SESSION [ 'cache' ] -> getgid ( $post [ 'gidNumber' ]) != $this -> attributes [ 'gidNumber' ][ 0 ])
$triggered_messages [ 'gidNumber' ][] = $this -> dynamic_Message ( 'gidNumber' , 0 );
if ( $this -> orig [ 'uidNumber' ][ 0 ] != '' && $post [ 'uidNumber' ] != $this -> attributes [ 'uidNumber' ][ 0 ])
$triggered_messages [ 'uidNumber' ][] = $this -> dynamic_Message ( 'uidNumber' , 0 );
if ( isset ( $post [ 'homeDirectory' ]) && $this -> orig [ 'homeDirectory' ][ 0 ] != '' && $post [ 'homeDirectory' ] != $this -> attributes [ 'homeDirectory' ][ 0 ])
$triggered_messages [ 'homeDirectory' ][] = $this -> dynamic_Message ( 'homeDirectory' , 0 );
// Load attributes
$this -> attributes [ 'uid' ][ 0 ] = $post [ 'uid' ];
2005-06-19 09:38:44 +00:00
$this -> attributes [ 'cn' ][ 0 ] = $post [ 'cn' ];
if ( $this -> attributes [ 'cn' ][ 0 ] == '' ) {
2005-06-26 07:53:48 +00:00
if (( $this -> scope == 'host' ) && ( substr ( $post [ 'uid' ], - 1 , 1 ) == '$' )) {
$this -> attributes [ 'cn' ][ 0 ] = substr ( $post [ 'uid' ], 0 , strlen ( $post [ 'uid' ]) - 1 );
}
elseif ( isset ( $_SESSION [ $this -> base ] -> module [ 'inetOrgPerson' ])) {
2005-06-19 09:38:44 +00:00
if ( $_SESSION [ $this -> base ] -> module [ 'inetOrgPerson' ] -> attributes [ 'givenName' ][ 0 ]) {
$this -> attributes [ 'cn' ][ 0 ] = $_SESSION [ $this -> base ] -> module [ 'inetOrgPerson' ] -> attributes [ 'givenName' ][ 0 ] . " " . $_SESSION [ $this -> base ] -> module [ 'inetOrgPerson' ] -> attributes [ 'sn' ][ 0 ];
}
elseif ( $_SESSION [ $this -> base ] -> module [ 'inetOrgPerson' ] -> attributes [ 'sn' ][ 0 ]) {
$this -> attributes [ 'cn' ][ 0 ] = $_SESSION [ $this -> base ] -> module [ 'inetOrgPerson' ] -> attributes [ 'sn' ][ 0 ];
}
else {
$this -> attributes [ 'cn' ][ 0 ] = $post [ 'uid' ];
}
}
else {
$this -> attributes [ 'cn' ][ 0 ] = $post [ 'uid' ];
}
}
if ( ! get_preg ( $this -> attributes [ 'cn' ][ 0 ], 'cn' )) {
$triggered_messages [ 'cn' ][] = $this -> messages [ 'cn' ][ 0 ];
}
2004-10-16 19:51:36 +00:00
$this -> attributes [ 'uidNumber' ][ 0 ] = $post [ 'uidNumber' ];
$this -> attributes [ 'gidNumber' ][ 0 ] = $_SESSION [ 'cache' ] -> getgid ( $post [ 'gidNumber' ]);
// Check if UID is valid. If none value was entered, the next useable value will be inserted
// load min and may uidNumber
if ( $_SESSION [ $this -> base ] -> type == 'user' ) {
$minID = intval ( $this -> moduleSettings [ 'posixAccount_minUID' ][ 0 ]);
$maxID = intval ( $this -> moduleSettings [ 'posixAccount_maxUID' ][ 0 ]);
}
if ( $_SESSION [ $this -> base ] -> type == 'host' ) {
$minID = intval ( $this -> moduleSettings [ 'posixAccount_minMachine' ][ 0 ]);
$maxID = intval ( $this -> moduleSettings [ 'posixAccount_maxMachine' ][ 0 ]);
}
2005-10-15 09:33:05 +00:00
$dn_uids = $_SESSION [ 'cache' ] -> get_cache ( 'uidNumber' , 'posixAccount' , array ( 'user' , 'host' ));
2004-10-16 19:51:36 +00:00
// get_cache will return an array ( dn1 => array(uidnumber1), dn2 => array(uidnumber2), ... )
if ( is_array ( $dn_uids )) {
foreach ( $dn_uids as $uid ) $uids [] = $uid [ 0 ];
2005-12-06 14:47:57 +00:00
if ( sizeof ( $uids ) > 0 ) sort ( $uids , SORT_NUMERIC );
2004-10-16 19:51:36 +00:00
}
if ( $this -> attributes [ 'uidNumber' ][ 0 ] == '' ) {
// No id-number given
if ( $this -> orig [ 'uidNumber' ][ 0 ] == '' ) {
// new account -> we have to find a free id-number
2005-03-25 14:21:07 +00:00
$newUID = $this -> getNextUIDs ( 1 , $triggered_messages );
if ( is_array ( $newUID )) {
$this -> attributes [ 'uidNumber' ][ 0 ] = $newUID [ 0 ];
}
else {
$triggered_messages [ 'uidNumber' ][] = $this -> messages [ 'uidNumber' ][ 3 ];
2004-10-12 13:34:00 +00:00
}
}
2004-10-16 19:51:36 +00:00
else $this -> attributes [ 'uidNumber' ][ 0 ] = $this -> orig [ 'uidNumber' ][ 0 ];
// old account -> return id-number which has been used
}
else {
// Check manual ID
// id-number is out of valid range
if ( ( $this -> attributes [ 'uidNumber' ][ 0 ] != $post [ 'uidNumber' ]) && ( $this -> attributes [ 'uidNumber' ][ 0 ] < $minID || $this -> attributes [ 'uidNumber' ][ 0 ] > $maxID )) $triggered_messages [ 'uidNumber' ][] = array ( 'ERROR' , _ ( 'ID-Number' ), sprintf ( _ ( 'Please enter a value between %s and %s!' ), $minID , $maxID ));
// $uids is allways an array but not if no entries were found
if ( is_array ( $uids )) {
// id-number is in use and account is a new account
if (( in_array ( $this -> attributes [ 'uidNumber' ][ 0 ], $uids )) && $this -> orig [ 'uidNumber' ][ 0 ] == '' ) $triggered_messages [ 'uidNumber' ][] = array ( 'ERROR' , _ ( 'ID-Number' ), _ ( 'ID is already in use' ));
// id-number is in use, account is existing account and id-number is not used by itself
if (( in_array ( $this -> attributes [ 'uidNumber' ][ 0 ], $uids )) && $this -> orig [ 'uidNumber' ][ 0 ] != '' && ( $this -> orig [ 'uidNumber' ][ 0 ] != $this -> attributes [ 'uidNumber' ][ 0 ]) ) {
$triggered_messages [ 'uidNumber' ][] = $this -> messages [ 'uidNumber' ][ 3 ];
$this -> attributes [ 'uidNumber' ][ 0 ] = $this -> orig [ 'uidNumber' ][ 0 ];
2003-12-30 15:36:30 +00:00
}
}
2004-10-16 19:51:36 +00:00
}
if ( $_SESSION [ $this -> base ] -> type == 'user' ) {
if (( $this -> attributes [ 'uid' ][ 0 ] != $post [ 'uid' ]) && ! get_preg ( $post [ 'uid' ], '!upper' ))
$triggered_messages [ 'uid' ][] = $this -> messages [ 'uid' ][ 1 ];
if ( ! get_preg ( $this -> attributes [ 'homeDirectory' ][ 0 ], 'homeDirectory' ))
$triggered_messages [ 'homeDirecotry' ][] = $this -> messages [ 'homeDirectory' ][ 0 ];
}
2005-10-26 09:24:20 +00:00
if (( $post [ 'userPassword_lock' ] && $post [ 'userPassword_invalid' ]) || ( $post [ 'userPassword_nopassword' ] && $post [ 'userPassword_invalid' ])) {
2004-10-16 19:51:36 +00:00
// found invalid password parameter combination
$triggered_messages [ 'userPassword' ][] = $this -> messages [ 'userPassword' ][ 3 ];
}
else {
if ( $post [ 'userPassword_nopassword' ]) {
$this -> userPassword_nopassword = true ;
$this -> userPassword_invalid = false ;
2005-08-06 08:04:36 +00:00
$this -> attributes [ 'userPassword' ][ 0 ] = '' ;
2004-10-16 19:51:36 +00:00
$post [ 'userPassword2' ] = '' ;
if ( $post [ 'userPassword_lock' ])
$this -> userPassword_lock = true ;
else $this -> userPassword_lock = false ;
2003-12-30 15:36:30 +00:00
}
2004-10-12 13:34:00 +00:00
else {
2004-10-16 19:51:36 +00:00
$this -> userPassword_nopassword = false ;
if ( $post [ 'userPassword_invalid' ]) {
$this -> userPassword_invalid = true ;
$this -> userPassword_lock = false ;
2004-10-12 13:34:00 +00:00
$post [ 'userPassword2' ] = '' ;
}
else {
2004-10-16 19:51:36 +00:00
$this -> userPassword_invalid = false ;
2005-08-06 08:04:36 +00:00
if ( $post [ 'genpass' ]) $this -> attributes [ 'userPassword' ][ 0 ] = genpasswd ();
2005-05-03 14:46:06 +00:00
elseif ( $_SESSION [ $this -> base ] -> isNewAccount ) {
2004-10-16 19:51:36 +00:00
if ( $post [ 'userPassword' ] != $post [ 'userPassword2' ])
$triggered_messages [ 'userPassword' ][] = $this -> messages [ 'userPassword' ][ 0 ];
2005-08-06 08:04:36 +00:00
else $this -> attributes [ 'userPassword' ][ 0 ] = $post [ 'userPassword' ];
if ( ! get_preg ( $this -> attributes [ 'userPassword' ][ 0 ], 'password' ))
2004-10-16 19:51:36 +00:00
$triggered_messages [ 'userPassword' ][] = $this -> messages [ 'userPassword' ][ 1 ];
2004-10-12 13:34:00 +00:00
}
2004-10-16 19:51:36 +00:00
if ( $post [ 'userPassword_lock' ]) $this -> userPassword_lock = true ;
else $this -> userPassword_lock = false ;
2004-10-12 13:34:00 +00:00
}
2004-10-16 19:51:36 +00:00
}
if ( $_SESSION [ $this -> base ] -> type == 'user' ) {
$this -> attributes [ 'homeDirectory' ][ 0 ] = str_replace ( '$group' , $_SESSION [ 'cache' ] -> getgrnam ( $this -> attributes [ 'gidNumber' ][ 0 ]), $this -> attributes [ 'homeDirectory' ][ 0 ]);
if ( $this -> attributes [ 'uid' ][ 0 ] != '' )
$this -> attributes [ 'homeDirectory' ][ 0 ] = str_replace ( '$user' , $this -> attributes [ 'uid' ][ 0 ], $this -> attributes [ 'homeDirectory' ][ 0 ]);
if ( $this -> attributes [ 'homeDirectory' ][ 0 ] != $post [ 'homeDirectory' ]) $triggered_messages [ 'homeDirecotry' ][] = array ( 'INFO' , _ ( 'Home directory' ), _ ( 'Replaced $user or $group in homedir.' ));
// Check if Username contains only valid characters
if ( ! get_preg ( $this -> attributes [ 'uid' ][ 0 ], 'username' ) && ! $profile )
$triggered_messages [ 'uid' ][] = $this -> messages [ 'uid' ][ 2 ];
}
if ( $_SESSION [ $this -> base ] -> type == 'host' ) {
2005-10-26 09:24:20 +00:00
// add "$" to uid if needed
if ( substr ( $this -> attributes [ 'uid' ][ 0 ], - 1 , 1 ) != '$' ) {
$this -> attributes [ 'uid' ][ 0 ] .= '$' ;
$post [ 'uid' ] .= '$' ;
}
2004-10-16 19:51:36 +00:00
// Check if Hostname contains only valid characters
if ( ! get_preg ( $this -> attributes [ 'uid' ][ 0 ], 'hostname' ))
$triggered_messages [ 'uid' ][] = $this -> messages [ 'uid' ][ 4 ];
2005-06-26 07:53:48 +00:00
if ( ! $this -> attributes [ 'homeDirectory' ][ 0 ]) {
$this -> attributes [ 'homeDirectory' ][ 0 ] = '/dev/null' ;
}
if ( ! $this -> attributes [ 'loginShell' ][ 0 ]) {
$this -> attributes [ 'loginShell' ][ 0 ] = '/bin/false' ;
}
2004-10-16 19:51:36 +00:00
}
// Create automatic useraccount with number if original user already exists
// Reset name to original name if new name is in use
// Set username back to original name if new username is in use
2005-10-15 09:33:05 +00:00
if ( $_SESSION [ 'cache' ] -> in_cache ( $this -> attributes [ 'uid' ][ 0 ], 'uid' , array ( 'user' , 'host' )) && ( $this -> orig [ 'uid' ][ 0 ] != '' ))
2004-10-16 19:51:36 +00:00
$this -> attributes [ 'uid' ][ 0 ] = $this -> orig [ 'uid' ][ 0 ];
// Change uid to a new uid until a free uid is found
else
2005-10-15 09:33:05 +00:00
while ( $_SESSION [ 'cache' ] -> in_cache ( $this -> attributes [ 'uid' ][ 0 ], 'uid' , array ( 'user' , 'host' ))) {
2004-10-16 19:51:36 +00:00
if ( $_SESSION [ $this -> base ] -> type == 'host' ) $this -> attributes [ 'uid' ][ 0 ] = substr ( $this -> attributes [ 'uid' ][ 0 ], 0 , - 1 );
// get last character of username
$lastchar = substr ( $this -> attributes [ 'uid' ][ 0 ], strlen ( $this -> attributes [ 'uid' ][ 0 ]) - 1 , 1 );
// Last character is no number
if ( ! ereg ( '^([0-9])+$' , $lastchar ))
/* Last character is no number . Therefore we only have to
* add " 2 " to it .
*/
if ( $_SESSION [ $this -> base ] -> type == 'host' ) $this -> attributes [ 'uid' ][ 0 ] = $this -> attributes [ 'uid' ][ 0 ] . '2$' ;
else $this -> attributes [ 'uid' ][ 0 ] = $this -> attributes [ 'uid' ][ 0 ] . '2' ;
else {
/* Last character is a number -> we have to increase the number until we ' ve
* found a groupname with trailing number which is not in use .
*
* $i will show us were we have to split groupname so we get a part
* with the groupname and a part with the trailing number
2004-01-27 19:07:31 +00:00
*/
2004-10-16 19:51:36 +00:00
$i = strlen ( $this -> attributes [ 'uid' ][ 0 ]) - 1 ;
$mark = false ;
// Set $i to the last character which is a number in $account_new->general_username
while ( ! $mark )
if ( ereg ( '^([0-9])+$' , substr ( $this -> attributes [ 'uid' ][ 0 ], $i , strlen ( $this -> attributes [ 'uid' ][ 0 ]) - $i ))) $i -- ;
else $mark = true ;
// increase last number with one
$firstchars = substr ( $this -> attributes [ 'uid' ][ 0 ], 0 , $i + 1 );
$lastchars = substr ( $this -> attributes [ 'uid' ][ 0 ], $i + 1 , strlen ( $this -> attributes [ 'uid' ][ 0 ]) - $i );
// Put username together
if ( $_SESSION [ $this -> base ] -> type == 'host' ) $this -> attributes [ 'uid' ][ 0 ] = $firstchars . ( intval ( $lastchars ) + 1 ) . " $ " ;
else $this -> attributes [ 'uid' ][ 0 ] = $firstchars . ( intval ( $lastchars ) + 1 );
2003-12-30 15:36:30 +00:00
}
2004-10-12 13:34:00 +00:00
}
2004-10-16 19:51:36 +00:00
// Show warning if lam has changed username
if ( $this -> attributes [ 'uid' ][ 0 ] != $post [ 'uid' ]) {
2005-10-26 09:24:20 +00:00
if ( $_SESSION [ $this -> base ] -> type == 'user' ) $triggered_messages [ 'uid' ][] = $this -> messages [ 'uid' ][ 5 ];
if ( $_SESSION [ $this -> base ] -> type == 'host' ) $triggered_messages [ 'uid' ][] = $this -> messages [ 'uid' ][ 6 ];
2004-10-16 19:51:36 +00:00
}
2005-08-06 08:04:36 +00:00
if ( $_SESSION [ $this -> base ] -> isNewAccount && ! get_preg ( $this -> attributes [ 'userPassword' ][ 0 ], 'password' ))
2004-10-16 19:51:36 +00:00
$triggered_messages [ 'userPassword' ][] = $this -> messages [ 'userPassword' ][ 1 ];
2004-10-12 13:34:00 +00:00
}
2005-09-01 15:20:15 +00:00
$temp = $this -> input_check ();
// TODO is this really OK?
if ( is_array ( $temp )) $triggered_messages = array_merge_recursive ( $triggered_messages , $temp );
// Return error-messages
if ( count ( $triggered_messages ) != 0 ) {
$this -> triggered_messages = $triggered_messages ;
return $triggered_messages ;
}
else $this -> triggered_messages = array ();
2004-10-12 13:34:00 +00:00
}
2003-12-30 15:36:30 +00:00
2005-09-07 12:58:34 +00:00
/**
* Processes user input of the group selection 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-09 18:42:50 +00:00
*/
2005-03-10 18:35:04 +00:00
function process_group ( & $post ) {
2004-10-12 13:34:00 +00:00
if ( isset ( $post [ 'addgroups' ]) && isset ( $post [ 'addgroups_button' ])) { // Add groups to list
2005-09-07 12:58:34 +00:00
// Add new group
$this -> groups = @ array_merge ( $this -> groups , $post [ 'addgroups' ]);
2004-10-12 13:34:00 +00:00
}
2005-09-07 12:58:34 +00:00
elseif ( isset ( $post [ 'removegroups' ]) && isset ( $post [ 'removegroups_button' ])) { // remove groups from list
$this -> groups = array_delete ( $post [ 'removegroups' ], $this -> groups );
2004-10-12 13:34:00 +00:00
}
}
2003-12-09 18:42:50 +00:00
2005-05-03 14:46:06 +00:00
/**
2005-09-07 12:58:34 +00:00
* Processes user input of the password page .
* It checks if all input values are correct and updates the associated LDAP attributes .
2005-05-03 14:46:06 +00:00
*
2005-09-07 12:58:34 +00:00
* @ param array $post HTTP - POST values
* @ return array list of info / error messages
2005-05-03 14:46:06 +00:00
*/
function process_password ( & $post ) {
2005-09-01 15:20:15 +00:00
if ( $post [ 'form_subpage_posixAccount_attributes_back' ]) return ;
2005-05-03 14:46:06 +00:00
$messages = array ();
if ( $post [ 'userPassword' ] != $post [ 'userPassword2' ]) {
$messages [ 'userPassword' ][] = $this -> messages [ 'userPassword' ][ 0 ];
2005-08-15 18:10:38 +00:00
}
else {
if ( ! get_preg ( $post [ 'userPassword' ], 'password' )) {
2005-05-03 14:46:06 +00:00
$messages [ 'userPassword' ][] = $this -> messages [ 'userPassword' ][ 1 ];
}
2005-08-06 08:04:36 +00:00
else {
$this -> attributes [ 'userPassword' ][ 0 ] = $post [ 'userPassword' ];
$this -> userPassword_invalid = false ;
$this -> userPassword_lock = false ;
$this -> userPassword_nopassword = false ;
}
2005-08-15 18:10:38 +00:00
}
2005-05-03 14:46:06 +00:00
if ( sizeof ( $messages ) > 0 ) return $messages ;
}
2003-12-09 18:42:50 +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-06 08:04:36 +00:00
// check password format if called the first time
if ( ! isset ( $this -> userPassword_invalid )) {
if ( $this -> attributes [ 'userPassword' ][ 0 ]) {
if ( $this -> attributes [ 'userPassword' ][ 0 ] == '*' ) $this -> userPassword_invalid = true ;
else $this -> userPassword_invalid = false ;
if ( pwd_is_enabled ( $this -> attributes [ 'userPassword' ][ 0 ])) $this -> userPassword_lock = false ;
else $this -> userPassword_lock = true ;
}
else {
if ( $_SESSION [ $this -> base ] -> isNewAccount ) {
$this -> userPassword_nopassword = false ;
}
else {
$this -> userPassword_nopassword = true ;
}
}
}
2004-09-14 11:53:33 +00:00
$groups = $_SESSION [ 'cache' ] -> findgroups (); // list of all groupnames
2005-04-12 19:38:32 +00:00
if ( count ( $groups ) == 0 ) {
StatusMessage ( " ERROR " , _ ( 'No Unix groups found in LDAP! Please create one first.' ), '' );
return ;
}
2003-12-09 18:42:50 +00:00
$shelllist = getshells (); // list of all valid shells
2004-01-18 12:52:52 +00:00
2005-05-03 14:46:06 +00:00
$return [] = array (
2005-06-19 09:38:44 +00:00
0 => array ( 'kind' => 'text' , 'text' => _ ( " User name " ) . '*' ),
1 => array ( 'kind' => 'input' , 'name' => 'uid' , 'type' => 'text' , 'size' => '30' , 'maxlength' => '20' , 'value' => $this -> attributes [ 'uid' ][ 0 ]),
2005-05-03 14:46:06 +00:00
2 => array ( 'kind' => 'help' , 'value' => 'uid' ));
2005-06-19 09:38:44 +00:00
$return [] = array (
0 => array ( 'kind' => 'text' , 'text' => _ ( " Common name " ) . '*' ),
1 => array ( 'kind' => 'input' , 'name' => 'cn' , 'type' => 'text' , 'size' => '30' , 'value' => $this -> attributes [ 'cn' ][ 0 ]),
2 => array ( 'kind' => 'help' , 'value' => 'cn' ));
2005-05-03 14:46:06 +00:00
$return [] = array (
0 => array ( 'kind' => 'text' , 'text' => _ ( 'UID number' ) . '*' ),
1 => array ( 'kind' => 'input' , 'name' => 'uidNumber' , 'type' => 'text' , 'size' => '6' , 'maxlength' => '6' , 'value' => $this -> attributes [ 'uidNumber' ][ 0 ]),
2 => array ( 'kind' => 'help' , 'value' => 'uidNumber' ));
2005-11-04 09:52:06 +00:00
$return [] = array (
0 => array ( 'kind' => 'text' , 'text' => _ ( 'Gecos' )),
1 => array ( 'kind' => 'input' , 'name' => 'gecos' , 'type' => 'text' , 'size' => '30' , 'maxlength' => '255' , 'value' => $this -> attributes [ 'gecos' ][ 0 ]),
2 => array ( 'kind' => 'help' , 'value' => 'gecos' ));
2005-05-03 14:46:06 +00:00
$return [] = array (
0 => array ( 'kind' => 'text' , 'text' => _ ( 'Primary group' ) . '*' ),
1 => array ( 'kind' => 'select' , 'name' => 'gidNumber' , 'options' => $groups , 'options_selected' => array ( $_SESSION [ 'cache' ] -> getgrnam ( $this -> attributes [ 'gidNumber' ][ 0 ]))),
2 => array ( 'kind' => 'help' , 'value' => 'gidNumber' ));
2004-01-18 12:52:52 +00:00
2003-12-19 12:45:23 +00:00
if ( $_SESSION [ $this -> base ] -> type == 'user' ) {
2005-05-03 14:46:06 +00:00
$return [] = array (
0 => array ( 'kind' => 'text' , 'text' => _ ( 'Additional groups' )),
2005-09-01 15:20:15 +00:00
1 => array ( 'kind' => 'input' , 'name' => 'form_subpage_posixAccount_group_open' , 'type' => 'submit' , 'value' => _ ( 'Edit groups' )),
2005-05-03 14:46:06 +00:00
2 => array ( 'kind' => 'help' , 'value' => 'addgroup' ));
$return [] = array (
0 => array ( 'kind' => 'text' , 'text' => _ ( 'Home directory' ) . '*' ),
1 => array ( 'kind' => 'input' , 'name' => 'homeDirectory' , 'type' => 'text' , 'size' => '30' , 'maxlength' => '255' , 'value' => $this -> attributes [ 'homeDirectory' ][ 0 ]),
2 => array ( 'kind' => 'help' , 'value' => 'homeDirectory' ));
2005-10-21 13:48:30 +00:00
if ( $_SESSION [ $this -> base ] -> isNewAccount && isset ( $_SESSION [ 'config' ] -> scriptPath )) {
2005-05-03 14:46:06 +00:00
$return [] = array (
0 => array ( 'kind' => 'text' , 'text' => _ ( 'Create home directory' )),
1 => array ( 'kind' => 'input' , 'name' => 'createhomedir' , 'type' => 'checkbox' , 'checked' => $this -> createhomedir ),
2 => array ( 'kind' => 'help' , 'value' => 'createhomedir' ));
2005-10-21 13:48:30 +00:00
}
2005-05-03 14:46:06 +00:00
if ( $_SESSION [ $this -> base ] -> isNewAccount ) {
$return [] = array (
0 => array ( 'kind' => 'text' , 'text' => _ ( 'Password' ) ),
2005-08-06 08:04:36 +00:00
1 => array ( 'kind' => 'input' , 'name' => 'userPassword' , 'type' => 'password' , 'size' => '30' , 'maxlength' => '255' , 'value' => $this -> attributes [ 'userPassword' ][ 0 ]),
2005-05-03 14:46:06 +00:00
2 => array ( 'kind' => 'input' , 'name' => 'genpass' , 'type' => 'submit' , 'value' => _ ( 'Generate password' )));
$return [] = array (
0 => array ( 'kind' => 'text' , 'text' => _ ( 'Repeat password' )),
2005-08-06 08:04:36 +00:00
1 => array ( 'kind' => 'input' , 'name' => 'userPassword2' , 'type' => 'password' , 'size' => '30' , 'maxlength' => '255' , 'value' => $this -> attributes [ 'userPassword' ][ 0 ]),
2005-05-03 14:46:06 +00:00
2 => array ( 'kind' => 'help' , 'value' => 'userPassword' ));
}
else {
$return [] = array (
0 => array ( 'kind' => 'text' , 'text' => _ ( 'Password' ) ),
2005-09-01 15:20:15 +00:00
1 => array ( 'kind' => 'input' , 'name' => 'form_subpage_posixAccount_password_open' , 'type' => 'submit' , 'value' => _ ( 'Change password' )));
2005-05-03 14:46:06 +00:00
}
$return [] = array (
0 => array ( 'kind' => 'text' , 'text' => _ ( 'Set no password' )),
1 => array ( 'kind' => 'input' , 'name' => 'userPassword_nopassword' , 'type' => 'checkbox' , 'checked' => $this -> userPassword_nopassword ),
2005-09-03 10:59:50 +00:00
2 => array ( 'kind' => 'help' , 'value' => 'userPassword_no' ));
2005-05-03 14:46:06 +00:00
$return [] = array (
0 => array ( 'kind' => 'text' , 'text' => _ ( 'Invalid password' )),
1 => array ( 'kind' => 'input' , 'name' => 'userPassword_invalid' , 'type' => 'checkbox' , 'checked' => $this -> userPassword_invalid ),
2 => array ( 'kind' => 'help' , 'value' => 'userPassword_invalid' ));
if ( $_SESSION [ $this -> base ] -> isNewAccount || isset ( $this -> attributes [ 'userPassword' ][ 0 ])) {
$return [] = array (
0 => array ( 'kind' => 'text' , 'text' => _ ( 'Lock password' )),
1 => array ( 'kind' => 'input' , 'name' => 'userPassword_lock' , 'type' => 'checkbox' , 'checked' => $this -> userPassword_lock ),
2 => array ( 'kind' => 'help' , 'value' => 'userPassword_lock' ));
}
if ( count ( $shelllist ) != 0 ) {
$return [] = array (
0 => array ( 'kind' => 'text' , 'text' => _ ( 'Login shell' ) . '*' ),
1 => array ( 'kind' => 'select' , 'name' => 'loginShell' , 'options' => $shelllist , 'options_selected' => array ( $this -> attributes [ 'loginShell' ][ 0 ])),
2 => array ( 'kind' => 'help' , 'value' => 'loginShell' ));
}
2003-12-09 18:42:50 +00:00
}
2004-10-24 17:23:23 +00:00
return $return ;
2004-10-12 13:34:00 +00:00
}
2003-12-09 18:42:50 +00:00
2005-02-16 21:00:19 +00:00
function display_html_delete ( & $post ) {
2005-04-05 11:43:19 +00:00
if ( $this -> scope == 'user' && isset ( $_SESSION [ 'config' ] -> scriptPath )) {
$return [] = array (
0 => array ( 'kind' => 'text' , 'text' => _ ( 'Delete home directory' )),
1 => array ( 'kind' => 'input' , 'name' => 'deletehomedir' , 'type' => 'checkbox' ),
2 => array ( 'kind' => 'help' , 'value' => 'deletehomedir' ));
2003-12-30 15:36:30 +00:00
}
2004-10-12 13:34:00 +00:00
return $return ;
}
2003-12-30 15:36:30 +00:00
2005-04-23 14:26:22 +00:00
/**
* Displays the group selection .
*
* @ param array $post HTTP - POST
* @ return array meta HTML code
*/
2005-02-16 21:00:19 +00:00
function display_html_group ( & $post ) {
2003-12-09 18:42:50 +00:00
// load list with all groups
2005-05-05 13:28:54 +00:00
$dn_groups = $_SESSION [ 'cache' ] -> get_cache ( 'cn' , 'posixGroup' , 'group' );
2003-12-27 11:21:00 +00:00
$DNs = array_keys ( $dn_groups );
2005-05-05 13:28:54 +00:00
foreach ( $DNs as $DN ) {
$groups [] = $dn_groups [ $DN ][ 0 ];
}
2003-12-09 18:42:50 +00:00
// remove groups the user is member of from grouplist
$groups = array_delete ( $this -> groups , $groups );
// Remove primary group from grouplist
2004-09-14 11:53:33 +00:00
$group = $_SESSION [ 'cache' ] -> getgrnam ( $this -> attributes [ 'gidNumber' ][ 0 ]);
2003-12-09 18:42:50 +00:00
$groups = array_flip ( $groups );
2004-02-09 20:15:43 +00:00
unset ( $groups [ $group ]);
2003-12-09 18:42:50 +00:00
$groups = array_flip ( $groups );
2004-10-12 13:34:00 +00:00
2005-04-23 14:26:22 +00:00
$return [] = array (
0 => array ( 'kind' => 'fieldset' , 'legend' => _ ( " Additional groups " ), 'value' => array (
0 => array (
0 => array ( 'kind' => 'fieldset' , 'td' => array ( 'valign' => 'top' ), 'legend' => _ ( " Selected groups " ), 'value' => array (
0 => array (
0 => array ( 'kind' => 'select' , 'name' => 'removegroups' , 'size' => '15' , 'multiple' => true , 'options' => $this -> groups )))),
1 => array ( 'kind' => 'table' , 'value' => array (
0 => array (
0 => array ( 'kind' => 'input' , 'type' => 'submit' , 'name' => 'addgroups_button' , 'value' => '<=' , 'td' => array ( 'align' => 'center' ))),
1 => array (
0 => array ( 'kind' => 'input' , 'type' => 'submit' , 'name' => 'removegroups_button' , 'value' => '=>' , 'td' => array ( 'align' => 'center' ))),
2 => array (
0 => array ( 'kind' => 'help' , 'value' => 'addgroup' , 'td' => array ( 'align' => 'center' ))))),
2 => array ( 'kind' => 'fieldset' , 'td' => array ( 'valign' => 'top' ), 'legend' => _ ( " Available groups " ), 'value' => array (
0 => array (
0 => array ( 'kind' => 'select' , 'name' => 'addgroups' , 'size' => '15' , 'multiple' => true , 'options' => $groups ))))
2004-10-12 13:34:00 +00:00
))));
2004-01-18 12:52:52 +00:00
2005-04-23 14:26:22 +00:00
$return [] = array (
2005-09-01 15:20:15 +00:00
0 => array ( 'kind' => 'input' , 'type' => 'submit' , 'value' => _ ( 'Back' ), 'name' => 'form_subpage_posixAccount_attributes_back' ),
2005-04-23 14:26:22 +00:00
1 => array ( 'kind' => 'text' ),
2 => array ( 'kind' => 'text' ));
2004-01-18 12:52:52 +00:00
return $return ;
2004-10-12 13:34:00 +00:00
}
2003-12-09 18:42:50 +00:00
2005-05-03 14:46:06 +00:00
/**
* Displays the password changing dialog .
*
* @ param array $post HTTP - POST
* @ return array meta HTML code
*/
function display_html_password ( & $post ) {
$return [] = array (
0 => array ( 'kind' => 'text' , 'text' => _ ( 'Password' ) ),
1 => array ( 'kind' => 'input' , 'name' => 'userPassword' , 'type' => 'password' , 'size' => '20' , 'maxlength' => '255' , 'value' => " " ),
2 => array ( 'kind' => 'help' , 'value' => 'userPassword' ));
$return [] = array (
0 => array ( 'kind' => 'text' , 'text' => _ ( 'Repeat password' )),
1 => array ( 'kind' => 'input' , 'name' => 'userPassword2' , 'type' => 'password' , 'size' => '20' , 'maxlength' => '255' , 'value' => " " ));
$return [] = array (
0 => array ( 'kind' => 'table' , 'value' => array (
0 => array (
2006-03-04 10:49:55 +00:00
0 => array ( 'kind' => 'input' , 'type' => 'submit' , 'value' => _ ( 'Ok' ), 'name' => 'form_subpage_posixAccount_attributes_submit' ),
1 => array ( 'kind' => 'input' , 'type' => 'submit' , 'value' => _ ( 'Cancel' ), 'name' => 'form_subpage_posixAccount_attributes_back' ),
2005-05-03 14:46:06 +00:00
2 => array ( 'kind' => 'text' )))));
return $return ;
}
2003-12-09 18:42:50 +00:00
2004-09-19 08:34:14 +00:00
/**
* Returns a list of elements for the account profiles .
*
* @ return profile elements
*/
2004-04-03 14:47:33 +00:00
function get_profileOptions () {
2004-03-09 12:03:39 +00:00
$return = array ();
2004-10-02 18:45:11 +00:00
if ( $this -> scope == 'user' ) {
2004-09-14 11:53:33 +00:00
$groups = $_SESSION [ 'cache' ] -> findgroups (); // list of all groupnames
2004-04-04 13:48:21 +00:00
$shelllist = getshells (); // list of all valid shells
// primary Unix group
$return [] = array ( 0 => array ( 'kind' => 'text' , 'text' => _ ( 'Primary group' ) . " : " ),
2004-10-12 13:34:00 +00:00
1 => array ( 'kind' => 'select' , 'name' => 'posixAccount_primaryGroup' , 'options' => $groups , 'options_selected' => array (), 'size' => 1 ),
2 => array ( 'kind' => 'help' , 'value' => 'gidNumber' , 'scope' => 'user' ));
2004-04-04 13:48:21 +00:00
// additional group memberships
$return [] = array ( 0 => array ( 'kind' => 'text' , 'text' => _ ( 'Additional groups' ) . " : " ),
2004-10-12 13:34:00 +00:00
1 => array ( 'kind' => 'select' , 'name' => 'posixAccount_additionalGroup' , 'options' => $groups ,
'options_selected' => array (), 'size' => 10 , 'multiple' => true ),
2 => array ( 'kind' => 'help' , 'value' => 'addgroup' , 'scope' => 'user' ));
2004-04-04 13:48:21 +00:00
// home directory
$return [] = array ( 0 => array ( 'kind' => 'text' , 'text' => _ ( 'Home directory' ) . " : " ),
2004-10-12 13:34:00 +00:00
1 => array ( 'kind' => 'input' , 'name' => 'posixAccount_homeDirectory' , 'type' => 'text' , 'size' => '30' , 'maxlength' => '255' , 'value' => '/home/$user' ),
2 => array ( 'kind' => 'help' , 'value' => 'homeDirectory' , 'scope' => 'user' ));
2004-04-04 13:48:21 +00:00
// login shell
$return [] = array ( 0 => array ( 'kind' => 'text' , 'text' => _ ( 'Login shell' ) . " : " ),
2004-10-12 13:34:00 +00:00
1 => array ( 'kind' => 'select' , 'name' => 'posixAccount_loginShell' , 'options' => $shelllist , 'options_selected' => array ( " /bin/bash " )),
2 => array ( 'kind' => 'help' , 'value' => 'loginShell' , 'scope' => 'user' ));
2004-04-04 13:48:21 +00:00
// do not set password
$return [] = array ( 0 => array ( 'kind' => 'text' , 'text' => _ ( 'Set no password' ) . " : " ),
2004-10-12 13:34:00 +00:00
1 => array ( 'kind' => 'input' , 'name' => 'posixAccount_userPassword_no' , 'type' => 'checkbox' , 'checked' => false ),
2 => array ( 'kind' => 'help' , 'value' => 'posixAccount_userPassword_no' , 'scope' => 'user' ));
2004-04-04 13:48:21 +00:00
// disable account
$return [] = array ( 0 => array ( 'kind' => 'text' , 'text' => _ ( 'Lock password' ) . " : " ),
2004-10-12 13:34:00 +00:00
1 => array ( 'kind' => 'input' , 'name' => 'posixAccount_userPassword_lock' , 'type' => 'checkbox' , 'checked' => false ),
2 => array ( 'kind' => 'help' , 'value' => 'posixAccount_userPassword_lock' , 'scope' => 'user' ));
2004-10-02 18:45:11 +00:00
}
elseif ( $this -> scope == 'host' ) {
$groups = $_SESSION [ 'cache' ] -> findgroups (); // list of all groupnames
// primary Unix group
$return [] = array ( 0 => array ( 'kind' => 'text' , 'text' => _ ( 'Primary group' ) . " : " ),
2004-10-12 13:34:00 +00:00
1 => array ( 'kind' => 'select' , 'name' => 'posixAccount_primaryGroup' , 'options' => $groups , 'options_selected' => array (), 'size' => 1 ),
2 => array ( 'kind' => 'help' , 'value' => 'gidNumber' , 'scope' => 'host' ));
2004-04-04 13:48:21 +00:00
}
2004-03-09 12:03:39 +00:00
return $return ;
2003-12-09 18:42:50 +00:00
}
2005-01-16 12:41:38 +00:00
/**
* Loads the values of an account profile into internal variables .
*
* @ param array $profile hash array with profile values ( identifier => value )
*/
function load_profile ( $profile ) {
// profile mappings in meta data
parent :: load_profile ( $profile );
// special profile options
// GID
if ( isset ( $profile [ 'posixAccount_primaryGroup' ][ 0 ])) {
$gid = $_SESSION [ 'cache' ] -> getgid ( $profile [ 'posixAccount_primaryGroup' ][ 0 ]);
if ( isset ( $gid )) {
$this -> attributes [ 'gidNumber' ][ 0 ] = $gid ;
}
}
// other group memberships
if ( isset ( $profile [ 'posixAccount_additionalGroup' ][ 0 ])) {
$this -> groups = $profile [ 'posixAccount_additionalGroup' ];
}
// no password
2005-05-08 16:50:13 +00:00
if ( $profile [ 'posixAccount_userPassword_no' ][ 0 ] == " true " ) {
$this -> userPassword_nopassword = true ;
}
elseif ( $profile [ 'posixAccount_userPassword_no' ][ 0 ] == " false " ) {
$this -> userPassword_nopassword = false ;
2005-01-16 12:41:38 +00:00
}
// locked password
2005-05-08 16:50:13 +00:00
if ( $profile [ 'posixAccount_userPassword_lock' ][ 0 ] == " true " ) {
$this -> userPassword_lock = true ;
}
elseif ( $profile [ 'posixAccount_userPassword_lock' ][ 0 ] == " false " ) {
$this -> userPassword_lock = false ;
2005-01-16 12:41:38 +00:00
}
}
2005-10-09 18:05:32 +00:00
/**
* Returns the PDF entries for this module .
*
* @ return array list of possible PDF entries
2004-10-12 13:34:00 +00:00
*/
2005-10-09 18:05:32 +00:00
function get_pdfEntries () {
2005-06-19 09:38:44 +00:00
return array (
'posixAccount_uid' => array ( '<block><key>' . _ ( 'User name' ) . '</key><value>' . $this -> attributes [ 'uid' ][ 0 ] . '</value></block>' ),
'posixAccount_cn' => array ( '<block><key>' . _ ( 'Common name' ) . '</key><value>' . $this -> attributes [ 'cn' ][ 0 ] . '</value></block>' ),
'posixAccount_uidNumber' => array ( '<block><key>' . _ ( 'UID number' ) . '</key><value>' . $this -> attributes [ 'uidNumber' ][ 0 ] . '</value></block>' ),
'posixAccount_gidNumber' => array ( '<block><key>' . _ ( 'GID number' ) . '</key><value>' . $this -> attributes [ 'gidNumber' ][ 0 ] . '</value></block>' ),
'posixAccount_gecos' => array ( '<block><key>' . _ ( 'Gecos' ) . '</key><value>' . $this -> attributes [ 'gecos' ][ 0 ] . '</value></block>' ),
'posixAccount_primaryGroup' => array ( '<block><key>' . _ ( 'Primary group' ) . '</key><value>' . $_SESSION [ 'cache' ] -> getgrnam ( $this -> attributes [ 'gidNumber' ][ 0 ]) . '</value></block>' ),
2005-09-27 12:41:38 +00:00
'posixAccount_additionalGroups' => array ( '<block><key>' . _ ( 'Additional groups' ) . '</key><value>' . implode ( " , " , $this -> groups ) . '</value></block>' ),
2005-06-19 09:38:44 +00:00
'posixAccount_homeDirectory' => array ( '<block><key>' . _ ( 'Home directory' ) . '</key><value>' . $this -> attributes [ 'homeDirectory' ][ 0 ] . '</value></block>' ),
'posixAccount_userPassword' => array ( '<block><key>' . _ ( 'Password' ) . '</key><value>' . $this -> attributes [ 'userPassword' ][ 0 ] . '</value></block>' ),
'posixAccount_loginShell' => array ( '<block><key>' . _ ( 'Login shell' ) . '</key><value>' . $this -> attributes [ 'loginShell' ][ 0 ] . '</value></block>' ),
2004-10-12 13:34:00 +00:00
);
2004-05-24 21:39:57 +00:00
}
2004-03-14 17:33:05 +00:00
2004-08-01 09:39:24 +00:00
/**
* Checks input values of module settings .
*
* @ param array $scopes list of account types which are used
* @ param array $options hash array containing the settings ( array ( 'option' => array ( 'value' )))
* @ return array list of error messages
*/
function check_configOptions ( $scopes , $options ) {
$return = array ();
// user settings
if ( in_array ( 'user' , $scopes )) {
// min/maxUID are required, check if they are numeric
if ( ! isset ( $options [ 'posixAccount_minUID' ][ 0 ]) || ! ereg ( '^[0-9]+$' , $options [ 'posixAccount_minUID' ][ 0 ])) {
2004-09-26 13:48:52 +00:00
$return [] = $this -> messages [ 'minUID' ][ 0 ];
2004-08-01 09:39:24 +00:00
}
if ( ! isset ( $options [ 'posixAccount_maxUID' ][ 0 ]) || ! ereg ( '^[0-9]+$' , $options [ 'posixAccount_maxUID' ][ 0 ])) {
2004-09-26 13:48:52 +00:00
$return [] = $this -> messages [ 'maxUID' ][ 0 ];
2004-08-01 09:39:24 +00:00
}
// minUID < maxUID
if ( isset ( $options [ 'posixAccount_minUID' ][ 0 ]) && isset ( $options [ 'posixAccount_maxUID' ][ 0 ])) {
if ( $options [ 'posixAccount_minUID' ][ 0 ] > $options [ 'posixAccount_maxUID' ][ 0 ]) {
2004-09-26 13:48:52 +00:00
$return [] = $this -> messages [ 'cmp_UID' ][ 0 ];
2004-08-01 09:39:24 +00:00
}
}
}
// host settings
if ( in_array ( 'host' , $scopes )) {
// min/maxUID are required, check if they are numeric
if ( ! isset ( $options [ 'posixAccount_minMachine' ][ 0 ]) || ! ereg ( '^[0-9]+$' , $options [ 'posixAccount_minMachine' ][ 0 ])) {
2004-09-26 13:48:52 +00:00
$return [] = $this -> messages [ 'minMachine' ][ 0 ];
2004-08-01 09:39:24 +00:00
}
if ( ! isset ( $options [ 'posixAccount_maxMachine' ][ 0 ]) || ! ereg ( '^[0-9]+$' , $options [ 'posixAccount_maxMachine' ][ 0 ])) {
2004-09-26 13:48:52 +00:00
$return [] = $this -> messages [ 'maxMachine' ][ 0 ];
2004-08-01 09:39:24 +00:00
}
// minUID < maxUID
if ( isset ( $options [ 'posixAccount_minMachine' ][ 0 ]) && isset ( $options [ 'posixAccount_maxMachine' ][ 0 ])) {
if ( $options [ 'posixAccount_minMachine' ][ 0 ] > $options [ 'posixAccount_maxMachine' ][ 0 ]) {
2004-09-26 13:48:52 +00:00
$return [] = $this -> messages [ 'cmp_Machine' ][ 0 ];
2004-08-01 09:39:24 +00:00
}
}
}
// check if user and host ranges overlap
if ( in_array ( 'user' , $scopes ) && in_array ( 'host' , $scopes )) {
if ( isset ( $options [ 'posixAccount_minUID' ][ 0 ]) && isset ( $options [ 'posixAccount_maxUID' ][ 0 ]) &&
2004-10-12 13:34:00 +00:00
isset ( $options [ 'posixAccount_minMachine' ][ 0 ]) && isset ( $options [ 'posixAccount_maxMachine' ][ 0 ])) {
2004-08-01 09:39:24 +00:00
if (( $options [ 'posixAccount_minMachine' ][ 0 ] > $options [ 'posixAccount_minUID' ][ 0 ]) &&
2004-10-12 13:34:00 +00:00
( $options [ 'posixAccount_minMachine' ][ 0 ] < $options [ 'posixAccount_maxUID' ][ 0 ])) {
2004-09-26 13:48:52 +00:00
$return [] = $this -> messages [ 'cmp_both' ][ 0 ];
2004-08-01 09:39:24 +00:00
}
if (( $options [ 'posixAccount_minUID' ][ 0 ] > $options [ 'posixAccount_minMachine' ][ 0 ]) &&
2004-10-12 13:34:00 +00:00
( $options [ 'posixAccount_minUID' ][ 0 ] < $options [ 'posixAccount_maxMachine' ][ 0 ])) {
2004-09-26 13:48:52 +00:00
$return [] = $this -> messages [ 'cmp_both' ][ 0 ];
2004-08-01 09:39:24 +00:00
}
}
}
return $return ;
2004-10-30 17:00:34 +00:00
}
/**
2004-10-16 14:28:06 +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 ) {
2004-10-16 19:51:36 +00:00
$triggered_messages = array ();
2005-03-25 14:21:07 +00:00
$needAutoUID = array ();
2005-06-08 21:02:01 +00:00
// get list of existing users
2005-10-15 09:33:05 +00:00
$dnUsers = $_SESSION [ 'cache' ] -> get_cache ( 'uid' , 'posixAccount' , array ( 'user' , 'host' ));
2005-06-08 21:02:01 +00:00
$existingUsers = array ();
foreach ( $dnUsers as $dn ) {
$existingUsers [] = $dn [ 0 ];
}
// get list of existing groups
$existingGroups = $_SESSION [ 'cache' ] -> findgroups ();
// check input
2004-10-16 14:28:06 +00:00
for ( $i = 0 ; $i < sizeof ( $rawAccounts ); $i ++ ) {
if ( ! in_array ( " posixAccount " , $partialAccounts [ $i ][ 'objectClass' ])) $partialAccounts [ $i ][ 'objectClass' ][] = " posixAccount " ;
// UID
if ( $rawAccounts [ $i ][ $ids [ 'posixAccount_uid' ]] == " " ) {
2005-03-25 14:21:07 +00:00
// autoUID
$needAutoUID [] = $i ;
2004-10-16 14:28:06 +00:00
}
2004-11-01 11:49:43 +00:00
elseif ( get_preg ( $rawAccounts [ $i ][ $ids [ 'posixAccount_uid' ]], 'digit' )) {
if (( $this -> get_scope () == 'user' ) &&
( $rawAccounts [ $i ][ $ids [ 'posixAccount_uid' ]] > $this -> moduleSettings [ 'posixAccount_minUID' ][ 0 ]) &&
( $rawAccounts [ $i ][ $ids [ 'posixAccount_uid' ]] < $this -> moduleSettings [ 'posixAccount_maxUID' ][ 0 ])) {
$partialAccounts [ $i ][ 'uidNumber' ] = $rawAccounts [ $i ][ $ids [ 'posixAccount_uid' ]];
}
elseif (( $this -> get_scope () == 'host' ) &&
( $rawAccounts [ $i ][ $ids [ 'posixAccount_uid' ]] > $this -> moduleSettings [ 'posixAccount_minMachine' ][ 0 ]) &&
( $rawAccounts [ $i ][ $ids [ 'posixAccount_uid' ]] < $this -> moduleSettings [ 'posixAccount_maxMachine' ][ 0 ])) {
$partialAccounts [ $i ][ 'uidNumber' ] = $rawAccounts [ $i ][ $ids [ 'posixAccount_uid' ]];
}
2004-10-16 14:28:06 +00:00
}
else {
2004-10-17 18:29:39 +00:00
$errMsg = $this -> messages [ 'uidNumber' ][ 4 ];
2004-10-16 14:28:06 +00:00
array_push ( $errMsg , array ( $i ));
2004-10-16 19:51:36 +00:00
$triggered_messages [] = $errMsg ;
2004-10-16 14:28:06 +00:00
}
// GID number
if ( get_preg ( $rawAccounts [ $i ][ $ids [ 'posixAccount_group' ]], 'digit' )) {
$partialAccounts [ $i ][ 'gidNumber' ] = $rawAccounts [ $i ][ $ids [ 'posixAccount_group' ]];
}
if ( get_preg ( $rawAccounts [ $i ][ $ids [ 'posixAccount_group' ]], 'groupname' )) {
2004-10-17 18:29:39 +00:00
$gid = $_SESSION [ 'cache' ] -> getgid ( $rawAccounts [ $i ][ $ids [ 'posixAccount_group' ]]);
if ( is_numeric ( $gid )) {
$partialAccounts [ $i ][ 'gidNumber' ] = $gid ;
}
else {
$errMsg = $this -> messages [ 'gidNumber' ][ 0 ];
array_push ( $errMsg , array ( $i ));
$triggered_messages [] = $errMsg ;
}
2004-10-16 14:28:06 +00:00
}
else {
2004-10-17 18:29:39 +00:00
$errMsg = $this -> messages [ 'gidNumber' ][ 1 ];
2004-10-16 14:28:06 +00:00
array_push ( $errMsg , array ( $i ));
2004-10-16 19:51:36 +00:00
$triggered_messages [] = $errMsg ;
2004-10-16 14:28:06 +00:00
}
2005-06-07 18:28:28 +00:00
// GECOS
if ( $rawAccounts [ $i ][ $ids [ 'posixAccount_gecos' ]] != " " ) {
if ( get_preg ( $rawAccounts [ $i ][ $ids [ 'posixAccount_gecos' ]], 'gecos' )) {
$partialAccounts [ $i ][ 'gecos' ] = $rawAccounts [ $i ][ $ids [ 'posixAccount_gecos' ]];
}
else {
$errMsg = $this -> messages [ 'gecos' ][ 0 ];
array_push ( $errMsg , array ( $i ));
$triggered_messages [] = $errMsg ;
}
2004-10-16 14:28:06 +00:00
}
else {
2005-06-07 18:28:28 +00:00
$gecos = " " ;
if (( $rawAccounts [ $i ][ $ids [ 'inetOrgPerson_firstName' ]] != " " ) && ( $rawAccounts [ $i ][ $ids [ 'inetOrgPerson_lastName' ]] != " " )) {
$gecos = $rawAccounts [ $i ][ $ids [ 'inetOrgPerson_firstName' ]] . " " . $rawAccounts [ $i ][ $ids [ 'inetOrgPerson_lastName' ]];
if ( $rawAccounts [ $i ][ $ids [ 'inetOrgPerson_telephone' ]] != " " ) {
$gecos = $gecos . " ,, " . $rawAccounts [ $i ][ $ids [ 'inetOrgPerson_telephone' ]]; // double "," because room is unknown
if ( $rawAccounts [ $i ][ $ids [ 'inetOrgPerson_fax' ]] != " " ) {
$gecos = $gecos . " , " . $rawAccounts [ $i ][ $ids [ 'inetOrgPerson_fax' ]];
}
}
}
if ( $gecos != " " ) $partialAccounts [ $i ][ 'gecos' ] = $gecos ;
2004-10-16 14:28:06 +00:00
}
// user specific attributes
if ( $this -> scope == 'user' ) {
2005-06-08 21:02:01 +00:00
// additional groups
if ( $rawAccounts [ $i ][ $ids [ 'posixAccount_additionalGroups' ]] != " " ) {
$groups = explode ( " , " , $rawAccounts [ $i ][ $ids [ 'posixAccount_additionalGroups' ]]);
for ( $g = 0 ; $g < sizeof ( $groups ); $g ++ ) {
if ( ! in_array ( $groups [ $g ], $existingGroups )) {
$triggered_messages [] = array ( 'ERROR' , _ ( 'Unable to find group in LDAP.' ), $groups [ $g ]);
}
}
}
2004-10-16 14:28:06 +00:00
// user name
2005-06-08 21:02:01 +00:00
if ( in_array ( $rawAccounts [ $i ][ $ids [ 'posixAccount_userName' ]], $existingUsers )) {
$errMsg = $this -> messages [ 'uid' ][ 9 ];
array_push ( $errMsg , array ( $i ));
$triggered_messages [] = $errMsg ;
}
elseif ( get_preg ( $rawAccounts [ $i ][ $ids [ 'posixAccount_userName' ]], 'username' )) {
2004-10-16 14:28:06 +00:00
$partialAccounts [ $i ][ 'uid' ] = $rawAccounts [ $i ][ $ids [ 'posixAccount_userName' ]];
}
else {
2004-10-17 18:29:39 +00:00
$errMsg = $this -> messages [ 'uid' ][ 7 ];
2004-10-16 14:28:06 +00:00
array_push ( $errMsg , array ( $i ));
2004-10-16 19:51:36 +00:00
$triggered_messages [] = $errMsg ;
2004-10-16 14:28:06 +00:00
}
// home directory
if ( $rawAccounts [ $i ][ $ids [ 'posixAccount_homedir' ]] == " " ) {
$partialAccounts [ $i ][ 'homeDirectory' ] = '/home/' . $partialAccounts [ $i ][ 'uid' ];
}
elseif ( get_preg ( $rawAccounts [ $i ][ $ids [ 'posixAccount_homedir' ]], 'homeDirectory' )) {
$partialAccounts [ $i ][ 'homeDirectory' ] = $rawAccounts [ $i ][ $ids [ 'posixAccount_homedir' ]];
}
else {
2004-10-17 18:29:39 +00:00
$errMsg = $this -> messages [ 'homeDirectory' ][ 2 ];
2004-10-16 14:28:06 +00:00
array_push ( $errMsg , array ( $i ));
2004-10-16 19:51:36 +00:00
$triggered_messages [] = $errMsg ;
2004-10-16 14:28:06 +00:00
}
// login shell
if ( $rawAccounts [ $i ][ $ids [ 'posixAccount_shell' ]] == " " ) {
$partialAccounts [ $i ][ 'loginShell' ] = '/bin/bash' ;
}
elseif ( in_array ( $rawAccounts [ $i ][ $ids [ 'posixAccount_shell' ]], getshells ())) {
$partialAccounts [ $i ][ 'loginShell' ] = $rawAccounts [ $i ][ $ids [ 'posixAccount_shell' ]];
}
else {
2004-10-17 18:29:39 +00:00
$errMsg = $this -> messages [ 'shell' ][ 0 ];
2004-10-16 14:28:06 +00:00
array_push ( $errMsg , array ( $i ));
2004-10-16 19:51:36 +00:00
$triggered_messages [] = $errMsg ;
2004-10-16 14:28:06 +00:00
}
$pwd_enabled = true ;
// password enabled/disabled
if ( $rawAccounts [ $i ][ $ids [ 'posixAccount_passwordDisabled' ]] == " " ) {
$pwd_enabled = true ;
}
elseif ( in_array ( $rawAccounts [ $i ][ $ids [ 'posixAccount_passwordDisabled' ]], array ( 'true' , 'false' ))) {
if ( $rawAccounts [ $i ][ $ids [ 'posixAccount_passwordDisabled' ]] == 'true' ) $pwd_enabled = false ;
else $pwd_enabled = true ;
}
else {
2004-10-17 18:29:39 +00:00
$errMsg = $this -> messages [ 'passwordDisabled' ][ 0 ];
2004-10-16 14:28:06 +00:00
array_push ( $errMsg , array ( $i ));
2004-10-16 19:51:36 +00:00
$triggered_messages [] = $errMsg ;
2004-10-16 14:28:06 +00:00
}
// password
if (( $rawAccounts [ $i ][ $ids [ 'posixAccount_password' ]] != " " ) && ( get_preg ( $rawAccounts [ $i ][ $ids [ 'posixAccount_password' ]], 'password' ))) {
$partialAccounts [ $i ][ 'userPassword' ] = pwd_hash ( $rawAccounts [ $i ][ $ids [ 'posixAccount_password' ]], $pwd_enabled , $this -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ]);
}
2004-10-17 18:29:39 +00:00
elseif ( $rawAccounts [ $i ][ $ids [ 'posixAccount_password' ]] != " " ) {
$errMsg = $this -> messages [ 'userPassword' ][ 4 ];
2004-10-16 14:28:06 +00:00
array_push ( $errMsg , array ( $i ));
2004-10-16 19:51:36 +00:00
$triggered_messages [] = $errMsg ;
2004-10-16 14:28:06 +00:00
}
2004-11-05 16:53:38 +00:00
// description
$modules = $_SESSION [ 'config' ] -> get_AccountModules ( $this -> get_scope ());
if ( ! in_array ( 'inetOrgPerson' , $modules )) {
if ( $rawAccounts [ $i ][ $ids [ 'posixAccount_description' ]] && ( $rawAccounts [ $i ][ $ids [ 'posixAccount_description' ]] != '' )) {
$partialAccounts [ $i ][ 'description' ] = $rawAccounts [ $i ][ $ids [ 'posixAccount_description' ]];
}
else {
$partialAccounts [ $i ][ 'description' ] = $rawAccounts [ $i ][ $ids [ 'posixAccount_hostName' ]];
}
}
2005-06-19 09:38:44 +00:00
// cn
if ( $rawAccounts [ $i ][ $ids [ 'posixAccount_cn' ]] != " " ) {
if ( get_preg ( $rawAccounts [ $i ][ $ids [ 'posixAccount_cn' ]], 'cn' )) {
$partialAccounts [ $i ][ 'cn' ] = $rawAccounts [ $i ][ $ids [ 'posixAccount_cn' ]];
}
else {
$errMsg = $this -> messages [ 'cn' ][ 1 ];
array_push ( $errMsg , array ( $i ));
$triggered_messages [] = $errMsg ;
}
}
else {
if ( $partialAccounts [ $i ][ 'givenName' ]) {
$partialAccounts [ $i ][ 'cn' ] = $partialAccounts [ $i ][ 'givenName' ] . " " . $partialAccounts [ $i ][ 'sn' ];
}
elseif ( $partialAccounts [ $i ][ 'sn' ]) {
$partialAccounts [ $i ][ 'cn' ] = $partialAccounts [ $i ][ 'sn' ];
}
else {
$partialAccounts [ $i ][ 'cn' ] = $partialAccounts [ $i ][ 'uid' ];
}
}
2004-10-16 14:28:06 +00:00
}
// host specific attributes
elseif ( $this -> scope == 'host' ) {
// host name
2005-06-08 21:02:01 +00:00
if ( in_array ( $rawAccounts [ $i ][ $ids [ 'posixAccount_hostName' ]], $existingUsers )) {
$errMsg = $this -> messages [ 'uid' ][ 10 ];
array_push ( $errMsg , array ( $i ));
$triggered_messages [] = $errMsg ;
}
elseif ( get_preg ( $rawAccounts [ $i ][ $ids [ 'posixAccount_hostName' ]], 'hostname' )) {
2004-10-16 14:28:06 +00:00
$partialAccounts [ $i ][ 'uid' ] = $rawAccounts [ $i ][ $ids [ 'posixAccount_hostName' ]];
2004-11-05 16:53:38 +00:00
$partialAccounts [ $i ][ 'cn' ] = $rawAccounts [ $i ][ $ids [ 'posixAccount_hostName' ]];
2004-10-16 14:28:06 +00:00
}
else {
2004-10-17 18:29:39 +00:00
$errMsg = $this -> messages [ 'uid' ][ 8 ];
2004-10-16 14:28:06 +00:00
array_push ( $errMsg , array ( $i ));
2004-10-16 19:51:36 +00:00
$triggered_messages [] = $errMsg ;
2004-10-16 14:28:06 +00:00
}
2004-11-05 16:53:38 +00:00
// description
if ( $rawAccounts [ $i ][ $ids [ 'posixAccount_description' ]] && ( $rawAccounts [ $i ][ $ids [ 'posixAccount_description' ]] != '' )) {
$partialAccounts [ $i ][ 'description' ] = $rawAccounts [ $i ][ $ids [ 'posixAccount_description' ]];
}
else {
$partialAccounts [ $i ][ 'description' ] = $rawAccounts [ $i ][ $ids [ 'posixAccount_hostName' ]];
}
2004-10-16 14:28:06 +00:00
$partialAccounts [ $i ][ 'homeDirectory' ] = '/dev/null' ;
$partialAccounts [ $i ][ 'loginShell' ] = '/bin/false' ;
}
}
2005-03-25 14:21:07 +00:00
// fill in autoUIDs
if ( sizeof ( $needAutoUID ) > 0 ) {
$errorsTemp = array ();
$uids = $this -> getNextUIDs ( sizeof ( $needAutoUID ), $errorsTemp );
if ( is_array ( $uids )) {
for ( $i = 0 ; $i < sizeof ( $needAutoUID ); $i ++ ) {
$partialAccounts [ $i ][ 'uidNumber' ] = $uids [ $i ];
}
}
else {
$triggered_messages [] = $this -> messages [ 'uidNumber' ][ 2 ];
}
}
2004-10-16 19:51:36 +00:00
return $triggered_messages ;
2004-10-16 14:28:06 +00:00
}
2004-10-23 11:54:44 +00:00
/**
* This function executes one post upload action .
*
* @ param array $data array containing one account in each element
* @ param array $ids array ( < column_name > => < column number > )
* @ param array $failed list of accounts which were not created successfully
* @ param array $temp variable to store temporary data between two post actions
* @ return array current status
* < br > array (
* < br > 'status' => 'finished' | 'inProgress'
* < br > 'progress' => 0. . 100
* < br > 'errors' => array ( < array of parameters for StatusMessage > )
* < br > )
*/
function doUploadPostActions ( $data , $ids , $failed , & $temp ) {
// on first call generate list of ldap operations
if ( ! isset ( $temp [ 'counter' ])) {
2004-10-24 09:50:02 +00:00
$temp [ 'groups' ] = array ();
2004-10-23 11:54:44 +00:00
$temp [ 'counter' ] = 0 ;
$col = $ids [ 'posixAccount_additionalGroups' ];
for ( $i = 0 ; $i < sizeof ( $data ); $i ++ ) {
2004-10-24 09:50:02 +00:00
if ( in_array ( $i , $failed )) continue ; // ignore failed accounts
2004-10-23 11:54:44 +00:00
if ( $data [ $i ][ $col ] != " " ) {
$groups = explode ( " , " , $data [ $i ][ $col ]);
for ( $g = 0 ; $g < sizeof ( $groups ); $g ++ ) {
2004-10-24 09:50:02 +00:00
if ( ! in_array ( $groups [ $g ], $temp [ 'groups' ])) $temp [ 'groups' ][] = $groups [ $g ];
$temp [ 'members' ][ $groups [ $g ]][] = $data [ $i ][ $ids [ 'posixAccount_userName' ]];
2004-10-23 11:54:44 +00:00
}
}
}
return array (
'status' => 'inProgress' ,
'progress' => 0 ,
'errors' => array ()
);
}
2004-10-24 09:50:02 +00:00
// get DNs of groups
elseif ( ! isset ( $temp [ 'dn' ])) {
$temp [ 'dn' ] = array ();
$result = $_SESSION [ 'cache' ] -> get_cache ( 'cn' , 'posixGroup' , 'group' );
$keys = array_keys ( $result );
for ( $i = 0 ; $i < sizeof ( $result ); $i ++ ) {
$temp [ 'dn' ][ $result [ $keys [ $i ]][ 0 ]] = $keys [ $i ];
}
2005-03-25 14:21:07 +00:00
return array (
'status' => 'inProgress' ,
'progress' => 0 ,
'errors' => array ()
);
2004-10-24 09:50:02 +00:00
}
// add users to groups
elseif ( $temp [ 'counter' ] < sizeof ( $temp [ 'groups' ])) {
if ( isset ( $temp [ 'dn' ][ $temp [ 'groups' ][ $temp [ 'counter' ]]])) {
$success = @ ldap_mod_add ( $_SESSION [ 'ldap' ] -> server , $temp [ 'dn' ][ $temp [ 'groups' ][ $temp [ 'counter' ]]], array ( 'memberUID' => $temp [ 'members' ][ $temp [ 'groups' ][ $temp [ 'counter' ]]]));
$errors = array ();
if ( ! $success ) {
$errors [] = array (
" ERROR " ,
_ ( " LAM was unable to modify group memberships for group: %s " ),
ldap_errno ( $_SESSION [ ldap ] -> server ) . " : " . ldap_error ( $_SESSION [ ldap ] -> server ),
array ( $temp [ 'groups' ][ $temp [ 'counter' ]])
);
}
$temp [ 'counter' ] ++ ;
return array (
'status' => 'inProgress' ,
'progress' => ( $temp [ 'counter' ] * 100 ) / sizeof ( $temp [ 'groups' ]),
'errors' => $errors
);
}
else {
$temp [ 'counter' ] ++ ;
return array (
'status' => 'inProgress' ,
'progress' => ( $temp [ 'counter' ] * 100 ) / sizeof ( $temp [ 'groups' ]),
'errors' => array ( array ( 'ERROR' , _ ( 'Unable to find group in LDAP.' ), $temp [ 'groups' ][ $temp [ 'counter' ]]))
);
}
}
// all groups are modified
2004-10-23 11:54:44 +00:00
else {
2004-10-24 09:50:02 +00:00
return array (
'status' => 'finished' ,
'progress' => 100 ,
'errors' => array ()
);
2004-10-23 11:54:44 +00:00
}
}
2005-03-25 14:21:07 +00:00
/**
* Returns one or more free UID numbers .
*
* @ param integer $count Number of needed free UIDs .
* @ param array $triggered_messages list of error messages where errors can be added
* @ return mixed Null if no UIDs are free else an array of free UIDs .
*/
function getNextUIDs ( $count , & $triggered_messages ) {
$ret = array ();
if ( $this -> scope == " user " ) {
$minID = intval ( $this -> moduleSettings [ 'posixAccount_minUID' ][ 0 ]);
$maxID = intval ( $this -> moduleSettings [ 'posixAccount_maxUID' ][ 0 ]);
}
else {
$minID = intval ( $this -> moduleSettings [ 'posixAccount_minMachine' ][ 0 ]);
$maxID = intval ( $this -> moduleSettings [ 'posixAccount_maxMachine' ][ 0 ]);
}
2005-10-15 09:33:05 +00:00
$dn_uids = $_SESSION [ 'cache' ] -> get_cache ( 'uidNumber' , 'posixAccount' , array ( 'user' , 'host' ));
2005-03-25 14:21:07 +00:00
// get_cache will return an array ( dn1 => array(uidnumber1), dn2 => array(uidnumber2), ... )
$uids = array ();
if ( is_array ( $dn_uids )) {
foreach ( $dn_uids as $uid ) {
2005-09-27 12:34:04 +00:00
if (( $uid [ 0 ] <= $maxID ) && ( $uid [ 0 ] >= $minID )) $uids [] = $uid [ 0 ]; // ignore UIDs > maxID and UIDs < minID
2005-03-25 14:21:07 +00:00
}
sort ( $uids , SORT_NUMERIC );
}
for ( $i = 0 ; $i < $count ; $i ++ ) {
if ( count ( $uids ) != 0 ) {
// there already are some uids
// store highest id-number
$id = $uids [ count ( $uids ) - 1 ];
// Return minimum allowed id-number if all found id-numbers are too low
if ( $id < $minID ) {
$ret [] = $minID ;
$uids [] = $minID ;
}
// return highest used id-number + 1 if it's still in valid range
elseif ( $id < $maxID ) {
$ret [] = $id + 1 ;
$uids [] = $id + 1 ;
}
// find free numbers between existing ones
else {
$k = intval ( $minID );
while ( in_array ( $k , $uids )) $k ++ ;
if ( $k > $maxID ) return null ;
else {
$ret [] = $k ;
$uids [] = $k ;
sort ( $uids , SORT_NUMERIC );
}
// show warning message
$triggered_messages [ 'uidNumber' ][] = $this -> messages [ 'uidNumber' ][ 2 ];
}
}
else {
// return minimum allowed id-number if no id-numbers are found
$ret [] = $minID ;
$uids [] = $minID ;
}
}
return $ret ;
}
2004-03-09 12:03:39 +00:00
}
2003-12-09 18:42:50 +00:00
?>