fixed deleting of accounts

This commit is contained in:
Roland Gruber 2005-03-26 11:27:15 +00:00
parent 589e3755d8
commit 5b8cb3aa9c
1 changed files with 89 additions and 97 deletions

View File

@ -1,26 +1,31 @@
<?php <?php
/* /*
$Id$ $Id$
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
Copyright (C) 2003 Tilo Lutz
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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam) /**
Copyright (C) 2003 Tilo Lutz * Used to delete accounts from LDAP tree.
*
This program is free software; you can redistribute it and/or modify * @author Tilo Lutz
it under the terms of the GNU General Public License as published by * @module main
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
LDAP Account Manager Delete user, hosts or groups
*/ */
@ -32,15 +37,7 @@ include_once('../lib/status.inc'); // Return error-message
include_once('../lib/pdf.inc'); // Return a pdf-file include_once('../lib/pdf.inc'); // Return a pdf-file
include_once('../lib/ldap.inc'); // LDAP-functions include_once('../lib/ldap.inc'); // LDAP-functions
include_once('../lib/lamdaemon.inc'); // lamdaemon include_once('../lib/lamdaemon.inc'); // lamdaemon
include_once('../lib/modules.inc'); // lamdaemon
/* We have to include all modules
* before start session
* *** fixme I would prefer loading them dynamic but
* i don't know how to to this
*/
$dir = opendir('../lib/modules');
while ($entry = readdir($dir))
if (is_file('../lib/modules/'.$entry)) include_once ('../lib/modules/'.$entry);
// Start session // Start session
session_save_path('../sess'); session_save_path('../sess');
@ -50,25 +47,24 @@ session_save_path('../sess');
if (!isset($_SESSION['loggedIn'])) { if (!isset($_SESSION['loggedIn'])) {
metaRefresh("login.php"); metaRefresh("login.php");
exit; exit;
} }
// Set correct language, codepages, .... // Set correct language, codepages, ....
setlanguage(); setlanguage();
if (!isset($_SESSION['cache'])) { if (!isset($_SESSION['cache'])) {
$_SESSION['cache'] = new cache(); $_SESSION['cache'] = new cache();
} }
if ($_GET['type']) { if ($_GET['type']) {
// Create account list // Create account list
foreach ($_SESSION['delete_dn'] as $dn) { foreach ($_SESSION['delete_dn'] as $dn) {
$start = strpos ($dn, "=")+1; $start = strpos ($dn, "=")+1;
$end = strpos ($dn, ","); $end = strpos ($dn, ",");
$users[] = substr($dn, $start, $end-$start); $users[] = substr($dn, $start, $end-$start);
} }
//load account //load account
$_SESSION['account'] = new accountContainer($_GET['type'], 'account'); $_SESSION['account'] = new accountContainer($_GET['type'], 'account');
$_SESSION['account']->load_account($_SESSION['delete_dn'][0]);
// Show HTML Page // Show HTML Page
echo $_SESSION['header']; echo $_SESSION['header'];
echo "<title>"; echo "<title>";
@ -78,18 +74,18 @@ if ($_GET['type']) {
echo "</head><body>\n"; echo "</head><body>\n";
echo "<form action=\"delete.php\" method=\"post\">\n"; echo "<form action=\"delete.php\" method=\"post\">\n";
echo "<fieldset class=\"".$_GET['type']."edit-dark\"><legend class=\"".$_GET['type']."edit-bright\"><b>"; echo "<fieldset class=\"".$_GET['type']."edit-dark\"><legend class=\"".$_GET['type']."edit-bright\"><b>";
echo _('Please confirm:'); echo _('Please confirm:');
echo "</b></legend>\n"; echo "</b></legend>\n";
echo "<input name=\"type\" type=\"hidden\" value=\"" . $_GET['type'] . "\">\n"; echo "<input name=\"type\" type=\"hidden\" value=\"" . $_GET['type'] . "\">\n";
echo _("Do you really want to remove the following accounts?"); echo "<b>" . _("Do you really want to remove the following accounts?") . "</b>";
echo "<br>\n"; echo "<br><br>\n";
echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >"; echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >";
for ($i=0; $i<count($users); $i++) { for ($i=0; $i<count($users); $i++) {
echo "<tr>\n"; echo "<tr>\n";
echo "<td>" . _("Account name:") . " $users[$i]</td>\n"; echo "<td><b>" . _("Account name:") . "</b> $users[$i]</td>\n";
echo "<td>" . _('DN') . " " . $_SESSION['delete_dn'][$i] . "</td>\n"; echo "<td><b>" . _('DN') . ":</b> " . $_SESSION['delete_dn'][$i] . "</td>\n";
echo "</tr>\n"; echo "</tr>\n";
} }
echo "</table>\n"; echo "</table>\n";
echo "<br>\n"; echo "<br>\n";
// Print delete rows from modules // Print delete rows from modules
@ -97,23 +93,21 @@ if ($_GET['type']) {
$modules = array_keys($_SESSION['account']->module); $modules = array_keys($_SESSION['account']->module);
for ($i=0; $i<count($modules); $i++) { for ($i=0; $i<count($modules); $i++) {
$_SESSION['account']->module[$modules[$i]]->display_html_delete($_POST); $_SESSION['account']->module[$modules[$i]]->display_html_delete($_POST);
} }
echo "</table>\n"; echo "</table>\n";
echo "<br>\n"; echo "<br>\n";
echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >"; echo "<input name=\"delete\" type=\"submit\" value=\"" . _('Delete') . "\">&nbsp;\n";
echo "<td><input name=\"delete\" type=\"submit\" value=\"" . _('Delete') . "\"></td>\n"; echo "<input name=\"cancel\" type=\"submit\" value=\"" . _('Cancel') . "\">\n";
echo "<td><input name=\"cancel\" type=\"submit\" value=\"" . _('Cancel') . "\"></td>\n";
echo "</table>\n";
echo "</fieldset>\n"; echo "</fieldset>\n";
echo "</form>\n"; echo "</form>\n";
echo "</body>\n"; echo "</body>\n";
echo "</html>\n"; echo "</html>\n";
} }
if ($_POST['cancel']) { if ($_POST['cancel']) {
if (isset($_SESSION['delete_dn'])) unset($_SESSION['delete_dn']); if (isset($_SESSION['delete_dn'])) unset($_SESSION['delete_dn']);
metaRefresh("lists/list" . $_POST['type'] . "s.php"); metaRefresh("lists/list" . $_POST['type'] . "s.php");
} }
if ($_POST['delete']) { if ($_POST['delete']) {
// Show HTML Page // Show HTML Page
@ -126,10 +120,9 @@ if ($_POST['delete']) {
echo "<form action=\"delete.php\" method=\"post\">\n"; echo "<form action=\"delete.php\" method=\"post\">\n";
echo "<input name=\"type\" type=\"hidden\" value=\"" . $_POST['type'] . "\">\n"; echo "<input name=\"type\" type=\"hidden\" value=\"" . $_POST['type'] . "\">\n";
echo "<fieldset class=\"".$_POST['type']."edit-dark\"><legend class=\"".$_POST['type']."edit-bright\"><b>"; echo "<fieldset class=\"".$_POST['type']."edit-dark\"><legend class=\"".$_POST['type']."edit-bright\"><b>";
echo _('Deleting. Please stand by ...'); echo _('Deleting. Please stand by ...');
echo "</b></legend>\n"; echo "</b></legend>\n";
echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >";
// Delete dns // Delete dns
for ($m=0; $m<count($_SESSION['delete_dn']); $m++) { for ($m=0; $m<count($_SESSION['delete_dn']); $m++) {
// Set to true if an real error has happened // Set to true if an real error has happened
@ -154,95 +147,94 @@ if ($_POST['delete']) {
for ($j=0; $j<count($ops); $j++) { for ($j=0; $j<count($ops); $j++) {
$attrs = array_keys($temp[$DNs[$i]][$ops[$j]]); $attrs = array_keys($temp[$DNs[$i]][$ops[$j]]);
for ($k=0; $k<count($attrs); $k++) for ($k=0; $k<count($attrs); $k++)
$attributes[$DNs[$i]][$ops[$j]][$attrs[$k]] = array_unique($attributes[$DNs[$i]][$ops[$j]][$attrs[$k]]); $attributes[$DNs[$i]][$ops[$j]][$attrs[$k]] = array_unique($attributes[$DNs[$i]][$ops[$j]][$attrs[$k]]);
}
} }
} }
} }
}
$DNs = array_keys($attributes); $DNs = array_keys($attributes);
for ($i=0; $i<count($DNs); $i++) { for ($i=0; $i<count($DNs); $i++) {
if (isset($attributes[$DNs[$i]]['errors'])) { if (isset($attributes[$DNs[$i]]['errors'])) {
foreach ($attributes[$DNs[$i]]['errors'] as $singleerror) { foreach ($attributes[$DNs[$i]]['errors'] as $singleerror) {
$errors[] = $singleerror; $errors[] = $singleerror;
if ($singleerror[0] = 'ERROR') $stopprocessing = true; if ($singleerror[0] == 'ERROR') $stopprocessing = true;
}
} }
}
if (!$stopprocessing) { if (!$stopprocessing) {
// modify attributes // modify attributes
if (isset($attributes[$DNs[$i]]['modify']) && !$stopprocessing) { if (isset($attributes[$DNs[$i]]['modify']) && !$stopprocessing) {
$success = @ldap_mod_replace($_SESSION[$_SESSION['account']->ldap]->server(), $DNs[$i], $attributes[$DNs[$i]]['modify']); $success = @ldap_mod_replace($_SESSION['ldap']->server(), $DNs[$i], $attributes[$DNs[$i]]['modify']);
if (!$success) { if (!$success) {
$errors[] = array ('ERROR', 'LDAP', sprintf(_('Was unable to modify attribtues from DN: %s.'), $DNs[$i])); $errors[] = array ('ERROR', sprintf(_('Was unable to modify attribtues from DN: %s.'), $DNs[$i]), ldap_error($_SESSION['ldap']->server()));
$stopprocessing = true; $stopprocessing = true;
}
else
$_SESSION['cache']->update_cache($DNs[$i], 'modify', $attributes[$DNs[$i]]['modify']);
} }
else $_SESSION['cache']->update_cache($DNs[$i], 'modify', $attributes[$DNs[$i]]['modify']);
}
// add attributes // add attributes
if (isset($attributes[$DNs[$i]]['add']) && !$stopprocessing) { if (isset($attributes[$DNs[$i]]['add']) && !$stopprocessing) {
$success = @ldap_mod_add($_SESSION[$_SESSION['account']->ldap]->server(), $DNs[$i], $attributes[$DNs[$i]]['add']); $success = @ldap_mod_add($_SESSION['ldap']->server(), $DNs[$i], $attributes[$DNs[$i]]['add']);
if (!$success) { if (!$success) {
$errors[] = array ('ERROR', 'LDAP', sprintf(_('Was unable to add attribtues to DN: %s.'), $DNs[$i])); $errors[] = array ('ERROR', sprintf(_('Was unable to add attribtues to DN: %s.'), $DNs[$i]), ldap_error($_SESSION['ldap']->server()));
$stopprocessing = true; $stopprocessing = true;
}
else
$_SESSION['cache']->update_cache($DNs[$i], 'add', $attributes[$DNs[$i]]['add']);
} }
else $_SESSION['cache']->update_cache($DNs[$i], 'add', $attributes[$DNs[$i]]['add']);
}
// removce attributes // removce attributes
if (isset($attributes[$DNs[$i]]['remove']) && !$stopprocessing) { if (isset($attributes[$DNs[$i]]['remove']) && !$stopprocessing) {
$success = @ldap_mod_del($_SESSION[$_SESSION['account']->ldap]->server(), $DNs[$i], $attributes[$DNs[$i]]['remove']); $success = @ldap_mod_del($_SESSION['ldap']->server(), $DNs[$i], $attributes[$DNs[$i]]['remove']);
if (!$success) { if (!$success) {
$errors[] = array ('ERROR', 'LDAP', sprintf(_('Was unable to remove attribtues from DN: %s.'), $DNs[$i])); $errors[] = array ('ERROR', sprintf(_('Was unable to remove attribtues from DN: %s.'), $DNs[$i]), ldap_error($_SESSION['ldap']->server()));
$stopprocessing = true; $stopprocessing = true;
}
else
$_SESSION['cache']->update_cache($DNs[$i], 'remove', $attributes[$DNs[$i]]['remove']);
} }
else $_SESSION['cache']->update_cache($DNs[$i], 'remove', $attributes[$DNs[$i]]['remove']);
} }
} }
}
if (!$stopprocessing) { if (!$stopprocessing) {
foreach ($attributes as $DN) { foreach ($attributes as $DN) {
if (is_array($DN['lamdaemon']['command'])) $result = lamdaemon($DN['lamdaemon']['command']); if (is_array($DN['lamdaemon']['command'])) $result = lamdaemon($DN['lamdaemon']['command']);
// Error somewhere in lamdaemon if (!is_array($result)) continue;
// check for error somewhere in lamdaemon
foreach ($result as $singleresult) { foreach ($result as $singleresult) {
if (is_array($singleresult)) { if (is_array($singleresult)) {
if ($singleresult[0] = 'ERROR') $stopprocessing = true; if ($singleresult[0] == 'ERROR') {
$temparray[0] = $singleresult[0]; $stopprocessing = true;
$temparray[1] = _($singleresult[1]); $temparray[0] = $singleresult[0];
$temparray[2] = _($singleresult[2]); $temparray[1] = $singleresult[1];
$temparray[2] = $singleresult[2];
$errors[] = $temparray;
} }
} }
} }
} }
if (!$stopprocessing) {
$success = @ldap_delete($_SESSION[$_SESSION['account']->ldap]->server(), $_SESSION['delete_dn'][$m]);
if (!$success) $errors[] = array ('ERROR', 'LDAP', sprintf(_('Was unable to remove attribtues from DN: %s.'), $DNs[$i]));
else
$_SESSION['cache']->update_cache($_SESSION['delete_dn'][$m], 'delete_dn');
}
if (!$stopprocessing) {
echo "<tr>\n";
echo "<td>" . sprintf(_('Deleted DN: %s'), $_SESSION['delete_dn'][$m]) . "</td>\n";
echo "</tr>\n";
foreach ($errors as $error) StatusMessage($error[0], $error[1], $error[2]);
}
else {
echo "<tr>\n";
echo "<td>" . sprintf(_('Error while deleting DN: %s'), $_SESSION['delete_dn'][$m]) . "</td>\n";
echo "</tr>\n";
foreach ($errors as $error) StatusMessage($error[0], $error[1], $error[2]);
}
} }
echo "</table>\n"; if (!$stopprocessing) {
$success = @ldap_delete($_SESSION['ldap']->server(), $_SESSION['delete_dn'][$m]);
if (!$success) {
$errors[] = array ('ERROR', sprintf(_('Was unable to delete DN: %s.'), $_SESSION['delete_dn'][$m]), ldap_error($_SESSION['ldap']->server()));
$stopprocessing = true;
}
else
$_SESSION['cache']->update_cache($_SESSION['delete_dn'][$m], 'delete_dn');
}
if (!$stopprocessing) {
echo sprintf(_('Deleted DN: %s'), $_SESSION['delete_dn'][$m]) . "<br>\n";
foreach ($errors as $error) StatusMessage($error[0], $error[1], $error[2]);
echo "<br>\n";
}
else {
echo sprintf(_('Error while deleting DN: %s'), $_SESSION['delete_dn'][$m]) . "<br>\n";
foreach ($errors as $error) StatusMessage($error[0], $error[1], $error[2]);
echo "<br>\n";
}
}
echo "<br>\n"; echo "<br>\n";
echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >"; echo "<br><input name=\"cancel\" type=\"submit\" value=\"" . _('Back to list') . "\">\n";
echo "<td><input name=\"cancel\" type=\"submit\" value=\"" . _('Back to list') . "\"></td>\n";
echo "</table>\n";
echo "</fieldset>\n"; echo "</fieldset>\n";
echo "</form>\n"; echo "</form>\n";
echo "</body>\n"; echo "</body>\n";
echo "</html>\n"; echo "</html>\n";
} }
?> ?>