From 2273deaf17bbd34f1ff81b5fb4d5b8eeb73efc51 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 5 Aug 2021 13:28:13 -0400 Subject: [PATCH] Support specifying the export filename by passing the export_root --- web/ajax/event.php | 4 ++- .../classic/includes/export_functions.php | 34 +++++++++++-------- web/views/archive.php | 4 ++- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/web/ajax/event.php b/web/ajax/event.php index 1456bd192..9b7f86e03 100644 --- a/web/ajax/event.php +++ b/web/ajax/event.php @@ -86,7 +86,9 @@ if ( canView('Events') ) { $exportVideo, $exportMisc, $exportFormat, - $exportCompress + $exportCompress, + false, # structure + (isset($_REQUEST['exportFile'])?$_REQUEST['exportFile']:''), ) ) ajaxResponse(array('exportFile'=>$exportFile)); else diff --git a/web/skins/classic/includes/export_functions.php b/web/skins/classic/includes/export_functions.php index 0a1fd97b4..bc6bba1ed 100644 --- a/web/skins/classic/includes/export_functions.php +++ b/web/skins/classic/includes/export_functions.php @@ -869,7 +869,8 @@ function exportEvents( $exportMisc, $exportFormat, $exportCompressed, - $exportStructure = false + $exportStructure = false, + $export_root = 'zmExport' ) { if ( !canView('Events') ) { @@ -890,7 +891,7 @@ function exportEvents( ZM\Fatal('Can\'t create exports dir at \''.ZM_DIR_EXPORTS.'\''); } chmod(ZM_DIR_EXPORTS, 0700); - $export_dir = ZM_DIR_EXPORTS.'/zmExport_'.$connkey; + $export_dir = ZM_DIR_EXPORTS.'/'.$export_root.($connkey?'_'.$connkey:''); # Ensure that we are going to be able to do this. if ( ! ( mkdir($export_dir) or file_exists($export_dir) ) ) { @@ -904,7 +905,6 @@ function exportEvents( return; } - $export_root = 'zmExport'; $export_listFile = 'zmFileList.txt'; $exportFileList = array(); $html_eventMaster = ''; @@ -930,7 +930,7 @@ function exportEvents( } # end foreach event if ( !symlink(ZM_PATH_WEB.'/'.ZM_SKIN_PATH.'/js/jquery.min.js', $export_dir.'/jquery.min.js') ) - ZM\Error('Failed linking jquery.min.js'); + ZM\Error('Failed linking '.ZM_PATH_WEB.'/'.ZM_SKIN_PATH.'/js/jquery.min.js to '.$export_dir.'/jquery.min.js'); //if ( !symlink(ZM_PATH_WEB.'/'.ZM_SKIN_PATH.'/js/video.js', $export_dir.'/video.js') ) //Error("Failed linking video.js"); @@ -947,19 +947,21 @@ function exportEvents( $listFile = $export_dir.'/'.$export_listFile; if ( !($fp = fopen($listFile, 'w')) ) { - ZM\Fatal("Can't open event export list file '$listFile'"); + ZM\Error("Can't open event export list file '$listFile'"); + return false; } foreach ( $exportFileList as $exportFile ) { - $exportFile = 'zmExport'.$connkey.'/'.$exportFile; - fwrite($fp, "$exportFile\n"); + $exportFile = $export_root.$connkey.'/'.$exportFile; + fwrite($fp, $exportFile.PHP_EOL); } - fwrite($fp, "$listFile\n"); + fwrite($fp, $listFile.PHP_EOL); fclose($fp); chdir(ZM_DIR_EXPORTS); $archive = ''; if ( $exportFormat == 'tar' ) { - $archive = ZM_DIR_EXPORTS.'/'.$export_root.($connkey?'_'.$connkey:'').'.tar'; + + $archive = $export_root.($connkey?'_'.$connkey:'').'.tar'; $version = shell_exec('tar -v'); $command = 'tar --create --dereference'; @@ -975,16 +977,18 @@ function exportEvents( $command .= ' --xform=\'s#^.+/##x\''; } } - $command .= ' --file='.escapeshellarg($archive); + $archive_path = ZM_DIR_EXPORTS.'/'.$archive; + $command .= ' --file='.escapeshellarg($archive_path); } elseif ( $exportFormat == 'zip' ) { - $archive = ZM_DIR_EXPORTS.'/'.$export_root.($connkey?'_'.$connkey:'').'.zip'; + $archive = $export_root.($connkey?'_'.$connkey:'').'.zip'; + $archive_path = ZM_DIR_EXPORTS.'/'.$archive; $command = 'zip '; - $command .= ($exportStructure == 'flat' ? ' -j ' : ' -r ' ).escapeshellarg($archive); + $command .= ($exportStructure == 'flat' ? ' -j ' : ' -r ' ).escapeshellarg($archive_path); $command .= $exportCompressed ? ' -9' : ' -0'; } // if $exportFormat - @unlink($archive); - $command .= ' zmExport_' . $connkey.'/'; + @unlink($archive_path); + $command .= ' '.$export_root.($connkey?'_'.$connkey:'').'/'; exec($command, $output, $status); if ( $status ) { ZM\Error("Command '$command' returned with status $status"); @@ -999,5 +1003,5 @@ function exportEvents( unlink($monitorPath.'/'.$html_eventMaster); } - return '?view=archive&type='.$exportFormat.'&connkey='.$connkey; + return '?view=archive&type='.$exportFormat.'&connkey='.$connkey.'&file='.$archive; } // end function exportEvents diff --git a/web/views/archive.php b/web/views/archive.php index 6bd11fbd3..223b31a61 100644 --- a/web/views/archive.php +++ b/web/views/archive.php @@ -53,7 +53,9 @@ if ( !$mimetype ) { } $connkey = isset($_REQUEST['connkey'])?$_REQUEST['connkey']:''; -$filename = "zmExport_$connkey.$file_ext"; +$filename = isset($_REQUEST['file'])?$_REQUEST['file']:"zmExport_$connkey.$file_ext"; +$filename = str_replace('/', '', $filename); # protect system files. must be a filename, not a path + $filename_path = ZM_DIR_EXPORTS.'/'.$filename; ZM\Debug("downloading archive from $filename_path"); if ( is_readable($filename_path) ) {