Enable.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. *
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OC\Core\Command\Encryption;
  23. use OCP\Encryption\IManager;
  24. use OCP\IConfig;
  25. use Symfony\Component\Console\Command\Command;
  26. use Symfony\Component\Console\Input\InputInterface;
  27. use Symfony\Component\Console\Output\OutputInterface;
  28. class Enable extends Command {
  29. /** @var IConfig */
  30. protected $config;
  31. /** @var IManager */
  32. protected $encryptionManager;
  33. /**
  34. * @param IConfig $config
  35. * @param IManager $encryptionManager
  36. */
  37. public function __construct(IConfig $config, IManager $encryptionManager) {
  38. parent::__construct();
  39. $this->encryptionManager = $encryptionManager;
  40. $this->config = $config;
  41. }
  42. protected function configure() {
  43. $this
  44. ->setName('encryption:enable')
  45. ->setDescription('Enable encryption')
  46. ;
  47. }
  48. protected function execute(InputInterface $input, OutputInterface $output) {
  49. if ($this->config->getAppValue('core', 'encryption_enabled', 'no') === 'yes') {
  50. $output->writeln('Encryption is already enabled');
  51. } else {
  52. $this->config->setAppValue('core', 'encryption_enabled', 'yes');
  53. $output->writeln('<info>Encryption enabled</info>');
  54. }
  55. $output->writeln('');
  56. $modules = $this->encryptionManager->getEncryptionModules();
  57. if (empty($modules)) {
  58. $output->writeln('<error>No encryption module is loaded</error>');
  59. } else {
  60. $defaultModule = $this->config->getAppValue('core', 'default_encryption_module', null);
  61. if ($defaultModule === null) {
  62. $output->writeln('<error>No default module is set</error>');
  63. } else if (!isset($modules[$defaultModule])) {
  64. $output->writeln('<error>The current default module does not exist: ' . $defaultModule . '</error>');
  65. } else {
  66. $output->writeln('Default module: ' . $defaultModule);
  67. }
  68. }
  69. }
  70. }