2016-08-08 17:31:26 -04:00
|
|
|
<?php
|
2025-06-30 09:04:05 -04:00
|
|
|
|
2016-08-08 17:31:26 -04:00
|
|
|
/**
|
2024-06-03 04:23:34 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2016-08-08 17:31:26 -04:00
|
|
|
*/
|
2020-01-31 10:55:17 -05:00
|
|
|
namespace OCA\Settings\Settings\Admin;
|
2016-08-08 17:31:26 -04:00
|
|
|
|
2019-01-10 10:04:13 -05:00
|
|
|
use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor;
|
2016-08-10 09:21:25 -04:00
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
2021-03-02 13:52:39 -05:00
|
|
|
use OCP\AppFramework\Services\IInitialState;
|
2016-12-28 10:58:02 -05:00
|
|
|
use OCP\Encryption\IManager;
|
2022-05-19 13:09:12 -04:00
|
|
|
use OCP\IURLGenerator;
|
2016-08-08 17:31:26 -04:00
|
|
|
use OCP\IUserManager;
|
2016-08-11 08:48:21 -04:00
|
|
|
use OCP\Settings\ISettings;
|
2016-08-08 17:31:26 -04:00
|
|
|
|
2018-10-08 04:22:27 -04:00
|
|
|
class Security implements ISettings {
|
2022-05-19 13:09:12 -04:00
|
|
|
private MandatoryTwoFactor $mandatoryTwoFactor;
|
2019-01-10 10:04:13 -05:00
|
|
|
|
2024-10-18 06:04:22 -04:00
|
|
|
public function __construct(
|
|
|
|
|
private IManager $manager,
|
|
|
|
|
private IUserManager $userManager,
|
2019-01-10 10:04:13 -05:00
|
|
|
MandatoryTwoFactor $mandatoryTwoFactor,
|
2024-10-18 06:04:22 -04:00
|
|
|
private IInitialState $initialState,
|
|
|
|
|
private IURLGenerator $urlGenerator,
|
|
|
|
|
) {
|
2019-01-10 10:04:13 -05:00
|
|
|
$this->mandatoryTwoFactor = $mandatoryTwoFactor;
|
2016-08-08 17:31:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-08-10 09:21:25 -04:00
|
|
|
* @return TemplateResponse
|
2016-08-08 17:31:26 -04:00
|
|
|
*/
|
2021-03-02 13:52:39 -05:00
|
|
|
public function getForm(): TemplateResponse {
|
2016-08-16 12:11:59 -04:00
|
|
|
$encryptionModules = $this->manager->getEncryptionModules();
|
|
|
|
|
$defaultEncryptionModuleId = $this->manager->getDefaultEncryptionModuleId();
|
|
|
|
|
$encryptionModuleList = [];
|
|
|
|
|
foreach ($encryptionModules as $module) {
|
|
|
|
|
$encryptionModuleList[$module['id']]['displayName'] = $module['displayName'];
|
|
|
|
|
$encryptionModuleList[$module['id']]['default'] = false;
|
|
|
|
|
if ($module['id'] === $defaultEncryptionModuleId) {
|
|
|
|
|
$encryptionModuleList[$module['id']]['default'] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-19 18:13:06 -04:00
|
|
|
$this->initialState->provideInitialState('mandatory2FAState', $this->mandatoryTwoFactor->getState());
|
|
|
|
|
$this->initialState->provideInitialState('two-factor-admin-doc', $this->urlGenerator->linkToDocs('admin-2fa'));
|
|
|
|
|
$this->initialState->provideInitialState('encryption-enabled', $this->manager->isEnabled());
|
|
|
|
|
$this->initialState->provideInitialState('encryption-ready', $this->manager->isReady());
|
|
|
|
|
$this->initialState->provideInitialState('external-backends-enabled', count($this->userManager->getBackends()) > 1);
|
|
|
|
|
$this->initialState->provideInitialState('encryption-modules', $encryptionModuleList);
|
|
|
|
|
$this->initialState->provideInitialState('encryption-admin-doc', $this->urlGenerator->linkToDocs('admin-encryption'));
|
2019-01-10 10:04:13 -05:00
|
|
|
|
2022-05-19 18:13:06 -04:00
|
|
|
return new TemplateResponse('settings', 'settings/admin/security', [], '');
|
2016-08-08 17:31:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return string the section ID, e.g. 'sharing'
|
|
|
|
|
*/
|
2021-03-02 13:52:39 -05:00
|
|
|
public function getSection(): string {
|
2018-08-01 03:40:21 -04:00
|
|
|
return 'security';
|
2016-08-08 17:31:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return int whether the form should be rather on the top or bottom of
|
|
|
|
|
* the admin section. The forms are arranged in ascending order of the
|
|
|
|
|
* priority values. It is required to return a value between 0 and 100.
|
|
|
|
|
*
|
|
|
|
|
* E.g.: 70
|
|
|
|
|
*/
|
2021-03-02 13:52:39 -05:00
|
|
|
public function getPriority(): int {
|
2018-08-01 03:40:21 -04:00
|
|
|
return 10;
|
2016-08-08 17:31:26 -04:00
|
|
|
}
|
|
|
|
|
}
|