@@ -49,453 +49,453 @@ |
||
| 49 | 49 | |
| 50 | 50 | class FilesPlugin extends ServerPlugin { |
| 51 | 51 | |
| 52 | - // namespace |
|
| 53 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 54 | - const NS_NEXTCLOUD = 'http://nextcloud.org/ns'; |
|
| 55 | - const FILEID_PROPERTYNAME = '{http://owncloud.org/ns}id'; |
|
| 56 | - const INTERNAL_FILEID_PROPERTYNAME = '{http://owncloud.org/ns}fileid'; |
|
| 57 | - const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions'; |
|
| 58 | - const SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-collaboration-services.org/ns}share-permissions'; |
|
| 59 | - const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL'; |
|
| 60 | - const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size'; |
|
| 61 | - const GETETAG_PROPERTYNAME = '{DAV:}getetag'; |
|
| 62 | - const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified'; |
|
| 63 | - const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id'; |
|
| 64 | - const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name'; |
|
| 65 | - const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums'; |
|
| 66 | - const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint'; |
|
| 67 | - const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview'; |
|
| 68 | - const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type'; |
|
| 69 | - const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted'; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Reference to main server object |
|
| 73 | - * |
|
| 74 | - * @var \Sabre\DAV\Server |
|
| 75 | - */ |
|
| 76 | - private $server; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @var Tree |
|
| 80 | - */ |
|
| 81 | - private $tree; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Whether this is public webdav. |
|
| 85 | - * If true, some returned information will be stripped off. |
|
| 86 | - * |
|
| 87 | - * @var bool |
|
| 88 | - */ |
|
| 89 | - private $isPublic; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @var View |
|
| 93 | - */ |
|
| 94 | - private $fileView; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @var bool |
|
| 98 | - */ |
|
| 99 | - private $downloadAttachment; |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @var IConfig |
|
| 103 | - */ |
|
| 104 | - private $config; |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @var IRequest |
|
| 108 | - */ |
|
| 109 | - private $request; |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @var IPreview |
|
| 113 | - */ |
|
| 114 | - private $previewManager; |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @param Tree $tree |
|
| 118 | - * @param IConfig $config |
|
| 119 | - * @param IRequest $request |
|
| 120 | - * @param IPreview $previewManager |
|
| 121 | - * @param bool $isPublic |
|
| 122 | - * @param bool $downloadAttachment |
|
| 123 | - */ |
|
| 124 | - public function __construct(Tree $tree, |
|
| 125 | - IConfig $config, |
|
| 126 | - IRequest $request, |
|
| 127 | - IPreview $previewManager, |
|
| 128 | - $isPublic = false, |
|
| 129 | - $downloadAttachment = true) { |
|
| 130 | - $this->tree = $tree; |
|
| 131 | - $this->config = $config; |
|
| 132 | - $this->request = $request; |
|
| 133 | - $this->isPublic = $isPublic; |
|
| 134 | - $this->downloadAttachment = $downloadAttachment; |
|
| 135 | - $this->previewManager = $previewManager; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * This initializes the plugin. |
|
| 140 | - * |
|
| 141 | - * This function is called by \Sabre\DAV\Server, after |
|
| 142 | - * addPlugin is called. |
|
| 143 | - * |
|
| 144 | - * This method should set up the required event subscriptions. |
|
| 145 | - * |
|
| 146 | - * @param \Sabre\DAV\Server $server |
|
| 147 | - * @return void |
|
| 148 | - */ |
|
| 149 | - public function initialize(\Sabre\DAV\Server $server) { |
|
| 150 | - $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
| 151 | - $server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc'; |
|
| 152 | - $server->protectedProperties[] = self::FILEID_PROPERTYNAME; |
|
| 153 | - $server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME; |
|
| 154 | - $server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME; |
|
| 155 | - $server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME; |
|
| 156 | - $server->protectedProperties[] = self::SIZE_PROPERTYNAME; |
|
| 157 | - $server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME; |
|
| 158 | - $server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME; |
|
| 159 | - $server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME; |
|
| 160 | - $server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME; |
|
| 161 | - $server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME; |
|
| 162 | - $server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME; |
|
| 163 | - $server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME; |
|
| 164 | - $server->protectedProperties[] = self::IS_ENCRYPTED_PROPERTYNAME; |
|
| 165 | - |
|
| 166 | - // normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH |
|
| 167 | - $allowedProperties = ['{DAV:}getetag']; |
|
| 168 | - $server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties); |
|
| 169 | - |
|
| 170 | - $this->server = $server; |
|
| 171 | - $this->server->on('propFind', array($this, 'handleGetProperties')); |
|
| 172 | - $this->server->on('propPatch', array($this, 'handleUpdateProperties')); |
|
| 173 | - $this->server->on('afterBind', array($this, 'sendFileIdHeader')); |
|
| 174 | - $this->server->on('afterWriteContent', array($this, 'sendFileIdHeader')); |
|
| 175 | - $this->server->on('afterMethod:GET', [$this,'httpGet']); |
|
| 176 | - $this->server->on('afterMethod:GET', array($this, 'handleDownloadToken')); |
|
| 177 | - $this->server->on('afterResponse', function($request, ResponseInterface $response) { |
|
| 178 | - $body = $response->getBody(); |
|
| 179 | - if (is_resource($body)) { |
|
| 180 | - fclose($body); |
|
| 181 | - } |
|
| 182 | - }); |
|
| 183 | - $this->server->on('beforeMove', [$this, 'checkMove']); |
|
| 184 | - $this->server->on('beforeMove', [$this, 'beforeMoveFutureFile']); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Plugin that checks if a move can actually be performed. |
|
| 189 | - * |
|
| 190 | - * @param string $source source path |
|
| 191 | - * @param string $destination destination path |
|
| 192 | - * @throws Forbidden |
|
| 193 | - * @throws NotFound |
|
| 194 | - */ |
|
| 195 | - function checkMove($source, $destination) { |
|
| 196 | - $sourceNode = $this->tree->getNodeForPath($source); |
|
| 197 | - if (!$sourceNode instanceof Node) { |
|
| 198 | - return; |
|
| 199 | - } |
|
| 200 | - list($sourceDir,) = \Sabre\Uri\split($source); |
|
| 201 | - list($destinationDir,) = \Sabre\Uri\split($destination); |
|
| 202 | - |
|
| 203 | - if ($sourceDir !== $destinationDir) { |
|
| 204 | - $sourceNodeFileInfo = $sourceNode->getFileInfo(); |
|
| 205 | - if ($sourceNodeFileInfo === null) { |
|
| 206 | - throw new NotFound($source . ' does not exist'); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - if (!$sourceNodeFileInfo->isDeletable()) { |
|
| 210 | - throw new Forbidden($source . " cannot be deleted"); |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * This sets a cookie to be able to recognize the start of the download |
|
| 217 | - * the content must not be longer than 32 characters and must only contain |
|
| 218 | - * alphanumeric characters |
|
| 219 | - * |
|
| 220 | - * @param RequestInterface $request |
|
| 221 | - * @param ResponseInterface $response |
|
| 222 | - */ |
|
| 223 | - function handleDownloadToken(RequestInterface $request, ResponseInterface $response) { |
|
| 224 | - $queryParams = $request->getQueryParameters(); |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * this sets a cookie to be able to recognize the start of the download |
|
| 228 | - * the content must not be longer than 32 characters and must only contain |
|
| 229 | - * alphanumeric characters |
|
| 230 | - */ |
|
| 231 | - if (isset($queryParams['downloadStartSecret'])) { |
|
| 232 | - $token = $queryParams['downloadStartSecret']; |
|
| 233 | - if (!isset($token[32]) |
|
| 234 | - && preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) { |
|
| 235 | - // FIXME: use $response->setHeader() instead |
|
| 236 | - setcookie('ocDownloadStarted', $token, time() + 20, '/'); |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * Add headers to file download |
|
| 243 | - * |
|
| 244 | - * @param RequestInterface $request |
|
| 245 | - * @param ResponseInterface $response |
|
| 246 | - */ |
|
| 247 | - function httpGet(RequestInterface $request, ResponseInterface $response) { |
|
| 248 | - // Only handle valid files |
|
| 249 | - $node = $this->tree->getNodeForPath($request->getPath()); |
|
| 250 | - if (!($node instanceof IFile)) return; |
|
| 251 | - |
|
| 252 | - // adds a 'Content-Disposition: attachment' header in case no disposition |
|
| 253 | - // header has been set before |
|
| 254 | - if ($this->downloadAttachment && |
|
| 255 | - $response->getHeader('Content-Disposition') === null) { |
|
| 256 | - $filename = $node->getName(); |
|
| 257 | - if ($this->request->isUserAgent( |
|
| 258 | - [ |
|
| 259 | - \OC\AppFramework\Http\Request::USER_AGENT_IE, |
|
| 260 | - \OC\AppFramework\Http\Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
|
| 261 | - \OC\AppFramework\Http\Request::USER_AGENT_FREEBOX, |
|
| 262 | - ])) { |
|
| 263 | - $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"'); |
|
| 264 | - } else { |
|
| 265 | - $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename) |
|
| 266 | - . '; filename="' . rawurlencode($filename) . '"'); |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
| 271 | - //Add OC-Checksum header |
|
| 272 | - /** @var $node File */ |
|
| 273 | - $checksum = $node->getChecksum(); |
|
| 274 | - if ($checksum !== null && $checksum !== '') { |
|
| 275 | - $response->addHeader('OC-Checksum', $checksum); |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * Adds all ownCloud-specific properties |
|
| 282 | - * |
|
| 283 | - * @param PropFind $propFind |
|
| 284 | - * @param \Sabre\DAV\INode $node |
|
| 285 | - * @return void |
|
| 286 | - */ |
|
| 287 | - public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) { |
|
| 288 | - |
|
| 289 | - $httpRequest = $this->server->httpRequest; |
|
| 290 | - |
|
| 291 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
| 292 | - /** |
|
| 293 | - * This was disabled, because it made dir listing throw an exception, |
|
| 294 | - * so users were unable to navigate into folders where one subitem |
|
| 295 | - * is blocked by the files_accesscontrol app, see: |
|
| 296 | - * https://github.com/nextcloud/files_accesscontrol/issues/65 |
|
| 52 | + // namespace |
|
| 53 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 54 | + const NS_NEXTCLOUD = 'http://nextcloud.org/ns'; |
|
| 55 | + const FILEID_PROPERTYNAME = '{http://owncloud.org/ns}id'; |
|
| 56 | + const INTERNAL_FILEID_PROPERTYNAME = '{http://owncloud.org/ns}fileid'; |
|
| 57 | + const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions'; |
|
| 58 | + const SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-collaboration-services.org/ns}share-permissions'; |
|
| 59 | + const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL'; |
|
| 60 | + const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size'; |
|
| 61 | + const GETETAG_PROPERTYNAME = '{DAV:}getetag'; |
|
| 62 | + const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified'; |
|
| 63 | + const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id'; |
|
| 64 | + const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name'; |
|
| 65 | + const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums'; |
|
| 66 | + const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint'; |
|
| 67 | + const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview'; |
|
| 68 | + const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type'; |
|
| 69 | + const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted'; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Reference to main server object |
|
| 73 | + * |
|
| 74 | + * @var \Sabre\DAV\Server |
|
| 75 | + */ |
|
| 76 | + private $server; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @var Tree |
|
| 80 | + */ |
|
| 81 | + private $tree; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Whether this is public webdav. |
|
| 85 | + * If true, some returned information will be stripped off. |
|
| 86 | + * |
|
| 87 | + * @var bool |
|
| 88 | + */ |
|
| 89 | + private $isPublic; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @var View |
|
| 93 | + */ |
|
| 94 | + private $fileView; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @var bool |
|
| 98 | + */ |
|
| 99 | + private $downloadAttachment; |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @var IConfig |
|
| 103 | + */ |
|
| 104 | + private $config; |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @var IRequest |
|
| 108 | + */ |
|
| 109 | + private $request; |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @var IPreview |
|
| 113 | + */ |
|
| 114 | + private $previewManager; |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @param Tree $tree |
|
| 118 | + * @param IConfig $config |
|
| 119 | + * @param IRequest $request |
|
| 120 | + * @param IPreview $previewManager |
|
| 121 | + * @param bool $isPublic |
|
| 122 | + * @param bool $downloadAttachment |
|
| 123 | + */ |
|
| 124 | + public function __construct(Tree $tree, |
|
| 125 | + IConfig $config, |
|
| 126 | + IRequest $request, |
|
| 127 | + IPreview $previewManager, |
|
| 128 | + $isPublic = false, |
|
| 129 | + $downloadAttachment = true) { |
|
| 130 | + $this->tree = $tree; |
|
| 131 | + $this->config = $config; |
|
| 132 | + $this->request = $request; |
|
| 133 | + $this->isPublic = $isPublic; |
|
| 134 | + $this->downloadAttachment = $downloadAttachment; |
|
| 135 | + $this->previewManager = $previewManager; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * This initializes the plugin. |
|
| 140 | + * |
|
| 141 | + * This function is called by \Sabre\DAV\Server, after |
|
| 142 | + * addPlugin is called. |
|
| 143 | + * |
|
| 144 | + * This method should set up the required event subscriptions. |
|
| 145 | + * |
|
| 146 | + * @param \Sabre\DAV\Server $server |
|
| 147 | + * @return void |
|
| 148 | + */ |
|
| 149 | + public function initialize(\Sabre\DAV\Server $server) { |
|
| 150 | + $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
| 151 | + $server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc'; |
|
| 152 | + $server->protectedProperties[] = self::FILEID_PROPERTYNAME; |
|
| 153 | + $server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME; |
|
| 154 | + $server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME; |
|
| 155 | + $server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME; |
|
| 156 | + $server->protectedProperties[] = self::SIZE_PROPERTYNAME; |
|
| 157 | + $server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME; |
|
| 158 | + $server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME; |
|
| 159 | + $server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME; |
|
| 160 | + $server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME; |
|
| 161 | + $server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME; |
|
| 162 | + $server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME; |
|
| 163 | + $server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME; |
|
| 164 | + $server->protectedProperties[] = self::IS_ENCRYPTED_PROPERTYNAME; |
|
| 165 | + |
|
| 166 | + // normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH |
|
| 167 | + $allowedProperties = ['{DAV:}getetag']; |
|
| 168 | + $server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties); |
|
| 169 | + |
|
| 170 | + $this->server = $server; |
|
| 171 | + $this->server->on('propFind', array($this, 'handleGetProperties')); |
|
| 172 | + $this->server->on('propPatch', array($this, 'handleUpdateProperties')); |
|
| 173 | + $this->server->on('afterBind', array($this, 'sendFileIdHeader')); |
|
| 174 | + $this->server->on('afterWriteContent', array($this, 'sendFileIdHeader')); |
|
| 175 | + $this->server->on('afterMethod:GET', [$this,'httpGet']); |
|
| 176 | + $this->server->on('afterMethod:GET', array($this, 'handleDownloadToken')); |
|
| 177 | + $this->server->on('afterResponse', function($request, ResponseInterface $response) { |
|
| 178 | + $body = $response->getBody(); |
|
| 179 | + if (is_resource($body)) { |
|
| 180 | + fclose($body); |
|
| 181 | + } |
|
| 182 | + }); |
|
| 183 | + $this->server->on('beforeMove', [$this, 'checkMove']); |
|
| 184 | + $this->server->on('beforeMove', [$this, 'beforeMoveFutureFile']); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Plugin that checks if a move can actually be performed. |
|
| 189 | + * |
|
| 190 | + * @param string $source source path |
|
| 191 | + * @param string $destination destination path |
|
| 192 | + * @throws Forbidden |
|
| 193 | + * @throws NotFound |
|
| 194 | + */ |
|
| 195 | + function checkMove($source, $destination) { |
|
| 196 | + $sourceNode = $this->tree->getNodeForPath($source); |
|
| 197 | + if (!$sourceNode instanceof Node) { |
|
| 198 | + return; |
|
| 199 | + } |
|
| 200 | + list($sourceDir,) = \Sabre\Uri\split($source); |
|
| 201 | + list($destinationDir,) = \Sabre\Uri\split($destination); |
|
| 202 | + |
|
| 203 | + if ($sourceDir !== $destinationDir) { |
|
| 204 | + $sourceNodeFileInfo = $sourceNode->getFileInfo(); |
|
| 205 | + if ($sourceNodeFileInfo === null) { |
|
| 206 | + throw new NotFound($source . ' does not exist'); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + if (!$sourceNodeFileInfo->isDeletable()) { |
|
| 210 | + throw new Forbidden($source . " cannot be deleted"); |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * This sets a cookie to be able to recognize the start of the download |
|
| 217 | + * the content must not be longer than 32 characters and must only contain |
|
| 218 | + * alphanumeric characters |
|
| 219 | + * |
|
| 220 | + * @param RequestInterface $request |
|
| 221 | + * @param ResponseInterface $response |
|
| 222 | + */ |
|
| 223 | + function handleDownloadToken(RequestInterface $request, ResponseInterface $response) { |
|
| 224 | + $queryParams = $request->getQueryParameters(); |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * this sets a cookie to be able to recognize the start of the download |
|
| 228 | + * the content must not be longer than 32 characters and must only contain |
|
| 229 | + * alphanumeric characters |
|
| 230 | + */ |
|
| 231 | + if (isset($queryParams['downloadStartSecret'])) { |
|
| 232 | + $token = $queryParams['downloadStartSecret']; |
|
| 233 | + if (!isset($token[32]) |
|
| 234 | + && preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) { |
|
| 235 | + // FIXME: use $response->setHeader() instead |
|
| 236 | + setcookie('ocDownloadStarted', $token, time() + 20, '/'); |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * Add headers to file download |
|
| 243 | + * |
|
| 244 | + * @param RequestInterface $request |
|
| 245 | + * @param ResponseInterface $response |
|
| 246 | + */ |
|
| 247 | + function httpGet(RequestInterface $request, ResponseInterface $response) { |
|
| 248 | + // Only handle valid files |
|
| 249 | + $node = $this->tree->getNodeForPath($request->getPath()); |
|
| 250 | + if (!($node instanceof IFile)) return; |
|
| 251 | + |
|
| 252 | + // adds a 'Content-Disposition: attachment' header in case no disposition |
|
| 253 | + // header has been set before |
|
| 254 | + if ($this->downloadAttachment && |
|
| 255 | + $response->getHeader('Content-Disposition') === null) { |
|
| 256 | + $filename = $node->getName(); |
|
| 257 | + if ($this->request->isUserAgent( |
|
| 258 | + [ |
|
| 259 | + \OC\AppFramework\Http\Request::USER_AGENT_IE, |
|
| 260 | + \OC\AppFramework\Http\Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
|
| 261 | + \OC\AppFramework\Http\Request::USER_AGENT_FREEBOX, |
|
| 262 | + ])) { |
|
| 263 | + $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"'); |
|
| 264 | + } else { |
|
| 265 | + $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename) |
|
| 266 | + . '; filename="' . rawurlencode($filename) . '"'); |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
| 271 | + //Add OC-Checksum header |
|
| 272 | + /** @var $node File */ |
|
| 273 | + $checksum = $node->getChecksum(); |
|
| 274 | + if ($checksum !== null && $checksum !== '') { |
|
| 275 | + $response->addHeader('OC-Checksum', $checksum); |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * Adds all ownCloud-specific properties |
|
| 282 | + * |
|
| 283 | + * @param PropFind $propFind |
|
| 284 | + * @param \Sabre\DAV\INode $node |
|
| 285 | + * @return void |
|
| 286 | + */ |
|
| 287 | + public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) { |
|
| 288 | + |
|
| 289 | + $httpRequest = $this->server->httpRequest; |
|
| 290 | + |
|
| 291 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
| 292 | + /** |
|
| 293 | + * This was disabled, because it made dir listing throw an exception, |
|
| 294 | + * so users were unable to navigate into folders where one subitem |
|
| 295 | + * is blocked by the files_accesscontrol app, see: |
|
| 296 | + * https://github.com/nextcloud/files_accesscontrol/issues/65 |
|
| 297 | 297 | if (!$node->getFileInfo()->isReadable()) { |
| 298 | 298 | // avoid detecting files through this means |
| 299 | 299 | throw new NotFound(); |
| 300 | 300 | } |
| 301 | - */ |
|
| 302 | - |
|
| 303 | - $propFind->handle(self::FILEID_PROPERTYNAME, function() use ($node) { |
|
| 304 | - return $node->getFileId(); |
|
| 305 | - }); |
|
| 306 | - |
|
| 307 | - $propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function() use ($node) { |
|
| 308 | - return $node->getInternalFileId(); |
|
| 309 | - }); |
|
| 310 | - |
|
| 311 | - $propFind->handle(self::PERMISSIONS_PROPERTYNAME, function() use ($node) { |
|
| 312 | - $perms = $node->getDavPermissions(); |
|
| 313 | - if ($this->isPublic) { |
|
| 314 | - // remove mount information |
|
| 315 | - $perms = str_replace(['S', 'M'], '', $perms); |
|
| 316 | - } |
|
| 317 | - return $perms; |
|
| 318 | - }); |
|
| 319 | - |
|
| 320 | - $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) { |
|
| 321 | - return $node->getSharePermissions( |
|
| 322 | - $httpRequest->getRawServerValue('PHP_AUTH_USER') |
|
| 323 | - ); |
|
| 324 | - }); |
|
| 325 | - |
|
| 326 | - $propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) { |
|
| 327 | - return $node->getETag(); |
|
| 328 | - }); |
|
| 329 | - |
|
| 330 | - $propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) { |
|
| 331 | - $owner = $node->getOwner(); |
|
| 332 | - if (!$owner) { |
|
| 333 | - return null; |
|
| 334 | - } else { |
|
| 335 | - return $owner->getUID(); |
|
| 336 | - } |
|
| 337 | - }); |
|
| 338 | - $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) { |
|
| 339 | - $owner = $node->getOwner(); |
|
| 340 | - if (!$owner) { |
|
| 341 | - return null; |
|
| 342 | - } else { |
|
| 343 | - return $owner->getDisplayName(); |
|
| 344 | - } |
|
| 345 | - }); |
|
| 346 | - |
|
| 347 | - $propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function() use ($node) { |
|
| 348 | - $result = $node->getFileInfo()->isEncrypted() ? '1' : '0'; |
|
| 349 | - return $result; |
|
| 350 | - }); |
|
| 351 | - |
|
| 352 | - $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { |
|
| 353 | - return json_encode($this->previewManager->isAvailable($node->getFileInfo())); |
|
| 354 | - }); |
|
| 355 | - $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
|
| 356 | - return $node->getSize(); |
|
| 357 | - }); |
|
| 358 | - $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { |
|
| 359 | - return $node->getFileInfo()->getMountPoint()->getMountType(); |
|
| 360 | - }); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
| 364 | - $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) { |
|
| 365 | - return $this->config->getSystemValue('data-fingerprint', ''); |
|
| 366 | - }); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
| 370 | - $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) { |
|
| 371 | - /** @var $node \OCA\DAV\Connector\Sabre\File */ |
|
| 372 | - try { |
|
| 373 | - $directDownloadUrl = $node->getDirectDownload(); |
|
| 374 | - if (isset($directDownloadUrl['url'])) { |
|
| 375 | - return $directDownloadUrl['url']; |
|
| 376 | - } |
|
| 377 | - } catch (StorageNotAvailableException $e) { |
|
| 378 | - return false; |
|
| 379 | - } catch (ForbiddenException $e) { |
|
| 380 | - return false; |
|
| 381 | - } |
|
| 382 | - return false; |
|
| 383 | - }); |
|
| 384 | - |
|
| 385 | - $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) { |
|
| 386 | - $checksum = $node->getChecksum(); |
|
| 387 | - if ($checksum === NULL || $checksum === '') { |
|
| 388 | - return null; |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - return new ChecksumList($checksum); |
|
| 392 | - }); |
|
| 393 | - |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) { |
|
| 397 | - $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
|
| 398 | - return $node->getSize(); |
|
| 399 | - }); |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * Update ownCloud-specific properties |
|
| 405 | - * |
|
| 406 | - * @param string $path |
|
| 407 | - * @param PropPatch $propPatch |
|
| 408 | - * |
|
| 409 | - * @return void |
|
| 410 | - */ |
|
| 411 | - public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
| 412 | - $node = $this->tree->getNodeForPath($path); |
|
| 413 | - if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
| 414 | - return; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - $propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function($time) use ($node) { |
|
| 418 | - if (empty($time)) { |
|
| 419 | - return false; |
|
| 420 | - } |
|
| 421 | - $node->touch($time); |
|
| 422 | - return true; |
|
| 423 | - }); |
|
| 424 | - $propPatch->handle(self::GETETAG_PROPERTYNAME, function($etag) use ($node) { |
|
| 425 | - if (empty($etag)) { |
|
| 426 | - return false; |
|
| 427 | - } |
|
| 428 | - if ($node->setEtag($etag) !== -1) { |
|
| 429 | - return true; |
|
| 430 | - } |
|
| 431 | - return false; |
|
| 432 | - }); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * @param string $filePath |
|
| 437 | - * @param \Sabre\DAV\INode $node |
|
| 438 | - * @throws \Sabre\DAV\Exception\BadRequest |
|
| 439 | - */ |
|
| 440 | - public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) { |
|
| 441 | - // chunked upload handling |
|
| 442 | - if (isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
| 443 | - list($path, $name) = \Sabre\Uri\split($filePath); |
|
| 444 | - $info = \OC_FileChunking::decodeName($name); |
|
| 445 | - if (!empty($info)) { |
|
| 446 | - $filePath = $path . '/' . $info['name']; |
|
| 447 | - } |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - // we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder |
|
| 451 | - if (!$this->server->tree->nodeExists($filePath)) { |
|
| 452 | - return; |
|
| 453 | - } |
|
| 454 | - $node = $this->server->tree->getNodeForPath($filePath); |
|
| 455 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
| 456 | - $fileId = $node->getFileId(); |
|
| 457 | - if (!is_null($fileId)) { |
|
| 458 | - $this->server->httpResponse->setHeader('OC-FileId', $fileId); |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * Move handler for future file. |
|
| 465 | - * |
|
| 466 | - * This overrides the default move behavior to prevent Sabre |
|
| 467 | - * to delete the target file before moving. Because deleting would |
|
| 468 | - * lose the file id and metadata. |
|
| 469 | - * |
|
| 470 | - * @param string $path source path |
|
| 471 | - * @param string $destination destination path |
|
| 472 | - * @return bool|void false to stop handling, void to skip this handler |
|
| 473 | - */ |
|
| 474 | - public function beforeMoveFutureFile($path, $destination) { |
|
| 475 | - $sourceNode = $this->tree->getNodeForPath($path); |
|
| 476 | - if (!$sourceNode instanceof FutureFile) { |
|
| 477 | - // skip handling as the source is not a chunked FutureFile |
|
| 478 | - return; |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - if (!$this->tree->nodeExists($destination)) { |
|
| 482 | - // skip and let the default handler do its work |
|
| 483 | - return; |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - // do a move manually, skipping Sabre's default "delete" for existing nodes |
|
| 487 | - $this->tree->move($path, $destination); |
|
| 488 | - |
|
| 489 | - // trigger all default events (copied from CorePlugin::move) |
|
| 490 | - $this->server->emit('afterMove', [$path, $destination]); |
|
| 491 | - $this->server->emit('afterUnbind', [$path]); |
|
| 492 | - $this->server->emit('afterBind', [$destination]); |
|
| 493 | - |
|
| 494 | - $response = $this->server->httpResponse; |
|
| 495 | - $response->setHeader('Content-Length', '0'); |
|
| 496 | - $response->setStatus(204); |
|
| 497 | - |
|
| 498 | - return false; |
|
| 499 | - } |
|
| 301 | + */ |
|
| 302 | + |
|
| 303 | + $propFind->handle(self::FILEID_PROPERTYNAME, function() use ($node) { |
|
| 304 | + return $node->getFileId(); |
|
| 305 | + }); |
|
| 306 | + |
|
| 307 | + $propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function() use ($node) { |
|
| 308 | + return $node->getInternalFileId(); |
|
| 309 | + }); |
|
| 310 | + |
|
| 311 | + $propFind->handle(self::PERMISSIONS_PROPERTYNAME, function() use ($node) { |
|
| 312 | + $perms = $node->getDavPermissions(); |
|
| 313 | + if ($this->isPublic) { |
|
| 314 | + // remove mount information |
|
| 315 | + $perms = str_replace(['S', 'M'], '', $perms); |
|
| 316 | + } |
|
| 317 | + return $perms; |
|
| 318 | + }); |
|
| 319 | + |
|
| 320 | + $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) { |
|
| 321 | + return $node->getSharePermissions( |
|
| 322 | + $httpRequest->getRawServerValue('PHP_AUTH_USER') |
|
| 323 | + ); |
|
| 324 | + }); |
|
| 325 | + |
|
| 326 | + $propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) { |
|
| 327 | + return $node->getETag(); |
|
| 328 | + }); |
|
| 329 | + |
|
| 330 | + $propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) { |
|
| 331 | + $owner = $node->getOwner(); |
|
| 332 | + if (!$owner) { |
|
| 333 | + return null; |
|
| 334 | + } else { |
|
| 335 | + return $owner->getUID(); |
|
| 336 | + } |
|
| 337 | + }); |
|
| 338 | + $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) { |
|
| 339 | + $owner = $node->getOwner(); |
|
| 340 | + if (!$owner) { |
|
| 341 | + return null; |
|
| 342 | + } else { |
|
| 343 | + return $owner->getDisplayName(); |
|
| 344 | + } |
|
| 345 | + }); |
|
| 346 | + |
|
| 347 | + $propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function() use ($node) { |
|
| 348 | + $result = $node->getFileInfo()->isEncrypted() ? '1' : '0'; |
|
| 349 | + return $result; |
|
| 350 | + }); |
|
| 351 | + |
|
| 352 | + $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { |
|
| 353 | + return json_encode($this->previewManager->isAvailable($node->getFileInfo())); |
|
| 354 | + }); |
|
| 355 | + $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
|
| 356 | + return $node->getSize(); |
|
| 357 | + }); |
|
| 358 | + $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { |
|
| 359 | + return $node->getFileInfo()->getMountPoint()->getMountType(); |
|
| 360 | + }); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
| 364 | + $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) { |
|
| 365 | + return $this->config->getSystemValue('data-fingerprint', ''); |
|
| 366 | + }); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
| 370 | + $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) { |
|
| 371 | + /** @var $node \OCA\DAV\Connector\Sabre\File */ |
|
| 372 | + try { |
|
| 373 | + $directDownloadUrl = $node->getDirectDownload(); |
|
| 374 | + if (isset($directDownloadUrl['url'])) { |
|
| 375 | + return $directDownloadUrl['url']; |
|
| 376 | + } |
|
| 377 | + } catch (StorageNotAvailableException $e) { |
|
| 378 | + return false; |
|
| 379 | + } catch (ForbiddenException $e) { |
|
| 380 | + return false; |
|
| 381 | + } |
|
| 382 | + return false; |
|
| 383 | + }); |
|
| 384 | + |
|
| 385 | + $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) { |
|
| 386 | + $checksum = $node->getChecksum(); |
|
| 387 | + if ($checksum === NULL || $checksum === '') { |
|
| 388 | + return null; |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + return new ChecksumList($checksum); |
|
| 392 | + }); |
|
| 393 | + |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) { |
|
| 397 | + $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
|
| 398 | + return $node->getSize(); |
|
| 399 | + }); |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * Update ownCloud-specific properties |
|
| 405 | + * |
|
| 406 | + * @param string $path |
|
| 407 | + * @param PropPatch $propPatch |
|
| 408 | + * |
|
| 409 | + * @return void |
|
| 410 | + */ |
|
| 411 | + public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
| 412 | + $node = $this->tree->getNodeForPath($path); |
|
| 413 | + if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
| 414 | + return; |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + $propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function($time) use ($node) { |
|
| 418 | + if (empty($time)) { |
|
| 419 | + return false; |
|
| 420 | + } |
|
| 421 | + $node->touch($time); |
|
| 422 | + return true; |
|
| 423 | + }); |
|
| 424 | + $propPatch->handle(self::GETETAG_PROPERTYNAME, function($etag) use ($node) { |
|
| 425 | + if (empty($etag)) { |
|
| 426 | + return false; |
|
| 427 | + } |
|
| 428 | + if ($node->setEtag($etag) !== -1) { |
|
| 429 | + return true; |
|
| 430 | + } |
|
| 431 | + return false; |
|
| 432 | + }); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * @param string $filePath |
|
| 437 | + * @param \Sabre\DAV\INode $node |
|
| 438 | + * @throws \Sabre\DAV\Exception\BadRequest |
|
| 439 | + */ |
|
| 440 | + public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) { |
|
| 441 | + // chunked upload handling |
|
| 442 | + if (isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
| 443 | + list($path, $name) = \Sabre\Uri\split($filePath); |
|
| 444 | + $info = \OC_FileChunking::decodeName($name); |
|
| 445 | + if (!empty($info)) { |
|
| 446 | + $filePath = $path . '/' . $info['name']; |
|
| 447 | + } |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + // we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder |
|
| 451 | + if (!$this->server->tree->nodeExists($filePath)) { |
|
| 452 | + return; |
|
| 453 | + } |
|
| 454 | + $node = $this->server->tree->getNodeForPath($filePath); |
|
| 455 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
| 456 | + $fileId = $node->getFileId(); |
|
| 457 | + if (!is_null($fileId)) { |
|
| 458 | + $this->server->httpResponse->setHeader('OC-FileId', $fileId); |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * Move handler for future file. |
|
| 465 | + * |
|
| 466 | + * This overrides the default move behavior to prevent Sabre |
|
| 467 | + * to delete the target file before moving. Because deleting would |
|
| 468 | + * lose the file id and metadata. |
|
| 469 | + * |
|
| 470 | + * @param string $path source path |
|
| 471 | + * @param string $destination destination path |
|
| 472 | + * @return bool|void false to stop handling, void to skip this handler |
|
| 473 | + */ |
|
| 474 | + public function beforeMoveFutureFile($path, $destination) { |
|
| 475 | + $sourceNode = $this->tree->getNodeForPath($path); |
|
| 476 | + if (!$sourceNode instanceof FutureFile) { |
|
| 477 | + // skip handling as the source is not a chunked FutureFile |
|
| 478 | + return; |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + if (!$this->tree->nodeExists($destination)) { |
|
| 482 | + // skip and let the default handler do its work |
|
| 483 | + return; |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + // do a move manually, skipping Sabre's default "delete" for existing nodes |
|
| 487 | + $this->tree->move($path, $destination); |
|
| 488 | + |
|
| 489 | + // trigger all default events (copied from CorePlugin::move) |
|
| 490 | + $this->server->emit('afterMove', [$path, $destination]); |
|
| 491 | + $this->server->emit('afterUnbind', [$path]); |
|
| 492 | + $this->server->emit('afterBind', [$destination]); |
|
| 493 | + |
|
| 494 | + $response = $this->server->httpResponse; |
|
| 495 | + $response->setHeader('Content-Length', '0'); |
|
| 496 | + $response->setStatus(204); |
|
| 497 | + |
|
| 498 | + return false; |
|
| 499 | + } |
|
| 500 | 500 | |
| 501 | 501 | } |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | $this->server->on('propPatch', array($this, 'handleUpdateProperties')); |
| 173 | 173 | $this->server->on('afterBind', array($this, 'sendFileIdHeader')); |
| 174 | 174 | $this->server->on('afterWriteContent', array($this, 'sendFileIdHeader')); |
| 175 | - $this->server->on('afterMethod:GET', [$this,'httpGet']); |
|
| 175 | + $this->server->on('afterMethod:GET', [$this, 'httpGet']); |
|
| 176 | 176 | $this->server->on('afterMethod:GET', array($this, 'handleDownloadToken')); |
| 177 | 177 | $this->server->on('afterResponse', function($request, ResponseInterface $response) { |
| 178 | 178 | $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 | \OC\AppFramework\Http\Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
| 261 | 261 | \OC\AppFramework\Http\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 | |
@@ -349,13 +349,13 @@ discard block |
||
| 349 | 349 | return $result; |
| 350 | 350 | }); |
| 351 | 351 | |
| 352 | - $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { |
|
| 352 | + $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function() use ($node) { |
|
| 353 | 353 | return json_encode($this->previewManager->isAvailable($node->getFileInfo())); |
| 354 | 354 | }); |
| 355 | 355 | $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
| 356 | 356 | return $node->getSize(); |
| 357 | 357 | }); |
| 358 | - $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { |
|
| 358 | + $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function() use ($node) { |
|
| 359 | 359 | return $node->getFileInfo()->getMountPoint()->getMountType(); |
| 360 | 360 | }); |
| 361 | 361 | } |
@@ -443,7 +443,7 @@ discard block |
||
| 443 | 443 | list($path, $name) = \Sabre\Uri\split($filePath); |
| 444 | 444 | $info = \OC_FileChunking::decodeName($name); |
| 445 | 445 | if (!empty($info)) { |
| 446 | - $filePath = $path . '/' . $info['name']; |
|
| 446 | + $filePath = $path.'/'.$info['name']; |
|
| 447 | 447 | } |
| 448 | 448 | } |
| 449 | 449 | |