@@ -48,43 +48,43 @@ discard block |
||
48 | 48 | * @param Exception|Error $e |
49 | 49 | */ |
50 | 50 | function handleException($e) { |
51 | - $request = \OC::$server->getRequest(); |
|
52 | - // in case the request content type is text/xml - we assume it's a WebDAV request |
|
53 | - $isXmlContentType = strpos($request->getHeader('Content-Type'), 'text/xml'); |
|
54 | - if ($isXmlContentType === 0) { |
|
55 | - // fire up a simple server to properly process the exception |
|
56 | - $server = new Server(); |
|
57 | - if (!($e instanceof RemoteException)) { |
|
58 | - // we shall not log on RemoteException |
|
59 | - $server->addPlugin(new ExceptionLoggerPlugin('webdav', \OC::$server->getLogger())); |
|
60 | - } |
|
61 | - $server->on('beforeMethod:*', function () use ($e) { |
|
62 | - if ($e instanceof RemoteException) { |
|
63 | - switch ($e->getCode()) { |
|
64 | - case 503: |
|
65 | - throw new ServiceUnavailable($e->getMessage()); |
|
66 | - case 404: |
|
67 | - throw new \Sabre\DAV\Exception\NotFound($e->getMessage()); |
|
68 | - } |
|
69 | - } |
|
70 | - $class = get_class($e); |
|
71 | - $msg = $e->getMessage(); |
|
72 | - throw new ServiceUnavailable("$class: $msg"); |
|
73 | - }); |
|
74 | - $server->exec(); |
|
75 | - } else { |
|
76 | - $statusCode = 500; |
|
77 | - if ($e instanceof \OC\ServiceUnavailableException ) { |
|
78 | - $statusCode = 503; |
|
79 | - } |
|
80 | - if ($e instanceof RemoteException) { |
|
81 | - // we shall not log on RemoteException |
|
82 | - OC_Template::printErrorPage($e->getMessage(), '', $e->getCode()); |
|
83 | - } else { |
|
84 | - \OC::$server->getLogger()->logException($e, ['app' => 'remote']); |
|
85 | - OC_Template::printExceptionErrorPage($e, $statusCode); |
|
86 | - } |
|
87 | - } |
|
51 | + $request = \OC::$server->getRequest(); |
|
52 | + // in case the request content type is text/xml - we assume it's a WebDAV request |
|
53 | + $isXmlContentType = strpos($request->getHeader('Content-Type'), 'text/xml'); |
|
54 | + if ($isXmlContentType === 0) { |
|
55 | + // fire up a simple server to properly process the exception |
|
56 | + $server = new Server(); |
|
57 | + if (!($e instanceof RemoteException)) { |
|
58 | + // we shall not log on RemoteException |
|
59 | + $server->addPlugin(new ExceptionLoggerPlugin('webdav', \OC::$server->getLogger())); |
|
60 | + } |
|
61 | + $server->on('beforeMethod:*', function () use ($e) { |
|
62 | + if ($e instanceof RemoteException) { |
|
63 | + switch ($e->getCode()) { |
|
64 | + case 503: |
|
65 | + throw new ServiceUnavailable($e->getMessage()); |
|
66 | + case 404: |
|
67 | + throw new \Sabre\DAV\Exception\NotFound($e->getMessage()); |
|
68 | + } |
|
69 | + } |
|
70 | + $class = get_class($e); |
|
71 | + $msg = $e->getMessage(); |
|
72 | + throw new ServiceUnavailable("$class: $msg"); |
|
73 | + }); |
|
74 | + $server->exec(); |
|
75 | + } else { |
|
76 | + $statusCode = 500; |
|
77 | + if ($e instanceof \OC\ServiceUnavailableException ) { |
|
78 | + $statusCode = 503; |
|
79 | + } |
|
80 | + if ($e instanceof RemoteException) { |
|
81 | + // we shall not log on RemoteException |
|
82 | + OC_Template::printErrorPage($e->getMessage(), '', $e->getCode()); |
|
83 | + } else { |
|
84 | + \OC::$server->getLogger()->logException($e, ['app' => 'remote']); |
|
85 | + OC_Template::printExceptionErrorPage($e, $statusCode); |
|
86 | + } |
|
87 | + } |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -92,80 +92,80 @@ discard block |
||
92 | 92 | * @return string |
93 | 93 | */ |
94 | 94 | function resolveService($service) { |
95 | - $services = [ |
|
96 | - 'webdav' => 'dav/appinfo/v1/webdav.php', |
|
97 | - 'dav' => 'dav/appinfo/v2/remote.php', |
|
98 | - 'caldav' => 'dav/appinfo/v1/caldav.php', |
|
99 | - 'calendar' => 'dav/appinfo/v1/caldav.php', |
|
100 | - 'carddav' => 'dav/appinfo/v1/carddav.php', |
|
101 | - 'contacts' => 'dav/appinfo/v1/carddav.php', |
|
102 | - 'files' => 'dav/appinfo/v1/webdav.php', |
|
103 | - 'direct' => 'dav/appinfo/v2/direct.php', |
|
104 | - ]; |
|
105 | - if (isset($services[$service])) { |
|
106 | - return $services[$service]; |
|
107 | - } |
|
108 | - |
|
109 | - return \OC::$server->getConfig()->getAppValue('core', 'remote_' . $service); |
|
95 | + $services = [ |
|
96 | + 'webdav' => 'dav/appinfo/v1/webdav.php', |
|
97 | + 'dav' => 'dav/appinfo/v2/remote.php', |
|
98 | + 'caldav' => 'dav/appinfo/v1/caldav.php', |
|
99 | + 'calendar' => 'dav/appinfo/v1/caldav.php', |
|
100 | + 'carddav' => 'dav/appinfo/v1/carddav.php', |
|
101 | + 'contacts' => 'dav/appinfo/v1/carddav.php', |
|
102 | + 'files' => 'dav/appinfo/v1/webdav.php', |
|
103 | + 'direct' => 'dav/appinfo/v2/direct.php', |
|
104 | + ]; |
|
105 | + if (isset($services[$service])) { |
|
106 | + return $services[$service]; |
|
107 | + } |
|
108 | + |
|
109 | + return \OC::$server->getConfig()->getAppValue('core', 'remote_' . $service); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | try { |
113 | - require_once __DIR__ . '/lib/base.php'; |
|
114 | - |
|
115 | - // All resources served via the DAV endpoint should have the strictest possible |
|
116 | - // policy. Exempted from this is the SabreDAV browser plugin which overwrites |
|
117 | - // this policy with a softer one if debug mode is enabled. |
|
118 | - header("Content-Security-Policy: default-src 'none';"); |
|
119 | - |
|
120 | - if (\OCP\Util::needUpgrade()) { |
|
121 | - // since the behavior of apps or remotes are unpredictable during |
|
122 | - // an upgrade, return a 503 directly |
|
123 | - throw new RemoteException('Service unavailable', 503); |
|
124 | - } |
|
125 | - |
|
126 | - $request = \OC::$server->getRequest(); |
|
127 | - $pathInfo = $request->getPathInfo(); |
|
128 | - if ($pathInfo === false || $pathInfo === '') { |
|
129 | - throw new RemoteException('Path not found', 404); |
|
130 | - } |
|
131 | - if (!$pos = strpos($pathInfo, '/', 1)) { |
|
132 | - $pos = strlen($pathInfo); |
|
133 | - } |
|
134 | - $service=substr($pathInfo, 1, $pos-1); |
|
135 | - |
|
136 | - $file = resolveService($service); |
|
137 | - |
|
138 | - if(is_null($file)) { |
|
139 | - throw new RemoteException('Path not found', 404); |
|
140 | - } |
|
141 | - |
|
142 | - $file=ltrim($file, '/'); |
|
143 | - |
|
144 | - $parts=explode('/', $file, 2); |
|
145 | - $app=$parts[0]; |
|
146 | - |
|
147 | - // Load all required applications |
|
148 | - \OC::$REQUESTEDAPP = $app; |
|
149 | - OC_App::loadApps(['authentication']); |
|
150 | - OC_App::loadApps(['filesystem', 'logging']); |
|
151 | - |
|
152 | - switch ($app) { |
|
153 | - case 'core': |
|
154 | - $file = OC::$SERVERROOT .'/'. $file; |
|
155 | - break; |
|
156 | - default: |
|
157 | - if (!\OC::$server->getAppManager()->isInstalled($app)) { |
|
158 | - throw new RemoteException('App not installed: ' . $app); |
|
159 | - } |
|
160 | - OC_App::loadApp($app); |
|
161 | - $file = OC_App::getAppPath($app) .'/'. $parts[1]; |
|
162 | - break; |
|
163 | - } |
|
164 | - $baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/'; |
|
165 | - require_once $file; |
|
113 | + require_once __DIR__ . '/lib/base.php'; |
|
114 | + |
|
115 | + // All resources served via the DAV endpoint should have the strictest possible |
|
116 | + // policy. Exempted from this is the SabreDAV browser plugin which overwrites |
|
117 | + // this policy with a softer one if debug mode is enabled. |
|
118 | + header("Content-Security-Policy: default-src 'none';"); |
|
119 | + |
|
120 | + if (\OCP\Util::needUpgrade()) { |
|
121 | + // since the behavior of apps or remotes are unpredictable during |
|
122 | + // an upgrade, return a 503 directly |
|
123 | + throw new RemoteException('Service unavailable', 503); |
|
124 | + } |
|
125 | + |
|
126 | + $request = \OC::$server->getRequest(); |
|
127 | + $pathInfo = $request->getPathInfo(); |
|
128 | + if ($pathInfo === false || $pathInfo === '') { |
|
129 | + throw new RemoteException('Path not found', 404); |
|
130 | + } |
|
131 | + if (!$pos = strpos($pathInfo, '/', 1)) { |
|
132 | + $pos = strlen($pathInfo); |
|
133 | + } |
|
134 | + $service=substr($pathInfo, 1, $pos-1); |
|
135 | + |
|
136 | + $file = resolveService($service); |
|
137 | + |
|
138 | + if(is_null($file)) { |
|
139 | + throw new RemoteException('Path not found', 404); |
|
140 | + } |
|
141 | + |
|
142 | + $file=ltrim($file, '/'); |
|
143 | + |
|
144 | + $parts=explode('/', $file, 2); |
|
145 | + $app=$parts[0]; |
|
146 | + |
|
147 | + // Load all required applications |
|
148 | + \OC::$REQUESTEDAPP = $app; |
|
149 | + OC_App::loadApps(['authentication']); |
|
150 | + OC_App::loadApps(['filesystem', 'logging']); |
|
151 | + |
|
152 | + switch ($app) { |
|
153 | + case 'core': |
|
154 | + $file = OC::$SERVERROOT .'/'. $file; |
|
155 | + break; |
|
156 | + default: |
|
157 | + if (!\OC::$server->getAppManager()->isInstalled($app)) { |
|
158 | + throw new RemoteException('App not installed: ' . $app); |
|
159 | + } |
|
160 | + OC_App::loadApp($app); |
|
161 | + $file = OC_App::getAppPath($app) .'/'. $parts[1]; |
|
162 | + break; |
|
163 | + } |
|
164 | + $baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/'; |
|
165 | + require_once $file; |
|
166 | 166 | |
167 | 167 | } catch (Exception $ex) { |
168 | - handleException($ex); |
|
168 | + handleException($ex); |
|
169 | 169 | } catch (Error $e) { |
170 | - handleException($e); |
|
170 | + handleException($e); |
|
171 | 171 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * |
31 | 31 | */ |
32 | 32 | |
33 | -require_once __DIR__ . '/lib/versioncheck.php'; |
|
33 | +require_once __DIR__.'/lib/versioncheck.php'; |
|
34 | 34 | |
35 | 35 | use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin; |
36 | 36 | use Sabre\DAV\Exception\ServiceUnavailable; |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | // we shall not log on RemoteException |
59 | 59 | $server->addPlugin(new ExceptionLoggerPlugin('webdav', \OC::$server->getLogger())); |
60 | 60 | } |
61 | - $server->on('beforeMethod:*', function () use ($e) { |
|
61 | + $server->on('beforeMethod:*', function() use ($e) { |
|
62 | 62 | if ($e instanceof RemoteException) { |
63 | 63 | switch ($e->getCode()) { |
64 | 64 | case 503: |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | $server->exec(); |
75 | 75 | } else { |
76 | 76 | $statusCode = 500; |
77 | - if ($e instanceof \OC\ServiceUnavailableException ) { |
|
77 | + if ($e instanceof \OC\ServiceUnavailableException) { |
|
78 | 78 | $statusCode = 503; |
79 | 79 | } |
80 | 80 | if ($e instanceof RemoteException) { |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | return $services[$service]; |
107 | 107 | } |
108 | 108 | |
109 | - return \OC::$server->getConfig()->getAppValue('core', 'remote_' . $service); |
|
109 | + return \OC::$server->getConfig()->getAppValue('core', 'remote_'.$service); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | try { |
113 | - require_once __DIR__ . '/lib/base.php'; |
|
113 | + require_once __DIR__.'/lib/base.php'; |
|
114 | 114 | |
115 | 115 | // All resources served via the DAV endpoint should have the strictest possible |
116 | 116 | // policy. Exempted from this is the SabreDAV browser plugin which overwrites |
@@ -131,18 +131,18 @@ discard block |
||
131 | 131 | if (!$pos = strpos($pathInfo, '/', 1)) { |
132 | 132 | $pos = strlen($pathInfo); |
133 | 133 | } |
134 | - $service=substr($pathInfo, 1, $pos-1); |
|
134 | + $service = substr($pathInfo, 1, $pos - 1); |
|
135 | 135 | |
136 | 136 | $file = resolveService($service); |
137 | 137 | |
138 | - if(is_null($file)) { |
|
138 | + if (is_null($file)) { |
|
139 | 139 | throw new RemoteException('Path not found', 404); |
140 | 140 | } |
141 | 141 | |
142 | - $file=ltrim($file, '/'); |
|
142 | + $file = ltrim($file, '/'); |
|
143 | 143 | |
144 | - $parts=explode('/', $file, 2); |
|
145 | - $app=$parts[0]; |
|
144 | + $parts = explode('/', $file, 2); |
|
145 | + $app = $parts[0]; |
|
146 | 146 | |
147 | 147 | // Load all required applications |
148 | 148 | \OC::$REQUESTEDAPP = $app; |
@@ -151,17 +151,17 @@ discard block |
||
151 | 151 | |
152 | 152 | switch ($app) { |
153 | 153 | case 'core': |
154 | - $file = OC::$SERVERROOT .'/'. $file; |
|
154 | + $file = OC::$SERVERROOT.'/'.$file; |
|
155 | 155 | break; |
156 | 156 | default: |
157 | 157 | if (!\OC::$server->getAppManager()->isInstalled($app)) { |
158 | - throw new RemoteException('App not installed: ' . $app); |
|
158 | + throw new RemoteException('App not installed: '.$app); |
|
159 | 159 | } |
160 | 160 | OC_App::loadApp($app); |
161 | - $file = OC_App::getAppPath($app) .'/'. $parts[1]; |
|
161 | + $file = OC_App::getAppPath($app).'/'.$parts[1]; |
|
162 | 162 | break; |
163 | 163 | } |
164 | - $baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/'; |
|
164 | + $baseuri = OC::$WEBROOT.'/remote.php/'.$service.'/'; |
|
165 | 165 | require_once $file; |
166 | 166 | |
167 | 167 | } catch (Exception $ex) { |
@@ -34,52 +34,52 @@ |
||
34 | 34 | */ |
35 | 35 | class FilesDropPlugin extends ServerPlugin { |
36 | 36 | |
37 | - /** @var View */ |
|
38 | - private $view; |
|
37 | + /** @var View */ |
|
38 | + private $view; |
|
39 | 39 | |
40 | - /** @var bool */ |
|
41 | - private $enabled = false; |
|
40 | + /** @var bool */ |
|
41 | + private $enabled = false; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param View $view |
|
45 | - */ |
|
46 | - public function setView($view) { |
|
47 | - $this->view = $view; |
|
48 | - } |
|
43 | + /** |
|
44 | + * @param View $view |
|
45 | + */ |
|
46 | + public function setView($view) { |
|
47 | + $this->view = $view; |
|
48 | + } |
|
49 | 49 | |
50 | - public function enable() { |
|
51 | - $this->enabled = true; |
|
52 | - } |
|
50 | + public function enable() { |
|
51 | + $this->enabled = true; |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * This initializes the plugin. |
|
57 | - * |
|
58 | - * @param \Sabre\DAV\Server $server Sabre server |
|
59 | - * |
|
60 | - * @return void |
|
61 | - * @throws MethodNotAllowed |
|
62 | - */ |
|
63 | - public function initialize(\Sabre\DAV\Server $server) { |
|
64 | - $server->on('beforeMethod:*', [$this, 'beforeMethod'], 999); |
|
65 | - $this->enabled = false; |
|
66 | - } |
|
55 | + /** |
|
56 | + * This initializes the plugin. |
|
57 | + * |
|
58 | + * @param \Sabre\DAV\Server $server Sabre server |
|
59 | + * |
|
60 | + * @return void |
|
61 | + * @throws MethodNotAllowed |
|
62 | + */ |
|
63 | + public function initialize(\Sabre\DAV\Server $server) { |
|
64 | + $server->on('beforeMethod:*', [$this, 'beforeMethod'], 999); |
|
65 | + $this->enabled = false; |
|
66 | + } |
|
67 | 67 | |
68 | - public function beforeMethod(RequestInterface $request, ResponseInterface $response){ |
|
68 | + public function beforeMethod(RequestInterface $request, ResponseInterface $response){ |
|
69 | 69 | |
70 | - if (!$this->enabled) { |
|
71 | - return; |
|
72 | - } |
|
70 | + if (!$this->enabled) { |
|
71 | + return; |
|
72 | + } |
|
73 | 73 | |
74 | - if ($request->getMethod() !== 'PUT') { |
|
75 | - throw new MethodNotAllowed('Only PUT is allowed on files drop'); |
|
76 | - } |
|
74 | + if ($request->getMethod() !== 'PUT') { |
|
75 | + throw new MethodNotAllowed('Only PUT is allowed on files drop'); |
|
76 | + } |
|
77 | 77 | |
78 | - $path = explode('/', $request->getPath()); |
|
79 | - $path = array_pop($path); |
|
78 | + $path = explode('/', $request->getPath()); |
|
79 | + $path = array_pop($path); |
|
80 | 80 | |
81 | - $newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view); |
|
82 | - $url = $request->getBaseUrl() . $newName; |
|
83 | - $request->setUrl($url); |
|
84 | - } |
|
81 | + $newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view); |
|
82 | + $url = $request->getBaseUrl() . $newName; |
|
83 | + $request->setUrl($url); |
|
84 | + } |
|
85 | 85 | } |
@@ -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(); |
@@ -36,86 +36,86 @@ |
||
36 | 36 | |
37 | 37 | class InvitationResponseServer { |
38 | 38 | |
39 | - /** @var \OCA\DAV\Connector\Sabre\Server */ |
|
40 | - public $server; |
|
39 | + /** @var \OCA\DAV\Connector\Sabre\Server */ |
|
40 | + public $server; |
|
41 | 41 | |
42 | - /** |
|
43 | - * InvitationResponseServer constructor. |
|
44 | - */ |
|
45 | - public function __construct() { |
|
46 | - $baseUri = \OC::$WEBROOT . '/remote.php/dav/'; |
|
47 | - $logger = \OC::$server->getLogger(); |
|
48 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
42 | + /** |
|
43 | + * InvitationResponseServer constructor. |
|
44 | + */ |
|
45 | + public function __construct() { |
|
46 | + $baseUri = \OC::$WEBROOT . '/remote.php/dav/'; |
|
47 | + $logger = \OC::$server->getLogger(); |
|
48 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
49 | 49 | |
50 | - $root = new RootCollection(); |
|
51 | - $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); |
|
50 | + $root = new RootCollection(); |
|
51 | + $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); |
|
52 | 52 | |
53 | - // Add maintenance plugin |
|
54 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig())); |
|
53 | + // Add maintenance plugin |
|
54 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig())); |
|
55 | 55 | |
56 | - // Set URL explicitly due to reverse-proxy situations |
|
57 | - $this->server->httpRequest->setUrl($baseUri); |
|
58 | - $this->server->setBaseUri($baseUri); |
|
56 | + // Set URL explicitly due to reverse-proxy situations |
|
57 | + $this->server->httpRequest->setUrl($baseUri); |
|
58 | + $this->server->setBaseUri($baseUri); |
|
59 | 59 | |
60 | - $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
61 | - $this->server->addPlugin(new AnonymousOptionsPlugin()); |
|
62 | - $this->server->addPlugin(new class() extends Plugin { |
|
63 | - public function getCurrentPrincipal() { |
|
64 | - return 'principals/system/public'; |
|
65 | - } |
|
66 | - }); |
|
60 | + $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
61 | + $this->server->addPlugin(new AnonymousOptionsPlugin()); |
|
62 | + $this->server->addPlugin(new class() extends Plugin { |
|
63 | + public function getCurrentPrincipal() { |
|
64 | + return 'principals/system/public'; |
|
65 | + } |
|
66 | + }); |
|
67 | 67 | |
68 | - // allow setup of additional auth backends |
|
69 | - $event = new SabrePluginEvent($this->server); |
|
70 | - $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
68 | + // allow setup of additional auth backends |
|
69 | + $event = new SabrePluginEvent($this->server); |
|
70 | + $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
71 | 71 | |
72 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
73 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
74 | - $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
72 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
73 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
74 | + $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
75 | 75 | |
76 | - // acl |
|
77 | - $acl = new DavAclPlugin(); |
|
78 | - $acl->principalCollectionSet = [ |
|
79 | - 'principals/users', 'principals/groups' |
|
80 | - ]; |
|
81 | - $acl->defaultUsernamePath = 'principals/users'; |
|
82 | - $this->server->addPlugin($acl); |
|
76 | + // acl |
|
77 | + $acl = new DavAclPlugin(); |
|
78 | + $acl->principalCollectionSet = [ |
|
79 | + 'principals/users', 'principals/groups' |
|
80 | + ]; |
|
81 | + $acl->defaultUsernamePath = 'principals/users'; |
|
82 | + $this->server->addPlugin($acl); |
|
83 | 83 | |
84 | - // calendar plugins |
|
85 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
86 | - $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); |
|
87 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
|
88 | - $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
89 | - $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
90 | - //$this->server->addPlugin(new \OCA\DAV\DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
91 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
92 | - \OC::$server->getConfig(), |
|
93 | - \OC::$server->getURLGenerator() |
|
94 | - )); |
|
84 | + // calendar plugins |
|
85 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
86 | + $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); |
|
87 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
|
88 | + $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
89 | + $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
90 | + //$this->server->addPlugin(new \OCA\DAV\DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
91 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
92 | + \OC::$server->getConfig(), |
|
93 | + \OC::$server->getURLGenerator() |
|
94 | + )); |
|
95 | 95 | |
96 | - // wait with registering these until auth is handled and the filesystem is setup |
|
97 | - $this->server->on('beforeMethod:*', function () use ($root) { |
|
98 | - // register plugins from apps |
|
99 | - $pluginManager = new PluginManager( |
|
100 | - \OC::$server, |
|
101 | - \OC::$server->getAppManager() |
|
102 | - ); |
|
103 | - foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
104 | - $this->server->addPlugin($appPlugin); |
|
105 | - } |
|
106 | - foreach ($pluginManager->getAppCollections() as $appCollection) { |
|
107 | - $root->addChild($appCollection); |
|
108 | - } |
|
109 | - }); |
|
110 | - } |
|
96 | + // wait with registering these until auth is handled and the filesystem is setup |
|
97 | + $this->server->on('beforeMethod:*', function () use ($root) { |
|
98 | + // register plugins from apps |
|
99 | + $pluginManager = new PluginManager( |
|
100 | + \OC::$server, |
|
101 | + \OC::$server->getAppManager() |
|
102 | + ); |
|
103 | + foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
104 | + $this->server->addPlugin($appPlugin); |
|
105 | + } |
|
106 | + foreach ($pluginManager->getAppCollections() as $appCollection) { |
|
107 | + $root->addChild($appCollection); |
|
108 | + } |
|
109 | + }); |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * @param Message $iTipMessage |
|
114 | - * @return void |
|
115 | - */ |
|
116 | - public function handleITipMessage(Message $iTipMessage) { |
|
117 | - /** @var \OCA\DAV\CalDAV\Schedule\Plugin $schedulingPlugin */ |
|
118 | - $schedulingPlugin = $this->server->getPlugin('caldav-schedule'); |
|
119 | - $schedulingPlugin->scheduleLocalDelivery($iTipMessage); |
|
120 | - } |
|
112 | + /** |
|
113 | + * @param Message $iTipMessage |
|
114 | + * @return void |
|
115 | + */ |
|
116 | + public function handleITipMessage(Message $iTipMessage) { |
|
117 | + /** @var \OCA\DAV\CalDAV\Schedule\Plugin $schedulingPlugin */ |
|
118 | + $schedulingPlugin = $this->server->getPlugin('caldav-schedule'); |
|
119 | + $schedulingPlugin->scheduleLocalDelivery($iTipMessage); |
|
120 | + } |
|
121 | 121 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * InvitationResponseServer constructor. |
44 | 44 | */ |
45 | 45 | public function __construct() { |
46 | - $baseUri = \OC::$WEBROOT . '/remote.php/dav/'; |
|
46 | + $baseUri = \OC::$WEBROOT.'/remote.php/dav/'; |
|
47 | 47 | $logger = \OC::$server->getLogger(); |
48 | 48 | $dispatcher = \OC::$server->getEventDispatcher(); |
49 | 49 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | )); |
95 | 95 | |
96 | 96 | // wait with registering these until auth is handled and the filesystem is setup |
97 | - $this->server->on('beforeMethod:*', function () use ($root) { |
|
97 | + $this->server->on('beforeMethod:*', function() use ($root) { |
|
98 | 98 | // register plugins from apps |
99 | 99 | $pluginManager = new PluginManager( |
100 | 100 | \OC::$server, |
@@ -50,435 +50,435 @@ |
||
50 | 50 | */ |
51 | 51 | class BirthdayService { |
52 | 52 | |
53 | - const BIRTHDAY_CALENDAR_URI = 'contact_birthdays'; |
|
54 | - |
|
55 | - /** @var GroupPrincipalBackend */ |
|
56 | - private $principalBackend; |
|
57 | - |
|
58 | - /** @var CalDavBackend */ |
|
59 | - private $calDavBackEnd; |
|
60 | - |
|
61 | - /** @var CardDavBackend */ |
|
62 | - private $cardDavBackEnd; |
|
63 | - |
|
64 | - /** @var IConfig */ |
|
65 | - private $config; |
|
66 | - |
|
67 | - /** @var IDBConnection */ |
|
68 | - private $dbConnection; |
|
69 | - |
|
70 | - /** @var IL10N */ |
|
71 | - private $l10n; |
|
72 | - |
|
73 | - /** |
|
74 | - * BirthdayService constructor. |
|
75 | - * |
|
76 | - * @param CalDavBackend $calDavBackEnd |
|
77 | - * @param CardDavBackend $cardDavBackEnd |
|
78 | - * @param GroupPrincipalBackend $principalBackend |
|
79 | - * @param IConfig $config |
|
80 | - * @param IDBConnection $dbConnection |
|
81 | - * @param IL10N $l10n |
|
82 | - */ |
|
83 | - public function __construct(CalDavBackend $calDavBackEnd, |
|
84 | - CardDavBackend $cardDavBackEnd, |
|
85 | - GroupPrincipalBackend $principalBackend, |
|
86 | - IConfig $config, |
|
87 | - IDBConnection $dbConnection, |
|
88 | - IL10N $l10n) { |
|
89 | - $this->calDavBackEnd = $calDavBackEnd; |
|
90 | - $this->cardDavBackEnd = $cardDavBackEnd; |
|
91 | - $this->principalBackend = $principalBackend; |
|
92 | - $this->config = $config; |
|
93 | - $this->dbConnection = $dbConnection; |
|
94 | - $this->l10n = $l10n; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * @param int $addressBookId |
|
99 | - * @param string $cardUri |
|
100 | - * @param string $cardData |
|
101 | - */ |
|
102 | - public function onCardChanged(int $addressBookId, |
|
103 | - string $cardUri, |
|
104 | - string $cardData) { |
|
105 | - if (!$this->isGloballyEnabled()) { |
|
106 | - return; |
|
107 | - } |
|
108 | - |
|
109 | - $targetPrincipals = $this->getAllAffectedPrincipals($addressBookId); |
|
110 | - $book = $this->cardDavBackEnd->getAddressBookById($addressBookId); |
|
111 | - $targetPrincipals[] = $book['principaluri']; |
|
112 | - $datesToSync = [ |
|
113 | - ['postfix' => '', 'field' => 'BDAY'], |
|
114 | - ['postfix' => '-death', 'field' => 'DEATHDATE'], |
|
115 | - ['postfix' => '-anniversary', 'field' => 'ANNIVERSARY'], |
|
116 | - ]; |
|
117 | - |
|
118 | - foreach ($targetPrincipals as $principalUri) { |
|
119 | - if (!$this->isUserEnabled($principalUri)) { |
|
120 | - continue; |
|
121 | - } |
|
122 | - |
|
123 | - $calendar = $this->ensureCalendarExists($principalUri); |
|
124 | - foreach ($datesToSync as $type) { |
|
125 | - $this->updateCalendar($cardUri, $cardData, $book, (int) $calendar['id'], $type); |
|
126 | - } |
|
127 | - } |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @param int $addressBookId |
|
132 | - * @param string $cardUri |
|
133 | - */ |
|
134 | - public function onCardDeleted(int $addressBookId, |
|
135 | - string $cardUri) { |
|
136 | - if (!$this->isGloballyEnabled()) { |
|
137 | - return; |
|
138 | - } |
|
139 | - |
|
140 | - $targetPrincipals = $this->getAllAffectedPrincipals($addressBookId); |
|
141 | - $book = $this->cardDavBackEnd->getAddressBookById($addressBookId); |
|
142 | - $targetPrincipals[] = $book['principaluri']; |
|
143 | - foreach ($targetPrincipals as $principalUri) { |
|
144 | - if (!$this->isUserEnabled($principalUri)) { |
|
145 | - continue; |
|
146 | - } |
|
147 | - |
|
148 | - $calendar = $this->ensureCalendarExists($principalUri); |
|
149 | - foreach (['', '-death', '-anniversary'] as $tag) { |
|
150 | - $objectUri = $book['uri'] . '-' . $cardUri . $tag .'.ics'; |
|
151 | - $this->calDavBackEnd->deleteCalendarObject($calendar['id'], $objectUri); |
|
152 | - } |
|
153 | - } |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * @param string $principal |
|
158 | - * @return array|null |
|
159 | - * @throws \Sabre\DAV\Exception\BadRequest |
|
160 | - */ |
|
161 | - public function ensureCalendarExists(string $principal):?array { |
|
162 | - $calendar = $this->calDavBackEnd->getCalendarByUri($principal, self::BIRTHDAY_CALENDAR_URI); |
|
163 | - if (!is_null($calendar)) { |
|
164 | - return $calendar; |
|
165 | - } |
|
166 | - $this->calDavBackEnd->createCalendar($principal, self::BIRTHDAY_CALENDAR_URI, [ |
|
167 | - '{DAV:}displayname' => 'Contact birthdays', |
|
168 | - '{http://apple.com/ns/ical/}calendar-color' => '#FFFFCA', |
|
169 | - 'components' => 'VEVENT', |
|
170 | - ]); |
|
171 | - |
|
172 | - return $this->calDavBackEnd->getCalendarByUri($principal, self::BIRTHDAY_CALENDAR_URI); |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * @param $cardData |
|
177 | - * @param $dateField |
|
178 | - * @param $postfix |
|
179 | - * @return VCalendar|null |
|
180 | - * @throws InvalidDataException |
|
181 | - */ |
|
182 | - public function buildDateFromContact(string $cardData, |
|
183 | - string $dateField, |
|
184 | - string $postfix):?VCalendar { |
|
185 | - if (empty($cardData)) { |
|
186 | - return null; |
|
187 | - } |
|
188 | - try { |
|
189 | - $doc = Reader::read($cardData); |
|
190 | - // We're always converting to vCard 4.0 so we can rely on the |
|
191 | - // VCardConverter handling the X-APPLE-OMIT-YEAR property for us. |
|
192 | - if (!$doc instanceof VCard) { |
|
193 | - return null; |
|
194 | - } |
|
195 | - $doc = $doc->convert(Document::VCARD40); |
|
196 | - } catch (Exception $e) { |
|
197 | - return null; |
|
198 | - } |
|
199 | - |
|
200 | - if (!isset($doc->{$dateField})) { |
|
201 | - return null; |
|
202 | - } |
|
203 | - if (!isset($doc->FN)) { |
|
204 | - return null; |
|
205 | - } |
|
206 | - $birthday = $doc->{$dateField}; |
|
207 | - if (!(string)$birthday) { |
|
208 | - return null; |
|
209 | - } |
|
210 | - // Skip if the BDAY property is not of the right type. |
|
211 | - if (!$birthday instanceof DateAndOrTime) { |
|
212 | - return null; |
|
213 | - } |
|
214 | - |
|
215 | - // Skip if we can't parse the BDAY value. |
|
216 | - try { |
|
217 | - $dateParts = DateTimeParser::parseVCardDateTime($birthday->getValue()); |
|
218 | - } catch (InvalidDataException $e) { |
|
219 | - return null; |
|
220 | - } |
|
221 | - |
|
222 | - $unknownYear = false; |
|
223 | - $originalYear = null; |
|
224 | - if (!$dateParts['year']) { |
|
225 | - $birthday = '1970-' . $dateParts['month'] . '-' . $dateParts['date']; |
|
226 | - |
|
227 | - $unknownYear = true; |
|
228 | - } else { |
|
229 | - $parameters = $birthday->parameters(); |
|
230 | - if (isset($parameters['X-APPLE-OMIT-YEAR'])) { |
|
231 | - $omitYear = $parameters['X-APPLE-OMIT-YEAR']; |
|
232 | - if ($dateParts['year'] === $omitYear) { |
|
233 | - $birthday = '1970-' . $dateParts['month'] . '-' . $dateParts['date']; |
|
234 | - $unknownYear = true; |
|
235 | - } |
|
236 | - } else { |
|
237 | - $originalYear = (int)$dateParts['year']; |
|
238 | - |
|
239 | - if ($originalYear < 1970) { |
|
240 | - $birthday = '1970-' . $dateParts['month'] . '-' . $dateParts['date']; |
|
241 | - } |
|
242 | - } |
|
243 | - } |
|
244 | - |
|
245 | - try { |
|
246 | - if ($birthday instanceof DateAndOrTime) { |
|
247 | - $date = $birthday->getDateTime(); |
|
248 | - } else { |
|
249 | - $date = new \DateTimeImmutable($birthday); |
|
250 | - } |
|
251 | - } catch (Exception $e) { |
|
252 | - return null; |
|
253 | - } |
|
254 | - |
|
255 | - $summary = $this->formatTitle($dateField, $doc->FN->getValue(), $originalYear, $this->dbConnection->supports4ByteText()); |
|
256 | - |
|
257 | - $vCal = new VCalendar(); |
|
258 | - $vCal->VERSION = '2.0'; |
|
259 | - $vCal->PRODID = '-//IDN nextcloud.com//Birthday calendar//EN'; |
|
260 | - $vEvent = $vCal->createComponent('VEVENT'); |
|
261 | - $vEvent->add('DTSTART'); |
|
262 | - $vEvent->DTSTART->setDateTime( |
|
263 | - $date |
|
264 | - ); |
|
265 | - $vEvent->DTSTART['VALUE'] = 'DATE'; |
|
266 | - $vEvent->add('DTEND'); |
|
267 | - |
|
268 | - $dtEndDate = (new \DateTime())->setTimestamp($date->getTimeStamp()); |
|
269 | - $dtEndDate->add(new \DateInterval('P1D')); |
|
270 | - $vEvent->DTEND->setDateTime( |
|
271 | - $dtEndDate |
|
272 | - ); |
|
273 | - |
|
274 | - $vEvent->DTEND['VALUE'] = 'DATE'; |
|
275 | - $vEvent->{'UID'} = $doc->UID . $postfix; |
|
276 | - $vEvent->{'RRULE'} = 'FREQ=YEARLY'; |
|
277 | - $vEvent->{'SUMMARY'} = $summary; |
|
278 | - $vEvent->{'TRANSP'} = 'TRANSPARENT'; |
|
279 | - $vEvent->{'X-NEXTCLOUD-BC-FIELD-TYPE'} = $dateField; |
|
280 | - $vEvent->{'X-NEXTCLOUD-BC-UNKNOWN-YEAR'} = $unknownYear ? '1' : '0'; |
|
281 | - if ($originalYear !== null) { |
|
282 | - $vEvent->{'X-NEXTCLOUD-BC-YEAR'} = (string) $originalYear; |
|
283 | - } |
|
284 | - $alarm = $vCal->createComponent('VALARM'); |
|
285 | - $alarm->add($vCal->createProperty('TRIGGER', '-PT0M', ['VALUE' => 'DURATION'])); |
|
286 | - $alarm->add($vCal->createProperty('ACTION', 'DISPLAY')); |
|
287 | - $alarm->add($vCal->createProperty('DESCRIPTION', $vEvent->{'SUMMARY'})); |
|
288 | - $vEvent->add($alarm); |
|
289 | - $vCal->add($vEvent); |
|
290 | - return $vCal; |
|
291 | - } |
|
292 | - |
|
293 | - /** |
|
294 | - * @param string $user |
|
295 | - */ |
|
296 | - public function resetForUser(string $user):void { |
|
297 | - $principal = 'principals/users/'.$user; |
|
298 | - $calendar = $this->calDavBackEnd->getCalendarByUri($principal, self::BIRTHDAY_CALENDAR_URI); |
|
299 | - $calendarObjects = $this->calDavBackEnd->getCalendarObjects($calendar['id'], CalDavBackend::CALENDAR_TYPE_CALENDAR); |
|
300 | - |
|
301 | - foreach($calendarObjects as $calendarObject) { |
|
302 | - $this->calDavBackEnd->deleteCalendarObject($calendar['id'], $calendarObject['uri'], CalDavBackend::CALENDAR_TYPE_CALENDAR); |
|
303 | - } |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * @param string $user |
|
308 | - * @throws \Sabre\DAV\Exception\BadRequest |
|
309 | - */ |
|
310 | - public function syncUser(string $user):void { |
|
311 | - $principal = 'principals/users/'.$user; |
|
312 | - $this->ensureCalendarExists($principal); |
|
313 | - $books = $this->cardDavBackEnd->getAddressBooksForUser($principal); |
|
314 | - foreach($books as $book) { |
|
315 | - $cards = $this->cardDavBackEnd->getCards($book['id']); |
|
316 | - foreach($cards as $card) { |
|
317 | - $this->onCardChanged((int) $book['id'], $card['uri'], $card['carddata']); |
|
318 | - } |
|
319 | - } |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * @param string $existingCalendarData |
|
324 | - * @param VCalendar $newCalendarData |
|
325 | - * @return bool |
|
326 | - */ |
|
327 | - public function birthdayEvenChanged(string $existingCalendarData, |
|
328 | - VCalendar $newCalendarData):bool { |
|
329 | - try { |
|
330 | - $existingBirthday = Reader::read($existingCalendarData); |
|
331 | - } catch (Exception $ex) { |
|
332 | - return true; |
|
333 | - } |
|
334 | - |
|
335 | - return ( |
|
336 | - $newCalendarData->VEVENT->DTSTART->getValue() !== $existingBirthday->VEVENT->DTSTART->getValue() || |
|
337 | - $newCalendarData->VEVENT->SUMMARY->getValue() !== $existingBirthday->VEVENT->SUMMARY->getValue() |
|
338 | - ); |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * @param integer $addressBookId |
|
343 | - * @return mixed |
|
344 | - */ |
|
345 | - protected function getAllAffectedPrincipals(int $addressBookId) { |
|
346 | - $targetPrincipals = []; |
|
347 | - $shares = $this->cardDavBackEnd->getShares($addressBookId); |
|
348 | - foreach ($shares as $share) { |
|
349 | - if ($share['{http://owncloud.org/ns}group-share']) { |
|
350 | - $users = $this->principalBackend->getGroupMemberSet($share['{http://owncloud.org/ns}principal']); |
|
351 | - foreach ($users as $user) { |
|
352 | - $targetPrincipals[] = $user['uri']; |
|
353 | - } |
|
354 | - } else { |
|
355 | - $targetPrincipals[] = $share['{http://owncloud.org/ns}principal']; |
|
356 | - } |
|
357 | - } |
|
358 | - return array_values(array_unique($targetPrincipals, SORT_STRING)); |
|
359 | - } |
|
360 | - |
|
361 | - /** |
|
362 | - * @param string $cardUri |
|
363 | - * @param string $cardData |
|
364 | - * @param array $book |
|
365 | - * @param int $calendarId |
|
366 | - * @param array $type |
|
367 | - * @throws InvalidDataException |
|
368 | - * @throws \Sabre\DAV\Exception\BadRequest |
|
369 | - */ |
|
370 | - private function updateCalendar(string $cardUri, |
|
371 | - string $cardData, |
|
372 | - array $book, |
|
373 | - int $calendarId, |
|
374 | - array $type):void { |
|
375 | - $objectUri = $book['uri'] . '-' . $cardUri . $type['postfix'] . '.ics'; |
|
376 | - $calendarData = $this->buildDateFromContact($cardData, $type['field'], $type['postfix']); |
|
377 | - $existing = $this->calDavBackEnd->getCalendarObject($calendarId, $objectUri); |
|
378 | - if (is_null($calendarData)) { |
|
379 | - if (!is_null($existing)) { |
|
380 | - $this->calDavBackEnd->deleteCalendarObject($calendarId, $objectUri); |
|
381 | - } |
|
382 | - } else { |
|
383 | - if (is_null($existing)) { |
|
384 | - $this->calDavBackEnd->createCalendarObject($calendarId, $objectUri, $calendarData->serialize()); |
|
385 | - } else { |
|
386 | - if ($this->birthdayEvenChanged($existing['calendardata'], $calendarData)) { |
|
387 | - $this->calDavBackEnd->updateCalendarObject($calendarId, $objectUri, $calendarData->serialize()); |
|
388 | - } |
|
389 | - } |
|
390 | - } |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * checks if the admin opted-out of birthday calendars |
|
395 | - * |
|
396 | - * @return bool |
|
397 | - */ |
|
398 | - private function isGloballyEnabled():bool { |
|
399 | - return $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes') === 'yes'; |
|
400 | - } |
|
401 | - |
|
402 | - /** |
|
403 | - * Checks if the user opted-out of birthday calendars |
|
404 | - * |
|
405 | - * @param string $userPrincipal The user principal to check for |
|
406 | - * @return bool |
|
407 | - */ |
|
408 | - private function isUserEnabled(string $userPrincipal):bool { |
|
409 | - if (strpos($userPrincipal, 'principals/users/') === 0) { |
|
410 | - $userId = substr($userPrincipal, 17); |
|
411 | - $isEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
412 | - return $isEnabled === 'yes'; |
|
413 | - } |
|
414 | - |
|
415 | - // not sure how we got here, just be on the safe side and return true |
|
416 | - return true; |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * Formats title of Birthday event |
|
421 | - * |
|
422 | - * @param string $field Field name like BDAY, ANNIVERSARY, ... |
|
423 | - * @param string $name Name of contact |
|
424 | - * @param int|null $year Year of birth, anniversary, ... |
|
425 | - * @param bool $supports4Byte Whether or not the database supports 4 byte chars |
|
426 | - * @return string The formatted title |
|
427 | - */ |
|
428 | - private function formatTitle(string $field, |
|
429 | - string $name, |
|
430 | - int $year=null, |
|
431 | - bool $supports4Byte=true):string { |
|
432 | - if ($supports4Byte) { |
|
433 | - switch ($field) { |
|
434 | - case 'BDAY': |
|
435 | - return implode('', [ |
|
436 | - ' |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | |
148 | 148 | $calendar = $this->ensureCalendarExists($principalUri); |
149 | 149 | foreach (['', '-death', '-anniversary'] as $tag) { |
150 | - $objectUri = $book['uri'] . '-' . $cardUri . $tag .'.ics'; |
|
150 | + $objectUri = $book['uri'].'-'.$cardUri.$tag.'.ics'; |
|
151 | 151 | $this->calDavBackEnd->deleteCalendarObject($calendar['id'], $objectUri); |
152 | 152 | } |
153 | 153 | } |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return array|null |
159 | 159 | * @throws \Sabre\DAV\Exception\BadRequest |
160 | 160 | */ |
161 | - public function ensureCalendarExists(string $principal):?array { |
|
161 | + public function ensureCalendarExists(string $principal): ?array { |
|
162 | 162 | $calendar = $this->calDavBackEnd->getCalendarByUri($principal, self::BIRTHDAY_CALENDAR_URI); |
163 | 163 | if (!is_null($calendar)) { |
164 | 164 | return $calendar; |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | */ |
182 | 182 | public function buildDateFromContact(string $cardData, |
183 | 183 | string $dateField, |
184 | - string $postfix):?VCalendar { |
|
184 | + string $postfix): ?VCalendar { |
|
185 | 185 | if (empty($cardData)) { |
186 | 186 | return null; |
187 | 187 | } |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | return null; |
205 | 205 | } |
206 | 206 | $birthday = $doc->{$dateField}; |
207 | - if (!(string)$birthday) { |
|
207 | + if (!(string) $birthday) { |
|
208 | 208 | return null; |
209 | 209 | } |
210 | 210 | // Skip if the BDAY property is not of the right type. |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | $unknownYear = false; |
223 | 223 | $originalYear = null; |
224 | 224 | if (!$dateParts['year']) { |
225 | - $birthday = '1970-' . $dateParts['month'] . '-' . $dateParts['date']; |
|
225 | + $birthday = '1970-'.$dateParts['month'].'-'.$dateParts['date']; |
|
226 | 226 | |
227 | 227 | $unknownYear = true; |
228 | 228 | } else { |
@@ -230,14 +230,14 @@ discard block |
||
230 | 230 | if (isset($parameters['X-APPLE-OMIT-YEAR'])) { |
231 | 231 | $omitYear = $parameters['X-APPLE-OMIT-YEAR']; |
232 | 232 | if ($dateParts['year'] === $omitYear) { |
233 | - $birthday = '1970-' . $dateParts['month'] . '-' . $dateParts['date']; |
|
233 | + $birthday = '1970-'.$dateParts['month'].'-'.$dateParts['date']; |
|
234 | 234 | $unknownYear = true; |
235 | 235 | } |
236 | 236 | } else { |
237 | - $originalYear = (int)$dateParts['year']; |
|
237 | + $originalYear = (int) $dateParts['year']; |
|
238 | 238 | |
239 | 239 | if ($originalYear < 1970) { |
240 | - $birthday = '1970-' . $dateParts['month'] . '-' . $dateParts['date']; |
|
240 | + $birthday = '1970-'.$dateParts['month'].'-'.$dateParts['date']; |
|
241 | 241 | } |
242 | 242 | } |
243 | 243 | } |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | ); |
273 | 273 | |
274 | 274 | $vEvent->DTEND['VALUE'] = 'DATE'; |
275 | - $vEvent->{'UID'} = $doc->UID . $postfix; |
|
275 | + $vEvent->{'UID'} = $doc->UID.$postfix; |
|
276 | 276 | $vEvent->{'RRULE'} = 'FREQ=YEARLY'; |
277 | 277 | $vEvent->{'SUMMARY'} = $summary; |
278 | 278 | $vEvent->{'TRANSP'} = 'TRANSPARENT'; |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | $calendar = $this->calDavBackEnd->getCalendarByUri($principal, self::BIRTHDAY_CALENDAR_URI); |
299 | 299 | $calendarObjects = $this->calDavBackEnd->getCalendarObjects($calendar['id'], CalDavBackend::CALENDAR_TYPE_CALENDAR); |
300 | 300 | |
301 | - foreach($calendarObjects as $calendarObject) { |
|
301 | + foreach ($calendarObjects as $calendarObject) { |
|
302 | 302 | $this->calDavBackEnd->deleteCalendarObject($calendar['id'], $calendarObject['uri'], CalDavBackend::CALENDAR_TYPE_CALENDAR); |
303 | 303 | } |
304 | 304 | } |
@@ -311,9 +311,9 @@ discard block |
||
311 | 311 | $principal = 'principals/users/'.$user; |
312 | 312 | $this->ensureCalendarExists($principal); |
313 | 313 | $books = $this->cardDavBackEnd->getAddressBooksForUser($principal); |
314 | - foreach($books as $book) { |
|
314 | + foreach ($books as $book) { |
|
315 | 315 | $cards = $this->cardDavBackEnd->getCards($book['id']); |
316 | - foreach($cards as $card) { |
|
316 | + foreach ($cards as $card) { |
|
317 | 317 | $this->onCardChanged((int) $book['id'], $card['uri'], $card['carddata']); |
318 | 318 | } |
319 | 319 | } |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | array $book, |
373 | 373 | int $calendarId, |
374 | 374 | array $type):void { |
375 | - $objectUri = $book['uri'] . '-' . $cardUri . $type['postfix'] . '.ics'; |
|
375 | + $objectUri = $book['uri'].'-'.$cardUri.$type['postfix'].'.ics'; |
|
376 | 376 | $calendarData = $this->buildDateFromContact($cardData, $type['field'], $type['postfix']); |
377 | 377 | $existing = $this->calDavBackEnd->getCalendarObject($calendarId, $objectUri); |
378 | 378 | if (is_null($calendarData)) { |
@@ -427,53 +427,53 @@ discard block |
||
427 | 427 | */ |
428 | 428 | private function formatTitle(string $field, |
429 | 429 | string $name, |
430 | - int $year=null, |
|
431 | - bool $supports4Byte=true):string { |
|
430 | + int $year = null, |
|
431 | + bool $supports4Byte = true):string { |
|
432 | 432 | if ($supports4Byte) { |
433 | 433 | switch ($field) { |
434 | 434 | case 'BDAY': |
435 | 435 | return implode('', [ |
436 | 436 | ' |
@@ -37,113 +37,113 @@ |
||
37 | 37 | |
38 | 38 | class Plugin extends ServerPlugin { |
39 | 39 | |
40 | - /** |
|
41 | - * list of regular expressions for calendar user agents, |
|
42 | - * that do not support subscriptions on their own |
|
43 | - * |
|
44 | - * @var string[] |
|
45 | - */ |
|
46 | - const ENABLE_FOR_CLIENTS = []; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var bool |
|
50 | - */ |
|
51 | - private $enabled=false; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var Server |
|
55 | - */ |
|
56 | - private $server; |
|
57 | - |
|
58 | - /** |
|
59 | - * Plugin constructor. |
|
60 | - * |
|
61 | - * @param IRequest $request |
|
62 | - */ |
|
63 | - public function __construct(IRequest $request) { |
|
64 | - if ($request->isUserAgent(self::ENABLE_FOR_CLIENTS)) { |
|
65 | - $this->enabled = true; |
|
66 | - } |
|
67 | - |
|
68 | - $magicHeader = $request->getHeader('X-NC-CalDAV-Webcal-Caching'); |
|
69 | - if ($magicHeader === 'On') { |
|
70 | - $this->enabled = true; |
|
71 | - } |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * This initializes the plugin. |
|
76 | - * |
|
77 | - * This function is called by Sabre\DAV\Server, after |
|
78 | - * addPlugin is called. |
|
79 | - * |
|
80 | - * This method should set up the required event subscriptions. |
|
81 | - * |
|
82 | - * @param Server $server |
|
83 | - */ |
|
84 | - public function initialize(Server $server) { |
|
85 | - $this->server = $server; |
|
86 | - $server->on('beforeMethod:*', [$this, 'beforeMethod']); |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * @param RequestInterface $request |
|
91 | - * @param ResponseInterface $response |
|
92 | - */ |
|
93 | - public function beforeMethod(RequestInterface $request, ResponseInterface $response) { |
|
94 | - if (!$this->enabled) { |
|
95 | - return; |
|
96 | - } |
|
97 | - |
|
98 | - $path = $request->getPath(); |
|
99 | - $pathParts = explode('/', ltrim($path, '/')); |
|
100 | - if (\count($pathParts) < 2) { |
|
101 | - return; |
|
102 | - } |
|
103 | - |
|
104 | - // $calendarHomePath will look like: calendars/username |
|
105 | - $calendarHomePath = $pathParts[0] . '/' . $pathParts[1]; |
|
106 | - try { |
|
107 | - $calendarHome = $this->server->tree->getNodeForPath($calendarHomePath); |
|
108 | - if (!($calendarHome instanceof CalendarHome)) { |
|
109 | - //how did we end up here? |
|
110 | - return; |
|
111 | - } |
|
112 | - |
|
113 | - $calendarHome->enableCachedSubscriptionsForThisRequest(); |
|
114 | - } catch(NotFound $ex) { |
|
115 | - return; |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * @return bool |
|
121 | - */ |
|
122 | - public function isCachingEnabledForThisRequest():bool { |
|
123 | - return $this->enabled; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * This method should return a list of server-features. |
|
128 | - * |
|
129 | - * This is for example 'versioning' and is added to the DAV: header |
|
130 | - * in an OPTIONS response. |
|
131 | - * |
|
132 | - * @return string[] |
|
133 | - */ |
|
134 | - public function getFeatures():array { |
|
135 | - return ['nc-calendar-webcal-cache']; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Returns a plugin name. |
|
140 | - * |
|
141 | - * Using this name other plugins will be able to access other plugins |
|
142 | - * using Sabre\DAV\Server::getPlugin |
|
143 | - * |
|
144 | - * @return string |
|
145 | - */ |
|
146 | - public function getPluginName():string { |
|
147 | - return 'nc-calendar-webcal-cache'; |
|
148 | - } |
|
40 | + /** |
|
41 | + * list of regular expressions for calendar user agents, |
|
42 | + * that do not support subscriptions on their own |
|
43 | + * |
|
44 | + * @var string[] |
|
45 | + */ |
|
46 | + const ENABLE_FOR_CLIENTS = []; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var bool |
|
50 | + */ |
|
51 | + private $enabled=false; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var Server |
|
55 | + */ |
|
56 | + private $server; |
|
57 | + |
|
58 | + /** |
|
59 | + * Plugin constructor. |
|
60 | + * |
|
61 | + * @param IRequest $request |
|
62 | + */ |
|
63 | + public function __construct(IRequest $request) { |
|
64 | + if ($request->isUserAgent(self::ENABLE_FOR_CLIENTS)) { |
|
65 | + $this->enabled = true; |
|
66 | + } |
|
67 | + |
|
68 | + $magicHeader = $request->getHeader('X-NC-CalDAV-Webcal-Caching'); |
|
69 | + if ($magicHeader === 'On') { |
|
70 | + $this->enabled = true; |
|
71 | + } |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * This initializes the plugin. |
|
76 | + * |
|
77 | + * This function is called by Sabre\DAV\Server, after |
|
78 | + * addPlugin is called. |
|
79 | + * |
|
80 | + * This method should set up the required event subscriptions. |
|
81 | + * |
|
82 | + * @param Server $server |
|
83 | + */ |
|
84 | + public function initialize(Server $server) { |
|
85 | + $this->server = $server; |
|
86 | + $server->on('beforeMethod:*', [$this, 'beforeMethod']); |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * @param RequestInterface $request |
|
91 | + * @param ResponseInterface $response |
|
92 | + */ |
|
93 | + public function beforeMethod(RequestInterface $request, ResponseInterface $response) { |
|
94 | + if (!$this->enabled) { |
|
95 | + return; |
|
96 | + } |
|
97 | + |
|
98 | + $path = $request->getPath(); |
|
99 | + $pathParts = explode('/', ltrim($path, '/')); |
|
100 | + if (\count($pathParts) < 2) { |
|
101 | + return; |
|
102 | + } |
|
103 | + |
|
104 | + // $calendarHomePath will look like: calendars/username |
|
105 | + $calendarHomePath = $pathParts[0] . '/' . $pathParts[1]; |
|
106 | + try { |
|
107 | + $calendarHome = $this->server->tree->getNodeForPath($calendarHomePath); |
|
108 | + if (!($calendarHome instanceof CalendarHome)) { |
|
109 | + //how did we end up here? |
|
110 | + return; |
|
111 | + } |
|
112 | + |
|
113 | + $calendarHome->enableCachedSubscriptionsForThisRequest(); |
|
114 | + } catch(NotFound $ex) { |
|
115 | + return; |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * @return bool |
|
121 | + */ |
|
122 | + public function isCachingEnabledForThisRequest():bool { |
|
123 | + return $this->enabled; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * This method should return a list of server-features. |
|
128 | + * |
|
129 | + * This is for example 'versioning' and is added to the DAV: header |
|
130 | + * in an OPTIONS response. |
|
131 | + * |
|
132 | + * @return string[] |
|
133 | + */ |
|
134 | + public function getFeatures():array { |
|
135 | + return ['nc-calendar-webcal-cache']; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Returns a plugin name. |
|
140 | + * |
|
141 | + * Using this name other plugins will be able to access other plugins |
|
142 | + * using Sabre\DAV\Server::getPlugin |
|
143 | + * |
|
144 | + * @return string |
|
145 | + */ |
|
146 | + public function getPluginName():string { |
|
147 | + return 'nc-calendar-webcal-cache'; |
|
148 | + } |
|
149 | 149 | } |
@@ -47,176 +47,176 @@ |
||
47 | 47 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
48 | 48 | |
49 | 49 | class ServerFactory { |
50 | - /** @var IConfig */ |
|
51 | - private $config; |
|
52 | - /** @var ILogger */ |
|
53 | - private $logger; |
|
54 | - /** @var IDBConnection */ |
|
55 | - private $databaseConnection; |
|
56 | - /** @var IUserSession */ |
|
57 | - private $userSession; |
|
58 | - /** @var IMountManager */ |
|
59 | - private $mountManager; |
|
60 | - /** @var ITagManager */ |
|
61 | - private $tagManager; |
|
62 | - /** @var IRequest */ |
|
63 | - private $request; |
|
64 | - /** @var IPreview */ |
|
65 | - private $previewManager; |
|
66 | - /** @var EventDispatcherInterface */ |
|
67 | - private $eventDispatcher; |
|
50 | + /** @var IConfig */ |
|
51 | + private $config; |
|
52 | + /** @var ILogger */ |
|
53 | + private $logger; |
|
54 | + /** @var IDBConnection */ |
|
55 | + private $databaseConnection; |
|
56 | + /** @var IUserSession */ |
|
57 | + private $userSession; |
|
58 | + /** @var IMountManager */ |
|
59 | + private $mountManager; |
|
60 | + /** @var ITagManager */ |
|
61 | + private $tagManager; |
|
62 | + /** @var IRequest */ |
|
63 | + private $request; |
|
64 | + /** @var IPreview */ |
|
65 | + private $previewManager; |
|
66 | + /** @var EventDispatcherInterface */ |
|
67 | + private $eventDispatcher; |
|
68 | 68 | |
69 | - /** |
|
70 | - * @param IConfig $config |
|
71 | - * @param ILogger $logger |
|
72 | - * @param IDBConnection $databaseConnection |
|
73 | - * @param IUserSession $userSession |
|
74 | - * @param IMountManager $mountManager |
|
75 | - * @param ITagManager $tagManager |
|
76 | - * @param IRequest $request |
|
77 | - * @param IPreview $previewManager |
|
78 | - */ |
|
79 | - public function __construct( |
|
80 | - IConfig $config, |
|
81 | - ILogger $logger, |
|
82 | - IDBConnection $databaseConnection, |
|
83 | - IUserSession $userSession, |
|
84 | - IMountManager $mountManager, |
|
85 | - ITagManager $tagManager, |
|
86 | - IRequest $request, |
|
87 | - IPreview $previewManager, |
|
88 | - EventDispatcherInterface $eventDispatcher |
|
89 | - ) { |
|
90 | - $this->config = $config; |
|
91 | - $this->logger = $logger; |
|
92 | - $this->databaseConnection = $databaseConnection; |
|
93 | - $this->userSession = $userSession; |
|
94 | - $this->mountManager = $mountManager; |
|
95 | - $this->tagManager = $tagManager; |
|
96 | - $this->request = $request; |
|
97 | - $this->previewManager = $previewManager; |
|
98 | - $this->eventDispatcher = $eventDispatcher; |
|
99 | - } |
|
69 | + /** |
|
70 | + * @param IConfig $config |
|
71 | + * @param ILogger $logger |
|
72 | + * @param IDBConnection $databaseConnection |
|
73 | + * @param IUserSession $userSession |
|
74 | + * @param IMountManager $mountManager |
|
75 | + * @param ITagManager $tagManager |
|
76 | + * @param IRequest $request |
|
77 | + * @param IPreview $previewManager |
|
78 | + */ |
|
79 | + public function __construct( |
|
80 | + IConfig $config, |
|
81 | + ILogger $logger, |
|
82 | + IDBConnection $databaseConnection, |
|
83 | + IUserSession $userSession, |
|
84 | + IMountManager $mountManager, |
|
85 | + ITagManager $tagManager, |
|
86 | + IRequest $request, |
|
87 | + IPreview $previewManager, |
|
88 | + EventDispatcherInterface $eventDispatcher |
|
89 | + ) { |
|
90 | + $this->config = $config; |
|
91 | + $this->logger = $logger; |
|
92 | + $this->databaseConnection = $databaseConnection; |
|
93 | + $this->userSession = $userSession; |
|
94 | + $this->mountManager = $mountManager; |
|
95 | + $this->tagManager = $tagManager; |
|
96 | + $this->request = $request; |
|
97 | + $this->previewManager = $previewManager; |
|
98 | + $this->eventDispatcher = $eventDispatcher; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @param string $baseUri |
|
103 | - * @param string $requestUri |
|
104 | - * @param Plugin $authPlugin |
|
105 | - * @param callable $viewCallBack callback that should return the view for the dav endpoint |
|
106 | - * @return Server |
|
107 | - */ |
|
108 | - public function createServer($baseUri, |
|
109 | - $requestUri, |
|
110 | - Plugin $authPlugin, |
|
111 | - callable $viewCallBack) { |
|
112 | - // Fire up server |
|
113 | - $objectTree = new \OCA\DAV\Connector\Sabre\ObjectTree(); |
|
114 | - $server = new \OCA\DAV\Connector\Sabre\Server($objectTree); |
|
115 | - // Set URL explicitly due to reverse-proxy situations |
|
116 | - $server->httpRequest->setUrl($requestUri); |
|
117 | - $server->setBaseUri($baseUri); |
|
101 | + /** |
|
102 | + * @param string $baseUri |
|
103 | + * @param string $requestUri |
|
104 | + * @param Plugin $authPlugin |
|
105 | + * @param callable $viewCallBack callback that should return the view for the dav endpoint |
|
106 | + * @return Server |
|
107 | + */ |
|
108 | + public function createServer($baseUri, |
|
109 | + $requestUri, |
|
110 | + Plugin $authPlugin, |
|
111 | + callable $viewCallBack) { |
|
112 | + // Fire up server |
|
113 | + $objectTree = new \OCA\DAV\Connector\Sabre\ObjectTree(); |
|
114 | + $server = new \OCA\DAV\Connector\Sabre\Server($objectTree); |
|
115 | + // Set URL explicitly due to reverse-proxy situations |
|
116 | + $server->httpRequest->setUrl($requestUri); |
|
117 | + $server->setBaseUri($baseUri); |
|
118 | 118 | |
119 | - // Load plugins |
|
120 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config)); |
|
121 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin($this->config)); |
|
122 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\AnonymousOptionsPlugin()); |
|
123 | - $server->addPlugin($authPlugin); |
|
124 | - // FIXME: The following line is a workaround for legacy components relying on being able to send a GET to / |
|
125 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\DummyGetResponsePlugin()); |
|
126 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger)); |
|
127 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
128 | - // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
129 | - // we do not provide locking we emulate it using a fake locking plugin. |
|
130 | - if($this->request->isUserAgent([ |
|
131 | - '/WebDAVFS/', |
|
132 | - '/OneNote/', |
|
133 | - '/Microsoft-WebDAV-MiniRedir/', |
|
134 | - ])) { |
|
135 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin()); |
|
136 | - } |
|
119 | + // Load plugins |
|
120 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config)); |
|
121 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin($this->config)); |
|
122 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\AnonymousOptionsPlugin()); |
|
123 | + $server->addPlugin($authPlugin); |
|
124 | + // FIXME: The following line is a workaround for legacy components relying on being able to send a GET to / |
|
125 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\DummyGetResponsePlugin()); |
|
126 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger)); |
|
127 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
128 | + // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
129 | + // we do not provide locking we emulate it using a fake locking plugin. |
|
130 | + if($this->request->isUserAgent([ |
|
131 | + '/WebDAVFS/', |
|
132 | + '/OneNote/', |
|
133 | + '/Microsoft-WebDAV-MiniRedir/', |
|
134 | + ])) { |
|
135 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin()); |
|
136 | + } |
|
137 | 137 | |
138 | - if (BrowserErrorPagePlugin::isBrowserRequest($this->request)) { |
|
139 | - $server->addPlugin(new BrowserErrorPagePlugin()); |
|
140 | - } |
|
138 | + if (BrowserErrorPagePlugin::isBrowserRequest($this->request)) { |
|
139 | + $server->addPlugin(new BrowserErrorPagePlugin()); |
|
140 | + } |
|
141 | 141 | |
142 | - // wait with registering these until auth is handled and the filesystem is setup |
|
143 | - $server->on('beforeMethod:*', function () use ($server, $objectTree, $viewCallBack) { |
|
144 | - // ensure the skeleton is copied |
|
145 | - $userFolder = \OC::$server->getUserFolder(); |
|
142 | + // wait with registering these until auth is handled and the filesystem is setup |
|
143 | + $server->on('beforeMethod:*', function () use ($server, $objectTree, $viewCallBack) { |
|
144 | + // ensure the skeleton is copied |
|
145 | + $userFolder = \OC::$server->getUserFolder(); |
|
146 | 146 | |
147 | - /** @var \OC\Files\View $view */ |
|
148 | - $view = $viewCallBack($server); |
|
149 | - if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) { |
|
150 | - $rootInfo = $userFolder; |
|
151 | - } else { |
|
152 | - $rootInfo = $view->getFileInfo(''); |
|
153 | - } |
|
147 | + /** @var \OC\Files\View $view */ |
|
148 | + $view = $viewCallBack($server); |
|
149 | + if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) { |
|
150 | + $rootInfo = $userFolder; |
|
151 | + } else { |
|
152 | + $rootInfo = $view->getFileInfo(''); |
|
153 | + } |
|
154 | 154 | |
155 | - // Create Nextcloud Dir |
|
156 | - if ($rootInfo->getType() === 'dir') { |
|
157 | - $root = new \OCA\DAV\Connector\Sabre\Directory($view, $rootInfo, $objectTree); |
|
158 | - } else { |
|
159 | - $root = new \OCA\DAV\Connector\Sabre\File($view, $rootInfo); |
|
160 | - } |
|
161 | - $objectTree->init($root, $view, $this->mountManager); |
|
155 | + // Create Nextcloud Dir |
|
156 | + if ($rootInfo->getType() === 'dir') { |
|
157 | + $root = new \OCA\DAV\Connector\Sabre\Directory($view, $rootInfo, $objectTree); |
|
158 | + } else { |
|
159 | + $root = new \OCA\DAV\Connector\Sabre\File($view, $rootInfo); |
|
160 | + } |
|
161 | + $objectTree->init($root, $view, $this->mountManager); |
|
162 | 162 | |
163 | - $server->addPlugin( |
|
164 | - new \OCA\DAV\Connector\Sabre\FilesPlugin( |
|
165 | - $objectTree, |
|
166 | - $this->config, |
|
167 | - $this->request, |
|
168 | - $this->previewManager, |
|
169 | - false, |
|
170 | - !$this->config->getSystemValue('debug', false) |
|
171 | - ) |
|
172 | - ); |
|
173 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view, true)); |
|
163 | + $server->addPlugin( |
|
164 | + new \OCA\DAV\Connector\Sabre\FilesPlugin( |
|
165 | + $objectTree, |
|
166 | + $this->config, |
|
167 | + $this->request, |
|
168 | + $this->previewManager, |
|
169 | + false, |
|
170 | + !$this->config->getSystemValue('debug', false) |
|
171 | + ) |
|
172 | + ); |
|
173 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view, true)); |
|
174 | 174 | |
175 | - if($this->userSession->isLoggedIn()) { |
|
176 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager)); |
|
177 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin( |
|
178 | - $objectTree, |
|
179 | - $this->userSession, |
|
180 | - $userFolder, |
|
181 | - \OC::$server->getShareManager() |
|
182 | - )); |
|
183 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\CommentPropertiesPlugin(\OC::$server->getCommentsManager(), $this->userSession)); |
|
184 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesReportPlugin( |
|
185 | - $objectTree, |
|
186 | - $view, |
|
187 | - \OC::$server->getSystemTagManager(), |
|
188 | - \OC::$server->getSystemTagObjectMapper(), |
|
189 | - \OC::$server->getTagManager(), |
|
190 | - $this->userSession, |
|
191 | - \OC::$server->getGroupManager(), |
|
192 | - $userFolder, |
|
193 | - \OC::$server->getAppManager() |
|
194 | - )); |
|
195 | - // custom properties plugin must be the last one |
|
196 | - $server->addPlugin( |
|
197 | - new \Sabre\DAV\PropertyStorage\Plugin( |
|
198 | - new \OCA\DAV\DAV\CustomPropertiesBackend( |
|
199 | - $objectTree, |
|
200 | - $this->databaseConnection, |
|
201 | - $this->userSession->getUser() |
|
202 | - ) |
|
203 | - ) |
|
204 | - ); |
|
205 | - } |
|
206 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin()); |
|
175 | + if($this->userSession->isLoggedIn()) { |
|
176 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager)); |
|
177 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin( |
|
178 | + $objectTree, |
|
179 | + $this->userSession, |
|
180 | + $userFolder, |
|
181 | + \OC::$server->getShareManager() |
|
182 | + )); |
|
183 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\CommentPropertiesPlugin(\OC::$server->getCommentsManager(), $this->userSession)); |
|
184 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesReportPlugin( |
|
185 | + $objectTree, |
|
186 | + $view, |
|
187 | + \OC::$server->getSystemTagManager(), |
|
188 | + \OC::$server->getSystemTagObjectMapper(), |
|
189 | + \OC::$server->getTagManager(), |
|
190 | + $this->userSession, |
|
191 | + \OC::$server->getGroupManager(), |
|
192 | + $userFolder, |
|
193 | + \OC::$server->getAppManager() |
|
194 | + )); |
|
195 | + // custom properties plugin must be the last one |
|
196 | + $server->addPlugin( |
|
197 | + new \Sabre\DAV\PropertyStorage\Plugin( |
|
198 | + new \OCA\DAV\DAV\CustomPropertiesBackend( |
|
199 | + $objectTree, |
|
200 | + $this->databaseConnection, |
|
201 | + $this->userSession->getUser() |
|
202 | + ) |
|
203 | + ) |
|
204 | + ); |
|
205 | + } |
|
206 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin()); |
|
207 | 207 | |
208 | - // Load dav plugins from apps |
|
209 | - $event = new SabrePluginEvent($server); |
|
210 | - $this->eventDispatcher->dispatch($event); |
|
211 | - $pluginManager = new PluginManager( |
|
212 | - \OC::$server, |
|
213 | - \OC::$server->getAppManager() |
|
214 | - ); |
|
215 | - foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
216 | - $server->addPlugin($appPlugin); |
|
217 | - } |
|
208 | + // Load dav plugins from apps |
|
209 | + $event = new SabrePluginEvent($server); |
|
210 | + $this->eventDispatcher->dispatch($event); |
|
211 | + $pluginManager = new PluginManager( |
|
212 | + \OC::$server, |
|
213 | + \OC::$server->getAppManager() |
|
214 | + ); |
|
215 | + foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
216 | + $server->addPlugin($appPlugin); |
|
217 | + } |
|
218 | 218 | |
219 | - }, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request |
|
220 | - return $server; |
|
221 | - } |
|
219 | + }, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request |
|
220 | + return $server; |
|
221 | + } |
|
222 | 222 | } |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | $server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
128 | 128 | // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
129 | 129 | // we do not provide locking we emulate it using a fake locking plugin. |
130 | - if($this->request->isUserAgent([ |
|
130 | + if ($this->request->isUserAgent([ |
|
131 | 131 | '/WebDAVFS/', |
132 | 132 | '/OneNote/', |
133 | 133 | '/Microsoft-WebDAV-MiniRedir/', |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | } |
141 | 141 | |
142 | 142 | // wait with registering these until auth is handled and the filesystem is setup |
143 | - $server->on('beforeMethod:*', function () use ($server, $objectTree, $viewCallBack) { |
|
143 | + $server->on('beforeMethod:*', function() use ($server, $objectTree, $viewCallBack) { |
|
144 | 144 | // ensure the skeleton is copied |
145 | 145 | $userFolder = \OC::$server->getUserFolder(); |
146 | 146 | |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | ); |
173 | 173 | $server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view, true)); |
174 | 174 | |
175 | - if($this->userSession->isLoggedIn()) { |
|
175 | + if ($this->userSession->isLoggedIn()) { |
|
176 | 176 | $server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager)); |
177 | 177 | $server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin( |
178 | 178 | $objectTree, |
@@ -34,58 +34,58 @@ |
||
34 | 34 | */ |
35 | 35 | class AppEnabledPlugin extends ServerPlugin { |
36 | 36 | |
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 | - * @var string |
|
46 | - */ |
|
47 | - private $app; |
|
44 | + /** |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + private $app; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @var \OCP\App\IAppManager |
|
51 | - */ |
|
52 | - private $appManager; |
|
49 | + /** |
|
50 | + * @var \OCP\App\IAppManager |
|
51 | + */ |
|
52 | + private $appManager; |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param string $app |
|
56 | - * @param \OCP\App\IAppManager $appManager |
|
57 | - */ |
|
58 | - public function __construct($app, IAppManager $appManager) { |
|
59 | - $this->app = $app; |
|
60 | - $this->appManager = $appManager; |
|
61 | - } |
|
54 | + /** |
|
55 | + * @param string $app |
|
56 | + * @param \OCP\App\IAppManager $appManager |
|
57 | + */ |
|
58 | + public function __construct($app, IAppManager $appManager) { |
|
59 | + $this->app = $app; |
|
60 | + $this->appManager = $appManager; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * This initializes the plugin. |
|
65 | - * |
|
66 | - * This function is called by \Sabre\DAV\Server, after |
|
67 | - * addPlugin is called. |
|
68 | - * |
|
69 | - * This method should set up the required event subscriptions. |
|
70 | - * |
|
71 | - * @param \Sabre\DAV\Server $server |
|
72 | - * @return void |
|
73 | - */ |
|
74 | - public function initialize(\Sabre\DAV\Server $server) { |
|
63 | + /** |
|
64 | + * This initializes the plugin. |
|
65 | + * |
|
66 | + * This function is called by \Sabre\DAV\Server, after |
|
67 | + * addPlugin is called. |
|
68 | + * |
|
69 | + * This method should set up the required event subscriptions. |
|
70 | + * |
|
71 | + * @param \Sabre\DAV\Server $server |
|
72 | + * @return void |
|
73 | + */ |
|
74 | + public function initialize(\Sabre\DAV\Server $server) { |
|
75 | 75 | |
76 | - $this->server = $server; |
|
77 | - $this->server->on('beforeMethod:*', [$this, 'checkAppEnabled'], 30); |
|
78 | - } |
|
76 | + $this->server = $server; |
|
77 | + $this->server->on('beforeMethod:*', [$this, 'checkAppEnabled'], 30); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * This method is called before any HTTP after auth and checks if the user has access to the app |
|
82 | - * |
|
83 | - * @throws \Sabre\DAV\Exception\Forbidden |
|
84 | - * @return bool |
|
85 | - */ |
|
86 | - public function checkAppEnabled() { |
|
87 | - if (!$this->appManager->isEnabledForUser($this->app)) { |
|
88 | - throw new Forbidden(); |
|
89 | - } |
|
90 | - } |
|
80 | + /** |
|
81 | + * This method is called before any HTTP after auth and checks if the user has access to the app |
|
82 | + * |
|
83 | + * @throws \Sabre\DAV\Exception\Forbidden |
|
84 | + * @return bool |
|
85 | + */ |
|
86 | + public function checkAppEnabled() { |
|
87 | + if (!$this->appManager->isEnabledForUser($this->app)) { |
|
88 | + throw new Forbidden(); |
|
89 | + } |
|
90 | + } |
|
91 | 91 | } |
@@ -33,53 +33,53 @@ |
||
33 | 33 | use Sabre\HTTP\RequestInterface; |
34 | 34 | |
35 | 35 | class LockPlugin extends ServerPlugin { |
36 | - /** |
|
37 | - * Reference to main server object |
|
38 | - * |
|
39 | - * @var \Sabre\DAV\Server |
|
40 | - */ |
|
41 | - private $server; |
|
36 | + /** |
|
37 | + * Reference to main server object |
|
38 | + * |
|
39 | + * @var \Sabre\DAV\Server |
|
40 | + */ |
|
41 | + private $server; |
|
42 | 42 | |
43 | - /** |
|
44 | - * {@inheritdoc} |
|
45 | - */ |
|
46 | - public function initialize(\Sabre\DAV\Server $server) { |
|
47 | - $this->server = $server; |
|
48 | - $this->server->on('beforeMethod:*', [$this, 'getLock'], 50); |
|
49 | - $this->server->on('afterMethod', [$this, 'releaseLock'], 50); |
|
50 | - } |
|
43 | + /** |
|
44 | + * {@inheritdoc} |
|
45 | + */ |
|
46 | + public function initialize(\Sabre\DAV\Server $server) { |
|
47 | + $this->server = $server; |
|
48 | + $this->server->on('beforeMethod:*', [$this, 'getLock'], 50); |
|
49 | + $this->server->on('afterMethod', [$this, 'releaseLock'], 50); |
|
50 | + } |
|
51 | 51 | |
52 | - public function getLock(RequestInterface $request) { |
|
53 | - // we can't listen on 'beforeMethod:PUT' due to order of operations with setting up the tree |
|
54 | - // so instead we limit ourselves to the PUT method manually |
|
55 | - if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
56 | - return; |
|
57 | - } |
|
58 | - try { |
|
59 | - $node = $this->server->tree->getNodeForPath($request->getPath()); |
|
60 | - } catch (NotFound $e) { |
|
61 | - return; |
|
62 | - } |
|
63 | - if ($node instanceof Node) { |
|
64 | - try { |
|
65 | - $node->acquireLock(ILockingProvider::LOCK_SHARED); |
|
66 | - } catch (LockedException $e) { |
|
67 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
68 | - } |
|
69 | - } |
|
70 | - } |
|
52 | + public function getLock(RequestInterface $request) { |
|
53 | + // we can't listen on 'beforeMethod:PUT' due to order of operations with setting up the tree |
|
54 | + // so instead we limit ourselves to the PUT method manually |
|
55 | + if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
56 | + return; |
|
57 | + } |
|
58 | + try { |
|
59 | + $node = $this->server->tree->getNodeForPath($request->getPath()); |
|
60 | + } catch (NotFound $e) { |
|
61 | + return; |
|
62 | + } |
|
63 | + if ($node instanceof Node) { |
|
64 | + try { |
|
65 | + $node->acquireLock(ILockingProvider::LOCK_SHARED); |
|
66 | + } catch (LockedException $e) { |
|
67 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
68 | + } |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | - public function releaseLock(RequestInterface $request) { |
|
73 | - if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
74 | - return; |
|
75 | - } |
|
76 | - try { |
|
77 | - $node = $this->server->tree->getNodeForPath($request->getPath()); |
|
78 | - } catch (NotFound $e) { |
|
79 | - return; |
|
80 | - } |
|
81 | - if ($node instanceof Node) { |
|
82 | - $node->releaseLock(ILockingProvider::LOCK_SHARED); |
|
83 | - } |
|
84 | - } |
|
72 | + public function releaseLock(RequestInterface $request) { |
|
73 | + if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
74 | + return; |
|
75 | + } |
|
76 | + try { |
|
77 | + $node = $this->server->tree->getNodeForPath($request->getPath()); |
|
78 | + } catch (NotFound $e) { |
|
79 | + return; |
|
80 | + } |
|
81 | + if ($node instanceof Node) { |
|
82 | + $node->releaseLock(ILockingProvider::LOCK_SHARED); |
|
83 | + } |
|
84 | + } |
|
85 | 85 | } |