2003-12-09 18:42:50 +00:00
< ? php
2017-03-22 19:17:52 +00:00
use \LAM\TYPES\TypeManager ;
2017-12-20 19:44:08 +00:00
use function LAM\TYPES\getScopeFromTypeId ;
2018-06-15 17:03:51 +00:00
use LAM\TYPES\ConfiguredType ;
2003-12-09 18:42:50 +00:00
/*
2006-08-13 12:58:19 +00:00
2009-10-27 18:47:12 +00:00
This code is part of LDAP Account Manager ( http :// www . ldap - account - manager . org / )
2006-03-03 17:30:35 +00:00
Copyright ( C ) 2003 - 2006 Tilo Lutz
2020-02-08 14:42:07 +00:00
Copyright ( C ) 2005 - 2020 Roland Gruber
2006-08-13 12:58:19 +00:00
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 .
2006-08-13 12:58:19 +00:00
2004-10-16 14:28:06 +00:00
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
2006-08-13 12:58:19 +00:00
2004-10-16 14:28:06 +00:00
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
2003-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
2007-02-25 13:55:26 +00:00
* @ author Thomas Manninger
2005-07-21 10:33:02 +00:00
*/
/**
* Manages the object class " posixAccount " for users and hosts.
*
* @ package modules
*/
2009-10-08 20:16:02 +00:00
class posixAccount extends baseModule implements passwordService {
2004-06-08 18:54:37 +00:00
2006-09-03 12:41:22 +00:00
// Variables
2012-07-15 12:05:47 +00:00
/** delimiter for lamdaemon commands */
2009-12-12 17:22:14 +00:00
private static $SPLIT_DELIMITER = " ###x##y##x### " ;
2015-08-09 07:22:01 +00:00
2006-09-03 12:41:22 +00:00
/* These two variables keep an array of groups the user is also member of. */
2012-07-15 12:05:47 +00:00
/** current group list */
2007-10-13 17:28:37 +00:00
private $groups ;
2012-07-15 12:05:47 +00:00
/** original group list */
2007-10-13 17:28:37 +00:00
private $groups_orig ;
2009-11-26 10:48:05 +00:00
2011-10-06 20:03:45 +00:00
/* list of group of names that the user is member of */
2012-07-15 12:05:47 +00:00
/** current group of names list */
2011-12-14 19:11:33 +00:00
private $gonList = array ();
2012-07-15 12:05:47 +00:00
/** original group of names list */
2011-12-14 19:11:33 +00:00
private $gonList_orig = array ();
2012-07-15 12:05:47 +00:00
/** lamdaemon servers */
2011-05-07 08:59:50 +00:00
private $lamdaemonServers = array ();
2012-07-15 12:05:47 +00:00
/** cache for group objects */
2009-11-26 10:48:05 +00:00
private $groupCache = null ;
2012-07-15 12:05:47 +00:00
/** cache for group of names objects */
2011-10-06 20:03:45 +00:00
private $gonCache = null ;
2012-07-15 12:05:47 +00:00
/** clear text password */
2010-03-08 18:26:06 +00:00
private $clearTextPassword ;
2010-11-23 21:12:13 +00:00
/** caches the list of known UIDs */
private $cachedUIDList = null ;
2012-09-07 16:35:54 +00:00
/** caches the list of known user names */
private $cachedUserNameList = null ;
2015-08-09 07:22:01 +00:00
2013-06-17 18:38:42 +00:00
/** replacements for common umlauts */
private $umlautReplacements = array (
'ä' => 'ae' , 'Ä' => 'Ae' , 'ö' => 'oe' , 'Ö' => 'Oe' , 'ü' => 'ue' , 'Ü' => 'Ue' ,
'ß' => 'ss' , 'é' => 'e' , 'è' => 'e' , 'ô' => 'o' , 'ç' => 'c'
);
2006-09-03 12:41:22 +00:00
2006-05-18 08:50:51 +00:00
/**
2006-08-15 16:32:33 +00:00
* This function fills the error message array with messages .
2004-09-26 13:48:52 +00:00
**/
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.' ));
2006-08-15 16:32:33 +00:00
$this -> messages [ 'homeDirectory' ][ 3 ] = array ( 'INFO' , _ ( 'Home directory' ), _ ( 'Home directory changed. To keep home directory you have to run the following command as root: \'mv %s %s\'' ));
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.' ));
2006-08-15 16:32:33 +00:00
$this -> messages [ 'uidNumber' ][ 5 ] = array ( 'INFO' , _ ( 'UID number' ), _ ( 'UID number has changed. To keep file ownership you have to run the following command as root: \'find / -uid %s -exec chown %s {} \;\'' ));
2010-02-08 16:23:32 +00:00
$this -> messages [ 'userPassword' ][ 0 ] = array ( 'ERROR' , _ ( 'Password' ), _ ( 'Please enter the same password in both password fields.' ));
2013-01-13 10:40:47 +00:00
$this -> messages [ 'userPassword' ][ 1 ] = array ( 'ERROR' , _ ( 'Password' ), _ ( 'Password contains invalid characters. Valid characters are:' ) . ' a-z, A-Z, 0-9 and #*,.;:_-+!%&/|?{[()]}=@$ §°!' );
$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?' ));
2010-06-03 19:38:56 +00:00
$this -> messages [ 'uid' ][ 1 ] = array ( 'WARN' , _ ( 'User name' ), _ ( 'You are using capital letters. This can cause problems because Windows is not case-sensitive.' ));
2005-06-19 09:38:44 +00:00
$this -> messages [ 'uid' ][ 2 ] = array ( 'ERROR' , _ ( 'User name' ), _ ( 'User name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !' ));
2010-06-03 19:38:56 +00:00
$this -> messages [ 'uid' ][ 3 ] = array ( 'WARN' , _ ( 'Host name' ), _ ( 'You are using capital letters. This can cause problems because Windows is not case-sensitive.' ));
2009-02-01 16:24:37 +00:00
$this -> messages [ 'uid' ][ 4 ] = array ( 'ERROR' , _ ( 'Host name' ), _ ( 'Host name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !' ));
2018-04-11 16:40:44 +00:00
$this -> messages [ 'uid' ][ 5 ] = array ( 'WARN' , _ ( 'User name' ), _ ( 'User name in use (%s). Selected next free user name.' ));
$this -> messages [ 'uid' ][ 6 ] = array ( 'WARN' , _ ( 'Host name' ), _ ( 'Host name in use (%s). 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 .-_ !' ));
2018-08-12 08:38:56 +00:00
$this -> messages [ 'uid' ][ 9 ] = array ( 'WARN' , _ ( 'Account %s:' ) . ' posixAccount_userName' , _ ( 'User name already exists!' ) . ' ' . _ ( 'You might want to use %s instead of %s.' ) . ' %s' );
$this -> messages [ 'uid' ][ 10 ] = array ( 'WARN' , _ ( 'Account %s:' ) . ' posixAccount_hostName' , _ ( 'Host name already exists!' ) . ' ' . _ ( 'You might want to use %s instead of %s.' ) . ' %s' );
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.' ));
2006-08-15 16:32:33 +00:00
$this -> messages [ 'gidNumber' ][ 2 ] = array ( 'INFO' , _ ( 'GID number' ), _ ( '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 {} \;\'' ));
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!' ));
2010-08-15 16:22:50 +00:00
$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!' ));
2013-11-09 13:25:45 +00:00
$this -> messages [ 'cn' ][ 1 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' posixAccount_cn' , _ ( 'Please enter a valid common name!' ));
2013-02-17 13:19:50 +00:00
$this -> messages [ 'sambaIDPoolDN' ][ 0 ] = array ( 'ERROR' , _ ( 'Samba ID pool DN' ), _ ( 'This is not a valid DN!' ));
2015-06-07 06:34:24 +00:00
$this -> messages [ 'windowsIDPoolDN' ][ 0 ] = array ( 'ERROR' , _ ( 'Windows domain info DN' ), _ ( 'This is not a valid DN!' ));
2004-09-26 13:48:52 +00:00
}
2014-04-20 13:00:42 +00:00
/**
* Returns true if this module can manage accounts of the current type , otherwise false .
2015-08-09 07:22:01 +00:00
*
2014-04-20 13:00:42 +00:00
* @ return boolean true if module fits
*/
public function can_manage () {
return in_array ( $this -> get_scope (), array ( 'user' , 'host' ));
}
2004-06-08 18:54:37 +00:00
/**
* Returns meta data that is interpreted by parent class
*
* @ return array array with meta data
2015-08-09 07:22:01 +00:00
*
2008-02-03 14:28:28 +00:00
* @ see baseModule :: get_metaData ()
2004-06-08 18:54:37 +00:00
*/
function get_metaData () {
$return = array ();
2007-11-19 18:42:03 +00:00
// icon
$return [ 'icon' ] = 'tux.png' ;
2004-06-13 19:58:58 +00:00
// 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 " ) {
2009-10-06 17:00:43 +00:00
// LDAP filter
$return [ " ldap_filter " ] = array ( 'or' => " (objectClass=posixAccount) " );
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-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
2007-07-03 15:43:52 +00:00
$return [ " RDN " ] = array ( " uid " => " high " , " cn " => " low " );
2006-04-05 15:48:27 +00:00
// managed object classes
$return [ 'objectClasses' ] = array ( 'posixAccount' );
2006-05-01 16:13:10 +00:00
// LDAP aliases
2006-05-01 16:18:16 +00:00
$return [ 'LDAPaliases' ] = array ( 'commonName' => 'cn' , 'userid' => 'uid' );
2006-05-13 08:55:31 +00:00
// managed attributes
2017-05-10 17:23:28 +00:00
$return [ 'attributes' ] = array ( 'uid' , 'uidNumber' , 'gidNumber' ,
'loginShell' , 'gecos' , 'INFO.userPasswordClearText' );
2006-08-03 18:01:34 +00:00
if ( $this -> get_scope () == " user " ) {
// self service search attributes
$return [ 'selfServiceSearchAttributes' ] = array ( 'uid' );
// self service field settings
2016-06-26 08:15:45 +00:00
$return [ 'selfServiceFieldSettings' ] = array (
'password' => _ ( 'Password' ),
'cn' => _ ( 'Common name' ),
'loginShell' => _ ( 'Login shell' ),
2019-03-06 17:09:22 +00:00
'syncWindowsPassword' => _ ( 'Sync Unix password with Windows password' ),
'unixgroups' => _ ( 'Groups (read-only)' )
2016-06-26 08:15:45 +00:00
);
2012-08-18 15:55:43 +00:00
// possible self service read-only fields
$return [ 'selfServiceReadOnlyFields' ] = array ( 'cn' , 'loginShell' );
2006-11-21 17:37:12 +00:00
// self service configuration settings
2017-12-17 08:59:07 +00:00
$selfServiceContainer = new htmlResponsiveRow ();
$selfServiceContainer -> add ( new htmlResponsiveSelect ( 'posixAccount_pwdHash' , getSupportedHashTypes (),
array ( 'SSHA' ), _ ( " Password hash type " ), array ( 'pwdHash' , get_class ( $this ))), 12 );
$selfServiceContainer -> add ( new htmlResponsiveInputTextarea ( 'posixAccount_shells' , implode ( " \r \n " , $this -> getShells ()), 30 , 4 , _ ( 'Login shells' ), array ( 'loginShells' , get_class ( $this ))), 12 );
2019-03-06 17:09:22 +00:00
$selfServiceContainer -> add ( new htmlResponsiveInputField ( _ ( 'Group DN' ), 'posixAccount_groupDn' , '' , array ( 'groupDn' , get_class ( $this ))), 12 );
2017-12-17 08:59:07 +00:00
$selfServiceContainer -> add ( new htmlResponsiveInputCheckbox ( 'posixAccount_useOldPwd' , false , _ ( 'Password change with old password' ), array ( 'useOldPwd' , get_class ( $this ))), 12 );
2010-09-25 18:48:51 +00:00
$return [ 'selfServiceSettings' ] = $selfServiceContainer ;
2006-08-03 18:01:34 +00:00
}
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_loginShell' => 'loginShell'
);
2004-10-16 14:28:06 +00:00
// upload
$return [ 'upload_preDepends' ] = array ( 'inetOrgPerson' );
// user specific upload options
2014-10-25 19:17:53 +00:00
if (( $this -> get_scope () == 'user' ) && isLoggedIn ()) {
2019-10-22 19:22:32 +00:00
$lamdaemonServers = $_SESSION [ 'config' ] -> getConfiguredScriptServers ();
$lamdaemonOptions = array ();
foreach ( $lamdaemonServers as $lamdaemonServer ) {
$lamdaemonOptions [] = $lamdaemonServer -> getServer ();
}
2004-10-16 14:28:06 +00:00
$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
),
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' ),
2010-12-05 13:29:53 +00:00
'default' => '/home/{posixAccount_userName}'
2004-10-16 14:28:06 +00:00
),
2007-07-09 19:03:19 +00:00
array (
'name' => 'posixAccount_createHomeDir' ,
'description' => _ ( 'Create home directory' ),
'help' => 'createhomedir' ,
'example' => 'localhost' ,
2019-10-22 19:22:32 +00:00
'values' => implode ( ', ' , $lamdaemonOptions )
2007-07-09 19:03:19 +00:00
),
2004-10-16 14:28:06 +00:00
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' ,
2013-02-05 19:10:04 +00:00
'values' => implode ( " , " , $this -> getShells ()),
2004-10-16 14:28:06 +00:00
'default' => '/bin/bash'
),
);
2012-04-09 13:20:24 +00:00
if ( self :: areGroupOfNamesActive ()) {
2011-10-06 20:03:45 +00:00
$return [ 'upload_columns' ][] = array (
'name' => 'posixAccount_gon' ,
2013-03-24 10:03:35 +00:00
'description' => _ ( 'Groups of names' ),
2011-10-06 20:03:45 +00:00
'help' => 'addgroup_upload' ,
'example' => _ ( 'group01,group02' )
);
}
2004-10-16 14:28:06 +00:00
}
// host specific upload options
2007-10-04 16:45:05 +00:00
elseif ( $this -> get_scope () == 'host' ) {
2004-10-16 14:28:06 +00:00
$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
),
);
}
2004-08-17 15:16:17 +00:00
// available PDF fields
2013-03-16 17:12:00 +00:00
if ( $this -> get_scope () == 'host' ) {
$return [ 'PDF_fields' ] = array ( 'uid' => _ ( 'Host name' ));
}
else {
$return [ 'PDF_fields' ] = array ( 'uid' => _ ( 'User name' ));
}
$return [ 'PDF_fields' ] = array_merge ( $return [ 'PDF_fields' ], array (
2010-04-05 12:38:23 +00:00
'uidNumber' => _ ( 'UID number' ),
'gidNumber' => _ ( 'GID number' ),
'primaryGroup' => _ ( 'Primary group' ),
'additionalGroups' => _ ( 'Additional groups' ),
'homeDirectory' => _ ( 'Home directory' ),
'loginShell' => _ ( 'Login shell' ),
'userPassword' => _ ( 'Password' )
2013-03-16 17:12:00 +00:00
));
2012-04-09 13:20:24 +00:00
if ( self :: areGroupOfNamesActive ()) {
2013-03-24 10:03:35 +00:00
$return [ 'PDF_fields' ][ 'gon' ] = _ ( 'Groups of names' );
2011-10-06 20:03:45 +00:00
}
2004-09-08 14:41:57 +00:00
// help Entries
2004-10-02 18:45:11 +00:00
$return [ 'help' ] = array (
2013-08-18 12:24:53 +00:00
'autoAdd' => array (
" Headline " => _ ( " Automatically add this extension " ),
" Text " => _ ( " This will enable the extension automatically if this profile is loaded. " )
),
2013-03-24 18:39:08 +00:00
'userNameSuggestion' => array (
" Headline " => _ ( " User name suggestion " ),
" Text " => _ ( " LAM will suggest a user name based on e.g. first and last name. Here you can specify the suggestion. %sn% will be replaced by the last name. @givenname@ will be replaced by the first character of first name. Only attributes of tab Personal may be used. " )
. '<br>' . _ ( 'Common examples are "@givenname@%sn%" or "%givenname%.%sn%".' )
),
2013-03-24 10:03:35 +00:00
'hiddenOptions' => array (
" Headline " => _ ( " Hidden options " ),
" Text " => _ ( " The selected options will not be managed inside LAM. You can use this to reduce the number of displayed input fields. " )
),
2008-03-15 19:12:19 +00:00
'primaryGroupAsSecondary' => array (
'Headline' => _ ( 'Set primary group as memberUid' ),
'Text' => _ ( 'Usually, users are not added to groups as memberUid if they have this group as primary group. If your application ignores primary groups then you can select this option to override this behaviour.' )
),
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' ),
2009-02-01 16:24:37 +00:00
'Text' => _ ( 'These are the minimum and maximum numbers to use for machine IDs when creating new accounts for hosts. The range should be different from that of users. New host accounts will always get the highest number in use plus one.' )
2004-10-30 16:46:06 +00:00
),
'pwdHash' => array (
" Headline " => _ ( " Password hash type " ),
2012-08-26 17:54:31 +00:00
" Text " => _ ( " LAM supports CRYPT, CRYPT-SHA512, 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. " )
2016-01-02 12:16:14 +00:00
. ' ' . _ ( 'K5KEY is only needed if you use Kerberos with smbk5pwd.' )
2004-10-30 16:46:06 +00:00
),
'uidNumber' => array (
2012-02-04 15:56:31 +00:00
" Headline " => _ ( " UID number " ), 'attr' => 'uidNumber' ,
2004-10-30 16:46:06 +00:00
" 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 (
2017-05-10 17:23:28 +00:00
" Headline " => _ ( " Home directory " ),
2005-06-02 20:30:18 +00:00
" Text " => _ ( " Please enter the path to the user's home directory. " )
),
2017-05-10 17:23:28 +00:00
'homeDirectory' => 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. " )
),
2007-07-09 19:03:19 +00:00
'createhomedir' => array (
" Headline " => _ ( " Home directory " ),
" Text " => _ ( " This will create the user's home directory on the specified server. " )
),
2014-01-14 18:08:13 +00:00
'deleteSudoers' => array (
" Headline " => _ ( " Delete sudo rights " ),
" Text " => _ ( " Deletes the user from all existing sudo rights. " )
),
2012-09-07 16:35:54 +00:00
'uidCheckSuffix' => array (
" Headline " => _ ( " Suffix for UID/user name check " ),
" Text " => _ ( " LAM checks if the entered user name and UID are unique. Here you can enter the LDAP suffix that is used to search for duplicates. By default the account type suffix is used. You only need to change this if you use multiple server profiles with different OUs but need unique user names or UIDs. " )
),
2013-02-05 19:10:04 +00:00
'loginShells' => array (
" Headline " => _ ( " Login shells " ),
" Text " => _ ( " This is the list of valid login shells. " )
),
2013-02-17 13:19:50 +00:00
'uidGenerator' => array (
" Headline " => _ ( " UID generator " ),
2015-06-07 06:34:24 +00:00
" Text " => _ ( " LAM will automatically suggest UID/GID numbers. You can either use a fixed range of numbers or an LDAP entry with object class \" sambaUnixIdPool \" or \" msSFU30DomainInfo \" . " )
2016-03-28 09:06:04 +00:00
. ' ' . _ ( 'Magic number will set a fixed value that must match your server configuration.' )
2013-02-17 13:19:50 +00:00
),
'sambaIDPoolDN' => array (
" Headline " => _ ( " Samba ID pool DN " ),
" Text " => _ ( " Please enter the DN of the LDAP entry with object class \" sambaUnixIdPool \" . " )
),
2015-06-07 06:34:24 +00:00
'windowsIDPoolDN' => array (
" Headline " => _ ( " Windows domain info DN " ),
" Text " => _ ( " Please enter the DN of the LDAP entry with object class \" msSFU30DomainInfo \" . " )
),
2016-03-28 09:06:04 +00:00
'magicNumber' => array (
" Headline " => _ ( " Magic number " ),
" Text " => _ ( " Please enter the magic number you configured on server side. " )
),
2016-05-09 18:10:14 +00:00
'noObjectClass' => array (
" Headline " => _ ( " Do not add object class " ),
" Text " => _ ( " This will not add the posixAccount object class to the account. " )
2018-11-17 19:40:09 +00:00
),
'excludeFromGroupSync' => array (
" Headline " => _ ( 'Exclude from group sync' ),
" Text " => _ ( 'Enter one group per line that should be ignored when syncing groups.' )
2016-05-09 18:10:14 +00:00
),
2019-03-06 17:09:22 +00:00
'groupDn' => array (
" Headline " => _ ( 'Group DN' ),
" Text " => _ ( 'Enter the base DN of your groups here. This is only required if you want to display memberships on the self service page.' )
),
2004-10-30 16:46:06 +00:00
'user' => array (
'uid' => array (
2012-02-04 15:56:31 +00:00
" Headline " => _ ( " User name " ), 'attr' => 'uid' ,
2012-03-10 19:43:57 +00:00
" Text " => _ ( " User name of the user who should be created. Valid characters are: a-z,A-Z,0-9, @.-_. If user name is already used user 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 " ),
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 (
2012-02-04 15:56:31 +00:00
" Headline " => _ ( " Primary group " ), 'attr' => 'gidNumber' ,
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
),
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. " )
),
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. " )
),
2004-10-30 16:46:06 +00:00
'loginShell' => array (
" Headline " => _ ( " Login shell " ),
2013-02-05 19:10:04 +00:00
" Text " => _ ( " To disable login use /bin/false. " )
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 (
2012-02-04 15:56:31 +00:00
" Headline " => _ ( " Common name " ), 'attr' => 'cn' ,
2005-06-19 09:38:44 +00:00
" Text " => _ ( " This is the natural name of the user. If empty, the first and last name or user name is used. " )
2015-03-01 16:48:25 +00:00
),
'useOldPwd' => array (
" Headline " => _ ( 'Password change with old password' ),
" Text " => _ ( 'Sends the old password together with the new password when the user sets a new password.' )
2004-10-30 16:46:06 +00:00
)
),
'host' => array (
'uid' => array (
2012-02-04 15:56:31 +00:00
" Headline " => _ ( " Host name " ), 'attr' => 'uid' ,
2009-11-24 16:03:07 +00:00
" Text " => _ ( " Host name of the host which should be created. Valid characters are: a-z,A-Z,0-9, .-_ $ . 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 (
2012-02-04 15:56:31 +00:00
" Headline " => _ ( " Primary group " ), 'attr' => 'gidNumber' ,
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. " )
2007-01-03 16:29:25 +00:00
),
'cn' => array (
2012-02-04 15:56:31 +00:00
" Headline " => _ ( " Common name " ), 'attr' => 'cn' ,
2007-01-03 16:29:25 +00:00
" Text " => _ ( " This is the natural name of the host. If empty, the 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 ;
}
2007-11-03 14:17:19 +00:00
/**
* Initializes the module after it became part of an accountContainer
*
* @ param string $base the name of the accountContainer object ( $_SESSION [ $base ])
*/
2004-06-08 18:54:37 +00:00
function init ( $base ) {
2017-05-10 17:23:28 +00:00
// make optional if needed
$modules = $_SESSION [ $base ] -> get_type () -> getModules ();
2018-03-03 16:44:28 +00:00
$typeId = $_SESSION [ $base ] -> get_type () -> getId ();
2017-05-10 17:23:28 +00:00
$this -> autoAddObjectClasses = ! $this -> isOptional ( $modules ) && ! $this -> skipObjectClass ();
2004-09-01 20:53:06 +00:00
// call parent init
parent :: init ( $base );
2005-10-08 14:35:30 +00:00
$this -> groups = array ();
$this -> groups_orig = array ();
2017-05-10 17:23:28 +00:00
// list of all group names
$groups = $this -> findGroups ( $modules );
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 ;
}
2011-10-06 20:03:45 +00:00
$this -> gonList = array ();
$this -> gonList_orig = array ();
2004-10-12 13:34:00 +00:00
}
2003-12-09 18:42:50 +00:00
2017-05-10 17:23:28 +00:00
/**
* { @ inheritDoc }
* @ see baseModule :: getManagedAttributes ()
*/
public function getManagedAttributes ( $typeId ) {
$attrs = parent :: getManagedAttributes ( $typeId );
$typeManager = new TypeManager ();
2017-05-13 09:07:54 +00:00
if ( ! $typeManager -> hasConfig ()) {
return $attrs ;
}
2017-05-10 17:23:28 +00:00
$modules = $typeManager -> getConfiguredType ( $typeId ) -> getModules ();
if ( $this -> manageCn ( $modules )) {
$attrs [] = 'cn' ;
}
$attrs [] = $this -> getHomedirAttrName ( $modules );
$attrs [] = $this -> getPasswordAttrName ( $modules );
return $attrs ;
}
2006-09-03 12:41:22 +00:00
/**
* This functions is used to check if all settings for this module have been made .
*
* @ return boolean true , if settings are complete
2004-02-09 18:11:01 +00:00
*/
function module_complete () {
2016-05-09 18:10:14 +00:00
if ( ! $this -> skipObjectClass () && ( ! isset ( $this -> attributes [ 'objectClass' ]) || ! in_array ( 'posixAccount' , $this -> attributes [ 'objectClass' ]))) {
2013-08-18 12:24:53 +00:00
// no checks if object class is not set
return true ;
}
2019-03-05 16:59:33 +00:00
if ( ! isset ( $this -> attributes [ 'uid' ][ 0 ]) || ( $this -> attributes [ 'uid' ][ 0 ] == '' )) {
return false ;
}
if ( ! isset ( $this -> attributes [ 'uidNumber' ][ 0 ]) || ( $this -> attributes [ 'uidNumber' ][ 0 ] == '' )) {
return false ;
}
if ( ! isset ( $this -> attributes [ 'gidNumber' ][ 0 ]) || ( $this -> attributes [ 'gidNumber' ][ 0 ] == '' )) {
return false ;
}
if ( ! isset ( $this -> attributes [ 'loginShell' ][ 0 ]) || ( $this -> attributes [ 'loginShell' ][ 0 ] == '' )) {
return false ;
}
2004-02-09 18:11:01 +00:00
return true ;
2004-10-12 13:34:00 +00:00
}
2006-05-13 08:55:31 +00:00
/**
* This function loads all needed LDAP attributes .
2006-08-13 12:58:19 +00:00
*
2006-05-13 08:55:31 +00:00
* @ param array $attr list of attributes
*/
2003-12-09 18:42:50 +00:00
function load_attributes ( $attr ) {
2005-04-16 13:41:17 +00:00
parent :: load_attributes ( $attr );
2014-02-26 20:02:50 +00:00
$typeSettings = $_SESSION [ 'config' ] -> get_typeSettings ();
2005-09-04 16:53:43 +00:00
// get additional group memberships
2014-02-26 20:02:50 +00:00
if ( ! isset ( $attr [ 'uid' ][ 0 ])) {
return ;
}
$groupFilter = '(&(objectClass=posixGroup)(memberUid=' . $attr [ 'uid' ][ 0 ] . '))' ;
if ( ! empty ( $typeSettings [ 'filter_group' ])) {
$typeFilter = $typeSettings [ 'filter_group' ];
if ( strpos ( $typeFilter , '(' ) !== 0 ) {
$typeFilter = '(' . $typeFilter . ')' ;
}
$groupFilter = '(&' . $groupFilter . $typeFilter . ')' ;
}
$groupList = searchLDAPByFilter ( $groupFilter , array ( 'cn' ), array ( 'group' ));
2010-11-23 21:12:13 +00:00
for ( $i = 0 ; $i < sizeof ( $groupList ); $i ++ ) {
$this -> groups [] = $groupList [ $i ][ 'cn' ][ 0 ];
2003-12-09 18:42:50 +00:00
}
2005-10-08 14:35:30 +00:00
$this -> groups_orig = $this -> groups ;
2011-10-06 20:03:45 +00:00
// get additional group of names memberships
2012-04-09 13:20:24 +00:00
if ( self :: areGroupOfNamesActive ()) {
2014-02-26 20:02:50 +00:00
$types = array ( 'gon' , 'group' );
$gonList = array ();
foreach ( $types as $type ) {
2020-02-21 18:30:28 +00:00
$gonFilter = '(|(&(objectClass=groupOfNames)(member=' . ldap_escape ( $this -> getAccountContainer () -> dn_orig ) . '))(&(objectClass=groupOfMembers)(member=' . $this -> getAccountContainer () -> dn_orig . '))(&(objectClass=groupOfUniqueNames)(uniqueMember=' . $this -> getAccountContainer () -> dn_orig . ')))' ;
2014-02-26 20:02:50 +00:00
if ( ! empty ( $typeSettings [ 'filter_' . $type ])) {
$typeFilter = $typeSettings [ 'filter_' . $type ];
if ( strpos ( $typeFilter , '(' ) !== 0 ) {
$typeFilter = '(' . $typeFilter . ')' ;
}
$gonFilter = '(&' . $gonFilter . $typeFilter . ')' ;
}
$gonListPart = searchLDAPByFilter ( $gonFilter , array ( 'dn' ), array ( $type ));
$gonList = array_merge ( $gonList , $gonListPart );
}
2011-10-06 20:03:45 +00:00
$this -> gonList_orig = array ();
for ( $i = 0 ; $i < sizeof ( $gonList ); $i ++ ) {
$this -> gonList_orig [] = $gonList [ $i ][ 'dn' ];
}
2013-04-11 17:40:34 +00:00
$this -> gonList_orig = array_values ( array_unique ( $this -> gonList_orig ));
2011-10-06 20:03:45 +00:00
$this -> gonList = $this -> gonList_orig ;
}
2004-10-12 13:34:00 +00:00
}
2003-12-09 18:42:50 +00:00
2006-09-03 12:41:22 +00:00
/**
* Returns a list of modifications which have to be made to the LDAP account .
*
* @ return array list of modifications
* < br > This function returns an array with 3 entries :
* < br > array ( DN1 ( 'add' => array ( $attr ), 'remove' => array ( $attr ), 'modify' => array ( $attr )), DN2 .... )
* < br > 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 )
* < br > " add " are attributes which have to be added to LDAP entry
* < br > " remove " are attributes which have to be removed from LDAP entry
* < br > " modify " are attributes which have to been modified in LDAP entry
2011-02-26 13:14:10 +00:00
* < br > " info " are values with informational value ( e . g . to be used later by pre / postModify actions )
2003-12-09 18:42:50 +00:00
*/
function save_attributes () {
2016-05-09 18:10:14 +00:00
if ( ! $this -> skipObjectClass () && ( ! in_array ( 'posixAccount' , $this -> attributes [ 'objectClass' ]) && ! in_array ( 'posixAccount' , $this -> orig [ 'objectClass' ]))) {
2013-08-18 12:24:53 +00:00
// skip saving if the extension was not added/modified
return array ();
}
2017-05-10 17:23:28 +00:00
$modules = $this -> getAccountContainer () -> get_type () -> getModules ();
2015-02-11 16:57:38 +00:00
// get default changes
$return = $this -> getAccountContainer () -> save_module_attributes ( $this -> attributes , $this -> orig );
2011-02-26 13:14:10 +00:00
// add information about clear text password and password status change
2011-10-15 09:46:13 +00:00
$return [ $this -> getAccountContainer () -> dn_orig ][ 'info' ][ 'userPasswordClearText' ][ 0 ] = $this -> clearTextPassword ;
2017-05-10 17:23:28 +00:00
$pwdAttrName = $this -> getPasswordAttrName ( $modules );
2013-08-18 14:19:37 +00:00
if ( isset ( $this -> orig [ $pwdAttrName ][ 0 ]) && isset ( $this -> attributes [ $pwdAttrName ][ 0 ])) {
if (( pwd_is_enabled ( $this -> orig [ $pwdAttrName ][ 0 ]) && pwd_is_enabled ( $this -> attributes [ $pwdAttrName ][ 0 ]))
|| ( ! pwd_is_enabled ( $this -> orig [ $pwdAttrName ][ 0 ]) && ! pwd_is_enabled ( $this -> attributes [ $pwdAttrName ][ 0 ]))) {
2015-08-09 07:22:01 +00:00
$return [ $this -> getAccountContainer () -> dn_orig ][ 'info' ][ 'userPasswordStatusChange' ][ 0 ] = 'unchanged' ;
2011-02-26 13:14:10 +00:00
}
2013-08-18 14:19:37 +00:00
elseif ( pwd_is_enabled ( $this -> orig [ $pwdAttrName ][ 0 ])) {
2011-10-15 09:46:13 +00:00
$return [ $this -> getAccountContainer () -> dn_orig ][ 'info' ][ 'userPasswordStatusChange' ][ 0 ] = 'locked' ;
2011-02-26 13:14:10 +00:00
}
else {
2011-10-15 09:46:13 +00:00
$return [ $this -> getAccountContainer () -> dn_orig ][ 'info' ][ 'userPasswordStatusChange' ][ 0 ] = 'unlocked' ;
2011-02-26 13:14:10 +00:00
}
}
2016-05-09 18:10:14 +00:00
if ( $this -> skipObjectClass () || in_array ( 'posixAccount' , $this -> attributes [ 'objectClass' ])) {
2013-08-18 12:24:53 +00:00
// Remove primary group from additional groups
if ( ! isset ( $this -> moduleSettings [ 'posixAccount_primaryGroupAsSecondary' ][ 0 ])
|| ( $this -> moduleSettings [ 'posixAccount_primaryGroupAsSecondary' ][ 0 ] != 'true' )) {
for ( $i = 0 ; $i < count ( $this -> groups ); $i ++ ) {
if ( $this -> groups [ $i ] == $this -> getGroupName ( $this -> attributes [ 'gidNumber' ][ 0 ])) {
unset ( $this -> groups [ $i ]);
}
2009-11-26 10:48:05 +00:00
}
2008-03-15 19:12:19 +00:00
}
2013-08-18 12:24:53 +00:00
else {
// add user as memberuid in primary group
if ( ! in_array ( $this -> getGroupName ( $this -> attributes [ 'gidNumber' ][ 0 ]), $this -> groups )) {
$this -> groups [] = $this -> getGroupName ( $this -> attributes [ 'gidNumber' ][ 0 ]);
}
}
2015-08-09 07:22:01 +00:00
2013-08-18 12:24:53 +00:00
// Set additional group memberships
if ( isset ( $this -> orig [ 'uid' ][ 0 ]) && ( $this -> orig [ 'uid' ][ 0 ] != '' ) && ( $this -> attributes [ 'uid' ][ 0 ] != $this -> orig [ 'uid' ][ 0 ])) {
// find affected groups
$groupList = searchLDAPByAttribute ( 'memberUid' , $this -> orig [ 'uid' ][ 0 ], 'posixGroup' , array ( 'dn' ), array ( 'group' ));
for ( $i = 0 ; $i < sizeof ( $groupList ); $i ++ ) {
// replace old user name with new one
$return [ $groupList [ $i ][ 'dn' ]][ 'remove' ][ 'memberUid' ][] = $this -> orig [ 'uid' ][ 0 ];
$return [ $groupList [ $i ][ 'dn' ]][ 'add' ][ 'memberUid' ][] = $this -> attributes [ 'uid' ][ 0 ];
}
}
else {
// update groups.
$add = array_delete ( $this -> groups_orig , $this -> groups );
$remove = array_delete ( $this -> groups , $this -> groups_orig );
$groupList = searchLDAPByAttribute ( 'cn' , '*' , 'posixGroup' , array ( 'cn' , 'dn' ), array ( 'group' ));
2019-07-31 19:19:42 +00:00
$cn2dn = array ();
2013-08-18 12:24:53 +00:00
for ( $i = 0 ; $i < sizeof ( $groupList ); $i ++ ) {
$cn2dn [ $groupList [ $i ][ 'cn' ][ 0 ]] = $groupList [ $i ][ 'dn' ];
}
for ( $i = 0 ; $i < sizeof ( $add ); $i ++ ) {
if ( isset ( $cn2dn [ $add [ $i ]])) {
$return [ $cn2dn [ $add [ $i ]]][ 'add' ][ 'memberUid' ][] = $this -> attributes [ 'uid' ][ 0 ];
}
}
for ( $i = 0 ; $i < sizeof ( $remove ); $i ++ ) {
if ( isset ( $cn2dn [ $remove [ $i ]])) {
$return [ $cn2dn [ $remove [ $i ]]][ 'remove' ][ 'memberUid' ][] = $this -> attributes [ 'uid' ][ 0 ];
}
}
2008-03-15 19:12:19 +00:00
}
2004-10-12 13:34:00 +00:00
}
2013-08-18 12:24:53 +00:00
elseif ( in_array ( 'posixAccount' , $this -> orig [ 'objectClass' ]) && ! empty ( $this -> orig [ 'uid' ][ 0 ])) {
// Unix extension was removed, clean group memberships
2010-11-23 21:12:13 +00:00
$groupList = searchLDAPByAttribute ( 'memberUid' , $this -> orig [ 'uid' ][ 0 ], 'posixGroup' , array ( 'dn' ), array ( 'group' ));
for ( $i = 0 ; $i < sizeof ( $groupList ); $i ++ ) {
2013-08-18 12:24:53 +00:00
// remove user name
2010-11-23 21:12:13 +00:00
$return [ $groupList [ $i ][ 'dn' ]][ 'remove' ][ 'memberUid' ][] = $this -> orig [ 'uid' ][ 0 ];
2003-12-12 00:51:23 +00:00
}
2004-10-12 13:34:00 +00:00
}
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
2007-02-25 13:55:26 +00:00
/**
2012-07-15 12:05:47 +00:00
* Runs the postmodify actions .
2015-08-09 07:22:01 +00:00
*
2009-05-21 16:33:50 +00:00
* @ see baseModule :: postModifyActions ()
2007-02-25 13:55:26 +00:00
*
2009-05-21 16:33:50 +00:00
* @ param boolean $newAccount
* @ param array $attributes LDAP attributes of this entry
2012-01-04 19:08:19 +00:00
* @ return array array which contains status messages . Each entry is an array containing the status message parameters .
2007-02-25 13:55:26 +00:00
*/
2009-05-21 16:33:50 +00:00
public function postModifyActions ( $newAccount , $attributes ) {
2012-01-04 19:08:19 +00:00
$messages = array ();
2017-08-15 08:29:30 +00:00
$accountContainer = $this -> getAccountContainer ();
if ( $accountContainer == null ) {
return $messages ;
}
$modules = $accountContainer -> get_type () -> getModules ();
2018-07-07 12:05:39 +00:00
// set exop password
$messages = array_merge ( $messages , $this -> setExopPassword ( $this -> moduleSettings ));
2011-05-07 08:59:50 +00:00
// create home directories if needed
2018-07-07 12:05:39 +00:00
$homeDirAttr = $this -> getHomedirAttrName ( $modules );
2019-10-22 19:22:32 +00:00
$lamdaemonServerList = $_SESSION [ 'config' ] -> getConfiguredScriptServers ();
2011-05-07 08:59:50 +00:00
if ( sizeof ( $this -> lamdaemonServers ) > 0 ) {
2019-10-23 19:14:54 +00:00
foreach ( $lamdaemonServerList as $lamdaemonServer ) {
if ( ! in_array ( $lamdaemonServer -> getServer (), $this -> lamdaemonServers )) {
2011-05-07 08:59:50 +00:00
continue ;
2007-02-25 13:55:26 +00:00
}
2017-09-17 07:40:05 +00:00
$remote = new \LAM\REMOTE\Remote ();
2019-10-23 19:14:54 +00:00
$remote -> connect ( $lamdaemonServer );
2017-09-17 07:40:05 +00:00
$result = $remote -> execute (
2011-05-07 08:59:50 +00:00
implode (
2012-08-23 16:28:13 +00:00
self :: $SPLIT_DELIMITER ,
2011-05-07 08:59:50 +00:00
array (
$this -> attributes [ 'uid' ][ 0 ],
" home " ,
" add " ,
2019-10-26 15:28:24 +00:00
$lamdaemonServer -> getHomeDirPrefix () . $this -> attributes [ $homeDirAttr ][ 0 ],
2011-05-07 08:59:50 +00:00
" 0 " . $_SESSION [ 'config' ] -> get_scriptRights (),
$this -> attributes [ 'uidNumber' ][ 0 ],
$this -> attributes [ 'gidNumber' ][ 0 ])
2017-09-17 07:40:05 +00:00
));
$remote -> disconnect ();
2011-05-07 08:59:50 +00:00
// lamdaemon results
2017-09-17 07:40:05 +00:00
if ( ! empty ( $result )) {
$singleresult = explode ( " , " , $result );
2011-05-07 08:59:50 +00:00
if (( $singleresult [ 0 ] == 'ERROR' ) || ( $singleresult [ 0 ] == 'INFO' ) || ( $singleresult [ 0 ] == 'WARN' )) {
2012-01-04 19:08:19 +00:00
$messages [] = $singleresult ;
2011-05-07 08:59:50 +00:00
}
else {
2012-01-04 19:08:19 +00:00
$messages [] = array ( 'ERROR' , $result [ 0 ]);
2011-05-07 08:59:50 +00:00
}
2007-02-25 13:55:26 +00:00
}
}
}
2014-05-22 19:26:10 +00:00
// move home directory if needed
2017-05-10 17:23:28 +00:00
if ( ! empty ( $this -> orig [ $homeDirAttr ][ 0 ]) && ! empty ( $this -> attributes [ $homeDirAttr ][ 0 ])
&& ( $this -> orig [ $homeDirAttr ][ 0 ] != $this -> attributes [ $homeDirAttr ][ 0 ])) {
2019-10-23 19:14:54 +00:00
foreach ( $lamdaemonServerList as $lamdaemonServer ) {
2017-09-17 07:40:05 +00:00
$remote = new \LAM\REMOTE\Remote ();
2019-10-23 19:14:54 +00:00
$remote -> connect ( $lamdaemonServer );
2017-09-17 07:40:05 +00:00
$result = $remote -> execute (
2014-05-22 19:26:10 +00:00
implode (
self :: $SPLIT_DELIMITER ,
array (
$this -> attributes [ 'uid' ][ 0 ],
" home " ,
" move " ,
2019-10-26 15:28:24 +00:00
$lamdaemonServer -> getHomeDirPrefix () . $this -> orig [ $homeDirAttr ][ 0 ],
2014-05-22 19:26:10 +00:00
$this -> attributes [ 'uidNumber' ][ 0 ],
2019-10-26 15:28:24 +00:00
$lamdaemonServer -> getHomeDirPrefix () . $this -> attributes [ $homeDirAttr ][ 0 ])
2017-09-17 07:40:05 +00:00
));
$remote -> disconnect ();
2014-05-22 19:26:10 +00:00
// lamdaemon results
2017-09-17 07:40:05 +00:00
if ( ! empty ( $result )) {
$singleresult = explode ( " , " , $result );
2014-05-22 19:26:10 +00:00
if (( $singleresult [ 0 ] == 'ERROR' ) || ( $singleresult [ 0 ] == 'INFO' ) || ( $singleresult [ 0 ] == 'WARN' )) {
$messages [] = $singleresult ;
}
}
}
}
2015-05-22 17:22:01 +00:00
// set new group on homedirectory
2017-05-10 17:23:28 +00:00
if ( ! empty ( $this -> orig [ $homeDirAttr ][ 0 ]) && ! empty ( $this -> attributes [ $homeDirAttr ][ 0 ])
2015-05-22 17:22:01 +00:00
&& ( $this -> orig [ 'gidNumber' ][ 0 ] != $this -> attributes [ 'gidNumber' ][ 0 ])) {
2019-10-23 19:14:54 +00:00
foreach ( $lamdaemonServerList as $lamdaemonServer ) {
2017-09-17 07:40:05 +00:00
$remote = new \LAM\REMOTE\Remote ();
2019-10-23 19:14:54 +00:00
$remote -> connect ( $lamdaemonServer );
2017-09-17 07:40:05 +00:00
$result = $remote -> execute (
2015-05-22 17:22:01 +00:00
implode (
self :: $SPLIT_DELIMITER ,
array (
$this -> attributes [ 'uid' ][ 0 ],
" home " ,
" chgrp " ,
2019-10-26 15:28:24 +00:00
$lamdaemonServer -> getHomeDirPrefix () . $this -> attributes [ $homeDirAttr ][ 0 ],
2015-05-22 17:22:01 +00:00
$this -> attributes [ 'uidNumber' ][ 0 ],
$this -> attributes [ 'gidNumber' ][ 0 ])
2017-09-17 07:40:05 +00:00
));
$remote -> disconnect ();
2015-05-22 17:22:01 +00:00
// lamdaemon results
2017-09-17 07:40:05 +00:00
if ( ! empty ( $result )) {
$singleresult = explode ( " , " , $result );
2015-05-22 17:22:01 +00:00
if (( $singleresult [ 0 ] == 'ERROR' ) || ( $singleresult [ 0 ] == 'INFO' ) || ( $singleresult [ 0 ] == 'WARN' )) {
$messages [] = $singleresult ;
}
}
}
}
2011-10-06 20:03:45 +00:00
// set group of names
2012-04-09 13:20:24 +00:00
if ( self :: areGroupOfNamesActive ()) {
2011-10-06 20:03:45 +00:00
$gons = $this -> findGroupOfNames ();
$toAdd = array_values ( array_diff ( $this -> gonList , $this -> gonList_orig ));
$toRem = array_values ( array_diff ( $this -> gonList_orig , $this -> gonList ));
2012-05-20 13:16:13 +00:00
// update groups if DN changed
2019-09-26 16:40:16 +00:00
if ( isset ( $accountContainer -> dn_orig ) && ( strtolower ( $accountContainer -> dn_orig ) != strtolower ( $accountContainer -> finalDN ))) {
2015-06-07 16:52:16 +00:00
// update owner/member/uniqueMember attributes
2017-03-22 19:17:52 +00:00
$searchAttrs = array ( 'member' , 'uniquemember' , 'owner' );
2015-06-07 16:52:16 +00:00
foreach ( $searchAttrs as $searchAttr ) {
2017-08-15 08:29:30 +00:00
$ownerGroups = searchLDAPByAttribute ( $searchAttr , $accountContainer -> dn_orig , null , array ( 'dn' , $searchAttr ), array ( 'gon' , 'group' ));
2015-06-07 16:52:16 +00:00
for ( $i = 0 ; $i < sizeof ( $ownerGroups ); $i ++ ) {
$found = false ;
$newOwners = $ownerGroups [ $i ][ $searchAttr ];
for ( $o = 0 ; $o < sizeof ( $newOwners ); $o ++ ) {
2017-08-15 08:29:30 +00:00
if ( $newOwners [ $o ] == $accountContainer -> dn_orig ) {
$newOwners [ $o ] = $accountContainer -> finalDN ;
2015-06-07 16:52:16 +00:00
$found = true ;
break ;
}
2013-05-24 18:30:30 +00:00
}
2015-06-07 16:52:16 +00:00
if ( $found ) {
2019-09-26 16:40:16 +00:00
$attributesToModify = array ( $searchAttr => $newOwners );
$success = @ ldap_mod_replace ( $_SESSION [ 'ldap' ] -> server (), $ownerGroups [ $i ][ 'dn' ], $attributesToModify );
2015-06-07 16:52:16 +00:00
if ( ! $success ) {
2018-12-23 09:32:56 +00:00
$ldapError = getDefaultLDAPErrorString ( $_SESSION [ 'ldap' ] -> server ());
2019-07-31 19:19:42 +00:00
logNewMessage ( LOG_ERR , 'Unable to modify attributes of DN: ' . $ownerGroups [ $i ][ 'dn' ] . ' (' . $ldapError . ').' );
2019-09-26 16:40:16 +00:00
logNewMessage ( LOG_DEBUG , print_r ( $attributesToModify , true ));
2018-12-23 09:32:56 +00:00
$messages [] = array ( 'ERROR' , sprintf ( _ ( 'Was unable to modify attributes of DN: %s.' ), $ownerGroups [ $i ][ 'dn' ]), $ldapError );
2015-06-07 16:52:16 +00:00
}
2013-05-24 18:30:30 +00:00
}
}
}
2012-05-20 13:16:13 +00:00
}
// add groups
2011-10-06 20:03:45 +00:00
for ( $i = 0 ; $i < sizeof ( $toAdd ); $i ++ ) {
if ( isset ( $gons [ $toAdd [ $i ]])) {
$attrName = 'member' ;
2019-03-05 16:59:33 +00:00
if ( in_array_ignore_case ( 'groupOfUniqueNames' , $gons [ $toAdd [ $i ]][ 'objectclass' ])) {
2011-10-06 20:03:45 +00:00
$attrName = 'uniqueMember' ;
}
2017-08-15 08:29:30 +00:00
$success = @ ldap_mod_add ( $_SESSION [ 'ldap' ] -> server (), $toAdd [ $i ], array ( $attrName => array ( $accountContainer -> finalDN )));
2011-10-06 20:03:45 +00:00
if ( ! $success ) {
2019-07-31 19:19:42 +00:00
logNewMessage ( LOG_ERR , 'Unable to add user ' . $accountContainer -> finalDN . ' to group: ' . $toAdd [ $i ] . ' (' . ldap_error ( $_SESSION [ 'ldap' ] -> server ()) . ').' );
2013-10-16 17:37:17 +00:00
$messages [] = array ( 'ERROR' , sprintf ( _ ( 'Was unable to add attributes to DN: %s.' ), $toAdd [ $i ]), getDefaultLDAPErrorString ( $_SESSION [ 'ldap' ] -> server ()));
2011-10-06 20:03:45 +00:00
}
2013-04-11 17:40:34 +00:00
else {
2019-07-31 19:19:42 +00:00
logNewMessage ( LOG_NOTICE , 'Added user ' . $accountContainer -> finalDN . ' to group: ' . $toAdd [ $i ]);
2013-04-11 17:40:34 +00:00
}
2011-10-06 20:03:45 +00:00
}
}
2012-05-20 13:16:13 +00:00
// remove groups
2011-10-06 20:03:45 +00:00
for ( $i = 0 ; $i < sizeof ( $toRem ); $i ++ ) {
if ( isset ( $gons [ $toRem [ $i ]])) {
$attrName = 'member' ;
2019-03-05 16:59:33 +00:00
if ( in_array_ignore_case ( 'groupOfUniqueNames' , $gons [ $toRem [ $i ]][ 'objectclass' ])) {
2011-10-06 20:03:45 +00:00
$attrName = 'uniqueMember' ;
}
2017-08-15 08:29:30 +00:00
$success = @ ldap_mod_del ( $_SESSION [ 'ldap' ] -> server (), $toRem [ $i ], array ( $attrName => array ( $accountContainer -> dn_orig )));
2011-10-06 20:03:45 +00:00
if ( ! $success ) {
2019-07-31 19:19:42 +00:00
logNewMessage ( LOG_ERR , 'Unable to delete user ' . $accountContainer -> finalDN . ' from group: ' . $toRem [ $i ] . ' (' . ldap_error ( $_SESSION [ 'ldap' ] -> server ()) . ').' );
2013-10-16 17:37:17 +00:00
$messages [] = array ( 'ERROR' , sprintf ( _ ( 'Was unable to remove attributes from DN: %s.' ), $toRem [ $i ]), getDefaultLDAPErrorString ( $_SESSION [ 'ldap' ] -> server ()));
2011-10-06 20:03:45 +00:00
}
2013-04-11 17:40:34 +00:00
else {
2019-07-31 19:19:42 +00:00
logNewMessage ( LOG_NOTICE , 'Removed user ' . $accountContainer -> finalDN . ' from group: ' . $toRem [ $i ]);
2013-04-11 17:40:34 +00:00
}
2011-10-06 20:03:45 +00:00
}
}
}
2012-01-04 19:08:19 +00:00
return $messages ;
2007-02-25 13:55:26 +00:00
}
2015-08-09 07:22:01 +00:00
2018-07-07 12:05:39 +00:00
/**
* Sets the password via ldap_exop if configured .
*
* @ param array $settings settings
* @ return array error message parameters if any
*/
private function setExopPassword ( $settings ) {
if ( ! empty ( $this -> clearTextPassword ) && ! empty ( $settings [ 'posixAccount_pwdHash' ][ 0 ])
&& ( $settings [ 'posixAccount_pwdHash' ][ 0 ] === 'LDAP_EXOP' )) {
$success = ldap_exop_passwd ( $_SESSION [ 'ldap' ] -> server (), $this -> getAccountContainer () -> finalDN , null , $this -> clearTextPassword );
if ( ! $success ) {
2019-03-06 15:52:10 +00:00
return array ( array ( 'ERROR' , _ ( 'Unable to set password' ), getExtendedLDAPErrorMessage ( $_SESSION [ 'ldap' ] -> server ())));
2018-07-07 12:05:39 +00:00
}
}
return array ();
}
2006-08-13 12:58:19 +00:00
/**
* Additional LDAP operations on delete .
*
* @ return List of LDAP operations , same as for save_attributes ()
*/
function delete_attributes () {
2003-12-30 15:36:30 +00:00
$return = array ();
// remove memberUids if set
2010-11-23 21:12:13 +00:00
$groups = searchLDAPByAttribute ( 'memberUid' , $this -> attributes [ 'uid' ][ 0 ], 'posixGroup' , array ( 'dn' ), array ( 'group' ));
for ( $i = 0 ; $i < sizeof ( $groups ); $i ++ ) {
$return [ $groups [ $i ][ 'dn' ]][ 'remove' ][ 'memberUid' ][] = $this -> attributes [ 'uid' ][ 0 ];
2004-10-12 13:34:00 +00:00
}
2017-12-31 12:48:16 +00:00
// stop here if referential integrity overlay is active
$config = $this -> getAccountContainer () -> get_type () -> getTypeManager () -> getConfig ();
if ( $config -> isReferentialIntegrityOverlayActive ()) {
return $return ;
}
2013-01-09 20:11:14 +00:00
// remove from group of names
$dn = $this -> getAccountContainer () -> dn_orig ;
2017-03-22 19:17:52 +00:00
$gons = searchLDAPByFilter ( '(|(member=' . $dn . ')(uniqueMember=' . $dn . '))' , array ( 'member' , 'uniqueMember' ), array ( 'group' , 'gon' ));
2013-01-09 20:11:14 +00:00
for ( $i = 0 ; $i < sizeof ( $gons ); $i ++ ) {
if ( isset ( $gons [ $i ][ 'member' ])) {
$return [ $gons [ $i ][ 'dn' ]][ 'remove' ][ 'member' ][] = $dn ;
}
elseif ( isset ( $gons [ $i ][ 'uniquemember' ])) {
$return [ $gons [ $i ][ 'dn' ]][ 'remove' ][ 'uniqueMember' ][] = $dn ;
}
}
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
2007-02-25 13:55:26 +00:00
/**
* Allows the module to run commands before the LDAP entry is deleted .
2015-08-09 07:22:01 +00:00
*
2010-11-26 20:16:14 +00:00
* @ return array Array which contains status messages . Each entry is an array containing the status message parameters .
2007-02-25 13:55:26 +00:00
*/
function preDeleteActions () {
2010-11-26 20:16:14 +00:00
$return = array ();
2014-01-14 18:08:13 +00:00
// delete home directory
if ( isset ( $_POST [ 'deletehomedir' ]) && ( $_POST [ 'deletehomedir' ] == 'on' )) {
2017-05-10 17:23:28 +00:00
$modules = $this -> getAccountContainer () -> get_type () -> getModules ();
$homeDirAttr = $this -> getHomedirAttrName ( $modules );
2007-02-25 13:55:26 +00:00
// get list of lamdaemon servers
2019-10-22 19:22:32 +00:00
$lamdaemonServers = $_SESSION [ 'config' ] -> getConfiguredScriptServers ();
2007-02-25 13:55:26 +00:00
// try to delete directory on all servers
2019-10-22 19:22:32 +00:00
foreach ( $lamdaemonServers as $lamdaemonServer ) {
2017-09-17 07:40:05 +00:00
$remote = new \LAM\REMOTE\Remote ();
2017-12-13 11:31:26 +00:00
try {
2019-10-23 19:14:54 +00:00
$remote -> connect ( $lamdaemonServer );
2017-12-13 11:31:26 +00:00
$result = $remote -> execute (
implode (
self :: $SPLIT_DELIMITER ,
array (
$this -> attributes [ 'uid' ][ 0 ],
" home " ,
" rem " ,
2019-10-26 15:28:24 +00:00
$lamdaemonServer -> getHomeDirPrefix () . $this -> attributes [ $homeDirAttr ][ 0 ],
2017-12-13 11:31:26 +00:00
$this -> attributes [ 'uidNumber' ][ 0 ]
)
));
$remote -> disconnect ();
}
catch ( LAMException $e ) {
$return [] = array ( 'ERROR' , $e -> getTitle (), $e -> getMessage ());
}
2007-02-25 13:55:26 +00:00
// lamdaemon results
2017-09-17 07:40:05 +00:00
if ( ! empty ( $result )) {
$singleresult = explode ( " , " , $result );
if ( is_array ( $singleresult )) {
if (( $singleresult [ 0 ] == 'ERROR' ) || ( $singleresult [ 0 ] == 'WARN' ) || ( $singleresult [ 0 ] == 'INFO' )) {
$return [] = $singleresult ;
2007-02-25 13:55:26 +00:00
}
}
}
}
}
2014-01-14 18:08:13 +00:00
// delete sudo rights
if ( isset ( $_POST [ 'deleteSudoers' ]) && ( $_POST [ 'deleteSudoers' ] == 'on' )) {
$result = searchLDAPByAttribute ( 'sudoUser' , $this -> attributes [ 'uid' ][ 0 ], 'sudoRole' , array ( 'dn' ), array ( 'sudo' ));
foreach ( $result as $attrs ) {
$dn = $attrs [ 'dn' ];
$success = @ ldap_mod_del ( $_SESSION [ 'ldap' ] -> server (), $dn , array ( 'sudoUser' => array ( $this -> attributes [ 'uid' ][ 0 ])));
if ( ! $success ) {
$return [] = array ( 'ERROR' , getDefaultLDAPErrorString ( $_SESSION [ 'ldap' ] -> server ()));
}
}
}
2007-02-25 13:55:26 +00:00
return $return ;
}
2015-08-09 07:22:01 +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 .
*
* @ return array list of info / error messages
2003-12-30 15:36:30 +00:00
*/
2006-08-13 12:58:19 +00:00
function process_attributes () {
2016-11-19 18:20:44 +00:00
$keysToReplace = array ( 'cn' , 'gecos' , 'homeDirectory' );
$this -> getAccountContainer () -> replaceWildcardsInPOST ( $keysToReplace );
2017-05-10 17:23:28 +00:00
$modules = $this -> getAccountContainer () -> get_type () -> getModules ();
2018-03-03 16:44:28 +00:00
$typeId = $this -> getAccountContainer () -> get_type () -> getId ();
2006-05-18 08:50:51 +00:00
$errors = array ();
2013-08-18 12:24:53 +00:00
if ( isset ( $_POST [ 'addObjectClass' ])) {
if ( ! isset ( $this -> attributes [ 'objectClass' ])) {
$this -> attributes [ 'objectClass' ] = array ();
}
if ( ! in_array ( 'posixAccount' , $this -> attributes [ 'objectClass' ])) {
$this -> attributes [ 'objectClass' ][] = 'posixAccount' ;
}
return $errors ;
}
if ( isset ( $_POST [ 'remObjectClass' ])) {
$this -> attributes [ 'objectClass' ] = array_delete ( array ( 'posixAccount' ), $this -> attributes [ 'objectClass' ]);
2017-04-22 14:14:15 +00:00
$attrs = $this -> getManagedAttributes ( $this -> getAccountContainer () -> get_type () -> getId ());
2013-08-18 12:24:53 +00:00
foreach ( $attrs as $name ) {
if ( isset ( $this -> attributes [ $name ])) {
unset ( $this -> attributes [ $name ]);
}
}
return $errors ;
}
// skip processing if object class is not set
2017-05-10 17:23:28 +00:00
if ( $this -> isOptional ( $modules ) && ! $this -> skipObjectClass () && ( ! isset ( $this -> attributes [ 'objectClass' ]) || ! in_array ( 'posixAccount' , $this -> attributes [ 'objectClass' ]))) {
2013-08-18 12:24:53 +00:00
return $errors ;
}
2017-05-10 17:23:28 +00:00
$groups = $this -> findGroups ( $modules ); // list of all group names
2005-04-12 19:38:32 +00:00
if ( count ( $groups ) == 0 ) {
2009-11-26 10:48:05 +00:00
// abort if no groups were found
return array ();
2005-04-12 19:38:32 +00:00
}
2011-05-22 17:19:14 +00:00
if ( isset ( $_POST [ 'loginShell' ])) {
$this -> attributes [ 'loginShell' ][ 0 ] = $_POST [ 'loginShell' ];
}
2018-03-03 16:44:28 +00:00
if ( ! $this -> isBooleanConfigOptionSet ( 'posixAccount_' . $typeId . '_hidegecos' )) {
2019-10-22 19:22:32 +00:00
if ( isset ( $_POST [ 'gecos' ])) {
$this -> attributes [ 'gecos' ][ 0 ] = $_POST [ 'gecos' ];
}
2013-03-24 10:03:35 +00:00
}
2013-05-25 12:47:07 +00:00
if ( isset ( $this -> orig [ 'uid' ][ 0 ]) && ( $this -> orig [ 'uid' ][ 0 ] != '' ) && ( trim ( $_POST [ 'uid' ]) != $this -> attributes [ 'uid' ][ 0 ])) {
2006-08-16 17:42:35 +00:00
$errors [] = $this -> messages [ 'uid' ][ 0 ];
2009-11-26 10:48:05 +00:00
}
2010-07-23 11:08:57 +00:00
if ( isset ( $this -> orig [ 'gidNumber' ][ 0 ]) && ( $this -> orig [ 'gidNumber' ][ 0 ] != '' ) && ( $_POST [ 'gidNumber' ] != $this -> attributes [ 'gidNumber' ][ 0 ])) {
2006-08-15 16:32:33 +00:00
$errorMessage = $this -> messages [ 'gidNumber' ][ 2 ];
$errorMessage [] = array ( $this -> orig [ 'gidNumber' ][ 0 ], $this -> orig [ 'uidNumber' ][ 0 ], $_POST [ 'gidNumber' ]);
2006-08-16 17:42:35 +00:00
$errors [] = $errorMessage ;
2013-10-23 17:26:00 +00:00
if ( $this -> isBooleanConfigOptionSet ( 'posixAccount_primaryGroupAsSecondary' ) && ! empty ( $this -> attributes [ 'gidNumber' ][ 0 ])) {
// change primary group in $this->groups
$oldGroupName = $this -> getGroupName ( $this -> attributes [ 'gidNumber' ][ 0 ]);
$newGroupName = $this -> getGroupName ( $_POST [ 'gidNumber' ]);
if ( ! empty ( $oldGroupName ) && ! empty ( $newGroupName )) {
$this -> groups = array_delete ( array ( $oldGroupName ), $this -> groups );
$this -> groups [] = $newGroupName ;
}
}
2006-08-15 16:32:33 +00:00
}
2013-05-25 12:47:07 +00:00
if ( isset ( $this -> orig [ 'uidNumber' ][ 0 ]) && $this -> orig [ 'uidNumber' ][ 0 ] != '' && trim ( $_POST [ 'uidNumber' ]) != $this -> attributes [ 'uidNumber' ][ 0 ]) {
2006-08-15 16:32:33 +00:00
$errorMessage = $this -> messages [ 'uidNumber' ][ 5 ];
$errorMessage [] = array ( $this -> orig [ 'uidNumber' ][ 0 ], $_POST [ 'uidNumber' ]);
2006-08-16 17:42:35 +00:00
$errors [] = $errorMessage ;
2006-08-15 16:32:33 +00:00
}
2017-05-10 17:23:28 +00:00
$homedirAttrName = $this -> getHomedirAttrName ( $modules );
2013-08-18 14:19:37 +00:00
if ( isset ( $_POST [ 'homeDirectory' ]) && isset ( $this -> orig [ $homedirAttrName ][ 0 ]) && ( $this -> orig [ $homedirAttrName ][ 0 ] != '' ) && ( $_POST [ 'homeDirectory' ] != $this -> attributes [ $homedirAttrName ][ 0 ])) {
2006-08-15 16:32:33 +00:00
$errorMessage = $this -> messages [ 'homeDirectory' ][ 3 ];
2013-08-18 14:19:37 +00:00
$errorMessage [] = array ( $this -> orig [ $homedirAttrName ][ 0 ], $_POST [ 'homeDirectory' ]);
2006-08-16 17:42:35 +00:00
$errors [] = $errorMessage ;
2006-08-15 16:32:33 +00:00
}
2007-02-25 13:55:26 +00:00
// get list of DNS names or IPs
2019-10-22 19:22:32 +00:00
$lamdaemonServers = $_SESSION [ 'config' ] -> getConfiguredScriptServers ();
2011-05-07 08:59:50 +00:00
$this -> lamdaemonServers = array ();
for ( $h = 0 ; $h < sizeof ( $lamdaemonServers ); $h ++ ) {
if ( isset ( $_POST [ 'createhomedir_' . $h ]) && ( $_POST [ 'createhomedir_' . $h ] = 'on' )) {
2019-10-22 19:22:32 +00:00
$this -> lamdaemonServers [] = $lamdaemonServers [ $h ] -> getServer ();
2007-02-25 13:55:26 +00:00
}
}
2011-05-22 17:19:14 +00:00
if ( isset ( $_POST [ 'homeDirectory' ])) {
2013-08-18 14:19:37 +00:00
$this -> attributes [ $homedirAttrName ][ 0 ] = $_POST [ 'homeDirectory' ];
2011-05-22 17:19:14 +00:00
}
2004-10-16 19:51:36 +00:00
// Load attributes
2019-06-05 17:24:46 +00:00
if ( $this -> isPasswordManaged ()) {
if ( isset ( $_POST [ 'lockPassword' ])) {
$this -> lock ( $modules );
}
if ( isset ( $_POST [ 'unlockPassword' ])) {
$this -> unlock ( $modules );
}
if ( isset ( $_POST [ 'removePassword' ])) {
unset ( $this -> attributes [ $this -> getPasswordAttrName ( $modules )]);
}
2006-09-03 12:41:22 +00:00
}
2017-05-10 17:23:28 +00:00
if ( $this -> manageCn ( $modules )) {
2014-04-21 19:21:47 +00:00
$this -> processMultiValueInputTextField ( 'cn' , $errors , 'cn' );
2005-06-19 09:38:44 +00:00
}
2013-05-25 12:47:07 +00:00
$this -> attributes [ 'uidNumber' ][ 0 ] = trim ( $_POST [ 'uidNumber' ]);
2009-11-26 10:48:05 +00:00
$this -> attributes [ 'gidNumber' ][ 0 ] = $_POST [ 'gidNumber' ];
2011-10-01 19:23:09 +00:00
if ( $this -> get_scope () == 'user' ) {
if (( $this -> attributes [ 'uid' ][ 0 ] != $_POST [ 'uid' ]) && ! get_preg ( $_POST [ 'uid' ], '!upper' )) {
$errors [] = $this -> messages [ 'uid' ][ 1 ];
}
2013-08-18 14:19:37 +00:00
if ( ! get_preg ( $this -> attributes [ $homedirAttrName ][ 0 ], 'homeDirectory' )) {
2011-10-01 19:23:09 +00:00
$errors [] = $this -> messages [ 'homeDirectory' ][ 0 ];
}
}
2013-05-25 12:47:07 +00:00
$this -> attributes [ 'uid' ][ 0 ] = trim ( $_POST [ 'uid' ]);
2004-10-16 19:51:36 +00:00
// Check if UID is valid. If none value was entered, the next useable value will be inserted
// load min and may uidNumber
2007-10-04 16:45:05 +00:00
if ( $this -> get_scope () == 'user' ) {
2018-03-03 16:44:28 +00:00
$minID = intval ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_minUID' ][ 0 ]);
$maxID = intval ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_maxUID' ][ 0 ]);
2004-10-16 19:51:36 +00:00
}
2007-10-04 16:45:05 +00:00
if ( $this -> get_scope () == 'host' ) {
2018-03-03 16:44:28 +00:00
$minID = intval ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_minMachine' ][ 0 ]);
$maxID = intval ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_maxMachine' ][ 0 ]);
2004-10-16 19:51:36 +00:00
}
2018-03-03 16:44:28 +00:00
$uids = $this -> getUIDs ( $typeId );
2004-10-16 19:51:36 +00:00
if ( $this -> attributes [ 'uidNumber' ][ 0 ] == '' ) {
// No id-number given
2011-01-09 14:45:12 +00:00
if ( ! isset ( $this -> orig [ 'uidNumber' ][ 0 ]) || ( $this -> orig [ 'uidNumber' ][ 0 ] == '' )) {
2004-10-16 19:51:36 +00:00
// new account -> we have to find a free id-number
2018-03-03 16:44:28 +00:00
$newUID = $this -> getNextUIDs ( 1 , $errors , $typeId );
2005-03-25 14:21:07 +00:00
if ( is_array ( $newUID )) {
$this -> attributes [ 'uidNumber' ][ 0 ] = $newUID [ 0 ];
}
else {
2006-08-16 17:42:35 +00:00
$errors [] = $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 {
2008-07-17 19:25:30 +00:00
// check manual ID
if ( $this -> getAccountContainer () -> isNewAccount || ! isset ( $this -> orig [ 'uidNumber' ][ 0 ]) || ( $this -> orig [ 'uidNumber' ][ 0 ] != $this -> attributes [ 'uidNumber' ][ 0 ])) {
// check range
2018-03-03 16:44:28 +00:00
if (( $this -> get_scope () == 'user' ) && ( ! isset ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidGeneratorUsers' ]) || ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidGeneratorUsers' ][ 0 ] == 'range' ))) {
2013-04-10 19:04:43 +00:00
if ( ! is_numeric ( $this -> attributes [ 'uidNumber' ][ 0 ]) || ( $this -> attributes [ 'uidNumber' ][ 0 ] < $minID ) || ( $this -> attributes [ 'uidNumber' ][ 0 ] > $maxID )) {
$errors [] = array ( 'ERROR' , _ ( 'ID-Number' ), sprintf ( _ ( 'Please enter a value between %s and %s!' ), $minID , $maxID ));
}
}
2018-03-03 16:44:28 +00:00
if (( $this -> get_scope () == 'host' ) && ( ! isset ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidGeneratorHosts' ]) || ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidGeneratorHosts' ][ 0 ] == 'range' ))) {
2013-04-10 19:04:43 +00:00
if ( ! is_numeric ( $this -> attributes [ 'uidNumber' ][ 0 ]) || ( $this -> attributes [ 'uidNumber' ][ 0 ] < $minID ) || ( $this -> attributes [ 'uidNumber' ][ 0 ] > $maxID )) {
$errors [] = array ( 'ERROR' , _ ( 'ID-Number' ), sprintf ( _ ( 'Please enter a value between %s and %s!' ), $minID , $maxID ));
}
}
2010-11-23 21:12:13 +00:00
// id-number is in use and account is a new account
2018-03-04 08:37:32 +00:00
if (( in_array ( $this -> attributes [ 'uidNumber' ][ 0 ], $uids )) && ! isset ( $this -> orig [ 'uidNumber' ][ 0 ])) $errors [] = $this -> messages [ 'uidNumber' ][ 3 ];
2010-11-23 21:12:13 +00:00
// id-number is in use, account is existing account and id-number is not used by itself
2017-03-24 17:23:52 +00:00
if (( in_array ( $this -> attributes [ 'uidNumber' ][ 0 ], $uids )) && isset ( $this -> orig [ 'uidNumber' ][ 0 ]) && ( $this -> orig [ 'uidNumber' ][ 0 ] != $this -> attributes [ 'uidNumber' ][ 0 ]) ) {
2010-11-23 21:12:13 +00:00
$errors [] = $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
}
2006-09-03 12:41:22 +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
2018-03-03 16:44:28 +00:00
if ( $this -> userNameExists ( $this -> attributes [ 'uid' ][ 0 ], $typeId ) && isset ( $this -> orig [ 'uid' ][ 0 ]) && ( $this -> orig [ 'uid' ][ 0 ] != '' )) {
2010-01-31 18:37:28 +00:00
$this -> attributes [ 'uid' ][ 0 ] = $this -> orig [ 'uid' ][ 0 ];
}
else {
// Change uid to a new uid until a free uid is found
2018-03-03 16:44:28 +00:00
while ( $this -> userNameExists ( $this -> attributes [ 'uid' ][ 0 ], $typeId )) {
2018-08-15 08:43:10 +00:00
$this -> attributes [ 'uid' ][ 0 ] = $this -> getNextUserName ( $this -> attributes [ 'uid' ][ 0 ], array_keys ( $this -> getAccountContainer () -> getAccountModules ()));
2004-10-12 13:34:00 +00:00
}
2006-09-03 12:41:22 +00:00
}
2010-03-14 15:42:49 +00:00
// Show warning if LAM has changed username
2013-05-25 12:47:07 +00:00
if ( $this -> attributes [ 'uid' ][ 0 ] != trim ( $_POST [ 'uid' ])) {
2018-04-11 16:40:44 +00:00
$userNames = $this -> getUserNames ( $typeId );
if ( $this -> get_scope () == 'user' ) {
$error = $this -> messages [ 'uid' ][ 5 ];
$error [] = array ( htmlspecialchars ( $userNames [ trim ( $_POST [ 'uid' ])]));
$errors [] = $error ;
}
if ( $this -> get_scope () == 'host' ) {
$error = $this -> messages [ 'uid' ][ 6 ];
$error [] = array ( htmlspecialchars ( $userNames [ trim ( $_POST [ 'uid' ])]));
$errors [] = $error ;
}
2004-10-12 13:34:00 +00:00
}
2018-12-23 10:11:23 +00:00
if (( $this -> get_scope () == 'user' ) && ! get_preg ( $this -> attributes [ 'uid' ][ 0 ], 'username' )) {
2011-05-22 17:19:14 +00:00
// Check if Username contains only valid characters
$errors [] = $this -> messages [ 'uid' ][ 2 ];
}
2018-12-23 10:11:23 +00:00
if ( $this -> get_scope () == 'host' ) {
2011-05-22 17:19:14 +00:00
// Check if Hostname contains only valid characters
2018-12-23 10:11:23 +00:00
if ( ! get_preg ( $this -> attributes [ 'uid' ][ 0 ], 'hostname' )) {
$errors [] = $this -> messages [ 'uid' ][ 4 ];
}
2013-08-18 14:19:37 +00:00
if ( ! isset ( $this -> attributes [ $homedirAttrName ][ 0 ])) {
$this -> attributes [ $homedirAttrName ][ 0 ] = '/dev/null' ;
2011-05-22 17:19:14 +00:00
}
if ( ! isset ( $this -> attributes [ 'loginShell' ][ 0 ])) {
$this -> attributes [ 'loginShell' ][ 0 ] = '/bin/false' ;
}
}
2013-08-18 14:19:37 +00:00
$attributeList = array ( $homedirAttrName );
2018-03-03 16:44:28 +00:00
if ( ! $this -> isBooleanConfigOptionSet ( 'posixAccount_' . $typeId . '_hidegecos' )) {
2013-03-24 10:03:35 +00:00
$attributeList [] = 'gecos' ;
}
2006-05-21 19:45:57 +00:00
for ( $i = 0 ; $i < sizeof ( $attributeList ); $i ++ ) {
if ( isset ( $this -> attributes [ $attributeList [ $i ]][ 0 ])) {
$value = $this -> attributes [ $attributeList [ $i ]][ 0 ];
$replacedValue = $this -> checkASCII ( $value );
if ( $value != $replacedValue ) {
$this -> attributes [ $attributeList [ $i ]][ 0 ] = $replacedValue ;
2006-08-16 17:42:35 +00:00
$errors [] = array ( 'WARN' , $attributeList [ $i ], _ ( 'Changed value because only ASCII characters are allowed.' ));
2006-05-21 19:45:57 +00:00
}
}
}
2015-02-11 16:57:38 +00:00
if ( $this -> get_scope () == 'user' ) {
// set SASL password for new and renamed users
if ( ! empty ( $this -> attributes [ 'uid' ][ 0 ]) && ! empty ( $this -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ])
&& ( $this -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ] === 'SASL' )
&& ( $this -> getAccountContainer () -> isNewAccount || ( $this -> attributes [ 'uid' ][ 0 ] != $this -> orig [ 'uid' ][ 0 ]))) {
2017-05-10 17:23:28 +00:00
$this -> attributes [ $this -> getPasswordAttrName ( $modules )][ 0 ] = '{SASL}' . $this -> attributes [ 'uid' ][ 0 ];
2015-02-11 16:57:38 +00:00
}
2016-01-02 12:16:14 +00:00
// set K5KEY password for new users
if ( ! empty ( $this -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ]) && ( $this -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ] === 'K5KEY' )) {
2017-05-10 17:23:28 +00:00
$this -> attributes [ $this -> getPasswordAttrName ( $modules )][ 0 ] = pwd_hash ( 'x' , true , $this -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ]);
2016-01-02 12:16:14 +00:00
}
2015-02-11 16:57:38 +00:00
}
2005-09-01 15:20:15 +00:00
// Return error-messages
2006-05-18 08:50:51 +00:00
return $errors ;
2004-10-12 13:34:00 +00:00
}
2003-12-30 15:36:30 +00:00
2006-05-21 19:45:57 +00:00
/**
* Checks if an attribute contains only ASCII charaters and replaces invalid characters .
*
* @ param string $attribute attribute value
* @ return string attribute value with replaced non - ASCII characters
*/
function checkASCII ( $attribute ) {
2013-06-17 18:38:42 +00:00
if ( $attribute == null ) {
return '' ;
2006-05-21 19:45:57 +00:00
}
2013-06-17 18:38:42 +00:00
// replace special characters
$attribute = str_replace ( array_keys ( $this -> umlautReplacements ), array_values ( $this -> umlautReplacements ), $attribute );
2006-05-21 19:45:57 +00:00
// remove remaining UTF-8 characters
for ( $c = 0 ; $c < strlen ( $attribute ); $c ++ ) {
if ( ord ( $attribute [ $c ]) > 127 ) {
2008-09-16 17:11:44 +00:00
$attribute = str_replace ( $attribute [ $c ], " " , $attribute );
$c -- ;
2006-05-21 19:45:57 +00:00
}
}
return $attribute ;
}
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 .
*
* @ return array list of info / error messages
2003-12-09 18:42:50 +00:00
*/
2006-08-13 12:58:19 +00:00
function process_group () {
2018-03-03 16:44:28 +00:00
$typeId = $this -> getAccountContainer () -> get_type () -> getId ();
2011-10-06 20:03:45 +00:00
// Unix groups
2018-03-03 16:44:28 +00:00
if ( $this -> isBooleanConfigOptionSet ( 'posixGroup_autoSyncGon' )) {
2015-05-31 08:46:44 +00:00
$this -> syncGonToGroups ();
}
2018-03-03 16:44:28 +00:00
elseif ( ! $this -> isBooleanConfigOptionSet ( 'posixAccount_' . $typeId . '_hideposixGroups' )) {
2013-03-24 10:03:35 +00:00
if ( isset ( $_POST [ 'addgroups' ]) && isset ( $_POST [ 'addgroups_button' ])) { // Add groups to list
// add new group
$this -> groups = @ array_merge ( $this -> groups , $_POST [ 'addgroups' ]);
}
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
}
2011-10-06 20:03:45 +00:00
// group of names
2018-03-03 16:44:28 +00:00
if ( self :: areGroupOfNamesActive () && ! $this -> isBooleanConfigOptionSet ( 'posixAccount_' . $typeId . '_hidegon' )) {
2011-10-06 20:03:45 +00:00
if ( isset ( $_POST [ 'addgons' ]) && isset ( $_POST [ 'addgons_button' ])) { // Add groups to list
// add new group
$this -> gonList = @ array_merge ( $this -> gonList , $_POST [ 'addgons' ]);
}
elseif ( isset ( $_POST [ 'removegons' ]) && isset ( $_POST [ 'removegons_button' ])) { // remove groups from list
$this -> gonList = array_delete ( $_POST [ 'removegons' ], $this -> gonList );
}
}
2018-05-28 16:43:15 +00:00
// sync Unix to GoN
if ( isset ( $_POST [ 'form_subpage_posixAccount_group_syncU2GON' ])) {
$this -> manualSyncUnixToGon ( $typeId );
}
// sync GoN to Unix
if ( isset ( $_POST [ 'form_subpage_posixAccount_group_syncGON2U' ])) {
2018-06-15 17:03:51 +00:00
$this -> manualSyncGonToUnix ( $this -> getAccountContainer () -> get_type ());
}
// sync Windows to Unix
if ( isset ( $_POST [ 'form_subpage_posixAccount_group_syncWin2U' ])) {
$this -> manualSyncWindowsToUnix ( $this -> getAccountContainer () -> get_type ());
2018-05-28 16:43:15 +00:00
}
2006-08-16 17:42:35 +00:00
return array ();
2004-10-12 13:34:00 +00:00
}
2003-12-09 18:42:50 +00:00
2018-05-28 16:43:15 +00:00
/**
* Syncs the Unix groups to group of names .
*
* @ param string $typeId type ID
*/
private function manualSyncUnixToGon ( $typeId ) {
$allGons = $this -> findGroupOfNames ();
$namesToIgnore = array ();
if ( ! empty ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_syncGroupsExclusions' ])) {
$namesToIgnore = $this -> moduleSettings [ 'posixAccount_' . $typeId . '_syncGroupsExclusions' ];
array_map ( 'trim' , $namesToIgnore );
}
// remove all groups that are not in Unix
if ( isset ( $_POST [ 'syncDeleteGroups' ]) && ( $_POST [ 'syncDeleteGroups' ] == 'on' )) {
$toDelete = array ();
foreach ( $this -> gonList as $currentGon ) {
$gonName = $this -> getGonName ( $currentGon , $allGons );
if ( in_array ( $gonName , $namesToIgnore ) || in_array ( $gonName , $this -> groups )) {
continue ;
}
$toDelete [] = $currentGon ;
}
$this -> gonList = array_delete ( $toDelete , $this -> gonList );
}
// add groups that are not yet in groups of names
foreach ( $this -> groups as $currentName ) {
if ( in_array ( $currentName , $namesToIgnore )) {
continue ;
}
$found = false ;
foreach ( $this -> gonList as $currentGon ) {
if ( $currentName == $this -> getGonName ( $currentGon , $allGons )) {
$found = true ;
break ;
}
}
if ( $found ) {
continue ;
}
foreach ( $allGons as $currentGon ) {
if ( $currentName == $this -> getGonName ( $currentGon [ 'dn' ], $allGons )) {
$this -> gonList [] = $currentGon [ 'dn' ];
break ;
}
}
}
}
/**
* Syncs the group of names to Unix groups .
*
2018-06-15 17:03:51 +00:00
* @ param ConfiguredType $type type
2018-05-28 16:43:15 +00:00
*/
2018-06-15 17:03:51 +00:00
private function manualSyncGonToUnix ( $type ) {
2018-05-28 16:43:15 +00:00
$allGons = $this -> findGroupOfNames ();
2018-06-15 17:03:51 +00:00
$modules = $type -> getModules ();
2018-05-28 16:43:15 +00:00
$allGroups = $this -> findGroups ( $modules );
foreach ( $allGroups as $index => $groupData ) {
$allGroups [ $index ] = $groupData [ 1 ];
}
$namesToIgnore = array ();
2018-06-15 17:03:51 +00:00
if ( ! empty ( $this -> moduleSettings [ 'posixAccount_' . $type -> getId () . '_syncGroupsExclusions' ])) {
$namesToIgnore = $this -> moduleSettings [ 'posixAccount_' . $type -> getId () . '_syncGroupsExclusions' ];
2018-05-28 16:43:15 +00:00
array_map ( 'trim' , $namesToIgnore );
}
// remove all groups that are not in group of names
if ( isset ( $_POST [ 'syncDeleteGroups' ]) && ( $_POST [ 'syncDeleteGroups' ] == 'on' )) {
$toDelete = array ();
foreach ( $this -> groups as $currentName ) {
if ( in_array ( $currentName , $namesToIgnore )) {
continue ;
}
$found = false ;
foreach ( $this -> gonList as $currentGon ) {
$gonName = $this -> getGonName ( $currentGon , $allGons );
if ( $gonName == $currentName ) {
$found = true ;
break ;
}
}
if ( ! $found ) {
$toDelete [] = $currentName ;
}
}
$this -> groups = array_delete ( $toDelete , $this -> groups );
}
// add groups that are not yet in Unix groups
foreach ( $this -> gonList as $currentGon ) {
$gonName = $this -> getGonName ( $currentGon , $allGons );
if ( in_array ( $gonName , $namesToIgnore )) {
continue ;
}
if ( ! in_array ( $gonName , $this -> groups ) && in_array ( $gonName , $allGroups )) {
$this -> groups [] = $gonName ;
}
}
}
2018-06-15 17:03:51 +00:00
/**
* Syncs the Windows to Unix groups .
*
* @ param ConfiguredType $type type
*/
private function manualSyncWindowsToUnix ( $type ) {
$windowsGroups = $this -> getAccountContainer () -> getAccountModule ( 'windowsUser' ) -> getGroupList ();
$allWindowsGroups = searchLDAPByAttribute ( 'gidNumber' , '*' , null , array ( 'cn' ), array ( 'group' ));
$allGroups = $this -> findGroups ( $modules );
foreach ( $allGroups as $index => $groupData ) {
$allGroups [ $index ] = $groupData [ 1 ];
}
$namesToIgnore = array ();
if ( ! empty ( $this -> moduleSettings [ 'posixAccount_' . $type -> getId () . '_syncGroupsExclusions' ])) {
$namesToIgnore = $this -> moduleSettings [ 'posixAccount_' . $type -> getId () . '_syncGroupsExclusions' ];
array_map ( 'trim' , $namesToIgnore );
}
// remove all groups that are not in Windows groups
if ( isset ( $_POST [ 'syncDeleteGroups' ]) && ( $_POST [ 'syncDeleteGroups' ] == 'on' )) {
$toDelete = array ();
foreach ( $this -> groups as $currentName ) {
if ( in_array ( $currentName , $namesToIgnore )) {
continue ;
}
$found = false ;
foreach ( $windowsGroups as $currentWindowsGroup ) {
$windowsGroupName = $this -> getWindowsGroupName ( $allWindowsGroups , $currentWindowsGroup );
if ( $windowsGroupName == $currentName ) {
$found = true ;
break ;
}
}
if ( ! $found ) {
$toDelete [] = $currentName ;
}
}
$this -> groups = array_delete ( $toDelete , $this -> groups );
}
// add groups that are not yet in Unix groups
foreach ( $windowsGroups as $currentWindowsGroup ) {
$windowsGroupName = $this -> getWindowsGroupName ( $allWindowsGroups , $currentWindowsGroup );
if ( in_array ( $windowsGroupName , $namesToIgnore )) {
continue ;
}
if ( ! in_array ( $windowsGroupName , $this -> groups ) && in_array ( $windowsGroupName , $allGroups )) {
$this -> groups [] = $windowsGroupName ;
}
}
}
2018-05-28 16:43:15 +00:00
/**
* Returns the cn of the given group of names .
*
* @ param string $dn DN of group of names
* @ param $allGons list of all group of names
* @ return string cn value
*/
2018-11-17 19:40:09 +00:00
public function getGonName ( $dn , & $allGons ) {
2018-05-28 16:43:15 +00:00
if ( ! empty ( $allGons [ $dn ][ 'cn' ][ 0 ])) {
return $allGons [ $dn ][ 'cn' ][ 0 ];
}
return extractRDNValue ( $dn );
}
2018-06-15 17:03:51 +00:00
/**
* Returns the Windows group name .
*
* @ param array $allWindowsGroups LDAP data of all Windows groups
* @ param string $dn DN
*/
private function getWindowsGroupName ( & $allWindowsGroups , $dn ) {
foreach ( $allWindowsGroups as $data ) {
if ( $data [ 'dn' ] == $dn ) {
return $data [ 'cn' ][ 0 ];
}
}
return null ;
}
2011-05-07 08:59:50 +00:00
/**
* Processes user input of the homedir check page .
* It checks if all input values are correct and updates the associated LDAP attributes .
*
* @ return array list of info / error messages
*/
function process_homedir () {
$return = array ();
// get list of lamdaemon servers
2019-10-22 19:22:32 +00:00
$lamdaemonServers = $_SESSION [ 'config' ] -> getConfiguredScriptServers ();
2017-05-10 17:23:28 +00:00
$modules = $this -> getAccountContainer () -> get_type () -> getModules ();
$homeDirAttr = $this -> getHomedirAttrName ( $modules );
2011-05-07 08:59:50 +00:00
for ( $i = 0 ; $i < sizeof ( $lamdaemonServers ); $i ++ ) {
if ( isset ( $_POST [ 'form_subpage_' . get_class ( $this ) . '_homedir_create_' . $i ])) {
2017-09-17 07:40:05 +00:00
$remote = new \LAM\REMOTE\Remote ();
2019-10-23 19:14:54 +00:00
$remote -> connect ( $lamdaemonServers [ $i ]);
2017-09-17 07:40:05 +00:00
$result = $remote -> execute (
2011-05-07 08:59:50 +00:00
implode (
2012-08-23 16:28:13 +00:00
self :: $SPLIT_DELIMITER ,
2011-05-07 08:59:50 +00:00
array (
$this -> attributes [ 'uid' ][ 0 ],
" home " ,
" add " ,
2019-10-26 15:28:24 +00:00
$lamdaemonServers [ $i ] -> getHomeDirPrefix () . $this -> attributes [ $homeDirAttr ][ 0 ],
2011-05-07 08:59:50 +00:00
" 0 " . $_SESSION [ 'config' ] -> get_scriptRights (),
$this -> attributes [ 'uidNumber' ][ 0 ],
$this -> attributes [ 'gidNumber' ][ 0 ])
2017-09-17 07:40:05 +00:00
));
$remote -> disconnect ();
2011-05-07 08:59:50 +00:00
// lamdaemon results
2017-09-17 07:40:05 +00:00
if ( ! empty ( $result )) {
$singleresult = explode ( " , " , $result );
if ( is_array ( $singleresult )) {
if (( $singleresult [ 0 ] == 'ERROR' ) || ( $singleresult [ 0 ] == 'WARN' ) || ( $singleresult [ 0 ] == 'INFO' )) {
$return [] = $singleresult ;
2011-05-07 08:59:50 +00:00
}
}
}
}
elseif ( isset ( $_POST [ 'form_subpage_' . get_class ( $this ) . '_homedir_delete_' . $i ])) {
2017-09-17 07:40:05 +00:00
$remote = new \LAM\REMOTE\Remote ();
2019-10-23 19:14:54 +00:00
$remote -> connect ( $lamdaemonServers [ $i ]);
2017-09-17 07:40:05 +00:00
$result = $remote -> execute (
2011-05-07 08:59:50 +00:00
implode (
2012-08-23 16:28:13 +00:00
self :: $SPLIT_DELIMITER ,
2011-05-07 08:59:50 +00:00
array (
$this -> attributes [ 'uid' ][ 0 ],
" home " ,
" rem " ,
2019-10-26 15:28:24 +00:00
$lamdaemonServers [ $i ] -> getHomeDirPrefix () . $this -> attributes [ $homeDirAttr ][ 0 ],
2011-05-07 08:59:50 +00:00
$this -> attributes [ 'uidNumber' ][ 0 ]
)
2017-09-17 07:40:05 +00:00
));
$remote -> disconnect ();
2011-05-07 08:59:50 +00:00
// lamdaemon results
2017-09-17 07:40:05 +00:00
if ( ! empty ( $result )) {
$singleresult = explode ( " , " , $result );
if ( is_array ( $singleresult )) {
if (( $singleresult [ 0 ] == 'ERROR' ) || ( $singleresult [ 0 ] == 'WARN' ) || ( $singleresult [ 0 ] == 'INFO' )) {
$return [] = $singleresult ;
2011-05-07 08:59:50 +00:00
}
}
}
}
}
return $return ;
}
2007-11-03 14:17:19 +00:00
/**
* Returns the HTML meta data for the main account page .
2015-08-09 07:22:01 +00:00
*
2010-09-26 11:12:59 +00:00
* @ return htmlElement HTML meta data
2007-11-03 14:17:19 +00:00
*/
2006-08-13 12:58:19 +00:00
function display_html_attributes () {
2019-09-23 15:59:15 +00:00
$return = new htmlResponsiveRow ();
2018-06-20 06:27:10 +00:00
$this -> checkForInvalidConfiguration ( $return );
2017-05-10 17:23:28 +00:00
$modules = $this -> getAccountContainer () -> get_type () -> getModules ();
2018-03-03 16:44:28 +00:00
$typeId = $this -> getAccountContainer () -> get_type () -> getId ();
2017-05-10 17:23:28 +00:00
if ( ! $this -> isOptional ( $modules ) || $this -> skipObjectClass () || ( isset ( $this -> attributes [ 'objectClass' ]) && in_array ( 'posixAccount' , $this -> attributes [ 'objectClass' ]))) {
$homeDirAttr = $this -> getHomedirAttrName ( $modules );
$groupList = $this -> findGroups ( $modules ); // list of all group names
2013-08-18 12:24:53 +00:00
$groups = array ();
for ( $i = 0 ; $i < sizeof ( $groupList ); $i ++ ) {
$groups [ $groupList [ $i ][ 1 ]] = $groupList [ $i ][ 0 ];
}
if ( count ( $groups ) == 0 ) {
2019-09-23 15:59:15 +00:00
$return -> add ( new htmlStatusMessage ( " ERROR " , _ ( 'No Unix groups found in LDAP! Please create one first.' )), 12 );
2013-08-18 12:24:53 +00:00
return $return ;
}
$shelllist = $this -> getShells (); // list of all valid shells
2015-08-09 07:22:01 +00:00
2013-08-18 12:24:53 +00:00
// set default values
2013-12-28 10:48:31 +00:00
if ( empty ( $this -> attributes [ 'uid' ][ 0 ])) {
if ( $this -> getAccountContainer () -> getAccountModule ( 'inetOrgPerson' ) != null ) {
// fill default value for user ID with first/last name
$attrs = $this -> getAccountContainer () -> getAccountModule ( 'inetOrgPerson' ) -> getAttributes ();
2018-03-03 16:44:28 +00:00
$this -> attributes [ 'uid' ][ 0 ] = $this -> getUserNameSuggestion ( $attrs , $typeId );
2018-04-11 16:40:44 +00:00
$firstSuggestion = $this -> attributes [ 'uid' ][ 0 ];
2018-03-03 16:44:28 +00:00
if ( ! empty ( $this -> attributes [ 'uid' ][ 0 ]) && $this -> userNameExists ( $this -> attributes [ 'uid' ][ 0 ], $typeId )) {
while ( $this -> userNameExists ( $this -> attributes [ 'uid' ][ 0 ], $typeId )) {
2018-08-15 08:43:10 +00:00
$this -> attributes [ 'uid' ][ 0 ] = $this -> getNextUserName ( $this -> attributes [ 'uid' ][ 0 ], array_keys ( $this -> getAccountContainer () -> getAccountModules ()));
2014-02-06 17:34:56 +00:00
}
2018-04-11 16:40:44 +00:00
$users = $this -> getUserNames ( $typeId );
$msg = new htmlStatusMessage ( $this -> messages [ 'uid' ][ 5 ][ 0 ],
$this -> messages [ 'uid' ][ 5 ][ 1 ], $this -> messages [ 'uid' ][ 5 ][ 2 ],
array ( htmlspecialchars ( $users [ $firstSuggestion ])));
2019-09-23 15:59:15 +00:00
$return -> add ( $msg , 12 );
2014-02-06 17:34:56 +00:00
}
2013-12-28 10:48:31 +00:00
}
elseif ( $this -> getAccountContainer () -> getAccountModule ( 'windowsUser' ) != null ) {
// fill default value for user ID with AD user name
$attrs = $this -> getAccountContainer () -> getAccountModule ( 'windowsUser' ) -> getAttributes ();
if ( ! empty ( $attrs [ 'userPrincipalName' ][ 0 ])) {
$parts = explode ( '@' , $attrs [ 'userPrincipalName' ][ 0 ]);
$this -> attributes [ 'uid' ][ 0 ] = $parts [ 0 ];
}
}
2013-08-18 12:24:53 +00:00
}
2017-05-10 17:23:28 +00:00
if ( $this -> manageCn ( $modules ) && ( ! isset ( $this -> attributes [ 'cn' ][ 0 ]) || ( $this -> attributes [ 'cn' ][ 0 ] == '' ))) {
2013-08-18 12:24:53 +00:00
// set a default value for common name
2016-01-09 19:20:28 +00:00
if (( $this -> get_scope () == 'host' ) && isset ( $_POST [ 'uid' ])) {
if ( substr ( $_POST [ 'uid' ], - 1 , 1 ) == '$' ) {
$this -> attributes [ 'cn' ][ 0 ] = substr ( $_POST [ 'uid' ], 0 , strlen ( $_POST [ 'uid' ]) - 1 );
}
else {
$this -> attributes [ 'cn' ][ 0 ] = $_POST [ 'uid' ];
}
2010-03-14 15:42:49 +00:00
}
2013-08-18 12:24:53 +00:00
elseif ( $this -> getAccountContainer () -> getAccountModule ( 'inetOrgPerson' ) != null ) {
$attrs = $this -> getAccountContainer () -> getAccountModule ( 'inetOrgPerson' ) -> getAttributes ();
if ( $attrs [ 'givenName' ][ 0 ]) {
$this -> attributes [ 'cn' ][ 0 ] = $attrs [ 'givenName' ][ 0 ] . " " . $attrs [ 'sn' ][ 0 ];
}
elseif ( $attrs [ 'sn' ][ 0 ]) {
$this -> attributes [ 'cn' ][ 0 ] = $attrs [ 'sn' ][ 0 ];
}
else {
$this -> attributes [ 'cn' ][ 0 ] = $_POST [ 'uid' ];
}
2010-03-14 15:42:49 +00:00
}
2013-08-18 12:24:53 +00:00
elseif ( isset ( $_POST [ 'uid' ])) {
2010-03-14 15:42:49 +00:00
$this -> attributes [ 'cn' ][ 0 ] = $_POST [ 'uid' ];
}
}
2015-08-09 07:22:01 +00:00
2013-08-18 12:24:53 +00:00
$userName = '' ;
2019-09-23 15:59:15 +00:00
if ( isset ( $this -> attributes [ 'uid' ][ 0 ])) {
$userName = $this -> attributes [ 'uid' ][ 0 ];
}
2013-08-18 12:24:53 +00:00
$uidLabel = _ ( " User name " );
if ( $this -> get_scope () == 'host' ) {
$uidLabel = _ ( " Host name " );
}
2019-09-23 15:59:15 +00:00
$uidInput = new htmlResponsiveInputField ( $uidLabel , 'uid' , $userName , 'uid' );
2013-08-18 12:24:53 +00:00
$uidInput -> setRequired ( true );
$uidInput -> setFieldMaxLength ( 100 );
2019-09-23 15:59:15 +00:00
$return -> add ( $uidInput , 12 );
2017-05-10 17:23:28 +00:00
if ( $this -> manageCn ( $modules )) {
2014-04-21 19:21:47 +00:00
$this -> addMultiValueInputTextField ( $return , 'cn' , _ ( " Common name " ));
2013-08-18 12:24:53 +00:00
}
$uidNumber = '' ;
2019-09-23 15:59:15 +00:00
if ( isset ( $this -> attributes [ 'uidNumber' ][ 0 ])) {
$uidNumber = $this -> attributes [ 'uidNumber' ][ 0 ];
}
$uidNumberInput = new htmlResponsiveInputField ( _ ( 'UID number' ), 'uidNumber' , $uidNumber , 'uidNumber' );
2013-08-18 12:24:53 +00:00
$uidNumberInput -> setFieldMaxLength ( 20 );
$uidNumberInput -> setValidationRule ( htmlElement :: VALIDATE_NUMERIC );
2019-09-23 15:59:15 +00:00
$return -> add ( $uidNumberInput , 12 );
2018-03-03 16:44:28 +00:00
if ( ! $this -> isBooleanConfigOptionSet ( 'posixAccount_' . $typeId . '_hidegecos' )) {
2013-08-18 12:24:53 +00:00
$gecos = '' ;
2019-09-23 15:59:15 +00:00
if ( isset ( $this -> attributes [ 'gecos' ][ 0 ])) {
$gecos = $this -> attributes [ 'gecos' ][ 0 ];
}
$return -> add ( new htmlResponsiveInputField ( _ ( 'Gecos' ), 'gecos' , $gecos , 'gecos' ), 12 );
2010-03-14 15:42:49 +00:00
}
2013-08-18 12:24:53 +00:00
$primaryGroup = array ();
if ( isset ( $this -> attributes [ 'gidNumber' ][ 0 ])) {
$primaryGroup [] = $this -> attributes [ 'gidNumber' ][ 0 ];
2013-03-24 10:03:35 +00:00
}
2019-09-23 15:59:15 +00:00
$gidNumberSelect = new htmlResponsiveSelect ( 'gidNumber' , $groups , $primaryGroup , _ ( 'Primary group' ), 'gidNumber' );
2013-08-18 12:24:53 +00:00
$gidNumberSelect -> setHasDescriptiveElements ( true );
2019-09-23 15:59:15 +00:00
$return -> add ( $gidNumberSelect , 12 );
2015-08-09 07:22:01 +00:00
2013-08-18 12:24:53 +00:00
if ( $this -> get_scope () == 'user' ) {
// additional groups
2018-03-03 16:44:28 +00:00
if ( ! $this -> isBooleanConfigOptionSet ( 'posixAccount_' . $typeId . '_hidegon' ) || ! $this -> isBooleanConfigOptionSet ( 'posixAccount_' . $typeId . '_hideposixGroups' )) {
2019-09-23 15:59:15 +00:00
$return -> addLabel ( new htmlOutputText ( _ ( 'Additional groups' )));
$additionalGroups = new htmlGroup ();
$additionalGroups -> addElement ( new htmlAccountPageButton ( get_class ( $this ), 'group' , 'open' , _ ( 'Edit groups' )));
$additionalGroups -> addElement ( new htmlHelpLink ( 'addgroup' ));
$return -> addField ( $additionalGroups );
2013-08-18 12:24:53 +00:00
}
// home directory
2017-05-10 17:23:28 +00:00
$homeDir = isset ( $this -> attributes [ $homeDirAttr ][ 0 ]) ? $this -> attributes [ $homeDirAttr ][ 0 ] : '' ;
2019-09-23 15:59:15 +00:00
$homedirInput = new htmlResponsiveInputField ( _ ( 'Home directory' ), 'homeDirectory' , $homeDir , 'homeDirectory' );
2013-08-18 12:24:53 +00:00
$homedirInput -> setRequired ( true );
2019-09-23 15:59:15 +00:00
$return -> add ( $homedirInput , 12 );
2013-08-18 12:24:53 +00:00
if (( $_SESSION [ 'config' ] -> get_scriptPath () != null ) && ( $_SESSION [ 'config' ] -> get_scriptPath () != '' )) {
if ( $this -> getAccountContainer () -> isNewAccount ) {
// get list of lamdaemon servers
2019-10-22 19:22:32 +00:00
$lamdaemonServers = $_SESSION [ 'config' ] -> getConfiguredScriptServers ();
2013-08-18 12:24:53 +00:00
$homeDirLabel = new htmlOutputText ( _ ( 'Create home directory' ));
2019-09-23 15:59:15 +00:00
$return -> addLabel ( $homeDirLabel );
2013-08-18 12:24:53 +00:00
$homeServerContainer = new htmlTable ();
for ( $h = 0 ; $h < sizeof ( $lamdaemonServers ); $h ++ ) {
2019-10-26 15:28:24 +00:00
$homeServerContainer -> addElement ( new htmlTableExtendedInputCheckbox ( 'createhomedir_' . $h , in_array ( $lamdaemonServers [ $h ] -> getServer (), $this -> lamdaemonServers ), $lamdaemonServers [ $h ] -> getLabel (), null , false ));
2019-09-23 15:59:15 +00:00
if ( $h === 0 ) {
$homeDirHelp = new htmlHelpLink ( 'createhomedir' );
$homeServerContainer -> addElement ( $homeDirHelp );
}
$homeServerContainer -> addNewLine ();
2013-08-18 12:24:53 +00:00
}
2019-09-23 15:59:15 +00:00
$return -> addField ( $homeServerContainer );
2011-05-07 08:59:50 +00:00
}
2013-08-18 12:24:53 +00:00
else {
2019-09-23 15:59:15 +00:00
$return -> addLabel ( new htmlOutputText ( ' ' , false ));
$return -> addField ( new htmlAccountPageButton ( get_class ( $this ), 'homedir' , 'open' , _ ( 'Check home directories' )));
2011-05-07 08:59:50 +00:00
}
2013-08-18 12:24:53 +00:00
}
$selectedShell = array ();
if ( isset ( $this -> attributes [ 'loginShell' ][ 0 ])) {
$selectedShell = array ( $this -> attributes [ 'loginShell' ][ 0 ]);
}
2019-09-23 15:59:15 +00:00
$return -> add ( new htmlResponsiveSelect ( 'loginShell' , $shelllist , $selectedShell , _ ( 'Login shell' ), 'loginShell' ), 12 );
2013-08-18 12:24:53 +00:00
}
// password buttons
2019-06-05 17:24:46 +00:00
if ( checkIfWriteAccessIsAllowed ( $this -> get_scope ())
&& isset ( $this -> attributes [ $this -> getPasswordAttrName ( $modules )][ 0 ])
&& $this -> isPasswordManaged ()) {
2019-09-23 15:59:15 +00:00
$return -> addLabel ( new htmlOutputText ( _ ( 'Password' )));
$pwdContainer = new htmlGroup ();
2017-05-10 17:23:28 +00:00
if ( pwd_is_enabled ( $this -> attributes [ $this -> getPasswordAttrName ( $modules )][ 0 ])) {
2013-08-18 12:24:53 +00:00
$pwdContainer -> addElement ( new htmlButton ( 'lockPassword' , _ ( 'Lock password' )));
2011-05-07 08:59:50 +00:00
}
else {
2013-08-18 12:24:53 +00:00
$pwdContainer -> addElement ( new htmlButton ( 'unlockPassword' , _ ( 'Unlock password' )));
2007-02-25 13:55:26 +00:00
}
2013-08-18 12:24:53 +00:00
$pwdContainer -> addElement ( new htmlButton ( 'removePassword' , _ ( 'Remove password' )));
2019-09-23 15:59:15 +00:00
$return -> addField ( $pwdContainer );
2005-10-21 13:48:30 +00:00
}
2013-08-18 12:24:53 +00:00
// remove button
2017-05-10 17:23:28 +00:00
if ( $this -> isOptional ( $modules ) && ! $this -> skipObjectClass ()) {
2019-09-23 15:59:15 +00:00
$return -> addVerticalSpacer ( '2rem' );
2013-08-18 12:24:53 +00:00
$remButton = new htmlButton ( 'remObjectClass' , _ ( 'Remove Unix extension' ));
2019-09-23 15:59:15 +00:00
$return -> add ( $remButton , 12 , 12 , 12 , 'text-center' );
2011-01-09 14:45:12 +00:00
}
2007-11-10 15:16:55 +00:00
}
2013-08-18 12:24:53 +00:00
else {
// add button
2019-09-23 15:59:15 +00:00
$return -> add ( new htmlButton ( 'addObjectClass' , _ ( 'Add Unix extension' )), 12 );
2007-11-10 15:16:55 +00:00
}
2013-08-18 12:24:53 +00:00
return $return ;
2004-10-12 13:34:00 +00:00
}
2003-12-09 18:42:50 +00:00
2018-06-20 06:27:10 +00:00
/**
* Checks if the configuration is valid and prints an error if not .
*
2019-09-23 15:59:15 +00:00
* @ param htmlResponsiveRow $content content area
2018-06-20 06:27:10 +00:00
*/
2019-09-23 15:59:15 +00:00
private function checkForInvalidConfiguration ( htmlResponsiveRow $content ) {
2018-06-20 06:27:10 +00:00
$typeId = $this -> getAccountContainer () -> get_type () -> getId ();
if ( $this -> get_scope () == 'user' ) {
$generatorOption = 'posixAccount_' . $typeId . '_uidGeneratorUsers' ;
}
else {
$generatorOption = 'posixAccount_' . $typeId . '_uidGeneratorHosts' ;
}
if ( empty ( $this -> moduleSettings [ $generatorOption ])) {
$message = new htmlStatusMessage ( 'ERROR' , _ ( 'Invalid configuration detected. Please edit your server profile (module settings) and fill all required fields.' ));
2019-09-23 15:59:15 +00:00
$content -> add ( $message , 12 );
2018-06-20 06:27:10 +00:00
}
}
2007-11-03 14:17:19 +00:00
/**
* Displays the delete homedir option for the delete page .
*
2010-09-26 11:12:59 +00:00
* @ return htmlElement meta HTML code
2007-11-03 14:17:19 +00:00
*/
2006-08-13 12:58:19 +00:00
function display_html_delete () {
2018-11-20 18:18:23 +00:00
$return = new htmlResponsiveRow ();
2010-05-14 12:57:00 +00:00
if ( $this -> get_scope () == 'user' && ( $_SESSION [ 'config' ] -> get_scriptPath () != null )) {
2018-11-20 18:18:23 +00:00
$return -> add ( new htmlResponsiveInputCheckbox ( 'deletehomedir' , true , _ ( 'Delete home directory' ), 'deletehomedir' ), 12 );
2014-01-14 18:08:13 +00:00
}
2017-03-22 19:17:52 +00:00
$typeManager = new TypeManager ();
$sudoTypes = $typeManager -> getConfiguredTypesForScope ( 'sudo' );
if (( $this -> get_scope () == 'user' ) && ! empty ( $sudoTypes )) {
2018-11-20 18:18:23 +00:00
$return -> add ( new htmlResponsiveInputCheckbox ( 'deleteSudoers' , true , _ ( 'Delete sudo rights' ), 'deleteSudoers' ), 12 );
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 .
*
2010-09-26 11:12:59 +00:00
* @ return htmlElement meta HTML code
2005-04-23 14:26:22 +00:00
*/
2006-08-13 12:58:19 +00:00
function display_html_group () {
2019-09-23 15:59:15 +00:00
$return = new htmlResponsiveRow ();
2017-05-10 17:23:28 +00:00
$modules = $this -> getAccountContainer () -> get_type () -> getModules ();
2018-03-03 16:44:28 +00:00
$typeId = $this -> getAccountContainer () -> get_type () -> getId ();
2018-05-28 16:43:15 +00:00
$showUnix = ! $this -> isBooleanConfigOptionSet ( 'posixAccount_' . $typeId . '_hideposixGroups' );
$autoSyncGon = $this -> isBooleanConfigOptionSet ( 'posixGroup_autoSyncGon' );
if ( $showUnix ) {
2013-03-24 10:03:35 +00:00
// load list with all groups
2017-05-10 17:23:28 +00:00
$groups = $this -> findGroups ( $modules );
2013-03-24 10:03:35 +00:00
for ( $i = 0 ; $i < sizeof ( $groups ); $i ++ ) {
$groups [ $i ] = $groups [ $i ][ 1 ];
}
// remove groups the user is member of from grouplist
$groups = array_delete ( $this -> groups , $groups );
// Remove primary group from grouplist
$group = $this -> getGroupName ( $this -> attributes [ 'gidNumber' ][ 0 ]);
$groups = array_flip ( $groups );
unset ( $groups [ $group ]);
$groups = array_flip ( $groups );
2015-08-09 07:22:01 +00:00
2013-03-24 10:03:35 +00:00
$unixContainer = new htmlTable ();
$unixContainer -> alignment = htmlElement :: ALIGN_TOP ;
$unixContainer -> addElement ( new htmlSubTitle ( _ ( " Unix groups " )), true );
2018-05-28 16:43:15 +00:00
if ( $autoSyncGon ) {
2015-05-31 08:46:44 +00:00
$this -> syncGonToGroups ();
foreach ( $this -> groups as $group ) {
$unixContainer -> addElement ( new htmlOutputText ( $group ), true );
}
}
2015-08-09 07:22:01 +00:00
else {
2015-05-31 08:46:44 +00:00
$unixContainer -> addElement ( new htmlOutputText ( _ ( " Selected groups " )));
$unixContainer -> addElement ( new htmlOutputText ( '' ));
$unixContainer -> addElement ( new htmlOutputText ( _ ( " Available groups " )));
$unixContainer -> addNewLine ();
2015-08-09 07:22:01 +00:00
2015-05-31 08:46:44 +00:00
$remSelect = new htmlSelect ( 'removegroups' , $this -> groups , null , 15 );
$remSelect -> setMultiSelect ( true );
$remSelect -> setTransformSingleSelect ( false );
$unixContainer -> addElement ( $remSelect );
$buttonContainer = new htmlTable ();
$buttonContainer -> addElement ( new htmlButton ( 'addgroups_button' , 'back.gif' , true ), true );
$buttonContainer -> addElement ( new htmlButton ( 'removegroups_button' , 'forward.gif' , true ), true );
$buttonContainer -> addElement ( new htmlHelpLink ( 'addgroup' ));
$unixContainer -> addElement ( $buttonContainer );
$addSelect = new htmlSelect ( 'addgroups' , $groups , null , 15 );
$addSelect -> setMultiSelect ( true );
$addSelect -> setTransformSingleSelect ( false );
$unixContainer -> addElement ( $addSelect , true );
}
2015-08-09 07:22:01 +00:00
2019-09-23 15:59:15 +00:00
$return -> add ( $unixContainer , 12 );
$return -> addVerticalSpacer ( '3rem' );
2013-03-24 10:03:35 +00:00
}
2011-10-06 20:03:45 +00:00
2018-05-28 16:43:15 +00:00
$showGon = self :: areGroupOfNamesActive () && ! $this -> isBooleanConfigOptionSet ( 'posixAccount_' . $typeId . '_hidegon' );
if ( $showGon ) {
2011-10-06 20:03:45 +00:00
$gons = $this -> findGroupOfNames ();
2015-08-09 07:22:01 +00:00
2011-10-06 20:03:45 +00:00
$gonContainer = new htmlTable ();
$gonContainer -> alignment = htmlElement :: ALIGN_TOP ;
2013-03-24 10:03:35 +00:00
$gonContainer -> addElement ( new htmlSubTitle ( _ ( " Groups of names " )), true );
2011-10-06 20:03:45 +00:00
$gonContainer -> addElement ( new htmlOutputText ( _ ( " Selected groups " )));
$gonContainer -> addElement ( new htmlOutputText ( '' ));
$gonContainer -> addElement ( new htmlOutputText ( _ ( " Available groups " )));
$gonContainer -> addNewLine ();
2015-08-09 07:22:01 +00:00
2011-10-06 20:03:45 +00:00
$selectedGons = array ();
for ( $i = 0 ; $i < sizeof ( $this -> gonList ); $i ++ ) {
if ( isset ( $gons [ $this -> gonList [ $i ]])) {
2018-02-09 19:33:35 +00:00
$selectedGons [ getAbstractDN ( $this -> gonList [ $i ])] = $this -> gonList [ $i ];
2011-10-06 20:03:45 +00:00
}
}
2018-02-09 19:33:35 +00:00
uksort ( $selectedGons , 'compareDN' );
2011-10-06 20:03:45 +00:00
$availableGons = array ();
foreach ( $gons as $dn => $attr ) {
if ( ! in_array ( $dn , $this -> gonList )) {
2018-02-09 19:33:35 +00:00
$availableGons [ getAbstractDN ( $dn )] = $dn ;
2011-10-06 20:03:45 +00:00
}
}
2018-02-09 19:33:35 +00:00
uksort ( $availableGons , 'compareDN' );
2015-08-09 07:22:01 +00:00
2011-10-06 20:03:45 +00:00
$remGonSelect = new htmlSelect ( 'removegons' , $selectedGons , null , 15 );
$remGonSelect -> setMultiSelect ( true );
$remGonSelect -> setTransformSingleSelect ( false );
$remGonSelect -> setHasDescriptiveElements ( true );
2018-02-09 19:33:35 +00:00
$remGonSelect -> setSortElements ( false );
$remGonSelect -> setRightToLeftTextDirection ( true );
2011-10-06 20:03:45 +00:00
$gonContainer -> addElement ( $remGonSelect );
$buttonGonContainer = new htmlTable ();
$buttonGonContainer -> addElement ( new htmlButton ( 'addgons_button' , 'back.gif' , true ), true );
$buttonGonContainer -> addElement ( new htmlButton ( 'removegons_button' , 'forward.gif' , true ), true );
$buttonGonContainer -> addElement ( new htmlHelpLink ( 'addgroup' ));
$gonContainer -> addElement ( $buttonGonContainer );
$addGonSelect = new htmlSelect ( 'addgons' , $availableGons , null , 15 );
$addGonSelect -> setMultiSelect ( true );
$addGonSelect -> setHasDescriptiveElements ( true );
$addGonSelect -> setTransformSingleSelect ( false );
2018-02-09 19:33:35 +00:00
$addGonSelect -> setSortElements ( false );
$addGonSelect -> setRightToLeftTextDirection ( true );
2011-10-06 20:03:45 +00:00
$gonContainer -> addElement ( $addGonSelect );
$gonContainer -> addNewLine ();
2019-09-23 15:59:15 +00:00
$return -> add ( $gonContainer , 12 );
$return -> addVerticalSpacer ( '3rem' );
2011-10-06 20:03:45 +00:00
}
2015-08-09 07:22:01 +00:00
2018-06-15 17:03:51 +00:00
$showGonSync = $showGon && ! $autoSyncGon ;
$showUnixSync = $showUnix && ! $this -> isBooleanConfigOptionSet ( 'posixAccount_' . $typeId . '_syncGroups' );
$moduleList = $this -> getAccountContainer () -> get_type () -> getModules ();
$showWindowsSync = $this -> isWindows ( $moduleList );
if ( $showUnixSync && ( $showGonSync || $showWindowsSync )) {
2019-09-23 15:59:15 +00:00
$return -> add ( new htmlSubTitle ( _ ( 'Sync groups' )), 12 );
$return -> add ( new htmlResponsiveInputCheckbox ( 'syncDeleteGroups' , true , _ ( 'Delete non-matching entries' )), 12 );
$return -> addVerticalSpacer ( '1rem' );
2018-06-15 17:03:51 +00:00
if ( $showGonSync ) {
$syncButtons = new htmlGroup ();
$u2gonButton = new htmlAccountPageButton ( get_class ( $this ), 'group' , 'syncU2GON' , _ ( 'Sync Unix to group of names' ));
$u2gonButton -> setIconClass ( 'unixButton' );
$syncButtons -> addElement ( $u2gonButton );
$syncButtons -> addElement ( new htmlSpacer ( '2rem' , null ));
$gon2uButton = new htmlAccountPageButton ( get_class ( $this ), 'group' , 'syncGON2U' , _ ( 'Sync group of names to Unix' ));
$gon2uButton -> setIconClass ( 'groupButton' );
$syncButtons -> addElement ( $gon2uButton );
2019-09-23 15:59:15 +00:00
$return -> add ( $syncButtons , 12 , 12 , 12 , 'text-center' );
2018-06-15 17:03:51 +00:00
if ( $showWindowsSync ) {
$syncButtons -> addElement ( new htmlSpacer ( '2rem' , null ));
}
}
if ( $showWindowsSync ) {
$syncButtons = new htmlGroup ();
$gon2uButton = new htmlAccountPageButton ( get_class ( $this ), 'group' , 'syncWin2U' , _ ( 'Sync Windows to Unix' ));
$gon2uButton -> setIconClass ( 'sambaButton' );
$syncButtons -> addElement ( $gon2uButton );
2019-09-23 15:59:15 +00:00
$return -> add ( $syncButtons , 12 , 12 , 12 , 'text-center' );
2018-06-15 17:03:51 +00:00
}
2018-05-28 16:43:15 +00:00
}
2019-09-23 15:59:15 +00:00
$return -> addVerticalSpacer ( '2rem' );
2010-09-25 18:48:51 +00:00
$backButton = new htmlAccountPageButton ( get_class ( $this ), 'attributes' , 'back' , _ ( 'Back' ));
2019-09-23 15:59:15 +00:00
$return -> add ( $backButton , 12 );
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
2011-05-07 08:59:50 +00:00
/**
* Displays the delete homedir option for the homedir page .
*
* @ return htmlElement meta HTML code
*/
function display_html_homedir () {
2017-05-10 17:23:28 +00:00
$modules = $this -> getAccountContainer () -> get_type () -> getModules ();
$homeDirAttr = $this -> getHomedirAttrName ( $modules );
2019-09-23 15:59:15 +00:00
$return = new htmlResponsiveRow ();
$return -> addLabel ( new htmlOutputText ( _ ( 'Home directory' )));
$return -> addField ( new htmlOutputText ( $this -> attributes [ $homeDirAttr ][ 0 ]));
$return -> addVerticalSpacer ( '2rem' );
2011-05-07 08:59:50 +00:00
// get list of lamdaemon servers
2019-10-22 19:22:32 +00:00
$lamdaemonServers = $_SESSION [ 'config' ] -> getConfiguredScriptServers ();
2011-05-07 08:59:50 +00:00
for ( $i = 0 ; $i < sizeof ( $lamdaemonServers ); $i ++ ) {
2019-10-22 19:22:32 +00:00
$label = $lamdaemonServers [ $i ] -> getLabel ();
2017-09-17 07:40:05 +00:00
$remote = new \LAM\REMOTE\Remote ();
2019-10-23 19:14:54 +00:00
$remote -> connect ( $lamdaemonServers [ $i ]);
2017-09-17 07:40:05 +00:00
$result = $remote -> execute (
2011-05-07 08:59:50 +00:00
implode (
2012-08-23 16:28:13 +00:00
self :: $SPLIT_DELIMITER ,
2011-05-07 08:59:50 +00:00
array (
$this -> attributes [ 'uid' ][ 0 ],
" home " ,
" check " ,
2019-10-26 15:28:24 +00:00
$lamdaemonServers [ $i ] -> getHomeDirPrefix () . $this -> attributes [ $homeDirAttr ][ 0 ])
2017-09-17 07:40:05 +00:00
));
$remote -> disconnect ();
2011-05-07 08:59:50 +00:00
// lamdaemon results
2017-09-17 07:40:05 +00:00
if ( ! empty ( $result )) {
$returnValue = trim ( $result );
2011-05-07 08:59:50 +00:00
if ( $returnValue == 'ok' ) {
2019-09-23 15:59:15 +00:00
$return -> addLabel ( new htmlOutputText ( $label ));
$okGroup = new htmlGroup ();
$okGroup -> addElement ( new htmlImage ( '../../graphics/pass.png' , 16 , 16 ));
$okGroup -> addElement ( new htmlSpacer ( '5px' , null ));
$okGroup -> addElement ( new htmlAccountPageButton ( get_class ( $this ), 'homedir' , 'delete_' . $i , _ ( 'Delete' )));
$return -> addField ( $okGroup );
2011-05-07 08:59:50 +00:00
}
elseif ( $returnValue == 'missing' ) {
2019-09-23 15:59:15 +00:00
$return -> addLabel ( new htmlOutputText ( $label ));
$failGroup = new htmlGroup ();
$failGroup -> addElement ( new htmlImage ( '../../graphics/fail.png' , 16 , 16 ));
$failGroup -> addElement ( new htmlSpacer ( '5px' , null ));
$failGroup -> addElement ( new htmlAccountPageButton ( get_class ( $this ), 'homedir' , 'create_' . $i , _ ( 'Create' )));
$return -> addField ( $failGroup );
2011-05-07 08:59:50 +00:00
}
2012-02-22 22:52:15 +00:00
elseif ( trim ( $returnValue ) != '' ) {
2011-05-07 08:59:50 +00:00
$messageParams = explode ( " , " , $returnValue );
if ( isset ( $messageParams [ 2 ])) {
2012-02-22 22:52:15 +00:00
$message = new htmlStatusMessage ( $messageParams [ 0 ], htmlspecialchars ( $messageParams [ 1 ]), htmlspecialchars ( $messageParams [ 2 ]));
2011-05-07 08:59:50 +00:00
}
2012-02-22 22:44:18 +00:00
elseif (( $messageParams [ 0 ] == 'ERROR' ) || ( $messageParams [ 0 ] == 'WARN' ) || ( $messageParams [ 0 ] == 'INFO' )) {
2012-02-22 22:52:15 +00:00
$message = new htmlStatusMessage ( $messageParams [ 0 ], htmlspecialchars ( $messageParams [ 1 ]));
}
else {
$message = new htmlStatusMessage ( 'WARN' , htmlspecialchars ( $messageParams [ 0 ]));
2011-05-07 08:59:50 +00:00
}
2019-09-23 15:59:15 +00:00
$return -> add ( $message , 12 );
2011-05-07 08:59:50 +00:00
}
}
}
2019-09-23 15:59:15 +00:00
$return -> addVerticalSpacer ( '2rem' );
$return -> add ( new htmlAccountPageButton ( get_class ( $this ), 'attributes' , 'back' , _ ( 'Back' )), 12 , 12 , 12 , 'text-center' );
2011-05-07 08:59:50 +00:00
return $return ;
}
2004-09-19 08:34:14 +00:00
/**
2017-03-30 18:39:24 +00:00
* { @ inheritDoc }
2004-09-19 08:34:14 +00:00
*/
2017-03-30 18:39:24 +00:00
function get_profileOptions ( $typeId ) {
2018-05-19 11:26:35 +00:00
$return = new htmlResponsiveRow ();
2017-05-10 17:23:28 +00:00
$typeManager = new TypeManager ();
$modules = $typeManager -> getConfiguredType ( $typeId ) -> getModules ();
$groupList = $this -> findGroups ( $modules );
2009-11-26 10:48:05 +00:00
$groups = array ();
for ( $i = 0 ; $i < sizeof ( $groupList ); $i ++ ) {
$groups [] = $groupList [ $i ][ 1 ];
}
2007-10-04 16:45:05 +00:00
if ( $this -> get_scope () == 'user' ) {
2013-02-05 19:10:04 +00:00
$shelllist = $this -> getShells (); // list of all valid shells
2004-04-04 13:48:21 +00:00
// primary Unix group
2018-05-19 11:26:35 +00:00
$return -> add ( new htmlResponsiveSelect ( 'posixAccount_primaryGroup' , $groups , array (), _ ( 'Primary group' ), 'gidNumber' ), 12 );
2004-04-04 13:48:21 +00:00
// additional group memberships
2018-05-19 11:26:35 +00:00
$addGroupSelect = new htmlResponsiveSelect ( 'posixAccount_additionalGroup' , $groups , array (), _ ( 'Additional groups' ), 'addgroup' , 10 );
2010-09-25 18:48:51 +00:00
$addGroupSelect -> setMultiSelect ( true );
2011-10-06 20:03:45 +00:00
$addGroupSelect -> setTransformSingleSelect ( false );
2018-05-19 11:26:35 +00:00
$return -> add ( $addGroupSelect , 12 );
2011-10-06 20:03:45 +00:00
// group of names
2012-04-09 13:20:24 +00:00
if ( self :: areGroupOfNamesActive ()) {
2011-10-06 20:03:45 +00:00
$gons = $this -> findGroupOfNames ();
$gonList = array ();
foreach ( $gons as $dn => $attr ) {
$gonList [ $attr [ 'cn' ][ 0 ]] = $dn ;
}
2018-05-19 11:26:35 +00:00
$gonSelect = new htmlResponsiveSelect ( 'posixAccount_gon' , $gonList , array (), _ ( 'Groups of names' ), 'addgroup' , 10 );
2011-10-06 20:03:45 +00:00
$gonSelect -> setHasDescriptiveElements ( true );
$gonSelect -> setMultiSelect ( true );
$gonSelect -> setTransformSingleSelect ( false );
2018-05-19 11:26:35 +00:00
$return -> add ( $gonSelect , 12 );
2011-10-06 20:03:45 +00:00
}
2019-11-21 18:57:45 +00:00
// common name
if ( $this -> manageCn ( $modules )) {
$return -> add ( new htmlResponsiveInputField ( _ ( 'Common name' ), 'posixAccount_cn' , '' , 'cn' ), 12 );
}
2004-04-04 13:48:21 +00:00
// home directory
2018-05-19 11:26:35 +00:00
$return -> add ( new htmlResponsiveInputField ( _ ( 'Home directory' ), 'posixAccount_homeDirectory' , '/home/$user' , 'homeDirectory' ), 12 );
2004-04-04 13:48:21 +00:00
// login shell
2018-05-19 11:26:35 +00:00
$return -> add ( new htmlResponsiveSelect ( 'posixAccount_loginShell' , $shelllist , array ( " /bin/bash " ), _ ( 'Login shell' ), 'loginShell' ), 12 );
2008-08-10 19:53:13 +00:00
// lamdaemon settings
2018-12-28 10:19:15 +00:00
if ( $_SESSION [ 'config' ] -> get_scriptPath () != null ) {
2018-05-19 11:26:35 +00:00
$return -> add ( new htmlSubTitle ( _ ( 'Create home directory' )), 12 );
2019-10-22 19:22:32 +00:00
$lamdaemonServers = $_SESSION [ 'config' ] -> getConfiguredScriptServers ();
2011-05-07 08:59:50 +00:00
for ( $h = 0 ; $h < sizeof ( $lamdaemonServers ); $h ++ ) {
2019-10-22 19:22:32 +00:00
$server = $lamdaemonServers [ $h ] -> getServer ();
$label = $lamdaemonServers [ $h ] -> getLabel ();
$return -> add ( new htmlResponsiveInputCheckbox ( 'posixAccount_createHomedir_' . $h , in_array ( $server , $this -> lamdaemonServers ), $label , 'createhomedir' , false ), 12 );
2011-05-07 08:59:50 +00:00
}
2008-08-10 19:53:13 +00:00
}
2004-10-02 18:45:11 +00:00
}
2007-10-04 16:45:05 +00:00
elseif ( $this -> get_scope () == 'host' ) {
2004-10-02 18:45:11 +00:00
// primary Unix group
2018-05-19 11:26:35 +00:00
$return -> add ( new htmlResponsiveSelect ( 'posixAccount_primaryGroup' , $groups , array (), _ ( 'Primary group' ), 'gidNumber' ), 12 );
2004-04-04 13:48:21 +00:00
}
2017-05-10 17:23:28 +00:00
if ( $this -> isOptional ( $modules )) {
2018-05-19 11:26:35 +00:00
$return -> add ( new htmlResponsiveInputCheckbox ( 'posixAccount_addExt' , false , _ ( 'Automatically add this extension' ), 'autoAdd' ), 12 );
2013-08-18 12:24:53 +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 );
2017-05-10 17:23:28 +00:00
$modules = $this -> getAccountContainer () -> get_type () -> getModules ();
2018-03-03 16:44:28 +00:00
$typeId = $this -> getAccountContainer () -> get_type () -> getId ();
2019-11-21 18:57:45 +00:00
// cn
if ( $this -> manageCn ( $modules ) && ! empty ( $profile [ 'posixAccount_cn' ][ 0 ])) {
$this -> attributes [ 'cn' ][ 0 ] = $profile [ 'posixAccount_cn' ][ 0 ];
}
2017-05-10 17:23:28 +00:00
// home directory
$homeDirAttr = $this -> getHomedirAttrName ( $modules );
if ( ! empty ( $profile [ 'posixAccount_homeDirectory' ][ 0 ])) {
$this -> attributes [ $homeDirAttr ][ 0 ] = $profile [ 'posixAccount_homeDirectory' ][ 0 ];
}
2005-01-16 12:41:38 +00:00
// special profile options
// GID
if ( isset ( $profile [ 'posixAccount_primaryGroup' ][ 0 ])) {
2009-11-26 10:48:05 +00:00
$gid = $this -> getGID ( $profile [ 'posixAccount_primaryGroup' ][ 0 ]);
if ( $gid != null ) {
2005-01-16 12:41:38 +00:00
$this -> attributes [ 'gidNumber' ][ 0 ] = $gid ;
}
}
// other group memberships
if ( isset ( $profile [ 'posixAccount_additionalGroup' ][ 0 ])) {
$this -> groups = $profile [ 'posixAccount_additionalGroup' ];
}
2011-10-06 20:03:45 +00:00
// group of names
if ( isset ( $profile [ 'posixAccount_gon' ][ 0 ])) {
$this -> gonList = $profile [ 'posixAccount_gon' ];
}
2008-08-10 19:53:13 +00:00
// lamdaemon
if (( $this -> get_scope () == 'user' ) && $this -> getAccountContainer () -> isNewAccount ) {
2019-10-22 19:22:32 +00:00
$lamdaemonServers = $_SESSION [ 'config' ] -> getConfiguredScriptServers ();
2011-05-07 08:59:50 +00:00
$this -> lamdaemonServers = array ();
for ( $h = 0 ; $h < sizeof ( $lamdaemonServers ); $h ++ ) {
if ( isset ( $profile [ 'posixAccount_createHomedir_' . $h ][ 0 ]) && ( $profile [ 'posixAccount_createHomedir_' . $h ][ 0 ] == 'true' )) {
2019-10-22 19:22:32 +00:00
$this -> lamdaemonServers [] = $lamdaemonServers [ $h ] -> getServer ();
2011-05-07 08:59:50 +00:00
}
2008-08-10 19:53:13 +00:00
}
}
2013-08-18 12:24:53 +00:00
// add extension
if ( isset ( $profile [ 'posixAccount_addExt' ][ 0 ]) && ( $profile [ 'posixAccount_addExt' ][ 0 ] == " true " )) {
2016-05-09 18:10:14 +00:00
if ( ! $this -> skipObjectClass () && ! in_array ( 'posixAccount' , $this -> attributes [ 'objectClass' ])) {
2013-08-18 12:24:53 +00:00
$this -> attributes [ 'objectClass' ][] = 'posixAccount' ;
}
}
2005-01-16 12:41:38 +00:00
}
2017-05-10 17:23:28 +00:00
/**
* { @ inheritDoc }
* @ see baseModule :: get_pdfFields ()
*/
public function get_pdfFields ( $typeId ) {
$fields = parent :: get_pdfFields ( $typeId );
$typeManager = new TypeManager ();
$modules = $typeManager -> getConfiguredType ( $typeId ) -> getModules ();
if ( $this -> manageCn ( $modules )) {
$fields [ 'cn' ] = _ ( 'Common name' );
}
2018-03-03 16:44:28 +00:00
if ( ! $this -> isBooleanConfigOptionSet ( 'posixAccount_' . $typeId . '_hidegecos' )) {
2018-03-04 08:43:16 +00:00
$fields [ 'gecos' ] = _ ( 'Gecos' );
2018-03-03 16:44:28 +00:00
}
2017-05-10 17:23:28 +00:00
return $fields ;
}
2005-10-09 18:05:32 +00:00
/**
2017-02-19 08:14:11 +00:00
* { @ inheritDoc }
* @ see baseModule :: get_pdfEntries ()
2015-01-07 17:16:35 +00:00
*/
2017-04-01 07:57:03 +00:00
function get_pdfEntries ( $pdfKeys , $typeId ) {
2013-03-16 17:12:00 +00:00
$uidLabel = _ ( 'User name' );
if ( $this -> get_scope () == 'host' ) {
$uidLabel = _ ( 'Host name' );
}
2014-07-17 19:34:51 +00:00
$additionalGroups = array ();
if ( ! empty ( $this -> groups )) {
$additionalGroups = $this -> groups ;
natcasesort ( $additionalGroups );
}
2017-05-10 17:23:28 +00:00
$modules = $this -> getAccountContainer () -> get_type () -> getModules ();
$homeDirAttr = $this -> getHomedirAttrName ( $modules );
2015-03-11 20:50:37 +00:00
$return = array ();
2020-02-08 14:42:07 +00:00
if ( isset ( $this -> attributes [ 'gidNumber' ][ 0 ])) {
$this -> addPDFKeyValue ( $return , 'primaryGroup' , _ ( 'Primary group' ), $this -> getGroupName ( $this -> attributes [ 'gidNumber' ][ 0 ]));
}
2015-03-11 20:50:37 +00:00
$this -> addPDFKeyValue ( $return , 'additionalGroups' , _ ( 'Additional groups' ), implode ( " , " , $additionalGroups ));
2013-05-07 19:18:21 +00:00
$this -> addSimplePDFField ( $return , 'uid' , $uidLabel );
$this -> addSimplePDFField ( $return , 'cn' , _ ( 'Common name' ));
$this -> addSimplePDFField ( $return , 'uidNumber' , _ ( 'UID number' ));
$this -> addSimplePDFField ( $return , 'gidNumber' , _ ( 'GID number' ));
2017-05-10 17:23:28 +00:00
$this -> addSimplePDFField ( $return , 'homeDirectory' , _ ( 'Home directory' ), $homeDirAttr );
2013-05-07 19:18:21 +00:00
$this -> addSimplePDFField ( $return , 'loginShell' , _ ( 'Login shell' ));
$this -> addSimplePDFField ( $return , 'gecos' , _ ( 'Gecos' ));
2012-04-09 13:20:24 +00:00
if ( self :: areGroupOfNamesActive ()) {
2011-10-06 20:03:45 +00:00
$gons = array ();
for ( $i = 0 ; $i < sizeof ( $this -> gonList ); $i ++ ) {
2018-02-09 19:33:35 +00:00
$gons [] = $this -> gonList [ $i ];
}
usort ( $gons , 'compareDN' );
$gonCount = sizeof ( $gons );
for ( $i = 0 ; $i < $gonCount ; $i ++ ) {
$gons [ $i ] = getAbstractDN ( $gons [ $i ]);
2011-10-06 20:03:45 +00:00
}
2018-02-09 19:33:35 +00:00
$this -> addPDFKeyValue ( $return , 'gon' , _ ( 'Groups of names' ), $gons , " \n " );
2011-10-06 20:03:45 +00:00
}
2010-03-08 18:26:06 +00:00
if ( isset ( $this -> clearTextPassword )) {
2015-03-11 20:50:37 +00:00
$this -> addPDFKeyValue ( $return , 'userPassword' , _ ( 'Password' ), $this -> clearTextPassword );
2010-03-08 18:26:06 +00:00
}
2012-02-05 13:04:57 +00:00
else if ( isset ( $this -> attributes [ 'INFO.userPasswordClearText' ])) {
2015-03-11 20:50:37 +00:00
$this -> addPDFKeyValue ( $return , 'userPassword' , _ ( 'Password' ), $this -> attributes [ 'INFO.userPasswordClearText' ]);
2012-02-05 13:04:57 +00:00
}
2006-09-03 12:41:22 +00:00
return $return ;
2004-05-24 21:39:57 +00:00
}
2004-03-14 17:33:05 +00:00
2016-03-28 09:06:04 +00:00
/**
2018-03-03 16:44:28 +00:00
* { @ inheritDoc }
* @ see baseModule :: get_configOptions ()
2016-03-28 09:06:04 +00:00
*/
2018-03-03 16:44:28 +00:00
public function get_configOptions ( $scopes , $allScopes ) {
$typeManager = new TypeManager ( $_SESSION [ 'conf_config' ]);
$isWindows = array_key_exists ( 'windowsUser' , $allScopes );
2016-03-28 09:06:04 +00:00
$return = array ();
2017-11-25 16:55:29 +00:00
$generatorOptions = array (
_ ( 'Fixed range' ) => 'range' ,
_ ( 'Samba ID pool' ) => 'sambaPool' ,
_ ( 'Windows domain info' ) => 'windowsDomain' ,
_ ( 'Magic number' ) => 'magicNumber'
);
2019-08-14 18:49:10 +00:00
$hasUserConfig = false ;
$hasHostConfig = false ;
foreach ( $scopes as $typeId ) {
if ( getScopeFromTypeId ( $typeId ) === 'user' ) {
$hasUserConfig = true ;
}
elseif ( getScopeFromTypeId ( $typeId ) === 'host' ) {
$hasHostConfig = true ;
}
}
if ( $hasUserConfig ) {
2016-03-28 09:06:04 +00:00
// user options
2017-12-02 16:51:59 +00:00
$configUserContainer = new htmlResponsiveRow ();
$configUserContainer -> add ( new htmlSubTitle ( _ ( " Users " )), 12 );
2018-03-03 16:44:28 +00:00
foreach ( $allScopes [ get_class ( $this )] as $typeId ) {
if ( ! ( getScopeFromTypeId ( $typeId ) === 'user' )) {
continue ;
}
if ( sizeof ( $allScopes [ get_class ( $this )]) > 1 ) {
$title = new htmlDiv ( null , new htmlOutputText ( $typeManager -> getConfiguredType ( $typeId ) -> getAlias ()));
$title -> setCSSClasses ( array ( 'bold' , 'responsiveLabel' ));
$configUserContainer -> add ( $title , 12 , 6 );
$configUserContainer -> add ( new htmlOutputText ( ' ' , false ), 0 , 6 );
}
$uidGeneratorSelect = new htmlResponsiveSelect ( 'posixAccount_' . $typeId . '_uidGeneratorUsers' , $generatorOptions , array ( 'range' ), _ ( 'UID generator' ), 'uidGenerator' );
$uidGeneratorSelect -> setHasDescriptiveElements ( true );
$uidGeneratorSelect -> setTableRowsToHide ( array (
'range' => array ( 'posixAccount_' . $typeId . '_sambaIDPoolDNUsers' , 'posixAccount_' . $typeId . '_windowsIDPoolDNUsers' ,
'posixAccount_' . $typeId . '_magicNumberUser' ),
'sambaPool' => array ( 'posixAccount_' . $typeId . '_minUID' , 'posixAccount_' . $typeId . '_maxUID' ,
'posixAccount_' . $typeId . '_windowsIDPoolDNUsers' , 'posixAccount_' . $typeId . '_magicNumberUser' ),
'windowsDomain' => array ( 'posixAccount_' . $typeId . '_minUID' , 'posixAccount_' . $typeId . '_maxUID' ,
'posixAccount_' . $typeId . '_sambaIDPoolDNUsers' , 'posixAccount_' . $typeId . '_magicNumberUser' ),
'magicNumber' => array ( 'posixAccount_' . $typeId . '_minUID' , 'posixAccount_' . $typeId . '_maxUID' ,
'posixAccount_' . $typeId . '_windowsIDPoolDNUsers' , 'posixAccount_' . $typeId . '_sambaIDPoolDNUsers' )
));
$uidGeneratorSelect -> setTableRowsToShow ( array (
'range' => array ( 'posixAccount_' . $typeId . '_minUID' , 'posixAccount_' . $typeId . '_maxUID' ),
'sambaPool' => array ( 'posixAccount_' . $typeId . '_sambaIDPoolDNUsers' ),
'windowsDomain' => array ( 'posixAccount_' . $typeId . '_windowsIDPoolDNUsers' ),
'magicNumber' => array ( 'posixAccount_' . $typeId . '_magicNumberUser' )
));
$configUserContainer -> add ( $uidGeneratorSelect , 12 );
$uidUsersGeneratorDN = new htmlResponsiveInputField ( _ ( 'Samba ID pool DN' ), 'posixAccount_' . $typeId . '_sambaIDPoolDNUsers' , null , 'sambaIDPoolDN' );
$uidUsersGeneratorDN -> setRequired ( true );
$configUserContainer -> add ( $uidUsersGeneratorDN , 12 );
$uidUsersGeneratorWinDN = new htmlResponsiveInputField ( _ ( 'Windows domain info DN' ), 'posixAccount_' . $typeId . '_windowsIDPoolDNUsers' , null , 'windowsIDPoolDN' );
$uidUsersGeneratorWinDN -> setRequired ( true );
$configUserContainer -> add ( $uidUsersGeneratorWinDN , 12 );
$minUid = new htmlResponsiveInputField ( _ ( 'Minimum UID number' ), 'posixAccount_' . $typeId . '_minUID' , null , 'minMaxUser' );
$minUid -> setRequired ( true );
$configUserContainer -> add ( $minUid , 12 );
$maxUid = new htmlResponsiveInputField ( _ ( 'Maximum UID number' ), 'posixAccount_' . $typeId . '_maxUID' , null , 'minMaxUser' );
$maxUid -> setRequired ( true );
$configUserContainer -> add ( $maxUid , 12 );
$magicNumberUser = new htmlResponsiveInputField ( _ ( 'Magic number' ), 'posixAccount_' . $typeId . '_magicNumberUser' , null , 'magicNumber' );
$magicNumberUser -> setRequired ( true );
$configUserContainer -> add ( $magicNumberUser , 12 );
$configUserContainer -> add ( new htmlResponsiveInputField ( _ ( 'Suffix for UID/user name check' ), 'posixAccount_' . $typeId . '_uidCheckSuffixUser' , '' , 'uidCheckSuffix' ), 12 );
2018-06-11 15:48:43 +00:00
$configUserContainer -> add ( new htmlResponsiveInputField ( _ ( 'User name suggestion' ), 'posixAccount_' . $typeId . '_userNameSuggestion' , '@givenname@%sn%' , 'userNameSuggestion' ), 12 );
$configUserContainer -> addVerticalSpacer ( '2rem' );
2018-03-03 16:44:28 +00:00
$hiddenOptionsContainerHead = new htmlGroup ();
$hiddenOptionsContainerHead -> addElement ( new htmlOutputText ( _ ( 'Hidden options' )));
$hiddenOptionsContainerHead -> addElement ( new htmlHelpLink ( 'hiddenOptions' ));
$configUserContainer -> addLabel ( $hiddenOptionsContainerHead , 12 );
$configUserContainer -> addField ( new htmlOutputText ( '' ));
$configUserContainer -> addVerticalSpacer ( '0.5rem' );
$configUserContainer -> add ( new htmlResponsiveInputCheckbox ( 'posixAccount_' . $typeId . '_hidegecos' , false , _ ( 'Gecos' ), null , false ), 12 );
2019-06-05 17:24:46 +00:00
$configUserContainer -> add ( new htmlResponsiveInputCheckbox ( 'posixAccount_' . $typeId . '_hidepassword' , false , _ ( 'Password' ), null , false ), 12 );
2018-03-03 16:44:28 +00:00
$confActiveGONModules = array_merge ( $_SESSION [ 'conf_config' ] -> get_AccountModules ( 'group' ), $_SESSION [ 'conf_config' ] -> get_AccountModules ( 'gon' ));
if ( in_array ( 'groupOfNames' , $confActiveGONModules ) || in_array ( 'groupOfMembers' , $confActiveGONModules ) || in_array ( 'groupOfUniqueNames' , $confActiveGONModules )) {
$configUserContainer -> add ( new htmlResponsiveInputCheckbox ( 'posixAccount_' . $typeId . '_hidegon' , false , _ ( 'Groups of names' ), null , false ), 12 );
$configUserContainer -> add ( new htmlResponsiveInputCheckbox ( 'posixAccount_' . $typeId . '_hideposixGroups' , false , _ ( 'Unix groups' ), null , false ), 12 );
2018-05-28 16:43:15 +00:00
$syncGroupsCheckbox = new htmlResponsiveInputCheckbox ( 'posixAccount_' . $typeId . '_syncGroups' , false , _ ( 'Sync groups' ), null , false );
$syncGroupsCheckbox -> setTableRowsToHide ( array ( 'posixAccount_' . $typeId . '_syncGroupsExclusions' ));
$configUserContainer -> add ( $syncGroupsCheckbox , 12 );
2018-11-17 19:40:09 +00:00
$configUserContainer -> add ( new htmlResponsiveInputTextarea ( 'posixAccount_' . $typeId . '_syncGroupsExclusions' , '' , 20 , 4 , _ ( 'Exclude from group sync' ), 'excludeFromGroupSync' ), 12 );
2018-03-03 16:44:28 +00:00
}
}
2016-03-28 09:06:04 +00:00
$return [] = $configUserContainer ;
}
// host options
2019-08-14 18:49:10 +00:00
if ( $hasHostConfig ) {
2017-12-02 16:51:59 +00:00
$configHostContainer = new htmlResponsiveRow ();
$configHostContainer -> add ( new htmlSubTitle ( _ ( " Hosts " )), 12 );
2018-03-03 16:44:28 +00:00
foreach ( $allScopes [ get_class ( $this )] as $typeId ) {
if ( ! ( getScopeFromTypeId ( $typeId ) === 'host' )) {
continue ;
}
if ( sizeof ( $allScopes [ get_class ( $this )]) > 1 ) {
$title = new htmlDiv ( null , new htmlOutputText ( $typeManager -> getConfiguredType ( $typeId ) -> getAlias ()));
$title -> setCSSClasses ( array ( 'bold' , 'responsiveLabel' ));
$configHostContainer -> add ( $title , 12 , 6 );
$configHostContainer -> add ( new htmlOutputText ( ' ' , false ), 0 , 6 );
}
$uidHostGeneratorSelect = new htmlResponsiveSelect ( 'posixAccount_' . $typeId . '_uidGeneratorHosts' , $generatorOptions , array ( 'range' ), _ ( 'UID generator' ), 'uidGenerator' );
$uidHostGeneratorSelect -> setHasDescriptiveElements ( true );
$uidHostGeneratorSelect -> setTableRowsToHide ( array (
'range' => array ( 'posixAccount_' . $typeId . '_sambaIDPoolDNHosts' , 'posixAccount_' . $typeId . '_windowsIDPoolDNHosts' ,
'posixAccount_' . $typeId . '_magicNumberHost' ),
'sambaPool' => array ( 'posixAccount_' . $typeId . '_minMachine' , 'posixAccount_' . $typeId . '_maxMachine' ,
'posixAccount_' . $typeId . '_windowsIDPoolDNHosts' , 'posixAccount_' . $typeId . '_magicNumberHost' ),
'windowsDomain' => array ( 'posixAccount_' . $typeId . '_minMachine' , 'posixAccount_' . $typeId . '_maxMachine' ,
'posixAccount_' . $typeId . '_sambaIDPoolDNHosts' , 'posixAccount_' . $typeId . '_magicNumberHost' ),
'magicNumber' => array ( 'posixAccount_' . $typeId . '_minMachine' , 'posixAccount_' . $typeId . '_maxMachine' ,
'posixAccount_' . $typeId . '_windowsIDPoolDNHosts' , 'posixAccount_' . $typeId . '_sambaIDPoolDNHosts' )
));
$uidHostGeneratorSelect -> setTableRowsToShow ( array (
'range' => array ( 'posixAccount_' . $typeId . '_minMachine' , 'posixAccount_' . $typeId . '_maxMachine' ),
'sambaPool' => array ( 'posixAccount_' . $typeId . '_sambaIDPoolDNHosts' ),
'windowsDomain' => array ( 'posixAccount_' . $typeId . '_windowsIDPoolDNHosts' ),
'magicNumber' => array ( 'posixAccount_' . $typeId . '_magicNumberHost' )
));
$configHostContainer -> add ( $uidHostGeneratorSelect , 12 );
$uidHostsGeneratorDN = new htmlResponsiveInputField ( _ ( 'Samba ID pool DN' ), 'posixAccount_' . $typeId . '_sambaIDPoolDNHosts' , null , 'sambaIDPoolDN' );
$uidHostsGeneratorDN -> setRequired ( true );
$configHostContainer -> add ( $uidHostsGeneratorDN , 12 );
$uidHostsGeneratorWinDN = new htmlResponsiveInputField ( _ ( 'Windows domain info DN' ), 'posixAccount_' . $typeId . '_windowsIDPoolDNHosts' , null , 'windowsIDPoolDN' );
$uidHostsGeneratorWinDN -> setRequired ( true );
$configHostContainer -> add ( $uidHostsGeneratorWinDN , 12 );
$minUid = new htmlResponsiveInputField ( _ ( 'Minimum UID number' ), 'posixAccount_' . $typeId . '_minMachine' , null , 'minMaxHost' );
$minUid -> setRequired ( true );
$configHostContainer -> add ( $minUid , 12 );
$maxUid = new htmlResponsiveInputField ( _ ( 'Maximum UID number' ), 'posixAccount_' . $typeId . '_maxMachine' , null , 'minMaxHost' );
$maxUid -> setRequired ( true );
$configHostContainer -> add ( $maxUid , 12 );
$magicNumberHost = new htmlResponsiveInputField ( _ ( 'Magic number' ), 'posixAccount_' . $typeId . '_magicNumberHost' , null , 'magicNumber' );
$magicNumberHost -> setRequired ( true );
$configHostContainer -> add ( $magicNumberHost , 12 );
$configHostContainer -> add ( new htmlResponsiveInputField ( _ ( 'Suffix for UID/user name check' ), 'posixAccount_' . $typeId . '_uidCheckSuffixHost' , '' , 'uidCheckSuffix' ), 12 );
$hiddenOptionsContainerHead = new htmlGroup ();
$hiddenOptionsContainerHead -> addElement ( new htmlOutputText ( _ ( 'Hidden options' )));
$hiddenOptionsContainerHead -> addElement ( new htmlHelpLink ( 'hiddenOptions' ));
$configHostContainer -> addLabel ( $hiddenOptionsContainerHead , 12 );
$configHostContainer -> addField ( new htmlOutputText ( '' ));
$configHostContainer -> addVerticalSpacer ( '0.5rem' );
$configHostContainer -> add ( new htmlResponsiveInputCheckbox ( 'posixAccount_' . $typeId . '_hidegecos' , false , _ ( 'Gecos' ), null , false ), 12 );
$configHostContainer -> addVerticalSpacer ( '2rem' );
}
2016-03-28 09:06:04 +00:00
$return [] = $configHostContainer ;
}
// common options
2017-12-02 16:51:59 +00:00
$configOptionsContainer = new htmlResponsiveRow ();
$configOptionsContainer -> add ( new htmlSubTitle ( _ ( 'Options' )), 12 );
$configOptionsContainer -> add ( new htmlResponsiveSelect ( 'posixAccount_pwdHash' , getSupportedHashTypes (),
array ( 'SSHA' ), _ ( " Password hash type " ), 'pwdHash' ), 12 );
$configOptionsContainer -> add ( new htmlResponsiveInputTextarea ( 'posixAccount_shells' , implode ( " \r \n " , $this -> getShells ()), 30 , 4 , _ ( 'Login shells' ), 'loginShells' ), 12 );
2018-03-03 09:28:44 +00:00
$configOptionsContainer -> add ( new htmlResponsiveInputCheckbox ( 'posixAccount_primaryGroupAsSecondary' , false , _ ( 'Set primary group as memberUid' ), 'primaryGroupAsSecondary' ), 12 );
2016-05-09 18:10:14 +00:00
if ( $isWindows ) {
2018-03-03 09:28:44 +00:00
$configOptionsContainer -> add ( new htmlResponsiveInputCheckbox ( 'posixAccount_noObjectClass' , false , _ ( 'Do not add object class' ), 'noObjectClass' ), 12 );
2016-05-09 18:10:14 +00:00
}
2016-03-28 09:06:04 +00:00
$return [] = $configOptionsContainer ;
return $return ;
}
2004-08-01 09:39:24 +00:00
/**
2017-12-20 19:44:08 +00:00
* { @ inheritDoc }
* @ see baseModule :: check_configOptions ()
*/
2018-03-03 16:44:28 +00:00
public function check_configOptions ( $typeIds , & $options ) {
2004-08-01 09:39:24 +00:00
$return = array ();
2017-12-20 19:44:08 +00:00
$scopes = array ();
2018-03-03 16:44:28 +00:00
$ranges = array ();
2017-12-20 19:44:08 +00:00
foreach ( $typeIds as $typeId ) {
$scopes [] = getScopeFromTypeId ( $typeId );
2018-03-03 16:44:28 +00:00
// user settings
if ( getScopeFromTypeId ( $typeId ) === 'user' ) {
if ( $options [ 'posixAccount_' . $typeId . '_uidGeneratorUsers' ][ 0 ] == 'range' ) {
// min/maxUID are required, check if they are numeric
if ( ! isset ( $options [ 'posixAccount_' . $typeId . '_minUID' ][ 0 ]) || ! preg_match ( '/^[0-9]+$/' , $options [ 'posixAccount_' . $typeId . '_minUID' ][ 0 ])) {
$return [] = $this -> messages [ 'minUID' ][ 0 ];
}
if ( ! isset ( $options [ 'posixAccount_' . $typeId . '_maxUID' ][ 0 ]) || ! preg_match ( '/^[0-9]+$/' , $options [ 'posixAccount_' . $typeId . '_maxUID' ][ 0 ])) {
$return [] = $this -> messages [ 'maxUID' ][ 0 ];
}
// minUID < maxUID
if ( isset ( $options [ 'posixAccount_' . $typeId . '_minUID' ][ 0 ]) && isset ( $options [ 'posixAccount_' . $typeId . '_maxUID' ][ 0 ])) {
2019-02-01 19:27:49 +00:00
if ( $options [ 'posixAccount_' . $typeId . '_minUID' ][ 0 ] >= $options [ 'posixAccount_' . $typeId . '_maxUID' ][ 0 ]) {
2018-03-03 16:44:28 +00:00
$return [] = $this -> messages [ 'cmp_UID' ][ 0 ];
}
2013-02-17 13:19:50 +00:00
}
2018-03-03 16:44:28 +00:00
$ranges [] = array ( $options [ 'posixAccount_' . $typeId . '_minUID' ][ 0 ], $options [ 'posixAccount_' . $typeId . '_maxUID' ][ 0 ]);
2013-02-17 13:19:50 +00:00
}
2018-03-03 16:44:28 +00:00
elseif ( $options [ 'posixAccount_' . $typeId . '_uidGeneratorUsers' ][ 0 ] == 'sambaPool' ) {
if ( ! isset ( $options [ 'posixAccount_' . $typeId . '_sambaIDPoolDNUsers' ][ 0 ]) || ! get_preg ( $options [ 'posixAccount_' . $typeId . '_sambaIDPoolDNUsers' ][ 0 ], 'dn' )) {
$return [] = $this -> messages [ 'sambaIDPoolDN' ][ 0 ];
}
2004-08-01 09:39:24 +00:00
}
2018-03-03 16:44:28 +00:00
elseif ( $options [ 'posixAccount_' . $typeId . '_uidGeneratorUsers' ][ 0 ] == 'windowsDomain' ) {
if ( ! isset ( $options [ 'posixAccount_' . $typeId . '_windowsIDPoolDNUsers' ][ 0 ]) || ! get_preg ( $options [ 'posixAccount_' . $typeId . '_windowsIDPoolDNUsers' ][ 0 ], 'dn' )) {
$return [] = $this -> messages [ 'windowsIDPoolDN' ][ 0 ];
}
2015-06-07 06:34:24 +00:00
}
}
2018-03-03 16:44:28 +00:00
// host settings
if ( getScopeFromTypeId ( $typeId ) === 'host' ) {
if ( $options [ 'posixAccount_' . $typeId . '_uidGeneratorHosts' ][ 0 ] == 'range' ) {
// min/maxUID are required, check if they are numeric
if ( ! isset ( $options [ 'posixAccount_' . $typeId . '_minMachine' ][ 0 ]) || ! preg_match ( '/^[0-9]+$/' , $options [ 'posixAccount_' . $typeId . '_minMachine' ][ 0 ])) {
$return [] = $this -> messages [ 'minMachine' ][ 0 ];
2013-02-17 13:19:50 +00:00
}
2018-03-03 16:44:28 +00:00
if ( ! isset ( $options [ 'posixAccount_' . $typeId . '_maxMachine' ][ 0 ]) || ! preg_match ( '/^[0-9]+$/' , $options [ 'posixAccount_' . $typeId . '_maxMachine' ][ 0 ])) {
$return [] = $this -> messages [ 'maxMachine' ][ 0 ];
}
// minUID < maxUID
if ( isset ( $options [ 'posixAccount_' . $typeId . '_minMachine' ][ 0 ]) && isset ( $options [ 'posixAccount_' . $typeId . '_maxMachine' ][ 0 ])) {
2019-02-01 19:27:49 +00:00
if ( $options [ 'posixAccount_' . $typeId . '_minMachine' ][ 0 ] >= $options [ 'posixAccount_' . $typeId . '_maxMachine' ][ 0 ]) {
2018-03-03 16:44:28 +00:00
$return [] = $this -> messages [ 'cmp_Machine' ][ 0 ];
}
}
$ranges [] = array ( $options [ 'posixAccount_' . $typeId . '_minMachine' ][ 0 ], $options [ 'posixAccount_' . $typeId . '_maxMachine' ][ 0 ]);
2013-02-17 13:19:50 +00:00
}
2018-03-03 16:44:28 +00:00
elseif ( $options [ 'posixAccount_' . $typeId . '_uidGeneratorHosts' ][ 0 ] == 'sambaPool' ) {
if ( ! isset ( $options [ 'posixAccount_' . $typeId . '_sambaIDPoolDNHosts' ][ 0 ]) || ! get_preg ( $options [ 'posixAccount_' . $typeId . '_sambaIDPoolDNHosts' ][ 0 ], 'dn' )) {
$return [] = $this -> messages [ 'sambaIDPoolDN' ][ 0 ];
}
2004-08-01 09:39:24 +00:00
}
2018-03-03 16:44:28 +00:00
elseif ( $options [ 'posixAccount_' . $typeId . '_uidGeneratorHosts' ][ 0 ] == 'windowsDomain' ) {
if ( ! isset ( $options [ 'posixAccount_' . $typeId . '_windowsIDPoolDNHosts' ][ 0 ]) || ! get_preg ( $options [ 'posixAccount_' . $typeId . '_windowsIDPoolDNHosts' ][ 0 ], 'dn' )) {
$return [] = $this -> messages [ 'windowsIDPoolDN' ][ 0 ];
}
2015-06-07 06:34:24 +00:00
}
}
2004-08-01 09:39:24 +00:00
}
// check if user and host ranges overlap
2018-03-03 16:44:28 +00:00
foreach ( $ranges as $range ) {
foreach ( $ranges as $rangeToCompare ) {
// check if minimum is inside other range
if (( $rangeToCompare [ 0 ] > $range [ 0 ]) && ( $rangeToCompare [ 0 ] < $range [ 1 ])) {
2004-09-26 13:48:52 +00:00
$return [] = $this -> messages [ 'cmp_both' ][ 0 ];
2018-03-03 16:44:28 +00:00
break 2 ;
2004-08-01 09:39:24 +00:00
}
2018-03-03 16:44:28 +00:00
// check if maximum is inside other range
if (( $rangeToCompare [ 1 ] > $range [ 0 ]) && ( $rangeToCompare [ 1 ] < $range [ 1 ])) {
2004-09-26 13:48:52 +00:00
$return [] = $this -> messages [ 'cmp_both' ][ 0 ];
2018-03-03 16:44:28 +00:00
break 2 ;
2004-08-01 09:39:24 +00:00
}
}
}
return $return ;
2004-10-30 17:00:34 +00:00
}
2017-05-10 17:23:28 +00:00
/**
* { @ inheritDoc }
* @ see baseModule :: getManagedAttributes ()
*/
2017-05-20 08:55:26 +00:00
function get_uploadColumns ( $selectedModules , & $type ) {
2018-03-03 16:44:28 +00:00
$typeId = $type -> getId ();
2017-05-20 08:55:26 +00:00
$return = parent :: get_uploadColumns ( $selectedModules , $type );
2019-06-05 17:24:46 +00:00
if ( $this -> isPasswordManaged ( $typeId )) {
$return [] = array (
'name' => 'posixAccount_password' ,
'description' => _ ( 'Password' ),
'help' => 'userPassword' ,
'example' => _ ( 'secret' )
);
$return [] = array (
'name' => 'posixAccount_passwordDisabled' ,
'description' => _ ( 'Lock password' ),
'help' => 'userPassword_lock' ,
'example' => 'false' ,
'values' => 'true, false' ,
'default' => 'false'
);
}
2017-05-10 17:23:28 +00:00
if (( $this -> get_scope () == 'user' ) && $this -> manageCn ( $selectedModules )) {
2017-06-05 09:03:20 +00:00
array_unshift ( $return , array (
2017-05-10 17:23:28 +00:00
'name' => 'posixAccount_cn' ,
'description' => _ ( 'Common name' ),
'help' => 'cn' ,
'example' => _ ( 'Steve Miller' )
));
}
2018-03-03 16:44:28 +00:00
if (( $this -> get_scope () == 'user' ) && ! $this -> isBooleanConfigOptionSet ( 'posixAccount_' . $typeId . '_hidegecos' )) {
2018-03-04 08:37:32 +00:00
$return [] = array (
2018-03-03 16:44:28 +00:00
'name' => 'posixAccount_gecos' ,
'description' => _ ( 'Gecos' ),
'help' => 'gecos' ,
'example' => _ ( 'Steve Miller,Room 2.14,123-123-1234,123-123-1234' )
);
}
if (( $this -> get_scope () == 'host' ) && ! $this -> isBooleanConfigOptionSet ( 'posixAccount_' . $typeId . '_hidegecos' )) {
2018-03-04 08:37:32 +00:00
$return [] = array (
2018-03-03 16:44:28 +00:00
'name' => 'posixAccount_gecos' ,
'description' => _ ( 'Gecos' ),
'help' => 'gecos' ,
'example' => _ ( 'pc01,Room 2.34' )
);
}
2017-05-10 17:23:28 +00:00
return $return ;
}
2004-10-30 17:00:34 +00:00
/**
2017-05-20 09:46:49 +00:00
* { @ inheritDoc }
* @ see baseModule :: build_uploadAccounts ()
*/
function build_uploadAccounts ( $rawAccounts , $ids , & $partialAccounts , $selectedModules , & $type ) {
2006-05-18 08:50:51 +00:00
$errors = array ();
2018-03-03 16:44:28 +00:00
$typeId = $type -> getId ();
2017-05-10 17:23:28 +00:00
$pwdAttrName = $this -> getPasswordAttrName ( $selectedModules );
$homedirAttrName = $this -> getHomedirAttrName ( $selectedModules );
2005-03-25 14:21:07 +00:00
$needAutoUID = array ();
2005-06-08 21:02:01 +00:00
// get list of existing users
2018-03-03 16:44:28 +00:00
$existingUsers = $this -> getUserNames ( $typeId );
2005-06-08 21:02:01 +00:00
// get list of existing groups
2017-05-10 17:23:28 +00:00
$groupList = $this -> findGroups ( $selectedModules );
2009-11-26 10:48:05 +00:00
$groupMap = array ();
for ( $i = 0 ; $i < sizeof ( $groupList ); $i ++ ) {
$groupMap [ $groupList [ $i ][ 1 ]] = $groupList [ $i ][ 0 ];
}
$existingGroups = array_keys ( $groupMap );
2011-10-06 20:03:45 +00:00
// get list of existing group of names
2012-04-09 13:20:24 +00:00
if ( self :: areGroupOfNamesActive ()) {
2011-10-06 20:03:45 +00:00
$gons = $this -> findGroupOfNames ();
$gonList = array ();
foreach ( $gons as $dn => $attr ) {
$gonList [] = $attr [ 'cn' ][ 0 ];
}
}
2005-06-08 21:02:01 +00:00
// check input
2014-09-21 15:06:11 +00:00
foreach ( $rawAccounts as $i => $rawAccount ) {
2016-05-09 18:10:14 +00:00
if ( ! $this -> skipObjectClass () && ! in_array ( " posixAccount " , $partialAccounts [ $i ][ 'objectClass' ])) {
$partialAccounts [ $i ][ 'objectClass' ][] = " posixAccount " ;
}
2004-10-16 14:28:06 +00:00
// UID
2014-09-21 15:06:11 +00:00
if ( $rawAccount [ $ids [ 'posixAccount_uid' ]] == " " ) {
2005-03-25 14:21:07 +00:00
// autoUID
$needAutoUID [] = $i ;
2004-10-16 14:28:06 +00:00
}
2014-09-21 15:06:11 +00:00
elseif ( get_preg ( $rawAccount [ $ids [ 'posixAccount_uid' ]], 'digit' )) {
2018-03-03 16:44:28 +00:00
if (( $this -> get_scope () == 'user' ) && ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidGeneratorUsers' ][ 0 ] == 'range' )) {
if (( $rawAccount [ $ids [ 'posixAccount_uid' ]] > $this -> moduleSettings [ 'posixAccount_' . $typeId . '_minUID' ][ 0 ]) &&
( $rawAccount [ $ids [ 'posixAccount_uid' ]] < $this -> moduleSettings [ 'posixAccount_' . $typeId . '_maxUID' ][ 0 ])) {
2014-09-21 15:06:11 +00:00
$partialAccounts [ $i ][ 'uidNumber' ] = trim ( $rawAccount [ $ids [ 'posixAccount_uid' ]]);
2006-09-23 09:50:29 +00:00
}
else {
$errMsg = $this -> messages [ 'uidNumber' ][ 4 ];
array_push ( $errMsg , array ( $i ));
$errors [] = $errMsg ;
}
2004-11-01 11:49:43 +00:00
}
2018-03-03 16:44:28 +00:00
elseif (( $this -> get_scope () == 'host' ) && ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidGeneratorHosts' ][ 0 ] == 'range' )) {
if (( $rawAccount [ $ids [ 'posixAccount_uid' ]] > $this -> moduleSettings [ 'posixAccount_' . $typeId . '_minMachine' ][ 0 ]) &&
( $rawAccount [ $ids [ 'posixAccount_uid' ]] < $this -> moduleSettings [ 'posixAccount_' . $typeId . '_maxMachine' ][ 0 ])) {
2014-09-21 15:06:11 +00:00
$partialAccounts [ $i ][ 'uidNumber' ] = trim ( $rawAccount [ $ids [ 'posixAccount_uid' ]]);
2006-09-23 09:50:29 +00:00
}
else {
$errMsg = $this -> messages [ 'uidNumber' ][ 4 ];
array_push ( $errMsg , array ( $i ));
$errors [] = $errMsg ;
}
2004-11-01 11:49:43 +00:00
}
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 ));
2006-05-18 08:50:51 +00:00
$errors [] = $errMsg ;
2004-10-16 14:28:06 +00:00
}
// GID number
2014-09-21 15:06:11 +00:00
if ( get_preg ( $rawAccount [ $ids [ 'posixAccount_group' ]], 'digit' )) {
$partialAccounts [ $i ][ 'gidNumber' ] = $rawAccount [ $ids [ 'posixAccount_group' ]];
2004-10-16 14:28:06 +00:00
}
2014-09-21 15:06:11 +00:00
if ( get_preg ( $rawAccount [ $ids [ 'posixAccount_group' ]], 'groupname' )) {
2018-05-20 07:31:06 +00:00
$groupName = $rawAccount [ $ids [ 'posixAccount_group' ]];
$gid = nuLL ;
if ( isset ( $groupMap [ $groupName ])) {
$gid = $groupMap [ $groupName ];
}
2004-10-17 18:29:39 +00:00
if ( is_numeric ( $gid )) {
$partialAccounts [ $i ][ 'gidNumber' ] = $gid ;
}
else {
$errMsg = $this -> messages [ 'gidNumber' ][ 0 ];
array_push ( $errMsg , array ( $i ));
2006-05-18 08:50:51 +00:00
$errors [] = $errMsg ;
2004-10-17 18:29:39 +00:00
}
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 ));
2006-05-18 08:50:51 +00:00
$errors [] = $errMsg ;
2004-10-16 14:28:06 +00:00
}
2005-06-07 18:28:28 +00:00
// GECOS
2018-03-03 16:44:28 +00:00
if ( ! $this -> isBooleanConfigOptionSet ( 'posixAccount_' . $typeId . '_hidegecos' )) {
2016-12-07 20:17:20 +00:00
if ( ! empty ( $rawAccount [ $ids [ 'posixAccount_gecos' ]])) {
2014-09-21 15:06:11 +00:00
if ( get_preg ( $rawAccount [ $ids [ 'posixAccount_gecos' ]], 'gecos' )) {
$partialAccounts [ $i ][ 'gecos' ] = $this -> checkASCII ( $rawAccount [ $ids [ 'posixAccount_gecos' ]]);
2013-03-24 10:03:35 +00:00
}
else {
$errMsg = $this -> messages [ 'gecos' ][ 0 ];
array_push ( $errMsg , array ( $i ));
$errors [] = $errMsg ;
}
2005-06-07 18:28:28 +00:00
}
else {
2013-03-24 10:03:35 +00:00
$gecos = " " ;
2014-09-21 15:06:11 +00:00
if (( $rawAccount [ $ids [ 'inetOrgPerson_firstName' ]] != " " ) && ( $rawAccount [ $ids [ 'inetOrgPerson_lastName' ]] != " " )) {
$gecos = $rawAccount [ $ids [ 'inetOrgPerson_firstName' ]] . " " . $rawAccount [ $ids [ 'inetOrgPerson_lastName' ]];
2016-12-07 20:17:20 +00:00
if ( ! empty ( $rawAccount [ $ids [ 'inetOrgPerson_telephone' ]])) {
2014-09-21 15:06:11 +00:00
$gecos = $gecos . " ,, " . $rawAccount [ $ids [ 'inetOrgPerson_telephone' ]]; // double "," because room is unknown
2016-12-07 20:17:20 +00:00
if ( ! empty ( $rawAccount [ $ids [ 'inetOrgPerson_fax' ]])) {
2014-09-21 15:06:11 +00:00
$gecos = $gecos . " , " . $rawAccount [ $ids [ 'inetOrgPerson_fax' ]];
2013-03-24 10:03:35 +00:00
}
2005-06-07 18:28:28 +00:00
}
}
2016-12-07 20:17:20 +00:00
if ( ! empty ( $gecos )) {
2013-03-24 10:03:35 +00:00
$partialAccounts [ $i ][ 'gecos' ] = $this -> checkASCII ( $gecos );
}
2008-09-16 17:11:44 +00:00
}
2004-10-16 14:28:06 +00:00
}
// user specific attributes
2007-10-04 16:45:05 +00:00
if ( $this -> get_scope () == 'user' ) {
2005-06-08 21:02:01 +00:00
// additional groups
2014-09-21 15:06:11 +00:00
if ( $rawAccount [ $ids [ 'posixAccount_additionalGroups' ]] != " " ) {
$groups = explode ( " , " , $rawAccount [ $ids [ 'posixAccount_additionalGroups' ]]);
2005-06-08 21:02:01 +00:00
for ( $g = 0 ; $g < sizeof ( $groups ); $g ++ ) {
if ( ! in_array ( $groups [ $g ], $existingGroups )) {
2006-05-18 08:50:51 +00:00
$errors [] = array ( 'ERROR' , _ ( 'Unable to find group in LDAP.' ), $groups [ $g ]);
2005-06-08 21:02:01 +00:00
}
}
}
2011-10-06 20:03:45 +00:00
// group of names
2014-09-21 15:06:11 +00:00
if ( self :: areGroupOfNamesActive () && ( $rawAccount [ $ids [ 'posixAccount_gon' ]] != " " )) {
$groups = explode ( " , " , $rawAccount [ $ids [ 'posixAccount_gon' ]]);
2011-10-06 20:03:45 +00:00
for ( $g = 0 ; $g < sizeof ( $groups ); $g ++ ) {
if ( ! in_array ( $groups [ $g ], $gonList )) {
2011-10-30 18:07:36 +00:00
$errors [] = array ( 'ERROR' , _ ( 'Unable to find group in LDAP.' ), $groups [ $g ]);
2011-10-06 20:03:45 +00:00
}
}
}
2004-10-16 14:28:06 +00:00
// user name
2018-04-11 16:40:44 +00:00
if ( array_key_exists ( $rawAccount [ $ids [ 'posixAccount_userName' ]], $existingUsers )) {
2014-09-21 15:06:11 +00:00
$userName = $rawAccount [ $ids [ 'posixAccount_userName' ]];
2018-04-11 16:40:44 +00:00
while ( array_key_exists ( $userName , $existingUsers )) {
2018-08-15 08:43:10 +00:00
$userName = $this -> getNextUserName ( $userName , $selectedModules );
2012-09-23 17:59:14 +00:00
}
2005-06-08 21:02:01 +00:00
$errMsg = $this -> messages [ 'uid' ][ 9 ];
2018-04-11 16:40:44 +00:00
array_push ( $errMsg , array ( $i , $userName , $rawAccount [ $ids [ 'posixAccount_userName' ]],
htmlspecialchars ( $existingUsers [ $rawAccount [ $ids [ 'posixAccount_userName' ]]])));
2006-05-18 08:50:51 +00:00
$errors [] = $errMsg ;
2005-06-08 21:02:01 +00:00
}
2018-08-12 08:38:56 +00:00
if ( get_preg ( $rawAccount [ $ids [ 'posixAccount_userName' ]], 'username' )) {
2014-09-21 15:06:11 +00:00
$partialAccounts [ $i ][ 'uid' ] = $rawAccount [ $ids [ 'posixAccount_userName' ]];
2004-10-16 14:28:06 +00:00
}
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 ));
2006-05-18 08:50:51 +00:00
$errors [] = $errMsg ;
2004-10-16 14:28:06 +00:00
}
// home directory
2014-09-21 15:06:11 +00:00
if ( $rawAccount [ $ids [ 'posixAccount_homedir' ]] == " " ) {
2013-08-18 14:19:37 +00:00
$partialAccounts [ $i ][ $homedirAttrName ] = '/home/' . $partialAccounts [ $i ][ 'uid' ];
2004-10-16 14:28:06 +00:00
}
2014-09-21 15:06:11 +00:00
elseif ( get_preg ( $rawAccount [ $ids [ 'posixAccount_homedir' ]], 'homeDirectory' )) {
$partialAccounts [ $i ][ $homedirAttrName ] = $rawAccount [ $ids [ 'posixAccount_homedir' ]];
2004-10-16 14:28:06 +00:00
}
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 ));
2006-05-18 08:50:51 +00:00
$errors [] = $errMsg ;
2004-10-16 14:28:06 +00:00
}
// login shell
2014-09-21 15:06:11 +00:00
if ( $rawAccount [ $ids [ 'posixAccount_shell' ]] == " " ) {
2004-10-16 14:28:06 +00:00
$partialAccounts [ $i ][ 'loginShell' ] = '/bin/bash' ;
}
2014-09-21 15:06:11 +00:00
elseif ( in_array ( $rawAccount [ $ids [ 'posixAccount_shell' ]], $this -> getShells ())) {
$partialAccounts [ $i ][ 'loginShell' ] = $rawAccount [ $ids [ 'posixAccount_shell' ]];
2004-10-16 14:28:06 +00:00
}
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 ));
2006-05-18 08:50:51 +00:00
$errors [] = $errMsg ;
2004-10-16 14:28:06 +00:00
}
2019-06-05 17:24:46 +00:00
if ( $this -> isPasswordManaged ( $typeId )) {
2004-10-16 14:28:06 +00:00
$pwd_enabled = true ;
2019-06-05 17:24:46 +00:00
// password enabled/disabled
if ( $rawAccount [ $ids [ 'posixAccount_passwordDisabled' ]] == " " ) {
$pwd_enabled = true ;
}
elseif ( in_array ( $rawAccount [ $ids [ 'posixAccount_passwordDisabled' ]], array ( 'true' , 'false' ))) {
if ( $rawAccount [ $ids [ 'posixAccount_passwordDisabled' ]] == 'true' ) {
$pwd_enabled = false ;
}
else {
$pwd_enabled = true ;
}
2015-02-11 16:57:38 +00:00
}
2019-06-05 17:24:46 +00:00
else {
$errMsg = $this -> messages [ 'passwordDisabled' ][ 0 ];
2015-02-11 16:57:38 +00:00
array_push ( $errMsg , array ( $i ));
$errors [] = $errMsg ;
}
2019-06-05 17:24:46 +00:00
// password
// delay exop passwords
if ( ! empty ( $this -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ]) && ( $this -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ] === 'LDAP_EXOP' )) {
// changed in post action
}
// set SASL passwords
elseif ( ! empty ( $this -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ]) && ( $this -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ] === 'SASL' )) {
$partialAccounts [ $i ][ $pwdAttrName ] = '{SASL}' . $partialAccounts [ $i ][ 'uid' ];
}
// set K5KEY password
elseif ( ! empty ( $this -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ]) && ( $this -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ] === 'K5KEY' )) {
$partialAccounts [ $i ][ $pwdAttrName ] = pwd_hash ( 'x' , true , $this -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ]);
}
// set normal password
else {
if (( $rawAccount [ $ids [ 'posixAccount_password' ]] != " " ) && ( get_preg ( $rawAccount [ $ids [ 'posixAccount_password' ]], 'password' ))) {
$partialAccounts [ $i ][ $pwdAttrName ] = pwd_hash ( $rawAccount [ $ids [ 'posixAccount_password' ]], $pwd_enabled , $this -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ]);
$partialAccounts [ $i ][ 'INFO.userPasswordClearText' ] = $rawAccount [ $ids [ 'posixAccount_password' ]]; // for custom scripts etc.
}
elseif ( $rawAccount [ $ids [ 'posixAccount_password' ]] != " " ) {
$errMsg = $this -> messages [ 'userPassword' ][ 4 ];
$errMsg [ 2 ] = str_replace ( '%' , '%%' , $errMsg [ 2 ]); // double "%" because of later sprintf
array_push ( $errMsg , array ( $i ));
$errors [] = $errMsg ;
}
}
2004-10-16 14:28:06 +00:00
}
2005-06-19 09:38:44 +00:00
// cn
2017-05-10 17:23:28 +00:00
if ( $this -> manageCn ( $selectedModules )) {
2014-09-21 15:06:11 +00:00
if ( $rawAccount [ $ids [ 'posixAccount_cn' ]] != " " ) {
if ( get_preg ( $rawAccount [ $ids [ 'posixAccount_cn' ]], 'cn' )) {
$partialAccounts [ $i ][ 'cn' ] = $rawAccount [ $ids [ 'posixAccount_cn' ]];
2013-08-18 12:24:53 +00:00
}
else {
$errMsg = $this -> messages [ 'cn' ][ 1 ];
array_push ( $errMsg , array ( $i ));
$errors [] = $errMsg ;
}
2005-06-19 09:38:44 +00:00
}
else {
2013-08-18 12:24:53 +00:00
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' ];
}
2005-06-19 09:38:44 +00:00
}
}
2004-10-16 14:28:06 +00:00
}
// host specific attributes
2007-10-04 16:45:05 +00:00
elseif ( $this -> get_scope () == 'host' ) {
2004-10-16 14:28:06 +00:00
// host name
2018-04-11 16:40:44 +00:00
if ( array_key_exists ( $rawAccount [ $ids [ 'posixAccount_hostName' ]], $existingUsers )) {
2014-09-21 15:06:11 +00:00
$userName = $rawAccount [ $ids [ 'posixAccount_hostName' ]];
2018-04-11 16:40:44 +00:00
while ( array_key_exists ( $userName , $existingUsers )) {
2018-08-15 08:43:10 +00:00
$userName = $this -> getNextUserName ( $userName , $selectedModules );
2012-09-23 17:59:14 +00:00
}
2005-06-08 21:02:01 +00:00
$errMsg = $this -> messages [ 'uid' ][ 10 ];
2018-04-11 16:40:44 +00:00
array_push ( $errMsg , array ( $i , $userName , $rawAccount [ $ids [ 'posixAccount_hostName' ]],
2018-08-15 08:43:10 +00:00
htmlspecialchars ( $existingUsers [ $rawAccount [ $ids [ 'posixAccount_hostName' ]]])));
2006-05-18 08:50:51 +00:00
$errors [] = $errMsg ;
2005-06-08 21:02:01 +00:00
}
2018-08-12 08:38:56 +00:00
if ( get_preg ( $rawAccount [ $ids [ 'posixAccount_hostName' ]], 'hostname' )) {
2014-09-21 15:06:11 +00:00
$partialAccounts [ $i ][ 'uid' ] = $rawAccount [ $ids [ 'posixAccount_hostName' ]];
$partialAccounts [ $i ][ 'cn' ] = $rawAccount [ $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 ));
2006-05-18 08:50:51 +00:00
$errors [] = $errMsg ;
2004-10-16 14:28:06 +00:00
}
2004-11-05 16:53:38 +00:00
// description
2014-09-21 15:06:11 +00:00
if ( isset ( $ids [ 'posixAccount_description' ]) && isset ( $rawAccount [ $ids [ 'posixAccount_description' ]]) && ( $rawAccount [ $ids [ 'posixAccount_description' ]] != '' )) {
$partialAccounts [ $i ][ 'description' ] = $rawAccount [ $ids [ 'posixAccount_description' ]];
2004-11-05 16:53:38 +00:00
}
else {
2014-09-21 15:06:11 +00:00
$partialAccounts [ $i ][ 'description' ] = $rawAccount [ $ids [ 'posixAccount_hostName' ]];
2004-11-05 16:53:38 +00:00
}
2013-08-18 14:19:37 +00:00
$partialAccounts [ $i ][ $homedirAttrName ] = '/dev/null' ;
2004-10-16 14:28:06 +00:00
$partialAccounts [ $i ][ 'loginShell' ] = '/bin/false' ;
}
}
2005-03-25 14:21:07 +00:00
// fill in autoUIDs
if ( sizeof ( $needAutoUID ) > 0 ) {
$errorsTemp = array ();
2018-03-03 16:44:28 +00:00
$uids = $this -> getNextUIDs ( sizeof ( $needAutoUID ), $errorsTemp , $typeId );
2005-03-25 14:21:07 +00:00
if ( is_array ( $uids )) {
2014-09-21 15:06:11 +00:00
foreach ( $needAutoUID as $i => $index ) {
$partialAccounts [ $index ][ 'uidNumber' ] = $uids [ $i ];
2005-03-25 14:21:07 +00:00
}
}
else {
2006-05-18 08:50:51 +00:00
$errors [] = $this -> messages [ 'uidNumber' ][ 2 ];
2005-03-25 14:21:07 +00:00
}
}
2006-05-18 08:50:51 +00:00
return $errors ;
2004-10-16 14:28:06 +00:00
}
2006-08-13 12:58:19 +00:00
2004-10-23 11:54:44 +00:00
/**
2017-05-10 17:23:28 +00:00
* { @ inheritDoc }
* @ see baseModule :: doUploadPostActions ()
*/
2017-09-02 11:03:36 +00:00
function doUploadPostActions ( & $data , $ids , $failed , & $temp , & $accounts , $selectedModules , $type ) {
2014-01-15 20:48:52 +00:00
if ( ! checkIfWriteAccessIsAllowed ( $this -> get_scope ())) {
2007-12-30 16:08:54 +00:00
die ();
}
2017-05-10 17:23:28 +00:00
$homeDirAttr = $this -> getHomedirAttrName ( $selectedModules );
2016-01-09 19:20:28 +00:00
if ( $this -> get_scope () != 'user' ) {
return array (
'status' => 'finished' ,
'progress' => 100 ,
'errors' => array ()
);
}
2004-10-23 11:54:44 +00:00
// on first call generate list of ldap operations
if ( ! isset ( $temp [ 'counter' ])) {
2004-10-24 09:50:02 +00:00
$temp [ 'groups' ] = array ();
2011-10-06 20:03:45 +00:00
$temp [ 'dn_gon' ] = array ();
2007-07-09 19:03:19 +00:00
$temp [ 'createHomes' ] = array ();
2018-07-07 12:05:39 +00:00
$temp [ 'exop' ] = array ();
2004-10-23 11:54:44 +00:00
$temp [ 'counter' ] = 0 ;
$col = $ids [ 'posixAccount_additionalGroups' ];
2007-07-09 19:03:19 +00:00
$col_home = $ids [ 'posixAccount_createHomeDir' ];
2009-11-26 10:48:05 +00:00
// get list of existing groups
2017-05-10 17:23:28 +00:00
$groupList = $this -> findGroups ( $selectedModules );
2009-11-26 10:48:05 +00:00
$groupMap = array ();
for ( $i = 0 ; $i < sizeof ( $groupList ); $i ++ ) {
$groupMap [ $groupList [ $i ][ 0 ]] = $groupList [ $i ][ 1 ];
}
2011-10-06 20:03:45 +00:00
// get list of existing group of names
2012-04-09 13:20:24 +00:00
if ( self :: areGroupOfNamesActive ()) {
2011-10-06 20:03:45 +00:00
$gonList = $this -> findGroupOfNames ();
$gonMap = array ();
foreach ( $gonList as $dn => $attr ) {
$gonMap [ $attr [ 'cn' ][ 0 ]] = $dn ;
}
}
2014-09-21 18:09:44 +00:00
foreach ( $data as $i => $dataRow ) {
2004-10-24 09:50:02 +00:00
if ( in_array ( $i , $failed )) continue ; // ignore failed accounts
2014-09-21 18:09:44 +00:00
if ( $dataRow [ $col ] != " " ) {
$groups = explode ( " , " , $dataRow [ $col ]);
2008-03-15 19:12:19 +00:00
if ( isset ( $this -> moduleSettings [ 'posixAccount_primaryGroupAsSecondary' ][ 0 ])
&& ( $this -> moduleSettings [ 'posixAccount_primaryGroupAsSecondary' ][ 0 ] == 'true' )) {
2014-09-21 18:09:44 +00:00
if ( get_preg ( $dataRow [ $ids [ 'posixAccount_group' ]], 'digit' )) {
if ( ! in_array ( $groupMap [ $dataRow [ $ids [ 'posixAccount_group' ]]], $groups )) {
$groups [] = $groupMap [ $dataRow [ $ids [ 'posixAccount_group' ]]];
2008-03-15 19:12:19 +00:00
}
}
else {
2014-09-21 18:09:44 +00:00
if ( ! in_array ( $groupMap [ $dataRow [ $ids [ 'posixAccount_group' ]]], $groups )) {
$groups [] = $dataRow [ $ids [ 'posixAccount_group' ]];
2008-03-15 19:12:19 +00:00
}
}
}
2004-10-23 11:54:44 +00:00
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 ];
2014-09-21 18:09:44 +00:00
$temp [ 'members' ][ $groups [ $g ]][] = $dataRow [ $ids [ 'posixAccount_userName' ]];
2004-10-23 11:54:44 +00:00
}
}
2014-09-21 18:09:44 +00:00
if ( isset ( $ids [ 'posixAccount_gon' ]) && ( $dataRow [ $ids [ 'posixAccount_gon' ]] != " " )) {
$gons = explode ( " , " , $dataRow [ $ids [ 'posixAccount_gon' ]]);
2011-10-06 20:03:45 +00:00
$memberAttr = 'member' ;
for ( $g = 0 ; $g < sizeof ( $gons ); $g ++ ) {
2019-03-05 16:59:33 +00:00
if ( in_array_ignore_case ( 'groupOfUniqueNames' , $gonList [ $gonMap [ $gons [ $g ]]][ 'objectclass' ])) {
2011-10-06 20:03:45 +00:00
$memberAttr = 'uniqueMember' ;
}
$temp [ 'dn_gon' ][ $gonMap [ $gons [ $g ]]][ $memberAttr ][] = $accounts [ $i ][ 'dn' ];
}
}
2016-12-07 20:17:20 +00:00
if ( ! empty ( $dataRow [ $col_home ])) {
2007-07-09 19:03:19 +00:00
$temp [ 'createHomes' ][] = $i ;
}
2018-07-07 12:05:39 +00:00
if ( ! empty ( $this -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ]) && ( $this -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ] === 'LDAP_EXOP' )) {
if ( isset ( $ids [ 'posixAccount_password' ]) && ! empty ( $dataRow [ $ids [ 'posixAccount_password' ]])) {
$temp [ 'exop' ][] = array ( $accounts [ $i ][ 'dn' ], $dataRow [ $ids [ 'posixAccount_password' ]]);
}
}
2004-10-23 11:54:44 +00:00
}
2011-10-06 20:03:45 +00:00
$temp [ 'dn_gon_keys' ] = array_keys ( $temp [ 'dn_gon' ]);
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 ();
2010-11-23 21:12:13 +00:00
$ldapEntries = searchLDAPByAttribute ( 'cn' , '*' , 'posixGroup' , array ( 'dn' , 'cn' ), array ( 'group' ));
for ( $i = 0 ; $i < sizeof ( $ldapEntries ); $i ++ ) {
$temp [ 'dn' ][ $ldapEntries [ $i ][ 'cn' ][ 0 ]] = $ldapEntries [ $i ][ 'dn' ];
2004-10-24 09:50:02 +00:00
}
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' ]]])) {
2018-08-18 08:32:39 +00:00
$memberUid = $temp [ 'members' ][ $temp [ 'groups' ][ $temp [ 'counter' ]]];
$dnToUpdate = $temp [ 'dn' ][ $temp [ 'groups' ][ $temp [ 'counter' ]]];
$groupAttrs = ldapGetDN ( $dnToUpdate , array ( 'memberUID' ));
if ( ! empty ( $groupAttrs [ 'memberuid' ])) {
// skip members that are already set
$memberUid = array_delete ( $groupAttrs [ 'memberuid' ], $memberUid );
}
if ( ! empty ( $memberUid )) {
$toAdd = array ( 'memberUID' => $memberUid );
$success = @ ldap_mod_add ( $_SESSION [ 'ldap' ] -> server (), $dnToUpdate , $toAdd );
$errors = array ();
if ( ! $success ) {
$errors [] = array (
" ERROR " ,
_ ( " LAM was unable to modify group memberships for group: %s " ),
getDefaultLDAPErrorString ( $_SESSION [ 'ldap' ] -> server ()),
array ( $temp [ 'groups' ][ $temp [ 'counter' ]])
);
}
2004-10-24 09:50:02 +00:00
}
$temp [ 'counter' ] ++ ;
return array (
'status' => 'inProgress' ,
2018-07-07 12:05:39 +00:00
'progress' => ( $temp [ 'counter' ] * 100 ) / ( sizeof ( $temp [ 'groups' ]) + sizeof ( $temp [ 'createHomes' ]) + sizeof ( $temp [ 'dn_gon' ]) + sizeof ( $temp [ 'exop' ])),
2004-10-24 09:50:02 +00:00
'errors' => $errors
);
}
else {
$temp [ 'counter' ] ++ ;
return array (
'status' => 'inProgress' ,
2018-07-07 12:05:39 +00:00
'progress' => ( $temp [ 'counter' ] * 100 ) / ( sizeof ( $temp [ 'groups' ] + sizeof ( $temp [ 'createHomes' ]) + sizeof ( $temp [ 'dn_gon' ]) + sizeof ( $temp [ 'exop' ]))),
2004-10-24 09:50:02 +00:00
'errors' => array ( array ( 'ERROR' , _ ( 'Unable to find group in LDAP.' ), $temp [ 'groups' ][ $temp [ 'counter' ]]))
);
}
}
2007-07-09 19:03:19 +00:00
// create home directories
elseif ( $temp [ 'counter' ] < ( sizeof ( $temp [ 'groups' ]) + sizeof ( $temp [ 'createHomes' ]))) {
$pos = $temp [ 'createHomes' ][ $temp [ 'counter' ] - sizeof ( $temp [ 'groups' ])];
2018-03-04 08:37:32 +00:00
try {
$remote = new \LAM\REMOTE\Remote ();
2019-10-23 19:14:54 +00:00
$remoteServer = $_SESSION [ 'config' ] -> getScriptServerByName ( $data [ $pos ][ $ids [ 'posixAccount_createHomeDir' ]]);
$remote -> connect ( $remoteServer );
2018-03-04 08:37:32 +00:00
$result = $remote -> execute (
implode (
self :: $SPLIT_DELIMITER ,
array (
$data [ $pos ][ $ids [ 'posixAccount_userName' ]],
" home " ,
" add " ,
2019-10-26 15:28:24 +00:00
$remoteServer -> getHomeDirPrefix () . $accounts [ $pos ][ $homeDirAttr ],
2018-03-04 08:37:32 +00:00
" 0 " . $_SESSION [ 'config' ] -> get_scriptRights (),
$accounts [ $pos ][ 'uidNumber' ],
$accounts [ $pos ][ 'gidNumber' ],
)
));
$remote -> disconnect ();
$errors = array ();
if ( ! empty ( $result )) {
$parts = explode ( " , " , $result );
if ( in_array ( $parts [ 0 ], array ( 'ERROR' , 'WARN' ))) {
$errors [] = $parts ;
}
2007-07-09 19:03:19 +00:00
}
}
2018-03-04 08:37:32 +00:00
catch ( LAMException $e ) {
$errors [] = array ( 'ERROR' , $e -> getTitle (), $e -> getMessage ());
}
2007-07-09 19:03:19 +00:00
$temp [ 'counter' ] ++ ;
return array (
'status' => 'inProgress' ,
2018-07-07 12:05:39 +00:00
'progress' => ( $temp [ 'counter' ] * 100 ) / ( sizeof ( $temp [ 'groups' ]) + sizeof ( $temp [ 'createHomes' ]) + sizeof ( $temp [ 'dn_gon' ]) + sizeof ( $temp [ 'exop' ])),
2011-10-06 20:03:45 +00:00
'errors' => $errors
);
}
// add users to group of names
elseif ( $temp [ 'counter' ] < ( sizeof ( $temp [ 'groups' ]) + sizeof ( $temp [ 'createHomes' ]) + sizeof ( $temp [ 'dn_gon' ]))) {
$gonDn = $temp [ 'dn_gon_keys' ][ $temp [ 'counter' ] - sizeof ( $temp [ 'groups' ]) - sizeof ( $temp [ 'createHomes' ])];
2018-08-18 08:48:44 +00:00
$gonAttrToAdd = $temp [ 'dn_gon' ][ $gonDn ];
$gonAttrNames = array_keys ( $gonAttrToAdd );
$gonAttrs = ldapGetDN ( $gonDn , $gonAttrNames );
foreach ( $gonAttrNames as $gonAttrName ) {
$gonAttrNameLower = strtolower ( $gonAttrName );
if ( ! empty ( $gonAttrs [ $gonAttrNameLower ])) {
$gonAttrToAdd [ $gonAttrName ] = array_delete ( $gonAttrs [ $gonAttrNameLower ], $gonAttrToAdd [ $gonAttrName ]);
}
if ( empty ( $gonAttrToAdd [ $gonAttrName ])) {
unset ( $gonAttrToAdd [ $gonAttrName ]);
}
}
if ( ! empty ( $gonAttrToAdd )) {
$success = @ ldap_mod_add ( $_SESSION [ 'ldap' ] -> server (), $gonDn , $gonAttrToAdd );
$errors = array ();
if ( ! $success ) {
$errors [] = array (
" ERROR " ,
_ ( " LAM was unable to modify group memberships for group: %s " ),
getDefaultLDAPErrorString ( $_SESSION [ 'ldap' ] -> server ()),
array ( $temp [ 'groups' ][ $temp [ 'counter' ]])
);
}
2011-10-06 20:03:45 +00:00
}
$temp [ 'counter' ] ++ ;
2018-07-07 12:05:39 +00:00
return array (
'status' => 'inProgress' ,
'progress' => ( $temp [ 'counter' ] * 100 ) / ( sizeof ( $temp [ 'groups' ]) + sizeof ( $temp [ 'createHomes' ]) + sizeof ( $temp [ 'dn_gon' ]) + sizeof ( $temp [ 'exop' ])),
'errors' => $errors
);
}
// run password exop commands
elseif ( $temp [ 'counter' ] < ( sizeof ( $temp [ 'groups' ]) + sizeof ( $temp [ 'createHomes' ]) + sizeof ( $temp [ 'dn_gon' ]) + sizeof ( $temp [ 'exop' ]))) {
$data = $temp [ 'exop' ][ $temp [ 'counter' ] - sizeof ( $temp [ 'groups' ]) - sizeof ( $temp [ 'createHomes' ]) - sizeof ( $temp [ 'dn_gon' ])];
$dn = $data [ 0 ];
$password = $data [ 1 ];
$success = ldap_exop_passwd ( $_SESSION [ 'ldap' ] -> server (), $dn , null , $password );
2011-10-06 20:03:45 +00:00
$errors = array ();
2018-07-07 12:05:39 +00:00
if ( ! $success ) {
$errors [] = array (
" ERROR " ,
_ ( 'Unable to set password' ),
$dn . '<br>' . getDefaultLDAPErrorString ( $_SESSION [ 'ldap' ] -> server ()),
array ( $temp [ 'groups' ][ $temp [ 'counter' ]])
);
}
$temp [ 'counter' ] ++ ;
2011-10-06 20:03:45 +00:00
return array (
'status' => 'inProgress' ,
2018-07-07 12:05:39 +00:00
'progress' => ( $temp [ 'counter' ] * 100 ) / ( sizeof ( $temp [ 'groups' ]) + sizeof ( $temp [ 'createHomes' ]) + sizeof ( $temp [ 'dn_gon' ]) + sizeof ( $temp [ 'exop' ])),
2007-07-09 19:03:19 +00:00
'errors' => $errors
);
}
2011-10-06 20:03:45 +00:00
// all modifications are done
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 .
2006-05-18 08:50:51 +00:00
* @ param array $errors list of error messages where errors can be added
2018-03-03 16:44:28 +00:00
* @ param string $typeId type id ( e . g . user )
2006-08-13 12:58:19 +00:00
* @ return mixed Null if no UIDs are free else an array of free UIDs .
2005-03-25 14:21:07 +00:00
*/
2018-03-03 16:44:28 +00:00
function getNextUIDs ( $count , & $errors , $typeId ) {
2013-02-17 13:19:50 +00:00
// check if UIDs should be taken from Samba pool entry
2018-03-03 16:44:28 +00:00
if (( $this -> get_scope () == 'user' ) && isset ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidGeneratorUsers' ]) && ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidGeneratorUsers' ][ 0 ] == 'sambaPool' )) {
return $this -> getNextSambaPoolUIDs ( $count , $errors , $typeId );
2013-02-17 13:19:50 +00:00
}
2018-03-03 16:44:28 +00:00
if (( $this -> get_scope () == 'host' ) && isset ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidGeneratorHosts' ]) && ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidGeneratorHosts' ][ 0 ] == 'sambaPool' )) {
return $this -> getNextSambaPoolUIDs ( $count , $errors , $typeId );
2013-02-17 13:19:50 +00:00
}
2015-06-07 06:34:24 +00:00
// check if UIDs should be taken from domain info pool entry
2018-03-03 16:44:28 +00:00
if (( $this -> get_scope () == 'user' ) && isset ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidGeneratorUsers' ]) && ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidGeneratorUsers' ][ 0 ] == 'windowsDomain' )) {
return $this -> getNextDomainInfoUIDs ( $count , $errors , $typeId );
2015-06-07 06:34:24 +00:00
}
2018-03-03 16:44:28 +00:00
if (( $this -> get_scope () == 'host' ) && isset ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidGeneratorHosts' ]) && ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidGeneratorHosts' ][ 0 ] == 'windowsDomain' )) {
return $this -> getNextDomainInfoUIDs ( $count , $errors , $typeId );
2015-06-07 06:34:24 +00:00
}
2016-03-28 09:06:04 +00:00
// check if a magic number should be used
2018-03-03 16:44:28 +00:00
if (( $this -> get_scope () == 'user' ) && isset ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidGeneratorUsers' ]) && ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidGeneratorUsers' ][ 0 ] == 'magicNumber' )) {
2016-03-28 09:06:04 +00:00
$return = array ();
for ( $i = 0 ; $i < $count ; $i ++ ) {
2018-03-03 16:44:28 +00:00
$return [] = $this -> moduleSettings [ 'posixAccount_' . $typeId . '_magicNumberUser' ][ 0 ];
2016-03-28 09:06:04 +00:00
}
return $return ;
}
2018-03-03 16:44:28 +00:00
if (( $this -> get_scope () == 'host' ) && isset ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidGeneratorHosts' ]) && ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidGeneratorHosts' ][ 0 ] == 'magicNumber' )) {
2016-03-28 09:06:04 +00:00
$return = array ();
for ( $i = 0 ; $i < $count ; $i ++ ) {
2018-03-03 16:44:28 +00:00
$return [] = $this -> moduleSettings [ 'posixAccount_' . $typeId . '_magicNumberHost' ][ 0 ];
2016-03-28 09:06:04 +00:00
}
return $return ;
}
2005-03-25 14:21:07 +00:00
$ret = array ();
2007-10-04 16:45:05 +00:00
if ( $this -> get_scope () == " user " ) {
2018-03-03 16:44:28 +00:00
$minID = intval ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_minUID' ][ 0 ]);
$maxID = intval ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_maxUID' ][ 0 ]);
2005-03-25 14:21:07 +00:00
}
else {
2018-03-03 16:44:28 +00:00
$minID = intval ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_minMachine' ][ 0 ]);
$maxID = intval ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_maxMachine' ][ 0 ]);
2005-03-25 14:21:07 +00:00
}
2018-03-03 16:44:28 +00:00
$uidList = $this -> getUIDs ( $typeId );
2005-03-25 14:21:07 +00:00
$uids = array ();
2014-09-21 15:06:11 +00:00
foreach ( $uidList as $uid ) {
if (( $uid <= $maxID ) && ( $uid >= $minID )) $uids [] = $uid ; // ignore UIDs > maxID and UIDs < minID
2005-03-25 14:21:07 +00:00
}
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
2006-08-16 17:42:35 +00:00
$errors [] = $this -> messages [ 'uidNumber' ][ 2 ];
2005-03-25 14:21:07 +00:00
}
}
else {
// return minimum allowed id-number if no id-numbers are found
$ret [] = $minID ;
$uids [] = $minID ;
}
}
return $ret ;
}
2013-02-17 13:19:50 +00:00
/**
* Gets the free UID numbers from an Samba pool entry in LDAP .
2015-08-09 07:22:01 +00:00
*
2013-02-17 13:19:50 +00:00
* @ param integer $count number of needed free UIDs .
* @ param array $errors list of error messages where errors can be added
2018-03-03 16:44:28 +00:00
* @ param string $typeId type id ( e . g . user )
2013-02-17 13:19:50 +00:00
* @ return mixed null if no UIDs are free else an array of free UIDs
*/
2018-03-03 16:44:28 +00:00
private function getNextSambaPoolUIDs ( $count , & $errors , $typeId ) {
2013-02-17 13:19:50 +00:00
if ( $this -> get_scope () == 'user' ) {
2018-03-03 16:44:28 +00:00
$dn = $this -> moduleSettings [ 'posixAccount_' . $typeId . '_sambaIDPoolDNUsers' ][ 0 ];
2013-02-17 13:19:50 +00:00
}
else {
2018-03-03 16:44:28 +00:00
$dn = $this -> moduleSettings [ 'posixAccount_' . $typeId . '_sambaIDPoolDNHosts' ][ 0 ];
2013-02-17 13:19:50 +00:00
}
$attrs = ldapGetDN ( $dn , array ( 'uidNumber' ));
if ( isset ( $attrs [ 'uidnumber' ][ 0 ]) && ( $attrs [ 'uidnumber' ][ 0 ] != '' )) {
$newValue = $attrs [ 'uidnumber' ][ 0 ] + $count ;
$ldapHandle = $_SESSION [ 'ldap' ] -> server ();
ldap_modify ( $ldapHandle , $dn , array ( 'uidnumber' => array ( $newValue )));
logNewMessage ( LOG_DEBUG , 'Updated Samba ID pool ' . $dn . ' with UID number ' . $newValue . ' and LDAP code ' . ldap_errno ( $ldapHandle ));
if ( ldap_errno ( $ldapHandle ) != 0 ) {
logNewMessage ( LOG_NOTICE , 'Updating Samba ID pool ' . $dn . ' with UID number ' . $newValue . ' failed. ' . ldap_error ( $ldapHandle ));
return null ;
}
$result = array ();
for ( $i = 0 ; $i < $count ; $i ++ ) {
$result [] = $attrs [ 'uidnumber' ][ 0 ] + $i ;
}
return $result ;
}
return null ;
}
2015-06-07 06:34:24 +00:00
/**
* Gets the free UID numbers from a domain info entry in LDAP .
2015-08-09 07:22:01 +00:00
*
2015-06-07 06:34:24 +00:00
* @ param integer $count number of needed free UIDs .
* @ param array $errors list of error messages where errors can be added
2018-03-03 16:44:28 +00:00
* @ param string $typeId type id ( e . g . user )
2015-06-07 06:34:24 +00:00
* @ return mixed null if no UIDs are free else an array of free UIDs
*/
2018-03-03 16:44:28 +00:00
private function getNextDomainInfoUIDs ( $count , & $errors , $typeId ) {
2015-06-07 06:34:24 +00:00
if ( $this -> get_scope () == 'user' ) {
2018-03-03 16:44:28 +00:00
$dn = $this -> moduleSettings [ 'posixAccount_' . $typeId . '_windowsIDPoolDNUsers' ][ 0 ];
2015-06-07 06:34:24 +00:00
}
else {
2018-03-03 16:44:28 +00:00
$dn = $this -> moduleSettings [ 'posixAccount_' . $typeId . '_windowsIDPoolDNHosts' ][ 0 ];
2015-06-07 06:34:24 +00:00
}
$attrs = ldapGetDN ( $dn , array ( 'msSFU30MaxUidNumber' ));
if ( ! empty ( $attrs [ 'mssfu30maxuidnumber' ][ 0 ])) {
$newValue = $attrs [ 'mssfu30maxuidnumber' ][ 0 ] + $count ;
$ldapHandle = $_SESSION [ 'ldap' ] -> server ();
ldap_modify ( $ldapHandle , $dn , array ( 'mssfu30maxuidnumber' => array ( $newValue )));
logNewMessage ( LOG_DEBUG , 'Updated domain info ' . $dn . ' with UID number ' . $newValue . ' and LDAP code ' . ldap_errno ( $ldapHandle ));
if ( ldap_errno ( $ldapHandle ) != 0 ) {
logNewMessage ( LOG_NOTICE , 'Updating domain info ' . $dn . ' with UID number ' . $newValue . ' failed. ' . ldap_error ( $ldapHandle ));
return null ;
}
$result = array ();
for ( $i = 0 ; $i < $count ; $i ++ ) {
$result [] = $attrs [ 'mssfu30maxuidnumber' ][ 0 ] + $i ;
}
return $result ;
}
return null ;
}
2006-07-29 08:42:34 +00:00
/**
* Returns the meta HTML code for each input field .
* format : array ( < field1 > => array ( < META HTML > ), ... )
* It is not possible to display help links .
*
* @ param array $fields list of active fields
2011-08-20 17:59:36 +00:00
* @ param array $attributes attributes of LDAP account
2012-02-08 17:55:00 +00:00
* @ param boolean $passwordChangeOnly indicates that the user is only allowed to change his password and no LDAP content is readable
2012-08-18 15:55:43 +00:00
* @ param array $readOnlyFields list of read - only fields
2015-08-09 07:22:01 +00:00
* @ return array list of meta HTML elements ( field name => htmlResponsiveRow )
2006-07-29 08:42:34 +00:00
*/
2012-08-18 15:55:43 +00:00
function getSelfServiceOptions ( $fields , $attributes , $passwordChangeOnly , $readOnlyFields ) {
2006-07-29 08:42:34 +00:00
$return = array ();
if ( in_array ( 'password' , $fields )) {
2015-08-09 07:22:01 +00:00
$row = new htmlResponsiveRow ();
2015-03-01 16:48:25 +00:00
if ( ! empty ( $this -> selfServiceSettings -> moduleSettings [ 'posixAccount_useOldPwd' ]) && ( $this -> selfServiceSettings -> moduleSettings [ 'posixAccount_useOldPwd' ][ 0 ] == 'true' )) {
2015-08-09 07:22:01 +00:00
$pwd0 = new htmlResponsiveInputField ( _ ( 'Old password' ), 'posixAccount_passwordOld' );
2015-03-01 16:48:25 +00:00
$pwd0 -> setIsPassword ( true , true );
2015-08-09 07:22:01 +00:00
$row -> add ( $pwd0 , 12 );
2015-03-01 16:48:25 +00:00
}
2015-08-09 07:22:01 +00:00
$pwd1 = new htmlResponsiveInputField ( $this -> getSelfServiceLabel ( 'password' , _ ( 'New password' )), 'posixAccount_password' );
2014-05-25 17:29:19 +00:00
$pwd1 -> setIsPassword ( true , true );
2015-08-09 07:22:01 +00:00
$row -> add ( $pwd1 , 12 );
$pwd2 = new htmlResponsiveInputField ( _ ( 'Reenter password' ), 'posixAccount_password2' );
2010-07-03 13:17:50 +00:00
$pwd2 -> setIsPassword ( true );
2014-05-25 14:37:05 +00:00
$pwd2 -> setSameValueFieldID ( 'posixAccount_password' );
2015-08-09 07:22:01 +00:00
$row -> add ( $pwd2 , 12 );
$return [ 'password' ] = $row ;
2006-07-29 08:42:34 +00:00
}
2012-02-08 17:55:00 +00:00
if ( $passwordChangeOnly ) {
return $return ; // only password fields as long no LDAP content can be read
}
2011-03-23 18:35:57 +00:00
if ( in_array ( 'cn' , $fields )) {
$cn = '' ;
2019-03-06 17:09:22 +00:00
if ( isset ( $attributes [ 'cn' ][ 0 ])) {
$cn = $attributes [ 'cn' ][ 0 ];
}
2012-08-18 15:55:43 +00:00
$cnField = new htmlInputField ( 'posixAccount_cn' , $cn );
if ( in_array ( 'cn' , $readOnlyFields )) {
$cnField = new htmlOutputText ( $cn );
}
2015-08-09 07:22:01 +00:00
$row = new htmlResponsiveRow ();
2015-08-09 07:57:56 +00:00
$row -> addLabel ( new htmlOutputText ( $this -> getSelfServiceLabel ( 'cn' , _ ( 'Common name' ))));
$row -> addField ( $cnField );
2015-08-09 07:22:01 +00:00
$return [ 'cn' ] = $row ;
2011-03-23 18:35:57 +00:00
}
2011-12-14 18:41:59 +00:00
if ( in_array ( 'loginShell' , $fields )) {
2013-02-05 19:10:04 +00:00
$shelllist = $this -> getShells (); // list of all valid shells
2011-12-14 18:41:59 +00:00
$loginShell = '' ;
2019-03-06 17:09:22 +00:00
if ( isset ( $attributes [ 'loginShell' ][ 0 ])) {
$loginShell = $attributes [ 'loginShell' ][ 0 ];
}
2012-08-18 15:55:43 +00:00
$loginShellField = new htmlSelect ( 'posixAccount_loginShell' , $shelllist , array ( $loginShell ));
if ( in_array ( 'loginShell' , $readOnlyFields )) {
$loginShellField = new htmlOutputText ( $loginShell );
}
2015-08-09 07:22:01 +00:00
$row = new htmlResponsiveRow ();
2015-08-09 07:57:56 +00:00
$row -> addLabel ( new htmlOutputText ( $this -> getSelfServiceLabel ( 'loginShell' , _ ( 'Login shell' ))));
$row -> addField ( $loginShellField );
2015-08-09 07:22:01 +00:00
$return [ 'loginShell' ] = $row ;
2011-12-14 18:41:59 +00:00
}
2019-03-06 17:09:22 +00:00
if ( in_array ( 'unixgroups' , $fields ) && ! empty ( $this -> selfServiceSettings -> moduleSettings [ 'posixAccount_groupDn' ][ 0 ])) {
$groupDn = $this -> selfServiceSettings -> moduleSettings [ 'posixAccount_groupDn' ][ 0 ];
$gidNumber = $attributes [ 'gidNumber' ][ 0 ];
$userName = $attributes [ 'uid' ][ 0 ];
if ( ! empty ( $userName )) {
$filter = '(&(objectClass=posixGroup)(|(gidNumber=' . $gidNumber . ')(memberUid=' . $userName . ')))' ;
$results = searchLDAP ( $groupDn , $filter , array ( 'cn' ));
$groups = array ();
foreach ( $results as $result ) {
$groups [] = $result [ 'cn' ][ 0 ];
}
$groups = array_unique ( $groups );
natcasesort ( $groups );
$row = new htmlResponsiveRow ();
$row -> addLabel ( new htmlOutputText ( $this -> getSelfServiceLabel ( 'unixgroups' , _ ( 'Groups' ))));
$row -> addField ( new htmlOutputText ( implode ( ', ' , $groups )));
$return [ 'unixgroups' ] = $row ;
}
}
2006-07-29 08:42:34 +00:00
return $return ;
}
/**
2011-02-26 13:14:10 +00:00
* Checks if all input values are correct and returns the LDAP attributes which should be changed .
* < br > Return values :
* < br > messages : array of parameters to create status messages
* < br > add : array of attributes to add
* < br > del : array of attributes to remove
* < br > mod : array of attributes to modify
* < br > " info " are values with informational value ( e . g . to be used later by pre / postModify actions )
2015-08-09 07:22:01 +00:00
*
2011-02-26 13:14:10 +00:00
* Calling this method does not require the existence of an enclosing { @ link accountContainer } .
2006-07-29 08:42:34 +00:00
*
* @ param string $fields input fields
* @ param array $attributes LDAP attributes
2012-02-08 17:55:00 +00:00
* @ param boolean $passwordChangeOnly indicates that the user is only allowed to change his password and no LDAP content is readable
2012-08-18 15:55:43 +00:00
* @ param array $readOnlyFields list of read - only fields
2011-02-26 13:14:10 +00:00
* @ return array messages and attributes ( array ( 'messages' => array (), 'add' => array ( 'mail' => array ( 'test@test.com' )), 'del' => array (), 'mod' => array (), 'info' => array ()))
2006-07-29 08:42:34 +00:00
*/
2012-08-18 15:55:43 +00:00
function checkSelfServiceOptions ( $fields , $attributes , $passwordChangeOnly , $readOnlyFields ) {
2011-02-26 13:14:10 +00:00
$return = array ( 'messages' => array (), 'add' => array (), 'del' => array (), 'mod' => array (), 'info' => array ());
2006-07-29 08:42:34 +00:00
if ( in_array ( 'password' , $fields )) {
if ( isset ( $_POST [ 'posixAccount_password' ]) && ( $_POST [ 'posixAccount_password' ] != '' )) {
if ( $_POST [ 'posixAccount_password' ] != $_POST [ 'posixAccount_password2' ]) {
$return [ 'messages' ][] = $this -> messages [ 'userPassword' ][ 0 ];
}
else {
2006-08-13 12:58:19 +00:00
if ( ! get_preg ( $_POST [ 'posixAccount_password' ], 'password' )) {
2006-07-29 08:42:34 +00:00
$return [ 'messages' ][] = $this -> messages [ 'userPassword' ][ 1 ];
}
else {
2014-04-17 19:26:08 +00:00
$userName = empty ( $attributes [ 'uid' ][ 0 ]) ? null : $attributes [ 'uid' ][ 0 ];
$additionalAttrs = array ();
if ( ! empty ( $attributes [ 'sn' ][ 0 ])) {
$additionalAttrs [] = $attributes [ 'sn' ][ 0 ];
}
if ( ! empty ( $attributes [ 'givenName' ][ 0 ])) {
$additionalAttrs [] = $attributes [ 'givenName' ][ 0 ];
}
$pwdPolicyResult = checkPasswordStrength ( $_POST [ 'posixAccount_password' ], $userName , $additionalAttrs );
2008-02-14 17:37:02 +00:00
if ( $pwdPolicyResult === true ) {
2017-09-22 17:52:57 +00:00
$passwordHash = $this -> selfServiceSettings -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ];
2015-03-01 16:48:25 +00:00
if ( empty ( $this -> selfServiceSettings -> moduleSettings [ 'posixAccount_useOldPwd' ]) || ( $this -> selfServiceSettings -> moduleSettings [ 'posixAccount_useOldPwd' ][ 0 ] != 'true' )) {
2017-09-22 17:52:57 +00:00
// set SASL password
if ( ! empty ( $attributes [ 'uid' ][ 0 ]) && ( $passwordHash === 'SASL' )) {
$return [ 'mod' ][ 'userPassword' ][ 0 ] = '{SASL}' . $attributes [ 'uid' ][ 0 ];
}
2018-07-07 12:05:39 +00:00
elseif ( $passwordHash === 'LDAP_EXOP' ) {
// no LDAP modify action, use ldap_exop_passwd
$return [ 'info' ][ 'userPasswordModify' ][ 0 ] = 'exop' ;
}
2017-09-22 17:52:57 +00:00
// set other password hashes
else {
$return [ 'mod' ][ 'userPassword' ][ 0 ] = pwd_hash ( $_POST [ 'posixAccount_password' ], true , $passwordHash );
}
2015-03-01 16:48:25 +00:00
}
else {
2017-09-22 17:52:57 +00:00
$return [ 'add' ][ 'userPassword' ][ 0 ] = pwd_hash ( $_POST [ 'posixAccount_password' ], true , $passwordHash );
2017-05-13 15:58:02 +00:00
$return [ 'del' ][ 'userPassword' ][ 0 ] = $_POST [ 'posixAccount_passwordOld' ];
2015-03-01 16:48:25 +00:00
}
2011-02-26 13:14:10 +00:00
$return [ 'info' ][ 'userPasswordClearText' ][ 0 ] = $_POST [ 'posixAccount_password' ];
2008-05-15 17:22:32 +00:00
if ( isset ( $attributes [ 'shadowLastChange' ][ 0 ])) {
2008-02-14 17:37:02 +00:00
$return [ 'mod' ][ 'shadowLastChange' ][ 0 ] = intval ( time () / 3600 / 24 );
}
$_SESSION [ 'selfService_clientPasswordNew' ] = $_POST [ 'posixAccount_password' ];
}
else {
$return [ 'messages' ][] = array ( 'ERROR' , $pwdPolicyResult );
2007-07-08 10:21:34 +00:00
}
2006-07-29 08:42:34 +00:00
}
}
}
}
2015-03-01 16:48:25 +00:00
// stop processing if only a password change is done
2012-02-08 17:55:00 +00:00
if ( $passwordChangeOnly ) {
2015-03-01 16:48:25 +00:00
return $return ;
2012-02-08 17:55:00 +00:00
}
2016-06-26 08:15:45 +00:00
// sync from Windows password
if ( in_array ( 'syncWindowsPassword' , $fields ) && ! empty ( $_POST [ 'windowsUser_unicodePwd' ])) {
$password = $_POST [ 'windowsUser_unicodePwd' ];
$return [ 'mod' ][ 'unixUserPassword' ][ 0 ] = pwd_hash ( $password , true , $this -> selfServiceSettings -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ]);
if ( isset ( $attributes [ 'shadowLastChange' ][ 0 ])) {
$return [ 'mod' ][ 'shadowLastChange' ][ 0 ] = intval ( time () / 3600 / 24 );
}
}
2015-03-01 16:48:25 +00:00
// cn
2012-08-18 15:55:43 +00:00
if ( in_array ( 'cn' , $fields ) && ! in_array ( 'cn' , $readOnlyFields )) {
2011-03-23 18:35:57 +00:00
if ( isset ( $_POST [ 'posixAccount_cn' ]) && ( $_POST [ 'posixAccount_cn' ] != '' )) {
if ( ! get_preg ( $_POST [ 'posixAccount_cn' ], 'cn' )) {
$return [ 'messages' ][] = $this -> messages [ 'cn' ][ 0 ];
}
2012-02-08 18:09:21 +00:00
else if ( ! isset ( $attributes [ 'cn' ]) || ( $attributes [ 'cn' ][ 0 ] != $_POST [ 'posixAccount_cn' ])) {
2011-03-23 18:35:57 +00:00
$return [ 'mod' ][ 'cn' ][ 0 ] = $_POST [ 'posixAccount_cn' ];
}
}
else {
$return [ 'messages' ][] = $this -> messages [ 'cn' ][ 0 ];
}
}
2015-03-01 16:48:25 +00:00
// shell
2012-08-18 15:55:43 +00:00
if ( in_array ( 'loginShell' , $fields ) && ! in_array ( 'loginShell' , $readOnlyFields )) {
2013-02-05 19:10:04 +00:00
$shelllist = $this -> getShells (); // list of all valid shells
2012-02-08 18:09:21 +00:00
if ( in_array ( $_POST [ 'posixAccount_loginShell' ], $shelllist )
&& ( ! isset ( $attributes [ 'loginShell' ]) || ( $attributes [ 'loginShell' ][ 0 ] != $_POST [ 'posixAccount_loginShell' ]))) {
2011-12-14 18:41:59 +00:00
$return [ 'mod' ][ 'loginShell' ][ 0 ] = $_POST [ 'posixAccount_loginShell' ];
}
}
2006-07-29 08:42:34 +00:00
return $return ;
}
2015-08-09 07:22:01 +00:00
2018-07-07 12:05:39 +00:00
/**
* { @ inheritDoc }
* @ see baseModule :: postModifySelfService ()
*/
public function postModifySelfService ( $newAccount , $attributes ) {
if ( isset ( $attributes [ 'INFO.userPasswordModify' ][ 0 ])
&& ( $attributes [ 'INFO.userPasswordModify' ][ 0 ] === 'exop' )) {
$password = $attributes [ 'INFO.userPasswordClearText' ][ 0 ];
$dn = $attributes [ 'dn' ][ 0 ];
$success = ldap_exop_passwd ( $_SESSION [ 'ldapHandle' ], $dn , null , $password );
if ( ! $success ) {
StatusMessage ( 'ERROR' , _ ( 'Unable to set password' ), getExtendedLDAPErrorMessage ( $_SESSION [ 'ldapHandle' ]));
}
else {
StatusMessage ( 'INFO' , _ ( 'Password changed.' ));
}
return $success ;
}
return true ;
}
2019-07-31 19:19:42 +00:00
2019-06-05 17:24:46 +00:00
/**
* Returns if the module manages the password attribute .
2019-07-31 19:19:42 +00:00
*
2019-06-05 17:24:46 +00:00
* @ param string $typeId account type id
* @ return boolean manages password
*/
private function isPasswordManaged ( $typeId = null ) {
if ( $typeId === null ) {
$typeId = $this -> getAccountContainer () -> get_type () -> getId ();
}
return ! $this -> isBooleanConfigOptionSet ( 'posixAccount_' . $typeId . '_hidepassword' );
}
2018-07-07 12:05:39 +00:00
2009-10-08 20:16:02 +00:00
/**
* This method specifies if a module manages password attributes .
* @ see passwordService :: managesPasswordAttributes
*
* @ return boolean true if this module manages password attributes
*/
public function managesPasswordAttributes () {
2019-06-05 17:24:46 +00:00
return $this -> isPasswordManaged ();
2009-10-08 20:16:02 +00:00
}
2012-01-15 19:34:14 +00:00
/**
* Specifies if this module supports to force that a user must change his password on next login .
2015-08-09 07:22:01 +00:00
*
2012-01-15 19:34:14 +00:00
* @ return boolean force password change supported
*/
public function supportsForcePasswordChange () {
return false ;
}
2015-08-09 07:22:01 +00:00
2009-10-08 20:16:02 +00:00
/**
2009-10-09 18:21:12 +00:00
* This function is called whenever the password should be changed . Account modules
* must change their password attributes only if the modules list contains their module name .
*
2009-10-08 20:16:02 +00:00
* @ param String $password new password
2009-10-09 18:21:12 +00:00
* @ param $modules list of modules for which the password should be changed
2012-01-15 19:34:14 +00:00
* @ param boolean $forcePasswordChange force the user to change his password at next login
2009-10-08 20:16:02 +00:00
* @ return array list of error messages if any as parameter array for StatusMessage
* e . g . return arrray ( array ( 'ERROR' , 'Password change failed.' ))
2009-10-09 18:21:12 +00:00
* @ see passwordService :: passwordChangeRequested
2009-10-08 20:16:02 +00:00
*/
2012-01-15 19:34:14 +00:00
public function passwordChangeRequested ( $password , $modules , $forcePasswordChange ) {
2009-10-09 18:21:12 +00:00
if ( ! in_array ( get_class ( $this ), $modules )) {
return array ();
}
2017-05-10 17:23:28 +00:00
$accountModules = $this -> getAccountContainer () -> get_type () -> getModules ();
2014-04-17 19:26:08 +00:00
// check password strength
$user = empty ( $this -> attributes [ 'uid' ][ 0 ]) ? null : $this -> attributes [ 'uid' ][ 0 ];
$additionalAttrs = array ();
if ( $this -> getAccountContainer () -> getAccountModule ( 'inetOrgPerson' ) != null ) {
$attrs = $this -> getAccountContainer () -> getAccountModule ( 'inetOrgPerson' ) -> getAttributes ();
if ( ! empty ( $attrs [ 'sn' ][ 0 ])) {
$additionalAttrs [] = $attrs [ 'sn' ][ 0 ];
}
if ( ! empty ( $attrs [ 'givenName' ][ 0 ])) {
$additionalAttrs [] = $attrs [ 'givenName' ][ 0 ];
}
}
$checkResult = checkPasswordStrength ( $password , $user , $additionalAttrs );
if ( $checkResult !== true ) {
return array ( array ( 'ERROR' , $checkResult ));
}
// set new password
2010-03-08 18:26:06 +00:00
$this -> clearTextPassword = $password ;
2015-02-11 16:57:38 +00:00
// set SASL password
if ( ! empty ( $this -> attributes [ 'uid' ][ 0 ]) && ! empty ( $this -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ])
&& ( $this -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ] === 'SASL' )) {
2017-05-10 17:23:28 +00:00
$this -> attributes [ $this -> getPasswordAttrName ( $accountModules )][ 0 ] = '{SASL}' . $this -> attributes [ 'uid' ][ 0 ];
2015-02-11 16:57:38 +00:00
}
2018-07-07 12:05:39 +00:00
// delay on ldap_exop
elseif ( ! empty ( $this -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ]) && ( $this -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ] === 'LDAP_EXOP' )) {
logNewMessage ( LOG_DEBUG , 'Setting password in post action, exop' );
}
2015-02-11 16:57:38 +00:00
// set normal password
else {
2017-05-10 17:23:28 +00:00
$this -> attributes [ $this -> getPasswordAttrName ( $accountModules )][ 0 ] = pwd_hash ( $password , true , $this -> moduleSettings [ 'posixAccount_pwdHash' ][ 0 ]);
2015-02-11 16:57:38 +00:00
}
2009-10-08 20:16:02 +00:00
return array ();
}
2015-08-09 07:22:01 +00:00
2009-11-26 10:48:05 +00:00
/**
2009-11-26 13:32:14 +00:00
* Returns the group ID of the given group .
2009-11-26 10:48:05 +00:00
*
* @ param String $groupname group name
* @ return String GID
*/
private function getGID ( $groupname ) {
$results = searchLDAPByAttribute ( 'cn' , $groupname , 'posixGroup' , array ( 'gidnumber' ), array ( 'group' ));
if (( sizeof ( $results ) > 0 ) && isset ( $results [ 0 ][ 'gidnumber' ][ 0 ])) {
return $results [ 0 ][ 'gidnumber' ][ 0 ];
}
return null ;
}
2015-08-09 07:22:01 +00:00
2009-11-26 10:48:05 +00:00
/**
* Returns the group name of the group with the given group ID .
*
* @ param String $groupID group ID
* @ return String group name
*/
private function getGroupName ( $groupID ) {
$results = searchLDAPByAttribute ( 'gidNumber' , $groupID , 'posixGroup' , array ( 'cn' ), array ( 'group' ));
if (( sizeof ( $results ) > 0 ) && isset ( $results [ 0 ][ 'cn' ][ 0 ])) {
return $results [ 0 ][ 'cn' ][ 0 ];
}
return null ;
}
2015-08-09 07:22:01 +00:00
2009-11-26 10:48:05 +00:00
/**
* Finds all existing LDAP groups .
*
2010-11-23 21:12:13 +00:00
* @ return array groups array ( array ( gidnumber , cn ), array ( gidnumber , cn ), ... )
2009-11-26 10:48:05 +00:00
*/
2017-05-10 17:23:28 +00:00
private function findGroups ( & $modules ) {
2009-11-26 10:48:05 +00:00
if ( $this -> groupCache != null ) {
return $this -> groupCache ;
}
2017-05-08 17:59:28 +00:00
$this -> groupCache = array ();
$typeManager = new TypeManager ();
foreach ( $typeManager -> getConfiguredTypesForScope ( 'group' ) as $type ) {
$filter = '(objectClass=posixGroup)' ;
2017-05-10 17:23:28 +00:00
if ( $this -> isWindows ( $modules )) {
2017-05-08 17:59:28 +00:00
$filter = '(&(objectClass=group)(gidNumber=*))' ;
2014-02-26 20:02:50 +00:00
}
2017-05-08 17:59:28 +00:00
$typeFilter = $type -> getAdditionalLdapFilter ();
if ( ! empty ( $typeFilter )) {
if ( strpos ( $typeFilter , '(' ) !== 0 ) {
$typeFilter = '(' . $typeFilter . ')' ;
}
$filter = '(&' . $filter . $typeFilter . ')' ;
}
$results = searchLDAP ( $type -> getSuffix (), $filter , array ( 'cn' , 'gidnumber' ));
for ( $i = 0 ; $i < sizeof ( $results ); $i ++ ) {
if ( isset ( $results [ $i ][ 'cn' ][ 0 ]) && isset ( $results [ $i ][ 'gidnumber' ][ 0 ])) {
$this -> groupCache [] = array ( $results [ $i ][ 'gidnumber' ][ 0 ], $results [ $i ][ 'cn' ][ 0 ]);
}
2009-11-26 10:48:05 +00:00
}
}
2017-05-08 17:59:28 +00:00
return $this -> groupCache ;
2009-11-26 10:48:05 +00:00
}
2015-08-09 07:22:01 +00:00
2011-10-06 20:03:45 +00:00
/**
* Finds all existing LDAP group of names .
*
2015-05-31 08:46:44 +00:00
* @ return array groups array ( dn => array ( 'cn' => array ( 'groupName' ), 'objectclass' => array ( 'top' , 'groupOfNames' )))
2011-10-06 20:03:45 +00:00
*/
2018-11-17 19:40:09 +00:00
public function findGroupOfNames () {
2011-10-06 20:03:45 +00:00
if ( $this -> gonCache != null ) {
return $this -> gonCache ;
}
$return = array ();
2017-03-22 19:17:52 +00:00
$typeManager = new TypeManager ();
$types = $typeManager -> getConfiguredTypesForScopes ( array ( 'gon' , 'group' ));
foreach ( $types as $type ) {
$typeFilter = get_ldap_filter ( $type -> getId ());
$results = searchLDAP ( $type -> getSuffix (), $typeFilter , array ( 'cn' , 'dn' , 'objectClass' ));
for ( $i = 0 ; $i < sizeof ( $results ); $i ++ ) {
2019-03-05 16:59:33 +00:00
if (( in_array_ignore_case ( 'groupOfNames' , $results [ $i ][ 'objectclass' ])
|| in_array_ignore_case ( 'groupOfMembers' , $results [ $i ][ 'objectclass' ])
|| in_array_ignore_case ( 'groupOfUniqueNames' , $results [ $i ][ 'objectclass' ]))
2017-03-22 19:17:52 +00:00
&& isset ( $results [ $i ][ 'cn' ][ 0 ])) {
$return [ $results [ $i ][ 'dn' ]] = $results [ $i ];
2011-10-06 20:03:45 +00:00
}
}
}
$this -> gonCache = $return ;
return $return ;
}
2015-08-09 07:22:01 +00:00
2010-11-23 21:12:13 +00:00
/**
* Returns a list of existing UID numbers .
*
2018-03-03 16:44:28 +00:00
* @ param string $typeId type id ( e . g . user )
2010-11-23 21:12:13 +00:00
* @ return array list of UID numbers
*/
2018-03-03 16:44:28 +00:00
private function getUIDs ( $typeId ) {
2010-11-23 21:12:13 +00:00
if ( $this -> cachedUIDList != null ) {
return $this -> cachedUIDList ;
}
$this -> cachedUIDList = array ();
2012-09-07 16:35:54 +00:00
$attrs = array ( 'uidNumber' );
$filter = '(&(objectClass=posixAccount)(uidNumber=*))' ;
2016-05-09 18:10:14 +00:00
if ( $this -> skipObjectClass ()) {
$filter = '(uidNumber=*)' ;
}
2017-03-24 17:23:52 +00:00
$typeManager = new TypeManager ();
$typesUser = $typeManager -> getConfiguredTypesForScope ( 'user' );
$typesHost = $typeManager -> getConfiguredTypesForScope ( 'host' );
$suffixes = array ();
if ( ! empty ( $typesUser )) {
2018-03-03 16:44:28 +00:00
if ( ! empty ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidCheckSuffixUser' ][ 0 ])) {
$suffixes [] = $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidCheckSuffixUser' ][ 0 ];
2012-09-07 16:35:54 +00:00
}
2017-03-24 17:23:52 +00:00
else {
foreach ( $typesUser as $type ) {
$suffixes [] = $type -> getSuffix ();
}
2012-09-07 16:35:54 +00:00
}
}
2017-03-24 17:23:52 +00:00
if ( ! empty ( $typesHost )) {
2018-03-03 16:44:28 +00:00
if ( ! empty ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidCheckSuffixHost' ][ 0 ])) {
$suffixes [] = $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidCheckSuffixHost' ][ 0 ];
2012-09-07 16:35:54 +00:00
}
2017-03-24 17:23:52 +00:00
else {
foreach ( $typesHost as $type ) {
$suffixes [] = $type -> getSuffix ();
2012-09-07 16:35:54 +00:00
}
}
2010-11-23 21:12:13 +00:00
}
2017-03-24 17:23:52 +00:00
$suffixes = array_unique ( $suffixes );
foreach ( $suffixes as $suffix ) {
$result = searchLDAP ( $suffix , $filter , $attrs );
foreach ( $result as $resultEntry ) {
$this -> cachedUIDList [] = $resultEntry [ 'uidnumber' ][ 0 ];
}
}
$this -> cachedUIDList = array_values ( array_unique ( $this -> cachedUIDList ));
2010-11-23 21:12:13 +00:00
sort ( $this -> cachedUIDList , SORT_NUMERIC );
return $this -> cachedUIDList ;
}
2015-08-09 07:22:01 +00:00
2012-09-07 16:35:54 +00:00
/**
* Checks if the given user name already exists in LDAP .
2015-08-09 07:22:01 +00:00
*
2012-09-07 16:35:54 +00:00
* @ param String $userName user name
2018-03-03 16:44:28 +00:00
* @ param string $typeId type id ( e . g . user )
2012-09-07 16:35:54 +00:00
* @ return boolean true if already exists
*/
2018-03-03 16:44:28 +00:00
private function userNameExists ( $userName , $typeId ) {
2018-04-11 16:40:44 +00:00
return array_key_exists ( $userName , $this -> getUserNames ( $typeId ));
2012-09-07 16:35:54 +00:00
}
2015-08-09 07:22:01 +00:00
2012-09-07 16:35:54 +00:00
/**
* Returns a list of all user names in LDAP .
2015-08-09 07:22:01 +00:00
*
2018-03-03 16:44:28 +00:00
* @ param string $typeId type id ( e . g . user )
2012-09-07 16:35:54 +00:00
* @ return array user names
*/
2018-03-03 16:44:28 +00:00
private function getUserNames ( $typeId ) {
2012-09-07 16:35:54 +00:00
if ( $this -> cachedUserNameList != null ) {
return $this -> cachedUserNameList ;
}
$this -> cachedUserNameList = array ();
$attrs = array ( 'uid' );
$filter = '(&(objectClass=posixAccount)(uid=*))' ;
2016-05-09 18:10:14 +00:00
if ( $this -> skipObjectClass ()) {
$filter = '(uid=*)' ;
}
2017-03-24 17:23:52 +00:00
$typeManager = new TypeManager ();
$typesUser = $typeManager -> getConfiguredTypesForScope ( 'user' );
$typesHost = $typeManager -> getConfiguredTypesForScope ( 'host' );
$suffixes = array ();
if ( ! empty ( $typesUser )) {
2018-03-03 16:44:28 +00:00
if ( ! empty ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidCheckSuffixUser' ][ 0 ])) {
$suffixes [] = $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidCheckSuffixUser' ][ 0 ];
2012-09-07 16:35:54 +00:00
}
2017-03-24 17:23:52 +00:00
else {
foreach ( $typesUser as $type ) {
$suffixes [] = $type -> getSuffix ();
}
2012-09-07 16:35:54 +00:00
}
}
2017-03-24 17:23:52 +00:00
if ( ! empty ( $typesHost )) {
2018-03-03 16:44:28 +00:00
if ( ! empty ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidCheckSuffixHost' ][ 0 ])) {
$suffixes [] = $this -> moduleSettings [ 'posixAccount_' . $typeId . '_uidCheckSuffixHost' ][ 0 ];
2012-09-07 16:35:54 +00:00
}
2017-03-24 17:23:52 +00:00
else {
foreach ( $typesHost as $type ) {
$suffixes [] = $type -> getSuffix ();
2012-09-07 16:35:54 +00:00
}
}
}
2017-03-24 17:23:52 +00:00
$suffixes = array_unique ( $suffixes );
foreach ( $suffixes as $suffix ) {
$result = searchLDAP ( $suffix , $filter , $attrs );
foreach ( $result as $resultEntry ) {
2018-04-11 16:40:44 +00:00
$this -> cachedUserNameList [ $resultEntry [ 'uid' ][ 0 ]] = $resultEntry [ 'dn' ];
2017-03-24 17:23:52 +00:00
}
}
2012-09-07 16:35:54 +00:00
return $this -> cachedUserNameList ;
}
2015-08-09 07:22:01 +00:00
2011-10-06 20:03:45 +00:00
/**
* Returns if LAM manages group of names entries .
2015-08-09 07:22:01 +00:00
*
2011-10-06 20:03:45 +00:00
* @ return boolean group of names are active
*/
2012-04-09 13:20:24 +00:00
public static function areGroupOfNamesActive () {
2011-10-06 20:03:45 +00:00
if ( ! isset ( $_SESSION [ 'config' ])) {
return false ;
}
2017-03-24 17:23:52 +00:00
$typeManager = new TypeManager ();
$types = $typeManager -> getConfiguredTypesForScopes ( array ( 'group' , 'gon' ));
foreach ( $types as $type ) {
$modules = $type -> getModules ();
if ( in_array ( 'groupOfNames' , $modules )
|| in_array ( 'groupOfMembers' , $modules )
|| in_array ( 'groupOfUniqueNames' , $modules )) {
2011-10-06 20:03:45 +00:00
return true ;
}
}
return false ;
}
2015-08-09 07:22:01 +00:00
2011-02-20 13:28:32 +00:00
/**
* Returns a suggestion for the user name .
* By deafult this wil be the first character of the first name plus the last name .
*
* @ param array $attrs LDAP attributes
2018-03-03 16:44:28 +00:00
* @ param string $typeId type id ( e . g . user )
2011-02-20 13:28:32 +00:00
* @ return String user name
*/
2018-03-03 16:44:28 +00:00
protected function getUserNameSuggestion ( $attrs , $typeId ) {
2013-03-24 18:39:08 +00:00
$attributes = array_change_key_case ( $attrs , CASE_LOWER );
$format = '@givenname@%sn%' ;
2018-03-03 16:44:28 +00:00
if ( isset ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_userNameSuggestion' ][ 0 ])) {
$format = strtolower ( $this -> moduleSettings [ 'posixAccount_' . $typeId . '_userNameSuggestion' ][ 0 ]);
2013-03-24 18:39:08 +00:00
}
// search for @key@ wildcards in format string and replace with first character of attribute
$wildcards = array ();
if ( preg_match_all ( '/@([^@]|[a-zA-Z_-])+@/' , $format , $wildcards ) > 0 ) {
for ( $i = 0 ; $i < sizeof ( $wildcards [ 0 ]); $i ++ ) {
$wc = substr ( $wildcards [ 0 ][ $i ], 1 , strlen ( $wildcards [ 0 ][ $i ]) - 2 );
$value = '' ;
2013-05-01 12:35:09 +00:00
if ( isset ( $attributes [ $wc ][ 0 ]) && ! empty ( $attributes [ $wc ][ 0 ])) {
2018-01-17 16:39:31 +00:00
$value = $this -> cleanSuggestionPart ( $attributes [ $wc ][ 0 ][ 0 ]);
2011-02-20 13:28:32 +00:00
}
2013-03-24 18:39:08 +00:00
$format = str_replace ( '@' . $wc . '@' , $value , $format );
2011-02-20 13:28:32 +00:00
}
2013-03-24 18:39:08 +00:00
}
// search for %key% wildcards in format string and replace with attribute
$wildcards = array ();
if ( preg_match_all ( '/%([^%]|[a-zA-Z_-])+%/' , $format , $wildcards ) > 0 ) {
for ( $i = 0 ; $i < sizeof ( $wildcards [ 0 ]); $i ++ ) {
$wc = substr ( $wildcards [ 0 ][ $i ], 1 , strlen ( $wildcards [ 0 ][ $i ]) - 2 );
$value = '' ;
if ( isset ( $attributes [ $wc ][ 0 ])) {
2018-01-17 16:39:31 +00:00
$value = $this -> cleanSuggestionPart ( $attributes [ $wc ][ 0 ]);
2013-03-24 18:39:08 +00:00
}
$format = str_replace ( '%' . $wc . '%' , $value , $format );
2011-02-20 13:28:32 +00:00
}
}
2013-07-21 10:39:46 +00:00
return $format ;
2011-02-20 13:28:32 +00:00
}
2015-08-09 07:22:01 +00:00
2018-01-17 16:39:31 +00:00
/**
* Cleans a string that is injected in user name suggestion .
*
* @ param string $part injected part
* @ return string cleaned by removing umlauts , spaces , dashes and underscores
*/
private function cleanSuggestionPart ( $part ) {
$result = str_replace ( array_keys ( $this -> umlautReplacements ), array_values ( $this -> umlautReplacements ), strtolower ( $part ));
$result = str_replace ( array ( ' ' , '_' , '-' ), array ( '' , '' , '' ), $result );
return $result ;
}
2012-04-09 18:07:57 +00:00
/**
* Returns if this account can be locked .
* This is the case if a hashed password is set ( " { " at the beginning ) .
2017-05-10 17:23:28 +00:00
*
* @ param string [] $modules account modules
* @ return boolean lockable
2012-04-09 18:07:57 +00:00
*/
2017-05-10 17:23:28 +00:00
public function isLockable ( & $modules ) {
if ( isset ( $this -> attributes [ $this -> getPasswordAttrName ( $modules )][ 0 ])
&& pwd_is_lockable ( $this -> attributes [ $this -> getPasswordAttrName ( $modules )][ 0 ])) {
2012-04-09 18:07:57 +00:00
return true ;
}
return false ;
}
2015-08-09 07:22:01 +00:00
2012-04-09 13:20:24 +00:00
/**
* Returns if the Unix part of the current account is locked .
2015-08-09 07:22:01 +00:00
*
2017-05-10 17:23:28 +00:00
* @ param string [] $modules account modules
2012-04-09 13:20:24 +00:00
* @ return boolean password is locked
*/
2017-05-10 17:23:28 +00:00
public function isLocked ( & $modules ) {
return isset ( $this -> attributes [ $this -> getPasswordAttrName ( $modules )][ 0 ])
&& ! pwd_is_enabled ( $this -> attributes [ $this -> getPasswordAttrName ( $modules )][ 0 ]);
2012-04-09 13:20:24 +00:00
}
2015-08-09 07:22:01 +00:00
2012-04-09 13:20:24 +00:00
/**
* Locks the user password of this account .
2017-05-10 17:23:28 +00:00
*
* @ param string [] $modules account modules
2012-04-09 13:20:24 +00:00
*/
2017-05-10 17:23:28 +00:00
public function lock ( & $modules ) {
$pwdAttrName = $this -> getPasswordAttrName ( $modules );
2013-08-18 14:19:37 +00:00
if ( isset ( $this -> attributes [ $pwdAttrName ][ 0 ])) {
$this -> attributes [ $pwdAttrName ][ 0 ] = pwd_disable ( $this -> attributes [ $pwdAttrName ][ 0 ]);
2012-04-09 18:07:57 +00:00
}
2012-04-09 13:20:24 +00:00
}
2015-08-09 07:22:01 +00:00
2012-04-09 13:20:24 +00:00
/**
* Unlocks the user password of this account .
2017-05-10 17:23:28 +00:00
*
* @ param string [] $modules account modules
2012-04-09 13:20:24 +00:00
*/
2017-05-10 17:23:28 +00:00
public function unlock ( & $modules ) {
$pwdAttrName = $this -> getPasswordAttrName ( $modules );
2013-08-18 14:19:37 +00:00
if ( isset ( $this -> attributes [ $pwdAttrName ][ 0 ])) {
$this -> attributes [ $pwdAttrName ][ 0 ] = pwd_enable ( $this -> attributes [ $pwdAttrName ][ 0 ]);
2012-04-09 18:07:57 +00:00
}
2012-04-09 13:20:24 +00:00
}
2015-08-09 07:22:01 +00:00
2012-04-09 13:20:24 +00:00
/**
* Removes all Unix group memberships from this user .
*/
public function removeFromUnixGroups () {
$this -> groups = array ();
}
2015-08-09 07:22:01 +00:00
2012-04-09 13:20:24 +00:00
/**
* Removes all group of names memberships from this user .
*/
public function removeFromGONGroups () {
$this -> gonList = array ();
}
2015-08-09 07:22:01 +00:00
2012-09-23 17:59:14 +00:00
/**
* Returns the next possible user name based on the given one .
* If the user name does not end with a number then a " 2 " is added .
* User names with numbers at the end are simply increased by one .
* < br >
2015-08-09 07:22:01 +00:00
* < br > Attention : This user name might still be in use . This needs to be checked separately .
*
2012-09-23 17:59:14 +00:00
* @ param String $userName user name
2018-08-15 08:43:10 +00:00
* @ param string [] $moduleNames list of account module names
2012-09-23 17:59:14 +00:00
* @ return String new user name
*/
2018-08-15 08:43:10 +00:00
protected function getNextUserName ( $userName , $moduleNames ) {
if ( $this -> get_scope () == 'host' && in_array ( 'sambaSamAccount' , $moduleNames )) {
2012-09-23 17:59:14 +00:00
$userName = substr ( $userName , 0 , - 1 );
}
// get last character of username
$lastchar = substr ( $userName , strlen ( $userName ) - 1 , 1 );
2018-08-15 08:43:10 +00:00
$suffix = '' ;
if (( $this -> get_scope () == 'host' ) && in_array ( 'sambaSamAccount' , $moduleNames )) {
$suffix = '$' ;
}
2012-09-23 17:59:14 +00:00
// Last character is no number
if ( ! preg_match ( '/^([0-9])+$/' , $lastchar )) {
// Last character is no number. Therefore we only have to add "2" to it.
2018-08-15 08:43:10 +00:00
$userName = $userName . '2' . $suffix ;
2012-09-23 17:59:14 +00:00
}
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
*/
$i = strlen ( $userName ) - 1 ;
$mark = false ;
// Set $i to the last character which is a number in $account_new->general_username
while ( ! $mark ) {
if ( preg_match ( '/^([0-9])+$/' , substr ( $userName , $i , strlen ( $userName ) - $i ))) {
$i -- ;
}
else {
$mark = true ;
}
}
// increase last number with one
$firstchars = substr ( $userName , 0 , $i + 1 );
$lastchars = substr ( $userName , $i + 1 , strlen ( $userName ) - $i );
// Put username together
2018-08-15 08:43:10 +00:00
$userName = $firstchars . ( intval ( $lastchars ) + 1 ) . $suffix ;
2012-09-23 17:59:14 +00:00
}
return $userName ;
}
2015-08-09 07:22:01 +00:00
2013-02-05 19:10:04 +00:00
/**
* Returns the list of possible login shells .
2015-08-09 07:22:01 +00:00
*
2013-02-05 19:10:04 +00:00
* @ return array login shells
*/
private function getShells () {
// self service
2014-10-25 19:17:53 +00:00
if ( ! isLoggedIn () && isset ( $this -> selfServiceSettings ) && isset ( $this -> selfServiceSettings -> moduleSettings [ 'posixAccount_shells' ])
2013-02-05 19:10:04 +00:00
&& ( sizeof ( $this -> selfServiceSettings -> moduleSettings [ 'posixAccount_shells' ])) > 0 ) {
return $this -> selfServiceSettings -> moduleSettings [ 'posixAccount_shells' ];
}
// server profile
if ( ! isset ( $this -> selfServiceSettings ) && isset ( $this -> moduleSettings ) && isset ( $this -> moduleSettings [ 'posixAccount_shells' ])
&& ( sizeof ( $this -> moduleSettings [ 'posixAccount_shells' ])) > 0 ) {
return $this -> moduleSettings [ 'posixAccount_shells' ];
}
// fall back to default
return array (
'/bin/bash' ,
'/bin/csh' ,
'/bin/dash' ,
'/bin/false' ,
'/bin/ksh' ,
'/bin/sh'
);
}
2015-08-09 07:22:01 +00:00
2013-08-18 12:24:53 +00:00
/**
* Returns if the cn attribute should be managed .
* If Windows modules are active then cn will not be managed .
2015-08-09 07:22:01 +00:00
*
2017-05-10 17:23:28 +00:00
* @ param string [] $modules account modules
2013-08-18 12:24:53 +00:00
* @ return boolean manage cn attribute
*/
2017-05-10 17:23:28 +00:00
private function manageCn ( & $modules ) {
return ! $this -> isWindows ( $modules );
2013-08-18 12:24:53 +00:00
}
2015-08-09 07:22:01 +00:00
2013-08-18 12:24:53 +00:00
/**
* Returns if the Unix part can be added and removed .
2015-08-09 07:22:01 +00:00
*
2017-05-10 17:23:28 +00:00
* @ param string [] $modules account modules
2013-08-18 12:24:53 +00:00
* @ return boolean is optional
*/
2017-05-10 17:23:28 +00:00
private function isOptional ( & $modules ) {
return ! $this -> manageCn ( $modules );
2013-08-18 12:24:53 +00:00
}
2014-05-15 19:30:46 +00:00
/**
* Returns if the Windows module is active .
2015-08-09 07:22:01 +00:00
*
2017-05-10 17:23:28 +00:00
* @ param string [] $modules account modules
2014-05-15 19:30:46 +00:00
* @ return boolean is Windows
*/
2017-05-10 17:23:28 +00:00
private function isWindows ( & $modules ) {
return in_array ( 'windowsUser' , $modules );
2014-05-15 19:30:46 +00:00
}
2013-08-18 14:19:37 +00:00
/**
* Returns the password attribute .
* Usually , this is userPassword . If Windows modules are active this is unixUserPassword .
2015-08-09 07:22:01 +00:00
*
2017-05-10 17:23:28 +00:00
* @ param string [] $modules account modules
2013-08-18 14:19:37 +00:00
* @ return boolean attribute name
*/
2017-05-10 17:23:28 +00:00
private function getPasswordAttrName ( & $modules ) {
if ( $this -> isWindows ( $modules )) {
return 'unixUserPassword' ;
2013-08-18 14:19:37 +00:00
}
2017-05-10 17:23:28 +00:00
return 'userPassword' ;
2013-08-18 14:19:37 +00:00
}
2015-08-09 07:22:01 +00:00
2013-08-18 14:19:37 +00:00
/**
* Returns the home directory attribute .
* Usually , this is homeDirectory . If Windows modules are active this is unixHomeDirectory .
2015-08-09 07:22:01 +00:00
*
2017-05-10 17:23:28 +00:00
* @ param string [] $modules account modules
2013-08-18 14:19:37 +00:00
* @ return boolean attribute name
*/
2017-05-10 17:23:28 +00:00
private function getHomedirAttrName ( & $modules ) {
if ( $this -> isWindows ( $modules )) {
return 'unixHomeDirectory' ;
2013-08-18 14:19:37 +00:00
}
2017-05-10 17:23:28 +00:00
return 'homeDirectory' ;
2013-08-18 14:19:37 +00:00
}
2015-08-09 07:22:01 +00:00
2015-05-31 08:46:44 +00:00
/**
* Syncs the group of names with groups .
*/
private function syncGonToGroups () {
$this -> groups = array ();
$allGons = $this -> findGroupOfNames ();
foreach ( $this -> gonList as $dn ) {
if ( ! isset ( $allGons [ $dn ])) {
continue ;
}
$gon = $this -> gonCache [ $dn ];
if ( in_array_ignore_case ( 'posixGroup' , $gon [ 'objectclass' ]) && ! empty ( $gon [ 'cn' ])) {
$this -> groups [] = $gon [ 'cn' ][ 0 ];
}
}
}
2015-08-09 07:22:01 +00:00
2016-05-09 18:10:14 +00:00
/**
* Returns if the object class should not be added .
*
* @ return do not add
*/
private function skipObjectClass () {
return $this -> isBooleanConfigOptionSet ( 'posixAccount_noObjectClass' );
}
2016-11-19 18:20:44 +00:00
/**
2017-06-05 07:39:29 +00:00
* { @ inheritdoc }
2016-11-19 18:20:44 +00:00
*/
public function getWildCardReplacements () {
$replacements = array ();
// user name
if ( ! empty ( $_POST [ 'uid' ])) {
$replacements [ 'user' ] = $_POST [ 'uid' ];
}
elseif ( ! empty ( $this -> attributes [ 'uid' ][ 0 ])) {
$replacements [ 'user' ] = $this -> attributes [ 'uid' ][ 0 ];
}
// group name
if ( ! empty ( $_POST [ 'gidNumber' ])) {
$replacements [ 'group' ] = $this -> getGroupName ( $_POST [ 'gidNumber' ]);
}
elseif ( ! empty ( $this -> attributes [ 'gidNumber' ][ 0 ])) {
$replacements [ 'group' ] = $this -> getGroupName ( $this -> attributes [ 'gidNumber' ][ 0 ]);
}
return $replacements ;
}
2018-11-17 19:40:09 +00:00
/**
* Returns the current group names .
*
* @ return string [] group names
*/
public function getGroups () {
return $this -> groups ;
}
/**
* Returns the list of group of names where this user is member .
*
* @ return string [] list of DNs
*/
public function getGroupOfNames () {
return $this -> gonList ;
}
2004-03-09 12:03:39 +00:00
}
2003-12-09 18:42:50 +00:00
?>