You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.6 KiB

10 years ago
10 years ago
10 years ago
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Ruben Homs <ruben@homs.codes>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OC\Core\Command\Encryption;
  24. use OCP\Encryption\IManager;
  25. use OCP\IConfig;
  26. use Symfony\Component\Console\Command\Command;
  27. use Symfony\Component\Console\Input\InputArgument;
  28. use Symfony\Component\Console\Input\InputInterface;
  29. use Symfony\Component\Console\Output\OutputInterface;
  30. class SetDefaultModule extends Command {
  31. /** @var IManager */
  32. protected $encryptionManager;
  33. /** @var IConfig */
  34. protected $config;
  35. /**
  36. * @param IManager $encryptionManager
  37. * @param IConfig $config
  38. */
  39. public function __construct(
  40. IManager $encryptionManager,
  41. IConfig $config
  42. ) {
  43. parent::__construct();
  44. $this->encryptionManager = $encryptionManager;
  45. $this->config = $config;
  46. }
  47. protected function configure() {
  48. parent::configure();
  49. $this
  50. ->setName('encryption:set-default-module')
  51. ->setDescription('Set the encryption default module')
  52. ->addArgument(
  53. 'module',
  54. InputArgument::REQUIRED,
  55. 'ID of the encryption module that should be used'
  56. )
  57. ;
  58. }
  59. protected function execute(InputInterface $input, OutputInterface $output) {
  60. $isMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false);
  61. if ($isMaintenanceModeEnabled) {
  62. $output->writeln("Maintenance mode must be disabled when setting default module,");
  63. $output->writeln("in order to load the relevant encryption modules correctly.");
  64. return;
  65. }
  66. $moduleId = $input->getArgument('module');
  67. if ($moduleId === $this->encryptionManager->getDefaultEncryptionModuleId()) {
  68. $output->writeln('"' . $moduleId . '"" is already the default module');
  69. } elseif ($this->encryptionManager->setDefaultEncryptionModule($moduleId)) {
  70. $output->writeln('<info>Set default module to "' . $moduleId . '"</info>');
  71. } else {
  72. $output->writeln('<error>The specified module "' . $moduleId . '" does not exist</error>');
  73. }
  74. }
  75. }