From c4aef892788ced15812cc31abcf34c085b66ce5a Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Thu, 27 Jun 2013 14:09:22 +0200 Subject: introduce pre-disable-app hook and use it for the encryption app to reset migration status if the app was disabled --- apps/files_encryption/hooks/hooks.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'apps/files_encryption/hooks') diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index e39e068cc5d..09153918940 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -543,4 +543,17 @@ class Hooks { \OC_FileProxy::$enabled = $proxyStatus; } + + /** + * set migration status back to '0' so that all new files get encrypted + * if the app gets enabled again + * @param array $params contains the app ID + */ + public static function preDisable($params) { + if ($params['app'] === 'files_encryption') { + $query = \OC_DB::prepare('UPDATE `*PREFIX*encryption` SET `migration_status`=0'); + $query->execute(); + } + } + } -- cgit v1.2.3 From adcee5b695c25bc9e06dc9aeddb4ae2713a2ea05 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Mon, 1 Jul 2013 12:16:36 +0200 Subject: check php version, the encryption app needs php >= 5.3.3 --- apps/files_encryption/appinfo/app.php | 5 ++--- apps/files_encryption/hooks/hooks.php | 8 ++++---- apps/files_encryption/lib/helper.php | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 7 deletions(-) (limited to 'apps/files_encryption/hooks') diff --git a/apps/files_encryption/appinfo/app.php b/apps/files_encryption/appinfo/app.php index d97811bb791..78b226be013 100644 --- a/apps/files_encryption/appinfo/app.php +++ b/apps/files_encryption/appinfo/app.php @@ -34,10 +34,9 @@ if (!OC_Config::getValue('maintenance', false)) { $view = new OC_FilesystemView('/'); - $sessionReady = false; - if(extension_loaded("openssl")) { + $sessionReady = OCA\Encryption\Helper::checkRequirements(); + if($sessionReady) { $session = new \OCA\Encryption\Session($view); - $sessionReady = true; } $user = \OCP\USER::getUser(); diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index e39e068cc5d..786de177e89 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -39,10 +39,10 @@ class Hooks { */ public static function login($params) { $l = new \OC_L10N('files_encryption'); - //check if openssl is available - if(!extension_loaded("openssl") ) { - $error_msg = $l->t("PHP module OpenSSL is not installed."); - $hint = $l->t('Please ask your server administrator to install the module. For now the encryption app was disabled.'); + //check if all requirements are met + if(!Helper::checkRequirements() ) { + $error_msg = $l->t("Missing requirements."); + $hint = $l->t('Please make sure that the OpenSSL module and PHP >0 5.3.3 is installed. For now the encryption app was disabled.'); \OC_App::disable('files_encryption'); \OCP\Util::writeLog('Encryption library', $error_msg . ' ' . $hint, \OCP\Util::ERROR); \OCP\Template::printErrorPage($error_msg, $hint); diff --git a/apps/files_encryption/lib/helper.php b/apps/files_encryption/lib/helper.php index a22c139c503..f6201c7e5ff 100755 --- a/apps/files_encryption/lib/helper.php +++ b/apps/files_encryption/lib/helper.php @@ -208,4 +208,20 @@ class Helper { header('Location: ' . $location . '?p=' . $post); exit(); } + + + /** + * check requirements for encryptoin app. + * @return bool true if requirements are met + */ + public static function checkRequirements() { + $result = true; + + //openssl extension needs to be loaded + $result &= extension_loaded("openssl"); + // we need php >= 5.3.3 + $result &= version_compare(phpversion(), '5.3.11', '>='); + + return $result; + } } \ No newline at end of file -- cgit v1.2.3 From 9512382ae0c7d96a15dc10d7daeef72d89ca0ad2 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Mon, 1 Jul 2013 12:24:21 +0200 Subject: fix error string --- apps/files_encryption/hooks/hooks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps/files_encryption/hooks') diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 786de177e89..f340425e0f0 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -42,7 +42,7 @@ class Hooks { //check if all requirements are met if(!Helper::checkRequirements() ) { $error_msg = $l->t("Missing requirements."); - $hint = $l->t('Please make sure that the OpenSSL module and PHP >0 5.3.3 is installed. For now the encryption app was disabled.'); + $hint = $l->t('Please make sure that the OpenSSL module and PHP >= 5.3.3 is installed. For now the encryption app was disabled.'); \OC_App::disable('files_encryption'); \OCP\Util::writeLog('Encryption library', $error_msg . ' ' . $hint, \OCP\Util::ERROR); \OCP\Template::printErrorPage($error_msg, $hint); -- cgit v1.2.3 From 40e6ede6a274f65b8ad29bfc5413baf5fbfe8eb4 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Tue, 2 Jul 2013 10:14:33 +0200 Subject: improved error message --- apps/files_encryption/hooks/hooks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps/files_encryption/hooks') diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index f340425e0f0..8d868c10b1a 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -42,7 +42,7 @@ class Hooks { //check if all requirements are met if(!Helper::checkRequirements() ) { $error_msg = $l->t("Missing requirements."); - $hint = $l->t('Please make sure that the OpenSSL module and PHP >= 5.3.3 is installed. For now the encryption app was disabled.'); + $hint = $l->t('Please make sure that the OpenSSL module and PHP >= 5.3.3 is installed. For now, the encryption app has been disabled.'); \OC_App::disable('files_encryption'); \OCP\Util::writeLog('Encryption library', $error_msg . ' ' . $hint, \OCP\Util::ERROR); \OCP\Template::printErrorPage($error_msg, $hint); -- cgit v1.2.3 From f30dd1557eda78f81a7a9e40bea8ae5bee61d36d Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Thu, 4 Jul 2013 14:50:07 +0200 Subject: more verbose error message --- apps/files_encryption/hooks/hooks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps/files_encryption/hooks') diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 8d868c10b1a..ed768f176aa 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -42,7 +42,7 @@ class Hooks { //check if all requirements are met if(!Helper::checkRequirements() ) { $error_msg = $l->t("Missing requirements."); - $hint = $l->t('Please make sure that the OpenSSL module and PHP >= 5.3.3 is installed. For now, the encryption app has been disabled.'); + $hint = $l->t('Please make sure that PHP 5.3.3 or newer is installed and that the OpenSSL PHP extension is enabled and configured properly. For now, the encryption app has been disabled.'); \OC_App::disable('files_encryption'); \OCP\Util::writeLog('Encryption library', $error_msg . ' ' . $hint, \OCP\Util::ERROR); \OCP\Template::printErrorPage($error_msg, $hint); -- cgit v1.2.3 From abc2ee2e07e1e4f73e6e50aa3855d15ca92f6468 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Tue, 25 Jun 2013 14:42:49 +0200 Subject: handle rename correctly for system wide mounts --- apps/files_encryption/hooks/hooks.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'apps/files_encryption/hooks') diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 197982010f9..96f06b154f8 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -476,10 +476,19 @@ class Hooks { $util = new Util($view, $userId); // Format paths to be relative to user files dir - $oldKeyfilePath = \OC\Files\Filesystem::normalizePath( - $userId . '/' . 'files_encryption' . '/' . 'keyfiles' . '/' . $params['oldpath']); - $newKeyfilePath = \OC\Files\Filesystem::normalizePath( - $userId . '/' . 'files_encryption' . '/' . 'keyfiles' . '/' . $params['newpath']); + if ($util->isSystemWideMountPoint($params['oldpath'])) { + $baseDir = 'files_encryption/'; + $oldKeyfilePath = $baseDir . 'keyfiles/' . $params['oldpath']; + } else { + $baseDir = $userId . '/' . 'files_encryption/'; + $oldKeyfilePath = $baseDir . 'keyfiles/' . $params['oldpath']; + } + + if ($util->isSystemWideMountPoint($params['newpath'])) { + $newKeyfilePath = $baseDir . 'keyfiles/' . $params['newpath']; + } else { + $newKeyfilePath = $baseDir . 'keyfiles/' . $params['newpath']; + } // add key ext if this is not an folder if (!$view->is_dir($oldKeyfilePath)) { @@ -487,7 +496,7 @@ class Hooks { $newKeyfilePath .= '.key'; // handle share-keys - $localKeyPath = $view->getLocalFile($userId . '/files_encryption/share-keys/' . $params['oldpath']); + $localKeyPath = $view->getLocalFile($baseDir . 'share-keys/' . $params['oldpath']); $matches = glob(preg_quote($localKeyPath) . '*.shareKey'); foreach ($matches as $src) { $dst = \OC\Files\Filesystem::normalizePath(str_replace($params['oldpath'], $params['newpath'], $src)); @@ -502,10 +511,8 @@ class Hooks { } else { // handle share-keys folders - $oldShareKeyfilePath = \OC\Files\Filesystem::normalizePath( - $userId . '/' . 'files_encryption' . '/' . 'share-keys' . '/' . $params['oldpath']); - $newShareKeyfilePath = \OC\Files\Filesystem::normalizePath( - $userId . '/' . 'files_encryption' . '/' . 'share-keys' . '/' . $params['newpath']); + $oldShareKeyfilePath = $baseDir . 'share-keys/' . $params['oldpath']; + $newShareKeyfilePath = $baseDir . 'share-keys/' . $params['newpath']; // create destination folder if not exists if (!$view->file_exists(dirname($newShareKeyfilePath))) { -- cgit v1.2.3 From f9c337dd2149248be717f870bdba79ac21868bbe Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Tue, 25 Jun 2013 16:50:10 +0200 Subject: only escape glob pattern --- apps/files_encryption/hooks/hooks.php | 3 ++- apps/files_encryption/lib/keymanager.php | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'apps/files_encryption/hooks') diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 96f06b154f8..c26119b6c2e 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -497,7 +497,8 @@ class Hooks { // handle share-keys $localKeyPath = $view->getLocalFile($baseDir . 'share-keys/' . $params['oldpath']); - $matches = glob(preg_quote($localKeyPath) . '*.shareKey'); + $escapedPath = preg_replace('/(\*|\?|\[)/', '[$1]', $localKeyPath); + $matches = glob($escapedPath . '*.shareKey'); foreach ($matches as $src) { $dst = \OC\Files\Filesystem::normalizePath(str_replace($params['oldpath'], $params['newpath'], $src)); diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index 8de1d413642..da2ee380e89 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -488,7 +488,8 @@ class Keymanager { $view->unlink($baseDir . $filePath); } else { $localKeyPath = $view->getLocalFile($baseDir . $filePath); - $matches = glob(preg_quote($localKeyPath) . '*.shareKey'); + $escapedPath = preg_replace('/(\*|\?|\[)/', '[$1]', $localKeyPath); + $matches = glob($escapedPath . '*.shareKey'); foreach ($matches as $ma) { $result = unlink($ma); if (!$result) { @@ -547,7 +548,10 @@ class Keymanager { */ private static function recursiveDelShareKeys($dir, $userIds) { foreach ($userIds as $userId) { - $matches = glob(preg_quote($dir) . '/*' . preg_quote('.' . $userId . '.shareKey')); + $extension = '.' . $userId . '.shareKey'; + $escapedDir = preg_replace('/(\*|\?|\[)/', '[$1]', $dir); + $escapedExtension = preg_replace('/(\*|\?|\[)/', '[$1]', $extension); + $matches = glob($escapedDir . '/*' . $escapedExtension); } /** @var $matches array */ foreach ($matches as $ma) { @@ -556,7 +560,7 @@ class Keymanager { 'Could not delete shareKey; does not exist: "' . $ma . '"', \OCP\Util::ERROR); } } - $subdirs = $directories = glob(preg_quote($dir) . '/*', GLOB_ONLYDIR); + $subdirs = $directories = glob($escapedDir . '/*', GLOB_ONLYDIR); foreach ($subdirs as $subdir) { self::recursiveDelShareKeys($subdir, $userIds); } -- cgit v1.2.3 From 9575c2f37c39ae0799c3b8faec4d7902d17e6832 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Fri, 5 Jul 2013 14:58:33 +0200 Subject: added helper function to escape glob pattern Conflicts: apps/files_encryption/lib/helper.php --- apps/files_encryption/hooks/hooks.php | 2 +- apps/files_encryption/lib/helper.php | 12 +++++++++++- apps/files_encryption/lib/keymanager.php | 6 +++--- 3 files changed, 15 insertions(+), 5 deletions(-) (limited to 'apps/files_encryption/hooks') diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index c26119b6c2e..b2a17f6bca5 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -497,7 +497,7 @@ class Hooks { // handle share-keys $localKeyPath = $view->getLocalFile($baseDir . 'share-keys/' . $params['oldpath']); - $escapedPath = preg_replace('/(\*|\?|\[)/', '[$1]', $localKeyPath); + $escapedPath = Helper::escapeGlobPattern($localKeyPath); $matches = glob($escapedPath . '*.shareKey'); foreach ($matches as $src) { $dst = \OC\Files\Filesystem::normalizePath(str_replace($params['oldpath'], $params['newpath'], $src)); diff --git a/apps/files_encryption/lib/helper.php b/apps/files_encryption/lib/helper.php index 31cf48a0393..1b9637c1b9a 100755 --- a/apps/files_encryption/lib/helper.php +++ b/apps/files_encryption/lib/helper.php @@ -218,7 +218,6 @@ class Helper { exit(); } - /** * check requirements for encryption app. * @return bool true if requirements are met @@ -234,3 +233,14 @@ class Helper { return (bool) $result; } } + + /** + * @brief glob uses different pattern than regular expressions, escape glob pattern only + * @param unescaped path + * @return escaped path + */ + public static function escapeGlobPattern($path) { + return preg_replace('/(\*|\?|\[)/', '[$1]', $path); + } +} + diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index da2ee380e89..b2fd650f18d 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -488,7 +488,7 @@ class Keymanager { $view->unlink($baseDir . $filePath); } else { $localKeyPath = $view->getLocalFile($baseDir . $filePath); - $escapedPath = preg_replace('/(\*|\?|\[)/', '[$1]', $localKeyPath); + $escapedPath = Helper::escapeGlobPattern($localKeyPath); $matches = glob($escapedPath . '*.shareKey'); foreach ($matches as $ma) { $result = unlink($ma); @@ -549,8 +549,8 @@ class Keymanager { private static function recursiveDelShareKeys($dir, $userIds) { foreach ($userIds as $userId) { $extension = '.' . $userId . '.shareKey'; - $escapedDir = preg_replace('/(\*|\?|\[)/', '[$1]', $dir); - $escapedExtension = preg_replace('/(\*|\?|\[)/', '[$1]', $extension); + $escapedDir = Helper::escapeGlobPattern($dir); + $escapedExtension = Helper::escapeGlobPattern($extension); $matches = glob($escapedDir . '/*' . $escapedExtension); } /** @var $matches array */ -- cgit v1.2.3