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.

127 lines
3.4 KiB

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