2003-09-28 13:30:31 +00:00
|
|
|
<?php
|
2003-04-25 11:07:28 +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
|
|
|
|
|
|
|
|
|
|
|
|
LDAP Account Manager Delete user, hosts or groups
|
|
|
|
*/
|
2003-10-20 17:56:52 +00:00
|
|
|
|
2003-04-25 11:07:28 +00:00
|
|
|
include_once('../lib/ldap.inc');
|
2003-05-14 21:12:17 +00:00
|
|
|
include_once('../lib/account.inc');
|
2003-04-26 21:58:00 +00:00
|
|
|
include_once('../lib/config.inc');
|
2003-10-20 17:56:52 +00:00
|
|
|
// start session
|
2003-04-26 21:58:00 +00:00
|
|
|
session_save_path('../sess');
|
|
|
|
@session_start();
|
2003-10-20 17:56:52 +00:00
|
|
|
// set language
|
2003-08-10 19:46:21 +00:00
|
|
|
setlanguage();
|
2003-04-25 16:14:09 +00:00
|
|
|
|
2003-10-20 17:56:52 +00:00
|
|
|
// use references because session-vars can change in future
|
2003-10-04 18:44:18 +00:00
|
|
|
$ldap_intern =& $_SESSION['ldap'];
|
|
|
|
$header_intern =& $_SESSION['header'];
|
|
|
|
$config_intern =& $_SESSION['config'];
|
|
|
|
$delete_dn =& $_SESSION['delete_dn'];
|
|
|
|
|
2003-10-01 12:14:04 +00:00
|
|
|
|
2003-10-20 17:56:52 +00:00
|
|
|
if ($_POST['backmain']) {
|
|
|
|
// back to list page
|
2003-10-01 14:59:23 +00:00
|
|
|
if (isset($_SESSION['delete_dn'])) unset ($_SESSION['delete_dn']);
|
2003-10-20 17:56:52 +00:00
|
|
|
metaRefresh("lists/list".$_POST['type']."s.php");
|
|
|
|
// stop script because we don't want to reate invalid html-code
|
2003-10-01 12:14:04 +00:00
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
2003-10-20 17:56:52 +00:00
|
|
|
// Print header and part of body
|
2003-10-04 18:44:18 +00:00
|
|
|
echo $header_intern;
|
2003-04-25 11:07:28 +00:00
|
|
|
echo '<html><head><title>';
|
|
|
|
echo _('Delete Account');
|
2003-07-24 16:44:21 +00:00
|
|
|
echo '</title>'."\n".
|
2003-10-20 17:56:52 +00:00
|
|
|
'<link rel="stylesheet" type="text/css" href="../style/layout.css">'."\n".
|
2003-07-24 16:44:21 +00:00
|
|
|
'<meta http-equiv="pragma" content="no-cache">'."\n".
|
2003-10-01 12:14:04 +00:00
|
|
|
'<meta http-equiv="cache-control" content="no-cache">'."\n".
|
|
|
|
'</head>'."\n".
|
2003-07-24 16:44:21 +00:00
|
|
|
'<body>'."\n".
|
2003-09-19 10:03:00 +00:00
|
|
|
'<form action="delete.php" method="post">'."\n";
|
2003-04-25 11:07:28 +00:00
|
|
|
|
2003-10-20 17:56:52 +00:00
|
|
|
|
2003-05-02 12:52:42 +00:00
|
|
|
if ($_GET['type']) {
|
2003-10-20 17:56:52 +00:00
|
|
|
// $_GET['type'] is true if delete.php was called from *list.php
|
|
|
|
// Store $_GET['type'] as $_POST['type']
|
|
|
|
echo '<input name="type" type="hidden" value="'.$_GET['type'].'">';
|
2003-05-02 12:52:42 +00:00
|
|
|
switch ($_GET['type']) {
|
2003-10-20 17:56:52 +00:00
|
|
|
// Select which layout and text should be displayed
|
2003-05-02 07:59:13 +00:00
|
|
|
case 'user':
|
2003-09-19 10:03:00 +00:00
|
|
|
echo "<fieldset class=\"useredit-bright\"><legend class=\"useredit-bright\"><b>";
|
|
|
|
echo _('Delete user(s)');
|
|
|
|
echo "</b></legend>\n";
|
2003-10-07 18:39:44 +00:00
|
|
|
echo '<b>'._('Do you really want to delete user(s):').'</b>';
|
2003-05-02 07:59:13 +00:00
|
|
|
break;
|
|
|
|
case 'host':
|
2003-09-19 10:03:00 +00:00
|
|
|
echo "<fieldset class=\"hostedit-bright\"><legend class=\"hostedit-bright\"><b>";
|
|
|
|
echo _('Delete host(s)');
|
|
|
|
echo "</b></legend>\n";
|
2003-10-17 07:58:43 +00:00
|
|
|
echo '<b>'._('Do you really want to delete host(s):').'</b>';
|
2003-05-02 07:59:13 +00:00
|
|
|
break;
|
|
|
|
case 'group':
|
2003-09-19 10:03:00 +00:00
|
|
|
echo "<fieldset class=\"groupedit-bright\"><legend class=\"groupedit-bright\"><b>";
|
|
|
|
echo _('Delete group(s)');
|
|
|
|
echo "</b></legend>\n";
|
2003-10-17 07:58:43 +00:00
|
|
|
echo '<b>'._('Do you really want to delete group(s):').'</b>';
|
2003-05-02 07:59:13 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-10-02 14:10:31 +00:00
|
|
|
echo "<br>\n";
|
2003-10-20 17:56:52 +00:00
|
|
|
// display all DNs in a tables
|
2003-09-19 10:03:00 +00:00
|
|
|
echo "<table border=0 width=\"100%\">\n";
|
2003-10-04 18:44:18 +00:00
|
|
|
foreach ($delete_dn as $dn) echo '<tr><td>'.$dn.'</td></tr>';
|
2003-09-19 10:03:00 +00:00
|
|
|
echo "</table>\n";
|
2003-10-20 17:56:52 +00:00
|
|
|
|
|
|
|
// Ask if lam should delete homedirs if users are deleted and lamdaemon.pl is in use
|
2003-10-04 18:44:18 +00:00
|
|
|
if (($_GET['type']== user) && $config_intern->scriptServer) {
|
2003-10-02 14:10:31 +00:00
|
|
|
echo "<br>\n";
|
|
|
|
echo "<table border=0>\n";
|
2003-09-19 10:03:00 +00:00
|
|
|
echo '<tr><td>';
|
2003-06-08 12:12:42 +00:00
|
|
|
echo _('Delete also Homedirectories');
|
2003-07-24 16:44:21 +00:00
|
|
|
echo '</td>'."\n".'<td><input name="f_rem_home" type="checkbox">'.
|
2003-09-19 10:03:00 +00:00
|
|
|
'</td></tr>'."\n";
|
|
|
|
echo "</table>\n";
|
2003-06-08 12:12:42 +00:00
|
|
|
}
|
2003-09-19 10:03:00 +00:00
|
|
|
|
2003-10-20 17:56:52 +00:00
|
|
|
// Print buttons
|
2003-10-02 14:10:31 +00:00
|
|
|
echo "<br><table border=0>\n";
|
2003-09-19 10:03:00 +00:00
|
|
|
echo '<tr><td>'.
|
2003-07-24 16:44:21 +00:00
|
|
|
'<input name="delete_no" type="submit" value="';
|
|
|
|
echo _('Cancel'); echo '"></td><td></td><td>'.
|
|
|
|
'<input name="delete_yes" type="submit" value="';
|
2003-08-20 19:16:03 +00:00
|
|
|
echo _('Commit'); echo '"></td></tr>';
|
2003-09-19 10:03:00 +00:00
|
|
|
echo "</table></fieldset>\n";
|
2003-05-02 07:59:13 +00:00
|
|
|
}
|
|
|
|
|
2003-09-19 10:03:00 +00:00
|
|
|
|
2003-10-20 17:56:52 +00:00
|
|
|
if ($_POST['delete_yes']) {
|
|
|
|
// deletion has been confirmed.
|
|
|
|
switch ($_POST['type']) {
|
2003-09-19 10:03:00 +00:00
|
|
|
case 'user':
|
|
|
|
echo "<fieldset class=\"useredit-bright\"><legend class=\"useredit-bright\"><b>";
|
|
|
|
echo _('Deleting user(s)...');
|
|
|
|
echo "</b></legend>\n";
|
|
|
|
break;
|
|
|
|
case 'host':
|
|
|
|
echo "<fieldset class=\"hostedit-bright\"><legend class=\"hostedit-bright\"><b>";
|
|
|
|
echo _('Deleting host(s)...');
|
|
|
|
echo "</b></legend>\n";
|
|
|
|
break;
|
|
|
|
case 'group':
|
|
|
|
echo "<fieldset class=\"groupedit-bright\"><legend class=\"groupedit-bright\"><b>";
|
|
|
|
echo _('Deleting group(s)...');
|
|
|
|
echo "</b></legend>\n";
|
|
|
|
break;
|
|
|
|
}
|
2003-10-20 17:56:52 +00:00
|
|
|
echo '<input name="type" type="hidden" value="'.$_POST['type'].'">';
|
2003-10-02 14:10:31 +00:00
|
|
|
echo "<br><table border=0 >\n";
|
2003-10-20 17:56:52 +00:00
|
|
|
// Store kind of DNs
|
2003-10-04 18:44:18 +00:00
|
|
|
foreach ($delete_dn as $dn) {
|
2003-10-20 17:56:52 +00:00
|
|
|
// Loop for every DN which should be deleted
|
|
|
|
switch ($_POST['type']) {
|
2003-04-25 16:14:09 +00:00
|
|
|
case 'user':
|
2003-10-20 17:56:52 +00:00
|
|
|
// Get username from DN
|
2003-05-15 20:59:26 +00:00
|
|
|
$temp=explode(',', $dn);
|
2003-05-16 20:00:45 +00:00
|
|
|
$username = str_replace('uid=', '', $temp[0]);
|
2003-10-20 17:56:52 +00:00
|
|
|
|
2003-10-04 18:44:18 +00:00
|
|
|
if ($config_intern->scriptServer) {
|
2003-10-20 17:56:52 +00:00
|
|
|
// Remove homedir if required
|
2003-06-08 12:12:42 +00:00
|
|
|
if ($_POST['f_rem_home']) remhomedir($username);
|
2003-10-20 17:56:52 +00:00
|
|
|
// Remove quotas if lamdaemon.pl is used
|
|
|
|
if ($config_intern->scriptServer) remquotas($username, 'user');
|
2003-05-15 20:59:26 +00:00
|
|
|
}
|
2003-10-20 17:56:52 +00:00
|
|
|
// Search for groups which have memberUid set to username
|
|
|
|
$result = ldap_search($ldap_intern->server(), $config_intern->get_GroupSuffix(), "(&(objectClass=PosixGroup)(memberUid=$username))", array(''));
|
2003-10-04 18:44:18 +00:00
|
|
|
$entry = ldap_first_entry($ldap_intern->server(), $result);
|
2003-10-20 17:56:52 +00:00
|
|
|
// loop for every found group and remove membership
|
2003-05-15 20:59:26 +00:00
|
|
|
while ($entry) {
|
2003-10-20 17:56:52 +00:00
|
|
|
$success = ldap_mod_del($ldap_intern->server(), ldap_get_dn($ldap_intern->server(), $entry) , array('memberUid' => $username));
|
|
|
|
// *** fixme add error-message if memberUid couldn't be deleted
|
2003-10-04 18:44:18 +00:00
|
|
|
$entry = ldap_next_entry($ldap_intern->server(), $entry);
|
2003-05-15 20:59:26 +00:00
|
|
|
}
|
2003-10-20 17:56:52 +00:00
|
|
|
// Delete user itself
|
2003-10-04 18:44:18 +00:00
|
|
|
$success = ldap_delete($ldap_intern->server(), $dn);
|
2003-08-03 13:22:12 +00:00
|
|
|
if (!$success) $error = _('Could not delete user:').' '.$dn;
|
2003-04-25 16:14:09 +00:00
|
|
|
break;
|
|
|
|
case 'host':
|
2003-10-20 17:56:52 +00:00
|
|
|
// Delete host itself
|
2003-10-04 18:44:18 +00:00
|
|
|
$success = ldap_delete($ldap_intern->server(), $dn);
|
2003-08-03 13:22:12 +00:00
|
|
|
if (!$success) $error = _('Could not delete host:').' '.$dn;
|
2003-04-25 16:14:09 +00:00
|
|
|
break;
|
|
|
|
case 'group':
|
2003-10-20 17:56:52 +00:00
|
|
|
/* First we have to check if any user uses $group
|
|
|
|
* as primary group. It's not allowed to delete a
|
|
|
|
* group if it still contains primaty members
|
|
|
|
*/
|
2003-05-15 20:59:26 +00:00
|
|
|
$temp=explode(',', $dn);
|
2003-05-16 20:00:45 +00:00
|
|
|
$groupname = str_replace('cn=', '', $temp[0]);
|
2003-10-20 17:56:52 +00:00
|
|
|
// Get group GIDNumber
|
|
|
|
$groupgid = getgid($groupname);
|
|
|
|
// Search for users which have gid set to current gid
|
|
|
|
$result = ldap_search($ldap_intern->server(), $dn, "gidNumber=$groupgid", array(''));
|
2003-10-04 18:44:18 +00:00
|
|
|
$entry = ldap_first_entry($ldap_intern->server(), $result);
|
2003-10-20 17:56:52 +00:00
|
|
|
// Print error if still users in group
|
|
|
|
if ($entry) $error = _('Could not delete group. Still users in group:').' '.$dn;
|
|
|
|
else {
|
|
|
|
// continue if no primary users are in group
|
|
|
|
// Remove quotas if lamdaemon.pl is used
|
|
|
|
if ($config_intern->scriptServer) remquotas($groupname, 'group');
|
|
|
|
// Delete group itself
|
2003-10-04 18:44:18 +00:00
|
|
|
$success = ldap_delete($ldap_intern->server(), $dn);
|
2003-08-03 13:22:12 +00:00
|
|
|
if (!$success) $error = _('Could not delete group:').' '.$dn;
|
2003-04-26 21:58:00 +00:00
|
|
|
}
|
2003-04-25 16:14:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-10-20 17:56:52 +00:00
|
|
|
// Remove DNs from cache-array
|
|
|
|
if ($success && isset($_SESSION[$_POST['type'].'DN'][$dn])) unset($_SESSION[$_POST['type'].'DN'][$dn]);
|
|
|
|
// Display success or error-message
|
2003-09-19 10:03:00 +00:00
|
|
|
if (!$error) echo "<tr><td><b>$dn ". _('deleted').".</b></td></tr>\n";
|
|
|
|
else echo "<tr><td><b>$error</b></td></tr>\n";
|
2003-04-25 11:07:28 +00:00
|
|
|
}
|
2003-09-19 10:03:00 +00:00
|
|
|
echo "</table><br>\n";
|
2003-10-20 17:56:52 +00:00
|
|
|
switch ($_POST['type']) {
|
|
|
|
// Select which page should be displayd if back-button will be pressed
|
2003-08-20 19:16:03 +00:00
|
|
|
case 'user':
|
2003-09-19 10:03:00 +00:00
|
|
|
echo '<input name="backmain" type="submit" value="'; echo _('Back to user list'); echo '">';
|
2003-08-20 19:16:03 +00:00
|
|
|
break;
|
|
|
|
case 'group':
|
2003-09-19 10:03:00 +00:00
|
|
|
echo '<input name="backmain" type="submit" value="'; echo _('Back to group list'); echo '">';
|
2003-08-20 19:16:03 +00:00
|
|
|
break;
|
|
|
|
case 'host':
|
2003-09-19 10:03:00 +00:00
|
|
|
echo '<input name="backmain" type="submit" value="'; echo _('Back to host list'); echo '">';
|
2003-08-20 19:16:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-10-20 17:56:52 +00:00
|
|
|
echo "<br></fieldset>\n";
|
2003-04-25 11:07:28 +00:00
|
|
|
}
|
2003-05-02 07:59:13 +00:00
|
|
|
|
2003-08-20 19:16:03 +00:00
|
|
|
if ($_POST['delete_no']) {
|
2003-10-20 17:56:52 +00:00
|
|
|
// Delete no accounts
|
|
|
|
switch ($_POST['type']) {
|
|
|
|
// Select which page should be displayd if back-button will be pressed
|
2003-09-19 10:03:00 +00:00
|
|
|
case 'user':
|
|
|
|
echo "<fieldset class=\"useredit-bright\"><legend class=\"useredit-bright\"><b>";
|
|
|
|
echo _('Deleting user(s) canceled.');
|
|
|
|
echo "</b></legend>\n";
|
|
|
|
echo _('No user(s) were deleted');
|
|
|
|
echo "<br>";
|
|
|
|
echo '<input name="backmain" type="submit" value="'; echo _('Back to user list'); echo '">';
|
|
|
|
break;
|
|
|
|
case 'host':
|
|
|
|
echo "<fieldset class=\"hostedit-bright\"><legend class=\"hostedit-bright\"><b>";
|
|
|
|
echo _('Deleting host(s) canceled.');
|
|
|
|
echo "</b></legend>\n";
|
|
|
|
echo _('No host(s) were deleted');
|
|
|
|
echo "<br>";
|
|
|
|
echo '<input name="backmain" type="submit" value="'; echo _('Back to host list'); echo '">';
|
|
|
|
break;
|
|
|
|
case 'group':
|
|
|
|
echo "<fieldset class=\"groupedit-bright\"><legend class=\"groupedit-bright\"><b>";
|
|
|
|
echo _('Deleting group(s) canceled.');
|
|
|
|
echo "</b></legend>\n";
|
|
|
|
echo _('No group(s) were deleted');
|
|
|
|
echo "<br>";
|
|
|
|
echo '<input name="backmain" type="submit" value="'; echo _('Back to group list'); echo '">';
|
|
|
|
break;
|
|
|
|
}
|
2003-10-20 17:56:52 +00:00
|
|
|
echo "<br></fieldset>\n";
|
2003-08-20 19:16:03 +00:00
|
|
|
}
|
2003-05-02 07:59:13 +00:00
|
|
|
|
2003-09-19 10:03:00 +00:00
|
|
|
echo '</form></body></html>'."\n";
|
2003-04-25 16:14:09 +00:00
|
|
|
?>
|