diff options
-rw-r--r-- | apps/files_encryption/lib/proxy.php | 20 | ||||
-rw-r--r-- | apps/files_encryption/lib/stream.php | 6 | ||||
-rw-r--r-- | apps/files_encryption/lib/util.php | 59 | ||||
-rw-r--r-- | apps/files_encryption/tests/proxy.php | 13 | ||||
-rwxr-xr-x | apps/files_encryption/tests/util.php | 97 | ||||
-rw-r--r-- | apps/files_external/appinfo/info.xml | 1 | ||||
-rw-r--r-- | apps/files_sharing/appinfo/update.php | 12 | ||||
-rw-r--r-- | apps/files_sharing/appinfo/version | 2 | ||||
-rw-r--r-- | apps/files_sharing/js/public.js | 7 | ||||
-rw-r--r-- | apps/files_sharing/lib/migration.php | 42 | ||||
-rw-r--r-- | apps/files_sharing/tests/migrationtest.php | 76 | ||||
-rw-r--r-- | core/js/update.js | 12 | ||||
-rw-r--r-- | core/templates/update.admin.php | 2 | ||||
-rw-r--r-- | lib/private/util.php | 8 | ||||
-rw-r--r-- | settings/ajax/deletekeys.php | 8 | ||||
-rw-r--r-- | settings/ajax/restorekeys.php | 15 |
16 files changed, 306 insertions, 74 deletions
diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index 4972e1dffd6..07fd878f069 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -47,16 +47,15 @@ class Proxy extends \OC_FileProxy { * check if path is excluded from encryption * * @param string $path relative to data/ - * @param string $uid user * @return boolean */ - protected function isExcludedPath($path, $uid) { + protected function isExcludedPath($path) { $view = new \OC\Files\View(); - $path = \OC\Files\Filesystem::normalizePath($path); + $normalizedPath = \OC\Files\Filesystem::normalizePath($path); - $parts = explode('/', $path); + $parts = explode('/', $normalizedPath); // we only encrypt/decrypt files in the files and files_versions folder if (sizeof($parts) < 3) { @@ -69,18 +68,18 @@ class Proxy extends \OC_FileProxy { return true; } if( - strpos($path, '/' . $uid . '/files/') !== 0 && + !($parts[2] === 'files' && \OCP\User::userExists($parts[1])) && !($parts[2] === 'files_versions' && \OCP\User::userExists($parts[1]))) { return true; } - if (!$view->file_exists($path)) { - $path = dirname($path); + if (!$view->file_exists($normalizedPath)) { + $normalizedPath = dirname($normalizedPath); } // we don't encrypt server-to-server shares - list($storage, ) = \OC\Files\Filesystem::resolvePath($path); + list($storage, ) = \OC\Files\Filesystem::resolvePath($normalizedPath); /** * @var \OCP\Files\Storage $storage */ @@ -102,17 +101,16 @@ class Proxy extends \OC_FileProxy { */ private function shouldEncrypt($path, $mode = 'w') { - $userId = Helper::getUser($path); - // don't call the crypt stream wrapper, if... if ( Crypt::mode() !== 'server' // we are not in server-side-encryption mode - || $this->isExcludedPath($path, $userId) // if path is excluded from encryption + || $this->isExcludedPath($path) // if path is excluded from encryption || substr($path, 0, 8) === 'crypt://' // we are already in crypt mode ) { return false; } + $userId = Helper::getUser($path); $view = new \OC\Files\View(''); $util = new Util($view, $userId); diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php index 1bc0d54e1bc..b039e808c24 100644 --- a/apps/files_encryption/lib/stream.php +++ b/apps/files_encryption/lib/stream.php @@ -136,7 +136,8 @@ class Stream { switch ($fileType) { case Util::FILE_TYPE_FILE: $this->relPath = Helper::stripUserFilesPath($this->rawPath); - $this->userId = \OC::$server->getUserSession()->getUser()->getUID(); + $user = \OC::$server->getUserSession()->getUser(); + $this->userId = $user ? $user->getUID() : Helper::getUserFromPath($this->rawPath); break; case Util::FILE_TYPE_VERSION: $this->relPath = Helper::getPathFromVersion($this->rawPath); @@ -145,7 +146,8 @@ class Stream { case Util::FILE_TYPE_CACHE: $this->relPath = Helper::getPathFromCachedFile($this->rawPath); Helper::mkdirr($this->rawPath, new \OC\Files\View('/')); - $this->userId = \OC::$server->getUserSession()->getUser()->getUID(); + $user = \OC::$server->getUserSession()->getUser(); + $this->userId = $user ? $user->getUID() : Helper::getUserFromPath($this->rawPath); break; default: \OCP\Util::writeLog('Encryption library', 'failed to open file "' . $this->rawPath . '" expecting a path to "files", "files_versions" or "cache"', \OCP\Util::ERROR); diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index 1b140822724..c1f273d86ed 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -734,7 +734,7 @@ class Util { } if ($successful) { - $this->backupAllKeys('decryptAll'); + $this->backupAllKeys('decryptAll', false, false); $this->view->deleteAll($this->keysPath); } @@ -1495,16 +1495,61 @@ class Util { /** * create a backup of all keys from the user * - * @param string $purpose (optional) define the purpose of the backup, will be part of the backup folder + * @param string $purpose define the purpose of the backup, will be part of the backup folder name + * @param boolean $timestamp (optional) should a timestamp be added, default true + * @param boolean $includeUserKeys (optional) include users private-/public-key, default true */ - public function backupAllKeys($purpose = '') { + public function backupAllKeys($purpose, $timestamp = true, $includeUserKeys = true) { $this->userId; - $backupDir = $this->encryptionDir . '/backup.'; - $backupDir .= ($purpose === '') ? date("Y-m-d_H-i-s") . '/' : $purpose . '.' . date("Y-m-d_H-i-s") . '/'; + $backupDir = $this->encryptionDir . '/backup.' . $purpose; + $backupDir .= ($timestamp) ? '.' . date("Y-m-d_H-i-s") . '/' : '/'; $this->view->mkdir($backupDir); $this->view->copy($this->keysPath, $backupDir . 'keys/'); - $this->view->copy($this->privateKeyPath, $backupDir . $this->userId . '.privateKey'); - $this->view->copy($this->publicKeyPath, $backupDir . $this->userId . '.publicKey'); + if ($includeUserKeys) { + $this->view->copy($this->privateKeyPath, $backupDir . $this->userId . '.privateKey'); + $this->view->copy($this->publicKeyPath, $backupDir . $this->userId . '.publicKey'); + } + } + + /** + * restore backup + * + * @param string $backup complete name of the backup + * @return boolean + */ + public function restoreBackup($backup) { + $backupDir = $this->encryptionDir . '/backup.' . $backup . '/'; + + $fileKeysRestored = $this->view->rename($backupDir . 'keys', $this->encryptionDir . '/keys'); + + $pubKeyRestored = $privKeyRestored = true; + if ( + $this->view->file_exists($backupDir . $this->userId . '.privateKey') && + $this->view->file_exists($backupDir . $this->userId . '.privateKey') + ) { + + $pubKeyRestored = $this->view->rename($backupDir . $this->userId . '.publicKey', $this->publicKeyPath); + $privKeyRestored = $this->view->rename($backupDir . $this->userId . '.privateKey', $this->privateKeyPath); + } + + if ($fileKeysRestored && $pubKeyRestored && $privKeyRestored) { + $this->view->deleteAll($backupDir); + + return true; + } + + return false; + } + + /** + * delete backup + * + * @param string $backup complete name of the backup + * @return boolean + */ + public function deleteBackup($backup) { + $backupDir = $this->encryptionDir . '/backup.' . $backup . '/'; + return $this->view->deleteAll($backupDir); } /** diff --git a/apps/files_encryption/tests/proxy.php b/apps/files_encryption/tests/proxy.php index d5d9cc7daee..a6b63176569 100644 --- a/apps/files_encryption/tests/proxy.php +++ b/apps/files_encryption/tests/proxy.php @@ -126,9 +126,7 @@ class Proxy extends TestCase { $this->view->mkdir(dirname($path)); $this->view->file_put_contents($path, "test"); - $testClass = new DummyProxy(); - - $result = $testClass->isExcludedPathTesting($path, $this->userId); + $result = \Test_Helper::invokePrivate(new \OCA\Files_Encryption\Proxy(), 'isExcludedPath', array($path)); $this->assertSame($expected, $result); $this->view->deleteAll(dirname($path)); @@ -149,12 +147,3 @@ class Proxy extends TestCase { } - -/** - * Dummy class to make protected methods available for testing - */ -class DummyProxy extends \OCA\Files_Encryption\Proxy { - public function isExcludedPathTesting($path, $uid) { - return $this->isExcludedPath($path, $uid); - } -} diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php index 4e0b4f2d0de..f9ee005e95f 100755 --- a/apps/files_encryption/tests/util.php +++ b/apps/files_encryption/tests/util.php @@ -27,7 +27,7 @@ class Util extends TestCase { * @var \OC\Files\View */ public $view; - public $keyfilesPath; + public $keysPath; public $publicKeyPath; public $privateKeyPath; /** @@ -379,8 +379,6 @@ class Util extends TestCase { $this->assertTrue($this->view->is_dir($backupPath . '/keys')); $this->assertTrue($this->view->file_exists($backupPath . '/keys/' . $filename . '/fileKey')); $this->assertTrue($this->view->file_exists($backupPath . '/keys/' . $filename . '/' . $user . '.shareKey')); - $this->assertTrue($this->view->file_exists($backupPath . '/' . $user . '.privateKey')); - $this->assertTrue($this->view->file_exists($backupPath . '/' . $user . '.publicKey')); // cleanup $this->view->unlink($this->userId . '/files/' . $filename); @@ -389,21 +387,27 @@ class Util extends TestCase { } - /** - * test if all keys get moved to the backup folder correctly - */ - function testBackupAllKeys() { - self::loginHelper(self::TEST_ENCRYPTION_UTIL_USER1); - + private function createDummyKeysForBackupTest() { // create some dummy key files $encPath = '/' . self::TEST_ENCRYPTION_UTIL_USER1 . '/files_encryption'; $this->view->mkdir($encPath . '/keys/foo'); $this->view->file_put_contents($encPath . '/keys/foo/fileKey', 'key'); $this->view->file_put_contents($encPath . '/keys/foo/user1.shareKey', 'share key'); + } + + /** + * test if all keys get moved to the backup folder correctly + * + * @dataProvider dataBackupAllKeys + */ + function testBackupAllKeys($addTimestamp, $includeUserKeys) { + self::loginHelper(self::TEST_ENCRYPTION_UTIL_USER1); + + $this->createDummyKeysForBackupTest(); $util = new \OCA\Files_Encryption\Util($this->view, self::TEST_ENCRYPTION_UTIL_USER1); - $util->backupAllKeys('testBackupAllKeys'); + $util->backupAllKeys('testBackupAllKeys', $addTimestamp, $includeUserKeys); $backupPath = $this->getBackupPath('testBackupAllKeys'); @@ -412,15 +416,80 @@ class Util extends TestCase { $this->assertTrue($this->view->is_dir($backupPath . '/keys/foo')); $this->assertTrue($this->view->file_exists($backupPath . '/keys/foo/fileKey')); $this->assertTrue($this->view->file_exists($backupPath . '/keys/foo/user1.shareKey')); - $this->assertTrue($this->view->file_exists($backupPath . '/' . self::TEST_ENCRYPTION_UTIL_USER1 . '.privateKey')); - $this->assertTrue($this->view->file_exists($backupPath . '/' . self::TEST_ENCRYPTION_UTIL_USER1 . '.publicKey')); + + if ($includeUserKeys) { + $this->assertTrue($this->view->file_exists($backupPath . '/' . self::TEST_ENCRYPTION_UTIL_USER1 . '.privateKey')); + $this->assertTrue($this->view->file_exists($backupPath . '/' . self::TEST_ENCRYPTION_UTIL_USER1 . '.publicKey')); + } else { + $this->assertFalse($this->view->file_exists($backupPath . '/' . self::TEST_ENCRYPTION_UTIL_USER1 . '.privateKey')); + $this->assertFalse($this->view->file_exists($backupPath . '/' . self::TEST_ENCRYPTION_UTIL_USER1 . '.publicKey')); + } //cleanup $this->view->deleteAll($backupPath); - $this->view->unlink($encPath . '/keys/foo/fileKey'); - $this->view->unlink($encPath . '/keys/foo/user1.shareKey'); + $this->view->unlink($this->encryptionDir . '/keys/foo/fileKey'); + $this->view->unlink($this->encryptionDir . '/keys/foo/user1.shareKey'); } + function dataBackupAllKeys() { + return array( + array(true, true), + array(false, true), + array(true, false), + array(false, false), + ); + } + + + /** + * @dataProvider dataBackupAllKeys + */ + function testRestoreBackup($addTimestamp, $includeUserKeys) { + + $util = new \OCA\Files_Encryption\Util($this->view, self::TEST_ENCRYPTION_UTIL_USER1); + $this->createDummyKeysForBackupTest(); + + $util->backupAllKeys('restoreKeysBackupTest', $addTimestamp, $includeUserKeys); + $this->view->deleteAll($this->keysPath); + if ($includeUserKeys) { + $this->view->unlink($this->privateKeyPath); + $this->view->unlink($this->publicKeyPath); + } + + // key should be removed after backup was created + $this->assertFalse($this->view->is_dir($this->keysPath)); + if ($includeUserKeys) { + $this->assertFalse($this->view->file_exists($this->privateKeyPath)); + $this->assertFalse($this->view->file_exists($this->publicKeyPath)); + } + + $backupPath = $this->getBackupPath('restoreKeysBackupTest'); + $backupName = substr(basename($backupPath), strlen('backup.')); + + $this->assertTrue($util->restoreBackup($backupName)); + + // check if all keys are restored + $this->assertFalse($this->view->is_dir($backupPath)); + $this->assertTrue($this->view->is_dir($this->keysPath)); + $this->assertTrue($this->view->is_dir($this->keysPath . '/foo')); + $this->assertTrue($this->view->file_exists($this->keysPath . '/foo/fileKey')); + $this->assertTrue($this->view->file_exists($this->keysPath . '/foo/user1.shareKey')); + $this->assertTrue($this->view->file_exists($this->privateKeyPath)); + $this->assertTrue($this->view->file_exists($this->publicKeyPath)); + } + + function testDeleteBackup() { + $util = new \OCA\Files_Encryption\Util($this->view, self::TEST_ENCRYPTION_UTIL_USER1); + $this->createDummyKeysForBackupTest(); + + $util->backupAllKeys('testDeleteBackup', false, false); + + $this->assertTrue($this->view->is_dir($this->encryptionDir . '/backup.testDeleteBackup')); + + $util->deleteBackup('testDeleteBackup'); + + $this->assertFalse($this->view->is_dir($this->encryptionDir . '/backup.testDeleteBackup')); + } function testDescryptAllWithBrokenFiles() { diff --git a/apps/files_external/appinfo/info.xml b/apps/files_external/appinfo/info.xml index 0ae39f2341e..8518cc89298 100644 --- a/apps/files_external/appinfo/info.xml +++ b/apps/files_external/appinfo/info.xml @@ -13,6 +13,7 @@ <documentation> <admin>admin-external-storage</admin> </documentation> + <rememberlogin>false</rememberlogin> <types> <filesystem/> </types> diff --git a/apps/files_sharing/appinfo/update.php b/apps/files_sharing/appinfo/update.php new file mode 100644 index 00000000000..1e910eb6ac1 --- /dev/null +++ b/apps/files_sharing/appinfo/update.php @@ -0,0 +1,12 @@ +<?php + +use OCA\Files_Sharing\Migration; + +$installedVersion = \OC::$server->getConfig()->getAppValue('files_sharing', 'installed_version'); + +// Migration OC7 -> OC8 +if (version_compare($installedVersion, '0.6.0', '<')) { + $m = new Migration(); + $m->addAcceptRow(); +} + diff --git a/apps/files_sharing/appinfo/version b/apps/files_sharing/appinfo/version index 7d8568351b4..a918a2aa18d 100644 --- a/apps/files_sharing/appinfo/version +++ b/apps/files_sharing/appinfo/version @@ -1 +1 @@ -0.5.4 +0.6.0 diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js index 02ecf56fa09..cbd135028f1 100644 --- a/apps/files_sharing/js/public.js +++ b/apps/files_sharing/js/public.js @@ -8,7 +8,7 @@ * */ -/* global FileActions, Files */ +/* global FileActions, Files, FileList */ /* global dragOptions, folderDropOptions */ if (!OCA.Sharing) { OCA.Sharing = {}; @@ -164,6 +164,11 @@ OCA.Sharing.PublicApp = { // URL history handling this.fileList.$el.on('changeDirectory', _.bind(this._onDirectoryChanged, this)); OC.Util.History.addOnPopStateHandler(_.bind(this._onUrlChanged, this)); + + $('#download').click(function (e) { + e.preventDefault(); + OC.redirect(FileList.getDownloadUrl()); + }); } $(document).on('click', '#directLink', function () { diff --git a/apps/files_sharing/lib/migration.php b/apps/files_sharing/lib/migration.php new file mode 100644 index 00000000000..1a3bfecffb0 --- /dev/null +++ b/apps/files_sharing/lib/migration.php @@ -0,0 +1,42 @@ +<?php + /** + * ownCloud - migration to new version of the files sharing app + * + * @copyright (C) 2014 ownCloud, Inc. + * + * @author Bjoern Schiessle <schiessle@owncloud.com> + * + * 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 <http://www.gnu.org/licenses/>. + * + */ + + namespace OCA\Files_Sharing; + +class Migration { + + + /** + * set accepted to 1 for all external shares. At this point in time we only + * have shares from the first version of server-to-server sharing so all should + * be accepted + */ + public function addAcceptRow() { + $statement = 'UPDATE `*PREFIX*share_external` SET `accepted` = 1'; + $connection = \OC::$server->getDatabaseConnection(); + $query = $connection->prepare($statement); + $query->execute(); + } + + +} diff --git a/apps/files_sharing/tests/migrationtest.php b/apps/files_sharing/tests/migrationtest.php new file mode 100644 index 00000000000..1f29d9bed04 --- /dev/null +++ b/apps/files_sharing/tests/migrationtest.php @@ -0,0 +1,76 @@ +<?php +/** + * ownCloud + * + * @author Bjoern Schiessle + * @copyright 2014 Bjoern Schiessle <schiessle@owncloud.com> + * + * 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 <http://www.gnu.org/licenses/>. + * + */ + + +use OCA\Files_Sharing\Tests\TestCase; +use OCA\Files_Sharing\Migration; + +class MigrationTest extends TestCase { + + /** + * @var \OCP\IDBConnection + */ + private $connection; + + function __construct() { + parent::__construct(); + + $this->connection = \OC::$server->getDatabaseConnection(); + } + + function testAddAccept() { + + $query = $this->connection->prepare(' + INSERT INTO `*PREFIX*share_external` + (`remote`, `share_token`, `password`, `name`, `owner`, `user`, `mountpoint`, `mountpoint_hash`, `remote_id`, `accepted`) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + '); + + for ($i = 0; $i < 10; $i++) { + $query->execute(array('remote', 'token', 'password', 'name', 'owner', 'user', 'mount point', $i, $i, 0)); + } + + $query = $this->connection->prepare('SELECT `id` FROM `*PREFIX*share_external`'); + $query->execute(); + $dummyEntries = $query->fetchAll(); + + $this->assertSame(10, count($dummyEntries)); + + $m = new Migration(); + $m->addAcceptRow(); + + // verify result + $query = $this->connection->prepare('SELECT `accepted` FROM `*PREFIX*share_external`'); + $query->execute(); + $results = $query->fetchAll(); + $this->assertSame(10, count($results)); + + foreach ($results as $r) { + $this->assertSame(1, (int) $r['accepted']); + } + + // cleanup + $cleanup = $this->connection->prepare('DELETE FROM `*PREFIX*share_external`'); + $cleanup->execute(); + } + +} diff --git a/core/js/update.js b/core/js/update.js index 4899335f0ec..f63808f65be 100644 --- a/core/js/update.js +++ b/core/js/update.js @@ -17,7 +17,7 @@ * * @param $el progress list element */ - start: function($el) { + start: function($el, options) { if (this._started) { return; } @@ -28,8 +28,8 @@ this.addMessage(t( 'core', 'Updating {productName} to version {version}, this may take a while.', { - productName: OC.theme.name || 'ownCloud', - version: OC.config.versionstring + productName: options.productName || 'ownCloud', + version: options.version }), 'bold' ).append('<br />'); // FIXME: these should be ul/li with CSS paddings! @@ -76,10 +76,14 @@ $(document).ready(function() { $('.updateButton').on('click', function() { + var $updateEl = $('.update'); var $progressEl = $('.updateProgress'); $progressEl.removeClass('hidden'); $('.updateOverview').addClass('hidden'); - OC.Update.start($progressEl); + OC.Update.start($progressEl, { + productName: $updateEl.attr('data-productname'), + version: $updateEl.attr('data-version'), + }); return false; }); }); diff --git a/core/templates/update.admin.php b/core/templates/update.admin.php index 29df0dd484a..ccd5d236828 100644 --- a/core/templates/update.admin.php +++ b/core/templates/update.admin.php @@ -1,4 +1,4 @@ -<div class="update"> +<div class="update" data-productname="<?php p($_['productName']) ?>" data-version="<?php p($_['version']) ?>"> <div class="updateOverview"> <h2 class="title bold"><?php p($l->t('%s will be updated to version %s.', array($_['productName'], $_['version']))); ?></h2> diff --git a/lib/private/util.php b/lib/private/util.php index ec3640503e4..d2d286fc11e 100644 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -692,9 +692,9 @@ class OC_Util { $encryptedFiles = false; if (OC_App::isEnabled('files_encryption') === false) { $view = new OC\Files\View('/' . OCP\User::getUser()); - $keyfilePath = '/files_encryption/keyfiles'; - if ($view->is_dir($keyfilePath)) { - $dircontent = $view->getDirectoryContent($keyfilePath); + $keysPath = '/files_encryption/keys'; + if ($view->is_dir($keysPath)) { + $dircontent = $view->getDirectoryContent($keysPath); if (!empty($dircontent)) { $encryptedFiles = true; } @@ -714,7 +714,7 @@ class OC_Util { $backupExists = false; if (OC_App::isEnabled('files_encryption') === false) { $view = new OC\Files\View('/' . OCP\User::getUser()); - $backupPath = '/files_encryption/keyfiles.backup'; + $backupPath = '/files_encryption/backup.decryptAll'; if ($view->is_dir($backupPath)) { $dircontent = $view->getDirectoryContent($backupPath); if (!empty($dircontent)) { diff --git a/settings/ajax/deletekeys.php b/settings/ajax/deletekeys.php index 86a45820af9..7d6c9a27aa0 100644 --- a/settings/ajax/deletekeys.php +++ b/settings/ajax/deletekeys.php @@ -4,13 +4,11 @@ OCP\JSON::checkLoggedIn(); OCP\JSON::callCheck(); $l = \OC::$server->getL10N('settings'); -$user = \OC_User::getUser(); -$view = new \OC\Files\View('/' . $user . '/files_encryption'); -$keyfilesDeleted = $view->deleteAll('keyfiles.backup'); -$sharekeysDeleted = $view->deleteAll('share-keys.backup'); +$util = new \OCA\Files_Encryption\Util(new \OC\Files\View(), \OC_User::getUser()); +$result = $util->deleteBackup('decryptAll'); -if ($keyfilesDeleted && $sharekeysDeleted) { +if ($result) { \OCP\JSON::success(array('data' => array('message' => $l->t('Encryption keys deleted permanently')))); } else { \OCP\JSON::error(array('data' => array('message' => $l->t('Couldn\'t permanently delete your encryption keys, please check your owncloud.log or ask your administrator')))); diff --git a/settings/ajax/restorekeys.php b/settings/ajax/restorekeys.php index 5c263fadab4..b89a8286db2 100644 --- a/settings/ajax/restorekeys.php +++ b/settings/ajax/restorekeys.php @@ -4,21 +4,12 @@ OCP\JSON::checkLoggedIn(); OCP\JSON::callCheck(); $l = \OC::$server->getL10N('settings'); -$user = \OC_User::getUser(); -$view = new \OC\Files\View('/' . $user . '/files_encryption'); -$keyfilesRestored = $view->rename('keyfiles.backup', 'keyfiles'); -$sharekeysRestored = $view->rename('share-keys.backup' , 'share-keys'); +$util = new \OCA\Files_Encryption\Util(new \OC\Files\View(), \OC_User::getUser()); +$result = $util->restoreBackup('decryptAll'); -if ($keyfilesRestored && $sharekeysRestored) { +if ($result) { \OCP\JSON::success(array('data' => array('message' => $l->t('Backups restored successfully')))); } else { - // if one of the move operation was succesful we remove the files back to have a consistent state - if($keyfilesRestored) { - $view->rename('keyfiles', 'keyfiles.backup'); - } - if($sharekeysRestored) { - $view->rename('share-keys' , 'share-keys.backup'); - } \OCP\JSON::error(array('data' => array('message' => $l->t('Couldn\'t restore your encryption keys, please check your owncloud.log or ask your administrator')))); } |