OCSController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. *
  4. * @author Roeland Jago Douma <roeland@famdouma.nl>
  5. *
  6. * @license GNU AGPL version 3 or any later version
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. namespace OC\Core\Controller;
  23. use OC\CapabilitiesManager;
  24. use OC\Security\IdentityProof\Manager;
  25. use OCP\AppFramework\Http\DataResponse;
  26. use OCP\IRequest;
  27. use OCP\IUserManager;
  28. use OCP\IUserSession;
  29. class OCSController extends \OCP\AppFramework\OCSController {
  30. /** @var CapabilitiesManager */
  31. private $capabilitiesManager;
  32. /** @var IUserSession */
  33. private $userSession;
  34. /** @var IUserManager */
  35. private $userManager;
  36. /** @var Manager */
  37. private $keyManager;
  38. /**
  39. * OCSController constructor.
  40. *
  41. * @param string $appName
  42. * @param IRequest $request
  43. * @param CapabilitiesManager $capabilitiesManager
  44. * @param IUserSession $userSession
  45. * @param IUserManager $userManager
  46. * @param Manager $keyManager
  47. */
  48. public function __construct($appName,
  49. IRequest $request,
  50. CapabilitiesManager $capabilitiesManager,
  51. IUserSession $userSession,
  52. IUserManager $userManager,
  53. Manager $keyManager) {
  54. parent::__construct($appName, $request);
  55. $this->capabilitiesManager = $capabilitiesManager;
  56. $this->userSession = $userSession;
  57. $this->userManager = $userManager;
  58. $this->keyManager = $keyManager;
  59. }
  60. /**
  61. * @PublicPage
  62. *
  63. * @return DataResponse
  64. */
  65. public function getConfig() {
  66. $data = [
  67. 'version' => '1.7',
  68. 'website' => 'Nextcloud',
  69. 'host' => $this->request->getServerHost(),
  70. 'contact' => '',
  71. 'ssl' => 'false',
  72. ];
  73. return new DataResponse($data);
  74. }
  75. /**
  76. * @PublicPage
  77. *
  78. * @return DataResponse
  79. */
  80. public function getCapabilities() {
  81. $result = [];
  82. list($major, $minor, $micro) = \OCP\Util::getVersion();
  83. $result['version'] = array(
  84. 'major' => $major,
  85. 'minor' => $minor,
  86. 'micro' => $micro,
  87. 'string' => \OC_Util::getVersionString(),
  88. 'edition' => '',
  89. );
  90. if($this->userSession->isLoggedIn()) {
  91. $result['capabilities'] = $this->capabilitiesManager->getCapabilities();
  92. } else {
  93. $result['capabilities'] = $this->capabilitiesManager->getCapabilities(true);
  94. }
  95. return new DataResponse($result);
  96. }
  97. /**
  98. * @PublicPage
  99. * @BruteForceProtection(action=login)
  100. *
  101. * @param string $login
  102. * @param string $password
  103. * @return DataResponse
  104. */
  105. public function personCheck($login = '', $password = '') {
  106. if ($login !== '' && $password !== '') {
  107. if ($this->userManager->checkPassword($login, $password)) {
  108. return new DataResponse([
  109. 'person' => [
  110. 'personid' => $login
  111. ]
  112. ]);
  113. }
  114. $response = new DataResponse(null, 102);
  115. $response->throttle();
  116. return $response;
  117. }
  118. return new DataResponse(null, 101);
  119. }
  120. /**
  121. * @PublicPage
  122. *
  123. * @param string $cloudId
  124. * @return DataResponse
  125. */
  126. public function getIdentityProof($cloudId) {
  127. $userObject = $this->userManager->get($cloudId);
  128. if($userObject !== null) {
  129. $key = $this->keyManager->getKey($userObject);
  130. $data = [
  131. 'public' => $key->getPublic(),
  132. ];
  133. return new DataResponse($data);
  134. }
  135. return new DataResponse('User not found', 404);
  136. }
  137. }