@@ -76,270 +76,270 @@ |
||
| 76 | 76 | |
| 77 | 77 | class Server { |
| 78 | 78 | |
| 79 | - /** @var IRequest */ |
|
| 80 | - private $request; |
|
| 81 | - |
|
| 82 | - /** @var string */ |
|
| 83 | - private $baseUri; |
|
| 84 | - |
|
| 85 | - /** @var Connector\Sabre\Server */ |
|
| 86 | - public $server; |
|
| 87 | - |
|
| 88 | - public function __construct(IRequest $request, $baseUri) { |
|
| 89 | - $this->request = $request; |
|
| 90 | - $this->baseUri = $baseUri; |
|
| 91 | - $logger = \OC::$server->getLogger(); |
|
| 92 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 93 | - /** @var IEventDispatcher $newDispatcher */ |
|
| 94 | - $newDispatcher = \OC::$server->query(IEventDispatcher::class); |
|
| 95 | - |
|
| 96 | - $root = new RootCollection(); |
|
| 97 | - $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); |
|
| 98 | - |
|
| 99 | - // Add maintenance plugin |
|
| 100 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav'))); |
|
| 101 | - |
|
| 102 | - // Backends |
|
| 103 | - $authBackend = new Auth( |
|
| 104 | - \OC::$server->getSession(), |
|
| 105 | - \OC::$server->getUserSession(), |
|
| 106 | - \OC::$server->getRequest(), |
|
| 107 | - \OC::$server->getTwoFactorAuthManager(), |
|
| 108 | - \OC::$server->getBruteForceThrottler() |
|
| 109 | - ); |
|
| 110 | - |
|
| 111 | - // Set URL explicitly due to reverse-proxy situations |
|
| 112 | - $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
| 113 | - $this->server->setBaseUri($this->baseUri); |
|
| 114 | - |
|
| 115 | - $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
| 116 | - $this->server->addPlugin(new AnonymousOptionsPlugin()); |
|
| 117 | - $authPlugin = new Plugin(); |
|
| 118 | - $authPlugin->addBackend(new PublicAuth()); |
|
| 119 | - $this->server->addPlugin($authPlugin); |
|
| 120 | - |
|
| 121 | - // allow setup of additional auth backends |
|
| 122 | - $event = new SabrePluginEvent($this->server); |
|
| 123 | - $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
| 124 | - |
|
| 125 | - $newAuthEvent = new SabrePluginAuthInitEvent($this->server); |
|
| 126 | - $newDispatcher->dispatchTyped($newAuthEvent); |
|
| 127 | - |
|
| 128 | - $bearerAuthBackend = new BearerAuth( |
|
| 129 | - \OC::$server->getUserSession(), |
|
| 130 | - \OC::$server->getSession(), |
|
| 131 | - \OC::$server->getRequest() |
|
| 132 | - ); |
|
| 133 | - $authPlugin->addBackend($bearerAuthBackend); |
|
| 134 | - // because we are throwing exceptions this plugin has to be the last one |
|
| 135 | - $authPlugin->addBackend($authBackend); |
|
| 136 | - |
|
| 137 | - // debugging |
|
| 138 | - if (\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 139 | - $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
| 140 | - } else { |
|
| 141 | - $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
| 145 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
| 146 | - $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
| 147 | - |
|
| 148 | - // acl |
|
| 149 | - $acl = new DavAclPlugin(); |
|
| 150 | - $acl->principalCollectionSet = [ |
|
| 151 | - 'principals/users', |
|
| 152 | - 'principals/groups', |
|
| 153 | - 'principals/calendar-resources', |
|
| 154 | - 'principals/calendar-rooms', |
|
| 155 | - ]; |
|
| 156 | - $acl->defaultUsernamePath = 'principals/users'; |
|
| 157 | - $this->server->addPlugin($acl); |
|
| 158 | - |
|
| 159 | - // calendar plugins |
|
| 160 | - if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'system-calendars', 'principals'])) { |
|
| 161 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
| 162 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\ICSExportPlugin\ICSExportPlugin(\OC::$server->getConfig(), \OC::$server->getLogger())); |
|
| 163 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig())); |
|
| 164 | - if (\OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') { |
|
| 165 | - $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class)); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - $this->server->addPlugin(\OC::$server->get(\OCA\DAV\CalDAV\Trashbin\Plugin::class)); |
|
| 169 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\WebcalCaching\Plugin($request)); |
|
| 170 | - $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
| 171 | - |
|
| 172 | - $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
| 173 | - $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest(), \OC::$server->getConfig())); |
|
| 174 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
| 175 | - \OC::$server->getConfig(), |
|
| 176 | - \OC::$server->getURLGenerator() |
|
| 177 | - )); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - // addressbook plugins |
|
| 181 | - if ($this->requestIsForSubtree(['addressbooks', 'principals'])) { |
|
| 182 | - $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest(), \OC::$server->getConfig())); |
|
| 183 | - $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
| 184 | - $this->server->addPlugin(new VCFExportPlugin()); |
|
| 185 | - $this->server->addPlugin(new MultiGetExportPlugin()); |
|
| 186 | - $this->server->addPlugin(new HasPhotoPlugin()); |
|
| 187 | - $this->server->addPlugin(new ImageExportPlugin(new PhotoCache( |
|
| 188 | - \OC::$server->getAppDataDir('dav-photocache'), |
|
| 189 | - \OC::$server->getLogger()) |
|
| 190 | - )); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - // system tags plugins |
|
| 194 | - $this->server->addPlugin(new SystemTagPlugin( |
|
| 195 | - \OC::$server->getSystemTagManager(), |
|
| 196 | - \OC::$server->getGroupManager(), |
|
| 197 | - \OC::$server->getUserSession() |
|
| 198 | - )); |
|
| 199 | - |
|
| 200 | - // comments plugin |
|
| 201 | - $this->server->addPlugin(new CommentsPlugin( |
|
| 202 | - \OC::$server->getCommentsManager(), |
|
| 203 | - \OC::$server->getUserSession() |
|
| 204 | - )); |
|
| 205 | - |
|
| 206 | - $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
| 207 | - $this->server->addPlugin(new ChunkingPlugin()); |
|
| 208 | - |
|
| 209 | - // allow setup of additional plugins |
|
| 210 | - $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event); |
|
| 211 | - |
|
| 212 | - // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 213 | - // we do not provide locking we emulate it using a fake locking plugin. |
|
| 214 | - if ($request->isUserAgent([ |
|
| 215 | - '/WebDAVFS/', |
|
| 216 | - '/OneNote/', |
|
| 217 | - '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
| 218 | - ])) { |
|
| 219 | - $this->server->addPlugin(new FakeLockerPlugin()); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
| 223 | - $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - $lazySearchBackend = new LazySearchBackend(); |
|
| 227 | - $this->server->addPlugin(new SearchPlugin($lazySearchBackend)); |
|
| 228 | - |
|
| 229 | - // wait with registering these until auth is handled and the filesystem is setup |
|
| 230 | - $this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend) { |
|
| 231 | - // custom properties plugin must be the last one |
|
| 232 | - $userSession = \OC::$server->getUserSession(); |
|
| 233 | - $user = $userSession->getUser(); |
|
| 234 | - if ($user !== null) { |
|
| 235 | - $view = \OC\Files\Filesystem::getView(); |
|
| 236 | - $this->server->addPlugin( |
|
| 237 | - new FilesPlugin( |
|
| 238 | - $this->server->tree, |
|
| 239 | - \OC::$server->getConfig(), |
|
| 240 | - $this->request, |
|
| 241 | - \OC::$server->getPreviewManager(), |
|
| 242 | - false, |
|
| 243 | - !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
| 244 | - ) |
|
| 245 | - ); |
|
| 246 | - |
|
| 247 | - $this->server->addPlugin( |
|
| 248 | - new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 249 | - new CustomPropertiesBackend( |
|
| 250 | - $this->server->tree, |
|
| 251 | - \OC::$server->getDatabaseConnection(), |
|
| 252 | - \OC::$server->getUserSession()->getUser() |
|
| 253 | - ) |
|
| 254 | - ) |
|
| 255 | - ); |
|
| 256 | - if ($view !== null) { |
|
| 257 | - $this->server->addPlugin( |
|
| 258 | - new QuotaPlugin($view, false)); |
|
| 259 | - } |
|
| 260 | - $this->server->addPlugin( |
|
| 261 | - new TagsPlugin( |
|
| 262 | - $this->server->tree, \OC::$server->getTagManager() |
|
| 263 | - ) |
|
| 264 | - ); |
|
| 265 | - // TODO: switch to LazyUserFolder |
|
| 266 | - $userFolder = \OC::$server->getUserFolder(); |
|
| 267 | - $this->server->addPlugin(new SharesPlugin( |
|
| 268 | - $this->server->tree, |
|
| 269 | - $userSession, |
|
| 270 | - $userFolder, |
|
| 271 | - \OC::$server->getShareManager() |
|
| 272 | - )); |
|
| 273 | - $this->server->addPlugin(new CommentPropertiesPlugin( |
|
| 274 | - \OC::$server->getCommentsManager(), |
|
| 275 | - $userSession |
|
| 276 | - )); |
|
| 277 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
| 278 | - if ($view !== null) { |
|
| 279 | - $this->server->addPlugin(new FilesReportPlugin( |
|
| 280 | - $this->server->tree, |
|
| 281 | - $view, |
|
| 282 | - \OC::$server->getSystemTagManager(), |
|
| 283 | - \OC::$server->getSystemTagObjectMapper(), |
|
| 284 | - \OC::$server->getTagManager(), |
|
| 285 | - $userSession, |
|
| 286 | - \OC::$server->getGroupManager(), |
|
| 287 | - $userFolder, |
|
| 288 | - \OC::$server->getAppManager() |
|
| 289 | - )); |
|
| 290 | - $lazySearchBackend->setBackend(new \OCA\DAV\Files\FileSearchBackend( |
|
| 291 | - $this->server->tree, |
|
| 292 | - $user, |
|
| 293 | - \OC::$server->getRootFolder(), |
|
| 294 | - \OC::$server->getShareManager(), |
|
| 295 | - $view |
|
| 296 | - )); |
|
| 297 | - } |
|
| 298 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin( |
|
| 299 | - \OC::$server->getConfig(), |
|
| 300 | - \OC::$server->query(BirthdayService::class) |
|
| 301 | - )); |
|
| 302 | - $this->server->addPlugin(new AppleProvisioningPlugin( |
|
| 303 | - \OC::$server->getUserSession(), |
|
| 304 | - \OC::$server->getURLGenerator(), |
|
| 305 | - \OC::$server->getThemingDefaults(), |
|
| 306 | - \OC::$server->getRequest(), |
|
| 307 | - \OC::$server->getL10N('dav'), |
|
| 308 | - function () { |
|
| 309 | - return UUIDUtil::getUUID(); |
|
| 310 | - } |
|
| 311 | - )); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - // register plugins from apps |
|
| 315 | - $pluginManager = new PluginManager( |
|
| 316 | - \OC::$server, |
|
| 317 | - \OC::$server->getAppManager() |
|
| 318 | - ); |
|
| 319 | - foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
| 320 | - $this->server->addPlugin($appPlugin); |
|
| 321 | - } |
|
| 322 | - foreach ($pluginManager->getAppCollections() as $appCollection) { |
|
| 323 | - $root->addChild($appCollection); |
|
| 324 | - } |
|
| 325 | - }); |
|
| 326 | - |
|
| 327 | - $this->server->addPlugin( |
|
| 328 | - new PropfindCompressionPlugin() |
|
| 329 | - ); |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - public function exec() { |
|
| 333 | - $this->server->exec(); |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - private function requestIsForSubtree(array $subTrees): bool { |
|
| 337 | - foreach ($subTrees as $subTree) { |
|
| 338 | - $subTree = trim($subTree, ' /'); |
|
| 339 | - if (strpos($this->server->getRequestUri(), $subTree.'/') === 0) { |
|
| 340 | - return true; |
|
| 341 | - } |
|
| 342 | - } |
|
| 343 | - return false; |
|
| 344 | - } |
|
| 79 | + /** @var IRequest */ |
|
| 80 | + private $request; |
|
| 81 | + |
|
| 82 | + /** @var string */ |
|
| 83 | + private $baseUri; |
|
| 84 | + |
|
| 85 | + /** @var Connector\Sabre\Server */ |
|
| 86 | + public $server; |
|
| 87 | + |
|
| 88 | + public function __construct(IRequest $request, $baseUri) { |
|
| 89 | + $this->request = $request; |
|
| 90 | + $this->baseUri = $baseUri; |
|
| 91 | + $logger = \OC::$server->getLogger(); |
|
| 92 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 93 | + /** @var IEventDispatcher $newDispatcher */ |
|
| 94 | + $newDispatcher = \OC::$server->query(IEventDispatcher::class); |
|
| 95 | + |
|
| 96 | + $root = new RootCollection(); |
|
| 97 | + $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); |
|
| 98 | + |
|
| 99 | + // Add maintenance plugin |
|
| 100 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav'))); |
|
| 101 | + |
|
| 102 | + // Backends |
|
| 103 | + $authBackend = new Auth( |
|
| 104 | + \OC::$server->getSession(), |
|
| 105 | + \OC::$server->getUserSession(), |
|
| 106 | + \OC::$server->getRequest(), |
|
| 107 | + \OC::$server->getTwoFactorAuthManager(), |
|
| 108 | + \OC::$server->getBruteForceThrottler() |
|
| 109 | + ); |
|
| 110 | + |
|
| 111 | + // Set URL explicitly due to reverse-proxy situations |
|
| 112 | + $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
| 113 | + $this->server->setBaseUri($this->baseUri); |
|
| 114 | + |
|
| 115 | + $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
| 116 | + $this->server->addPlugin(new AnonymousOptionsPlugin()); |
|
| 117 | + $authPlugin = new Plugin(); |
|
| 118 | + $authPlugin->addBackend(new PublicAuth()); |
|
| 119 | + $this->server->addPlugin($authPlugin); |
|
| 120 | + |
|
| 121 | + // allow setup of additional auth backends |
|
| 122 | + $event = new SabrePluginEvent($this->server); |
|
| 123 | + $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
| 124 | + |
|
| 125 | + $newAuthEvent = new SabrePluginAuthInitEvent($this->server); |
|
| 126 | + $newDispatcher->dispatchTyped($newAuthEvent); |
|
| 127 | + |
|
| 128 | + $bearerAuthBackend = new BearerAuth( |
|
| 129 | + \OC::$server->getUserSession(), |
|
| 130 | + \OC::$server->getSession(), |
|
| 131 | + \OC::$server->getRequest() |
|
| 132 | + ); |
|
| 133 | + $authPlugin->addBackend($bearerAuthBackend); |
|
| 134 | + // because we are throwing exceptions this plugin has to be the last one |
|
| 135 | + $authPlugin->addBackend($authBackend); |
|
| 136 | + |
|
| 137 | + // debugging |
|
| 138 | + if (\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 139 | + $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
| 140 | + } else { |
|
| 141 | + $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
| 145 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
| 146 | + $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
| 147 | + |
|
| 148 | + // acl |
|
| 149 | + $acl = new DavAclPlugin(); |
|
| 150 | + $acl->principalCollectionSet = [ |
|
| 151 | + 'principals/users', |
|
| 152 | + 'principals/groups', |
|
| 153 | + 'principals/calendar-resources', |
|
| 154 | + 'principals/calendar-rooms', |
|
| 155 | + ]; |
|
| 156 | + $acl->defaultUsernamePath = 'principals/users'; |
|
| 157 | + $this->server->addPlugin($acl); |
|
| 158 | + |
|
| 159 | + // calendar plugins |
|
| 160 | + if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'system-calendars', 'principals'])) { |
|
| 161 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
| 162 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\ICSExportPlugin\ICSExportPlugin(\OC::$server->getConfig(), \OC::$server->getLogger())); |
|
| 163 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig())); |
|
| 164 | + if (\OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') { |
|
| 165 | + $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class)); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + $this->server->addPlugin(\OC::$server->get(\OCA\DAV\CalDAV\Trashbin\Plugin::class)); |
|
| 169 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\WebcalCaching\Plugin($request)); |
|
| 170 | + $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
| 171 | + |
|
| 172 | + $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
| 173 | + $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest(), \OC::$server->getConfig())); |
|
| 174 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
| 175 | + \OC::$server->getConfig(), |
|
| 176 | + \OC::$server->getURLGenerator() |
|
| 177 | + )); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + // addressbook plugins |
|
| 181 | + if ($this->requestIsForSubtree(['addressbooks', 'principals'])) { |
|
| 182 | + $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest(), \OC::$server->getConfig())); |
|
| 183 | + $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
| 184 | + $this->server->addPlugin(new VCFExportPlugin()); |
|
| 185 | + $this->server->addPlugin(new MultiGetExportPlugin()); |
|
| 186 | + $this->server->addPlugin(new HasPhotoPlugin()); |
|
| 187 | + $this->server->addPlugin(new ImageExportPlugin(new PhotoCache( |
|
| 188 | + \OC::$server->getAppDataDir('dav-photocache'), |
|
| 189 | + \OC::$server->getLogger()) |
|
| 190 | + )); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + // system tags plugins |
|
| 194 | + $this->server->addPlugin(new SystemTagPlugin( |
|
| 195 | + \OC::$server->getSystemTagManager(), |
|
| 196 | + \OC::$server->getGroupManager(), |
|
| 197 | + \OC::$server->getUserSession() |
|
| 198 | + )); |
|
| 199 | + |
|
| 200 | + // comments plugin |
|
| 201 | + $this->server->addPlugin(new CommentsPlugin( |
|
| 202 | + \OC::$server->getCommentsManager(), |
|
| 203 | + \OC::$server->getUserSession() |
|
| 204 | + )); |
|
| 205 | + |
|
| 206 | + $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
| 207 | + $this->server->addPlugin(new ChunkingPlugin()); |
|
| 208 | + |
|
| 209 | + // allow setup of additional plugins |
|
| 210 | + $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event); |
|
| 211 | + |
|
| 212 | + // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 213 | + // we do not provide locking we emulate it using a fake locking plugin. |
|
| 214 | + if ($request->isUserAgent([ |
|
| 215 | + '/WebDAVFS/', |
|
| 216 | + '/OneNote/', |
|
| 217 | + '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
| 218 | + ])) { |
|
| 219 | + $this->server->addPlugin(new FakeLockerPlugin()); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
| 223 | + $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + $lazySearchBackend = new LazySearchBackend(); |
|
| 227 | + $this->server->addPlugin(new SearchPlugin($lazySearchBackend)); |
|
| 228 | + |
|
| 229 | + // wait with registering these until auth is handled and the filesystem is setup |
|
| 230 | + $this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend) { |
|
| 231 | + // custom properties plugin must be the last one |
|
| 232 | + $userSession = \OC::$server->getUserSession(); |
|
| 233 | + $user = $userSession->getUser(); |
|
| 234 | + if ($user !== null) { |
|
| 235 | + $view = \OC\Files\Filesystem::getView(); |
|
| 236 | + $this->server->addPlugin( |
|
| 237 | + new FilesPlugin( |
|
| 238 | + $this->server->tree, |
|
| 239 | + \OC::$server->getConfig(), |
|
| 240 | + $this->request, |
|
| 241 | + \OC::$server->getPreviewManager(), |
|
| 242 | + false, |
|
| 243 | + !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
| 244 | + ) |
|
| 245 | + ); |
|
| 246 | + |
|
| 247 | + $this->server->addPlugin( |
|
| 248 | + new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 249 | + new CustomPropertiesBackend( |
|
| 250 | + $this->server->tree, |
|
| 251 | + \OC::$server->getDatabaseConnection(), |
|
| 252 | + \OC::$server->getUserSession()->getUser() |
|
| 253 | + ) |
|
| 254 | + ) |
|
| 255 | + ); |
|
| 256 | + if ($view !== null) { |
|
| 257 | + $this->server->addPlugin( |
|
| 258 | + new QuotaPlugin($view, false)); |
|
| 259 | + } |
|
| 260 | + $this->server->addPlugin( |
|
| 261 | + new TagsPlugin( |
|
| 262 | + $this->server->tree, \OC::$server->getTagManager() |
|
| 263 | + ) |
|
| 264 | + ); |
|
| 265 | + // TODO: switch to LazyUserFolder |
|
| 266 | + $userFolder = \OC::$server->getUserFolder(); |
|
| 267 | + $this->server->addPlugin(new SharesPlugin( |
|
| 268 | + $this->server->tree, |
|
| 269 | + $userSession, |
|
| 270 | + $userFolder, |
|
| 271 | + \OC::$server->getShareManager() |
|
| 272 | + )); |
|
| 273 | + $this->server->addPlugin(new CommentPropertiesPlugin( |
|
| 274 | + \OC::$server->getCommentsManager(), |
|
| 275 | + $userSession |
|
| 276 | + )); |
|
| 277 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
| 278 | + if ($view !== null) { |
|
| 279 | + $this->server->addPlugin(new FilesReportPlugin( |
|
| 280 | + $this->server->tree, |
|
| 281 | + $view, |
|
| 282 | + \OC::$server->getSystemTagManager(), |
|
| 283 | + \OC::$server->getSystemTagObjectMapper(), |
|
| 284 | + \OC::$server->getTagManager(), |
|
| 285 | + $userSession, |
|
| 286 | + \OC::$server->getGroupManager(), |
|
| 287 | + $userFolder, |
|
| 288 | + \OC::$server->getAppManager() |
|
| 289 | + )); |
|
| 290 | + $lazySearchBackend->setBackend(new \OCA\DAV\Files\FileSearchBackend( |
|
| 291 | + $this->server->tree, |
|
| 292 | + $user, |
|
| 293 | + \OC::$server->getRootFolder(), |
|
| 294 | + \OC::$server->getShareManager(), |
|
| 295 | + $view |
|
| 296 | + )); |
|
| 297 | + } |
|
| 298 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin( |
|
| 299 | + \OC::$server->getConfig(), |
|
| 300 | + \OC::$server->query(BirthdayService::class) |
|
| 301 | + )); |
|
| 302 | + $this->server->addPlugin(new AppleProvisioningPlugin( |
|
| 303 | + \OC::$server->getUserSession(), |
|
| 304 | + \OC::$server->getURLGenerator(), |
|
| 305 | + \OC::$server->getThemingDefaults(), |
|
| 306 | + \OC::$server->getRequest(), |
|
| 307 | + \OC::$server->getL10N('dav'), |
|
| 308 | + function () { |
|
| 309 | + return UUIDUtil::getUUID(); |
|
| 310 | + } |
|
| 311 | + )); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + // register plugins from apps |
|
| 315 | + $pluginManager = new PluginManager( |
|
| 316 | + \OC::$server, |
|
| 317 | + \OC::$server->getAppManager() |
|
| 318 | + ); |
|
| 319 | + foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
| 320 | + $this->server->addPlugin($appPlugin); |
|
| 321 | + } |
|
| 322 | + foreach ($pluginManager->getAppCollections() as $appCollection) { |
|
| 323 | + $root->addChild($appCollection); |
|
| 324 | + } |
|
| 325 | + }); |
|
| 326 | + |
|
| 327 | + $this->server->addPlugin( |
|
| 328 | + new PropfindCompressionPlugin() |
|
| 329 | + ); |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + public function exec() { |
|
| 333 | + $this->server->exec(); |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + private function requestIsForSubtree(array $subTrees): bool { |
|
| 337 | + foreach ($subTrees as $subTree) { |
|
| 338 | + $subTree = trim($subTree, ' /'); |
|
| 339 | + if (strpos($this->server->getRequestUri(), $subTree.'/') === 0) { |
|
| 340 | + return true; |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | + return false; |
|
| 344 | + } |
|
| 345 | 345 | } |
@@ -31,54 +31,54 @@ |
||
| 31 | 31 | use function max; |
| 32 | 32 | |
| 33 | 33 | class RetentionService { |
| 34 | - public const RETENTION_CONFIG_KEY = 'calendarRetentionObligation'; |
|
| 35 | - private const DEFAULT_RETENTION_SECONDS = 30 * 24 * 60 * 60; |
|
| 34 | + public const RETENTION_CONFIG_KEY = 'calendarRetentionObligation'; |
|
| 35 | + private const DEFAULT_RETENTION_SECONDS = 30 * 24 * 60 * 60; |
|
| 36 | 36 | |
| 37 | - /** @var IConfig */ |
|
| 38 | - private $config; |
|
| 37 | + /** @var IConfig */ |
|
| 38 | + private $config; |
|
| 39 | 39 | |
| 40 | - /** @var ITimeFactory */ |
|
| 41 | - private $time; |
|
| 40 | + /** @var ITimeFactory */ |
|
| 41 | + private $time; |
|
| 42 | 42 | |
| 43 | - /** @var CalDavBackend */ |
|
| 44 | - private $calDavBackend; |
|
| 43 | + /** @var CalDavBackend */ |
|
| 44 | + private $calDavBackend; |
|
| 45 | 45 | |
| 46 | - public function __construct(IConfig $config, |
|
| 47 | - ITimeFactory $time, |
|
| 48 | - CalDavBackend $calDavBackend) { |
|
| 49 | - $this->config = $config; |
|
| 50 | - $this->time = $time; |
|
| 51 | - $this->calDavBackend = $calDavBackend; |
|
| 52 | - } |
|
| 46 | + public function __construct(IConfig $config, |
|
| 47 | + ITimeFactory $time, |
|
| 48 | + CalDavBackend $calDavBackend) { |
|
| 49 | + $this->config = $config; |
|
| 50 | + $this->time = $time; |
|
| 51 | + $this->calDavBackend = $calDavBackend; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - public function getDuration(): int { |
|
| 55 | - return max( |
|
| 56 | - (int) $this->config->getAppValue( |
|
| 57 | - Application::APP_ID, |
|
| 58 | - self::RETENTION_CONFIG_KEY, |
|
| 59 | - (string) self::DEFAULT_RETENTION_SECONDS |
|
| 60 | - ), |
|
| 61 | - 0 // Just making sure we don't delete things in the future when a negative number is passed |
|
| 62 | - ); |
|
| 63 | - } |
|
| 54 | + public function getDuration(): int { |
|
| 55 | + return max( |
|
| 56 | + (int) $this->config->getAppValue( |
|
| 57 | + Application::APP_ID, |
|
| 58 | + self::RETENTION_CONFIG_KEY, |
|
| 59 | + (string) self::DEFAULT_RETENTION_SECONDS |
|
| 60 | + ), |
|
| 61 | + 0 // Just making sure we don't delete things in the future when a negative number is passed |
|
| 62 | + ); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - public function cleanUp(): void { |
|
| 66 | - $retentionTime = $this->getDuration(); |
|
| 67 | - $now = $this->time->getTime(); |
|
| 65 | + public function cleanUp(): void { |
|
| 66 | + $retentionTime = $this->getDuration(); |
|
| 67 | + $now = $this->time->getTime(); |
|
| 68 | 68 | |
| 69 | - $calendars = $this->calDavBackend->getDeletedCalendars($now - $retentionTime); |
|
| 70 | - foreach ($calendars as $calendar) { |
|
| 71 | - $this->calDavBackend->deleteCalendar($calendar['id'], true); |
|
| 72 | - } |
|
| 69 | + $calendars = $this->calDavBackend->getDeletedCalendars($now - $retentionTime); |
|
| 70 | + foreach ($calendars as $calendar) { |
|
| 71 | + $this->calDavBackend->deleteCalendar($calendar['id'], true); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - $objects = $this->calDavBackend->getDeletedCalendarObjects($now - $retentionTime); |
|
| 75 | - foreach ($objects as $object) { |
|
| 76 | - $this->calDavBackend->deleteCalendarObject( |
|
| 77 | - $object['calendarid'], |
|
| 78 | - $object['uri'], |
|
| 79 | - $object['calendartype'], |
|
| 80 | - true |
|
| 81 | - ); |
|
| 82 | - } |
|
| 83 | - } |
|
| 74 | + $objects = $this->calDavBackend->getDeletedCalendarObjects($now - $retentionTime); |
|
| 75 | + foreach ($objects as $object) { |
|
| 76 | + $this->calDavBackend->deleteCalendarObject( |
|
| 77 | + $object['calendarid'], |
|
| 78 | + $object['uri'], |
|
| 79 | + $object['calendartype'], |
|
| 80 | + true |
|
| 81 | + ); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | 84 | } |
@@ -40,85 +40,85 @@ |
||
| 40 | 40 | use function implode; |
| 41 | 41 | |
| 42 | 42 | class Plugin extends ServerPlugin { |
| 43 | - public const PROPERTY_DELETED_AT = '{http://nextcloud.com/ns}deleted-at'; |
|
| 44 | - public const PROPERTY_CALENDAR_URI = '{http://nextcloud.com/ns}calendar-uri'; |
|
| 45 | - public const PROPERTY_RETENTION_DURATION = '{http://nextcloud.com/ns}trash-bin-retention-duration'; |
|
| 46 | - |
|
| 47 | - /** @var bool */ |
|
| 48 | - private $disableTrashbin; |
|
| 49 | - |
|
| 50 | - /** @var RetentionService */ |
|
| 51 | - private $retentionService; |
|
| 52 | - |
|
| 53 | - /** @var Server */ |
|
| 54 | - private $server; |
|
| 55 | - |
|
| 56 | - public function __construct(IRequest $request, |
|
| 57 | - RetentionService $retentionService) { |
|
| 58 | - $this->disableTrashbin = $request->getHeader('X-NC-CalDAV-No-Trashbin') === '1'; |
|
| 59 | - $this->retentionService = $retentionService; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - public function initialize(Server $server): void { |
|
| 63 | - $this->server = $server; |
|
| 64 | - $server->on('beforeMethod:*', [$this, 'beforeMethod']); |
|
| 65 | - $server->on('propFind', Closure::fromCallable([$this, 'propFind'])); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - public function beforeMethod(RequestInterface $request, ResponseInterface $response): void { |
|
| 69 | - if (!$this->disableTrashbin) { |
|
| 70 | - return; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - $path = $request->getPath(); |
|
| 74 | - $pathParts = explode('/', ltrim($path, '/')); |
|
| 75 | - if (\count($pathParts) < 3) { |
|
| 76 | - // We are looking for a path like calendars/username/calendarname |
|
| 77 | - return; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // $calendarPath will look like calendars/username/calendarname |
|
| 81 | - $calendarPath = implode( |
|
| 82 | - '/', |
|
| 83 | - array_slice($pathParts, 0, 3) |
|
| 84 | - ); |
|
| 85 | - try { |
|
| 86 | - $calendar = $this->server->tree->getNodeForPath($calendarPath); |
|
| 87 | - if (!($calendar instanceof Calendar)) { |
|
| 88 | - // This is odd |
|
| 89 | - return; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** @var Calendar $calendar */ |
|
| 93 | - $calendar->disableTrashbin(); |
|
| 94 | - } catch (NotFound $ex) { |
|
| 95 | - return; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - private function propFind( |
|
| 100 | - PropFind $propFind, |
|
| 101 | - INode $node): void { |
|
| 102 | - if ($node instanceof DeletedCalendarObject) { |
|
| 103 | - $propFind->handle(self::PROPERTY_DELETED_AT, function () use ($node) { |
|
| 104 | - return $node->getDeletedAt(); |
|
| 105 | - }); |
|
| 106 | - $propFind->handle(self::PROPERTY_CALENDAR_URI, function () use ($node) { |
|
| 107 | - return $node->getCalendarUri(); |
|
| 108 | - }); |
|
| 109 | - } |
|
| 110 | - if ($node instanceof TrashbinHome) { |
|
| 111 | - $propFind->handle(self::PROPERTY_RETENTION_DURATION, function () use ($node) { |
|
| 112 | - return $this->retentionService->getDuration(); |
|
| 113 | - }); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - public function getFeatures(): array { |
|
| 118 | - return ['nc-calendar-trashbin']; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - public function getPluginName(): string { |
|
| 122 | - return 'nc-calendar-trashbin'; |
|
| 123 | - } |
|
| 43 | + public const PROPERTY_DELETED_AT = '{http://nextcloud.com/ns}deleted-at'; |
|
| 44 | + public const PROPERTY_CALENDAR_URI = '{http://nextcloud.com/ns}calendar-uri'; |
|
| 45 | + public const PROPERTY_RETENTION_DURATION = '{http://nextcloud.com/ns}trash-bin-retention-duration'; |
|
| 46 | + |
|
| 47 | + /** @var bool */ |
|
| 48 | + private $disableTrashbin; |
|
| 49 | + |
|
| 50 | + /** @var RetentionService */ |
|
| 51 | + private $retentionService; |
|
| 52 | + |
|
| 53 | + /** @var Server */ |
|
| 54 | + private $server; |
|
| 55 | + |
|
| 56 | + public function __construct(IRequest $request, |
|
| 57 | + RetentionService $retentionService) { |
|
| 58 | + $this->disableTrashbin = $request->getHeader('X-NC-CalDAV-No-Trashbin') === '1'; |
|
| 59 | + $this->retentionService = $retentionService; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + public function initialize(Server $server): void { |
|
| 63 | + $this->server = $server; |
|
| 64 | + $server->on('beforeMethod:*', [$this, 'beforeMethod']); |
|
| 65 | + $server->on('propFind', Closure::fromCallable([$this, 'propFind'])); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + public function beforeMethod(RequestInterface $request, ResponseInterface $response): void { |
|
| 69 | + if (!$this->disableTrashbin) { |
|
| 70 | + return; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + $path = $request->getPath(); |
|
| 74 | + $pathParts = explode('/', ltrim($path, '/')); |
|
| 75 | + if (\count($pathParts) < 3) { |
|
| 76 | + // We are looking for a path like calendars/username/calendarname |
|
| 77 | + return; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // $calendarPath will look like calendars/username/calendarname |
|
| 81 | + $calendarPath = implode( |
|
| 82 | + '/', |
|
| 83 | + array_slice($pathParts, 0, 3) |
|
| 84 | + ); |
|
| 85 | + try { |
|
| 86 | + $calendar = $this->server->tree->getNodeForPath($calendarPath); |
|
| 87 | + if (!($calendar instanceof Calendar)) { |
|
| 88 | + // This is odd |
|
| 89 | + return; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** @var Calendar $calendar */ |
|
| 93 | + $calendar->disableTrashbin(); |
|
| 94 | + } catch (NotFound $ex) { |
|
| 95 | + return; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + private function propFind( |
|
| 100 | + PropFind $propFind, |
|
| 101 | + INode $node): void { |
|
| 102 | + if ($node instanceof DeletedCalendarObject) { |
|
| 103 | + $propFind->handle(self::PROPERTY_DELETED_AT, function () use ($node) { |
|
| 104 | + return $node->getDeletedAt(); |
|
| 105 | + }); |
|
| 106 | + $propFind->handle(self::PROPERTY_CALENDAR_URI, function () use ($node) { |
|
| 107 | + return $node->getCalendarUri(); |
|
| 108 | + }); |
|
| 109 | + } |
|
| 110 | + if ($node instanceof TrashbinHome) { |
|
| 111 | + $propFind->handle(self::PROPERTY_RETENTION_DURATION, function () use ($node) { |
|
| 112 | + return $this->retentionService->getDuration(); |
|
| 113 | + }); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + public function getFeatures(): array { |
|
| 118 | + return ['nc-calendar-trashbin']; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + public function getPluginName(): string { |
|
| 122 | + return 'nc-calendar-trashbin'; |
|
| 123 | + } |
|
| 124 | 124 | } |
@@ -100,15 +100,15 @@ |
||
| 100 | 100 | PropFind $propFind, |
| 101 | 101 | INode $node): void { |
| 102 | 102 | if ($node instanceof DeletedCalendarObject) { |
| 103 | - $propFind->handle(self::PROPERTY_DELETED_AT, function () use ($node) { |
|
| 103 | + $propFind->handle(self::PROPERTY_DELETED_AT, function() use ($node) { |
|
| 104 | 104 | return $node->getDeletedAt(); |
| 105 | 105 | }); |
| 106 | - $propFind->handle(self::PROPERTY_CALENDAR_URI, function () use ($node) { |
|
| 106 | + $propFind->handle(self::PROPERTY_CALENDAR_URI, function() use ($node) { |
|
| 107 | 107 | return $node->getCalendarUri(); |
| 108 | 108 | }); |
| 109 | 109 | } |
| 110 | 110 | if ($node instanceof TrashbinHome) { |
| 111 | - $propFind->handle(self::PROPERTY_RETENTION_DURATION, function () use ($node) { |
|
| 111 | + $propFind->handle(self::PROPERTY_RETENTION_DURATION, function() use ($node) { |
|
| 112 | 112 | return $this->retentionService->getDuration(); |
| 113 | 113 | }); |
| 114 | 114 | } |