mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-11-30 12:14:36 -05:00
* fix: name exports after their owner and refuse downloads of other users' exports refs #7462 * fix: prefix exportEvents archives with the owner prefix so archive.php serves them refs #7462 * test: cover exportEvents to archive.php ownership round trip refs #7462
90 lines
2.8 KiB
PHP
90 lines
2.8 KiB
PHP
<?php
|
|
//
|
|
// ZoneMinder file view file
|
|
// Copyright (C) 2001-2008 Philip Coombes
|
|
//
|
|
// 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
//
|
|
|
|
require_once('includes/download_functions.php');
|
|
|
|
if (!(canView('Events') or canView('Snapshots'))) {
|
|
$view = 'error';
|
|
return;
|
|
}
|
|
|
|
$archivetype = isset($_REQUEST['type']) ? $_REQUEST['type'] : '';
|
|
if ( !$archivetype ) {
|
|
ZM\Error('No archive type given to archive.php. Please specify a tar or zip archive.');
|
|
return;
|
|
}
|
|
|
|
switch ($archivetype) {
|
|
case 'tar.gz':
|
|
$mimetype = 'application/gzip';
|
|
$file_ext = 'tar.gz';
|
|
break;
|
|
case 'tar':
|
|
$mimetype = 'application/x-tar';
|
|
$file_ext = 'tar';
|
|
break;
|
|
case 'zip':
|
|
$mimetype = 'application/zip';
|
|
$file_ext = 'zip';
|
|
break;
|
|
default:
|
|
$mimetype = NULL;
|
|
$file_ext = NULL;
|
|
}
|
|
|
|
if ( !$mimetype ) {
|
|
ZM\Error('Unsupported archive type specified. Supported archives are tar and zip');
|
|
return;
|
|
}
|
|
|
|
$connkey = isset($_REQUEST['connkey'])?$_REQUEST['connkey']:'';
|
|
# Must be a single path component, not a path. Stripping only '/' left '..'
|
|
# intact (GHSA-fvx4-86xp-9v22).
|
|
$filename = isset($_REQUEST['file']) ? safeExportComponent($_REQUEST['file']) : '';
|
|
if ($filename === '') $filename = exportOwnerPrefix()."zmExport_$connkey.$file_ext";
|
|
|
|
if (!exportNameBelongsToUser($filename)) {
|
|
ZM\Warning('Refusing an archive that does not belong to the requesting user.');
|
|
return;
|
|
}
|
|
|
|
$filename_path = ZM_DIR_EXPORTS.'/'.$filename;
|
|
ZM\Debug('downloading archive from '.$filename_path);
|
|
if ( is_readable($filename_path) and pathWithinExportDir($filename_path, ZM_DIR_EXPORTS) ) {
|
|
while (ob_get_level()) {
|
|
ob_end_clean();
|
|
}
|
|
header("Content-type: $mimetype");
|
|
header('Content-Disposition: '.contentDispositionAttachment($filename));
|
|
header('Content-Length: '.filesize($filename_path));
|
|
set_time_limit(0);
|
|
# A client that disconnects mid-download aborts the script, so delete in a
|
|
# shutdown function to keep the archive from being left behind.
|
|
register_shutdown_function(function() use ($filename_path) {
|
|
@unlink($filename_path);
|
|
});
|
|
if ( !@readfile($filename_path) ) {
|
|
ZM\Error("Error sending $filename_path");
|
|
}
|
|
} else {
|
|
ZM\Error($filename_path.' does not exist or is not readable.');
|
|
}
|
|
?>
|