You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OCSController.php 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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\Bruteforce\Throttler;
  25. use OC\Security\IdentityProof\Manager;
  26. use OCP\AppFramework\Http\DataResponse;
  27. use OCP\IRequest;
  28. use OCP\IUserManager;
  29. use OCP\IUserSession;
  30. class OCSController extends \OCP\AppFramework\OCSController {
  31. /** @var CapabilitiesManager */
  32. private $capabilitiesManager;
  33. /** @var IUserSession */
  34. private $userSession;
  35. /** @var IUserManager */
  36. private $userManager;
  37. /** @var Manager */
  38. private $keyManager;
  39. /** @var Throttler */
  40. private $throttler;
  41. /**
  42. * OCSController constructor.
  43. *
  44. * @param string $appName
  45. * @param IRequest $request
  46. * @param CapabilitiesManager $capabilitiesManager
  47. * @param IUserSession $userSession
  48. * @param IUserManager $userManager
  49. * @param Throttler $throttler
  50. * @param Manager $keyManager
  51. */
  52. public function __construct($appName,
  53. IRequest $request,
  54. CapabilitiesManager $capabilitiesManager,
  55. IUserSession $userSession,
  56. IUserManager $userManager,
  57. Throttler $throttler,
  58. Manager $keyManager) {
  59. parent::__construct($appName, $request);
  60. $this->capabilitiesManager = $capabilitiesManager;
  61. $this->userSession = $userSession;
  62. $this->userManager = $userManager;
  63. $this->throttler = $throttler;
  64. $this->keyManager = $keyManager;
  65. }
  66. /**
  67. * @PublicPage
  68. *
  69. * @return DataResponse
  70. */
  71. public function getConfig() {
  72. $data = [
  73. 'version' => '1.7',
  74. 'website' => 'Nextcloud',
  75. 'host' => $this->request->getServerHost(),
  76. 'contact' => '',
  77. 'ssl' => 'false',
  78. ];
  79. return new DataResponse($data);
  80. }
  81. /**
  82. * @NoAdminRequired
  83. * @return DataResponse
  84. */
  85. public function getCapabilities() {
  86. $result = [];
  87. list($major, $minor, $micro) = \OCP\Util::getVersion();
  88. $result['version'] = array(
  89. 'major' => $major,
  90. 'minor' => $minor,
  91. 'micro' => $micro,
  92. 'string' => \OC_Util::getVersionString(),
  93. 'edition' => '',
  94. );
  95. $result['capabilities'] = $this->capabilitiesManager->getCapabilities();
  96. return new DataResponse($result);
  97. }
  98. /**
  99. * @NoAdminRequired
  100. * @return DataResponse
  101. */
  102. public function getCurrentUser() {
  103. $userObject = $this->userSession->getUser();
  104. $data = [
  105. 'id' => $userObject->getUID(),
  106. 'display-name' => $userObject->getDisplayName(),
  107. 'email' => $userObject->getEMailAddress(),
  108. ];
  109. return new DataResponse($data);
  110. }
  111. /**
  112. * @PublicPage
  113. *
  114. * @param string $login
  115. * @param string $password
  116. * @return DataResponse
  117. */
  118. public function personCheck($login = '', $password = '') {
  119. if ($login !== '' && $password !== '') {
  120. $this->throttler->sleepDelay($this->request->getRemoteAddress());
  121. if ($this->userManager->checkPassword($login, $password)) {
  122. return new DataResponse([
  123. 'person' => [
  124. 'personid' => $login
  125. ]
  126. ]);
  127. }
  128. $this->throttler->registerAttempt('login', $this->request->getRemoteAddress());
  129. return new DataResponse(null, 102);
  130. }
  131. return new DataResponse(null, 101);
  132. }
  133. /**
  134. * @PublicPage
  135. *
  136. * @param string $cloudId
  137. * @return DataResponse
  138. */
  139. public function getIdentityProof($cloudId) {
  140. $userObject = $this->userManager->get($cloudId);
  141. if($userObject !== null) {
  142. $key = $this->keyManager->getKey($userObject);
  143. $data = [
  144. 'public' => $key->getPublic(),
  145. ];
  146. return new DataResponse($data);
  147. }
  148. return new DataResponse('User not found', 404);
  149. }
  150. }