2009-06-30 08:05:37 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* rdelete.php
|
|
|
|
*
|
|
|
|
* Recursively deletes the specified DN and all of its children
|
|
|
|
* Variables that come in as POST vars:
|
|
|
|
* - dn (rawurlencoded)
|
|
|
|
* - server_id
|
|
|
|
*/
|
|
|
|
|
2009-06-30 08:09:20 +00:00
|
|
|
require realpath( 'common.php' );
|
2009-06-30 08:05:37 +00:00
|
|
|
|
2009-06-30 08:09:20 +00:00
|
|
|
$dn = $_POST['dn'];
|
|
|
|
$encoded_dn = rawurlencode( $dn );
|
2009-06-30 08:05:37 +00:00
|
|
|
$server_id = $_POST['server_id'];
|
|
|
|
|
|
|
|
if( ! $dn )
|
|
|
|
pla_error( "You must specify a DN." );
|
|
|
|
|
2009-06-30 08:07:14 +00:00
|
|
|
if( is_server_read_only( $server_id ) )
|
|
|
|
pla_error( "You cannot perform updates while server is in read-only mode" );
|
|
|
|
|
2009-06-30 08:05:37 +00:00
|
|
|
check_server_id( $server_id ) or pla_error( "Bad server_id: " . htmlspecialchars( $server_id ) );
|
|
|
|
have_auth_info( $server_id ) or pla_error( "Not enough information to login to server. Please check your configuration." );
|
|
|
|
pla_ldap_connect( $server_id ) or pla_error( "Could not connect to LDAP server" );
|
|
|
|
|
|
|
|
session_start();
|
|
|
|
include 'header.php';
|
|
|
|
echo "<body>\n";
|
|
|
|
echo "<h3 class=\"title\">Deleting" . htmlspecialchars( $dn) . "</h3>\n";
|
|
|
|
echo "<h3 class=\"subtitle\">Recursive delete progress</h3>\n";
|
|
|
|
echo "<br /><br />";
|
|
|
|
echo "<small>\n";
|
|
|
|
flush();
|
|
|
|
|
|
|
|
// prevent script from bailing early on a long delete
|
|
|
|
@set_time_limit( 0 );
|
|
|
|
|
|
|
|
$del_result = pla_rdelete( $server_id, $dn );
|
|
|
|
echo "</small><br />\n";
|
|
|
|
if( $del_result )
|
|
|
|
{
|
|
|
|
// kill the DN from the tree browser session variable and
|
|
|
|
// refresh the tree viewer frame (left_frame)
|
|
|
|
|
|
|
|
if( session_is_registered( 'tree' ) )
|
|
|
|
{
|
|
|
|
$tree = $_SESSION['tree'];
|
|
|
|
|
|
|
|
// does it have children? (it shouldn't, but hey, you never know)
|
|
|
|
if( isset( $tree[$server_id][$dn] ) )
|
|
|
|
unset( $tree[$server_id][$dn] );
|
|
|
|
|
|
|
|
// search and destroy
|
|
|
|
foreach( $tree[$server_id] as $tree_dn => $subtree )
|
|
|
|
foreach( $subtree as $key => $sub_tree_dn )
|
|
|
|
if( 0 == strcasecmp( $sub_tree_dn, $dn ) )
|
|
|
|
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 08:07:14 +00:00
|
|
|
Object <b><?php echo htmlspecialchars( $dn ); ?></b> and sub-tree deleted successfully.
|
2009-06-30 08:05:37 +00:00
|
|
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
2009-06-30 08:09:20 +00:00
|
|
|
pla_error( "Could not delete the object: " . htmlspecialchars( $dn ), ldap_error( $ds ), ldap_errno( $ds ) );
|
2009-06-30 08:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
exit;
|
|
|
|
|
|
|
|
|
|
|
|
function pla_rdelete( $server_id, $dn )
|
|
|
|
{
|
|
|
|
$children = get_container_contents( $server_id, $dn );
|
|
|
|
global $ds;
|
|
|
|
$ds = pla_ldap_connect( $server_id );
|
|
|
|
|
|
|
|
if( ! is_array( $children ) || count( $children ) == 0 ) {
|
2009-06-30 08:07:14 +00:00
|
|
|
echo "<nobr>Deleting " . htmlspecialchars( $dn ) . "...";
|
2009-06-30 08:05:37 +00:00
|
|
|
flush();
|
2009-06-30 08:09:20 +00:00
|
|
|
if( true === preEntryDelete( $server_id, $dn ) )
|
|
|
|
if( @ldap_delete( $ds, $dn ) ) {
|
|
|
|
postEntryDelete( $server_id, $dn );
|
|
|
|
echo " <span style=\"color:green\">Success</span></nobr><br />\n";
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
pla_error( "Failed to delete dn: " . htmlspecialchars( $dn ),
|
|
|
|
ldap_error( $ds ), ldap_errno( $ds ) );
|
|
|
|
}
|
2009-06-30 08:05:37 +00:00
|
|
|
} else {
|
|
|
|
foreach( $children as $child_dn ) {
|
|
|
|
pla_rdelete( $server_id, $child_dn );
|
|
|
|
}
|
2009-06-30 08:07:14 +00:00
|
|
|
echo "<nobr>Deleting " . htmlspecialchars( $dn ) . "...";
|
2009-06-30 08:05:37 +00:00
|
|
|
flush();
|
2009-06-30 08:09:20 +00:00
|
|
|
if( true === preEntryDelete( $server_id, $dn ) )
|
|
|
|
if( @ldap_delete( $ds, $dn ) ) {
|
|
|
|
postEntryDelete( $server_id, $dn );
|
|
|
|
echo " <span style=\"color:green\">Success</span></nobr><br />\n";
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
pla_error( "Failed to delete dn: " . htmlspecialchars( ( $dn ) ),
|
|
|
|
ldap_error( $ds ), ldap_errno( $ds ) );
|
|
|
|
}
|
2009-06-30 08:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|