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.

87 lines
2.5 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. *
  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 OCA\Encryption\Command;
  23. use OCA\Encryption\Util;
  24. use OCP\IConfig;
  25. use Symfony\Component\Console\Command\Command;
  26. use Symfony\Component\Console\Helper\QuestionHelper;
  27. use Symfony\Component\Console\Input\InputInterface;
  28. use Symfony\Component\Console\Output\OutputInterface;
  29. use Symfony\Component\Console\Question\ConfirmationQuestion;
  30. class EnableMasterKey extends Command {
  31. /** @var Util */
  32. protected $util;
  33. /** @var IConfig */
  34. protected $config;
  35. /** @var QuestionHelper */
  36. protected $questionHelper;
  37. /**
  38. * @param Util $util
  39. * @param IConfig $config
  40. * @param QuestionHelper $questionHelper
  41. */
  42. public function __construct(Util $util,
  43. IConfig $config,
  44. QuestionHelper $questionHelper) {
  45. $this->util = $util;
  46. $this->config = $config;
  47. $this->questionHelper = $questionHelper;
  48. parent::__construct();
  49. }
  50. protected function configure() {
  51. $this
  52. ->setName('encryption:enable-master-key')
  53. ->setDescription('Enable the master key. Only available for fresh installations with no existing encrypted data! There is also no way to disable it again.');
  54. }
  55. protected function execute(InputInterface $input, OutputInterface $output) {
  56. $isAlreadyEnabled = $this->util->isMasterKeyEnabled();
  57. if($isAlreadyEnabled) {
  58. $output->writeln('Master key already enabled');
  59. } else {
  60. $question = new ConfirmationQuestion(
  61. 'Warning: Only available for fresh installations with no existing encrypted data! '
  62. . 'There is also no way to disable it again. Do you want to continue? (y/n) ', false);
  63. if ($this->questionHelper->ask($input, $output, $question)) {
  64. $this->config->setAppValue('encryption', 'useMasterKey', '1');
  65. $output->writeln('Master key successfully enabled.');
  66. } else {
  67. $output->writeln('aborted.');
  68. }
  69. }
  70. }
  71. }