Enable.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Core\Command\Encryption;
  8. use OCP\Encryption\IManager;
  9. use OCP\IConfig;
  10. use Symfony\Component\Console\Command\Command;
  11. use Symfony\Component\Console\Input\InputInterface;
  12. use Symfony\Component\Console\Output\OutputInterface;
  13. class Enable extends Command {
  14. public function __construct(
  15. protected IConfig $config,
  16. protected IManager $encryptionManager,
  17. ) {
  18. parent::__construct();
  19. }
  20. protected function configure() {
  21. $this
  22. ->setName('encryption:enable')
  23. ->setDescription('Enable encryption')
  24. ;
  25. }
  26. protected function execute(InputInterface $input, OutputInterface $output): int {
  27. if ($this->config->getAppValue('core', 'encryption_enabled', 'no') === 'yes') {
  28. $output->writeln('Encryption is already enabled');
  29. } else {
  30. $this->config->setAppValue('core', 'encryption_enabled', 'yes');
  31. $output->writeln('<info>Encryption enabled</info>');
  32. }
  33. $output->writeln('');
  34. $modules = $this->encryptionManager->getEncryptionModules();
  35. if (empty($modules)) {
  36. $output->writeln('<error>No encryption module is loaded</error>');
  37. return 1;
  38. }
  39. $defaultModule = $this->config->getAppValue('core', 'default_encryption_module', null);
  40. if ($defaultModule === null) {
  41. $output->writeln('<error>No default module is set</error>');
  42. return 1;
  43. }
  44. if (!isset($modules[$defaultModule])) {
  45. $output->writeln('<error>The current default module does not exist: ' . $defaultModule . '</error>');
  46. return 1;
  47. }
  48. $output->writeln('Default module: ' . $defaultModule);
  49. return 0;
  50. }
  51. }