|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016 Arthur Schiwon <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @author Arthur Schiwon <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @license GNU AGPL version 3 or any later version |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
12
|
|
|
* License, or (at your option) any later version. |
|
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 |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
namespace OCA\Encryption\Settings; |
|
25
|
|
|
|
|
26
|
|
|
use OC\Files\View; |
|
27
|
|
|
use OCA\Encryption\Crypto\Crypt; |
|
28
|
|
|
use OCA\Encryption\Session; |
|
29
|
|
|
use OCA\Encryption\Util; |
|
30
|
|
|
use OCP\AppFramework\Http\TemplateResponse; |
|
31
|
|
|
use OCP\IL10N; |
|
32
|
|
|
use OCP\ILogger; |
|
33
|
|
|
use OCP\ISession; |
|
34
|
|
|
use OCP\IUserManager; |
|
35
|
|
|
use OCP\IUserSession; |
|
36
|
|
|
use OCP\Settings\ISettings; |
|
37
|
|
|
use OCP\IConfig; |
|
38
|
|
|
|
|
39
|
|
|
class Admin implements ISettings { |
|
40
|
|
|
|
|
41
|
|
|
/** @var IL10N */ |
|
42
|
|
|
private $l; |
|
43
|
|
|
|
|
44
|
|
|
/** @var ILogger */ |
|
45
|
|
|
private $logger; |
|
46
|
|
|
|
|
47
|
|
|
/** @var IUserSession */ |
|
48
|
|
|
private $userSession; |
|
49
|
|
|
|
|
50
|
|
|
/** @var IConfig */ |
|
51
|
|
|
private $config; |
|
52
|
|
|
|
|
53
|
|
|
/** @var IUserManager */ |
|
54
|
|
|
private $userManager; |
|
55
|
|
|
|
|
56
|
|
|
/** @var ISession */ |
|
57
|
|
|
private $session; |
|
58
|
|
|
|
|
59
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
|
|
60
|
|
|
IL10N $l, |
|
61
|
|
|
ILogger $logger, |
|
62
|
|
|
IUserSession $userSession, |
|
63
|
|
|
IConfig $config, |
|
64
|
|
|
IUserManager $userManager, |
|
65
|
|
|
ISession $session |
|
66
|
|
|
) { |
|
67
|
|
|
$this->l = $l; |
|
68
|
|
|
$this->logger = $logger; |
|
69
|
|
|
$this->userSession = $userSession; |
|
70
|
|
|
$this->config = $config; |
|
71
|
|
|
$this->userManager = $userManager; |
|
72
|
|
|
$this->session = $session; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @return TemplateResponse |
|
77
|
|
|
*/ |
|
78
|
|
|
public function getForm() { |
|
79
|
|
|
$crypt = new Crypt( |
|
80
|
|
|
$this->logger, |
|
81
|
|
|
$this->userSession, |
|
82
|
|
|
$this->config, |
|
83
|
|
|
$this->l); |
|
84
|
|
|
|
|
85
|
|
|
$util = new Util( |
|
86
|
|
|
new View(), |
|
87
|
|
|
$crypt, |
|
88
|
|
|
$this->logger, |
|
89
|
|
|
$this->userSession, |
|
90
|
|
|
$this->config, |
|
91
|
|
|
$this->userManager); |
|
92
|
|
|
|
|
93
|
|
|
// Check if an adminRecovery account is enabled for recovering files after lost pwd |
|
94
|
|
|
$recoveryAdminEnabled = $this->config->getAppValue('encryption', 'recoveryAdminEnabled', '0'); |
|
95
|
|
|
$session = new Session($this->session); |
|
96
|
|
|
|
|
97
|
|
|
$encryptHomeStorage = $util->shouldEncryptHomeStorage(); |
|
98
|
|
|
|
|
99
|
|
|
$parameters = [ |
|
100
|
|
|
'recoveryEnabled' => $recoveryAdminEnabled, |
|
101
|
|
|
'initStatus' => $session->getStatus(), |
|
102
|
|
|
'encryptHomeStorage' => $encryptHomeStorage, |
|
103
|
|
|
'masterKeyEnabled' => $util->isMasterKeyEnabled(), |
|
104
|
|
|
]; |
|
105
|
|
|
|
|
106
|
|
|
return new TemplateResponse('encryption', 'settings-admin', $parameters, ''); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @return string the section ID, e.g. 'sharing' |
|
111
|
|
|
*/ |
|
112
|
|
|
public function getSection() { |
|
113
|
|
|
return 'encryption'; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @return int whether the form should be rather on the top or bottom of |
|
118
|
|
|
* the admin section. The forms are arranged in ascending order of the |
|
119
|
|
|
* priority values. It is required to return a value between 0 and 100. |
|
120
|
|
|
* |
|
121
|
|
|
* E.g.: 70 |
|
122
|
|
|
*/ |
|
123
|
|
|
public function getPriority() { |
|
124
|
|
|
return 5; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
} |
|
128
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.