@@ -177,7 +177,7 @@ |
||
177 | 177 | && $status !== Http::STATUS_FORBIDDEN |
178 | 178 | ) { |
179 | 179 | $this->retainJob = true; |
180 | - } else { |
|
180 | + } else { |
|
181 | 181 | // reset token if we received a valid response |
182 | 182 | $this->dbHandler->addToken($target, ''); |
183 | 183 | } |
@@ -50,199 +50,199 @@ |
||
50 | 50 | */ |
51 | 51 | class GetSharedSecret extends Job { |
52 | 52 | |
53 | - /** @var IClient */ |
|
54 | - private $httpClient; |
|
55 | - |
|
56 | - /** @var IJobList */ |
|
57 | - private $jobList; |
|
58 | - |
|
59 | - /** @var IURLGenerator */ |
|
60 | - private $urlGenerator; |
|
61 | - |
|
62 | - /** @var TrustedServers */ |
|
63 | - private $trustedServers; |
|
64 | - |
|
65 | - /** @var DbHandler */ |
|
66 | - private $dbHandler; |
|
67 | - |
|
68 | - /** @var IDiscoveryService */ |
|
69 | - private $ocsDiscoveryService; |
|
70 | - |
|
71 | - /** @var ILogger */ |
|
72 | - private $logger; |
|
73 | - |
|
74 | - /** @var ITimeFactory */ |
|
75 | - private $timeFactory; |
|
76 | - |
|
77 | - /** @var bool */ |
|
78 | - protected $retainJob = false; |
|
79 | - |
|
80 | - private $format = '?format=json'; |
|
81 | - |
|
82 | - private $defaultEndPoint = '/ocs/v2.php/apps/federation/api/v1/shared-secret'; |
|
83 | - |
|
84 | - /** @var int 30 day = 2592000sec */ |
|
85 | - private $maxLifespan = 2592000; |
|
86 | - |
|
87 | - /** |
|
88 | - * RequestSharedSecret constructor. |
|
89 | - * |
|
90 | - * @param IClientService $httpClientService |
|
91 | - * @param IURLGenerator $urlGenerator |
|
92 | - * @param IJobList $jobList |
|
93 | - * @param TrustedServers $trustedServers |
|
94 | - * @param ILogger $logger |
|
95 | - * @param DbHandler $dbHandler |
|
96 | - * @param IDiscoveryService $ocsDiscoveryService |
|
97 | - * @param ITimeFactory $timeFactory |
|
98 | - */ |
|
99 | - public function __construct( |
|
100 | - IClientService $httpClientService, |
|
101 | - IURLGenerator $urlGenerator, |
|
102 | - IJobList $jobList, |
|
103 | - TrustedServers $trustedServers, |
|
104 | - ILogger $logger, |
|
105 | - DbHandler $dbHandler, |
|
106 | - IDiscoveryService $ocsDiscoveryService, |
|
107 | - ITimeFactory $timeFactory |
|
108 | - ) { |
|
109 | - $this->logger = $logger; |
|
110 | - $this->httpClient = $httpClientService->newClient(); |
|
111 | - $this->jobList = $jobList; |
|
112 | - $this->urlGenerator = $urlGenerator; |
|
113 | - $this->dbHandler = $dbHandler; |
|
114 | - $this->ocsDiscoveryService = $ocsDiscoveryService; |
|
115 | - $this->trustedServers = $trustedServers; |
|
116 | - $this->timeFactory = $timeFactory; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * run the job, then remove it from the joblist |
|
121 | - * |
|
122 | - * @param JobList $jobList |
|
123 | - * @param ILogger|null $logger |
|
124 | - */ |
|
125 | - public function execute($jobList, ILogger $logger = null) { |
|
126 | - $target = $this->argument['url']; |
|
127 | - // only execute if target is still in the list of trusted domains |
|
128 | - if ($this->trustedServers->isTrustedServer($target)) { |
|
129 | - $this->parentExecute($jobList, $logger); |
|
130 | - } |
|
131 | - |
|
132 | - $jobList->remove($this, $this->argument); |
|
133 | - |
|
134 | - if ($this->retainJob) { |
|
135 | - $this->reAddJob($this->argument); |
|
136 | - } |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * call execute() method of parent |
|
141 | - * |
|
142 | - * @param JobList $jobList |
|
143 | - * @param ILogger $logger |
|
144 | - */ |
|
145 | - protected function parentExecute($jobList, $logger = null) { |
|
146 | - parent::execute($jobList, $logger); |
|
147 | - } |
|
148 | - |
|
149 | - protected function run($argument) { |
|
150 | - $target = $argument['url']; |
|
151 | - $created = isset($argument['created']) ? (int)$argument['created'] : $this->timeFactory->getTime(); |
|
152 | - $currentTime = $this->timeFactory->getTime(); |
|
153 | - $source = $this->urlGenerator->getAbsoluteURL('/'); |
|
154 | - $source = rtrim($source, '/'); |
|
155 | - $token = $argument['token']; |
|
156 | - |
|
157 | - // kill job after 30 days of trying |
|
158 | - $deadline = $currentTime - $this->maxLifespan; |
|
159 | - if ($created < $deadline) { |
|
160 | - $this->retainJob = false; |
|
161 | - $this->trustedServers->setServerStatus($target,TrustedServers::STATUS_FAILURE); |
|
162 | - return; |
|
163 | - } |
|
164 | - |
|
165 | - $endPoints = $this->ocsDiscoveryService->discover($target, 'FEDERATED_SHARING'); |
|
166 | - $endPoint = isset($endPoints['shared-secret']) ? $endPoints['shared-secret'] : $this->defaultEndPoint; |
|
167 | - |
|
168 | - // make sure that we have a well formatted url |
|
169 | - $url = rtrim($target, '/') . '/' . trim($endPoint, '/') . $this->format; |
|
170 | - |
|
171 | - $result = null; |
|
172 | - try { |
|
173 | - $result = $this->httpClient->get( |
|
174 | - $url, |
|
175 | - [ |
|
176 | - 'query' => |
|
177 | - [ |
|
178 | - 'url' => $source, |
|
179 | - 'token' => $token |
|
180 | - ], |
|
181 | - 'timeout' => 3, |
|
182 | - 'connect_timeout' => 3, |
|
183 | - ] |
|
184 | - ); |
|
185 | - |
|
186 | - $status = $result->getStatusCode(); |
|
187 | - |
|
188 | - } catch (ClientException $e) { |
|
189 | - $status = $e->getCode(); |
|
190 | - if ($status === Http::STATUS_FORBIDDEN) { |
|
191 | - $this->logger->info($target . ' refused to exchange a shared secret with you.', ['app' => 'federation']); |
|
192 | - } else { |
|
193 | - $this->logger->info($target . ' responded with a ' . $status . ' containing: ' . $e->getMessage(), ['app' => 'federation']); |
|
194 | - } |
|
195 | - } catch (\Exception $e) { |
|
196 | - $status = Http::STATUS_INTERNAL_SERVER_ERROR; |
|
197 | - $this->logger->logException($e, ['app' => 'federation']); |
|
198 | - } |
|
199 | - |
|
200 | - // if we received a unexpected response we try again later |
|
201 | - if ( |
|
202 | - $status !== Http::STATUS_OK |
|
203 | - && $status !== Http::STATUS_FORBIDDEN |
|
204 | - ) { |
|
205 | - $this->retainJob = true; |
|
206 | - } else { |
|
207 | - // reset token if we received a valid response |
|
208 | - $this->dbHandler->addToken($target, ''); |
|
209 | - } |
|
210 | - |
|
211 | - if ($status === Http::STATUS_OK && $result instanceof IResponse) { |
|
212 | - $body = $result->getBody(); |
|
213 | - $result = json_decode($body, true); |
|
214 | - if (isset($result['ocs']['data']['sharedSecret'])) { |
|
215 | - $this->trustedServers->addSharedSecret( |
|
216 | - $target, |
|
217 | - $result['ocs']['data']['sharedSecret'] |
|
218 | - ); |
|
219 | - } else { |
|
220 | - $this->logger->error( |
|
221 | - 'remote server "' . $target . '"" does not return a valid shared secret', |
|
222 | - ['app' => 'federation'] |
|
223 | - ); |
|
224 | - $this->trustedServers->setServerStatus($target, TrustedServers::STATUS_FAILURE); |
|
225 | - } |
|
226 | - } |
|
227 | - |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * re-add background job |
|
232 | - * |
|
233 | - * @param array $argument |
|
234 | - */ |
|
235 | - protected function reAddJob(array $argument) { |
|
236 | - $url = $argument['url']; |
|
237 | - $created = isset($argument['created']) ? (int)$argument['created'] : $this->timeFactory->getTime(); |
|
238 | - $token = $argument['token']; |
|
239 | - $this->jobList->add( |
|
240 | - GetSharedSecret::class, |
|
241 | - [ |
|
242 | - 'url' => $url, |
|
243 | - 'token' => $token, |
|
244 | - 'created' => $created |
|
245 | - ] |
|
246 | - ); |
|
247 | - } |
|
53 | + /** @var IClient */ |
|
54 | + private $httpClient; |
|
55 | + |
|
56 | + /** @var IJobList */ |
|
57 | + private $jobList; |
|
58 | + |
|
59 | + /** @var IURLGenerator */ |
|
60 | + private $urlGenerator; |
|
61 | + |
|
62 | + /** @var TrustedServers */ |
|
63 | + private $trustedServers; |
|
64 | + |
|
65 | + /** @var DbHandler */ |
|
66 | + private $dbHandler; |
|
67 | + |
|
68 | + /** @var IDiscoveryService */ |
|
69 | + private $ocsDiscoveryService; |
|
70 | + |
|
71 | + /** @var ILogger */ |
|
72 | + private $logger; |
|
73 | + |
|
74 | + /** @var ITimeFactory */ |
|
75 | + private $timeFactory; |
|
76 | + |
|
77 | + /** @var bool */ |
|
78 | + protected $retainJob = false; |
|
79 | + |
|
80 | + private $format = '?format=json'; |
|
81 | + |
|
82 | + private $defaultEndPoint = '/ocs/v2.php/apps/federation/api/v1/shared-secret'; |
|
83 | + |
|
84 | + /** @var int 30 day = 2592000sec */ |
|
85 | + private $maxLifespan = 2592000; |
|
86 | + |
|
87 | + /** |
|
88 | + * RequestSharedSecret constructor. |
|
89 | + * |
|
90 | + * @param IClientService $httpClientService |
|
91 | + * @param IURLGenerator $urlGenerator |
|
92 | + * @param IJobList $jobList |
|
93 | + * @param TrustedServers $trustedServers |
|
94 | + * @param ILogger $logger |
|
95 | + * @param DbHandler $dbHandler |
|
96 | + * @param IDiscoveryService $ocsDiscoveryService |
|
97 | + * @param ITimeFactory $timeFactory |
|
98 | + */ |
|
99 | + public function __construct( |
|
100 | + IClientService $httpClientService, |
|
101 | + IURLGenerator $urlGenerator, |
|
102 | + IJobList $jobList, |
|
103 | + TrustedServers $trustedServers, |
|
104 | + ILogger $logger, |
|
105 | + DbHandler $dbHandler, |
|
106 | + IDiscoveryService $ocsDiscoveryService, |
|
107 | + ITimeFactory $timeFactory |
|
108 | + ) { |
|
109 | + $this->logger = $logger; |
|
110 | + $this->httpClient = $httpClientService->newClient(); |
|
111 | + $this->jobList = $jobList; |
|
112 | + $this->urlGenerator = $urlGenerator; |
|
113 | + $this->dbHandler = $dbHandler; |
|
114 | + $this->ocsDiscoveryService = $ocsDiscoveryService; |
|
115 | + $this->trustedServers = $trustedServers; |
|
116 | + $this->timeFactory = $timeFactory; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * run the job, then remove it from the joblist |
|
121 | + * |
|
122 | + * @param JobList $jobList |
|
123 | + * @param ILogger|null $logger |
|
124 | + */ |
|
125 | + public function execute($jobList, ILogger $logger = null) { |
|
126 | + $target = $this->argument['url']; |
|
127 | + // only execute if target is still in the list of trusted domains |
|
128 | + if ($this->trustedServers->isTrustedServer($target)) { |
|
129 | + $this->parentExecute($jobList, $logger); |
|
130 | + } |
|
131 | + |
|
132 | + $jobList->remove($this, $this->argument); |
|
133 | + |
|
134 | + if ($this->retainJob) { |
|
135 | + $this->reAddJob($this->argument); |
|
136 | + } |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * call execute() method of parent |
|
141 | + * |
|
142 | + * @param JobList $jobList |
|
143 | + * @param ILogger $logger |
|
144 | + */ |
|
145 | + protected function parentExecute($jobList, $logger = null) { |
|
146 | + parent::execute($jobList, $logger); |
|
147 | + } |
|
148 | + |
|
149 | + protected function run($argument) { |
|
150 | + $target = $argument['url']; |
|
151 | + $created = isset($argument['created']) ? (int)$argument['created'] : $this->timeFactory->getTime(); |
|
152 | + $currentTime = $this->timeFactory->getTime(); |
|
153 | + $source = $this->urlGenerator->getAbsoluteURL('/'); |
|
154 | + $source = rtrim($source, '/'); |
|
155 | + $token = $argument['token']; |
|
156 | + |
|
157 | + // kill job after 30 days of trying |
|
158 | + $deadline = $currentTime - $this->maxLifespan; |
|
159 | + if ($created < $deadline) { |
|
160 | + $this->retainJob = false; |
|
161 | + $this->trustedServers->setServerStatus($target,TrustedServers::STATUS_FAILURE); |
|
162 | + return; |
|
163 | + } |
|
164 | + |
|
165 | + $endPoints = $this->ocsDiscoveryService->discover($target, 'FEDERATED_SHARING'); |
|
166 | + $endPoint = isset($endPoints['shared-secret']) ? $endPoints['shared-secret'] : $this->defaultEndPoint; |
|
167 | + |
|
168 | + // make sure that we have a well formatted url |
|
169 | + $url = rtrim($target, '/') . '/' . trim($endPoint, '/') . $this->format; |
|
170 | + |
|
171 | + $result = null; |
|
172 | + try { |
|
173 | + $result = $this->httpClient->get( |
|
174 | + $url, |
|
175 | + [ |
|
176 | + 'query' => |
|
177 | + [ |
|
178 | + 'url' => $source, |
|
179 | + 'token' => $token |
|
180 | + ], |
|
181 | + 'timeout' => 3, |
|
182 | + 'connect_timeout' => 3, |
|
183 | + ] |
|
184 | + ); |
|
185 | + |
|
186 | + $status = $result->getStatusCode(); |
|
187 | + |
|
188 | + } catch (ClientException $e) { |
|
189 | + $status = $e->getCode(); |
|
190 | + if ($status === Http::STATUS_FORBIDDEN) { |
|
191 | + $this->logger->info($target . ' refused to exchange a shared secret with you.', ['app' => 'federation']); |
|
192 | + } else { |
|
193 | + $this->logger->info($target . ' responded with a ' . $status . ' containing: ' . $e->getMessage(), ['app' => 'federation']); |
|
194 | + } |
|
195 | + } catch (\Exception $e) { |
|
196 | + $status = Http::STATUS_INTERNAL_SERVER_ERROR; |
|
197 | + $this->logger->logException($e, ['app' => 'federation']); |
|
198 | + } |
|
199 | + |
|
200 | + // if we received a unexpected response we try again later |
|
201 | + if ( |
|
202 | + $status !== Http::STATUS_OK |
|
203 | + && $status !== Http::STATUS_FORBIDDEN |
|
204 | + ) { |
|
205 | + $this->retainJob = true; |
|
206 | + } else { |
|
207 | + // reset token if we received a valid response |
|
208 | + $this->dbHandler->addToken($target, ''); |
|
209 | + } |
|
210 | + |
|
211 | + if ($status === Http::STATUS_OK && $result instanceof IResponse) { |
|
212 | + $body = $result->getBody(); |
|
213 | + $result = json_decode($body, true); |
|
214 | + if (isset($result['ocs']['data']['sharedSecret'])) { |
|
215 | + $this->trustedServers->addSharedSecret( |
|
216 | + $target, |
|
217 | + $result['ocs']['data']['sharedSecret'] |
|
218 | + ); |
|
219 | + } else { |
|
220 | + $this->logger->error( |
|
221 | + 'remote server "' . $target . '"" does not return a valid shared secret', |
|
222 | + ['app' => 'federation'] |
|
223 | + ); |
|
224 | + $this->trustedServers->setServerStatus($target, TrustedServers::STATUS_FAILURE); |
|
225 | + } |
|
226 | + } |
|
227 | + |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * re-add background job |
|
232 | + * |
|
233 | + * @param array $argument |
|
234 | + */ |
|
235 | + protected function reAddJob(array $argument) { |
|
236 | + $url = $argument['url']; |
|
237 | + $created = isset($argument['created']) ? (int)$argument['created'] : $this->timeFactory->getTime(); |
|
238 | + $token = $argument['token']; |
|
239 | + $this->jobList->add( |
|
240 | + GetSharedSecret::class, |
|
241 | + [ |
|
242 | + 'url' => $url, |
|
243 | + 'token' => $token, |
|
244 | + 'created' => $created |
|
245 | + ] |
|
246 | + ); |
|
247 | + } |
|
248 | 248 | } |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | |
149 | 149 | protected function run($argument) { |
150 | 150 | $target = $argument['url']; |
151 | - $created = isset($argument['created']) ? (int)$argument['created'] : $this->timeFactory->getTime(); |
|
151 | + $created = isset($argument['created']) ? (int) $argument['created'] : $this->timeFactory->getTime(); |
|
152 | 152 | $currentTime = $this->timeFactory->getTime(); |
153 | 153 | $source = $this->urlGenerator->getAbsoluteURL('/'); |
154 | 154 | $source = rtrim($source, '/'); |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | $deadline = $currentTime - $this->maxLifespan; |
159 | 159 | if ($created < $deadline) { |
160 | 160 | $this->retainJob = false; |
161 | - $this->trustedServers->setServerStatus($target,TrustedServers::STATUS_FAILURE); |
|
161 | + $this->trustedServers->setServerStatus($target, TrustedServers::STATUS_FAILURE); |
|
162 | 162 | return; |
163 | 163 | } |
164 | 164 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | $endPoint = isset($endPoints['shared-secret']) ? $endPoints['shared-secret'] : $this->defaultEndPoint; |
167 | 167 | |
168 | 168 | // make sure that we have a well formatted url |
169 | - $url = rtrim($target, '/') . '/' . trim($endPoint, '/') . $this->format; |
|
169 | + $url = rtrim($target, '/').'/'.trim($endPoint, '/').$this->format; |
|
170 | 170 | |
171 | 171 | $result = null; |
172 | 172 | try { |
@@ -188,9 +188,9 @@ discard block |
||
188 | 188 | } catch (ClientException $e) { |
189 | 189 | $status = $e->getCode(); |
190 | 190 | if ($status === Http::STATUS_FORBIDDEN) { |
191 | - $this->logger->info($target . ' refused to exchange a shared secret with you.', ['app' => 'federation']); |
|
191 | + $this->logger->info($target.' refused to exchange a shared secret with you.', ['app' => 'federation']); |
|
192 | 192 | } else { |
193 | - $this->logger->info($target . ' responded with a ' . $status . ' containing: ' . $e->getMessage(), ['app' => 'federation']); |
|
193 | + $this->logger->info($target.' responded with a '.$status.' containing: '.$e->getMessage(), ['app' => 'federation']); |
|
194 | 194 | } |
195 | 195 | } catch (\Exception $e) { |
196 | 196 | $status = Http::STATUS_INTERNAL_SERVER_ERROR; |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | && $status !== Http::STATUS_FORBIDDEN |
204 | 204 | ) { |
205 | 205 | $this->retainJob = true; |
206 | - } else { |
|
206 | + } else { |
|
207 | 207 | // reset token if we received a valid response |
208 | 208 | $this->dbHandler->addToken($target, ''); |
209 | 209 | } |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | ); |
219 | 219 | } else { |
220 | 220 | $this->logger->error( |
221 | - 'remote server "' . $target . '"" does not return a valid shared secret', |
|
221 | + 'remote server "'.$target.'"" does not return a valid shared secret', |
|
222 | 222 | ['app' => 'federation'] |
223 | 223 | ); |
224 | 224 | $this->trustedServers->setServerStatus($target, TrustedServers::STATUS_FAILURE); |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | */ |
235 | 235 | protected function reAddJob(array $argument) { |
236 | 236 | $url = $argument['url']; |
237 | - $created = isset($argument['created']) ? (int)$argument['created'] : $this->timeFactory->getTime(); |
|
237 | + $created = isset($argument['created']) ? (int) $argument['created'] : $this->timeFactory->getTime(); |
|
238 | 238 | $token = $argument['token']; |
239 | 239 | $this->jobList->add( |
240 | 240 | GetSharedSecret::class, |
@@ -29,41 +29,41 @@ |
||
29 | 29 | |
30 | 30 | class Admin implements ISettings { |
31 | 31 | |
32 | - /** @var TrustedServers */ |
|
33 | - private $trustedServers; |
|
32 | + /** @var TrustedServers */ |
|
33 | + private $trustedServers; |
|
34 | 34 | |
35 | - public function __construct(TrustedServers $trustedServers) { |
|
36 | - $this->trustedServers = $trustedServers; |
|
37 | - } |
|
35 | + public function __construct(TrustedServers $trustedServers) { |
|
36 | + $this->trustedServers = $trustedServers; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return TemplateResponse |
|
41 | - */ |
|
42 | - public function getForm() { |
|
43 | - $parameters = [ |
|
44 | - 'trustedServers' => $this->trustedServers->getServers(), |
|
45 | - 'autoAddServers' => $this->trustedServers->getAutoAddServers(), |
|
46 | - ]; |
|
39 | + /** |
|
40 | + * @return TemplateResponse |
|
41 | + */ |
|
42 | + public function getForm() { |
|
43 | + $parameters = [ |
|
44 | + 'trustedServers' => $this->trustedServers->getServers(), |
|
45 | + 'autoAddServers' => $this->trustedServers->getAutoAddServers(), |
|
46 | + ]; |
|
47 | 47 | |
48 | - return new TemplateResponse('federation', 'settings-admin', $parameters, ''); |
|
49 | - } |
|
48 | + return new TemplateResponse('federation', 'settings-admin', $parameters, ''); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return string the section ID, e.g. 'sharing' |
|
53 | - */ |
|
54 | - public function getSection() { |
|
55 | - return 'sharing'; |
|
56 | - } |
|
51 | + /** |
|
52 | + * @return string the section ID, e.g. 'sharing' |
|
53 | + */ |
|
54 | + public function getSection() { |
|
55 | + return 'sharing'; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return int whether the form should be rather on the top or bottom of |
|
60 | - * the admin section. The forms are arranged in ascending order of the |
|
61 | - * priority values. It is required to return a value between 0 and 100. |
|
62 | - * |
|
63 | - * E.g.: 70 |
|
64 | - */ |
|
65 | - public function getPriority() { |
|
66 | - return 30; |
|
67 | - } |
|
58 | + /** |
|
59 | + * @return int whether the form should be rather on the top or bottom of |
|
60 | + * the admin section. The forms are arranged in ascending order of the |
|
61 | + * priority values. It is required to return a value between 0 and 100. |
|
62 | + * |
|
63 | + * E.g.: 70 |
|
64 | + */ |
|
65 | + public function getPriority() { |
|
66 | + return 30; |
|
67 | + } |
|
68 | 68 | |
69 | 69 | } |
@@ -27,25 +27,25 @@ |
||
27 | 27 | |
28 | 28 | class Hooks { |
29 | 29 | |
30 | - /** @var TrustedServers */ |
|
31 | - private $trustedServers; |
|
32 | - |
|
33 | - public function __construct(TrustedServers $trustedServers) { |
|
34 | - $this->trustedServers = $trustedServers; |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * add servers to the list of trusted servers once a federated share was established |
|
39 | - * |
|
40 | - * @param array $params |
|
41 | - */ |
|
42 | - public function addServerHook($params) { |
|
43 | - if ( |
|
44 | - $this->trustedServers->getAutoAddServers() === true && |
|
45 | - $this->trustedServers->isTrustedServer($params['server']) === false |
|
46 | - ) { |
|
47 | - $this->trustedServers->addServer($params['server']); |
|
48 | - } |
|
49 | - } |
|
30 | + /** @var TrustedServers */ |
|
31 | + private $trustedServers; |
|
32 | + |
|
33 | + public function __construct(TrustedServers $trustedServers) { |
|
34 | + $this->trustedServers = $trustedServers; |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * add servers to the list of trusted servers once a federated share was established |
|
39 | + * |
|
40 | + * @param array $params |
|
41 | + */ |
|
42 | + public function addServerHook($params) { |
|
43 | + if ( |
|
44 | + $this->trustedServers->getAutoAddServers() === true && |
|
45 | + $this->trustedServers->isTrustedServer($params['server']) === false |
|
46 | + ) { |
|
47 | + $this->trustedServers->addServer($params['server']); |
|
48 | + } |
|
49 | + } |
|
50 | 50 | |
51 | 51 | } |
@@ -26,67 +26,67 @@ |
||
26 | 26 | |
27 | 27 | class PublicAuth implements BackendInterface { |
28 | 28 | |
29 | - /** @var string[] */ |
|
30 | - private $publicURLs; |
|
29 | + /** @var string[] */ |
|
30 | + private $publicURLs; |
|
31 | 31 | |
32 | - public function __construct() { |
|
33 | - $this->publicURLs = [ |
|
34 | - 'public-calendars', |
|
35 | - 'principals/system/public' |
|
36 | - ]; |
|
37 | - } |
|
32 | + public function __construct() { |
|
33 | + $this->publicURLs = [ |
|
34 | + 'public-calendars', |
|
35 | + 'principals/system/public' |
|
36 | + ]; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * When this method is called, the backend must check if authentication was |
|
41 | - * successful. |
|
42 | - * |
|
43 | - * The returned value must be one of the following |
|
44 | - * |
|
45 | - * [true, "principals/username"] |
|
46 | - * [false, "reason for failure"] |
|
47 | - * |
|
48 | - * If authentication was successful, it's expected that the authentication |
|
49 | - * backend returns a so-called principal url. |
|
50 | - * |
|
51 | - * Examples of a principal url: |
|
52 | - * |
|
53 | - * principals/admin |
|
54 | - * principals/user1 |
|
55 | - * principals/users/joe |
|
56 | - * principals/uid/123457 |
|
57 | - * |
|
58 | - * If you don't use WebDAV ACL (RFC3744) we recommend that you simply |
|
59 | - * return a string such as: |
|
60 | - * |
|
61 | - * principals/users/[username] |
|
62 | - * |
|
63 | - * @param RequestInterface $request |
|
64 | - * @param ResponseInterface $response |
|
65 | - * @return array |
|
66 | - */ |
|
67 | - function check(RequestInterface $request, ResponseInterface $response) { |
|
39 | + /** |
|
40 | + * When this method is called, the backend must check if authentication was |
|
41 | + * successful. |
|
42 | + * |
|
43 | + * The returned value must be one of the following |
|
44 | + * |
|
45 | + * [true, "principals/username"] |
|
46 | + * [false, "reason for failure"] |
|
47 | + * |
|
48 | + * If authentication was successful, it's expected that the authentication |
|
49 | + * backend returns a so-called principal url. |
|
50 | + * |
|
51 | + * Examples of a principal url: |
|
52 | + * |
|
53 | + * principals/admin |
|
54 | + * principals/user1 |
|
55 | + * principals/users/joe |
|
56 | + * principals/uid/123457 |
|
57 | + * |
|
58 | + * If you don't use WebDAV ACL (RFC3744) we recommend that you simply |
|
59 | + * return a string such as: |
|
60 | + * |
|
61 | + * principals/users/[username] |
|
62 | + * |
|
63 | + * @param RequestInterface $request |
|
64 | + * @param ResponseInterface $response |
|
65 | + * @return array |
|
66 | + */ |
|
67 | + function check(RequestInterface $request, ResponseInterface $response) { |
|
68 | 68 | |
69 | - if ($this->isRequestPublic($request)) { |
|
70 | - return [true, "principals/system/public"]; |
|
71 | - } |
|
72 | - return [false, "No public access to this resource."]; |
|
73 | - } |
|
69 | + if ($this->isRequestPublic($request)) { |
|
70 | + return [true, "principals/system/public"]; |
|
71 | + } |
|
72 | + return [false, "No public access to this resource."]; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @inheritdoc |
|
77 | - */ |
|
78 | - function challenge(RequestInterface $request, ResponseInterface $response) { |
|
79 | - } |
|
75 | + /** |
|
76 | + * @inheritdoc |
|
77 | + */ |
|
78 | + function challenge(RequestInterface $request, ResponseInterface $response) { |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @param RequestInterface $request |
|
83 | - * @return bool |
|
84 | - */ |
|
85 | - private function isRequestPublic(RequestInterface $request) { |
|
86 | - $url = $request->getPath(); |
|
87 | - $matchingUrls = array_filter($this->publicURLs, function ($publicUrl) use ($url) { |
|
88 | - return strpos($url, $publicUrl, 0) === 0; |
|
89 | - }); |
|
90 | - return !empty($matchingUrls); |
|
91 | - } |
|
81 | + /** |
|
82 | + * @param RequestInterface $request |
|
83 | + * @return bool |
|
84 | + */ |
|
85 | + private function isRequestPublic(RequestInterface $request) { |
|
86 | + $url = $request->getPath(); |
|
87 | + $matchingUrls = array_filter($this->publicURLs, function ($publicUrl) use ($url) { |
|
88 | + return strpos($url, $publicUrl, 0) === 0; |
|
89 | + }); |
|
90 | + return !empty($matchingUrls); |
|
91 | + } |
|
92 | 92 | } |
@@ -84,7 +84,7 @@ |
||
84 | 84 | */ |
85 | 85 | private function isRequestPublic(RequestInterface $request) { |
86 | 86 | $url = $request->getPath(); |
87 | - $matchingUrls = array_filter($this->publicURLs, function ($publicUrl) use ($url) { |
|
87 | + $matchingUrls = array_filter($this->publicURLs, function($publicUrl) use ($url) { |
|
88 | 88 | return strpos($url, $publicUrl, 0) === 0; |
89 | 89 | }); |
90 | 90 | return !empty($matchingUrls); |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | static function xmlDeserialize(Reader $reader) { |
48 | 48 | |
49 | 49 | $elements = $reader->parseInnerTree([ |
50 | - '{' . Plugin::NS_OWNCLOUD. '}set' => 'Sabre\\Xml\\Element\\KeyValue', |
|
51 | - '{' . Plugin::NS_OWNCLOUD . '}remove' => 'Sabre\\Xml\\Element\\KeyValue', |
|
50 | + '{'.Plugin::NS_OWNCLOUD.'}set' => 'Sabre\\Xml\\Element\\KeyValue', |
|
51 | + '{'.Plugin::NS_OWNCLOUD.'}remove' => 'Sabre\\Xml\\Element\\KeyValue', |
|
52 | 52 | ]); |
53 | 53 | |
54 | 54 | $set = []; |
@@ -57,21 +57,21 @@ discard block |
||
57 | 57 | foreach ($elements as $elem) { |
58 | 58 | switch ($elem['name']) { |
59 | 59 | |
60 | - case '{' . Plugin::NS_OWNCLOUD . '}set' : |
|
60 | + case '{'.Plugin::NS_OWNCLOUD.'}set' : |
|
61 | 61 | $sharee = $elem['value']; |
62 | 62 | |
63 | - $sumElem = '{' . Plugin::NS_OWNCLOUD . '}summary'; |
|
64 | - $commonName = '{' . Plugin::NS_OWNCLOUD . '}common-name'; |
|
63 | + $sumElem = '{'.Plugin::NS_OWNCLOUD.'}summary'; |
|
64 | + $commonName = '{'.Plugin::NS_OWNCLOUD.'}common-name'; |
|
65 | 65 | |
66 | 66 | $set[] = [ |
67 | 67 | 'href' => $sharee['{DAV:}href'], |
68 | 68 | 'commonName' => isset($sharee[$commonName]) ? $sharee[$commonName] : null, |
69 | 69 | 'summary' => isset($sharee[$sumElem]) ? $sharee[$sumElem] : null, |
70 | - 'readOnly' => !array_key_exists('{' . Plugin::NS_OWNCLOUD . '}read-write', $sharee), |
|
70 | + 'readOnly' => !array_key_exists('{'.Plugin::NS_OWNCLOUD.'}read-write', $sharee), |
|
71 | 71 | ]; |
72 | 72 | break; |
73 | 73 | |
74 | - case '{' . Plugin::NS_OWNCLOUD . '}remove' : |
|
74 | + case '{'.Plugin::NS_OWNCLOUD.'}remove' : |
|
75 | 75 | $remove[] = $elem['value']['{DAV:}href']; |
76 | 76 | break; |
77 | 77 |
@@ -41,130 +41,130 @@ |
||
41 | 41 | */ |
42 | 42 | class Invite implements XmlSerializable { |
43 | 43 | |
44 | - /** |
|
45 | - * The list of users a calendar has been shared to. |
|
46 | - * |
|
47 | - * @var array |
|
48 | - */ |
|
49 | - protected $users; |
|
50 | - |
|
51 | - /** |
|
52 | - * The organizer contains information about the person who shared the |
|
53 | - * object. |
|
54 | - * |
|
55 | - * @var array|null |
|
56 | - */ |
|
57 | - protected $organizer; |
|
58 | - |
|
59 | - /** |
|
60 | - * Creates the property. |
|
61 | - * |
|
62 | - * Users is an array. Each element of the array has the following |
|
63 | - * properties: |
|
64 | - * |
|
65 | - * * href - Often a mailto: address |
|
66 | - * * commonName - Optional, for example a first and lastname for a user. |
|
67 | - * * status - One of the SharingPlugin::STATUS_* constants. |
|
68 | - * * readOnly - true or false |
|
69 | - * * summary - Optional, description of the share |
|
70 | - * |
|
71 | - * The organizer key is optional to specify. It's only useful when a |
|
72 | - * 'sharee' requests the sharing information. |
|
73 | - * |
|
74 | - * The organizer may have the following properties: |
|
75 | - * * href - Often a mailto: address. |
|
76 | - * * commonName - Optional human-readable name. |
|
77 | - * * firstName - Optional first name. |
|
78 | - * * lastName - Optional last name. |
|
79 | - * |
|
80 | - * If you wonder why these two structures are so different, I guess a |
|
81 | - * valid answer is that the current spec is still a draft. |
|
82 | - * |
|
83 | - * @param array $users |
|
84 | - */ |
|
85 | - function __construct(array $users, array $organizer = null) { |
|
86 | - |
|
87 | - $this->users = $users; |
|
88 | - $this->organizer = $organizer; |
|
89 | - |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Returns the list of users, as it was passed to the constructor. |
|
94 | - * |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - function getValue() { |
|
98 | - |
|
99 | - return $this->users; |
|
100 | - |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * The xmlSerialize metod is called during xml writing. |
|
105 | - * |
|
106 | - * Use the $writer argument to write its own xml serialization. |
|
107 | - * |
|
108 | - * An important note: do _not_ create a parent element. Any element |
|
109 | - * implementing XmlSerializble should only ever write what's considered |
|
110 | - * its 'inner xml'. |
|
111 | - * |
|
112 | - * The parent of the current element is responsible for writing a |
|
113 | - * containing element. |
|
114 | - * |
|
115 | - * This allows serializers to be re-used for different element names. |
|
116 | - * |
|
117 | - * If you are opening new elements, you must also close them again. |
|
118 | - * |
|
119 | - * @param Writer $writer |
|
120 | - * @return void |
|
121 | - */ |
|
122 | - function xmlSerialize(Writer $writer) { |
|
123 | - |
|
124 | - $cs = '{' . Plugin::NS_OWNCLOUD . '}'; |
|
125 | - |
|
126 | - if (!is_null($this->organizer)) { |
|
127 | - |
|
128 | - $writer->startElement($cs . 'organizer'); |
|
129 | - $writer->writeElement('{DAV:}href', $this->organizer['href']); |
|
130 | - |
|
131 | - if (isset($this->organizer['commonName']) && $this->organizer['commonName']) { |
|
132 | - $writer->writeElement($cs . 'common-name', $this->organizer['commonName']); |
|
133 | - } |
|
134 | - if (isset($this->organizer['firstName']) && $this->organizer['firstName']) { |
|
135 | - $writer->writeElement($cs . 'first-name', $this->organizer['firstName']); |
|
136 | - } |
|
137 | - if (isset($this->organizer['lastName']) && $this->organizer['lastName']) { |
|
138 | - $writer->writeElement($cs . 'last-name', $this->organizer['lastName']); |
|
139 | - } |
|
140 | - $writer->endElement(); // organizer |
|
141 | - |
|
142 | - } |
|
143 | - |
|
144 | - foreach ($this->users as $user) { |
|
145 | - |
|
146 | - $writer->startElement($cs . 'user'); |
|
147 | - $writer->writeElement('{DAV:}href', $user['href']); |
|
148 | - if (isset($user['commonName']) && $user['commonName']) { |
|
149 | - $writer->writeElement($cs . 'common-name', $user['commonName']); |
|
150 | - } |
|
151 | - $writer->writeElement($cs . 'invite-accepted'); |
|
152 | - |
|
153 | - $writer->startElement($cs . 'access'); |
|
154 | - if ($user['readOnly']) { |
|
155 | - $writer->writeElement($cs . 'read'); |
|
156 | - } else { |
|
157 | - $writer->writeElement($cs . 'read-write'); |
|
158 | - } |
|
159 | - $writer->endElement(); // access |
|
160 | - |
|
161 | - if (isset($user['summary']) && $user['summary']) { |
|
162 | - $writer->writeElement($cs . 'summary', $user['summary']); |
|
163 | - } |
|
164 | - |
|
165 | - $writer->endElement(); //user |
|
166 | - |
|
167 | - } |
|
168 | - |
|
169 | - } |
|
44 | + /** |
|
45 | + * The list of users a calendar has been shared to. |
|
46 | + * |
|
47 | + * @var array |
|
48 | + */ |
|
49 | + protected $users; |
|
50 | + |
|
51 | + /** |
|
52 | + * The organizer contains information about the person who shared the |
|
53 | + * object. |
|
54 | + * |
|
55 | + * @var array|null |
|
56 | + */ |
|
57 | + protected $organizer; |
|
58 | + |
|
59 | + /** |
|
60 | + * Creates the property. |
|
61 | + * |
|
62 | + * Users is an array. Each element of the array has the following |
|
63 | + * properties: |
|
64 | + * |
|
65 | + * * href - Often a mailto: address |
|
66 | + * * commonName - Optional, for example a first and lastname for a user. |
|
67 | + * * status - One of the SharingPlugin::STATUS_* constants. |
|
68 | + * * readOnly - true or false |
|
69 | + * * summary - Optional, description of the share |
|
70 | + * |
|
71 | + * The organizer key is optional to specify. It's only useful when a |
|
72 | + * 'sharee' requests the sharing information. |
|
73 | + * |
|
74 | + * The organizer may have the following properties: |
|
75 | + * * href - Often a mailto: address. |
|
76 | + * * commonName - Optional human-readable name. |
|
77 | + * * firstName - Optional first name. |
|
78 | + * * lastName - Optional last name. |
|
79 | + * |
|
80 | + * If you wonder why these two structures are so different, I guess a |
|
81 | + * valid answer is that the current spec is still a draft. |
|
82 | + * |
|
83 | + * @param array $users |
|
84 | + */ |
|
85 | + function __construct(array $users, array $organizer = null) { |
|
86 | + |
|
87 | + $this->users = $users; |
|
88 | + $this->organizer = $organizer; |
|
89 | + |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Returns the list of users, as it was passed to the constructor. |
|
94 | + * |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + function getValue() { |
|
98 | + |
|
99 | + return $this->users; |
|
100 | + |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * The xmlSerialize metod is called during xml writing. |
|
105 | + * |
|
106 | + * Use the $writer argument to write its own xml serialization. |
|
107 | + * |
|
108 | + * An important note: do _not_ create a parent element. Any element |
|
109 | + * implementing XmlSerializble should only ever write what's considered |
|
110 | + * its 'inner xml'. |
|
111 | + * |
|
112 | + * The parent of the current element is responsible for writing a |
|
113 | + * containing element. |
|
114 | + * |
|
115 | + * This allows serializers to be re-used for different element names. |
|
116 | + * |
|
117 | + * If you are opening new elements, you must also close them again. |
|
118 | + * |
|
119 | + * @param Writer $writer |
|
120 | + * @return void |
|
121 | + */ |
|
122 | + function xmlSerialize(Writer $writer) { |
|
123 | + |
|
124 | + $cs = '{' . Plugin::NS_OWNCLOUD . '}'; |
|
125 | + |
|
126 | + if (!is_null($this->organizer)) { |
|
127 | + |
|
128 | + $writer->startElement($cs . 'organizer'); |
|
129 | + $writer->writeElement('{DAV:}href', $this->organizer['href']); |
|
130 | + |
|
131 | + if (isset($this->organizer['commonName']) && $this->organizer['commonName']) { |
|
132 | + $writer->writeElement($cs . 'common-name', $this->organizer['commonName']); |
|
133 | + } |
|
134 | + if (isset($this->organizer['firstName']) && $this->organizer['firstName']) { |
|
135 | + $writer->writeElement($cs . 'first-name', $this->organizer['firstName']); |
|
136 | + } |
|
137 | + if (isset($this->organizer['lastName']) && $this->organizer['lastName']) { |
|
138 | + $writer->writeElement($cs . 'last-name', $this->organizer['lastName']); |
|
139 | + } |
|
140 | + $writer->endElement(); // organizer |
|
141 | + |
|
142 | + } |
|
143 | + |
|
144 | + foreach ($this->users as $user) { |
|
145 | + |
|
146 | + $writer->startElement($cs . 'user'); |
|
147 | + $writer->writeElement('{DAV:}href', $user['href']); |
|
148 | + if (isset($user['commonName']) && $user['commonName']) { |
|
149 | + $writer->writeElement($cs . 'common-name', $user['commonName']); |
|
150 | + } |
|
151 | + $writer->writeElement($cs . 'invite-accepted'); |
|
152 | + |
|
153 | + $writer->startElement($cs . 'access'); |
|
154 | + if ($user['readOnly']) { |
|
155 | + $writer->writeElement($cs . 'read'); |
|
156 | + } else { |
|
157 | + $writer->writeElement($cs . 'read-write'); |
|
158 | + } |
|
159 | + $writer->endElement(); // access |
|
160 | + |
|
161 | + if (isset($user['summary']) && $user['summary']) { |
|
162 | + $writer->writeElement($cs . 'summary', $user['summary']); |
|
163 | + } |
|
164 | + |
|
165 | + $writer->endElement(); //user |
|
166 | + |
|
167 | + } |
|
168 | + |
|
169 | + } |
|
170 | 170 | } |
@@ -121,21 +121,21 @@ discard block |
||
121 | 121 | */ |
122 | 122 | function xmlSerialize(Writer $writer) { |
123 | 123 | |
124 | - $cs = '{' . Plugin::NS_OWNCLOUD . '}'; |
|
124 | + $cs = '{'.Plugin::NS_OWNCLOUD.'}'; |
|
125 | 125 | |
126 | 126 | if (!is_null($this->organizer)) { |
127 | 127 | |
128 | - $writer->startElement($cs . 'organizer'); |
|
128 | + $writer->startElement($cs.'organizer'); |
|
129 | 129 | $writer->writeElement('{DAV:}href', $this->organizer['href']); |
130 | 130 | |
131 | 131 | if (isset($this->organizer['commonName']) && $this->organizer['commonName']) { |
132 | - $writer->writeElement($cs . 'common-name', $this->organizer['commonName']); |
|
132 | + $writer->writeElement($cs.'common-name', $this->organizer['commonName']); |
|
133 | 133 | } |
134 | 134 | if (isset($this->organizer['firstName']) && $this->organizer['firstName']) { |
135 | - $writer->writeElement($cs . 'first-name', $this->organizer['firstName']); |
|
135 | + $writer->writeElement($cs.'first-name', $this->organizer['firstName']); |
|
136 | 136 | } |
137 | 137 | if (isset($this->organizer['lastName']) && $this->organizer['lastName']) { |
138 | - $writer->writeElement($cs . 'last-name', $this->organizer['lastName']); |
|
138 | + $writer->writeElement($cs.'last-name', $this->organizer['lastName']); |
|
139 | 139 | } |
140 | 140 | $writer->endElement(); // organizer |
141 | 141 | |
@@ -143,23 +143,23 @@ discard block |
||
143 | 143 | |
144 | 144 | foreach ($this->users as $user) { |
145 | 145 | |
146 | - $writer->startElement($cs . 'user'); |
|
146 | + $writer->startElement($cs.'user'); |
|
147 | 147 | $writer->writeElement('{DAV:}href', $user['href']); |
148 | 148 | if (isset($user['commonName']) && $user['commonName']) { |
149 | - $writer->writeElement($cs . 'common-name', $user['commonName']); |
|
149 | + $writer->writeElement($cs.'common-name', $user['commonName']); |
|
150 | 150 | } |
151 | - $writer->writeElement($cs . 'invite-accepted'); |
|
151 | + $writer->writeElement($cs.'invite-accepted'); |
|
152 | 152 | |
153 | - $writer->startElement($cs . 'access'); |
|
153 | + $writer->startElement($cs.'access'); |
|
154 | 154 | if ($user['readOnly']) { |
155 | - $writer->writeElement($cs . 'read'); |
|
155 | + $writer->writeElement($cs.'read'); |
|
156 | 156 | } else { |
157 | - $writer->writeElement($cs . 'read-write'); |
|
157 | + $writer->writeElement($cs.'read-write'); |
|
158 | 158 | } |
159 | 159 | $writer->endElement(); // access |
160 | 160 | |
161 | 161 | if (isset($user['summary']) && $user['summary']) { |
162 | - $writer->writeElement($cs . 'summary', $user['summary']); |
|
162 | + $writer->writeElement($cs.'summary', $user['summary']); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | $writer->endElement(); //user |
@@ -99,11 +99,11 @@ discard block |
||
99 | 99 | */ |
100 | 100 | function initialize(Server $server) { |
101 | 101 | $this->server = $server; |
102 | - $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}share'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\ShareRequest'; |
|
103 | - $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}invite'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\Invite'; |
|
102 | + $this->server->xml->elementMap['{'.Plugin::NS_OWNCLOUD.'}share'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\ShareRequest'; |
|
103 | + $this->server->xml->elementMap['{'.Plugin::NS_OWNCLOUD.'}invite'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\Invite'; |
|
104 | 104 | |
105 | 105 | $this->server->on('method:POST', [$this, 'httpPost']); |
106 | - $this->server->on('propFind', [$this, 'propFind']); |
|
106 | + $this->server->on('propFind', [$this, 'propFind']); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | |
147 | 147 | // Dealing with the 'share' document, which modified invitees on a |
148 | 148 | // calendar. |
149 | - case '{' . self::NS_OWNCLOUD . '}share' : |
|
149 | + case '{'.self::NS_OWNCLOUD.'}share' : |
|
150 | 150 | |
151 | 151 | // We can only deal with IShareableCalendar objects |
152 | 152 | if (!$node instanceof IShareable) { |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | function propFind(PropFind $propFind, INode $node) { |
190 | 190 | if ($node instanceof IShareable) { |
191 | 191 | |
192 | - $propFind->handle('{' . Plugin::NS_OWNCLOUD . '}invite', function() use ($node) { |
|
192 | + $propFind->handle('{'.Plugin::NS_OWNCLOUD.'}invite', function() use ($node) { |
|
193 | 193 | return new Invite( |
194 | 194 | $node->getShares() |
195 | 195 | ); |
@@ -119,8 +119,9 @@ |
||
119 | 119 | |
120 | 120 | // Only handling xml |
121 | 121 | $contentType = $request->getHeader('Content-Type'); |
122 | - if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) |
|
123 | - return; |
|
122 | + if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) { |
|
123 | + return; |
|
124 | + } |
|
124 | 125 | |
125 | 126 | // Making sure the node exists |
126 | 127 | try { |
@@ -36,167 +36,167 @@ |
||
36 | 36 | |
37 | 37 | class Plugin extends ServerPlugin { |
38 | 38 | |
39 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
40 | - const NS_NEXTCLOUD = 'http://nextcloud.com/ns'; |
|
41 | - |
|
42 | - /** @var Auth */ |
|
43 | - private $auth; |
|
44 | - |
|
45 | - /** @var IRequest */ |
|
46 | - private $request; |
|
47 | - |
|
48 | - /** |
|
49 | - * Plugin constructor. |
|
50 | - * |
|
51 | - * @param Auth $authBackEnd |
|
52 | - * @param IRequest $request |
|
53 | - */ |
|
54 | - public function __construct(Auth $authBackEnd, IRequest $request) { |
|
55 | - $this->auth = $authBackEnd; |
|
56 | - $this->request = $request; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Reference to SabreDAV server object. |
|
61 | - * |
|
62 | - * @var \Sabre\DAV\Server |
|
63 | - */ |
|
64 | - protected $server; |
|
65 | - |
|
66 | - /** |
|
67 | - * This method should return a list of server-features. |
|
68 | - * |
|
69 | - * This is for example 'versioning' and is added to the DAV: header |
|
70 | - * in an OPTIONS response. |
|
71 | - * |
|
72 | - * @return string[] |
|
73 | - */ |
|
74 | - function getFeatures() { |
|
75 | - return ['oc-resource-sharing']; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Returns a plugin name. |
|
80 | - * |
|
81 | - * Using this name other plugins will be able to access other plugins |
|
82 | - * using Sabre\DAV\Server::getPlugin |
|
83 | - * |
|
84 | - * @return string |
|
85 | - */ |
|
86 | - function getPluginName() { |
|
87 | - return 'oc-resource-sharing'; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * This initializes the plugin. |
|
92 | - * |
|
93 | - * This function is called by Sabre\DAV\Server, after |
|
94 | - * addPlugin is called. |
|
95 | - * |
|
96 | - * This method should set up the required event subscriptions. |
|
97 | - * |
|
98 | - * @param Server $server |
|
99 | - * @return void |
|
100 | - */ |
|
101 | - function initialize(Server $server) { |
|
102 | - $this->server = $server; |
|
103 | - $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}share'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\ShareRequest'; |
|
104 | - $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}invite'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\Invite'; |
|
105 | - |
|
106 | - $this->server->on('method:POST', [$this, 'httpPost']); |
|
107 | - $this->server->on('propFind', [$this, 'propFind']); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * We intercept this to handle POST requests on a dav resource. |
|
112 | - * |
|
113 | - * @param RequestInterface $request |
|
114 | - * @param ResponseInterface $response |
|
115 | - * @return null|false |
|
116 | - */ |
|
117 | - function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
118 | - |
|
119 | - $path = $request->getPath(); |
|
120 | - |
|
121 | - // Only handling xml |
|
122 | - $contentType = $request->getHeader('Content-Type'); |
|
123 | - if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) |
|
124 | - return; |
|
125 | - |
|
126 | - // Making sure the node exists |
|
127 | - try { |
|
128 | - $node = $this->server->tree->getNodeForPath($path); |
|
129 | - } catch (NotFound $e) { |
|
130 | - return; |
|
131 | - } |
|
132 | - |
|
133 | - $requestBody = $request->getBodyAsString(); |
|
134 | - |
|
135 | - // If this request handler could not deal with this POST request, it |
|
136 | - // will return 'null' and other plugins get a chance to handle the |
|
137 | - // request. |
|
138 | - // |
|
139 | - // However, we already requested the full body. This is a problem, |
|
140 | - // because a body can only be read once. This is why we preemptively |
|
141 | - // re-populated the request body with the existing data. |
|
142 | - $request->setBody($requestBody); |
|
143 | - |
|
144 | - $message = $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
145 | - |
|
146 | - switch ($documentType) { |
|
147 | - |
|
148 | - // Dealing with the 'share' document, which modified invitees on a |
|
149 | - // calendar. |
|
150 | - case '{' . self::NS_OWNCLOUD . '}share' : |
|
151 | - |
|
152 | - // We can only deal with IShareableCalendar objects |
|
153 | - if (!$node instanceof IShareable) { |
|
154 | - return; |
|
155 | - } |
|
156 | - |
|
157 | - $this->server->transactionType = 'post-oc-resource-share'; |
|
158 | - |
|
159 | - // Getting ACL info |
|
160 | - $acl = $this->server->getPlugin('acl'); |
|
161 | - |
|
162 | - // If there's no ACL support, we allow everything |
|
163 | - if ($acl) { |
|
164 | - /** @var \Sabre\DAVACL\Plugin $acl */ |
|
165 | - $acl->checkPrivileges($path, '{DAV:}write'); |
|
166 | - } |
|
167 | - |
|
168 | - $node->updateShares($message->set, $message->remove); |
|
169 | - |
|
170 | - $response->setStatus(200); |
|
171 | - // Adding this because sending a response body may cause issues, |
|
172 | - // and I wanted some type of indicator the response was handled. |
|
173 | - $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
174 | - |
|
175 | - // Breaking the event chain |
|
176 | - return false; |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * This event is triggered when properties are requested for a certain |
|
182 | - * node. |
|
183 | - * |
|
184 | - * This allows us to inject any properties early. |
|
185 | - * |
|
186 | - * @param PropFind $propFind |
|
187 | - * @param INode $node |
|
188 | - * @return void |
|
189 | - */ |
|
190 | - function propFind(PropFind $propFind, INode $node) { |
|
191 | - if ($node instanceof IShareable) { |
|
192 | - |
|
193 | - $propFind->handle('{' . Plugin::NS_OWNCLOUD . '}invite', function() use ($node) { |
|
194 | - return new Invite( |
|
195 | - $node->getShares() |
|
196 | - ); |
|
197 | - }); |
|
198 | - |
|
199 | - } |
|
200 | - } |
|
39 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
40 | + const NS_NEXTCLOUD = 'http://nextcloud.com/ns'; |
|
41 | + |
|
42 | + /** @var Auth */ |
|
43 | + private $auth; |
|
44 | + |
|
45 | + /** @var IRequest */ |
|
46 | + private $request; |
|
47 | + |
|
48 | + /** |
|
49 | + * Plugin constructor. |
|
50 | + * |
|
51 | + * @param Auth $authBackEnd |
|
52 | + * @param IRequest $request |
|
53 | + */ |
|
54 | + public function __construct(Auth $authBackEnd, IRequest $request) { |
|
55 | + $this->auth = $authBackEnd; |
|
56 | + $this->request = $request; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Reference to SabreDAV server object. |
|
61 | + * |
|
62 | + * @var \Sabre\DAV\Server |
|
63 | + */ |
|
64 | + protected $server; |
|
65 | + |
|
66 | + /** |
|
67 | + * This method should return a list of server-features. |
|
68 | + * |
|
69 | + * This is for example 'versioning' and is added to the DAV: header |
|
70 | + * in an OPTIONS response. |
|
71 | + * |
|
72 | + * @return string[] |
|
73 | + */ |
|
74 | + function getFeatures() { |
|
75 | + return ['oc-resource-sharing']; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Returns a plugin name. |
|
80 | + * |
|
81 | + * Using this name other plugins will be able to access other plugins |
|
82 | + * using Sabre\DAV\Server::getPlugin |
|
83 | + * |
|
84 | + * @return string |
|
85 | + */ |
|
86 | + function getPluginName() { |
|
87 | + return 'oc-resource-sharing'; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * This initializes the plugin. |
|
92 | + * |
|
93 | + * This function is called by Sabre\DAV\Server, after |
|
94 | + * addPlugin is called. |
|
95 | + * |
|
96 | + * This method should set up the required event subscriptions. |
|
97 | + * |
|
98 | + * @param Server $server |
|
99 | + * @return void |
|
100 | + */ |
|
101 | + function initialize(Server $server) { |
|
102 | + $this->server = $server; |
|
103 | + $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}share'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\ShareRequest'; |
|
104 | + $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}invite'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\Invite'; |
|
105 | + |
|
106 | + $this->server->on('method:POST', [$this, 'httpPost']); |
|
107 | + $this->server->on('propFind', [$this, 'propFind']); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * We intercept this to handle POST requests on a dav resource. |
|
112 | + * |
|
113 | + * @param RequestInterface $request |
|
114 | + * @param ResponseInterface $response |
|
115 | + * @return null|false |
|
116 | + */ |
|
117 | + function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
118 | + |
|
119 | + $path = $request->getPath(); |
|
120 | + |
|
121 | + // Only handling xml |
|
122 | + $contentType = $request->getHeader('Content-Type'); |
|
123 | + if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) |
|
124 | + return; |
|
125 | + |
|
126 | + // Making sure the node exists |
|
127 | + try { |
|
128 | + $node = $this->server->tree->getNodeForPath($path); |
|
129 | + } catch (NotFound $e) { |
|
130 | + return; |
|
131 | + } |
|
132 | + |
|
133 | + $requestBody = $request->getBodyAsString(); |
|
134 | + |
|
135 | + // If this request handler could not deal with this POST request, it |
|
136 | + // will return 'null' and other plugins get a chance to handle the |
|
137 | + // request. |
|
138 | + // |
|
139 | + // However, we already requested the full body. This is a problem, |
|
140 | + // because a body can only be read once. This is why we preemptively |
|
141 | + // re-populated the request body with the existing data. |
|
142 | + $request->setBody($requestBody); |
|
143 | + |
|
144 | + $message = $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
145 | + |
|
146 | + switch ($documentType) { |
|
147 | + |
|
148 | + // Dealing with the 'share' document, which modified invitees on a |
|
149 | + // calendar. |
|
150 | + case '{' . self::NS_OWNCLOUD . '}share' : |
|
151 | + |
|
152 | + // We can only deal with IShareableCalendar objects |
|
153 | + if (!$node instanceof IShareable) { |
|
154 | + return; |
|
155 | + } |
|
156 | + |
|
157 | + $this->server->transactionType = 'post-oc-resource-share'; |
|
158 | + |
|
159 | + // Getting ACL info |
|
160 | + $acl = $this->server->getPlugin('acl'); |
|
161 | + |
|
162 | + // If there's no ACL support, we allow everything |
|
163 | + if ($acl) { |
|
164 | + /** @var \Sabre\DAVACL\Plugin $acl */ |
|
165 | + $acl->checkPrivileges($path, '{DAV:}write'); |
|
166 | + } |
|
167 | + |
|
168 | + $node->updateShares($message->set, $message->remove); |
|
169 | + |
|
170 | + $response->setStatus(200); |
|
171 | + // Adding this because sending a response body may cause issues, |
|
172 | + // and I wanted some type of indicator the response was handled. |
|
173 | + $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
174 | + |
|
175 | + // Breaking the event chain |
|
176 | + return false; |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * This event is triggered when properties are requested for a certain |
|
182 | + * node. |
|
183 | + * |
|
184 | + * This allows us to inject any properties early. |
|
185 | + * |
|
186 | + * @param PropFind $propFind |
|
187 | + * @param INode $node |
|
188 | + * @return void |
|
189 | + */ |
|
190 | + function propFind(PropFind $propFind, INode $node) { |
|
191 | + if ($node instanceof IShareable) { |
|
192 | + |
|
193 | + $propFind->handle('{' . Plugin::NS_OWNCLOUD . '}invite', function() use ($node) { |
|
194 | + return new Invite( |
|
195 | + $node->getShares() |
|
196 | + ); |
|
197 | + }); |
|
198 | + |
|
199 | + } |
|
200 | + } |
|
201 | 201 | |
202 | 202 | } |
@@ -57,10 +57,10 @@ discard block |
||
57 | 57 | * @param string[] $remove |
58 | 58 | */ |
59 | 59 | public function updateShares($shareable, $add, $remove) { |
60 | - foreach($add as $element) { |
|
60 | + foreach ($add as $element) { |
|
61 | 61 | $this->shareWith($shareable, $element); |
62 | 62 | } |
63 | - foreach($remove as $element) { |
|
63 | + foreach ($remove as $element) { |
|
64 | 64 | $this->unshare($shareable, $element); |
65 | 65 | } |
66 | 66 | } |
@@ -164,9 +164,9 @@ discard block |
||
164 | 164 | ->execute(); |
165 | 165 | |
166 | 166 | $shares = []; |
167 | - while($row = $result->fetch()) { |
|
167 | + while ($row = $result->fetch()) { |
|
168 | 168 | $p = $this->principalBackend->getPrincipalByPath($row['principaluri']); |
169 | - $shares[]= [ |
|
169 | + $shares[] = [ |
|
170 | 170 | 'href' => "principal:${row['principaluri']}", |
171 | 171 | 'commonName' => isset($p['{DAV:}displayname']) ? $p['{DAV:}displayname'] : '', |
172 | 172 | 'status' => 1, |
@@ -192,13 +192,13 @@ discard block |
||
192 | 192 | foreach ($shares as $share) { |
193 | 193 | $acl[] = [ |
194 | 194 | 'privilege' => '{DAV:}read', |
195 | - 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
195 | + 'principal' => $share['{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}principal'], |
|
196 | 196 | 'protected' => true, |
197 | 197 | ]; |
198 | 198 | if (!$share['readOnly']) { |
199 | 199 | $acl[] = [ |
200 | 200 | 'privilege' => '{DAV:}write', |
201 | - 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
201 | + 'principal' => $share['{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}principal'], |
|
202 | 202 | 'protected' => true, |
203 | 203 | ]; |
204 | 204 | } else if ($this->resourceType === 'calendar') { |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | // so users can change the visibility. |
207 | 207 | $acl[] = [ |
208 | 208 | 'privilege' => '{DAV:}write-properties', |
209 | - 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
209 | + 'principal' => $share['{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}principal'], |
|
210 | 210 | 'protected' => true, |
211 | 211 | ]; |
212 | 212 | } |
@@ -31,208 +31,208 @@ |
||
31 | 31 | |
32 | 32 | class Backend { |
33 | 33 | |
34 | - /** @var IDBConnection */ |
|
35 | - private $db; |
|
36 | - /** @var IUserManager */ |
|
37 | - private $userManager; |
|
38 | - /** @var IGroupManager */ |
|
39 | - private $groupManager; |
|
40 | - /** @var Principal */ |
|
41 | - private $principalBackend; |
|
42 | - /** @var string */ |
|
43 | - private $resourceType; |
|
44 | - |
|
45 | - const ACCESS_OWNER = 1; |
|
46 | - const ACCESS_READ_WRITE = 2; |
|
47 | - const ACCESS_READ = 3; |
|
48 | - |
|
49 | - /** |
|
50 | - * @param IDBConnection $db |
|
51 | - * @param IUserManager $userManager |
|
52 | - * @param IGroupManager $groupManager |
|
53 | - * @param Principal $principalBackend |
|
54 | - * @param string $resourceType |
|
55 | - */ |
|
56 | - public function __construct(IDBConnection $db, IUserManager $userManager, IGroupManager $groupManager, Principal $principalBackend, $resourceType) { |
|
57 | - $this->db = $db; |
|
58 | - $this->userManager = $userManager; |
|
59 | - $this->groupManager = $groupManager; |
|
60 | - $this->principalBackend = $principalBackend; |
|
61 | - $this->resourceType = $resourceType; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @param IShareable $shareable |
|
66 | - * @param string[] $add |
|
67 | - * @param string[] $remove |
|
68 | - */ |
|
69 | - public function updateShares($shareable, $add, $remove) { |
|
70 | - foreach($add as $element) { |
|
71 | - $this->shareWith($shareable, $element); |
|
72 | - } |
|
73 | - foreach($remove as $element) { |
|
74 | - $this->unshare($shareable, $element); |
|
75 | - } |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * @param IShareable $shareable |
|
80 | - * @param string $element |
|
81 | - */ |
|
82 | - private function shareWith($shareable, $element) { |
|
83 | - $user = $element['href']; |
|
84 | - $parts = explode(':', $user, 2); |
|
85 | - if ($parts[0] !== 'principal') { |
|
86 | - return; |
|
87 | - } |
|
88 | - |
|
89 | - // don't share with owner |
|
90 | - if ($shareable->getOwner() === $parts[1]) { |
|
91 | - return; |
|
92 | - } |
|
93 | - |
|
94 | - $principal = explode('/', $parts[1], 3); |
|
95 | - if (count($principal) !== 3 || $principal[0] !== 'principals' || !in_array($principal[1], ['users', 'groups'], true)) { |
|
96 | - // Invalid principal |
|
97 | - return; |
|
98 | - } |
|
99 | - |
|
100 | - if (($principal[1] === 'users' && !$this->userManager->userExists($principal[2])) || |
|
101 | - ($principal[1] === 'groups' && !$this->groupManager->groupExists($principal[2]))) { |
|
102 | - // User or group does not exist |
|
103 | - return; |
|
104 | - } |
|
105 | - |
|
106 | - // remove the share if it already exists |
|
107 | - $this->unshare($shareable, $element['href']); |
|
108 | - $access = self::ACCESS_READ; |
|
109 | - if (isset($element['readOnly'])) { |
|
110 | - $access = $element['readOnly'] ? self::ACCESS_READ : self::ACCESS_READ_WRITE; |
|
111 | - } |
|
112 | - |
|
113 | - $query = $this->db->getQueryBuilder(); |
|
114 | - $query->insert('dav_shares') |
|
115 | - ->values([ |
|
116 | - 'principaluri' => $query->createNamedParameter($parts[1]), |
|
117 | - 'type' => $query->createNamedParameter($this->resourceType), |
|
118 | - 'access' => $query->createNamedParameter($access), |
|
119 | - 'resourceid' => $query->createNamedParameter($shareable->getResourceId()) |
|
120 | - ]); |
|
121 | - $query->execute(); |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * @param $resourceId |
|
126 | - */ |
|
127 | - public function deleteAllShares($resourceId) { |
|
128 | - $query = $this->db->getQueryBuilder(); |
|
129 | - $query->delete('dav_shares') |
|
130 | - ->where($query->expr()->eq('resourceid', $query->createNamedParameter($resourceId))) |
|
131 | - ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType))) |
|
132 | - ->execute(); |
|
133 | - } |
|
134 | - |
|
135 | - public function deleteAllSharesByUser($principaluri) { |
|
136 | - $query = $this->db->getQueryBuilder(); |
|
137 | - $query->delete('dav_shares') |
|
138 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principaluri))) |
|
139 | - ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType))) |
|
140 | - ->execute(); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * @param IShareable $shareable |
|
145 | - * @param string $element |
|
146 | - */ |
|
147 | - private function unshare($shareable, $element) { |
|
148 | - $parts = explode(':', $element, 2); |
|
149 | - if ($parts[0] !== 'principal') { |
|
150 | - return; |
|
151 | - } |
|
152 | - |
|
153 | - // don't share with owner |
|
154 | - if ($shareable->getOwner() === $parts[1]) { |
|
155 | - return; |
|
156 | - } |
|
157 | - |
|
158 | - $query = $this->db->getQueryBuilder(); |
|
159 | - $query->delete('dav_shares') |
|
160 | - ->where($query->expr()->eq('resourceid', $query->createNamedParameter($shareable->getResourceId()))) |
|
161 | - ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType))) |
|
162 | - ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($parts[1]))) |
|
163 | - ; |
|
164 | - $query->execute(); |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Returns the list of people whom this resource is shared with. |
|
169 | - * |
|
170 | - * Every element in this array should have the following properties: |
|
171 | - * * href - Often a mailto: address |
|
172 | - * * commonName - Optional, for example a first + last name |
|
173 | - * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
174 | - * * readOnly - boolean |
|
175 | - * * summary - Optional, a description for the share |
|
176 | - * |
|
177 | - * @param int $resourceId |
|
178 | - * @return array |
|
179 | - */ |
|
180 | - public function getShares($resourceId) { |
|
181 | - $query = $this->db->getQueryBuilder(); |
|
182 | - $result = $query->select(['principaluri', 'access']) |
|
183 | - ->from('dav_shares') |
|
184 | - ->where($query->expr()->eq('resourceid', $query->createNamedParameter($resourceId))) |
|
185 | - ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType))) |
|
186 | - ->execute(); |
|
187 | - |
|
188 | - $shares = []; |
|
189 | - while($row = $result->fetch()) { |
|
190 | - $p = $this->principalBackend->getPrincipalByPath($row['principaluri']); |
|
191 | - $shares[]= [ |
|
192 | - 'href' => "principal:${row['principaluri']}", |
|
193 | - 'commonName' => isset($p['{DAV:}displayname']) ? $p['{DAV:}displayname'] : '', |
|
194 | - 'status' => 1, |
|
195 | - 'readOnly' => ((int) $row['access'] === self::ACCESS_READ), |
|
196 | - '{http://owncloud.org/ns}principal' => $row['principaluri'], |
|
197 | - '{http://owncloud.org/ns}group-share' => is_null($p) |
|
198 | - ]; |
|
199 | - } |
|
200 | - |
|
201 | - return $shares; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * For shared resources the sharee is set in the ACL of the resource |
|
206 | - * |
|
207 | - * @param int $resourceId |
|
208 | - * @param array $acl |
|
209 | - * @return array |
|
210 | - */ |
|
211 | - public function applyShareAcl($resourceId, $acl) { |
|
212 | - |
|
213 | - $shares = $this->getShares($resourceId); |
|
214 | - foreach ($shares as $share) { |
|
215 | - $acl[] = [ |
|
216 | - 'privilege' => '{DAV:}read', |
|
217 | - 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
218 | - 'protected' => true, |
|
219 | - ]; |
|
220 | - if (!$share['readOnly']) { |
|
221 | - $acl[] = [ |
|
222 | - 'privilege' => '{DAV:}write', |
|
223 | - 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
224 | - 'protected' => true, |
|
225 | - ]; |
|
226 | - } else if ($this->resourceType === 'calendar') { |
|
227 | - // Allow changing the properties of read only calendars, |
|
228 | - // so users can change the visibility. |
|
229 | - $acl[] = [ |
|
230 | - 'privilege' => '{DAV:}write-properties', |
|
231 | - 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
232 | - 'protected' => true, |
|
233 | - ]; |
|
234 | - } |
|
235 | - } |
|
236 | - return $acl; |
|
237 | - } |
|
34 | + /** @var IDBConnection */ |
|
35 | + private $db; |
|
36 | + /** @var IUserManager */ |
|
37 | + private $userManager; |
|
38 | + /** @var IGroupManager */ |
|
39 | + private $groupManager; |
|
40 | + /** @var Principal */ |
|
41 | + private $principalBackend; |
|
42 | + /** @var string */ |
|
43 | + private $resourceType; |
|
44 | + |
|
45 | + const ACCESS_OWNER = 1; |
|
46 | + const ACCESS_READ_WRITE = 2; |
|
47 | + const ACCESS_READ = 3; |
|
48 | + |
|
49 | + /** |
|
50 | + * @param IDBConnection $db |
|
51 | + * @param IUserManager $userManager |
|
52 | + * @param IGroupManager $groupManager |
|
53 | + * @param Principal $principalBackend |
|
54 | + * @param string $resourceType |
|
55 | + */ |
|
56 | + public function __construct(IDBConnection $db, IUserManager $userManager, IGroupManager $groupManager, Principal $principalBackend, $resourceType) { |
|
57 | + $this->db = $db; |
|
58 | + $this->userManager = $userManager; |
|
59 | + $this->groupManager = $groupManager; |
|
60 | + $this->principalBackend = $principalBackend; |
|
61 | + $this->resourceType = $resourceType; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @param IShareable $shareable |
|
66 | + * @param string[] $add |
|
67 | + * @param string[] $remove |
|
68 | + */ |
|
69 | + public function updateShares($shareable, $add, $remove) { |
|
70 | + foreach($add as $element) { |
|
71 | + $this->shareWith($shareable, $element); |
|
72 | + } |
|
73 | + foreach($remove as $element) { |
|
74 | + $this->unshare($shareable, $element); |
|
75 | + } |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * @param IShareable $shareable |
|
80 | + * @param string $element |
|
81 | + */ |
|
82 | + private function shareWith($shareable, $element) { |
|
83 | + $user = $element['href']; |
|
84 | + $parts = explode(':', $user, 2); |
|
85 | + if ($parts[0] !== 'principal') { |
|
86 | + return; |
|
87 | + } |
|
88 | + |
|
89 | + // don't share with owner |
|
90 | + if ($shareable->getOwner() === $parts[1]) { |
|
91 | + return; |
|
92 | + } |
|
93 | + |
|
94 | + $principal = explode('/', $parts[1], 3); |
|
95 | + if (count($principal) !== 3 || $principal[0] !== 'principals' || !in_array($principal[1], ['users', 'groups'], true)) { |
|
96 | + // Invalid principal |
|
97 | + return; |
|
98 | + } |
|
99 | + |
|
100 | + if (($principal[1] === 'users' && !$this->userManager->userExists($principal[2])) || |
|
101 | + ($principal[1] === 'groups' && !$this->groupManager->groupExists($principal[2]))) { |
|
102 | + // User or group does not exist |
|
103 | + return; |
|
104 | + } |
|
105 | + |
|
106 | + // remove the share if it already exists |
|
107 | + $this->unshare($shareable, $element['href']); |
|
108 | + $access = self::ACCESS_READ; |
|
109 | + if (isset($element['readOnly'])) { |
|
110 | + $access = $element['readOnly'] ? self::ACCESS_READ : self::ACCESS_READ_WRITE; |
|
111 | + } |
|
112 | + |
|
113 | + $query = $this->db->getQueryBuilder(); |
|
114 | + $query->insert('dav_shares') |
|
115 | + ->values([ |
|
116 | + 'principaluri' => $query->createNamedParameter($parts[1]), |
|
117 | + 'type' => $query->createNamedParameter($this->resourceType), |
|
118 | + 'access' => $query->createNamedParameter($access), |
|
119 | + 'resourceid' => $query->createNamedParameter($shareable->getResourceId()) |
|
120 | + ]); |
|
121 | + $query->execute(); |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * @param $resourceId |
|
126 | + */ |
|
127 | + public function deleteAllShares($resourceId) { |
|
128 | + $query = $this->db->getQueryBuilder(); |
|
129 | + $query->delete('dav_shares') |
|
130 | + ->where($query->expr()->eq('resourceid', $query->createNamedParameter($resourceId))) |
|
131 | + ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType))) |
|
132 | + ->execute(); |
|
133 | + } |
|
134 | + |
|
135 | + public function deleteAllSharesByUser($principaluri) { |
|
136 | + $query = $this->db->getQueryBuilder(); |
|
137 | + $query->delete('dav_shares') |
|
138 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principaluri))) |
|
139 | + ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType))) |
|
140 | + ->execute(); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * @param IShareable $shareable |
|
145 | + * @param string $element |
|
146 | + */ |
|
147 | + private function unshare($shareable, $element) { |
|
148 | + $parts = explode(':', $element, 2); |
|
149 | + if ($parts[0] !== 'principal') { |
|
150 | + return; |
|
151 | + } |
|
152 | + |
|
153 | + // don't share with owner |
|
154 | + if ($shareable->getOwner() === $parts[1]) { |
|
155 | + return; |
|
156 | + } |
|
157 | + |
|
158 | + $query = $this->db->getQueryBuilder(); |
|
159 | + $query->delete('dav_shares') |
|
160 | + ->where($query->expr()->eq('resourceid', $query->createNamedParameter($shareable->getResourceId()))) |
|
161 | + ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType))) |
|
162 | + ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($parts[1]))) |
|
163 | + ; |
|
164 | + $query->execute(); |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Returns the list of people whom this resource is shared with. |
|
169 | + * |
|
170 | + * Every element in this array should have the following properties: |
|
171 | + * * href - Often a mailto: address |
|
172 | + * * commonName - Optional, for example a first + last name |
|
173 | + * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
174 | + * * readOnly - boolean |
|
175 | + * * summary - Optional, a description for the share |
|
176 | + * |
|
177 | + * @param int $resourceId |
|
178 | + * @return array |
|
179 | + */ |
|
180 | + public function getShares($resourceId) { |
|
181 | + $query = $this->db->getQueryBuilder(); |
|
182 | + $result = $query->select(['principaluri', 'access']) |
|
183 | + ->from('dav_shares') |
|
184 | + ->where($query->expr()->eq('resourceid', $query->createNamedParameter($resourceId))) |
|
185 | + ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType))) |
|
186 | + ->execute(); |
|
187 | + |
|
188 | + $shares = []; |
|
189 | + while($row = $result->fetch()) { |
|
190 | + $p = $this->principalBackend->getPrincipalByPath($row['principaluri']); |
|
191 | + $shares[]= [ |
|
192 | + 'href' => "principal:${row['principaluri']}", |
|
193 | + 'commonName' => isset($p['{DAV:}displayname']) ? $p['{DAV:}displayname'] : '', |
|
194 | + 'status' => 1, |
|
195 | + 'readOnly' => ((int) $row['access'] === self::ACCESS_READ), |
|
196 | + '{http://owncloud.org/ns}principal' => $row['principaluri'], |
|
197 | + '{http://owncloud.org/ns}group-share' => is_null($p) |
|
198 | + ]; |
|
199 | + } |
|
200 | + |
|
201 | + return $shares; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * For shared resources the sharee is set in the ACL of the resource |
|
206 | + * |
|
207 | + * @param int $resourceId |
|
208 | + * @param array $acl |
|
209 | + * @return array |
|
210 | + */ |
|
211 | + public function applyShareAcl($resourceId, $acl) { |
|
212 | + |
|
213 | + $shares = $this->getShares($resourceId); |
|
214 | + foreach ($shares as $share) { |
|
215 | + $acl[] = [ |
|
216 | + 'privilege' => '{DAV:}read', |
|
217 | + 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
218 | + 'protected' => true, |
|
219 | + ]; |
|
220 | + if (!$share['readOnly']) { |
|
221 | + $acl[] = [ |
|
222 | + 'privilege' => '{DAV:}write', |
|
223 | + 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
224 | + 'protected' => true, |
|
225 | + ]; |
|
226 | + } else if ($this->resourceType === 'calendar') { |
|
227 | + // Allow changing the properties of read only calendars, |
|
228 | + // so users can change the visibility. |
|
229 | + $acl[] = [ |
|
230 | + 'privilege' => '{DAV:}write-properties', |
|
231 | + 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
232 | + 'protected' => true, |
|
233 | + ]; |
|
234 | + } |
|
235 | + } |
|
236 | + return $acl; |
|
237 | + } |
|
238 | 238 | } |
@@ -28,48 +28,48 @@ |
||
28 | 28 | */ |
29 | 29 | interface IShareable extends INode { |
30 | 30 | |
31 | - /** |
|
32 | - * Updates the list of shares. |
|
33 | - * |
|
34 | - * The first array is a list of people that are to be added to the |
|
35 | - * resource. |
|
36 | - * |
|
37 | - * Every element in the add array has the following properties: |
|
38 | - * * href - A url. Usually a mailto: address |
|
39 | - * * commonName - Usually a first and last name, or false |
|
40 | - * * summary - A description of the share, can also be false |
|
41 | - * * readOnly - A boolean value |
|
42 | - * |
|
43 | - * Every element in the remove array is just the address string. |
|
44 | - * |
|
45 | - * @param array $add |
|
46 | - * @param array $remove |
|
47 | - * @return void |
|
48 | - */ |
|
49 | - function updateShares(array $add, array $remove); |
|
31 | + /** |
|
32 | + * Updates the list of shares. |
|
33 | + * |
|
34 | + * The first array is a list of people that are to be added to the |
|
35 | + * resource. |
|
36 | + * |
|
37 | + * Every element in the add array has the following properties: |
|
38 | + * * href - A url. Usually a mailto: address |
|
39 | + * * commonName - Usually a first and last name, or false |
|
40 | + * * summary - A description of the share, can also be false |
|
41 | + * * readOnly - A boolean value |
|
42 | + * |
|
43 | + * Every element in the remove array is just the address string. |
|
44 | + * |
|
45 | + * @param array $add |
|
46 | + * @param array $remove |
|
47 | + * @return void |
|
48 | + */ |
|
49 | + function updateShares(array $add, array $remove); |
|
50 | 50 | |
51 | - /** |
|
52 | - * Returns the list of people whom this resource is shared with. |
|
53 | - * |
|
54 | - * Every element in this array should have the following properties: |
|
55 | - * * href - Often a mailto: address |
|
56 | - * * commonName - Optional, for example a first + last name |
|
57 | - * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
58 | - * * readOnly - boolean |
|
59 | - * * summary - Optional, a description for the share |
|
60 | - * |
|
61 | - * @return array |
|
62 | - */ |
|
63 | - function getShares(); |
|
51 | + /** |
|
52 | + * Returns the list of people whom this resource is shared with. |
|
53 | + * |
|
54 | + * Every element in this array should have the following properties: |
|
55 | + * * href - Often a mailto: address |
|
56 | + * * commonName - Optional, for example a first + last name |
|
57 | + * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
58 | + * * readOnly - boolean |
|
59 | + * * summary - Optional, a description for the share |
|
60 | + * |
|
61 | + * @return array |
|
62 | + */ |
|
63 | + function getShares(); |
|
64 | 64 | |
65 | - /** |
|
66 | - * @return int |
|
67 | - */ |
|
68 | - public function getResourceId(); |
|
65 | + /** |
|
66 | + * @return int |
|
67 | + */ |
|
68 | + public function getResourceId(); |
|
69 | 69 | |
70 | - /** |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - public function getOwner(); |
|
70 | + /** |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + public function getOwner(); |
|
74 | 74 | |
75 | 75 | } |
76 | 76 | \ No newline at end of file |