check if selected files for zip archive are not too large
offer config option
This commit is contained in:
parent
cfc41942e4
commit
a77edf88c6
|
@ -28,13 +28,20 @@ require_once('../lib/base.php');
|
||||||
OC_Util::checkAdminUser();
|
OC_Util::checkAdminUser();
|
||||||
|
|
||||||
$htaccessWorking=(getenv('htaccessWorking')=='true');
|
$htaccessWorking=(getenv('htaccessWorking')=='true');
|
||||||
if(isset($_POST['maxUploadSize'])){
|
if($_POST) {
|
||||||
$maxUploadFilesize=$_POST['maxUploadSize'];
|
if(isset($_POST['maxUploadSize'])){
|
||||||
OC_Files::setUploadLimit(OC_Helper::computerFileSize($maxUploadFilesize));
|
$maxUploadFilesize=$_POST['maxUploadSize'];
|
||||||
|
OC_Files::setUploadLimit(OC_Helper::computerFileSize($maxUploadFilesize));
|
||||||
|
}
|
||||||
|
if(isset($_POST['maxZipInputSize'])) {
|
||||||
|
$maxZipInputSize=$_POST['maxZipInputSize'];
|
||||||
|
OC_Preferences::setValue('', 'files', 'maxZipInputSize', OC_Helper::computerFileSize($maxZipInputSize));
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
$upload_max_filesize = OC_Helper::computerFileSize(ini_get('upload_max_filesize'));
|
$upload_max_filesize = OC_Helper::computerFileSize(ini_get('upload_max_filesize'));
|
||||||
$post_max_size = OC_Helper::computerFileSize(ini_get('post_max_size'));
|
$post_max_size = OC_Helper::computerFileSize(ini_get('post_max_size'));
|
||||||
$maxUploadFilesize = min($upload_max_filesize, $post_max_size);
|
$maxUploadFilesize = min($upload_max_filesize, $post_max_size);
|
||||||
|
$maxZipInputSize = OC_Helper::humanfilesize(OC_Preferences::getValue('', 'files', 'maxZipInputSize', OC_Helper::computerFileSize('800 MB')));
|
||||||
}
|
}
|
||||||
|
|
||||||
OC_App::setActiveNavigationEntry( "files_administration" );
|
OC_App::setActiveNavigationEntry( "files_administration" );
|
||||||
|
@ -42,6 +49,5 @@ OC_App::setActiveNavigationEntry( "files_administration" );
|
||||||
$tmpl = new OC_Template( 'files', 'admin' );
|
$tmpl = new OC_Template( 'files', 'admin' );
|
||||||
$tmpl->assign( 'htaccessWorking', $htaccessWorking );
|
$tmpl->assign( 'htaccessWorking', $htaccessWorking );
|
||||||
$tmpl->assign( 'uploadMaxFilesize', $maxUploadFilesize);
|
$tmpl->assign( 'uploadMaxFilesize', $maxUploadFilesize);
|
||||||
return $tmpl->fetchPage();
|
$tmpl->assign( 'maxZipInputSize', $maxZipInputSize);
|
||||||
|
return $tmpl->fetchPage();
|
||||||
?>
|
|
|
@ -3,11 +3,10 @@
|
||||||
<form name="filesForm" action='#' method='post'>
|
<form name="filesForm" action='#' method='post'>
|
||||||
<fieldset class="personalblock">
|
<fieldset class="personalblock">
|
||||||
<legend><strong><?php echo $l->t('File handling');?></strong></legend>
|
<legend><strong><?php echo $l->t('File handling');?></strong></legend>
|
||||||
<?php if($_['htaccessWorking']):?>
|
<?php if($_['htaccessWorking']):?>
|
||||||
<label for="maxUploadSize"><?php echo $l->t( 'Maximum upload size' ); ?> </label><input name='maxUploadSize' id="maxUploadSize" value='<?php echo $_['uploadMaxFilesize'] ?>'/><br/>
|
<label for="maxUploadSize"><?php echo $l->t( 'Maximum upload size' ); ?> </label><input name='maxUploadSize' id="maxUploadSize" value='<?php echo $_['uploadMaxFilesize'] ?>'/><br/>
|
||||||
<input type='submit' value='Save'/>
|
<?php endif;?>
|
||||||
<?php else:?>
|
<label for="maxZipInputSize"><?php echo $l->t( 'Maximum input size for zip files (affects folder- and multi-file download)' ); ?> </label><input name="maxZipInputSize" id="maxZipInputSize" value='<?php echo $_['maxZipInputSize'] ?>'/><br/>
|
||||||
No settings currently available.
|
<input type="submit" value="Save"/>
|
||||||
<?php endif;?>
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -59,6 +59,9 @@ class OC_Files {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_array($files)){
|
if(is_array($files)){
|
||||||
|
self::checkZipInputSize($dir,$files);
|
||||||
|
$executionTime = intval(ini_get('max_execution_time'));
|
||||||
|
set_time_limit(0);
|
||||||
$zip = new ZipArchive();
|
$zip = new ZipArchive();
|
||||||
$filename = get_temp_dir()."/ownCloud.zip";
|
$filename = get_temp_dir()."/ownCloud.zip";
|
||||||
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
|
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
|
||||||
|
@ -75,7 +78,11 @@ class OC_Files {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$zip->close();
|
$zip->close();
|
||||||
|
set_time_limit($executionTime);
|
||||||
}elseif(OC_Filesystem::is_dir($dir.'/'.$files)){
|
}elseif(OC_Filesystem::is_dir($dir.'/'.$files)){
|
||||||
|
self::checkZipInputSize($dir,$files);
|
||||||
|
$executionTime = intval(ini_get('max_execution_time'));
|
||||||
|
set_time_limit(0);
|
||||||
$zip = new ZipArchive();
|
$zip = new ZipArchive();
|
||||||
$filename = get_temp_dir()."/ownCloud.zip";
|
$filename = get_temp_dir()."/ownCloud.zip";
|
||||||
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
|
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
|
||||||
|
@ -84,6 +91,7 @@ class OC_Files {
|
||||||
$file=$dir.'/'.$files;
|
$file=$dir.'/'.$files;
|
||||||
self::zipAddDir($file,$zip);
|
self::zipAddDir($file,$zip);
|
||||||
$zip->close();
|
$zip->close();
|
||||||
|
set_time_limit($executionTime);
|
||||||
}else{
|
}else{
|
||||||
$zip=false;
|
$zip=false;
|
||||||
$filename=$dir.'/'.$files;
|
$filename=$dir.'/'.$files;
|
||||||
|
@ -209,6 +217,40 @@ class OC_Files {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* checks if the selected files are within the size constraint. If not, outputs an error page.
|
||||||
|
*
|
||||||
|
* @param dir $dir
|
||||||
|
* @param files $files
|
||||||
|
*/
|
||||||
|
static function checkZipInputSize($dir, $files) {
|
||||||
|
$zipLimit = OC_Preferences::getValue('', 'files', 'maxZipInputSize', OC_Helper::computerFileSize('800 MB'));
|
||||||
|
if($zipLimit > 0) {
|
||||||
|
$totalsize = 0;
|
||||||
|
if(is_array($files)){
|
||||||
|
foreach($files as $file){
|
||||||
|
$totalsize += OC_Filesystem::filesize($dir.'/'.$file);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$totalsize += OC_Filesystem::filesize($dir.'/'.$files);
|
||||||
|
}
|
||||||
|
if($totalsize > $zipLimit) {
|
||||||
|
$l = new OC_L10N('files');
|
||||||
|
header("HTTP/1.0 409 Conflict");
|
||||||
|
$tmpl = new OC_Template( '', 'error', 'user' );
|
||||||
|
$errors = array(
|
||||||
|
array(
|
||||||
|
'error' => $l->t('Selected files too large to generate zip file.'),
|
||||||
|
'hint' => 'Download the files in smaller chunks, seperately or kindly ask your administrator.<br/><a href="javascript:history.back()">' . $l->t('Back to Files') . '</a>',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$tmpl->assign('errors', $errors);
|
||||||
|
$tmpl->printPage();
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* try to detect the mime type of a file
|
* try to detect the mime type of a file
|
||||||
*
|
*
|
||||||
|
@ -256,7 +298,7 @@ class OC_Files {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set the maximum upload size limit for apache hosts using .htaccess
|
* set the maximum upload size limit for apache hosts using .htaccess
|
||||||
* @param int size filesisze in bytes
|
* @param int size filesisze in bytes
|
||||||
|
|
Loading…
Reference in New Issue