haveAuthInfo()) pla_error(_('Not enough information to login to server. Please check your configuration.')); $continuous_mode = isset($_POST['continuous_mode']) ? 1 : 0; if (isset($_REQUEST['ldif']) && trim($_REQUEST['ldif'])) { $textarealdif = $_REQUEST['ldif']; $remote_file = 'STDIN'; $file_len = strlen($textarealdif); } elseif (isset($_FILES['ldif_file'])) { $file = $_FILES['ldif_file']['tmp_name']; $remote_file = $_FILES['ldif_file']['name']; $file_len = $_FILES['ldif_file']['size']; is_array($_FILES['ldif_file']) or pla_error(_('Missing uploaded file.')); file_exists($file) or pla_error(_('No LDIF file specified. Please try again.')); $file_len > 0 or pla_error(_('Uploaded LDIF file is empty.')); } else { pla_error(_('You must either upload a file or provide an LDIF in the text box.')); } include './header.php'; echo ''; printf('

%s

',_('Import LDIF File')); printf('

%s: %s %s: %s (%s %s)

', _('Server'),htmlspecialchars($ldapserver->name), _('File'),htmlspecialchars($remote_file),number_format($file_len),_('bytes')); echo '

'; require LIBDIR.'ldif_functions.php'; @set_time_limit(0); # String associated to the operation on the ldap server $actionString = array(); $actionString['add'] = _('Adding...'); $actionString['delete'] = _('Deleting...'); $actionString['modrdn'] = _('Renaming...'); $actionString['moddn'] = _('Renaming...'); $actionString['modify'] = _('Modifying...'); # String associated with error $actionErrorMsg =array(); $actionErrorMsg['add'] = _('Could not add object:'); $actionErrorMsg['delete']= _('Could not delete object:'); $actionErrorMsg['modrdn']= _('Could not rename object:'); $actionErrorMsg['moddn']= _('Could not rename object:'); $actionErrorMsg['modify']= _('Could not modify object:'); # instantiate the reader if (isset($textarealdif)) $ldifReader = new LdifReaderStdIn($textarealdif,$continuous_mode); else $ldifReader = new LdifReader($file,$continuous_mode); # instantiate the writer $ldapWriter = new LdapWriter($ldapserver); # if ldif file has no version number, just display a warning if (!$ldifReader->hasVersionNumber()) display_warning($ldifReader->getWarningMessage()); $i=0; # if .. else not mandatory but should be easier to maintain if ($continuous_mode) { while ($ldifReader->readEntry()) { $i++; # get the entry. $currentEntry = $ldifReader->fetchEntryObject(); $edit_href = sprintf('template_engine.php?server_id=%s&dn=%s',$ldapserver->server_id, rawurlencode($currentEntry->dn)); $changeType = $currentEntry->getChangeType(); printf('%s %s',$actionString[$changeType],$edit_href,$entry->dn); if ($ldifReader->hasRaisedException()) { printf(' %s
',_('Failed')); $exception = $ldifReader->getLdapLdifReaderException(); printf(' %s: %s
', _('Line Number'),$exception->lineNumber); printf(' %s: %s
', _('Line'),$exception->currentLine); printf(' %s: %s
', _('Description'),$exception->message); } else { if ($ldapWriter->ldapModify($currentEntry)) printf(' %s
',_('Success')); else { printf('%s
',_('Failed')); printf('%s: %s
', _('Error code'),$ldapserver->errno()); printf('%s: %s
', _('Description'),$ldapserver->error()); } } if ($i % 5 == 0) flush(); } # end while } else { # while we have a valid entry, while ($entry = $ldifReader->readEntry()) { $i++; $edit_href = sprintf('template_engine.php?server_id=%s&dn=%s',$ldapserver->server_id, rawurlencode($entry->dn)); $changeType = $entry->getChangeType(); printf('%s %s',$actionString[$changeType],$edit_href,$entry->dn); if ($ldapWriter->ldapModify($entry)) { printf(' %s
',_('Success')); if ($i % 5 == 0) flush(); } else { printf(' %s

',_('Failed')); reload_left_frame(); pla_error($actionErrorMsg[$changeType].' '.htmlspecialchars($entry->dn), $ldapserver->error(),$ldapserver->errno()); } } # 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 $currentEntry = $ldifReader->fetchEntryObject(); if ($currentEntry->dn != '') { printf('%s %s %s
', $actionString[$currentEntry->getChangeType()],$currentEntry->dn,_('Failed')); } # get the exception wich was raised $exception = $ldifReader->getLdapLdifReaderException(); echo '

'; display_pla_parse_error($exception,$currentEntry); } } # close the file $ldifReader->done(); reload_left_frame(); function reload_left_frame(){ echo ''; } function display_error_message($error_message){ printf('
%s
',$error_message); } function display_warning($warning){ printf('
%s
',$warning); } function display_pla_parse_error($exception,$faultyEntry){ global $actionErrorMsg; $errorMessage = $actionErrorMsg[$faultyEntry->getChangeType()]; echo '
'; echo ''; echo ''; echo ''; echo '
'; } echo ''; ?>
'; printf('

%s

',_('LDIF Parse Error')); echo '
'; printf('%s %s',$errorMessage,$faultyEntry->dn); printf('

%s: %s

',_('Description'),$exception->message); printf('

%s: %s

',_('Line'),$exception->currentLine); printf('

%s: %s

',_('Line Number'),$exception->lineNumber); echo '
'; printf('

%s %s

', _('Is this a phpLDAPadmin bug?'),sprintf(_('If so, please report it.'),get_href('add_bug'))); echo '