OCSController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. private CapabilitiesManager $capabilitiesManager;
  37. private IUserSession $userSession;
  38. private IUserManager $userManager;
  39. private Manager $keyManager;
  40. public function __construct(string $appName,
  41. IRequest $request,
  42. CapabilitiesManager $capabilitiesManager,
  43. IUserSession $userSession,
  44. IUserManager $userManager,
  45. Manager $keyManager) {
  46. parent::__construct($appName, $request);
  47. $this->capabilitiesManager = $capabilitiesManager;
  48. $this->userSession = $userSession;
  49. $this->userManager = $userManager;
  50. $this->keyManager = $keyManager;
  51. }
  52. /**
  53. * @PublicPage
  54. */
  55. public function getConfig(): DataResponse {
  56. $data = [
  57. 'version' => '1.7',
  58. 'website' => 'Nextcloud',
  59. 'host' => $this->request->getServerHost(),
  60. 'contact' => '',
  61. 'ssl' => 'false',
  62. ];
  63. return new DataResponse($data);
  64. }
  65. /**
  66. * @PublicPage
  67. */
  68. public function getCapabilities(): DataResponse {
  69. $result = [];
  70. [$major, $minor, $micro] = \OCP\Util::getVersion();
  71. $result['version'] = [
  72. 'major' => $major,
  73. 'minor' => $minor,
  74. 'micro' => $micro,
  75. 'string' => \OC_Util::getVersionString(),
  76. 'edition' => '',
  77. 'extendedSupport' => \OCP\Util::hasExtendedSupport()
  78. ];
  79. if ($this->userSession->isLoggedIn()) {
  80. $result['capabilities'] = $this->capabilitiesManager->getCapabilities();
  81. } else {
  82. $result['capabilities'] = $this->capabilitiesManager->getCapabilities(true);
  83. }
  84. $response = new DataResponse($result);
  85. $response->setETag(md5(json_encode($result)));
  86. return $response;
  87. }
  88. /**
  89. * @PublicPage
  90. * @BruteForceProtection(action=login)
  91. */
  92. public function personCheck(string $login = '', string $password = ''): DataResponse {
  93. if ($login !== '' && $password !== '') {
  94. if ($this->userManager->checkPassword($login, $password)) {
  95. return new DataResponse([
  96. 'person' => [
  97. 'personid' => $login
  98. ]
  99. ]);
  100. }
  101. $response = new DataResponse([], 102);
  102. $response->throttle();
  103. return $response;
  104. }
  105. return new DataResponse([], 101);
  106. }
  107. /**
  108. * @PublicPage
  109. */
  110. public function getIdentityProof(string $cloudId): DataResponse {
  111. $userObject = $this->userManager->get($cloudId);
  112. if ($userObject !== null) {
  113. $key = $this->keyManager->getKey($userObject);
  114. $data = [
  115. 'public' => $key->getPublic(),
  116. ];
  117. return new DataResponse($data);
  118. }
  119. return new DataResponse(['User not found'], 404);
  120. }
  121. }