@@ -34,92 +34,92 @@ |
||
| 34 | 34 | * This property contains multiple "tag" elements, each containing a tag name. |
| 35 | 35 | */ |
| 36 | 36 | class TagList implements Element { |
| 37 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 37 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * tags |
|
| 41 | - * |
|
| 42 | - * @var array |
|
| 43 | - */ |
|
| 44 | - private $tags; |
|
| 39 | + /** |
|
| 40 | + * tags |
|
| 41 | + * |
|
| 42 | + * @var array |
|
| 43 | + */ |
|
| 44 | + private $tags; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @param array $tags |
|
| 48 | - */ |
|
| 49 | - public function __construct(array $tags) { |
|
| 50 | - $this->tags = $tags; |
|
| 51 | - } |
|
| 46 | + /** |
|
| 47 | + * @param array $tags |
|
| 48 | + */ |
|
| 49 | + public function __construct(array $tags) { |
|
| 50 | + $this->tags = $tags; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Returns the tags |
|
| 55 | - * |
|
| 56 | - * @return array |
|
| 57 | - */ |
|
| 58 | - public function getTags() { |
|
| 53 | + /** |
|
| 54 | + * Returns the tags |
|
| 55 | + * |
|
| 56 | + * @return array |
|
| 57 | + */ |
|
| 58 | + public function getTags() { |
|
| 59 | 59 | |
| 60 | - return $this->tags; |
|
| 60 | + return $this->tags; |
|
| 61 | 61 | |
| 62 | - } |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * The deserialize method is called during xml parsing. |
|
| 66 | - * |
|
| 67 | - * This method is called statictly, this is because in theory this method |
|
| 68 | - * may be used as a type of constructor, or factory method. |
|
| 69 | - * |
|
| 70 | - * Often you want to return an instance of the current class, but you are |
|
| 71 | - * free to return other data as well. |
|
| 72 | - * |
|
| 73 | - * You are responsible for advancing the reader to the next element. Not |
|
| 74 | - * doing anything will result in a never-ending loop. |
|
| 75 | - * |
|
| 76 | - * If you just want to skip parsing for this element altogether, you can |
|
| 77 | - * just call $reader->next(); |
|
| 78 | - * |
|
| 79 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
| 80 | - * the next element. |
|
| 81 | - * |
|
| 82 | - * @param Reader $reader |
|
| 83 | - * @return mixed |
|
| 84 | - */ |
|
| 85 | - static function xmlDeserialize(Reader $reader) { |
|
| 86 | - $tags = []; |
|
| 64 | + /** |
|
| 65 | + * The deserialize method is called during xml parsing. |
|
| 66 | + * |
|
| 67 | + * This method is called statictly, this is because in theory this method |
|
| 68 | + * may be used as a type of constructor, or factory method. |
|
| 69 | + * |
|
| 70 | + * Often you want to return an instance of the current class, but you are |
|
| 71 | + * free to return other data as well. |
|
| 72 | + * |
|
| 73 | + * You are responsible for advancing the reader to the next element. Not |
|
| 74 | + * doing anything will result in a never-ending loop. |
|
| 75 | + * |
|
| 76 | + * If you just want to skip parsing for this element altogether, you can |
|
| 77 | + * just call $reader->next(); |
|
| 78 | + * |
|
| 79 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
| 80 | + * the next element. |
|
| 81 | + * |
|
| 82 | + * @param Reader $reader |
|
| 83 | + * @return mixed |
|
| 84 | + */ |
|
| 85 | + static function xmlDeserialize(Reader $reader) { |
|
| 86 | + $tags = []; |
|
| 87 | 87 | |
| 88 | - $tree = $reader->parseInnerTree(); |
|
| 89 | - if ($tree === null) { |
|
| 90 | - return null; |
|
| 91 | - } |
|
| 92 | - foreach ($tree as $elem) { |
|
| 93 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
| 94 | - $tags[] = $elem['value']; |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - return new self($tags); |
|
| 98 | - } |
|
| 88 | + $tree = $reader->parseInnerTree(); |
|
| 89 | + if ($tree === null) { |
|
| 90 | + return null; |
|
| 91 | + } |
|
| 92 | + foreach ($tree as $elem) { |
|
| 93 | + if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
| 94 | + $tags[] = $elem['value']; |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + return new self($tags); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * The xmlSerialize metod is called during xml writing. |
|
| 102 | - * |
|
| 103 | - * Use the $writer argument to write its own xml serialization. |
|
| 104 | - * |
|
| 105 | - * An important note: do _not_ create a parent element. Any element |
|
| 106 | - * implementing XmlSerializble should only ever write what's considered |
|
| 107 | - * its 'inner xml'. |
|
| 108 | - * |
|
| 109 | - * The parent of the current element is responsible for writing a |
|
| 110 | - * containing element. |
|
| 111 | - * |
|
| 112 | - * This allows serializers to be re-used for different element names. |
|
| 113 | - * |
|
| 114 | - * If you are opening new elements, you must also close them again. |
|
| 115 | - * |
|
| 116 | - * @param Writer $writer |
|
| 117 | - * @return void |
|
| 118 | - */ |
|
| 119 | - function xmlSerialize(Writer $writer) { |
|
| 100 | + /** |
|
| 101 | + * The xmlSerialize metod is called during xml writing. |
|
| 102 | + * |
|
| 103 | + * Use the $writer argument to write its own xml serialization. |
|
| 104 | + * |
|
| 105 | + * An important note: do _not_ create a parent element. Any element |
|
| 106 | + * implementing XmlSerializble should only ever write what's considered |
|
| 107 | + * its 'inner xml'. |
|
| 108 | + * |
|
| 109 | + * The parent of the current element is responsible for writing a |
|
| 110 | + * containing element. |
|
| 111 | + * |
|
| 112 | + * This allows serializers to be re-used for different element names. |
|
| 113 | + * |
|
| 114 | + * If you are opening new elements, you must also close them again. |
|
| 115 | + * |
|
| 116 | + * @param Writer $writer |
|
| 117 | + * @return void |
|
| 118 | + */ |
|
| 119 | + function xmlSerialize(Writer $writer) { |
|
| 120 | 120 | |
| 121 | - foreach ($this->tags as $tag) { |
|
| 122 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
| 123 | - } |
|
| 124 | - } |
|
| 121 | + foreach ($this->tags as $tag) { |
|
| 122 | + $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | 125 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | return null; |
| 91 | 91 | } |
| 92 | 92 | foreach ($tree as $elem) { |
| 93 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
| 93 | + if ($elem['name'] === '{'.self::NS_OWNCLOUD.'}tag') { |
|
| 94 | 94 | $tags[] = $elem['value']; |
| 95 | 95 | } |
| 96 | 96 | } |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | function xmlSerialize(Writer $writer) { |
| 120 | 120 | |
| 121 | 121 | foreach ($this->tags as $tag) { |
| 122 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
| 122 | + $writer->writeElement('{'.self::NS_OWNCLOUD.'}tag', $tag); |
|
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | } |
@@ -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 |
@@ -51,452 +51,452 @@ |
||
| 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 SHARE_NOTE = '{http://nextcloud.org/ns}note'; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Reference to main server object |
|
| 77 | - * |
|
| 78 | - * @var \Sabre\DAV\Server |
|
| 79 | - */ |
|
| 80 | - private $server; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * @var Tree |
|
| 84 | - */ |
|
| 85 | - private $tree; |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Whether this is public webdav. |
|
| 89 | - * If true, some returned information will be stripped off. |
|
| 90 | - * |
|
| 91 | - * @var bool |
|
| 92 | - */ |
|
| 93 | - private $isPublic; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @var bool |
|
| 97 | - */ |
|
| 98 | - private $downloadAttachment; |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @var IConfig |
|
| 102 | - */ |
|
| 103 | - private $config; |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @var IRequest |
|
| 107 | - */ |
|
| 108 | - private $request; |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * @var IPreview |
|
| 112 | - */ |
|
| 113 | - private $previewManager; |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @param Tree $tree |
|
| 117 | - * @param IConfig $config |
|
| 118 | - * @param IRequest $request |
|
| 119 | - * @param IPreview $previewManager |
|
| 120 | - * @param bool $isPublic |
|
| 121 | - * @param bool $downloadAttachment |
|
| 122 | - */ |
|
| 123 | - public function __construct(Tree $tree, |
|
| 124 | - IConfig $config, |
|
| 125 | - IRequest $request, |
|
| 126 | - IPreview $previewManager, |
|
| 127 | - $isPublic = false, |
|
| 128 | - $downloadAttachment = true) { |
|
| 129 | - $this->tree = $tree; |
|
| 130 | - $this->config = $config; |
|
| 131 | - $this->request = $request; |
|
| 132 | - $this->isPublic = $isPublic; |
|
| 133 | - $this->downloadAttachment = $downloadAttachment; |
|
| 134 | - $this->previewManager = $previewManager; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * This initializes the plugin. |
|
| 139 | - * |
|
| 140 | - * This function is called by \Sabre\DAV\Server, after |
|
| 141 | - * addPlugin is called. |
|
| 142 | - * |
|
| 143 | - * This method should set up the required event subscriptions. |
|
| 144 | - * |
|
| 145 | - * @param \Sabre\DAV\Server $server |
|
| 146 | - * @return void |
|
| 147 | - */ |
|
| 148 | - public function initialize(\Sabre\DAV\Server $server) { |
|
| 149 | - $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
| 150 | - $server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc'; |
|
| 151 | - $server->protectedProperties[] = self::FILEID_PROPERTYNAME; |
|
| 152 | - $server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME; |
|
| 153 | - $server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME; |
|
| 154 | - $server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME; |
|
| 155 | - $server->protectedProperties[] = self::OCM_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 | - $server->protectedProperties[] = self::SHARE_NOTE; |
|
| 166 | - |
|
| 167 | - // normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH |
|
| 168 | - $allowedProperties = ['{DAV:}getetag']; |
|
| 169 | - $server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties); |
|
| 170 | - |
|
| 171 | - $this->server = $server; |
|
| 172 | - $this->server->on('propFind', array($this, 'handleGetProperties')); |
|
| 173 | - $this->server->on('propPatch', array($this, 'handleUpdateProperties')); |
|
| 174 | - $this->server->on('afterBind', array($this, 'sendFileIdHeader')); |
|
| 175 | - $this->server->on('afterWriteContent', array($this, 'sendFileIdHeader')); |
|
| 176 | - $this->server->on('afterMethod:GET', [$this,'httpGet']); |
|
| 177 | - $this->server->on('afterMethod:GET', array($this, 'handleDownloadToken')); |
|
| 178 | - $this->server->on('afterResponse', function($request, ResponseInterface $response) { |
|
| 179 | - $body = $response->getBody(); |
|
| 180 | - if (is_resource($body)) { |
|
| 181 | - fclose($body); |
|
| 182 | - } |
|
| 183 | - }); |
|
| 184 | - $this->server->on('beforeMove', [$this, 'checkMove']); |
|
| 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 | - Request::USER_AGENT_IE, |
|
| 260 | - Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
|
| 261 | - 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 |
|
| 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 SHARE_NOTE = '{http://nextcloud.org/ns}note'; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Reference to main server object |
|
| 77 | + * |
|
| 78 | + * @var \Sabre\DAV\Server |
|
| 79 | + */ |
|
| 80 | + private $server; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * @var Tree |
|
| 84 | + */ |
|
| 85 | + private $tree; |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Whether this is public webdav. |
|
| 89 | + * If true, some returned information will be stripped off. |
|
| 90 | + * |
|
| 91 | + * @var bool |
|
| 92 | + */ |
|
| 93 | + private $isPublic; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @var bool |
|
| 97 | + */ |
|
| 98 | + private $downloadAttachment; |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @var IConfig |
|
| 102 | + */ |
|
| 103 | + private $config; |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @var IRequest |
|
| 107 | + */ |
|
| 108 | + private $request; |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * @var IPreview |
|
| 112 | + */ |
|
| 113 | + private $previewManager; |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @param Tree $tree |
|
| 117 | + * @param IConfig $config |
|
| 118 | + * @param IRequest $request |
|
| 119 | + * @param IPreview $previewManager |
|
| 120 | + * @param bool $isPublic |
|
| 121 | + * @param bool $downloadAttachment |
|
| 122 | + */ |
|
| 123 | + public function __construct(Tree $tree, |
|
| 124 | + IConfig $config, |
|
| 125 | + IRequest $request, |
|
| 126 | + IPreview $previewManager, |
|
| 127 | + $isPublic = false, |
|
| 128 | + $downloadAttachment = true) { |
|
| 129 | + $this->tree = $tree; |
|
| 130 | + $this->config = $config; |
|
| 131 | + $this->request = $request; |
|
| 132 | + $this->isPublic = $isPublic; |
|
| 133 | + $this->downloadAttachment = $downloadAttachment; |
|
| 134 | + $this->previewManager = $previewManager; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * This initializes the plugin. |
|
| 139 | + * |
|
| 140 | + * This function is called by \Sabre\DAV\Server, after |
|
| 141 | + * addPlugin is called. |
|
| 142 | + * |
|
| 143 | + * This method should set up the required event subscriptions. |
|
| 144 | + * |
|
| 145 | + * @param \Sabre\DAV\Server $server |
|
| 146 | + * @return void |
|
| 147 | + */ |
|
| 148 | + public function initialize(\Sabre\DAV\Server $server) { |
|
| 149 | + $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
| 150 | + $server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc'; |
|
| 151 | + $server->protectedProperties[] = self::FILEID_PROPERTYNAME; |
|
| 152 | + $server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME; |
|
| 153 | + $server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME; |
|
| 154 | + $server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME; |
|
| 155 | + $server->protectedProperties[] = self::OCM_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 | + $server->protectedProperties[] = self::SHARE_NOTE; |
|
| 166 | + |
|
| 167 | + // normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH |
|
| 168 | + $allowedProperties = ['{DAV:}getetag']; |
|
| 169 | + $server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties); |
|
| 170 | + |
|
| 171 | + $this->server = $server; |
|
| 172 | + $this->server->on('propFind', array($this, 'handleGetProperties')); |
|
| 173 | + $this->server->on('propPatch', array($this, 'handleUpdateProperties')); |
|
| 174 | + $this->server->on('afterBind', array($this, 'sendFileIdHeader')); |
|
| 175 | + $this->server->on('afterWriteContent', array($this, 'sendFileIdHeader')); |
|
| 176 | + $this->server->on('afterMethod:GET', [$this,'httpGet']); |
|
| 177 | + $this->server->on('afterMethod:GET', array($this, 'handleDownloadToken')); |
|
| 178 | + $this->server->on('afterResponse', function($request, ResponseInterface $response) { |
|
| 179 | + $body = $response->getBody(); |
|
| 180 | + if (is_resource($body)) { |
|
| 181 | + fclose($body); |
|
| 182 | + } |
|
| 183 | + }); |
|
| 184 | + $this->server->on('beforeMove', [$this, 'checkMove']); |
|
| 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 | + Request::USER_AGENT_IE, |
|
| 260 | + Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
|
| 261 | + 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::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) { |
|
| 327 | - $ncPermissions = $node->getSharePermissions( |
|
| 328 | - $httpRequest->getRawServerValue('PHP_AUTH_USER') |
|
| 329 | - ); |
|
| 330 | - $ocmPermissions = $this->ncPermissions2ocmPermissions($ncPermissions); |
|
| 331 | - return json_encode($ocmPermissions); |
|
| 332 | - }); |
|
| 333 | - |
|
| 334 | - $propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) { |
|
| 335 | - return $node->getETag(); |
|
| 336 | - }); |
|
| 337 | - |
|
| 338 | - $propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) { |
|
| 339 | - $owner = $node->getOwner(); |
|
| 340 | - if (!$owner) { |
|
| 341 | - return null; |
|
| 342 | - } else { |
|
| 343 | - return $owner->getUID(); |
|
| 344 | - } |
|
| 345 | - }); |
|
| 346 | - $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) { |
|
| 347 | - $owner = $node->getOwner(); |
|
| 348 | - if (!$owner) { |
|
| 349 | - return null; |
|
| 350 | - } else { |
|
| 351 | - return $owner->getDisplayName(); |
|
| 352 | - } |
|
| 353 | - }); |
|
| 354 | - |
|
| 355 | - $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { |
|
| 356 | - return json_encode($this->previewManager->isAvailable($node->getFileInfo())); |
|
| 357 | - }); |
|
| 358 | - $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
|
| 359 | - return $node->getSize(); |
|
| 360 | - }); |
|
| 361 | - $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { |
|
| 362 | - return $node->getFileInfo()->getMountPoint()->getMountType(); |
|
| 363 | - }); |
|
| 364 | - |
|
| 365 | - $propFind->handle(self::SHARE_NOTE, function() use ($node, $httpRequest) { |
|
| 366 | - return $node->getNoteFromShare( |
|
| 367 | - $httpRequest->getRawServerValue('PHP_AUTH_USER') |
|
| 368 | - ); |
|
| 369 | - }); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
| 373 | - $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) { |
|
| 374 | - return $this->config->getSystemValue('data-fingerprint', ''); |
|
| 375 | - }); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
| 379 | - $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) { |
|
| 380 | - /** @var $node \OCA\DAV\Connector\Sabre\File */ |
|
| 381 | - try { |
|
| 382 | - $directDownloadUrl = $node->getDirectDownload(); |
|
| 383 | - if (isset($directDownloadUrl['url'])) { |
|
| 384 | - return $directDownloadUrl['url']; |
|
| 385 | - } |
|
| 386 | - } catch (StorageNotAvailableException $e) { |
|
| 387 | - return false; |
|
| 388 | - } catch (ForbiddenException $e) { |
|
| 389 | - return false; |
|
| 390 | - } |
|
| 391 | - return false; |
|
| 392 | - }); |
|
| 393 | - |
|
| 394 | - $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) { |
|
| 395 | - $checksum = $node->getChecksum(); |
|
| 396 | - if ($checksum === NULL || $checksum === '') { |
|
| 397 | - return null; |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - return new ChecksumList($checksum); |
|
| 401 | - }); |
|
| 402 | - |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) { |
|
| 406 | - $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
|
| 407 | - return $node->getSize(); |
|
| 408 | - }); |
|
| 409 | - |
|
| 410 | - $propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function() use ($node) { |
|
| 411 | - return $node->getFileInfo()->isEncrypted() ? '1' : '0'; |
|
| 412 | - }); |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * translate Nextcloud permissions to OCM Permissions |
|
| 418 | - * |
|
| 419 | - * @param $ncPermissions |
|
| 420 | - * @return array |
|
| 421 | - */ |
|
| 422 | - protected function ncPermissions2ocmPermissions($ncPermissions) { |
|
| 423 | - |
|
| 424 | - $ocmPermissions = []; |
|
| 425 | - |
|
| 426 | - if ($ncPermissions & Constants::PERMISSION_SHARE) { |
|
| 427 | - $ocmPermissions[] = 'share'; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - if ($ncPermissions & Constants::PERMISSION_READ) { |
|
| 431 | - $ocmPermissions[] = 'read'; |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - if (($ncPermissions & Constants::PERMISSION_CREATE) || |
|
| 435 | - ($ncPermissions & Constants::PERMISSION_UPDATE)) { |
|
| 436 | - $ocmPermissions[] = 'write'; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - return $ocmPermissions; |
|
| 440 | - |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * Update ownCloud-specific properties |
|
| 445 | - * |
|
| 446 | - * @param string $path |
|
| 447 | - * @param PropPatch $propPatch |
|
| 448 | - * |
|
| 449 | - * @return void |
|
| 450 | - */ |
|
| 451 | - public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
| 452 | - $node = $this->tree->getNodeForPath($path); |
|
| 453 | - if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
| 454 | - return; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - $propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function($time) use ($node) { |
|
| 458 | - if (empty($time)) { |
|
| 459 | - return false; |
|
| 460 | - } |
|
| 461 | - $node->touch($time); |
|
| 462 | - return true; |
|
| 463 | - }); |
|
| 464 | - $propPatch->handle(self::GETETAG_PROPERTYNAME, function($etag) use ($node) { |
|
| 465 | - if (empty($etag)) { |
|
| 466 | - return false; |
|
| 467 | - } |
|
| 468 | - if ($node->setEtag($etag) !== -1) { |
|
| 469 | - return true; |
|
| 470 | - } |
|
| 471 | - return false; |
|
| 472 | - }); |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - /** |
|
| 476 | - * @param string $filePath |
|
| 477 | - * @param \Sabre\DAV\INode $node |
|
| 478 | - * @throws \Sabre\DAV\Exception\BadRequest |
|
| 479 | - */ |
|
| 480 | - public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) { |
|
| 481 | - // chunked upload handling |
|
| 482 | - if (isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
| 483 | - list($path, $name) = \Sabre\Uri\split($filePath); |
|
| 484 | - $info = \OC_FileChunking::decodeName($name); |
|
| 485 | - if (!empty($info)) { |
|
| 486 | - $filePath = $path . '/' . $info['name']; |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - // we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder |
|
| 491 | - if (!$this->server->tree->nodeExists($filePath)) { |
|
| 492 | - return; |
|
| 493 | - } |
|
| 494 | - $node = $this->server->tree->getNodeForPath($filePath); |
|
| 495 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
| 496 | - $fileId = $node->getFileId(); |
|
| 497 | - if (!is_null($fileId)) { |
|
| 498 | - $this->server->httpResponse->setHeader('OC-FileId', $fileId); |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - } |
|
| 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::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) { |
|
| 327 | + $ncPermissions = $node->getSharePermissions( |
|
| 328 | + $httpRequest->getRawServerValue('PHP_AUTH_USER') |
|
| 329 | + ); |
|
| 330 | + $ocmPermissions = $this->ncPermissions2ocmPermissions($ncPermissions); |
|
| 331 | + return json_encode($ocmPermissions); |
|
| 332 | + }); |
|
| 333 | + |
|
| 334 | + $propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) { |
|
| 335 | + return $node->getETag(); |
|
| 336 | + }); |
|
| 337 | + |
|
| 338 | + $propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) { |
|
| 339 | + $owner = $node->getOwner(); |
|
| 340 | + if (!$owner) { |
|
| 341 | + return null; |
|
| 342 | + } else { |
|
| 343 | + return $owner->getUID(); |
|
| 344 | + } |
|
| 345 | + }); |
|
| 346 | + $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) { |
|
| 347 | + $owner = $node->getOwner(); |
|
| 348 | + if (!$owner) { |
|
| 349 | + return null; |
|
| 350 | + } else { |
|
| 351 | + return $owner->getDisplayName(); |
|
| 352 | + } |
|
| 353 | + }); |
|
| 354 | + |
|
| 355 | + $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { |
|
| 356 | + return json_encode($this->previewManager->isAvailable($node->getFileInfo())); |
|
| 357 | + }); |
|
| 358 | + $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
|
| 359 | + return $node->getSize(); |
|
| 360 | + }); |
|
| 361 | + $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { |
|
| 362 | + return $node->getFileInfo()->getMountPoint()->getMountType(); |
|
| 363 | + }); |
|
| 364 | + |
|
| 365 | + $propFind->handle(self::SHARE_NOTE, function() use ($node, $httpRequest) { |
|
| 366 | + return $node->getNoteFromShare( |
|
| 367 | + $httpRequest->getRawServerValue('PHP_AUTH_USER') |
|
| 368 | + ); |
|
| 369 | + }); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
| 373 | + $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) { |
|
| 374 | + return $this->config->getSystemValue('data-fingerprint', ''); |
|
| 375 | + }); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
| 379 | + $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) { |
|
| 380 | + /** @var $node \OCA\DAV\Connector\Sabre\File */ |
|
| 381 | + try { |
|
| 382 | + $directDownloadUrl = $node->getDirectDownload(); |
|
| 383 | + if (isset($directDownloadUrl['url'])) { |
|
| 384 | + return $directDownloadUrl['url']; |
|
| 385 | + } |
|
| 386 | + } catch (StorageNotAvailableException $e) { |
|
| 387 | + return false; |
|
| 388 | + } catch (ForbiddenException $e) { |
|
| 389 | + return false; |
|
| 390 | + } |
|
| 391 | + return false; |
|
| 392 | + }); |
|
| 393 | + |
|
| 394 | + $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) { |
|
| 395 | + $checksum = $node->getChecksum(); |
|
| 396 | + if ($checksum === NULL || $checksum === '') { |
|
| 397 | + return null; |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + return new ChecksumList($checksum); |
|
| 401 | + }); |
|
| 402 | + |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) { |
|
| 406 | + $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
|
| 407 | + return $node->getSize(); |
|
| 408 | + }); |
|
| 409 | + |
|
| 410 | + $propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function() use ($node) { |
|
| 411 | + return $node->getFileInfo()->isEncrypted() ? '1' : '0'; |
|
| 412 | + }); |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * translate Nextcloud permissions to OCM Permissions |
|
| 418 | + * |
|
| 419 | + * @param $ncPermissions |
|
| 420 | + * @return array |
|
| 421 | + */ |
|
| 422 | + protected function ncPermissions2ocmPermissions($ncPermissions) { |
|
| 423 | + |
|
| 424 | + $ocmPermissions = []; |
|
| 425 | + |
|
| 426 | + if ($ncPermissions & Constants::PERMISSION_SHARE) { |
|
| 427 | + $ocmPermissions[] = 'share'; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + if ($ncPermissions & Constants::PERMISSION_READ) { |
|
| 431 | + $ocmPermissions[] = 'read'; |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + if (($ncPermissions & Constants::PERMISSION_CREATE) || |
|
| 435 | + ($ncPermissions & Constants::PERMISSION_UPDATE)) { |
|
| 436 | + $ocmPermissions[] = 'write'; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + return $ocmPermissions; |
|
| 440 | + |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * Update ownCloud-specific properties |
|
| 445 | + * |
|
| 446 | + * @param string $path |
|
| 447 | + * @param PropPatch $propPatch |
|
| 448 | + * |
|
| 449 | + * @return void |
|
| 450 | + */ |
|
| 451 | + public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
| 452 | + $node = $this->tree->getNodeForPath($path); |
|
| 453 | + if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
| 454 | + return; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + $propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function($time) use ($node) { |
|
| 458 | + if (empty($time)) { |
|
| 459 | + return false; |
|
| 460 | + } |
|
| 461 | + $node->touch($time); |
|
| 462 | + return true; |
|
| 463 | + }); |
|
| 464 | + $propPatch->handle(self::GETETAG_PROPERTYNAME, function($etag) use ($node) { |
|
| 465 | + if (empty($etag)) { |
|
| 466 | + return false; |
|
| 467 | + } |
|
| 468 | + if ($node->setEtag($etag) !== -1) { |
|
| 469 | + return true; |
|
| 470 | + } |
|
| 471 | + return false; |
|
| 472 | + }); |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + /** |
|
| 476 | + * @param string $filePath |
|
| 477 | + * @param \Sabre\DAV\INode $node |
|
| 478 | + * @throws \Sabre\DAV\Exception\BadRequest |
|
| 479 | + */ |
|
| 480 | + public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) { |
|
| 481 | + // chunked upload handling |
|
| 482 | + if (isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
| 483 | + list($path, $name) = \Sabre\Uri\split($filePath); |
|
| 484 | + $info = \OC_FileChunking::decodeName($name); |
|
| 485 | + if (!empty($info)) { |
|
| 486 | + $filePath = $path . '/' . $info['name']; |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + // we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder |
|
| 491 | + if (!$this->server->tree->nodeExists($filePath)) { |
|
| 492 | + return; |
|
| 493 | + } |
|
| 494 | + $node = $this->server->tree->getNodeForPath($filePath); |
|
| 495 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
| 496 | + $fileId = $node->getFileId(); |
|
| 497 | + if (!is_null($fileId)) { |
|
| 498 | + $this->server->httpResponse->setHeader('OC-FileId', $fileId); |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + } |
|
| 502 | 502 | } |
@@ -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 | |
@@ -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(); |