Admin.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 Julius Härtl <jus@bitgrid.net>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\Encryption\Settings;
  26. use OC\Files\View;
  27. use OCA\Encryption\Crypto\Crypt;
  28. use OCA\Encryption\Session;
  29. use OCA\Encryption\Util;
  30. use OCP\AppFramework\Http\TemplateResponse;
  31. use OCP\IConfig;
  32. use OCP\IL10N;
  33. use OCP\ILogger;
  34. use OCP\ISession;
  35. use OCP\IUserManager;
  36. use OCP\IUserSession;
  37. use OCP\Settings\ISettings;
  38. class Admin implements ISettings {
  39. /** @var IL10N */
  40. private $l;
  41. /** @var ILogger */
  42. private $logger;
  43. /** @var IUserSession */
  44. private $userSession;
  45. /** @var IConfig */
  46. private $config;
  47. /** @var IUserManager */
  48. private $userManager;
  49. /** @var ISession */
  50. private $session;
  51. public function __construct(
  52. IL10N $l,
  53. ILogger $logger,
  54. IUserSession $userSession,
  55. IConfig $config,
  56. IUserManager $userManager,
  57. ISession $session
  58. ) {
  59. $this->l = $l;
  60. $this->logger = $logger;
  61. $this->userSession = $userSession;
  62. $this->config = $config;
  63. $this->userManager = $userManager;
  64. $this->session = $session;
  65. }
  66. /**
  67. * @return TemplateResponse
  68. */
  69. public function getForm() {
  70. $crypt = new Crypt(
  71. $this->logger,
  72. $this->userSession,
  73. $this->config,
  74. $this->l);
  75. $util = new Util(
  76. new View(),
  77. $crypt,
  78. $this->logger,
  79. $this->userSession,
  80. $this->config,
  81. $this->userManager);
  82. // Check if an adminRecovery account is enabled for recovering files after lost pwd
  83. $recoveryAdminEnabled = $this->config->getAppValue('encryption', 'recoveryAdminEnabled', '0');
  84. $session = new Session($this->session);
  85. $encryptHomeStorage = $util->shouldEncryptHomeStorage();
  86. $parameters = [
  87. 'recoveryEnabled' => $recoveryAdminEnabled,
  88. 'initStatus' => $session->getStatus(),
  89. 'encryptHomeStorage' => $encryptHomeStorage,
  90. 'masterKeyEnabled' => $util->isMasterKeyEnabled(),
  91. ];
  92. return new TemplateResponse('encryption', 'settings-admin', $parameters, '');
  93. }
  94. /**
  95. * @return string the section ID, e.g. 'sharing'
  96. */
  97. public function getSection() {
  98. return 'security';
  99. }
  100. /**
  101. * @return int whether the form should be rather on the top or bottom of
  102. * the admin section. The forms are arranged in ascending order of the
  103. * priority values. It is required to return a value between 0 and 100.
  104. *
  105. * E.g.: 70
  106. */
  107. public function getPriority() {
  108. return 11;
  109. }
  110. }