-
-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathPageController.php
More file actions
159 lines (140 loc) Β· 5.1 KB
/
PageController.php
File metadata and controls
159 lines (140 loc) Β· 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
/**
* Nextcloud - maps
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @authorVinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
* @copyright Vinzenz Rosenkranz 2017
*/
namespace OCA\Maps\Controller;
use OCA\Files\Event\LoadSidebar;
use OCA\Maps\Service\MyMapsService;
use OCA\Viewer\Event\LoadViewer;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IURLGenerator;
class PageController extends Controller {
public function __construct(
string $appName,
IRequest $request,
private string $userId,
private IEventDispatcher $eventDispatcher,
private IConfig $config,
private IInitialState $initialState,
private IURLGenerator $urlGenerator,
) {
parent::__construct($appName, $request);
}
/**
* CAUTION: the @Stuff turns off security checks; for this page no admin is
* required and no CSRF check. If you don't know what CSRF is, read
* it up in the docs or you might create a security hole. This is
* basically the only required method to add this exemption, don't
* add it to any other method if you don't exactly know what it does
*
* @NoAdminRequired
* @NoCSRFRequired
* @return TemplateResponse
*/
public function index(): TemplateResponse {
$this->eventDispatcher->dispatch(LoadSidebar::class, new LoadSidebar());
$this->eventDispatcher->dispatch(LoadViewer::class, new LoadViewer());
$params = ['user' => $this->userId];
$this->initialState->provideInitialState('photos', $this->config->getAppValue('photos', 'enabled', 'no') === 'yes');
$response = new TemplateResponse('maps', 'main', $params);
$this->addCsp($response);
return $response;
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function indexMyMap(int $myMapId, MyMapsService $service): TemplateResponse|RedirectResponse {
$map = $service->getMyMap($myMapId, $this->userId);
if ($map !== null && $map['id'] !== $myMapId) {
// Instead of the id of the map containing folder the '.index.maps' file id was passed so redirect
// this happens if coming from the files app integration
return new RedirectResponse(
$this->urlGenerator->linkToRouteAbsolute('maps.page.indexMyMap', ['myMapId' => $map['id']]),
);
}
$this->eventDispatcher->dispatch(LoadSidebar::class, new LoadSidebar());
$this->eventDispatcher->dispatch(LoadViewer::class, new LoadViewer());
$params = ['user' => $this->userId];
$this->initialState->provideInitialState('photos', $this->config->getAppValue('photos', 'enabled', 'no') === 'yes');
$response = new TemplateResponse('maps', 'main', $params);
$this->addCsp($response);
return $response;
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @param $url
* @return TemplateResponse
*/
public function openGeoLink($url): TemplateResponse {
return $this->index();
}
/**
* @param $response
* @return void
*/
private function addCsp($response): void {
if (class_exists('OCP\AppFramework\Http\ContentSecurityPolicy')) {
$csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
// map tiles
$csp->addAllowedImageDomain('https://*.tile.openstreetmap.org');
$csp->addAllowedImageDomain('https://tile.openstreetmap.org');
$csp->addAllowedImageDomain('https://server.arcgisonline.com');
$csp->addAllowedImageDomain('https://*.cartocdn.com');
$csp->addAllowedImageDomain('https://*.opentopomap.org');
$csp->addAllowedImageDomain('https://*.cartocdn.com');
$csp->addAllowedImageDomain('https://*.ssl.fastly.net');
$csp->addAllowedImageDomain('https://*.openstreetmap.se');
// default routing engine
$csp->addAllowedConnectDomain('https://*.project-osrm.org');
$csp->addAllowedConnectDomain('https://api.mapbox.com');
$csp->addAllowedConnectDomain('https://events.mapbox.com');
$csp->addAllowedConnectDomain('https://graphhopper.com');
$csp->addAllowedChildSrcDomain('blob:');
$csp->addAllowedWorkerSrcDomain('blob:');
$csp->addAllowedScriptDomain('https://unpkg.com');
// allow connections to custom routing engines
$urlKeys = [
'osrmBikeURL',
'osrmCarURL',
'osrmFootURL',
'graphhopperURL',
'maplibreStreetStyleURL',
'maplibreStreetStyleAuth',
'maplibreStreetStylePmtiles'
];
foreach ($urlKeys as $key) {
$url = $this->config->getAppValue('maps', $key);
if ($url !== '') {
$scheme = parse_url($url, PHP_URL_SCHEME);
$host = parse_url($url, PHP_URL_HOST);
$port = parse_url($url, PHP_URL_PORT);
$cleanUrl = $scheme . '://' . $host;
if ($port && $port !== '') {
$cleanUrl .= ':' . $port;
}
$csp->addAllowedConnectDomain($cleanUrl);
}
}
//$csp->addAllowedConnectDomain('http://192.168.0.66:5000');
// poi images
$csp->addAllowedImageDomain('https://nominatim.openstreetmap.org');
// search and geocoder
$csp->addAllowedConnectDomain('https://nominatim.openstreetmap.org');
$response->setContentSecurityPolicy($csp);
}
}
}