Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions web/ajax/event.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,22 @@
}
ajaxResponse();
break;
case 'file_existence_check' :
$fileNameArray = $_REQUEST['file_name_array'] ?? [];
if (!is_array($fileNameArray)) ajaxError('The "file_name_array" request parameter is not an array');
if (count($fileNameArray) > 100) ajaxError('Too many files requested');
$result = [];
foreach ($fileNameArray as $fileName) {
if (!is_string($fileName) || $fileName === '' || strlen($fileName) > 4096 || strpos($fileName, "\0") !== false) continue;

// Only allow relative paths under DIR_EXPORTS_DOWNLOAD; reject traversal/absolute paths.
$fileName = ltrim($fileName, "/\\");
if (preg_match('#(^|[\\/])\.\.([\\/]|$)#', $fileName)) continue;
$path = DIR_EXPORTS_DOWNLOAD . DIRECTORY_SEPARATOR . str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $fileName);
$result[] = [$fileName, file_exists($path)];
}
ajaxResponse(array('response'=>$result));
break;
Comment thread
IgorA100 marked this conversation as resolved.
Comment thread
IgorA100 marked this conversation as resolved.
}
} // end if canView('Events')

Expand Down
10 changes: 10 additions & 0 deletions web/skins/classic/css/base/views/events.css
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,19 @@ body.sticky #eventTable thead {
.bs-bars {
width: 100%;
}

#toolbar .row {
width: 100%;
}

#toolbar .row >div {
padding: 0;
}

#downloadModal a.disabled {
pointer-events: none;
background-color: inherit;
border-color: inherit;
opacity: 0.5;
text-decoration: line-through;
}
Comment thread
IgorA100 marked this conversation as resolved.
93 changes: 87 additions & 6 deletions web/skins/classic/js/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* This file contains UI functions relating to export / download modals
*
*/
var fileExistencePollingInterval = null;

function startDownload(exportFile) {
console.log("Starting download from " + exportFile);
Expand All @@ -20,6 +21,7 @@ function exportResponse(data, responseText) {
if (generated) {
let fileForAutoDownload = [];
const exportFile = data.exportFile; // NOW THIS IS a real array of links
const downloadLink = $j('#downloadLink');
if (exportFile instanceof Array) {
let nodeCopy;
fileForAutoDownload = [...exportFile];
Expand All @@ -29,23 +31,26 @@ function exportResponse(data, responseText) {

if (i==0) {
if (exportFile.length == 1) {
$j('#downloadLink').text('Download ' + '"' + fileName + '"');
downloadLink.text('Download ' + '"' + fileName + '"');
} else {
$j('#downloadLink').text((i+1) + '. Download ' + '"' + fileName + '"');
downloadLink.text((i+1) + '. Download ' + '"' + fileName + '"');
}
$j('#downloadLink').attr("href", thisUrl + file);
downloadLink.attr("href", thisUrl + file);
downloadLink.removeClass('disabled').removeAttr('aria-disabled tabindex');
} else {
const downloadLink = document.getElementById('downloadLink'+(i-1)) || document.getElementById('downloadLink'); // Links must be in sequential order.
nodeCopy = downloadLink.cloneNode(true);
nodeCopy.id = 'downloadLink'+i;
downloadLink.parentNode.insertBefore(nodeCopy, downloadLink.nextSibling);
$j(nodeCopy).html('<br>' + (i+1) + '. Download ' + '"' + fileName + '"');
nodeCopy.before(document.createElement('br'));
$j(nodeCopy).text((i+1) + '. Download ' + '"' + fileName + '"');
$j(nodeCopy).attr("href", thisUrl + file);
}
}
} else {
$j('#downloadLink').text('Download ' + '"' + getFileNameFromURL(exportFile) + '"');
$j('#downloadLink').attr("href", thisUrl + exportFile);
downloadLink.removeClass('disabled').removeAttr('aria-disabled tabindex');
downloadLink.text('Download ' + '"' + getFileNameFromURL(exportFile) + '"');
downloadLink.attr("href", thisUrl + exportFile);
fileForAutoDownload = [exportFile];
}

Expand All @@ -54,12 +59,88 @@ function exportResponse(data, responseText) {
for (let i=0, length = fileForAutoDownload.length; i < length; i++) {
setTimeout(startDownload, 1500+(i*500), fileForAutoDownload[i]); // This is an automatic download link.
}

const filenamePathArray = [];
for (let i = 0; i < fileForAutoDownload.length; i++) {
// Let's create an array of filename path
const params = new URLSearchParams(fileForAutoDownload[i]);
const exportRoot = (params.has('export_root')) ? params.get('export_root') : '';
const filename = (params.has('file')) ? params.get('file') : '';
const filenamePath = (exportRoot) ? exportRoot + '/' + filename : filename;

filenamePathArray.push(filenamePath);
Comment thread
IgorA100 marked this conversation as resolved.
}

if (fileExistencePollingInterval) clearInterval(fileExistencePollingInterval);
let existenceCheckInFlight = false;
fileExistencePollingInterval = setInterval(() => {
Comment thread
IgorA100 marked this conversation as resolved.
if (existenceCheckInFlight) return;
existenceCheckInFlight = true;
$j.ajax({
type: 'GET',
url: thisUrl,
dataType: 'json',
data: {
'view': 'request',
'request': 'event',
'action': 'file_existence_check',
'file_name_array': filenamePathArray
},
success: checkedResponse,
timeout: 0,
complete: function() {
existenceCheckInFlight = false;
},
error: function(jqXHR, status, errorThrown) {
logAjaxFail(jqXHR, status, errorThrown);
$j('#exportProgress').html('Failed: ' + errorThrown);
clearInterval(fileExistencePollingInterval);
fileExistencePollingInterval = null;
}
Comment thread
IgorA100 marked this conversation as resolved.
});
}, 3000);
Comment thread
IgorA100 marked this conversation as resolved.
} else {
$j('#exportProgress').addClass( 'text-danger' );
$j('#exportProgress').text(exportFailedString);
}
}

function checkedResponse(data, responseText) {
const downloadModal = document.getElementById('downloadModal');
if (!downloadModal) {
console.log("Modal window for files download is missing.");
clearInterval(fileExistencePollingInterval);
return;
}
let filesExist = false;
if (data.result == "Error") {
console.warn(data, responseText);
} else if (data.result == "Ok") {
let nodeList = {};
if (downloadModal) nodeList = downloadModal.querySelectorAll("[id^=downloadLink]");
for (let i = 0; i < data.response.length; i++) {
if (data.response[i][1] === false) {
nodeList.forEach(function(el) {
const params = new URL(el.href).searchParams;
const exportRoot = params.get('export_root') || '';
const file = params.get('file') || '';
const relPath = exportRoot ? (exportRoot + '/' + file) : file;
if (relPath === data.response[i][0]) {
el.classList.add('disabled');
Comment thread
IgorA100 marked this conversation as resolved.
el.setAttribute('aria-disabled', 'true');
el.setAttribute('tabindex', '-1');
}
});
} else {
filesExist = true;
}
}
}
if (data.result == "Error" || !filesExist || !(downloadModal.offsetWidth > 0 && downloadModal.offsetHeight > 0)) {
clearInterval(fileExistencePollingInterval);
}
}

function exportEvent() {
$j('#exportProgress').html('<span class="spinner-grow" role="status" aria-hidden="true"></span>Exporting...');
$j('#exportProgress').removeClass( 'text-success text-danger text-warning' );
Expand Down
Loading