types specify suffix list

This commit is contained in:
Roland Gruber 2011-04-25 18:01:11 +00:00
parent 8def4a53ff
commit 18bc1b0c0d
5 changed files with 12 additions and 74 deletions

View File

@ -127,38 +127,6 @@ class Ldap{
@ldap_close($this->server);
}
/**
* Returns an array with all organizational units under the given suffix
*
* @param string $suffix search suffix
* @return array DNs of organizational units
*/
function search_units($suffix) {
$ret = array();
$sr = @ldap_search($this->server(), escapeDN($suffix), "objectClass=organizationalunit", array("DN"), 0, 0, 0, LDAP_DEREF_NEVER);
if ($sr) {
$units = ldap_get_entries($this->server, $sr);
$units = cleanLDAPResult($units);
// extract Dns
for ($i = 0; $i < sizeof($units); $i++) {
if ($units[$i]['dn']) $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, array($this,"cmp_array"));
return $ret;
}
/**
* Returns the LDAP connection handle
*
@ -303,41 +271,6 @@ class Ldap{
}
/**
* Helper function to sort the unit DNs
*
* @param string $a first argument to compare
* @param string $b second argument to compare
* @return integer 0 if equal, 1 if $a is greater, -1 if $b is greater
*/
function cmp_array($a, $b) {
// split DNs
$array_a = explode(",", $a);
$array_b = explode(",", $b);
$len_a = sizeof($array_a);
$len_b = sizeof($array_b);
// check how many parts to compare
$len = min($len_a, $len_b);
// compare from last part on
for ($i = 0; $i < $len; $i++) {
// get parts to compare
$part_a = strtolower($array_a[$len_a - $i - 1]);
$part_b = strtolower($array_b[$len_b - $i - 1]);
// compare parts
if ($part_a == $part_b) { // part is identical
if ($i == ($len - 1)) {
if ($len_a > $len_b) return 1;
elseif ($len_a < $len_b) return -1;
else return 0; // DNs are identical
}
}
elseif ($part_a == max($part_a, $part_b)) return 1;
else return -1;
}
return -1;
}
}
?>

View File

@ -845,7 +845,8 @@ class lamList {
}
$this->entries = $entries;
// generate list of possible suffixes
$this->possibleSuffixes = $_SESSION['ldap']->search_units($_SESSION["config"]->get_Suffix($this->type));
$typeObj = new $this->type();
$this->possibleSuffixes = $typeObj->getSuffixList();
}
/**
@ -873,7 +874,7 @@ class lamList {
* Prints the list configuration page.
*/
protected function listPrintConfigurationPage() {
echo "<div id=\"settingsDialog\" style=\"display: none;\">\n";
echo "<div id=\"settingsDialog\" class=\"hidden\">\n";
echo "<form id=\"settingsDialogForm\" action=\"list.php?type=" . $this->type . "&amp;norefresh=true\" method=\"post\">\n";
echo '<table width="100%"><tr><td>';

View File

@ -2183,7 +2183,8 @@ class accountContainer {
return $this->cachedOUs;
}
$rootsuffix = $_SESSION['config']->get_Suffix($this->type);
$this->cachedOUs = $_SESSION['ldap']->search_units($rootsuffix);
$typeObj = new $this->type();
$this->cachedOUs = $typeObj->getSuffixList();
return $this->cachedOUs;
}

View File

@ -64,7 +64,8 @@ if (isset($_POST['createOU']) || isset($_POST['deleteOU'])) {
if (preg_match("/^[a-z0-9 _\\-]+$/i", $_POST['newOU'])) {
// check if ou already exists
$new_dn = "ou=" . $_POST['newOU'] . "," . $_POST['parentOU'];
if (!in_array($new_dn, $_SESSION['ldap']->search_units($_POST['parentOU']))) {
$found = ldapGetDN($new_dn);
if ($found == null) {
// add new ou
$ou = array();
$ou['objectClass'] = "organizationalunit";
@ -167,9 +168,9 @@ function display_main($message, $error) {
$options = array();
foreach ($types as $name => $title) {
$elements = array();
$units = $_SESSION['ldap']->search_units($_SESSION["config"]->get_Suffix($name));
$units = searchLDAPByAttribute(null, null, 'organizationalunit', array('dn'), array($name));
for ($u = 0; $u < sizeof($units); $u++) {
$elements[getAbstractDN($units[$u])] = $units[$u];
$elements[getAbstractDN($units[$u]['dn'])] = $units[$u]['dn'];
}
$options[$title] = $elements;
}

View File

@ -179,7 +179,9 @@ $dnContent->addElement(new htmlSpacer(null, '10px'), true);
$rootsuffix = $_SESSION['config']->get_Suffix($type);
// get subsuffixes
$suffixes = array();
foreach ($_SESSION['ldap']->search_units($rootsuffix) as $suffix) {
$typeObj = new $type();
$possibleSuffixes = $typeObj->getSuffixList();
foreach ($possibleSuffixes as $suffix) {
$suffixes[getAbstractDN($suffix)] = $suffix;
}
$selectedSuffix = array();