From 2c8e5ec84ff98088fb9e3b275735098beaa5e27f Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Mon, 10 Jun 2013 11:03:07 +0200 Subject: user interface to allow user to decrypt all his files once the encryption app was disabled Conflicts: settings/templates/personal.php --- apps/files_encryption/lib/helper.php | 27 +++++++++++++++++++++++++++ apps/files_encryption/lib/proxy.php | 6 +++--- apps/files_encryption/lib/stream.php | 14 +++++++++----- 3 files changed, 39 insertions(+), 8 deletions(-) (limited to 'apps/files_encryption') diff --git a/apps/files_encryption/lib/helper.php b/apps/files_encryption/lib/helper.php index 6eee8fed6a6..f5a5d269a69 100755 --- a/apps/files_encryption/lib/helper.php +++ b/apps/files_encryption/lib/helper.php @@ -199,12 +199,39 @@ class Helper { public static function stripUserFilesPath($path) { $trimmed = ltrim($path, '/'); $split = explode('/', $trimmed); + + // it is not a file relative to data/user/files + if ($split[1] !== 'files') { + return false; + } + $sliced = array_slice($split, 2); $relPath = implode('/', $sliced); return $relPath; } + /** + * @brief get path to the correspondig file in data/user/files + * @param string $path path to a version or a file in the trash + * @return string path to correspondig file relative to data/user/files + */ + public static function getPathToRealFile($path) { + $trimmed = ltrim($path, '/'); + $split = explode('/', $trimmed); + + if ($split[1] !== "files_versions") { + return false; + } + + $sliced = array_slice($split, 2); + $realPath = implode('/', $sliced); + //remove the last .v + $realPath = substr($realPath, 0, strrpos($realPath, '.v')); + + return $realPath; + } + /** * @brief redirect to a error page */ diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index 735eba911a9..12fee750a6a 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -116,7 +116,7 @@ class Proxy extends \OC_FileProxy { return true; } - $handle = fopen('crypt://' . $relativePath . '.etmp', 'w'); + $handle = fopen('crypt://' . $path . '.etmp', 'w'); if (is_resource($handle)) { // write data to stream @@ -296,14 +296,14 @@ class Proxy extends \OC_FileProxy { // Open the file using the crypto stream wrapper // protocol and let it do the decryption work instead - $result = fopen('crypt://' . $relativePath, $meta['mode']); + $result = fopen('crypt://' . $path, $meta['mode']); } elseif ( self::shouldEncrypt($path) and $meta ['mode'] !== 'r' and $meta['mode'] !== 'rb' ) { - $result = fopen('crypt://' . $relativePath, $meta['mode']); + $result = fopen('crypt://' . $path, $meta['mode']); } // Re-enable the proxy diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php index 3c1eb2c5f5e..2f7af1410b9 100644 --- a/apps/files_encryption/lib/stream.php +++ b/apps/files_encryption/lib/stream.php @@ -73,7 +73,7 @@ class Stream { private $privateKey; /** - * @param $path + * @param $path raw path relative to data/ * @param $mode * @param $options * @param $opened_path @@ -93,12 +93,16 @@ class Stream { $this->userId = $util->getUserId(); - // Strip identifier text from path, this gives us the path relative to data//files - $this->relPath = \OC\Files\Filesystem::normalizePath(str_replace('crypt://', '', $path)); - // rawPath is relative to the data directory - $this->rawPath = $util->getUserFilesDir() . $this->relPath; + $this->rawPath = \OC\Files\Filesystem::normalizePath(str_replace('crypt://', '', $path)); + // Strip identifier text from path, this gives us the path relative to data//files + $this->relPath = Helper::stripUserFilesPath($this->rawPath); + // if raw path doesn't point to a real file, check if it is a version or a file in the trash bin + if ($this->relPath === false) { + $this->relPath = Helper::getPathToRealFile($this->rawPath); + } + // Disable fileproxies so we can get the file size and open the source file without recursive encryption $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; -- cgit v1.2.3