OCSController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. * @PublicPage
  100. *
  101. * @param string $login
  102. * @param string $password
  103. * @return DataResponse
  104. */
  105. public function personCheck($login = '', $password = '') {
  106. if ($login !== '' && $password !== '') {
  107. $this->throttler->sleepDelay($this->request->getRemoteAddress(), 'login');
  108. if ($this->userManager->checkPassword($login, $password)) {
  109. return new DataResponse([
  110. 'person' => [
  111. 'personid' => $login
  112. ]
  113. ]);
  114. }
  115. $this->throttler->registerAttempt('login', $this->request->getRemoteAddress());
  116. return new DataResponse(null, 102);
  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. }