From fc607e6bce76e9e2f6f52421bdddece951f629cd Mon Sep 17 00:00:00 2001 From: Pellaeon Lin Date: Sun, 8 Dec 2013 22:59:46 +0800 Subject: Separate PHP upload limit and free space --- lib/private/helper.php | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'lib/private') diff --git a/lib/private/helper.php b/lib/private/helper.php index c82d3bd4ef4..0bef427c6c1 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -828,23 +828,39 @@ class OC_Helper { * @return number of bytes representing */ public static function maxUploadFilesize($dir) { - $upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize')); - $post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size')); - $freeSpace = \OC\Files\Filesystem::free_space($dir); - if ((int)$upload_max_filesize === 0 and (int)$post_max_size === 0) { - $maxUploadFilesize = \OC\Files\SPACE_UNLIMITED; - } elseif ((int)$upload_max_filesize === 0 or (int)$post_max_size === 0) { - $maxUploadFilesize = max($upload_max_filesize, $post_max_size); //only the non 0 value counts - } else { - $maxUploadFilesize = min($upload_max_filesize, $post_max_size); - } + return min(self::freeSpace($dir), self::uploadLimit()); + } + /** + * Calculate free space left within user quota + * + * @param $dir the current folder where the user currently operates + * @return number of bytes representing + */ + public static function freeSpace($dir) { + $freeSpace = \OC\Files\Filesystem::free_space($dir); if ($freeSpace !== \OC\Files\SPACE_UNKNOWN) { $freeSpace = max($freeSpace, 0); + return $freeSpace; + } else { + return INF; + } + } - return min($maxUploadFilesize, $freeSpace); + /** + * Calculate PHP upload limit + * + * @return PHP upload file size limit + */ + public static function uploadLimit() { + $upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize')); + $post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size')); + if ((int)$upload_max_filesize === 0 and (int)$post_max_size === 0) { + return INF; + } elseif ((int)$upload_max_filesize === 0 or (int)$post_max_size === 0) { + return max($upload_max_filesize, $post_max_size); //only the non 0 value counts } else { - return $maxUploadFilesize; + return min($upload_max_filesize, $post_max_size); } } -- cgit v1.2.3 From 409b5108896edda9adf916cd566dbce2d2b00351 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Tue, 10 Dec 2013 12:05:39 +0100 Subject: Moved content disposition code+workarounds to OCP\Response Added new OC\Response API called setContentDispositionHeader() that contains the needed workarounds for UTF8 and IE. Refactored download code to use the new API. Removed unused trashbin download file. --- apps/files/download.php | 7 +----- apps/files_trashbin/download.php | 51 ---------------------------------------- apps/files_versions/download.php | 7 +----- lib/private/files.php | 7 +----- lib/private/response.php | 14 +++++++++++ lib/public/response.php | 9 +++++++ 6 files changed, 26 insertions(+), 69 deletions(-) delete mode 100644 apps/files_trashbin/download.php (limited to 'lib/private') diff --git a/apps/files/download.php b/apps/files/download.php index e3fe24e45d7..6b055e99a53 100644 --- a/apps/files/download.php +++ b/apps/files/download.php @@ -37,12 +37,7 @@ if(!\OC\Files\Filesystem::file_exists($filename)) { $ftype=\OC\Files\Filesystem::getMimeType( $filename ); header('Content-Type:'.$ftype); -if ( preg_match( "/MSIE/", $_SERVER["HTTP_USER_AGENT"] ) ) { - header( 'Content-Disposition: attachment; filename="' . rawurlencode( basename($filename) ) . '"' ); -} else { - header( 'Content-Disposition: attachment; filename*=UTF-8\'\'' . rawurlencode( basename($filename) ) - . '; filename="' . rawurlencode( basename($filename) ) . '"' ); -} +OCP\Response::setContentDispositionHeader(basename($filename), 'attachment'); OCP\Response::disableCaching(); header('Content-Length: '.\OC\Files\Filesystem::filesize($filename)); diff --git a/apps/files_trashbin/download.php b/apps/files_trashbin/download.php deleted file mode 100644 index 60328e1dddb..00000000000 --- a/apps/files_trashbin/download.php +++ /dev/null @@ -1,51 +0,0 @@ -. -* -*/ - -// Check if we are a user -OCP\User::checkLoggedIn(); - -$filename = $_GET["file"]; - -$view = new OC_FilesystemView('/'.\OCP\User::getUser().'/files_trashbin/files'); - -if(!$view->file_exists($filename)) { - header("HTTP/1.0 404 Not Found"); - $tmpl = new OCP\Template( '', '404', 'guest' ); - $tmpl->assign('file', $filename); - $tmpl->printPage(); - exit; -} - -$ftype=$view->getMimeType( $filename ); - -header('Content-Type:'.$ftype);if ( preg_match( "/MSIE/", $_SERVER["HTTP_USER_AGENT"] ) ) { - header( 'Content-Disposition: attachment; filename="' . rawurlencode( basename($filename) ) . '"' ); -} else { - header( 'Content-Disposition: attachment; filename*=UTF-8\'\'' . rawurlencode( basename($filename) ) - . '; filename="' . rawurlencode( basename($filename) ) . '"' ); -} -OCP\Response::disableCaching(); -header('Content-Length: '. $view->filesize($filename)); - -OC_Util::obEnd(); -$view->readfile( $filename ); diff --git a/apps/files_versions/download.php b/apps/files_versions/download.php index 040a662e61b..2fe56d2e638 100644 --- a/apps/files_versions/download.php +++ b/apps/files_versions/download.php @@ -36,12 +36,7 @@ $view = new OC\Files\View('/'); $ftype = $view->getMimeType('/'.$uid.'/files/'.$filename); header('Content-Type:'.$ftype); -if ( preg_match( "/MSIE/", $_SERVER["HTTP_USER_AGENT"] ) ) { - header( 'Content-Disposition: attachment; filename="' . rawurlencode( basename($filename) ) . '"' ); -} else { - header( 'Content-Disposition: attachment; filename*=UTF-8\'\'' . rawurlencode( basename($filename) ) - . '; filename="' . rawurlencode( basename($filename) ) . '"' ); -} +OCP\Response::setContentDispositionHeader(basename($filename), 'attachment'); OCP\Response::disableCaching(); header('Content-Length: '.$view->filesize($versionName)); diff --git a/lib/private/files.php b/lib/private/files.php index 6ffa14c0d91..e6c81d58bd2 100644 --- a/lib/private/files.php +++ b/lib/private/files.php @@ -115,12 +115,7 @@ class OC_Files { } OC_Util::obEnd(); if ($zip or \OC\Files\Filesystem::isReadable($filename)) { - if ( preg_match( "/MSIE/", $_SERVER["HTTP_USER_AGENT"] ) ) { - header( 'Content-Disposition: attachment; filename="' . rawurlencode($name) . '"' ); - } else { - header( 'Content-Disposition: attachment; filename*=UTF-8\'\'' . rawurlencode($name) - . '; filename="' . rawurlencode($name) . '"' ); - } + OC_Response::setContentDispositionHeader($name, 'attachment'); header('Content-Transfer-Encoding: binary'); OC_Response::disableCaching(); if ($zip) { diff --git a/lib/private/response.php b/lib/private/response.php index 674176d078b..1b9cb473d67 100644 --- a/lib/private/response.php +++ b/lib/private/response.php @@ -147,6 +147,20 @@ class OC_Response { header('Last-Modified: '.$lastModified); } + /** + * Sets the content disposition header (with possible workarounds) + * @param string $filename file name + * @param string $type disposition type, either 'attachment' or 'inline' + */ + static public function setContentDispositionHeader( $filename, $type = 'attachment' ) { + if ( preg_match( "/MSIE/", $_SERVER["HTTP_USER_AGENT"] ) ) { + header( 'Content-Disposition: ' . rawurlencode($type) . '; filename="' . rawurlencode( $filename ) . '"' ); + } else { + header( 'Content-Disposition: ' . rawurlencode($type) . '; filename*=UTF-8\'\'' . rawurlencode( $filename ) + . '; filename="' . rawurlencode( $filename ) . '"' ); + } + } + /** * @brief Send file as response, checking and setting caching headers * @param $filepath of file to send diff --git a/lib/public/response.php b/lib/public/response.php index 2ca0a0c9fa4..24d3c81d628 100644 --- a/lib/public/response.php +++ b/lib/public/response.php @@ -54,6 +54,15 @@ class Response { \OC_Response::setLastModifiedHeader( $lastModified ); } + /** + * Sets the content disposition header (with possible workarounds) + * @param string $filename file name + * @param string $type disposition type, either 'attachment' or 'inline' + */ + static public function setContentDispositionHeader( $filename, $type = 'attachment' ) { + \OC_Response::setContentDispositionHeader( $filename, $type ); + } + /** * Disable browser caching * @see enableCaching with cache_time = 0 -- cgit v1.2.3 From 82bf1f9c8ccbfed39790d22b2fbea2c5286122dc Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Tue, 10 Dec 2013 12:40:59 +0100 Subject: Added workaround for Android content disposition Fixes #5807 --- lib/private/response.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/response.php b/lib/private/response.php index 1b9cb473d67..c6edda0f949 100644 --- a/lib/private/response.php +++ b/lib/private/response.php @@ -153,7 +153,8 @@ class OC_Response { * @param string $type disposition type, either 'attachment' or 'inline' */ static public function setContentDispositionHeader( $filename, $type = 'attachment' ) { - if ( preg_match( "/MSIE/", $_SERVER["HTTP_USER_AGENT"] ) ) { + // Android Chrome user agent: https://developers.google.com/chrome/mobile/docs/user-agent + if ( preg_match( '/MSIE/', $_SERVER['HTTP_USER_AGENT'] ) or preg_match( '#Android.*Chrome/[.0-9]*#', $_SERVER['HTTP_USER_AGENT'] ) ) { header( 'Content-Disposition: ' . rawurlencode($type) . '; filename="' . rawurlencode( $filename ) . '"' ); } else { header( 'Content-Disposition: ' . rawurlencode($type) . '; filename*=UTF-8\'\'' . rawurlencode( $filename ) -- cgit v1.2.3 From 059c3c8708c9b94df80d43ab8cac0cfc9b867cb8 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 16 Dec 2013 15:38:12 +0100 Subject: fix issue with logging non utf8 chars --- lib/private/image.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/image.php b/lib/private/image.php index 7761a3c7737..314a4216b82 100644 --- a/lib/private/image.php +++ b/lib/private/image.php @@ -416,7 +416,7 @@ class OC_Image { // exif_imagetype throws "read error!" if file is less than 12 byte if(!@is_file($imagePath) || !file_exists($imagePath) || filesize($imagePath) < 12 || !is_readable($imagePath)) { // Debug output disabled because this method is tried before loadFromBase64? - OC_Log::write('core', 'OC_Image->loadFromFile, couldn\'t load: '.$imagePath, OC_Log::DEBUG); + OC_Log::write('core', 'OC_Image->loadFromFile, couldn\'t load: ' . (string) $imagePath, OC_Log::DEBUG); return false; } $iType = exif_imagetype($imagePath); -- cgit v1.2.3 From 09bd5bd517fee80e8b44b7645b51a8ba482a4d7c Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 12 Dec 2013 11:32:56 +0100 Subject: Added isUserAgent() method to request - added isUserAgent() method to OC_Request which makes it possible to test it - OC_Response::setContentDisposition now uses OC_Request::isUserAgent() --- lib/private/request.php | 23 ++++++++++++++++++++++ lib/private/response.php | 3 +-- tests/lib/request.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) (limited to 'lib/private') diff --git a/lib/private/request.php b/lib/private/request.php index b2afda35922..d9d5ae08e28 100755 --- a/lib/private/request.php +++ b/lib/private/request.php @@ -7,6 +7,11 @@ */ class OC_Request { + + const USER_AGENT_IE = '/MSIE/'; + // Android Chrome user agent: https://developers.google.com/chrome/mobile/docs/user-agent + const USER_AGENT_ANDROID_MOBILE_CHROME = '#Android.*Chrome/[.0-9]*#'; + /** * @brief Check overwrite condition * @param string $type @@ -210,4 +215,22 @@ class OC_Request { return false; } } + + /** + * Checks whether the user agent matches a given regex + * @param string|array $agent agent name or array of agent names + * @return boolean true if at least one of the given agent matches, + * false otherwise + */ + static public function isUserAgent($agent) { + if (!is_array($agent)) { + $agent = array($agent); + } + foreach ($agent as $regex) { + if (preg_match($regex, $_SERVER['HTTP_USER_AGENT'])) { + return true; + } + } + return false; + } } diff --git a/lib/private/response.php b/lib/private/response.php index c6edda0f949..04746437347 100644 --- a/lib/private/response.php +++ b/lib/private/response.php @@ -153,8 +153,7 @@ class OC_Response { * @param string $type disposition type, either 'attachment' or 'inline' */ static public function setContentDispositionHeader( $filename, $type = 'attachment' ) { - // Android Chrome user agent: https://developers.google.com/chrome/mobile/docs/user-agent - if ( preg_match( '/MSIE/', $_SERVER['HTTP_USER_AGENT'] ) or preg_match( '#Android.*Chrome/[.0-9]*#', $_SERVER['HTTP_USER_AGENT'] ) ) { + if (OC_Request::isUserAgent(array(OC_Request::USER_AGENT_IE, OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME))) { header( 'Content-Disposition: ' . rawurlencode($type) . '; filename="' . rawurlencode( $filename ) . '"' ); } else { header( 'Content-Disposition: ' . rawurlencode($type) . '; filename*=UTF-8\'\'' . rawurlencode( $filename ) diff --git a/tests/lib/request.php b/tests/lib/request.php index 090cebc9231..c6401a57144 100644 --- a/tests/lib/request.php +++ b/tests/lib/request.php @@ -70,4 +70,54 @@ class Test_Request extends PHPUnit_Framework_TestCase { array('/oc/core1', '/oc/core/index.php'), ); } + + /** + * @dataProvider userAgentProvider + */ + public function testUserAgent($testAgent, $userAgent, $matches) { + $_SERVER['HTTP_USER_AGENT'] = $testAgent; + $this->assertEquals($matches, OC_Request::isUserAgent($userAgent)); + } + + function userAgentProvider() { + return array( + array( + 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)', + OC_Request::USER_AGENT_IE, + true + ), + array( + 'Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Firefox/24.0', + OC_Request::USER_AGENT_IE, + false + ), + array( + 'Mozilla/5.0 (Linux; Android 4.4; Nexus 4 Build/KRT16S) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Mobile Safari/537.36', + OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME, + true + ), + array( + 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)', + OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME, + false + ), + // test two values + array( + 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)', + array( + OC_Request::USER_AGENT_IE, + OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME, + ), + true + ), + array( + 'Mozilla/5.0 (Linux; Android 4.4; Nexus 4 Build/KRT16S) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Mobile Safari/537.36', + array( + OC_Request::USER_AGENT_IE, + OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME, + ), + true + ), + ); + } } -- cgit v1.2.3 From 1c0b8ed21421334fed1a699e52dbb5765b66f96d Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Fri, 20 Dec 2013 13:48:46 +0100 Subject: Adding a random postfix to the part file. --- lib/private/connector/sabre/file.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php index 295575f0af6..d476e9fab14 100644 --- a/lib/private/connector/sabre/file.php +++ b/lib/private/connector/sabre/file.php @@ -64,7 +64,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D } // mark file as partial while uploading (ignored by the scanner) - $partpath = $this->path . '.part'; + $partpath = $this->path . rand() . '.part'; // if file is located in /Shared we write the part file to the users // root folder because we can't create new files in /shared -- cgit v1.2.3 From ae5671d2813f74562b77ae4288f01b4ed5ed52be Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Tue, 31 Dec 2013 14:36:02 +0100 Subject: new config parameter 'front_controller_active' which will instruct the url generator to generate urls without index.php --- lib/private/server.php | 5 +++-- lib/private/urlgenerator.php | 25 ++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) (limited to 'lib/private') diff --git a/lib/private/server.php b/lib/private/server.php index 77c3732a9ca..17565fafa46 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -120,7 +120,8 @@ class Server extends SimpleContainer implements IServerContainer { return new \OC\L10N\Factory(); }); $this->registerService('URLGenerator', function($c) { - return new \OC\URLGenerator(); + $config = $this->getConfig(); + return new \OC\URLGenerator($config); }); $this->registerService('AppHelper', function($c) { return new \OC\AppHelper(); @@ -249,7 +250,7 @@ class Server extends SimpleContainer implements IServerContainer { } /** - * @return \OC\Config + * @return \OCP\IConfig */ function getConfig() { return $this->query('AllConfig'); diff --git a/lib/private/urlgenerator.php b/lib/private/urlgenerator.php index 7795011fd06..4e3c1109000 100644 --- a/lib/private/urlgenerator.php +++ b/lib/private/urlgenerator.php @@ -15,6 +15,19 @@ use RuntimeException; * Class to generate URLs */ class URLGenerator implements IURLGenerator { + + /** + * @var \OCP\IConfig + */ + private $config; + + /** + * @param \OCP\IConfig $config + */ + public function __construct($config) { + $this->config = $config; + } + /** * @brief Creates an url using a defined route * @param $route @@ -41,12 +54,18 @@ class URLGenerator implements IURLGenerator { * Returns a url to the given app and file. */ public function linkTo( $app, $file, $args = array() ) { + $frontControllerActive=($this->config->getSystemValue('front_controller_active', 'false') == 'true'); + if( $app != '' ) { $app_path = \OC_App::getAppPath($app); // Check if the app is in the app folder if ($app_path && file_exists($app_path . '/' . $file)) { if (substr($file, -3) == 'php' || substr($file, -3) == 'css') { + $urlLinkTo = \OC::$WEBROOT . '/index.php/apps/' . $app; + if ($frontControllerActive) { + $urlLinkTo = \OC::$WEBROOT . '/apps/' . $app; + } $urlLinkTo .= ($file != 'index.php') ? '/' . $file : ''; } else { $urlLinkTo = \OC_App::getAppWebPath($app) . '/' . $file; @@ -58,7 +77,11 @@ class URLGenerator implements IURLGenerator { if (file_exists(\OC::$SERVERROOT . '/core/' . $file)) { $urlLinkTo = \OC::$WEBROOT . '/core/' . $file; } else { - $urlLinkTo = \OC::$WEBROOT . '/' . $file; + if ($frontControllerActive && $file === 'index.php') { + $urlLinkTo = \OC::$WEBROOT; + } else { + $urlLinkTo = \OC::$WEBROOT . '/' . $file; + } } } -- cgit v1.2.3 From 6254f0a403e315461f8e20ebccf71cb91e9313a3 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Tue, 31 Dec 2013 15:12:17 +0100 Subject: use getAppWebPath() in here as well --- lib/private/template/cssresourcelocator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/template/cssresourcelocator.php b/lib/private/template/cssresourcelocator.php index 8e7831ca549..e26daa25827 100644 --- a/lib/private/template/cssresourcelocator.php +++ b/lib/private/template/cssresourcelocator.php @@ -22,7 +22,7 @@ class CSSResourceLocator extends ResourceLocator { $app = substr($style, 0, strpos($style, '/')); $style = substr($style, strpos($style, '/')+1); $app_path = \OC_App::getAppPath($app); - $app_url = $this->webroot . '/index.php/apps/' . $app; + $app_url = \OC_App::getAppWebPath($app); if ($this->appendIfExist($app_path, $style.$this->form_factor.'.css', $app_url) || $this->appendIfExist($app_path, $style.'.css', $app_url) ) { -- cgit v1.2.3 From 1df1b55b66f0bcc696a1ee9aeb8362dee9889100 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 6 Jan 2014 12:55:56 +0100 Subject: expose memory cache in public api --- lib/private/server.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/private') diff --git a/lib/private/server.php b/lib/private/server.php index bee70dec2df..84ee8cadf04 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -136,6 +136,10 @@ class Server extends SimpleContainer implements IServerContainer { $this->registerService('UserCache', function($c) { return new UserCache(); }); + $this->registerService('MemCache', function ($c) { + $factory = new \OC\Memcache\Factory(); + return $factory->create(); + }); $this->registerService('ActivityManager', function($c) { return new ActivityManager(); }); @@ -295,6 +299,15 @@ class Server extends SimpleContainer implements IServerContainer { return $this->query('UserCache'); } + /** + * Returns an ICache instance + * + * @return \OCP\ICache + */ + function getMemCache() { + return $this->query('MemCache'); + } + /** * Returns the current session * -- cgit v1.2.3 From cd147bb37ae247082442f87b3cdd7d3d752e2d37 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 6 Jan 2014 12:58:43 +0100 Subject: Use APCIterator for Memcache\APC::clear() --- lib/private/memcache/apc.php | 27 ++++++++------------------- lib/private/memcache/apcu.php | 7 ------- 2 files changed, 8 insertions(+), 26 deletions(-) (limited to 'lib/private') diff --git a/lib/private/memcache/apc.php b/lib/private/memcache/apc.php index 575ee4427db..d5bc1498d65 100644 --- a/lib/private/memcache/apc.php +++ b/lib/private/memcache/apc.php @@ -9,15 +9,8 @@ namespace OC\Memcache; class APC extends Cache { - /** - * entries in APC gets namespaced to prevent collisions between owncloud instances and users - */ - protected function getNameSpace() { - return $this->prefix; - } - public function get($key) { - $result = apc_fetch($this->getNamespace() . $key, $success); + $result = apc_fetch($this->getPrefix() . $key, $success); if (!$success) { return null; } @@ -25,26 +18,22 @@ class APC extends Cache { } public function set($key, $value, $ttl = 0) { - return apc_store($this->getNamespace() . $key, $value, $ttl); + return apc_store($this->getPrefix() . $key, $value, $ttl); } public function hasKey($key) { - return apc_exists($this->getNamespace() . $key); + return apc_exists($this->getPrefix() . $key); } public function remove($key) { - return apc_delete($this->getNamespace() . $key); + return apc_delete($this->getPrefix() . $key); } public function clear($prefix = '') { - $ns = $this->getNamespace() . $prefix; - $cache = apc_cache_info('user'); - foreach ($cache['cache_list'] as $entry) { - if (strpos($entry['info'], $ns) === 0) { - apc_delete($entry['info']); - } - } - return true; + $ns = $this->getPrefix() . $prefix; + $ns = preg_quote($ns, '/'); + $iter = new \APCIterator('user', '/^' . $ns . '/'); + return apc_delete($iter); } static public function isAvailable() { diff --git a/lib/private/memcache/apcu.php b/lib/private/memcache/apcu.php index dac0f5f208a..7f780f32718 100644 --- a/lib/private/memcache/apcu.php +++ b/lib/private/memcache/apcu.php @@ -9,13 +9,6 @@ namespace OC\Memcache; class APCu extends APC { - public function clear($prefix = '') { - $ns = $this->getNamespace() . $prefix; - $ns = preg_quote($ns, '/'); - $iter = new \APCIterator('user', '/^'.$ns.'/'); - return apc_delete($iter); - } - static public function isAvailable() { if (!extension_loaded('apcu')) { return false; -- cgit v1.2.3 From 4d65a8089284e4dde09181b56fb45b86c50d6fb5 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 6 Jan 2014 13:11:38 +0100 Subject: Remove the static dependency on OC_Util from Memcache --- lib/private/memcache/cache.php | 2 +- lib/private/memcache/factory.php | 13 +++++++++++++ lib/private/server.php | 3 ++- lib/public/iservercontainer.php | 7 +++++++ 4 files changed, 23 insertions(+), 2 deletions(-) (limited to 'lib/private') diff --git a/lib/private/memcache/cache.php b/lib/private/memcache/cache.php index 0ad1cc7ec03..03671b3f240 100644 --- a/lib/private/memcache/cache.php +++ b/lib/private/memcache/cache.php @@ -18,7 +18,7 @@ abstract class Cache implements \ArrayAccess { * @param string $prefix */ public function __construct($prefix = '') { - $this->prefix = \OC_Util::getInstanceId() . '/' . $prefix; + $this->prefix = $prefix; } public function getPrefix() { diff --git a/lib/private/memcache/factory.php b/lib/private/memcache/factory.php index fde7d947567..48c97b59551 100644 --- a/lib/private/memcache/factory.php +++ b/lib/private/memcache/factory.php @@ -9,6 +9,18 @@ namespace OC\Memcache; class Factory { + /** + * @var string $globalPrefix + */ + private $globalPrefix; + + /** + * @param string $globalPrefix + */ + public function __construct($globalPrefix) { + $this->globalPrefix = $globalPrefix; + } + /** * get a cache instance, will return null if no backend is available * @@ -16,6 +28,7 @@ class Factory { * @return \OC\Memcache\Cache */ function create($prefix = '') { + $prefix = $this->globalPrefix . '/' . $prefix; if (XCache::isAvailable()) { return new XCache($prefix); } elseif (APCu::isAvailable()) { diff --git a/lib/private/server.php b/lib/private/server.php index 84ee8cadf04..6b242bddd01 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -137,7 +137,8 @@ class Server extends SimpleContainer implements IServerContainer { return new UserCache(); }); $this->registerService('MemCache', function ($c) { - $factory = new \OC\Memcache\Factory(); + $instanceId = \OC_Util::getInstanceId(); + $factory = new \OC\Memcache\Factory($instanceId); return $factory->create(); }); $this->registerService('ActivityManager', function($c) { diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index b958d2d03f4..7ac5049ef24 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -141,6 +141,13 @@ interface IServerContainer { */ function getCache(); + /** + * Returns an ICache instance + * + * @return \OCP\ICache + */ + function getMemCache(); + /** * Returns the current session * -- cgit v1.2.3 From ed469a7d2c11b92cad4446a596c2b27c2d46362b Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Tue, 7 Jan 2014 11:53:33 +0100 Subject: in order to work properly with encryption ocTransferId is added to the file path - questionable usage of magic string --- lib/private/connector/sabre/file.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php index d476e9fab14..53524ec9e54 100644 --- a/lib/private/connector/sabre/file.php +++ b/lib/private/connector/sabre/file.php @@ -64,7 +64,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D } // mark file as partial while uploading (ignored by the scanner) - $partpath = $this->path . rand() . '.part'; + $partpath = $this->path . '.ocTransferId' . rand() . '.part'; // if file is located in /Shared we write the part file to the users // root folder because we can't create new files in /shared -- cgit v1.2.3 From 07a84aa5ebc71c1476f89eb5736754b7a2f74d47 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Tue, 7 Jan 2014 14:52:18 +0100 Subject: reuse existing helper function OC_Helper::is_function_enabled --- lib/private/preview/movies.php | 2 +- lib/private/preview/office.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/private') diff --git a/lib/private/preview/movies.php b/lib/private/preview/movies.php index ac771deb413..71cd3bae057 100644 --- a/lib/private/preview/movies.php +++ b/lib/private/preview/movies.php @@ -18,7 +18,7 @@ function findBinaryPath($program) { // movie preview is currently not supported on Windows if (!\OC_Util::runningOnWindows()) { - $isExecEnabled = !in_array('exec', explode(', ', ini_get('disable_functions'))); + $isExecEnabled = \OC_Helper::is_function_enabled('exec'); $ffmpegBinary = null; $avconvBinary = null; diff --git a/lib/private/preview/office.php b/lib/private/preview/office.php index 318ab51f851..7a4826c76ec 100644 --- a/lib/private/preview/office.php +++ b/lib/private/preview/office.php @@ -7,7 +7,7 @@ */ //both, libreoffice backend and php fallback, need imagick if (extension_loaded('imagick')) { - $isShellExecEnabled = !in_array('shell_exec', explode(', ', ini_get('disable_functions'))); + $isShellExecEnabled = \OC_Helper::is_function_enabled('shell_exec'); // LibreOffice preview is currently not supported on Windows if (!\OC_Util::runningOnWindows()) { -- cgit v1.2.3 From 9d869ab5968b737531a0f0bb3c648d7ffe920341 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Tue, 7 Jan 2014 14:53:02 +0100 Subject: we shall explode on ',' only --- lib/private/helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/helper.php b/lib/private/helper.php index 4fe3097af26..a06932a11f9 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -858,7 +858,7 @@ class OC_Helper { if (!function_exists($function_name)) { return false; } - $disabled = explode(', ', ini_get('disable_functions')); + $disabled = explode(',', ini_get('disable_functions')); if (in_array($function_name, $disabled)) { return false; } -- cgit v1.2.3 From 9404a8f40c51f57309d3b5a3b5937f869d563573 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Tue, 7 Jan 2014 15:51:08 +0100 Subject: remove duplicate exe mimetype, add correct msi mimetype --- lib/private/mimetypes.list.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/private') diff --git a/lib/private/mimetypes.list.php b/lib/private/mimetypes.list.php index 740982910e0..08228336966 100644 --- a/lib/private/mimetypes.list.php +++ b/lib/private/mimetypes.list.php @@ -66,6 +66,7 @@ return array( 'xlsx'=>'application/msexcel', 'php'=>'application/x-php', 'exe'=>'application/x-ms-dos-executable', + 'msi'=>'application/x-msi', 'pl'=>'application/x-pearl', 'py'=>'application/x-python', 'blend'=>'application/x-blender', @@ -97,8 +98,6 @@ return array( 'ai' => 'application/illustrator', 'epub' => 'application/epub+zip', 'mobi' => 'application/x-mobipocket-ebook', - 'exe' => 'application', - 'msi' => 'application', 'md' => 'text/markdown', 'markdown' => 'text/markdown', 'mdown' => 'text/markdown', -- cgit v1.2.3 From 09d7882571e047de4ed907f0f0317dae056cf890 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Tue, 7 Jan 2014 19:47:01 +0100 Subject: trimming all array elements --- lib/private/helper.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/helper.php b/lib/private/helper.php index a06932a11f9..1c8d01c141f 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -859,10 +859,12 @@ class OC_Helper { return false; } $disabled = explode(',', ini_get('disable_functions')); + $disabled = array_map('trim', $disabled); if (in_array($function_name, $disabled)) { return false; } - $disabled = explode(', ', ini_get('suhosin.executor.func.blacklist')); + $disabled = explode(',', ini_get('suhosin.executor.func.blacklist')); + $disabled = array_map('trim', $disabled); if (in_array($function_name, $disabled)) { return false; } -- cgit v1.2.3 From 5be4af9f519ef8d0424f8b07ba84c43da9cf11f4 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Tue, 7 Jan 2014 17:41:04 +0100 Subject: Now also preventing to override "files" dir size with -1 Fixes #6526 --- lib/private/files/cache/homecache.php | 2 +- tests/lib/files/cache/homecache.php | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) (limited to 'lib/private') diff --git a/lib/private/files/cache/homecache.php b/lib/private/files/cache/homecache.php index 18dfbfe3191..71bb944da71 100644 --- a/lib/private/files/cache/homecache.php +++ b/lib/private/files/cache/homecache.php @@ -16,7 +16,7 @@ class HomeCache extends Cache { * @return int */ public function calculateFolderSize($path) { - if ($path !== '/' and $path !== '') { + if ($path !== '/' and $path !== '' and $path !== 'files') { return parent::calculateFolderSize($path); } diff --git a/tests/lib/files/cache/homecache.php b/tests/lib/files/cache/homecache.php index 2fa7f1ba92e..87fd0dba4c6 100644 --- a/tests/lib/files/cache/homecache.php +++ b/tests/lib/files/cache/homecache.php @@ -62,33 +62,39 @@ class HomeCache extends \PHPUnit_Framework_TestCase { } /** - * Tests that the root folder size calculation ignores the subdirs that have an unknown - * size. This makes sure that quota calculation still works as it's based on the root - * folder size. + * Tests that the root and files folder size calculation ignores the subdirs + * that have an unknown size. This makes sure that quota calculation still + * works as it's based on the "files" folder size. */ public function testRootFolderSizeIgnoresUnknownUpdate() { - $dir1 = 'knownsize'; - $dir2 = 'unknownsize'; + $dir1 = 'files/knownsize'; + $dir2 = 'files/unknownsize'; $fileData = array(); $fileData[''] = array('size' => -1, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory'); + $fileData['files'] = array('size' => -1, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory'); $fileData[$dir1] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory'); $fileData[$dir2] = array('size' => -1, 'mtime' => 25, 'mimetype' => 'httpd/unix-directory'); $this->cache->put('', $fileData['']); + $this->cache->put('files', $fileData['files']); $this->cache->put($dir1, $fileData[$dir1]); $this->cache->put($dir2, $fileData[$dir2]); + $this->assertTrue($this->cache->inCache('files')); $this->assertTrue($this->cache->inCache($dir1)); $this->assertTrue($this->cache->inCache($dir2)); - // check that root size ignored the unknown sizes + // check that files and root size ignored the unknown sizes + $this->assertEquals(1000, $this->cache->calculateFolderSize('files')); $this->assertEquals(1000, $this->cache->calculateFolderSize('')); // clean up $this->cache->remove(''); + $this->cache->remove('files'); $this->cache->remove($dir1); $this->cache->remove($dir2); + $this->assertFalse($this->cache->inCache('files')); $this->assertFalse($this->cache->inCache($dir1)); $this->assertFalse($this->cache->inCache($dir2)); } -- cgit v1.2.3 From 1e1ced777275c70307d26556843938e68ca25fde Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 7 Jan 2014 23:05:37 +0100 Subject: Introduce user count action to user management --- lib/private/user/backend.php | 16 +++++++++------- lib/private/user/database.php | 15 +++++++++++++++ lib/private/user/manager.php | 18 ++++++++++++++++++ 3 files changed, 42 insertions(+), 7 deletions(-) (limited to 'lib/private') diff --git a/lib/private/user/backend.php b/lib/private/user/backend.php index 02c93d13bdf..6969ce4ba34 100644 --- a/lib/private/user/backend.php +++ b/lib/private/user/backend.php @@ -31,13 +31,14 @@ define('OC_USER_BACKEND_NOT_IMPLEMENTED', -501); /** * actions that user backends can define */ -define('OC_USER_BACKEND_CREATE_USER', 0x0000001); -define('OC_USER_BACKEND_SET_PASSWORD', 0x0000010); -define('OC_USER_BACKEND_CHECK_PASSWORD', 0x0000100); -define('OC_USER_BACKEND_GET_HOME', 0x0001000); -define('OC_USER_BACKEND_GET_DISPLAYNAME', 0x0010000); -define('OC_USER_BACKEND_SET_DISPLAYNAME', 0x0100000); -define('OC_USER_BACKEND_PROVIDE_AVATAR', 0x1000000); +define('OC_USER_BACKEND_CREATE_USER', 0x00000001); +define('OC_USER_BACKEND_SET_PASSWORD', 0x00000010); +define('OC_USER_BACKEND_CHECK_PASSWORD', 0x00000100); +define('OC_USER_BACKEND_GET_HOME', 0x00001000); +define('OC_USER_BACKEND_GET_DISPLAYNAME', 0x00010000); +define('OC_USER_BACKEND_SET_DISPLAYNAME', 0x00100000); +define('OC_USER_BACKEND_PROVIDE_AVATAR', 0x01000000); +define('OC_USER_BACKEND_COUNT_USERS', 0x10000000); /** * Abstract base class for user management. Provides methods for querying backend @@ -55,6 +56,7 @@ abstract class OC_User_Backend implements OC_User_Interface { OC_USER_BACKEND_GET_DISPLAYNAME => 'getDisplayName', OC_USER_BACKEND_SET_DISPLAYNAME => 'setDisplayName', OC_USER_BACKEND_PROVIDE_AVATAR => 'canChangeAvatar', + OC_USER_BACKEND_COUNT_USERS => 'countUsers', ); /** diff --git a/lib/private/user/database.php b/lib/private/user/database.php index c99db3b27ca..1a63755b980 100644 --- a/lib/private/user/database.php +++ b/lib/private/user/database.php @@ -253,4 +253,19 @@ class OC_User_Database extends OC_User_Backend { return true; } + /** + * counts the users in the database + * + * @return int | bool + */ + public function countUsers() { + $query = OC_DB::prepare('SELECT COUNT(*) FROM `*PREFIX*users`'); + $result = $query->execute(); + if (OC_DB::isError($result)) { + OC_Log::write('core', OC_DB::getErrorMessage($result), OC_Log::ERROR); + return false; + } + return $result->fetchOne(); + } + } diff --git a/lib/private/user/manager.php b/lib/private/user/manager.php index cf83a75ba25..101b388f1e0 100644 --- a/lib/private/user/manager.php +++ b/lib/private/user/manager.php @@ -270,4 +270,22 @@ class Manager extends PublicEmitter { } return false; } + + /** + * returns how many users per backend exist (if supported by backend) + * + * @return array with backend class as key and count number as value + */ + public function countUsers() { + $userCountStatistics = array(); + foreach ($this->backends as $backend) { + if ($backend->implementsActions(\OC_USER_BACKEND_COUNT_USERS)) { + $backendusers = $backend->countUsers(); + if($backendusers !== false) { + $userCountStatistics[get_class($backend)] = $backendusers; + } + } + } + return $userCountStatistics; + } } -- cgit v1.2.3 From 5eef107344bbb3fc4a93675f6d3b63fc82ba930a Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Wed, 8 Jan 2014 07:56:08 +0100 Subject: turn off mod_pagespeed --- .htaccess | 3 +++ lib/private/setup.php | 3 +++ 2 files changed, 6 insertions(+) (limited to 'lib/private') diff --git a/.htaccess b/.htaccess index 08e2a82facb..fa6263c7ffe 100755 --- a/.htaccess +++ b/.htaccess @@ -38,3 +38,6 @@ DirectoryIndex index.php index.html AddDefaultCharset utf-8 Options -Indexes + + ModPagespeed Off + diff --git a/lib/private/setup.php b/lib/private/setup.php index b5c530a091f..5232398d1d7 100644 --- a/lib/private/setup.php +++ b/lib/private/setup.php @@ -159,6 +159,9 @@ class OC_Setup { $content.= "\n"; $content.= "AddDefaultCharset utf-8\n"; $content.= "Options -Indexes\n"; + $content.= "\n"; + $content.= "ModPagespeed Off\n"; + $content.= "\n"; @file_put_contents(OC::$SERVERROOT.'/.htaccess', $content); //supress errors in case we don't have permissions for it self::protectDataDirectory(); -- cgit v1.2.3 From f642ad39614970de67358d80517bc1d76a006e0e Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Wed, 8 Jan 2014 13:17:36 +0100 Subject: Prevent deleting storage root Storage mount points are not deletable, so make sure that the unlink operation and its hooks aren't run in such cases. Note that some storages might recursively delete their contents when calling unlink on their root. This fix prevents that as well. --- lib/private/files/view.php | 13 +++++++++++++ tests/lib/files/view.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) (limited to 'lib/private') diff --git a/lib/private/files/view.php b/lib/private/files/view.php index ac45a881331..8893911ed5d 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -336,6 +336,19 @@ class View { } public function unlink($path) { + if ($path === '' || $path === '/') { + // do not allow deleting the root + return false; + } + $postFix = (substr($path, -1, 1) === '/') ? '/' : ''; + $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path)); + list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix); + if (!$internalPath || $internalPath === '' || $internalPath === '/') { + // do not allow deleting the storage's root / the mount point + // because for some storages it might delete the whole contents + // but isn't supposed to work that way + return false; + } return $this->basicOperation('unlink', $path, array('delete')); } diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index b59cef9f0da..76a7fd5f1ca 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -306,6 +306,48 @@ class View extends \PHPUnit_Framework_TestCase { $this->assertTrue($rootView->file_exists('anotherfolder/bar.txt')); } + /** + * @medium + */ + function testUnlink() { + $storage1 = $this->getTestStorage(); + $storage2 = $this->getTestStorage(); + \OC\Files\Filesystem::mount($storage1, array(), '/'); + \OC\Files\Filesystem::mount($storage2, array(), '/substorage'); + + $rootView = new \OC\Files\View(''); + $rootView->file_put_contents('/foo.txt', 'asd'); + $rootView->file_put_contents('/substorage/bar.txt', 'asd'); + + $this->assertTrue($rootView->file_exists('foo.txt')); + $this->assertTrue($rootView->file_exists('substorage/bar.txt')); + + $this->assertTrue($rootView->unlink('foo.txt')); + $this->assertTrue($rootView->unlink('substorage/bar.txt')); + + $this->assertFalse($rootView->file_exists('foo.txt')); + $this->assertFalse($rootView->file_exists('substorage/bar.txt')); + } + + /** + * @medium + */ + function testUnlinkRootMustFail() { + $storage1 = $this->getTestStorage(); + $storage2 = $this->getTestStorage(); + \OC\Files\Filesystem::mount($storage1, array(), '/'); + \OC\Files\Filesystem::mount($storage2, array(), '/substorage'); + + $rootView = new \OC\Files\View(''); + $rootView->file_put_contents('/foo.txt', 'asd'); + $rootView->file_put_contents('/substorage/bar.txt', 'asd'); + + $this->assertFalse($rootView->unlink('')); + $this->assertFalse($rootView->unlink('/')); + $this->assertFalse($rootView->unlink('substorage')); + $this->assertFalse($rootView->unlink('/substorage')); + } + /** * @medium */ -- cgit v1.2.3 From cb6a3e2617c6549d4a305f3612bef8aa5840306e Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 8 Jan 2014 13:24:28 +0100 Subject: if backends have the same class name, sum their users up instead of overwriting --- lib/private/user/manager.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/user/manager.php b/lib/private/user/manager.php index 101b388f1e0..90970ef9963 100644 --- a/lib/private/user/manager.php +++ b/lib/private/user/manager.php @@ -282,7 +282,11 @@ class Manager extends PublicEmitter { if ($backend->implementsActions(\OC_USER_BACKEND_COUNT_USERS)) { $backendusers = $backend->countUsers(); if($backendusers !== false) { - $userCountStatistics[get_class($backend)] = $backendusers; + if(isset($userCountStatistics[get_class($backend)])) { + $userCountStatistics[get_class($backend)] += $backendusers; + } else { + $userCountStatistics[get_class($backend)] = $backendusers; + } } } } -- cgit v1.2.3 From d7cb5ab080e2b3abe804ffe974ebb65398914943 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 8 Jan 2014 13:26:48 +0100 Subject: add tests for user counting --- lib/private/user/dummy.php | 9 ++++++ tests/lib/user/manager.php | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) (limited to 'lib/private') diff --git a/lib/private/user/dummy.php b/lib/private/user/dummy.php index 52be7edfa75..fc15a630cf3 100644 --- a/lib/private/user/dummy.php +++ b/lib/private/user/dummy.php @@ -123,4 +123,13 @@ class OC_User_Dummy extends OC_User_Backend { public function hasUserListings() { return true; } + + /** + * counts the users in the database + * + * @return int | bool + */ + public function countUsers() { + return 0; + } } diff --git a/tests/lib/user/manager.php b/tests/lib/user/manager.php index 00901dd4115..ad1ac9e12f2 100644 --- a/tests/lib/user/manager.php +++ b/tests/lib/user/manager.php @@ -346,4 +346,76 @@ class Manager extends \PHPUnit_Framework_TestCase { $manager->createUser('foo', 'bar'); } + + public function testCountUsersNoBackend() { + $manager = new \OC\User\Manager(); + + $result = $manager->countUsers(); + $this->assertTrue(is_array($result)); + $this->assertTrue(empty($result)); + } + + public function testCountUsersOneBackend() { + /** + * @var \OC_User_Dummy | \PHPUnit_Framework_MockObject_MockObject $backend + */ + $backend = $this->getMock('\OC_User_Dummy'); + $backend->expects($this->once()) + ->method('countUsers') + ->will($this->returnValue(7)); + + $backend->expects($this->once()) + ->method('implementsActions') + ->with(\OC_USER_BACKEND_COUNT_USERS) + ->will($this->returnValue(true)); + + $manager = new \OC\User\Manager(); + $manager->registerBackend($backend); + + $result = $manager->countUsers(); + $keys = array_keys($result); + $this->assertTrue(strpos($keys[0], 'Mock_OC_User_Dummy') !== false); + + $users = array_shift($result); + $this->assertEquals(7, $users); + } + + public function testCountUsersTwoBackends() { + /** + * @var \OC_User_Dummy | \PHPUnit_Framework_MockObject_MockObject $backend + */ + $backend1 = $this->getMock('\OC_User_Dummy'); + $backend1->expects($this->once()) + ->method('countUsers') + ->will($this->returnValue(7)); + + $backend1->expects($this->once()) + ->method('implementsActions') + ->with(\OC_USER_BACKEND_COUNT_USERS) + ->will($this->returnValue(true)); + + $backend2 = $this->getMock('\OC_User_Dummy'); + $backend2->expects($this->once()) + ->method('countUsers') + ->will($this->returnValue(16)); + + $backend2->expects($this->once()) + ->method('implementsActions') + ->with(\OC_USER_BACKEND_COUNT_USERS) + ->will($this->returnValue(true)); + + $manager = new \OC\User\Manager(); + $manager->registerBackend($backend1); + $manager->registerBackend($backend2); + + $result = $manager->countUsers(); + //because the backends have the same class name, only one value expected + $this->assertEquals(1, count($result)); + $keys = array_keys($result); + $this->assertTrue(strpos($keys[0], 'Mock_OC_User_Dummy') !== false); + + $users = array_shift($result); + //users from backends shall be summed up + $this->assertEquals(7+16, $users); + } } -- cgit v1.2.3 From be7837402d55abc9a6dc801c943c9b642e821dd0 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 8 Jan 2014 15:18:12 +0100 Subject: get the memorycache factory from OCP\Server instead of a cache instance this allows apps to specify a prefix to use --- lib/private/server.php | 11 +++++------ lib/public/cachefactory.php | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 lib/public/cachefactory.php (limited to 'lib/private') diff --git a/lib/private/server.php b/lib/private/server.php index 6b242bddd01..b5fa9148626 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -136,10 +136,9 @@ class Server extends SimpleContainer implements IServerContainer { $this->registerService('UserCache', function($c) { return new UserCache(); }); - $this->registerService('MemCache', function ($c) { + $this->registerService('MemCacheFactory', function ($c) { $instanceId = \OC_Util::getInstanceId(); - $factory = new \OC\Memcache\Factory($instanceId); - return $factory->create(); + return new \OC\Memcache\Factory($instanceId); }); $this->registerService('ActivityManager', function($c) { return new ActivityManager(); @@ -303,10 +302,10 @@ class Server extends SimpleContainer implements IServerContainer { /** * Returns an ICache instance * - * @return \OCP\ICache + * @return \OCP\CacheFactory */ - function getMemCache() { - return $this->query('MemCache'); + function getMemCacheFactory() { + return $this->query('MemCacheFactory'); } /** diff --git a/lib/public/cachefactory.php b/lib/public/cachefactory.php new file mode 100644 index 00000000000..bb49aea7f3a --- /dev/null +++ b/lib/public/cachefactory.php @@ -0,0 +1,17 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCP; + +interface CacheFactory{ + /** + * @param string $prefix + * @return $return \OCP\ICache + */ + public function create($prefix = ''); +} -- cgit v1.2.3 From 5a2a0426a6c01cffe88c80e0529931a323c699d9 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 8 Jan 2014 15:51:40 +0100 Subject: Also update the OCP\IServerContainer --- lib/private/server.php | 2 +- lib/public/iservercontainer.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/private') diff --git a/lib/private/server.php b/lib/private/server.php index b5fa9148626..6b034a5be9f 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -300,7 +300,7 @@ class Server extends SimpleContainer implements IServerContainer { } /** - * Returns an ICache instance + * Returns an \OCP\CacheFactory instance * * @return \OCP\CacheFactory */ diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index 7ac5049ef24..67884bdc3e4 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -142,11 +142,11 @@ interface IServerContainer { function getCache(); /** - * Returns an ICache instance + * Returns an \OCP\CacheFactory instance * - * @return \OCP\ICache + * @return \OCP\CacheFactory */ - function getMemCache(); + function getMemCacheFactory(); /** * Returns the current session -- cgit v1.2.3 From e35bca1c266cbe1468da9b4a328e2521d00c30f2 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Wed, 8 Jan 2014 16:07:01 +0100 Subject: Fix ownCloud for php5.3.x --- lib/private/server.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/server.php b/lib/private/server.php index 5977ee9b5a0..2cbd37a97d7 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -128,7 +128,8 @@ class Server extends SimpleContainer implements IServerContainer { return new \OC\L10N\Factory(); }); $this->registerService('URLGenerator', function($c) { - $config = $this->getConfig(); + /** @var $c SimpleContainer */ + $config = $c->query('AllConfig'); return new \OC\URLGenerator($config); }); $this->registerService('AppHelper', function($c) { -- cgit v1.2.3 From 8eaa39f4e2fb7bb1036aca5727db320de00960e2 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Wed, 8 Jan 2014 18:43:20 +0100 Subject: Removed special handling of part files in shared storage rename This fixes the issue introduced by the transfer id which itself wasn't taken into account by the shortcut code for part file in the shared storage class. --- apps/files_sharing/lib/sharedstorage.php | 33 ++++++++++++-------------------- lib/private/connector/sabre/file.php | 5 ++++- 2 files changed, 16 insertions(+), 22 deletions(-) (limited to 'lib/private') diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index 3116cd717fb..6b4db9763f5 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -293,29 +293,20 @@ class Shared extends \OC\Files\Storage\Common { } public function rename($path1, $path2) { - // Check for partial files - if (pathinfo($path1, PATHINFO_EXTENSION) === 'part') { - if ($oldSource = $this->getSourcePath($path1)) { + // Renaming/moving is only allowed within shared folders + $pos1 = strpos($path1, '/', 1); + $pos2 = strpos($path2, '/', 1); + if ($pos1 !== false && $pos2 !== false && ($oldSource = $this->getSourcePath($path1))) { + $newSource = $this->getSourcePath(dirname($path2)) . '/' . basename($path2); + // Within the same folder, we only need UPDATE permissions + if (dirname($path1) == dirname($path2) and $this->isUpdatable($path1)) { list($storage, $oldInternalPath) = \OC\Files\Filesystem::resolvePath($oldSource); - $newInternalPath = substr($oldInternalPath, 0, -5); + list(, $newInternalPath) = \OC\Files\Filesystem::resolvePath($newSource); return $storage->rename($oldInternalPath, $newInternalPath); - } - } else { - // Renaming/moving is only allowed within shared folders - $pos1 = strpos($path1, '/', 1); - $pos2 = strpos($path2, '/', 1); - if ($pos1 !== false && $pos2 !== false && ($oldSource = $this->getSourcePath($path1))) { - $newSource = $this->getSourcePath(dirname($path2)) . '/' . basename($path2); - // Within the same folder, we only need UPDATE permissions - if (dirname($path1) == dirname($path2) and $this->isUpdatable($path1)) { - list($storage, $oldInternalPath) = \OC\Files\Filesystem::resolvePath($oldSource); - list(, $newInternalPath) = \OC\Files\Filesystem::resolvePath($newSource); - return $storage->rename($oldInternalPath, $newInternalPath); - // otherwise DELETE and CREATE permissions required - } elseif ($this->isDeletable($path1) && $this->isCreatable(dirname($path2))) { - $rootView = new \OC\Files\View(''); - return $rootView->rename($oldSource, $newSource); - } + // otherwise DELETE and CREATE permissions required + } elseif ($this->isDeletable($path1) && $this->isCreatable(dirname($path2))) { + $rootView = new \OC\Files\View(''); + return $rootView->rename($oldSource, $newSource); } } return false; diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php index 53524ec9e54..c3b59007295 100644 --- a/lib/private/connector/sabre/file.php +++ b/lib/private/connector/sabre/file.php @@ -242,7 +242,10 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D $fileExists = $fs->file_exists($targetPath); if ($renameOkay === false || $fileExists === false) { \OC_Log::write('webdav', '\OC\Files\Filesystem::rename() failed', \OC_Log::ERROR); - $fs->unlink($targetPath); + // only delete if an error occurred and the target file was already created + if ($fileExists) { + $fs->unlink($targetPath); + } throw new Sabre_DAV_Exception(); } -- cgit v1.2.3 From 4585b4ea3f1fd21aabc167102e74a382dfa0cbd8 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 8 Jan 2014 19:41:10 +0100 Subject: Infowarning about 32bit --- lib/private/user/backend.php | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/private') diff --git a/lib/private/user/backend.php b/lib/private/user/backend.php index 6969ce4ba34..f4e5618e04a 100644 --- a/lib/private/user/backend.php +++ b/lib/private/user/backend.php @@ -39,6 +39,7 @@ define('OC_USER_BACKEND_GET_DISPLAYNAME', 0x00010000); define('OC_USER_BACKEND_SET_DISPLAYNAME', 0x00100000); define('OC_USER_BACKEND_PROVIDE_AVATAR', 0x01000000); define('OC_USER_BACKEND_COUNT_USERS', 0x10000000); +//more actions cannot be defined without breaking 32bit platforms! /** * Abstract base class for user management. Provides methods for querying backend -- cgit v1.2.3 From 9b7c3a5c66a9f987ff572aaece2ef6e895bf4ab6 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Thu, 9 Jan 2014 10:27:47 +0100 Subject: fixing PHPDoc and use cameCase names --- lib/private/user/session.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/private') diff --git a/lib/private/user/session.php b/lib/private/user/session.php index c2885d00413..1e299416fb3 100644 --- a/lib/private/user/session.php +++ b/lib/private/user/session.php @@ -115,13 +115,13 @@ class Session implements Emitter, \OCP\IUserSession { /** * set the login name * - * @param string login name for the logged in user + * @param string $loginName for the logged in user */ - public function setLoginname($loginname) { - if (is_null($loginname)) { + public function setLoginName($loginName) { + if (is_null($loginName)) { $this->session->remove('loginname'); } else { - $this->session->set('loginname', $loginname); + $this->session->set('loginname', $loginName); } } @@ -130,7 +130,7 @@ class Session implements Emitter, \OCP\IUserSession { * * @return string */ - public function getLoginname() { + public function getLoginName() { if ($this->activeUser) { return $this->session->get('loginname'); } else { @@ -158,7 +158,7 @@ class Session implements Emitter, \OCP\IUserSession { if (!is_null($user)) { if ($user->isEnabled()) { $this->setUser($user); - $this->setLoginname($uid); + $this->setLoginName($uid); $this->manager->emit('\OC\User', 'postLogin', array($user, $password)); return true; } else { @@ -176,7 +176,7 @@ class Session implements Emitter, \OCP\IUserSession { public function logout() { $this->manager->emit('\OC\User', 'logout'); $this->setUser(null); - $this->setLoginname(null); + $this->setLoginName(null); $this->unsetMagicInCookie(); } -- cgit v1.2.3 From 22bd69f75cc91a79653038d20143aff9ee8b226a Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Thu, 9 Jan 2014 10:28:24 +0100 Subject: set login name within apache auth backend --- lib/private/user.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/private') diff --git a/lib/private/user.php b/lib/private/user.php index e0d6b9f3f51..98ebebbe5c1 100644 --- a/lib/private/user.php +++ b/lib/private/user.php @@ -246,6 +246,8 @@ class OC_User { session_regenerate_id(true); self::setUserId($uid); self::setDisplayName($uid); + self::getUserSession()->setLoginName($uid); + OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid, 'password'=>'' )); return true; } -- cgit v1.2.3 From 4faba49f0a38427e96ef8393900f799c5a5ba6aa Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 9 Jan 2014 17:27:55 +0100 Subject: Fix calculated folder size to use unencrypted size The encrypted size was used when calculating folder sizes. This fix now also sums up the unencrypted size and shows that one when available. --- lib/private/files/cache/cache.php | 22 ++++++++++++++----- tests/lib/files/cache/cache.php | 45 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 5 deletions(-) (limited to 'lib/private') diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php index 8e682a96b75..1e7936ca26d 100644 --- a/lib/private/files/cache/cache.php +++ b/lib/private/files/cache/cache.php @@ -178,7 +178,7 @@ class Cache { if ($file['storage_mtime'] == 0) { $file['storage_mtime'] = $file['mtime']; } - if ($file['encrypted']) { + if ($file['encrypted'] or ($file['unencrypted_size'] > 0 and $file['mimetype'] === 'httpd/unix-directory')) { $file['encrypted_size'] = $file['size']; $file['size'] = $file['unencrypted_size']; } @@ -511,22 +511,34 @@ class Cache { $entry = $this->get($path); if ($entry && $entry['mimetype'] === 'httpd/unix-directory') { $id = $entry['fileid']; - $sql = 'SELECT SUM(`size`) AS f1, MIN(`size`) AS f2 FROM `*PREFIX*filecache` '. + $sql = 'SELECT SUM(`size`) AS f1, MIN(`size`) AS f2, ' . + 'SUM(`unencrypted_size`) AS f3 ' . + 'FROM `*PREFIX*filecache` ' . 'WHERE `parent` = ? AND `storage` = ?'; $result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId())); if ($row = $result->fetchRow()) { - list($sum, $min) = array_values($row); + list($sum, $min, $unencryptedSum) = array_values($row); $sum = (int)$sum; $min = (int)$min; + $unencryptedSum = (int)$unencryptedSum; if ($min === -1) { $totalSize = $min; } else { $totalSize = $sum; } + $update = array(); if ($entry['size'] !== $totalSize) { - $this->update($id, array('size' => $totalSize)); + $update['size'] = $totalSize; + } + if ($entry['unencrypted_size'] !== $unencryptedSum) { + $update['unencrypted_size'] = $unencryptedSum; + } + if (count($update) > 0) { + $this->update($id, $update); + } + if ($totalSize !== -1 and $unencryptedSum > 0) { + $totalSize = $unencryptedSum; } - } } return $totalSize; diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php index 052d70dd0b4..7d9329328a3 100644 --- a/tests/lib/files/cache/cache.php +++ b/tests/lib/files/cache/cache.php @@ -137,6 +137,51 @@ class Cache extends \PHPUnit_Framework_TestCase { $this->assertFalse($this->cache->inCache('folder/bar')); } + public function testEncryptedFolder() { + $file1 = 'folder'; + $file2 = 'folder/bar'; + $file3 = 'folder/foo'; + $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'); + $fileData = array(); + $fileData['bar'] = array('size' => 1000, 'unencrypted_size' => 900, 'encrypted' => 1, 'mtime' => 20, 'mimetype' => 'foo/file'); + $fileData['foo'] = array('size' => 20, 'unencrypted_size' => 16, 'encrypted' => 1, 'mtime' => 25, 'mimetype' => 'foo/file'); + + $this->cache->put($file1, $data1); + $this->cache->put($file2, $fileData['bar']); + $this->cache->put($file3, $fileData['foo']); + + $content = $this->cache->getFolderContents($file1); + $this->assertEquals(count($content), 2); + foreach ($content as $cachedData) { + $data = $fileData[$cachedData['name']]; + // indirect retrieval swaps unencrypted_size and size + $this->assertEquals($data['unencrypted_size'], $cachedData['size']); + } + + $file4 = 'folder/unkownSize'; + $fileData['unkownSize'] = array('size' => -1, 'mtime' => 25, 'mimetype' => 'foo/file'); + $this->cache->put($file4, $fileData['unkownSize']); + + $this->assertEquals(-1, $this->cache->calculateFolderSize($file1)); + + $fileData['unkownSize'] = array('size' => 5, 'mtime' => 25, 'mimetype' => 'foo/file'); + $this->cache->put($file4, $fileData['unkownSize']); + + $this->assertEquals(916, $this->cache->calculateFolderSize($file1)); + // direct cache entry retrieval returns the original values + $this->assertEquals(1025, $this->cache->get($file1)['size']); + $this->assertEquals(916, $this->cache->get($file1)['unencrypted_size']); + + $this->cache->remove($file2); + $this->cache->remove($file3); + $this->cache->remove($file4); + $this->assertEquals(0, $this->cache->calculateFolderSize($file1)); + + $this->cache->remove('folder'); + $this->assertFalse($this->cache->inCache('folder/foo')); + $this->assertFalse($this->cache->inCache('folder/bar')); + } + public function testRootFolderSizeForNonHomeStorage() { $dir1 = 'knownsize'; $dir2 = 'unknownsize'; -- cgit v1.2.3 From 320353c237fbee2d9a8f12dd474feb3a0f6ddec6 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 9 Dec 2013 01:34:31 +0100 Subject: Add support for multiple memcached servers. --- config/config.sample.php | 10 ++++++++-- lib/private/memcache/memcached.php | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'lib/private') diff --git a/config/config.sample.php b/config/config.sample.php index 1070ef72eda..67152accc3b 100755 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -114,8 +114,14 @@ $CONFIG = array( /* Password to use for sendmail mail, depends on mail_smtpauth if this is used */ "mail_smtppassword" => "", -/* memcached hostname and port (Only used when xCache, APC and APCu are absent.) */ -"memcached_server" => array('localhost', 11211), +/* memcached servers (Only used when xCache, APC and APCu are absent.) */ +"memcached_servers" => array( + // hostname, port and optional weight. Also see: + // http://www.php.net/manual/en/memcached.addservers.php + // http://www.php.net/manual/en/memcached.addserver.php + array('localhost', 11211), + //array('other.host.local', 11211), +), /* How long should ownCloud keep deleted files in the trash bin, default value: 30 days */ 'trashbin_retention_obligation' => 30, diff --git a/lib/private/memcache/memcached.php b/lib/private/memcache/memcached.php index 978e6c2eff1..13b1867231a 100644 --- a/lib/private/memcache/memcached.php +++ b/lib/private/memcache/memcached.php @@ -18,8 +18,8 @@ class Memcached extends Cache { parent::__construct($prefix); if (is_null(self::$cache)) { self::$cache = new \Memcached(); - list($host, $port) = \OC_Config::getValue('memcached_server', array('localhost', 11211)); - self::$cache->addServer($host, $port); + $servers = \OC_Config::getValue('memcached_servers', array(array('localhost', 11211))); + self::$cache->addServers($servers); } } -- cgit v1.2.3 From acd81f6c694373a18a0ee9ba29075b9924603c25 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 10 Jan 2014 00:57:40 +0100 Subject: Readd support for memcached_server config variable. --- lib/private/memcache/memcached.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/memcache/memcached.php b/lib/private/memcache/memcached.php index 13b1867231a..075828eebad 100644 --- a/lib/private/memcache/memcached.php +++ b/lib/private/memcache/memcached.php @@ -18,7 +18,15 @@ class Memcached extends Cache { parent::__construct($prefix); if (is_null(self::$cache)) { self::$cache = new \Memcached(); - $servers = \OC_Config::getValue('memcached_servers', array(array('localhost', 11211))); + $servers = \OC_Config::getValue('memcached_servers'); + if (!$servers) { + $server = \OC_Config::getValue('memcached_server'); + if ($server) { + $servers = array($server); + } else { + $servers = array(array('localhost', 11211)); + } + } self::$cache->addServers($servers); } } -- cgit v1.2.3 From 2abea964625713180d811e4fd1cfd25a92ee2c88 Mon Sep 17 00:00:00 2001 From: Joan Date: Fri, 10 Jan 2014 09:33:35 +0100 Subject: Disabled internet checking as mentioned when in proxy mode --- lib/private/util.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/private') diff --git a/lib/private/util.php b/lib/private/util.php index c0e618cc863..9b37dccb507 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -892,6 +892,11 @@ class OC_Util { return false; } + // in case the connection is via proxy return true to avoid connecting to owncloud.org + if(OC_Config::getValue('proxy', '') != '') { + return true; + } + // try to connect to owncloud.org to see if http connections to the internet are possible. $connected = @fsockopen("www.owncloud.org", 80); if ($connected) { -- cgit v1.2.3 From 6f21da12e8c953bebdbd444460b07160821ba7a8 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Sat, 11 Jan 2014 12:07:28 +0100 Subject: encode imagePath and fix documentation of loadFromFile --- lib/private/image.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/private') diff --git a/lib/private/image.php b/lib/private/image.php index 314a4216b82..91a9f91e1d6 100644 --- a/lib/private/image.php +++ b/lib/private/image.php @@ -409,14 +409,14 @@ class OC_Image { /** * @brief Loads an image from a local file. - * @param $imageref The path to a local file. + * @param $imagePath The path to a local file. * @returns An image resource or false on error */ public function loadFromFile($imagePath=false) { // exif_imagetype throws "read error!" if file is less than 12 byte if(!@is_file($imagePath) || !file_exists($imagePath) || filesize($imagePath) < 12 || !is_readable($imagePath)) { // Debug output disabled because this method is tried before loadFromBase64? - OC_Log::write('core', 'OC_Image->loadFromFile, couldn\'t load: ' . (string) $imagePath, OC_Log::DEBUG); + OC_Log::write('core', 'OC_Image->loadFromFile, couldn\'t load: ' . (string) urlencode($imagePath), OC_Log::DEBUG); return false; } $iType = exif_imagetype($imagePath); -- cgit v1.2.3 From a2cae551f30a0166439af9d467134d4bd802e940 Mon Sep 17 00:00:00 2001 From: st3so Date: Sun, 12 Jan 2014 15:45:33 +0100 Subject: fixing typo in redirection query string --- lib/private/util.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/util.php b/lib/private/util.php index c0e618cc863..a4b3761dbd3 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -580,7 +580,7 @@ class OC_Util { // Check if we are a user if( !OC_User::isLoggedIn()) { header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php', - array('redirectUrl' => OC_Request::requestUri()) + array('redirect_url' => OC_Request::requestUri()) )); exit(); } -- cgit v1.2.3 From 68458604703eab0283dc9e4c2c8b3dd1f97aaaef Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 13 Jan 2014 12:27:05 +0100 Subject: keep response message --- lib/private/api.php | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'lib/private') diff --git a/lib/private/api.php b/lib/private/api.php index 03d7b7382a5..c713368125c 100644 --- a/lib/private/api.php +++ b/lib/private/api.php @@ -33,7 +33,7 @@ class OC_API { const USER_AUTH = 1; const SUBADMIN_AUTH = 2; const ADMIN_AUTH = 3; - + /** * API Response Codes */ @@ -41,13 +41,13 @@ class OC_API { const RESPOND_SERVER_ERROR = 996; const RESPOND_NOT_FOUND = 998; const RESPOND_UNKNOWN_ERROR = 999; - + /** * api actions */ protected static $actions = array(); private static $logoutRequired = false; - + /** * registers an api call * @param string $method the http method @@ -58,7 +58,7 @@ class OC_API { * @param array $defaults * @param array $requirements */ - public static function register($method, $url, $action, $app, + public static function register($method, $url, $action, $app, $authLevel = OC_API::USER_AUTH, $defaults = array(), $requirements = array()) { @@ -75,7 +75,7 @@ class OC_API { } self::$actions[$name][] = array('app' => $app, 'action' => $action, 'authlevel' => $authLevel); } - + /** * handles an api call * @param array $parameters @@ -125,7 +125,7 @@ class OC_API { self::respond($response, $format); } - + /** * merge the returned result objects into one response * @param array $responses @@ -166,32 +166,31 @@ class OC_API { // Maybe any that are not OC_API::RESPOND_SERVER_ERROR // Merge failed responses if more than one $data = array(); - $meta = array(); foreach($shipped['failed'] as $failure) { $data = array_merge_recursive($data, $failure['response']->getData()); } $picked = reset($shipped['failed']); $code = $picked['response']->getStatusCode(); - $response = new OC_OCS_Result($data, $code); + $meta = $picked['response']->getMeta(); + $response = new OC_OCS_Result($data, $code, $meta['message']); return $response; } elseif(!empty($shipped['succeeded'])) { $responses = array_merge($shipped['succeeded'], $thirdparty['succeeded']); } elseif(!empty($thirdparty['failed'])) { // Merge failed responses if more than one $data = array(); - $meta = array(); foreach($thirdparty['failed'] as $failure) { $data = array_merge_recursive($data, $failure['response']->getData()); } $picked = reset($thirdparty['failed']); $code = $picked['response']->getStatusCode(); - $response = new OC_OCS_Result($data, $code); + $meta = $picked['response']->getMeta(); + $response = new OC_OCS_Result($data, $code, $meta['message']); return $response; } else { $responses = $thirdparty['succeeded']; } // Merge the successful responses - $meta = array(); $data = array(); foreach($responses as $app => $response) { @@ -200,22 +199,25 @@ class OC_API { } else { $data = array_merge_recursive($data, $response['response']->getData()); } - $codes[] = $response['response']->getStatusCode(); + $codes[] = array('code' => $response['response']->getStatusCode(), + 'meta' => $response['response']->getMeta()); } // Use any non 100 status codes $statusCode = 100; + $statusMessage = null; foreach($codes as $code) { - if($code != 100) { - $statusCode = $code; + if($code['code'] != 100) { + $statusCode = $code['code']; + $statusMessage = $code['meta']['message']; break; } } - $result = new OC_OCS_Result($data, $statusCode); + $result = new OC_OCS_Result($data, $statusCode, $statusMessage); return $result; } - + /** * authenticate the api call * @param array $action the action details as supplied to OC_API::register() @@ -261,8 +263,8 @@ class OC_API { return false; break; } - } - + } + /** * http basic auth * @return string|false (username, or false on failure) @@ -294,7 +296,7 @@ class OC_API { return false; } - + /** * respond to a call * @param OC_OCS_Result $result @@ -343,5 +345,5 @@ class OC_API { } } } - + } -- cgit v1.2.3 From 203d5d01cabae52373f556d50f2bb541560eb4b0 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 14 Jan 2014 13:54:07 +0100 Subject: Use storage_mtime when determining if we can reuse cached data while scanning --- lib/private/files/cache/scanner.php | 2 +- tests/lib/files/cache/updater.php | 2 +- tests/lib/files/etagtest.php | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) (limited to 'lib/private') diff --git a/lib/private/files/cache/scanner.php b/lib/private/files/cache/scanner.php index a8c069ee99f..92a4c01841b 100644 --- a/lib/private/files/cache/scanner.php +++ b/lib/private/files/cache/scanner.php @@ -122,7 +122,7 @@ class Scanner extends BasicEmitter { $propagateETagChange = true; } // only reuse data if the file hasn't explicitly changed - if (isset($data['mtime']) && isset($cacheData['mtime']) && $data['mtime'] === $cacheData['mtime']) { + if (isset($data['storage_mtime']) && isset($cacheData['storage_mtime']) && $data['storage_mtime'] === $cacheData['storage_mtime']) { if (($reuseExisting & self::REUSE_SIZE) && ($data['size'] === -1)) { $data['size'] = $cacheData['size']; } diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php index 91e384e12af..ba103cee675 100644 --- a/tests/lib/files/cache/updater.php +++ b/tests/lib/files/cache/updater.php @@ -88,7 +88,7 @@ class Updater extends \PHPUnit_Framework_TestCase { public function testWrite() { $textSize = strlen("dummy file data\n"); $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png'); - $this->cache->put('foo.txt', array('mtime' => 100)); + $this->cache->put('foo.txt', array('mtime' => 100, 'storage_mtime' => 100)); $rootCachedData = $this->cache->get(''); $this->assertEquals(3 * $textSize + $imageSize, $rootCachedData['size']); diff --git a/tests/lib/files/etagtest.php b/tests/lib/files/etagtest.php index 6c41413c4df..14003896d66 100644 --- a/tests/lib/files/etagtest.php +++ b/tests/lib/files/etagtest.php @@ -11,6 +11,12 @@ namespace Test\Files; use OC\Files\Filesystem; use OCP\Share; +class TemporaryNoTouch extends \OC\Files\Storage\Temporary { + public function touch($path, $mtime = null) { + return false; + } +} + class EtagTest extends \PHPUnit_Framework_TestCase { private $datadir; @@ -68,6 +74,23 @@ class EtagTest extends \PHPUnit_Framework_TestCase { $this->assertEquals($originalEtags, $this->getEtags($files)); } + public function testTouchNotSupported() { + $storage = new TemporaryNoTouch(array()); + $scanner = $storage->getScanner(); + Filesystem::mount($storage, array(), '/test/'); + $past = time() - 100; + $storage->file_put_contents('test', 'foobar'); + $scanner->scan(''); + $view = new \OC\Files\View(''); + $info = $view->getFileInfo('/test/test'); + + $view->touch('/test/test', $past); + $scanner->scanFile('test', \OC\Files\Cache\Scanner::REUSE_ETAG); + + $info2 = $view->getFileInfo('/test/test'); + $this->assertEquals($info['etag'], $info2['etag']); + } + private function getEtags($files) { $etags = array(); foreach ($files as $file) { -- cgit v1.2.3 From 7f68497b39db9528975862a091effe03fc802f91 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Wed, 15 Jan 2014 17:11:29 +0100 Subject: error handling in case a requested app doesn't exists --- lib/private/installer.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/private') diff --git a/lib/private/installer.php b/lib/private/installer.php index 8375b231e9b..835b6b4c01a 100644 --- a/lib/private/installer.php +++ b/lib/private/installer.php @@ -407,6 +407,9 @@ class OC_Installer{ include OC_App::getAppPath($app)."/appinfo/install.php"; } $info=OC_App::getAppInfo($app); + if (is_null($info)) { + return false; + } OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app)); //set remote/public handelers -- cgit v1.2.3 From 6b4c3df0876a4786bbde406349746600c87e1e6b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 17 Jan 2014 14:40:48 +0100 Subject: Load a separate config (if present) when running unit tests --- lib/base.php | 14 ++++++++++++-- lib/private/config.php | 2 +- lib/private/legacy/config.php | 1 - lib/private/util.php | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) (limited to 'lib/private') diff --git a/lib/base.php b/lib/base.php index f30575c7b12..d320f6f2411 100644 --- a/lib/base.php +++ b/lib/base.php @@ -57,6 +57,9 @@ class OC { * web path in 'url' */ public static $APPSROOTS = array(); + + public static $configDir; + /* * requested app */ @@ -100,6 +103,13 @@ class OC { get_include_path() ); + if(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/test_config/')) { + self::$configDir = OC::$SERVERROOT . '/test_config/'; + } else { + self::$configDir = OC::$SERVERROOT . '/config/'; + } + OC_Config::$object = new \OC\Config(self::$configDir); + OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); $scriptName = OC_Request::scriptName(); if (substr($scriptName, -1) == '/') { @@ -175,8 +185,8 @@ class OC { } public static function checkConfig() { - if (file_exists(OC::$SERVERROOT . "/config/config.php") - and !is_writable(OC::$SERVERROOT . "/config/config.php") + if (file_exists(self::$configDir . "/config.php") + and !is_writable(self::$configDir . "/config.php") ) { $defaults = new OC_Defaults(); if (self::$CLI) { diff --git a/lib/private/config.php b/lib/private/config.php index caf7b1d7066..8a9d5ca6158 100644 --- a/lib/private/config.php +++ b/lib/private/config.php @@ -50,7 +50,7 @@ class Config { protected $debugMode; /** - * @param $configDir path to the config dir, needs to end with '/' + * @param string $configDir path to the config dir, needs to end with '/' */ public function __construct($configDir) { $this->configDir = $configDir; diff --git a/lib/private/legacy/config.php b/lib/private/legacy/config.php index c457979113e..ab67c8d3020 100644 --- a/lib/private/legacy/config.php +++ b/lib/private/legacy/config.php @@ -38,7 +38,6 @@ * This class is responsible for reading and writing config.php, the very basic * configuration file of ownCloud. */ -OC_Config::$object = new \OC\Config(OC::$SERVERROOT.'/config/'); class OC_Config { /** diff --git a/lib/private/util.php b/lib/private/util.php index a4b3761dbd3..be8b5439543 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -312,7 +312,7 @@ class OC_Util { .'" target="_blank">giving the webserver write access to the root directory.'; // Check if config folder is writable. - if(!is_writable(OC::$SERVERROOT."/config/") or !is_readable(OC::$SERVERROOT."/config/")) { + if(!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) { $errors[] = array( 'error' => "Can't write into config directory", 'hint' => 'This can usually be fixed by ' -- cgit v1.2.3 From bf0471a92ed4fca8fe3344839acd83d6918cf566 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 17 Jan 2014 14:05:39 +0100 Subject: show link to app documentation --- lib/private/app.php | 4 ++++ settings/css/settings.css | 6 ++++++ settings/js/apps.js | 20 +++++++++++++++++++- settings/templates/apps.php | 5 +++++ 4 files changed, 34 insertions(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/app.php b/lib/private/app.php index 34c00e97fb9..0c60557914a 100644 --- a/lib/private/app.php +++ b/lib/private/app.php @@ -555,6 +555,10 @@ class OC_App{ }elseif($child->getName()=='description') { $xml=(string)$child->asXML(); $data[$child->getName()]=substr($xml, 13, -14);//script tags + }elseif($child->getName()=='documentation') { + foreach($child as $subchild) { + $data["documentation"][$subchild->getName()] = (string)$subchild; + } }else{ $data[$child->getName()]=(string)$child; } diff --git a/settings/css/settings.css b/settings/css/settings.css index a93c675d466..8a96885b789 100644 --- a/settings/css/settings.css +++ b/settings/css/settings.css @@ -131,6 +131,12 @@ span.version { margin-left:1em; margin-right:1em; color:#555; } .appslink { text-decoration: underline; } .score { color:#666; font-weight:bold; font-size:0.8em; } +.appinfo .documentation { + margin-top: 1em; + margin-bottom: 1em; +} + + /* LOG */ #log { white-space:normal; } #lessLog { display:none; } diff --git a/settings/js/apps.js b/settings/js/apps.js index a55c55e24cf..1d05d01e1f2 100644 --- a/settings/js/apps.js +++ b/settings/js/apps.js @@ -37,6 +37,24 @@ OC.Settings.Apps = OC.Settings.Apps || { } page.find('span.licence').text(appLicense); + var userDocumentation = false; + var adminDocumentation = false; + if (typeof(app.documentation.user) !== 'undefined') { + userDocumentation = true; + page.find('span.userDocumentation').html("" + t('settings', 'User Documentation') + ""); + page.find('p.documentation').show(); + } + if (typeof(app.documentation.admin) !== 'undefined') { + adminDocumentation = true; + page.find('span.adminDocumentation').html("" + t('settings', 'Admin Documentation') + ""); + page.find('p.documentation').show(); + } + + if(userDocumentation && adminDocumentation) { + page.find('span.userDocumentation').after(', '); + } + + if (app.update !== false) { page.find('input.update').show(); page.find('input.update').data('appid', app.id); @@ -110,7 +128,7 @@ OC.Settings.Apps = OC.Settings.Apps || { element.val(t('settings','Disable')); } },'json') - .fail(function() { + .fail(function() { OC.Settings.Apps.showErrorMessage(t('settings', 'Error while enabling app')); appitem.data('errormsg', t('settings', 'Error while enabling app')); appitem.data('active',false); diff --git a/settings/templates/apps.php b/settings/templates/apps.php index 0b76f775fea..ce48ef77d12 100644 --- a/settings/templates/apps.php +++ b/settings/templates/apps.php @@ -34,6 +34,11 @@ class="version">

+ -- cgit v1.2.3 From 1af7dab5358d7fd495e4382037c6e2528e2b76d5 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Sun, 19 Jan 2014 18:49:51 +0100 Subject: Fixed quota wrapper to not wrap failed fopen streams When calling fopen() on some storage types, these return false instead of throwing an exception. This fix makes sure that in case the stream wasn't opened (for example when a file doesn't exist any more) the stream isn't wrapped. Also added 'rb' as another case that doesn't need to be wrapped. Fixes #6832 --- lib/private/files/storage/wrapper/quota.php | 2 +- tests/lib/files/storage/wrapper/quota.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/files/storage/wrapper/quota.php b/lib/private/files/storage/wrapper/quota.php index 43016e0892f..a430e3e4617 100644 --- a/lib/private/files/storage/wrapper/quota.php +++ b/lib/private/files/storage/wrapper/quota.php @@ -95,7 +95,7 @@ class Quota extends Wrapper { public function fopen($path, $mode) { $source = $this->storage->fopen($path, $mode); $free = $this->free_space(''); - if ($free >= 0 && $mode !== 'r') { + if ($source && $free >= 0 && $mode !== 'r' && $mode !== 'rb') { return \OC\Files\Stream\Quota::wrap($source, $free); } else { return $source; diff --git a/tests/lib/files/storage/wrapper/quota.php b/tests/lib/files/storage/wrapper/quota.php index 9b14335782f..87bafb64d41 100644 --- a/tests/lib/files/storage/wrapper/quota.php +++ b/tests/lib/files/storage/wrapper/quota.php @@ -59,6 +59,20 @@ class Quota extends \Test\Files\Storage\Storage { $this->assertEquals('foobarqwe', $instance->file_get_contents('foo')); } + public function testReturnFalseWhenFopenFailed(){ + $failStorage = $this->getMock( + '\OC\Files\Storage\Local', + array('fopen'), + array(array('datadir' => $this->tmpDir))); + $failStorage->expects($this->any()) + ->method('fopen') + ->will($this->returnValue(false)); + + $instance = new \OC\Files\Storage\Wrapper\Quota(array('storage' => $failStorage, 'quota' => 1000)); + + $this->assertFalse($instance->fopen('failedfopen', 'r')); + } + public function testReturnRegularStreamOnRead(){ $instance = $this->getLimitedStorage(9); @@ -71,6 +85,11 @@ class Quota extends \Test\Files\Storage\Storage { $meta = stream_get_meta_data($stream); $this->assertEquals('plainfile', $meta['wrapper_type']); fclose($stream); + + $stream = $instance->fopen('foo', 'rb'); + $meta = stream_get_meta_data($stream); + $this->assertEquals('plainfile', $meta['wrapper_type']); + fclose($stream); } public function testReturnQuotaStreamOnWrite(){ -- cgit v1.2.3 From 221e656e91de48f74e170662cb9680e5e2aac792 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Mon, 20 Jan 2014 10:10:34 +0100 Subject: Revert "use getAppWebPath() in here as well" This reverts commit 6254f0a403e315461f8e20ebccf71cb91e9313a3. --- lib/private/template/cssresourcelocator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/template/cssresourcelocator.php b/lib/private/template/cssresourcelocator.php index e26daa25827..8e7831ca549 100644 --- a/lib/private/template/cssresourcelocator.php +++ b/lib/private/template/cssresourcelocator.php @@ -22,7 +22,7 @@ class CSSResourceLocator extends ResourceLocator { $app = substr($style, 0, strpos($style, '/')); $style = substr($style, strpos($style, '/')+1); $app_path = \OC_App::getAppPath($app); - $app_url = \OC_App::getAppWebPath($app); + $app_url = $this->webroot . '/index.php/apps/' . $app; if ($this->appendIfExist($app_path, $style.$this->form_factor.'.css', $app_url) || $this->appendIfExist($app_path, $style.'.css', $app_url) ) { -- cgit v1.2.3 From 3d6d8d1bb683f9daca3a2b8a876e291adc320375 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 20 Jan 2014 15:21:21 +0100 Subject: Reuse the data retrieved from the cache in checkUpdate --- apps/files_sharing/lib/watcher.php | 2 +- lib/private/files/cache/watcher.php | 4 ++-- lib/private/files/view.php | 7 +++++-- 3 files changed, 8 insertions(+), 5 deletions(-) (limited to 'lib/private') diff --git a/apps/files_sharing/lib/watcher.php b/apps/files_sharing/lib/watcher.php index c40cf6911b8..285b1a58c6e 100644 --- a/apps/files_sharing/lib/watcher.php +++ b/apps/files_sharing/lib/watcher.php @@ -32,7 +32,7 @@ class Shared_Watcher extends Watcher { * @param string $path */ public function checkUpdate($path) { - if ($path != '' && parent::checkUpdate($path)) { + if ($path != '' && parent::checkUpdate($path) === true) { // since checkUpdate() has already updated the size of the subdirs, // only apply the update to the owner's parent dirs diff --git a/lib/private/files/cache/watcher.php b/lib/private/files/cache/watcher.php index 58f624c8990..251ecbe7071 100644 --- a/lib/private/files/cache/watcher.php +++ b/lib/private/files/cache/watcher.php @@ -40,7 +40,7 @@ class Watcher { * check $path for updates * * @param string $path - * @return boolean true if path was updated, false otherwise + * @return boolean | array true if path was updated, otherwise the cached data is returned */ public function checkUpdate($path) { $cachedEntry = $this->cache->get($path); @@ -56,7 +56,7 @@ class Watcher { $this->cache->correctFolderSize($path); return true; } - return false; + return $cachedEntry; } /** diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 8893911ed5d..d97544b865e 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -801,6 +801,7 @@ class View { * @var string $internalPath */ list($storage, $internalPath) = Filesystem::resolvePath($path); + $data = null; if ($storage) { $cache = $storage->getCache($internalPath); $permissionsCache = $storage->getPermissionsCache($internalPath); @@ -811,10 +812,12 @@ class View { $scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW); } else { $watcher = $storage->getWatcher($internalPath); - $watcher->checkUpdate($internalPath); + $data = $watcher->checkUpdate($internalPath); } - $data = $cache->get($internalPath); + if (!is_array($data)) { + $data = $cache->get($internalPath); + } if ($data and $data['fileid']) { if ($includeMountPoints and $data['mimetype'] === 'httpd/unix-directory') { -- cgit v1.2.3 From 23a4d0d44ef8b918f054e7ad608d04b2e9a68995 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Tue, 21 Jan 2014 11:32:30 +0100 Subject: OC_Util::setupFS($user) will create a data dir for the given string - no matter if the user really exists - OCP\JSON::checkUserExists($owner); introduces a ready to use check which will bail out with an JSON error --- apps/files/ajax/upload.php | 1 + apps/files/triggerupdate.php | 1 + apps/files_sharing/ajax/publicpreview.php | 3 ++- apps/files_sharing/appinfo/update.php | 1 + apps/files_sharing/public.php | 6 +++--- lib/private/json.php | 14 ++++++++++++++ lib/private/util.php | 4 ++++ lib/public/json.php | 10 +++++++++- 8 files changed, 35 insertions(+), 5 deletions(-) (limited to 'lib/private') diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php index 0e905f993ac..bdaf6a77d14 100644 --- a/apps/files/ajax/upload.php +++ b/apps/files/ajax/upload.php @@ -34,6 +34,7 @@ if (empty($_POST['dirToken'])) { // resolve reshares $rootLinkItem = OCP\Share::resolveReShare($linkItem); + OCP\JSON::checkUserExists($rootLinkItem['uid_owner']); // Setup FS with owner OC_Util::tearDownFS(); OC_Util::setupFS($rootLinkItem['uid_owner']); diff --git a/apps/files/triggerupdate.php b/apps/files/triggerupdate.php index 0e29edbba35..a37b9823add 100644 --- a/apps/files/triggerupdate.php +++ b/apps/files/triggerupdate.php @@ -6,6 +6,7 @@ if (OC::$CLI) { if (count($argv) === 2) { $file = $argv[1]; list(, $user) = explode('/', $file); + OCP\JSON::checkUserExists($owner); OC_Util::setupFS($user); $view = new \OC\Files\View(''); /** diff --git a/apps/files_sharing/ajax/publicpreview.php b/apps/files_sharing/ajax/publicpreview.php index 54a9806e8bf..a52f522afac 100644 --- a/apps/files_sharing/ajax/publicpreview.php +++ b/apps/files_sharing/ajax/publicpreview.php @@ -39,6 +39,7 @@ if(!isset($linkedItem['uid_owner']) || !isset($linkedItem['file_source'])) { $rootLinkItem = OCP\Share::resolveReShare($linkedItem); $userId = $rootLinkItem['uid_owner']; +OCP\JSON::checkUserExists($rootLinkItem['uid_owner']); \OC_Util::setupFS($userId); \OC\Files\Filesystem::initMountPoints($userId); $view = new \OC\Files\View('/' . $userId . '/files'); @@ -88,4 +89,4 @@ try{ } catch (\Exception $e) { \OC_Response::setStatus(500); \OC_Log::write('core', $e->getmessage(), \OC_Log::DEBUG); -} \ No newline at end of file +} diff --git a/apps/files_sharing/appinfo/update.php b/apps/files_sharing/appinfo/update.php index 0d827da28ea..4b716e764f4 100644 --- a/apps/files_sharing/appinfo/update.php +++ b/apps/files_sharing/appinfo/update.php @@ -44,6 +44,7 @@ if (version_compare($installedVersion, '0.3', '<')) { $shareType = OCP\Share::SHARE_TYPE_USER; $shareWith = $row['uid_shared_with']; } + OCP\JSON::checkUserExists($row['uid_owner']); OC_User::setUserId($row['uid_owner']); //we need to setup the filesystem for the user, otherwise OC_FileSystem::getRoot will fail and break OC_Util::setupFS($row['uid_owner']); diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index d050efd5b32..80dd708ee51 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -43,10 +43,10 @@ if (isset($_GET['t'])) { $shareOwner = $linkItem['uid_owner']; $path = null; $rootLinkItem = OCP\Share::resolveReShare($linkItem); - $fileOwner = $rootLinkItem['uid_owner']; - if (isset($fileOwner)) { + if (isset($rootLinkItem['uid_owner'])) { + OCP\JSON::checkUserExists($rootLinkItem['uid_owner']); OC_Util::tearDownFS(); - OC_Util::setupFS($fileOwner); + OC_Util::setupFS($rootLinkItem['uid_owner']); $path = \OC\Files\Filesystem::getPath($linkItem['file_source']); } } diff --git a/lib/private/json.php b/lib/private/json.php index 6a9e5a2df5e..5c5d7e3a3da 100644 --- a/lib/private/json.php +++ b/lib/private/json.php @@ -64,6 +64,20 @@ class OC_JSON{ } } + /** + * Check is a given user exists - send json error msg if not + * @param string $user + */ + public static function checkUserExists($user) { + if (!OCP\User::userExists($user)) { + $l = OC_L10N::get('lib'); + OCP\JSON::error(array('data' => array('message' => $l->t('Unknown user')))); + exit; + } + } + + + /** * Check if the user is a subadmin, send json error msg if not */ diff --git a/lib/private/util.php b/lib/private/util.php index 72afa6f9478..8aa7a074d0d 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -51,6 +51,10 @@ class OC_Util { self::$rootMounted = true; } + if ($user != '' && !OCP\User::userExists($user)) { + return false; + } + //if we aren't logged in, there is no use to set up the filesystem if( $user != "" ) { \OC\Files\Filesystem::addStorageWrapper(function($mountPoint, $storage){ diff --git a/lib/public/json.php b/lib/public/json.php index 831e3ef1cf6..cd5d233ef90 100644 --- a/lib/public/json.php +++ b/lib/public/json.php @@ -167,7 +167,7 @@ class JSON { * @return string json formatted string if not admin user. */ public static function checkAdminUser() { - return(\OC_JSON::checkAdminUser()); + \OC_JSON::checkAdminUser(); } /** @@ -177,4 +177,12 @@ class JSON { public static function encode($data) { return(\OC_JSON::encode($data)); } + + /** + * Check is a given user exists - send json error msg if not + * @param string $user + */ + public static function checkUserExists($user) { + \OC_JSON::checkUserExists($user); + } } -- cgit v1.2.3 From 267e1f3c40b9b9bdabaf0e49221744f80f7bc5a4 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Tue, 21 Jan 2014 12:41:10 +0100 Subject: use 'download.zip' as default name for zip downloads instead of 'owncloud.zip' --- lib/private/files.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/files.php b/lib/private/files.php index e6c81d58bd2..8ce632013cf 100644 --- a/lib/private/files.php +++ b/lib/private/files.php @@ -83,7 +83,7 @@ class OC_Files { if ($basename) { $name = $basename . '.zip'; } else { - $name = 'owncloud.zip'; + $name = 'download.zip'; } set_time_limit($executionTime); -- cgit v1.2.3 From 374e3475c9e2e0220cc8639a1a06f68b7f43fb2b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 21 Jan 2014 23:58:48 +0100 Subject: Also remove the user's home storage from the storage table when deleting a user --- lib/private/files/cache/storage.php | 13 +++++++++++++ lib/private/user.php | 3 +++ 2 files changed, 16 insertions(+) (limited to 'lib/private') diff --git a/lib/private/files/cache/storage.php b/lib/private/files/cache/storage.php index 5657cf06e12..6d7a1002c1b 100644 --- a/lib/private/files/cache/storage.php +++ b/lib/private/files/cache/storage.php @@ -70,4 +70,17 @@ class Storage { return false; } } + + /** + * remove the entry for the storage + * + * @param string $storageId + */ + public static function remove($storageId) { + if (strlen($storageId) > 64) { + $storageId = md5($storageId); + } + $sql = 'DELETE FROM `*PREFIX*storages` WHERE `id` = ?'; + \OC_DB::executeAudited($sql, array($storageId)); + } } diff --git a/lib/private/user.php b/lib/private/user.php index 98ebebbe5c1..2519200d0f0 100644 --- a/lib/private/user.php +++ b/lib/private/user.php @@ -205,6 +205,9 @@ class OC_User { // Delete user files in /data/ OC_Helper::rmdirr(\OC_User::getHome($uid)); + // Delete the users entry in the storage table + \OC\Files\Cache\Storage::remove('home::' . $uid); + // Remove it from the Cache self::getManager()->delete($uid); } -- cgit v1.2.3 From 5a5b6f187e719e6c0bac5e64c411eb74e6d28389 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 22 Jan 2014 13:00:45 +0100 Subject: Use Cache->clear to cleanup the filecache for removed users --- lib/private/user.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'lib/private') diff --git a/lib/private/user.php b/lib/private/user.php index 2519200d0f0..7932f4aef76 100644 --- a/lib/private/user.php +++ b/lib/private/user.php @@ -205,8 +205,13 @@ class OC_User { // Delete user files in /data/ OC_Helper::rmdirr(\OC_User::getHome($uid)); - // Delete the users entry in the storage table - \OC\Files\Cache\Storage::remove('home::' . $uid); + // Cleanup the filecache + $mount = \OC\Files\Filesystem::getMountByStorageId('home::' . $uid); + if (count($mount) > 0) { + $mount = $mount[0]; + $cache = $mount->getStorage()->getCache(); + $cache->clear(); + } // Remove it from the Cache self::getManager()->delete($uid); @@ -243,15 +248,15 @@ class OC_User { $uid = $backend->getCurrentUserId(); $run = true; - OC_Hook::emit( "OC_User", "pre_login", array( "run" => &$run, "uid" => $uid )); + OC_Hook::emit("OC_User", "pre_login", array("run" => &$run, "uid" => $uid)); - if($uid) { + if ($uid) { session_regenerate_id(true); self::setUserId($uid); self::setDisplayName($uid); self::getUserSession()->setLoginName($uid); - OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid, 'password'=>'' )); + OC_Hook::emit("OC_User", "post_login", array("uid" => $uid, 'password' => '')); return true; } return false; -- cgit v1.2.3 From 6241655df4121619de42ba797ec076d9b6927568 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 23 Jan 2014 02:15:42 +0100 Subject: Bring mimetype list into alphabetical order. --- lib/private/mimetypes.list.php | 123 ++++++++++++++++++++--------------------- 1 file changed, 61 insertions(+), 62 deletions(-) (limited to 'lib/private') diff --git a/lib/private/mimetypes.list.php b/lib/private/mimetypes.list.php index 08228336966..72860d0e64f 100644 --- a/lib/private/mimetypes.list.php +++ b/lib/private/mimetypes.list.php @@ -21,93 +21,92 @@ */ /** - * list of mimetypes by extension + * Array mapping file extensions to mimetypes (in alphabetical order). */ - return array( + 'ai' => 'application/illustrator', + 'avi'=>'video/x-msvideo', + 'bash' => 'text/x-shellscript', + 'blend'=>'application/x-blender', + 'cc' => 'text/x-c', + 'cdr' => 'application/coreldraw', + 'cpp' => 'text/x-c++src', 'css'=>'text/css', + 'c' => 'text/x-c', + 'c++' => 'text/x-c++src', + 'doc'=>'application/msword', + 'doc'=>'application/msword', + 'docx'=>'application/msword', + 'docx'=>'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + 'dv'=>'video/dv', + 'epub' => 'application/epub+zip', + 'exe'=>'application/x-ms-dos-executable', 'flac'=>'audio/flac', 'gif'=>'image/gif', - 'gzip'=>'application/x-gzip', 'gz'=>'application/x-gzip', + 'gzip'=>'application/x-gzip', 'html'=>'text/html', 'htm'=>'text/html', - 'ics'=>'text/calendar', 'ical'=>'text/calendar', + 'ics'=>'text/calendar', + 'impress' => 'text/impress', 'jpeg'=>'image/jpeg', 'jpg'=>'image/jpeg', 'js'=>'application/javascript', + 'keynote'=>'application/x-iwork-keynote-sffkey', + 'kra'=>'application/x-krita', + 'm2t'=>'video/mp2t', + 'm4v'=>'video/mp4', + 'markdown' => 'text/markdown', + 'mdown' => 'text/markdown', + 'md' => 'text/markdown', + 'mdwn' => 'text/markdown', + 'mobi' => 'application/x-mobipocket-ebook', + 'mov'=>'video/quicktime', + 'mp3'=>'audio/mpeg', + 'mp4'=>'video/mp4', + 'mpeg'=>'video/mpeg', + 'mpg'=>'video/mpeg', + 'msi'=>'application/x-msi', + 'numbers'=>'application/x-iwork-numbers-sffnumbers', + 'odg'=>'application/vnd.oasis.opendocument.graphics', + 'odp'=>'application/vnd.oasis.opendocument.presentation', + 'ods'=>'application/vnd.oasis.opendocument.spreadsheet', + 'odt'=>'application/vnd.oasis.opendocument.text', 'oga'=>'audio/ogg', 'ogg'=>'audio/ogg', 'ogv'=>'video/ogg', + 'pages'=>'application/x-iwork-pages-sffpages', 'pdf'=>'application/pdf', + 'php'=>'application/x-php', + 'pl'=>'application/x-pearl', 'png'=>'image/png', + 'ppt'=>'application/mspowerpoint', + 'pptx'=>'application/vnd.openxmlformats-officedocument.presentationml.presentation', + 'psd'=>'application/x-photoshop', + 'py'=>'application/x-python', + 'py'=>'text/x-script.python', + 'reveal' => 'text/reveal', + 'sgf' => 'application/sgf', + 'sh-lib' => 'text/x-shellscript', + 'sh' => 'text/x-shellscript', 'svg'=>'image/svg+xml', 'tar'=>'application/x-tar', - 'tgz'=>'application/x-compressed', 'tar.gz'=>'application/x-compressed', - 'tif'=>'image/tiff', + 'tgz'=>'application/x-compressed', 'tiff'=>'image/tiff', + 'tif'=>'image/tiff', 'txt'=>'text/plain', - 'zip'=>'application/zip', + 'vcard' => 'text/vcard', + 'vcf' => 'text/vcard', 'wav'=>'audio/wav', - 'odt'=>'application/vnd.oasis.opendocument.text', - 'ods'=>'application/vnd.oasis.opendocument.spreadsheet', - 'odg'=>'application/vnd.oasis.opendocument.graphics', - 'odp'=>'application/vnd.oasis.opendocument.presentation', - 'pages'=>'application/x-iwork-pages-sffpages', - 'numbers'=>'application/x-iwork-numbers-sffnumbers', - 'keynote'=>'application/x-iwork-keynote-sffkey', - 'kra'=>'application/x-krita', - 'mp3'=>'audio/mpeg', - 'doc'=>'application/msword', - 'docx'=>'application/msword', - 'xls'=>'application/msexcel', - 'xlsx'=>'application/msexcel', - 'php'=>'application/x-php', - 'exe'=>'application/x-ms-dos-executable', - 'msi'=>'application/x-msi', - 'pl'=>'application/x-pearl', - 'py'=>'application/x-python', - 'blend'=>'application/x-blender', - 'xcf'=>'application/x-gimp', - 'psd'=>'application/x-photoshop', - 'xml'=>'application/xml', - 'avi'=>'video/x-msvideo', - 'dv'=>'video/dv', - 'm2t'=>'video/mp2t', - 'mp4'=>'video/mp4', - 'm4v'=>'video/mp4', - 'mpg'=>'video/mpeg', - 'mpeg'=>'video/mpeg', - 'mov'=>'video/quicktime', 'webm'=>'video/webm', 'wmv'=>'video/x-ms-asf', - 'py'=>'text/x-script.python', - 'vcf' => 'text/vcard', - 'vcard' => 'text/vcard', - 'doc'=>'application/msword', - 'docx'=>'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + 'xcf'=>'application/x-gimp', 'xls'=>'application/msexcel', + 'xls'=>'application/msexcel', + 'xlsx'=>'application/msexcel', 'xlsx'=>'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - 'ppt'=>'application/mspowerpoint', - 'pptx'=>'application/vnd.openxmlformats-officedocument.presentationml.presentation', - 'sgf' => 'application/sgf', - 'cdr' => 'application/coreldraw', - 'impress' => 'text/impress', - 'ai' => 'application/illustrator', - 'epub' => 'application/epub+zip', - 'mobi' => 'application/x-mobipocket-ebook', - 'md' => 'text/markdown', - 'markdown' => 'text/markdown', - 'mdown' => 'text/markdown', - 'mdwn' => 'text/markdown', - 'reveal' => 'text/reveal', - 'c' => 'text/x-c', - 'cc' => 'text/x-c', - 'cpp' => 'text/x-c++src', - 'c++' => 'text/x-c++src', - 'sh' => 'text/x-shellscript', - 'bash' => 'text/x-shellscript', - 'sh-lib' => 'text/x-shellscript', + 'xml'=>'application/xml', + 'zip'=>'application/zip', ); -- cgit v1.2.3 From 689516ebd7a47847938420bf8715469b68fb3535 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 23 Jan 2014 02:22:46 +0100 Subject: Remove duplicate mimetypes while keeping previous behaviour. --- lib/private/mimetypes.list.php | 5 ----- 1 file changed, 5 deletions(-) (limited to 'lib/private') diff --git a/lib/private/mimetypes.list.php b/lib/private/mimetypes.list.php index 72860d0e64f..9db396e9fd2 100644 --- a/lib/private/mimetypes.list.php +++ b/lib/private/mimetypes.list.php @@ -35,8 +35,6 @@ return array( 'c' => 'text/x-c', 'c++' => 'text/x-c++src', 'doc'=>'application/msword', - 'doc'=>'application/msword', - 'docx'=>'application/msword', 'docx'=>'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'dv'=>'video/dv', 'epub' => 'application/epub+zip', @@ -84,7 +82,6 @@ return array( 'ppt'=>'application/mspowerpoint', 'pptx'=>'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'psd'=>'application/x-photoshop', - 'py'=>'application/x-python', 'py'=>'text/x-script.python', 'reveal' => 'text/reveal', 'sgf' => 'application/sgf', @@ -104,8 +101,6 @@ return array( 'wmv'=>'video/x-ms-asf', 'xcf'=>'application/x-gimp', 'xls'=>'application/msexcel', - 'xls'=>'application/msexcel', - 'xlsx'=>'application/msexcel', 'xlsx'=>'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'xml'=>'application/xml', 'zip'=>'application/zip', -- cgit v1.2.3 From 47ea7704ca796a23fc5e9ec8f4a7668d1bbe9446 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 23 Jan 2014 02:46:05 +0100 Subject: Fix icons for xml,ppt,dot,dotx files. --- lib/private/helper.php | 2 ++ lib/private/mimetypes.list.php | 2 ++ 2 files changed, 4 insertions(+) (limited to 'lib/private') diff --git a/lib/private/helper.php b/lib/private/helper.php index 1c8d01c141f..90ef704c3cc 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -161,6 +161,7 @@ class OC_Helper { 'application/vnd.oasis.opendocument.text-template' => 'x-office/document', 'application/vnd.oasis.opendocument.text-web' => 'x-office/document', 'application/vnd.oasis.opendocument.text-master' => 'x-office/document', + 'application/mspowerpoint' => 'x-office/presentation', 'application/vnd.ms-powerpoint' => 'x-office/presentation', 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'x-office/presentation', 'application/vnd.openxmlformats-officedocument.presentationml.template' => 'x-office/presentation', @@ -171,6 +172,7 @@ class OC_Helper { 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12' => 'x-office/presentation', 'application/vnd.oasis.opendocument.presentation' => 'x-office/presentation', 'application/vnd.oasis.opendocument.presentation-template' => 'x-office/presentation', + 'application/msexcel' => 'x-office/spreadsheet', 'application/vnd.ms-excel' => 'x-office/spreadsheet', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'x-office/spreadsheet', 'application/vnd.openxmlformats-officedocument.spreadsheetml.template' => 'x-office/spreadsheet', diff --git a/lib/private/mimetypes.list.php b/lib/private/mimetypes.list.php index 9db396e9fd2..1ad333b5084 100644 --- a/lib/private/mimetypes.list.php +++ b/lib/private/mimetypes.list.php @@ -36,6 +36,8 @@ return array( 'c++' => 'text/x-c++src', 'doc'=>'application/msword', 'docx'=>'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + 'dot'=>'application/msword', + 'dotx'=>'application/vnd.openxmlformats-officedocument.wordprocessingml.template', 'dv'=>'video/dv', 'epub' => 'application/epub+zip', 'exe'=>'application/x-ms-dos-executable', -- cgit v1.2.3 From 96f194c0f6038444aae4270d2481a2ee1ccd7691 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 23 Jan 2014 03:06:14 +0100 Subject: Add icons for mdb and accdb files. --- lib/private/helper.php | 1 + lib/private/mimetypes.list.php | 2 ++ 2 files changed, 3 insertions(+) (limited to 'lib/private') diff --git a/lib/private/helper.php b/lib/private/helper.php index 90ef704c3cc..58bee9c6300 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -182,6 +182,7 @@ class OC_Helper { 'application/vnd.ms-excel.sheet.binary.macroEnabled.12' => 'x-office/spreadsheet', 'application/vnd.oasis.opendocument.spreadsheet' => 'x-office/spreadsheet', 'application/vnd.oasis.opendocument.spreadsheet-template' => 'x-office/spreadsheet', + 'application/msaccess' => 'database', ); if (isset($alias[$mimetype])) { diff --git a/lib/private/mimetypes.list.php b/lib/private/mimetypes.list.php index 1ad333b5084..40fb1d2d97d 100644 --- a/lib/private/mimetypes.list.php +++ b/lib/private/mimetypes.list.php @@ -24,6 +24,7 @@ * Array mapping file extensions to mimetypes (in alphabetical order). */ return array( + 'accdb'=>'application/msaccess', 'ai' => 'application/illustrator', 'avi'=>'video/x-msvideo', 'bash' => 'text/x-shellscript', @@ -60,6 +61,7 @@ return array( 'markdown' => 'text/markdown', 'mdown' => 'text/markdown', 'md' => 'text/markdown', + 'mdb'=>'application/msaccess', 'mdwn' => 'text/markdown', 'mobi' => 'application/x-mobipocket-ebook', 'mov'=>'video/quicktime', -- cgit v1.2.3 From 5ad28f4d1ff952c17f3ca13c8ea7e2e118965846 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Wed, 27 Nov 2013 12:46:12 +0100 Subject: Allow getting info or renaming part files through WebDAV When mounting an ownCloud (backend OC) inside another ownCloud (frontend OC), the frontend OC will use WebDAV to upload file, which will create part files. These part files need to be accessible for the frontend OC to rename them to the actual file name. This fix leaves the file cache untouched but gives direct access to part file info when requested. This means that part file can be accessed only when their path and name are known. These won't appear in file listtings. Fixes #6068 --- lib/private/connector/sabre/objecttree.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/connector/sabre/objecttree.php b/lib/private/connector/sabre/objecttree.php index cd3f081f7cc..d1e179af2ec 100644 --- a/lib/private/connector/sabre/objecttree.php +++ b/lib/private/connector/sabre/objecttree.php @@ -38,7 +38,20 @@ class ObjectTree extends \Sabre_DAV_ObjectTree { return $this->rootNode; } - $info = $this->getFileView()->getFileInfo($path); + if (pathinfo($path, PATHINFO_EXTENSION) === 'part') { + // read from storage + $absPath = $this->getFileView()->getAbsolutePath($path); + list($storage, $internalPath) = Filesystem::resolvePath('/' . $absPath); + if ($storage) { + $scanner = $storage->getScanner($internalPath); + // get data directly + $info = $scanner->getData($internalPath); + } + } + else { + // read from cache + $info = $this->getFileView()->getFileInfo($path); + } if (!$info) { throw new \Sabre_DAV_Exception_NotFound('File with name ' . $path . ' could not be located'); -- cgit v1.2.3 From 2f8ebd03b011b705883bf9666b1bdaafb971f110 Mon Sep 17 00:00:00 2001 From: Otto Sabart Date: Fri, 24 Jan 2014 15:52:28 +0100 Subject: Add check for apc.enabled option Sometimes it's not possible to disable APC entirely and some of apc_functions are disabled. Only thing which is possible is to disable apc.enable option. --- lib/private/memcache/apc.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/private') diff --git a/lib/private/memcache/apc.php b/lib/private/memcache/apc.php index 575ee4427db..e995cbc526e 100644 --- a/lib/private/memcache/apc.php +++ b/lib/private/memcache/apc.php @@ -50,6 +50,8 @@ class APC extends Cache { static public function isAvailable() { if (!extension_loaded('apc')) { return false; + } elseif (!ini_get('apc.enabled')) { + return false; } elseif (!ini_get('apc.enable_cli') && \OC::$CLI) { return false; } else { -- cgit v1.2.3 From 1ab7ca0a19d5f3984e87f99945d81aecffbbae19 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 24 Jan 2014 16:01:19 +0100 Subject: Fix some phpdoc errors and rename interface --- lib/private/memcache/factory.php | 4 +++- lib/public/cachefactory.php | 26 -------------------------- lib/public/icachefactory.php | 28 ++++++++++++++++++++++++++++ lib/public/iservercontainer.php | 2 +- 4 files changed, 32 insertions(+), 28 deletions(-) delete mode 100644 lib/public/cachefactory.php create mode 100644 lib/public/icachefactory.php (limited to 'lib/private') diff --git a/lib/private/memcache/factory.php b/lib/private/memcache/factory.php index 48c97b59551..334cf9a1f0e 100644 --- a/lib/private/memcache/factory.php +++ b/lib/private/memcache/factory.php @@ -8,7 +8,9 @@ namespace OC\Memcache; -class Factory { +use \OCP\ICacheFactory; + +class Factory implements ICacheFactory { /** * @var string $globalPrefix */ diff --git a/lib/public/cachefactory.php b/lib/public/cachefactory.php deleted file mode 100644 index 1bb0ea3dd51..00000000000 --- a/lib/public/cachefactory.php +++ /dev/null @@ -1,26 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -namespace OCP; - -interface CacheFactory{ - /** - * Get a memory cache instance - * - * @param string $prefix - * @return $return \OCP\ICache - */ - public function create($prefix = ''); - - /** - * Check if a memory cache backend is available - * - * @return bool - */ - public function isAvailable(); -} diff --git a/lib/public/icachefactory.php b/lib/public/icachefactory.php new file mode 100644 index 00000000000..874f1ec0a59 --- /dev/null +++ b/lib/public/icachefactory.php @@ -0,0 +1,28 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCP; + +interface ICacheFactory{ + /** + * Get a memory cache instance + * + * All entries added trough the cache instance will be namespaced by $prefix to prevent collisions between apps + * + * @param string $prefix + * @return \OCP\ICache + */ + public function create($prefix = ''); + + /** + * Check if any memory cache backend is available + * + * @return bool + */ + public function isAvailable(); +} diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index 67884bdc3e4..5473f3ee334 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -144,7 +144,7 @@ interface IServerContainer { /** * Returns an \OCP\CacheFactory instance * - * @return \OCP\CacheFactory + * @return \OCP\ICacheFactory */ function getMemCacheFactory(); -- cgit v1.2.3 From c2ed8d5aa111ac537cf37bbf0d60fd503a62c24a Mon Sep 17 00:00:00 2001 From: Martial Saunois Date: Sun, 26 Jan 2014 18:46:09 +0100 Subject: New user agent added for the Freebox. The Freebox is the multimedia device of a french Internet provider: Free. This device provides a seedbox which uses the user agent "Mozilla/5.0". In the "Content-Disposition" header, if the "filename" key is used with the "filename*=UTF-8''" value, the seedbox does not take care about the header and saves the file name with the origin URL. This patch brings the support for the Freebox users. --- lib/private/request.php | 1 + lib/private/response.php | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/request.php b/lib/private/request.php index d9d5ae08e28..855148ac25a 100755 --- a/lib/private/request.php +++ b/lib/private/request.php @@ -11,6 +11,7 @@ class OC_Request { const USER_AGENT_IE = '/MSIE/'; // Android Chrome user agent: https://developers.google.com/chrome/mobile/docs/user-agent const USER_AGENT_ANDROID_MOBILE_CHROME = '#Android.*Chrome/[.0-9]*#'; + const USER_AGENT_FREEBOX = '#Mozilla/5\.0$#'; /** * @brief Check overwrite condition diff --git a/lib/private/response.php b/lib/private/response.php index 04746437347..52dbb9d90f8 100644 --- a/lib/private/response.php +++ b/lib/private/response.php @@ -153,7 +153,11 @@ class OC_Response { * @param string $type disposition type, either 'attachment' or 'inline' */ static public function setContentDispositionHeader( $filename, $type = 'attachment' ) { - if (OC_Request::isUserAgent(array(OC_Request::USER_AGENT_IE, OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME))) { + if (OC_Request::isUserAgent(array( + OC_Request::USER_AGENT_IE, + OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME, + OC_Request::USER_AGENT_FREEBOX + ))) { header( 'Content-Disposition: ' . rawurlencode($type) . '; filename="' . rawurlencode( $filename ) . '"' ); } else { header( 'Content-Disposition: ' . rawurlencode($type) . '; filename*=UTF-8\'\'' . rawurlencode( $filename ) -- cgit v1.2.3 From 11ef12a1060f3e34312ae40c690f95765d7c5f89 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 23 Jan 2014 12:11:53 +0100 Subject: Added exception logger plugin for sabre connector Whenever an exception occurs in the sabre connector code or code called by it, it will be logged. This plugin approach is needed because Sabre already catches exceptions to return them to the client in the XML response, so they don't appear logged in the web server log. This will make it much easier to debug syncing issues. --- apps/files/appinfo/remote.php | 1 + .../connector/sabre/exceptionloggerplugin.php | 50 ++++++++++++++++++++++ lib/private/connector/sabre/file.php | 6 +-- lib/public/util.php | 8 +++- 4 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 lib/private/connector/sabre/exceptionloggerplugin.php (limited to 'lib/private') diff --git a/apps/files/appinfo/remote.php b/apps/files/appinfo/remote.php index 9f290796205..ef22fe92188 100644 --- a/apps/files/appinfo/remote.php +++ b/apps/files/appinfo/remote.php @@ -52,6 +52,7 @@ $server->addPlugin(new OC_Connector_Sabre_FilesPlugin()); $server->addPlugin(new OC_Connector_Sabre_AbortedUploadDetectionPlugin()); $server->addPlugin(new OC_Connector_Sabre_QuotaPlugin()); $server->addPlugin(new OC_Connector_Sabre_MaintenancePlugin()); +$server->addPlugin(new OC_Connector_Sabre_ExceptionLoggerPlugin('webdav')); // And off we go! $server->exec(); diff --git a/lib/private/connector/sabre/exceptionloggerplugin.php b/lib/private/connector/sabre/exceptionloggerplugin.php new file mode 100644 index 00000000000..8e77afaf207 --- /dev/null +++ b/lib/private/connector/sabre/exceptionloggerplugin.php @@ -0,0 +1,50 @@ + + * + * @license AGPL3 + */ + +class OC_Connector_Sabre_ExceptionLoggerPlugin extends Sabre_DAV_ServerPlugin +{ + private $appName; + + /** + * @param string $loggerAppName app name to use when logging + */ + public function __construct($loggerAppName = 'webdav') { + $this->appName = $loggerAppName; + } + + /** + * This initializes the plugin. + * + * This function is called by Sabre_DAV_Server, after + * addPlugin is called. + * + * This method should set up the required event subscriptions. + * + * @param Sabre_DAV_Server $server + * @return void + */ + public function initialize(Sabre_DAV_Server $server) { + + $server->subscribeEvent('exception', array($this, 'logException'), 10); + } + + /** + * Log exception + * + * @internal param Exception $e exception + */ + public function logException($e) { + $exceptionClass = get_class($e); + if ($exceptionClass !== 'Sabre_DAV_Exception_NotAuthenticated') { + \OCP\Util::logException($this->appName, $e); + } + } +} diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php index c3b59007295..ed27cef440d 100644 --- a/lib/private/connector/sabre/file.php +++ b/lib/private/connector/sabre/file.php @@ -79,7 +79,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D \OC_Log::write('webdav', '\OC\Files\Filesystem::file_put_contents() failed', \OC_Log::ERROR); $fs->unlink($partpath); // because we have no clue about the cause we can only throw back a 500/Internal Server Error - throw new Sabre_DAV_Exception(); + throw new Sabre_DAV_Exception('Could not write file contents'); } } catch (\OCP\Files\NotPermittedException $e) { // a more general case - due to whatever reason the content could not be written @@ -105,7 +105,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D if ($renameOkay === false || $fileExists === false) { \OC_Log::write('webdav', '\OC\Files\Filesystem::rename() failed', \OC_Log::ERROR); $fs->unlink($partpath); - throw new Sabre_DAV_Exception(); + throw new Sabre_DAV_Exception('Could not rename part file to final file'); } // allow sync clients to send the mtime along in a header @@ -246,7 +246,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D if ($fileExists) { $fs->unlink($targetPath); } - throw new Sabre_DAV_Exception(); + throw new Sabre_DAV_Exception('Could not rename part file assembled from chunks'); } // allow sync clients to send the mtime along in a header diff --git a/lib/public/util.php b/lib/public/util.php index 8e85f9afc3f..e893a76d811 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -88,14 +88,18 @@ class Util { * @param Exception $ex exception to log */ public static function logException( $app, \Exception $ex ) { - $message = $ex->getMessage(); + $class = get_class($ex); + if ($class !== 'Exception') { + $message = $class . ': '; + } + $message .= $ex->getMessage(); if ($ex->getCode()) { $message .= ' [' . $ex->getCode() . ']'; } \OCP\Util::writeLog($app, 'Exception: ' . $message, \OCP\Util::FATAL); if (defined('DEBUG') and DEBUG) { // also log stack trace - $stack = explode('#', $ex->getTraceAsString()); + $stack = explode("\n", $ex->getTraceAsString()); // first element is empty array_shift($stack); foreach ($stack as $s) { -- cgit v1.2.3 From 0f1c587e6baaa201f01683b6adac8cc907c4f3e3 Mon Sep 17 00:00:00 2001 From: Martial Saunois Date: Wed, 29 Jan 2014 10:58:34 +0100 Subject: The regexp of the Freebox user agent is now more strict. A new unit test has been added in consequence. --- lib/private/request.php | 2 +- tests/lib/request.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/request.php b/lib/private/request.php index 855148ac25a..2c5b907846e 100755 --- a/lib/private/request.php +++ b/lib/private/request.php @@ -11,7 +11,7 @@ class OC_Request { const USER_AGENT_IE = '/MSIE/'; // Android Chrome user agent: https://developers.google.com/chrome/mobile/docs/user-agent const USER_AGENT_ANDROID_MOBILE_CHROME = '#Android.*Chrome/[.0-9]*#'; - const USER_AGENT_FREEBOX = '#Mozilla/5\.0$#'; + const USER_AGENT_FREEBOX = '#^Mozilla/5\.0$#'; /** * @brief Check overwrite condition diff --git a/tests/lib/request.php b/tests/lib/request.php index 3cb58674d3e..1d77acc70ae 100644 --- a/tests/lib/request.php +++ b/tests/lib/request.php @@ -128,6 +128,11 @@ class Test_Request extends PHPUnit_Framework_TestCase { OC_Request::USER_AGENT_FREEBOX, true ), + array( + 'Fake Mozilla/5.0', + OC_Request::USER_AGENT_FREEBOX, + false + ), ); } } -- cgit v1.2.3 From 229f13adc0eca770c07646e56773f1aa93fee643 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 29 Jan 2014 14:40:59 +0100 Subject: change order of issubdirectory() calls to avoid error messages for non-apps --- lib/private/l10n.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/private') diff --git a/lib/private/l10n.php b/lib/private/l10n.php index 98665c84c55..1aa1dc5ea28 100644 --- a/lib/private/l10n.php +++ b/lib/private/l10n.php @@ -132,10 +132,10 @@ class OC_L10N implements \OCP\IL10N { $i18ndir = self::findI18nDir($app); // Localization is in /l10n, Texts are in $i18ndir // (Just no need to define date/time format etc. twice) - if((OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC_App::getAppPath($app).'/l10n/') - || OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/core/l10n/') + if((OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/core/l10n/') || OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/lib/l10n/') || OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/settings') + || OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC_App::getAppPath($app).'/l10n/') ) && file_exists($i18ndir.$lang.'.php')) { // Include the file, save the data from $CONFIG -- cgit v1.2.3 From 0d9fe770f36c9aac53c41a6c8430bb68751937bb Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 31 Jan 2014 15:12:21 +0100 Subject: Mark an app as loaded before we start loading it --- lib/private/app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/app.php b/lib/private/app.php index 0c60557914a..da09021cf3f 100644 --- a/lib/private/app.php +++ b/lib/private/app.php @@ -63,8 +63,8 @@ class OC_App{ ob_start(); foreach( $apps as $app ) { if((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) { - self::loadApp($app); self::$loadedApps[] = $app; + self::loadApp($app); } } ob_end_clean(); -- cgit v1.2.3 From f1c60c7f8b12180917828775fcf4ba82ba68d573 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 31 Jan 2014 17:33:15 +0100 Subject: Remove unused functions from OC_Helper init_var and init_radio where only used in the installation template --- lib/private/helper.php | 23 ----------------------- 1 file changed, 23 deletions(-) (limited to 'lib/private') diff --git a/lib/private/helper.php b/lib/private/helper.php index 58bee9c6300..ce5708e2bb9 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -448,29 +448,6 @@ class OC_Helper { * */ - //FIXME: should also check for value validation (i.e. the email is an email). - public static function init_var($s, $d = "") { - $r = $d; - if (isset($_REQUEST[$s]) && !empty($_REQUEST[$s])) { - $r = OC_Util::sanitizeHTML($_REQUEST[$s]); - } - - return $r; - } - - /** - * returns "checked"-attribute if request contains selected radio element - * OR if radio element is the default one -- maybe? - * - * @param string $s Name of radio-button element name - * @param string $v Value of current radio-button element - * @param string $d Value of default radio-button element - */ - public static function init_radio($s, $v, $d) { - if ((isset($_REQUEST[$s]) && $_REQUEST[$s] == $v) || (!isset($_REQUEST[$s]) && $v == $d)) - print "checked=\"checked\" "; - } - /** * detect if a given program is found in the search PATH * -- cgit v1.2.3 From 44b637470c57f098d328bc6d298be9385d3f30c4 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 31 Jan 2014 12:28:21 +0100 Subject: remove passwords in URLs from all log messages --- lib/private/log/errorhandler.php | 15 ++++++++++++--- lib/private/log/owncloud.php | 1 - 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'lib/private') diff --git a/lib/private/log/errorhandler.php b/lib/private/log/errorhandler.php index 69cb960de91..4460468336b 100644 --- a/lib/private/log/errorhandler.php +++ b/lib/private/log/errorhandler.php @@ -14,6 +14,15 @@ class ErrorHandler { /** @var LoggerInterface */ private static $logger; + /** + * @brief remove password in URLs + * @param string $msg + * @return string + */ + private static function removePassword($msg) { + return preg_replace('/\/\/(.*):(.*)@/', '//xxx:xxx@', $msg); + } + public static function register() { $handler = new ErrorHandler(); @@ -32,14 +41,14 @@ class ErrorHandler { if($error && self::$logger) { //ob_end_clean(); $msg = $error['message'] . ' at ' . $error['file'] . '#' . $error['line']; - self::$logger->critical($msg, array('app' => 'PHP')); + self::$logger->critical(self::removePassword($msg), array('app' => 'PHP')); } } // Uncaught exception handler public static function onException($exception) { $msg = $exception->getMessage() . ' at ' . $exception->getFile() . '#' . $exception->getLine(); - self::$logger->critical($msg, array('app' => 'PHP')); + self::$logger->critical(self::removePassword($msg), array('app' => 'PHP')); } //Recoverable errors handler @@ -48,7 +57,7 @@ class ErrorHandler { return; } $msg = $message . ' at ' . $file . '#' . $line; - self::$logger->warning($msg, array('app' => 'PHP')); + self::$logger->warning(self::removePassword($msg), array('app' => 'PHP')); } } diff --git a/lib/private/log/owncloud.php b/lib/private/log/owncloud.php index 4c86d0e45e0..3590bbd436d 100644 --- a/lib/private/log/owncloud.php +++ b/lib/private/log/owncloud.php @@ -69,7 +69,6 @@ class OC_Log_Owncloud { } $time = new DateTime(null, $timezone); // remove username/passswords from URLs before writing the to the log file - $message = preg_replace('/\/\/(.*):(.*)@/', '//xxx:xxx@', $message); $entry=array('app'=>$app, 'message'=>$message, 'level'=>$level, 'time'=> $time->format($format)); $entry = json_encode($entry); $handle = @fopen(self::$logFile, 'a'); -- cgit v1.2.3 From cf5277b558e1838a1b8126621cb8cd5a0ca60cb4 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 31 Jan 2014 13:27:51 +0100 Subject: also load error handler if debugging is enabled --- lib/base.php | 3 ++- lib/private/log/errorhandler.php | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'lib/private') diff --git a/lib/base.php b/lib/base.php index af78b4e4eb1..b54b2973551 100644 --- a/lib/base.php +++ b/lib/base.php @@ -504,11 +504,12 @@ class OC { if (!defined('PHPUNIT_RUN')) { if (defined('DEBUG') and DEBUG) { + OC\Log\ErrorHandler::register(true); set_exception_handler(array('OC_Template', 'printExceptionErrorPage')); } else { OC\Log\ErrorHandler::register(); - OC\Log\ErrorHandler::setLogger(OC_Log::$object); } + OC\Log\ErrorHandler::setLogger(OC_Log::$object); } // register the stream wrappers diff --git a/lib/private/log/errorhandler.php b/lib/private/log/errorhandler.php index 4460468336b..f6c96ef8218 100644 --- a/lib/private/log/errorhandler.php +++ b/lib/private/log/errorhandler.php @@ -23,10 +23,14 @@ class ErrorHandler { return preg_replace('/\/\/(.*):(.*)@/', '//xxx:xxx@', $msg); } - public static function register() { + public static function register($debug=false) { $handler = new ErrorHandler(); - set_error_handler(array($handler, 'onError')); + if ($debug) { + set_error_handler(array($handler, 'onAll'), E_ALL); + } else { + set_error_handler(array($handler, 'onError')); + } register_shutdown_function(array($handler, 'onShutdown')); set_exception_handler(array($handler, 'onException')); } @@ -57,7 +61,15 @@ class ErrorHandler { return; } $msg = $message . ' at ' . $file . '#' . $line; - self::$logger->warning(self::removePassword($msg), array('app' => 'PHP')); + self::$logger->error(self::removePassword($msg), array('app' => 'PHP')); + + } + + //Recoverable handler which catch all errors, warnings and notices + public static function onAll($number, $message, $file, $line) { + $msg = $message . ' at ' . $file . '#' . $line; + self::$logger->debug(self::removePassword($msg), array('app' => 'PHP')); } + } -- cgit v1.2.3 From 8d6a3a00b47aa7d034de378f498a7d5e329a8e1d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 3 Feb 2014 16:29:04 +0100 Subject: Revert "Use Cache->clear to cleanup the filecache for removed users" This reverts commit 5a5b6f187e719e6c0bac5e64c411eb74e6d28389. --- lib/private/user.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'lib/private') diff --git a/lib/private/user.php b/lib/private/user.php index 7932f4aef76..2519200d0f0 100644 --- a/lib/private/user.php +++ b/lib/private/user.php @@ -205,13 +205,8 @@ class OC_User { // Delete user files in /data/ OC_Helper::rmdirr(\OC_User::getHome($uid)); - // Cleanup the filecache - $mount = \OC\Files\Filesystem::getMountByStorageId('home::' . $uid); - if (count($mount) > 0) { - $mount = $mount[0]; - $cache = $mount->getStorage()->getCache(); - $cache->clear(); - } + // Delete the users entry in the storage table + \OC\Files\Cache\Storage::remove('home::' . $uid); // Remove it from the Cache self::getManager()->delete($uid); @@ -248,15 +243,15 @@ class OC_User { $uid = $backend->getCurrentUserId(); $run = true; - OC_Hook::emit("OC_User", "pre_login", array("run" => &$run, "uid" => $uid)); + OC_Hook::emit( "OC_User", "pre_login", array( "run" => &$run, "uid" => $uid )); - if ($uid) { + if($uid) { session_regenerate_id(true); self::setUserId($uid); self::setDisplayName($uid); self::getUserSession()->setLoginName($uid); - OC_Hook::emit("OC_User", "post_login", array("uid" => $uid, 'password' => '')); + OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid, 'password'=>'' )); return true; } return false; -- cgit v1.2.3 From 0ae4022fb4fc6ade3ed300205ccdcdd32863dcdc Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 3 Feb 2014 16:36:21 +0100 Subject: Also clean up the filecache table when deleting a storage entry --- lib/private/files/cache/storage.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/private') diff --git a/lib/private/files/cache/storage.php b/lib/private/files/cache/storage.php index 6d7a1002c1b..5b1b30176e8 100644 --- a/lib/private/files/cache/storage.php +++ b/lib/private/files/cache/storage.php @@ -77,10 +77,16 @@ class Storage { * @param string $storageId */ public static function remove($storageId) { + $storageCache = new Storage($storageId); + $numericId = $storageCache->getNumericId(); + if (strlen($storageId) > 64) { $storageId = md5($storageId); } $sql = 'DELETE FROM `*PREFIX*storages` WHERE `id` = ?'; \OC_DB::executeAudited($sql, array($storageId)); + + $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `storage` = ?'; + \OC_DB::executeAudited($sql, array($numericId)); } } -- cgit v1.2.3 From 36838b2837168b69aba82f88f110c174db25e6d7 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 4 Feb 2014 11:11:24 +0100 Subject: add test for password remove method --- lib/private/log/errorhandler.php | 2 +- tests/lib/errorHandler.php | 62 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 tests/lib/errorHandler.php (limited to 'lib/private') diff --git a/lib/private/log/errorhandler.php b/lib/private/log/errorhandler.php index f6c96ef8218..1dde6b507fc 100644 --- a/lib/private/log/errorhandler.php +++ b/lib/private/log/errorhandler.php @@ -19,7 +19,7 @@ class ErrorHandler { * @param string $msg * @return string */ - private static function removePassword($msg) { + protected static function removePassword($msg) { return preg_replace('/\/\/(.*):(.*)@/', '//xxx:xxx@', $msg); } diff --git a/tests/lib/errorHandler.php b/tests/lib/errorHandler.php new file mode 100644 index 00000000000..68b87deccb6 --- /dev/null +++ b/tests/lib/errorHandler.php @@ -0,0 +1,62 @@ + + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see . + * + */ + +class Test_ErrorHandler extends \PHPUnit_Framework_TestCase { + + /** + * @brief provide username, password combinations for testRemovePassword + * @return array + */ + function passwordProvider() { + return array( + array('user', 'password'), + array('user@owncloud.org', 'password'), + array('user', 'pass@word'), + array('us:er', 'password'), + array('user', 'pass:word'), + ); + + } + + /** + * @dataProvider passwordProvider + * @param string $username + * @param string $password + */ + function testRemovePassword($username, $password) { + $url = 'http://'.$username.':'.$password.'@owncloud.org'; + $expectedResult = 'http://xxx:xxx@owncloud.org'; + $result = TestableErrorHandler::testRemovePassword($url); + + $this->assertEquals($expectedResult, $result); + } + +} + +/** + * @brief dummy class to access protected methods of \OC\Log\ErrorHandler + */ +class TestableErrorHandler extends \OC\Log\ErrorHandler { + public static function testRemovePassword($msg) { + return self::removePassword($msg); + } +} -- cgit v1.2.3 From d55ef442cd861d04b9ccfd4493aedf0c9a4164ff Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 4 Feb 2014 12:59:14 +0100 Subject: properly check if pdf and svg modules are installed --- lib/private/preview/office.php | 2 +- lib/private/preview/pdf.php | 2 +- lib/private/preview/svg.php | 2 +- lib/private/preview/unknown.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/private') diff --git a/lib/private/preview/office.php b/lib/private/preview/office.php index 7a4826c76ec..884b6e7dc9b 100644 --- a/lib/private/preview/office.php +++ b/lib/private/preview/office.php @@ -6,7 +6,7 @@ * See the COPYING-README file. */ //both, libreoffice backend and php fallback, need imagick -if (extension_loaded('imagick')) { +if (extension_loaded('imagick') && count(\Imagick::queryFormats("PDF")) === 1) { $isShellExecEnabled = \OC_Helper::is_function_enabled('shell_exec'); // LibreOffice preview is currently not supported on Windows diff --git a/lib/private/preview/pdf.php b/lib/private/preview/pdf.php index cc974b68818..572b8788ac9 100644 --- a/lib/private/preview/pdf.php +++ b/lib/private/preview/pdf.php @@ -7,7 +7,7 @@ */ namespace OC\Preview; -if (extension_loaded('imagick')) { +if (extension_loaded('imagick') && count(\Imagick::queryFormats("PDF")) === 1) { class PDF extends Provider { diff --git a/lib/private/preview/svg.php b/lib/private/preview/svg.php index b49e51720fa..07a37e8f8c1 100644 --- a/lib/private/preview/svg.php +++ b/lib/private/preview/svg.php @@ -7,7 +7,7 @@ */ namespace OC\Preview; -if (extension_loaded('imagick')) { +if (extension_loaded('imagick') && count(\Imagick::queryFormats("SVG")) === 1) { class SVG extends Provider { diff --git a/lib/private/preview/unknown.php b/lib/private/preview/unknown.php index 4747f9e25ed..8145c826149 100644 --- a/lib/private/preview/unknown.php +++ b/lib/private/preview/unknown.php @@ -22,7 +22,7 @@ class Unknown extends Provider { $svgPath = substr_replace($path, 'svg', -3); - if (extension_loaded('imagick') && file_exists($svgPath)) { + if (extension_loaded('imagick') && file_exists($svgPath) && count(\Imagick::queryFormats("SVG")) === 1) { // http://www.php.net/manual/de/imagick.setresolution.php#85284 $svg = new \Imagick(); -- cgit v1.2.3 From 11f46e121caa30f46250a1980e315520d68eb593 Mon Sep 17 00:00:00 2001 From: Jens-Christian Fischer Date: Tue, 4 Feb 2014 17:03:52 +0100 Subject: close statement in MimeType detection is executed [#7069] close statement was never executed due to it being after a return statement. --- lib/private/files/type/detection.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/files/type/detection.php b/lib/private/files/type/detection.php index d7cc9ebbf4e..11e439032ce 100644 --- a/lib/private/files/type/detection.php +++ b/lib/private/files/type/detection.php @@ -72,11 +72,12 @@ class Detection { and function_exists('finfo_file') and $finfo = finfo_open(FILEINFO_MIME) ) { $info = @strtolower(finfo_file($finfo, $path)); + finfo_close($finfo); if ($info) { $mimeType = substr($info, 0, strpos($info, ';')); return empty($mimeType) ? 'application/octet-stream' : $mimeType; } - finfo_close($finfo); + } $isWrapped = (strpos($path, '://') !== false) and (substr($path, 0, 7) === 'file://'); if (!$isWrapped and $mimeType === 'application/octet-stream' && function_exists("mime_content_type")) { -- cgit v1.2.3 From dc53c83e7bdbadeb24c74fe1c7794de54811c264 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 28 Jan 2014 17:42:26 +0100 Subject: getData() always needs to return an array --- lib/private/ocs/result.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'lib/private') diff --git a/lib/private/ocs/result.php b/lib/private/ocs/result.php index 84f06fa01c7..9f14e8da7e8 100644 --- a/lib/private/ocs/result.php +++ b/lib/private/ocs/result.php @@ -29,7 +29,13 @@ class OC_OCS_Result{ * @param $data mixed the data to return */ public function __construct($data=null, $code=100, $message=null) { - $this->data = $data; + if ($data === null) { + $this->data = array(); + } elseif (!is_array($data)) { + $this->data = array($this->data); + } else { + $this->data = $data; + } $this->statusCode = $code; $this->message = $message; } @@ -49,7 +55,7 @@ class OC_OCS_Result{ public function setItemsPerPage(int $items) { $this->perPage = $items; } - + /** * get the status code * @return int @@ -57,7 +63,7 @@ class OC_OCS_Result{ public function getStatusCode() { return $this->statusCode; } - + /** * get the meta data for the result * @return array @@ -76,15 +82,15 @@ class OC_OCS_Result{ return $meta; } - + /** * get the result data - * @return array|string|int + * @return array */ public function getData() { return $this->data; } - + /** * return bool if the method succedded * @return bool -- cgit v1.2.3 From dbec143f09f32832a52fb507ababb84518721370 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 7 Feb 2014 16:09:31 +0100 Subject: Change MySQL to MySQL/MariaDB in the frontend Fix issue #6269 --- core/setup/controller.php | 2 +- lib/private/setup/mysql.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/private') diff --git a/core/setup/controller.php b/core/setup/controller.php index 58ed4d28dc0..697408cfb57 100644 --- a/core/setup/controller.php +++ b/core/setup/controller.php @@ -91,7 +91,7 @@ class Controller { $databases['sqlite'] = 'SQLite'; } if ($hasMySQL) { - $databases['mysql'] = 'MySQL'; + $databases['mysql'] = 'MySQL/MariaDB'; } if ($hasPostgreSQL) { $databases['pgsql'] = 'PostgreSQL'; diff --git a/lib/private/setup/mysql.php b/lib/private/setup/mysql.php index d97b6d2602f..b2c28173b1c 100644 --- a/lib/private/setup/mysql.php +++ b/lib/private/setup/mysql.php @@ -3,13 +3,13 @@ namespace OC\Setup; class MySQL extends AbstractDatabase { - public $dbprettyname = 'MySQL'; + public $dbprettyname = 'MySQL/MariaDB'; public function setupDatabase($username) { //check if the database user has admin right $connection = @mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword); if(!$connection) { - throw new \DatabaseSetupException($this->trans->t('MySQL username and/or password not valid'), + throw new \DatabaseSetupException($this->trans->t('MySQL/MariaDB username and/or password not valid'), $this->trans->t('You need to enter either an existing account or the administrator.')); } $oldUser=\OC_Config::getValue('dbuser', false); @@ -82,14 +82,14 @@ class MySQL extends AbstractDatabase { $query = "CREATE USER '$name'@'localhost' IDENTIFIED BY '$password'"; $result = mysql_query($query, $connection); if (!$result) { - throw new \DatabaseSetupException($this->trans->t("MySQL user '%s'@'localhost' exists already.", array($name)), - $this->trans->t("Drop this user from MySQL", array($name))); + throw new \DatabaseSetupException($this->trans->t("MySQL/MariaDB user '%s'@'localhost' exists already.", array($name)), + $this->trans->t("Drop this user from MySQL/MariaDB", array($name))); } $query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'"; $result = mysql_query($query, $connection); if (!$result) { - throw new \DatabaseSetupException($this->trans->t("MySQL user '%s'@'%%' already exists", array($name)), - $this->trans->t("Drop this user from MySQL.")); + throw new \DatabaseSetupException($this->trans->t("MySQL/MariaDB user '%s'@'%%' already exists", array($name)), + $this->trans->t("Drop this user from MySQL/MariaDB.")); } } } -- cgit v1.2.3