diff options
author | Jörn Friedrich Dreyer <jfd@butonic.de> | 2014-08-08 16:35:33 +0400 |
---|---|---|
committer | Jörn Friedrich Dreyer <jfd@butonic.de> | 2014-08-15 18:47:50 +0400 |
commit | 8f0d89a98663fa0d5ce889515a3a6c9dc5fd55d1 (patch) | |
tree | 592df9811663bf4f6e489ad50920fa0876060e38 | |
parent | 6d6dfe23297f24e4f97293137b9744036b02f5de (diff) |
check quota when trying to download a file via new -> web
-rw-r--r-- | apps/files/ajax/newfile.php | 39 | ||||
-rw-r--r-- | apps/files/lib/helper.php | 3 |
2 files changed, 39 insertions, 3 deletions
diff --git a/apps/files/ajax/newfile.php b/apps/files/ajax/newfile.php index c327d2b9f94..4943f8793af 100644 --- a/apps/files/ajax/newfile.php +++ b/apps/files/ajax/newfile.php @@ -82,9 +82,41 @@ if($source) { exit(); } + if (!ini_get('allow_url_fopen')) { + $eventSource->send('error', $l10n->t('Server is not allowed to open URLs, please check the server configuration')); + $eventSource->close(); + exit(); + } + $ctx = stream_context_create(null, array('notification' =>'progress')); - $sourceStream=fopen($source, 'rb', false, $ctx); - $result=\OC\Files\Filesystem::file_put_contents($target, $sourceStream); + $sourceStream=@fopen($source, 'rb', false, $ctx); + $result = 0; + if (is_resource($sourceStream)) { + $meta = stream_get_meta_data($sourceStream); + if (isset($meta['wrapper_data']) && is_array($meta['wrapper_data'])) { + //check stream size + $storageStats = \OCA\Files\Helper::buildFileStorageStatistics($dir); + $freeSpace = $storageStats['freeSpace']; + + foreach($meta['wrapper_data'] as $header) { + list($name, $value) = explode(':', $header); + if ('content-length' === strtolower(trim($name))) { + $length = (int) trim($value); + + if ($length > $freeSpace) { + $delta = $length - $freeSpace; + $humanDelta = OCP\Util::humanFileSize($delta); + + $eventSource->send('error', (string)$l10n->t('The file exceeds your quota by %s', array($humanDelta))); + $eventSource->close(); + fclose($sourceStream); + exit(); + } + } + } + } + $result=\OC\Files\Filesystem::file_put_contents($target, $sourceStream); + } if($result) { $meta = \OC\Files\Filesystem::getFileInfo($target); $mime=$meta['mimetype']; @@ -93,6 +125,9 @@ if($source) { } else { $eventSource->send('error', $l10n->t('Error while downloading %s to %s', array($source, $target))); } + if (is_resource($sourceStream)) { + fclose($sourceStream); + } $eventSource->close(); exit(); } else { diff --git a/apps/files/lib/helper.php b/apps/files/lib/helper.php index eaff28178ea..8c7f2d26ef0 100644 --- a/apps/files/lib/helper.php +++ b/apps/files/lib/helper.php @@ -15,7 +15,8 @@ class Helper return array('uploadMaxFilesize' => $maxUploadFilesize, 'maxHumanFilesize' => $maxHumanFilesize, - 'usedSpacePercent' => (int)$storageInfo['relative']); + 'usedSpacePercent' => (int)$storageInfo['relative'], + 'freeSpace' => (int)$storageInfo['free']); } public static function determineIcon($file) { |