1
0

Security.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Julius Härtl <jus@bitgrid.net>
  8. * @author Robin Appelman <robin@icewind.nl>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  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. namespace OCA\Settings\Settings\Admin;
  28. use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor;
  29. use OCP\AppFramework\Http\TemplateResponse;
  30. use OCP\AppFramework\Services\IInitialState;
  31. use OCP\Encryption\IManager;
  32. use OCP\IUserManager;
  33. use OCP\IURLGenerator;
  34. use OCP\Settings\ISettings;
  35. class Security implements ISettings {
  36. private IManager $manager;
  37. private IUserManager $userManager;
  38. private MandatoryTwoFactor $mandatoryTwoFactor;
  39. private IInitialState $initialState;
  40. private IURLGenerator $urlGenerator;
  41. public function __construct(IManager $manager,
  42. IUserManager $userManager,
  43. MandatoryTwoFactor $mandatoryTwoFactor,
  44. IInitialState $initialState,
  45. IURLGenerator $urlGenerator) {
  46. $this->manager = $manager;
  47. $this->userManager = $userManager;
  48. $this->mandatoryTwoFactor = $mandatoryTwoFactor;
  49. $this->initialState = $initialState;
  50. $this->urlGenerator = $urlGenerator;
  51. }
  52. /**
  53. * @return TemplateResponse
  54. */
  55. public function getForm(): TemplateResponse {
  56. $encryptionModules = $this->manager->getEncryptionModules();
  57. $defaultEncryptionModuleId = $this->manager->getDefaultEncryptionModuleId();
  58. $encryptionModuleList = [];
  59. foreach ($encryptionModules as $module) {
  60. $encryptionModuleList[$module['id']]['displayName'] = $module['displayName'];
  61. $encryptionModuleList[$module['id']]['default'] = false;
  62. if ($module['id'] === $defaultEncryptionModuleId) {
  63. $encryptionModuleList[$module['id']]['default'] = true;
  64. }
  65. }
  66. $this->initialState->provideInitialState('mandatory2FAState', $this->mandatoryTwoFactor->getState());
  67. $this->initialState->provideInitialState('two-factor-admin-doc', $this->urlGenerator->linkToDocs('admin-2fa'));
  68. $this->initialState->provideInitialState('encryption-enabled', $this->manager->isEnabled());
  69. $this->initialState->provideInitialState('encryption-ready', $this->manager->isReady());
  70. $this->initialState->provideInitialState('external-backends-enabled', count($this->userManager->getBackends()) > 1);
  71. $this->initialState->provideInitialState('encryption-modules', $encryptionModuleList);
  72. $this->initialState->provideInitialState('encryption-admin-doc', $this->urlGenerator->linkToDocs('admin-encryption'));
  73. return new TemplateResponse('settings', 'settings/admin/security', [], '');
  74. }
  75. /**
  76. * @return string the section ID, e.g. 'sharing'
  77. */
  78. public function getSection(): string {
  79. return 'security';
  80. }
  81. /**
  82. * @return int whether the form should be rather on the top or bottom of
  83. * the admin section. The forms are arranged in ascending order of the
  84. * priority values. It is required to return a value between 0 and 100.
  85. *
  86. * E.g.: 70
  87. */
  88. public function getPriority(): int {
  89. return 10;
  90. }
  91. }