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