summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/app.php33
-rw-r--r--lib/private/avatar.php4
-rw-r--r--lib/private/cache/file.php18
-rw-r--r--lib/private/connector/sabre/auth.php6
-rw-r--r--lib/private/connector/sabre/directory.php2
-rw-r--r--lib/private/connector/sabre/exception/entitytoolarge.php22
-rw-r--r--lib/private/connector/sabre/exception/unsupportedmediatype.php22
-rw-r--r--lib/private/connector/sabre/file.php67
-rw-r--r--lib/private/filechunking.php23
-rw-r--r--lib/private/files/view.php3
-rw-r--r--lib/private/helper.php4
-rw-r--r--lib/private/log/owncloud.php6
-rw-r--r--lib/private/user.php2
13 files changed, 178 insertions, 34 deletions
diff --git a/lib/private/app.php b/lib/private/app.php
index b4a71992178..1a242ad968e 100644
--- a/lib/private/app.php
+++ b/lib/private/app.php
@@ -752,10 +752,43 @@ class OC_App{
} else {
$combinedApps = $appList;
}
+ // bring the apps into the right order with a custom sort funtion
+ usort( $combinedApps, '\OC_App::customSort' );
+
return $combinedApps;
}
/**
+ * @brief: Internal custom sort funtion to bring the app into the right order. Should only be called by listAllApps
+ * @return array
+ */
+ private static function customSort($a, $b) {
+
+ // prio 1: active
+ if ($a['active'] != $b['active']) {
+ return $b['active'] - $a['active'];
+ }
+
+ // prio 2: shipped
+ if ($a['shipped'] != $b['shipped']) {
+ $atemp = ($a['shipped'] == true ? 1 : 0);
+ $btemp = ($b['shipped'] == true ? 1 : 0);
+ return ($btemp - $atemp);
+ }
+
+ // prio 3: recommended
+ if ($a['internalclass'] != $b['internalclass']) {
+ $atemp = ($a['internalclass'] == 'recommendedapp' ? 1 : 0);
+ $btemp = ($b['internalclass'] == 'recommendedapp' ? 1 : 0);
+ return ($btemp - $atemp);
+ }
+
+ // prio 4: alphabetical
+ return strcasecmp($a['name'], $b['name']);
+
+ }
+
+ /**
* @brief: get a list of all apps on apps.owncloud.com
* @return array, multi-dimensional array of apps.
* Keys: id, name, type, typename, personid, license, detailpage, preview, changed, description
diff --git a/lib/private/avatar.php b/lib/private/avatar.php
index f20980c364b..720740569df 100644
--- a/lib/private/avatar.php
+++ b/lib/private/avatar.php
@@ -51,10 +51,6 @@ class OC_Avatar {
* @return void
*/
public function set ($data) {
- if (\OC_App::isEnabled('files_encryption')) {
- $l = \OC_L10N::get('lib');
- throw new \Exception($l->t("Custom profile pictures don't work with encryption yet"));
- }
$img = new OC_Image($data);
$type = substr($img->mimeType(), -3);
diff --git a/lib/private/cache/file.php b/lib/private/cache/file.php
index 2ab914d17b8..b0738d2a92b 100644
--- a/lib/private/cache/file.php
+++ b/lib/private/cache/file.php
@@ -41,6 +41,24 @@ class File {
return $result;
}
+ /**
+ * Returns the size of the stored/cached data
+ *
+ * @param $key
+ * @return int
+ */
+ public function size($key) {
+ $result = 0;
+ $proxyStatus = \OC_FileProxy::$enabled;
+ \OC_FileProxy::$enabled = false;
+ if ($this->hasKey($key)) {
+ $storage = $this->getStorage();
+ $result = $storage->filesize($key);
+ }
+ \OC_FileProxy::$enabled = $proxyStatus;
+ return $result;
+ }
+
public function set($key, $value, $ttl=0) {
$storage = $this->getStorage();
$result = false;
diff --git a/lib/private/connector/sabre/auth.php b/lib/private/connector/sabre/auth.php
index d2fd74c44f9..0c84fa6b757 100644
--- a/lib/private/connector/sabre/auth.php
+++ b/lib/private/connector/sabre/auth.php
@@ -73,11 +73,7 @@ class OC_Connector_Sabre_Auth extends Sabre_DAV_Auth_Backend_AbstractBasic {
*/
public function authenticate(Sabre_DAV_Server $server, $realm) {
- if (OC_User::handleApacheAuth()) {
- return true;
- }
-
- if (OC_User::isLoggedIn()) {
+ if (OC_User::handleApacheAuth() || OC_User::isLoggedIn()) {
$user = OC_User::getUser();
OC_Util::setupFS($user);
$this->currentUser = $user;
diff --git a/lib/private/connector/sabre/directory.php b/lib/private/connector/sabre/directory.php
index d0334780361..c51f84bf67c 100644
--- a/lib/private/connector/sabre/directory.php
+++ b/lib/private/connector/sabre/directory.php
@@ -71,7 +71,6 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
$path = $this->path . '/' . $name;
$node = new OC_Connector_Sabre_File($path);
return $node->put($data);
-
}
/**
@@ -229,4 +228,5 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
}
return $props;
}
+
}
diff --git a/lib/private/connector/sabre/exception/entitytoolarge.php b/lib/private/connector/sabre/exception/entitytoolarge.php
new file mode 100644
index 00000000000..2bda51f2f3e
--- /dev/null
+++ b/lib/private/connector/sabre/exception/entitytoolarge.php
@@ -0,0 +1,22 @@
+<?php
+
+/**
+ * Entity Too Large
+ *
+ * This exception is thrown whenever a user tries to upload a file which exceeds hard limitations
+ *
+ */
+class OC_Connector_Sabre_Exception_EntityTooLarge extends Sabre_DAV_Exception {
+
+ /**
+ * Returns the HTTP status code for this exception
+ *
+ * @return int
+ */
+ public function getHTTPCode() {
+
+ return 413;
+
+ }
+
+}
diff --git a/lib/private/connector/sabre/exception/unsupportedmediatype.php b/lib/private/connector/sabre/exception/unsupportedmediatype.php
new file mode 100644
index 00000000000..95d6a8cc651
--- /dev/null
+++ b/lib/private/connector/sabre/exception/unsupportedmediatype.php
@@ -0,0 +1,22 @@
+<?php
+
+/**
+ * Unsupported Media Type
+ *
+ * This exception is thrown whenever a user tries to upload a file which holds content which is not allowed
+ *
+ */
+class OC_Connector_Sabre_Exception_UnsupportedMediaType extends Sabre_DAV_Exception {
+
+ /**
+ * Returns the HTTP status code for this exception
+ *
+ * @return int
+ */
+ public function getHTTPCode() {
+
+ return 415;
+
+ }
+
+}
diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php
index 037dba7f37b..3402946a136 100644
--- a/lib/private/connector/sabre/file.php
+++ b/lib/private/connector/sabre/file.php
@@ -60,23 +60,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
// chunked handling
if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
-
- list($path, $name) = \Sabre_DAV_URLUtil::splitPath($this->path);
-
- $info = OC_FileChunking::decodeName($name);
- if (empty($info)) {
- throw new Sabre_DAV_Exception_NotImplemented();
- }
-
- $chunk_handler = new OC_FileChunking($info);
- $chunk_handler->store($info['index'], $data);
- if ($chunk_handler->isComplete()) {
- $newPath = $path . '/' . $info['name'];
- $chunk_handler->file_assemble($newPath);
- return $this->getETagPropertyForPath($newPath);
- }
-
- return null;
+ return $this->createFileChunked($data);
}
// mark file as partial while uploading (ignored by the scanner)
@@ -98,7 +82,21 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
throw new Sabre_DAV_Exception();
}
} catch (\OCP\Files\NotPermittedException $e) {
- throw new Sabre_DAV_Exception_Forbidden();
+ // a more general case - due to whatever reason the content could not be written
+ throw new Sabre_DAV_Exception_Forbidden($e->getMessage());
+
+ } catch (\OCP\Files\EntityTooLargeException $e) {
+ // the file is too big to be stored
+ throw new OC_Connector_Sabre_Exception_EntityTooLarge($e->getMessage());
+
+ } catch (\OCP\Files\InvalidContentException $e) {
+ // the file content is not permitted
+ throw new OC_Connector_Sabre_Exception_UnsupportedMediaType($e->getMessage());
+
+ } catch (\OCP\Files\InvalidPathException $e) {
+ // the path for the file was not valid
+ // TODO: find proper http status code for this case
+ throw new Sabre_DAV_Exception_Forbidden($e->getMessage());
}
// rename to correct path
@@ -200,4 +198,37 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
return \OC\Files\Filesystem::getMimeType($this->path);
}
+
+ private function createFileChunked($data)
+ {
+ list($path, $name) = \Sabre_DAV_URLUtil::splitPath($this->path);
+
+ $info = OC_FileChunking::decodeName($name);
+ if (empty($info)) {
+ throw new Sabre_DAV_Exception_NotImplemented();
+ }
+ $chunk_handler = new OC_FileChunking($info);
+ $bytesWritten = $chunk_handler->store($info['index'], $data);
+
+ //detect aborted upload
+ if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT' ) {
+ if (isset($_SERVER['CONTENT_LENGTH'])) {
+ $expected = $_SERVER['CONTENT_LENGTH'];
+ if ($bytesWritten != $expected) {
+ $chunk_handler->cleanup();
+ throw new Sabre_DAV_Exception_BadRequest(
+ 'expected filesize ' . $expected . ' got ' . $bytesWritten);
+ }
+ }
+ }
+
+ if ($chunk_handler->isComplete()) {
+ $newPath = $path . '/' . $info['name'];
+ $chunk_handler->file_assemble($newPath);
+ return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath);
+ }
+
+ return null;
+ }
+
}
diff --git a/lib/private/filechunking.php b/lib/private/filechunking.php
index 313a6ee87d2..0dfce696cda 100644
--- a/lib/private/filechunking.php
+++ b/lib/private/filechunking.php
@@ -34,10 +34,19 @@ class OC_FileChunking {
return $this->cache;
}
+ /**
+ * Stores the given $data under the given $key - the number of stored bytes is returned
+ *
+ * @param $index
+ * @param $data
+ * @return int
+ */
public function store($index, $data) {
$cache = $this->getCache();
$name = $this->getPrefix().$index;
$cache->set($name, $data);
+
+ return $cache->size($name);
}
public function isComplete() {
@@ -58,12 +67,24 @@ class OC_FileChunking {
$count = 0;
for($i=0; $i < $this->info['chunkcount']; $i++) {
$chunk = $cache->get($prefix.$i);
- $cache->remove($prefix.$i);
$count += fwrite($f, $chunk);
}
+
+ $this->cleanup();
return $count;
}
+ /**
+ * Removes all chunks which belong to this transmission
+ */
+ public function cleanup() {
+ $cache = $this->getCache();
+ $prefix = $this->getPrefix();
+ for($i=0; $i < $this->info['chunkcount']; $i++) {
+ $cache->remove($prefix.$i);
+ }
+ }
+
public function signature_split($orgfile, $input) {
$info = unpack('n', fread($input, 2));
$blocksize = $info[1];
diff --git a/lib/private/files/view.php b/lib/private/files/view.php
index a56135d9b3c..c0b9f0fc9c8 100644
--- a/lib/private/files/view.php
+++ b/lib/private/files/view.php
@@ -904,7 +904,8 @@ class View {
$permissions = $subStorage->getPermissions($rootEntry['path']);
$subPermissionsCache->set($rootEntry['fileid'], $user, $permissions);
}
- $rootEntry['permissions'] = $permissions;
+ // do not allow renaming/deleting the mount point
+ $rootEntry['permissions'] = $permissions & (\OCP\PERMISSION_ALL - (\OCP\PERMISSION_UPDATE | \OCP\PERMISSION_DELETE));
//remove any existing entry with the same name
foreach ($files as $i => $file) {
diff --git a/lib/private/helper.php b/lib/private/helper.php
index a34640d8e36..1236e748256 100644
--- a/lib/private/helper.php
+++ b/lib/private/helper.php
@@ -509,11 +509,11 @@ class OC_Helper {
*
* @param resource $source
* @param resource $target
- * @return int the number of bytes copied
+ * @return array the number of bytes copied and result
*/
public static function streamCopy($source, $target) {
if (!$source or !$target) {
- return false;
+ return array(0, false);
}
$result = true;
$count = 0;
diff --git a/lib/private/log/owncloud.php b/lib/private/log/owncloud.php
index f3b43584409..a408e3830d6 100644
--- a/lib/private/log/owncloud.php
+++ b/lib/private/log/owncloud.php
@@ -59,10 +59,14 @@ class OC_Log_Owncloud {
}
$time = new DateTime(null, $timezone);
$entry=array('app'=>$app, 'message'=>$message, 'level'=>$level, 'time'=> $time->format($format));
+ $entry = json_encode($entry);
$handle = @fopen(self::$logFile, 'a');
if ($handle) {
- fwrite($handle, json_encode($entry)."\n");
+ fwrite($handle, $entry."\n");
fclose($handle);
+ } else {
+ // Fall back to error_log
+ error_log($entry);
}
}
}
diff --git a/lib/private/user.php b/lib/private/user.php
index b68786c773c..6b350d4cf1b 100644
--- a/lib/private/user.php
+++ b/lib/private/user.php
@@ -325,7 +325,7 @@ class OC_User {
return $backend->getLogoutAttribute();
}
- return "href=" . link_to('', 'index.php') . "?logout=true";
+ return 'href="' . link_to('', 'index.php') . '?logout=true"';
}
/**