1
0

OCSController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. 'extendedSupport' => \OCP\Util::hasExtendedSupport()
  94. );
  95. if($this->userSession->isLoggedIn()) {
  96. $result['capabilities'] = $this->capabilitiesManager->getCapabilities();
  97. } else {
  98. $result['capabilities'] = $this->capabilitiesManager->getCapabilities(true);
  99. }
  100. return new DataResponse($result);
  101. }
  102. /**
  103. * @PublicPage
  104. * @BruteForceProtection(action=login)
  105. *
  106. * @param string $login
  107. * @param string $password
  108. * @return DataResponse
  109. */
  110. public function personCheck($login = '', $password = '') {
  111. if ($login !== '' && $password !== '') {
  112. if ($this->userManager->checkPassword($login, $password)) {
  113. return new DataResponse([
  114. 'person' => [
  115. 'personid' => $login
  116. ]
  117. ]);
  118. }
  119. $response = new DataResponse([], 102);
  120. $response->throttle();
  121. return $response;
  122. }
  123. return new DataResponse([], 101);
  124. }
  125. /**
  126. * @PublicPage
  127. *
  128. * @param string $cloudId
  129. * @return DataResponse
  130. */
  131. public function getIdentityProof($cloudId) {
  132. $userObject = $this->userManager->get($cloudId);
  133. if($userObject !== null) {
  134. $key = $this->keyManager->getKey($userObject);
  135. $data = [
  136. 'public' => $key->getPublic(),
  137. ];
  138. return new DataResponse($data);
  139. }
  140. return new DataResponse(['User not found'], 404);
  141. }
  142. }