Encryption.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  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. namespace OC\Settings\Admin;
  24. use OCP\AppFramework\Http\TemplateResponse;
  25. use OCP\Encryption\IManager;
  26. use OCP\IUserManager;
  27. use OCP\Settings\ISettings;
  28. class Encryption implements ISettings {
  29. /** @var IManager */
  30. private $manager;
  31. /** @var IUserManager */
  32. private $userManager;
  33. /**
  34. * @param IManager $manager
  35. * @param IUserManager $userManager
  36. */
  37. public function __construct(IManager $manager, IUserManager $userManager) {
  38. $this->manager = $manager;
  39. $this->userManager = $userManager;
  40. }
  41. /**
  42. * @return TemplateResponse
  43. */
  44. public function getForm() {
  45. $encryptionModules = $this->manager->getEncryptionModules();
  46. $defaultEncryptionModuleId = $this->manager->getDefaultEncryptionModuleId();
  47. $encryptionModuleList = [];
  48. foreach ($encryptionModules as $module) {
  49. $encryptionModuleList[$module['id']]['displayName'] = $module['displayName'];
  50. $encryptionModuleList[$module['id']]['default'] = false;
  51. if ($module['id'] === $defaultEncryptionModuleId) {
  52. $encryptionModuleList[$module['id']]['default'] = true;
  53. }
  54. }
  55. $parameters = [
  56. // Encryption API
  57. 'encryptionEnabled' => $this->manager->isEnabled(),
  58. 'encryptionReady' => $this->manager->isReady(),
  59. 'externalBackendsEnabled' => count($this->userManager->getBackends()) > 1,
  60. // Modules
  61. 'encryptionModules' => $encryptionModuleList,
  62. ];
  63. return new TemplateResponse('settings', 'admin/encryption', $parameters, '');
  64. }
  65. /**
  66. * @return string the section ID, e.g. 'sharing'
  67. */
  68. public function getSection() {
  69. return 'encryption';
  70. }
  71. /**
  72. * @return int whether the form should be rather on the top or bottom of
  73. * the admin section. The forms are arranged in ascending order of the
  74. * priority values. It is required to return a value between 0 and 100.
  75. *
  76. * E.g.: 70
  77. */
  78. public function getPriority() {
  79. return 0;
  80. }
  81. }