LDAPAccountManager/lam/templates/delete.php

342 lines
11 KiB
PHP
Raw Normal View History

<?php
2017-01-07 17:39:40 +00:00
namespace LAM\DELETE;
/*
2005-03-26 11:27:15 +00:00
$Id$
2006-08-14 17:29:45 +00:00
2009-10-27 18:47:12 +00:00
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
2006-03-03 17:30:35 +00:00
Copyright (C) 2003 - 2006 Tilo Lutz
2017-01-07 17:39:40 +00:00
Copyright (C) 2007 - 2017 Roland Gruber
2006-08-14 17:29:45 +00:00
2005-03-26 11:27:15 +00:00
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.
2006-08-14 17:29:45 +00:00
2005-03-26 11:27:15 +00:00
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.
2006-08-14 17:29:45 +00:00
2005-03-26 11:27:15 +00:00
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
2006-08-14 17:29:45 +00:00
2005-03-26 11:27:15 +00:00
*/
2005-03-26 11:27:15 +00:00
/**
* Used to delete accounts from LDAP tree.
*
* @author Tilo Lutz
* @author Roland Gruber
2005-08-17 19:17:15 +00:00
* @package main
*/
2004-01-10 11:47:48 +00:00
2006-03-26 17:51:25 +00:00
/** security functions */
include_once("../lib/security.inc");
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');
2017-09-16 13:09:25 +00:00
/** remote interface */
include_once('../lib/remote.inc');
2005-08-17 19:17:15 +00:00
/** module interface */
include_once('../lib/modules.inc');
2004-01-10 11:47:48 +00:00
// Start session
2006-03-26 17:51:25 +00:00
startSecureSession();
2017-02-11 16:11:37 +00:00
enforceUserIsLoggedIn();
2004-01-10 11:47:48 +00:00
2007-12-30 16:08:54 +00:00
if (!checkIfWriteAccessIsAllowed()) {
die();
}
// Redirect to startpage if user is not loged in
2014-10-25 19:17:53 +00:00
if (!isLoggedIn()) {
metaRefresh("login.php");
2004-01-10 11:47:48 +00:00
exit;
2005-03-26 11:27:15 +00:00
}
2004-01-10 11:47:48 +00:00
// Set correct language, codepages, ....
setlanguage();
2003-04-25 16:14:09 +00:00
2015-05-15 19:16:46 +00:00
if (!empty($_POST)) {
validateSecurityToken();
}
2017-01-07 17:39:40 +00:00
$typeManager = new \LAM\TYPES\TypeManager();
2017-10-24 18:43:28 +00:00
if (isset($_POST['type']) && ($typeManager->getConfiguredType($_POST['type']) === null)) {
2012-03-13 21:34:13 +00:00
logNewMessage(LOG_ERR, 'Invalid type: ' . $_POST['type']);
die();
}
2007-04-21 11:04:50 +00:00
if (isset($_GET['type']) && isset($_SESSION['delete_dn'])) {
2017-01-07 17:39:40 +00:00
$typeId = $_GET['type'];
$type = $typeManager->getConfiguredType($typeId);
2017-10-24 18:43:28 +00:00
if ($type === null) {
2017-01-07 17:39:40 +00:00
logNewMessage(LOG_ERR, 'Invalid type: ' . $type->getId());
2012-03-13 21:34:13 +00:00
die();
}
2017-01-07 17:39:40 +00:00
if (!checkIfDeleteEntriesIsAllowed($type->getId()) || !checkIfWriteAccessIsAllowed($type->getId())) {
logNewMessage(LOG_ERR, 'User tried to delete entries of forbidden type '. $type->getId());
die();
}
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
2017-01-07 17:39:40 +00:00
$_SESSION['account'] = new \accountContainer($type, 'account');
2004-01-10 11:47:48 +00:00
// Show HTML Page
2010-01-01 17:21:46 +00:00
include 'main_header.php';
2017-01-07 17:39:40 +00:00
echo "<div class=\"" . $type->getScope() . "-bright smallPaddingContent\">";
2010-08-21 09:43:52 +00:00
echo "<br>\n";
2004-01-10 11:47:48 +00:00
echo "<form action=\"delete.php\" method=\"post\">\n";
2015-05-15 19:16:46 +00:00
echo '<input type="hidden" name="' . getSecurityTokenName() . '" value="' . getSecurityTokenValue() . '">';
2017-01-07 17:39:40 +00:00
echo "<input name=\"type\" type=\"hidden\" value=\"" . $type->getId() . "\">\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";
2005-11-26 12:49:48 +00:00
echo "<table border=0>\n";
2017-09-17 09:25:11 +00:00
$userCount = sizeof($users);
for ($i = 0; $i < $userCount; $i++) {
2004-01-10 11:47:48 +00:00
echo "<tr>\n";
2012-03-13 21:34:13 +00:00
echo "<td><b>" . _("Account name:") . "</b> " . htmlspecialchars($users[$i]) . "</td>\n";
echo "<td>&nbsp;&nbsp;<b>" . _('DN') . ":</b> " . htmlspecialchars($_SESSION['delete_dn'][$i]) . "</td>\n";
2016-01-06 15:05:52 +00:00
$_SESSION['account']->load_account($_SESSION['delete_dn'][$i]);
if (!$_SESSION['account']->hasOnlyVirtualChildren()) {
$childCount = getChildCount($_SESSION['delete_dn'][$i]);
if ($childCount > 0) {
echo "<td>&nbsp;&nbsp;<b>" . _('Number of child entries') . ":</b> " . $childCount . "</td>\n";
}
2005-11-26 12:49:48 +00:00
}
2004-01-10 11:47:48 +00:00
echo "</tr>\n";
2005-03-26 11:27:15 +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%\" >";
2017-01-07 17:39:40 +00:00
$modules = $_SESSION['config']->get_AccountModules($type->getId());
$values = array();
$tabindex = 100;
2005-04-04 16:55:34 +00:00
foreach ($modules as $module) {
2017-01-07 17:39:40 +00:00
$module = \moduleCache::getModule($module, $type->getScope());
parseHtml(get_class($module), $module->display_html_delete(), $values, true, $tabindex, $type->getScope());
2005-03-26 11:27:15 +00:00
}
2004-01-10 11:47:48 +00:00
echo "</table>\n";
echo "<br>\n";
echo "<button class=\"smallPadding\" name=\"delete\" id=\"submitButton\">" . _('Delete') . "</button>&nbsp;\n";
echo "<button class=\"smallPadding\" name=\"cancel\" id=\"cancelButton\">" . _('Cancel') . "</button>\n";
2004-01-10 11:47:48 +00:00
echo "</form>\n";
echo "</div>\n";
?>
2017-01-07 17:39:40 +00:00
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#submitButton').button();
jQuery('#cancelButton').button();
});
</script>
<?php
2010-08-21 09:43:52 +00:00
include 'main_footer.php';
2005-03-26 11:27:15 +00:00
}
2003-05-02 07:59:13 +00:00
2010-09-26 11:11:01 +00:00
if (isset($_POST['cancel'])) {
2004-01-10 11:47:48 +00:00
if (isset($_SESSION['delete_dn'])) unset($_SESSION['delete_dn']);
2006-01-06 10:47:43 +00:00
metaRefresh("lists/list.php?type=" . $_POST['type']);
2005-03-26 11:27:15 +00:00
}
elseif (isset($_POST['cancelAllOk'])) {
if (isset($_SESSION['delete_dn'])) unset($_SESSION['delete_dn']);
metaRefresh("lists/list.php?type=" . $_POST['type'] . '&amp;deleteAllOk=1');
}
2010-09-26 11:11:01 +00:00
if (isset($_POST['delete'])) {
2017-01-07 17:39:40 +00:00
$typeId = $_POST['type'];
$type = $typeManager->getConfiguredType($typeId);
if (!checkIfDeleteEntriesIsAllowed($type->getId()) || !checkIfWriteAccessIsAllowed($type->getId())) {
logNewMessage(LOG_ERR, 'User tried to delete entries of forbidden type '. $type->getId());
die();
}
2004-01-10 11:47:48 +00:00
// Show HTML Page
2010-01-01 17:21:46 +00:00
include 'main_header.php';
2004-01-10 11:47:48 +00:00
echo "<form action=\"delete.php\" method=\"post\">\n";
2015-05-15 19:16:46 +00:00
echo '<input type="hidden" name="' . getSecurityTokenName() . '" value="' . getSecurityTokenValue() . '">';
2017-01-07 17:39:40 +00:00
echo "<input name=\"type\" type=\"hidden\" value=\"" . $type->getId() . "\">\n";
echo "<div class=\"" . $type->getScope() . "-bright smallPaddingContent\"><br>\n";
echo "<br>\n";
2016-01-06 15:05:52 +00:00
2004-01-10 11:47:48 +00:00
// Delete dns
$allOk = true;
2012-06-05 18:20:17 +00:00
$allErrors = array();
2017-09-17 09:25:11 +00:00
foreach ($_SESSION['delete_dn'] as $deleteDN) {
2004-01-10 11:47:48 +00:00
// Set to true if an real error has happened
$stopprocessing = false;
// First load DN.
2017-09-17 09:25:11 +00:00
$_SESSION['account']->load_account($deleteDN);
2004-01-10 11:47:48 +00:00
// get commands and changes of each attribute
2007-10-26 14:10:10 +00:00
$moduleNames = array_keys($_SESSION['account']->getAccountModules());
$modules = $_SESSION['account']->getAccountModules();
2004-01-10 11:47:48 +00:00
$attributes = array();
$errors = array();
2007-02-25 13:51:40 +00:00
// predelete actions
if (!$stopprocessing) {
2007-10-26 14:10:10 +00:00
foreach ($moduleNames as $singlemodule) {
$success = true;
$messages = $modules[$singlemodule]->preDeleteActions();
2017-09-17 10:33:33 +00:00
foreach ($messages as $message) {
$errors[] = $message;
if ($message[0] == 'ERROR') {
$success = false;
$allOk = false;
}
2017-09-17 10:33:33 +00:00
elseif ($message[0] == 'WARN') {
$allOk = false;
}
}
2007-02-25 13:51:40 +00:00
if (!$success) {
$stopprocessing = true;
break;
2004-01-10 11:47:48 +00:00
}
}
2009-06-14 12:31:51 +00:00
}
2007-02-25 13:51:40 +00:00
if (!$stopprocessing) {
// load attributes
2007-10-26 14:10:10 +00:00
foreach ($moduleNames as $singlemodule) {
2007-02-25 13:51:40 +00:00
// load changes
2007-10-26 14:10:10 +00:00
$temp = $modules[$singlemodule]->delete_attributes();
2007-02-25 13:51:40 +00:00
if (is_array($temp)) {
// merge changes
$DNs = array_keys($temp);
$attributes = array_merge_recursive($temp, $attributes);
2017-09-17 10:33:33 +00:00
foreach ($DNs as $dn) {
$ops = array_keys($temp[$dn]);
foreach ($ops as $op) {
$attrs = array_keys($temp[$dn][$op]);
foreach ($attrs as $attribute) {
$attributes[$dn][$op][$attribute] = array_unique($attributes[$dn][$op][$attribute]);
}
2007-02-25 13:51:40 +00:00
}
}
2004-01-10 11:47:48 +00:00
}
2005-03-26 11:27:15 +00:00
}
2007-02-25 13:51:40 +00:00
$DNs = array_keys($attributes);
2017-09-17 10:33:33 +00:00
foreach ($DNs as $dn) {
if (isset($attributes[$dn]['errors'])) {
foreach ($attributes[$dn]['errors'] as $singleerror) {
2007-02-25 13:51:40 +00:00
$errors[] = $singleerror;
if ($singleerror[0] == 'ERROR') {
$stopprocessing = true;
$allOk = false;
}
}
2005-03-26 11:27:15 +00:00
}
2007-02-25 13:51:40 +00:00
if (!$stopprocessing) {
// modify attributes
2017-09-17 10:33:33 +00:00
if (isset($attributes[$dn]['modify']) && !$stopprocessing) {
2017-10-24 18:48:34 +00:00
$success = ldap_mod_replace($_SESSION['ldap']->server(), $dn, $attributes[$dn]['modify']);
2007-02-25 13:51:40 +00:00
if (!$success) {
2017-09-17 10:33:33 +00:00
$errors[] = array ('ERROR', sprintf(_('Was unable to modify attributes from DN: %s.'), $dn), getDefaultLDAPErrorString($_SESSION['ldap']->server()));
2007-02-25 13:51:40 +00:00
$stopprocessing = true;
$allOk = false;
2007-02-25 13:51:40 +00:00
}
2003-04-26 21:58:00 +00:00
}
2007-02-25 13:51:40 +00:00
// add attributes
2017-09-17 10:33:33 +00:00
if (isset($attributes[$dn]['add']) && !$stopprocessing) {
2017-10-24 18:48:34 +00:00
$success = ldap_mod_add($_SESSION['ldap']->server(), $dn, $attributes[$dn]['add']);
2007-02-25 13:51:40 +00:00
if (!$success) {
2017-09-17 10:33:33 +00:00
$errors[] = array ('ERROR', sprintf(_('Was unable to add attributes to DN: %s.'), $dn), getDefaultLDAPErrorString($_SESSION['ldap']->server()));
2007-02-25 13:51:40 +00:00
$stopprocessing = true;
$allOk = false;
2007-02-25 13:51:40 +00:00
}
}
2011-02-26 13:14:10 +00:00
// remove attributes
2017-09-17 10:33:33 +00:00
if (isset($attributes[$dn]['remove']) && !$stopprocessing) {
2017-10-24 18:48:34 +00:00
$success = ldap_mod_del($_SESSION['ldap']->server(), $dn, $attributes[$dn]['remove']);
2007-02-25 13:51:40 +00:00
if (!$success) {
2017-09-17 10:33:33 +00:00
$errors[] = array ('ERROR', sprintf(_('Was unable to remove attributes from DN: %s.'), $dn), getDefaultLDAPErrorString($_SESSION['ldap']->server()));
2007-02-25 13:51:40 +00:00
$stopprocessing = true;
$allOk = false;
2007-02-25 13:51:40 +00:00
}
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) {
2016-01-06 15:05:52 +00:00
$recursive = !$_SESSION['account']->hasOnlyVirtualChildren();
2017-09-17 09:25:11 +00:00
$messages = deleteDN($deleteDN, $recursive);
2012-06-05 18:20:17 +00:00
$errors = array_merge($errors, $messages);
if (sizeof($errors) > 0) {
$stopprocessing = true;
$allOk = false;
}
2005-03-26 11:27:15 +00:00
}
2007-02-25 13:51:40 +00:00
// post delete actions
if (!$stopprocessing) {
2007-10-26 14:10:10 +00:00
foreach ($moduleNames as $singlemodule) {
$messages = $modules[$singlemodule]->postDeleteActions();
2017-09-17 10:33:33 +00:00
foreach ($messages as $message) {
$errors[] = $message;
if (($message[0] == 'ERROR') || ($message[0] == 'WARN')) {
$allOk = false;
}
}
}
2016-01-06 15:05:52 +00:00
}
2004-01-10 11:47:48 +00:00
if (!$stopprocessing) {
2017-09-17 09:25:11 +00:00
echo sprintf(_('Deleted DN: %s'), $deleteDN) . "<br>\n";
foreach ($errors as $error) {
call_user_func_array('StatusMessage', $error);
}
2005-03-26 11:27:15 +00:00
echo "<br>\n";
flush();
2005-03-26 11:27:15 +00:00
}
2004-01-10 11:47:48 +00:00
else {
2017-09-17 09:25:11 +00:00
echo sprintf(_('Error while deleting DN: %s'), $deleteDN) . "<br>\n";
foreach ($errors as $error) {
call_user_func_array('StatusMessage', $error);
}
2005-03-26 11:27:15 +00:00
echo "<br>\n";
2003-08-20 19:16:03 +00:00
}
2012-06-05 18:20:17 +00:00
$allErrors = array_merge($allErrors, $errors);
2005-03-26 11:27:15 +00:00
}
2004-01-10 11:47:48 +00:00
echo "<br>\n";
echo "<br><button class=\"smallPadding\" name=\"cancel\" id=\"backButton\">" . _('Back to list') . "</button>\n";
echo "<br><button class=\"hidden\" name=\"cancelAllOk\" id=\"backButtonAllOk\"> </button>\n";
echo "</div>\n";
2004-01-10 11:47:48 +00:00
echo "</form>\n";
?>
2017-01-07 17:39:40 +00:00
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#backButton').button();
<?php
if ($allOk) {
2012-06-05 18:20:17 +00:00
$_SESSION['listRedirectMessages'] = $allErrors;
echo "jQuery('#backButtonAllOk').click();";
}
?>
});
</script>
<?php
2010-08-21 09:43:52 +00:00
include 'main_footer.php';
2003-05-02 07:59:13 +00:00
2005-03-26 11:27:15 +00:00
}
2003-05-02 07:59:13 +00:00
2005-11-26 12:49:48 +00:00
/**
* Returns the number of child entries of a DN.
*
* @param string $dn DN of parent
2017-06-27 18:19:28 +00:00
* @return integer number of childs
2005-11-26 12:49:48 +00:00
*/
function getChildCount($dn) {
$entries = searchLDAP(escapeDN($dn), 'objectClass=*', array('dn'));
return (sizeof($entries) - 1);
2005-11-26 12:49:48 +00:00
}
2003-04-25 16:14:09 +00:00
?>