diff options
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/app.php | 33 | ||||
-rw-r--r-- | lib/private/appframework/dependencyinjection/dicontainer.php | 5 | ||||
-rw-r--r-- | lib/private/avatar.php | 4 | ||||
-rw-r--r-- | lib/private/cache/file.php | 18 | ||||
-rw-r--r-- | lib/private/connector/sabre/auth.php | 6 | ||||
-rw-r--r-- | lib/private/connector/sabre/directory.php | 2 | ||||
-rw-r--r-- | lib/private/connector/sabre/exception/entitytoolarge.php | 22 | ||||
-rw-r--r-- | lib/private/connector/sabre/exception/unsupportedmediatype.php | 22 | ||||
-rw-r--r-- | lib/private/connector/sabre/file.php | 67 | ||||
-rw-r--r-- | lib/private/connector/sabre/node.php | 6 | ||||
-rw-r--r-- | lib/private/filechunking.php | 23 | ||||
-rw-r--r-- | lib/private/files/storage/storage.php | 279 | ||||
-rw-r--r-- | lib/private/files/view.php | 15 | ||||
-rw-r--r-- | lib/private/group.php | 2 | ||||
-rw-r--r-- | lib/private/helper.php | 4 | ||||
-rw-r--r-- | lib/private/log/owncloud.php | 6 | ||||
-rw-r--r-- | lib/private/session/session.php | 35 | ||||
-rw-r--r-- | lib/private/user.php | 2 |
18 files changed, 195 insertions, 356 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/appframework/dependencyinjection/dicontainer.php b/lib/private/appframework/dependencyinjection/dicontainer.php index 3755d45fa09..e62b72fd973 100644 --- a/lib/private/appframework/dependencyinjection/dicontainer.php +++ b/lib/private/appframework/dependencyinjection/dicontainer.php @@ -89,11 +89,12 @@ class DIContainer extends SimpleContainer implements IAppContainer{ return new SecurityMiddleware($c['API'], $c['Request']); }); - $this['MiddlewareDispatcher'] = $this->share(function($c){ + $middleWares = $this->middleWares; + $this['MiddlewareDispatcher'] = $this->share(function($c) use ($middleWares) { $dispatcher = new MiddlewareDispatcher(); $dispatcher->registerMiddleware($c['SecurityMiddleware']); - foreach($this->middleWares as $middleWare) { + foreach($middleWares as $middleWare) { $dispatcher->registerMiddleware($middleWare); } 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/connector/sabre/node.php b/lib/private/connector/sabre/node.php index fa27abb381a..c38e9f86375 100644 --- a/lib/private/connector/sabre/node.php +++ b/lib/private/connector/sabre/node.php @@ -147,12 +147,6 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr * Even if the modification time is set to a custom value the access time is set to now. */ public function touch($mtime) { - - // touch is only allowed if the update privilege is granted - if (!\OC\Files\Filesystem::isUpdatable($this->path)) { - throw new \Sabre_DAV_Exception_Forbidden(); - } - \OC\Files\Filesystem::touch($this->path, $mtime); } 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/storage/storage.php b/lib/private/files/storage/storage.php index b673bb9a32d..5be90f24756 100644 --- a/lib/private/files/storage/storage.php +++ b/lib/private/files/storage/storage.php @@ -14,278 +14,6 @@ namespace OC\Files\Storage; * All paths passed to the storage are relative to the storage and should NOT have a leading slash. */ interface Storage extends \OCP\Files\Storage { - /** - * $parameters is a free form array with the configuration options needed to construct the storage - * - * @param array $parameters - */ - public function __construct($parameters); - - /** - * Get the identifier for the storage, - * the returned id should be the same for every storage object that is created with the same parameters - * and two storage objects with the same id should refer to two storages that display the same files. - * - * @return string - */ - public function getId(); - - /** - * see http://php.net/manual/en/function.mkdir.php - * - * @param string $path - * @return bool - */ - public function mkdir($path); - - /** - * see http://php.net/manual/en/function.rmdir.php - * - * @param string $path - * @return bool - */ - public function rmdir($path); - - /** - * see http://php.net/manual/en/function.opendir.php - * - * @param string $path - * @return resource - */ - public function opendir($path); - - /** - * see http://php.net/manual/en/function.is_dir.php - * - * @param string $path - * @return bool - */ - public function is_dir($path); - - /** - * see http://php.net/manual/en/function.is_file.php - * - * @param string $path - * @return bool - */ - public function is_file($path); - - /** - * see http://php.net/manual/en/function.stat.php - * only the following keys are required in the result: size and mtime - * - * @param string $path - * @return array - */ - public function stat($path); - - /** - * see http://php.net/manual/en/function.filetype.php - * - * @param string $path - * @return bool - */ - public function filetype($path); - - /** - * see http://php.net/manual/en/function.filesize.php - * The result for filesize when called on a folder is required to be 0 - * - * @param string $path - * @return int - */ - public function filesize($path); - - /** - * check if a file can be created in $path - * - * @param string $path - * @return bool - */ - public function isCreatable($path); - - /** - * check if a file can be read - * - * @param string $path - * @return bool - */ - public function isReadable($path); - - /** - * check if a file can be written to - * - * @param string $path - * @return bool - */ - public function isUpdatable($path); - - /** - * check if a file can be deleted - * - * @param string $path - * @return bool - */ - public function isDeletable($path); - - /** - * check if a file can be shared - * - * @param string $path - * @return bool - */ - public function isSharable($path); - - /** - * get the full permissions of a path. - * Should return a combination of the PERMISSION_ constants defined in lib/public/constants.php - * - * @param string $path - * @return int - */ - public function getPermissions($path); - - /** - * see http://php.net/manual/en/function.file_exists.php - * - * @param string $path - * @return bool - */ - public function file_exists($path); - - /** - * see http://php.net/manual/en/function.filemtime.php - * - * @param string $path - * @return int - */ - public function filemtime($path); - - /** - * see http://php.net/manual/en/function.file_get_contents.php - * - * @param string $path - * @return string - */ - public function file_get_contents($path); - - /** - * see http://php.net/manual/en/function.file_put_contents.php - * - * @param string $path - * @param string $data - * @return bool - */ - public function file_put_contents($path, $data); - - /** - * see http://php.net/manual/en/function.unlink.php - * - * @param string $path - * @return bool - */ - public function unlink($path); - - /** - * see http://php.net/manual/en/function.rename.php - * - * @param string $path1 - * @param string $path2 - * @return bool - */ - public function rename($path1, $path2); - - /** - * see http://php.net/manual/en/function.copy.php - * - * @param string $path1 - * @param string $path2 - * @return bool - */ - public function copy($path1, $path2); - - /** - * see http://php.net/manual/en/function.fopen.php - * - * @param string $path - * @param string $mode - * @return resource - */ - public function fopen($path, $mode); - - /** - * get the mimetype for a file or folder - * The mimetype for a folder is required to be "httpd/unix-directory" - * - * @param string $path - * @return string - */ - public function getMimeType($path); - - /** - * see http://php.net/manual/en/function.hash.php - * - * @param string $type - * @param string $path - * @param bool $raw - * @return string - */ - public function hash($type, $path, $raw = false); - - /** - * see http://php.net/manual/en/function.free_space.php - * - * @param string $path - * @return int - */ - public function free_space($path); - - /** - * search for occurrences of $query in file names - * - * @param string $query - * @return array - */ - public function search($query); - - /** - * see http://php.net/manual/en/function.touch.php - * If the backend does not support the operation, false should be returned - * - * @param string $path - * @param int $mtime - * @return bool - */ - public function touch($path, $mtime = null); - - /** - * get the path to a local version of the file. - * The local version of the file can be temporary and doesn't have to be persistent across requests - * - * @param string $path - * @return string - */ - public function getLocalFile($path); - - /** - * get the path to a local version of the folder. - * The local version of the folder can be temporary and doesn't have to be persistent across requests - * - * @param string $path - * @return string - */ - public function getLocalFolder($path); - /** - * check if a file or folder has been updated since $time - * - * @param string $path - * @param int $time - * @return bool - * - * hasUpdated for folders should return at least true if a file inside the folder is add, removed or renamed. - * returning true for other changes in the folder is optional - */ - public function hasUpdated($path, $time); /** * get a cache instance for the storage @@ -333,11 +61,4 @@ interface Storage extends \OCP\Files\Storage { */ public function getStorageCache(); - /** - * get the ETag for a file or folder - * - * @param string $path - * @return string - */ - public function getETag($path); } diff --git a/lib/private/files/view.php b/lib/private/files/view.php index aa08a5f7cc9..c0b9f0fc9c8 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -110,7 +110,9 @@ class View { * @return array consisting of the storage and the internal path */ public function resolvePath($path) { - return Filesystem::resolvePath($this->getAbsolutePath($path)); + $a = $this->getAbsolutePath($path); + $p = Filesystem::normalizePath($a); + return Filesystem::resolvePath($p); } /** @@ -324,7 +326,8 @@ class View { return false; } } else { - return $this->basicOperation('file_put_contents', $path, array('create', 'write'), $data); + $hooks = ($this->file_exists($path)) ? array('write') : array('create', 'write'); + return $this->basicOperation('file_put_contents', $path, $hooks, $data); } } @@ -709,7 +712,10 @@ class View { return false; } $defaultRoot = Filesystem::getRoot(); - return (strlen($this->fakeRoot) >= strlen($defaultRoot)) && (substr($this->fakeRoot, 0, strlen($defaultRoot)) === $defaultRoot); + if($this->fakeRoot === $defaultRoot){ + return true; + } + return (strlen($this->fakeRoot) > strlen($defaultRoot)) && (substr($this->fakeRoot, 0, strlen($defaultRoot) + 1) === $defaultRoot . '/'); } private function runHooks($hooks, $path, $post = false) { @@ -898,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/group.php b/lib/private/group.php index ba93dc129a1..9144ef683b6 100644 --- a/lib/private/group.php +++ b/lib/private/group.php @@ -265,7 +265,7 @@ class OC_Group { public static function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { $group = self::getManager()->get($gid); if ($group) { - $users = $group->searchDisplayName($search . $limit, $offset); + $users = $group->searchDisplayName($search, $limit, $offset); $displayNames = array(); foreach ($users as $user) { $displayNames[] = $user->getDisplayName(); 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/session/session.php b/lib/private/session/session.php index c55001eccac..fe160faa267 100644 --- a/lib/private/session/session.php +++ b/lib/private/session/session.php @@ -8,7 +8,10 @@ namespace OC\Session; -abstract class Session implements \ArrayAccess, \OCP\ISession { +use OCP\ISession; + +abstract class Session implements \ArrayAccess, ISession { + /** * $name serves as a namespace for the session keys * @@ -17,36 +20,6 @@ abstract class Session implements \ArrayAccess, \OCP\ISession { abstract public function __construct($name); /** - * @param string $key - * @param mixed $value - */ - abstract public function set($key, $value); - - /** - * @param string $key - * @return mixed should return null if $key does not exist - */ - abstract public function get($key); - - /** - * @param string $key - * @return bool - */ - abstract public function exists($key); - - /** - * should not throw any errors if $key does not exist - * - * @param string $key - */ - abstract public function remove($key); - - /** - * removes all entries within the cache namespace - */ - abstract public function clear(); - - /** * @param mixed $offset * @return bool */ 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"'; } /** |