2016-08-09 10:21:20 +02:00
|
|
|
<?php
|
2016-08-09 10:21:51 +02:00
|
|
|
/**
|
2021-06-04 21:52:51 +02:00
|
|
|
* @copyright Copyright (c) 2016 Roeland Jago Douma <roeland@famdouma.nl>
|
2017-11-06 15:56:42 +01:00
|
|
|
*
|
2020-03-31 10:49:10 +02:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2020-08-24 14:54:25 +02:00
|
|
|
* @author Daniel Kesselberg <mail@danielkesselberg.de>
|
2017-11-06 15:56:42 +01:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2016-08-09 10:21:51 +02:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2023-03-15 17:29:32 +01:00
|
|
|
* @author Kate Döen <kate.doeen@nextcloud.com>
|
2016-08-09 10:21:51 +02:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2021-06-04 21:52:51 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2016-08-09 10:21:51 +02:00
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2019-12-03 19:57:53 +01:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-08-09 10:21:51 +02:00
|
|
|
*
|
|
|
|
*/
|
2016-08-09 10:21:20 +02:00
|
|
|
namespace OC\Core\Controller;
|
|
|
|
|
|
|
|
use OC\CapabilitiesManager;
|
2016-11-17 17:35:14 +01:00
|
|
|
use OC\Security\IdentityProof\Manager;
|
2023-03-15 17:29:32 +01:00
|
|
|
use OCP\AppFramework\Http;
|
2024-01-18 10:38:37 +01:00
|
|
|
use OCP\AppFramework\Http\Attribute\OpenAPI;
|
2016-08-09 10:21:20 +02:00
|
|
|
use OCP\AppFramework\Http\DataResponse;
|
|
|
|
use OCP\IRequest;
|
2016-11-16 19:21:00 +01:00
|
|
|
use OCP\IUserManager;
|
2016-08-09 11:27:55 +02:00
|
|
|
use OCP\IUserSession;
|
2016-08-09 10:21:20 +02:00
|
|
|
|
|
|
|
class OCSController extends \OCP\AppFramework\OCSController {
|
2023-06-05 17:12:42 +02:00
|
|
|
public function __construct(
|
|
|
|
string $appName,
|
|
|
|
IRequest $request,
|
|
|
|
private CapabilitiesManager $capabilitiesManager,
|
|
|
|
private IUserSession $userSession,
|
|
|
|
private IUserManager $userManager,
|
|
|
|
private Manager $keyManager,
|
|
|
|
) {
|
2016-08-09 10:21:20 +02:00
|
|
|
parent::__construct($appName, $request);
|
|
|
|
}
|
|
|
|
|
2016-08-14 20:46:33 +02:00
|
|
|
/**
|
|
|
|
* @PublicPage
|
|
|
|
*/
|
2024-01-18 10:38:37 +01:00
|
|
|
#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
|
2022-04-12 17:55:01 +02:00
|
|
|
public function getConfig(): DataResponse {
|
2016-08-14 20:46:33 +02:00
|
|
|
$data = [
|
|
|
|
'version' => '1.7',
|
2016-08-17 15:34:10 +02:00
|
|
|
'website' => 'Nextcloud',
|
2016-08-14 20:46:33 +02:00
|
|
|
'host' => $this->request->getServerHost(),
|
|
|
|
'contact' => '',
|
|
|
|
'ssl' => 'false',
|
|
|
|
];
|
|
|
|
|
|
|
|
return new DataResponse($data);
|
|
|
|
}
|
|
|
|
|
2016-08-09 10:21:51 +02:00
|
|
|
/**
|
2017-06-30 11:08:04 +02:00
|
|
|
* @PublicPage
|
2023-03-15 17:29:32 +01:00
|
|
|
*
|
|
|
|
* Get the capabilities
|
|
|
|
*
|
|
|
|
* @return DataResponse<Http::STATUS_OK, array{version: array{major: int, minor: int, micro: int, string: string, edition: '', extendedSupport: bool}, capabilities: array<string, mixed>}, array{}>
|
2023-09-19 14:12:17 +02:00
|
|
|
*
|
|
|
|
* 200: Capabilities returned
|
2016-08-09 10:21:51 +02:00
|
|
|
*/
|
2022-04-12 17:55:01 +02:00
|
|
|
public function getCapabilities(): DataResponse {
|
2016-08-09 10:21:20 +02:00
|
|
|
$result = [];
|
2021-01-12 10:15:48 +01:00
|
|
|
[$major, $minor, $micro] = \OCP\Util::getVersion();
|
2020-03-26 09:30:18 +01:00
|
|
|
$result['version'] = [
|
2023-03-15 17:29:32 +01:00
|
|
|
'major' => (int)$major,
|
|
|
|
'minor' => (int)$minor,
|
|
|
|
'micro' => (int)$micro,
|
2016-08-09 10:21:20 +02:00
|
|
|
'string' => \OC_Util::getVersionString(),
|
2016-09-06 14:11:30 +02:00
|
|
|
'edition' => '',
|
2019-06-11 16:08:26 +02:00
|
|
|
'extendedSupport' => \OCP\Util::hasExtendedSupport()
|
2020-03-26 09:30:18 +01:00
|
|
|
];
|
2016-08-09 10:21:20 +02:00
|
|
|
|
2020-04-10 14:19:56 +02:00
|
|
|
if ($this->userSession->isLoggedIn()) {
|
2017-06-30 11:08:04 +02:00
|
|
|
$result['capabilities'] = $this->capabilitiesManager->getCapabilities();
|
|
|
|
} else {
|
|
|
|
$result['capabilities'] = $this->capabilitiesManager->getCapabilities(true);
|
|
|
|
}
|
2016-08-09 10:21:20 +02:00
|
|
|
|
2020-04-29 15:16:53 +02:00
|
|
|
$response = new DataResponse($result);
|
|
|
|
$response->setETag(md5(json_encode($result)));
|
|
|
|
return $response;
|
2016-08-09 10:21:20 +02:00
|
|
|
}
|
2016-08-09 11:27:55 +02:00
|
|
|
|
|
|
|
/**
|
2016-11-16 19:21:00 +01:00
|
|
|
* @PublicPage
|
2017-04-14 13:42:40 +02:00
|
|
|
* @BruteForceProtection(action=login)
|
2016-11-16 19:21:00 +01:00
|
|
|
*/
|
2024-01-18 10:38:37 +01:00
|
|
|
#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
|
2022-04-12 17:55:01 +02:00
|
|
|
public function personCheck(string $login = '', string $password = ''): DataResponse {
|
2016-11-16 19:21:00 +01:00
|
|
|
if ($login !== '' && $password !== '') {
|
|
|
|
if ($this->userManager->checkPassword($login, $password)) {
|
|
|
|
return new DataResponse([
|
|
|
|
'person' => [
|
|
|
|
'personid' => $login
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
}
|
2017-04-14 13:42:40 +02:00
|
|
|
|
2017-07-19 16:42:17 +02:00
|
|
|
$response = new DataResponse([], 102);
|
2017-04-14 13:42:40 +02:00
|
|
|
$response->throttle();
|
|
|
|
return $response;
|
2016-11-16 19:21:00 +01:00
|
|
|
}
|
2017-07-19 16:42:17 +02:00
|
|
|
return new DataResponse([], 101);
|
2016-11-16 19:21:00 +01:00
|
|
|
}
|
2016-11-17 17:35:14 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @PublicPage
|
|
|
|
*/
|
2024-01-18 10:38:37 +01:00
|
|
|
#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
|
2022-04-12 17:55:01 +02:00
|
|
|
public function getIdentityProof(string $cloudId): DataResponse {
|
2016-11-17 17:35:14 +01:00
|
|
|
$userObject = $this->userManager->get($cloudId);
|
|
|
|
|
2020-04-10 14:19:56 +02:00
|
|
|
if ($userObject !== null) {
|
2016-11-17 17:35:14 +01:00
|
|
|
$key = $this->keyManager->getKey($userObject);
|
|
|
|
$data = [
|
|
|
|
'public' => $key->getPublic(),
|
|
|
|
];
|
|
|
|
return new DataResponse($data);
|
|
|
|
}
|
|
|
|
|
2017-07-19 16:42:17 +02:00
|
|
|
return new DataResponse(['User not found'], 404);
|
2016-11-17 17:35:14 +01:00
|
|
|
}
|
2016-08-09 10:21:51 +02:00
|
|
|
}
|