@@ -34,50 +34,50 @@ |
||
34 | 34 | |
35 | 35 | class AnonymousOptionsPlugin extends ServerPlugin { |
36 | 36 | |
37 | - /** |
|
38 | - * @var \Sabre\DAV\Server |
|
39 | - */ |
|
40 | - private $server; |
|
37 | + /** |
|
38 | + * @var \Sabre\DAV\Server |
|
39 | + */ |
|
40 | + private $server; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param \Sabre\DAV\Server $server |
|
44 | - * @return void |
|
45 | - */ |
|
46 | - public function initialize(\Sabre\DAV\Server $server) { |
|
47 | - $this->server = $server; |
|
48 | - // before auth |
|
49 | - $this->server->on('beforeMethod:*', [$this, 'handleAnonymousOptions'], 9); |
|
50 | - } |
|
42 | + /** |
|
43 | + * @param \Sabre\DAV\Server $server |
|
44 | + * @return void |
|
45 | + */ |
|
46 | + public function initialize(\Sabre\DAV\Server $server) { |
|
47 | + $this->server = $server; |
|
48 | + // before auth |
|
49 | + $this->server->on('beforeMethod:*', [$this, 'handleAnonymousOptions'], 9); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @return bool |
|
54 | - */ |
|
55 | - public function isRequestInRoot($path) { |
|
56 | - return $path === '' || (is_string($path) && strpos($path, '/') === false); |
|
57 | - } |
|
52 | + /** |
|
53 | + * @return bool |
|
54 | + */ |
|
55 | + public function isRequestInRoot($path) { |
|
56 | + return $path === '' || (is_string($path) && strpos($path, '/') === false); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @throws \Sabre\DAV\Exception\Forbidden |
|
61 | - * @return bool |
|
62 | - */ |
|
63 | - public function handleAnonymousOptions(RequestInterface $request, ResponseInterface $response) { |
|
64 | - $isOffice = preg_match('/Microsoft Office/i', $request->getHeader('User-Agent')); |
|
65 | - $emptyAuth = $request->getHeader('Authorization') === null |
|
66 | - || $request->getHeader('Authorization') === '' |
|
67 | - || trim($request->getHeader('Authorization')) === 'Bearer'; |
|
68 | - $isAnonymousOption = $request->getMethod() === 'OPTIONS' && $emptyAuth; |
|
69 | - $isOfficeHead = $request->getMethod() === 'HEAD' && $isOffice && $emptyAuth; |
|
70 | - if ($isAnonymousOption || $isOfficeHead) { |
|
71 | - /** @var CorePlugin $corePlugin */ |
|
72 | - $corePlugin = $this->server->getPlugin('core'); |
|
73 | - // setup a fake tree for anonymous access |
|
74 | - $this->server->tree = new Tree(new Directory('')); |
|
75 | - $corePlugin->httpOptions($request, $response); |
|
76 | - $this->server->emit('afterMethod', [$request, $response]); |
|
77 | - $this->server->emit('afterMethod:OPTIONS', [$request, $response]); |
|
59 | + /** |
|
60 | + * @throws \Sabre\DAV\Exception\Forbidden |
|
61 | + * @return bool |
|
62 | + */ |
|
63 | + public function handleAnonymousOptions(RequestInterface $request, ResponseInterface $response) { |
|
64 | + $isOffice = preg_match('/Microsoft Office/i', $request->getHeader('User-Agent')); |
|
65 | + $emptyAuth = $request->getHeader('Authorization') === null |
|
66 | + || $request->getHeader('Authorization') === '' |
|
67 | + || trim($request->getHeader('Authorization')) === 'Bearer'; |
|
68 | + $isAnonymousOption = $request->getMethod() === 'OPTIONS' && $emptyAuth; |
|
69 | + $isOfficeHead = $request->getMethod() === 'HEAD' && $isOffice && $emptyAuth; |
|
70 | + if ($isAnonymousOption || $isOfficeHead) { |
|
71 | + /** @var CorePlugin $corePlugin */ |
|
72 | + $corePlugin = $this->server->getPlugin('core'); |
|
73 | + // setup a fake tree for anonymous access |
|
74 | + $this->server->tree = new Tree(new Directory('')); |
|
75 | + $corePlugin->httpOptions($request, $response); |
|
76 | + $this->server->emit('afterMethod', [$request, $response]); |
|
77 | + $this->server->emit('afterMethod:OPTIONS', [$request, $response]); |
|
78 | 78 | |
79 | - $this->server->sapi->sendResponse($response); |
|
80 | - return false; |
|
81 | - } |
|
82 | - } |
|
79 | + $this->server->sapi->sendResponse($response); |
|
80 | + return false; |
|
81 | + } |
|
82 | + } |
|
83 | 83 | } |
@@ -33,58 +33,58 @@ |
||
33 | 33 | |
34 | 34 | class MaintenancePlugin extends ServerPlugin { |
35 | 35 | |
36 | - /** @var IConfig */ |
|
37 | - private $config; |
|
36 | + /** @var IConfig */ |
|
37 | + private $config; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Reference to main server object |
|
41 | - * |
|
42 | - * @var Server |
|
43 | - */ |
|
44 | - private $server; |
|
39 | + /** |
|
40 | + * Reference to main server object |
|
41 | + * |
|
42 | + * @var Server |
|
43 | + */ |
|
44 | + private $server; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @param IConfig $config |
|
48 | - */ |
|
49 | - public function __construct(IConfig $config = null) { |
|
50 | - $this->config = $config; |
|
51 | - if (is_null($config)) { |
|
52 | - $this->config = \OC::$server->getConfig(); |
|
53 | - } |
|
54 | - } |
|
46 | + /** |
|
47 | + * @param IConfig $config |
|
48 | + */ |
|
49 | + public function __construct(IConfig $config = null) { |
|
50 | + $this->config = $config; |
|
51 | + if (is_null($config)) { |
|
52 | + $this->config = \OC::$server->getConfig(); |
|
53 | + } |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * This initializes the plugin. |
|
59 | - * |
|
60 | - * This function is called by \Sabre\DAV\Server, after |
|
61 | - * addPlugin is called. |
|
62 | - * |
|
63 | - * This method should set up the required event subscriptions. |
|
64 | - * |
|
65 | - * @param \Sabre\DAV\Server $server |
|
66 | - * @return void |
|
67 | - */ |
|
68 | - public function initialize(\Sabre\DAV\Server $server) { |
|
69 | - $this->server = $server; |
|
70 | - $this->server->on('beforeMethod:*', [$this, 'checkMaintenanceMode'], 1); |
|
71 | - } |
|
57 | + /** |
|
58 | + * This initializes the plugin. |
|
59 | + * |
|
60 | + * This function is called by \Sabre\DAV\Server, after |
|
61 | + * addPlugin is called. |
|
62 | + * |
|
63 | + * This method should set up the required event subscriptions. |
|
64 | + * |
|
65 | + * @param \Sabre\DAV\Server $server |
|
66 | + * @return void |
|
67 | + */ |
|
68 | + public function initialize(\Sabre\DAV\Server $server) { |
|
69 | + $this->server = $server; |
|
70 | + $this->server->on('beforeMethod:*', [$this, 'checkMaintenanceMode'], 1); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * This method is called before any HTTP method and returns http status code 503 |
|
75 | - * in case the system is in maintenance mode. |
|
76 | - * |
|
77 | - * @throws ServiceUnavailable |
|
78 | - * @return bool |
|
79 | - */ |
|
80 | - public function checkMaintenanceMode() { |
|
81 | - if ($this->config->getSystemValueBool('maintenance')) { |
|
82 | - throw new ServiceUnavailable('System in maintenance mode.'); |
|
83 | - } |
|
84 | - if (Util::needUpgrade()) { |
|
85 | - throw new ServiceUnavailable('Upgrade needed'); |
|
86 | - } |
|
73 | + /** |
|
74 | + * This method is called before any HTTP method and returns http status code 503 |
|
75 | + * in case the system is in maintenance mode. |
|
76 | + * |
|
77 | + * @throws ServiceUnavailable |
|
78 | + * @return bool |
|
79 | + */ |
|
80 | + public function checkMaintenanceMode() { |
|
81 | + if ($this->config->getSystemValueBool('maintenance')) { |
|
82 | + throw new ServiceUnavailable('System in maintenance mode.'); |
|
83 | + } |
|
84 | + if (Util::needUpgrade()) { |
|
85 | + throw new ServiceUnavailable('Upgrade needed'); |
|
86 | + } |
|
87 | 87 | |
88 | - return true; |
|
89 | - } |
|
88 | + return true; |
|
89 | + } |
|
90 | 90 | } |
@@ -72,260 +72,260 @@ |
||
72 | 72 | |
73 | 73 | class Server { |
74 | 74 | |
75 | - /** @var IRequest */ |
|
76 | - private $request; |
|
77 | - |
|
78 | - /** @var string */ |
|
79 | - private $baseUri; |
|
80 | - |
|
81 | - /** @var Connector\Sabre\Server */ |
|
82 | - public $server; |
|
83 | - |
|
84 | - public function __construct(IRequest $request, $baseUri) { |
|
85 | - $this->request = $request; |
|
86 | - $this->baseUri = $baseUri; |
|
87 | - $logger = \OC::$server->getLogger(); |
|
88 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
89 | - |
|
90 | - $root = new RootCollection(); |
|
91 | - $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); |
|
92 | - |
|
93 | - // Add maintenance plugin |
|
94 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig())); |
|
95 | - |
|
96 | - // Backends |
|
97 | - $authBackend = new Auth( |
|
98 | - \OC::$server->getSession(), |
|
99 | - \OC::$server->getUserSession(), |
|
100 | - \OC::$server->getRequest(), |
|
101 | - \OC::$server->getTwoFactorAuthManager(), |
|
102 | - \OC::$server->getBruteForceThrottler() |
|
103 | - ); |
|
104 | - |
|
105 | - // Set URL explicitly due to reverse-proxy situations |
|
106 | - $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
107 | - $this->server->setBaseUri($this->baseUri); |
|
108 | - |
|
109 | - $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
110 | - $this->server->addPlugin(new AnonymousOptionsPlugin()); |
|
111 | - $authPlugin = new Plugin(); |
|
112 | - $authPlugin->addBackend(new PublicAuth()); |
|
113 | - $this->server->addPlugin($authPlugin); |
|
114 | - |
|
115 | - // allow setup of additional auth backends |
|
116 | - $event = new SabrePluginEvent($this->server); |
|
117 | - $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
118 | - |
|
119 | - $bearerAuthBackend = new BearerAuth( |
|
120 | - \OC::$server->getUserSession(), |
|
121 | - \OC::$server->getSession(), |
|
122 | - \OC::$server->getRequest() |
|
123 | - ); |
|
124 | - $authPlugin->addBackend($bearerAuthBackend); |
|
125 | - // because we are throwing exceptions this plugin has to be the last one |
|
126 | - $authPlugin->addBackend($authBackend); |
|
127 | - |
|
128 | - // debugging |
|
129 | - if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
130 | - $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
131 | - } else { |
|
132 | - $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
133 | - } |
|
134 | - |
|
135 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
136 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
137 | - $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
138 | - |
|
139 | - // acl |
|
140 | - $acl = new DavAclPlugin(); |
|
141 | - $acl->principalCollectionSet = [ |
|
142 | - 'principals/users', |
|
143 | - 'principals/groups', |
|
144 | - 'principals/calendar-resources', |
|
145 | - 'principals/calendar-rooms', |
|
146 | - ]; |
|
147 | - $acl->defaultUsernamePath = 'principals/users'; |
|
148 | - $this->server->addPlugin($acl); |
|
149 | - |
|
150 | - // calendar plugins |
|
151 | - if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'system-calendars', 'principals'])) { |
|
152 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
153 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\ICSExportPlugin\ICSExportPlugin(\OC::$server->getConfig(), \OC::$server->getLogger())); |
|
154 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
|
155 | - if (\OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') { |
|
156 | - $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class)); |
|
157 | - } |
|
158 | - |
|
159 | - $this->server->addPlugin(new CalDAV\WebcalCaching\Plugin($request)); |
|
160 | - $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
161 | - |
|
162 | - $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
163 | - $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
164 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
165 | - \OC::$server->getConfig(), |
|
166 | - \OC::$server->getURLGenerator() |
|
167 | - )); |
|
168 | - } |
|
169 | - |
|
170 | - // addressbook plugins |
|
171 | - if ($this->requestIsForSubtree(['addressbooks', 'principals'])) { |
|
172 | - $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
173 | - $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
174 | - $this->server->addPlugin(new VCFExportPlugin()); |
|
175 | - $this->server->addPlugin(new MultiGetExportPlugin()); |
|
176 | - $this->server->addPlugin(new HasPhotoPlugin()); |
|
177 | - $this->server->addPlugin(new ImageExportPlugin(new PhotoCache( |
|
178 | - \OC::$server->getAppDataDir('dav-photocache'), |
|
179 | - \OC::$server->getLogger()) |
|
180 | - )); |
|
181 | - } |
|
182 | - |
|
183 | - // system tags plugins |
|
184 | - $this->server->addPlugin(new SystemTagPlugin( |
|
185 | - \OC::$server->getSystemTagManager(), |
|
186 | - \OC::$server->getGroupManager(), |
|
187 | - \OC::$server->getUserSession() |
|
188 | - )); |
|
189 | - |
|
190 | - // comments plugin |
|
191 | - $this->server->addPlugin(new CommentsPlugin( |
|
192 | - \OC::$server->getCommentsManager(), |
|
193 | - \OC::$server->getUserSession() |
|
194 | - )); |
|
195 | - |
|
196 | - $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
197 | - $this->server->addPlugin(new ChunkingPlugin()); |
|
198 | - |
|
199 | - // allow setup of additional plugins |
|
200 | - $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event); |
|
201 | - |
|
202 | - // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
203 | - // we do not provide locking we emulate it using a fake locking plugin. |
|
204 | - if($request->isUserAgent([ |
|
205 | - '/WebDAVFS/', |
|
206 | - '/OneNote/', |
|
207 | - '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
208 | - ])) { |
|
209 | - $this->server->addPlugin(new FakeLockerPlugin()); |
|
210 | - } |
|
211 | - |
|
212 | - if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
213 | - $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
214 | - } |
|
215 | - |
|
216 | - $lazySearchBackend = new LazySearchBackend(); |
|
217 | - $this->server->addPlugin(new SearchPlugin($lazySearchBackend)); |
|
218 | - |
|
219 | - // wait with registering these until auth is handled and the filesystem is setup |
|
220 | - $this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend) { |
|
221 | - // custom properties plugin must be the last one |
|
222 | - $userSession = \OC::$server->getUserSession(); |
|
223 | - $user = $userSession->getUser(); |
|
224 | - if ($user !== null) { |
|
225 | - $view = \OC\Files\Filesystem::getView(); |
|
226 | - $this->server->addPlugin( |
|
227 | - new FilesPlugin( |
|
228 | - $this->server->tree, |
|
229 | - \OC::$server->getConfig(), |
|
230 | - $this->request, |
|
231 | - \OC::$server->getPreviewManager(), |
|
232 | - false, |
|
233 | - !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
234 | - ) |
|
235 | - ); |
|
236 | - |
|
237 | - $this->server->addPlugin( |
|
238 | - new \Sabre\DAV\PropertyStorage\Plugin( |
|
239 | - new CustomPropertiesBackend( |
|
240 | - $this->server->tree, |
|
241 | - \OC::$server->getDatabaseConnection(), |
|
242 | - \OC::$server->getUserSession()->getUser() |
|
243 | - ) |
|
244 | - ) |
|
245 | - ); |
|
246 | - if ($view !== null) { |
|
247 | - $this->server->addPlugin( |
|
248 | - new QuotaPlugin($view, false)); |
|
249 | - } |
|
250 | - $this->server->addPlugin( |
|
251 | - new TagsPlugin( |
|
252 | - $this->server->tree, \OC::$server->getTagManager() |
|
253 | - ) |
|
254 | - ); |
|
255 | - // TODO: switch to LazyUserFolder |
|
256 | - $userFolder = \OC::$server->getUserFolder(); |
|
257 | - $this->server->addPlugin(new SharesPlugin( |
|
258 | - $this->server->tree, |
|
259 | - $userSession, |
|
260 | - $userFolder, |
|
261 | - \OC::$server->getShareManager() |
|
262 | - )); |
|
263 | - $this->server->addPlugin(new CommentPropertiesPlugin( |
|
264 | - \OC::$server->getCommentsManager(), |
|
265 | - $userSession |
|
266 | - )); |
|
267 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
268 | - if ($view !== null) { |
|
269 | - $this->server->addPlugin(new FilesReportPlugin( |
|
270 | - $this->server->tree, |
|
271 | - $view, |
|
272 | - \OC::$server->getSystemTagManager(), |
|
273 | - \OC::$server->getSystemTagObjectMapper(), |
|
274 | - \OC::$server->getTagManager(), |
|
275 | - $userSession, |
|
276 | - \OC::$server->getGroupManager(), |
|
277 | - $userFolder, |
|
278 | - \OC::$server->getAppManager() |
|
279 | - )); |
|
280 | - $lazySearchBackend->setBackend(new \OCA\DAV\Files\FileSearchBackend( |
|
281 | - $this->server->tree, |
|
282 | - $user, |
|
283 | - \OC::$server->getRootFolder(), |
|
284 | - \OC::$server->getShareManager(), |
|
285 | - $view |
|
286 | - )); |
|
287 | - } |
|
288 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin( |
|
289 | - \OC::$server->getConfig(), |
|
290 | - \OC::$server->query(BirthdayService::class) |
|
291 | - )); |
|
292 | - $this->server->addPlugin(new AppleProvisioningPlugin( |
|
293 | - \OC::$server->getUserSession(), |
|
294 | - \OC::$server->getURLGenerator(), |
|
295 | - \OC::$server->getThemingDefaults(), |
|
296 | - \OC::$server->getRequest(), |
|
297 | - \OC::$server->getL10N('dav'), |
|
298 | - function() { |
|
299 | - return UUIDUtil::getUUID(); |
|
300 | - } |
|
301 | - )); |
|
302 | - } |
|
303 | - |
|
304 | - // register plugins from apps |
|
305 | - $pluginManager = new PluginManager( |
|
306 | - \OC::$server, |
|
307 | - \OC::$server->getAppManager() |
|
308 | - ); |
|
309 | - foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
310 | - $this->server->addPlugin($appPlugin); |
|
311 | - } |
|
312 | - foreach ($pluginManager->getAppCollections() as $appCollection) { |
|
313 | - $root->addChild($appCollection); |
|
314 | - } |
|
315 | - }); |
|
316 | - } |
|
317 | - |
|
318 | - public function exec() { |
|
319 | - $this->server->exec(); |
|
320 | - } |
|
321 | - |
|
322 | - private function requestIsForSubtree(array $subTrees): bool { |
|
323 | - foreach ($subTrees as $subTree) { |
|
324 | - $subTree = trim($subTree, ' /'); |
|
325 | - if (strpos($this->server->getRequestUri(), $subTree.'/') === 0) { |
|
326 | - return true; |
|
327 | - } |
|
328 | - } |
|
329 | - return false; |
|
330 | - } |
|
75 | + /** @var IRequest */ |
|
76 | + private $request; |
|
77 | + |
|
78 | + /** @var string */ |
|
79 | + private $baseUri; |
|
80 | + |
|
81 | + /** @var Connector\Sabre\Server */ |
|
82 | + public $server; |
|
83 | + |
|
84 | + public function __construct(IRequest $request, $baseUri) { |
|
85 | + $this->request = $request; |
|
86 | + $this->baseUri = $baseUri; |
|
87 | + $logger = \OC::$server->getLogger(); |
|
88 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
89 | + |
|
90 | + $root = new RootCollection(); |
|
91 | + $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); |
|
92 | + |
|
93 | + // Add maintenance plugin |
|
94 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig())); |
|
95 | + |
|
96 | + // Backends |
|
97 | + $authBackend = new Auth( |
|
98 | + \OC::$server->getSession(), |
|
99 | + \OC::$server->getUserSession(), |
|
100 | + \OC::$server->getRequest(), |
|
101 | + \OC::$server->getTwoFactorAuthManager(), |
|
102 | + \OC::$server->getBruteForceThrottler() |
|
103 | + ); |
|
104 | + |
|
105 | + // Set URL explicitly due to reverse-proxy situations |
|
106 | + $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
107 | + $this->server->setBaseUri($this->baseUri); |
|
108 | + |
|
109 | + $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
110 | + $this->server->addPlugin(new AnonymousOptionsPlugin()); |
|
111 | + $authPlugin = new Plugin(); |
|
112 | + $authPlugin->addBackend(new PublicAuth()); |
|
113 | + $this->server->addPlugin($authPlugin); |
|
114 | + |
|
115 | + // allow setup of additional auth backends |
|
116 | + $event = new SabrePluginEvent($this->server); |
|
117 | + $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
118 | + |
|
119 | + $bearerAuthBackend = new BearerAuth( |
|
120 | + \OC::$server->getUserSession(), |
|
121 | + \OC::$server->getSession(), |
|
122 | + \OC::$server->getRequest() |
|
123 | + ); |
|
124 | + $authPlugin->addBackend($bearerAuthBackend); |
|
125 | + // because we are throwing exceptions this plugin has to be the last one |
|
126 | + $authPlugin->addBackend($authBackend); |
|
127 | + |
|
128 | + // debugging |
|
129 | + if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
130 | + $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
131 | + } else { |
|
132 | + $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
133 | + } |
|
134 | + |
|
135 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
136 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
137 | + $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
138 | + |
|
139 | + // acl |
|
140 | + $acl = new DavAclPlugin(); |
|
141 | + $acl->principalCollectionSet = [ |
|
142 | + 'principals/users', |
|
143 | + 'principals/groups', |
|
144 | + 'principals/calendar-resources', |
|
145 | + 'principals/calendar-rooms', |
|
146 | + ]; |
|
147 | + $acl->defaultUsernamePath = 'principals/users'; |
|
148 | + $this->server->addPlugin($acl); |
|
149 | + |
|
150 | + // calendar plugins |
|
151 | + if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'system-calendars', 'principals'])) { |
|
152 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
153 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\ICSExportPlugin\ICSExportPlugin(\OC::$server->getConfig(), \OC::$server->getLogger())); |
|
154 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
|
155 | + if (\OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') { |
|
156 | + $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class)); |
|
157 | + } |
|
158 | + |
|
159 | + $this->server->addPlugin(new CalDAV\WebcalCaching\Plugin($request)); |
|
160 | + $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
161 | + |
|
162 | + $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
163 | + $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
164 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
165 | + \OC::$server->getConfig(), |
|
166 | + \OC::$server->getURLGenerator() |
|
167 | + )); |
|
168 | + } |
|
169 | + |
|
170 | + // addressbook plugins |
|
171 | + if ($this->requestIsForSubtree(['addressbooks', 'principals'])) { |
|
172 | + $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
173 | + $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
174 | + $this->server->addPlugin(new VCFExportPlugin()); |
|
175 | + $this->server->addPlugin(new MultiGetExportPlugin()); |
|
176 | + $this->server->addPlugin(new HasPhotoPlugin()); |
|
177 | + $this->server->addPlugin(new ImageExportPlugin(new PhotoCache( |
|
178 | + \OC::$server->getAppDataDir('dav-photocache'), |
|
179 | + \OC::$server->getLogger()) |
|
180 | + )); |
|
181 | + } |
|
182 | + |
|
183 | + // system tags plugins |
|
184 | + $this->server->addPlugin(new SystemTagPlugin( |
|
185 | + \OC::$server->getSystemTagManager(), |
|
186 | + \OC::$server->getGroupManager(), |
|
187 | + \OC::$server->getUserSession() |
|
188 | + )); |
|
189 | + |
|
190 | + // comments plugin |
|
191 | + $this->server->addPlugin(new CommentsPlugin( |
|
192 | + \OC::$server->getCommentsManager(), |
|
193 | + \OC::$server->getUserSession() |
|
194 | + )); |
|
195 | + |
|
196 | + $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
197 | + $this->server->addPlugin(new ChunkingPlugin()); |
|
198 | + |
|
199 | + // allow setup of additional plugins |
|
200 | + $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event); |
|
201 | + |
|
202 | + // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
203 | + // we do not provide locking we emulate it using a fake locking plugin. |
|
204 | + if($request->isUserAgent([ |
|
205 | + '/WebDAVFS/', |
|
206 | + '/OneNote/', |
|
207 | + '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
208 | + ])) { |
|
209 | + $this->server->addPlugin(new FakeLockerPlugin()); |
|
210 | + } |
|
211 | + |
|
212 | + if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
213 | + $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
214 | + } |
|
215 | + |
|
216 | + $lazySearchBackend = new LazySearchBackend(); |
|
217 | + $this->server->addPlugin(new SearchPlugin($lazySearchBackend)); |
|
218 | + |
|
219 | + // wait with registering these until auth is handled and the filesystem is setup |
|
220 | + $this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend) { |
|
221 | + // custom properties plugin must be the last one |
|
222 | + $userSession = \OC::$server->getUserSession(); |
|
223 | + $user = $userSession->getUser(); |
|
224 | + if ($user !== null) { |
|
225 | + $view = \OC\Files\Filesystem::getView(); |
|
226 | + $this->server->addPlugin( |
|
227 | + new FilesPlugin( |
|
228 | + $this->server->tree, |
|
229 | + \OC::$server->getConfig(), |
|
230 | + $this->request, |
|
231 | + \OC::$server->getPreviewManager(), |
|
232 | + false, |
|
233 | + !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
234 | + ) |
|
235 | + ); |
|
236 | + |
|
237 | + $this->server->addPlugin( |
|
238 | + new \Sabre\DAV\PropertyStorage\Plugin( |
|
239 | + new CustomPropertiesBackend( |
|
240 | + $this->server->tree, |
|
241 | + \OC::$server->getDatabaseConnection(), |
|
242 | + \OC::$server->getUserSession()->getUser() |
|
243 | + ) |
|
244 | + ) |
|
245 | + ); |
|
246 | + if ($view !== null) { |
|
247 | + $this->server->addPlugin( |
|
248 | + new QuotaPlugin($view, false)); |
|
249 | + } |
|
250 | + $this->server->addPlugin( |
|
251 | + new TagsPlugin( |
|
252 | + $this->server->tree, \OC::$server->getTagManager() |
|
253 | + ) |
|
254 | + ); |
|
255 | + // TODO: switch to LazyUserFolder |
|
256 | + $userFolder = \OC::$server->getUserFolder(); |
|
257 | + $this->server->addPlugin(new SharesPlugin( |
|
258 | + $this->server->tree, |
|
259 | + $userSession, |
|
260 | + $userFolder, |
|
261 | + \OC::$server->getShareManager() |
|
262 | + )); |
|
263 | + $this->server->addPlugin(new CommentPropertiesPlugin( |
|
264 | + \OC::$server->getCommentsManager(), |
|
265 | + $userSession |
|
266 | + )); |
|
267 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
268 | + if ($view !== null) { |
|
269 | + $this->server->addPlugin(new FilesReportPlugin( |
|
270 | + $this->server->tree, |
|
271 | + $view, |
|
272 | + \OC::$server->getSystemTagManager(), |
|
273 | + \OC::$server->getSystemTagObjectMapper(), |
|
274 | + \OC::$server->getTagManager(), |
|
275 | + $userSession, |
|
276 | + \OC::$server->getGroupManager(), |
|
277 | + $userFolder, |
|
278 | + \OC::$server->getAppManager() |
|
279 | + )); |
|
280 | + $lazySearchBackend->setBackend(new \OCA\DAV\Files\FileSearchBackend( |
|
281 | + $this->server->tree, |
|
282 | + $user, |
|
283 | + \OC::$server->getRootFolder(), |
|
284 | + \OC::$server->getShareManager(), |
|
285 | + $view |
|
286 | + )); |
|
287 | + } |
|
288 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin( |
|
289 | + \OC::$server->getConfig(), |
|
290 | + \OC::$server->query(BirthdayService::class) |
|
291 | + )); |
|
292 | + $this->server->addPlugin(new AppleProvisioningPlugin( |
|
293 | + \OC::$server->getUserSession(), |
|
294 | + \OC::$server->getURLGenerator(), |
|
295 | + \OC::$server->getThemingDefaults(), |
|
296 | + \OC::$server->getRequest(), |
|
297 | + \OC::$server->getL10N('dav'), |
|
298 | + function() { |
|
299 | + return UUIDUtil::getUUID(); |
|
300 | + } |
|
301 | + )); |
|
302 | + } |
|
303 | + |
|
304 | + // register plugins from apps |
|
305 | + $pluginManager = new PluginManager( |
|
306 | + \OC::$server, |
|
307 | + \OC::$server->getAppManager() |
|
308 | + ); |
|
309 | + foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
310 | + $this->server->addPlugin($appPlugin); |
|
311 | + } |
|
312 | + foreach ($pluginManager->getAppCollections() as $appCollection) { |
|
313 | + $root->addChild($appCollection); |
|
314 | + } |
|
315 | + }); |
|
316 | + } |
|
317 | + |
|
318 | + public function exec() { |
|
319 | + $this->server->exec(); |
|
320 | + } |
|
321 | + |
|
322 | + private function requestIsForSubtree(array $subTrees): bool { |
|
323 | + foreach ($subTrees as $subTree) { |
|
324 | + $subTree = trim($subTree, ' /'); |
|
325 | + if (strpos($this->server->getRequestUri(), $subTree.'/') === 0) { |
|
326 | + return true; |
|
327 | + } |
|
328 | + } |
|
329 | + return false; |
|
330 | + } |
|
331 | 331 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | $authPlugin->addBackend($authBackend); |
127 | 127 | |
128 | 128 | // debugging |
129 | - if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
129 | + if (\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
130 | 130 | $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
131 | 131 | } else { |
132 | 132 | $this->server->addPlugin(new DummyGetResponsePlugin()); |
@@ -201,10 +201,10 @@ discard block |
||
201 | 201 | |
202 | 202 | // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
203 | 203 | // we do not provide locking we emulate it using a fake locking plugin. |
204 | - if($request->isUserAgent([ |
|
204 | + if ($request->isUserAgent([ |
|
205 | 205 | '/WebDAVFS/', |
206 | 206 | '/OneNote/', |
207 | - '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
207 | + '/^Microsoft-WebDAV/', // Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
208 | 208 | ])) { |
209 | 209 | $this->server->addPlugin(new FakeLockerPlugin()); |
210 | 210 | } |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | $this->server->addPlugin(new SearchPlugin($lazySearchBackend)); |
218 | 218 | |
219 | 219 | // wait with registering these until auth is handled and the filesystem is setup |
220 | - $this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend) { |
|
220 | + $this->server->on('beforeMethod:*', function() use ($root, $lazySearchBackend) { |
|
221 | 221 | // custom properties plugin must be the last one |
222 | 222 | $userSession = \OC::$server->getUserSession(); |
223 | 223 | $user = $userSession->getUser(); |