diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2013-10-16 14:48:55 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2013-10-16 14:48:55 +0200 |
commit | d8a7b1e5372e7fcc05095c3b9aebe90f33da5760 (patch) | |
tree | b7028371cc353a2813bf370d091e48922e50c02f /lib | |
parent | 71601a7c6f708dddd3d1ae030f86ae982a2e3865 (diff) | |
parent | db31541fe13510ca4d1b752d7ac5a08ea8e89310 (diff) | |
download | nextcloud-server-d8a7b1e5372e7fcc05095c3b9aebe90f33da5760.tar.gz nextcloud-server-d8a7b1e5372e7fcc05095c3b9aebe90f33da5760.zip |
Merge branch 'master' into fixing-5170-master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 3 | ||||
-rw-r--r-- | lib/l10n/pt_PT.php | 7 | ||||
-rw-r--r-- | lib/l10n/sv.php | 3 | ||||
-rw-r--r-- | lib/l10n/tr.php | 3 | ||||
-rw-r--r-- | lib/private/app.php | 33 | ||||
-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/filechunking.php | 23 | ||||
-rw-r--r-- | lib/private/files/view.php | 3 | ||||
-rw-r--r-- | lib/private/helper.php | 4 | ||||
-rw-r--r-- | lib/private/log/owncloud.php | 6 | ||||
-rw-r--r-- | lib/private/user.php | 2 | ||||
-rw-r--r-- | lib/public/files/entitytoolargeexception.php | 11 | ||||
-rw-r--r-- | lib/public/files/invalidcontentexception.php | 11 | ||||
-rw-r--r-- | lib/public/files/invalidpathexception.php | 11 | ||||
-rw-r--r-- | lib/public/share.php | 8 |
21 files changed, 229 insertions, 40 deletions
diff --git a/lib/base.php b/lib/base.php index ff4ca588213..9068fe76981 100644 --- a/lib/base.php +++ b/lib/base.php @@ -304,9 +304,8 @@ class OC { self::$session = new \OC\Session\Internal(OC_Util::getInstanceId()); // if session cant be started break with http 500 error } catch (Exception $e) { - OC_Log::write('core', 'Session could not be initialized', + OC_Log::write('core', 'Session could not be initialized. Exception message: '.$e->getMessage(), OC_Log::ERROR); - header('HTTP/1.1 500 Internal Server Error'); OC_Util::addStyle("styles"); $error = 'Session could not be initialized. Please contact your '; diff --git a/lib/l10n/pt_PT.php b/lib/l10n/pt_PT.php index bc298a3f33f..cb990aed110 100644 --- a/lib/l10n/pt_PT.php +++ b/lib/l10n/pt_PT.php @@ -1,5 +1,7 @@ <?php $TRANSLATIONS = array( +"App \"%s\" can't be installed because it is not compatible with this version of ownCloud." => "A aplicação \"%s\" não pode ser instaladas por não ser compatível com esta versão da ownCloud.", +"No app name specified" => "O nome da aplicação não foi especificado", "Help" => "Ajuda", "Personal" => "Pessoal", "Settings" => "Configurações", @@ -15,6 +17,11 @@ $TRANSLATIONS = array( "Back to Files" => "Voltar a Ficheiros", "Selected files too large to generate zip file." => "Os ficheiros seleccionados são grandes demais para gerar um ficheiro zip.", "Download the files in smaller chunks, seperately or kindly ask your administrator." => "Descarregue os ficheiros em partes menores, separados ou peça gentilmente ao seu administrador.", +"Archives of type %s are not supported" => "Arquivos do tipo %s não são suportados", +"App does not provide an info.xml file" => "A aplicação não disponibiliza um ficheiro info.xml", +"App can't be installed because of not allowed code in the App" => "A aplicação não pode ser instalado devido a código não permitido dentro da aplicação", +"App directory already exists" => "A directoria da aplicação já existe", +"Can't create app folder. Please fix permissions. %s" => "Não foi possível criar a pasta da aplicação. Por favor verifique as permissões. %s", "Application is not enabled" => "A aplicação não está activada", "Authentication error" => "Erro na autenticação", "Token expired. Please reload page." => "O token expirou. Por favor recarregue a página.", diff --git a/lib/l10n/sv.php b/lib/l10n/sv.php index 37f2e1d8c08..8ce6d005ca4 100644 --- a/lib/l10n/sv.php +++ b/lib/l10n/sv.php @@ -8,6 +8,9 @@ $TRANSLATIONS = array( "Users" => "Användare", "Admin" => "Admin", "Failed to upgrade \"%s\"." => "Misslyckades med att uppgradera \"%s\".", +"Custom profile pictures don't work with encryption yet" => "Anpassningsbara profilbilder fungerar inte med kryptering ännu.", +"Unknown filetype" => "Okänd filtyp", +"Invalid image" => "Ogiltig bild", "web services under your control" => "webbtjänster under din kontroll", "cannot open \"%s\"" => "Kan inte öppna \"%s\"", "ZIP download is turned off." => "Nerladdning av ZIP är avstängd.", diff --git a/lib/l10n/tr.php b/lib/l10n/tr.php index 01f48517aec..80288ed0516 100644 --- a/lib/l10n/tr.php +++ b/lib/l10n/tr.php @@ -8,6 +8,9 @@ $TRANSLATIONS = array( "Users" => "Kullanıcılar", "Admin" => "Yönetici", "Failed to upgrade \"%s\"." => "\"%s\" yükseltme başarısız oldu.", +"Custom profile pictures don't work with encryption yet" => "Hala özel profil resminiz şifreleme ile çalışmıyor", +"Unknown filetype" => "Bilinmeyen dosya türü", +"Invalid image" => "Geçersiz resim", "web services under your control" => "Bilgileriniz güvenli ve şifreli", "cannot open \"%s\"" => "\"%s\" açılamıyor", "ZIP download is turned off." => "ZIP indirmeleri kapatılmıştır.", 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"'; } /** diff --git a/lib/public/files/entitytoolargeexception.php b/lib/public/files/entitytoolargeexception.php new file mode 100644 index 00000000000..3dff41bca02 --- /dev/null +++ b/lib/public/files/entitytoolargeexception.php @@ -0,0 +1,11 @@ +<?php +/** + * Copyright (c) 2013 Thomas Müller <thomas.mueller@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCP\Files; + +class EntityTooLargeException extends \Exception {} diff --git a/lib/public/files/invalidcontentexception.php b/lib/public/files/invalidcontentexception.php new file mode 100644 index 00000000000..184ec4d06d6 --- /dev/null +++ b/lib/public/files/invalidcontentexception.php @@ -0,0 +1,11 @@ +<?php +/** + * Copyright (c) 2013 Thomas Müller <thomas.mueller@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCP\Files; + +class InvalidContentException extends \Exception {} diff --git a/lib/public/files/invalidpathexception.php b/lib/public/files/invalidpathexception.php new file mode 100644 index 00000000000..36090ae5b48 --- /dev/null +++ b/lib/public/files/invalidpathexception.php @@ -0,0 +1,11 @@ +<?php +/** + * Copyright (c) 2013 Thomas Müller <thomas.mueller@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCP\Files; + +class InvalidPathException extends \Exception {} diff --git a/lib/public/share.php b/lib/public/share.php index e6a74117aa2..66605dafee5 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -155,13 +155,13 @@ class Share { while ($source !== -1) { - // Fetch all shares of this file path from DB + // Fetch all shares with another user $query = \OC_DB::prepare( 'SELECT `share_with` FROM `*PREFIX*share` WHERE - `item_source` = ? AND `share_type` = ?' + `item_source` = ? AND `share_type` = ? AND `item_type` IN (\'file\', \'folder\')' ); $result = $query->execute(array($source, self::SHARE_TYPE_USER)); @@ -180,7 +180,7 @@ class Share { FROM `*PREFIX*share` WHERE - `item_source` = ? AND `share_type` = ?' + `item_source` = ? AND `share_type` = ? AND `item_type` IN (\'file\', \'folder\')' ); $result = $query->execute(array($source, self::SHARE_TYPE_GROUP)); @@ -201,7 +201,7 @@ class Share { FROM `*PREFIX*share` WHERE - `item_source` = ? AND `share_type` = ?' + `item_source` = ? AND `share_type` = ? AND `item_type` IN (\'file\', \'folder\')' ); $result = $query->execute(array($source, self::SHARE_TYPE_LINK)); |