From 200f92b1adf66472576f5d3593800397ee11dc34 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Wed, 17 May 2017 10:30:39 -0500 Subject: [PATCH] make zmexport not rely on symlinks in the webroot (#1888) * make zmexport not rely on symlinks in the webroot * add archive view --- .../lib/ZoneMinder/ConfigData.pm.in | 14 +++++ web/includes/config.php.in | 1 + .../classic/includes/export_functions.php | 11 ++-- web/views/archive.php | 62 +++++++++++++++++++ 4 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 web/views/archive.php diff --git a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in index 4a88de3be..0082707c6 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in +++ b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in @@ -505,6 +505,20 @@ our @options = ( type => $types{directory}, category => "paths", }, + { + name => "ZM_DIR_EXPORTS", + default => "@ZM_TMPDIR@", + description => "Directory where exported archives are stored", + help => qqq(" + This is the path to the exports directory where exported + tar.gz and zip archives are stored. By default this points to + ZoneMinder's temp folder, which often sits in ram. Since exported + archives can potentially become large, it is a good idea to move + this folder to some other location on machines with low memory. + "), + type => $types{directory}, + category => "paths", + }, { name => "ZM_PATH_ZMS", default => "/cgi-bin/nph-zms", diff --git a/web/includes/config.php.in b/web/includes/config.php.in index 801fa30cf..0af60b76a 100644 --- a/web/includes/config.php.in +++ b/web/includes/config.php.in @@ -24,6 +24,7 @@ define( "ZM_CONFIG", "@ZM_CONFIG@" ); // Path to config file // Define, and override any given in config file define( "ZM_VERSION", "@VERSION@" ); // Version +define( "ZM_DIR_TEMP", "@ZM_TMPDIR@" ); $configFile = ZM_CONFIG; $localConfigFile = basename($configFile); diff --git a/web/skins/classic/includes/export_functions.php b/web/skins/classic/includes/export_functions.php index 15f3e1720..d9dc4f9c8 100644 --- a/web/skins/classic/includes/export_functions.php +++ b/web/skins/classic/includes/export_functions.php @@ -890,7 +890,7 @@ function exportEvents( $eids, $exportDetail, $exportFrames, $exportImages, $expo { $eids = array($eids); } - $monitorPath = 'events/'; + $monitorPath = ZM_DIR_EVENTS."/"; $html_eventMaster = 'zmEventImagesMaster_'.date('Ymd_His'). '.html'; if ( !($fp = fopen( $monitorPath."/".$html_eventMaster, "w" )) ) Fatal( "Can't open event images export file '$html_eventMaster'" ); fwrite( $fp, exportEventImagesMaster( $eids ) ); @@ -898,7 +898,7 @@ function exportEvents( $eids, $exportDetail, $exportFrames, $exportImages, $expo $exportFileList[] = $monitorPath."/".$html_eventMaster; } - $listFile = "temp/".$export_listFile; + $listFile = ZM_DIR_EXPORTS."/".$export_listFile; if ( !($fp = fopen( $listFile, "w" )) ) { Fatal( "Can't open event export list file '$listFile'" ); @@ -911,7 +911,7 @@ function exportEvents( $eids, $exportDetail, $exportFrames, $exportImages, $expo $archive = ""; if ( $exportFormat == "tar" ) { - $archive = "temp/".$export_root.".tar.gz"; + $archive = ZM_DIR_EXPORTS."/".$export_root.".tar.gz"; @unlink( $archive ); $command = "tar --create --gzip --file=$archive --files-from=$listFile"; exec( escapeshellcmd( $command ), $output, $status ); @@ -925,8 +925,7 @@ function exportEvents( $eids, $exportDetail, $exportFrames, $exportImages, $expo } elseif ( $exportFormat == "zip" ) { - $archive = "temp/zm_export.zip"; - $archive = "temp/".$export_root.".zip"; + $archive = ZM_DIR_EXPORTS."/".$export_root.".zip"; @unlink( $archive ); $command = "cat ".escapeshellarg($listFile)." | zip -q ".escapeshellarg($archive)." -@"; //cat zmFileList.txt | zip -q zm_export.zip -@ @@ -948,7 +947,7 @@ function exportEvents( $eids, $exportDetail, $exportFrames, $exportImages, $expo } } - return( $archive ); + return( '?view=archive%26type='.$exportFormat ); } function mygetEventPath( $event ) { diff --git a/web/views/archive.php b/web/views/archive.php new file mode 100644 index 000000000..75f51448b --- /dev/null +++ b/web/views/archive.php @@ -0,0 +1,62 @@ + +