2009-06-30 09:22:30 +00:00
|
|
|
<?php
|
2009-06-30 09:29:51 +00:00
|
|
|
// $Header: /cvsroot/phpldapadmin/phpldapadmin/ldif_import.php,v 1.31 2005/08/16 09:02:50 wurley Exp $
|
2009-06-30 09:22:30 +00:00
|
|
|
|
2009-06-30 09:29:51 +00:00
|
|
|
/**
|
2009-06-30 08:07:14 +00:00
|
|
|
* Imports an LDIF file to the specified server_id.
|
|
|
|
*
|
|
|
|
* Variables that come in as POST vars:
|
|
|
|
* - ldif_file (as an uploaded file)
|
|
|
|
* - server_id
|
2009-06-30 09:29:51 +00:00
|
|
|
*
|
|
|
|
* @package phpLDAPadmin
|
|
|
|
*/
|
|
|
|
/**
|
2009-06-30 08:07:14 +00:00
|
|
|
*/
|
|
|
|
|
2009-06-30 09:22:30 +00:00
|
|
|
require './common.php';
|
2009-06-30 08:07:14 +00:00
|
|
|
|
|
|
|
$debug = true;
|
|
|
|
|
2009-06-30 09:29:51 +00:00
|
|
|
$server_id = (isset($_POST['server_id']) ? $_POST['server_id'] : '');
|
|
|
|
$ldapserver = $ldapservers->Instance($server_id);
|
|
|
|
|
|
|
|
if( ! $ldapserver->haveAuthInfo())
|
|
|
|
pla_error( $lang['not_enough_login_info'] );
|
|
|
|
|
2009-06-30 09:22:30 +00:00
|
|
|
$continuous_mode = isset( $_POST['continuous_mode'] ) ?1:0;
|
2009-06-30 08:07:14 +00:00
|
|
|
$file = $_FILES['ldif_file']['tmp_name'];
|
|
|
|
$remote_file = $_FILES['ldif_file']['name'];
|
|
|
|
$file_len = $_FILES['ldif_file']['size'];
|
|
|
|
|
2009-06-30 09:22:30 +00:00
|
|
|
is_array( $_FILES['ldif_file'] ) or pla_error( $lang['missing_uploaded_file'] );
|
|
|
|
file_exists( $file ) or pla_error( $lang['no_ldif_file_specified'] );
|
|
|
|
$file_len > 0 or pla_error( $lang['ldif_file_empty'] );
|
2009-06-30 08:07:14 +00:00
|
|
|
|
2009-06-30 09:22:30 +00:00
|
|
|
include './header.php'; ?>
|
2009-06-30 08:07:14 +00:00
|
|
|
|
|
|
|
<body>
|
|
|
|
|
2009-06-30 09:22:30 +00:00
|
|
|
<h3 class="title"><?php echo $lang['import_ldif_file_title']; ?></h3>
|
2009-06-30 08:07:14 +00:00
|
|
|
<h3 class="subtitle">
|
2009-06-30 09:29:51 +00:00
|
|
|
<?php echo $lang['server']; ?>: <b><?php echo htmlspecialchars( $ldapserver->name ); ?></b>
|
2009-06-30 09:22:30 +00:00
|
|
|
<?php echo $lang['file']; ?>: <b><?php echo htmlspecialchars( $remote_file ); ?>
|
|
|
|
(<?php echo sprintf( $lang['number_bytes'], number_format( $file_len ) ); ?>)</b>
|
2009-06-30 08:07:14 +00:00
|
|
|
</h3>
|
|
|
|
|
|
|
|
<br />
|
|
|
|
<br />
|
|
|
|
|
|
|
|
<?php
|
|
|
|
include("ldif_functions.php");
|
|
|
|
@set_time_limit( 0 );
|
|
|
|
|
2009-06-30 08:09:20 +00:00
|
|
|
// String associated to the operation on the ldap server
|
|
|
|
$actionString = array();
|
|
|
|
$actionString['add'] = $lang['add_action'];
|
|
|
|
$actionString['delete'] = $lang['delete_action'];
|
|
|
|
$actionString['modrdn'] = $lang['rename_action'];
|
|
|
|
$actionString['moddn'] = $lang['rename_action'];
|
|
|
|
$actionString['modify'] = $lang['modify_action'];
|
|
|
|
|
|
|
|
|
|
|
|
// String associated with error
|
|
|
|
$actionErrorMsg =array();
|
|
|
|
$actionErrorMsg['add'] = $lang['ldif_could_not_add_object'];
|
|
|
|
$actionErrorMsg['delete']= $lang['ldif_could_not_delete_object'];
|
|
|
|
$actionErrorMsg['modrdn']= $lang['ldif_could_not_rename_object'];
|
|
|
|
$actionErrorMsg['moddn']= $lang['ldif_could_not_rename_object'];
|
|
|
|
$actionErrorMsg['modify']= $lang['ldif_could_not_modify_object'];
|
|
|
|
|
|
|
|
// get the connection
|
2009-06-30 09:29:51 +00:00
|
|
|
//$ds = pla_ldap_connect( $server_id );
|
|
|
|
//pla_ldap_connection_is_error( $ds );
|
2009-06-30 08:09:20 +00:00
|
|
|
|
|
|
|
//instantiate the reader
|
2009-06-30 09:22:30 +00:00
|
|
|
$ldifReader = new LdifReader($file,$continuous_mode);
|
2009-06-30 08:09:20 +00:00
|
|
|
|
|
|
|
//instantiate the writer
|
2009-06-30 09:29:51 +00:00
|
|
|
$ldapWriter = new LdapWriter($ldapserver->connect());
|
2009-06-30 08:09:20 +00:00
|
|
|
|
|
|
|
// if ldif file has no version number, just display a warning
|
|
|
|
if(!$ldifReader->hasVersionNumber()){
|
|
|
|
display_warning($ldifReader->getWarningMessage());
|
2009-06-30 08:07:14 +00:00
|
|
|
}
|
2009-06-30 09:22:30 +00:00
|
|
|
$i=0;
|
|
|
|
// if .. else not mandatory but should be easier to maintain
|
|
|
|
if( $continuous_mode ){
|
|
|
|
while( $ldifReader->readEntry() ){
|
|
|
|
$i++;
|
|
|
|
// get the entry.
|
2009-06-30 09:29:51 +00:00
|
|
|
$currentEntry = $ldifReader->fetchEntryObject();
|
2009-06-30 09:22:30 +00:00
|
|
|
$changeType = $currentEntry->getChangeType();
|
|
|
|
echo "<small>".$actionString[$changeType]." ".$currentEntry->dn;
|
|
|
|
|
|
|
|
if($ldifReader->hasRaisedException()){
|
|
|
|
echo " <span style=\"color:red;\">".$lang['failed']."</span></small><br>";
|
|
|
|
$exception = $ldifReader->getLdapLdifReaderException();
|
|
|
|
echo "<small><span style=\"color:red;\">".$lang['ldif_line_number'].": ".$exception->lineNumber."</span></small><br />";
|
|
|
|
echo "<small><span style=\"color:red;\">".$lang['ldif_line'].": ".$exception->currentLine."</span></small><br />";
|
|
|
|
echo "<small><span style=\"color:red;\">".$lang['desc'].": ".$exception->message."</span></small><br />";
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
if($ldapWriter->ldapModify($currentEntry))
|
|
|
|
echo " <span style=\"color:green;\">".$lang['success']."</span></small><br>";
|
|
|
|
else{
|
|
|
|
echo " <span style=\"color:red;\">".$lang['failed']."</span></small><br>";
|
2009-06-30 09:29:51 +00:00
|
|
|
echo "<small><span style=\"color:red;\">Error Code: ".ldap_errno($ldapserver->connect())."</span></small><br />";
|
|
|
|
echo "<small><span style=\"color:red;\">".$lang['desc'].": ".ldap_error($ldapserver->connect())."</span></small><br />";
|
2009-06-30 09:22:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if( 0 == $i % 5 )
|
|
|
|
flush();
|
|
|
|
}// end while
|
|
|
|
}
|
|
|
|
else{
|
2009-06-30 08:09:20 +00:00
|
|
|
//while we have a valid entry,
|
|
|
|
while($entry = $ldifReader->readEntry()){
|
2009-06-30 09:22:30 +00:00
|
|
|
$i++;
|
2009-06-30 08:09:20 +00:00
|
|
|
$changeType = $entry->getChangeType();
|
|
|
|
|
|
|
|
echo "<small>".$actionString[$changeType]." ".$entry->dn;
|
|
|
|
if($ldapWriter->ldapModify($entry)){
|
|
|
|
echo " <span style=\"color:green;\">".$lang['success']."</span></small><br>";
|
2009-06-30 09:22:30 +00:00
|
|
|
if( 0 == $i % 5 )
|
2009-06-30 08:09:20 +00:00
|
|
|
flush();
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
echo " <span style=\"color:red;\">".$lang['failed']."</span></small><br><br>";
|
|
|
|
reload_left_frame();
|
2009-06-30 09:29:51 +00:00
|
|
|
pla_error( $actionErrorMsg[$changeType]. " " . htmlspecialchars( $entry->dn ), ldap_error( $ldapserver->connect() ), ldap_errno( $ldapserver->connect() ) );
|
2009-06-30 08:09:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if any errors occurs during reading file ,"catch" the exception and display it here.
|
|
|
|
if($ldifReader->hasRaisedException()){
|
|
|
|
//get the entry which raise the exception,quick hack here
|
2009-06-30 09:29:51 +00:00
|
|
|
$currentEntry = $ldifReader->fetchEntryObject();
|
2009-06-30 08:09:20 +00:00
|
|
|
|
|
|
|
if($currentEntry->dn !=""){
|
|
|
|
echo "<small>".$actionString[$currentEntry->getChangeType()]." ".$currentEntry->dn." <span style=\"color:red;\">".$lang['failed']."</span></small><br>";
|
|
|
|
}
|
|
|
|
//get the exception wich was raised
|
|
|
|
$exception = $ldifReader->getLdapLdifReaderException();
|
|
|
|
echo "<br />";
|
|
|
|
echo "<br />";
|
|
|
|
display_pla_parse_error($exception,$currentEntry);
|
|
|
|
}
|
2009-06-30 09:22:30 +00:00
|
|
|
}
|
|
|
|
// close the file
|
|
|
|
$ldifReader->done();
|
|
|
|
|
|
|
|
//close the ldap connection
|
|
|
|
$ldapWriter->ldapClose();
|
2009-06-30 08:07:14 +00:00
|
|
|
|
|
|
|
reload_left_frame();
|
|
|
|
|
|
|
|
|
|
|
|
function reload_left_frame(){
|
|
|
|
global $server_id;
|
|
|
|
|
|
|
|
echo "<script>\r\n";
|
|
|
|
echo "parent.left_frame.document.location='refresh.php?server_id=".$server_id."';\r\n";
|
|
|
|
echo "</script>\r\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
function display_error_message($error_message){
|
2009-06-30 08:09:20 +00:00
|
|
|
echo "<div style=\"color:red;\"><small>".$error_message."</small></div>";
|
2009-06-30 08:07:14 +00:00
|
|
|
}
|
|
|
|
function display_warning($warning){
|
2009-06-30 08:09:20 +00:00
|
|
|
echo "<div style=\"color:orange\"><small>".$warning."</small></div>";
|
2009-06-30 08:07:14 +00:00
|
|
|
}
|
|
|
|
|
2009-06-30 08:09:20 +00:00
|
|
|
function display_pla_parse_error($exception,$faultyEntry){
|
|
|
|
global $lang;
|
|
|
|
global $actionErrorMsg;
|
|
|
|
$errorMessage = $actionErrorMsg[$faultyEntry->getChangeType()];
|
|
|
|
|
|
|
|
print("<center>");
|
|
|
|
print("<table class=\"error\"><tr><td class=\"img\"><img src=\"images/warning.png\" /></td>");
|
|
|
|
print("<td><center><h2>".$lang['ldif_parse_error']."</h2></center>");
|
|
|
|
print("<br />");
|
|
|
|
print($errorMessage." ". $faultyEntry->dn);
|
|
|
|
print("<p>");
|
|
|
|
print("<b>".$lang['desc']."</b>: ".$exception->message);
|
|
|
|
print("</p>");
|
|
|
|
print("<p>");
|
|
|
|
print("<b>".$lang['ldif_line']."</b>: ".$exception->currentLine);
|
|
|
|
print("</p>");
|
|
|
|
print("<p>");
|
|
|
|
print("<b>".$lang['ldif_line_number']."</b>: ".$exception->lineNumber);
|
|
|
|
print("</p>");
|
|
|
|
print("<br />");
|
|
|
|
print("<p>\r\n");
|
|
|
|
print("<center>");
|
|
|
|
print("<small>");
|
|
|
|
print(sprintf($lang['ferror_submit_bug'] , get_href( 'add_bug' )));
|
|
|
|
|
|
|
|
print("</small></center></p>");
|
|
|
|
print("<td>");
|
|
|
|
print("</tr>");
|
|
|
|
print("<center>");
|
2009-06-30 08:07:14 +00:00
|
|
|
|
2009-06-30 08:09:20 +00:00
|
|
|
}
|
2009-06-30 08:07:14 +00:00
|
|
|
|
2009-06-30 08:09:20 +00:00
|
|
|
?>
|
2009-06-30 08:07:14 +00:00
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|
|
|
|
|