* AD/LDAP: added a DN filter to the periodic import to e.g. use 2 OU with a shared base

This commit is contained in:
ralf 2023-08-21 17:14:56 +02:00
parent 293657a48b
commit e14fa4340b
3 changed files with 18 additions and 1 deletions

View File

@ -276,6 +276,12 @@ class Import
$contact = $reconnected = null; $contact = $reconnected = null;
foreach ($this->contacts->search('', false, '', 'account_lid', '', '', 'AND', $start, $filter) as $contact) foreach ($this->contacts->search('', false, '', 'account_lid', '', '', 'AND', $start, $filter) as $contact)
{ {
// if we have a regexp to filter the DN, continue on non-match
if (!empty($GLOBALS['egw_info']['server']['account_import_dn_regexp']) &&
!preg_match($GLOBALS['egw_info']['server']['account_import_dn_regexp'], $contact['dn']))
{
continue;
}
$new = null; $new = null;
if (!isset($last_modified) || (int)$last_modified < (int)$contact['modified']) if (!isset($last_modified) || (int)$last_modified < (int)$contact['modified'])
{ {
@ -679,6 +685,12 @@ class Import
$created = $updated = $uptodate = $errors = $deleted = $num = 0; $created = $updated = $uptodate = $errors = $deleted = $num = 0;
foreach($this->accounts->search($filter) as $account_id => $group) foreach($this->accounts->search($filter) as $account_id => $group)
{ {
// if we have a regexp to filter the DN, continue on non-match
if (!empty($GLOBALS['egw_info']['server']['account_import_dn_regexp']) &&
!preg_match($GLOBALS['egw_info']['server']['account_import_dn_regexp'], $group['account_dn']))
{
continue;
}
// for local-groups, we always have to read all groups (to be able to determine which ones are local and preserve their memberships) // for local-groups, we always have to read all groups (to be able to determine which ones are local and preserve their memberships)
if ($modified && $local_groups && $group['account_modified'] < $modified && if ($modified && $local_groups && $group['account_modified'] < $modified &&
($sql_id = $this->accounts_sql->name2id($group['account_lid']))) ($sql_id = $this->accounts_sql->name2id($group['account_lid'])))

View File

@ -1302,6 +1302,7 @@ class Ldap
$contact = array( $contact = array(
'id' => $entry['uid'][0] ?? $entry['entryuuid'][0], 'id' => $entry['uid'][0] ?? $entry['entryuuid'][0],
'dn' => $entry['dn'],
'tid' => 'n', // the type id for the addressbook 'tid' => 'n', // the type id for the addressbook
); );
if (!empty($this->schema2egw[self::CF_OBJECTCLASS])) if (!empty($this->schema2egw[self::CF_OBJECTCLASS]))

View File

@ -469,7 +469,7 @@
<td colspan="2"><b>{lang_Periodic_import_from_ADS_or_LDAP_into_EGroupware_database}:</b></td> <td colspan="2"><b>{lang_Periodic_import_from_ADS_or_LDAP_into_EGroupware_database}:</b></td>
</tr> </tr>
<tr class="row_on"> <tr class="row_off">
<td>{lang_Source_(must_be_configured_above)}:</td> <td>{lang_Source_(must_be_configured_above)}:</td>
<td> <td>
<select name="newsettings[account_import_source]"> <select name="newsettings[account_import_source]">
@ -479,6 +479,10 @@
</select> </select>
</td> </td>
</tr> </tr>
<tr class="row_on">
<td>{lang_Regular_expression_to_filter_by_DN}</td>
<td><input name="newsettings[account_import_dn_regexp]" value="{value_account_import_dn_regexp}" placeholder="/OU=(One|Two),DC=example,DC=org$/i" size="80" /></td>
</tr>
<tr class="row_off"> <tr class="row_off">
<td>{lang_What_to_import?}:</td> <td>{lang_What_to_import?}:</td>
<td> <td>