fixed deleting of accounts
This commit is contained in:
parent
589e3755d8
commit
5b8cb3aa9c
|
@ -19,8 +19,13 @@ $Id$
|
|||
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
|
||||
/**
|
||||
* Used to delete accounts from LDAP tree.
|
||||
*
|
||||
* @author Tilo Lutz
|
||||
* @module main
|
||||
*/
|
||||
|
||||
|
||||
|
@ -32,15 +37,7 @@ include_once('../lib/status.inc'); // Return error-message
|
|||
include_once('../lib/pdf.inc'); // Return a pdf-file
|
||||
include_once('../lib/ldap.inc'); // LDAP-functions
|
||||
include_once('../lib/lamdaemon.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);
|
||||
include_once('../lib/modules.inc'); // lamdaemon
|
||||
|
||||
// Start session
|
||||
session_save_path('../sess');
|
||||
|
@ -68,7 +65,6 @@ if ($_GET['type']) {
|
|||
|
||||
//load account
|
||||
$_SESSION['account'] = new accountContainer($_GET['type'], 'account');
|
||||
$_SESSION['account']->load_account($_SESSION['delete_dn'][0]);
|
||||
// Show HTML Page
|
||||
echo $_SESSION['header'];
|
||||
echo "<title>";
|
||||
|
@ -81,13 +77,13 @@ if ($_GET['type']) {
|
|||
echo _('Please confirm:');
|
||||
echo "</b></legend>\n";
|
||||
echo "<input name=\"type\" type=\"hidden\" value=\"" . $_GET['type'] . "\">\n";
|
||||
echo _("Do you really want to remove the following accounts?");
|
||||
echo "<br>\n";
|
||||
echo "<b>" . _("Do you really want to remove the following accounts?") . "</b>";
|
||||
echo "<br><br>\n";
|
||||
echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >";
|
||||
for ($i=0; $i<count($users); $i++) {
|
||||
echo "<tr>\n";
|
||||
echo "<td>" . _("Account name:") . " $users[$i]</td>\n";
|
||||
echo "<td>" . _('DN') . " " . $_SESSION['delete_dn'][$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 "</tr>\n";
|
||||
}
|
||||
echo "</table>\n";
|
||||
|
@ -100,10 +96,8 @@ if ($_GET['type']) {
|
|||
}
|
||||
echo "</table>\n";
|
||||
echo "<br>\n";
|
||||
echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >";
|
||||
echo "<td><input name=\"delete\" type=\"submit\" value=\"" . _('Delete') . "\"></td>\n";
|
||||
echo "<td><input name=\"cancel\" type=\"submit\" value=\"" . _('Cancel') . "\"></td>\n";
|
||||
echo "</table>\n";
|
||||
echo "<input name=\"delete\" type=\"submit\" value=\"" . _('Delete') . "\"> \n";
|
||||
echo "<input name=\"cancel\" type=\"submit\" value=\"" . _('Cancel') . "\">\n";
|
||||
echo "</fieldset>\n";
|
||||
echo "</form>\n";
|
||||
echo "</body>\n";
|
||||
|
@ -129,7 +123,6 @@ if ($_POST['delete']) {
|
|||
echo _('Deleting. Please stand by ...');
|
||||
echo "</b></legend>\n";
|
||||
|
||||
echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >";
|
||||
// Delete dns
|
||||
for ($m=0; $m<count($_SESSION['delete_dn']); $m++) {
|
||||
// Set to true if an real error has happened
|
||||
|
@ -164,80 +157,79 @@ if ($_POST['delete']) {
|
|||
if (isset($attributes[$DNs[$i]]['errors'])) {
|
||||
foreach ($attributes[$DNs[$i]]['errors'] as $singleerror) {
|
||||
$errors[] = $singleerror;
|
||||
if ($singleerror[0] = 'ERROR') $stopprocessing = true;
|
||||
if ($singleerror[0] == 'ERROR') $stopprocessing = true;
|
||||
}
|
||||
}
|
||||
if (!$stopprocessing) {
|
||||
// modify attributes
|
||||
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) {
|
||||
$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;
|
||||
}
|
||||
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
|
||||
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) {
|
||||
$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;
|
||||
}
|
||||
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
|
||||
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) {
|
||||
$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;
|
||||
}
|
||||
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) {
|
||||
foreach ($attributes as $DN) {
|
||||
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) {
|
||||
if (is_array($singleresult)) {
|
||||
if ($singleresult[0] = 'ERROR') $stopprocessing = true;
|
||||
if ($singleresult[0] == 'ERROR') {
|
||||
$stopprocessing = true;
|
||||
$temparray[0] = $singleresult[0];
|
||||
$temparray[1] = _($singleresult[1]);
|
||||
$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]));
|
||||
$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 "<tr>\n";
|
||||
echo "<td>" . sprintf(_('Deleted DN: %s'), $_SESSION['delete_dn'][$m]) . "</td>\n";
|
||||
echo "</tr>\n";
|
||||
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 "<tr>\n";
|
||||
echo "<td>" . sprintf(_('Error while deleting DN: %s'), $_SESSION['delete_dn'][$m]) . "</td>\n";
|
||||
echo "</tr>\n";
|
||||
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 "</table>\n";
|
||||
echo "<br>\n";
|
||||
echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >";
|
||||
echo "<td><input name=\"cancel\" type=\"submit\" value=\"" . _('Back to list') . "\"></td>\n";
|
||||
echo "</table>\n";
|
||||
}
|
||||
}
|
||||
echo "<br>\n";
|
||||
echo "<br><input name=\"cancel\" type=\"submit\" value=\"" . _('Back to list') . "\">\n";
|
||||
echo "</fieldset>\n";
|
||||
echo "</form>\n";
|
||||
echo "</body>\n";
|
||||
|
|
Loading…
Reference in New Issue