OCSController.php 3.9 KB

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