implemented recursive delete
This commit is contained in:
parent
2574578953
commit
7deb644016
|
@ -1,4 +1,5 @@
|
||||||
??? 0.5.3
|
??? 0.5.3
|
||||||
|
- accounts are now deleted with subentries
|
||||||
- fixed bugs:
|
- fixed bugs:
|
||||||
-> fixed problems with case-insensitive DNs
|
-> fixed problems with case-insensitive DNs
|
||||||
|
|
||||||
|
|
1
lam/TODO
1
lam/TODO
|
@ -7,5 +7,4 @@
|
||||||
0.5.3
|
0.5.3
|
||||||
|
|
||||||
- InetOrgPerson: jpgPhoto
|
- InetOrgPerson: jpgPhoto
|
||||||
- delete entries recursively
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
0.5.2
|
0.5.3
|
||||||
|
|
|
@ -82,11 +82,15 @@ if ($_GET['type']) {
|
||||||
echo "<input name=\"type\" type=\"hidden\" value=\"" . $_GET['type'] . "\">\n";
|
echo "<input name=\"type\" type=\"hidden\" value=\"" . $_GET['type'] . "\">\n";
|
||||||
echo "<b>" . _("Do you really want to remove the following accounts?") . "</b>";
|
echo "<b>" . _("Do you really want to remove the following accounts?") . "</b>";
|
||||||
echo "<br><br>\n";
|
echo "<br><br>\n";
|
||||||
echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >";
|
echo "<table border=0>\n";
|
||||||
for ($i=0; $i<count($users); $i++) {
|
for ($i=0; $i<count($users); $i++) {
|
||||||
echo "<tr>\n";
|
echo "<tr>\n";
|
||||||
echo "<td><b>" . _("Account name:") . "</b> $users[$i]</td>\n";
|
echo "<td><b>" . _("Account name:") . "</b> $users[$i]</td>\n";
|
||||||
echo "<td><b>" . _('DN') . ":</b> " . $_SESSION['delete_dn'][$i] . "</td>\n";
|
echo "<td> <b>" . _('DN') . ":</b> " . $_SESSION['delete_dn'][$i] . "</td>\n";
|
||||||
|
$childCount = getChildCount($_SESSION['delete_dn'][$i]);
|
||||||
|
if ($childCount > 0) {
|
||||||
|
echo "<td> <b>" . _('Number of child entries') . ":</b> " . $childCount . "</td>\n";
|
||||||
|
}
|
||||||
echo "</tr>\n";
|
echo "</tr>\n";
|
||||||
}
|
}
|
||||||
echo "</table>\n";
|
echo "</table>\n";
|
||||||
|
@ -213,11 +217,8 @@ if ($_POST['delete']) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!$stopprocessing) {
|
if (!$stopprocessing) {
|
||||||
$success = @ldap_delete($_SESSION['ldap']->server(), $_SESSION['delete_dn'][$m]);
|
$errors = deleteDN($_SESSION['delete_dn'][$m]);
|
||||||
if (!$success) {
|
if (sizeof($errors) > 0) $stopprocessing = true;
|
||||||
$errors[] = array ('ERROR', sprintf(_('Was unable to delete DN: %s.'), $_SESSION['delete_dn'][$m]), ldap_error($_SESSION['ldap']->server()));
|
|
||||||
$stopprocessing = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!$stopprocessing) {
|
if (!$stopprocessing) {
|
||||||
echo sprintf(_('Deleted DN: %s'), $_SESSION['delete_dn'][$m]) . "<br>\n";
|
echo sprintf(_('Deleted DN: %s'), $_SESSION['delete_dn'][$m]) . "<br>\n";
|
||||||
|
@ -240,4 +241,48 @@ if ($_POST['delete']) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of child entries of a DN.
|
||||||
|
*
|
||||||
|
* @param string $dn DN of parent
|
||||||
|
* @return interger number of childs
|
||||||
|
*/
|
||||||
|
function getChildCount($dn) {
|
||||||
|
$return = 0;
|
||||||
|
$sr = @ldap_search($_SESSION['ldap']->server, $dn, 'objectClass=*', array('dn'), 0);
|
||||||
|
if ($sr) {
|
||||||
|
$entries = ldap_get_entries($_SESSION['ldap']->server, $sr);
|
||||||
|
$return = $entries['count'] - 1;
|
||||||
|
}
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a DN and all child entries.
|
||||||
|
*
|
||||||
|
* @param string $dn DN to delete
|
||||||
|
* @return array error messages
|
||||||
|
*/
|
||||||
|
function deleteDN($dn) {
|
||||||
|
$errors = array();
|
||||||
|
$sr = @ldap_list($_SESSION['ldap']->server, $dn, 'objectClass=*', array('dn'), 0);
|
||||||
|
if ($sr) {
|
||||||
|
$entries = ldap_get_entries($_SESSION['ldap']->server, $sr);
|
||||||
|
for ($i = 0; $i < $entries['count']; $i++) {
|
||||||
|
// delete recursively
|
||||||
|
$subErrors = deleteDN($entries[$i]['dn']);
|
||||||
|
for ($e = 0; $e < sizeof($subErrors); $e++) $errors[] = $subErrors[$e];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$errors[] = array ('ERROR', sprintf(_('Was unable to delete DN: %s.'), $dn), ldap_error($_SESSION['ldap']->server()));
|
||||||
|
}
|
||||||
|
// delete parent DN
|
||||||
|
$success = @ldap_delete($_SESSION['ldap']->server(), $dn);
|
||||||
|
if (!$success) {
|
||||||
|
$errors[] = array ('ERROR', sprintf(_('Was unable to delete DN: %s.'), $dn), ldap_error($_SESSION['ldap']->server()));
|
||||||
|
}
|
||||||
|
return $errors;
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue