]> source.dussan.org Git - nextcloud-server.git/commitdiff
allow user to start migration in admin settings if no external user back-ends are...
authorBjoern Schiessle <schiessle@owncloud.com>
Thu, 9 Apr 2015 14:07:15 +0000 (16:07 +0200)
committerBjoern Schiessle <schiessle@owncloud.com>
Thu, 16 Apr 2015 12:15:04 +0000 (14:15 +0200)
settings/admin.php
settings/application.php
settings/controller/encryptioncontroller.php [new file with mode: 0644]
settings/js/admin.js
settings/routes.php
settings/templates/admin.php

index 43b21f409294924799a7f86cd57d6472f7d289f9..5cfe2654f66c5eb21e5ab3dd4bdcab2aafd0ee5a 100644 (file)
@@ -82,8 +82,12 @@ $excludedGroupsList = $appConfig->getValue('core', 'shareapi_exclude_groups_list
 $excludedGroupsList = explode(',', $excludedGroupsList); // FIXME: this should be JSON!
 $template->assign('shareExcludedGroupsList', implode('|', $excludedGroupsList));
 $template->assign('encryptionEnabled', \OC::$server->getEncryptionManager()->isEnabled());
+$backends = \OC::$server->getUserManager()->getBackends();
+$externalBackends = (count($backends) > 1) ? true : false;
 $template->assign('encryptionReady', \OC::$server->getEncryptionManager()->isReady());
+$template->assign('externalBackendsEnabled', $externalBackends);
 $encryptionModules = \OC::$server->getEncryptionManager()->getEncryptionModules();
+
 try {
        $defaultEncryptionModule = \OC::$server->getEncryptionManager()->getDefaultEncryptionModule();
        $defaultEncryptionModuleId = $defaultEncryptionModule->getId();
index be127da31ac617c04142387e98dd5489f53edf65..59fe9f6b65abf7b06ec286862edde6506532b853 100644 (file)
 
 namespace OC\Settings;
 
+use OC\Files\View;
 use OC\Settings\Controller\AppSettingsController;
 use OC\Settings\Controller\CheckSetupController;
+use OC\Settings\Controller\EncryptionController;
 use OC\Settings\Controller\GroupsController;
 use OC\Settings\Controller\LogSettingsController;
 use OC\Settings\Controller\MailSettingsController;
@@ -65,6 +67,17 @@ class Application extends App {
                                $c->query('DefaultMailAddress')
                        );
                });
+               $container->registerService('EncryptionController', function(IContainer $c) {
+                       return new EncryptionController(
+                               $c->query('AppName'),
+                               $c->query('Request'),
+                               $c->query('L10N'),
+                               $c->query('Config'),
+                               $c->query('DatabaseConnection'),
+                               $c->query('UserManager'),
+                               new View()
+                       );
+               });
                $container->registerService('AppSettingsController', function(IContainer $c) {
                        return new AppSettingsController(
                                $c->query('AppName'),
@@ -207,5 +220,8 @@ class Application extends App {
                $container->registerService('Util', function(IContainer $c) {
                        return new \OC_Util();
                });
+               $container->registerService('DatabaseConnection', function(IContainer $c) {
+                       return $c->query('ServerContainer')->getDatabaseConnection();
+               });
        }
 }
diff --git a/settings/controller/encryptioncontroller.php b/settings/controller/encryptioncontroller.php
new file mode 100644 (file)
index 0000000..800982d
--- /dev/null
@@ -0,0 +1,122 @@
+<?php
+/**
+ * @author Björn Schießle <schiessle@owncloud.com>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program 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, version 3,
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+
+namespace OC\Settings\Controller;
+use OC\Files\View;
+use OCA\Encryption\Migration;
+use OCP\IL10N;
+use OCP\AppFramework\Controller;
+use OCP\IRequest;
+use OCP\IConfig;
+use OC\DB\Connection;
+use OCP\IUserManager;
+
+/**
+ * @package OC\Settings\Controller
+ */
+class EncryptionController extends Controller {
+
+       /** @var \OCP\IL10N */
+       private $l10n;
+
+       /** @var  Connection */
+       private $connection;
+
+       /** @var IConfig */
+       private $config;
+
+       /** @var IUserManager */
+       private $userManager;
+
+       /** @var View */
+       private $view;
+
+       /**
+        * @param string $appName
+        * @param IRequest $request
+        * @param \OCP\IL10N $l10n
+        * @param \OCP\IConfig $config
+        * @param \OC\DB\Connection $connection
+        * @param IUserManager $userManager
+        * @param View $view
+        */
+       public function __construct($appName,
+                                                               IRequest $request,
+                                                               IL10N $l10n,
+                                                               IConfig $config,
+                                                               Connection $connection,
+                                                               IUserManager $userManager,
+                                                               View $view) {
+               parent::__construct($appName, $request);
+               $this->l10n = $l10n;
+               $this->config = $config;
+               $this->connection = $connection;
+               $this->view = $view;
+               $this->userManager = $userManager;
+       }
+
+       /**
+        * start migration
+        *
+        * @return array
+        */
+       public function startMigration() {
+        // allow as long execution on the web server as possible
+               set_time_limit(0);
+               $migration = new Migration($this->config, $this->view, $this->connection);
+               $migration->reorganizeSystemFolderStructure();
+               $migration->updateDB();
+
+               try {
+
+                       foreach ($this->userManager->getBackends() as $backend) {
+
+                               $limit = 500;
+                               $offset = 0;
+                               do {
+                                       $users = $backend->getUsers('', $limit, $offset);
+                                       foreach ($users as $user) {
+                                               $migration->reorganizeFolderStructureForUser($user);
+                                       }
+                                       $offset += $limit;
+                               } while (count($users) >= $limit);
+                       }
+
+               } catch (\Exception $e) {
+                       return array(
+                               'data' => array(
+                                       'message' => (string)$this->l10n->t('A problem occurred, please check your log files (Error: %s)', [$e->getMessage()]),
+                               ),
+                               'status' => 'error',
+                       );
+               }
+
+               return array('data' =>
+                       array('message' =>
+                               (string) $this->l10n->t('Migration Completed')
+                       ),
+                       'status' => 'success'
+               );
+
+       }
+
+}
index 1e27c1be7e3089d66a5d48b4cfab98f282f81495..3c203bb3966b60fa9b3b20c094132152a11c6ef5 100644 (file)
@@ -55,7 +55,7 @@ $(document).ready(function(){
        });
 
        $('#encryptionEnabled').change(function() {
-               $('#encryptionAPI div#selectEncryptionModules').toggleClass('hidden');
+               $('#encryptionAPI div#EncryptionSettingsArea').toggleClass('hidden');
        });
 
        $('#encryptionAPI input').change(function() {
@@ -70,6 +70,26 @@ $(document).ready(function(){
                OC.AppConfig.setValue('core', $(this).attr('name'), value);
        });
 
+       $('#startmigration').click(function(event){
+               $(window).on('beforeunload.encryption', function(e) {
+                       return t('settings', 'Migration in progress. Please wait until the migration is finished');
+               });
+               event.preventDefault();
+               $('#startmigration').prop('disabled', true);
+               OC.msg.startAction('#startmigration_msg', t('settings', 'Migration started …'));
+               $.post(OC.generateUrl('/settings/admin/startmigration'), '', function(data){
+                       OC.msg.finishedAction('#startmigration_msg', data);
+                       if (data['status'] === 'success') {
+                               $('#encryptionAPI div#selectEncryptionModules').toggleClass('hidden');
+                               $('#encryptionAPI div#migrationWarning').toggleClass('hidden');
+                       } else {
+                               $('#startmigration').prop('disabled', false);
+                       }
+                       $(window).off('beforeunload.encryption');
+
+               });
+       });
+
        $('#shareAPI input:not(#excludedGroups)').change(function() {
                var value = $(this).val();
                if ($(this).attr('type') === 'checkbox') {
index 1bb14812145c302812e481ad8e68b1dfa6cc1f50..462b4ab543f55ca0de560c6bc6a4608a6c3a4054 100644 (file)
@@ -42,6 +42,7 @@ $application->registerRoutes($this, [
                ['name' => 'MailSettings#setMailSettings', 'url' => '/settings/admin/mailsettings', 'verb' => 'POST'],
                ['name' => 'MailSettings#storeCredentials', 'url' => '/settings/admin/mailsettings/credentials', 'verb' => 'POST'],
                ['name' => 'MailSettings#sendTestMail', 'url' => '/settings/admin/mailtest', 'verb' => 'POST'],
+               ['name' => 'Encryption#startMigration', 'url' => '/settings/admin/startmigration', 'verb' => 'POST'],
                ['name' => 'AppSettings#listCategories', 'url' => '/settings/apps/categories', 'verb' => 'GET'],
                ['name' => 'AppSettings#viewApps', 'url' => '/settings/apps', 'verb' => 'GET'],
                ['name' => 'AppSettings#listApps', 'url' => '/settings/apps/list', 'verb' => 'GET'],
index 299592bdd82f8e445b3c6cf1ded14121fb3262e2..55c0018e5af798a08257095e4ee5e252a3399504 100644 (file)
@@ -300,30 +300,50 @@ if ($_['cronErrors']) {
 </div>
 
 <div class="section" id='encryptionAPI'>
-       <h2><?php p($l->t('Server Side Encryption'));?></h2>
-               <p id="enable">
-                       <input type="checkbox" name="encryption_enabled" id="encryptionEnabled"
-                                  value="1" <?php if ($_['encryptionEnabled']) print_unescaped('checked="checked"'); ?> />
-                       <label for="encryptionEnabled"><?php p($l->t('Enable Server-Side-Encryption'));?></label><br/>
-               </p>
-               <div id='selectEncryptionModules' class="<?php if (!$_['encryptionEnabled']) { p('hidden'); }?>">
-                       <?php if ($_['encryptionReady'] === false) {
-                               p('Seems like you are in transit from the old encryption (ownCloud <= 8.0) to the new one. Please enable the "ownCloud Default Encryption Module" and run \'occ encryption:migrate\'');
-                       } elseif (empty($_['encryptionModules'])) {
+       <h2><?php p($l->t('Server Side Encryption')); ?> </h2>
+
+       <p id="enable">
+               <input type="checkbox" name="encryption_enabled"
+                          id="encryptionEnabled"
+                          value="1" <?php if ($_['encryptionEnabled']) print_unescaped('checked="checked"'); ?> />
+               <label
+                       for="encryptionEnabled"><?php p($l->t('Enable Server-Side-Encryption')); ?> <span id="startmigration_msg" class="msg"></span> </label><br/>
+       </p>
+
+       <div id="EncryptionSettingsArea" class="<?php if (!$_['encryptionEnabled']) p('hidden'); ?>">
+               <div id='selectEncryptionModules' class="<?php if (!$_['encryptionReady']) p('hidden'); ?>">
+                       <?php
+                       if (empty($_['encryptionModules'])) {
                                p('No encryption module loaded, please load a encryption module in the app menu');
                        } else { ?>
                                <h3>Select default encryption module:</h3>
                                <fieldset id='encryptionModules'>
-                                        <?php foreach ($_['encryptionModules'] as $id => $module): ?>
-                                       <input type="radio" id="<?php p($id) ?>"
-                                                  name="default_encryption_module"
-                                                  value="<?php p($id) ?>"
-                                                  <?php if($module['default']) { p('checked'); } ?>>
-                                       <label for="<?php p($id) ?>"><?php p($module['displayName']) ?></label><br />
-                                        <?php endforeach;?>
+                                       <?php foreach ($_['encryptionModules'] as $id => $module): ?>
+                                               <input type="radio" id="<?php p($id) ?>"
+                                                          name="default_encryption_module"
+                                                          value="<?php p($id) ?>"
+                                                       <?php if ($module['default']) {
+                                                               p('checked');
+                                                       } ?>>
+                                               <label
+                                                       for="<?php p($id) ?>"><?php p($module['displayName']) ?></label>
+                                               <br/>
+                                       <?php endforeach; ?>
                                </fieldset>
                        <?php } ?>
                </div>
+               <div id="migrationWarning" class="<?php if ($_['encryptionReady']) p('hidden'); ?>">
+                       <?php
+                       if ($_['encryptionReady'] === false && $_['externalBackendsEnabled'] === true) {
+                               p('You need to migrate your encryption keys from the old encryption (ownCloud <= 8.0) to the new one. '
+                                       . 'Please enable the "ownCloud Default Encryption Module" and run \'occ encryption:migrate\'');
+                       } elseif ($_['encryptionReady'] === false && $_['externalBackendsEnabled'] === false) {
+                               p('You need to migrate your encryption keys from the old encryption (ownCloud <= 8.0) to the new one.'); ?>
+                               <input type="submit" name="startmigration" id="startmigration"
+                                          value="<?php p($l->t('Start migration')); ?>"/>
+                       <?php } ?>
+               </div>
+       </div>
 </div>
 
 <div class="section" id="mail_general_settings">