1
0

OCSController.php 3.8 KB

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