moved getSuffixList()

This commit is contained in:
Roland Gruber 2016-12-31 14:44:46 +01:00
parent 7027522950
commit e93d59740c
8 changed files with 49 additions and 49 deletions

View File

@ -19,6 +19,7 @@
@ -54,8 +55,10 @@ This is a list of API changes for all LAM releases.
Functions in lib/types.inc got namespace LAM/TYPES (e.g. getTypeAlias()).</li>
<li>
New API to access configured account types: LAM\TYPES\TypeManager.</li>
<li>class baseType: new function getSuffixFilter()<br>
<li>class baseType: new function getSuffixFilter()</li>
<li>moved getSuffixList() from baseType to ConfiguredType<br>
</li>
</ul>

View File

@ -138,47 +138,6 @@ class baseType {
return "(|(objectClass=organizationalunit)(objectClass=country)(objectClass=organization)(objectClass=krbRealmContainer)(objectClass=container))";
}
/**
* Returns a list of LDAP suffixes for this type.
*
* @return array sorted list of possible suffixes for this type.
*/
public function getSuffixList() {
$suffix = $_SESSION["config"]->get_Suffix(get_class($this));
$connection = $_SESSION["ldap"]->server();
$ret = array();
$filter = $this->getSuffixFilter();
$sr = @ldap_search($connection, escapeDN($suffix),$filter , array('dn', 'objectClass'), 0, 0, 0, LDAP_DEREF_NEVER);
if ($sr) {
$units = ldap_get_entries($connection, $sr);
cleanLDAPResult($units);
// extract Dns
$count = sizeof($units);
for ($i = 0; $i < $count; $i++) {
if (in_array('container', $units[$i]['objectclass'])) {
// Active Directory fix, hide system containers
if (preg_match('/.*cn=system,dc=.+/i', $units[$i]['dn']) || preg_match('/.*CN=program data,dc=.+/i', $units[$i]['dn'])) {
continue;
}
}
$ret[] = $units[$i]['dn'];
}
}
// add root suffix if needed
$found = false;
for ($i = 0; $i < sizeof($ret); $i++) { // search suffix case-intensitive
if (strtolower($suffix) == strtolower($ret[$i])) {
$found = true;
break;
}
}
if (!$found) {
$ret[] = $suffix;
}
usort($ret, 'compareDN');
return $ret;
}
/**
* This function is called after the edit page is processed and before the page content is generated.
* This can be used to run custom handlers after each page processing.

View File

@ -962,7 +962,7 @@ class lamList {
call_user_func_array('StatusMessage', $lastError);
}
// generate list of possible suffixes
$this->possibleSuffixes = $this->type->getBaseType()->getSuffixList();
$this->possibleSuffixes = $this->type->getSuffixList();
}
/**

View File

@ -2146,8 +2146,7 @@ class accountContainer {
if ($this->cachedOUs != null) {
return $this->cachedOUs;
}
$typeObj = $this->type->getBaseType();
$this->cachedOUs = $typeObj->getSuffixList();
$this->cachedOUs = $this->type->getSuffixList();
return $this->cachedOUs;
}

View File

@ -361,7 +361,7 @@ class nisMailAliasUser extends baseModule {
$mailAliasTypes = $typeManager->getConfiguredTypesForScope('mailAlias');
$ous = array();
foreach ($mailAliasTypes as $type) {
$ous = array_merge($ous, $type->getBaseType()->getSuffixList());
$ous = array_merge($ous, $type->getSuffixList());
}
$ous = array_unique($ous);
usort($ous, 'compareDN');

View File

@ -271,6 +271,46 @@ class ConfiguredType {
return $this->baseType;
}
/**
* Returns a list of LDAP suffixes for this type.
*
* @return array sorted list of possible suffixes for this type.
*/
public function getSuffixList() {
$connection = $_SESSION["ldap"]->server();
$ret = array();
$filter = $this->getBaseType()->getSuffixFilter();
$sr = @ldap_search($connection, escapeDN($this->suffix), $filter, array('dn', 'objectClass'), 0, 0, 0, LDAP_DEREF_NEVER);
if ($sr) {
$units = ldap_get_entries($connection, $sr);
cleanLDAPResult($units);
// extract Dns
$count = sizeof($units);
for ($i = 0; $i < $count; $i++) {
if (in_array('container', $units[$i]['objectclass'])) {
// Active Directory fix, hide system containers
if (preg_match('/.*cn=system,dc=.+/i', $units[$i]['dn']) || preg_match('/.*CN=program data,dc=.+/i', $units[$i]['dn'])) {
continue;
}
}
$ret[] = $units[$i]['dn'];
}
}
// add root suffix if needed
$found = false;
for ($i = 0; $i < sizeof($ret); $i++) { // search suffix case-intensitive
if (strtolower($this->suffix) == strtolower($ret[$i])) {
$found = true;
break;
}
}
if (!$found) {
$ret[] = $this->suffix;
}
usort($ret, 'compareDN');
return $ret;
}
}
/**

View File

@ -180,7 +180,7 @@ class lamAsteriskExtList extends lamList {
$entries = $this->normalizeLdapOutput($entries);
$this->entries = $entries;
// generate list of possible suffixes
$this->possibleSuffixes = $this->type->getBaseType()->getSuffixList();
$this->possibleSuffixes = $this->type->getSuffixList();
}
/**

View File

@ -207,8 +207,7 @@ $dnContent->addElement(new htmlSpacer(null, '10px'), true);
$rootsuffix = $type->getSuffix();
// get subsuffixes
$suffixes = array('-' => '-');
$typeObj = $type->getBaseType();
$possibleSuffixes = $typeObj->getSuffixList();
$possibleSuffixes = $type->getSuffixList();
foreach ($possibleSuffixes as $suffix) {
$suffixes[getAbstractDN($suffix)] = $suffix;
}