2003-09-28 13:30:31 +00:00
|
|
|
<?php
|
2003-04-25 11:07:28 +00:00
|
|
|
/*
|
2005-03-26 11:27:15 +00:00
|
|
|
$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
|
|
|
|
|
|
|
|
*/
|
2003-04-25 11:07:28 +00:00
|
|
|
|
2005-03-26 11:27:15 +00:00
|
|
|
/**
|
|
|
|
* Used to delete accounts from LDAP tree.
|
|
|
|
*
|
|
|
|
* @author Tilo Lutz
|
2005-08-17 19:17:15 +00:00
|
|
|
* @package main
|
2003-04-25 11:07:28 +00:00
|
|
|
*/
|
2003-10-20 17:56:52 +00:00
|
|
|
|
2004-01-10 11:47:48 +00:00
|
|
|
|
2005-08-17 19:17:15 +00:00
|
|
|
/** account functions */
|
|
|
|
include_once('../lib/account.inc');
|
|
|
|
/** current configuration options */
|
|
|
|
include_once('../lib/config.inc');
|
|
|
|
/** message displaying */
|
|
|
|
include_once('../lib/status.inc');
|
|
|
|
/** LDAP connection */
|
|
|
|
include_once('../lib/ldap.inc');
|
|
|
|
/** lamdaemon interface */
|
|
|
|
include_once('../lib/lamdaemon.inc');
|
|
|
|
/** module interface */
|
|
|
|
include_once('../lib/modules.inc');
|
2004-01-10 11:47:48 +00:00
|
|
|
|
|
|
|
// Start session
|
2003-04-26 21:58:00 +00:00
|
|
|
session_save_path('../sess');
|
|
|
|
@session_start();
|
2004-01-10 11:47:48 +00:00
|
|
|
|
2003-10-22 17:51:44 +00:00
|
|
|
// Redirect to startpage if user is not loged in
|
|
|
|
if (!isset($_SESSION['loggedIn'])) {
|
|
|
|
metaRefresh("login.php");
|
2004-01-10 11:47:48 +00:00
|
|
|
exit;
|
2005-03-26 11:27:15 +00:00
|
|
|
}
|
2003-10-22 17:51:44 +00:00
|
|
|
|
2004-01-10 11:47:48 +00:00
|
|
|
// Set correct language, codepages, ....
|
2003-08-10 19:46:21 +00:00
|
|
|
setlanguage();
|
2003-04-25 16:14:09 +00:00
|
|
|
|
2004-01-10 11:47:48 +00:00
|
|
|
if (!isset($_SESSION['cache'])) {
|
|
|
|
$_SESSION['cache'] = new cache();
|
2005-03-26 11:27:15 +00:00
|
|
|
}
|
2003-05-02 12:52:42 +00:00
|
|
|
if ($_GET['type']) {
|
2004-01-10 11:47:48 +00:00
|
|
|
// Create account list
|
|
|
|
foreach ($_SESSION['delete_dn'] as $dn) {
|
|
|
|
$start = strpos ($dn, "=")+1;
|
|
|
|
$end = strpos ($dn, ",");
|
|
|
|
$users[] = substr($dn, $start, $end-$start);
|
2005-03-26 11:27:15 +00:00
|
|
|
}
|
2004-01-10 11:47:48 +00:00
|
|
|
|
|
|
|
//load account
|
|
|
|
$_SESSION['account'] = new accountContainer($_GET['type'], 'account');
|
|
|
|
// Show HTML Page
|
|
|
|
echo $_SESSION['header'];
|
|
|
|
echo "<title>";
|
|
|
|
echo _("Delete Account");
|
|
|
|
echo "</title>\n";
|
|
|
|
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../style/layout.css\">\n";
|
|
|
|
echo "</head><body>\n";
|
|
|
|
echo "<form action=\"delete.php\" method=\"post\">\n";
|
2005-04-22 08:56:47 +00:00
|
|
|
echo "<fieldset class=\"".$_GET['type']."edit\"><legend><b>";
|
2005-03-26 11:27:15 +00:00
|
|
|
echo _('Please confirm:');
|
|
|
|
echo "</b></legend>\n";
|
2004-01-10 11:47:48 +00:00
|
|
|
echo "<input name=\"type\" type=\"hidden\" value=\"" . $_GET['type'] . "\">\n";
|
2005-03-26 11:27:15 +00:00
|
|
|
echo "<b>" . _("Do you really want to remove the following accounts?") . "</b>";
|
|
|
|
echo "<br><br>\n";
|
2004-01-10 11:47:48 +00:00
|
|
|
echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >";
|
|
|
|
for ($i=0; $i<count($users); $i++) {
|
|
|
|
echo "<tr>\n";
|
2005-03-26 11:27:15 +00:00
|
|
|
echo "<td><b>" . _("Account name:") . "</b> $users[$i]</td>\n";
|
|
|
|
echo "<td><b>" . _('DN') . ":</b> " . $_SESSION['delete_dn'][$i] . "</td>\n";
|
2004-01-10 11:47:48 +00:00
|
|
|
echo "</tr>\n";
|
2005-03-26 11:27:15 +00:00
|
|
|
}
|
2003-09-19 10:03:00 +00:00
|
|
|
echo "</table>\n";
|
2004-01-10 11:47:48 +00:00
|
|
|
echo "<br>\n";
|
|
|
|
// Print delete rows from modules
|
|
|
|
echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >";
|
2005-04-04 16:55:34 +00:00
|
|
|
$modules = $_SESSION['config']->get_AccountModules($_GET['type']);
|
2005-04-05 12:06:30 +00:00
|
|
|
$values = array();
|
|
|
|
$tabindex = 100;
|
|
|
|
$tabindexLink = 1000;
|
2005-04-04 16:55:34 +00:00
|
|
|
foreach ($modules as $module) {
|
|
|
|
$module = new $module($_GET['type']);
|
2005-04-05 12:06:30 +00:00
|
|
|
parseHtml(get_class($module), $module->display_html_delete($_POST), $values, true, $tabindex, $tabindexLink, $_GET['type']);
|
2005-03-26 11:27:15 +00:00
|
|
|
}
|
2004-01-10 11:47:48 +00:00
|
|
|
echo "</table>\n";
|
|
|
|
echo "<br>\n";
|
2005-03-26 11:27:15 +00:00
|
|
|
echo "<input name=\"delete\" type=\"submit\" value=\"" . _('Delete') . "\"> \n";
|
|
|
|
echo "<input name=\"cancel\" type=\"submit\" value=\"" . _('Cancel') . "\">\n";
|
2004-01-10 11:47:48 +00:00
|
|
|
echo "</fieldset>\n";
|
|
|
|
echo "</form>\n";
|
|
|
|
echo "</body>\n";
|
|
|
|
echo "</html>\n";
|
2005-03-26 11:27:15 +00:00
|
|
|
}
|
2003-05-02 07:59:13 +00:00
|
|
|
|
2004-01-10 11:47:48 +00:00
|
|
|
if ($_POST['cancel']) {
|
|
|
|
if (isset($_SESSION['delete_dn'])) unset($_SESSION['delete_dn']);
|
|
|
|
metaRefresh("lists/list" . $_POST['type'] . "s.php");
|
2005-03-26 11:27:15 +00:00
|
|
|
}
|
2003-09-19 10:03:00 +00:00
|
|
|
|
2004-01-10 11:47:48 +00:00
|
|
|
if ($_POST['delete']) {
|
|
|
|
// Show HTML Page
|
|
|
|
echo $_SESSION['header'];
|
|
|
|
echo "<title>";
|
|
|
|
echo _("Delete Account");
|
|
|
|
echo "</title>\n";
|
|
|
|
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../style/layout.css\">\n";
|
|
|
|
echo "</head><body>\n";
|
|
|
|
echo "<form action=\"delete.php\" method=\"post\">\n";
|
|
|
|
echo "<input name=\"type\" type=\"hidden\" value=\"" . $_POST['type'] . "\">\n";
|
2005-04-22 08:56:47 +00:00
|
|
|
echo "<fieldset class=\"".$_POST['type']."edit\"><legend><b>";
|
2005-03-26 11:27:15 +00:00
|
|
|
echo _('Deleting. Please stand by ...');
|
|
|
|
echo "</b></legend>\n";
|
2004-01-10 11:47:48 +00:00
|
|
|
|
|
|
|
// Delete dns
|
|
|
|
for ($m=0; $m<count($_SESSION['delete_dn']); $m++) {
|
|
|
|
// Set to true if an real error has happened
|
|
|
|
$stopprocessing = false;
|
|
|
|
// First load DN.
|
|
|
|
$_SESSION['account']->load_account($_SESSION['delete_dn'][$m]);
|
|
|
|
// get commands and changes of each attribute
|
|
|
|
$module = array_keys ($_SESSION['account']->module);
|
|
|
|
$attributes = array();
|
|
|
|
$errors = array();
|
|
|
|
// load attributes
|
|
|
|
foreach ($module as $singlemodule) {
|
|
|
|
// load changes
|
|
|
|
$temp = $_SESSION['account']->module[$singlemodule]->delete_attributes($_POST);
|
|
|
|
if (is_array($temp)) {
|
|
|
|
// merge changes
|
|
|
|
$DNs = array_keys($temp);
|
|
|
|
// *** fixme don't include references
|
|
|
|
$attributes = array_merge_recursive($temp, $attributes);
|
|
|
|
for ($i=0; $i<count($DNs); $i++) {
|
|
|
|
$ops = array_keys($temp[$DNs[$i]]);
|
|
|
|
for ($j=0; $j<count($ops); $j++) {
|
|
|
|
$attrs = array_keys($temp[$DNs[$i]][$ops[$j]]);
|
|
|
|
for ($k=0; $k<count($attrs); $k++)
|
2005-03-26 11:27:15 +00:00
|
|
|
$attributes[$DNs[$i]][$ops[$j]][$attrs[$k]] = array_unique($attributes[$DNs[$i]][$ops[$j]][$attrs[$k]]);
|
2004-01-10 11:47:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-03-26 11:27:15 +00:00
|
|
|
}
|
2004-01-10 11:47:48 +00:00
|
|
|
$DNs = array_keys($attributes);
|
|
|
|
for ($i=0; $i<count($DNs); $i++) {
|
|
|
|
if (isset($attributes[$DNs[$i]]['errors'])) {
|
|
|
|
foreach ($attributes[$DNs[$i]]['errors'] as $singleerror) {
|
|
|
|
$errors[] = $singleerror;
|
2005-03-26 11:27:15 +00:00
|
|
|
if ($singleerror[0] == 'ERROR') $stopprocessing = true;
|
2004-01-10 11:47:48 +00:00
|
|
|
}
|
2005-03-26 11:27:15 +00:00
|
|
|
}
|
2004-01-10 11:47:48 +00:00
|
|
|
if (!$stopprocessing) {
|
|
|
|
// modify attributes
|
|
|
|
if (isset($attributes[$DNs[$i]]['modify']) && !$stopprocessing) {
|
2005-03-26 11:27:15 +00:00
|
|
|
$success = @ldap_mod_replace($_SESSION['ldap']->server(), $DNs[$i], $attributes[$DNs[$i]]['modify']);
|
2004-01-10 11:47:48 +00:00
|
|
|
if (!$success) {
|
2005-03-26 11:27:15 +00:00
|
|
|
$errors[] = array ('ERROR', sprintf(_('Was unable to modify attribtues from DN: %s.'), $DNs[$i]), ldap_error($_SESSION['ldap']->server()));
|
2004-01-10 11:47:48 +00:00
|
|
|
$stopprocessing = true;
|
2003-05-15 20:59:26 +00:00
|
|
|
}
|
2005-08-08 09:26:19 +00:00
|
|
|
//else $_SESSION['cache']->update_cache($DNs[$i], 'modify', $attributes[$DNs[$i]]['modify']); TODO: reactivate
|
2005-03-26 11:27:15 +00:00
|
|
|
}
|
2004-01-10 11:47:48 +00:00
|
|
|
// add attributes
|
|
|
|
if (isset($attributes[$DNs[$i]]['add']) && !$stopprocessing) {
|
2005-03-26 11:27:15 +00:00
|
|
|
$success = @ldap_mod_add($_SESSION['ldap']->server(), $DNs[$i], $attributes[$DNs[$i]]['add']);
|
2004-01-10 11:47:48 +00:00
|
|
|
if (!$success) {
|
2005-03-26 11:27:15 +00:00
|
|
|
$errors[] = array ('ERROR', sprintf(_('Was unable to add attribtues to DN: %s.'), $DNs[$i]), ldap_error($_SESSION['ldap']->server()));
|
2004-01-10 11:47:48 +00:00
|
|
|
$stopprocessing = true;
|
2003-04-26 21:58:00 +00:00
|
|
|
}
|
2005-08-08 09:26:19 +00:00
|
|
|
//else $_SESSION['cache']->update_cache($DNs[$i], 'add', $attributes[$DNs[$i]]['add']); TODO: reactivate
|
2005-03-26 11:27:15 +00:00
|
|
|
}
|
2004-01-10 11:47:48 +00:00
|
|
|
// removce attributes
|
|
|
|
if (isset($attributes[$DNs[$i]]['remove']) && !$stopprocessing) {
|
2005-03-26 11:27:15 +00:00
|
|
|
$success = @ldap_mod_del($_SESSION['ldap']->server(), $DNs[$i], $attributes[$DNs[$i]]['remove']);
|
2004-01-10 11:47:48 +00:00
|
|
|
if (!$success) {
|
2005-03-26 11:27:15 +00:00
|
|
|
$errors[] = array ('ERROR', sprintf(_('Was unable to remove attribtues from DN: %s.'), $DNs[$i]), ldap_error($_SESSION['ldap']->server()));
|
2004-01-10 11:47:48 +00:00
|
|
|
$stopprocessing = true;
|
|
|
|
}
|
2005-08-08 09:26:19 +00:00
|
|
|
//else $_SESSION['cache']->update_cache($DNs[$i], 'remove', $attributes[$DNs[$i]]['remove']); TODO: reactivate
|
2004-01-10 11:47:48 +00:00
|
|
|
}
|
|
|
|
}
|
2005-03-26 11:27:15 +00:00
|
|
|
}
|
2004-01-10 11:47:48 +00:00
|
|
|
if (!$stopprocessing) {
|
|
|
|
foreach ($attributes as $DN) {
|
2004-12-09 19:10:57 +00:00
|
|
|
if (is_array($DN['lamdaemon']['command'])) $result = lamdaemon($DN['lamdaemon']['command']);
|
2005-03-26 11:27:15 +00:00
|
|
|
if (!is_array($result)) continue;
|
|
|
|
// check for error somewhere in lamdaemon
|
2004-01-10 11:47:48 +00:00
|
|
|
foreach ($result as $singleresult) {
|
|
|
|
if (is_array($singleresult)) {
|
2005-03-26 11:27:15 +00:00
|
|
|
if ($singleresult[0] == 'ERROR') {
|
|
|
|
$stopprocessing = true;
|
|
|
|
$temparray[0] = $singleresult[0];
|
|
|
|
$temparray[1] = $singleresult[1];
|
|
|
|
$temparray[2] = $singleresult[2];
|
|
|
|
$errors[] = $temparray;
|
2004-01-10 11:47:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-04-25 16:14:09 +00:00
|
|
|
}
|
2005-03-26 11:27:15 +00:00
|
|
|
}
|
2004-01-10 11:47:48 +00:00
|
|
|
if (!$stopprocessing) {
|
2005-03-26 11:27:15 +00:00
|
|
|
$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;
|
2004-01-10 11:47:48 +00:00
|
|
|
}
|
2005-08-08 09:26:19 +00:00
|
|
|
//else TODO: reactivate
|
|
|
|
//$_SESSION['cache']->update_cache($_SESSION['delete_dn'][$m], 'delete_dn'); TODO: reactivate
|
2005-03-26 11:27:15 +00:00
|
|
|
}
|
2004-01-10 11:47:48 +00:00
|
|
|
if (!$stopprocessing) {
|
2005-03-26 11:27:15 +00:00
|
|
|
echo sprintf(_('Deleted DN: %s'), $_SESSION['delete_dn'][$m]) . "<br>\n";
|
2004-01-10 11:47:48 +00:00
|
|
|
foreach ($errors as $error) StatusMessage($error[0], $error[1], $error[2]);
|
2005-03-26 11:27:15 +00:00
|
|
|
echo "<br>\n";
|
|
|
|
}
|
2004-01-10 11:47:48 +00:00
|
|
|
else {
|
2005-03-26 11:27:15 +00:00
|
|
|
echo sprintf(_('Error while deleting DN: %s'), $_SESSION['delete_dn'][$m]) . "<br>\n";
|
2004-01-10 11:47:48 +00:00
|
|
|
foreach ($errors as $error) StatusMessage($error[0], $error[1], $error[2]);
|
2005-03-26 11:27:15 +00:00
|
|
|
echo "<br>\n";
|
2003-08-20 19:16:03 +00:00
|
|
|
}
|
2005-03-26 11:27:15 +00:00
|
|
|
}
|
2005-08-08 09:26:19 +00:00
|
|
|
$_SESSION['cache']->refresh_cache(true); // TODO: remove when update_cache is fixed
|
2004-01-10 11:47:48 +00:00
|
|
|
echo "<br>\n";
|
2005-03-26 11:27:15 +00:00
|
|
|
echo "<br><input name=\"cancel\" type=\"submit\" value=\"" . _('Back to list') . "\">\n";
|
2004-01-10 11:47:48 +00:00
|
|
|
echo "</fieldset>\n";
|
|
|
|
echo "</form>\n";
|
|
|
|
echo "</body>\n";
|
|
|
|
echo "</html>\n";
|
2003-05-02 07:59:13 +00:00
|
|
|
|
2005-03-26 11:27:15 +00:00
|
|
|
}
|
2003-05-02 07:59:13 +00:00
|
|
|
|
2003-04-25 16:14:09 +00:00
|
|
|
?>
|