[Pkg-owncloud-commits] [owncloud] 01/03: check quota when trying to download a file via new -> web
David Prévot
taffit at moszumanska.debian.org
Fri Aug 29 15:24:14 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to annotated tag v6.0.5
in repository owncloud.
commit 8f0d89a98663fa0d5ce889515a3a6c9dc5fd55d1
Author: Jörn Friedrich Dreyer <jfd at butonic.de>
Date: Fri Aug 8 14:35:33 2014 +0200
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 c327d2b..4943f87 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 eaff281..8c7f2d2 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) {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list