From a85e2e0bfdb86de029f7b5fde42ead60498aed82 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 30 Mar 2015 11:49:03 +0200 Subject: [PATCH] make recovery settings work --- apps/encryption/appinfo/app.php | 11 ++------ .../{encryption.php => application.php} | 28 ++++++++++--------- apps/encryption/appinfo/routes.php | 8 +++--- apps/encryption/js/settings-admin.js | 4 +-- apps/encryption/lib/keymanager.php | 2 +- apps/encryption/settings/settings-admin.php | 3 -- apps/encryption/templates/settings-admin.php | 6 ++-- lib/private/encryption/manager.php | 5 +++- lib/public/iservercontainer.php | 12 ++++++++ 9 files changed, 45 insertions(+), 34 deletions(-) rename apps/encryption/appinfo/{encryption.php => application.php} (88%) diff --git a/apps/encryption/appinfo/app.php b/apps/encryption/appinfo/app.php index 72e7fc42ca0..38f9ff2f040 100644 --- a/apps/encryption/appinfo/app.php +++ b/apps/encryption/appinfo/app.php @@ -19,15 +19,10 @@ * */ -use OCA\Encryption\AppInfo\Encryption; +namespace OCA\Encryption\AppInfo; -if (!OC::$CLI) { +if (!\OC::$CLI) { $di = \OC::$server; - $app = new Encryption('encryption', - [], - $di->getEncryptionManager(), - $di->getConfig()); - - $app->boot(); + $app = new Application(); } diff --git a/apps/encryption/appinfo/encryption.php b/apps/encryption/appinfo/application.php similarity index 88% rename from apps/encryption/appinfo/encryption.php rename to apps/encryption/appinfo/application.php index 6aad9219025..606c0cc5c49 100644 --- a/apps/encryption/appinfo/encryption.php +++ b/apps/encryption/appinfo/application.php @@ -36,7 +36,7 @@ use OCP\Encryption\IManager; use OCP\IConfig; -class Encryption extends \OCP\AppFramework\App { +class Application extends \OCP\AppFramework\App { /** * @var IManager */ @@ -49,19 +49,11 @@ class Encryption extends \OCP\AppFramework\App { /** * @param $appName * @param array $urlParams - * @param IManager $encryptionManager - * @param IConfig $config */ - public function __construct($appName, $urlParams = array(), IManager $encryptionManager, IConfig $config) { - parent::__construct($appName, $urlParams); - $this->encryptionManager = $encryptionManager; - $this->config = $config; - } - - /** - * - */ - public function boot() { + public function __construct($urlParams = array()) { + parent::__construct('encryption', $urlParams); + $this->encryptionManager = \OC::$server->getEncryptionManager(); + $this->config = \OC::$server->getConfig(); $this->registerServices(); $this->registerEncryptionModule(); $this->registerHooks(); @@ -153,6 +145,16 @@ class Encryption extends \OCP\AppFramework\App { $server->getEncryptionKeyStorage(\OCA\Encryption\Crypto\Encryption::ID)); }); + $container->registerService('RecoveryController', function (IAppContainer $c) { + $server = $c->getServer(); + return new \OCA\Encryption\Controller\RecoveryController( + $c->getAppName(), + $server->getRequest(), + $server->getConfig(), + $server->getL10N($c->getAppName()), + $c->query('Recovery')); + }); + $container->registerService('UserSetup', function (IAppContainer $c) { $server = $c->getServer(); diff --git a/apps/encryption/appinfo/routes.php b/apps/encryption/appinfo/routes.php index a86f3717ce9..b2c00c83349 100644 --- a/apps/encryption/appinfo/routes.php +++ b/apps/encryption/appinfo/routes.php @@ -20,17 +20,17 @@ */ -use OCP\AppFramework\App; +namespace OCA\Encryption\AppInfo; -(new App('encryption'))->registerRoutes($this, array('routes' => array( +(new Application())->registerRoutes($this, array('routes' => array( [ - 'name' => 'recovery#adminRecovery', + 'name' => 'Recovery#adminRecovery', 'url' => '/ajax/adminRecovery', 'verb' => 'POST' ], [ - 'name' => 'recovery#userRecovery', + 'name' => 'Recovery#userRecovery', 'url' => '/ajax/userRecovery', 'verb' => 'POST' ] diff --git a/apps/encryption/js/settings-admin.js b/apps/encryption/js/settings-admin.js index 2242c1f7124..e5d3bebb208 100644 --- a/apps/encryption/js/settings-admin.js +++ b/apps/encryption/js/settings-admin.js @@ -17,7 +17,7 @@ $(document).ready(function(){ var confirmPassword = $( '#repeatEncryptionRecoveryPassword' ).val(); OC.msg.startSaving('#encryptionSetRecoveryKey .msg'); $.post( - OC.filePath( 'files_encryption', 'ajax', 'adminrecovery.php' ) + OC.generateUrl('/apps/encryption/ajax/adminRecovery') , { adminEnableRecovery: recoveryStatus, recoveryPassword: recoveryPassword, confirmPassword: confirmPassword } , function( result ) { OC.msg.finishedSaving('#encryptionSetRecoveryKey .msg', result); @@ -44,7 +44,7 @@ $(document).ready(function(){ var confirmNewPassword = $('#repeatedNewEncryptionRecoveryPassword').val(); OC.msg.startSaving('#encryptionChangeRecoveryKey .msg'); $.post( - OC.filePath( 'files_encryption', 'ajax', 'changeRecoveryPassword.php' ) + OC.filePath( 'encryption', 'ajax', 'changeRecoveryPassword.php' ) , { oldPassword: oldRecoveryPassword, newPassword: newRecoveryPassword, confirmPassword: confirmNewPassword } , function( data ) { OC.msg.finishedSaving('#encryptionChangeRecoveryKey .msg', data); diff --git a/apps/encryption/lib/keymanager.php b/apps/encryption/lib/keymanager.php index b3961c8566e..68fb722c5ea 100644 --- a/apps/encryption/lib/keymanager.php +++ b/apps/encryption/lib/keymanager.php @@ -193,7 +193,7 @@ class KeyManager { if ($encryptedKey) { $this->setPrivateKey($uid, $encryptedKey); - $this->config->setAppValue('encryption', 'recoveryAdminEnabled', 1); + $this->config->setAppValue('encryption', 'recoveryAdminEnabled', 0); return true; } return false; diff --git a/apps/encryption/settings/settings-admin.php b/apps/encryption/settings/settings-admin.php index 813956aa0af..a34d30d1de5 100644 --- a/apps/encryption/settings/settings-admin.php +++ b/apps/encryption/settings/settings-admin.php @@ -18,7 +18,4 @@ $recoveryAdminEnabled = \OC::$server->getConfig()->getAppValue('encryption', 're $tmpl->assign('recoveryEnabled', $recoveryAdminEnabled); $tmpl->assign('initStatus', KeyManager::$session->get('initStatus')); -\OCP\Util::addscript('files_encryption', 'settings-admin'); -\OCP\Util::addscript('core', 'multiselect'); - return $tmpl->fetchPage(); diff --git a/apps/encryption/templates/settings-admin.php b/apps/encryption/templates/settings-admin.php index 252701e9ed0..616c593f6fb 100644 --- a/apps/encryption/templates/settings-admin.php +++ b/apps/encryption/templates/settings-admin.php @@ -1,6 +1,8 @@

t('ownCloud basic encryption module')); ?>

diff --git a/lib/private/encryption/manager.php b/lib/private/encryption/manager.php index fa50d32218d..7cd49d1c0e2 100644 --- a/lib/private/encryption/manager.php +++ b/lib/private/encryption/manager.php @@ -66,12 +66,15 @@ class Manager implements \OCP\Encryption\IManager { public function registerEncryptionModule(IEncryptionModule $module) { $id = $module->getId(); $name = $module->getDisplayName(); + + // FIXME why do we load the same encryption module multiple times + /* if (isset($this->encryptionModules[$id])) { $message = 'Id "' . $id . '" already used by encryption module "' . $name . '"'; throw new Exceptions\ModuleAlreadyExistsException($message); } - +*/ $defaultEncryptionModuleId = $this->getDefaultEncryptionModuleId(); if (empty($defaultEncryptionModuleId)) { diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index d7df884adf8..2db1fc32499 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -172,6 +172,18 @@ interface IServerContainer { */ function getL10N($app, $lang = null); + /** + * @return \OC\Encryption\Manager + */ + function getEncryptionManager(); + + /** + * @param string $encryptionModuleId encryption module ID + * + * @return \OCP\Encryption\Keys\IStorage + */ + function getEncryptionKeyStorage($encryptionModuleId); + /** * Returns the URL generator * -- 2.39.5