@@ -36,50 +36,50 @@ |
||
| 36 | 36 | |
| 37 | 37 | class AnonymousOptionsPlugin extends ServerPlugin { |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @var \Sabre\DAV\Server |
|
| 41 | - */ |
|
| 42 | - private $server; |
|
| 39 | + /** |
|
| 40 | + * @var \Sabre\DAV\Server |
|
| 41 | + */ |
|
| 42 | + private $server; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @param \Sabre\DAV\Server $server |
|
| 46 | - * @return void |
|
| 47 | - */ |
|
| 48 | - public function initialize(\Sabre\DAV\Server $server) { |
|
| 49 | - $this->server = $server; |
|
| 50 | - // before auth |
|
| 51 | - $this->server->on('beforeMethod:*', [$this, 'handleAnonymousOptions'], 9); |
|
| 52 | - } |
|
| 44 | + /** |
|
| 45 | + * @param \Sabre\DAV\Server $server |
|
| 46 | + * @return void |
|
| 47 | + */ |
|
| 48 | + public function initialize(\Sabre\DAV\Server $server) { |
|
| 49 | + $this->server = $server; |
|
| 50 | + // before auth |
|
| 51 | + $this->server->on('beforeMethod:*', [$this, 'handleAnonymousOptions'], 9); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @return bool |
|
| 56 | - */ |
|
| 57 | - public function isRequestInRoot($path) { |
|
| 58 | - return $path === '' || (is_string($path) && strpos($path, '/') === false); |
|
| 59 | - } |
|
| 54 | + /** |
|
| 55 | + * @return bool |
|
| 56 | + */ |
|
| 57 | + public function isRequestInRoot($path) { |
|
| 58 | + return $path === '' || (is_string($path) && strpos($path, '/') === false); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @throws \Sabre\DAV\Exception\Forbidden |
|
| 63 | - * @return bool |
|
| 64 | - */ |
|
| 65 | - public function handleAnonymousOptions(RequestInterface $request, ResponseInterface $response) { |
|
| 66 | - $isOffice = preg_match('/Microsoft Office/i', $request->getHeader('User-Agent')); |
|
| 67 | - $emptyAuth = $request->getHeader('Authorization') === null |
|
| 68 | - || $request->getHeader('Authorization') === '' |
|
| 69 | - || trim($request->getHeader('Authorization')) === 'Bearer'; |
|
| 70 | - $isAnonymousOption = $request->getMethod() === 'OPTIONS' && $emptyAuth; |
|
| 71 | - $isOfficeHead = $request->getMethod() === 'HEAD' && $isOffice && $emptyAuth; |
|
| 72 | - if ($isAnonymousOption || $isOfficeHead) { |
|
| 73 | - /** @var CorePlugin $corePlugin */ |
|
| 74 | - $corePlugin = $this->server->getPlugin('core'); |
|
| 75 | - // setup a fake tree for anonymous access |
|
| 76 | - $this->server->tree = new Tree(new Directory('')); |
|
| 77 | - $corePlugin->httpOptions($request, $response); |
|
| 78 | - $this->server->emit('afterMethod:*', [$request, $response]); |
|
| 79 | - $this->server->emit('afterMethod:OPTIONS', [$request, $response]); |
|
| 61 | + /** |
|
| 62 | + * @throws \Sabre\DAV\Exception\Forbidden |
|
| 63 | + * @return bool |
|
| 64 | + */ |
|
| 65 | + public function handleAnonymousOptions(RequestInterface $request, ResponseInterface $response) { |
|
| 66 | + $isOffice = preg_match('/Microsoft Office/i', $request->getHeader('User-Agent')); |
|
| 67 | + $emptyAuth = $request->getHeader('Authorization') === null |
|
| 68 | + || $request->getHeader('Authorization') === '' |
|
| 69 | + || trim($request->getHeader('Authorization')) === 'Bearer'; |
|
| 70 | + $isAnonymousOption = $request->getMethod() === 'OPTIONS' && $emptyAuth; |
|
| 71 | + $isOfficeHead = $request->getMethod() === 'HEAD' && $isOffice && $emptyAuth; |
|
| 72 | + if ($isAnonymousOption || $isOfficeHead) { |
|
| 73 | + /** @var CorePlugin $corePlugin */ |
|
| 74 | + $corePlugin = $this->server->getPlugin('core'); |
|
| 75 | + // setup a fake tree for anonymous access |
|
| 76 | + $this->server->tree = new Tree(new Directory('')); |
|
| 77 | + $corePlugin->httpOptions($request, $response); |
|
| 78 | + $this->server->emit('afterMethod:*', [$request, $response]); |
|
| 79 | + $this->server->emit('afterMethod:OPTIONS', [$request, $response]); |
|
| 80 | 80 | |
| 81 | - $this->server->sapi->sendResponse($response); |
|
| 82 | - return false; |
|
| 83 | - } |
|
| 84 | - } |
|
| 81 | + $this->server->sapi->sendResponse($response); |
|
| 82 | + return false; |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | 85 | } |
@@ -34,53 +34,53 @@ |
||
| 34 | 34 | use Sabre\HTTP\RequestInterface; |
| 35 | 35 | |
| 36 | 36 | class LockPlugin extends ServerPlugin { |
| 37 | - /** |
|
| 38 | - * Reference to main server object |
|
| 39 | - * |
|
| 40 | - * @var \Sabre\DAV\Server |
|
| 41 | - */ |
|
| 42 | - private $server; |
|
| 37 | + /** |
|
| 38 | + * Reference to main server object |
|
| 39 | + * |
|
| 40 | + * @var \Sabre\DAV\Server |
|
| 41 | + */ |
|
| 42 | + private $server; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * {@inheritdoc} |
|
| 46 | - */ |
|
| 47 | - public function initialize(\Sabre\DAV\Server $server) { |
|
| 48 | - $this->server = $server; |
|
| 49 | - $this->server->on('beforeMethod:*', [$this, 'getLock'], 50); |
|
| 50 | - $this->server->on('afterMethod:*', [$this, 'releaseLock'], 50); |
|
| 51 | - } |
|
| 44 | + /** |
|
| 45 | + * {@inheritdoc} |
|
| 46 | + */ |
|
| 47 | + public function initialize(\Sabre\DAV\Server $server) { |
|
| 48 | + $this->server = $server; |
|
| 49 | + $this->server->on('beforeMethod:*', [$this, 'getLock'], 50); |
|
| 50 | + $this->server->on('afterMethod:*', [$this, 'releaseLock'], 50); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - public function getLock(RequestInterface $request) { |
|
| 54 | - // we can't listen on 'beforeMethod:PUT' due to order of operations with setting up the tree |
|
| 55 | - // so instead we limit ourselves to the PUT method manually |
|
| 56 | - if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
| 57 | - return; |
|
| 58 | - } |
|
| 59 | - try { |
|
| 60 | - $node = $this->server->tree->getNodeForPath($request->getPath()); |
|
| 61 | - } catch (NotFound $e) { |
|
| 62 | - return; |
|
| 63 | - } |
|
| 64 | - if ($node instanceof Node) { |
|
| 65 | - try { |
|
| 66 | - $node->acquireLock(ILockingProvider::LOCK_SHARED); |
|
| 67 | - } catch (LockedException $e) { |
|
| 68 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - } |
|
| 53 | + public function getLock(RequestInterface $request) { |
|
| 54 | + // we can't listen on 'beforeMethod:PUT' due to order of operations with setting up the tree |
|
| 55 | + // so instead we limit ourselves to the PUT method manually |
|
| 56 | + if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
| 57 | + return; |
|
| 58 | + } |
|
| 59 | + try { |
|
| 60 | + $node = $this->server->tree->getNodeForPath($request->getPath()); |
|
| 61 | + } catch (NotFound $e) { |
|
| 62 | + return; |
|
| 63 | + } |
|
| 64 | + if ($node instanceof Node) { |
|
| 65 | + try { |
|
| 66 | + $node->acquireLock(ILockingProvider::LOCK_SHARED); |
|
| 67 | + } catch (LockedException $e) { |
|
| 68 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - public function releaseLock(RequestInterface $request) { |
|
| 74 | - if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
| 75 | - return; |
|
| 76 | - } |
|
| 77 | - try { |
|
| 78 | - $node = $this->server->tree->getNodeForPath($request->getPath()); |
|
| 79 | - } catch (NotFound $e) { |
|
| 80 | - return; |
|
| 81 | - } |
|
| 82 | - if ($node instanceof Node) { |
|
| 83 | - $node->releaseLock(ILockingProvider::LOCK_SHARED); |
|
| 84 | - } |
|
| 85 | - } |
|
| 73 | + public function releaseLock(RequestInterface $request) { |
|
| 74 | + if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
| 75 | + return; |
|
| 76 | + } |
|
| 77 | + try { |
|
| 78 | + $node = $this->server->tree->getNodeForPath($request->getPath()); |
|
| 79 | + } catch (NotFound $e) { |
|
| 80 | + return; |
|
| 81 | + } |
|
| 82 | + if ($node instanceof Node) { |
|
| 83 | + $node->releaseLock(ILockingProvider::LOCK_SHARED); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | 86 | } |