@@ -64,215 +64,215 @@ |
||
| 64 | 64 | |
| 65 | 65 | class Server { |
| 66 | 66 | |
| 67 | - /** @var IRequest */ |
|
| 68 | - private $request; |
|
| 67 | + /** @var IRequest */ |
|
| 68 | + private $request; |
|
| 69 | 69 | |
| 70 | - /** @var string */ |
|
| 71 | - private $baseUri; |
|
| 70 | + /** @var string */ |
|
| 71 | + private $baseUri; |
|
| 72 | 72 | |
| 73 | - /** @var Connector\Sabre\Server */ |
|
| 74 | - private $server; |
|
| 73 | + /** @var Connector\Sabre\Server */ |
|
| 74 | + private $server; |
|
| 75 | 75 | |
| 76 | - public function __construct(IRequest $request, $baseUri) { |
|
| 77 | - $this->request = $request; |
|
| 78 | - $this->baseUri = $baseUri; |
|
| 79 | - $logger = \OC::$server->getLogger(); |
|
| 80 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 81 | - $sendInvitations = \OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes'; |
|
| 76 | + public function __construct(IRequest $request, $baseUri) { |
|
| 77 | + $this->request = $request; |
|
| 78 | + $this->baseUri = $baseUri; |
|
| 79 | + $logger = \OC::$server->getLogger(); |
|
| 80 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 81 | + $sendInvitations = \OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes'; |
|
| 82 | 82 | |
| 83 | - $root = new RootCollection(); |
|
| 84 | - $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); |
|
| 83 | + $root = new RootCollection(); |
|
| 84 | + $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); |
|
| 85 | 85 | |
| 86 | - // Add maintenance plugin |
|
| 87 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig())); |
|
| 86 | + // Add maintenance plugin |
|
| 87 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig())); |
|
| 88 | 88 | |
| 89 | - // Backends |
|
| 90 | - $authBackend = new Auth( |
|
| 91 | - \OC::$server->getSession(), |
|
| 92 | - \OC::$server->getUserSession(), |
|
| 93 | - \OC::$server->getRequest(), |
|
| 94 | - \OC::$server->getTwoFactorAuthManager(), |
|
| 95 | - \OC::$server->getBruteForceThrottler() |
|
| 96 | - ); |
|
| 89 | + // Backends |
|
| 90 | + $authBackend = new Auth( |
|
| 91 | + \OC::$server->getSession(), |
|
| 92 | + \OC::$server->getUserSession(), |
|
| 93 | + \OC::$server->getRequest(), |
|
| 94 | + \OC::$server->getTwoFactorAuthManager(), |
|
| 95 | + \OC::$server->getBruteForceThrottler() |
|
| 96 | + ); |
|
| 97 | 97 | |
| 98 | - // Set URL explicitly due to reverse-proxy situations |
|
| 99 | - $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
| 100 | - $this->server->setBaseUri($this->baseUri); |
|
| 98 | + // Set URL explicitly due to reverse-proxy situations |
|
| 99 | + $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
| 100 | + $this->server->setBaseUri($this->baseUri); |
|
| 101 | 101 | |
| 102 | - $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
| 103 | - $authPlugin = new Plugin(); |
|
| 104 | - $authPlugin->addBackend(new PublicAuth()); |
|
| 105 | - $this->server->addPlugin($authPlugin); |
|
| 102 | + $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
| 103 | + $authPlugin = new Plugin(); |
|
| 104 | + $authPlugin->addBackend(new PublicAuth()); |
|
| 105 | + $this->server->addPlugin($authPlugin); |
|
| 106 | 106 | |
| 107 | - // allow setup of additional auth backends |
|
| 108 | - $event = new SabrePluginEvent($this->server); |
|
| 109 | - $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
| 107 | + // allow setup of additional auth backends |
|
| 108 | + $event = new SabrePluginEvent($this->server); |
|
| 109 | + $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
| 110 | 110 | |
| 111 | - $bearerAuthBackend = new BearerAuth( |
|
| 112 | - \OC::$server->getUserSession(), |
|
| 113 | - \OC::$server->getSession(), |
|
| 114 | - \OC::$server->getRequest() |
|
| 115 | - ); |
|
| 116 | - $authPlugin->addBackend($bearerAuthBackend); |
|
| 117 | - // because we are throwing exceptions this plugin has to be the last one |
|
| 118 | - $authPlugin->addBackend($authBackend); |
|
| 111 | + $bearerAuthBackend = new BearerAuth( |
|
| 112 | + \OC::$server->getUserSession(), |
|
| 113 | + \OC::$server->getSession(), |
|
| 114 | + \OC::$server->getRequest() |
|
| 115 | + ); |
|
| 116 | + $authPlugin->addBackend($bearerAuthBackend); |
|
| 117 | + // because we are throwing exceptions this plugin has to be the last one |
|
| 118 | + $authPlugin->addBackend($authBackend); |
|
| 119 | 119 | |
| 120 | - // debugging |
|
| 121 | - if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 122 | - $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
| 123 | - } else { |
|
| 124 | - $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
| 125 | - } |
|
| 120 | + // debugging |
|
| 121 | + if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 122 | + $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
| 123 | + } else { |
|
| 124 | + $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
| 128 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
| 129 | - $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
| 127 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
| 128 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
| 129 | + $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
| 130 | 130 | |
| 131 | - // acl |
|
| 132 | - $acl = new DavAclPlugin(); |
|
| 133 | - $acl->principalCollectionSet = [ |
|
| 134 | - 'principals/users', 'principals/groups' |
|
| 135 | - ]; |
|
| 136 | - $acl->defaultUsernamePath = 'principals/users'; |
|
| 137 | - $this->server->addPlugin($acl); |
|
| 131 | + // acl |
|
| 132 | + $acl = new DavAclPlugin(); |
|
| 133 | + $acl->principalCollectionSet = [ |
|
| 134 | + 'principals/users', 'principals/groups' |
|
| 135 | + ]; |
|
| 136 | + $acl->defaultUsernamePath = 'principals/users'; |
|
| 137 | + $this->server->addPlugin($acl); |
|
| 138 | 138 | |
| 139 | - // calendar plugins |
|
| 140 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
| 141 | - $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); |
|
| 142 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
|
| 143 | - if ($sendInvitations) { |
|
| 144 | - $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class)); |
|
| 145 | - } |
|
| 146 | - $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
| 147 | - $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
| 148 | - $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
| 149 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
| 150 | - \OC::$server->getConfig(), |
|
| 151 | - \OC::$server->getURLGenerator() |
|
| 152 | - )); |
|
| 139 | + // calendar plugins |
|
| 140 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
| 141 | + $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); |
|
| 142 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
|
| 143 | + if ($sendInvitations) { |
|
| 144 | + $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class)); |
|
| 145 | + } |
|
| 146 | + $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
| 147 | + $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
| 148 | + $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
| 149 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
| 150 | + \OC::$server->getConfig(), |
|
| 151 | + \OC::$server->getURLGenerator() |
|
| 152 | + )); |
|
| 153 | 153 | |
| 154 | - // addressbook plugins |
|
| 155 | - $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
| 156 | - $this->server->addPlugin(new VCFExportPlugin()); |
|
| 157 | - $this->server->addPlugin(new ImageExportPlugin(new PhotoCache(\OC::$server->getAppDataDir('dav-photocache')))); |
|
| 154 | + // addressbook plugins |
|
| 155 | + $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
| 156 | + $this->server->addPlugin(new VCFExportPlugin()); |
|
| 157 | + $this->server->addPlugin(new ImageExportPlugin(new PhotoCache(\OC::$server->getAppDataDir('dav-photocache')))); |
|
| 158 | 158 | |
| 159 | - // system tags plugins |
|
| 160 | - $this->server->addPlugin(new SystemTagPlugin( |
|
| 161 | - \OC::$server->getSystemTagManager(), |
|
| 162 | - \OC::$server->getGroupManager(), |
|
| 163 | - \OC::$server->getUserSession() |
|
| 164 | - )); |
|
| 159 | + // system tags plugins |
|
| 160 | + $this->server->addPlugin(new SystemTagPlugin( |
|
| 161 | + \OC::$server->getSystemTagManager(), |
|
| 162 | + \OC::$server->getGroupManager(), |
|
| 163 | + \OC::$server->getUserSession() |
|
| 164 | + )); |
|
| 165 | 165 | |
| 166 | - // comments plugin |
|
| 167 | - $this->server->addPlugin(new CommentsPlugin( |
|
| 168 | - \OC::$server->getCommentsManager(), |
|
| 169 | - \OC::$server->getUserSession() |
|
| 170 | - )); |
|
| 166 | + // comments plugin |
|
| 167 | + $this->server->addPlugin(new CommentsPlugin( |
|
| 168 | + \OC::$server->getCommentsManager(), |
|
| 169 | + \OC::$server->getUserSession() |
|
| 170 | + )); |
|
| 171 | 171 | |
| 172 | - $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
| 172 | + $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
| 173 | 173 | |
| 174 | - // allow setup of additional plugins |
|
| 175 | - $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event); |
|
| 174 | + // allow setup of additional plugins |
|
| 175 | + $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event); |
|
| 176 | 176 | |
| 177 | - // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 178 | - // we do not provide locking we emulate it using a fake locking plugin. |
|
| 179 | - if($request->isUserAgent([ |
|
| 180 | - '/WebDAVFS/', |
|
| 181 | - '/Microsoft Office OneNote 2013/', |
|
| 182 | - '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
| 183 | - ])) { |
|
| 184 | - $this->server->addPlugin(new FakeLockerPlugin()); |
|
| 185 | - } |
|
| 177 | + // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 178 | + // we do not provide locking we emulate it using a fake locking plugin. |
|
| 179 | + if($request->isUserAgent([ |
|
| 180 | + '/WebDAVFS/', |
|
| 181 | + '/Microsoft Office OneNote 2013/', |
|
| 182 | + '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
| 183 | + ])) { |
|
| 184 | + $this->server->addPlugin(new FakeLockerPlugin()); |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
| 188 | - $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 189 | - } |
|
| 187 | + if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
| 188 | + $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | - // wait with registering these until auth is handled and the filesystem is setup |
|
| 192 | - $this->server->on('beforeMethod', function () use ($root) { |
|
| 193 | - // custom properties plugin must be the last one |
|
| 194 | - $userSession = \OC::$server->getUserSession(); |
|
| 195 | - $user = $userSession->getUser(); |
|
| 196 | - if ($user !== null) { |
|
| 197 | - $view = \OC\Files\Filesystem::getView(); |
|
| 198 | - $this->server->addPlugin( |
|
| 199 | - new FilesPlugin( |
|
| 200 | - $this->server->tree, |
|
| 201 | - \OC::$server->getConfig(), |
|
| 202 | - $this->request, |
|
| 203 | - \OC::$server->getPreviewManager(), |
|
| 204 | - false, |
|
| 205 | - !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
| 206 | - ) |
|
| 207 | - ); |
|
| 191 | + // wait with registering these until auth is handled and the filesystem is setup |
|
| 192 | + $this->server->on('beforeMethod', function () use ($root) { |
|
| 193 | + // custom properties plugin must be the last one |
|
| 194 | + $userSession = \OC::$server->getUserSession(); |
|
| 195 | + $user = $userSession->getUser(); |
|
| 196 | + if ($user !== null) { |
|
| 197 | + $view = \OC\Files\Filesystem::getView(); |
|
| 198 | + $this->server->addPlugin( |
|
| 199 | + new FilesPlugin( |
|
| 200 | + $this->server->tree, |
|
| 201 | + \OC::$server->getConfig(), |
|
| 202 | + $this->request, |
|
| 203 | + \OC::$server->getPreviewManager(), |
|
| 204 | + false, |
|
| 205 | + !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
| 206 | + ) |
|
| 207 | + ); |
|
| 208 | 208 | |
| 209 | - $this->server->addPlugin( |
|
| 210 | - new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 211 | - new CustomPropertiesBackend( |
|
| 212 | - $this->server->tree, |
|
| 213 | - \OC::$server->getDatabaseConnection(), |
|
| 214 | - \OC::$server->getUserSession()->getUser() |
|
| 215 | - ) |
|
| 216 | - ) |
|
| 217 | - ); |
|
| 218 | - if ($view !== null) { |
|
| 219 | - $this->server->addPlugin( |
|
| 220 | - new QuotaPlugin($view, false)); |
|
| 221 | - } |
|
| 222 | - $this->server->addPlugin( |
|
| 223 | - new TagsPlugin( |
|
| 224 | - $this->server->tree, \OC::$server->getTagManager() |
|
| 225 | - ) |
|
| 226 | - ); |
|
| 227 | - // TODO: switch to LazyUserFolder |
|
| 228 | - $userFolder = \OC::$server->getUserFolder(); |
|
| 229 | - $this->server->addPlugin(new SharesPlugin( |
|
| 230 | - $this->server->tree, |
|
| 231 | - $userSession, |
|
| 232 | - $userFolder, |
|
| 233 | - \OC::$server->getShareManager() |
|
| 234 | - )); |
|
| 235 | - $this->server->addPlugin(new CommentPropertiesPlugin( |
|
| 236 | - \OC::$server->getCommentsManager(), |
|
| 237 | - $userSession |
|
| 238 | - )); |
|
| 239 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
| 240 | - if ($view !== null) { |
|
| 241 | - $this->server->addPlugin(new FilesReportPlugin( |
|
| 242 | - $this->server->tree, |
|
| 243 | - $view, |
|
| 244 | - \OC::$server->getSystemTagManager(), |
|
| 245 | - \OC::$server->getSystemTagObjectMapper(), |
|
| 246 | - \OC::$server->getTagManager(), |
|
| 247 | - $userSession, |
|
| 248 | - \OC::$server->getGroupManager(), |
|
| 249 | - $userFolder |
|
| 250 | - )); |
|
| 251 | - $this->server->addPlugin(new SearchPlugin(new \OCA\DAV\Files\FileSearchBackend( |
|
| 252 | - $this->server->tree, |
|
| 253 | - $user, |
|
| 254 | - \OC::$server->getRootFolder(), |
|
| 255 | - \OC::$server->getShareManager(), |
|
| 256 | - $view |
|
| 257 | - ))); |
|
| 258 | - } |
|
| 259 | - } |
|
| 209 | + $this->server->addPlugin( |
|
| 210 | + new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 211 | + new CustomPropertiesBackend( |
|
| 212 | + $this->server->tree, |
|
| 213 | + \OC::$server->getDatabaseConnection(), |
|
| 214 | + \OC::$server->getUserSession()->getUser() |
|
| 215 | + ) |
|
| 216 | + ) |
|
| 217 | + ); |
|
| 218 | + if ($view !== null) { |
|
| 219 | + $this->server->addPlugin( |
|
| 220 | + new QuotaPlugin($view, false)); |
|
| 221 | + } |
|
| 222 | + $this->server->addPlugin( |
|
| 223 | + new TagsPlugin( |
|
| 224 | + $this->server->tree, \OC::$server->getTagManager() |
|
| 225 | + ) |
|
| 226 | + ); |
|
| 227 | + // TODO: switch to LazyUserFolder |
|
| 228 | + $userFolder = \OC::$server->getUserFolder(); |
|
| 229 | + $this->server->addPlugin(new SharesPlugin( |
|
| 230 | + $this->server->tree, |
|
| 231 | + $userSession, |
|
| 232 | + $userFolder, |
|
| 233 | + \OC::$server->getShareManager() |
|
| 234 | + )); |
|
| 235 | + $this->server->addPlugin(new CommentPropertiesPlugin( |
|
| 236 | + \OC::$server->getCommentsManager(), |
|
| 237 | + $userSession |
|
| 238 | + )); |
|
| 239 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
| 240 | + if ($view !== null) { |
|
| 241 | + $this->server->addPlugin(new FilesReportPlugin( |
|
| 242 | + $this->server->tree, |
|
| 243 | + $view, |
|
| 244 | + \OC::$server->getSystemTagManager(), |
|
| 245 | + \OC::$server->getSystemTagObjectMapper(), |
|
| 246 | + \OC::$server->getTagManager(), |
|
| 247 | + $userSession, |
|
| 248 | + \OC::$server->getGroupManager(), |
|
| 249 | + $userFolder |
|
| 250 | + )); |
|
| 251 | + $this->server->addPlugin(new SearchPlugin(new \OCA\DAV\Files\FileSearchBackend( |
|
| 252 | + $this->server->tree, |
|
| 253 | + $user, |
|
| 254 | + \OC::$server->getRootFolder(), |
|
| 255 | + \OC::$server->getShareManager(), |
|
| 256 | + $view |
|
| 257 | + ))); |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - // register plugins from apps |
|
| 262 | - $pluginManager = new PluginManager( |
|
| 263 | - \OC::$server, |
|
| 264 | - \OC::$server->getAppManager() |
|
| 265 | - ); |
|
| 266 | - foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
| 267 | - $this->server->addPlugin($appPlugin); |
|
| 268 | - } |
|
| 269 | - foreach ($pluginManager->getAppCollections() as $appCollection) { |
|
| 270 | - $root->addChild($appCollection); |
|
| 271 | - } |
|
| 272 | - }); |
|
| 273 | - } |
|
| 261 | + // register plugins from apps |
|
| 262 | + $pluginManager = new PluginManager( |
|
| 263 | + \OC::$server, |
|
| 264 | + \OC::$server->getAppManager() |
|
| 265 | + ); |
|
| 266 | + foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
| 267 | + $this->server->addPlugin($appPlugin); |
|
| 268 | + } |
|
| 269 | + foreach ($pluginManager->getAppCollections() as $appCollection) { |
|
| 270 | + $root->addChild($appCollection); |
|
| 271 | + } |
|
| 272 | + }); |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | - public function exec() { |
|
| 276 | - $this->server->exec(); |
|
| 277 | - } |
|
| 275 | + public function exec() { |
|
| 276 | + $this->server->exec(); |
|
| 277 | + } |
|
| 278 | 278 | } |