|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* @copyright 2020 Christoph Wurst <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* @author 2020 Christoph Wurst <[email protected]> |
|
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
|
|
|
|
|
28
|
|
|
use OC\Http\WellKnown\RequestManager; |
|
29
|
|
|
use OCP\AppFramework\Controller; |
|
30
|
|
|
use OCP\AppFramework\Http; |
|
31
|
|
|
use OCP\AppFramework\Http\JSONResponse; |
|
32
|
|
|
use OCP\AppFramework\Http\Response; |
|
33
|
|
|
use OCP\IRequest; |
|
34
|
|
|
|
|
35
|
|
|
class WellKnownController extends Controller { |
|
36
|
|
|
|
|
37
|
|
|
/** @var RequestManager */ |
|
38
|
|
|
private $requestManager; |
|
39
|
|
|
|
|
40
|
|
|
public function __construct(IRequest $request, |
|
41
|
|
|
RequestManager $wellKnownManager) { |
|
42
|
|
|
parent::__construct('core', $request); |
|
43
|
|
|
$this->requestManager = $wellKnownManager; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @PublicPage |
|
48
|
|
|
* @NoCSRFRequired |
|
49
|
|
|
* |
|
50
|
|
|
* @return Response |
|
51
|
|
|
*/ |
|
52
|
|
|
public function handle(string $service): Response { |
|
53
|
|
|
$response = $this->requestManager->process( |
|
54
|
|
|
$service, |
|
55
|
|
|
$this->request |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
|
if ($response === null) { |
|
59
|
|
|
$httpResponse = new JSONResponse(["message" => "$service not supported"], Http::STATUS_NOT_FOUND); |
|
60
|
|
|
} else { |
|
61
|
|
|
$httpResponse = $response->toHttpResponse(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
// We add a custom header so that setup checks can detect if their requests are answered by this controller |
|
65
|
|
|
return $httpResponse->addHeader('X-NEXTCLOUD-WELL-KNOWN', '1'); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|