1
0

OCSController.php 3.6 KB

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