2009-06-30 09:22:30 +00:00
|
|
|
<?php
|
2009-06-30 09:24:29 +00:00
|
|
|
// $Header: /cvsroot/phpldapadmin/phpldapadmin/rdelete.php,v 1.20 2005/03/05 06:27:06 wurley Exp $
|
2009-06-30 08:05:37 +00:00
|
|
|
|
2009-06-30 09:24:29 +00:00
|
|
|
/**
|
2009-06-30 08:05:37 +00:00
|
|
|
* Recursively deletes the specified DN and all of its children
|
|
|
|
* Variables that come in as POST vars:
|
|
|
|
* - dn (rawurlencoded)
|
|
|
|
* - server_id
|
2009-06-30 09:24:29 +00:00
|
|
|
*
|
|
|
|
* @package phpLDAPadmin
|
|
|
|
*/
|
|
|
|
/**
|
2009-06-30 08:05:37 +00:00
|
|
|
*/
|
|
|
|
|
2009-06-30 08:09:20 +00:00
|
|
|
require realpath( 'common.php' );
|
2009-06-30 08:05:37 +00:00
|
|
|
|
2009-06-30 09:24:29 +00:00
|
|
|
$server_id = (isset($_POST['server_id']) ? $_POST['server_id'] : '');
|
|
|
|
$ldapserver = new LDAPServer($server_id);
|
|
|
|
|
|
|
|
if( $ldapserver->isReadOnly() )
|
|
|
|
pla_error( $lang['no_updates_in_read_only_mode'] );
|
|
|
|
if( ! $ldapserver->haveAuthInfo())
|
|
|
|
pla_error( $lang['not_enough_login_info'] );
|
|
|
|
|
2009-06-30 08:09:20 +00:00
|
|
|
$dn = $_POST['dn'];
|
|
|
|
$encoded_dn = rawurlencode( $dn );
|
2009-06-30 09:22:30 +00:00
|
|
|
$rdn = get_rdn( $dn );
|
2009-06-30 08:05:37 +00:00
|
|
|
|
|
|
|
if( ! $dn )
|
2009-06-30 09:22:30 +00:00
|
|
|
pla_error( $lang['you_must_specify_a_dn'] );
|
2009-06-30 08:05:37 +00:00
|
|
|
|
2009-06-30 09:24:29 +00:00
|
|
|
dn_exists( $ldapserver, $dn ) or pla_error( sprintf( $lang['no_such_entry'], htmlspecialchars( $dn ) ) );
|
2009-06-30 08:05:37 +00:00
|
|
|
|
2009-06-30 09:22:30 +00:00
|
|
|
include './header.php';
|
2009-06-30 09:24:29 +00:00
|
|
|
|
2009-06-30 08:05:37 +00:00
|
|
|
echo "<body>\n";
|
2009-06-30 09:22:30 +00:00
|
|
|
echo "<h3 class=\"title\">" . sprintf( $lang['deleting_dn'], htmlspecialchars($rdn) ) . "</h3>\n";
|
|
|
|
echo "<h3 class=\"subtitle\">" . $lang['recursive_delete_progress'] . "</h3>";
|
2009-06-30 08:05:37 +00:00
|
|
|
echo "<br /><br />";
|
|
|
|
echo "<small>\n";
|
2009-06-30 09:24:29 +00:00
|
|
|
|
2009-06-30 08:05:37 +00:00
|
|
|
flush();
|
|
|
|
|
|
|
|
// prevent script from bailing early on a long delete
|
|
|
|
@set_time_limit( 0 );
|
|
|
|
|
2009-06-30 09:24:29 +00:00
|
|
|
$del_result = pla_rdelete( $ldapserver, $dn );
|
2009-06-30 08:05:37 +00:00
|
|
|
echo "</small><br />\n";
|
2009-06-30 09:24:29 +00:00
|
|
|
|
|
|
|
if( $del_result ) {
|
2009-06-30 08:05:37 +00:00
|
|
|
// kill the DN from the tree browser session variable and
|
|
|
|
// refresh the tree viewer frame (left_frame)
|
|
|
|
|
2009-06-30 09:24:29 +00:00
|
|
|
if( array_key_exists( 'tree', $_SESSION ) ) {
|
2009-06-30 08:05:37 +00:00
|
|
|
$tree = $_SESSION['tree'];
|
|
|
|
|
2009-06-30 09:24:29 +00:00
|
|
|
// does it have children? (it shouldn't, but hey, you never know)
|
2009-06-30 08:05:37 +00:00
|
|
|
if( isset( $tree[$server_id][$dn] ) )
|
|
|
|
unset( $tree[$server_id][$dn] );
|
2009-06-30 09:24:29 +00:00
|
|
|
|
|
|
|
// Get a tree in the session if not already gotten
|
|
|
|
initialize_session_tree();
|
2009-06-30 09:22:30 +00:00
|
|
|
|
|
|
|
// search and destroy from the tree sesssion
|
2009-06-30 08:05:37 +00:00
|
|
|
foreach( $tree[$server_id] as $tree_dn => $subtree )
|
|
|
|
foreach( $subtree as $key => $sub_tree_dn )
|
2009-06-30 09:24:29 +00:00
|
|
|
if( 0 == strcasecmp( $sub_tree_dn, $dn ) )
|
2009-06-30 08:05:37 +00:00
|
|
|
unset( $tree[$server_id][$tree_dn][$key] );
|
|
|
|
}
|
|
|
|
|
|
|
|
$_SESSION['tree'] = $tree;
|
|
|
|
session_write_close();
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
<script language="javascript">
|
|
|
|
parent.left_frame.location.reload();
|
|
|
|
</script>
|
|
|
|
|
2009-06-30 09:24:29 +00:00
|
|
|
<?php
|
2009-06-30 08:05:37 +00:00
|
|
|
|
2009-06-30 09:22:30 +00:00
|
|
|
echo sprintf( $lang['entry_and_sub_tree_deleted_successfully'], '<b>' . htmlspecialchars( $dn ) . '</b>' );
|
2009-06-30 08:05:37 +00:00
|
|
|
|
|
|
|
} else {
|
2009-06-30 09:24:29 +00:00
|
|
|
pla_error( sprintf( $lang['could_not_delete_entry'], htmlspecialchars( $dn ) ), ldap_error( $ldapserver->connect() ), ldap_errno( $ldapserver->connect() ) );
|
2009-06-30 08:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exit;
|
|
|
|
|
2009-06-30 09:24:29 +00:00
|
|
|
function pla_rdelete( $ldapserver, $dn ) {
|
2009-06-30 09:22:30 +00:00
|
|
|
global $lang;
|
2009-06-30 09:24:29 +00:00
|
|
|
$children = get_container_contents( $ldapserver, $dn );
|
2009-06-30 08:05:37 +00:00
|
|
|
|
|
|
|
if( ! is_array( $children ) || count( $children ) == 0 ) {
|
2009-06-30 09:22:30 +00:00
|
|
|
echo "<nobr>" . sprintf( $lang['deleting_dn'], htmlspecialchars( $dn ) ) . "...";
|
2009-06-30 08:05:37 +00:00
|
|
|
flush();
|
2009-06-30 09:24:29 +00:00
|
|
|
|
|
|
|
if( true === run_hook ( 'pre_entry_delete', array ( 'server_id' => $ldapserver->server_id, 'dn' => $dn ) ) )
|
|
|
|
|
|
|
|
if( @ldap_delete( $ldapserver->connect(), $dn ) ) {
|
|
|
|
run_hook ( 'post_entry_delete',
|
|
|
|
array ( 'server_id' => $ldapserver->server_id, 'dn' => $dn ) );
|
|
|
|
echo " <span style=\"color:green\">" . $lang['success'] . "</span></nobr><br />\n";
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
pla_error( sprintf( $lang['failed_to_delete_entry'], htmlspecialchars( $dn ) ),
|
|
|
|
ldap_error( $ldapserver->connect() ), ldap_errno( $ldapserver->connect() ) );
|
|
|
|
}
|
2009-06-30 08:05:37 +00:00
|
|
|
} else {
|
|
|
|
foreach( $children as $child_dn ) {
|
2009-06-30 09:24:29 +00:00
|
|
|
pla_rdelete( $ldapserver, $child_dn );
|
2009-06-30 08:05:37 +00:00
|
|
|
}
|
2009-06-30 09:24:29 +00:00
|
|
|
|
2009-06-30 09:22:30 +00:00
|
|
|
echo "<nobr>" . sprintf( $lang['deleting_dn'], htmlspecialchars( $dn ) ) . "...";
|
2009-06-30 08:05:37 +00:00
|
|
|
flush();
|
|
|
|
|
2009-06-30 09:24:29 +00:00
|
|
|
if( true === run_hook ( 'pre_entry_delete', array ( 'server_id' => $ldapserver->server_id, 'dn' => $dn ) ) )
|
|
|
|
if( @ldap_delete( $ldapserver->connect(), $dn ) ) {
|
|
|
|
run_hook ( 'post_entry_delete',
|
|
|
|
array ( 'server_id' => $ldapserver->server_id, 'dn' => $dn ) );
|
|
|
|
|
|
|
|
echo " <span style=\"color:green\">" . $lang['success'] . "</span></nobr><br />\n";
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
pla_error( sprintf( $lang['failed_to_delete_entry'], htmlspecialchars( $dn ) ),
|
|
|
|
ldap_error( $ldapserver->connect() ), ldap_errno( $ldapserver->connect() ) );
|
|
|
|
}
|
|
|
|
}
|
2009-06-30 08:05:37 +00:00
|
|
|
}
|
2009-06-30 09:24:29 +00:00
|
|
|
?>
|