-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathEnable.php
More file actions
74 lines (65 loc) · 2.16 KB
/
Enable.php
File metadata and controls
74 lines (65 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OC\Core\Command\Encryption;
use OCP\Encryption\IManager;
use OCP\Exceptions\AppConfigTypeConflictException;
use OCP\IAppConfig;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class Enable extends Command {
public function __construct(
protected IAppConfig $appConfig,
protected IManager $encryptionManager,
) {
parent::__construct();
}
#[\Override]
protected function configure() {
$this
->setName('encryption:enable')
->setDescription('Enable encryption')
;
}
#[\Override]
protected function execute(InputInterface $input, OutputInterface $output): int {
try {
$isEnabled = $this->appConfig->getValueBool('core', 'encryption_enabled', false);
} catch (AppConfigTypeConflictException) {
$raw = $this->appConfig->getValueString('core', 'encryption_enabled', 'no');
$isEnabled = in_array(strtolower(trim($raw)), ['1', 'true', 'yes', 'on'], true);
}
if ($isEnabled) {
$output->writeln('Encryption is already enabled');
} else {
try {
$this->appConfig->setValueBool('core', 'encryption_enabled', true);
} catch (AppConfigTypeConflictException) {
$this->appConfig->setValueString('core', 'encryption_enabled', 'yes');
}
$output->writeln('<info>Encryption enabled</info>');
}
$output->writeln('');
$modules = $this->encryptionManager->getEncryptionModules();
if (empty($modules)) {
$output->writeln('<error>No encryption module is loaded</error>');
return 1;
}
$defaultModule = $this->appConfig->getValueString('core', 'default_encryption_module', '');
if ($defaultModule === '') {
$output->writeln('<error>No default module is set</error>');
return 1;
}
if (!isset($modules[$defaultModule])) {
$output->writeln('<error>The current default module does not exist: ' . $defaultModule . '</error>');
return 1;
}
$output->writeln('Default module: ' . $defaultModule);
return 0;
}
}