@@ -245,7 +245,9 @@ |
||
245 | 245 | function httpGet(RequestInterface $request, ResponseInterface $response) { |
246 | 246 | // Only handle valid files |
247 | 247 | $node = $this->tree->getNodeForPath($request->getPath()); |
248 | - if (!($node instanceof IFile)) return; |
|
248 | + if (!($node instanceof IFile)) { |
|
249 | + return; |
|
250 | + } |
|
249 | 251 | |
250 | 252 | // adds a 'Content-Disposition: attachment' header in case no disposition |
251 | 253 | // header has been set before |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | $this->server->on('propPatch', array($this, 'handleUpdateProperties')); |
174 | 174 | $this->server->on('afterBind', array($this, 'sendFileIdHeader')); |
175 | 175 | $this->server->on('afterWriteContent', array($this, 'sendFileIdHeader')); |
176 | - $this->server->on('afterMethod:GET', [$this,'httpGet']); |
|
176 | + $this->server->on('afterMethod:GET', [$this, 'httpGet']); |
|
177 | 177 | $this->server->on('afterMethod:GET', array($this, 'handleDownloadToken')); |
178 | 178 | $this->server->on('afterResponse', function($request, ResponseInterface $response) { |
179 | 179 | $body = $response->getBody(); |
@@ -203,11 +203,11 @@ discard block |
||
203 | 203 | if ($sourceDir !== $destinationDir) { |
204 | 204 | $sourceNodeFileInfo = $sourceNode->getFileInfo(); |
205 | 205 | if ($sourceNodeFileInfo === null) { |
206 | - throw new NotFound($source . ' does not exist'); |
|
206 | + throw new NotFound($source.' does not exist'); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | if (!$sourceNodeFileInfo->isDeletable()) { |
210 | - throw new Forbidden($source . " cannot be deleted"); |
|
210 | + throw new Forbidden($source." cannot be deleted"); |
|
211 | 211 | } |
212 | 212 | } |
213 | 213 | } |
@@ -260,10 +260,10 @@ discard block |
||
260 | 260 | Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
261 | 261 | Request::USER_AGENT_FREEBOX, |
262 | 262 | ])) { |
263 | - $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"'); |
|
263 | + $response->addHeader('Content-Disposition', 'attachment; filename="'.rawurlencode($filename).'"'); |
|
264 | 264 | } else { |
265 | - $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename) |
|
266 | - . '; filename="' . rawurlencode($filename) . '"'); |
|
265 | + $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\''.rawurlencode($filename) |
|
266 | + . '; filename="'.rawurlencode($filename).'"'); |
|
267 | 267 | } |
268 | 268 | } |
269 | 269 | |
@@ -352,13 +352,13 @@ discard block |
||
352 | 352 | } |
353 | 353 | }); |
354 | 354 | |
355 | - $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { |
|
355 | + $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function() use ($node) { |
|
356 | 356 | return json_encode($this->previewManager->isAvailable($node->getFileInfo())); |
357 | 357 | }); |
358 | 358 | $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
359 | 359 | return $node->getSize(); |
360 | 360 | }); |
361 | - $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { |
|
361 | + $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function() use ($node) { |
|
362 | 362 | return $node->getFileInfo()->getMountPoint()->getMountType(); |
363 | 363 | }); |
364 | 364 | |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | list($path, $name) = \Sabre\Uri\split($filePath); |
484 | 484 | $info = \OC_FileChunking::decodeName($name); |
485 | 485 | if (!empty($info)) { |
486 | - $filePath = $path . '/' . $info['name']; |
|
486 | + $filePath = $path.'/'.$info['name']; |
|
487 | 487 | } |
488 | 488 | } |
489 | 489 |
@@ -51,470 +51,470 @@ |
||
51 | 51 | |
52 | 52 | class FilesPlugin extends ServerPlugin { |
53 | 53 | |
54 | - // namespace |
|
55 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
56 | - const NS_NEXTCLOUD = 'http://nextcloud.org/ns'; |
|
57 | - const FILEID_PROPERTYNAME = '{http://owncloud.org/ns}id'; |
|
58 | - const INTERNAL_FILEID_PROPERTYNAME = '{http://owncloud.org/ns}fileid'; |
|
59 | - const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions'; |
|
60 | - const SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-collaboration-services.org/ns}share-permissions'; |
|
61 | - const OCM_SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-cloud-mesh.org/ns}share-permissions'; |
|
62 | - const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL'; |
|
63 | - const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size'; |
|
64 | - const GETETAG_PROPERTYNAME = '{DAV:}getetag'; |
|
65 | - const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified'; |
|
66 | - const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id'; |
|
67 | - const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name'; |
|
68 | - const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums'; |
|
69 | - const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint'; |
|
70 | - const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview'; |
|
71 | - const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type'; |
|
72 | - const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted'; |
|
73 | - const METADATA_ETAG_PROPERTYNAME = '{http://nextcloud.org/ns}metadata_etag'; |
|
74 | - const UPLOAD_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}upload_time'; |
|
75 | - const CREATION_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}creation_time'; |
|
76 | - const SHARE_NOTE = '{http://nextcloud.org/ns}note'; |
|
77 | - |
|
78 | - /** |
|
79 | - * Reference to main server object |
|
80 | - * |
|
81 | - * @var \Sabre\DAV\Server |
|
82 | - */ |
|
83 | - private $server; |
|
84 | - |
|
85 | - /** |
|
86 | - * @var Tree |
|
87 | - */ |
|
88 | - private $tree; |
|
89 | - |
|
90 | - /** |
|
91 | - * Whether this is public webdav. |
|
92 | - * If true, some returned information will be stripped off. |
|
93 | - * |
|
94 | - * @var bool |
|
95 | - */ |
|
96 | - private $isPublic; |
|
97 | - |
|
98 | - /** |
|
99 | - * @var bool |
|
100 | - */ |
|
101 | - private $downloadAttachment; |
|
102 | - |
|
103 | - /** |
|
104 | - * @var IConfig |
|
105 | - */ |
|
106 | - private $config; |
|
107 | - |
|
108 | - /** |
|
109 | - * @var IRequest |
|
110 | - */ |
|
111 | - private $request; |
|
112 | - |
|
113 | - /** |
|
114 | - * @var IPreview |
|
115 | - */ |
|
116 | - private $previewManager; |
|
117 | - |
|
118 | - /** |
|
119 | - * @param Tree $tree |
|
120 | - * @param IConfig $config |
|
121 | - * @param IRequest $request |
|
122 | - * @param IPreview $previewManager |
|
123 | - * @param bool $isPublic |
|
124 | - * @param bool $downloadAttachment |
|
125 | - */ |
|
126 | - public function __construct(Tree $tree, |
|
127 | - IConfig $config, |
|
128 | - IRequest $request, |
|
129 | - IPreview $previewManager, |
|
130 | - $isPublic = false, |
|
131 | - $downloadAttachment = true) { |
|
132 | - $this->tree = $tree; |
|
133 | - $this->config = $config; |
|
134 | - $this->request = $request; |
|
135 | - $this->isPublic = $isPublic; |
|
136 | - $this->downloadAttachment = $downloadAttachment; |
|
137 | - $this->previewManager = $previewManager; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * This initializes the plugin. |
|
142 | - * |
|
143 | - * This function is called by \Sabre\DAV\Server, after |
|
144 | - * addPlugin is called. |
|
145 | - * |
|
146 | - * This method should set up the required event subscriptions. |
|
147 | - * |
|
148 | - * @param \Sabre\DAV\Server $server |
|
149 | - * @return void |
|
150 | - */ |
|
151 | - public function initialize(\Sabre\DAV\Server $server) { |
|
152 | - $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
153 | - $server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc'; |
|
154 | - $server->protectedProperties[] = self::FILEID_PROPERTYNAME; |
|
155 | - $server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME; |
|
156 | - $server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME; |
|
157 | - $server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME; |
|
158 | - $server->protectedProperties[] = self::OCM_SHARE_PERMISSIONS_PROPERTYNAME; |
|
159 | - $server->protectedProperties[] = self::SIZE_PROPERTYNAME; |
|
160 | - $server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME; |
|
161 | - $server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME; |
|
162 | - $server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME; |
|
163 | - $server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME; |
|
164 | - $server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME; |
|
165 | - $server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME; |
|
166 | - $server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME; |
|
167 | - $server->protectedProperties[] = self::IS_ENCRYPTED_PROPERTYNAME; |
|
168 | - $server->protectedProperties[] = self::SHARE_NOTE; |
|
169 | - |
|
170 | - // normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH |
|
171 | - $allowedProperties = ['{DAV:}getetag']; |
|
172 | - $server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties); |
|
173 | - |
|
174 | - $this->server = $server; |
|
175 | - $this->server->on('propFind', array($this, 'handleGetProperties')); |
|
176 | - $this->server->on('propPatch', array($this, 'handleUpdateProperties')); |
|
177 | - $this->server->on('afterBind', array($this, 'sendFileIdHeader')); |
|
178 | - $this->server->on('afterWriteContent', array($this, 'sendFileIdHeader')); |
|
179 | - $this->server->on('afterMethod:GET', [$this,'httpGet']); |
|
180 | - $this->server->on('afterMethod:GET', array($this, 'handleDownloadToken')); |
|
181 | - $this->server->on('afterResponse', function($request, ResponseInterface $response) { |
|
182 | - $body = $response->getBody(); |
|
183 | - if (is_resource($body)) { |
|
184 | - fclose($body); |
|
185 | - } |
|
186 | - }); |
|
187 | - $this->server->on('beforeMove', [$this, 'checkMove']); |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * Plugin that checks if a move can actually be performed. |
|
192 | - * |
|
193 | - * @param string $source source path |
|
194 | - * @param string $destination destination path |
|
195 | - * @throws Forbidden |
|
196 | - * @throws NotFound |
|
197 | - */ |
|
198 | - function checkMove($source, $destination) { |
|
199 | - $sourceNode = $this->tree->getNodeForPath($source); |
|
200 | - if (!$sourceNode instanceof Node) { |
|
201 | - return; |
|
202 | - } |
|
203 | - list($sourceDir,) = \Sabre\Uri\split($source); |
|
204 | - list($destinationDir,) = \Sabre\Uri\split($destination); |
|
205 | - |
|
206 | - if ($sourceDir !== $destinationDir) { |
|
207 | - $sourceNodeFileInfo = $sourceNode->getFileInfo(); |
|
208 | - if ($sourceNodeFileInfo === null) { |
|
209 | - throw new NotFound($source . ' does not exist'); |
|
210 | - } |
|
211 | - |
|
212 | - if (!$sourceNodeFileInfo->isDeletable()) { |
|
213 | - throw new Forbidden($source . " cannot be deleted"); |
|
214 | - } |
|
215 | - } |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * This sets a cookie to be able to recognize the start of the download |
|
220 | - * the content must not be longer than 32 characters and must only contain |
|
221 | - * alphanumeric characters |
|
222 | - * |
|
223 | - * @param RequestInterface $request |
|
224 | - * @param ResponseInterface $response |
|
225 | - */ |
|
226 | - function handleDownloadToken(RequestInterface $request, ResponseInterface $response) { |
|
227 | - $queryParams = $request->getQueryParameters(); |
|
228 | - |
|
229 | - /** |
|
230 | - * this sets a cookie to be able to recognize the start of the download |
|
231 | - * the content must not be longer than 32 characters and must only contain |
|
232 | - * alphanumeric characters |
|
233 | - */ |
|
234 | - if (isset($queryParams['downloadStartSecret'])) { |
|
235 | - $token = $queryParams['downloadStartSecret']; |
|
236 | - if (!isset($token[32]) |
|
237 | - && preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) { |
|
238 | - // FIXME: use $response->setHeader() instead |
|
239 | - setcookie('ocDownloadStarted', $token, time() + 20, '/'); |
|
240 | - } |
|
241 | - } |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * Add headers to file download |
|
246 | - * |
|
247 | - * @param RequestInterface $request |
|
248 | - * @param ResponseInterface $response |
|
249 | - */ |
|
250 | - function httpGet(RequestInterface $request, ResponseInterface $response) { |
|
251 | - // Only handle valid files |
|
252 | - $node = $this->tree->getNodeForPath($request->getPath()); |
|
253 | - if (!($node instanceof IFile)) return; |
|
254 | - |
|
255 | - // adds a 'Content-Disposition: attachment' header in case no disposition |
|
256 | - // header has been set before |
|
257 | - if ($this->downloadAttachment && |
|
258 | - $response->getHeader('Content-Disposition') === null) { |
|
259 | - $filename = $node->getName(); |
|
260 | - if ($this->request->isUserAgent( |
|
261 | - [ |
|
262 | - Request::USER_AGENT_IE, |
|
263 | - Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
|
264 | - Request::USER_AGENT_FREEBOX, |
|
265 | - ])) { |
|
266 | - $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"'); |
|
267 | - } else { |
|
268 | - $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename) |
|
269 | - . '; filename="' . rawurlencode($filename) . '"'); |
|
270 | - } |
|
271 | - } |
|
272 | - |
|
273 | - if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
274 | - //Add OC-Checksum header |
|
275 | - /** @var $node File */ |
|
276 | - $checksum = $node->getChecksum(); |
|
277 | - if ($checksum !== null && $checksum !== '') { |
|
278 | - $response->addHeader('OC-Checksum', $checksum); |
|
279 | - } |
|
280 | - } |
|
281 | - } |
|
282 | - |
|
283 | - /** |
|
284 | - * Adds all ownCloud-specific properties |
|
285 | - * |
|
286 | - * @param PropFind $propFind |
|
287 | - * @param \Sabre\DAV\INode $node |
|
288 | - * @return void |
|
289 | - */ |
|
290 | - public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) { |
|
291 | - |
|
292 | - $httpRequest = $this->server->httpRequest; |
|
293 | - |
|
294 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
295 | - /** |
|
296 | - * This was disabled, because it made dir listing throw an exception, |
|
297 | - * so users were unable to navigate into folders where one subitem |
|
298 | - * is blocked by the files_accesscontrol app, see: |
|
299 | - * https://github.com/nextcloud/files_accesscontrol/issues/65 |
|
54 | + // namespace |
|
55 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
56 | + const NS_NEXTCLOUD = 'http://nextcloud.org/ns'; |
|
57 | + const FILEID_PROPERTYNAME = '{http://owncloud.org/ns}id'; |
|
58 | + const INTERNAL_FILEID_PROPERTYNAME = '{http://owncloud.org/ns}fileid'; |
|
59 | + const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions'; |
|
60 | + const SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-collaboration-services.org/ns}share-permissions'; |
|
61 | + const OCM_SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-cloud-mesh.org/ns}share-permissions'; |
|
62 | + const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL'; |
|
63 | + const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size'; |
|
64 | + const GETETAG_PROPERTYNAME = '{DAV:}getetag'; |
|
65 | + const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified'; |
|
66 | + const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id'; |
|
67 | + const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name'; |
|
68 | + const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums'; |
|
69 | + const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint'; |
|
70 | + const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview'; |
|
71 | + const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type'; |
|
72 | + const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted'; |
|
73 | + const METADATA_ETAG_PROPERTYNAME = '{http://nextcloud.org/ns}metadata_etag'; |
|
74 | + const UPLOAD_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}upload_time'; |
|
75 | + const CREATION_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}creation_time'; |
|
76 | + const SHARE_NOTE = '{http://nextcloud.org/ns}note'; |
|
77 | + |
|
78 | + /** |
|
79 | + * Reference to main server object |
|
80 | + * |
|
81 | + * @var \Sabre\DAV\Server |
|
82 | + */ |
|
83 | + private $server; |
|
84 | + |
|
85 | + /** |
|
86 | + * @var Tree |
|
87 | + */ |
|
88 | + private $tree; |
|
89 | + |
|
90 | + /** |
|
91 | + * Whether this is public webdav. |
|
92 | + * If true, some returned information will be stripped off. |
|
93 | + * |
|
94 | + * @var bool |
|
95 | + */ |
|
96 | + private $isPublic; |
|
97 | + |
|
98 | + /** |
|
99 | + * @var bool |
|
100 | + */ |
|
101 | + private $downloadAttachment; |
|
102 | + |
|
103 | + /** |
|
104 | + * @var IConfig |
|
105 | + */ |
|
106 | + private $config; |
|
107 | + |
|
108 | + /** |
|
109 | + * @var IRequest |
|
110 | + */ |
|
111 | + private $request; |
|
112 | + |
|
113 | + /** |
|
114 | + * @var IPreview |
|
115 | + */ |
|
116 | + private $previewManager; |
|
117 | + |
|
118 | + /** |
|
119 | + * @param Tree $tree |
|
120 | + * @param IConfig $config |
|
121 | + * @param IRequest $request |
|
122 | + * @param IPreview $previewManager |
|
123 | + * @param bool $isPublic |
|
124 | + * @param bool $downloadAttachment |
|
125 | + */ |
|
126 | + public function __construct(Tree $tree, |
|
127 | + IConfig $config, |
|
128 | + IRequest $request, |
|
129 | + IPreview $previewManager, |
|
130 | + $isPublic = false, |
|
131 | + $downloadAttachment = true) { |
|
132 | + $this->tree = $tree; |
|
133 | + $this->config = $config; |
|
134 | + $this->request = $request; |
|
135 | + $this->isPublic = $isPublic; |
|
136 | + $this->downloadAttachment = $downloadAttachment; |
|
137 | + $this->previewManager = $previewManager; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * This initializes the plugin. |
|
142 | + * |
|
143 | + * This function is called by \Sabre\DAV\Server, after |
|
144 | + * addPlugin is called. |
|
145 | + * |
|
146 | + * This method should set up the required event subscriptions. |
|
147 | + * |
|
148 | + * @param \Sabre\DAV\Server $server |
|
149 | + * @return void |
|
150 | + */ |
|
151 | + public function initialize(\Sabre\DAV\Server $server) { |
|
152 | + $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
153 | + $server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc'; |
|
154 | + $server->protectedProperties[] = self::FILEID_PROPERTYNAME; |
|
155 | + $server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME; |
|
156 | + $server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME; |
|
157 | + $server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME; |
|
158 | + $server->protectedProperties[] = self::OCM_SHARE_PERMISSIONS_PROPERTYNAME; |
|
159 | + $server->protectedProperties[] = self::SIZE_PROPERTYNAME; |
|
160 | + $server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME; |
|
161 | + $server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME; |
|
162 | + $server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME; |
|
163 | + $server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME; |
|
164 | + $server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME; |
|
165 | + $server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME; |
|
166 | + $server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME; |
|
167 | + $server->protectedProperties[] = self::IS_ENCRYPTED_PROPERTYNAME; |
|
168 | + $server->protectedProperties[] = self::SHARE_NOTE; |
|
169 | + |
|
170 | + // normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH |
|
171 | + $allowedProperties = ['{DAV:}getetag']; |
|
172 | + $server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties); |
|
173 | + |
|
174 | + $this->server = $server; |
|
175 | + $this->server->on('propFind', array($this, 'handleGetProperties')); |
|
176 | + $this->server->on('propPatch', array($this, 'handleUpdateProperties')); |
|
177 | + $this->server->on('afterBind', array($this, 'sendFileIdHeader')); |
|
178 | + $this->server->on('afterWriteContent', array($this, 'sendFileIdHeader')); |
|
179 | + $this->server->on('afterMethod:GET', [$this,'httpGet']); |
|
180 | + $this->server->on('afterMethod:GET', array($this, 'handleDownloadToken')); |
|
181 | + $this->server->on('afterResponse', function($request, ResponseInterface $response) { |
|
182 | + $body = $response->getBody(); |
|
183 | + if (is_resource($body)) { |
|
184 | + fclose($body); |
|
185 | + } |
|
186 | + }); |
|
187 | + $this->server->on('beforeMove', [$this, 'checkMove']); |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * Plugin that checks if a move can actually be performed. |
|
192 | + * |
|
193 | + * @param string $source source path |
|
194 | + * @param string $destination destination path |
|
195 | + * @throws Forbidden |
|
196 | + * @throws NotFound |
|
197 | + */ |
|
198 | + function checkMove($source, $destination) { |
|
199 | + $sourceNode = $this->tree->getNodeForPath($source); |
|
200 | + if (!$sourceNode instanceof Node) { |
|
201 | + return; |
|
202 | + } |
|
203 | + list($sourceDir,) = \Sabre\Uri\split($source); |
|
204 | + list($destinationDir,) = \Sabre\Uri\split($destination); |
|
205 | + |
|
206 | + if ($sourceDir !== $destinationDir) { |
|
207 | + $sourceNodeFileInfo = $sourceNode->getFileInfo(); |
|
208 | + if ($sourceNodeFileInfo === null) { |
|
209 | + throw new NotFound($source . ' does not exist'); |
|
210 | + } |
|
211 | + |
|
212 | + if (!$sourceNodeFileInfo->isDeletable()) { |
|
213 | + throw new Forbidden($source . " cannot be deleted"); |
|
214 | + } |
|
215 | + } |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * This sets a cookie to be able to recognize the start of the download |
|
220 | + * the content must not be longer than 32 characters and must only contain |
|
221 | + * alphanumeric characters |
|
222 | + * |
|
223 | + * @param RequestInterface $request |
|
224 | + * @param ResponseInterface $response |
|
225 | + */ |
|
226 | + function handleDownloadToken(RequestInterface $request, ResponseInterface $response) { |
|
227 | + $queryParams = $request->getQueryParameters(); |
|
228 | + |
|
229 | + /** |
|
230 | + * this sets a cookie to be able to recognize the start of the download |
|
231 | + * the content must not be longer than 32 characters and must only contain |
|
232 | + * alphanumeric characters |
|
233 | + */ |
|
234 | + if (isset($queryParams['downloadStartSecret'])) { |
|
235 | + $token = $queryParams['downloadStartSecret']; |
|
236 | + if (!isset($token[32]) |
|
237 | + && preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) { |
|
238 | + // FIXME: use $response->setHeader() instead |
|
239 | + setcookie('ocDownloadStarted', $token, time() + 20, '/'); |
|
240 | + } |
|
241 | + } |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * Add headers to file download |
|
246 | + * |
|
247 | + * @param RequestInterface $request |
|
248 | + * @param ResponseInterface $response |
|
249 | + */ |
|
250 | + function httpGet(RequestInterface $request, ResponseInterface $response) { |
|
251 | + // Only handle valid files |
|
252 | + $node = $this->tree->getNodeForPath($request->getPath()); |
|
253 | + if (!($node instanceof IFile)) return; |
|
254 | + |
|
255 | + // adds a 'Content-Disposition: attachment' header in case no disposition |
|
256 | + // header has been set before |
|
257 | + if ($this->downloadAttachment && |
|
258 | + $response->getHeader('Content-Disposition') === null) { |
|
259 | + $filename = $node->getName(); |
|
260 | + if ($this->request->isUserAgent( |
|
261 | + [ |
|
262 | + Request::USER_AGENT_IE, |
|
263 | + Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
|
264 | + Request::USER_AGENT_FREEBOX, |
|
265 | + ])) { |
|
266 | + $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"'); |
|
267 | + } else { |
|
268 | + $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename) |
|
269 | + . '; filename="' . rawurlencode($filename) . '"'); |
|
270 | + } |
|
271 | + } |
|
272 | + |
|
273 | + if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
274 | + //Add OC-Checksum header |
|
275 | + /** @var $node File */ |
|
276 | + $checksum = $node->getChecksum(); |
|
277 | + if ($checksum !== null && $checksum !== '') { |
|
278 | + $response->addHeader('OC-Checksum', $checksum); |
|
279 | + } |
|
280 | + } |
|
281 | + } |
|
282 | + |
|
283 | + /** |
|
284 | + * Adds all ownCloud-specific properties |
|
285 | + * |
|
286 | + * @param PropFind $propFind |
|
287 | + * @param \Sabre\DAV\INode $node |
|
288 | + * @return void |
|
289 | + */ |
|
290 | + public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) { |
|
291 | + |
|
292 | + $httpRequest = $this->server->httpRequest; |
|
293 | + |
|
294 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
295 | + /** |
|
296 | + * This was disabled, because it made dir listing throw an exception, |
|
297 | + * so users were unable to navigate into folders where one subitem |
|
298 | + * is blocked by the files_accesscontrol app, see: |
|
299 | + * https://github.com/nextcloud/files_accesscontrol/issues/65 |
|
300 | 300 | if (!$node->getFileInfo()->isReadable()) { |
301 | 301 | // avoid detecting files through this means |
302 | 302 | throw new NotFound(); |
303 | 303 | } |
304 | - */ |
|
305 | - |
|
306 | - $propFind->handle(self::FILEID_PROPERTYNAME, function() use ($node) { |
|
307 | - return $node->getFileId(); |
|
308 | - }); |
|
309 | - |
|
310 | - $propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function() use ($node) { |
|
311 | - return $node->getInternalFileId(); |
|
312 | - }); |
|
313 | - |
|
314 | - $propFind->handle(self::PERMISSIONS_PROPERTYNAME, function() use ($node) { |
|
315 | - $perms = $node->getDavPermissions(); |
|
316 | - if ($this->isPublic) { |
|
317 | - // remove mount information |
|
318 | - $perms = str_replace(['S', 'M'], '', $perms); |
|
319 | - } |
|
320 | - return $perms; |
|
321 | - }); |
|
322 | - |
|
323 | - $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) { |
|
324 | - return $node->getSharePermissions( |
|
325 | - $httpRequest->getRawServerValue('PHP_AUTH_USER') |
|
326 | - ); |
|
327 | - }); |
|
328 | - |
|
329 | - $propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) { |
|
330 | - $ncPermissions = $node->getSharePermissions( |
|
331 | - $httpRequest->getRawServerValue('PHP_AUTH_USER') |
|
332 | - ); |
|
333 | - $ocmPermissions = $this->ncPermissions2ocmPermissions($ncPermissions); |
|
334 | - return json_encode($ocmPermissions); |
|
335 | - }); |
|
336 | - |
|
337 | - $propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) { |
|
338 | - return $node->getETag(); |
|
339 | - }); |
|
340 | - |
|
341 | - $propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) { |
|
342 | - $owner = $node->getOwner(); |
|
343 | - if (!$owner) { |
|
344 | - return null; |
|
345 | - } else { |
|
346 | - return $owner->getUID(); |
|
347 | - } |
|
348 | - }); |
|
349 | - $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) { |
|
350 | - $owner = $node->getOwner(); |
|
351 | - if (!$owner) { |
|
352 | - return null; |
|
353 | - } else { |
|
354 | - return $owner->getDisplayName(); |
|
355 | - } |
|
356 | - }); |
|
357 | - |
|
358 | - $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { |
|
359 | - return json_encode($this->previewManager->isAvailable($node->getFileInfo())); |
|
360 | - }); |
|
361 | - $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
|
362 | - return $node->getSize(); |
|
363 | - }); |
|
364 | - $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { |
|
365 | - return $node->getFileInfo()->getMountPoint()->getMountType(); |
|
366 | - }); |
|
367 | - |
|
368 | - $propFind->handle(self::SHARE_NOTE, function() use ($node, $httpRequest) { |
|
369 | - return $node->getNoteFromShare( |
|
370 | - $httpRequest->getRawServerValue('PHP_AUTH_USER') |
|
371 | - ); |
|
372 | - }); |
|
373 | - } |
|
374 | - |
|
375 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
376 | - $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) { |
|
377 | - return $this->config->getSystemValue('data-fingerprint', ''); |
|
378 | - }); |
|
379 | - } |
|
380 | - |
|
381 | - if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
382 | - $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) { |
|
383 | - /** @var $node \OCA\DAV\Connector\Sabre\File */ |
|
384 | - try { |
|
385 | - $directDownloadUrl = $node->getDirectDownload(); |
|
386 | - if (isset($directDownloadUrl['url'])) { |
|
387 | - return $directDownloadUrl['url']; |
|
388 | - } |
|
389 | - } catch (StorageNotAvailableException $e) { |
|
390 | - return false; |
|
391 | - } catch (ForbiddenException $e) { |
|
392 | - return false; |
|
393 | - } |
|
394 | - return false; |
|
395 | - }); |
|
396 | - |
|
397 | - $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) { |
|
398 | - $checksum = $node->getChecksum(); |
|
399 | - if ($checksum === NULL || $checksum === '') { |
|
400 | - return null; |
|
401 | - } |
|
402 | - |
|
403 | - return new ChecksumList($checksum); |
|
404 | - }); |
|
405 | - |
|
406 | - $propFind->handle(self::CREATION_TIME_PROPERTYNAME, function() use ($node) { |
|
407 | - return $node->getFileInfo()->getCreationTime(); |
|
408 | - }); |
|
409 | - |
|
410 | - $propFind->handle(self::UPLOAD_TIME_PROPERTYNAME, function() use ($node) { |
|
411 | - return $node->getFileInfo()->getUploadTime(); |
|
412 | - }); |
|
413 | - |
|
414 | - } |
|
415 | - |
|
416 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) { |
|
417 | - $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
|
418 | - return $node->getSize(); |
|
419 | - }); |
|
420 | - |
|
421 | - $propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function() use ($node) { |
|
422 | - return $node->getFileInfo()->isEncrypted() ? '1' : '0'; |
|
423 | - }); |
|
424 | - } |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
428 | - * translate Nextcloud permissions to OCM Permissions |
|
429 | - * |
|
430 | - * @param $ncPermissions |
|
431 | - * @return array |
|
432 | - */ |
|
433 | - protected function ncPermissions2ocmPermissions($ncPermissions) { |
|
434 | - |
|
435 | - $ocmPermissions = []; |
|
436 | - |
|
437 | - if ($ncPermissions & Constants::PERMISSION_SHARE) { |
|
438 | - $ocmPermissions[] = 'share'; |
|
439 | - } |
|
440 | - |
|
441 | - if ($ncPermissions & Constants::PERMISSION_READ) { |
|
442 | - $ocmPermissions[] = 'read'; |
|
443 | - } |
|
444 | - |
|
445 | - if (($ncPermissions & Constants::PERMISSION_CREATE) || |
|
446 | - ($ncPermissions & Constants::PERMISSION_UPDATE)) { |
|
447 | - $ocmPermissions[] = 'write'; |
|
448 | - } |
|
449 | - |
|
450 | - return $ocmPermissions; |
|
451 | - |
|
452 | - } |
|
453 | - |
|
454 | - /** |
|
455 | - * Update ownCloud-specific properties |
|
456 | - * |
|
457 | - * @param string $path |
|
458 | - * @param PropPatch $propPatch |
|
459 | - * |
|
460 | - * @return void |
|
461 | - */ |
|
462 | - public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
463 | - $node = $this->tree->getNodeForPath($path); |
|
464 | - if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
465 | - return; |
|
466 | - } |
|
467 | - |
|
468 | - $propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function($time) use ($node) { |
|
469 | - if (empty($time)) { |
|
470 | - return false; |
|
471 | - } |
|
472 | - $node->touch($time); |
|
473 | - return true; |
|
474 | - }); |
|
475 | - $propPatch->handle(self::GETETAG_PROPERTYNAME, function($etag) use ($node) { |
|
476 | - if (empty($etag)) { |
|
477 | - return false; |
|
478 | - } |
|
479 | - if ($node->setEtag($etag) !== -1) { |
|
480 | - return true; |
|
481 | - } |
|
482 | - return false; |
|
483 | - }); |
|
484 | - $propPatch->handle(self::CREATION_TIME_PROPERTYNAME, function($time) use ($node) { |
|
485 | - if (empty($time)) { |
|
486 | - return false; |
|
487 | - } |
|
488 | - $node->setCreationTime((int) $time); |
|
489 | - return true; |
|
490 | - }); |
|
491 | - } |
|
492 | - |
|
493 | - /** |
|
494 | - * @param string $filePath |
|
495 | - * @param \Sabre\DAV\INode $node |
|
496 | - * @throws \Sabre\DAV\Exception\BadRequest |
|
497 | - */ |
|
498 | - public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) { |
|
499 | - // chunked upload handling |
|
500 | - if (isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
501 | - list($path, $name) = \Sabre\Uri\split($filePath); |
|
502 | - $info = \OC_FileChunking::decodeName($name); |
|
503 | - if (!empty($info)) { |
|
504 | - $filePath = $path . '/' . $info['name']; |
|
505 | - } |
|
506 | - } |
|
507 | - |
|
508 | - // we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder |
|
509 | - if (!$this->server->tree->nodeExists($filePath)) { |
|
510 | - return; |
|
511 | - } |
|
512 | - $node = $this->server->tree->getNodeForPath($filePath); |
|
513 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
514 | - $fileId = $node->getFileId(); |
|
515 | - if (!is_null($fileId)) { |
|
516 | - $this->server->httpResponse->setHeader('OC-FileId', $fileId); |
|
517 | - } |
|
518 | - } |
|
519 | - } |
|
304 | + */ |
|
305 | + |
|
306 | + $propFind->handle(self::FILEID_PROPERTYNAME, function() use ($node) { |
|
307 | + return $node->getFileId(); |
|
308 | + }); |
|
309 | + |
|
310 | + $propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function() use ($node) { |
|
311 | + return $node->getInternalFileId(); |
|
312 | + }); |
|
313 | + |
|
314 | + $propFind->handle(self::PERMISSIONS_PROPERTYNAME, function() use ($node) { |
|
315 | + $perms = $node->getDavPermissions(); |
|
316 | + if ($this->isPublic) { |
|
317 | + // remove mount information |
|
318 | + $perms = str_replace(['S', 'M'], '', $perms); |
|
319 | + } |
|
320 | + return $perms; |
|
321 | + }); |
|
322 | + |
|
323 | + $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) { |
|
324 | + return $node->getSharePermissions( |
|
325 | + $httpRequest->getRawServerValue('PHP_AUTH_USER') |
|
326 | + ); |
|
327 | + }); |
|
328 | + |
|
329 | + $propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) { |
|
330 | + $ncPermissions = $node->getSharePermissions( |
|
331 | + $httpRequest->getRawServerValue('PHP_AUTH_USER') |
|
332 | + ); |
|
333 | + $ocmPermissions = $this->ncPermissions2ocmPermissions($ncPermissions); |
|
334 | + return json_encode($ocmPermissions); |
|
335 | + }); |
|
336 | + |
|
337 | + $propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) { |
|
338 | + return $node->getETag(); |
|
339 | + }); |
|
340 | + |
|
341 | + $propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) { |
|
342 | + $owner = $node->getOwner(); |
|
343 | + if (!$owner) { |
|
344 | + return null; |
|
345 | + } else { |
|
346 | + return $owner->getUID(); |
|
347 | + } |
|
348 | + }); |
|
349 | + $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) { |
|
350 | + $owner = $node->getOwner(); |
|
351 | + if (!$owner) { |
|
352 | + return null; |
|
353 | + } else { |
|
354 | + return $owner->getDisplayName(); |
|
355 | + } |
|
356 | + }); |
|
357 | + |
|
358 | + $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { |
|
359 | + return json_encode($this->previewManager->isAvailable($node->getFileInfo())); |
|
360 | + }); |
|
361 | + $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
|
362 | + return $node->getSize(); |
|
363 | + }); |
|
364 | + $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { |
|
365 | + return $node->getFileInfo()->getMountPoint()->getMountType(); |
|
366 | + }); |
|
367 | + |
|
368 | + $propFind->handle(self::SHARE_NOTE, function() use ($node, $httpRequest) { |
|
369 | + return $node->getNoteFromShare( |
|
370 | + $httpRequest->getRawServerValue('PHP_AUTH_USER') |
|
371 | + ); |
|
372 | + }); |
|
373 | + } |
|
374 | + |
|
375 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
376 | + $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) { |
|
377 | + return $this->config->getSystemValue('data-fingerprint', ''); |
|
378 | + }); |
|
379 | + } |
|
380 | + |
|
381 | + if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
382 | + $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) { |
|
383 | + /** @var $node \OCA\DAV\Connector\Sabre\File */ |
|
384 | + try { |
|
385 | + $directDownloadUrl = $node->getDirectDownload(); |
|
386 | + if (isset($directDownloadUrl['url'])) { |
|
387 | + return $directDownloadUrl['url']; |
|
388 | + } |
|
389 | + } catch (StorageNotAvailableException $e) { |
|
390 | + return false; |
|
391 | + } catch (ForbiddenException $e) { |
|
392 | + return false; |
|
393 | + } |
|
394 | + return false; |
|
395 | + }); |
|
396 | + |
|
397 | + $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) { |
|
398 | + $checksum = $node->getChecksum(); |
|
399 | + if ($checksum === NULL || $checksum === '') { |
|
400 | + return null; |
|
401 | + } |
|
402 | + |
|
403 | + return new ChecksumList($checksum); |
|
404 | + }); |
|
405 | + |
|
406 | + $propFind->handle(self::CREATION_TIME_PROPERTYNAME, function() use ($node) { |
|
407 | + return $node->getFileInfo()->getCreationTime(); |
|
408 | + }); |
|
409 | + |
|
410 | + $propFind->handle(self::UPLOAD_TIME_PROPERTYNAME, function() use ($node) { |
|
411 | + return $node->getFileInfo()->getUploadTime(); |
|
412 | + }); |
|
413 | + |
|
414 | + } |
|
415 | + |
|
416 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) { |
|
417 | + $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
|
418 | + return $node->getSize(); |
|
419 | + }); |
|
420 | + |
|
421 | + $propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function() use ($node) { |
|
422 | + return $node->getFileInfo()->isEncrypted() ? '1' : '0'; |
|
423 | + }); |
|
424 | + } |
|
425 | + } |
|
426 | + |
|
427 | + /** |
|
428 | + * translate Nextcloud permissions to OCM Permissions |
|
429 | + * |
|
430 | + * @param $ncPermissions |
|
431 | + * @return array |
|
432 | + */ |
|
433 | + protected function ncPermissions2ocmPermissions($ncPermissions) { |
|
434 | + |
|
435 | + $ocmPermissions = []; |
|
436 | + |
|
437 | + if ($ncPermissions & Constants::PERMISSION_SHARE) { |
|
438 | + $ocmPermissions[] = 'share'; |
|
439 | + } |
|
440 | + |
|
441 | + if ($ncPermissions & Constants::PERMISSION_READ) { |
|
442 | + $ocmPermissions[] = 'read'; |
|
443 | + } |
|
444 | + |
|
445 | + if (($ncPermissions & Constants::PERMISSION_CREATE) || |
|
446 | + ($ncPermissions & Constants::PERMISSION_UPDATE)) { |
|
447 | + $ocmPermissions[] = 'write'; |
|
448 | + } |
|
449 | + |
|
450 | + return $ocmPermissions; |
|
451 | + |
|
452 | + } |
|
453 | + |
|
454 | + /** |
|
455 | + * Update ownCloud-specific properties |
|
456 | + * |
|
457 | + * @param string $path |
|
458 | + * @param PropPatch $propPatch |
|
459 | + * |
|
460 | + * @return void |
|
461 | + */ |
|
462 | + public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
463 | + $node = $this->tree->getNodeForPath($path); |
|
464 | + if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
465 | + return; |
|
466 | + } |
|
467 | + |
|
468 | + $propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function($time) use ($node) { |
|
469 | + if (empty($time)) { |
|
470 | + return false; |
|
471 | + } |
|
472 | + $node->touch($time); |
|
473 | + return true; |
|
474 | + }); |
|
475 | + $propPatch->handle(self::GETETAG_PROPERTYNAME, function($etag) use ($node) { |
|
476 | + if (empty($etag)) { |
|
477 | + return false; |
|
478 | + } |
|
479 | + if ($node->setEtag($etag) !== -1) { |
|
480 | + return true; |
|
481 | + } |
|
482 | + return false; |
|
483 | + }); |
|
484 | + $propPatch->handle(self::CREATION_TIME_PROPERTYNAME, function($time) use ($node) { |
|
485 | + if (empty($time)) { |
|
486 | + return false; |
|
487 | + } |
|
488 | + $node->setCreationTime((int) $time); |
|
489 | + return true; |
|
490 | + }); |
|
491 | + } |
|
492 | + |
|
493 | + /** |
|
494 | + * @param string $filePath |
|
495 | + * @param \Sabre\DAV\INode $node |
|
496 | + * @throws \Sabre\DAV\Exception\BadRequest |
|
497 | + */ |
|
498 | + public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) { |
|
499 | + // chunked upload handling |
|
500 | + if (isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
501 | + list($path, $name) = \Sabre\Uri\split($filePath); |
|
502 | + $info = \OC_FileChunking::decodeName($name); |
|
503 | + if (!empty($info)) { |
|
504 | + $filePath = $path . '/' . $info['name']; |
|
505 | + } |
|
506 | + } |
|
507 | + |
|
508 | + // we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder |
|
509 | + if (!$this->server->tree->nodeExists($filePath)) { |
|
510 | + return; |
|
511 | + } |
|
512 | + $node = $this->server->tree->getNodeForPath($filePath); |
|
513 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
514 | + $fileId = $node->getFileId(); |
|
515 | + if (!is_null($fileId)) { |
|
516 | + $this->server->httpResponse->setHeader('OC-FileId', $fileId); |
|
517 | + } |
|
518 | + } |
|
519 | + } |
|
520 | 520 | } |
@@ -60,9 +60,9 @@ |
||
60 | 60 | |
61 | 61 | public function propFind(PropFind $propFind, INode $node) { |
62 | 62 | /* Overload current-user-principal */ |
63 | - $propFind->handle('{DAV:}current-user-principal', function () { |
|
63 | + $propFind->handle('{DAV:}current-user-principal', function() { |
|
64 | 64 | if ($url = parent::getCurrentUserPrincipal()) { |
65 | - return new Principal(Principal::HREF, $url . '/'); |
|
65 | + return new Principal(Principal::HREF, $url.'/'); |
|
66 | 66 | } else { |
67 | 67 | return new Principal(Principal::UNAUTHENTICATED); |
68 | 68 | } |
@@ -38,7 +38,9 @@ |
||
38 | 38 | public function getCurrentUserPrincipals() { |
39 | 39 | $principalV2 = $this->getCurrentUserPrincipal(); |
40 | 40 | |
41 | - if (is_null($principalV2)) return []; |
|
41 | + if (is_null($principalV2)) { |
|
42 | + return []; |
|
43 | + } |
|
42 | 44 | |
43 | 45 | $principalV1 = $this->convertPrincipal($principalV2, false); |
44 | 46 | return array_merge( |
@@ -32,42 +32,42 @@ |
||
32 | 32 | |
33 | 33 | class LegacyDAVACL extends DavAclPlugin { |
34 | 34 | |
35 | - /** |
|
36 | - * @inheritdoc |
|
37 | - */ |
|
38 | - public function getCurrentUserPrincipals() { |
|
39 | - $principalV2 = $this->getCurrentUserPrincipal(); |
|
35 | + /** |
|
36 | + * @inheritdoc |
|
37 | + */ |
|
38 | + public function getCurrentUserPrincipals() { |
|
39 | + $principalV2 = $this->getCurrentUserPrincipal(); |
|
40 | 40 | |
41 | - if (is_null($principalV2)) return []; |
|
41 | + if (is_null($principalV2)) return []; |
|
42 | 42 | |
43 | - $principalV1 = $this->convertPrincipal($principalV2, false); |
|
44 | - return array_merge( |
|
45 | - [ |
|
46 | - $principalV2, |
|
47 | - $principalV1 |
|
48 | - ], |
|
49 | - $this->getPrincipalMembership($principalV1) |
|
50 | - ); |
|
51 | - } |
|
43 | + $principalV1 = $this->convertPrincipal($principalV2, false); |
|
44 | + return array_merge( |
|
45 | + [ |
|
46 | + $principalV2, |
|
47 | + $principalV1 |
|
48 | + ], |
|
49 | + $this->getPrincipalMembership($principalV1) |
|
50 | + ); |
|
51 | + } |
|
52 | 52 | |
53 | - private function convertPrincipal($principal, $toV2) { |
|
54 | - list(, $name) = \Sabre\Uri\split($principal); |
|
55 | - if ($toV2) { |
|
56 | - return "principals/users/$name"; |
|
57 | - } |
|
58 | - return "principals/$name"; |
|
59 | - } |
|
53 | + private function convertPrincipal($principal, $toV2) { |
|
54 | + list(, $name) = \Sabre\Uri\split($principal); |
|
55 | + if ($toV2) { |
|
56 | + return "principals/users/$name"; |
|
57 | + } |
|
58 | + return "principals/$name"; |
|
59 | + } |
|
60 | 60 | |
61 | - public function propFind(PropFind $propFind, INode $node) { |
|
62 | - /* Overload current-user-principal */ |
|
63 | - $propFind->handle('{DAV:}current-user-principal', function () { |
|
64 | - if ($url = parent::getCurrentUserPrincipal()) { |
|
65 | - return new Principal(Principal::HREF, $url . '/'); |
|
66 | - } else { |
|
67 | - return new Principal(Principal::UNAUTHENTICATED); |
|
68 | - } |
|
69 | - }); |
|
61 | + public function propFind(PropFind $propFind, INode $node) { |
|
62 | + /* Overload current-user-principal */ |
|
63 | + $propFind->handle('{DAV:}current-user-principal', function () { |
|
64 | + if ($url = parent::getCurrentUserPrincipal()) { |
|
65 | + return new Principal(Principal::HREF, $url . '/'); |
|
66 | + } else { |
|
67 | + return new Principal(Principal::UNAUTHENTICATED); |
|
68 | + } |
|
69 | + }); |
|
70 | 70 | |
71 | - return parent::propFind($propFind, $node); |
|
72 | - } |
|
71 | + return parent::propFind($propFind, $node); |
|
72 | + } |
|
73 | 73 | } |
@@ -28,35 +28,35 @@ |
||
28 | 28 | |
29 | 29 | class FixBirthdayCalendarComponent implements IRepairStep { |
30 | 30 | |
31 | - /** @var IDBConnection */ |
|
32 | - private $connection; |
|
33 | - |
|
34 | - /** |
|
35 | - * FixBirthdayCalendarComponent constructor. |
|
36 | - * |
|
37 | - * @param IDBConnection $connection |
|
38 | - */ |
|
39 | - public function __construct(IDBConnection $connection) { |
|
40 | - $this->connection = $connection; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * @inheritdoc |
|
45 | - */ |
|
46 | - public function getName() { |
|
47 | - return 'Fix component of birthday calendars'; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * @inheritdoc |
|
52 | - */ |
|
53 | - public function run(IOutput $output) { |
|
54 | - $query = $this->connection->getQueryBuilder(); |
|
55 | - $updated = $query->update('calendars') |
|
56 | - ->set('components', $query->createNamedParameter('VEVENT')) |
|
57 | - ->where($query->expr()->eq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))) |
|
58 | - ->execute(); |
|
59 | - |
|
60 | - $output->info("$updated birthday calendars updated."); |
|
61 | - } |
|
31 | + /** @var IDBConnection */ |
|
32 | + private $connection; |
|
33 | + |
|
34 | + /** |
|
35 | + * FixBirthdayCalendarComponent constructor. |
|
36 | + * |
|
37 | + * @param IDBConnection $connection |
|
38 | + */ |
|
39 | + public function __construct(IDBConnection $connection) { |
|
40 | + $this->connection = $connection; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * @inheritdoc |
|
45 | + */ |
|
46 | + public function getName() { |
|
47 | + return 'Fix component of birthday calendars'; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * @inheritdoc |
|
52 | + */ |
|
53 | + public function run(IOutput $output) { |
|
54 | + $query = $this->connection->getQueryBuilder(); |
|
55 | + $updated = $query->update('calendars') |
|
56 | + ->set('components', $query->createNamedParameter('VEVENT')) |
|
57 | + ->where($query->expr()->eq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))) |
|
58 | + ->execute(); |
|
59 | + |
|
60 | + $output->info("$updated birthday calendars updated."); |
|
61 | + } |
|
62 | 62 | } |
@@ -31,36 +31,36 @@ |
||
31 | 31 | |
32 | 32 | class SyncSystemAddressBook extends Command { |
33 | 33 | |
34 | - /** @var SyncService */ |
|
35 | - private $syncService; |
|
34 | + /** @var SyncService */ |
|
35 | + private $syncService; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param SyncService $syncService |
|
39 | - */ |
|
40 | - function __construct(SyncService $syncService) { |
|
41 | - parent::__construct(); |
|
42 | - $this->syncService = $syncService; |
|
43 | - } |
|
37 | + /** |
|
38 | + * @param SyncService $syncService |
|
39 | + */ |
|
40 | + function __construct(SyncService $syncService) { |
|
41 | + parent::__construct(); |
|
42 | + $this->syncService = $syncService; |
|
43 | + } |
|
44 | 44 | |
45 | - protected function configure() { |
|
46 | - $this |
|
47 | - ->setName('dav:sync-system-addressbook') |
|
48 | - ->setDescription('Synchronizes users to the system addressbook'); |
|
49 | - } |
|
45 | + protected function configure() { |
|
46 | + $this |
|
47 | + ->setName('dav:sync-system-addressbook') |
|
48 | + ->setDescription('Synchronizes users to the system addressbook'); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param InputInterface $input |
|
53 | - * @param OutputInterface $output |
|
54 | - */ |
|
55 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
56 | - $output->writeln('Syncing users ...'); |
|
57 | - $progress = new ProgressBar($output); |
|
58 | - $progress->start(); |
|
59 | - $this->syncService->syncInstance(function() use ($progress) { |
|
60 | - $progress->advance(); |
|
61 | - }); |
|
51 | + /** |
|
52 | + * @param InputInterface $input |
|
53 | + * @param OutputInterface $output |
|
54 | + */ |
|
55 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
56 | + $output->writeln('Syncing users ...'); |
|
57 | + $progress = new ProgressBar($output); |
|
58 | + $progress->start(); |
|
59 | + $this->syncService->syncInstance(function() use ($progress) { |
|
60 | + $progress->advance(); |
|
61 | + }); |
|
62 | 62 | |
63 | - $progress->finish(); |
|
64 | - $output->writeln(''); |
|
65 | - } |
|
63 | + $progress->finish(); |
|
64 | + $output->writeln(''); |
|
65 | + } |
|
66 | 66 | } |
@@ -36,43 +36,43 @@ |
||
36 | 36 | |
37 | 37 | class CreateAddressBook extends Command { |
38 | 38 | |
39 | - /** @var IUserManager */ |
|
40 | - private $userManager; |
|
39 | + /** @var IUserManager */ |
|
40 | + private $userManager; |
|
41 | 41 | |
42 | - /** @var CardDavBackend */ |
|
43 | - private $cardDavBackend; |
|
42 | + /** @var CardDavBackend */ |
|
43 | + private $cardDavBackend; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param IUserManager $userManager |
|
47 | - * @param CardDavBackend $cardDavBackend |
|
48 | - */ |
|
49 | - function __construct(IUserManager $userManager, |
|
50 | - CardDavBackend $cardDavBackend |
|
51 | - ) { |
|
52 | - parent::__construct(); |
|
53 | - $this->userManager = $userManager; |
|
54 | - $this->cardDavBackend = $cardDavBackend; |
|
55 | - } |
|
45 | + /** |
|
46 | + * @param IUserManager $userManager |
|
47 | + * @param CardDavBackend $cardDavBackend |
|
48 | + */ |
|
49 | + function __construct(IUserManager $userManager, |
|
50 | + CardDavBackend $cardDavBackend |
|
51 | + ) { |
|
52 | + parent::__construct(); |
|
53 | + $this->userManager = $userManager; |
|
54 | + $this->cardDavBackend = $cardDavBackend; |
|
55 | + } |
|
56 | 56 | |
57 | - protected function configure() { |
|
58 | - $this |
|
59 | - ->setName('dav:create-addressbook') |
|
60 | - ->setDescription('Create a dav addressbook') |
|
61 | - ->addArgument('user', |
|
62 | - InputArgument::REQUIRED, |
|
63 | - 'User for whom the addressbook will be created') |
|
64 | - ->addArgument('name', |
|
65 | - InputArgument::REQUIRED, |
|
66 | - 'Name of the addressbook'); |
|
67 | - } |
|
57 | + protected function configure() { |
|
58 | + $this |
|
59 | + ->setName('dav:create-addressbook') |
|
60 | + ->setDescription('Create a dav addressbook') |
|
61 | + ->addArgument('user', |
|
62 | + InputArgument::REQUIRED, |
|
63 | + 'User for whom the addressbook will be created') |
|
64 | + ->addArgument('name', |
|
65 | + InputArgument::REQUIRED, |
|
66 | + 'Name of the addressbook'); |
|
67 | + } |
|
68 | 68 | |
69 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
70 | - $user = $input->getArgument('user'); |
|
71 | - if (!$this->userManager->userExists($user)) { |
|
72 | - throw new \InvalidArgumentException("User <$user> in unknown."); |
|
73 | - } |
|
69 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
70 | + $user = $input->getArgument('user'); |
|
71 | + if (!$this->userManager->userExists($user)) { |
|
72 | + throw new \InvalidArgumentException("User <$user> in unknown."); |
|
73 | + } |
|
74 | 74 | |
75 | - $name = $input->getArgument('name'); |
|
76 | - $this->cardDavBackend->createAddressBook("principals/users/$user", $name, []); |
|
77 | - } |
|
75 | + $name = $input->getArgument('name'); |
|
76 | + $this->cardDavBackend->createAddressBook("principals/users/$user", $name, []); |
|
77 | + } |
|
78 | 78 | } |
@@ -26,11 +26,11 @@ |
||
26 | 26 | |
27 | 27 | class Capabilities implements ICapability { |
28 | 28 | |
29 | - public function getCapabilities() { |
|
30 | - return [ |
|
31 | - 'dav' => [ |
|
32 | - 'chunking' => '1.0', |
|
33 | - ] |
|
34 | - ]; |
|
35 | - } |
|
29 | + public function getCapabilities() { |
|
30 | + return [ |
|
31 | + 'dav' => [ |
|
32 | + 'chunking' => '1.0', |
|
33 | + ] |
|
34 | + ]; |
|
35 | + } |
|
36 | 36 | } |
@@ -31,78 +31,78 @@ |
||
31 | 31 | use Sabre\DAV\ServerPlugin; |
32 | 32 | |
33 | 33 | class BrowserErrorPagePlugin extends ServerPlugin { |
34 | - /** @var Server */ |
|
35 | - private $server; |
|
34 | + /** @var Server */ |
|
35 | + private $server; |
|
36 | 36 | |
37 | - /** |
|
38 | - * This initializes the plugin. |
|
39 | - * |
|
40 | - * This function is called by Sabre\DAV\Server, after |
|
41 | - * addPlugin is called. |
|
42 | - * |
|
43 | - * This method should set up the required event subscriptions. |
|
44 | - * |
|
45 | - * @param Server $server |
|
46 | - * @return void |
|
47 | - */ |
|
48 | - function initialize(Server $server) { |
|
49 | - $this->server = $server; |
|
50 | - $server->on('exception', array($this, 'logException'), 1000); |
|
51 | - } |
|
37 | + /** |
|
38 | + * This initializes the plugin. |
|
39 | + * |
|
40 | + * This function is called by Sabre\DAV\Server, after |
|
41 | + * addPlugin is called. |
|
42 | + * |
|
43 | + * This method should set up the required event subscriptions. |
|
44 | + * |
|
45 | + * @param Server $server |
|
46 | + * @return void |
|
47 | + */ |
|
48 | + function initialize(Server $server) { |
|
49 | + $this->server = $server; |
|
50 | + $server->on('exception', array($this, 'logException'), 1000); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param IRequest $request |
|
55 | - * @return bool |
|
56 | - */ |
|
57 | - public static function isBrowserRequest(IRequest $request) { |
|
58 | - if ($request->getMethod() !== 'GET') { |
|
59 | - return false; |
|
60 | - } |
|
61 | - return $request->isUserAgent([ |
|
62 | - Request::USER_AGENT_IE, |
|
63 | - Request::USER_AGENT_MS_EDGE, |
|
64 | - Request::USER_AGENT_CHROME, |
|
65 | - Request::USER_AGENT_FIREFOX, |
|
66 | - Request::USER_AGENT_SAFARI, |
|
67 | - ]); |
|
68 | - } |
|
53 | + /** |
|
54 | + * @param IRequest $request |
|
55 | + * @return bool |
|
56 | + */ |
|
57 | + public static function isBrowserRequest(IRequest $request) { |
|
58 | + if ($request->getMethod() !== 'GET') { |
|
59 | + return false; |
|
60 | + } |
|
61 | + return $request->isUserAgent([ |
|
62 | + Request::USER_AGENT_IE, |
|
63 | + Request::USER_AGENT_MS_EDGE, |
|
64 | + Request::USER_AGENT_CHROME, |
|
65 | + Request::USER_AGENT_FIREFOX, |
|
66 | + Request::USER_AGENT_SAFARI, |
|
67 | + ]); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * @param \Exception $ex |
|
72 | - */ |
|
73 | - public function logException(\Exception $ex) { |
|
74 | - if ($ex instanceof Exception) { |
|
75 | - $httpCode = $ex->getHTTPCode(); |
|
76 | - $headers = $ex->getHTTPHeaders($this->server); |
|
77 | - } else { |
|
78 | - $httpCode = 500; |
|
79 | - $headers = []; |
|
80 | - } |
|
81 | - $this->server->httpResponse->addHeaders($headers); |
|
82 | - $this->server->httpResponse->setStatus($httpCode); |
|
83 | - $body = $this->generateBody(); |
|
84 | - $this->server->httpResponse->setBody($body); |
|
85 | - $this->sendResponse(); |
|
86 | - } |
|
70 | + /** |
|
71 | + * @param \Exception $ex |
|
72 | + */ |
|
73 | + public function logException(\Exception $ex) { |
|
74 | + if ($ex instanceof Exception) { |
|
75 | + $httpCode = $ex->getHTTPCode(); |
|
76 | + $headers = $ex->getHTTPHeaders($this->server); |
|
77 | + } else { |
|
78 | + $httpCode = 500; |
|
79 | + $headers = []; |
|
80 | + } |
|
81 | + $this->server->httpResponse->addHeaders($headers); |
|
82 | + $this->server->httpResponse->setStatus($httpCode); |
|
83 | + $body = $this->generateBody(); |
|
84 | + $this->server->httpResponse->setBody($body); |
|
85 | + $this->sendResponse(); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @codeCoverageIgnore |
|
90 | - * @return bool|string |
|
91 | - */ |
|
92 | - public function generateBody() { |
|
93 | - $request = \OC::$server->getRequest(); |
|
94 | - $content = new OC_Template('dav', 'exception', 'guest'); |
|
95 | - $content->assign('title', $this->server->httpResponse->getStatusText()); |
|
96 | - $content->assign('remoteAddr', $request->getRemoteAddress()); |
|
97 | - $content->assign('requestID', $request->getId()); |
|
98 | - return $content->fetchPage(); |
|
99 | - } |
|
88 | + /** |
|
89 | + * @codeCoverageIgnore |
|
90 | + * @return bool|string |
|
91 | + */ |
|
92 | + public function generateBody() { |
|
93 | + $request = \OC::$server->getRequest(); |
|
94 | + $content = new OC_Template('dav', 'exception', 'guest'); |
|
95 | + $content->assign('title', $this->server->httpResponse->getStatusText()); |
|
96 | + $content->assign('remoteAddr', $request->getRemoteAddress()); |
|
97 | + $content->assign('requestID', $request->getId()); |
|
98 | + return $content->fetchPage(); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @codeCoverageIgnore |
|
103 | - */ |
|
104 | - public function sendResponse() { |
|
105 | - $this->server->sapi->sendResponse($this->server->httpResponse); |
|
106 | - exit(); |
|
107 | - } |
|
101 | + /** |
|
102 | + * @codeCoverageIgnore |
|
103 | + */ |
|
104 | + public function sendResponse() { |
|
105 | + $this->server->sapi->sendResponse($this->server->httpResponse); |
|
106 | + exit(); |
|
107 | + } |
|
108 | 108 | } |
@@ -32,33 +32,33 @@ |
||
32 | 32 | * Verify that the public link share is valid |
33 | 33 | */ |
34 | 34 | class PublicLinkCheckPlugin extends ServerPlugin { |
35 | - /** |
|
36 | - * @var FileInfo |
|
37 | - */ |
|
38 | - private $fileInfo; |
|
35 | + /** |
|
36 | + * @var FileInfo |
|
37 | + */ |
|
38 | + private $fileInfo; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param FileInfo $fileInfo |
|
42 | - */ |
|
43 | - public function setFileInfo($fileInfo) { |
|
44 | - $this->fileInfo = $fileInfo; |
|
45 | - } |
|
40 | + /** |
|
41 | + * @param FileInfo $fileInfo |
|
42 | + */ |
|
43 | + public function setFileInfo($fileInfo) { |
|
44 | + $this->fileInfo = $fileInfo; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * This initializes the plugin. |
|
49 | - * |
|
50 | - * @param \Sabre\DAV\Server $server Sabre server |
|
51 | - * |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - public function initialize(\Sabre\DAV\Server $server) { |
|
55 | - $server->on('beforeMethod', [$this, 'beforeMethod']); |
|
56 | - } |
|
47 | + /** |
|
48 | + * This initializes the plugin. |
|
49 | + * |
|
50 | + * @param \Sabre\DAV\Server $server Sabre server |
|
51 | + * |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + public function initialize(\Sabre\DAV\Server $server) { |
|
55 | + $server->on('beforeMethod', [$this, 'beforeMethod']); |
|
56 | + } |
|
57 | 57 | |
58 | - public function beforeMethod(RequestInterface $request, ResponseInterface $response){ |
|
59 | - // verify that the owner didn't have his share permissions revoked |
|
60 | - if ($this->fileInfo && !$this->fileInfo->isShareable()) { |
|
61 | - throw new NotFound(); |
|
62 | - } |
|
63 | - } |
|
58 | + public function beforeMethod(RequestInterface $request, ResponseInterface $response){ |
|
59 | + // verify that the owner didn't have his share permissions revoked |
|
60 | + if ($this->fileInfo && !$this->fileInfo->isShareable()) { |
|
61 | + throw new NotFound(); |
|
62 | + } |
|
63 | + } |
|
64 | 64 | } |
@@ -55,7 +55,7 @@ |
||
55 | 55 | $server->on('beforeMethod', [$this, 'beforeMethod']); |
56 | 56 | } |
57 | 57 | |
58 | - public function beforeMethod(RequestInterface $request, ResponseInterface $response){ |
|
58 | + public function beforeMethod(RequestInterface $request, ResponseInterface $response) { |
|
59 | 59 | // verify that the owner didn't have his share permissions revoked |
60 | 60 | if ($this->fileInfo && !$this->fileInfo->isShareable()) { |
61 | 61 | throw new NotFound(); |
@@ -33,52 +33,52 @@ |
||
33 | 33 | */ |
34 | 34 | class FilesDropPlugin extends ServerPlugin { |
35 | 35 | |
36 | - /** @var View */ |
|
37 | - private $view; |
|
36 | + /** @var View */ |
|
37 | + private $view; |
|
38 | 38 | |
39 | - /** @var bool */ |
|
40 | - private $enabled = false; |
|
39 | + /** @var bool */ |
|
40 | + private $enabled = false; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param View $view |
|
44 | - */ |
|
45 | - public function setView($view) { |
|
46 | - $this->view = $view; |
|
47 | - } |
|
42 | + /** |
|
43 | + * @param View $view |
|
44 | + */ |
|
45 | + public function setView($view) { |
|
46 | + $this->view = $view; |
|
47 | + } |
|
48 | 48 | |
49 | - public function enable() { |
|
50 | - $this->enabled = true; |
|
51 | - } |
|
49 | + public function enable() { |
|
50 | + $this->enabled = true; |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * This initializes the plugin. |
|
56 | - * |
|
57 | - * @param \Sabre\DAV\Server $server Sabre server |
|
58 | - * |
|
59 | - * @return void |
|
60 | - * @throws MethodNotAllowed |
|
61 | - */ |
|
62 | - public function initialize(\Sabre\DAV\Server $server) { |
|
63 | - $server->on('beforeMethod', [$this, 'beforeMethod'], 999); |
|
64 | - $this->enabled = false; |
|
65 | - } |
|
54 | + /** |
|
55 | + * This initializes the plugin. |
|
56 | + * |
|
57 | + * @param \Sabre\DAV\Server $server Sabre server |
|
58 | + * |
|
59 | + * @return void |
|
60 | + * @throws MethodNotAllowed |
|
61 | + */ |
|
62 | + public function initialize(\Sabre\DAV\Server $server) { |
|
63 | + $server->on('beforeMethod', [$this, 'beforeMethod'], 999); |
|
64 | + $this->enabled = false; |
|
65 | + } |
|
66 | 66 | |
67 | - public function beforeMethod(RequestInterface $request, ResponseInterface $response){ |
|
67 | + public function beforeMethod(RequestInterface $request, ResponseInterface $response){ |
|
68 | 68 | |
69 | - if (!$this->enabled) { |
|
70 | - return; |
|
71 | - } |
|
69 | + if (!$this->enabled) { |
|
70 | + return; |
|
71 | + } |
|
72 | 72 | |
73 | - if ($request->getMethod() !== 'PUT') { |
|
74 | - throw new MethodNotAllowed('Only PUT is allowed on files drop'); |
|
75 | - } |
|
73 | + if ($request->getMethod() !== 'PUT') { |
|
74 | + throw new MethodNotAllowed('Only PUT is allowed on files drop'); |
|
75 | + } |
|
76 | 76 | |
77 | - $path = explode('/', $request->getPath()); |
|
78 | - $path = array_pop($path); |
|
77 | + $path = explode('/', $request->getPath()); |
|
78 | + $path = array_pop($path); |
|
79 | 79 | |
80 | - $newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view); |
|
81 | - $url = $request->getBaseUrl() . $newName; |
|
82 | - $request->setUrl($url); |
|
83 | - } |
|
80 | + $newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view); |
|
81 | + $url = $request->getBaseUrl() . $newName; |
|
82 | + $request->setUrl($url); |
|
83 | + } |
|
84 | 84 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $this->enabled = false; |
65 | 65 | } |
66 | 66 | |
67 | - public function beforeMethod(RequestInterface $request, ResponseInterface $response){ |
|
67 | + public function beforeMethod(RequestInterface $request, ResponseInterface $response) { |
|
68 | 68 | |
69 | 69 | if (!$this->enabled) { |
70 | 70 | return; |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | $path = array_pop($path); |
79 | 79 | |
80 | 80 | $newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view); |
81 | - $url = $request->getBaseUrl() . $newName; |
|
81 | + $url = $request->getBaseUrl().$newName; |
|
82 | 82 | $request->setUrl($url); |
83 | 83 | } |
84 | 84 | } |