Merge pull request #17 from LDAPAccountManager/type_api_tmp
Type api tmp
This commit is contained in:
commit
71ccfc7356
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,8 +50,17 @@ This is a list of API changes for all LAM releases.
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
<h2>5.5 -> 5.6</h2>
|
<h2>5.5 -> 5.6</h2>
|
||||||
Functions in lib/types.inc got namespace LAM/TYPES (e.g. getTypeAlias()).<br>
|
<ul>
|
||||||
New API to access configured account types: LAM\TYPES\TypeManager.<br>
|
<li>
|
||||||
|
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()</li>
|
||||||
|
<li>moved getSuffixList() from baseType to ConfiguredType<br>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
<h2>5.4 -> 5.5</h2>Functions Ldap::encrypt/decrypt in ldap.inc moved to lamEncrypt/lamDecrypt in security.inc.<br>
|
<h2>5.4 -> 5.5</h2>Functions Ldap::encrypt/decrypt in ldap.inc moved to lamEncrypt/lamDecrypt in security.inc.<br>
|
||||||
<br>
|
<br>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
$Id$
|
$Id$
|
||||||
|
|
||||||
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
||||||
Copyright (C) 2005 - 2014 Roland Gruber
|
Copyright (C) 2005 - 2016 Roland Gruber
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -130,50 +130,12 @@ class baseType {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of LDAP suffixes for this type.
|
* Returns the LDAP filter to find the possible suffixes for this account type.
|
||||||
*
|
*
|
||||||
* @return array sorted list of possible suffixes for this type.
|
* @return string LDAP filter
|
||||||
*/
|
*/
|
||||||
public function getSuffixList() {
|
public function getSuffixFilter() {
|
||||||
if (isset($_SESSION["config"])) {
|
return "(|(objectClass=organizationalunit)(objectClass=country)(objectClass=organization)(objectClass=krbRealmContainer)(objectClass=container))";
|
||||||
$suffix = $_SESSION["config"]->get_Suffix(get_class($this));
|
|
||||||
$connection = $_SESSION["ldap"]->server();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$suffix = $_SESSION['selfServiceProfile']->LDAPSuffix;
|
|
||||||
$connection = $_SESSION['ldapHandle'];
|
|
||||||
}
|
|
||||||
$ret = array();
|
|
||||||
$filter = "(|(objectClass=organizationalunit)(objectClass=country)(objectClass=organization)(objectClass=krbRealmContainer)(objectClass=container))";
|
|
||||||
$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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -962,7 +962,7 @@ class lamList {
|
||||||
call_user_func_array('StatusMessage', $lastError);
|
call_user_func_array('StatusMessage', $lastError);
|
||||||
}
|
}
|
||||||
// generate list of possible suffixes
|
// generate list of possible suffixes
|
||||||
$this->possibleSuffixes = $this->type->getBaseType()->getSuffixList();
|
$this->possibleSuffixes = $this->type->getSuffixList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2146,8 +2146,7 @@ class accountContainer {
|
||||||
if ($this->cachedOUs != null) {
|
if ($this->cachedOUs != null) {
|
||||||
return $this->cachedOUs;
|
return $this->cachedOUs;
|
||||||
}
|
}
|
||||||
$typeObj = $this->type->getBaseType();
|
$this->cachedOUs = $this->type->getSuffixList();
|
||||||
$this->cachedOUs = $typeObj->getSuffixList();
|
|
||||||
return $this->cachedOUs;
|
return $this->cachedOUs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2809,7 +2809,13 @@ class inetOrgPerson extends baseModule implements passwordService {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$userObj = new user();
|
$userObj = new user();
|
||||||
$ouList = $userObj->getSuffixList();
|
$filter = $userObj->getSuffixFilter();
|
||||||
|
$suffix = $_SESSION['selfServiceProfile']->LDAPSuffix;
|
||||||
|
$foundOus = searchLDAPPaged($_SESSION['ldapHandle'], $suffix, $filter, array('dn'), false, 0);
|
||||||
|
$ouList = array();
|
||||||
|
foreach ($foundOus as $foundOu) {
|
||||||
|
$ouList[] = $foundOu['dn'];
|
||||||
|
}
|
||||||
if (!empty($attributes['ou'][0]) && !in_array($attributes['ou'][0], $ouList)) {
|
if (!empty($attributes['ou'][0]) && !in_array($attributes['ou'][0], $ouList)) {
|
||||||
$ouList[] = $attributes['ou'][0];
|
$ouList[] = $attributes['ou'][0];
|
||||||
usort($ouList, 'compareDN');
|
usort($ouList, 'compareDN');
|
||||||
|
|
|
@ -357,9 +357,18 @@ class nisMailAliasUser extends baseModule {
|
||||||
$return->addElement(new htmlHiddenInput('recipient', $recipient), true);
|
$return->addElement(new htmlHiddenInput('recipient', $recipient), true);
|
||||||
// new mail alias
|
// new mail alias
|
||||||
$return->addElement(new htmlSubTitle(_('Create new alias')), true);
|
$return->addElement(new htmlSubTitle(_('Create new alias')), true);
|
||||||
$typeObj = new mailAlias();
|
$typeManager = new \LAM\TYPES\TypeManager();
|
||||||
$ous = $typeObj->getSuffixList();
|
$mailAliasTypes = $typeManager->getConfiguredTypesForScope('mailAlias');
|
||||||
$return->addElement(new htmlTableExtendedSelect('new_ou', $ous, array(), _('Suffix'), 'suffix'), true);
|
$ous = array();
|
||||||
|
foreach ($mailAliasTypes as $type) {
|
||||||
|
$ous = array_merge($ous, $type->getSuffixList());
|
||||||
|
}
|
||||||
|
$ous = array_unique($ous);
|
||||||
|
usort($ous, 'compareDN');
|
||||||
|
$suffixSelect = new htmlTableExtendedSelect('new_ou', $ous, array(), _('Suffix'), 'suffix');
|
||||||
|
$suffixSelect->setRightToLeftTextDirection(true);
|
||||||
|
$suffixSelect->setSortElements(false);
|
||||||
|
$return->addElement($suffixSelect, true);
|
||||||
$newAliasCn = empty($_POST['new_cn']) ? '' : $_POST['new_cn'];
|
$newAliasCn = empty($_POST['new_cn']) ? '' : $_POST['new_cn'];
|
||||||
$return->addElement(new htmlTableExtendedInputField(_('Alias name'), 'new_cn', $newAliasCn, 'newAlias'), true);
|
$return->addElement(new htmlTableExtendedInputField(_('Alias name'), 'new_cn', $newAliasCn, 'newAlias'), true);
|
||||||
$return->addVerticalSpace('5px');
|
$return->addVerticalSpace('5px');
|
||||||
|
|
|
@ -271,6 +271,46 @@ class ConfiguredType {
|
||||||
return $this->baseType;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -389,6 +429,23 @@ class TypeManager {
|
||||||
return $configuredTypes;
|
return $configuredTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of configured types for this scope.
|
||||||
|
*
|
||||||
|
* @param string $scope scope (e.g. user)
|
||||||
|
* @return \LAM\TYPES\ConfiguredType[] list of ConfiguredType
|
||||||
|
*/
|
||||||
|
public function getConfiguredTypesForScope($scope) {
|
||||||
|
$allTypes = $this->getConfiguredTypes();
|
||||||
|
$scopedTypes = array();
|
||||||
|
foreach ($allTypes as $type) {
|
||||||
|
if ($type->getScope() == $scope) {
|
||||||
|
$scopedTypes[] = $type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $scopedTypes;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a configured account type.
|
* Builds a configured account type.
|
||||||
*
|
*
|
||||||
|
|
|
@ -180,7 +180,7 @@ class lamAsteriskExtList extends lamList {
|
||||||
$entries = $this->normalizeLdapOutput($entries);
|
$entries = $this->normalizeLdapOutput($entries);
|
||||||
$this->entries = $entries;
|
$this->entries = $entries;
|
||||||
// generate list of possible suffixes
|
// generate list of possible suffixes
|
||||||
$this->possibleSuffixes = $this->type->getBaseType()->getSuffixList();
|
$this->possibleSuffixes = $this->type->getSuffixList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -207,8 +207,7 @@ $dnContent->addElement(new htmlSpacer(null, '10px'), true);
|
||||||
$rootsuffix = $type->getSuffix();
|
$rootsuffix = $type->getSuffix();
|
||||||
// get subsuffixes
|
// get subsuffixes
|
||||||
$suffixes = array('-' => '-');
|
$suffixes = array('-' => '-');
|
||||||
$typeObj = $type->getBaseType();
|
$possibleSuffixes = $type->getSuffixList();
|
||||||
$possibleSuffixes = $typeObj->getSuffixList();
|
|
||||||
foreach ($possibleSuffixes as $suffix) {
|
foreach ($possibleSuffixes as $suffix) {
|
||||||
$suffixes[getAbstractDN($suffix)] = $suffix;
|
$suffixes[getAbstractDN($suffix)] = $suffix;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue