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.

84 lines
2.6 KiB

10 years ago
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  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 OCA\Encryption\Command;
  24. use OCA\Encryption\Util;
  25. use OCP\IConfig;
  26. use Symfony\Component\Console\Command\Command;
  27. use Symfony\Component\Console\Helper\QuestionHelper;
  28. use Symfony\Component\Console\Input\InputInterface;
  29. use Symfony\Component\Console\Output\OutputInterface;
  30. use Symfony\Component\Console\Question\ConfirmationQuestion;
  31. class EnableMasterKey extends Command {
  32. /** @var Util */
  33. protected $util;
  34. /** @var IConfig */
  35. protected $config;
  36. /** @var QuestionHelper */
  37. protected $questionHelper;
  38. /**
  39. * @param Util $util
  40. * @param IConfig $config
  41. * @param QuestionHelper $questionHelper
  42. */
  43. public function __construct(Util $util,
  44. IConfig $config,
  45. QuestionHelper $questionHelper) {
  46. $this->util = $util;
  47. $this->config = $config;
  48. $this->questionHelper = $questionHelper;
  49. parent::__construct();
  50. }
  51. protected function configure() {
  52. $this
  53. ->setName('encryption:enable-master-key')
  54. ->setDescription('Enable the master key. Only available for fresh installations with no existing encrypted data! There is also no way to disable it again.');
  55. }
  56. protected function execute(InputInterface $input, OutputInterface $output): int {
  57. $isAlreadyEnabled = $this->util->isMasterKeyEnabled();
  58. if ($isAlreadyEnabled) {
  59. $output->writeln('Master key already enabled');
  60. } else {
  61. $question = new ConfirmationQuestion(
  62. 'Warning: Only available for fresh installations with no existing encrypted data! '
  63. . 'There is also no way to disable it again. Do you want to continue? (y/n) ', false);
  64. if ($this->questionHelper->ask($input, $output, $question)) {
  65. $this->config->setAppValue('encryption', 'useMasterKey', '1');
  66. $output->writeln('Master key successfully enabled.');
  67. } else {
  68. $output->writeln('aborted.');
  69. return 1;
  70. }
  71. }
  72. return 0;
  73. }
  74. }