* Admin: if group was selected only active accounts were shown and show primary group in LDAP

This commit is contained in:
Ralf Becker 2014-10-22 17:10:12 +00:00
parent f58cb571ef
commit bc864c4103
5 changed files with 91 additions and 99 deletions

View File

@ -43,7 +43,7 @@ class admin_ui
} }
$tpl = new etemplate_new('admin.index'); $tpl = new etemplate_new('admin.index');
$content = array(); if (!is_array($content)) $content = array();
$content['nm'] = array( $content['nm'] = array(
'get_rows' => 'admin_ui::get_users', 'get_rows' => 'admin_ui::get_users',
'no_cat' => true, 'no_cat' => true,
@ -338,7 +338,7 @@ class admin_ui
* )), * )),
* )); * ));
* *
* @param string $root='/' * @param string $root ='/'
* @return array * @return array
*/ */
public static function tree_data($root = '/') public static function tree_data($root = '/')

View File

@ -164,7 +164,7 @@ class accounts
/** /**
* Constructor * Constructor
* *
* @param string|array $backend=null string with backend 'sql'|'ldap', or whole config array, default read from global egw_info * @param string|array $backend =null string with backend 'sql'|'ldap', or whole config array, default read from global egw_info
*/ */
public function __construct($backend=null) public function __construct($backend=null)
{ {
@ -209,7 +209,7 @@ class accounts
/** /**
* Old constructor name * Old constructor name
* *
* @param int $account_id=0 depricated param to instanciate for the given account_id * @param int $account_id =0 depricated param to instanciate for the given account_id
* @deprecated use __construct * @deprecated use __construct
*/ */
function accounts($account_id=0) function accounts($account_id=0)
@ -291,7 +291,7 @@ class accounts
$members = array(); $members = array();
foreach((array)$this->memberships($GLOBALS['egw_info']['user']['account_id'],true) as $grp) foreach((array)$this->memberships($GLOBALS['egw_info']['user']['account_id'],true) as $grp)
{ {
$members = array_unique(array_merge($members, (array)$this->members($grp,true))); $members = array_unique(array_merge($members, (array)$this->members($grp,true,$param['active'])));
if ($param['type'] == 'groupmembers+memberships') $members[] = $grp; if ($param['type'] == 'groupmembers+memberships') $members[] = $grp;
} }
$param['type'] = $param['type'] == 'groupmembers+memberships' ? 'both' : 'accounts'; $param['type'] = $param['type'] == 'groupmembers+memberships' ? 'both' : 'accounts';
@ -304,7 +304,7 @@ class accounts
if ($app) if ($app)
{ {
// we want the result merged, whatever it takes, as we only care for the ids // we want the result merged, whatever it takes, as we only care for the ids
$valid = $this->split_accounts($app,!in_array($param['type'],array('accounts','groups')) ? 'merge' : $param['type']); $valid = $this->split_accounts($app,!in_array($param['type'],array('accounts','groups')) ? 'merge' : $param['type'],$param['active']);
} }
if (isset($members)) if (isset($members))
{ {
@ -411,8 +411,8 @@ class accounts
* All key of the returned array use the 'account_' prefix. * All key of the returned array use the 'account_' prefix.
* For backward compatibility some values are additionaly availible without the prefix, using them is depricated! * For backward compatibility some values are additionaly availible without the prefix, using them is depricated!
* *
* @param int/string $id numeric account_id or string with account_lid (use of default value of 0 is depricated!!!) * @param int|string $id numeric account_id or string with account_lid (use of default value of 0 is depricated!!!)
* @param boolean $set_depricated_names=false set _additionaly_ the depricated keys without 'account_' prefix * @param boolean $set_depricated_names =false set _additionaly_ the depricated keys without 'account_' prefix
* @return array/boolean array with account data (keys: account_id, account_lid, ...) or false if account not found * @return array/boolean array with account data (keys: account_id, account_lid, ...) or false if account not found
*/ */
function read($id=0,$set_depricated_names=false) function read($id=0,$set_depricated_names=false)
@ -475,8 +475,8 @@ class accounts
* If no account_id is set in data the account is added and the new id is set in $data. * If no account_id is set in data the account is added and the new id is set in $data.
* *
* @param array $data array with account-data * @param array $data array with account-data
* @param boolean $check_depricated_names=false check _additionaly_ the depricated keys without 'account_' prefix * @param boolean $check_depricated_names =false check _additionaly_ the depricated keys without 'account_' prefix
* @return int/boolean the account_id or false on error * @return int|boolean the account_id or false on error
*/ */
function save(&$data,$check_depricated_names=false) function save(&$data,$check_depricated_names=false)
{ {
@ -527,7 +527,7 @@ class accounts
/** /**
* Delete one account, deletes also all acl-entries for that account * Delete one account, deletes also all acl-entries for that account
* *
* @param int/string $id numeric account_id or string with account_lid * @param int|string $id numeric account_id or string with account_lid
* @return boolean true on success, false otherwise * @return boolean true on success, false otherwise
*/ */
function delete($id) function delete($id)
@ -566,7 +566,7 @@ class accounts
* *
* Can be used static if array with user-data is supplied * Can be used static if array with user-data is supplied
* *
* @param array $data=null array with account data, not specifying the account is depricated!!! * @param array $data =null array with account data, not specifying the account is depricated!!!
* @return boolean true=expired (no more login possible), false otherwise * @return boolean true=expired (no more login possible), false otherwise
*/ */
function is_expired($data=null) function is_expired($data=null)
@ -601,9 +601,9 @@ class accounts
* - if multiple user have the same email address, the returned user is undefined * - if multiple user have the same email address, the returned user is undefined
* *
* @param string $name value to convert * @param string $name value to convert
* @param string $which='account_lid' type of $name: account_lid (default), account_email, person_id, account_fullname * @param string $which ='account_lid' type of $name: account_lid (default), account_email, person_id, account_fullname
* @param string $account_type=null u = user or g = group, or default null = try both * @param string $account_type =null u = user or g = group, or default null = try both
* @return int/false numeric account_id or false on error ($name not found) * @return int|false numeric account_id or false on error ($name not found)
*/ */
function name2id($name,$which='account_lid',$account_type=null) function name2id($name,$which='account_lid',$account_type=null)
{ {
@ -630,7 +630,7 @@ class accounts
* Uses the read method to fetch all data. * Uses the read method to fetch all data.
* *
* @param int|string $account_id numeric account_id or account_lid * @param int|string $account_id numeric account_id or account_lid
* @param string $which='account_lid' type to convert to: account_lid (default), account_email, ... * @param string $which ='account_lid' type to convert to: account_lid (default), account_email, ...
* @return string|boolean converted value or false on error ($account_id not found) * @return string|boolean converted value or false on error ($account_id not found)
*/ */
static function id2name($account_id, $which='account_lid') static function id2name($account_id, $which='account_lid')
@ -653,7 +653,7 @@ class accounts
/** /**
* get the type of an account: 'u' = user, 'g' = group * get the type of an account: 'u' = user, 'g' = group
* *
* @param int/string $accountid numeric account-id or alphanum. account-lid, * @param int|string $account_id numeric account-id or alphanum. account-lid,
* if !$accountid account of the user of this session * if !$accountid account of the user of this session
* @return string/false 'u' = user, 'g' = group or false on error ($accountid not found) * @return string/false 'u' = user, 'g' = group or false on error ($accountid not found)
*/ */
@ -669,7 +669,7 @@ class accounts
/** /**
* check if an account exists and if it is an user or group * check if an account exists and if it is an user or group
* *
* @param int/string $account_id numeric account_id or account_lid * @param int|string $account_id numeric account_id or account_lid
* @return int 0 = acount does not exist, 1 = user, 2 = group * @return int 0 = acount does not exist, 1 = user, 2 = group
*/ */
function exists($account_id) function exists($account_id)
@ -718,8 +718,8 @@ class accounts
/** /**
* Get all memberships of an account $account_id / groups the account is a member off * Get all memberships of an account $account_id / groups the account is a member off
* *
* @param int/string $account_id numeric account-id or alphanum. account-lid * @param int|string $account_id numeric account-id or alphanum. account-lid
* @param boolean $just_id=false return just account_id's or account_id => account_lid pairs * @param boolean $just_id =false return just account_id's or account_id => account_lid pairs
* @return array with account_id's ($just_id) or account_id => account_lid pairs (!$just_id) * @return array with account_id's ($just_id) or account_id => account_lid pairs (!$just_id)
*/ */
function memberships($account_id, $just_id=false) function memberships($account_id, $just_id=false)
@ -765,10 +765,10 @@ class accounts
/** /**
* Get all members of the group $account_id * Get all members of the group $account_id
* *
* @param int/string $accountid='' numeric account-id or alphanum. account-lid, * @param int|string $account_id ='' numeric account-id or alphanum. account-lid,
* default account of the user of this session * default account of the user of this session
* @param boolean $just_id=false return just an array of id's and not id => lid pairs, default false * @param boolean $just_id =false return just an array of id's and not id => lid pairs, default false
* @param boolean $active=false true: return only active (not expired or deactived) members, false: return all accounts * @param boolean $active =false true: return only active (not expired or deactived) members, false: return all accounts
* @return array with account_id ($just_id) or account_id => account_lid pairs (!$just_id) * @return array with account_id ($just_id) or account_id => account_lid pairs (!$just_id)
*/ */
function members($account_id, $just_id=false, $active=true) function members($account_id, $just_id=false, $active=true)
@ -814,9 +814,10 @@ class accounts
* @param string $use what should be returned only an array with id's of either 'accounts' or 'groups'. * @param string $use what should be returned only an array with id's of either 'accounts' or 'groups'.
* Or an array with arrays for 'both' under the keys 'groups' and 'accounts' or 'merge' for accounts * Or an array with arrays for 'both' under the keys 'groups' and 'accounts' or 'merge' for accounts
* and groups merged into one array * and groups merged into one array
* @param boolean $active =false true: return only active (not expired or deactived) members, false: return all accounts
* @return array/boolean see $use, false on error (wront $use) * @return array/boolean see $use, false on error (wront $use)
*/ */
function split_accounts($app_users,$use='both') function split_accounts($app_users,$use='both',$active=true)
{ {
if (!is_array($app_users)) if (!is_array($app_users))
{ {
@ -841,7 +842,7 @@ class accounts
$accounts['groups'][$id] = $id; $accounts['groups'][$id] = $id;
if ($use != 'groups') if ($use != 'groups')
{ {
foreach((array)$this->members($id, true) as $id) foreach((array)$this->members($id, true, $active) as $id)
{ {
$accounts['accounts'][$id] = $id; $accounts['accounts'][$id] = $id;
} }
@ -885,7 +886,7 @@ class accounts
* @param string $account_lid * @param string $account_lid
* @param string $passwd * @param string $passwd
* @param array $GLOBALS['auto_create_acct'] values for 'firstname', 'lastname', 'email' and 'primary_group' * @param array $GLOBALS['auto_create_acct'] values for 'firstname', 'lastname', 'email' and 'primary_group'
* @return int/boolean account_id or false on error * @return int|boolean account_id or false on error
*/ */
function auto_add($account_lid, $passwd) function auto_add($account_lid, $passwd)
{ {
@ -1049,7 +1050,7 @@ class accounts
* Read account incl. members/memberships from cache (or backend and cache it) * Read account incl. members/memberships from cache (or backend and cache it)
* *
* @param int $account_id * @param int $account_id
* @param boolean $need_active=false true = 'members-active' required * @param boolean $need_active =false true = 'members-active' required
* @return array * @return array
* @throws egw_exception_wrong_parameter if no integer was passed as $account_id * @throws egw_exception_wrong_parameter if no integer was passed as $account_id
*/ */
@ -1191,8 +1192,8 @@ class accounts
* Create a new account with the given $account_info * Create a new account with the given $account_info
* *
* @deprecated use save * @deprecated use save
* @param array $data account data for the new account * @param array $account_info account data for the new account
* @param booelan $default_prefs has no meaning any more, as we use "real" default prefs since 1.0 * @param booelan $default_prefs =true has no meaning any more, as we use "real" default prefs since 1.0
* @return int new nummeric account-id * @return int new nummeric account-id
*/ */
function create($account_info,$default_prefs=True) function create($account_info,$default_prefs=True)
@ -1217,13 +1218,13 @@ class accounts
* Get all memberships of an account $accountid / groups the account is a member off * Get all memberships of an account $accountid / groups the account is a member off
* *
* @deprecated use memberships() which account_id => account_lid pairs * @deprecated use memberships() which account_id => account_lid pairs
* @param int/string $accountid='' numeric account-id or alphanum. account-lid, * @param int|string $_accountid ='' numeric account-id or alphanum. account-lid,
* default account of the user of this session * default account of the user of this session
* @return array or arrays with keys 'account_id' and 'account_name' for the groups $accountid is a member of * @return array or arrays with keys 'account_id' and 'account_name' for the groups $accountid is a member of
*/ */
function membership($accountid = '') function membership($_accountid = '')
{ {
$accountid = get_account_id($accountid); $accountid = get_account_id($_accountid);
if (!($memberships = $this->memberships($accountid))) if (!($memberships = $this->memberships($accountid)))
{ {
@ -1242,7 +1243,7 @@ class accounts
* Get all members of the group $accountid * Get all members of the group $accountid
* *
* @deprecated use members which returns acount_id => account_lid pairs * @deprecated use members which returns acount_id => account_lid pairs
* @param int/string $accountid='' numeric account-id or alphanum. account-lid, * @param int|string $accountid ='' numeric account-id or alphanum. account-lid,
* default account of the user of this session * default account of the user of this session
* @return array of arrays with keys 'account_id' and 'account_name' * @return array of arrays with keys 'account_id' and 'account_name'
*/ */
@ -1280,7 +1281,7 @@ class accounts
* Gets account-name (lid), firstname and lastname of an account $accountid * Gets account-name (lid), firstname and lastname of an account $accountid
* *
* @deprecated use read to read account data * @deprecated use read to read account data
* @param int/string $accountid='' numeric account-id or alphanum. account-lid, * @param int|string $accountid ='' numeric account-id or alphanum. account-lid,
* if !$accountid account of the user of this session * if !$accountid account of the user of this session
* @param string &$lid on return: alphanumeric account-name (lid) * @param string &$lid on return: alphanumeric account-name (lid)
* @param string &$fname on return: first name * @param string &$fname on return: first name
@ -1307,7 +1308,7 @@ class accounts
* Same effect as instanciating the class with that account, dont do it with $GLOBALS['egw']->account !!! * Same effect as instanciating the class with that account, dont do it with $GLOBALS['egw']->account !!!
* *
* @deprecated use read to read account data and store it in your own code * @deprecated use read to read account data and store it in your own code
* @param int $accountid numeric account-id * @param int $account_id numeric account-id
* @return array with keys lid, firstname, lastname, fullname, type * @return array with keys lid, firstname, lastname, fullname, type
*/ */
function get_account_data($account_id) function get_account_data($account_id)

View File

@ -200,7 +200,7 @@ class accounts_ads
* *
* Can be set via server-config "ads_context", otherwise baseDN is used * Can be set via server-config "ads_context", otherwise baseDN is used
* *
* @param boolean $set_if_empty=false true set from DN of "Domain Users" group # * @param boolean $set_if_empty =false true set from DN of "Domain Users" group #
* @return string * @return string
*/ */
public function ads_context($set_if_empty=false) public function ads_context($set_if_empty=false)
@ -244,7 +244,7 @@ class accounts_ads
/** /**
* Get connection to ldap server from adLDAP * Get connection to ldap server from adLDAP
* *
* @param boolean $reconnect=false true: reconnect even if already connected * @param boolean $reconnect =false true: reconnect even if already connected
* @return resource * @return resource
*/ */
public function ldap_connection($reconnect=false) public function ldap_connection($reconnect=false)
@ -373,7 +373,7 @@ class accounts_ads
/** /**
* Delete one account, deletes also all acl-entries for that account * Delete one account, deletes also all acl-entries for that account
* *
* @param int $id numeric account_id * @param int $account_id numeric account_id
* @return boolean true on success, false otherwise * @return boolean true on success, false otherwise
*/ */
function delete($account_id) function delete($account_id)
@ -403,12 +403,12 @@ class accounts_ads
/** /**
* Convert ldap data of a group * Convert ldap data of a group
* *
* @param array $data * @param array $_data
* @return array * @return array
*/ */
protected function _ldap2group($data) protected function _ldap2group($_data)
{ {
$data = translation::convert($data, 'utf-8'); $data = translation::convert($_data, 'utf-8');
// no need to calculate sid, if already calculated // no need to calculate sid, if already calculated
$sid = is_string($data['objectsid']) ? $data['objectsid'] : $sid = is_string($data['objectsid']) ? $data['objectsid'] :
@ -464,12 +464,12 @@ class accounts_ads
/** /**
* Convert ldap data of a user * Convert ldap data of a user
* *
* @param array $data * @param array $_data
* @return array * @return array
*/ */
protected function _ldap2user(array $data) protected function _ldap2user(array $_data)
{ {
$data = translation::convert($data, 'utf-8'); $data = translation::convert($_data, 'utf-8');
// no need to calculate sid, if already calculated // no need to calculate sid, if already calculated
$sid = is_string($data['objectsid']) ? $data['objectsid'] : $sid = is_string($data['objectsid']) ? $data['objectsid'] :
@ -483,7 +483,7 @@ class accounts_ads
'account_guid' => $this->adldap->utilities()->decodeGuid($data['objectguid'][0]), 'account_guid' => $this->adldap->utilities()->decodeGuid($data['objectguid'][0]),
'account_lid' => $data['samaccountname'][0], 'account_lid' => $data['samaccountname'][0],
'account_type' => 'u', 'account_type' => 'u',
'account_primary_group' => -$data['primarygroupid'][0], 'account_primary_group' => (string)-$data['primarygroupid'][0],
'account_firstname' => $data['givenname'][0], 'account_firstname' => $data['givenname'][0],
'account_lastname' => $data['sn'][0], 'account_lastname' => $data['sn'][0],
'account_email' => $data['mail'][0], 'account_email' => $data['mail'][0],
@ -552,15 +552,15 @@ class accounts_ads
/** /**
* Convert when(Created|Changed) attribute to unix timestamp * Convert when(Created|Changed) attribute to unix timestamp
* *
* @param string $when eg. "20130520200000.0Z" * @param string $_when eg. "20130520200000.0Z"
* @return int * @return int
*/ */
protected static function _when2ts($when) protected static function _when2ts($_when)
{ {
static $utc=null; static $utc=null;
if (!isset($utc)) $utc = new DateTimeZone('UTC'); if (!isset($utc)) $utc = new DateTimeZone('UTC');
list($when) = explode('.', $when); // remove .0Z not understood by createFromFormat list($when) = explode('.', $_when); // remove .0Z not understood by createFromFormat
$datetime = egw_time::createFromFormat(self::WHEN_FORMAT, $when, $utc); $datetime = egw_time::createFromFormat(self::WHEN_FORMAT, $when, $utc);
if (egw_time::$server_timezone) $datetime->setTimezone(egw_time::$server_timezone); if (egw_time::$server_timezone) $datetime->setTimezone(egw_time::$server_timezone);
@ -572,7 +572,7 @@ class accounts_ads
* *
* @internal * @internal
* @param array $data array with account-data in utf-8 * @param array $data array with account-data in utf-8
* @param array $old=null current data * @param array $old =null current data
* @return int|false account_id or false on error * @return int|false account_id or false on error
*/ */
protected function _save_group(array &$data, array $old=null) protected function _save_group(array &$data, array $old=null)
@ -653,7 +653,7 @@ class accounts_ads
* *
* @internal * @internal
* @param array $data array with account-data in utf-8 * @param array $data array with account-data in utf-8
* @param array $old=null current data * @param array $old =null current data
* @return int|false account_id or false on error * @return int|false account_id or false on error
*/ */
protected function _save_user(array &$data, array $old=null) protected function _save_user(array &$data, array $old=null)
@ -1001,8 +1001,8 @@ class accounts_ads
* *
* @param string|array $attr_filter array with attribute => value pairs or filter string or empty * @param string|array $attr_filter array with attribute => value pairs or filter string or empty
* @param string $account_type u = user, g = group, default null = try both * @param string $account_type u = user, g = group, default null = try both
* @param array $attrs=null default return account_lid, else return raw values from ldap-query * @param array $attrs =null default return account_lid, else return raw values from ldap-query
* @param array $accounts=array() array to add filtered accounts too, default empty array * @param array $accounts =array() array to add filtered accounts too, default empty array
* @return array account_id => account_lid or values for $attrs pairs * @return array account_id => account_lid or values for $attrs pairs
*/ */
protected function filter($attr_filter, $account_type=null, array $attrs=null, array $accounts=array()) protected function filter($attr_filter, $account_type=null, array $attrs=null, array $accounts=array())
@ -1084,7 +1084,7 @@ class accounts_ads
* - if multiple user have the same email address, the returned user is undefined * - if multiple user have the same email address, the returned user is undefined
* *
* @param string $name value to convert * @param string $name value to convert
* @param string $which='account_lid' type of $name: account_lid (default), account_email, person_id, account_fullname * @param string $which ='account_lid' type of $name: account_lid (default), account_email, person_id, account_fullname
* @param string $account_type u = user, g = group, default null = try both * @param string $account_type u = user, g = group, default null = try both
* @return int|false numeric account_id or false on error ($name not found) * @return int|false numeric account_id or false on error ($name not found)
*/ */
@ -1117,7 +1117,7 @@ class accounts_ads
* Calls frontend which uses (cached) read method to fetch all data by account_id. * Calls frontend which uses (cached) read method to fetch all data by account_id.
* *
* @param int $account_id numerica account_id * @param int $account_id numerica account_id
* @param string $which='account_lid' type to convert to: account_lid (default), account_email, ... * @param string $which ='account_lid' type to convert to: account_lid (default), account_email, ...
* @return string/false converted value or false on error ($account_id not found) * @return string/false converted value or false on error ($account_id not found)
*/ */
public function id2name($account_id, $which='account_lid') public function id2name($account_id, $which='account_lid')
@ -1128,7 +1128,7 @@ class accounts_ads
/** /**
* Update the last login timestamps and the IP * Update the last login timestamps and the IP
* *
* @param int $account_id * @param int $_account_id
* @param string $ip * @param string $ip
* @return int lastlogin time * @return int lastlogin time
*/ */

View File

@ -295,7 +295,7 @@ class accounts_ldap
if (!$members) $members = $this->members($data['account_id']); if (!$members) $members = $this->members($data['account_id']);
$to_write[$forward] = array(); $to_write[$forward] = array();
foreach ($members as $member => $account_lid) foreach (array_keys($members) as $member)
{ {
if (($email = $this->id2name($member,'account_email'))) if (($email = $this->id2name($member,'account_email')))
{ {
@ -375,7 +375,7 @@ class accounts_ldap
/** /**
* Delete one account, deletes also all acl-entries for that account * Delete one account, deletes also all acl-entries for that account
* *
* @param int $id numeric account_id * @param int $account_id numeric account_id
* @return boolean true on success, false otherwise * @return boolean true on success, false otherwise
*/ */
function delete($account_id) function delete($account_id)
@ -413,12 +413,12 @@ class accounts_ldap
$sri = ldap_search($this->ds, $this->group_context,'(&(objectClass=posixGroup)(gidnumber=' . abs($account_id).'))', $sri = ldap_search($this->ds, $this->group_context,'(&(objectClass=posixGroup)(gidnumber=' . abs($account_id).'))',
array('dn','gidnumber','cn','objectclass','mail')); array('dn','gidnumber','cn','objectclass','mail'));
$data = ldap_get_entries($this->ds, $sri); $ldap_data = ldap_get_entries($this->ds, $sri);
if (!$data['count']) if (!$ldap_data['count'])
{ {
return false; // group not found return false; // group not found
} }
$data = translation::convert($data[0],'utf-8'); $data = translation::convert($ldap_data[0],'utf-8');
$group = array( $group = array(
'account_dn' => $data['dn'], 'account_dn' => $data['dn'],
@ -435,7 +435,7 @@ class accounts_ldap
{ {
$this->ldapServerInfo = $this->ldap->getLDAPServerInfo($this->frontend->config['ldap_host']); $this->ldapServerInfo = $this->ldap->getLDAPServerInfo($this->frontend->config['ldap_host']);
} }
foreach($this->group_mail_classes as $objectclass => $forward) foreach(array_keys($this->group_mail_classes) as $objectclass)
{ {
if ($this->ldapServerInfo->supportsObjectClass($objectclass)) if ($this->ldapServerInfo->supportsObjectClass($objectclass))
{ {
@ -459,12 +459,12 @@ class accounts_ldap
array('dn','uidnumber','uid','gidnumber','givenname','sn','cn','mail','userpassword','telephonenumber', array('dn','uidnumber','uid','gidnumber','givenname','sn','cn','mail','userpassword','telephonenumber',
'shadowexpire','shadowlastchange','homedirectory','loginshell','createtimestamp','modifytimestamp')); 'shadowexpire','shadowlastchange','homedirectory','loginshell','createtimestamp','modifytimestamp'));
$data = ldap_get_entries($this->ds, $sri); $ldap_data = ldap_get_entries($this->ds, $sri);
if (!$data['count']) if (!$ldap_data['count'])
{ {
return false; // user not found return false; // user not found
} }
$data = translation::convert($data[0],'utf-8'); $data = translation::convert($ldap_data[0],'utf-8');
$utc_diff = date('Z'); $utc_diff = date('Z');
$user = array( $user = array(
@ -566,7 +566,6 @@ class accounts_ldap
// - if it's set to > 0, it will or already has expired --> acount is active if it not yet expired // - if it's set to > 0, it will or already has expired --> acount is active if it not yet expired
// shadowexpire is in days since 1970/01/01 (equivalent to a timestamp (int UTC!) / (24*60*60) // shadowexpire is in days since 1970/01/01 (equivalent to a timestamp (int UTC!) / (24*60*60)
$shadowexpire = ($data['account_expires']-$utc_diff) / (24*3600); $shadowexpire = ($data['account_expires']-$utc_diff) / (24*3600);
$account_expire = $shadowexpire*3600*24+$utc_diff;
//echo "<p align=right>account_expires=".date('Y-m-d H:i',$data['account_expires'])." --> $shadowexpire --> ".date('Y-m-d H:i',$account_expire)."</p>\n"; //echo "<p align=right>account_expires=".date('Y-m-d H:i',$data['account_expires'])." --> $shadowexpire --> ".date('Y-m-d H:i',$account_expire)."</p>\n";
$to_write['shadowexpire'] = !$data['account_status'] ? $to_write['shadowexpire'] = !$data['account_status'] ?
($data['account_expires'] != -1 && $data['account_expires'] < time() ? round($shadowexpire) : 0) : ($data['account_expires'] != -1 && $data['account_expires'] < time() ? round($shadowexpire) : 0) :
@ -676,8 +675,7 @@ class accounts_ldap
} }
} }
// add account_filter to filter (user has to be '*', as we otherwise only search uid's) // add account_filter to filter (user has to be '*', as we otherwise only search uid's)
$filter .= $this->account_filter; $filter .= str_replace(array('%user','%domain'),array('*',$GLOBALS['egw_info']['user']['domain']),$this->account_filter);
$filter = str_replace(array('%user','%domain'),array('*',$GLOBALS['egw_info']['user']['domain']),$filter);
$filter .= ')'; $filter .= ')';
if ($param['type'] != 'both') if ($param['type'] != 'both')
@ -694,6 +692,7 @@ class accounts_ldap
'account_lastname' => 'sn', 'account_lastname' => 'sn',
'account_email' => 'email', 'account_email' => 'email',
'account_fullname' => 'cn', 'account_fullname' => 'cn',
'account_primary_group' => 'gidnumber',
); );
$orders = explode(',',$param['order']); $orders = explode(',',$param['order']);
$order = isset($propertyMap[$orders[0]]) ? $propertyMap[$orders[0]] : 'uid'; $order = isset($propertyMap[$orders[0]]) ? $propertyMap[$orders[0]] : 'uid';
@ -723,7 +722,7 @@ class accounts_ldap
$filter = '(&(objectclass=posixaccount)(|(uid='.implode(')(uid=',$relevantAccounts).'))' . $this->account_filter.')'; $filter = '(&(objectclass=posixaccount)(|(uid='.implode(')(uid=',$relevantAccounts).'))' . $this->account_filter.')';
$filter = str_replace(array('%user','%domain'),array('*',$GLOBALS['egw_info']['user']['domain']),$filter); $filter = str_replace(array('%user','%domain'),array('*',$GLOBALS['egw_info']['user']['domain']),$filter);
} }
$sri = ldap_search($this->ds, $this->user_context, $filter,array('uid','uidNumber','givenname','sn','mail','shadowExpire','createtimestamp','modifytimestamp','objectclass')); $sri = ldap_search($this->ds, $this->user_context, $filter,array('uid','uidNumber','givenname','sn','mail','shadowExpire','createtimestamp','modifytimestamp','objectclass','gidNumber'));
//echo "<p>ldap_search(,$this->user_context,'$filter',) ".($sri ? '' : ldap_error($this->ds)).microtime()."</p>\n"; //echo "<p>ldap_search(,$this->user_context,'$filter',) ".($sri ? '' : ldap_error($this->ds)).microtime()."</p>\n";
$utc_diff = date('Z'); $utc_diff = date('Z');
@ -740,11 +739,13 @@ class accounts_ldap
'account_firstname' => translation::convert($allVals['givenname'][0],'utf-8'), 'account_firstname' => translation::convert($allVals['givenname'][0],'utf-8'),
'account_lastname' => translation::convert($allVals['sn'][0],'utf-8'), 'account_lastname' => translation::convert($allVals['sn'][0],'utf-8'),
'account_status' => isset($allVals['shadowexpire'][0]) && $allVals['shadowexpire'][0]*24*3600-$utc_diff < time() ? false : 'A', 'account_status' => isset($allVals['shadowexpire'][0]) && $allVals['shadowexpire'][0]*24*3600-$utc_diff < time() ? false : 'A',
'account_expires' => isset($data['shadowexpire']) && $data['shadowexpire'][0] ? $data['shadowexpire'][0]*24*3600+$utc_diff : -1, // LDAP date is in UTC 'account_expires' => isset($allVals['shadowexpire']) && $allVals['shadowexpire'][0] ? $allVals['shadowexpire'][0]*24*3600+$utc_diff : -1, // LDAP date is in UTC
'account_email' => $allVals['mail'][0], 'account_email' => $allVals['mail'][0],
'account_created' => isset($allVals['createtimestamp'][0]) ? self::accounts_ldap2ts($allVals['createtimestamp'][0]) : null, 'account_created' => isset($allVals['createtimestamp'][0]) ? self::accounts_ldap2ts($allVals['createtimestamp'][0]) : null,
'account_modified' => isset($allVals['modifytimestamp'][0]) ? self::accounts_ldap2ts($allVals['modifytimestamp'][0]) : null, 'account_modified' => isset($allVals['modifytimestamp'][0]) ? self::accounts_ldap2ts($allVals['modifytimestamp'][0]) : null,
'account_primary_group' => (string)-$allVals['gidnumber'][0],
); );
error_log(__METHOD__."() ldap=".array2string($allVals)." --> account=".array2string($account));
if ($param['active'] && !$this->frontend->is_active($account)) if ($param['active'] && !$this->frontend->is_active($account))
{ {
if (isset($totalcount)) --$totalcount; if (isset($totalcount)) --$totalcount;
@ -892,14 +893,14 @@ class accounts_ldap
* - if a group and an user have the same account_lid the group will be returned (LDAP only) * - if a group and an user have the same account_lid the group will be returned (LDAP only)
* - if multiple user have the same email address, the returned user is undefined * - if multiple user have the same email address, the returned user is undefined
* *
* @param string $name value to convert * @param string $_name value to convert
* @param string $which='account_lid' type of $name: account_lid (default), account_email, person_id, account_fullname * @param string $which ='account_lid' type of $name: account_lid (default), account_email, person_id, account_fullname
* @param string $account_type u = user, g = group, default null = try both * @param string $account_type u = user, g = group, default null = try both
* @return int|false numeric account_id or false on error ($name not found) * @return int|false numeric account_id or false on error ($name not found)
*/ */
function name2id($name,$which='account_lid',$account_type=null) function name2id($_name,$which='account_lid',$account_type=null)
{ {
$name = ldap::quote(translation::convert($name,translation::charset(),'utf-8')); $name = ldap::quote(translation::convert($_name,translation::charset(),'utf-8'));
if ($which == 'account_lid' && $account_type !== 'u') // groups only support account_lid if ($which == 'account_lid' && $account_type !== 'u') // groups only support account_lid
{ {
@ -938,7 +939,7 @@ class accounts_ldap
* Uses the read method to fetch all data. * Uses the read method to fetch all data.
* *
* @param int $account_id numerica account_id * @param int $account_id numerica account_id
* @param string $which='account_lid' type to convert to: account_lid (default), account_email, ... * @param string $which ='account_lid' type to convert to: account_lid (default), account_email, ...
* @return string/false converted value or false on error ($account_id not found) * @return string/false converted value or false on error ($account_id not found)
*/ */
function id2name($account_id,$which='account_lid') function id2name($account_id,$which='account_lid')
@ -949,24 +950,14 @@ class accounts_ldap
/** /**
* Update the last login timestamps and the IP * Update the last login timestamps and the IP
* *
* @param int $account_id * @param int $_account_id
* @param string $ip * @param string $ip
* @return int lastlogin time * @return int lastlogin time
*/ */
function update_lastlogin($_account_id, $ip) function update_lastlogin($_account_id, $ip)
{ {
unset($_account_id, $ip);
return false; // not longer supported return false; // not longer supported
$entry['phpgwaccountlastlogin'] = time();
$entry['phpgwaccountlastloginfrom'] = $ip;
$sri = ldap_search($this->ds, $this->frontend->config['ldap_context'], 'uidnumber=' . (int)$_account_id);
$allValues = ldap_get_entries($this->ds, $sri);
$dn = $allValues[0]['dn'];
@ldap_modify($this->ds, $dn, $entry);
return $allValues[0]['phpgwaccountlastlogin'][0];
} }
/** /**
@ -994,19 +985,19 @@ class accounts_ldap
/** /**
* Query the members of a group * Query the members of a group
* *
* @param int $gid * @param int $_gid
* @return array with uidnumber => uid pairs * @return array with uidnumber => uid pairs
*/ */
function members($gid) function members($_gid)
{ {
if (!is_numeric($gid)) if (!is_numeric($_gid))
{ {
// try to recover // try to recover
$gid = $this->name2id($gid,'account_lid','g'); $_gid = $this->name2id($_gid,'account_lid','g');
if (!is_numeric($gid)) return false; if (!is_numeric($_gid)) return false;
} }
$gid = abs($gid); // our gid is negative! $gid = abs($_gid); // our gid is negative!
$sri = ldap_search($this->ds,$this->group_context,"(&(objectClass=posixGroup)(gidnumber=$gid))",array('memberuid')); $sri = ldap_search($this->ds,$this->group_context,"(&(objectClass=posixGroup)(gidnumber=$gid))",array('memberuid'));
$group = ldap_get_entries($this->ds, $sri); $group = ldap_get_entries($this->ds, $sri);
@ -1063,8 +1054,8 @@ class accounts_ldap
* *
* @param array $members array with uidnumber or uid's * @param array $members array with uidnumber or uid's
* @param int $gid gidnumber of group to set * @param int $gid gidnumber of group to set
* @param boolean $groupOfNames=null should we set the member attribute of groupOfNames (default detect it) * @param boolean $groupOfNames =null should we set the member attribute of groupOfNames (default detect it)
* @param string $use_cn=null if set $cn is used instead $gid and the attributes are returned, not written to ldap * @param string $use_cn =null if set $cn is used instead $gid and the attributes are returned, not written to ldap
* @return boolean/array false on failure, array or true otherwise * @return boolean/array false on failure, array or true otherwise
*/ */
function set_members($members,$gid,$groupOfNames=null,$use_cn=null) function set_members($members,$gid,$groupOfNames=null,$use_cn=null)
@ -1118,7 +1109,7 @@ class accounts_ldap
* Using the common functions next_id and last_id, find the next available account_id * Using the common functions next_id and last_id, find the next available account_id
* *
* @internal * @internal
* @param $string $account_type='u' (optional, default to 'u') * @param string $account_type ='u' (optional, default to 'u')
* @return int|boolean integer account_id (negative for groups) or false if none is free anymore * @return int|boolean integer account_id (negative for groups) or false if none is free anymore
*/ */
protected function _get_nextid($account_type='u') protected function _get_nextid($account_type='u')

View File

@ -263,7 +263,7 @@ class accounts_sql
/** /**
* Delete one account, deletes also all acl-entries for that account * Delete one account, deletes also all acl-entries for that account
* *
* @param int $id numeric account_id * @param int $account_id numeric account_id
* @return boolean true on success, false otherwise * @return boolean true on success, false otherwise
*/ */
function delete($account_id) function delete($account_id)
@ -440,7 +440,7 @@ class accounts_sql
default: default:
if (is_numeric($param['type'])) if (is_numeric($param['type']))
{ {
$filter['account_id'] = $this->frontend->members($param['type'], true); $filter['account_id'] = $this->frontend->members($param['type'], true, $param['active']);
$filter['owner'] = 0; $filter['owner'] = 0;
break; break;
} }
@ -544,7 +544,7 @@ class accounts_sql
* - if multiple user have the same email address, the returned user is undefined * - if multiple user have the same email address, the returned user is undefined
* *
* @param string $name value to convert * @param string $name value to convert
* @param string $which='account_lid' type of $name: account_lid (default), account_email, person_id, account_fullname * @param string $which ='account_lid' type of $name: account_lid (default), account_email, person_id, account_fullname
* @param string $account_type u = user, g = group, default null = try both * @param string $account_type u = user, g = group, default null = try both
* @return int/false numeric account_id or false on error ($name not found) * @return int/false numeric account_id or false on error ($name not found)
*/ */
@ -597,7 +597,7 @@ class accounts_sql
* Uses the read method to fetch all data. * Uses the read method to fetch all data.
* *
* @param int $account_id numerica account_id * @param int $account_id numerica account_id
* @param string $which='account_lid' type to convert to: account_lid (default), account_email, ... * @param string $which ='account_lid' type to convert to: account_lid (default), account_email, ...
* @return string/false converted value or false on error ($account_id not found) * @return string/false converted value or false on error ($account_id not found)
*/ */
function id2name($account_id,$which='account_lid') function id2name($account_id,$which='account_lid')