@@ -42,159 +42,159 @@ |
||
| 42 | 42 | use Sabre\DAV\Auth\Plugin; |
| 43 | 43 | |
| 44 | 44 | class ServerFactory { |
| 45 | - /** @var IConfig */ |
|
| 46 | - private $config; |
|
| 47 | - /** @var ILogger */ |
|
| 48 | - private $logger; |
|
| 49 | - /** @var IDBConnection */ |
|
| 50 | - private $databaseConnection; |
|
| 51 | - /** @var IUserSession */ |
|
| 52 | - private $userSession; |
|
| 53 | - /** @var IMountManager */ |
|
| 54 | - private $mountManager; |
|
| 55 | - /** @var ITagManager */ |
|
| 56 | - private $tagManager; |
|
| 57 | - /** @var IRequest */ |
|
| 58 | - private $request; |
|
| 59 | - /** @var IPreview */ |
|
| 60 | - private $previewManager; |
|
| 45 | + /** @var IConfig */ |
|
| 46 | + private $config; |
|
| 47 | + /** @var ILogger */ |
|
| 48 | + private $logger; |
|
| 49 | + /** @var IDBConnection */ |
|
| 50 | + private $databaseConnection; |
|
| 51 | + /** @var IUserSession */ |
|
| 52 | + private $userSession; |
|
| 53 | + /** @var IMountManager */ |
|
| 54 | + private $mountManager; |
|
| 55 | + /** @var ITagManager */ |
|
| 56 | + private $tagManager; |
|
| 57 | + /** @var IRequest */ |
|
| 58 | + private $request; |
|
| 59 | + /** @var IPreview */ |
|
| 60 | + private $previewManager; |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @param IConfig $config |
|
| 64 | - * @param ILogger $logger |
|
| 65 | - * @param IDBConnection $databaseConnection |
|
| 66 | - * @param IUserSession $userSession |
|
| 67 | - * @param IMountManager $mountManager |
|
| 68 | - * @param ITagManager $tagManager |
|
| 69 | - * @param IRequest $request |
|
| 70 | - * @param IPreview $previewManager |
|
| 71 | - */ |
|
| 72 | - public function __construct( |
|
| 73 | - IConfig $config, |
|
| 74 | - ILogger $logger, |
|
| 75 | - IDBConnection $databaseConnection, |
|
| 76 | - IUserSession $userSession, |
|
| 77 | - IMountManager $mountManager, |
|
| 78 | - ITagManager $tagManager, |
|
| 79 | - IRequest $request, |
|
| 80 | - IPreview $previewManager |
|
| 81 | - ) { |
|
| 82 | - $this->config = $config; |
|
| 83 | - $this->logger = $logger; |
|
| 84 | - $this->databaseConnection = $databaseConnection; |
|
| 85 | - $this->userSession = $userSession; |
|
| 86 | - $this->mountManager = $mountManager; |
|
| 87 | - $this->tagManager = $tagManager; |
|
| 88 | - $this->request = $request; |
|
| 89 | - $this->previewManager = $previewManager; |
|
| 90 | - } |
|
| 62 | + /** |
|
| 63 | + * @param IConfig $config |
|
| 64 | + * @param ILogger $logger |
|
| 65 | + * @param IDBConnection $databaseConnection |
|
| 66 | + * @param IUserSession $userSession |
|
| 67 | + * @param IMountManager $mountManager |
|
| 68 | + * @param ITagManager $tagManager |
|
| 69 | + * @param IRequest $request |
|
| 70 | + * @param IPreview $previewManager |
|
| 71 | + */ |
|
| 72 | + public function __construct( |
|
| 73 | + IConfig $config, |
|
| 74 | + ILogger $logger, |
|
| 75 | + IDBConnection $databaseConnection, |
|
| 76 | + IUserSession $userSession, |
|
| 77 | + IMountManager $mountManager, |
|
| 78 | + ITagManager $tagManager, |
|
| 79 | + IRequest $request, |
|
| 80 | + IPreview $previewManager |
|
| 81 | + ) { |
|
| 82 | + $this->config = $config; |
|
| 83 | + $this->logger = $logger; |
|
| 84 | + $this->databaseConnection = $databaseConnection; |
|
| 85 | + $this->userSession = $userSession; |
|
| 86 | + $this->mountManager = $mountManager; |
|
| 87 | + $this->tagManager = $tagManager; |
|
| 88 | + $this->request = $request; |
|
| 89 | + $this->previewManager = $previewManager; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * @param string $baseUri |
|
| 94 | - * @param string $requestUri |
|
| 95 | - * @param Plugin $authPlugin |
|
| 96 | - * @param callable $viewCallBack callback that should return the view for the dav endpoint |
|
| 97 | - * @return Server |
|
| 98 | - */ |
|
| 99 | - public function createServer($baseUri, |
|
| 100 | - $requestUri, |
|
| 101 | - Plugin $authPlugin, |
|
| 102 | - callable $viewCallBack) { |
|
| 103 | - // Fire up server |
|
| 104 | - $objectTree = new \OCA\DAV\Connector\Sabre\ObjectTree(); |
|
| 105 | - $server = new \OCA\DAV\Connector\Sabre\Server($objectTree); |
|
| 106 | - // Set URL explicitly due to reverse-proxy situations |
|
| 107 | - $server->httpRequest->setUrl($requestUri); |
|
| 108 | - $server->setBaseUri($baseUri); |
|
| 92 | + /** |
|
| 93 | + * @param string $baseUri |
|
| 94 | + * @param string $requestUri |
|
| 95 | + * @param Plugin $authPlugin |
|
| 96 | + * @param callable $viewCallBack callback that should return the view for the dav endpoint |
|
| 97 | + * @return Server |
|
| 98 | + */ |
|
| 99 | + public function createServer($baseUri, |
|
| 100 | + $requestUri, |
|
| 101 | + Plugin $authPlugin, |
|
| 102 | + callable $viewCallBack) { |
|
| 103 | + // Fire up server |
|
| 104 | + $objectTree = new \OCA\DAV\Connector\Sabre\ObjectTree(); |
|
| 105 | + $server = new \OCA\DAV\Connector\Sabre\Server($objectTree); |
|
| 106 | + // Set URL explicitly due to reverse-proxy situations |
|
| 107 | + $server->httpRequest->setUrl($requestUri); |
|
| 108 | + $server->setBaseUri($baseUri); |
|
| 109 | 109 | |
| 110 | - // Load plugins |
|
| 111 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config)); |
|
| 112 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin($this->config)); |
|
| 113 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\AnonymousOptionsPlugin()); |
|
| 114 | - $server->addPlugin($authPlugin); |
|
| 115 | - // FIXME: The following line is a workaround for legacy components relying on being able to send a GET to / |
|
| 116 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\DummyGetResponsePlugin()); |
|
| 117 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger)); |
|
| 118 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
| 119 | - // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 120 | - // we do not provide locking we emulate it using a fake locking plugin. |
|
| 121 | - if($this->request->isUserAgent([ |
|
| 122 | - '/WebDAVFS/', |
|
| 123 | - '/OneNote/', |
|
| 124 | - '/Microsoft-WebDAV-MiniRedir/', |
|
| 125 | - ])) { |
|
| 126 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin()); |
|
| 127 | - } |
|
| 110 | + // Load plugins |
|
| 111 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config)); |
|
| 112 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin($this->config)); |
|
| 113 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\AnonymousOptionsPlugin()); |
|
| 114 | + $server->addPlugin($authPlugin); |
|
| 115 | + // FIXME: The following line is a workaround for legacy components relying on being able to send a GET to / |
|
| 116 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\DummyGetResponsePlugin()); |
|
| 117 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger)); |
|
| 118 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
| 119 | + // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 120 | + // we do not provide locking we emulate it using a fake locking plugin. |
|
| 121 | + if($this->request->isUserAgent([ |
|
| 122 | + '/WebDAVFS/', |
|
| 123 | + '/OneNote/', |
|
| 124 | + '/Microsoft-WebDAV-MiniRedir/', |
|
| 125 | + ])) { |
|
| 126 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin()); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - if (BrowserErrorPagePlugin::isBrowserRequest($this->request)) { |
|
| 130 | - $server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 131 | - } |
|
| 129 | + if (BrowserErrorPagePlugin::isBrowserRequest($this->request)) { |
|
| 130 | + $server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - // wait with registering these until auth is handled and the filesystem is setup |
|
| 134 | - $server->on('beforeMethod', function () use ($server, $objectTree, $viewCallBack) { |
|
| 135 | - // ensure the skeleton is copied |
|
| 136 | - $userFolder = \OC::$server->getUserFolder(); |
|
| 133 | + // wait with registering these until auth is handled and the filesystem is setup |
|
| 134 | + $server->on('beforeMethod', function () use ($server, $objectTree, $viewCallBack) { |
|
| 135 | + // ensure the skeleton is copied |
|
| 136 | + $userFolder = \OC::$server->getUserFolder(); |
|
| 137 | 137 | |
| 138 | - /** @var \OC\Files\View $view */ |
|
| 139 | - $view = $viewCallBack($server); |
|
| 140 | - if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) { |
|
| 141 | - $rootInfo = $userFolder; |
|
| 142 | - } else { |
|
| 143 | - $rootInfo = $view->getFileInfo(''); |
|
| 144 | - } |
|
| 138 | + /** @var \OC\Files\View $view */ |
|
| 139 | + $view = $viewCallBack($server); |
|
| 140 | + if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) { |
|
| 141 | + $rootInfo = $userFolder; |
|
| 142 | + } else { |
|
| 143 | + $rootInfo = $view->getFileInfo(''); |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - // Create Nextcloud Dir |
|
| 147 | - if ($rootInfo->getType() === 'dir') { |
|
| 148 | - $root = new \OCA\DAV\Connector\Sabre\Directory($view, $rootInfo, $objectTree); |
|
| 149 | - } else { |
|
| 150 | - $root = new \OCA\DAV\Connector\Sabre\File($view, $rootInfo); |
|
| 151 | - } |
|
| 152 | - $objectTree->init($root, $view, $this->mountManager); |
|
| 146 | + // Create Nextcloud Dir |
|
| 147 | + if ($rootInfo->getType() === 'dir') { |
|
| 148 | + $root = new \OCA\DAV\Connector\Sabre\Directory($view, $rootInfo, $objectTree); |
|
| 149 | + } else { |
|
| 150 | + $root = new \OCA\DAV\Connector\Sabre\File($view, $rootInfo); |
|
| 151 | + } |
|
| 152 | + $objectTree->init($root, $view, $this->mountManager); |
|
| 153 | 153 | |
| 154 | - $server->addPlugin( |
|
| 155 | - new \OCA\DAV\Connector\Sabre\FilesPlugin( |
|
| 156 | - $objectTree, |
|
| 157 | - $this->config, |
|
| 158 | - $this->request, |
|
| 159 | - $this->previewManager, |
|
| 160 | - false, |
|
| 161 | - !$this->config->getSystemValue('debug', false) |
|
| 162 | - ) |
|
| 163 | - ); |
|
| 164 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view, true)); |
|
| 154 | + $server->addPlugin( |
|
| 155 | + new \OCA\DAV\Connector\Sabre\FilesPlugin( |
|
| 156 | + $objectTree, |
|
| 157 | + $this->config, |
|
| 158 | + $this->request, |
|
| 159 | + $this->previewManager, |
|
| 160 | + false, |
|
| 161 | + !$this->config->getSystemValue('debug', false) |
|
| 162 | + ) |
|
| 163 | + ); |
|
| 164 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view, true)); |
|
| 165 | 165 | |
| 166 | - if($this->userSession->isLoggedIn()) { |
|
| 167 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager)); |
|
| 168 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin( |
|
| 169 | - $objectTree, |
|
| 170 | - $this->userSession, |
|
| 171 | - $userFolder, |
|
| 172 | - \OC::$server->getShareManager() |
|
| 173 | - )); |
|
| 174 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\CommentPropertiesPlugin(\OC::$server->getCommentsManager(), $this->userSession)); |
|
| 175 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesReportPlugin( |
|
| 176 | - $objectTree, |
|
| 177 | - $view, |
|
| 178 | - \OC::$server->getSystemTagManager(), |
|
| 179 | - \OC::$server->getSystemTagObjectMapper(), |
|
| 180 | - \OC::$server->getTagManager(), |
|
| 181 | - $this->userSession, |
|
| 182 | - \OC::$server->getGroupManager(), |
|
| 183 | - $userFolder |
|
| 184 | - )); |
|
| 185 | - // custom properties plugin must be the last one |
|
| 186 | - $server->addPlugin( |
|
| 187 | - new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 188 | - new \OCA\DAV\Connector\Sabre\CustomPropertiesBackend( |
|
| 189 | - $objectTree, |
|
| 190 | - $this->databaseConnection, |
|
| 191 | - $this->userSession->getUser() |
|
| 192 | - ) |
|
| 193 | - ) |
|
| 194 | - ); |
|
| 195 | - } |
|
| 196 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin()); |
|
| 197 | - }, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request |
|
| 198 | - return $server; |
|
| 199 | - } |
|
| 166 | + if($this->userSession->isLoggedIn()) { |
|
| 167 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager)); |
|
| 168 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin( |
|
| 169 | + $objectTree, |
|
| 170 | + $this->userSession, |
|
| 171 | + $userFolder, |
|
| 172 | + \OC::$server->getShareManager() |
|
| 173 | + )); |
|
| 174 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\CommentPropertiesPlugin(\OC::$server->getCommentsManager(), $this->userSession)); |
|
| 175 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesReportPlugin( |
|
| 176 | + $objectTree, |
|
| 177 | + $view, |
|
| 178 | + \OC::$server->getSystemTagManager(), |
|
| 179 | + \OC::$server->getSystemTagObjectMapper(), |
|
| 180 | + \OC::$server->getTagManager(), |
|
| 181 | + $this->userSession, |
|
| 182 | + \OC::$server->getGroupManager(), |
|
| 183 | + $userFolder |
|
| 184 | + )); |
|
| 185 | + // custom properties plugin must be the last one |
|
| 186 | + $server->addPlugin( |
|
| 187 | + new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 188 | + new \OCA\DAV\Connector\Sabre\CustomPropertiesBackend( |
|
| 189 | + $objectTree, |
|
| 190 | + $this->databaseConnection, |
|
| 191 | + $this->userSession->getUser() |
|
| 192 | + ) |
|
| 193 | + ) |
|
| 194 | + ); |
|
| 195 | + } |
|
| 196 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin()); |
|
| 197 | + }, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request |
|
| 198 | + return $server; |
|
| 199 | + } |
|
| 200 | 200 | } |
@@ -65,235 +65,235 @@ |
||
| 65 | 65 | |
| 66 | 66 | class Server { |
| 67 | 67 | |
| 68 | - /** @var IRequest */ |
|
| 69 | - private $request; |
|
| 68 | + /** @var IRequest */ |
|
| 69 | + private $request; |
|
| 70 | 70 | |
| 71 | - /** @var string */ |
|
| 72 | - private $baseUri; |
|
| 71 | + /** @var string */ |
|
| 72 | + private $baseUri; |
|
| 73 | 73 | |
| 74 | - /** @var Connector\Sabre\Server */ |
|
| 75 | - public $server; |
|
| 74 | + /** @var Connector\Sabre\Server */ |
|
| 75 | + public $server; |
|
| 76 | 76 | |
| 77 | - public function __construct(IRequest $request, $baseUri) { |
|
| 78 | - $this->request = $request; |
|
| 79 | - $this->baseUri = $baseUri; |
|
| 80 | - $logger = \OC::$server->getLogger(); |
|
| 81 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 77 | + public function __construct(IRequest $request, $baseUri) { |
|
| 78 | + $this->request = $request; |
|
| 79 | + $this->baseUri = $baseUri; |
|
| 80 | + $logger = \OC::$server->getLogger(); |
|
| 81 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 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 | - $this->server->addPlugin(new AnonymousOptionsPlugin()); |
|
| 104 | - $authPlugin = new Plugin(); |
|
| 105 | - $authPlugin->addBackend(new PublicAuth()); |
|
| 106 | - $this->server->addPlugin($authPlugin); |
|
| 102 | + $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
| 103 | + $this->server->addPlugin(new AnonymousOptionsPlugin()); |
|
| 104 | + $authPlugin = new Plugin(); |
|
| 105 | + $authPlugin->addBackend(new PublicAuth()); |
|
| 106 | + $this->server->addPlugin($authPlugin); |
|
| 107 | 107 | |
| 108 | - // allow setup of additional auth backends |
|
| 109 | - $event = new SabrePluginEvent($this->server); |
|
| 110 | - $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
| 108 | + // allow setup of additional auth backends |
|
| 109 | + $event = new SabrePluginEvent($this->server); |
|
| 110 | + $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
| 111 | 111 | |
| 112 | - $bearerAuthBackend = new BearerAuth( |
|
| 113 | - \OC::$server->getUserSession(), |
|
| 114 | - \OC::$server->getSession(), |
|
| 115 | - \OC::$server->getRequest() |
|
| 116 | - ); |
|
| 117 | - $authPlugin->addBackend($bearerAuthBackend); |
|
| 118 | - // because we are throwing exceptions this plugin has to be the last one |
|
| 119 | - $authPlugin->addBackend($authBackend); |
|
| 112 | + $bearerAuthBackend = new BearerAuth( |
|
| 113 | + \OC::$server->getUserSession(), |
|
| 114 | + \OC::$server->getSession(), |
|
| 115 | + \OC::$server->getRequest() |
|
| 116 | + ); |
|
| 117 | + $authPlugin->addBackend($bearerAuthBackend); |
|
| 118 | + // because we are throwing exceptions this plugin has to be the last one |
|
| 119 | + $authPlugin->addBackend($authBackend); |
|
| 120 | 120 | |
| 121 | - // debugging |
|
| 122 | - if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 123 | - $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
| 124 | - } else { |
|
| 125 | - $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
| 126 | - } |
|
| 121 | + // debugging |
|
| 122 | + if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 123 | + $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
| 124 | + } else { |
|
| 125 | + $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
| 129 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
| 130 | - $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
| 128 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
| 129 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
| 130 | + $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
| 131 | 131 | |
| 132 | - // acl |
|
| 133 | - $acl = new DavAclPlugin(); |
|
| 134 | - $acl->principalCollectionSet = [ |
|
| 135 | - 'principals/users', 'principals/groups' |
|
| 136 | - ]; |
|
| 137 | - $acl->defaultUsernamePath = 'principals/users'; |
|
| 138 | - $this->server->addPlugin($acl); |
|
| 132 | + // acl |
|
| 133 | + $acl = new DavAclPlugin(); |
|
| 134 | + $acl->principalCollectionSet = [ |
|
| 135 | + 'principals/users', 'principals/groups' |
|
| 136 | + ]; |
|
| 137 | + $acl->defaultUsernamePath = 'principals/users'; |
|
| 138 | + $this->server->addPlugin($acl); |
|
| 139 | 139 | |
| 140 | - // calendar plugins |
|
| 141 | - if ($this->requestIsForSubtree(['calendars', 'principals'])) { |
|
| 142 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
| 143 | - $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); |
|
| 144 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
|
| 145 | - if (\OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') { |
|
| 146 | - $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class)); |
|
| 147 | - } |
|
| 148 | - $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
| 149 | - $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
| 150 | - $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
| 151 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
| 152 | - \OC::$server->getConfig(), |
|
| 153 | - \OC::$server->getURLGenerator() |
|
| 154 | - )); |
|
| 155 | - } |
|
| 140 | + // calendar plugins |
|
| 141 | + if ($this->requestIsForSubtree(['calendars', 'principals'])) { |
|
| 142 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
| 143 | + $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); |
|
| 144 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
|
| 145 | + if (\OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') { |
|
| 146 | + $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class)); |
|
| 147 | + } |
|
| 148 | + $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
| 149 | + $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
| 150 | + $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
| 151 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
| 152 | + \OC::$server->getConfig(), |
|
| 153 | + \OC::$server->getURLGenerator() |
|
| 154 | + )); |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - // addressbook plugins |
|
| 158 | - if ($this->requestIsForSubtree(['addressbooks', 'principals'])) { |
|
| 159 | - $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
| 160 | - $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
| 161 | - $this->server->addPlugin(new VCFExportPlugin()); |
|
| 162 | - $this->server->addPlugin(new ImageExportPlugin(new PhotoCache(\OC::$server->getAppDataDir('dav-photocache')))); |
|
| 163 | - } |
|
| 157 | + // addressbook plugins |
|
| 158 | + if ($this->requestIsForSubtree(['addressbooks', 'principals'])) { |
|
| 159 | + $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
| 160 | + $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
| 161 | + $this->server->addPlugin(new VCFExportPlugin()); |
|
| 162 | + $this->server->addPlugin(new ImageExportPlugin(new PhotoCache(\OC::$server->getAppDataDir('dav-photocache')))); |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - // system tags plugins |
|
| 166 | - $this->server->addPlugin(new SystemTagPlugin( |
|
| 167 | - \OC::$server->getSystemTagManager(), |
|
| 168 | - \OC::$server->getGroupManager(), |
|
| 169 | - \OC::$server->getUserSession() |
|
| 170 | - )); |
|
| 165 | + // system tags plugins |
|
| 166 | + $this->server->addPlugin(new SystemTagPlugin( |
|
| 167 | + \OC::$server->getSystemTagManager(), |
|
| 168 | + \OC::$server->getGroupManager(), |
|
| 169 | + \OC::$server->getUserSession() |
|
| 170 | + )); |
|
| 171 | 171 | |
| 172 | - // comments plugin |
|
| 173 | - $this->server->addPlugin(new CommentsPlugin( |
|
| 174 | - \OC::$server->getCommentsManager(), |
|
| 175 | - \OC::$server->getUserSession() |
|
| 176 | - )); |
|
| 172 | + // comments plugin |
|
| 173 | + $this->server->addPlugin(new CommentsPlugin( |
|
| 174 | + \OC::$server->getCommentsManager(), |
|
| 175 | + \OC::$server->getUserSession() |
|
| 176 | + )); |
|
| 177 | 177 | |
| 178 | - $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
| 179 | - $this->server->addPlugin(new ChunkingPlugin()); |
|
| 178 | + $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
| 179 | + $this->server->addPlugin(new ChunkingPlugin()); |
|
| 180 | 180 | |
| 181 | - // allow setup of additional plugins |
|
| 182 | - $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event); |
|
| 181 | + // allow setup of additional plugins |
|
| 182 | + $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event); |
|
| 183 | 183 | |
| 184 | - // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 185 | - // we do not provide locking we emulate it using a fake locking plugin. |
|
| 186 | - if($request->isUserAgent([ |
|
| 187 | - '/WebDAVFS/', |
|
| 188 | - '/OneNote/', |
|
| 189 | - '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
| 190 | - ])) { |
|
| 191 | - $this->server->addPlugin(new FakeLockerPlugin()); |
|
| 192 | - } |
|
| 184 | + // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 185 | + // we do not provide locking we emulate it using a fake locking plugin. |
|
| 186 | + if($request->isUserAgent([ |
|
| 187 | + '/WebDAVFS/', |
|
| 188 | + '/OneNote/', |
|
| 189 | + '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
| 190 | + ])) { |
|
| 191 | + $this->server->addPlugin(new FakeLockerPlugin()); |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | - if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
| 195 | - $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 196 | - } |
|
| 194 | + if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
| 195 | + $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - // wait with registering these until auth is handled and the filesystem is setup |
|
| 199 | - $this->server->on('beforeMethod', function () use ($root) { |
|
| 200 | - // custom properties plugin must be the last one |
|
| 201 | - $userSession = \OC::$server->getUserSession(); |
|
| 202 | - $user = $userSession->getUser(); |
|
| 203 | - if ($user !== null) { |
|
| 204 | - $view = \OC\Files\Filesystem::getView(); |
|
| 205 | - $this->server->addPlugin( |
|
| 206 | - new FilesPlugin( |
|
| 207 | - $this->server->tree, |
|
| 208 | - \OC::$server->getConfig(), |
|
| 209 | - $this->request, |
|
| 210 | - \OC::$server->getPreviewManager(), |
|
| 211 | - false, |
|
| 212 | - !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
| 213 | - ) |
|
| 214 | - ); |
|
| 198 | + // wait with registering these until auth is handled and the filesystem is setup |
|
| 199 | + $this->server->on('beforeMethod', function () use ($root) { |
|
| 200 | + // custom properties plugin must be the last one |
|
| 201 | + $userSession = \OC::$server->getUserSession(); |
|
| 202 | + $user = $userSession->getUser(); |
|
| 203 | + if ($user !== null) { |
|
| 204 | + $view = \OC\Files\Filesystem::getView(); |
|
| 205 | + $this->server->addPlugin( |
|
| 206 | + new FilesPlugin( |
|
| 207 | + $this->server->tree, |
|
| 208 | + \OC::$server->getConfig(), |
|
| 209 | + $this->request, |
|
| 210 | + \OC::$server->getPreviewManager(), |
|
| 211 | + false, |
|
| 212 | + !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
| 213 | + ) |
|
| 214 | + ); |
|
| 215 | 215 | |
| 216 | - $this->server->addPlugin( |
|
| 217 | - new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 218 | - new CustomPropertiesBackend( |
|
| 219 | - $this->server->tree, |
|
| 220 | - \OC::$server->getDatabaseConnection(), |
|
| 221 | - \OC::$server->getUserSession()->getUser() |
|
| 222 | - ) |
|
| 223 | - ) |
|
| 224 | - ); |
|
| 225 | - if ($view !== null) { |
|
| 226 | - $this->server->addPlugin( |
|
| 227 | - new QuotaPlugin($view, false)); |
|
| 228 | - } |
|
| 229 | - $this->server->addPlugin( |
|
| 230 | - new TagsPlugin( |
|
| 231 | - $this->server->tree, \OC::$server->getTagManager() |
|
| 232 | - ) |
|
| 233 | - ); |
|
| 234 | - // TODO: switch to LazyUserFolder |
|
| 235 | - $userFolder = \OC::$server->getUserFolder(); |
|
| 236 | - $this->server->addPlugin(new SharesPlugin( |
|
| 237 | - $this->server->tree, |
|
| 238 | - $userSession, |
|
| 239 | - $userFolder, |
|
| 240 | - \OC::$server->getShareManager() |
|
| 241 | - )); |
|
| 242 | - $this->server->addPlugin(new CommentPropertiesPlugin( |
|
| 243 | - \OC::$server->getCommentsManager(), |
|
| 244 | - $userSession |
|
| 245 | - )); |
|
| 246 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
| 247 | - if ($view !== null) { |
|
| 248 | - $this->server->addPlugin(new FilesReportPlugin( |
|
| 249 | - $this->server->tree, |
|
| 250 | - $view, |
|
| 251 | - \OC::$server->getSystemTagManager(), |
|
| 252 | - \OC::$server->getSystemTagObjectMapper(), |
|
| 253 | - \OC::$server->getTagManager(), |
|
| 254 | - $userSession, |
|
| 255 | - \OC::$server->getGroupManager(), |
|
| 256 | - $userFolder |
|
| 257 | - )); |
|
| 258 | - $this->server->addPlugin(new SearchPlugin(new \OCA\DAV\Files\FileSearchBackend( |
|
| 259 | - $this->server->tree, |
|
| 260 | - $user, |
|
| 261 | - \OC::$server->getRootFolder(), |
|
| 262 | - \OC::$server->getShareManager(), |
|
| 263 | - $view |
|
| 264 | - ))); |
|
| 265 | - } |
|
| 266 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin( |
|
| 267 | - \OC::$server->getConfig(), |
|
| 268 | - \OC::$server->query(BirthdayService::class) |
|
| 269 | - )); |
|
| 270 | - } |
|
| 216 | + $this->server->addPlugin( |
|
| 217 | + new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 218 | + new CustomPropertiesBackend( |
|
| 219 | + $this->server->tree, |
|
| 220 | + \OC::$server->getDatabaseConnection(), |
|
| 221 | + \OC::$server->getUserSession()->getUser() |
|
| 222 | + ) |
|
| 223 | + ) |
|
| 224 | + ); |
|
| 225 | + if ($view !== null) { |
|
| 226 | + $this->server->addPlugin( |
|
| 227 | + new QuotaPlugin($view, false)); |
|
| 228 | + } |
|
| 229 | + $this->server->addPlugin( |
|
| 230 | + new TagsPlugin( |
|
| 231 | + $this->server->tree, \OC::$server->getTagManager() |
|
| 232 | + ) |
|
| 233 | + ); |
|
| 234 | + // TODO: switch to LazyUserFolder |
|
| 235 | + $userFolder = \OC::$server->getUserFolder(); |
|
| 236 | + $this->server->addPlugin(new SharesPlugin( |
|
| 237 | + $this->server->tree, |
|
| 238 | + $userSession, |
|
| 239 | + $userFolder, |
|
| 240 | + \OC::$server->getShareManager() |
|
| 241 | + )); |
|
| 242 | + $this->server->addPlugin(new CommentPropertiesPlugin( |
|
| 243 | + \OC::$server->getCommentsManager(), |
|
| 244 | + $userSession |
|
| 245 | + )); |
|
| 246 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
| 247 | + if ($view !== null) { |
|
| 248 | + $this->server->addPlugin(new FilesReportPlugin( |
|
| 249 | + $this->server->tree, |
|
| 250 | + $view, |
|
| 251 | + \OC::$server->getSystemTagManager(), |
|
| 252 | + \OC::$server->getSystemTagObjectMapper(), |
|
| 253 | + \OC::$server->getTagManager(), |
|
| 254 | + $userSession, |
|
| 255 | + \OC::$server->getGroupManager(), |
|
| 256 | + $userFolder |
|
| 257 | + )); |
|
| 258 | + $this->server->addPlugin(new SearchPlugin(new \OCA\DAV\Files\FileSearchBackend( |
|
| 259 | + $this->server->tree, |
|
| 260 | + $user, |
|
| 261 | + \OC::$server->getRootFolder(), |
|
| 262 | + \OC::$server->getShareManager(), |
|
| 263 | + $view |
|
| 264 | + ))); |
|
| 265 | + } |
|
| 266 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin( |
|
| 267 | + \OC::$server->getConfig(), |
|
| 268 | + \OC::$server->query(BirthdayService::class) |
|
| 269 | + )); |
|
| 270 | + } |
|
| 271 | 271 | |
| 272 | - // register plugins from apps |
|
| 273 | - $pluginManager = new PluginManager( |
|
| 274 | - \OC::$server, |
|
| 275 | - \OC::$server->getAppManager() |
|
| 276 | - ); |
|
| 277 | - foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
| 278 | - $this->server->addPlugin($appPlugin); |
|
| 279 | - } |
|
| 280 | - foreach ($pluginManager->getAppCollections() as $appCollection) { |
|
| 281 | - $root->addChild($appCollection); |
|
| 282 | - } |
|
| 283 | - }); |
|
| 284 | - } |
|
| 272 | + // register plugins from apps |
|
| 273 | + $pluginManager = new PluginManager( |
|
| 274 | + \OC::$server, |
|
| 275 | + \OC::$server->getAppManager() |
|
| 276 | + ); |
|
| 277 | + foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
| 278 | + $this->server->addPlugin($appPlugin); |
|
| 279 | + } |
|
| 280 | + foreach ($pluginManager->getAppCollections() as $appCollection) { |
|
| 281 | + $root->addChild($appCollection); |
|
| 282 | + } |
|
| 283 | + }); |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | - public function exec() { |
|
| 287 | - $this->server->exec(); |
|
| 288 | - } |
|
| 286 | + public function exec() { |
|
| 287 | + $this->server->exec(); |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - private function requestIsForSubtree(array $subTrees): bool { |
|
| 291 | - foreach ($subTrees as $subTree) { |
|
| 292 | - $subTree = trim($subTree, ' /'); |
|
| 293 | - if (strpos($this->server->getRequestUri(), $subTree.'/') === 0) { |
|
| 294 | - return true; |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - return false; |
|
| 298 | - } |
|
| 290 | + private function requestIsForSubtree(array $subTrees): bool { |
|
| 291 | + foreach ($subTrees as $subTree) { |
|
| 292 | + $subTree = trim($subTree, ' /'); |
|
| 293 | + if (strpos($this->server->getRequestUri(), $subTree.'/') === 0) { |
|
| 294 | + return true; |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + return false; |
|
| 298 | + } |
|
| 299 | 299 | } |
@@ -30,34 +30,34 @@ |
||
| 30 | 30 | |
| 31 | 31 | class AnonymousOptionsPlugin extends ServerPlugin { |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @var \Sabre\DAV\Server |
|
| 35 | - */ |
|
| 36 | - private $server; |
|
| 33 | + /** |
|
| 34 | + * @var \Sabre\DAV\Server |
|
| 35 | + */ |
|
| 36 | + private $server; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @param \Sabre\DAV\Server $server |
|
| 40 | - * @return void |
|
| 41 | - */ |
|
| 42 | - public function initialize(\Sabre\DAV\Server $server) { |
|
| 43 | - $this->server = $server; |
|
| 44 | - // before auth |
|
| 45 | - $this->server->on('beforeMethod', [$this, 'handleAnonymousOptions'], 9); |
|
| 46 | - } |
|
| 38 | + /** |
|
| 39 | + * @param \Sabre\DAV\Server $server |
|
| 40 | + * @return void |
|
| 41 | + */ |
|
| 42 | + public function initialize(\Sabre\DAV\Server $server) { |
|
| 43 | + $this->server = $server; |
|
| 44 | + // before auth |
|
| 45 | + $this->server->on('beforeMethod', [$this, 'handleAnonymousOptions'], 9); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @throws \Sabre\DAV\Exception\Forbidden |
|
| 50 | - * @return bool |
|
| 51 | - */ |
|
| 52 | - public function handleAnonymousOptions(RequestInterface $request, ResponseInterface $response) { |
|
| 53 | - if ($request->getMethod() === 'OPTIONS' && $request->getPath() === '') { |
|
| 54 | - /** @var CorePlugin $corePlugin */ |
|
| 55 | - $corePlugin = $this->server->getPlugin('core'); |
|
| 56 | - // setup a fake tree for anonymous access |
|
| 57 | - $this->server->tree = new Tree(new Directory('')); |
|
| 58 | - $corePlugin->httpOptions($request, $response); |
|
| 59 | - $this->server->sapi->sendResponse($response); |
|
| 60 | - return false; |
|
| 61 | - } |
|
| 62 | - } |
|
| 48 | + /** |
|
| 49 | + * @throws \Sabre\DAV\Exception\Forbidden |
|
| 50 | + * @return bool |
|
| 51 | + */ |
|
| 52 | + public function handleAnonymousOptions(RequestInterface $request, ResponseInterface $response) { |
|
| 53 | + if ($request->getMethod() === 'OPTIONS' && $request->getPath() === '') { |
|
| 54 | + /** @var CorePlugin $corePlugin */ |
|
| 55 | + $corePlugin = $this->server->getPlugin('core'); |
|
| 56 | + // setup a fake tree for anonymous access |
|
| 57 | + $this->server->tree = new Tree(new Directory('')); |
|
| 58 | + $corePlugin->httpOptions($request, $response); |
|
| 59 | + $this->server->sapi->sendResponse($response); |
|
| 60 | + return false; |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | 63 | } |