RELEASE 1.1.0

This commit is contained in:
Deon George
2009-06-30 20:46:00 +10:00
parent a08bc4e9e1
commit dd581eb5c8
191 changed files with 25012 additions and 10177 deletions

View File

@@ -1,13 +1,13 @@
<?php
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/copy.php,v 1.43 2007/03/18 01:30:33 wurley Exp $
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/copy.php,v 1.44 2007/12/15 07:50:30 wurley Exp $
/**
* Copies a given object to create a new one.
*
* Vars that come in as POST vars
* - source_dn (rawurlencoded)
* - new_dn (form element)
* - server_id
* - source_dn (rawurlencoded)
* - new_dn (form element)
* - server_id
*
* @package phpLDAPadmin
*/
@@ -16,118 +16,111 @@
require './common.php';
$server_id_src = (isset($_POST['server_id']) ? $_POST['server_id'] : '');
$server_id_dst = (isset($_POST['dest_server_id']) ? $_POST['dest_server_id'] : '');
if (! $_SESSION['plaConfig']->isCommandAvailable('entry_move'))
pla_error(sprintf('%s%s %s',_('This operation is not permitted by the configuration'),_(':'),_('copy entry')));
$ldapserver_src = $ldapservers->Instance($server_id_src);
$ldapserver_dst = $ldapservers->Instance($server_id_dst);
$entry['src']['id'] = get_request('server_id');
$entry['dst']['id'] = get_request('dest_server_id');
if ($ldapserver_dst->isReadOnly())
$entry['src']['ldapserver'] = $_SESSION['plaConfig']->ldapservers->Instance($entry['src']['id']);
$entry['dst']['ldapserver'] = $_SESSION['plaConfig']->ldapservers->Instance($entry['dst']['id']);
if ($entry['dst']['ldapserver']->isReadOnly())
pla_error(_('Destination server is currently READ-ONLY.'));
if (! $ldapserver_src->haveAuthInfo() || ! $ldapserver_dst->haveAuthInfo())
if (! $entry['src']['ldapserver']->haveAuthInfo() || ! $entry['dst']['ldapserver']->haveAuthInfo())
pla_error(_('Not enough information to login to server. Please check your configuration.'));
$dn_src = $_POST['old_dn'];
$dn_dst = $_POST['new_dn'];
$do_recursive = (isset($_POST['recursive']) && $_POST['recursive'] == 'on') ? true : false;
$do_remove = (isset($_POST['remove']) && $_POST['remove'] == 'yes') ? true : false;
include './header.php';
$entry['src']['dn'] = get_request('old_dn');
$entry['dst']['dn'] = get_request('new_dn');
$entry['src']['recursive'] = (get_request('recursive') == 'on') ? true : false;
$entry['src']['remove'] = (get_request('remove') == 'yes') ? true : false;
# Error checking
if (0 == strlen(trim($dn_dst)))
if (strlen(trim($entry['dst']['dn'])) == 0)
pla_error(_('You left the destination DN blank.'));
if (pla_compare_dns($dn_src,$dn_dst) == 0 && $server_id_src == $server_id_dst)
if (pla_compare_dns($entry['src']['dn'],$entry['dst']['dn']) == 0 && $entry['src']['id'] == $entry['dst']['id'])
pla_error(_('The source and destination DN are the same.'));
if ($ldapserver_dst->dnExists($dn_dst))
pla_error(sprintf(_('The destination entry (%s) already exists.'),pretty_print_dn($dn_dst)));
if ($entry['dst']['ldapserver']->dnExists($entry['dst']['dn']))
pla_error(sprintf(_('The destination entry (%s) already exists.'),pretty_print_dn($entry['dst']['dn'])));
if (! $ldapserver_dst->dnExists(get_container($dn_dst)))
pla_error(sprintf(_('The destination container (%s) does not exist.'),pretty_print_dn(get_container($dn_dst))));
if (! $entry['dst']['ldapserver']->dnExists(get_container($entry['dst']['dn'])))
pla_error(sprintf(_('The destination container (%s) does not exist.'),pretty_print_dn(get_container($entry['dst']['dn']))));
if ($do_recursive) {
if ($entry['src']['recursive']) {
$filter = isset($_POST['filter']) ? $_POST['filter'] : '(objectClass=*)';
# Build a tree similar to that of the tree browser to give to r_copy_dn
$snapshot_tree = array();
print '<body>';
printf('<h3 class="title">%s%s</h3>',_('Copying '),htmlspecialchars($dn_src));
printf('<h3 class="title">%s%s</h3>',_('Copying '),htmlspecialchars($entry['src']['dn']));
printf('<h3 class="subtitle">%s</h3>',_('Recursive copy progress'));
print '<br /><br />';
print '<small>';
print _('Building snapshot of tree to copy... ');
flush();
$snapshot_tree = build_tree($ldapserver_src,$dn_src,array(),$filter);
$snapshot_tree = build_tree($entry['src']['ldapserver'],$entry['src']['dn'],array(),$filter);
printf('<span style="color:green">%s</span><br />',_('Success'));
flush();
# Prevent script from bailing early on a long delete
@set_time_limit(0);
$copy_result = r_copy_dn($ldapserver_src,$ldapserver_dst,$snapshot_tree,$dn_src,$dn_dst);
$copy_result = r_copy_dn($entry['src']['ldapserver'],$entry['dst']['ldapserver'],$snapshot_tree,$entry['src']['dn'],$entry['dst']['dn']);
# @todo: This is not showing the complete results - only the children of the dst - need to look at.
$copy_message = $copy_result;
print '</small>';
} else {
$copy_result = copy_dn($ldapserver_src,$ldapserver_dst,$dn_src,$dn_dst);
$copy_result = copy_dn($entry['src']['ldapserver'],$entry['dst']['ldapserver'],$entry['src']['dn'],$entry['dst']['dn']);
$copy_message = sprintf('%s DN%s <b>%s</b> %s',_('Copy successful!'),_(':'),htmlspecialchars($entry['dst']['dn']),_('has been created.'));
}
if ($copy_result) {
$edit_url = sprintf('template_engine.php?server_id=%s&amp;dn=%s',$server_id_dst,rawurlencode($dn_dst));
$new_rdn = get_rdn($dn_dst);
$container = get_container($dn_dst);
$redirect_url = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s',$entry['dst']['id'],rawurlencode($entry['dst']['dn']));
$new_rdn = get_rdn($entry['dst']['dn']);
$container = get_container($entry['dst']['dn']);
printf('<center>%s<a href="%s">%s</a></center>',_('Copy successful! Would you like to '),$edit_url,_('view the new entry'));
echo '<!-- refresh the tree view (with the new DN renamed) and redirect to the edit_dn page -->';
echo '<script type="text/javascript" language="javascript">parent.left_frame.location.reload();</script>';
echo '</body></html>';
if ($entry['src']['remove'])
$redirect_url = sprintf('cmd.php?cmd=delete_form&server_id=%s&dn=%s',$entry['src']['id'],rawurlencode($entry['src']['dn']));
if ($do_remove) {
sleep(2);
$delete_url = sprintf('delete_form.php?server_id=%s&dn=%s',$server_id_src,rawurlencode($dn_src));
echo '<!-- redirect to the delete form -->';
printf('<script type="text/javascript" language="javascript">parent.right_frame.location="%s" </script>',$delete_url);
}
system_message(array(
'title'=>_('Copy Entry'),
'body'=>$copy_message,
'type'=>'info'),
$redirect_url);
}
function r_copy_dn($ldapserver_src,$ldapserver_dst,$snapshottree,$root_dn,$dn_dst) {
if (DEBUG_ENABLED)
debug_log('r_copy_dn: Entered with (%s,%s,%s,%s,%s)',1,
if (DEBUG_ENABLED)
debug_log('Entered with (%s,%s,%s,%s,%s)',1,__FILE__,__LINE__,__METHOD__,
$ldapserver_src->server_id,$ldapserver_dst->server_id,$snapshottree,$root_dn,$dn_dst);
printf('<span style="white-space: nowrap;">%s %s...',_('Copying'),htmlspecialchars($root_dn));
flush();
$copy_message = array();
$copy_result = copy_dn($ldapserver_src,$ldapserver_dst,$root_dn,$dn_dst);
if (! $copy_result)
return false;
printf('<span style="color:green">%s</span><br />',_('Success'));
flush();
$copy_message[] = sprintf('%s DN: <b>%s</b> %s',_('Copy successful!'),htmlspecialchars($dn_dst),_('has been created.'));
$children = isset($snapshottree[$root_dn]) ? $snapshottree[$root_dn] : null;
if (is_array($children) && count($children) > 0) {
foreach($children as $child_dn) {
$child_rdn = get_rdn($child_dn);
$new_dest_dn = sprintf('%s,%s',$child_rdn,$dn_dst);
r_copy_dn($ldapserver_src,$ldapserver_dst,$snapshottree,$child_dn,$new_dest_dn);
$copy_result = r_copy_dn($ldapserver_src,$ldapserver_dst,$snapshottree,$child_dn,$new_dest_dn);
$copy_message[] = array_shift($copy_result);
}
} else {
return true;
}
return true;
return $copy_message;
}
function copy_dn($ldapserver_src,$ldapserver_dst,$dn_src,$dn_dst) {
if (DEBUG_ENABLED)
debug_log('copy_dn: Entered with (%s,%s,%s,%s)',17,
if (DEBUG_ENABLED)
debug_log('Entered with (%s,%s,%s,%s)',17,__FILE__,__LINE__,__METHOD__,
$ldapserver_src->server_id,$ldapserver_dst->server_id,$dn_src,$dn_dst);
$new_entry = $ldapserver_src->getDNAttrs($dn_src);
@@ -147,11 +140,11 @@ function copy_dn($ldapserver_src,$ldapserver_dst,$dn_src,$dn_dst) {
$add_result = $ldapserver_dst->add($dn_dst,$new_entry);
if (! $add_result) {
run_hook('post_entry_create',
array('server_id'=>$ldapserver_dst->server_id,'dn'=>$dn_dst,'attrs'=>$new_entry));
echo '</small><br /><br />';
pla_error(_('Failed to copy DN: ').$dn_dst,$ldapserver_dst->error(),$ldapserver_dst->errno());
} else {
run_hook('post_entry_create',
array('server_id'=>$ldapserver_dst->server_id,'dn'=>$dn_dst,'attrs'=>$new_entry));
}
return $add_result;
@@ -169,7 +162,7 @@ function copy_dn($ldapserver_src,$ldapserver_dst,$dn_src,$dn_dst) {
*/
function build_tree($ldapserver,$dn,$buildtree) {
if (DEBUG_ENABLED)
debug_log('build_tree: Entered with (%s,%s,%s)',1,
debug_log('Entered with (%s,%s,%s)',1,__FILE__,__LINE__,__METHOD__,
$ldapserver->server_id,$dn,$buildtree);
# we search all children, not only the visible children in the tree
@@ -182,7 +175,7 @@ function build_tree($ldapserver,$dn,$buildtree) {
}
if (DEBUG_ENABLED)
debug_log('build_tree: Returning (%s)',1,$buildtree);
debug_log('Returning (%s)',1,__FILE__,__LINE__,__METHOD__,$buildtree);
return $buildtree;
}