| 
									
										
										
										
											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 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 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'); | 
					
						
							|  |  |  | session_save_path('../sess'); | 
					
						
							|  |  |  | @session_start(); | 
					
						
							| 
									
										
										
										
											2003-08-10 19:46:21 +00:00
										 |  |  | setlanguage(); | 
					
						
							| 
									
										
										
										
											2003-04-25 16:14:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-10 19:46:21 +00:00
										 |  |  | echo $_SESSION['header']; | 
					
						
							| 
									
										
										
										
											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". | 
					
						
							|  |  |  | 	'<link rel="stylesheet" type="text/css" href="../style/layout.css">'."\n". | 
					
						
							|  |  |  | 	'<meta http-equiv="pragma" content="no-cache">'."\n". | 
					
						
							| 
									
										
										
										
											2003-08-20 19:16:03 +00:00
										 |  |  | 	'<meta http-equiv="cache-control" content="no-cache">'."\n"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if ($_POST['backmain']) | 
					
						
							|  |  |  | 	switch ( $_POST['type5'] ) { | 
					
						
							|  |  |  | 		case 'user' : | 
					
						
							|  |  |  | 			echo "<meta http-equiv=\"refresh\" content=\"2; URL=lists/listusers.php\">\n"; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 'group' : | 
					
						
							|  |  |  | 			echo "<meta http-equiv=\"refresh\" content=\"2; URL=lists/listgroups.php\">\n"; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 'host' : | 
					
						
							|  |  |  | 			echo "<meta http-equiv=\"refresh\" content=\"2; URL=lists/listhosts.php\">\n"; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | echo '</head>'."\n". | 
					
						
							| 
									
										
										
										
											2003-07-24 16:44:21 +00:00
										 |  |  | 	'<body>'."\n". | 
					
						
							|  |  |  | 	'<form action="delete.php" method="post">'."\n". | 
					
						
							|  |  |  | 	'<table class="delete" width="100%">'."\n". | 
					
						
							|  |  |  | 	'<tr><td>'; | 
					
						
							| 
									
										
										
										
											2003-04-25 11:07:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-02 12:52:42 +00:00
										 |  |  | if ($_GET['type']) { | 
					
						
							|  |  |  | 	$DN2 = explode(";", str_replace("\'", '',$_GET['DN'])); | 
					
						
							|  |  |  | 	echo '<input name="type5" type="hidden" value="'.$_GET['type'].'">'; | 
					
						
							|  |  |  | 	echo '<input name="DN" type="hidden" value="'.$_GET['DN'].'">'; | 
					
						
							|  |  |  | 	switch ($_GET['type']) { | 
					
						
							| 
									
										
										
										
											2003-05-02 07:59:13 +00:00
										 |  |  | 		case 'user': | 
					
						
							|  |  |  | 			echo _('Do you really want to delete user(s):'); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 'host': | 
					
						
							|  |  |  | 			echo _('Do you really want to delete host(s):'); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 'group': | 
					
						
							|  |  |  | 			echo _('Do you really want to delete group(s):'); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2003-06-08 12:12:42 +00:00
										 |  |  | 	echo '</td></tr>'."\n"; | 
					
						
							| 
									
										
										
										
											2003-05-02 07:59:13 +00:00
										 |  |  | 	foreach ($DN2 as $dn) echo '<tr><td>'.$dn.'</td></tr>'; | 
					
						
							| 
									
										
										
										
											2003-06-08 12:12:42 +00:00
										 |  |  | 	echo '<tr><td>'; | 
					
						
							|  |  |  | 	if (($_GET['type']== user) && $_SESSION['config']->scriptServer) { | 
					
						
							|  |  |  | 		echo _('Delete also Homedirectories'); | 
					
						
							| 
									
										
										
										
											2003-07-24 16:44:21 +00:00
										 |  |  | 		echo '</td>'."\n".'<td><input name="f_rem_home" type="checkbox">'. | 
					
						
							|  |  |  | 			'</td></tr>'."\n".'<tr><td>'; | 
					
						
							| 
									
										
										
										
											2003-06-08 12:12:42 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2003-07-24 16:44:21 +00:00
										 |  |  | 	echo '<br></td></tr>'."\n".'<tr><td>'. | 
					
						
							|  |  |  | 		'<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-05-02 07:59:13 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-20 19:16:03 +00:00
										 |  |  | if ($_POST['delete_yes'] && !$_POST['backmain']) { | 
					
						
							| 
									
										
										
										
											2003-05-02 12:52:42 +00:00
										 |  |  | 	$DN2 = explode(";", str_replace("\\", '',str_replace("\'", '',$_POST['DN']))); | 
					
						
							| 
									
										
										
										
											2003-04-26 21:58:00 +00:00
										 |  |  | 	foreach ($DN2 as $dn) { | 
					
						
							| 
									
										
										
										
											2003-08-20 19:16:03 +00:00
										 |  |  | 		echo '<input name="type5" type="hidden" value="'.$_POST['type5'].'">'; | 
					
						
							| 
									
										
										
										
											2003-05-02 12:52:42 +00:00
										 |  |  | 		switch ($_POST['type5']) { | 
					
						
							| 
									
										
										
										
											2003-04-25 16:14:09 +00:00
										 |  |  | 			case 'user': | 
					
						
							| 
									
										
										
										
											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-05-15 20:59:26 +00:00
										 |  |  | 				if ($_SESSION['config']->scriptServer) { | 
					
						
							| 
									
										
										
										
											2003-06-08 12:12:42 +00:00
										 |  |  | 					if ($_POST['f_rem_home']) remhomedir($username); | 
					
						
							| 
									
										
										
										
											2003-05-15 20:59:26 +00:00
										 |  |  | 					remquotas($username, $_POST['type5']); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				$result = ldap_search($_SESSION['ldap']->server(), $_SESSION['config']->get_GroupSuffix(), 'objectClass=PosixGroup', array('memberUid')); | 
					
						
							|  |  |  | 				$entry = ldap_first_entry($_SESSION['ldap']->server(), $result); | 
					
						
							|  |  |  | 				while ($entry) { | 
					
						
							|  |  |  | 					$attr2 = ldap_get_attributes($_SESSION['ldap']->server(), $entry); | 
					
						
							|  |  |  | 					if ($attr2['memberUid']) { | 
					
						
							|  |  |  | 						array_shift($attr2['memberUid']); | 
					
						
							|  |  |  | 						foreach ($attr2['memberUid'] as $nam) { | 
					
						
							|  |  |  | 							if ($nam==$username) { | 
					
						
							|  |  |  | 								$todelete['memberUid'] = $nam; | 
					
						
							|  |  |  | 								$success = ldap_mod_del($_SESSION['ldap']->server(), ldap_get_dn($_SESSION['ldap']->server(), $entry) ,$todelete); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					$entry = ldap_next_entry($_SESSION['ldap']->server(), $entry); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2003-04-25 16:14:09 +00:00
										 |  |  | 				$success = ldap_delete($_SESSION['ldap']->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': | 
					
						
							|  |  |  | 				$success = ldap_delete($_SESSION['ldap']->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-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-06-08 12:12:42 +00:00
										 |  |  | 				$result = ldap_search($_SESSION['ldap']->server(), $dn, 'objectClass=*', array('gidNumber')); | 
					
						
							| 
									
										
										
										
											2003-04-26 21:58:00 +00:00
										 |  |  | 				$entry = ldap_first_entry($_SESSION['ldap']->server(), $result); | 
					
						
							| 
									
										
										
										
											2003-06-07 14:25:30 +00:00
										 |  |  | 				while ($entry) { | 
					
						
							|  |  |  | 					$attr2 = ldap_get_attributes($_SESSION['ldap']->server(), $entry); | 
					
						
							| 
									
										
										
										
											2003-08-03 13:22:12 +00:00
										 |  |  | 					if ($attr2['gidNumber']==getgid($groupname)) $error = _('Could not delete group. Still users in group:').' '.$dn; | 
					
						
							| 
									
										
										
										
											2003-06-07 14:25:30 +00:00
										 |  |  | 					$entry = ldap_next_entry($_SESSION['ldap']->server(), $entry); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				if (!$error) { | 
					
						
							| 
									
										
										
										
											2003-05-16 20:00:45 +00:00
										 |  |  | 					if ($_SESSION['config']->scriptServer) remquotas($groupname, $_POST['type5']); | 
					
						
							| 
									
										
										
										
											2003-04-26 21:58:00 +00:00
										 |  |  | 					$success = ldap_delete($_SESSION['ldap']->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-08-03 13:22:12 +00:00
										 |  |  | 		if (!$error) echo $dn.' '. _('deleted').'.'; | 
					
						
							| 
									
										
										
										
											2003-04-26 21:58:00 +00:00
										 |  |  | 		 else echo $error; | 
					
						
							| 
									
										
										
										
											2003-06-08 12:12:42 +00:00
										 |  |  | 		echo '</td></tr>'."\n".'<tr><td>'; | 
					
						
							| 
									
										
										
										
											2003-04-25 11:07:28 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2003-08-20 19:16:03 +00:00
										 |  |  | 	switch ($_POST['type5']) { | 
					
						
							|  |  |  | 		case 'user': | 
					
						
							|  |  |  | 			echo '<input name="backmain" type="submit" value="'; echo _('Back to user list'); echo '">'. | 
					
						
							|  |  |  | 			'</td></tr>'."\n"; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 'group': | 
					
						
							|  |  |  | 			echo '<input name="backmain" type="submit" value="'; echo _('Back to group list'); echo '">'. | 
					
						
							|  |  |  | 			'</td></tr>'."\n"; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 'host': | 
					
						
							|  |  |  | 			echo '<input name="backmain" type="submit" value="'; echo _('Back to host list'); echo '">'. | 
					
						
							|  |  |  | 			'</td></tr>'."\n"; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											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-08-29 12:22:08 +00:00
										 |  |  | 	echo _('Nothing was deleted').'</td></tr>'; | 
					
						
							| 
									
										
										
										
											2003-08-20 19:16:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-05-02 07:59:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-20 19:16:03 +00:00
										 |  |  | if ($_POST['backmain']) | 
					
						
							|  |  |  | 	switch ( $_POST['type5'] ) { | 
					
						
							|  |  |  | 		case 'user' : | 
					
						
							|  |  |  | 			echo '<tr><td><a href="lists/listusers.php">'; | 
					
						
							|  |  |  | 			echo _('Please press here if meta-refresh didn\'t work.'); | 
					
						
							|  |  |  | 			echo "</a></td></tr>\n"; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 'group' : | 
					
						
							|  |  |  | 			echo '<tr><td><a href="lists/listgroup.php">'; | 
					
						
							|  |  |  | 			echo _('Please press here if meta-refresh didn\'t work.'); | 
					
						
							|  |  |  | 			echo "</a></td></tr>\n"; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 'host' : | 
					
						
							|  |  |  | 			echo '<tr><td><a href="lists/listhost.php">'; | 
					
						
							|  |  |  | 			echo _('Please press here if meta-refresh didn\'t work.'); | 
					
						
							|  |  |  | 			echo "</a></td></tr>\n"; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2003-06-08 12:12:42 +00:00
										 |  |  | echo '</table></form></body></html>'."\n"; | 
					
						
							| 
									
										
										
										
											2003-04-25 16:14:09 +00:00
										 |  |  | ?>
 |