|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016 Arthur Schiwon <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @author Arthur Schiwon <[email protected]> |
|
6
|
|
|
* @author Christoph Wurst <[email protected]> |
|
7
|
|
|
* @author Julius Härtl <[email protected]> |
|
8
|
|
|
* @author Robin Appelman <[email protected]> |
|
9
|
|
|
* @author Roeland Jago Douma <[email protected]> |
|
10
|
|
|
* |
|
11
|
|
|
* @license GNU AGPL version 3 or any later version |
|
12
|
|
|
* |
|
13
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
14
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
15
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
16
|
|
|
* License, or (at your option) any later version. |
|
17
|
|
|
* |
|
18
|
|
|
* This program is distributed in the hope that it will be useful, |
|
19
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21
|
|
|
* GNU Affero General Public License for more details. |
|
22
|
|
|
* |
|
23
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
24
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
25
|
|
|
* |
|
26
|
|
|
*/ |
|
27
|
|
|
|
|
28
|
|
|
namespace OCA\Settings\Settings\Admin; |
|
29
|
|
|
|
|
30
|
|
|
use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor; |
|
31
|
|
|
use OCP\AppFramework\Http\TemplateResponse; |
|
32
|
|
|
use OCP\Encryption\IManager; |
|
33
|
|
|
use OCP\IInitialStateService; |
|
34
|
|
|
use OCP\IUserManager; |
|
35
|
|
|
use OCP\Settings\ISettings; |
|
36
|
|
|
|
|
37
|
|
|
class Security implements ISettings { |
|
38
|
|
|
|
|
39
|
|
|
/** @var IManager */ |
|
40
|
|
|
private $manager; |
|
41
|
|
|
|
|
42
|
|
|
/** @var IUserManager */ |
|
43
|
|
|
private $userManager; |
|
44
|
|
|
|
|
45
|
|
|
/** @var MandatoryTwoFactor */ |
|
46
|
|
|
private $mandatoryTwoFactor; |
|
47
|
|
|
|
|
48
|
|
|
/** @var IInitialStateService */ |
|
49
|
|
|
private $initialState; |
|
50
|
|
|
|
|
51
|
|
|
public function __construct(IManager $manager, |
|
52
|
|
|
IUserManager $userManager, |
|
53
|
|
|
MandatoryTwoFactor $mandatoryTwoFactor, |
|
54
|
|
|
IInitialStateService $initialState) { |
|
55
|
|
|
$this->manager = $manager; |
|
56
|
|
|
$this->userManager = $userManager; |
|
57
|
|
|
$this->mandatoryTwoFactor = $mandatoryTwoFactor; |
|
58
|
|
|
$this->initialState = $initialState; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return TemplateResponse |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getForm() { |
|
65
|
|
|
$encryptionModules = $this->manager->getEncryptionModules(); |
|
66
|
|
|
$defaultEncryptionModuleId = $this->manager->getDefaultEncryptionModuleId(); |
|
67
|
|
|
$encryptionModuleList = []; |
|
68
|
|
|
foreach ($encryptionModules as $module) { |
|
69
|
|
|
$encryptionModuleList[$module['id']]['displayName'] = $module['displayName']; |
|
70
|
|
|
$encryptionModuleList[$module['id']]['default'] = false; |
|
71
|
|
|
if ($module['id'] === $defaultEncryptionModuleId) { |
|
72
|
|
|
$encryptionModuleList[$module['id']]['default'] = true; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$this->initialState->provideInitialState( |
|
77
|
|
|
'settings', |
|
78
|
|
|
'mandatory2FAState', |
|
79
|
|
|
$this->mandatoryTwoFactor->getState() |
|
80
|
|
|
); |
|
81
|
|
|
|
|
82
|
|
|
$parameters = [ |
|
83
|
|
|
// Encryption API |
|
84
|
|
|
'encryptionEnabled' => $this->manager->isEnabled(), |
|
85
|
|
|
'encryptionReady' => $this->manager->isReady(), |
|
|
|
|
|
|
86
|
|
|
'externalBackendsEnabled' => count($this->userManager->getBackends()) > 1, |
|
87
|
|
|
// Modules |
|
88
|
|
|
'encryptionModules' => $encryptionModuleList, |
|
89
|
|
|
]; |
|
90
|
|
|
|
|
91
|
|
|
return new TemplateResponse('settings', 'settings/admin/security', $parameters, ''); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return string the section ID, e.g. 'sharing' |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getSection() { |
|
98
|
|
|
return 'security'; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @return int whether the form should be rather on the top or bottom of |
|
103
|
|
|
* the admin section. The forms are arranged in ascending order of the |
|
104
|
|
|
* priority values. It is required to return a value between 0 and 100. |
|
105
|
|
|
* |
|
106
|
|
|
* E.g.: 70 |
|
107
|
|
|
*/ |
|
108
|
|
|
public function getPriority() { |
|
109
|
|
|
return 10; |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|