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