From 8f0d89a98663fa0d5ce889515a3a6c9dc5fd55d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 8 Aug 2014 14:35:33 +0200 Subject: check quota when trying to download a file via new -> web --- apps/files/ajax/newfile.php | 39 +++++++++++++++++++++++++++++++++++++-- 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) { -- cgit v1.2.3