@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | - /** @var array $_ */ |
|
3 | - /** @var \OCP\IL10N $l */ |
|
2 | + /** @var array $_ */ |
|
3 | + /** @var \OCP\IL10N $l */ |
|
4 | 4 | script('encryption', 'settings-personal'); |
5 | 5 | ?> |
6 | 6 | <form id="ocDefaultEncryptionModule" class="section"> |
@@ -19,8 +19,8 @@ discard block |
||
19 | 19 | <br /> |
20 | 20 | <?php p($l->t("Set your old private key password to your current log-in password:")); ?> |
21 | 21 | <?php if ($_["recoveryEnabledForUser"]): |
22 | - p($l->t(" If you don't remember your old password you can ask your administrator to recover your files.")); |
|
23 | - endif; ?> |
|
22 | + p($l->t(" If you don't remember your old password you can ask your administrator to recover your files.")); |
|
23 | + endif; ?> |
|
24 | 24 | <br /> |
25 | 25 | <input |
26 | 26 | type="password" |
@@ -42,7 +42,7 @@ |
||
42 | 42 | <span class="msg"></span> |
43 | 43 | </p> |
44 | 44 | |
45 | - <?php elseif ($_["recoveryEnabled"] && $_["privateKeySet"] && $_["initialized"] === \OCA\Encryption\Session::INIT_SUCCESSFUL): ?> |
|
45 | + <?php elseif ($_["recoveryEnabled"] && $_["privateKeySet"] && $_["initialized"] === \OCA\Encryption\Session::INIT_SUCCESSFUL): ?> |
|
46 | 46 | <br /> |
47 | 47 | <p id="userEnableRecovery"> |
48 | 48 | <label for="userEnableRecovery"><?php p($l->t("Enable password recovery:")); ?></label> |
@@ -6,17 +6,17 @@ discard block |
||
6 | 6 | ?> |
7 | 7 | <form id="ocDefaultEncryptionModule" class="sub-section"> |
8 | 8 | <h3><?php p($l->t("Default encryption module")); ?></h3> |
9 | - <?php if(!$_["initStatus"] && $_['masterKeyEnabled'] === false): ?> |
|
9 | + <?php if (!$_["initStatus"] && $_['masterKeyEnabled'] === false): ?> |
|
10 | 10 | <?php p($l->t("Encryption app is enabled but your keys are not initialized, please log-out and log-in again")); ?> |
11 | 11 | <?php else: ?> |
12 | 12 | <p id="encryptHomeStorageSetting"> |
13 | 13 | <input type="checkbox" class="checkbox" name="encrypt_home_storage" id="encryptHomeStorage" |
14 | 14 | value="1" <?php if ($_['encryptHomeStorage']) print_unescaped('checked="checked"'); ?> /> |
15 | - <label for="encryptHomeStorage"><?php p($l->t('Encrypt the home storage'));?></label></br> |
|
15 | + <label for="encryptHomeStorage"><?php p($l->t('Encrypt the home storage')); ?></label></br> |
|
16 | 16 | <em><?php p($l->t("Enabling this option encrypts all files stored on the main storage, otherwise only files on external storage will be encrypted")); ?></em> |
17 | 17 | </p> |
18 | 18 | <br /> |
19 | - <?php if($_['masterKeyEnabled'] === false): ?> |
|
19 | + <?php if ($_['masterKeyEnabled'] === false): ?> |
|
20 | 20 | <p id="encryptionSetRecoveryKey"> |
21 | 21 | <?php $_["recoveryEnabled"] === '0' ? p($l->t("Enable recovery key")) : p($l->t("Disable recovery key")); ?> |
22 | 22 | <span class="msg"></span> |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | </p> |
42 | 42 | <br/><br/> |
43 | 43 | |
44 | - <p name="changeRecoveryPasswordBlock" id="encryptionChangeRecoveryKey" <?php if($_['recoveryEnabled'] === '0') print_unescaped('class="hidden"');?>> |
|
44 | + <p name="changeRecoveryPasswordBlock" id="encryptionChangeRecoveryKey" <?php if ($_['recoveryEnabled'] === '0') print_unescaped('class="hidden"'); ?>> |
|
45 | 45 | <?php p($l->t("Change recovery key password:")); ?> |
46 | 46 | <span class="msg"></span> |
47 | 47 | <br/> |
@@ -8,10 +8,13 @@ discard block |
||
8 | 8 | <h3><?php p($l->t("Default encryption module")); ?></h3> |
9 | 9 | <?php if(!$_["initStatus"] && $_['masterKeyEnabled'] === false): ?> |
10 | 10 | <?php p($l->t("Encryption app is enabled but your keys are not initialized, please log-out and log-in again")); ?> |
11 | - <?php else: ?> |
|
11 | + <?php else { |
|
12 | + : ?> |
|
12 | 13 | <p id="encryptHomeStorageSetting"> |
13 | 14 | <input type="checkbox" class="checkbox" name="encrypt_home_storage" id="encryptHomeStorage" |
14 | - value="1" <?php if ($_['encryptHomeStorage']) print_unescaped('checked="checked"'); ?> /> |
|
15 | + value="1" <?php if ($_['encryptHomeStorage']) print_unescaped('checked="checked"'); |
|
16 | +} |
|
17 | +?> /> |
|
15 | 18 | <label for="encryptHomeStorage"><?php p($l->t('Encrypt the home storage'));?></label></br> |
16 | 19 | <em><?php p($l->t("Enabling this option encrypts all files stored on the main storage, otherwise only files on external storage will be encrypted")); ?></em> |
17 | 20 | </p> |
@@ -41,7 +44,10 @@ discard block |
||
41 | 44 | </p> |
42 | 45 | <br/><br/> |
43 | 46 | |
44 | - <p name="changeRecoveryPasswordBlock" id="encryptionChangeRecoveryKey" <?php if($_['recoveryEnabled'] === '0') print_unescaped('class="hidden"');?>> |
|
47 | + <p name="changeRecoveryPasswordBlock" id="encryptionChangeRecoveryKey" <?php if($_['recoveryEnabled'] === '0') { |
|
48 | + print_unescaped('class="hidden"'); |
|
49 | +} |
|
50 | +?>> |
|
45 | 51 | <?php p($l->t("Change recovery key password:")); ?> |
46 | 52 | <span class="msg"></span> |
47 | 53 | <br/> |
@@ -47,440 +47,440 @@ |
||
47 | 47 | |
48 | 48 | class EncryptAll { |
49 | 49 | |
50 | - /** @var Setup */ |
|
51 | - protected $userSetup; |
|
52 | - |
|
53 | - /** @var IUserManager */ |
|
54 | - protected $userManager; |
|
55 | - |
|
56 | - /** @var View */ |
|
57 | - protected $rootView; |
|
58 | - |
|
59 | - /** @var KeyManager */ |
|
60 | - protected $keyManager; |
|
61 | - |
|
62 | - /** @var Util */ |
|
63 | - protected $util; |
|
64 | - |
|
65 | - /** @var array */ |
|
66 | - protected $userPasswords; |
|
67 | - |
|
68 | - /** @var IConfig */ |
|
69 | - protected $config; |
|
70 | - |
|
71 | - /** @var IMailer */ |
|
72 | - protected $mailer; |
|
73 | - |
|
74 | - /** @var IL10N */ |
|
75 | - protected $l; |
|
76 | - |
|
77 | - /** @var QuestionHelper */ |
|
78 | - protected $questionHelper; |
|
79 | - |
|
80 | - /** @var OutputInterface */ |
|
81 | - protected $output; |
|
82 | - |
|
83 | - /** @var InputInterface */ |
|
84 | - protected $input; |
|
85 | - |
|
86 | - /** @var ISecureRandom */ |
|
87 | - protected $secureRandom; |
|
88 | - |
|
89 | - /** |
|
90 | - * @param Setup $userSetup |
|
91 | - * @param IUserManager $userManager |
|
92 | - * @param View $rootView |
|
93 | - * @param KeyManager $keyManager |
|
94 | - * @param Util $util |
|
95 | - * @param IConfig $config |
|
96 | - * @param IMailer $mailer |
|
97 | - * @param IL10N $l |
|
98 | - * @param QuestionHelper $questionHelper |
|
99 | - * @param ISecureRandom $secureRandom |
|
100 | - */ |
|
101 | - public function __construct( |
|
102 | - Setup $userSetup, |
|
103 | - IUserManager $userManager, |
|
104 | - View $rootView, |
|
105 | - KeyManager $keyManager, |
|
106 | - Util $util, |
|
107 | - IConfig $config, |
|
108 | - IMailer $mailer, |
|
109 | - IL10N $l, |
|
110 | - QuestionHelper $questionHelper, |
|
111 | - ISecureRandom $secureRandom |
|
112 | - ) { |
|
113 | - $this->userSetup = $userSetup; |
|
114 | - $this->userManager = $userManager; |
|
115 | - $this->rootView = $rootView; |
|
116 | - $this->keyManager = $keyManager; |
|
117 | - $this->util = $util; |
|
118 | - $this->config = $config; |
|
119 | - $this->mailer = $mailer; |
|
120 | - $this->l = $l; |
|
121 | - $this->questionHelper = $questionHelper; |
|
122 | - $this->secureRandom = $secureRandom; |
|
123 | - // store one time passwords for the users |
|
124 | - $this->userPasswords = []; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * start to encrypt all files |
|
129 | - * |
|
130 | - * @param InputInterface $input |
|
131 | - * @param OutputInterface $output |
|
132 | - */ |
|
133 | - public function encryptAll(InputInterface $input, OutputInterface $output) { |
|
134 | - |
|
135 | - $this->input = $input; |
|
136 | - $this->output = $output; |
|
137 | - |
|
138 | - $headline = 'Encrypt all files with the ' . Encryption::DISPLAY_NAME; |
|
139 | - $this->output->writeln("\n"); |
|
140 | - $this->output->writeln($headline); |
|
141 | - $this->output->writeln(str_pad('', strlen($headline), '=')); |
|
142 | - $this->output->writeln("\n"); |
|
143 | - |
|
144 | - if ($this->util->isMasterKeyEnabled()) { |
|
145 | - $this->output->writeln('Use master key to encrypt all files.'); |
|
146 | - $this->keyManager->validateMasterKey(); |
|
147 | - } else { |
|
148 | - //create private/public keys for each user and store the private key password |
|
149 | - $this->output->writeln('Create key-pair for every user'); |
|
150 | - $this->output->writeln('------------------------------'); |
|
151 | - $this->output->writeln(''); |
|
152 | - $this->output->writeln('This module will encrypt all files in the users files folder initially.'); |
|
153 | - $this->output->writeln('Already existing versions and files in the trash bin will not be encrypted.'); |
|
154 | - $this->output->writeln(''); |
|
155 | - $this->createKeyPairs(); |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - // output generated encryption key passwords |
|
160 | - if ($this->util->isMasterKeyEnabled() === false) { |
|
161 | - //send-out or display password list and write it to a file |
|
162 | - $this->output->writeln("\n"); |
|
163 | - $this->output->writeln('Generated encryption key passwords'); |
|
164 | - $this->output->writeln('----------------------------------'); |
|
165 | - $this->output->writeln(''); |
|
166 | - $this->outputPasswords(); |
|
167 | - } |
|
168 | - |
|
169 | - //setup users file system and encrypt all files one by one (take should encrypt setting of storage into account) |
|
170 | - $this->output->writeln("\n"); |
|
171 | - $this->output->writeln('Start to encrypt users files'); |
|
172 | - $this->output->writeln('----------------------------'); |
|
173 | - $this->output->writeln(''); |
|
174 | - $this->encryptAllUsersFiles(); |
|
175 | - $this->output->writeln("\n"); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * create key-pair for every user |
|
180 | - */ |
|
181 | - protected function createKeyPairs() { |
|
182 | - $this->output->writeln("\n"); |
|
183 | - $progress = new ProgressBar($this->output); |
|
184 | - $progress->setFormat(" %message% \n [%bar%]"); |
|
185 | - $progress->start(); |
|
186 | - |
|
187 | - foreach($this->userManager->getBackends() as $backend) { |
|
188 | - $limit = 500; |
|
189 | - $offset = 0; |
|
190 | - do { |
|
191 | - $users = $backend->getUsers('', $limit, $offset); |
|
192 | - foreach ($users as $user) { |
|
193 | - if ($this->keyManager->userHasKeys($user) === false) { |
|
194 | - $progress->setMessage('Create key-pair for ' . $user); |
|
195 | - $progress->advance(); |
|
196 | - $this->setupUserFS($user); |
|
197 | - $password = $this->generateOneTimePassword($user); |
|
198 | - $this->userSetup->setupUser($user, $password); |
|
199 | - } else { |
|
200 | - // users which already have a key-pair will be stored with a |
|
201 | - // empty password and filtered out later |
|
202 | - $this->userPasswords[$user] = ''; |
|
203 | - } |
|
204 | - } |
|
205 | - $offset += $limit; |
|
206 | - } while(count($users) >= $limit); |
|
207 | - } |
|
208 | - |
|
209 | - $progress->setMessage('Key-pair created for all users'); |
|
210 | - $progress->finish(); |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * iterate over all user and encrypt their files |
|
215 | - */ |
|
216 | - protected function encryptAllUsersFiles() { |
|
217 | - $this->output->writeln("\n"); |
|
218 | - $progress = new ProgressBar($this->output); |
|
219 | - $progress->setFormat(" %message% \n [%bar%]"); |
|
220 | - $progress->start(); |
|
221 | - $numberOfUsers = count($this->userPasswords); |
|
222 | - $userNo = 1; |
|
223 | - if ($this->util->isMasterKeyEnabled()) { |
|
224 | - $this->encryptAllUserFilesWithMasterKey($progress); |
|
225 | - } else { |
|
226 | - foreach ($this->userPasswords as $uid => $password) { |
|
227 | - $userCount = "$uid ($userNo of $numberOfUsers)"; |
|
228 | - $this->encryptUsersFiles($uid, $progress, $userCount); |
|
229 | - $userNo++; |
|
230 | - } |
|
231 | - } |
|
232 | - $progress->setMessage("all files encrypted"); |
|
233 | - $progress->finish(); |
|
234 | - |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * encrypt all user files with the master key |
|
239 | - * |
|
240 | - * @param ProgressBar $progress |
|
241 | - */ |
|
242 | - protected function encryptAllUserFilesWithMasterKey(ProgressBar $progress) { |
|
243 | - $userNo = 1; |
|
244 | - foreach($this->userManager->getBackends() as $backend) { |
|
245 | - $limit = 500; |
|
246 | - $offset = 0; |
|
247 | - do { |
|
248 | - $users = $backend->getUsers('', $limit, $offset); |
|
249 | - foreach ($users as $user) { |
|
250 | - $userCount = "$user ($userNo)"; |
|
251 | - $this->encryptUsersFiles($user, $progress, $userCount); |
|
252 | - $userNo++; |
|
253 | - } |
|
254 | - $offset += $limit; |
|
255 | - } while(count($users) >= $limit); |
|
256 | - } |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * encrypt files from the given user |
|
261 | - * |
|
262 | - * @param string $uid |
|
263 | - * @param ProgressBar $progress |
|
264 | - * @param string $userCount |
|
265 | - */ |
|
266 | - protected function encryptUsersFiles($uid, ProgressBar $progress, $userCount) { |
|
267 | - |
|
268 | - $this->setupUserFS($uid); |
|
269 | - $directories = []; |
|
270 | - $directories[] = '/' . $uid . '/files'; |
|
271 | - |
|
272 | - while($root = array_pop($directories)) { |
|
273 | - $content = $this->rootView->getDirectoryContent($root); |
|
274 | - foreach ($content as $file) { |
|
275 | - $path = $root . '/' . $file['name']; |
|
276 | - if ($this->rootView->is_dir($path)) { |
|
277 | - $directories[] = $path; |
|
278 | - continue; |
|
279 | - } else { |
|
280 | - $progress->setMessage("encrypt files for user $userCount: $path"); |
|
281 | - $progress->advance(); |
|
282 | - if($this->encryptFile($path) === false) { |
|
283 | - $progress->setMessage("encrypt files for user $userCount: $path (already encrypted)"); |
|
284 | - $progress->advance(); |
|
285 | - } |
|
286 | - } |
|
287 | - } |
|
288 | - } |
|
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * encrypt file |
|
293 | - * |
|
294 | - * @param string $path |
|
295 | - * @return bool |
|
296 | - */ |
|
297 | - protected function encryptFile($path) { |
|
298 | - |
|
299 | - // skip already encrypted files |
|
300 | - $fileInfo = $this->rootView->getFileInfo($path); |
|
301 | - if ($fileInfo !== false && $fileInfo->isEncrypted()) { |
|
302 | - return true; |
|
303 | - } |
|
304 | - |
|
305 | - $source = $path; |
|
306 | - $target = $path . '.encrypted.' . time(); |
|
307 | - |
|
308 | - try { |
|
309 | - $this->rootView->copy($source, $target); |
|
310 | - $this->rootView->rename($target, $source); |
|
311 | - } catch (DecryptionFailedException $e) { |
|
312 | - if ($this->rootView->file_exists($target)) { |
|
313 | - $this->rootView->unlink($target); |
|
314 | - } |
|
315 | - return false; |
|
316 | - } |
|
317 | - |
|
318 | - return true; |
|
319 | - } |
|
320 | - |
|
321 | - /** |
|
322 | - * output one-time encryption passwords |
|
323 | - */ |
|
324 | - protected function outputPasswords() { |
|
325 | - $table = new Table($this->output); |
|
326 | - $table->setHeaders(['Username', 'Private key password']); |
|
327 | - |
|
328 | - //create rows |
|
329 | - $newPasswords = []; |
|
330 | - $unchangedPasswords = []; |
|
331 | - foreach ($this->userPasswords as $uid => $password) { |
|
332 | - if (empty($password)) { |
|
333 | - $unchangedPasswords[] = $uid; |
|
334 | - } else { |
|
335 | - $newPasswords[] = [$uid, $password]; |
|
336 | - } |
|
337 | - } |
|
338 | - |
|
339 | - if (empty($newPasswords)) { |
|
340 | - $this->output->writeln("\nAll users already had a key-pair, no further action needed.\n"); |
|
341 | - return; |
|
342 | - } |
|
343 | - |
|
344 | - $table->setRows($newPasswords); |
|
345 | - $table->render(); |
|
346 | - |
|
347 | - if (!empty($unchangedPasswords)) { |
|
348 | - $this->output->writeln("\nThe following users already had a key-pair which was reused without setting a new password:\n"); |
|
349 | - foreach ($unchangedPasswords as $uid) { |
|
350 | - $this->output->writeln(" $uid"); |
|
351 | - } |
|
352 | - } |
|
353 | - |
|
354 | - $this->writePasswordsToFile($newPasswords); |
|
355 | - |
|
356 | - $this->output->writeln(''); |
|
357 | - $question = new ConfirmationQuestion('Do you want to send the passwords directly to the users by mail? (y/n) ', false); |
|
358 | - if ($this->questionHelper->ask($this->input, $this->output, $question)) { |
|
359 | - $this->sendPasswordsByMail(); |
|
360 | - } |
|
361 | - } |
|
362 | - |
|
363 | - /** |
|
364 | - * write one-time encryption passwords to a csv file |
|
365 | - * |
|
366 | - * @param array $passwords |
|
367 | - */ |
|
368 | - protected function writePasswordsToFile(array $passwords) { |
|
369 | - $fp = $this->rootView->fopen('oneTimeEncryptionPasswords.csv', 'w'); |
|
370 | - foreach ($passwords as $pwd) { |
|
371 | - fputcsv($fp, $pwd); |
|
372 | - } |
|
373 | - fclose($fp); |
|
374 | - $this->output->writeln("\n"); |
|
375 | - $this->output->writeln('A list of all newly created passwords was written to data/oneTimeEncryptionPasswords.csv'); |
|
376 | - $this->output->writeln(''); |
|
377 | - $this->output->writeln('Each of these users need to login to the web interface, go to the'); |
|
378 | - $this->output->writeln('personal settings section "basic encryption module" and'); |
|
379 | - $this->output->writeln('update the private key password to match the login password again by'); |
|
380 | - $this->output->writeln('entering the one-time password into the "old log-in password" field'); |
|
381 | - $this->output->writeln('and their current login password'); |
|
382 | - } |
|
383 | - |
|
384 | - /** |
|
385 | - * setup user file system |
|
386 | - * |
|
387 | - * @param string $uid |
|
388 | - */ |
|
389 | - protected function setupUserFS($uid) { |
|
390 | - \OC_Util::tearDownFS(); |
|
391 | - \OC_Util::setupFS($uid); |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * generate one time password for the user and store it in a array |
|
396 | - * |
|
397 | - * @param string $uid |
|
398 | - * @return string password |
|
399 | - */ |
|
400 | - protected function generateOneTimePassword($uid) { |
|
401 | - $password = $this->secureRandom->generate(8); |
|
402 | - $this->userPasswords[$uid] = $password; |
|
403 | - return $password; |
|
404 | - } |
|
405 | - |
|
406 | - /** |
|
407 | - * send encryption key passwords to the users by mail |
|
408 | - */ |
|
409 | - protected function sendPasswordsByMail() { |
|
410 | - $noMail = []; |
|
411 | - |
|
412 | - $this->output->writeln(''); |
|
413 | - $progress = new ProgressBar($this->output, count($this->userPasswords)); |
|
414 | - $progress->start(); |
|
415 | - |
|
416 | - foreach ($this->userPasswords as $uid => $password) { |
|
417 | - $progress->advance(); |
|
418 | - if (!empty($password)) { |
|
419 | - $recipient = $this->userManager->get($uid); |
|
420 | - $recipientDisplayName = $recipient->getDisplayName(); |
|
421 | - $to = $recipient->getEMailAddress(); |
|
422 | - |
|
423 | - if ($to === '') { |
|
424 | - $noMail[] = $uid; |
|
425 | - continue; |
|
426 | - } |
|
427 | - |
|
428 | - $subject = (string)$this->l->t('one-time password for server-side-encryption'); |
|
429 | - list($htmlBody, $textBody) = $this->createMailBody($password); |
|
430 | - |
|
431 | - // send it out now |
|
432 | - try { |
|
433 | - $message = $this->mailer->createMessage(); |
|
434 | - $message->setSubject($subject); |
|
435 | - $message->setTo([$to => $recipientDisplayName]); |
|
436 | - $message->setHtmlBody($htmlBody); |
|
437 | - $message->setPlainBody($textBody); |
|
438 | - $message->setFrom([ |
|
439 | - \OCP\Util::getDefaultEmailAddress('admin-noreply') |
|
440 | - ]); |
|
441 | - |
|
442 | - $this->mailer->send($message); |
|
443 | - } catch (\Exception $e) { |
|
444 | - $noMail[] = $uid; |
|
445 | - } |
|
446 | - } |
|
447 | - } |
|
448 | - |
|
449 | - $progress->finish(); |
|
450 | - |
|
451 | - if (empty($noMail)) { |
|
452 | - $this->output->writeln("\n\nPassword successfully send to all users"); |
|
453 | - } else { |
|
454 | - $table = new Table($this->output); |
|
455 | - $table->setHeaders(['Username', 'Private key password']); |
|
456 | - $this->output->writeln("\n\nCould not send password to following users:\n"); |
|
457 | - $rows = []; |
|
458 | - foreach ($noMail as $uid) { |
|
459 | - $rows[] = [$uid, $this->userPasswords[$uid]]; |
|
460 | - } |
|
461 | - $table->setRows($rows); |
|
462 | - $table->render(); |
|
463 | - } |
|
464 | - |
|
465 | - } |
|
466 | - |
|
467 | - /** |
|
468 | - * create mail body for plain text and html mail |
|
469 | - * |
|
470 | - * @param string $password one-time encryption password |
|
471 | - * @return array an array of the html mail body and the plain text mail body |
|
472 | - */ |
|
473 | - protected function createMailBody($password) { |
|
474 | - |
|
475 | - $html = new \OC_Template("encryption", "mail", ""); |
|
476 | - $html->assign('password', $password); |
|
477 | - $htmlMail = $html->fetchPage(); |
|
478 | - |
|
479 | - $plainText = new \OC_Template("encryption", "altmail", ""); |
|
480 | - $plainText->assign('password', $password); |
|
481 | - $plainTextMail = $plainText->fetchPage(); |
|
482 | - |
|
483 | - return [$htmlMail, $plainTextMail]; |
|
484 | - } |
|
50 | + /** @var Setup */ |
|
51 | + protected $userSetup; |
|
52 | + |
|
53 | + /** @var IUserManager */ |
|
54 | + protected $userManager; |
|
55 | + |
|
56 | + /** @var View */ |
|
57 | + protected $rootView; |
|
58 | + |
|
59 | + /** @var KeyManager */ |
|
60 | + protected $keyManager; |
|
61 | + |
|
62 | + /** @var Util */ |
|
63 | + protected $util; |
|
64 | + |
|
65 | + /** @var array */ |
|
66 | + protected $userPasswords; |
|
67 | + |
|
68 | + /** @var IConfig */ |
|
69 | + protected $config; |
|
70 | + |
|
71 | + /** @var IMailer */ |
|
72 | + protected $mailer; |
|
73 | + |
|
74 | + /** @var IL10N */ |
|
75 | + protected $l; |
|
76 | + |
|
77 | + /** @var QuestionHelper */ |
|
78 | + protected $questionHelper; |
|
79 | + |
|
80 | + /** @var OutputInterface */ |
|
81 | + protected $output; |
|
82 | + |
|
83 | + /** @var InputInterface */ |
|
84 | + protected $input; |
|
85 | + |
|
86 | + /** @var ISecureRandom */ |
|
87 | + protected $secureRandom; |
|
88 | + |
|
89 | + /** |
|
90 | + * @param Setup $userSetup |
|
91 | + * @param IUserManager $userManager |
|
92 | + * @param View $rootView |
|
93 | + * @param KeyManager $keyManager |
|
94 | + * @param Util $util |
|
95 | + * @param IConfig $config |
|
96 | + * @param IMailer $mailer |
|
97 | + * @param IL10N $l |
|
98 | + * @param QuestionHelper $questionHelper |
|
99 | + * @param ISecureRandom $secureRandom |
|
100 | + */ |
|
101 | + public function __construct( |
|
102 | + Setup $userSetup, |
|
103 | + IUserManager $userManager, |
|
104 | + View $rootView, |
|
105 | + KeyManager $keyManager, |
|
106 | + Util $util, |
|
107 | + IConfig $config, |
|
108 | + IMailer $mailer, |
|
109 | + IL10N $l, |
|
110 | + QuestionHelper $questionHelper, |
|
111 | + ISecureRandom $secureRandom |
|
112 | + ) { |
|
113 | + $this->userSetup = $userSetup; |
|
114 | + $this->userManager = $userManager; |
|
115 | + $this->rootView = $rootView; |
|
116 | + $this->keyManager = $keyManager; |
|
117 | + $this->util = $util; |
|
118 | + $this->config = $config; |
|
119 | + $this->mailer = $mailer; |
|
120 | + $this->l = $l; |
|
121 | + $this->questionHelper = $questionHelper; |
|
122 | + $this->secureRandom = $secureRandom; |
|
123 | + // store one time passwords for the users |
|
124 | + $this->userPasswords = []; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * start to encrypt all files |
|
129 | + * |
|
130 | + * @param InputInterface $input |
|
131 | + * @param OutputInterface $output |
|
132 | + */ |
|
133 | + public function encryptAll(InputInterface $input, OutputInterface $output) { |
|
134 | + |
|
135 | + $this->input = $input; |
|
136 | + $this->output = $output; |
|
137 | + |
|
138 | + $headline = 'Encrypt all files with the ' . Encryption::DISPLAY_NAME; |
|
139 | + $this->output->writeln("\n"); |
|
140 | + $this->output->writeln($headline); |
|
141 | + $this->output->writeln(str_pad('', strlen($headline), '=')); |
|
142 | + $this->output->writeln("\n"); |
|
143 | + |
|
144 | + if ($this->util->isMasterKeyEnabled()) { |
|
145 | + $this->output->writeln('Use master key to encrypt all files.'); |
|
146 | + $this->keyManager->validateMasterKey(); |
|
147 | + } else { |
|
148 | + //create private/public keys for each user and store the private key password |
|
149 | + $this->output->writeln('Create key-pair for every user'); |
|
150 | + $this->output->writeln('------------------------------'); |
|
151 | + $this->output->writeln(''); |
|
152 | + $this->output->writeln('This module will encrypt all files in the users files folder initially.'); |
|
153 | + $this->output->writeln('Already existing versions and files in the trash bin will not be encrypted.'); |
|
154 | + $this->output->writeln(''); |
|
155 | + $this->createKeyPairs(); |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + // output generated encryption key passwords |
|
160 | + if ($this->util->isMasterKeyEnabled() === false) { |
|
161 | + //send-out or display password list and write it to a file |
|
162 | + $this->output->writeln("\n"); |
|
163 | + $this->output->writeln('Generated encryption key passwords'); |
|
164 | + $this->output->writeln('----------------------------------'); |
|
165 | + $this->output->writeln(''); |
|
166 | + $this->outputPasswords(); |
|
167 | + } |
|
168 | + |
|
169 | + //setup users file system and encrypt all files one by one (take should encrypt setting of storage into account) |
|
170 | + $this->output->writeln("\n"); |
|
171 | + $this->output->writeln('Start to encrypt users files'); |
|
172 | + $this->output->writeln('----------------------------'); |
|
173 | + $this->output->writeln(''); |
|
174 | + $this->encryptAllUsersFiles(); |
|
175 | + $this->output->writeln("\n"); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * create key-pair for every user |
|
180 | + */ |
|
181 | + protected function createKeyPairs() { |
|
182 | + $this->output->writeln("\n"); |
|
183 | + $progress = new ProgressBar($this->output); |
|
184 | + $progress->setFormat(" %message% \n [%bar%]"); |
|
185 | + $progress->start(); |
|
186 | + |
|
187 | + foreach($this->userManager->getBackends() as $backend) { |
|
188 | + $limit = 500; |
|
189 | + $offset = 0; |
|
190 | + do { |
|
191 | + $users = $backend->getUsers('', $limit, $offset); |
|
192 | + foreach ($users as $user) { |
|
193 | + if ($this->keyManager->userHasKeys($user) === false) { |
|
194 | + $progress->setMessage('Create key-pair for ' . $user); |
|
195 | + $progress->advance(); |
|
196 | + $this->setupUserFS($user); |
|
197 | + $password = $this->generateOneTimePassword($user); |
|
198 | + $this->userSetup->setupUser($user, $password); |
|
199 | + } else { |
|
200 | + // users which already have a key-pair will be stored with a |
|
201 | + // empty password and filtered out later |
|
202 | + $this->userPasswords[$user] = ''; |
|
203 | + } |
|
204 | + } |
|
205 | + $offset += $limit; |
|
206 | + } while(count($users) >= $limit); |
|
207 | + } |
|
208 | + |
|
209 | + $progress->setMessage('Key-pair created for all users'); |
|
210 | + $progress->finish(); |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * iterate over all user and encrypt their files |
|
215 | + */ |
|
216 | + protected function encryptAllUsersFiles() { |
|
217 | + $this->output->writeln("\n"); |
|
218 | + $progress = new ProgressBar($this->output); |
|
219 | + $progress->setFormat(" %message% \n [%bar%]"); |
|
220 | + $progress->start(); |
|
221 | + $numberOfUsers = count($this->userPasswords); |
|
222 | + $userNo = 1; |
|
223 | + if ($this->util->isMasterKeyEnabled()) { |
|
224 | + $this->encryptAllUserFilesWithMasterKey($progress); |
|
225 | + } else { |
|
226 | + foreach ($this->userPasswords as $uid => $password) { |
|
227 | + $userCount = "$uid ($userNo of $numberOfUsers)"; |
|
228 | + $this->encryptUsersFiles($uid, $progress, $userCount); |
|
229 | + $userNo++; |
|
230 | + } |
|
231 | + } |
|
232 | + $progress->setMessage("all files encrypted"); |
|
233 | + $progress->finish(); |
|
234 | + |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * encrypt all user files with the master key |
|
239 | + * |
|
240 | + * @param ProgressBar $progress |
|
241 | + */ |
|
242 | + protected function encryptAllUserFilesWithMasterKey(ProgressBar $progress) { |
|
243 | + $userNo = 1; |
|
244 | + foreach($this->userManager->getBackends() as $backend) { |
|
245 | + $limit = 500; |
|
246 | + $offset = 0; |
|
247 | + do { |
|
248 | + $users = $backend->getUsers('', $limit, $offset); |
|
249 | + foreach ($users as $user) { |
|
250 | + $userCount = "$user ($userNo)"; |
|
251 | + $this->encryptUsersFiles($user, $progress, $userCount); |
|
252 | + $userNo++; |
|
253 | + } |
|
254 | + $offset += $limit; |
|
255 | + } while(count($users) >= $limit); |
|
256 | + } |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * encrypt files from the given user |
|
261 | + * |
|
262 | + * @param string $uid |
|
263 | + * @param ProgressBar $progress |
|
264 | + * @param string $userCount |
|
265 | + */ |
|
266 | + protected function encryptUsersFiles($uid, ProgressBar $progress, $userCount) { |
|
267 | + |
|
268 | + $this->setupUserFS($uid); |
|
269 | + $directories = []; |
|
270 | + $directories[] = '/' . $uid . '/files'; |
|
271 | + |
|
272 | + while($root = array_pop($directories)) { |
|
273 | + $content = $this->rootView->getDirectoryContent($root); |
|
274 | + foreach ($content as $file) { |
|
275 | + $path = $root . '/' . $file['name']; |
|
276 | + if ($this->rootView->is_dir($path)) { |
|
277 | + $directories[] = $path; |
|
278 | + continue; |
|
279 | + } else { |
|
280 | + $progress->setMessage("encrypt files for user $userCount: $path"); |
|
281 | + $progress->advance(); |
|
282 | + if($this->encryptFile($path) === false) { |
|
283 | + $progress->setMessage("encrypt files for user $userCount: $path (already encrypted)"); |
|
284 | + $progress->advance(); |
|
285 | + } |
|
286 | + } |
|
287 | + } |
|
288 | + } |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * encrypt file |
|
293 | + * |
|
294 | + * @param string $path |
|
295 | + * @return bool |
|
296 | + */ |
|
297 | + protected function encryptFile($path) { |
|
298 | + |
|
299 | + // skip already encrypted files |
|
300 | + $fileInfo = $this->rootView->getFileInfo($path); |
|
301 | + if ($fileInfo !== false && $fileInfo->isEncrypted()) { |
|
302 | + return true; |
|
303 | + } |
|
304 | + |
|
305 | + $source = $path; |
|
306 | + $target = $path . '.encrypted.' . time(); |
|
307 | + |
|
308 | + try { |
|
309 | + $this->rootView->copy($source, $target); |
|
310 | + $this->rootView->rename($target, $source); |
|
311 | + } catch (DecryptionFailedException $e) { |
|
312 | + if ($this->rootView->file_exists($target)) { |
|
313 | + $this->rootView->unlink($target); |
|
314 | + } |
|
315 | + return false; |
|
316 | + } |
|
317 | + |
|
318 | + return true; |
|
319 | + } |
|
320 | + |
|
321 | + /** |
|
322 | + * output one-time encryption passwords |
|
323 | + */ |
|
324 | + protected function outputPasswords() { |
|
325 | + $table = new Table($this->output); |
|
326 | + $table->setHeaders(['Username', 'Private key password']); |
|
327 | + |
|
328 | + //create rows |
|
329 | + $newPasswords = []; |
|
330 | + $unchangedPasswords = []; |
|
331 | + foreach ($this->userPasswords as $uid => $password) { |
|
332 | + if (empty($password)) { |
|
333 | + $unchangedPasswords[] = $uid; |
|
334 | + } else { |
|
335 | + $newPasswords[] = [$uid, $password]; |
|
336 | + } |
|
337 | + } |
|
338 | + |
|
339 | + if (empty($newPasswords)) { |
|
340 | + $this->output->writeln("\nAll users already had a key-pair, no further action needed.\n"); |
|
341 | + return; |
|
342 | + } |
|
343 | + |
|
344 | + $table->setRows($newPasswords); |
|
345 | + $table->render(); |
|
346 | + |
|
347 | + if (!empty($unchangedPasswords)) { |
|
348 | + $this->output->writeln("\nThe following users already had a key-pair which was reused without setting a new password:\n"); |
|
349 | + foreach ($unchangedPasswords as $uid) { |
|
350 | + $this->output->writeln(" $uid"); |
|
351 | + } |
|
352 | + } |
|
353 | + |
|
354 | + $this->writePasswordsToFile($newPasswords); |
|
355 | + |
|
356 | + $this->output->writeln(''); |
|
357 | + $question = new ConfirmationQuestion('Do you want to send the passwords directly to the users by mail? (y/n) ', false); |
|
358 | + if ($this->questionHelper->ask($this->input, $this->output, $question)) { |
|
359 | + $this->sendPasswordsByMail(); |
|
360 | + } |
|
361 | + } |
|
362 | + |
|
363 | + /** |
|
364 | + * write one-time encryption passwords to a csv file |
|
365 | + * |
|
366 | + * @param array $passwords |
|
367 | + */ |
|
368 | + protected function writePasswordsToFile(array $passwords) { |
|
369 | + $fp = $this->rootView->fopen('oneTimeEncryptionPasswords.csv', 'w'); |
|
370 | + foreach ($passwords as $pwd) { |
|
371 | + fputcsv($fp, $pwd); |
|
372 | + } |
|
373 | + fclose($fp); |
|
374 | + $this->output->writeln("\n"); |
|
375 | + $this->output->writeln('A list of all newly created passwords was written to data/oneTimeEncryptionPasswords.csv'); |
|
376 | + $this->output->writeln(''); |
|
377 | + $this->output->writeln('Each of these users need to login to the web interface, go to the'); |
|
378 | + $this->output->writeln('personal settings section "basic encryption module" and'); |
|
379 | + $this->output->writeln('update the private key password to match the login password again by'); |
|
380 | + $this->output->writeln('entering the one-time password into the "old log-in password" field'); |
|
381 | + $this->output->writeln('and their current login password'); |
|
382 | + } |
|
383 | + |
|
384 | + /** |
|
385 | + * setup user file system |
|
386 | + * |
|
387 | + * @param string $uid |
|
388 | + */ |
|
389 | + protected function setupUserFS($uid) { |
|
390 | + \OC_Util::tearDownFS(); |
|
391 | + \OC_Util::setupFS($uid); |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * generate one time password for the user and store it in a array |
|
396 | + * |
|
397 | + * @param string $uid |
|
398 | + * @return string password |
|
399 | + */ |
|
400 | + protected function generateOneTimePassword($uid) { |
|
401 | + $password = $this->secureRandom->generate(8); |
|
402 | + $this->userPasswords[$uid] = $password; |
|
403 | + return $password; |
|
404 | + } |
|
405 | + |
|
406 | + /** |
|
407 | + * send encryption key passwords to the users by mail |
|
408 | + */ |
|
409 | + protected function sendPasswordsByMail() { |
|
410 | + $noMail = []; |
|
411 | + |
|
412 | + $this->output->writeln(''); |
|
413 | + $progress = new ProgressBar($this->output, count($this->userPasswords)); |
|
414 | + $progress->start(); |
|
415 | + |
|
416 | + foreach ($this->userPasswords as $uid => $password) { |
|
417 | + $progress->advance(); |
|
418 | + if (!empty($password)) { |
|
419 | + $recipient = $this->userManager->get($uid); |
|
420 | + $recipientDisplayName = $recipient->getDisplayName(); |
|
421 | + $to = $recipient->getEMailAddress(); |
|
422 | + |
|
423 | + if ($to === '') { |
|
424 | + $noMail[] = $uid; |
|
425 | + continue; |
|
426 | + } |
|
427 | + |
|
428 | + $subject = (string)$this->l->t('one-time password for server-side-encryption'); |
|
429 | + list($htmlBody, $textBody) = $this->createMailBody($password); |
|
430 | + |
|
431 | + // send it out now |
|
432 | + try { |
|
433 | + $message = $this->mailer->createMessage(); |
|
434 | + $message->setSubject($subject); |
|
435 | + $message->setTo([$to => $recipientDisplayName]); |
|
436 | + $message->setHtmlBody($htmlBody); |
|
437 | + $message->setPlainBody($textBody); |
|
438 | + $message->setFrom([ |
|
439 | + \OCP\Util::getDefaultEmailAddress('admin-noreply') |
|
440 | + ]); |
|
441 | + |
|
442 | + $this->mailer->send($message); |
|
443 | + } catch (\Exception $e) { |
|
444 | + $noMail[] = $uid; |
|
445 | + } |
|
446 | + } |
|
447 | + } |
|
448 | + |
|
449 | + $progress->finish(); |
|
450 | + |
|
451 | + if (empty($noMail)) { |
|
452 | + $this->output->writeln("\n\nPassword successfully send to all users"); |
|
453 | + } else { |
|
454 | + $table = new Table($this->output); |
|
455 | + $table->setHeaders(['Username', 'Private key password']); |
|
456 | + $this->output->writeln("\n\nCould not send password to following users:\n"); |
|
457 | + $rows = []; |
|
458 | + foreach ($noMail as $uid) { |
|
459 | + $rows[] = [$uid, $this->userPasswords[$uid]]; |
|
460 | + } |
|
461 | + $table->setRows($rows); |
|
462 | + $table->render(); |
|
463 | + } |
|
464 | + |
|
465 | + } |
|
466 | + |
|
467 | + /** |
|
468 | + * create mail body for plain text and html mail |
|
469 | + * |
|
470 | + * @param string $password one-time encryption password |
|
471 | + * @return array an array of the html mail body and the plain text mail body |
|
472 | + */ |
|
473 | + protected function createMailBody($password) { |
|
474 | + |
|
475 | + $html = new \OC_Template("encryption", "mail", ""); |
|
476 | + $html->assign('password', $password); |
|
477 | + $htmlMail = $html->fetchPage(); |
|
478 | + |
|
479 | + $plainText = new \OC_Template("encryption", "altmail", ""); |
|
480 | + $plainText->assign('password', $password); |
|
481 | + $plainTextMail = $plainText->fetchPage(); |
|
482 | + |
|
483 | + return [$htmlMail, $plainTextMail]; |
|
484 | + } |
|
485 | 485 | |
486 | 486 | } |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | $this->input = $input; |
136 | 136 | $this->output = $output; |
137 | 137 | |
138 | - $headline = 'Encrypt all files with the ' . Encryption::DISPLAY_NAME; |
|
138 | + $headline = 'Encrypt all files with the '.Encryption::DISPLAY_NAME; |
|
139 | 139 | $this->output->writeln("\n"); |
140 | 140 | $this->output->writeln($headline); |
141 | 141 | $this->output->writeln(str_pad('', strlen($headline), '=')); |
@@ -184,14 +184,14 @@ discard block |
||
184 | 184 | $progress->setFormat(" %message% \n [%bar%]"); |
185 | 185 | $progress->start(); |
186 | 186 | |
187 | - foreach($this->userManager->getBackends() as $backend) { |
|
187 | + foreach ($this->userManager->getBackends() as $backend) { |
|
188 | 188 | $limit = 500; |
189 | 189 | $offset = 0; |
190 | 190 | do { |
191 | 191 | $users = $backend->getUsers('', $limit, $offset); |
192 | 192 | foreach ($users as $user) { |
193 | 193 | if ($this->keyManager->userHasKeys($user) === false) { |
194 | - $progress->setMessage('Create key-pair for ' . $user); |
|
194 | + $progress->setMessage('Create key-pair for '.$user); |
|
195 | 195 | $progress->advance(); |
196 | 196 | $this->setupUserFS($user); |
197 | 197 | $password = $this->generateOneTimePassword($user); |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | } |
204 | 204 | } |
205 | 205 | $offset += $limit; |
206 | - } while(count($users) >= $limit); |
|
206 | + } while (count($users) >= $limit); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | $progress->setMessage('Key-pair created for all users'); |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | */ |
242 | 242 | protected function encryptAllUserFilesWithMasterKey(ProgressBar $progress) { |
243 | 243 | $userNo = 1; |
244 | - foreach($this->userManager->getBackends() as $backend) { |
|
244 | + foreach ($this->userManager->getBackends() as $backend) { |
|
245 | 245 | $limit = 500; |
246 | 246 | $offset = 0; |
247 | 247 | do { |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | $userNo++; |
253 | 253 | } |
254 | 254 | $offset += $limit; |
255 | - } while(count($users) >= $limit); |
|
255 | + } while (count($users) >= $limit); |
|
256 | 256 | } |
257 | 257 | } |
258 | 258 | |
@@ -267,19 +267,19 @@ discard block |
||
267 | 267 | |
268 | 268 | $this->setupUserFS($uid); |
269 | 269 | $directories = []; |
270 | - $directories[] = '/' . $uid . '/files'; |
|
270 | + $directories[] = '/'.$uid.'/files'; |
|
271 | 271 | |
272 | - while($root = array_pop($directories)) { |
|
272 | + while ($root = array_pop($directories)) { |
|
273 | 273 | $content = $this->rootView->getDirectoryContent($root); |
274 | 274 | foreach ($content as $file) { |
275 | - $path = $root . '/' . $file['name']; |
|
275 | + $path = $root.'/'.$file['name']; |
|
276 | 276 | if ($this->rootView->is_dir($path)) { |
277 | 277 | $directories[] = $path; |
278 | 278 | continue; |
279 | 279 | } else { |
280 | 280 | $progress->setMessage("encrypt files for user $userCount: $path"); |
281 | 281 | $progress->advance(); |
282 | - if($this->encryptFile($path) === false) { |
|
282 | + if ($this->encryptFile($path) === false) { |
|
283 | 283 | $progress->setMessage("encrypt files for user $userCount: $path (already encrypted)"); |
284 | 284 | $progress->advance(); |
285 | 285 | } |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | } |
304 | 304 | |
305 | 305 | $source = $path; |
306 | - $target = $path . '.encrypted.' . time(); |
|
306 | + $target = $path.'.encrypted.'.time(); |
|
307 | 307 | |
308 | 308 | try { |
309 | 309 | $this->rootView->copy($source, $target); |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | continue; |
426 | 426 | } |
427 | 427 | |
428 | - $subject = (string)$this->l->t('one-time password for server-side-encryption'); |
|
428 | + $subject = (string) $this->l->t('one-time password for server-side-encryption'); |
|
429 | 429 | list($htmlBody, $textBody) = $this->createMailBody($password); |
430 | 430 | |
431 | 431 | // send it out now |
@@ -34,160 +34,160 @@ |
||
34 | 34 | use OCP\IRequest; |
35 | 35 | |
36 | 36 | class RecoveryController extends Controller { |
37 | - /** |
|
38 | - * @var IConfig |
|
39 | - */ |
|
40 | - private $config; |
|
41 | - /** |
|
42 | - * @var IL10N |
|
43 | - */ |
|
44 | - private $l; |
|
45 | - /** |
|
46 | - * @var Recovery |
|
47 | - */ |
|
48 | - private $recovery; |
|
49 | - |
|
50 | - /** |
|
51 | - * @param string $AppName |
|
52 | - * @param IRequest $request |
|
53 | - * @param IConfig $config |
|
54 | - * @param IL10N $l10n |
|
55 | - * @param Recovery $recovery |
|
56 | - */ |
|
57 | - public function __construct($AppName, |
|
58 | - IRequest $request, |
|
59 | - IConfig $config, |
|
60 | - IL10N $l10n, |
|
61 | - Recovery $recovery) { |
|
62 | - parent::__construct($AppName, $request); |
|
63 | - $this->config = $config; |
|
64 | - $this->l = $l10n; |
|
65 | - $this->recovery = $recovery; |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @param string $recoveryPassword |
|
70 | - * @param string $confirmPassword |
|
71 | - * @param string $adminEnableRecovery |
|
72 | - * @return DataResponse |
|
73 | - */ |
|
74 | - public function adminRecovery($recoveryPassword, $confirmPassword, $adminEnableRecovery) { |
|
75 | - // Check if both passwords are the same |
|
76 | - if (empty($recoveryPassword)) { |
|
77 | - $errorMessage = (string)$this->l->t('Missing recovery key password'); |
|
78 | - return new DataResponse(['data' => ['message' => $errorMessage]], |
|
79 | - Http::STATUS_BAD_REQUEST); |
|
80 | - } |
|
81 | - |
|
82 | - if (empty($confirmPassword)) { |
|
83 | - $errorMessage = (string)$this->l->t('Please repeat the recovery key password'); |
|
84 | - return new DataResponse(['data' => ['message' => $errorMessage]], |
|
85 | - Http::STATUS_BAD_REQUEST); |
|
86 | - } |
|
87 | - |
|
88 | - if ($recoveryPassword !== $confirmPassword) { |
|
89 | - $errorMessage = (string)$this->l->t('Repeated recovery key password does not match the provided recovery key password'); |
|
90 | - return new DataResponse(['data' => ['message' => $errorMessage]], |
|
91 | - Http::STATUS_BAD_REQUEST); |
|
92 | - } |
|
93 | - |
|
94 | - if (isset($adminEnableRecovery) && $adminEnableRecovery === '1') { |
|
95 | - if ($this->recovery->enableAdminRecovery($recoveryPassword)) { |
|
96 | - return new DataResponse(['data' => ['message' => (string)$this->l->t('Recovery key successfully enabled')]]); |
|
97 | - } |
|
98 | - return new DataResponse(['data' => ['message' => (string)$this->l->t('Could not enable recovery key. Please check your recovery key password!')]], Http::STATUS_BAD_REQUEST); |
|
99 | - } elseif (isset($adminEnableRecovery) && $adminEnableRecovery === '0') { |
|
100 | - if ($this->recovery->disableAdminRecovery($recoveryPassword)) { |
|
101 | - return new DataResponse(['data' => ['message' => (string)$this->l->t('Recovery key successfully disabled')]]); |
|
102 | - } |
|
103 | - return new DataResponse(['data' => ['message' => (string)$this->l->t('Could not disable recovery key. Please check your recovery key password!')]], Http::STATUS_BAD_REQUEST); |
|
104 | - } |
|
105 | - // this response should never be sent but just in case. |
|
106 | - return new DataResponse(['data' => ['message' => (string)$this->l->t('Missing parameters')]], Http::STATUS_BAD_REQUEST); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @param string $newPassword |
|
111 | - * @param string $oldPassword |
|
112 | - * @param string $confirmPassword |
|
113 | - * @return DataResponse |
|
114 | - */ |
|
115 | - public function changeRecoveryPassword($newPassword, $oldPassword, $confirmPassword) { |
|
116 | - //check if both passwords are the same |
|
117 | - if (empty($oldPassword)) { |
|
118 | - $errorMessage = (string)$this->l->t('Please provide the old recovery password'); |
|
119 | - return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST); |
|
120 | - } |
|
121 | - |
|
122 | - if (empty($newPassword)) { |
|
123 | - $errorMessage = (string)$this->l->t('Please provide a new recovery password'); |
|
124 | - return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST); |
|
125 | - } |
|
126 | - |
|
127 | - if (empty($confirmPassword)) { |
|
128 | - $errorMessage = (string)$this->l->t('Please repeat the new recovery password'); |
|
129 | - return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST); |
|
130 | - } |
|
131 | - |
|
132 | - if ($newPassword !== $confirmPassword) { |
|
133 | - $errorMessage = (string)$this->l->t('Repeated recovery key password does not match the provided recovery key password'); |
|
134 | - return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST); |
|
135 | - } |
|
136 | - |
|
137 | - $result = $this->recovery->changeRecoveryKeyPassword($newPassword, |
|
138 | - $oldPassword); |
|
139 | - |
|
140 | - if ($result) { |
|
141 | - return new DataResponse( |
|
142 | - [ |
|
143 | - 'data' => [ |
|
144 | - 'message' => (string)$this->l->t('Password successfully changed.')] |
|
145 | - ] |
|
146 | - ); |
|
147 | - } |
|
148 | - return new DataResponse( |
|
149 | - [ |
|
150 | - 'data' => [ |
|
151 | - 'message' => (string)$this->l->t('Could not change the password. Maybe the old password was not correct.') |
|
152 | - ] |
|
153 | - ], Http::STATUS_BAD_REQUEST); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * @NoAdminRequired |
|
158 | - * |
|
159 | - * @param string $userEnableRecovery |
|
160 | - * @return DataResponse |
|
161 | - */ |
|
162 | - public function userSetRecovery($userEnableRecovery) { |
|
163 | - if ($userEnableRecovery === '0' || $userEnableRecovery === '1') { |
|
164 | - |
|
165 | - $result = $this->recovery->setRecoveryForUser($userEnableRecovery); |
|
166 | - |
|
167 | - if ($result) { |
|
168 | - if ($userEnableRecovery === '0') { |
|
169 | - return new DataResponse( |
|
170 | - [ |
|
171 | - 'data' => [ |
|
172 | - 'message' => (string)$this->l->t('Recovery Key disabled')] |
|
173 | - ] |
|
174 | - ); |
|
175 | - } |
|
176 | - return new DataResponse( |
|
177 | - [ |
|
178 | - 'data' => [ |
|
179 | - 'message' => (string)$this->l->t('Recovery Key enabled')] |
|
180 | - ] |
|
181 | - ); |
|
182 | - } |
|
183 | - |
|
184 | - } |
|
185 | - return new DataResponse( |
|
186 | - [ |
|
187 | - 'data' => [ |
|
188 | - 'message' => (string)$this->l->t('Could not enable the recovery key, please try again or contact your administrator') |
|
189 | - ] |
|
190 | - ], Http::STATUS_BAD_REQUEST); |
|
191 | - } |
|
37 | + /** |
|
38 | + * @var IConfig |
|
39 | + */ |
|
40 | + private $config; |
|
41 | + /** |
|
42 | + * @var IL10N |
|
43 | + */ |
|
44 | + private $l; |
|
45 | + /** |
|
46 | + * @var Recovery |
|
47 | + */ |
|
48 | + private $recovery; |
|
49 | + |
|
50 | + /** |
|
51 | + * @param string $AppName |
|
52 | + * @param IRequest $request |
|
53 | + * @param IConfig $config |
|
54 | + * @param IL10N $l10n |
|
55 | + * @param Recovery $recovery |
|
56 | + */ |
|
57 | + public function __construct($AppName, |
|
58 | + IRequest $request, |
|
59 | + IConfig $config, |
|
60 | + IL10N $l10n, |
|
61 | + Recovery $recovery) { |
|
62 | + parent::__construct($AppName, $request); |
|
63 | + $this->config = $config; |
|
64 | + $this->l = $l10n; |
|
65 | + $this->recovery = $recovery; |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @param string $recoveryPassword |
|
70 | + * @param string $confirmPassword |
|
71 | + * @param string $adminEnableRecovery |
|
72 | + * @return DataResponse |
|
73 | + */ |
|
74 | + public function adminRecovery($recoveryPassword, $confirmPassword, $adminEnableRecovery) { |
|
75 | + // Check if both passwords are the same |
|
76 | + if (empty($recoveryPassword)) { |
|
77 | + $errorMessage = (string)$this->l->t('Missing recovery key password'); |
|
78 | + return new DataResponse(['data' => ['message' => $errorMessage]], |
|
79 | + Http::STATUS_BAD_REQUEST); |
|
80 | + } |
|
81 | + |
|
82 | + if (empty($confirmPassword)) { |
|
83 | + $errorMessage = (string)$this->l->t('Please repeat the recovery key password'); |
|
84 | + return new DataResponse(['data' => ['message' => $errorMessage]], |
|
85 | + Http::STATUS_BAD_REQUEST); |
|
86 | + } |
|
87 | + |
|
88 | + if ($recoveryPassword !== $confirmPassword) { |
|
89 | + $errorMessage = (string)$this->l->t('Repeated recovery key password does not match the provided recovery key password'); |
|
90 | + return new DataResponse(['data' => ['message' => $errorMessage]], |
|
91 | + Http::STATUS_BAD_REQUEST); |
|
92 | + } |
|
93 | + |
|
94 | + if (isset($adminEnableRecovery) && $adminEnableRecovery === '1') { |
|
95 | + if ($this->recovery->enableAdminRecovery($recoveryPassword)) { |
|
96 | + return new DataResponse(['data' => ['message' => (string)$this->l->t('Recovery key successfully enabled')]]); |
|
97 | + } |
|
98 | + return new DataResponse(['data' => ['message' => (string)$this->l->t('Could not enable recovery key. Please check your recovery key password!')]], Http::STATUS_BAD_REQUEST); |
|
99 | + } elseif (isset($adminEnableRecovery) && $adminEnableRecovery === '0') { |
|
100 | + if ($this->recovery->disableAdminRecovery($recoveryPassword)) { |
|
101 | + return new DataResponse(['data' => ['message' => (string)$this->l->t('Recovery key successfully disabled')]]); |
|
102 | + } |
|
103 | + return new DataResponse(['data' => ['message' => (string)$this->l->t('Could not disable recovery key. Please check your recovery key password!')]], Http::STATUS_BAD_REQUEST); |
|
104 | + } |
|
105 | + // this response should never be sent but just in case. |
|
106 | + return new DataResponse(['data' => ['message' => (string)$this->l->t('Missing parameters')]], Http::STATUS_BAD_REQUEST); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @param string $newPassword |
|
111 | + * @param string $oldPassword |
|
112 | + * @param string $confirmPassword |
|
113 | + * @return DataResponse |
|
114 | + */ |
|
115 | + public function changeRecoveryPassword($newPassword, $oldPassword, $confirmPassword) { |
|
116 | + //check if both passwords are the same |
|
117 | + if (empty($oldPassword)) { |
|
118 | + $errorMessage = (string)$this->l->t('Please provide the old recovery password'); |
|
119 | + return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST); |
|
120 | + } |
|
121 | + |
|
122 | + if (empty($newPassword)) { |
|
123 | + $errorMessage = (string)$this->l->t('Please provide a new recovery password'); |
|
124 | + return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST); |
|
125 | + } |
|
126 | + |
|
127 | + if (empty($confirmPassword)) { |
|
128 | + $errorMessage = (string)$this->l->t('Please repeat the new recovery password'); |
|
129 | + return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST); |
|
130 | + } |
|
131 | + |
|
132 | + if ($newPassword !== $confirmPassword) { |
|
133 | + $errorMessage = (string)$this->l->t('Repeated recovery key password does not match the provided recovery key password'); |
|
134 | + return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST); |
|
135 | + } |
|
136 | + |
|
137 | + $result = $this->recovery->changeRecoveryKeyPassword($newPassword, |
|
138 | + $oldPassword); |
|
139 | + |
|
140 | + if ($result) { |
|
141 | + return new DataResponse( |
|
142 | + [ |
|
143 | + 'data' => [ |
|
144 | + 'message' => (string)$this->l->t('Password successfully changed.')] |
|
145 | + ] |
|
146 | + ); |
|
147 | + } |
|
148 | + return new DataResponse( |
|
149 | + [ |
|
150 | + 'data' => [ |
|
151 | + 'message' => (string)$this->l->t('Could not change the password. Maybe the old password was not correct.') |
|
152 | + ] |
|
153 | + ], Http::STATUS_BAD_REQUEST); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * @NoAdminRequired |
|
158 | + * |
|
159 | + * @param string $userEnableRecovery |
|
160 | + * @return DataResponse |
|
161 | + */ |
|
162 | + public function userSetRecovery($userEnableRecovery) { |
|
163 | + if ($userEnableRecovery === '0' || $userEnableRecovery === '1') { |
|
164 | + |
|
165 | + $result = $this->recovery->setRecoveryForUser($userEnableRecovery); |
|
166 | + |
|
167 | + if ($result) { |
|
168 | + if ($userEnableRecovery === '0') { |
|
169 | + return new DataResponse( |
|
170 | + [ |
|
171 | + 'data' => [ |
|
172 | + 'message' => (string)$this->l->t('Recovery Key disabled')] |
|
173 | + ] |
|
174 | + ); |
|
175 | + } |
|
176 | + return new DataResponse( |
|
177 | + [ |
|
178 | + 'data' => [ |
|
179 | + 'message' => (string)$this->l->t('Recovery Key enabled')] |
|
180 | + ] |
|
181 | + ); |
|
182 | + } |
|
183 | + |
|
184 | + } |
|
185 | + return new DataResponse( |
|
186 | + [ |
|
187 | + 'data' => [ |
|
188 | + 'message' => (string)$this->l->t('Could not enable the recovery key, please try again or contact your administrator') |
|
189 | + ] |
|
190 | + ], Http::STATUS_BAD_REQUEST); |
|
191 | + } |
|
192 | 192 | |
193 | 193 | } |
@@ -74,36 +74,36 @@ discard block |
||
74 | 74 | public function adminRecovery($recoveryPassword, $confirmPassword, $adminEnableRecovery) { |
75 | 75 | // Check if both passwords are the same |
76 | 76 | if (empty($recoveryPassword)) { |
77 | - $errorMessage = (string)$this->l->t('Missing recovery key password'); |
|
77 | + $errorMessage = (string) $this->l->t('Missing recovery key password'); |
|
78 | 78 | return new DataResponse(['data' => ['message' => $errorMessage]], |
79 | 79 | Http::STATUS_BAD_REQUEST); |
80 | 80 | } |
81 | 81 | |
82 | 82 | if (empty($confirmPassword)) { |
83 | - $errorMessage = (string)$this->l->t('Please repeat the recovery key password'); |
|
83 | + $errorMessage = (string) $this->l->t('Please repeat the recovery key password'); |
|
84 | 84 | return new DataResponse(['data' => ['message' => $errorMessage]], |
85 | 85 | Http::STATUS_BAD_REQUEST); |
86 | 86 | } |
87 | 87 | |
88 | 88 | if ($recoveryPassword !== $confirmPassword) { |
89 | - $errorMessage = (string)$this->l->t('Repeated recovery key password does not match the provided recovery key password'); |
|
89 | + $errorMessage = (string) $this->l->t('Repeated recovery key password does not match the provided recovery key password'); |
|
90 | 90 | return new DataResponse(['data' => ['message' => $errorMessage]], |
91 | 91 | Http::STATUS_BAD_REQUEST); |
92 | 92 | } |
93 | 93 | |
94 | 94 | if (isset($adminEnableRecovery) && $adminEnableRecovery === '1') { |
95 | 95 | if ($this->recovery->enableAdminRecovery($recoveryPassword)) { |
96 | - return new DataResponse(['data' => ['message' => (string)$this->l->t('Recovery key successfully enabled')]]); |
|
96 | + return new DataResponse(['data' => ['message' => (string) $this->l->t('Recovery key successfully enabled')]]); |
|
97 | 97 | } |
98 | - return new DataResponse(['data' => ['message' => (string)$this->l->t('Could not enable recovery key. Please check your recovery key password!')]], Http::STATUS_BAD_REQUEST); |
|
98 | + return new DataResponse(['data' => ['message' => (string) $this->l->t('Could not enable recovery key. Please check your recovery key password!')]], Http::STATUS_BAD_REQUEST); |
|
99 | 99 | } elseif (isset($adminEnableRecovery) && $adminEnableRecovery === '0') { |
100 | 100 | if ($this->recovery->disableAdminRecovery($recoveryPassword)) { |
101 | - return new DataResponse(['data' => ['message' => (string)$this->l->t('Recovery key successfully disabled')]]); |
|
101 | + return new DataResponse(['data' => ['message' => (string) $this->l->t('Recovery key successfully disabled')]]); |
|
102 | 102 | } |
103 | - return new DataResponse(['data' => ['message' => (string)$this->l->t('Could not disable recovery key. Please check your recovery key password!')]], Http::STATUS_BAD_REQUEST); |
|
103 | + return new DataResponse(['data' => ['message' => (string) $this->l->t('Could not disable recovery key. Please check your recovery key password!')]], Http::STATUS_BAD_REQUEST); |
|
104 | 104 | } |
105 | 105 | // this response should never be sent but just in case. |
106 | - return new DataResponse(['data' => ['message' => (string)$this->l->t('Missing parameters')]], Http::STATUS_BAD_REQUEST); |
|
106 | + return new DataResponse(['data' => ['message' => (string) $this->l->t('Missing parameters')]], Http::STATUS_BAD_REQUEST); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -115,22 +115,22 @@ discard block |
||
115 | 115 | public function changeRecoveryPassword($newPassword, $oldPassword, $confirmPassword) { |
116 | 116 | //check if both passwords are the same |
117 | 117 | if (empty($oldPassword)) { |
118 | - $errorMessage = (string)$this->l->t('Please provide the old recovery password'); |
|
118 | + $errorMessage = (string) $this->l->t('Please provide the old recovery password'); |
|
119 | 119 | return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST); |
120 | 120 | } |
121 | 121 | |
122 | 122 | if (empty($newPassword)) { |
123 | - $errorMessage = (string)$this->l->t('Please provide a new recovery password'); |
|
123 | + $errorMessage = (string) $this->l->t('Please provide a new recovery password'); |
|
124 | 124 | return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST); |
125 | 125 | } |
126 | 126 | |
127 | 127 | if (empty($confirmPassword)) { |
128 | - $errorMessage = (string)$this->l->t('Please repeat the new recovery password'); |
|
128 | + $errorMessage = (string) $this->l->t('Please repeat the new recovery password'); |
|
129 | 129 | return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST); |
130 | 130 | } |
131 | 131 | |
132 | 132 | if ($newPassword !== $confirmPassword) { |
133 | - $errorMessage = (string)$this->l->t('Repeated recovery key password does not match the provided recovery key password'); |
|
133 | + $errorMessage = (string) $this->l->t('Repeated recovery key password does not match the provided recovery key password'); |
|
134 | 134 | return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST); |
135 | 135 | } |
136 | 136 | |
@@ -141,14 +141,14 @@ discard block |
||
141 | 141 | return new DataResponse( |
142 | 142 | [ |
143 | 143 | 'data' => [ |
144 | - 'message' => (string)$this->l->t('Password successfully changed.')] |
|
144 | + 'message' => (string) $this->l->t('Password successfully changed.')] |
|
145 | 145 | ] |
146 | 146 | ); |
147 | 147 | } |
148 | 148 | return new DataResponse( |
149 | 149 | [ |
150 | 150 | 'data' => [ |
151 | - 'message' => (string)$this->l->t('Could not change the password. Maybe the old password was not correct.') |
|
151 | + 'message' => (string) $this->l->t('Could not change the password. Maybe the old password was not correct.') |
|
152 | 152 | ] |
153 | 153 | ], Http::STATUS_BAD_REQUEST); |
154 | 154 | } |
@@ -169,14 +169,14 @@ discard block |
||
169 | 169 | return new DataResponse( |
170 | 170 | [ |
171 | 171 | 'data' => [ |
172 | - 'message' => (string)$this->l->t('Recovery Key disabled')] |
|
172 | + 'message' => (string) $this->l->t('Recovery Key disabled')] |
|
173 | 173 | ] |
174 | 174 | ); |
175 | 175 | } |
176 | 176 | return new DataResponse( |
177 | 177 | [ |
178 | 178 | 'data' => [ |
179 | - 'message' => (string)$this->l->t('Recovery Key enabled')] |
|
179 | + 'message' => (string) $this->l->t('Recovery Key enabled')] |
|
180 | 180 | ] |
181 | 181 | ); |
182 | 182 | } |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | return new DataResponse( |
186 | 186 | [ |
187 | 187 | 'data' => [ |
188 | - 'message' => (string)$this->l->t('Could not enable the recovery key, please try again or contact your administrator') |
|
188 | + 'message' => (string) $this->l->t('Could not enable the recovery key, please try again or contact your administrator') |
|
189 | 189 | ] |
190 | 190 | ], Http::STATUS_BAD_REQUEST); |
191 | 191 | } |
@@ -34,73 +34,73 @@ |
||
34 | 34 | |
35 | 35 | class StatusController extends Controller { |
36 | 36 | |
37 | - /** @var IL10N */ |
|
38 | - private $l; |
|
37 | + /** @var IL10N */ |
|
38 | + private $l; |
|
39 | 39 | |
40 | - /** @var Session */ |
|
41 | - private $session; |
|
40 | + /** @var Session */ |
|
41 | + private $session; |
|
42 | 42 | |
43 | - /** @var IManager */ |
|
44 | - private $encryptionManager; |
|
43 | + /** @var IManager */ |
|
44 | + private $encryptionManager; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @param string $AppName |
|
48 | - * @param IRequest $request |
|
49 | - * @param IL10N $l10n |
|
50 | - * @param Session $session |
|
51 | - * @param IManager $encryptionManager |
|
52 | - */ |
|
53 | - public function __construct($AppName, |
|
54 | - IRequest $request, |
|
55 | - IL10N $l10n, |
|
56 | - Session $session, |
|
57 | - IManager $encryptionManager |
|
58 | - ) { |
|
59 | - parent::__construct($AppName, $request); |
|
60 | - $this->l = $l10n; |
|
61 | - $this->session = $session; |
|
62 | - $this->encryptionManager = $encryptionManager; |
|
63 | - } |
|
46 | + /** |
|
47 | + * @param string $AppName |
|
48 | + * @param IRequest $request |
|
49 | + * @param IL10N $l10n |
|
50 | + * @param Session $session |
|
51 | + * @param IManager $encryptionManager |
|
52 | + */ |
|
53 | + public function __construct($AppName, |
|
54 | + IRequest $request, |
|
55 | + IL10N $l10n, |
|
56 | + Session $session, |
|
57 | + IManager $encryptionManager |
|
58 | + ) { |
|
59 | + parent::__construct($AppName, $request); |
|
60 | + $this->l = $l10n; |
|
61 | + $this->session = $session; |
|
62 | + $this->encryptionManager = $encryptionManager; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @NoAdminRequired |
|
67 | - * @return DataResponse |
|
68 | - */ |
|
69 | - public function getStatus() { |
|
65 | + /** |
|
66 | + * @NoAdminRequired |
|
67 | + * @return DataResponse |
|
68 | + */ |
|
69 | + public function getStatus() { |
|
70 | 70 | |
71 | - $status = 'error'; |
|
72 | - $message = 'no valid init status'; |
|
73 | - switch($this->session->getStatus()) { |
|
74 | - case Session::INIT_EXECUTED: |
|
75 | - $status = 'interactionNeeded'; |
|
76 | - $message = (string)$this->l->t( |
|
77 | - 'Invalid private key for encryption app. Please update your private key password in your personal settings to recover access to your encrypted files.' |
|
78 | - ); |
|
79 | - break; |
|
80 | - case Session::NOT_INITIALIZED: |
|
81 | - $status = 'interactionNeeded'; |
|
82 | - if ($this->encryptionManager->isEnabled()) { |
|
83 | - $message = (string)$this->l->t( |
|
84 | - 'Encryption App is enabled, but your keys are not initialized. Please log-out and log-in again.' |
|
85 | - ); |
|
86 | - } else { |
|
87 | - $message = (string)$this->l->t( |
|
88 | - 'Please enable server side encryption in the admin settings in order to use the encryption module.' |
|
89 | - ); |
|
90 | - } |
|
91 | - break; |
|
92 | - case Session::INIT_SUCCESSFUL: |
|
93 | - $status = 'success'; |
|
94 | - $message = (string)$this->l->t('Encryption app is enabled and ready'); |
|
95 | - } |
|
71 | + $status = 'error'; |
|
72 | + $message = 'no valid init status'; |
|
73 | + switch($this->session->getStatus()) { |
|
74 | + case Session::INIT_EXECUTED: |
|
75 | + $status = 'interactionNeeded'; |
|
76 | + $message = (string)$this->l->t( |
|
77 | + 'Invalid private key for encryption app. Please update your private key password in your personal settings to recover access to your encrypted files.' |
|
78 | + ); |
|
79 | + break; |
|
80 | + case Session::NOT_INITIALIZED: |
|
81 | + $status = 'interactionNeeded'; |
|
82 | + if ($this->encryptionManager->isEnabled()) { |
|
83 | + $message = (string)$this->l->t( |
|
84 | + 'Encryption App is enabled, but your keys are not initialized. Please log-out and log-in again.' |
|
85 | + ); |
|
86 | + } else { |
|
87 | + $message = (string)$this->l->t( |
|
88 | + 'Please enable server side encryption in the admin settings in order to use the encryption module.' |
|
89 | + ); |
|
90 | + } |
|
91 | + break; |
|
92 | + case Session::INIT_SUCCESSFUL: |
|
93 | + $status = 'success'; |
|
94 | + $message = (string)$this->l->t('Encryption app is enabled and ready'); |
|
95 | + } |
|
96 | 96 | |
97 | - return new DataResponse( |
|
98 | - [ |
|
99 | - 'status' => $status, |
|
100 | - 'data' => [ |
|
101 | - 'message' => $message] |
|
102 | - ] |
|
103 | - ); |
|
104 | - } |
|
97 | + return new DataResponse( |
|
98 | + [ |
|
99 | + 'status' => $status, |
|
100 | + 'data' => [ |
|
101 | + 'message' => $message] |
|
102 | + ] |
|
103 | + ); |
|
104 | + } |
|
105 | 105 | |
106 | 106 | } |
@@ -70,28 +70,28 @@ |
||
70 | 70 | |
71 | 71 | $status = 'error'; |
72 | 72 | $message = 'no valid init status'; |
73 | - switch($this->session->getStatus()) { |
|
73 | + switch ($this->session->getStatus()) { |
|
74 | 74 | case Session::INIT_EXECUTED: |
75 | 75 | $status = 'interactionNeeded'; |
76 | - $message = (string)$this->l->t( |
|
76 | + $message = (string) $this->l->t( |
|
77 | 77 | 'Invalid private key for encryption app. Please update your private key password in your personal settings to recover access to your encrypted files.' |
78 | 78 | ); |
79 | 79 | break; |
80 | 80 | case Session::NOT_INITIALIZED: |
81 | 81 | $status = 'interactionNeeded'; |
82 | 82 | if ($this->encryptionManager->isEnabled()) { |
83 | - $message = (string)$this->l->t( |
|
83 | + $message = (string) $this->l->t( |
|
84 | 84 | 'Encryption App is enabled, but your keys are not initialized. Please log-out and log-in again.' |
85 | 85 | ); |
86 | 86 | } else { |
87 | - $message = (string)$this->l->t( |
|
87 | + $message = (string) $this->l->t( |
|
88 | 88 | 'Please enable server side encryption in the admin settings in order to use the encryption module.' |
89 | 89 | ); |
90 | 90 | } |
91 | 91 | break; |
92 | 92 | case Session::INIT_SUCCESSFUL: |
93 | 93 | $status = 'success'; |
94 | - $message = (string)$this->l->t('Encryption app is enabled and ready'); |
|
94 | + $message = (string) $this->l->t('Encryption app is enabled and ready'); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | return new DataResponse( |
@@ -29,93 +29,93 @@ |
||
29 | 29 | use OCP\Notification\IManager; |
30 | 30 | |
31 | 31 | class Listener { |
32 | - /** @var IManager */ |
|
33 | - protected $notificationManager; |
|
32 | + /** @var IManager */ |
|
33 | + protected $notificationManager; |
|
34 | 34 | |
35 | - /** @var IUserManager */ |
|
36 | - protected $userManager; |
|
35 | + /** @var IUserManager */ |
|
36 | + protected $userManager; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Listener constructor. |
|
40 | - * |
|
41 | - * @param IManager $notificationManager |
|
42 | - * @param IUserManager $userManager |
|
43 | - */ |
|
44 | - public function __construct( |
|
45 | - IManager $notificationManager, |
|
46 | - IUserManager $userManager |
|
47 | - ) { |
|
38 | + /** |
|
39 | + * Listener constructor. |
|
40 | + * |
|
41 | + * @param IManager $notificationManager |
|
42 | + * @param IUserManager $userManager |
|
43 | + */ |
|
44 | + public function __construct( |
|
45 | + IManager $notificationManager, |
|
46 | + IUserManager $userManager |
|
47 | + ) { |
|
48 | 48 | |
49 | - $this->notificationManager = $notificationManager; |
|
50 | - $this->userManager = $userManager; |
|
51 | - } |
|
49 | + $this->notificationManager = $notificationManager; |
|
50 | + $this->userManager = $userManager; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param CommentsEvent $event |
|
55 | - */ |
|
56 | - public function evaluate(CommentsEvent $event) { |
|
57 | - $comment = $event->getComment(); |
|
53 | + /** |
|
54 | + * @param CommentsEvent $event |
|
55 | + */ |
|
56 | + public function evaluate(CommentsEvent $event) { |
|
57 | + $comment = $event->getComment(); |
|
58 | 58 | |
59 | - $mentions = $this->extractMentions($comment->getMentions()); |
|
60 | - if(empty($mentions)) { |
|
61 | - // no one to notify |
|
62 | - return; |
|
63 | - } |
|
59 | + $mentions = $this->extractMentions($comment->getMentions()); |
|
60 | + if(empty($mentions)) { |
|
61 | + // no one to notify |
|
62 | + return; |
|
63 | + } |
|
64 | 64 | |
65 | - $notification = $this->instantiateNotification($comment); |
|
65 | + $notification = $this->instantiateNotification($comment); |
|
66 | 66 | |
67 | - foreach($mentions as $uid) { |
|
68 | - if(($comment->getActorType() === 'users' && $uid === $comment->getActorId()) |
|
69 | - || !$this->userManager->userExists($uid) |
|
70 | - ) { |
|
71 | - // do not notify unknown users or yourself |
|
72 | - continue; |
|
73 | - } |
|
67 | + foreach($mentions as $uid) { |
|
68 | + if(($comment->getActorType() === 'users' && $uid === $comment->getActorId()) |
|
69 | + || !$this->userManager->userExists($uid) |
|
70 | + ) { |
|
71 | + // do not notify unknown users or yourself |
|
72 | + continue; |
|
73 | + } |
|
74 | 74 | |
75 | - $notification->setUser($uid); |
|
76 | - if($event->getEvent() === CommentsEvent::EVENT_DELETE |
|
77 | - || $event->getEvent() === CommentsEvent::EVENT_PRE_UPDATE) |
|
78 | - { |
|
79 | - $this->notificationManager->markProcessed($notification); |
|
80 | - } else { |
|
81 | - $this->notificationManager->notify($notification); |
|
82 | - } |
|
83 | - } |
|
84 | - } |
|
75 | + $notification->setUser($uid); |
|
76 | + if($event->getEvent() === CommentsEvent::EVENT_DELETE |
|
77 | + || $event->getEvent() === CommentsEvent::EVENT_PRE_UPDATE) |
|
78 | + { |
|
79 | + $this->notificationManager->markProcessed($notification); |
|
80 | + } else { |
|
81 | + $this->notificationManager->notify($notification); |
|
82 | + } |
|
83 | + } |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * creates a notification instance and fills it with comment data |
|
88 | - * |
|
89 | - * @param IComment $comment |
|
90 | - * @return \OCP\Notification\INotification |
|
91 | - */ |
|
92 | - public function instantiateNotification(IComment $comment) { |
|
93 | - $notification = $this->notificationManager->createNotification(); |
|
94 | - $notification |
|
95 | - ->setApp('comments') |
|
96 | - ->setObject('comment', $comment->getId()) |
|
97 | - ->setSubject('mention', [ $comment->getObjectType(), $comment->getObjectId() ]) |
|
98 | - ->setDateTime($comment->getCreationDateTime()); |
|
86 | + /** |
|
87 | + * creates a notification instance and fills it with comment data |
|
88 | + * |
|
89 | + * @param IComment $comment |
|
90 | + * @return \OCP\Notification\INotification |
|
91 | + */ |
|
92 | + public function instantiateNotification(IComment $comment) { |
|
93 | + $notification = $this->notificationManager->createNotification(); |
|
94 | + $notification |
|
95 | + ->setApp('comments') |
|
96 | + ->setObject('comment', $comment->getId()) |
|
97 | + ->setSubject('mention', [ $comment->getObjectType(), $comment->getObjectId() ]) |
|
98 | + ->setDateTime($comment->getCreationDateTime()); |
|
99 | 99 | |
100 | - return $notification; |
|
101 | - } |
|
100 | + return $notification; |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * flattens the mention array returned from comments to a list of user ids. |
|
105 | - * |
|
106 | - * @param array $mentions |
|
107 | - * @return string[] containing the mentions, e.g. ['alice', 'bob'] |
|
108 | - */ |
|
109 | - public function extractMentions(array $mentions) { |
|
110 | - if(empty($mentions)) { |
|
111 | - return []; |
|
112 | - } |
|
113 | - $uids = []; |
|
114 | - foreach($mentions as $mention) { |
|
115 | - if($mention['type'] === 'user') { |
|
116 | - $uids[] = $mention['id']; |
|
117 | - } |
|
118 | - } |
|
119 | - return $uids; |
|
120 | - } |
|
103 | + /** |
|
104 | + * flattens the mention array returned from comments to a list of user ids. |
|
105 | + * |
|
106 | + * @param array $mentions |
|
107 | + * @return string[] containing the mentions, e.g. ['alice', 'bob'] |
|
108 | + */ |
|
109 | + public function extractMentions(array $mentions) { |
|
110 | + if(empty($mentions)) { |
|
111 | + return []; |
|
112 | + } |
|
113 | + $uids = []; |
|
114 | + foreach($mentions as $mention) { |
|
115 | + if($mention['type'] === 'user') { |
|
116 | + $uids[] = $mention['id']; |
|
117 | + } |
|
118 | + } |
|
119 | + return $uids; |
|
120 | + } |
|
121 | 121 | } |
@@ -57,15 +57,15 @@ discard block |
||
57 | 57 | $comment = $event->getComment(); |
58 | 58 | |
59 | 59 | $mentions = $this->extractMentions($comment->getMentions()); |
60 | - if(empty($mentions)) { |
|
60 | + if (empty($mentions)) { |
|
61 | 61 | // no one to notify |
62 | 62 | return; |
63 | 63 | } |
64 | 64 | |
65 | 65 | $notification = $this->instantiateNotification($comment); |
66 | 66 | |
67 | - foreach($mentions as $uid) { |
|
68 | - if(($comment->getActorType() === 'users' && $uid === $comment->getActorId()) |
|
67 | + foreach ($mentions as $uid) { |
|
68 | + if (($comment->getActorType() === 'users' && $uid === $comment->getActorId()) |
|
69 | 69 | || !$this->userManager->userExists($uid) |
70 | 70 | ) { |
71 | 71 | // do not notify unknown users or yourself |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | } |
74 | 74 | |
75 | 75 | $notification->setUser($uid); |
76 | - if($event->getEvent() === CommentsEvent::EVENT_DELETE |
|
76 | + if ($event->getEvent() === CommentsEvent::EVENT_DELETE |
|
77 | 77 | || $event->getEvent() === CommentsEvent::EVENT_PRE_UPDATE) |
78 | 78 | { |
79 | 79 | $this->notificationManager->markProcessed($notification); |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | $notification |
95 | 95 | ->setApp('comments') |
96 | 96 | ->setObject('comment', $comment->getId()) |
97 | - ->setSubject('mention', [ $comment->getObjectType(), $comment->getObjectId() ]) |
|
97 | + ->setSubject('mention', [$comment->getObjectType(), $comment->getObjectId()]) |
|
98 | 98 | ->setDateTime($comment->getCreationDateTime()); |
99 | 99 | |
100 | 100 | return $notification; |
@@ -107,12 +107,12 @@ discard block |
||
107 | 107 | * @return string[] containing the mentions, e.g. ['alice', 'bob'] |
108 | 108 | */ |
109 | 109 | public function extractMentions(array $mentions) { |
110 | - if(empty($mentions)) { |
|
110 | + if (empty($mentions)) { |
|
111 | 111 | return []; |
112 | 112 | } |
113 | 113 | $uids = []; |
114 | - foreach($mentions as $mention) { |
|
115 | - if($mention['type'] === 'user') { |
|
114 | + foreach ($mentions as $mention) { |
|
115 | + if ($mention['type'] === 'user') { |
|
116 | 116 | $uids[] = $mention['id']; |
117 | 117 | } |
118 | 118 | } |
@@ -34,56 +34,56 @@ |
||
34 | 34 | * @package OCA\Comments |
35 | 35 | */ |
36 | 36 | class EventHandler implements ICommentsEventHandler { |
37 | - /** @var ActivityListener */ |
|
38 | - private $activityListener; |
|
37 | + /** @var ActivityListener */ |
|
38 | + private $activityListener; |
|
39 | 39 | |
40 | - /** @var NotificationListener */ |
|
41 | - private $notificationListener; |
|
40 | + /** @var NotificationListener */ |
|
41 | + private $notificationListener; |
|
42 | 42 | |
43 | - public function __construct(ActivityListener $activityListener, NotificationListener $notificationListener) { |
|
44 | - $this->activityListener = $activityListener; |
|
45 | - $this->notificationListener = $notificationListener; |
|
46 | - } |
|
43 | + public function __construct(ActivityListener $activityListener, NotificationListener $notificationListener) { |
|
44 | + $this->activityListener = $activityListener; |
|
45 | + $this->notificationListener = $notificationListener; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param CommentsEvent $event |
|
50 | - */ |
|
51 | - public function handle(CommentsEvent $event) { |
|
52 | - if($event->getComment()->getObjectType() !== 'files') { |
|
53 | - // this is a 'files'-specific Handler |
|
54 | - return; |
|
55 | - } |
|
48 | + /** |
|
49 | + * @param CommentsEvent $event |
|
50 | + */ |
|
51 | + public function handle(CommentsEvent $event) { |
|
52 | + if($event->getComment()->getObjectType() !== 'files') { |
|
53 | + // this is a 'files'-specific Handler |
|
54 | + return; |
|
55 | + } |
|
56 | 56 | |
57 | - $eventType = $event->getEvent(); |
|
58 | - if($eventType === CommentsEvent::EVENT_ADD |
|
59 | - ) { |
|
60 | - $this->notificationHandler($event); |
|
61 | - $this->activityHandler($event); |
|
62 | - return; |
|
63 | - } |
|
57 | + $eventType = $event->getEvent(); |
|
58 | + if($eventType === CommentsEvent::EVENT_ADD |
|
59 | + ) { |
|
60 | + $this->notificationHandler($event); |
|
61 | + $this->activityHandler($event); |
|
62 | + return; |
|
63 | + } |
|
64 | 64 | |
65 | - $applicableEvents = [ |
|
66 | - CommentsEvent::EVENT_PRE_UPDATE, |
|
67 | - CommentsEvent::EVENT_UPDATE, |
|
68 | - CommentsEvent::EVENT_DELETE, |
|
69 | - ]; |
|
70 | - if(in_array($eventType, $applicableEvents)) { |
|
71 | - $this->notificationHandler($event); |
|
72 | - return; |
|
73 | - } |
|
74 | - } |
|
65 | + $applicableEvents = [ |
|
66 | + CommentsEvent::EVENT_PRE_UPDATE, |
|
67 | + CommentsEvent::EVENT_UPDATE, |
|
68 | + CommentsEvent::EVENT_DELETE, |
|
69 | + ]; |
|
70 | + if(in_array($eventType, $applicableEvents)) { |
|
71 | + $this->notificationHandler($event); |
|
72 | + return; |
|
73 | + } |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * @param CommentsEvent $event |
|
78 | - */ |
|
79 | - private function activityHandler(CommentsEvent $event) { |
|
80 | - $this->activityListener->commentEvent($event); |
|
81 | - } |
|
76 | + /** |
|
77 | + * @param CommentsEvent $event |
|
78 | + */ |
|
79 | + private function activityHandler(CommentsEvent $event) { |
|
80 | + $this->activityListener->commentEvent($event); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @param CommentsEvent $event |
|
85 | - */ |
|
86 | - private function notificationHandler(CommentsEvent $event) { |
|
87 | - $this->notificationListener->evaluate($event); |
|
88 | - } |
|
83 | + /** |
|
84 | + * @param CommentsEvent $event |
|
85 | + */ |
|
86 | + private function notificationHandler(CommentsEvent $event) { |
|
87 | + $this->notificationListener->evaluate($event); |
|
88 | + } |
|
89 | 89 | } |
@@ -49,13 +49,13 @@ discard block |
||
49 | 49 | * @param CommentsEvent $event |
50 | 50 | */ |
51 | 51 | public function handle(CommentsEvent $event) { |
52 | - if($event->getComment()->getObjectType() !== 'files') { |
|
52 | + if ($event->getComment()->getObjectType() !== 'files') { |
|
53 | 53 | // this is a 'files'-specific Handler |
54 | 54 | return; |
55 | 55 | } |
56 | 56 | |
57 | 57 | $eventType = $event->getEvent(); |
58 | - if($eventType === CommentsEvent::EVENT_ADD |
|
58 | + if ($eventType === CommentsEvent::EVENT_ADD |
|
59 | 59 | ) { |
60 | 60 | $this->notificationHandler($event); |
61 | 61 | $this->activityHandler($event); |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | CommentsEvent::EVENT_UPDATE, |
68 | 68 | CommentsEvent::EVENT_DELETE, |
69 | 69 | ]; |
70 | - if(in_array($eventType, $applicableEvents)) { |
|
70 | + if (in_array($eventType, $applicableEvents)) { |
|
71 | 71 | $this->notificationHandler($event); |
72 | 72 | return; |
73 | 73 | } |
@@ -34,14 +34,14 @@ |
||
34 | 34 | use OCP\Util; |
35 | 35 | |
36 | 36 | class LoadAdditionalScripts implements IEventListener { |
37 | - public function handle(Event $event): void { |
|
38 | - if (!($event instanceof LoadAdditionalScriptsEvent)) { |
|
39 | - return; |
|
40 | - } |
|
37 | + public function handle(Event $event): void { |
|
38 | + if (!($event instanceof LoadAdditionalScriptsEvent)) { |
|
39 | + return; |
|
40 | + } |
|
41 | 41 | |
42 | - // TODO: make sure to only include the sidebar script when |
|
43 | - // we properly split it between files list and sidebar |
|
44 | - Util::addScript(Application::APP_ID, 'comments'); |
|
45 | - } |
|
42 | + // TODO: make sure to only include the sidebar script when |
|
43 | + // we properly split it between files list and sidebar |
|
44 | + Util::addScript(Application::APP_ID, 'comments'); |
|
45 | + } |
|
46 | 46 | |
47 | 47 | } |
@@ -33,14 +33,14 @@ |
||
33 | 33 | use OCP\Util; |
34 | 34 | |
35 | 35 | class LoadSidebarScripts implements IEventListener { |
36 | - public function handle(Event $event): void { |
|
37 | - if (!($event instanceof LoadSidebar)) { |
|
38 | - return; |
|
39 | - } |
|
36 | + public function handle(Event $event): void { |
|
37 | + if (!($event instanceof LoadSidebar)) { |
|
38 | + return; |
|
39 | + } |
|
40 | 40 | |
41 | - // TODO: make sure to only include the sidebar script when |
|
42 | - // we properly split it between files list and sidebar |
|
43 | - Util::addScript(Application::APP_ID, 'comments'); |
|
44 | - } |
|
41 | + // TODO: make sure to only include the sidebar script when |
|
42 | + // we properly split it between files list and sidebar |
|
43 | + Util::addScript(Application::APP_ID, 'comments'); |
|
44 | + } |
|
45 | 45 | |
46 | 46 | } |