2015-04-16 18:41:32 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-01-12 17:02:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
2016-07-22 10:45:36 +03:00
|
|
|
*
|
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
|
|
|
*
|
2015-04-16 18:41:32 +03:00
|
|
|
* @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\Core\Command\Encryption;
|
|
|
|
|
2015-05-04 13:36:50 +03:00
|
|
|
use OCP\Encryption\IManager;
|
2015-04-16 18:41:32 +03:00
|
|
|
use OCP\IConfig;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
class Enable extends Command {
|
|
|
|
/** @var IConfig */
|
|
|
|
protected $config;
|
|
|
|
|
2015-05-04 13:36:50 +03:00
|
|
|
/** @var IManager */
|
|
|
|
protected $encryptionManager;
|
|
|
|
|
2015-04-16 18:41:32 +03:00
|
|
|
/**
|
|
|
|
* @param IConfig $config
|
2015-05-04 13:36:50 +03:00
|
|
|
* @param IManager $encryptionManager
|
2015-04-16 18:41:32 +03:00
|
|
|
*/
|
2015-05-04 13:36:50 +03:00
|
|
|
public function __construct(IConfig $config, IManager $encryptionManager) {
|
2015-04-16 18:41:32 +03:00
|
|
|
parent::__construct();
|
2015-05-04 13:36:50 +03:00
|
|
|
|
|
|
|
$this->encryptionManager = $encryptionManager;
|
2015-04-16 18:41:32 +03:00
|
|
|
$this->config = $config;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function configure() {
|
|
|
|
$this
|
|
|
|
->setName('encryption:enable')
|
|
|
|
->setDescription('Enable encryption')
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) {
|
|
|
|
if ($this->config->getAppValue('core', 'encryption_enabled', 'no') === 'yes') {
|
|
|
|
$output->writeln('Encryption is already enabled');
|
|
|
|
} else {
|
|
|
|
$this->config->setAppValue('core', 'encryption_enabled', 'yes');
|
2015-05-04 13:36:50 +03:00
|
|
|
$output->writeln('<info>Encryption enabled</info>');
|
2015-04-16 18:41:32 +03:00
|
|
|
}
|
2015-05-04 13:36:50 +03:00
|
|
|
$output->writeln('');
|
2015-04-16 18:41:32 +03:00
|
|
|
|
2015-05-04 13:36:50 +03:00
|
|
|
$modules = $this->encryptionManager->getEncryptionModules();
|
|
|
|
if (empty($modules)) {
|
|
|
|
$output->writeln('<error>No encryption module is loaded</error>');
|
|
|
|
} else {
|
|
|
|
$defaultModule = $this->config->getAppValue('core', 'default_encryption_module', null);
|
|
|
|
if ($defaultModule === null) {
|
|
|
|
$output->writeln('<error>No default module is set</error>');
|
|
|
|
} else if (!isset($modules[$defaultModule])) {
|
|
|
|
$output->writeln('<error>The current default module does not exist: ' . $defaultModule . '</error>');
|
|
|
|
} else {
|
|
|
|
$output->writeln('Default module: ' . $defaultModule);
|
|
|
|
}
|
|
|
|
}
|
2015-04-16 18:41:32 +03:00
|
|
|
}
|
|
|
|
}
|