OCSController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Roeland Jago Douma <roeland@famdouma.nl>
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Julius Härtl <jus@bitgrid.net>
  9. * @author Lukas Reschke <lukas@statuscode.ch>
  10. * @author Roeland Jago Douma <roeland@famdouma.nl>
  11. *
  12. * @license GNU AGPL version 3 or any later version
  13. *
  14. * This program is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License as
  16. * published by the Free Software Foundation, either version 3 of the
  17. * License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  26. *
  27. */
  28. namespace OC\Core\Controller;
  29. use OC\CapabilitiesManager;
  30. use OC\Security\IdentityProof\Manager;
  31. use OCP\AppFramework\Http\DataResponse;
  32. use OCP\IRequest;
  33. use OCP\IUserManager;
  34. use OCP\IUserSession;
  35. class OCSController extends \OCP\AppFramework\OCSController {
  36. /** @var CapabilitiesManager */
  37. private $capabilitiesManager;
  38. /** @var IUserSession */
  39. private $userSession;
  40. /** @var IUserManager */
  41. private $userManager;
  42. /** @var Manager */
  43. private $keyManager;
  44. /**
  45. * OCSController constructor.
  46. *
  47. * @param string $appName
  48. * @param IRequest $request
  49. * @param CapabilitiesManager $capabilitiesManager
  50. * @param IUserSession $userSession
  51. * @param IUserManager $userManager
  52. * @param Manager $keyManager
  53. */
  54. public function __construct($appName,
  55. IRequest $request,
  56. CapabilitiesManager $capabilitiesManager,
  57. IUserSession $userSession,
  58. IUserManager $userManager,
  59. Manager $keyManager) {
  60. parent::__construct($appName, $request);
  61. $this->capabilitiesManager = $capabilitiesManager;
  62. $this->userSession = $userSession;
  63. $this->userManager = $userManager;
  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. * @PublicPage
  83. *
  84. * @return DataResponse
  85. */
  86. public function getCapabilities() {
  87. $result = [];
  88. [$major, $minor, $micro] = \OCP\Util::getVersion();
  89. $result['version'] = [
  90. 'major' => $major,
  91. 'minor' => $minor,
  92. 'micro' => $micro,
  93. 'string' => \OC_Util::getVersionString(),
  94. 'edition' => '',
  95. 'extendedSupport' => \OCP\Util::hasExtendedSupport()
  96. ];
  97. if ($this->userSession->isLoggedIn()) {
  98. $result['capabilities'] = $this->capabilitiesManager->getCapabilities();
  99. } else {
  100. $result['capabilities'] = $this->capabilitiesManager->getCapabilities(true);
  101. }
  102. $response = new DataResponse($result);
  103. $response->setETag(md5(json_encode($result)));
  104. return $response;
  105. }
  106. /**
  107. * @PublicPage
  108. * @BruteForceProtection(action=login)
  109. *
  110. * @param string $login
  111. * @param string $password
  112. * @return DataResponse
  113. */
  114. public function personCheck($login = '', $password = '') {
  115. if ($login !== '' && $password !== '') {
  116. if ($this->userManager->checkPassword($login, $password)) {
  117. return new DataResponse([
  118. 'person' => [
  119. 'personid' => $login
  120. ]
  121. ]);
  122. }
  123. $response = new DataResponse([], 102);
  124. $response->throttle();
  125. return $response;
  126. }
  127. return new DataResponse([], 101);
  128. }
  129. /**
  130. * @PublicPage
  131. *
  132. * @param string $cloudId
  133. * @return DataResponse
  134. */
  135. public function getIdentityProof($cloudId) {
  136. $userObject = $this->userManager->get($cloudId);
  137. if ($userObject !== null) {
  138. $key = $this->keyManager->getKey($userObject);
  139. $data = [
  140. 'public' => $key->getPublic(),
  141. ];
  142. return new DataResponse($data);
  143. }
  144. return new DataResponse(['User not found'], 404);
  145. }
  146. }