2004-09-26 09:48:58 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
$Id$
|
|
|
|
|
2009-10-27 18:47:12 +00:00
|
|
|
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
2012-02-05 10:38:59 +00:00
|
|
|
Copyright (C) 2004 - 2012 Roland Gruber
|
2004-09-26 09:48:58 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates LDAP accounts for file upload.
|
|
|
|
*
|
|
|
|
* @author Roland Gruber
|
|
|
|
* @package tools
|
|
|
|
*/
|
|
|
|
|
2006-03-26 17:51:25 +00:00
|
|
|
/** security functions */
|
|
|
|
include_once("../lib/security.inc");
|
2004-09-26 09:48:58 +00:00
|
|
|
/** access to configuration */
|
|
|
|
include_once('../lib/config.inc');
|
|
|
|
/** LDAP handle */
|
|
|
|
include_once('../lib/ldap.inc');
|
|
|
|
/** status messages */
|
|
|
|
include_once('../lib/status.inc');
|
|
|
|
/** account modules */
|
|
|
|
include_once('../lib/modules.inc');
|
2012-02-05 10:38:59 +00:00
|
|
|
/** PDF */
|
|
|
|
include_once('../lib/pdf.inc');
|
2004-09-26 09:48:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Start session
|
2006-03-26 17:51:25 +00:00
|
|
|
startSecureSession();
|
2004-09-26 09:48:58 +00:00
|
|
|
|
2007-12-30 13:15:39 +00:00
|
|
|
// die if no write access
|
|
|
|
if (!checkIfWriteAccessIsAllowed()) die();
|
|
|
|
|
2004-09-26 09:48:58 +00:00
|
|
|
// Redirect to startpage if user is not loged in
|
2008-05-15 17:32:59 +00:00
|
|
|
if (!isset($_SESSION['loggedIn']) || ($_SESSION['loggedIn'] !== true)) {
|
2004-09-26 09:48:58 +00:00
|
|
|
metaRefresh("login.php");
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set correct language, codepages, ....
|
|
|
|
setlanguage();
|
|
|
|
|
2010-01-01 17:21:46 +00:00
|
|
|
include 'main_header.php';
|
2011-02-13 11:46:52 +00:00
|
|
|
echo '<div class="' . $_SESSION['mass_scope'] . 'list-bright smallPaddingContent">';
|
2004-09-26 09:48:58 +00:00
|
|
|
|
|
|
|
// create accounts
|
|
|
|
$accounts = unserialize($_SESSION['ldap']->decrypt($_SESSION['mass_accounts']));
|
2012-02-05 10:38:59 +00:00
|
|
|
if (($_SESSION['mass_counter'] < sizeof($accounts)) || !isset($_SESSION['mass_postActions']['finished']) || !isset($_SESSION['mass_pdf']['finished'])) {
|
2004-09-26 09:48:58 +00:00
|
|
|
$startTime = time();
|
2005-07-19 12:19:50 +00:00
|
|
|
$maxTime = get_cfg_var('max_execution_time') - 5;
|
|
|
|
if ($maxTime > 60) $maxTime = 60;
|
2005-11-28 14:24:52 +00:00
|
|
|
if ($maxTime <= 0) $maxTime = 60;
|
2010-10-24 13:53:44 +00:00
|
|
|
echo "<div class=\"title\">\n";
|
|
|
|
echo "<h2 class=\"titleText\">" . _("LDAP upload in progress. Please wait.") . "</h2>\n";
|
|
|
|
echo "</div>";
|
2011-12-22 08:43:17 +00:00
|
|
|
$progress = ($_SESSION['mass_counter'] * 100) / sizeof($accounts);
|
|
|
|
?>
|
|
|
|
<div id="progressbarGeneral"></div>
|
|
|
|
<script type="text/javascript">
|
|
|
|
$(function() {
|
|
|
|
$( "#progressbarGeneral" ).progressbar({
|
|
|
|
value: <?php echo $progress; ?>
|
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
<?php
|
2004-09-26 09:48:58 +00:00
|
|
|
flush(); // send HTML to browser
|
2004-10-19 18:18:46 +00:00
|
|
|
// add accounts to LDAP
|
2005-07-19 12:19:50 +00:00
|
|
|
while (($_SESSION['mass_counter'] < sizeof($accounts)) && (($startTime + $maxTime) > time())) {
|
2004-09-26 09:48:58 +00:00
|
|
|
// create accounts as long as max_execution_time is not near
|
|
|
|
$attrs = $accounts[$_SESSION['mass_counter']];
|
|
|
|
$dn = $attrs['dn'];
|
|
|
|
unset($attrs['dn']);
|
2012-01-15 14:15:56 +00:00
|
|
|
// remove informational attributes
|
|
|
|
foreach ($attrs as $key => $value) {
|
|
|
|
if (strpos($key, 'INFO.') === 0) {
|
|
|
|
unset($attrs[$key]);
|
|
|
|
}
|
|
|
|
}
|
2007-07-08 10:51:01 +00:00
|
|
|
$success = @ldap_add($_SESSION['ldap']->server(), $dn, $attrs);
|
2004-09-26 09:48:58 +00:00
|
|
|
if (!$success) {
|
|
|
|
$errorMessage = array(
|
|
|
|
"ERROR",
|
|
|
|
_("LAM was unable to create account %s! An LDAP error occured."),
|
2007-07-08 10:51:01 +00:00
|
|
|
ldap_errno($_SESSION['ldap']->server()) . ": " . ldap_error($_SESSION['ldap']->server()),
|
2004-09-26 09:48:58 +00:00
|
|
|
array($_SESSION['mass_counter']));
|
|
|
|
$_SESSION['mass_errors'][] = $errorMessage;
|
2004-10-19 18:18:46 +00:00
|
|
|
$_SESSION['mass_failed'][] = $_SESSION['mass_counter'];
|
2004-09-26 09:48:58 +00:00
|
|
|
}
|
|
|
|
$_SESSION['mass_counter']++;
|
|
|
|
}
|
2011-12-22 08:43:17 +00:00
|
|
|
$progress = ($_SESSION['mass_counter'] * 100) / sizeof($accounts);
|
|
|
|
?>
|
|
|
|
<script type="text/javascript">
|
|
|
|
$(function() {
|
|
|
|
$( "#progressbarGeneral" ).progressbar({
|
|
|
|
value: <?php echo $progress; ?>
|
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
<?php
|
|
|
|
flush(); // send HTML to browser
|
2012-02-05 10:38:59 +00:00
|
|
|
// do post upload actions after all accounts are created
|
2004-10-19 18:18:46 +00:00
|
|
|
if ($_SESSION['mass_counter'] >= sizeof($accounts)) {
|
|
|
|
$data = unserialize($_SESSION['ldap']->decrypt($_SESSION['mass_data']));
|
2010-12-16 17:59:04 +00:00
|
|
|
$return = doUploadPostActions($_SESSION['mass_scope'], $data, $_SESSION['mass_ids'], $_SESSION['mass_failed'], $_SESSION['mass_selectedModules'], $accounts);
|
2004-10-19 18:18:46 +00:00
|
|
|
if ($return['status'] == 'finished') {
|
|
|
|
$_SESSION['mass_postActions']['finished'] = true;
|
|
|
|
}
|
|
|
|
for ($i = 0; $i < sizeof($return['errors']); $i++) $_SESSION['mass_errors'][] = $return['errors'][$i];
|
2006-11-28 19:45:30 +00:00
|
|
|
echo "<h1>" . _("Additional tasks for module:") . ' ' . getModuleAlias($return['module'], $_SESSION['mass_scope']) . "</h1>\n";
|
2011-12-22 08:43:17 +00:00
|
|
|
?>
|
|
|
|
<div id="progressbar<?php echo $return['module']; ?>"></div>
|
|
|
|
<script type="text/javascript">
|
|
|
|
$(function() {
|
|
|
|
$( "#progressbar<?php echo $return['module']; ?>" ).progressbar({
|
|
|
|
value: <?php echo $return['progress']; ?>
|
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
<?php
|
2004-10-19 18:18:46 +00:00
|
|
|
flush();
|
2005-07-19 12:19:50 +00:00
|
|
|
while (!isset($_SESSION['mass_postActions']['finished']) && (($startTime + $maxTime) > time())) {
|
2010-12-16 17:59:04 +00:00
|
|
|
$return = doUploadPostActions($_SESSION['mass_scope'], $data, $_SESSION['mass_ids'], $_SESSION['mass_failed'], $_SESSION['mass_selectedModules'], $accounts);
|
2004-10-19 18:18:46 +00:00
|
|
|
if ($return['status'] == 'finished') {
|
|
|
|
$_SESSION['mass_postActions']['finished'] = true;
|
|
|
|
}
|
2012-01-15 14:15:56 +00:00
|
|
|
if (isset($return['errors'])) {
|
|
|
|
for ($i = 0; $i < sizeof($return['errors']); $i++) {
|
|
|
|
$_SESSION['mass_errors'][] = $return['errors'][$i];
|
|
|
|
}
|
|
|
|
}
|
2004-10-19 18:18:46 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-05 10:38:59 +00:00
|
|
|
// create PDF when upload post actions are done
|
|
|
|
if (isset($_SESSION['mass_postActions']['finished'])) {
|
|
|
|
if (($_SESSION['mass_pdf']['structure'] != null) && !isset($_SESSION['mass_pdf']['finished'])) {
|
|
|
|
$file = $_SESSION['mass_pdf']['file'];
|
|
|
|
$pdfStructure = $_SESSION['mass_pdf']['structure'];
|
|
|
|
$pdfZip = new ZipArchive();
|
|
|
|
if ($_SESSION['mass_pdf']['counter'] == 0) {
|
|
|
|
$pdfZipResult = @$pdfZip->open($_SESSION['mass_pdf']['file'], ZipArchive::CREATE);
|
|
|
|
if (!$pdfZipResult === true) {
|
|
|
|
$_SESSION['mass_errors'][] = array('ERROR', _('Unable to create ZIP file for PDF export.'), $file);
|
|
|
|
$_SESSION['mass_pdf']['finished'] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
@$pdfZip->open($_SESSION['mass_pdf']['file']);
|
|
|
|
}
|
|
|
|
// show progress bar
|
|
|
|
$progress = ($_SESSION['mass_pdf']['counter'] * 100) / sizeof($accounts);
|
|
|
|
echo "<h1>" . _('Create PDF files') . "</h1>\n";
|
|
|
|
?>
|
|
|
|
<div id="progressbarPDF"></div>
|
|
|
|
<script type="text/javascript">
|
|
|
|
$(function() {
|
|
|
|
$( "#progressbarPDF" ).progressbar({
|
|
|
|
value: <?php echo $progress; ?>
|
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
<?php
|
|
|
|
flush();
|
|
|
|
while (!isset($_SESSION['mass_pdf']['finished']) && (($startTime + $maxTime) > time())) {
|
|
|
|
// load account
|
|
|
|
$attrs = $accounts[$_SESSION['mass_pdf']['counter']];
|
|
|
|
$dn = $attrs['dn'];
|
|
|
|
$_SESSION['pdfAccount'] = new accountContainer($_SESSION['mass_scope'], 'pdfAccount');
|
|
|
|
$pdfErrors = $_SESSION['pdfAccount']->load_account($dn);
|
|
|
|
if (sizeof($pdfErrors) > 0) {
|
|
|
|
$_SESSION['mass_errors'] = array_merge($_SESSION['mass_errors'], $pdfErrors);
|
|
|
|
$_SESSION['mass_pdf']['finished'] = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// create and save PDF
|
|
|
|
$pdfContent = createModulePDF(array($_SESSION['pdfAccount']), $pdfStructure, true);
|
|
|
|
$pdfZip->addFromString($dn, $pdfContent);
|
|
|
|
$_SESSION['mass_pdf']['counter'] ++;
|
|
|
|
if ($_SESSION['mass_pdf']['counter'] >= sizeof($accounts)) {
|
|
|
|
$_SESSION['mass_pdf']['finished'] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@$pdfZip->close();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$_SESSION['mass_pdf']['finished'] = true;
|
|
|
|
}
|
|
|
|
}
|
2010-01-17 20:36:25 +00:00
|
|
|
// refresh with JavaScript
|
|
|
|
echo "<script type=\"text/javascript\">\n";
|
|
|
|
echo "top.location.href = \"massDoUpload.php\";\n";
|
|
|
|
echo "</script>\n";
|
2004-09-26 09:48:58 +00:00
|
|
|
}
|
|
|
|
// all accounts have been created
|
|
|
|
else {
|
2010-10-24 13:53:44 +00:00
|
|
|
echo "<div class=\"title\">\n";
|
2010-11-28 13:41:44 +00:00
|
|
|
echo "<h2 class=\"titleText\">" . _("Upload has finished") . "</h2>\n";
|
2010-10-24 13:53:44 +00:00
|
|
|
echo "</div>";
|
2004-09-26 09:48:58 +00:00
|
|
|
if (sizeof($_SESSION['mass_errors']) > 0) {
|
2010-10-24 13:53:44 +00:00
|
|
|
echo "<div class=\"subTitle\">\n";
|
|
|
|
echo "<h4 class=\"subTitleText\">" . _("There were errors while uploading:") . "</h4>\n";
|
|
|
|
echo "</div>";
|
2004-09-26 09:48:58 +00:00
|
|
|
for ($i = 0; $i < sizeof($_SESSION['mass_errors']); $i++) {
|
|
|
|
call_user_func_array('StatusMessage', $_SESSION['mass_errors'][$i]);
|
2010-10-24 13:53:44 +00:00
|
|
|
echo "<br>";
|
2004-09-26 09:48:58 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-28 13:41:44 +00:00
|
|
|
else {
|
|
|
|
// redirect to list if no errors occured
|
|
|
|
echo "<script type=\"text/javascript\">\n";
|
|
|
|
echo "top.location.href = \"lists/list.php?type=" . $_SESSION['mass_scope'] . "&uploadAllOk\";\n";
|
|
|
|
echo "</script>\n";
|
|
|
|
}
|
2004-09-26 09:48:58 +00:00
|
|
|
}
|
2010-10-24 13:53:44 +00:00
|
|
|
echo '</div>';
|
|
|
|
include 'main_footer.php';
|
2004-09-26 09:48:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
?>
|