@@ -43,458 +43,458 @@ |
||
43 | 43 | */ |
44 | 44 | interface IManager { |
45 | 45 | |
46 | - /** |
|
47 | - * Create a Share |
|
48 | - * |
|
49 | - * @param IShare $share |
|
50 | - * @return IShare The share object |
|
51 | - * @throws \Exception |
|
52 | - * @since 9.0.0 |
|
53 | - */ |
|
54 | - public function createShare(IShare $share); |
|
55 | - |
|
56 | - /** |
|
57 | - * Update a share. |
|
58 | - * The target of the share can't be changed this way: use moveShare |
|
59 | - * The share can't be removed this way (permission 0): use deleteShare |
|
60 | - * The state can't be changed this way: use acceptShare |
|
61 | - * |
|
62 | - * @param IShare $share |
|
63 | - * @return IShare The share object |
|
64 | - * @throws \InvalidArgumentException |
|
65 | - * @since 9.0.0 |
|
66 | - */ |
|
67 | - public function updateShare(IShare $share); |
|
68 | - |
|
69 | - /** |
|
70 | - * Accept a share. |
|
71 | - * |
|
72 | - * @param IShare $share |
|
73 | - * @param string $recipientId |
|
74 | - * @return IShare The share object |
|
75 | - * @throws \InvalidArgumentException |
|
76 | - * @since 18.0.0 |
|
77 | - */ |
|
78 | - public function acceptShare(IShare $share, string $recipientId): IShare; |
|
79 | - |
|
80 | - /** |
|
81 | - * Delete a share |
|
82 | - * |
|
83 | - * @param IShare $share |
|
84 | - * @throws ShareNotFound |
|
85 | - * @throws \InvalidArgumentException |
|
86 | - * @since 9.0.0 |
|
87 | - */ |
|
88 | - public function deleteShare(IShare $share); |
|
89 | - |
|
90 | - /** |
|
91 | - * Unshare a file as the recipient. |
|
92 | - * This can be different from a regular delete for example when one of |
|
93 | - * the users in a groups deletes that share. But the provider should |
|
94 | - * handle this. |
|
95 | - * |
|
96 | - * @param IShare $share |
|
97 | - * @param string $recipientId |
|
98 | - * @since 9.0.0 |
|
99 | - */ |
|
100 | - public function deleteFromSelf(IShare $share, $recipientId); |
|
101 | - |
|
102 | - /** |
|
103 | - * Restore the share when it has been deleted |
|
104 | - * Certain share types can be restored when they have been deleted |
|
105 | - * but the provider should properly handle this\ |
|
106 | - * |
|
107 | - * @param IShare $share The share to restore |
|
108 | - * @param string $recipientId The user to restore the share for |
|
109 | - * @return IShare The restored share object |
|
110 | - * @throws GenericShareException In case restoring the share failed |
|
111 | - * |
|
112 | - * @since 14.0.0 |
|
113 | - */ |
|
114 | - public function restoreShare(IShare $share, string $recipientId): IShare; |
|
115 | - |
|
116 | - /** |
|
117 | - * Move the share as a recipient of the share. |
|
118 | - * This is updating the share target. So where the recipient has the share mounted. |
|
119 | - * |
|
120 | - * @param IShare $share |
|
121 | - * @param string $recipientId |
|
122 | - * @return IShare |
|
123 | - * @throws \InvalidArgumentException If $share is a link share or the $recipient does not match |
|
124 | - * @since 9.0.0 |
|
125 | - */ |
|
126 | - public function moveShare(IShare $share, $recipientId); |
|
127 | - |
|
128 | - /** |
|
129 | - * Get all shares shared by (initiated) by the provided user in a folder. |
|
130 | - * |
|
131 | - * @param string $userId |
|
132 | - * @param Folder $node |
|
133 | - * @param bool $reshares |
|
134 | - * @return IShare[][] [$fileId => IShare[], ...] |
|
135 | - * @since 11.0.0 |
|
136 | - */ |
|
137 | - public function getSharesInFolder($userId, Folder $node, $reshares = false); |
|
138 | - |
|
139 | - /** |
|
140 | - * Get shares shared by (initiated) by the provided user. |
|
141 | - * |
|
142 | - * @param string $userId |
|
143 | - * @param int $shareType |
|
144 | - * @param Node|null $path |
|
145 | - * @param bool $reshares |
|
146 | - * @param int $limit The maximum number of returned results, -1 for all results |
|
147 | - * @param int $offset |
|
148 | - * @return IShare[] |
|
149 | - * @since 9.0.0 |
|
150 | - */ |
|
151 | - public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0); |
|
152 | - |
|
153 | - /** |
|
154 | - * Get shares shared with $user. |
|
155 | - * Filter by $node if provided |
|
156 | - * |
|
157 | - * @param string $userId |
|
158 | - * @param int $shareType |
|
159 | - * @param Node|null $node |
|
160 | - * @param int $limit The maximum number of shares returned, -1 for all |
|
161 | - * @param int $offset |
|
162 | - * @return IShare[] |
|
163 | - * @since 9.0.0 |
|
164 | - */ |
|
165 | - public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0); |
|
166 | - |
|
167 | - /** |
|
168 | - * Get deleted shares shared with $user. |
|
169 | - * Filter by $node if provided |
|
170 | - * |
|
171 | - * @param string $userId |
|
172 | - * @param int $shareType |
|
173 | - * @param Node|null $node |
|
174 | - * @param int $limit The maximum number of shares returned, -1 for all |
|
175 | - * @param int $offset |
|
176 | - * @return IShare[] |
|
177 | - * @since 14.0.0 |
|
178 | - */ |
|
179 | - public function getDeletedSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0); |
|
180 | - |
|
181 | - /** |
|
182 | - * Retrieve a share by the share id. |
|
183 | - * If the recipient is set make sure to retrieve the file for that user. |
|
184 | - * This makes sure that if a user has moved/deleted a group share this |
|
185 | - * is reflected. |
|
186 | - * |
|
187 | - * @param string $id |
|
188 | - * @param string|null $recipient userID of the recipient |
|
189 | - * @return IShare |
|
190 | - * @throws ShareNotFound |
|
191 | - * @since 9.0.0 |
|
192 | - */ |
|
193 | - public function getShareById($id, $recipient = null); |
|
194 | - |
|
195 | - /** |
|
196 | - * Get the share by token possible with password |
|
197 | - * |
|
198 | - * @param string $token |
|
199 | - * @return IShare |
|
200 | - * @throws ShareNotFound |
|
201 | - * @since 9.0.0 |
|
202 | - */ |
|
203 | - public function getShareByToken($token); |
|
204 | - |
|
205 | - /** |
|
206 | - * Verify the password of a public share |
|
207 | - * |
|
208 | - * @param IShare $share |
|
209 | - * @param string $password |
|
210 | - * @return bool |
|
211 | - * @since 9.0.0 |
|
212 | - */ |
|
213 | - public function checkPassword(IShare $share, $password); |
|
214 | - |
|
215 | - /** |
|
216 | - * The user with UID is deleted. |
|
217 | - * All share providers have to cleanup the shares with this user as well |
|
218 | - * as shares owned by this user. |
|
219 | - * Shares only initiated by this user are fine. |
|
220 | - * |
|
221 | - * @param string $uid |
|
222 | - * @since 9.1.0 |
|
223 | - */ |
|
224 | - public function userDeleted($uid); |
|
225 | - |
|
226 | - /** |
|
227 | - * The group with $gid is deleted |
|
228 | - * We need to clear up all shares to this group |
|
229 | - * |
|
230 | - * @param string $gid |
|
231 | - * @since 9.1.0 |
|
232 | - */ |
|
233 | - public function groupDeleted($gid); |
|
234 | - |
|
235 | - /** |
|
236 | - * The user $uid is deleted from the group $gid |
|
237 | - * All user specific group shares have to be removed |
|
238 | - * |
|
239 | - * @param string $uid |
|
240 | - * @param string $gid |
|
241 | - * @since 9.1.0 |
|
242 | - */ |
|
243 | - public function userDeletedFromGroup($uid, $gid); |
|
244 | - |
|
245 | - /** |
|
246 | - * Get access list to a path. This means |
|
247 | - * all the users that can access a given path. |
|
248 | - * |
|
249 | - * Consider: |
|
250 | - * -root |
|
251 | - * |-folder1 (23) |
|
252 | - * |-folder2 (32) |
|
253 | - * |-fileA (42) |
|
254 | - * |
|
255 | - * fileA is shared with user1 and user1@server1 |
|
256 | - * folder2 is shared with group2 (user4 is a member of group2) |
|
257 | - * folder1 is shared with user2 (renamed to "folder (1)") and user2@server2 |
|
258 | - * |
|
259 | - * Then the access list to '/folder1/folder2/fileA' with $currentAccess is: |
|
260 | - * [ |
|
261 | - * users => [ |
|
262 | - * 'user1' => ['node_id' => 42, 'node_path' => '/fileA'], |
|
263 | - * 'user4' => ['node_id' => 32, 'node_path' => '/folder2'], |
|
264 | - * 'user2' => ['node_id' => 23, 'node_path' => '/folder (1)'], |
|
265 | - * ], |
|
266 | - * remote => [ |
|
267 | - * 'user1@server1' => ['node_id' => 42, 'token' => 'SeCr3t'], |
|
268 | - * 'user2@server2' => ['node_id' => 23, 'token' => 'FooBaR'], |
|
269 | - * ], |
|
270 | - * public => bool |
|
271 | - * mail => bool |
|
272 | - * ] |
|
273 | - * |
|
274 | - * The access list to '/folder1/folder2/fileA' **without** $currentAccess is: |
|
275 | - * [ |
|
276 | - * users => ['user1', 'user2', 'user4'], |
|
277 | - * remote => bool, |
|
278 | - * public => bool |
|
279 | - * mail => bool |
|
280 | - * ] |
|
281 | - * |
|
282 | - * This is required for encryption/activity |
|
283 | - * |
|
284 | - * @param \OCP\Files\Node $path |
|
285 | - * @param bool $recursive Should we check all parent folders as well |
|
286 | - * @param bool $currentAccess Should the user have currently access to the file |
|
287 | - * @return array |
|
288 | - * @since 12 |
|
289 | - */ |
|
290 | - public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false); |
|
291 | - |
|
292 | - /** |
|
293 | - * Instantiates a new share object. This is to be passed to |
|
294 | - * createShare. |
|
295 | - * |
|
296 | - * @return IShare |
|
297 | - * @since 9.0.0 |
|
298 | - */ |
|
299 | - public function newShare(); |
|
300 | - |
|
301 | - /** |
|
302 | - * Is the share API enabled |
|
303 | - * |
|
304 | - * @return bool |
|
305 | - * @since 9.0.0 |
|
306 | - */ |
|
307 | - public function shareApiEnabled(); |
|
308 | - |
|
309 | - /** |
|
310 | - * Is public link sharing enabled |
|
311 | - * |
|
312 | - * @return bool |
|
313 | - * @since 9.0.0 |
|
314 | - */ |
|
315 | - public function shareApiAllowLinks(); |
|
316 | - |
|
317 | - /** |
|
318 | - * Is password on public link requires |
|
319 | - * |
|
320 | - * @return bool |
|
321 | - * @since 9.0.0 |
|
322 | - */ |
|
323 | - public function shareApiLinkEnforcePassword(); |
|
324 | - |
|
325 | - /** |
|
326 | - * Is default expire date enabled |
|
327 | - * |
|
328 | - * @return bool |
|
329 | - * @since 9.0.0 |
|
330 | - */ |
|
331 | - public function shareApiLinkDefaultExpireDate(); |
|
332 | - |
|
333 | - /** |
|
334 | - * Is default expire date enforced |
|
335 | - *` |
|
336 | - * @return bool |
|
337 | - * @since 9.0.0 |
|
338 | - */ |
|
339 | - public function shareApiLinkDefaultExpireDateEnforced(); |
|
340 | - |
|
341 | - /** |
|
342 | - * Number of default expire days |
|
343 | - * |
|
344 | - * @return int |
|
345 | - * @since 9.0.0 |
|
346 | - */ |
|
347 | - public function shareApiLinkDefaultExpireDays(); |
|
348 | - |
|
349 | - /** |
|
350 | - * Is default internal expire date enabled |
|
351 | - * |
|
352 | - * @return bool |
|
353 | - * @since 22.0.0 |
|
354 | - */ |
|
355 | - public function shareApiInternalDefaultExpireDate(): bool; |
|
356 | - |
|
357 | - /** |
|
358 | - * Is default remote expire date enabled |
|
359 | - * |
|
360 | - * @return bool |
|
361 | - * @since 22.0.0 |
|
362 | - */ |
|
363 | - public function shareApiRemoteDefaultExpireDate(): bool; |
|
364 | - |
|
365 | - /** |
|
366 | - * Is default expire date enforced |
|
367 | - * |
|
368 | - * @return bool |
|
369 | - * @since 22.0.0 |
|
370 | - */ |
|
371 | - public function shareApiInternalDefaultExpireDateEnforced(): bool; |
|
372 | - |
|
373 | - /** |
|
374 | - * Is default expire date enforced for remote shares |
|
375 | - * |
|
376 | - * @return bool |
|
377 | - * @since 22.0.0 |
|
378 | - */ |
|
379 | - public function shareApiRemoteDefaultExpireDateEnforced(): bool; |
|
380 | - |
|
381 | - /** |
|
382 | - * Number of default expire days |
|
383 | - * |
|
384 | - * @return int |
|
385 | - * @since 22.0.0 |
|
386 | - */ |
|
387 | - public function shareApiInternalDefaultExpireDays(): int; |
|
388 | - |
|
389 | - /** |
|
390 | - * Number of default expire days for remote shares |
|
391 | - * |
|
392 | - * @return int |
|
393 | - * @since 22.0.0 |
|
394 | - */ |
|
395 | - public function shareApiRemoteDefaultExpireDays(): int; |
|
396 | - |
|
397 | - /** |
|
398 | - * Allow public upload on link shares |
|
399 | - * |
|
400 | - * @return bool |
|
401 | - * @since 9.0.0 |
|
402 | - */ |
|
403 | - public function shareApiLinkAllowPublicUpload(); |
|
404 | - |
|
405 | - /** |
|
406 | - * check if user can only share with group members |
|
407 | - * @return bool |
|
408 | - * @since 9.0.0 |
|
409 | - */ |
|
410 | - public function shareWithGroupMembersOnly(); |
|
411 | - |
|
412 | - /** |
|
413 | - * Check if users can share with groups |
|
414 | - * @return bool |
|
415 | - * @since 9.0.1 |
|
416 | - */ |
|
417 | - public function allowGroupSharing(); |
|
418 | - |
|
419 | - /** |
|
420 | - * Check if user enumeration is allowed |
|
421 | - * |
|
422 | - * @return bool |
|
423 | - * @since 19.0.0 |
|
424 | - */ |
|
425 | - public function allowEnumeration(): bool; |
|
426 | - |
|
427 | - /** |
|
428 | - * Check if user enumeration is limited to the users groups |
|
429 | - * |
|
430 | - * @return bool |
|
431 | - * @since 19.0.0 |
|
432 | - */ |
|
433 | - public function limitEnumerationToGroups(): bool; |
|
434 | - |
|
435 | - /** |
|
436 | - * Check if user enumeration is limited to the phonebook matches |
|
437 | - * |
|
438 | - * @return bool |
|
439 | - * @since 21.0.1 |
|
440 | - */ |
|
441 | - public function limitEnumerationToPhone(): bool; |
|
442 | - |
|
443 | - /** |
|
444 | - * Check if user enumeration is allowed to return on full match |
|
445 | - * |
|
446 | - * @return bool |
|
447 | - * @since 21.0.1 |
|
448 | - */ |
|
449 | - public function allowEnumerationFullMatch(): bool; |
|
450 | - |
|
451 | - /** |
|
452 | - * Check if sharing is disabled for the given user |
|
453 | - * |
|
454 | - * @param string $userId |
|
455 | - * @return bool |
|
456 | - * @since 9.0.0 |
|
457 | - */ |
|
458 | - public function sharingDisabledForUser($userId); |
|
459 | - |
|
460 | - /** |
|
461 | - * Check if outgoing server2server shares are allowed |
|
462 | - * @return bool |
|
463 | - * @since 9.0.0 |
|
464 | - */ |
|
465 | - public function outgoingServer2ServerSharesAllowed(); |
|
466 | - |
|
467 | - /** |
|
468 | - * Check if outgoing server2server shares are allowed |
|
469 | - * @return bool |
|
470 | - * @since 14.0.0 |
|
471 | - */ |
|
472 | - public function outgoingServer2ServerGroupSharesAllowed(); |
|
473 | - |
|
474 | - |
|
475 | - /** |
|
476 | - * Check if a given share provider exists |
|
477 | - * @param int $shareType |
|
478 | - * @return bool |
|
479 | - * @since 11.0.0 |
|
480 | - */ |
|
481 | - public function shareProviderExists($shareType); |
|
482 | - |
|
483 | - /** |
|
484 | - * @param string $shareProviderClass |
|
485 | - * @since 21.0.0 |
|
486 | - */ |
|
487 | - public function registerShareProvider(string $shareProviderClass): void; |
|
488 | - |
|
489 | - /** |
|
490 | - * @Internal |
|
491 | - * |
|
492 | - * Get all the shares as iterable to reduce memory overhead |
|
493 | - * Note, since this opens up database cursors the iterable should |
|
494 | - * be fully itterated. |
|
495 | - * |
|
496 | - * @return iterable |
|
497 | - * @since 18.0.0 |
|
498 | - */ |
|
499 | - public function getAllShares(): iterable; |
|
46 | + /** |
|
47 | + * Create a Share |
|
48 | + * |
|
49 | + * @param IShare $share |
|
50 | + * @return IShare The share object |
|
51 | + * @throws \Exception |
|
52 | + * @since 9.0.0 |
|
53 | + */ |
|
54 | + public function createShare(IShare $share); |
|
55 | + |
|
56 | + /** |
|
57 | + * Update a share. |
|
58 | + * The target of the share can't be changed this way: use moveShare |
|
59 | + * The share can't be removed this way (permission 0): use deleteShare |
|
60 | + * The state can't be changed this way: use acceptShare |
|
61 | + * |
|
62 | + * @param IShare $share |
|
63 | + * @return IShare The share object |
|
64 | + * @throws \InvalidArgumentException |
|
65 | + * @since 9.0.0 |
|
66 | + */ |
|
67 | + public function updateShare(IShare $share); |
|
68 | + |
|
69 | + /** |
|
70 | + * Accept a share. |
|
71 | + * |
|
72 | + * @param IShare $share |
|
73 | + * @param string $recipientId |
|
74 | + * @return IShare The share object |
|
75 | + * @throws \InvalidArgumentException |
|
76 | + * @since 18.0.0 |
|
77 | + */ |
|
78 | + public function acceptShare(IShare $share, string $recipientId): IShare; |
|
79 | + |
|
80 | + /** |
|
81 | + * Delete a share |
|
82 | + * |
|
83 | + * @param IShare $share |
|
84 | + * @throws ShareNotFound |
|
85 | + * @throws \InvalidArgumentException |
|
86 | + * @since 9.0.0 |
|
87 | + */ |
|
88 | + public function deleteShare(IShare $share); |
|
89 | + |
|
90 | + /** |
|
91 | + * Unshare a file as the recipient. |
|
92 | + * This can be different from a regular delete for example when one of |
|
93 | + * the users in a groups deletes that share. But the provider should |
|
94 | + * handle this. |
|
95 | + * |
|
96 | + * @param IShare $share |
|
97 | + * @param string $recipientId |
|
98 | + * @since 9.0.0 |
|
99 | + */ |
|
100 | + public function deleteFromSelf(IShare $share, $recipientId); |
|
101 | + |
|
102 | + /** |
|
103 | + * Restore the share when it has been deleted |
|
104 | + * Certain share types can be restored when they have been deleted |
|
105 | + * but the provider should properly handle this\ |
|
106 | + * |
|
107 | + * @param IShare $share The share to restore |
|
108 | + * @param string $recipientId The user to restore the share for |
|
109 | + * @return IShare The restored share object |
|
110 | + * @throws GenericShareException In case restoring the share failed |
|
111 | + * |
|
112 | + * @since 14.0.0 |
|
113 | + */ |
|
114 | + public function restoreShare(IShare $share, string $recipientId): IShare; |
|
115 | + |
|
116 | + /** |
|
117 | + * Move the share as a recipient of the share. |
|
118 | + * This is updating the share target. So where the recipient has the share mounted. |
|
119 | + * |
|
120 | + * @param IShare $share |
|
121 | + * @param string $recipientId |
|
122 | + * @return IShare |
|
123 | + * @throws \InvalidArgumentException If $share is a link share or the $recipient does not match |
|
124 | + * @since 9.0.0 |
|
125 | + */ |
|
126 | + public function moveShare(IShare $share, $recipientId); |
|
127 | + |
|
128 | + /** |
|
129 | + * Get all shares shared by (initiated) by the provided user in a folder. |
|
130 | + * |
|
131 | + * @param string $userId |
|
132 | + * @param Folder $node |
|
133 | + * @param bool $reshares |
|
134 | + * @return IShare[][] [$fileId => IShare[], ...] |
|
135 | + * @since 11.0.0 |
|
136 | + */ |
|
137 | + public function getSharesInFolder($userId, Folder $node, $reshares = false); |
|
138 | + |
|
139 | + /** |
|
140 | + * Get shares shared by (initiated) by the provided user. |
|
141 | + * |
|
142 | + * @param string $userId |
|
143 | + * @param int $shareType |
|
144 | + * @param Node|null $path |
|
145 | + * @param bool $reshares |
|
146 | + * @param int $limit The maximum number of returned results, -1 for all results |
|
147 | + * @param int $offset |
|
148 | + * @return IShare[] |
|
149 | + * @since 9.0.0 |
|
150 | + */ |
|
151 | + public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0); |
|
152 | + |
|
153 | + /** |
|
154 | + * Get shares shared with $user. |
|
155 | + * Filter by $node if provided |
|
156 | + * |
|
157 | + * @param string $userId |
|
158 | + * @param int $shareType |
|
159 | + * @param Node|null $node |
|
160 | + * @param int $limit The maximum number of shares returned, -1 for all |
|
161 | + * @param int $offset |
|
162 | + * @return IShare[] |
|
163 | + * @since 9.0.0 |
|
164 | + */ |
|
165 | + public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0); |
|
166 | + |
|
167 | + /** |
|
168 | + * Get deleted shares shared with $user. |
|
169 | + * Filter by $node if provided |
|
170 | + * |
|
171 | + * @param string $userId |
|
172 | + * @param int $shareType |
|
173 | + * @param Node|null $node |
|
174 | + * @param int $limit The maximum number of shares returned, -1 for all |
|
175 | + * @param int $offset |
|
176 | + * @return IShare[] |
|
177 | + * @since 14.0.0 |
|
178 | + */ |
|
179 | + public function getDeletedSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0); |
|
180 | + |
|
181 | + /** |
|
182 | + * Retrieve a share by the share id. |
|
183 | + * If the recipient is set make sure to retrieve the file for that user. |
|
184 | + * This makes sure that if a user has moved/deleted a group share this |
|
185 | + * is reflected. |
|
186 | + * |
|
187 | + * @param string $id |
|
188 | + * @param string|null $recipient userID of the recipient |
|
189 | + * @return IShare |
|
190 | + * @throws ShareNotFound |
|
191 | + * @since 9.0.0 |
|
192 | + */ |
|
193 | + public function getShareById($id, $recipient = null); |
|
194 | + |
|
195 | + /** |
|
196 | + * Get the share by token possible with password |
|
197 | + * |
|
198 | + * @param string $token |
|
199 | + * @return IShare |
|
200 | + * @throws ShareNotFound |
|
201 | + * @since 9.0.0 |
|
202 | + */ |
|
203 | + public function getShareByToken($token); |
|
204 | + |
|
205 | + /** |
|
206 | + * Verify the password of a public share |
|
207 | + * |
|
208 | + * @param IShare $share |
|
209 | + * @param string $password |
|
210 | + * @return bool |
|
211 | + * @since 9.0.0 |
|
212 | + */ |
|
213 | + public function checkPassword(IShare $share, $password); |
|
214 | + |
|
215 | + /** |
|
216 | + * The user with UID is deleted. |
|
217 | + * All share providers have to cleanup the shares with this user as well |
|
218 | + * as shares owned by this user. |
|
219 | + * Shares only initiated by this user are fine. |
|
220 | + * |
|
221 | + * @param string $uid |
|
222 | + * @since 9.1.0 |
|
223 | + */ |
|
224 | + public function userDeleted($uid); |
|
225 | + |
|
226 | + /** |
|
227 | + * The group with $gid is deleted |
|
228 | + * We need to clear up all shares to this group |
|
229 | + * |
|
230 | + * @param string $gid |
|
231 | + * @since 9.1.0 |
|
232 | + */ |
|
233 | + public function groupDeleted($gid); |
|
234 | + |
|
235 | + /** |
|
236 | + * The user $uid is deleted from the group $gid |
|
237 | + * All user specific group shares have to be removed |
|
238 | + * |
|
239 | + * @param string $uid |
|
240 | + * @param string $gid |
|
241 | + * @since 9.1.0 |
|
242 | + */ |
|
243 | + public function userDeletedFromGroup($uid, $gid); |
|
244 | + |
|
245 | + /** |
|
246 | + * Get access list to a path. This means |
|
247 | + * all the users that can access a given path. |
|
248 | + * |
|
249 | + * Consider: |
|
250 | + * -root |
|
251 | + * |-folder1 (23) |
|
252 | + * |-folder2 (32) |
|
253 | + * |-fileA (42) |
|
254 | + * |
|
255 | + * fileA is shared with user1 and user1@server1 |
|
256 | + * folder2 is shared with group2 (user4 is a member of group2) |
|
257 | + * folder1 is shared with user2 (renamed to "folder (1)") and user2@server2 |
|
258 | + * |
|
259 | + * Then the access list to '/folder1/folder2/fileA' with $currentAccess is: |
|
260 | + * [ |
|
261 | + * users => [ |
|
262 | + * 'user1' => ['node_id' => 42, 'node_path' => '/fileA'], |
|
263 | + * 'user4' => ['node_id' => 32, 'node_path' => '/folder2'], |
|
264 | + * 'user2' => ['node_id' => 23, 'node_path' => '/folder (1)'], |
|
265 | + * ], |
|
266 | + * remote => [ |
|
267 | + * 'user1@server1' => ['node_id' => 42, 'token' => 'SeCr3t'], |
|
268 | + * 'user2@server2' => ['node_id' => 23, 'token' => 'FooBaR'], |
|
269 | + * ], |
|
270 | + * public => bool |
|
271 | + * mail => bool |
|
272 | + * ] |
|
273 | + * |
|
274 | + * The access list to '/folder1/folder2/fileA' **without** $currentAccess is: |
|
275 | + * [ |
|
276 | + * users => ['user1', 'user2', 'user4'], |
|
277 | + * remote => bool, |
|
278 | + * public => bool |
|
279 | + * mail => bool |
|
280 | + * ] |
|
281 | + * |
|
282 | + * This is required for encryption/activity |
|
283 | + * |
|
284 | + * @param \OCP\Files\Node $path |
|
285 | + * @param bool $recursive Should we check all parent folders as well |
|
286 | + * @param bool $currentAccess Should the user have currently access to the file |
|
287 | + * @return array |
|
288 | + * @since 12 |
|
289 | + */ |
|
290 | + public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false); |
|
291 | + |
|
292 | + /** |
|
293 | + * Instantiates a new share object. This is to be passed to |
|
294 | + * createShare. |
|
295 | + * |
|
296 | + * @return IShare |
|
297 | + * @since 9.0.0 |
|
298 | + */ |
|
299 | + public function newShare(); |
|
300 | + |
|
301 | + /** |
|
302 | + * Is the share API enabled |
|
303 | + * |
|
304 | + * @return bool |
|
305 | + * @since 9.0.0 |
|
306 | + */ |
|
307 | + public function shareApiEnabled(); |
|
308 | + |
|
309 | + /** |
|
310 | + * Is public link sharing enabled |
|
311 | + * |
|
312 | + * @return bool |
|
313 | + * @since 9.0.0 |
|
314 | + */ |
|
315 | + public function shareApiAllowLinks(); |
|
316 | + |
|
317 | + /** |
|
318 | + * Is password on public link requires |
|
319 | + * |
|
320 | + * @return bool |
|
321 | + * @since 9.0.0 |
|
322 | + */ |
|
323 | + public function shareApiLinkEnforcePassword(); |
|
324 | + |
|
325 | + /** |
|
326 | + * Is default expire date enabled |
|
327 | + * |
|
328 | + * @return bool |
|
329 | + * @since 9.0.0 |
|
330 | + */ |
|
331 | + public function shareApiLinkDefaultExpireDate(); |
|
332 | + |
|
333 | + /** |
|
334 | + * Is default expire date enforced |
|
335 | + *` |
|
336 | + * @return bool |
|
337 | + * @since 9.0.0 |
|
338 | + */ |
|
339 | + public function shareApiLinkDefaultExpireDateEnforced(); |
|
340 | + |
|
341 | + /** |
|
342 | + * Number of default expire days |
|
343 | + * |
|
344 | + * @return int |
|
345 | + * @since 9.0.0 |
|
346 | + */ |
|
347 | + public function shareApiLinkDefaultExpireDays(); |
|
348 | + |
|
349 | + /** |
|
350 | + * Is default internal expire date enabled |
|
351 | + * |
|
352 | + * @return bool |
|
353 | + * @since 22.0.0 |
|
354 | + */ |
|
355 | + public function shareApiInternalDefaultExpireDate(): bool; |
|
356 | + |
|
357 | + /** |
|
358 | + * Is default remote expire date enabled |
|
359 | + * |
|
360 | + * @return bool |
|
361 | + * @since 22.0.0 |
|
362 | + */ |
|
363 | + public function shareApiRemoteDefaultExpireDate(): bool; |
|
364 | + |
|
365 | + /** |
|
366 | + * Is default expire date enforced |
|
367 | + * |
|
368 | + * @return bool |
|
369 | + * @since 22.0.0 |
|
370 | + */ |
|
371 | + public function shareApiInternalDefaultExpireDateEnforced(): bool; |
|
372 | + |
|
373 | + /** |
|
374 | + * Is default expire date enforced for remote shares |
|
375 | + * |
|
376 | + * @return bool |
|
377 | + * @since 22.0.0 |
|
378 | + */ |
|
379 | + public function shareApiRemoteDefaultExpireDateEnforced(): bool; |
|
380 | + |
|
381 | + /** |
|
382 | + * Number of default expire days |
|
383 | + * |
|
384 | + * @return int |
|
385 | + * @since 22.0.0 |
|
386 | + */ |
|
387 | + public function shareApiInternalDefaultExpireDays(): int; |
|
388 | + |
|
389 | + /** |
|
390 | + * Number of default expire days for remote shares |
|
391 | + * |
|
392 | + * @return int |
|
393 | + * @since 22.0.0 |
|
394 | + */ |
|
395 | + public function shareApiRemoteDefaultExpireDays(): int; |
|
396 | + |
|
397 | + /** |
|
398 | + * Allow public upload on link shares |
|
399 | + * |
|
400 | + * @return bool |
|
401 | + * @since 9.0.0 |
|
402 | + */ |
|
403 | + public function shareApiLinkAllowPublicUpload(); |
|
404 | + |
|
405 | + /** |
|
406 | + * check if user can only share with group members |
|
407 | + * @return bool |
|
408 | + * @since 9.0.0 |
|
409 | + */ |
|
410 | + public function shareWithGroupMembersOnly(); |
|
411 | + |
|
412 | + /** |
|
413 | + * Check if users can share with groups |
|
414 | + * @return bool |
|
415 | + * @since 9.0.1 |
|
416 | + */ |
|
417 | + public function allowGroupSharing(); |
|
418 | + |
|
419 | + /** |
|
420 | + * Check if user enumeration is allowed |
|
421 | + * |
|
422 | + * @return bool |
|
423 | + * @since 19.0.0 |
|
424 | + */ |
|
425 | + public function allowEnumeration(): bool; |
|
426 | + |
|
427 | + /** |
|
428 | + * Check if user enumeration is limited to the users groups |
|
429 | + * |
|
430 | + * @return bool |
|
431 | + * @since 19.0.0 |
|
432 | + */ |
|
433 | + public function limitEnumerationToGroups(): bool; |
|
434 | + |
|
435 | + /** |
|
436 | + * Check if user enumeration is limited to the phonebook matches |
|
437 | + * |
|
438 | + * @return bool |
|
439 | + * @since 21.0.1 |
|
440 | + */ |
|
441 | + public function limitEnumerationToPhone(): bool; |
|
442 | + |
|
443 | + /** |
|
444 | + * Check if user enumeration is allowed to return on full match |
|
445 | + * |
|
446 | + * @return bool |
|
447 | + * @since 21.0.1 |
|
448 | + */ |
|
449 | + public function allowEnumerationFullMatch(): bool; |
|
450 | + |
|
451 | + /** |
|
452 | + * Check if sharing is disabled for the given user |
|
453 | + * |
|
454 | + * @param string $userId |
|
455 | + * @return bool |
|
456 | + * @since 9.0.0 |
|
457 | + */ |
|
458 | + public function sharingDisabledForUser($userId); |
|
459 | + |
|
460 | + /** |
|
461 | + * Check if outgoing server2server shares are allowed |
|
462 | + * @return bool |
|
463 | + * @since 9.0.0 |
|
464 | + */ |
|
465 | + public function outgoingServer2ServerSharesAllowed(); |
|
466 | + |
|
467 | + /** |
|
468 | + * Check if outgoing server2server shares are allowed |
|
469 | + * @return bool |
|
470 | + * @since 14.0.0 |
|
471 | + */ |
|
472 | + public function outgoingServer2ServerGroupSharesAllowed(); |
|
473 | + |
|
474 | + |
|
475 | + /** |
|
476 | + * Check if a given share provider exists |
|
477 | + * @param int $shareType |
|
478 | + * @return bool |
|
479 | + * @since 11.0.0 |
|
480 | + */ |
|
481 | + public function shareProviderExists($shareType); |
|
482 | + |
|
483 | + /** |
|
484 | + * @param string $shareProviderClass |
|
485 | + * @since 21.0.0 |
|
486 | + */ |
|
487 | + public function registerShareProvider(string $shareProviderClass): void; |
|
488 | + |
|
489 | + /** |
|
490 | + * @Internal |
|
491 | + * |
|
492 | + * Get all the shares as iterable to reduce memory overhead |
|
493 | + * Note, since this opens up database cursors the iterable should |
|
494 | + * be fully itterated. |
|
495 | + * |
|
496 | + * @return iterable |
|
497 | + * @since 18.0.0 |
|
498 | + */ |
|
499 | + public function getAllShares(): iterable; |
|
500 | 500 | } |
@@ -76,1404 +76,1404 @@ |
||
76 | 76 | use Psr\Log\LoggerInterface; |
77 | 77 | |
78 | 78 | class OC_Util { |
79 | - public static $scripts = []; |
|
80 | - public static $styles = []; |
|
81 | - public static $headers = []; |
|
82 | - private static $rootMounted = false; |
|
83 | - private static $fsSetup = false; |
|
84 | - |
|
85 | - /** @var array Local cache of version.php */ |
|
86 | - private static $versionCache = null; |
|
87 | - |
|
88 | - protected static function getAppManager() { |
|
89 | - return \OC::$server->getAppManager(); |
|
90 | - } |
|
91 | - |
|
92 | - private static function initLocalStorageRootFS() { |
|
93 | - // mount local file backend as root |
|
94 | - $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data"); |
|
95 | - //first set up the local "root" storage |
|
96 | - \OC\Files\Filesystem::initMountManager(); |
|
97 | - if (!self::$rootMounted) { |
|
98 | - \OC\Files\Filesystem::mount(LocalRootStorage::class, ['datadir' => $configDataDirectory], '/'); |
|
99 | - self::$rootMounted = true; |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * mounting an object storage as the root fs will in essence remove the |
|
105 | - * necessity of a data folder being present. |
|
106 | - * TODO make home storage aware of this and use the object storage instead of local disk access |
|
107 | - * |
|
108 | - * @param array $config containing 'class' and optional 'arguments' |
|
109 | - * @suppress PhanDeprecatedFunction |
|
110 | - */ |
|
111 | - private static function initObjectStoreRootFS($config) { |
|
112 | - // check misconfiguration |
|
113 | - if (empty($config['class'])) { |
|
114 | - \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR); |
|
115 | - } |
|
116 | - if (!isset($config['arguments'])) { |
|
117 | - $config['arguments'] = []; |
|
118 | - } |
|
119 | - |
|
120 | - // instantiate object store implementation |
|
121 | - $name = $config['class']; |
|
122 | - if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
123 | - $segments = explode('\\', $name); |
|
124 | - OC_App::loadApp(strtolower($segments[1])); |
|
125 | - } |
|
126 | - $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
127 | - // mount with plain / root object store implementation |
|
128 | - $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
129 | - |
|
130 | - // mount object storage as root |
|
131 | - \OC\Files\Filesystem::initMountManager(); |
|
132 | - if (!self::$rootMounted) { |
|
133 | - \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
134 | - self::$rootMounted = true; |
|
135 | - } |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * mounting an object storage as the root fs will in essence remove the |
|
140 | - * necessity of a data folder being present. |
|
141 | - * |
|
142 | - * @param array $config containing 'class' and optional 'arguments' |
|
143 | - * @suppress PhanDeprecatedFunction |
|
144 | - */ |
|
145 | - private static function initObjectStoreMultibucketRootFS($config) { |
|
146 | - // check misconfiguration |
|
147 | - if (empty($config['class'])) { |
|
148 | - \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR); |
|
149 | - } |
|
150 | - if (!isset($config['arguments'])) { |
|
151 | - $config['arguments'] = []; |
|
152 | - } |
|
153 | - |
|
154 | - // instantiate object store implementation |
|
155 | - $name = $config['class']; |
|
156 | - if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
157 | - $segments = explode('\\', $name); |
|
158 | - OC_App::loadApp(strtolower($segments[1])); |
|
159 | - } |
|
160 | - |
|
161 | - if (!isset($config['arguments']['bucket'])) { |
|
162 | - $config['arguments']['bucket'] = ''; |
|
163 | - } |
|
164 | - // put the root FS always in first bucket for multibucket configuration |
|
165 | - $config['arguments']['bucket'] .= '0'; |
|
166 | - |
|
167 | - $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
168 | - // mount with plain / root object store implementation |
|
169 | - $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
170 | - |
|
171 | - // mount object storage as root |
|
172 | - \OC\Files\Filesystem::initMountManager(); |
|
173 | - if (!self::$rootMounted) { |
|
174 | - \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
175 | - self::$rootMounted = true; |
|
176 | - } |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Can be set up |
|
181 | - * |
|
182 | - * @param string $user |
|
183 | - * @return boolean |
|
184 | - * @description configure the initial filesystem based on the configuration |
|
185 | - * @suppress PhanDeprecatedFunction |
|
186 | - * @suppress PhanAccessMethodInternal |
|
187 | - */ |
|
188 | - public static function setupFS($user = '') { |
|
189 | - //setting up the filesystem twice can only lead to trouble |
|
190 | - if (self::$fsSetup) { |
|
191 | - return false; |
|
192 | - } |
|
193 | - |
|
194 | - \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem'); |
|
195 | - |
|
196 | - // If we are not forced to load a specific user we load the one that is logged in |
|
197 | - if ($user === null) { |
|
198 | - $user = ''; |
|
199 | - } elseif ($user == "" && \OC::$server->getUserSession()->isLoggedIn()) { |
|
200 | - $user = OC_User::getUser(); |
|
201 | - } |
|
202 | - |
|
203 | - // load all filesystem apps before, so no setup-hook gets lost |
|
204 | - OC_App::loadApps(['filesystem']); |
|
205 | - |
|
206 | - // the filesystem will finish when $user is not empty, |
|
207 | - // mark fs setup here to avoid doing the setup from loading |
|
208 | - // OC_Filesystem |
|
209 | - if ($user != '') { |
|
210 | - self::$fsSetup = true; |
|
211 | - } |
|
212 | - |
|
213 | - \OC\Files\Filesystem::initMountManager(); |
|
214 | - |
|
215 | - $prevLogging = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
216 | - \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
217 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { |
|
218 | - /** @var \OC\Files\Storage\Common $storage */ |
|
219 | - $storage->setMountOptions($mount->getOptions()); |
|
220 | - } |
|
221 | - return $storage; |
|
222 | - }); |
|
223 | - |
|
224 | - \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
225 | - if (!$mount->getOption('enable_sharing', true)) { |
|
226 | - return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
227 | - 'storage' => $storage, |
|
228 | - 'mask' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE |
|
229 | - ]); |
|
230 | - } |
|
231 | - return $storage; |
|
232 | - }); |
|
233 | - |
|
234 | - // install storage availability wrapper, before most other wrappers |
|
235 | - \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, \OCP\Files\Storage\IStorage $storage) { |
|
236 | - if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
237 | - return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); |
|
238 | - } |
|
239 | - return $storage; |
|
240 | - }); |
|
241 | - |
|
242 | - \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
243 | - if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
244 | - return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); |
|
245 | - } |
|
246 | - return $storage; |
|
247 | - }); |
|
248 | - |
|
249 | - \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
250 | - // set up quota for home storages, even for other users |
|
251 | - // which can happen when using sharing |
|
252 | - |
|
253 | - /** |
|
254 | - * @var \OC\Files\Storage\Storage $storage |
|
255 | - */ |
|
256 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Home') |
|
257 | - || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage') |
|
258 | - ) { |
|
259 | - /** @var \OC\Files\Storage\Home $storage */ |
|
260 | - if (is_object($storage->getUser())) { |
|
261 | - $quota = OC_Util::getUserQuota($storage->getUser()); |
|
262 | - if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
263 | - return new \OC\Files\Storage\Wrapper\Quota(['storage' => $storage, 'quota' => $quota, 'root' => 'files']); |
|
264 | - } |
|
265 | - } |
|
266 | - } |
|
267 | - |
|
268 | - return $storage; |
|
269 | - }); |
|
270 | - |
|
271 | - \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
272 | - /* |
|
79 | + public static $scripts = []; |
|
80 | + public static $styles = []; |
|
81 | + public static $headers = []; |
|
82 | + private static $rootMounted = false; |
|
83 | + private static $fsSetup = false; |
|
84 | + |
|
85 | + /** @var array Local cache of version.php */ |
|
86 | + private static $versionCache = null; |
|
87 | + |
|
88 | + protected static function getAppManager() { |
|
89 | + return \OC::$server->getAppManager(); |
|
90 | + } |
|
91 | + |
|
92 | + private static function initLocalStorageRootFS() { |
|
93 | + // mount local file backend as root |
|
94 | + $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data"); |
|
95 | + //first set up the local "root" storage |
|
96 | + \OC\Files\Filesystem::initMountManager(); |
|
97 | + if (!self::$rootMounted) { |
|
98 | + \OC\Files\Filesystem::mount(LocalRootStorage::class, ['datadir' => $configDataDirectory], '/'); |
|
99 | + self::$rootMounted = true; |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * mounting an object storage as the root fs will in essence remove the |
|
105 | + * necessity of a data folder being present. |
|
106 | + * TODO make home storage aware of this and use the object storage instead of local disk access |
|
107 | + * |
|
108 | + * @param array $config containing 'class' and optional 'arguments' |
|
109 | + * @suppress PhanDeprecatedFunction |
|
110 | + */ |
|
111 | + private static function initObjectStoreRootFS($config) { |
|
112 | + // check misconfiguration |
|
113 | + if (empty($config['class'])) { |
|
114 | + \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR); |
|
115 | + } |
|
116 | + if (!isset($config['arguments'])) { |
|
117 | + $config['arguments'] = []; |
|
118 | + } |
|
119 | + |
|
120 | + // instantiate object store implementation |
|
121 | + $name = $config['class']; |
|
122 | + if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
123 | + $segments = explode('\\', $name); |
|
124 | + OC_App::loadApp(strtolower($segments[1])); |
|
125 | + } |
|
126 | + $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
127 | + // mount with plain / root object store implementation |
|
128 | + $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
129 | + |
|
130 | + // mount object storage as root |
|
131 | + \OC\Files\Filesystem::initMountManager(); |
|
132 | + if (!self::$rootMounted) { |
|
133 | + \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
134 | + self::$rootMounted = true; |
|
135 | + } |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * mounting an object storage as the root fs will in essence remove the |
|
140 | + * necessity of a data folder being present. |
|
141 | + * |
|
142 | + * @param array $config containing 'class' and optional 'arguments' |
|
143 | + * @suppress PhanDeprecatedFunction |
|
144 | + */ |
|
145 | + private static function initObjectStoreMultibucketRootFS($config) { |
|
146 | + // check misconfiguration |
|
147 | + if (empty($config['class'])) { |
|
148 | + \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR); |
|
149 | + } |
|
150 | + if (!isset($config['arguments'])) { |
|
151 | + $config['arguments'] = []; |
|
152 | + } |
|
153 | + |
|
154 | + // instantiate object store implementation |
|
155 | + $name = $config['class']; |
|
156 | + if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
157 | + $segments = explode('\\', $name); |
|
158 | + OC_App::loadApp(strtolower($segments[1])); |
|
159 | + } |
|
160 | + |
|
161 | + if (!isset($config['arguments']['bucket'])) { |
|
162 | + $config['arguments']['bucket'] = ''; |
|
163 | + } |
|
164 | + // put the root FS always in first bucket for multibucket configuration |
|
165 | + $config['arguments']['bucket'] .= '0'; |
|
166 | + |
|
167 | + $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
168 | + // mount with plain / root object store implementation |
|
169 | + $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
170 | + |
|
171 | + // mount object storage as root |
|
172 | + \OC\Files\Filesystem::initMountManager(); |
|
173 | + if (!self::$rootMounted) { |
|
174 | + \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
175 | + self::$rootMounted = true; |
|
176 | + } |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Can be set up |
|
181 | + * |
|
182 | + * @param string $user |
|
183 | + * @return boolean |
|
184 | + * @description configure the initial filesystem based on the configuration |
|
185 | + * @suppress PhanDeprecatedFunction |
|
186 | + * @suppress PhanAccessMethodInternal |
|
187 | + */ |
|
188 | + public static function setupFS($user = '') { |
|
189 | + //setting up the filesystem twice can only lead to trouble |
|
190 | + if (self::$fsSetup) { |
|
191 | + return false; |
|
192 | + } |
|
193 | + |
|
194 | + \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem'); |
|
195 | + |
|
196 | + // If we are not forced to load a specific user we load the one that is logged in |
|
197 | + if ($user === null) { |
|
198 | + $user = ''; |
|
199 | + } elseif ($user == "" && \OC::$server->getUserSession()->isLoggedIn()) { |
|
200 | + $user = OC_User::getUser(); |
|
201 | + } |
|
202 | + |
|
203 | + // load all filesystem apps before, so no setup-hook gets lost |
|
204 | + OC_App::loadApps(['filesystem']); |
|
205 | + |
|
206 | + // the filesystem will finish when $user is not empty, |
|
207 | + // mark fs setup here to avoid doing the setup from loading |
|
208 | + // OC_Filesystem |
|
209 | + if ($user != '') { |
|
210 | + self::$fsSetup = true; |
|
211 | + } |
|
212 | + |
|
213 | + \OC\Files\Filesystem::initMountManager(); |
|
214 | + |
|
215 | + $prevLogging = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
216 | + \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
217 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { |
|
218 | + /** @var \OC\Files\Storage\Common $storage */ |
|
219 | + $storage->setMountOptions($mount->getOptions()); |
|
220 | + } |
|
221 | + return $storage; |
|
222 | + }); |
|
223 | + |
|
224 | + \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
225 | + if (!$mount->getOption('enable_sharing', true)) { |
|
226 | + return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
227 | + 'storage' => $storage, |
|
228 | + 'mask' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE |
|
229 | + ]); |
|
230 | + } |
|
231 | + return $storage; |
|
232 | + }); |
|
233 | + |
|
234 | + // install storage availability wrapper, before most other wrappers |
|
235 | + \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, \OCP\Files\Storage\IStorage $storage) { |
|
236 | + if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
237 | + return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); |
|
238 | + } |
|
239 | + return $storage; |
|
240 | + }); |
|
241 | + |
|
242 | + \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
243 | + if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
244 | + return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); |
|
245 | + } |
|
246 | + return $storage; |
|
247 | + }); |
|
248 | + |
|
249 | + \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
250 | + // set up quota for home storages, even for other users |
|
251 | + // which can happen when using sharing |
|
252 | + |
|
253 | + /** |
|
254 | + * @var \OC\Files\Storage\Storage $storage |
|
255 | + */ |
|
256 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Home') |
|
257 | + || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage') |
|
258 | + ) { |
|
259 | + /** @var \OC\Files\Storage\Home $storage */ |
|
260 | + if (is_object($storage->getUser())) { |
|
261 | + $quota = OC_Util::getUserQuota($storage->getUser()); |
|
262 | + if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
263 | + return new \OC\Files\Storage\Wrapper\Quota(['storage' => $storage, 'quota' => $quota, 'root' => 'files']); |
|
264 | + } |
|
265 | + } |
|
266 | + } |
|
267 | + |
|
268 | + return $storage; |
|
269 | + }); |
|
270 | + |
|
271 | + \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
272 | + /* |
|
273 | 273 | * Do not allow any operations that modify the storage |
274 | 274 | */ |
275 | - if ($mount->getOption('readonly', false)) { |
|
276 | - return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
277 | - 'storage' => $storage, |
|
278 | - 'mask' => \OCP\Constants::PERMISSION_ALL & ~( |
|
279 | - \OCP\Constants::PERMISSION_UPDATE | |
|
280 | - \OCP\Constants::PERMISSION_CREATE | |
|
281 | - \OCP\Constants::PERMISSION_DELETE |
|
282 | - ), |
|
283 | - ]); |
|
284 | - } |
|
285 | - return $storage; |
|
286 | - }); |
|
287 | - |
|
288 | - OC_Hook::emit('OC_Filesystem', 'preSetup', ['user' => $user]); |
|
289 | - |
|
290 | - \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($prevLogging); |
|
291 | - |
|
292 | - //check if we are using an object storage |
|
293 | - $objectStore = \OC::$server->getSystemConfig()->getValue('objectstore', null); |
|
294 | - $objectStoreMultibucket = \OC::$server->getSystemConfig()->getValue('objectstore_multibucket', null); |
|
295 | - |
|
296 | - // use the same order as in ObjectHomeMountProvider |
|
297 | - if (isset($objectStoreMultibucket)) { |
|
298 | - self::initObjectStoreMultibucketRootFS($objectStoreMultibucket); |
|
299 | - } elseif (isset($objectStore)) { |
|
300 | - self::initObjectStoreRootFS($objectStore); |
|
301 | - } else { |
|
302 | - self::initLocalStorageRootFS(); |
|
303 | - } |
|
304 | - |
|
305 | - /** @var \OCP\Files\Config\IMountProviderCollection $mountProviderCollection */ |
|
306 | - $mountProviderCollection = \OC::$server->query(\OCP\Files\Config\IMountProviderCollection::class); |
|
307 | - $rootMountProviders = $mountProviderCollection->getRootMounts(); |
|
308 | - |
|
309 | - /** @var \OC\Files\Mount\Manager $mountManager */ |
|
310 | - $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
311 | - foreach ($rootMountProviders as $rootMountProvider) { |
|
312 | - $mountManager->addMount($rootMountProvider); |
|
313 | - } |
|
314 | - |
|
315 | - if ($user != '' && !\OC::$server->getUserManager()->userExists($user)) { |
|
316 | - \OC::$server->getEventLogger()->end('setup_fs'); |
|
317 | - return false; |
|
318 | - } |
|
319 | - |
|
320 | - //if we aren't logged in, there is no use to set up the filesystem |
|
321 | - if ($user != "") { |
|
322 | - $userDir = '/' . $user . '/files'; |
|
323 | - |
|
324 | - //jail the user into his "home" directory |
|
325 | - \OC\Files\Filesystem::init($user, $userDir); |
|
326 | - |
|
327 | - OC_Hook::emit('OC_Filesystem', 'setup', ['user' => $user, 'user_dir' => $userDir]); |
|
328 | - } |
|
329 | - \OC::$server->getEventLogger()->end('setup_fs'); |
|
330 | - return true; |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * check if a password is required for each public link |
|
335 | - * |
|
336 | - * @return boolean |
|
337 | - * @suppress PhanDeprecatedFunction |
|
338 | - */ |
|
339 | - public static function isPublicLinkPasswordRequired() { |
|
340 | - /** @var IManager $shareManager */ |
|
341 | - $shareManager = \OC::$server->get(IManager::class); |
|
342 | - return $shareManager->shareApiLinkEnforcePassword(); |
|
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * check if sharing is disabled for the current user |
|
347 | - * @param IConfig $config |
|
348 | - * @param IGroupManager $groupManager |
|
349 | - * @param IUser|null $user |
|
350 | - * @return bool |
|
351 | - */ |
|
352 | - public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) { |
|
353 | - /** @var IManager $shareManager */ |
|
354 | - $shareManager = \OC::$server->get(IManager::class); |
|
355 | - $userId = $user ? $user->getUID() : null; |
|
356 | - return $shareManager->sharingDisabledForUser($userId); |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * check if share API enforces a default expire date |
|
361 | - * |
|
362 | - * @return boolean |
|
363 | - * @suppress PhanDeprecatedFunction |
|
364 | - */ |
|
365 | - public static function isDefaultExpireDateEnforced() { |
|
366 | - /** @var IManager $shareManager */ |
|
367 | - $shareManager = \OC::$server->get(IManager::class); |
|
368 | - return $shareManager->shareApiLinkDefaultExpireDateEnforced(); |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Get the quota of a user |
|
373 | - * |
|
374 | - * @param IUser|null $user |
|
375 | - * @return float Quota bytes |
|
376 | - */ |
|
377 | - public static function getUserQuota(?IUser $user) { |
|
378 | - if (is_null($user)) { |
|
379 | - return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
380 | - } |
|
381 | - $userQuota = $user->getQuota(); |
|
382 | - if ($userQuota === 'none') { |
|
383 | - return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
384 | - } |
|
385 | - return OC_Helper::computerFileSize($userQuota); |
|
386 | - } |
|
387 | - |
|
388 | - /** |
|
389 | - * copies the skeleton to the users /files |
|
390 | - * |
|
391 | - * @param string $userId |
|
392 | - * @param \OCP\Files\Folder $userDirectory |
|
393 | - * @throws \OCP\Files\NotFoundException |
|
394 | - * @throws \OCP\Files\NotPermittedException |
|
395 | - * @suppress PhanDeprecatedFunction |
|
396 | - */ |
|
397 | - public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) { |
|
398 | - /** @var LoggerInterface $logger */ |
|
399 | - $logger = \OC::$server->get(LoggerInterface::class); |
|
400 | - |
|
401 | - $plainSkeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); |
|
402 | - $userLang = \OC::$server->getL10NFactory()->findLanguage(); |
|
403 | - $skeletonDirectory = str_replace('{lang}', $userLang, $plainSkeletonDirectory); |
|
404 | - |
|
405 | - if (!file_exists($skeletonDirectory)) { |
|
406 | - $dialectStart = strpos($userLang, '_'); |
|
407 | - if ($dialectStart !== false) { |
|
408 | - $skeletonDirectory = str_replace('{lang}', substr($userLang, 0, $dialectStart), $plainSkeletonDirectory); |
|
409 | - } |
|
410 | - if ($dialectStart === false || !file_exists($skeletonDirectory)) { |
|
411 | - $skeletonDirectory = str_replace('{lang}', 'default', $plainSkeletonDirectory); |
|
412 | - } |
|
413 | - if (!file_exists($skeletonDirectory)) { |
|
414 | - $skeletonDirectory = ''; |
|
415 | - } |
|
416 | - } |
|
417 | - |
|
418 | - $instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', ''); |
|
419 | - |
|
420 | - if ($instanceId === null) { |
|
421 | - throw new \RuntimeException('no instance id!'); |
|
422 | - } |
|
423 | - $appdata = 'appdata_' . $instanceId; |
|
424 | - if ($userId === $appdata) { |
|
425 | - throw new \RuntimeException('username is reserved name: ' . $appdata); |
|
426 | - } |
|
427 | - |
|
428 | - if (!empty($skeletonDirectory)) { |
|
429 | - $logger->debug('copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'), ['app' => 'files_skeleton']); |
|
430 | - self::copyr($skeletonDirectory, $userDirectory); |
|
431 | - // update the file cache |
|
432 | - $userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE); |
|
433 | - |
|
434 | - /** @var ITemplateManager $templateManager */ |
|
435 | - $templateManager = \OC::$server->get(ITemplateManager::class); |
|
436 | - $templateManager->initializeTemplateDirectory(null, $userId); |
|
437 | - } |
|
438 | - } |
|
439 | - |
|
440 | - /** |
|
441 | - * copies a directory recursively by using streams |
|
442 | - * |
|
443 | - * @param string $source |
|
444 | - * @param \OCP\Files\Folder $target |
|
445 | - * @return void |
|
446 | - */ |
|
447 | - public static function copyr($source, \OCP\Files\Folder $target) { |
|
448 | - $logger = \OC::$server->getLogger(); |
|
449 | - |
|
450 | - // Verify if folder exists |
|
451 | - $dir = opendir($source); |
|
452 | - if ($dir === false) { |
|
453 | - $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']); |
|
454 | - return; |
|
455 | - } |
|
456 | - |
|
457 | - // Copy the files |
|
458 | - while (false !== ($file = readdir($dir))) { |
|
459 | - if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
|
460 | - if (is_dir($source . '/' . $file)) { |
|
461 | - $child = $target->newFolder($file); |
|
462 | - self::copyr($source . '/' . $file, $child); |
|
463 | - } else { |
|
464 | - $child = $target->newFile($file); |
|
465 | - $sourceStream = fopen($source . '/' . $file, 'r'); |
|
466 | - if ($sourceStream === false) { |
|
467 | - $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']); |
|
468 | - closedir($dir); |
|
469 | - return; |
|
470 | - } |
|
471 | - stream_copy_to_stream($sourceStream, $child->fopen('w')); |
|
472 | - } |
|
473 | - } |
|
474 | - } |
|
475 | - closedir($dir); |
|
476 | - } |
|
477 | - |
|
478 | - /** |
|
479 | - * @return void |
|
480 | - * @suppress PhanUndeclaredMethod |
|
481 | - */ |
|
482 | - public static function tearDownFS() { |
|
483 | - \OC\Files\Filesystem::tearDown(); |
|
484 | - \OC::$server->getRootFolder()->clearCache(); |
|
485 | - self::$fsSetup = false; |
|
486 | - self::$rootMounted = false; |
|
487 | - } |
|
488 | - |
|
489 | - /** |
|
490 | - * get the current installed version of ownCloud |
|
491 | - * |
|
492 | - * @return array |
|
493 | - */ |
|
494 | - public static function getVersion() { |
|
495 | - OC_Util::loadVersion(); |
|
496 | - return self::$versionCache['OC_Version']; |
|
497 | - } |
|
498 | - |
|
499 | - /** |
|
500 | - * get the current installed version string of ownCloud |
|
501 | - * |
|
502 | - * @return string |
|
503 | - */ |
|
504 | - public static function getVersionString() { |
|
505 | - OC_Util::loadVersion(); |
|
506 | - return self::$versionCache['OC_VersionString']; |
|
507 | - } |
|
508 | - |
|
509 | - /** |
|
510 | - * @deprecated the value is of no use anymore |
|
511 | - * @return string |
|
512 | - */ |
|
513 | - public static function getEditionString() { |
|
514 | - return ''; |
|
515 | - } |
|
516 | - |
|
517 | - /** |
|
518 | - * @description get the update channel of the current installed of ownCloud. |
|
519 | - * @return string |
|
520 | - */ |
|
521 | - public static function getChannel() { |
|
522 | - OC_Util::loadVersion(); |
|
523 | - return \OC::$server->getConfig()->getSystemValue('updater.release.channel', self::$versionCache['OC_Channel']); |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * @description get the build number of the current installed of ownCloud. |
|
528 | - * @return string |
|
529 | - */ |
|
530 | - public static function getBuild() { |
|
531 | - OC_Util::loadVersion(); |
|
532 | - return self::$versionCache['OC_Build']; |
|
533 | - } |
|
534 | - |
|
535 | - /** |
|
536 | - * @description load the version.php into the session as cache |
|
537 | - * @suppress PhanUndeclaredVariable |
|
538 | - */ |
|
539 | - private static function loadVersion() { |
|
540 | - if (self::$versionCache !== null) { |
|
541 | - return; |
|
542 | - } |
|
543 | - |
|
544 | - $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); |
|
545 | - require OC::$SERVERROOT . '/version.php'; |
|
546 | - /** @var int $timestamp */ |
|
547 | - self::$versionCache['OC_Version_Timestamp'] = $timestamp; |
|
548 | - /** @var string $OC_Version */ |
|
549 | - self::$versionCache['OC_Version'] = $OC_Version; |
|
550 | - /** @var string $OC_VersionString */ |
|
551 | - self::$versionCache['OC_VersionString'] = $OC_VersionString; |
|
552 | - /** @var string $OC_Build */ |
|
553 | - self::$versionCache['OC_Build'] = $OC_Build; |
|
554 | - |
|
555 | - /** @var string $OC_Channel */ |
|
556 | - self::$versionCache['OC_Channel'] = $OC_Channel; |
|
557 | - } |
|
558 | - |
|
559 | - /** |
|
560 | - * generates a path for JS/CSS files. If no application is provided it will create the path for core. |
|
561 | - * |
|
562 | - * @param string $application application to get the files from |
|
563 | - * @param string $directory directory within this application (css, js, vendor, etc) |
|
564 | - * @param string $file the file inside of the above folder |
|
565 | - * @return string the path |
|
566 | - */ |
|
567 | - private static function generatePath($application, $directory, $file) { |
|
568 | - if (is_null($file)) { |
|
569 | - $file = $application; |
|
570 | - $application = ""; |
|
571 | - } |
|
572 | - if (!empty($application)) { |
|
573 | - return "$application/$directory/$file"; |
|
574 | - } else { |
|
575 | - return "$directory/$file"; |
|
576 | - } |
|
577 | - } |
|
578 | - |
|
579 | - /** |
|
580 | - * add a javascript file |
|
581 | - * |
|
582 | - * @param string $application application id |
|
583 | - * @param string|null $file filename |
|
584 | - * @param bool $prepend prepend the Script to the beginning of the list |
|
585 | - * @return void |
|
586 | - */ |
|
587 | - public static function addScript($application, $file = null, $prepend = false) { |
|
588 | - $path = OC_Util::generatePath($application, 'js', $file); |
|
589 | - |
|
590 | - // core js files need separate handling |
|
591 | - if ($application !== 'core' && $file !== null) { |
|
592 | - self::addTranslations($application); |
|
593 | - } |
|
594 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
595 | - } |
|
596 | - |
|
597 | - /** |
|
598 | - * add a javascript file from the vendor sub folder |
|
599 | - * |
|
600 | - * @param string $application application id |
|
601 | - * @param string|null $file filename |
|
602 | - * @param bool $prepend prepend the Script to the beginning of the list |
|
603 | - * @return void |
|
604 | - */ |
|
605 | - public static function addVendorScript($application, $file = null, $prepend = false) { |
|
606 | - $path = OC_Util::generatePath($application, 'vendor', $file); |
|
607 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
608 | - } |
|
609 | - |
|
610 | - /** |
|
611 | - * add a translation JS file |
|
612 | - * |
|
613 | - * @param string $application application id |
|
614 | - * @param string|null $languageCode language code, defaults to the current language |
|
615 | - * @param bool|null $prepend prepend the Script to the beginning of the list |
|
616 | - */ |
|
617 | - public static function addTranslations($application, $languageCode = null, $prepend = false) { |
|
618 | - if (is_null($languageCode)) { |
|
619 | - $languageCode = \OC::$server->getL10NFactory()->findLanguage($application); |
|
620 | - } |
|
621 | - if (!empty($application)) { |
|
622 | - $path = "$application/l10n/$languageCode"; |
|
623 | - } else { |
|
624 | - $path = "l10n/$languageCode"; |
|
625 | - } |
|
626 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
627 | - } |
|
628 | - |
|
629 | - /** |
|
630 | - * add a css file |
|
631 | - * |
|
632 | - * @param string $application application id |
|
633 | - * @param string|null $file filename |
|
634 | - * @param bool $prepend prepend the Style to the beginning of the list |
|
635 | - * @return void |
|
636 | - */ |
|
637 | - public static function addStyle($application, $file = null, $prepend = false) { |
|
638 | - $path = OC_Util::generatePath($application, 'css', $file); |
|
639 | - self::addExternalResource($application, $prepend, $path, "style"); |
|
640 | - } |
|
641 | - |
|
642 | - /** |
|
643 | - * add a css file from the vendor sub folder |
|
644 | - * |
|
645 | - * @param string $application application id |
|
646 | - * @param string|null $file filename |
|
647 | - * @param bool $prepend prepend the Style to the beginning of the list |
|
648 | - * @return void |
|
649 | - */ |
|
650 | - public static function addVendorStyle($application, $file = null, $prepend = false) { |
|
651 | - $path = OC_Util::generatePath($application, 'vendor', $file); |
|
652 | - self::addExternalResource($application, $prepend, $path, "style"); |
|
653 | - } |
|
654 | - |
|
655 | - /** |
|
656 | - * add an external resource css/js file |
|
657 | - * |
|
658 | - * @param string $application application id |
|
659 | - * @param bool $prepend prepend the file to the beginning of the list |
|
660 | - * @param string $path |
|
661 | - * @param string $type (script or style) |
|
662 | - * @return void |
|
663 | - */ |
|
664 | - private static function addExternalResource($application, $prepend, $path, $type = "script") { |
|
665 | - if ($type === "style") { |
|
666 | - if (!in_array($path, self::$styles)) { |
|
667 | - if ($prepend === true) { |
|
668 | - array_unshift(self::$styles, $path); |
|
669 | - } else { |
|
670 | - self::$styles[] = $path; |
|
671 | - } |
|
672 | - } |
|
673 | - } elseif ($type === "script") { |
|
674 | - if (!in_array($path, self::$scripts)) { |
|
675 | - if ($prepend === true) { |
|
676 | - array_unshift(self::$scripts, $path); |
|
677 | - } else { |
|
678 | - self::$scripts [] = $path; |
|
679 | - } |
|
680 | - } |
|
681 | - } |
|
682 | - } |
|
683 | - |
|
684 | - /** |
|
685 | - * Add a custom element to the header |
|
686 | - * If $text is null then the element will be written as empty element. |
|
687 | - * So use "" to get a closing tag. |
|
688 | - * @param string $tag tag name of the element |
|
689 | - * @param array $attributes array of attributes for the element |
|
690 | - * @param string $text the text content for the element |
|
691 | - * @param bool $prepend prepend the header to the beginning of the list |
|
692 | - */ |
|
693 | - public static function addHeader($tag, $attributes, $text = null, $prepend = false) { |
|
694 | - $header = [ |
|
695 | - 'tag' => $tag, |
|
696 | - 'attributes' => $attributes, |
|
697 | - 'text' => $text |
|
698 | - ]; |
|
699 | - if ($prepend === true) { |
|
700 | - array_unshift(self::$headers, $header); |
|
701 | - } else { |
|
702 | - self::$headers[] = $header; |
|
703 | - } |
|
704 | - } |
|
705 | - |
|
706 | - /** |
|
707 | - * check if the current server configuration is suitable for ownCloud |
|
708 | - * |
|
709 | - * @param \OC\SystemConfig $config |
|
710 | - * @return array arrays with error messages and hints |
|
711 | - */ |
|
712 | - public static function checkServer(\OC\SystemConfig $config) { |
|
713 | - $l = \OC::$server->getL10N('lib'); |
|
714 | - $errors = []; |
|
715 | - $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
716 | - |
|
717 | - if (!self::needUpgrade($config) && $config->getValue('installed', false)) { |
|
718 | - // this check needs to be done every time |
|
719 | - $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY); |
|
720 | - } |
|
721 | - |
|
722 | - // Assume that if checkServer() succeeded before in this session, then all is fine. |
|
723 | - if (\OC::$server->getSession()->exists('checkServer_succeeded') && \OC::$server->getSession()->get('checkServer_succeeded')) { |
|
724 | - return $errors; |
|
725 | - } |
|
726 | - |
|
727 | - $webServerRestart = false; |
|
728 | - $setup = new \OC\Setup( |
|
729 | - $config, |
|
730 | - \OC::$server->get(IniGetWrapper::class), |
|
731 | - \OC::$server->getL10N('lib'), |
|
732 | - \OC::$server->get(\OCP\Defaults::class), |
|
733 | - \OC::$server->get(LoggerInterface::class), |
|
734 | - \OC::$server->getSecureRandom(), |
|
735 | - \OC::$server->get(\OC\Installer::class) |
|
736 | - ); |
|
737 | - |
|
738 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
739 | - |
|
740 | - $availableDatabases = $setup->getSupportedDatabases(); |
|
741 | - if (empty($availableDatabases)) { |
|
742 | - $errors[] = [ |
|
743 | - 'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'), |
|
744 | - 'hint' => '' //TODO: sane hint |
|
745 | - ]; |
|
746 | - $webServerRestart = true; |
|
747 | - } |
|
748 | - |
|
749 | - // Check if config folder is writable. |
|
750 | - if (!OC_Helper::isReadOnlyConfigEnabled()) { |
|
751 | - if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) { |
|
752 | - $errors[] = [ |
|
753 | - 'error' => $l->t('Cannot write into "config" directory'), |
|
754 | - 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
|
755 | - [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) . '. ' |
|
756 | - . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s', |
|
757 | - [ $urlGenerator->linkToDocs('admin-config') ]) |
|
758 | - ]; |
|
759 | - } |
|
760 | - } |
|
761 | - |
|
762 | - // Check if there is a writable install folder. |
|
763 | - if ($config->getValue('appstoreenabled', true)) { |
|
764 | - if (OC_App::getInstallPath() === null |
|
765 | - || !is_writable(OC_App::getInstallPath()) |
|
766 | - || !is_readable(OC_App::getInstallPath()) |
|
767 | - ) { |
|
768 | - $errors[] = [ |
|
769 | - 'error' => $l->t('Cannot write into "apps" directory'), |
|
770 | - 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the apps directory' |
|
771 | - . ' or disabling the appstore in the config file.') |
|
772 | - ]; |
|
773 | - } |
|
774 | - } |
|
775 | - // Create root dir. |
|
776 | - if ($config->getValue('installed', false)) { |
|
777 | - if (!is_dir($CONFIG_DATADIRECTORY)) { |
|
778 | - $success = @mkdir($CONFIG_DATADIRECTORY); |
|
779 | - if ($success) { |
|
780 | - $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
781 | - } else { |
|
782 | - $errors[] = [ |
|
783 | - 'error' => $l->t('Cannot create "data" directory'), |
|
784 | - 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the root directory. See %s', |
|
785 | - [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
786 | - ]; |
|
787 | - } |
|
788 | - } elseif (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) { |
|
789 | - // is_writable doesn't work for NFS mounts, so try to write a file and check if it exists. |
|
790 | - $testFile = sprintf('%s/%s.tmp', $CONFIG_DATADIRECTORY, uniqid('data_dir_writability_test_')); |
|
791 | - $handle = fopen($testFile, 'w'); |
|
792 | - if (!$handle || fwrite($handle, 'Test write operation') === false) { |
|
793 | - $permissionsHint = $l->t('Permissions can usually be fixed by giving the webserver write access to the root directory. See %s.', |
|
794 | - [$urlGenerator->linkToDocs('admin-dir_permissions')]); |
|
795 | - $errors[] = [ |
|
796 | - 'error' => 'Your data directory is not writable', |
|
797 | - 'hint' => $permissionsHint |
|
798 | - ]; |
|
799 | - } else { |
|
800 | - fclose($handle); |
|
801 | - unlink($testFile); |
|
802 | - } |
|
803 | - } else { |
|
804 | - $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
805 | - } |
|
806 | - } |
|
807 | - |
|
808 | - if (!OC_Util::isSetLocaleWorking()) { |
|
809 | - $errors[] = [ |
|
810 | - 'error' => $l->t('Setting locale to %s failed', |
|
811 | - ['en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/' |
|
812 | - . 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8']), |
|
813 | - 'hint' => $l->t('Please install one of these locales on your system and restart your webserver.') |
|
814 | - ]; |
|
815 | - } |
|
816 | - |
|
817 | - // Contains the dependencies that should be checked against |
|
818 | - // classes = class_exists |
|
819 | - // functions = function_exists |
|
820 | - // defined = defined |
|
821 | - // ini = ini_get |
|
822 | - // If the dependency is not found the missing module name is shown to the EndUser |
|
823 | - // When adding new checks always verify that they pass on Travis as well |
|
824 | - // for ini settings, see https://github.com/owncloud/administration/blob/master/travis-ci/custom.ini |
|
825 | - $dependencies = [ |
|
826 | - 'classes' => [ |
|
827 | - 'ZipArchive' => 'zip', |
|
828 | - 'DOMDocument' => 'dom', |
|
829 | - 'XMLWriter' => 'XMLWriter', |
|
830 | - 'XMLReader' => 'XMLReader', |
|
831 | - ], |
|
832 | - 'functions' => [ |
|
833 | - 'xml_parser_create' => 'libxml', |
|
834 | - 'mb_strcut' => 'mbstring', |
|
835 | - 'ctype_digit' => 'ctype', |
|
836 | - 'json_encode' => 'JSON', |
|
837 | - 'gd_info' => 'GD', |
|
838 | - 'gzencode' => 'zlib', |
|
839 | - 'iconv' => 'iconv', |
|
840 | - 'simplexml_load_string' => 'SimpleXML', |
|
841 | - 'hash' => 'HASH Message Digest Framework', |
|
842 | - 'curl_init' => 'cURL', |
|
843 | - 'openssl_verify' => 'OpenSSL', |
|
844 | - ], |
|
845 | - 'defined' => [ |
|
846 | - 'PDO::ATTR_DRIVER_NAME' => 'PDO' |
|
847 | - ], |
|
848 | - 'ini' => [ |
|
849 | - 'default_charset' => 'UTF-8', |
|
850 | - ], |
|
851 | - ]; |
|
852 | - $missingDependencies = []; |
|
853 | - $invalidIniSettings = []; |
|
854 | - |
|
855 | - $iniWrapper = \OC::$server->get(IniGetWrapper::class); |
|
856 | - foreach ($dependencies['classes'] as $class => $module) { |
|
857 | - if (!class_exists($class)) { |
|
858 | - $missingDependencies[] = $module; |
|
859 | - } |
|
860 | - } |
|
861 | - foreach ($dependencies['functions'] as $function => $module) { |
|
862 | - if (!function_exists($function)) { |
|
863 | - $missingDependencies[] = $module; |
|
864 | - } |
|
865 | - } |
|
866 | - foreach ($dependencies['defined'] as $defined => $module) { |
|
867 | - if (!defined($defined)) { |
|
868 | - $missingDependencies[] = $module; |
|
869 | - } |
|
870 | - } |
|
871 | - foreach ($dependencies['ini'] as $setting => $expected) { |
|
872 | - if (is_bool($expected)) { |
|
873 | - if ($iniWrapper->getBool($setting) !== $expected) { |
|
874 | - $invalidIniSettings[] = [$setting, $expected]; |
|
875 | - } |
|
876 | - } |
|
877 | - if (is_int($expected)) { |
|
878 | - if ($iniWrapper->getNumeric($setting) !== $expected) { |
|
879 | - $invalidIniSettings[] = [$setting, $expected]; |
|
880 | - } |
|
881 | - } |
|
882 | - if (is_string($expected)) { |
|
883 | - if (strtolower($iniWrapper->getString($setting)) !== strtolower($expected)) { |
|
884 | - $invalidIniSettings[] = [$setting, $expected]; |
|
885 | - } |
|
886 | - } |
|
887 | - } |
|
888 | - |
|
889 | - foreach ($missingDependencies as $missingDependency) { |
|
890 | - $errors[] = [ |
|
891 | - 'error' => $l->t('PHP module %s not installed.', [$missingDependency]), |
|
892 | - 'hint' => $l->t('Please ask your server administrator to install the module.'), |
|
893 | - ]; |
|
894 | - $webServerRestart = true; |
|
895 | - } |
|
896 | - foreach ($invalidIniSettings as $setting) { |
|
897 | - if (is_bool($setting[1])) { |
|
898 | - $setting[1] = $setting[1] ? 'on' : 'off'; |
|
899 | - } |
|
900 | - $errors[] = [ |
|
901 | - 'error' => $l->t('PHP setting "%s" is not set to "%s".', [$setting[0], var_export($setting[1], true)]), |
|
902 | - 'hint' => $l->t('Adjusting this setting in php.ini will make Nextcloud run again') |
|
903 | - ]; |
|
904 | - $webServerRestart = true; |
|
905 | - } |
|
906 | - |
|
907 | - /** |
|
908 | - * The mbstring.func_overload check can only be performed if the mbstring |
|
909 | - * module is installed as it will return null if the checking setting is |
|
910 | - * not available and thus a check on the boolean value fails. |
|
911 | - * |
|
912 | - * TODO: Should probably be implemented in the above generic dependency |
|
913 | - * check somehow in the long-term. |
|
914 | - */ |
|
915 | - if ($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
916 | - $iniWrapper->getBool('mbstring.func_overload') === true) { |
|
917 | - $errors[] = [ |
|
918 | - 'error' => $l->t('mbstring.func_overload is set to "%s" instead of the expected value "0"', [$iniWrapper->getString('mbstring.func_overload')]), |
|
919 | - 'hint' => $l->t('To fix this issue set <code>mbstring.func_overload</code> to <code>0</code> in your php.ini') |
|
920 | - ]; |
|
921 | - } |
|
922 | - |
|
923 | - if (function_exists('xml_parser_create') && |
|
924 | - LIBXML_LOADED_VERSION < 20700) { |
|
925 | - $version = LIBXML_LOADED_VERSION; |
|
926 | - $major = floor($version / 10000); |
|
927 | - $version -= ($major * 10000); |
|
928 | - $minor = floor($version / 100); |
|
929 | - $version -= ($minor * 100); |
|
930 | - $patch = $version; |
|
931 | - $errors[] = [ |
|
932 | - 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]), |
|
933 | - 'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.') |
|
934 | - ]; |
|
935 | - } |
|
936 | - |
|
937 | - if (!self::isAnnotationsWorking()) { |
|
938 | - $errors[] = [ |
|
939 | - 'error' => $l->t('PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.'), |
|
940 | - 'hint' => $l->t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.') |
|
941 | - ]; |
|
942 | - } |
|
943 | - |
|
944 | - if (!\OC::$CLI && $webServerRestart) { |
|
945 | - $errors[] = [ |
|
946 | - 'error' => $l->t('PHP modules have been installed, but they are still listed as missing?'), |
|
947 | - 'hint' => $l->t('Please ask your server administrator to restart the web server.') |
|
948 | - ]; |
|
949 | - } |
|
950 | - |
|
951 | - $errors = array_merge($errors, self::checkDatabaseVersion()); |
|
952 | - |
|
953 | - // Cache the result of this function |
|
954 | - \OC::$server->getSession()->set('checkServer_succeeded', count($errors) == 0); |
|
955 | - |
|
956 | - return $errors; |
|
957 | - } |
|
958 | - |
|
959 | - /** |
|
960 | - * Check the database version |
|
961 | - * |
|
962 | - * @return array errors array |
|
963 | - */ |
|
964 | - public static function checkDatabaseVersion() { |
|
965 | - $l = \OC::$server->getL10N('lib'); |
|
966 | - $errors = []; |
|
967 | - $dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite'); |
|
968 | - if ($dbType === 'pgsql') { |
|
969 | - // check PostgreSQL version |
|
970 | - try { |
|
971 | - $result = \OC_DB::executeAudited('SHOW SERVER_VERSION'); |
|
972 | - $data = $result->fetchRow(); |
|
973 | - $result->closeCursor(); |
|
974 | - if (isset($data['server_version'])) { |
|
975 | - $version = $data['server_version']; |
|
976 | - if (version_compare($version, '9.0.0', '<')) { |
|
977 | - $errors[] = [ |
|
978 | - 'error' => $l->t('PostgreSQL >= 9 required'), |
|
979 | - 'hint' => $l->t('Please upgrade your database version') |
|
980 | - ]; |
|
981 | - } |
|
982 | - } |
|
983 | - } catch (\Doctrine\DBAL\Exception $e) { |
|
984 | - $logger = \OC::$server->getLogger(); |
|
985 | - $logger->warning('Error occurred while checking PostgreSQL version, assuming >= 9'); |
|
986 | - $logger->logException($e); |
|
987 | - } |
|
988 | - } |
|
989 | - return $errors; |
|
990 | - } |
|
991 | - |
|
992 | - /** |
|
993 | - * Check for correct file permissions of data directory |
|
994 | - * |
|
995 | - * @param string $dataDirectory |
|
996 | - * @return array arrays with error messages and hints |
|
997 | - */ |
|
998 | - public static function checkDataDirectoryPermissions($dataDirectory) { |
|
999 | - if (\OC::$server->getConfig()->getSystemValue('check_data_directory_permissions', true) === false) { |
|
1000 | - return []; |
|
1001 | - } |
|
1002 | - |
|
1003 | - $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
1004 | - if (substr($perms, -1) !== '0') { |
|
1005 | - chmod($dataDirectory, 0770); |
|
1006 | - clearstatcache(); |
|
1007 | - $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
1008 | - if ($perms[2] !== '0') { |
|
1009 | - $l = \OC::$server->getL10N('lib'); |
|
1010 | - return [[ |
|
1011 | - 'error' => $l->t('Your data directory is readable by other users'), |
|
1012 | - 'hint' => $l->t('Please change the permissions to 0770 so that the directory cannot be listed by other users.'), |
|
1013 | - ]]; |
|
1014 | - } |
|
1015 | - } |
|
1016 | - return []; |
|
1017 | - } |
|
1018 | - |
|
1019 | - /** |
|
1020 | - * Check that the data directory exists and is valid by |
|
1021 | - * checking the existence of the ".ocdata" file. |
|
1022 | - * |
|
1023 | - * @param string $dataDirectory data directory path |
|
1024 | - * @return array errors found |
|
1025 | - */ |
|
1026 | - public static function checkDataDirectoryValidity($dataDirectory) { |
|
1027 | - $l = \OC::$server->getL10N('lib'); |
|
1028 | - $errors = []; |
|
1029 | - if ($dataDirectory[0] !== '/') { |
|
1030 | - $errors[] = [ |
|
1031 | - 'error' => $l->t('Your data directory must be an absolute path'), |
|
1032 | - 'hint' => $l->t('Check the value of "datadirectory" in your configuration') |
|
1033 | - ]; |
|
1034 | - } |
|
1035 | - if (!file_exists($dataDirectory . '/.ocdata')) { |
|
1036 | - $errors[] = [ |
|
1037 | - 'error' => $l->t('Your data directory is invalid'), |
|
1038 | - 'hint' => $l->t('Ensure there is a file called ".ocdata"' . |
|
1039 | - ' in the root of the data directory.') |
|
1040 | - ]; |
|
1041 | - } |
|
1042 | - return $errors; |
|
1043 | - } |
|
1044 | - |
|
1045 | - /** |
|
1046 | - * Check if the user is logged in, redirects to home if not. With |
|
1047 | - * redirect URL parameter to the request URI. |
|
1048 | - * |
|
1049 | - * @return void |
|
1050 | - */ |
|
1051 | - public static function checkLoggedIn() { |
|
1052 | - // Check if we are a user |
|
1053 | - if (!\OC::$server->getUserSession()->isLoggedIn()) { |
|
1054 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute( |
|
1055 | - 'core.login.showLoginForm', |
|
1056 | - [ |
|
1057 | - 'redirect_url' => \OC::$server->getRequest()->getRequestUri(), |
|
1058 | - ] |
|
1059 | - ) |
|
1060 | - ); |
|
1061 | - exit(); |
|
1062 | - } |
|
1063 | - // Redirect to 2FA challenge selection if 2FA challenge was not solved yet |
|
1064 | - if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { |
|
1065 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
1066 | - exit(); |
|
1067 | - } |
|
1068 | - } |
|
1069 | - |
|
1070 | - /** |
|
1071 | - * Check if the user is a admin, redirects to home if not |
|
1072 | - * |
|
1073 | - * @return void |
|
1074 | - */ |
|
1075 | - public static function checkAdminUser() { |
|
1076 | - OC_Util::checkLoggedIn(); |
|
1077 | - if (!OC_User::isAdminUser(OC_User::getUser())) { |
|
1078 | - header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
1079 | - exit(); |
|
1080 | - } |
|
1081 | - } |
|
1082 | - |
|
1083 | - /** |
|
1084 | - * Returns the URL of the default page |
|
1085 | - * based on the system configuration and |
|
1086 | - * the apps visible for the current user |
|
1087 | - * |
|
1088 | - * @return string URL |
|
1089 | - * @suppress PhanDeprecatedFunction |
|
1090 | - */ |
|
1091 | - public static function getDefaultPageUrl() { |
|
1092 | - /** @var IConfig $config */ |
|
1093 | - $config = \OC::$server->get(IConfig::class); |
|
1094 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
1095 | - // Deny the redirect if the URL contains a @ |
|
1096 | - // This prevents unvalidated redirects like ?redirect_url=:[email protected] |
|
1097 | - if (isset($_REQUEST['redirect_url']) && strpos($_REQUEST['redirect_url'], '@') === false) { |
|
1098 | - $location = $urlGenerator->getAbsoluteURL(urldecode($_REQUEST['redirect_url'])); |
|
1099 | - } else { |
|
1100 | - $defaultPage = \OC::$server->getConfig()->getAppValue('core', 'defaultpage'); |
|
1101 | - if ($defaultPage) { |
|
1102 | - $location = $urlGenerator->getAbsoluteURL($defaultPage); |
|
1103 | - } else { |
|
1104 | - $appId = 'files'; |
|
1105 | - $defaultApps = explode(',', $config->getSystemValue('defaultapp', 'dashboard,files')); |
|
1106 | - |
|
1107 | - /** @var IUserSession $userSession */ |
|
1108 | - $userSession = \OC::$server->get(IUserSession::class); |
|
1109 | - $user = $userSession->getUser(); |
|
1110 | - if ($user) { |
|
1111 | - $userDefaultApps = explode(',', $config->getUserValue($user->getUID(), 'core', 'defaultapp')); |
|
1112 | - $defaultApps = array_filter(array_merge($userDefaultApps, $defaultApps)); |
|
1113 | - } |
|
1114 | - |
|
1115 | - // find the first app that is enabled for the current user |
|
1116 | - foreach ($defaultApps as $defaultApp) { |
|
1117 | - $defaultApp = OC_App::cleanAppId(strip_tags($defaultApp)); |
|
1118 | - if (static::getAppManager()->isEnabledForUser($defaultApp)) { |
|
1119 | - $appId = $defaultApp; |
|
1120 | - break; |
|
1121 | - } |
|
1122 | - } |
|
1123 | - |
|
1124 | - if ($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { |
|
1125 | - $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); |
|
1126 | - } else { |
|
1127 | - $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); |
|
1128 | - } |
|
1129 | - } |
|
1130 | - } |
|
1131 | - return $location; |
|
1132 | - } |
|
1133 | - |
|
1134 | - /** |
|
1135 | - * Redirect to the user default page |
|
1136 | - * |
|
1137 | - * @return void |
|
1138 | - */ |
|
1139 | - public static function redirectToDefaultPage() { |
|
1140 | - $location = self::getDefaultPageUrl(); |
|
1141 | - header('Location: ' . $location); |
|
1142 | - exit(); |
|
1143 | - } |
|
1144 | - |
|
1145 | - /** |
|
1146 | - * get an id unique for this instance |
|
1147 | - * |
|
1148 | - * @return string |
|
1149 | - */ |
|
1150 | - public static function getInstanceId() { |
|
1151 | - $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
1152 | - if (is_null($id)) { |
|
1153 | - // We need to guarantee at least one letter in instanceid so it can be used as the session_name |
|
1154 | - $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
1155 | - \OC::$server->getSystemConfig()->setValue('instanceid', $id); |
|
1156 | - } |
|
1157 | - return $id; |
|
1158 | - } |
|
1159 | - |
|
1160 | - /** |
|
1161 | - * Public function to sanitize HTML |
|
1162 | - * |
|
1163 | - * This function is used to sanitize HTML and should be applied on any |
|
1164 | - * string or array of strings before displaying it on a web page. |
|
1165 | - * |
|
1166 | - * @param string|array $value |
|
1167 | - * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
1168 | - */ |
|
1169 | - public static function sanitizeHTML($value) { |
|
1170 | - if (is_array($value)) { |
|
1171 | - $value = array_map(function ($value) { |
|
1172 | - return self::sanitizeHTML($value); |
|
1173 | - }, $value); |
|
1174 | - } else { |
|
1175 | - // Specify encoding for PHP<5.4 |
|
1176 | - $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); |
|
1177 | - } |
|
1178 | - return $value; |
|
1179 | - } |
|
1180 | - |
|
1181 | - /** |
|
1182 | - * Public function to encode url parameters |
|
1183 | - * |
|
1184 | - * This function is used to encode path to file before output. |
|
1185 | - * Encoding is done according to RFC 3986 with one exception: |
|
1186 | - * Character '/' is preserved as is. |
|
1187 | - * |
|
1188 | - * @param string $component part of URI to encode |
|
1189 | - * @return string |
|
1190 | - */ |
|
1191 | - public static function encodePath($component) { |
|
1192 | - $encoded = rawurlencode($component); |
|
1193 | - $encoded = str_replace('%2F', '/', $encoded); |
|
1194 | - return $encoded; |
|
1195 | - } |
|
1196 | - |
|
1197 | - |
|
1198 | - public function createHtaccessTestFile(\OCP\IConfig $config) { |
|
1199 | - // php dev server does not support htaccess |
|
1200 | - if (php_sapi_name() === 'cli-server') { |
|
1201 | - return false; |
|
1202 | - } |
|
1203 | - |
|
1204 | - // testdata |
|
1205 | - $fileName = '/htaccesstest.txt'; |
|
1206 | - $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; |
|
1207 | - |
|
1208 | - // creating a test file |
|
1209 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
1210 | - |
|
1211 | - if (file_exists($testFile)) {// already running this test, possible recursive call |
|
1212 | - return false; |
|
1213 | - } |
|
1214 | - |
|
1215 | - $fp = @fopen($testFile, 'w'); |
|
1216 | - if (!$fp) { |
|
1217 | - throw new OC\HintException('Can\'t create test file to check for working .htaccess file.', |
|
1218 | - 'Make sure it is possible for the webserver to write to ' . $testFile); |
|
1219 | - } |
|
1220 | - fwrite($fp, $testContent); |
|
1221 | - fclose($fp); |
|
1222 | - |
|
1223 | - return $testContent; |
|
1224 | - } |
|
1225 | - |
|
1226 | - /** |
|
1227 | - * Check if the .htaccess file is working |
|
1228 | - * @param \OCP\IConfig $config |
|
1229 | - * @return bool |
|
1230 | - * @throws Exception |
|
1231 | - * @throws \OC\HintException If the test file can't get written. |
|
1232 | - */ |
|
1233 | - public function isHtaccessWorking(\OCP\IConfig $config) { |
|
1234 | - if (\OC::$CLI || !$config->getSystemValue('check_for_working_htaccess', true)) { |
|
1235 | - return true; |
|
1236 | - } |
|
1237 | - |
|
1238 | - $testContent = $this->createHtaccessTestFile($config); |
|
1239 | - if ($testContent === false) { |
|
1240 | - return false; |
|
1241 | - } |
|
1242 | - |
|
1243 | - $fileName = '/htaccesstest.txt'; |
|
1244 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
1245 | - |
|
1246 | - // accessing the file via http |
|
1247 | - $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); |
|
1248 | - try { |
|
1249 | - $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
|
1250 | - } catch (\Exception $e) { |
|
1251 | - $content = false; |
|
1252 | - } |
|
1253 | - |
|
1254 | - if (strpos($url, 'https:') === 0) { |
|
1255 | - $url = 'http:' . substr($url, 6); |
|
1256 | - } else { |
|
1257 | - $url = 'https:' . substr($url, 5); |
|
1258 | - } |
|
1259 | - |
|
1260 | - try { |
|
1261 | - $fallbackContent = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
|
1262 | - } catch (\Exception $e) { |
|
1263 | - $fallbackContent = false; |
|
1264 | - } |
|
1265 | - |
|
1266 | - // cleanup |
|
1267 | - @unlink($testFile); |
|
1268 | - |
|
1269 | - /* |
|
275 | + if ($mount->getOption('readonly', false)) { |
|
276 | + return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
277 | + 'storage' => $storage, |
|
278 | + 'mask' => \OCP\Constants::PERMISSION_ALL & ~( |
|
279 | + \OCP\Constants::PERMISSION_UPDATE | |
|
280 | + \OCP\Constants::PERMISSION_CREATE | |
|
281 | + \OCP\Constants::PERMISSION_DELETE |
|
282 | + ), |
|
283 | + ]); |
|
284 | + } |
|
285 | + return $storage; |
|
286 | + }); |
|
287 | + |
|
288 | + OC_Hook::emit('OC_Filesystem', 'preSetup', ['user' => $user]); |
|
289 | + |
|
290 | + \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($prevLogging); |
|
291 | + |
|
292 | + //check if we are using an object storage |
|
293 | + $objectStore = \OC::$server->getSystemConfig()->getValue('objectstore', null); |
|
294 | + $objectStoreMultibucket = \OC::$server->getSystemConfig()->getValue('objectstore_multibucket', null); |
|
295 | + |
|
296 | + // use the same order as in ObjectHomeMountProvider |
|
297 | + if (isset($objectStoreMultibucket)) { |
|
298 | + self::initObjectStoreMultibucketRootFS($objectStoreMultibucket); |
|
299 | + } elseif (isset($objectStore)) { |
|
300 | + self::initObjectStoreRootFS($objectStore); |
|
301 | + } else { |
|
302 | + self::initLocalStorageRootFS(); |
|
303 | + } |
|
304 | + |
|
305 | + /** @var \OCP\Files\Config\IMountProviderCollection $mountProviderCollection */ |
|
306 | + $mountProviderCollection = \OC::$server->query(\OCP\Files\Config\IMountProviderCollection::class); |
|
307 | + $rootMountProviders = $mountProviderCollection->getRootMounts(); |
|
308 | + |
|
309 | + /** @var \OC\Files\Mount\Manager $mountManager */ |
|
310 | + $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
311 | + foreach ($rootMountProviders as $rootMountProvider) { |
|
312 | + $mountManager->addMount($rootMountProvider); |
|
313 | + } |
|
314 | + |
|
315 | + if ($user != '' && !\OC::$server->getUserManager()->userExists($user)) { |
|
316 | + \OC::$server->getEventLogger()->end('setup_fs'); |
|
317 | + return false; |
|
318 | + } |
|
319 | + |
|
320 | + //if we aren't logged in, there is no use to set up the filesystem |
|
321 | + if ($user != "") { |
|
322 | + $userDir = '/' . $user . '/files'; |
|
323 | + |
|
324 | + //jail the user into his "home" directory |
|
325 | + \OC\Files\Filesystem::init($user, $userDir); |
|
326 | + |
|
327 | + OC_Hook::emit('OC_Filesystem', 'setup', ['user' => $user, 'user_dir' => $userDir]); |
|
328 | + } |
|
329 | + \OC::$server->getEventLogger()->end('setup_fs'); |
|
330 | + return true; |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * check if a password is required for each public link |
|
335 | + * |
|
336 | + * @return boolean |
|
337 | + * @suppress PhanDeprecatedFunction |
|
338 | + */ |
|
339 | + public static function isPublicLinkPasswordRequired() { |
|
340 | + /** @var IManager $shareManager */ |
|
341 | + $shareManager = \OC::$server->get(IManager::class); |
|
342 | + return $shareManager->shareApiLinkEnforcePassword(); |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * check if sharing is disabled for the current user |
|
347 | + * @param IConfig $config |
|
348 | + * @param IGroupManager $groupManager |
|
349 | + * @param IUser|null $user |
|
350 | + * @return bool |
|
351 | + */ |
|
352 | + public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) { |
|
353 | + /** @var IManager $shareManager */ |
|
354 | + $shareManager = \OC::$server->get(IManager::class); |
|
355 | + $userId = $user ? $user->getUID() : null; |
|
356 | + return $shareManager->sharingDisabledForUser($userId); |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * check if share API enforces a default expire date |
|
361 | + * |
|
362 | + * @return boolean |
|
363 | + * @suppress PhanDeprecatedFunction |
|
364 | + */ |
|
365 | + public static function isDefaultExpireDateEnforced() { |
|
366 | + /** @var IManager $shareManager */ |
|
367 | + $shareManager = \OC::$server->get(IManager::class); |
|
368 | + return $shareManager->shareApiLinkDefaultExpireDateEnforced(); |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Get the quota of a user |
|
373 | + * |
|
374 | + * @param IUser|null $user |
|
375 | + * @return float Quota bytes |
|
376 | + */ |
|
377 | + public static function getUserQuota(?IUser $user) { |
|
378 | + if (is_null($user)) { |
|
379 | + return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
380 | + } |
|
381 | + $userQuota = $user->getQuota(); |
|
382 | + if ($userQuota === 'none') { |
|
383 | + return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
384 | + } |
|
385 | + return OC_Helper::computerFileSize($userQuota); |
|
386 | + } |
|
387 | + |
|
388 | + /** |
|
389 | + * copies the skeleton to the users /files |
|
390 | + * |
|
391 | + * @param string $userId |
|
392 | + * @param \OCP\Files\Folder $userDirectory |
|
393 | + * @throws \OCP\Files\NotFoundException |
|
394 | + * @throws \OCP\Files\NotPermittedException |
|
395 | + * @suppress PhanDeprecatedFunction |
|
396 | + */ |
|
397 | + public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) { |
|
398 | + /** @var LoggerInterface $logger */ |
|
399 | + $logger = \OC::$server->get(LoggerInterface::class); |
|
400 | + |
|
401 | + $plainSkeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); |
|
402 | + $userLang = \OC::$server->getL10NFactory()->findLanguage(); |
|
403 | + $skeletonDirectory = str_replace('{lang}', $userLang, $plainSkeletonDirectory); |
|
404 | + |
|
405 | + if (!file_exists($skeletonDirectory)) { |
|
406 | + $dialectStart = strpos($userLang, '_'); |
|
407 | + if ($dialectStart !== false) { |
|
408 | + $skeletonDirectory = str_replace('{lang}', substr($userLang, 0, $dialectStart), $plainSkeletonDirectory); |
|
409 | + } |
|
410 | + if ($dialectStart === false || !file_exists($skeletonDirectory)) { |
|
411 | + $skeletonDirectory = str_replace('{lang}', 'default', $plainSkeletonDirectory); |
|
412 | + } |
|
413 | + if (!file_exists($skeletonDirectory)) { |
|
414 | + $skeletonDirectory = ''; |
|
415 | + } |
|
416 | + } |
|
417 | + |
|
418 | + $instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', ''); |
|
419 | + |
|
420 | + if ($instanceId === null) { |
|
421 | + throw new \RuntimeException('no instance id!'); |
|
422 | + } |
|
423 | + $appdata = 'appdata_' . $instanceId; |
|
424 | + if ($userId === $appdata) { |
|
425 | + throw new \RuntimeException('username is reserved name: ' . $appdata); |
|
426 | + } |
|
427 | + |
|
428 | + if (!empty($skeletonDirectory)) { |
|
429 | + $logger->debug('copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'), ['app' => 'files_skeleton']); |
|
430 | + self::copyr($skeletonDirectory, $userDirectory); |
|
431 | + // update the file cache |
|
432 | + $userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE); |
|
433 | + |
|
434 | + /** @var ITemplateManager $templateManager */ |
|
435 | + $templateManager = \OC::$server->get(ITemplateManager::class); |
|
436 | + $templateManager->initializeTemplateDirectory(null, $userId); |
|
437 | + } |
|
438 | + } |
|
439 | + |
|
440 | + /** |
|
441 | + * copies a directory recursively by using streams |
|
442 | + * |
|
443 | + * @param string $source |
|
444 | + * @param \OCP\Files\Folder $target |
|
445 | + * @return void |
|
446 | + */ |
|
447 | + public static function copyr($source, \OCP\Files\Folder $target) { |
|
448 | + $logger = \OC::$server->getLogger(); |
|
449 | + |
|
450 | + // Verify if folder exists |
|
451 | + $dir = opendir($source); |
|
452 | + if ($dir === false) { |
|
453 | + $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']); |
|
454 | + return; |
|
455 | + } |
|
456 | + |
|
457 | + // Copy the files |
|
458 | + while (false !== ($file = readdir($dir))) { |
|
459 | + if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
|
460 | + if (is_dir($source . '/' . $file)) { |
|
461 | + $child = $target->newFolder($file); |
|
462 | + self::copyr($source . '/' . $file, $child); |
|
463 | + } else { |
|
464 | + $child = $target->newFile($file); |
|
465 | + $sourceStream = fopen($source . '/' . $file, 'r'); |
|
466 | + if ($sourceStream === false) { |
|
467 | + $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']); |
|
468 | + closedir($dir); |
|
469 | + return; |
|
470 | + } |
|
471 | + stream_copy_to_stream($sourceStream, $child->fopen('w')); |
|
472 | + } |
|
473 | + } |
|
474 | + } |
|
475 | + closedir($dir); |
|
476 | + } |
|
477 | + |
|
478 | + /** |
|
479 | + * @return void |
|
480 | + * @suppress PhanUndeclaredMethod |
|
481 | + */ |
|
482 | + public static function tearDownFS() { |
|
483 | + \OC\Files\Filesystem::tearDown(); |
|
484 | + \OC::$server->getRootFolder()->clearCache(); |
|
485 | + self::$fsSetup = false; |
|
486 | + self::$rootMounted = false; |
|
487 | + } |
|
488 | + |
|
489 | + /** |
|
490 | + * get the current installed version of ownCloud |
|
491 | + * |
|
492 | + * @return array |
|
493 | + */ |
|
494 | + public static function getVersion() { |
|
495 | + OC_Util::loadVersion(); |
|
496 | + return self::$versionCache['OC_Version']; |
|
497 | + } |
|
498 | + |
|
499 | + /** |
|
500 | + * get the current installed version string of ownCloud |
|
501 | + * |
|
502 | + * @return string |
|
503 | + */ |
|
504 | + public static function getVersionString() { |
|
505 | + OC_Util::loadVersion(); |
|
506 | + return self::$versionCache['OC_VersionString']; |
|
507 | + } |
|
508 | + |
|
509 | + /** |
|
510 | + * @deprecated the value is of no use anymore |
|
511 | + * @return string |
|
512 | + */ |
|
513 | + public static function getEditionString() { |
|
514 | + return ''; |
|
515 | + } |
|
516 | + |
|
517 | + /** |
|
518 | + * @description get the update channel of the current installed of ownCloud. |
|
519 | + * @return string |
|
520 | + */ |
|
521 | + public static function getChannel() { |
|
522 | + OC_Util::loadVersion(); |
|
523 | + return \OC::$server->getConfig()->getSystemValue('updater.release.channel', self::$versionCache['OC_Channel']); |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * @description get the build number of the current installed of ownCloud. |
|
528 | + * @return string |
|
529 | + */ |
|
530 | + public static function getBuild() { |
|
531 | + OC_Util::loadVersion(); |
|
532 | + return self::$versionCache['OC_Build']; |
|
533 | + } |
|
534 | + |
|
535 | + /** |
|
536 | + * @description load the version.php into the session as cache |
|
537 | + * @suppress PhanUndeclaredVariable |
|
538 | + */ |
|
539 | + private static function loadVersion() { |
|
540 | + if (self::$versionCache !== null) { |
|
541 | + return; |
|
542 | + } |
|
543 | + |
|
544 | + $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); |
|
545 | + require OC::$SERVERROOT . '/version.php'; |
|
546 | + /** @var int $timestamp */ |
|
547 | + self::$versionCache['OC_Version_Timestamp'] = $timestamp; |
|
548 | + /** @var string $OC_Version */ |
|
549 | + self::$versionCache['OC_Version'] = $OC_Version; |
|
550 | + /** @var string $OC_VersionString */ |
|
551 | + self::$versionCache['OC_VersionString'] = $OC_VersionString; |
|
552 | + /** @var string $OC_Build */ |
|
553 | + self::$versionCache['OC_Build'] = $OC_Build; |
|
554 | + |
|
555 | + /** @var string $OC_Channel */ |
|
556 | + self::$versionCache['OC_Channel'] = $OC_Channel; |
|
557 | + } |
|
558 | + |
|
559 | + /** |
|
560 | + * generates a path for JS/CSS files. If no application is provided it will create the path for core. |
|
561 | + * |
|
562 | + * @param string $application application to get the files from |
|
563 | + * @param string $directory directory within this application (css, js, vendor, etc) |
|
564 | + * @param string $file the file inside of the above folder |
|
565 | + * @return string the path |
|
566 | + */ |
|
567 | + private static function generatePath($application, $directory, $file) { |
|
568 | + if (is_null($file)) { |
|
569 | + $file = $application; |
|
570 | + $application = ""; |
|
571 | + } |
|
572 | + if (!empty($application)) { |
|
573 | + return "$application/$directory/$file"; |
|
574 | + } else { |
|
575 | + return "$directory/$file"; |
|
576 | + } |
|
577 | + } |
|
578 | + |
|
579 | + /** |
|
580 | + * add a javascript file |
|
581 | + * |
|
582 | + * @param string $application application id |
|
583 | + * @param string|null $file filename |
|
584 | + * @param bool $prepend prepend the Script to the beginning of the list |
|
585 | + * @return void |
|
586 | + */ |
|
587 | + public static function addScript($application, $file = null, $prepend = false) { |
|
588 | + $path = OC_Util::generatePath($application, 'js', $file); |
|
589 | + |
|
590 | + // core js files need separate handling |
|
591 | + if ($application !== 'core' && $file !== null) { |
|
592 | + self::addTranslations($application); |
|
593 | + } |
|
594 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
595 | + } |
|
596 | + |
|
597 | + /** |
|
598 | + * add a javascript file from the vendor sub folder |
|
599 | + * |
|
600 | + * @param string $application application id |
|
601 | + * @param string|null $file filename |
|
602 | + * @param bool $prepend prepend the Script to the beginning of the list |
|
603 | + * @return void |
|
604 | + */ |
|
605 | + public static function addVendorScript($application, $file = null, $prepend = false) { |
|
606 | + $path = OC_Util::generatePath($application, 'vendor', $file); |
|
607 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
608 | + } |
|
609 | + |
|
610 | + /** |
|
611 | + * add a translation JS file |
|
612 | + * |
|
613 | + * @param string $application application id |
|
614 | + * @param string|null $languageCode language code, defaults to the current language |
|
615 | + * @param bool|null $prepend prepend the Script to the beginning of the list |
|
616 | + */ |
|
617 | + public static function addTranslations($application, $languageCode = null, $prepend = false) { |
|
618 | + if (is_null($languageCode)) { |
|
619 | + $languageCode = \OC::$server->getL10NFactory()->findLanguage($application); |
|
620 | + } |
|
621 | + if (!empty($application)) { |
|
622 | + $path = "$application/l10n/$languageCode"; |
|
623 | + } else { |
|
624 | + $path = "l10n/$languageCode"; |
|
625 | + } |
|
626 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
627 | + } |
|
628 | + |
|
629 | + /** |
|
630 | + * add a css file |
|
631 | + * |
|
632 | + * @param string $application application id |
|
633 | + * @param string|null $file filename |
|
634 | + * @param bool $prepend prepend the Style to the beginning of the list |
|
635 | + * @return void |
|
636 | + */ |
|
637 | + public static function addStyle($application, $file = null, $prepend = false) { |
|
638 | + $path = OC_Util::generatePath($application, 'css', $file); |
|
639 | + self::addExternalResource($application, $prepend, $path, "style"); |
|
640 | + } |
|
641 | + |
|
642 | + /** |
|
643 | + * add a css file from the vendor sub folder |
|
644 | + * |
|
645 | + * @param string $application application id |
|
646 | + * @param string|null $file filename |
|
647 | + * @param bool $prepend prepend the Style to the beginning of the list |
|
648 | + * @return void |
|
649 | + */ |
|
650 | + public static function addVendorStyle($application, $file = null, $prepend = false) { |
|
651 | + $path = OC_Util::generatePath($application, 'vendor', $file); |
|
652 | + self::addExternalResource($application, $prepend, $path, "style"); |
|
653 | + } |
|
654 | + |
|
655 | + /** |
|
656 | + * add an external resource css/js file |
|
657 | + * |
|
658 | + * @param string $application application id |
|
659 | + * @param bool $prepend prepend the file to the beginning of the list |
|
660 | + * @param string $path |
|
661 | + * @param string $type (script or style) |
|
662 | + * @return void |
|
663 | + */ |
|
664 | + private static function addExternalResource($application, $prepend, $path, $type = "script") { |
|
665 | + if ($type === "style") { |
|
666 | + if (!in_array($path, self::$styles)) { |
|
667 | + if ($prepend === true) { |
|
668 | + array_unshift(self::$styles, $path); |
|
669 | + } else { |
|
670 | + self::$styles[] = $path; |
|
671 | + } |
|
672 | + } |
|
673 | + } elseif ($type === "script") { |
|
674 | + if (!in_array($path, self::$scripts)) { |
|
675 | + if ($prepend === true) { |
|
676 | + array_unshift(self::$scripts, $path); |
|
677 | + } else { |
|
678 | + self::$scripts [] = $path; |
|
679 | + } |
|
680 | + } |
|
681 | + } |
|
682 | + } |
|
683 | + |
|
684 | + /** |
|
685 | + * Add a custom element to the header |
|
686 | + * If $text is null then the element will be written as empty element. |
|
687 | + * So use "" to get a closing tag. |
|
688 | + * @param string $tag tag name of the element |
|
689 | + * @param array $attributes array of attributes for the element |
|
690 | + * @param string $text the text content for the element |
|
691 | + * @param bool $prepend prepend the header to the beginning of the list |
|
692 | + */ |
|
693 | + public static function addHeader($tag, $attributes, $text = null, $prepend = false) { |
|
694 | + $header = [ |
|
695 | + 'tag' => $tag, |
|
696 | + 'attributes' => $attributes, |
|
697 | + 'text' => $text |
|
698 | + ]; |
|
699 | + if ($prepend === true) { |
|
700 | + array_unshift(self::$headers, $header); |
|
701 | + } else { |
|
702 | + self::$headers[] = $header; |
|
703 | + } |
|
704 | + } |
|
705 | + |
|
706 | + /** |
|
707 | + * check if the current server configuration is suitable for ownCloud |
|
708 | + * |
|
709 | + * @param \OC\SystemConfig $config |
|
710 | + * @return array arrays with error messages and hints |
|
711 | + */ |
|
712 | + public static function checkServer(\OC\SystemConfig $config) { |
|
713 | + $l = \OC::$server->getL10N('lib'); |
|
714 | + $errors = []; |
|
715 | + $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
716 | + |
|
717 | + if (!self::needUpgrade($config) && $config->getValue('installed', false)) { |
|
718 | + // this check needs to be done every time |
|
719 | + $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY); |
|
720 | + } |
|
721 | + |
|
722 | + // Assume that if checkServer() succeeded before in this session, then all is fine. |
|
723 | + if (\OC::$server->getSession()->exists('checkServer_succeeded') && \OC::$server->getSession()->get('checkServer_succeeded')) { |
|
724 | + return $errors; |
|
725 | + } |
|
726 | + |
|
727 | + $webServerRestart = false; |
|
728 | + $setup = new \OC\Setup( |
|
729 | + $config, |
|
730 | + \OC::$server->get(IniGetWrapper::class), |
|
731 | + \OC::$server->getL10N('lib'), |
|
732 | + \OC::$server->get(\OCP\Defaults::class), |
|
733 | + \OC::$server->get(LoggerInterface::class), |
|
734 | + \OC::$server->getSecureRandom(), |
|
735 | + \OC::$server->get(\OC\Installer::class) |
|
736 | + ); |
|
737 | + |
|
738 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
739 | + |
|
740 | + $availableDatabases = $setup->getSupportedDatabases(); |
|
741 | + if (empty($availableDatabases)) { |
|
742 | + $errors[] = [ |
|
743 | + 'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'), |
|
744 | + 'hint' => '' //TODO: sane hint |
|
745 | + ]; |
|
746 | + $webServerRestart = true; |
|
747 | + } |
|
748 | + |
|
749 | + // Check if config folder is writable. |
|
750 | + if (!OC_Helper::isReadOnlyConfigEnabled()) { |
|
751 | + if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) { |
|
752 | + $errors[] = [ |
|
753 | + 'error' => $l->t('Cannot write into "config" directory'), |
|
754 | + 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
|
755 | + [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) . '. ' |
|
756 | + . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s', |
|
757 | + [ $urlGenerator->linkToDocs('admin-config') ]) |
|
758 | + ]; |
|
759 | + } |
|
760 | + } |
|
761 | + |
|
762 | + // Check if there is a writable install folder. |
|
763 | + if ($config->getValue('appstoreenabled', true)) { |
|
764 | + if (OC_App::getInstallPath() === null |
|
765 | + || !is_writable(OC_App::getInstallPath()) |
|
766 | + || !is_readable(OC_App::getInstallPath()) |
|
767 | + ) { |
|
768 | + $errors[] = [ |
|
769 | + 'error' => $l->t('Cannot write into "apps" directory'), |
|
770 | + 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the apps directory' |
|
771 | + . ' or disabling the appstore in the config file.') |
|
772 | + ]; |
|
773 | + } |
|
774 | + } |
|
775 | + // Create root dir. |
|
776 | + if ($config->getValue('installed', false)) { |
|
777 | + if (!is_dir($CONFIG_DATADIRECTORY)) { |
|
778 | + $success = @mkdir($CONFIG_DATADIRECTORY); |
|
779 | + if ($success) { |
|
780 | + $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
781 | + } else { |
|
782 | + $errors[] = [ |
|
783 | + 'error' => $l->t('Cannot create "data" directory'), |
|
784 | + 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the root directory. See %s', |
|
785 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
786 | + ]; |
|
787 | + } |
|
788 | + } elseif (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) { |
|
789 | + // is_writable doesn't work for NFS mounts, so try to write a file and check if it exists. |
|
790 | + $testFile = sprintf('%s/%s.tmp', $CONFIG_DATADIRECTORY, uniqid('data_dir_writability_test_')); |
|
791 | + $handle = fopen($testFile, 'w'); |
|
792 | + if (!$handle || fwrite($handle, 'Test write operation') === false) { |
|
793 | + $permissionsHint = $l->t('Permissions can usually be fixed by giving the webserver write access to the root directory. See %s.', |
|
794 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]); |
|
795 | + $errors[] = [ |
|
796 | + 'error' => 'Your data directory is not writable', |
|
797 | + 'hint' => $permissionsHint |
|
798 | + ]; |
|
799 | + } else { |
|
800 | + fclose($handle); |
|
801 | + unlink($testFile); |
|
802 | + } |
|
803 | + } else { |
|
804 | + $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
805 | + } |
|
806 | + } |
|
807 | + |
|
808 | + if (!OC_Util::isSetLocaleWorking()) { |
|
809 | + $errors[] = [ |
|
810 | + 'error' => $l->t('Setting locale to %s failed', |
|
811 | + ['en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/' |
|
812 | + . 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8']), |
|
813 | + 'hint' => $l->t('Please install one of these locales on your system and restart your webserver.') |
|
814 | + ]; |
|
815 | + } |
|
816 | + |
|
817 | + // Contains the dependencies that should be checked against |
|
818 | + // classes = class_exists |
|
819 | + // functions = function_exists |
|
820 | + // defined = defined |
|
821 | + // ini = ini_get |
|
822 | + // If the dependency is not found the missing module name is shown to the EndUser |
|
823 | + // When adding new checks always verify that they pass on Travis as well |
|
824 | + // for ini settings, see https://github.com/owncloud/administration/blob/master/travis-ci/custom.ini |
|
825 | + $dependencies = [ |
|
826 | + 'classes' => [ |
|
827 | + 'ZipArchive' => 'zip', |
|
828 | + 'DOMDocument' => 'dom', |
|
829 | + 'XMLWriter' => 'XMLWriter', |
|
830 | + 'XMLReader' => 'XMLReader', |
|
831 | + ], |
|
832 | + 'functions' => [ |
|
833 | + 'xml_parser_create' => 'libxml', |
|
834 | + 'mb_strcut' => 'mbstring', |
|
835 | + 'ctype_digit' => 'ctype', |
|
836 | + 'json_encode' => 'JSON', |
|
837 | + 'gd_info' => 'GD', |
|
838 | + 'gzencode' => 'zlib', |
|
839 | + 'iconv' => 'iconv', |
|
840 | + 'simplexml_load_string' => 'SimpleXML', |
|
841 | + 'hash' => 'HASH Message Digest Framework', |
|
842 | + 'curl_init' => 'cURL', |
|
843 | + 'openssl_verify' => 'OpenSSL', |
|
844 | + ], |
|
845 | + 'defined' => [ |
|
846 | + 'PDO::ATTR_DRIVER_NAME' => 'PDO' |
|
847 | + ], |
|
848 | + 'ini' => [ |
|
849 | + 'default_charset' => 'UTF-8', |
|
850 | + ], |
|
851 | + ]; |
|
852 | + $missingDependencies = []; |
|
853 | + $invalidIniSettings = []; |
|
854 | + |
|
855 | + $iniWrapper = \OC::$server->get(IniGetWrapper::class); |
|
856 | + foreach ($dependencies['classes'] as $class => $module) { |
|
857 | + if (!class_exists($class)) { |
|
858 | + $missingDependencies[] = $module; |
|
859 | + } |
|
860 | + } |
|
861 | + foreach ($dependencies['functions'] as $function => $module) { |
|
862 | + if (!function_exists($function)) { |
|
863 | + $missingDependencies[] = $module; |
|
864 | + } |
|
865 | + } |
|
866 | + foreach ($dependencies['defined'] as $defined => $module) { |
|
867 | + if (!defined($defined)) { |
|
868 | + $missingDependencies[] = $module; |
|
869 | + } |
|
870 | + } |
|
871 | + foreach ($dependencies['ini'] as $setting => $expected) { |
|
872 | + if (is_bool($expected)) { |
|
873 | + if ($iniWrapper->getBool($setting) !== $expected) { |
|
874 | + $invalidIniSettings[] = [$setting, $expected]; |
|
875 | + } |
|
876 | + } |
|
877 | + if (is_int($expected)) { |
|
878 | + if ($iniWrapper->getNumeric($setting) !== $expected) { |
|
879 | + $invalidIniSettings[] = [$setting, $expected]; |
|
880 | + } |
|
881 | + } |
|
882 | + if (is_string($expected)) { |
|
883 | + if (strtolower($iniWrapper->getString($setting)) !== strtolower($expected)) { |
|
884 | + $invalidIniSettings[] = [$setting, $expected]; |
|
885 | + } |
|
886 | + } |
|
887 | + } |
|
888 | + |
|
889 | + foreach ($missingDependencies as $missingDependency) { |
|
890 | + $errors[] = [ |
|
891 | + 'error' => $l->t('PHP module %s not installed.', [$missingDependency]), |
|
892 | + 'hint' => $l->t('Please ask your server administrator to install the module.'), |
|
893 | + ]; |
|
894 | + $webServerRestart = true; |
|
895 | + } |
|
896 | + foreach ($invalidIniSettings as $setting) { |
|
897 | + if (is_bool($setting[1])) { |
|
898 | + $setting[1] = $setting[1] ? 'on' : 'off'; |
|
899 | + } |
|
900 | + $errors[] = [ |
|
901 | + 'error' => $l->t('PHP setting "%s" is not set to "%s".', [$setting[0], var_export($setting[1], true)]), |
|
902 | + 'hint' => $l->t('Adjusting this setting in php.ini will make Nextcloud run again') |
|
903 | + ]; |
|
904 | + $webServerRestart = true; |
|
905 | + } |
|
906 | + |
|
907 | + /** |
|
908 | + * The mbstring.func_overload check can only be performed if the mbstring |
|
909 | + * module is installed as it will return null if the checking setting is |
|
910 | + * not available and thus a check on the boolean value fails. |
|
911 | + * |
|
912 | + * TODO: Should probably be implemented in the above generic dependency |
|
913 | + * check somehow in the long-term. |
|
914 | + */ |
|
915 | + if ($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
916 | + $iniWrapper->getBool('mbstring.func_overload') === true) { |
|
917 | + $errors[] = [ |
|
918 | + 'error' => $l->t('mbstring.func_overload is set to "%s" instead of the expected value "0"', [$iniWrapper->getString('mbstring.func_overload')]), |
|
919 | + 'hint' => $l->t('To fix this issue set <code>mbstring.func_overload</code> to <code>0</code> in your php.ini') |
|
920 | + ]; |
|
921 | + } |
|
922 | + |
|
923 | + if (function_exists('xml_parser_create') && |
|
924 | + LIBXML_LOADED_VERSION < 20700) { |
|
925 | + $version = LIBXML_LOADED_VERSION; |
|
926 | + $major = floor($version / 10000); |
|
927 | + $version -= ($major * 10000); |
|
928 | + $minor = floor($version / 100); |
|
929 | + $version -= ($minor * 100); |
|
930 | + $patch = $version; |
|
931 | + $errors[] = [ |
|
932 | + 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]), |
|
933 | + 'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.') |
|
934 | + ]; |
|
935 | + } |
|
936 | + |
|
937 | + if (!self::isAnnotationsWorking()) { |
|
938 | + $errors[] = [ |
|
939 | + 'error' => $l->t('PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.'), |
|
940 | + 'hint' => $l->t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.') |
|
941 | + ]; |
|
942 | + } |
|
943 | + |
|
944 | + if (!\OC::$CLI && $webServerRestart) { |
|
945 | + $errors[] = [ |
|
946 | + 'error' => $l->t('PHP modules have been installed, but they are still listed as missing?'), |
|
947 | + 'hint' => $l->t('Please ask your server administrator to restart the web server.') |
|
948 | + ]; |
|
949 | + } |
|
950 | + |
|
951 | + $errors = array_merge($errors, self::checkDatabaseVersion()); |
|
952 | + |
|
953 | + // Cache the result of this function |
|
954 | + \OC::$server->getSession()->set('checkServer_succeeded', count($errors) == 0); |
|
955 | + |
|
956 | + return $errors; |
|
957 | + } |
|
958 | + |
|
959 | + /** |
|
960 | + * Check the database version |
|
961 | + * |
|
962 | + * @return array errors array |
|
963 | + */ |
|
964 | + public static function checkDatabaseVersion() { |
|
965 | + $l = \OC::$server->getL10N('lib'); |
|
966 | + $errors = []; |
|
967 | + $dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite'); |
|
968 | + if ($dbType === 'pgsql') { |
|
969 | + // check PostgreSQL version |
|
970 | + try { |
|
971 | + $result = \OC_DB::executeAudited('SHOW SERVER_VERSION'); |
|
972 | + $data = $result->fetchRow(); |
|
973 | + $result->closeCursor(); |
|
974 | + if (isset($data['server_version'])) { |
|
975 | + $version = $data['server_version']; |
|
976 | + if (version_compare($version, '9.0.0', '<')) { |
|
977 | + $errors[] = [ |
|
978 | + 'error' => $l->t('PostgreSQL >= 9 required'), |
|
979 | + 'hint' => $l->t('Please upgrade your database version') |
|
980 | + ]; |
|
981 | + } |
|
982 | + } |
|
983 | + } catch (\Doctrine\DBAL\Exception $e) { |
|
984 | + $logger = \OC::$server->getLogger(); |
|
985 | + $logger->warning('Error occurred while checking PostgreSQL version, assuming >= 9'); |
|
986 | + $logger->logException($e); |
|
987 | + } |
|
988 | + } |
|
989 | + return $errors; |
|
990 | + } |
|
991 | + |
|
992 | + /** |
|
993 | + * Check for correct file permissions of data directory |
|
994 | + * |
|
995 | + * @param string $dataDirectory |
|
996 | + * @return array arrays with error messages and hints |
|
997 | + */ |
|
998 | + public static function checkDataDirectoryPermissions($dataDirectory) { |
|
999 | + if (\OC::$server->getConfig()->getSystemValue('check_data_directory_permissions', true) === false) { |
|
1000 | + return []; |
|
1001 | + } |
|
1002 | + |
|
1003 | + $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
1004 | + if (substr($perms, -1) !== '0') { |
|
1005 | + chmod($dataDirectory, 0770); |
|
1006 | + clearstatcache(); |
|
1007 | + $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
1008 | + if ($perms[2] !== '0') { |
|
1009 | + $l = \OC::$server->getL10N('lib'); |
|
1010 | + return [[ |
|
1011 | + 'error' => $l->t('Your data directory is readable by other users'), |
|
1012 | + 'hint' => $l->t('Please change the permissions to 0770 so that the directory cannot be listed by other users.'), |
|
1013 | + ]]; |
|
1014 | + } |
|
1015 | + } |
|
1016 | + return []; |
|
1017 | + } |
|
1018 | + |
|
1019 | + /** |
|
1020 | + * Check that the data directory exists and is valid by |
|
1021 | + * checking the existence of the ".ocdata" file. |
|
1022 | + * |
|
1023 | + * @param string $dataDirectory data directory path |
|
1024 | + * @return array errors found |
|
1025 | + */ |
|
1026 | + public static function checkDataDirectoryValidity($dataDirectory) { |
|
1027 | + $l = \OC::$server->getL10N('lib'); |
|
1028 | + $errors = []; |
|
1029 | + if ($dataDirectory[0] !== '/') { |
|
1030 | + $errors[] = [ |
|
1031 | + 'error' => $l->t('Your data directory must be an absolute path'), |
|
1032 | + 'hint' => $l->t('Check the value of "datadirectory" in your configuration') |
|
1033 | + ]; |
|
1034 | + } |
|
1035 | + if (!file_exists($dataDirectory . '/.ocdata')) { |
|
1036 | + $errors[] = [ |
|
1037 | + 'error' => $l->t('Your data directory is invalid'), |
|
1038 | + 'hint' => $l->t('Ensure there is a file called ".ocdata"' . |
|
1039 | + ' in the root of the data directory.') |
|
1040 | + ]; |
|
1041 | + } |
|
1042 | + return $errors; |
|
1043 | + } |
|
1044 | + |
|
1045 | + /** |
|
1046 | + * Check if the user is logged in, redirects to home if not. With |
|
1047 | + * redirect URL parameter to the request URI. |
|
1048 | + * |
|
1049 | + * @return void |
|
1050 | + */ |
|
1051 | + public static function checkLoggedIn() { |
|
1052 | + // Check if we are a user |
|
1053 | + if (!\OC::$server->getUserSession()->isLoggedIn()) { |
|
1054 | + header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute( |
|
1055 | + 'core.login.showLoginForm', |
|
1056 | + [ |
|
1057 | + 'redirect_url' => \OC::$server->getRequest()->getRequestUri(), |
|
1058 | + ] |
|
1059 | + ) |
|
1060 | + ); |
|
1061 | + exit(); |
|
1062 | + } |
|
1063 | + // Redirect to 2FA challenge selection if 2FA challenge was not solved yet |
|
1064 | + if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { |
|
1065 | + header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
1066 | + exit(); |
|
1067 | + } |
|
1068 | + } |
|
1069 | + |
|
1070 | + /** |
|
1071 | + * Check if the user is a admin, redirects to home if not |
|
1072 | + * |
|
1073 | + * @return void |
|
1074 | + */ |
|
1075 | + public static function checkAdminUser() { |
|
1076 | + OC_Util::checkLoggedIn(); |
|
1077 | + if (!OC_User::isAdminUser(OC_User::getUser())) { |
|
1078 | + header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
1079 | + exit(); |
|
1080 | + } |
|
1081 | + } |
|
1082 | + |
|
1083 | + /** |
|
1084 | + * Returns the URL of the default page |
|
1085 | + * based on the system configuration and |
|
1086 | + * the apps visible for the current user |
|
1087 | + * |
|
1088 | + * @return string URL |
|
1089 | + * @suppress PhanDeprecatedFunction |
|
1090 | + */ |
|
1091 | + public static function getDefaultPageUrl() { |
|
1092 | + /** @var IConfig $config */ |
|
1093 | + $config = \OC::$server->get(IConfig::class); |
|
1094 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
1095 | + // Deny the redirect if the URL contains a @ |
|
1096 | + // This prevents unvalidated redirects like ?redirect_url=:[email protected] |
|
1097 | + if (isset($_REQUEST['redirect_url']) && strpos($_REQUEST['redirect_url'], '@') === false) { |
|
1098 | + $location = $urlGenerator->getAbsoluteURL(urldecode($_REQUEST['redirect_url'])); |
|
1099 | + } else { |
|
1100 | + $defaultPage = \OC::$server->getConfig()->getAppValue('core', 'defaultpage'); |
|
1101 | + if ($defaultPage) { |
|
1102 | + $location = $urlGenerator->getAbsoluteURL($defaultPage); |
|
1103 | + } else { |
|
1104 | + $appId = 'files'; |
|
1105 | + $defaultApps = explode(',', $config->getSystemValue('defaultapp', 'dashboard,files')); |
|
1106 | + |
|
1107 | + /** @var IUserSession $userSession */ |
|
1108 | + $userSession = \OC::$server->get(IUserSession::class); |
|
1109 | + $user = $userSession->getUser(); |
|
1110 | + if ($user) { |
|
1111 | + $userDefaultApps = explode(',', $config->getUserValue($user->getUID(), 'core', 'defaultapp')); |
|
1112 | + $defaultApps = array_filter(array_merge($userDefaultApps, $defaultApps)); |
|
1113 | + } |
|
1114 | + |
|
1115 | + // find the first app that is enabled for the current user |
|
1116 | + foreach ($defaultApps as $defaultApp) { |
|
1117 | + $defaultApp = OC_App::cleanAppId(strip_tags($defaultApp)); |
|
1118 | + if (static::getAppManager()->isEnabledForUser($defaultApp)) { |
|
1119 | + $appId = $defaultApp; |
|
1120 | + break; |
|
1121 | + } |
|
1122 | + } |
|
1123 | + |
|
1124 | + if ($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { |
|
1125 | + $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); |
|
1126 | + } else { |
|
1127 | + $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); |
|
1128 | + } |
|
1129 | + } |
|
1130 | + } |
|
1131 | + return $location; |
|
1132 | + } |
|
1133 | + |
|
1134 | + /** |
|
1135 | + * Redirect to the user default page |
|
1136 | + * |
|
1137 | + * @return void |
|
1138 | + */ |
|
1139 | + public static function redirectToDefaultPage() { |
|
1140 | + $location = self::getDefaultPageUrl(); |
|
1141 | + header('Location: ' . $location); |
|
1142 | + exit(); |
|
1143 | + } |
|
1144 | + |
|
1145 | + /** |
|
1146 | + * get an id unique for this instance |
|
1147 | + * |
|
1148 | + * @return string |
|
1149 | + */ |
|
1150 | + public static function getInstanceId() { |
|
1151 | + $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
1152 | + if (is_null($id)) { |
|
1153 | + // We need to guarantee at least one letter in instanceid so it can be used as the session_name |
|
1154 | + $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
1155 | + \OC::$server->getSystemConfig()->setValue('instanceid', $id); |
|
1156 | + } |
|
1157 | + return $id; |
|
1158 | + } |
|
1159 | + |
|
1160 | + /** |
|
1161 | + * Public function to sanitize HTML |
|
1162 | + * |
|
1163 | + * This function is used to sanitize HTML and should be applied on any |
|
1164 | + * string or array of strings before displaying it on a web page. |
|
1165 | + * |
|
1166 | + * @param string|array $value |
|
1167 | + * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
1168 | + */ |
|
1169 | + public static function sanitizeHTML($value) { |
|
1170 | + if (is_array($value)) { |
|
1171 | + $value = array_map(function ($value) { |
|
1172 | + return self::sanitizeHTML($value); |
|
1173 | + }, $value); |
|
1174 | + } else { |
|
1175 | + // Specify encoding for PHP<5.4 |
|
1176 | + $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); |
|
1177 | + } |
|
1178 | + return $value; |
|
1179 | + } |
|
1180 | + |
|
1181 | + /** |
|
1182 | + * Public function to encode url parameters |
|
1183 | + * |
|
1184 | + * This function is used to encode path to file before output. |
|
1185 | + * Encoding is done according to RFC 3986 with one exception: |
|
1186 | + * Character '/' is preserved as is. |
|
1187 | + * |
|
1188 | + * @param string $component part of URI to encode |
|
1189 | + * @return string |
|
1190 | + */ |
|
1191 | + public static function encodePath($component) { |
|
1192 | + $encoded = rawurlencode($component); |
|
1193 | + $encoded = str_replace('%2F', '/', $encoded); |
|
1194 | + return $encoded; |
|
1195 | + } |
|
1196 | + |
|
1197 | + |
|
1198 | + public function createHtaccessTestFile(\OCP\IConfig $config) { |
|
1199 | + // php dev server does not support htaccess |
|
1200 | + if (php_sapi_name() === 'cli-server') { |
|
1201 | + return false; |
|
1202 | + } |
|
1203 | + |
|
1204 | + // testdata |
|
1205 | + $fileName = '/htaccesstest.txt'; |
|
1206 | + $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; |
|
1207 | + |
|
1208 | + // creating a test file |
|
1209 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
1210 | + |
|
1211 | + if (file_exists($testFile)) {// already running this test, possible recursive call |
|
1212 | + return false; |
|
1213 | + } |
|
1214 | + |
|
1215 | + $fp = @fopen($testFile, 'w'); |
|
1216 | + if (!$fp) { |
|
1217 | + throw new OC\HintException('Can\'t create test file to check for working .htaccess file.', |
|
1218 | + 'Make sure it is possible for the webserver to write to ' . $testFile); |
|
1219 | + } |
|
1220 | + fwrite($fp, $testContent); |
|
1221 | + fclose($fp); |
|
1222 | + |
|
1223 | + return $testContent; |
|
1224 | + } |
|
1225 | + |
|
1226 | + /** |
|
1227 | + * Check if the .htaccess file is working |
|
1228 | + * @param \OCP\IConfig $config |
|
1229 | + * @return bool |
|
1230 | + * @throws Exception |
|
1231 | + * @throws \OC\HintException If the test file can't get written. |
|
1232 | + */ |
|
1233 | + public function isHtaccessWorking(\OCP\IConfig $config) { |
|
1234 | + if (\OC::$CLI || !$config->getSystemValue('check_for_working_htaccess', true)) { |
|
1235 | + return true; |
|
1236 | + } |
|
1237 | + |
|
1238 | + $testContent = $this->createHtaccessTestFile($config); |
|
1239 | + if ($testContent === false) { |
|
1240 | + return false; |
|
1241 | + } |
|
1242 | + |
|
1243 | + $fileName = '/htaccesstest.txt'; |
|
1244 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
1245 | + |
|
1246 | + // accessing the file via http |
|
1247 | + $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); |
|
1248 | + try { |
|
1249 | + $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
|
1250 | + } catch (\Exception $e) { |
|
1251 | + $content = false; |
|
1252 | + } |
|
1253 | + |
|
1254 | + if (strpos($url, 'https:') === 0) { |
|
1255 | + $url = 'http:' . substr($url, 6); |
|
1256 | + } else { |
|
1257 | + $url = 'https:' . substr($url, 5); |
|
1258 | + } |
|
1259 | + |
|
1260 | + try { |
|
1261 | + $fallbackContent = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
|
1262 | + } catch (\Exception $e) { |
|
1263 | + $fallbackContent = false; |
|
1264 | + } |
|
1265 | + |
|
1266 | + // cleanup |
|
1267 | + @unlink($testFile); |
|
1268 | + |
|
1269 | + /* |
|
1270 | 1270 | * If the content is not equal to test content our .htaccess |
1271 | 1271 | * is working as required |
1272 | 1272 | */ |
1273 | - return $content !== $testContent && $fallbackContent !== $testContent; |
|
1274 | - } |
|
1275 | - |
|
1276 | - /** |
|
1277 | - * Check if the setlocal call does not work. This can happen if the right |
|
1278 | - * local packages are not available on the server. |
|
1279 | - * |
|
1280 | - * @return bool |
|
1281 | - */ |
|
1282 | - public static function isSetLocaleWorking() { |
|
1283 | - if ('' === basename('§')) { |
|
1284 | - // Borrowed from \Patchwork\Utf8\Bootup::initLocale |
|
1285 | - setlocale(LC_ALL, 'C.UTF-8', 'C'); |
|
1286 | - setlocale(LC_CTYPE, 'en_US.UTF-8', 'fr_FR.UTF-8', 'es_ES.UTF-8', 'de_DE.UTF-8', 'ru_RU.UTF-8', 'pt_BR.UTF-8', 'it_IT.UTF-8', 'ja_JP.UTF-8', 'zh_CN.UTF-8', '0'); |
|
1287 | - } |
|
1288 | - |
|
1289 | - // Check again |
|
1290 | - if ('' === basename('§')) { |
|
1291 | - return false; |
|
1292 | - } |
|
1293 | - return true; |
|
1294 | - } |
|
1295 | - |
|
1296 | - /** |
|
1297 | - * Check if it's possible to get the inline annotations |
|
1298 | - * |
|
1299 | - * @return bool |
|
1300 | - */ |
|
1301 | - public static function isAnnotationsWorking() { |
|
1302 | - $reflection = new \ReflectionMethod(__METHOD__); |
|
1303 | - $docs = $reflection->getDocComment(); |
|
1304 | - |
|
1305 | - return (is_string($docs) && strlen($docs) > 50); |
|
1306 | - } |
|
1307 | - |
|
1308 | - /** |
|
1309 | - * Check if the PHP module fileinfo is loaded. |
|
1310 | - * |
|
1311 | - * @return bool |
|
1312 | - */ |
|
1313 | - public static function fileInfoLoaded() { |
|
1314 | - return function_exists('finfo_open'); |
|
1315 | - } |
|
1316 | - |
|
1317 | - /** |
|
1318 | - * clear all levels of output buffering |
|
1319 | - * |
|
1320 | - * @return void |
|
1321 | - */ |
|
1322 | - public static function obEnd() { |
|
1323 | - while (ob_get_level()) { |
|
1324 | - ob_end_clean(); |
|
1325 | - } |
|
1326 | - } |
|
1327 | - |
|
1328 | - /** |
|
1329 | - * Checks whether the server is running on Mac OS X |
|
1330 | - * |
|
1331 | - * @return bool true if running on Mac OS X, false otherwise |
|
1332 | - */ |
|
1333 | - public static function runningOnMac() { |
|
1334 | - return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN'); |
|
1335 | - } |
|
1336 | - |
|
1337 | - /** |
|
1338 | - * Handles the case that there may not be a theme, then check if a "default" |
|
1339 | - * theme exists and take that one |
|
1340 | - * |
|
1341 | - * @return string the theme |
|
1342 | - */ |
|
1343 | - public static function getTheme() { |
|
1344 | - $theme = \OC::$server->getSystemConfig()->getValue("theme", ''); |
|
1345 | - |
|
1346 | - if ($theme === '') { |
|
1347 | - if (is_dir(OC::$SERVERROOT . '/themes/default')) { |
|
1348 | - $theme = 'default'; |
|
1349 | - } |
|
1350 | - } |
|
1351 | - |
|
1352 | - return $theme; |
|
1353 | - } |
|
1354 | - |
|
1355 | - /** |
|
1356 | - * Normalize a unicode string |
|
1357 | - * |
|
1358 | - * @param string $value a not normalized string |
|
1359 | - * @return bool|string |
|
1360 | - */ |
|
1361 | - public static function normalizeUnicode($value) { |
|
1362 | - if (Normalizer::isNormalized($value)) { |
|
1363 | - return $value; |
|
1364 | - } |
|
1365 | - |
|
1366 | - $normalizedValue = Normalizer::normalize($value); |
|
1367 | - if ($normalizedValue === null || $normalizedValue === false) { |
|
1368 | - \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); |
|
1369 | - return $value; |
|
1370 | - } |
|
1371 | - |
|
1372 | - return $normalizedValue; |
|
1373 | - } |
|
1374 | - |
|
1375 | - /** |
|
1376 | - * A human readable string is generated based on version and build number |
|
1377 | - * |
|
1378 | - * @return string |
|
1379 | - */ |
|
1380 | - public static function getHumanVersion() { |
|
1381 | - $version = OC_Util::getVersionString(); |
|
1382 | - $build = OC_Util::getBuild(); |
|
1383 | - if (!empty($build) and OC_Util::getChannel() === 'daily') { |
|
1384 | - $version .= ' Build:' . $build; |
|
1385 | - } |
|
1386 | - return $version; |
|
1387 | - } |
|
1388 | - |
|
1389 | - /** |
|
1390 | - * Returns whether the given file name is valid |
|
1391 | - * |
|
1392 | - * @param string $file file name to check |
|
1393 | - * @return bool true if the file name is valid, false otherwise |
|
1394 | - * @deprecated use \OC\Files\View::verifyPath() |
|
1395 | - */ |
|
1396 | - public static function isValidFileName($file) { |
|
1397 | - $trimmed = trim($file); |
|
1398 | - if ($trimmed === '') { |
|
1399 | - return false; |
|
1400 | - } |
|
1401 | - if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) { |
|
1402 | - return false; |
|
1403 | - } |
|
1404 | - |
|
1405 | - // detect part files |
|
1406 | - if (preg_match('/' . \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX . '/', $trimmed) !== 0) { |
|
1407 | - return false; |
|
1408 | - } |
|
1409 | - |
|
1410 | - foreach (str_split($trimmed) as $char) { |
|
1411 | - if (strpos(\OCP\Constants::FILENAME_INVALID_CHARS, $char) !== false) { |
|
1412 | - return false; |
|
1413 | - } |
|
1414 | - } |
|
1415 | - return true; |
|
1416 | - } |
|
1417 | - |
|
1418 | - /** |
|
1419 | - * Check whether the instance needs to perform an upgrade, |
|
1420 | - * either when the core version is higher or any app requires |
|
1421 | - * an upgrade. |
|
1422 | - * |
|
1423 | - * @param \OC\SystemConfig $config |
|
1424 | - * @return bool whether the core or any app needs an upgrade |
|
1425 | - * @throws \OC\HintException When the upgrade from the given version is not allowed |
|
1426 | - */ |
|
1427 | - public static function needUpgrade(\OC\SystemConfig $config) { |
|
1428 | - if ($config->getValue('installed', false)) { |
|
1429 | - $installedVersion = $config->getValue('version', '0.0.0'); |
|
1430 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
1431 | - $versionDiff = version_compare($currentVersion, $installedVersion); |
|
1432 | - if ($versionDiff > 0) { |
|
1433 | - return true; |
|
1434 | - } elseif ($config->getValue('debug', false) && $versionDiff < 0) { |
|
1435 | - // downgrade with debug |
|
1436 | - $installedMajor = explode('.', $installedVersion); |
|
1437 | - $installedMajor = $installedMajor[0] . '.' . $installedMajor[1]; |
|
1438 | - $currentMajor = explode('.', $currentVersion); |
|
1439 | - $currentMajor = $currentMajor[0] . '.' . $currentMajor[1]; |
|
1440 | - if ($installedMajor === $currentMajor) { |
|
1441 | - // Same major, allow downgrade for developers |
|
1442 | - return true; |
|
1443 | - } else { |
|
1444 | - // downgrade attempt, throw exception |
|
1445 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
1446 | - } |
|
1447 | - } elseif ($versionDiff < 0) { |
|
1448 | - // downgrade attempt, throw exception |
|
1449 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
1450 | - } |
|
1451 | - |
|
1452 | - // also check for upgrades for apps (independently from the user) |
|
1453 | - $apps = \OC_App::getEnabledApps(false, true); |
|
1454 | - $shouldUpgrade = false; |
|
1455 | - foreach ($apps as $app) { |
|
1456 | - if (\OC_App::shouldUpgrade($app)) { |
|
1457 | - $shouldUpgrade = true; |
|
1458 | - break; |
|
1459 | - } |
|
1460 | - } |
|
1461 | - return $shouldUpgrade; |
|
1462 | - } else { |
|
1463 | - return false; |
|
1464 | - } |
|
1465 | - } |
|
1466 | - |
|
1467 | - /** |
|
1468 | - * is this Internet explorer ? |
|
1469 | - * |
|
1470 | - * @return boolean |
|
1471 | - */ |
|
1472 | - public static function isIe() { |
|
1473 | - if (!isset($_SERVER['HTTP_USER_AGENT'])) { |
|
1474 | - return false; |
|
1475 | - } |
|
1476 | - |
|
1477 | - return preg_match(Request::USER_AGENT_IE, $_SERVER['HTTP_USER_AGENT']) === 1; |
|
1478 | - } |
|
1273 | + return $content !== $testContent && $fallbackContent !== $testContent; |
|
1274 | + } |
|
1275 | + |
|
1276 | + /** |
|
1277 | + * Check if the setlocal call does not work. This can happen if the right |
|
1278 | + * local packages are not available on the server. |
|
1279 | + * |
|
1280 | + * @return bool |
|
1281 | + */ |
|
1282 | + public static function isSetLocaleWorking() { |
|
1283 | + if ('' === basename('§')) { |
|
1284 | + // Borrowed from \Patchwork\Utf8\Bootup::initLocale |
|
1285 | + setlocale(LC_ALL, 'C.UTF-8', 'C'); |
|
1286 | + setlocale(LC_CTYPE, 'en_US.UTF-8', 'fr_FR.UTF-8', 'es_ES.UTF-8', 'de_DE.UTF-8', 'ru_RU.UTF-8', 'pt_BR.UTF-8', 'it_IT.UTF-8', 'ja_JP.UTF-8', 'zh_CN.UTF-8', '0'); |
|
1287 | + } |
|
1288 | + |
|
1289 | + // Check again |
|
1290 | + if ('' === basename('§')) { |
|
1291 | + return false; |
|
1292 | + } |
|
1293 | + return true; |
|
1294 | + } |
|
1295 | + |
|
1296 | + /** |
|
1297 | + * Check if it's possible to get the inline annotations |
|
1298 | + * |
|
1299 | + * @return bool |
|
1300 | + */ |
|
1301 | + public static function isAnnotationsWorking() { |
|
1302 | + $reflection = new \ReflectionMethod(__METHOD__); |
|
1303 | + $docs = $reflection->getDocComment(); |
|
1304 | + |
|
1305 | + return (is_string($docs) && strlen($docs) > 50); |
|
1306 | + } |
|
1307 | + |
|
1308 | + /** |
|
1309 | + * Check if the PHP module fileinfo is loaded. |
|
1310 | + * |
|
1311 | + * @return bool |
|
1312 | + */ |
|
1313 | + public static function fileInfoLoaded() { |
|
1314 | + return function_exists('finfo_open'); |
|
1315 | + } |
|
1316 | + |
|
1317 | + /** |
|
1318 | + * clear all levels of output buffering |
|
1319 | + * |
|
1320 | + * @return void |
|
1321 | + */ |
|
1322 | + public static function obEnd() { |
|
1323 | + while (ob_get_level()) { |
|
1324 | + ob_end_clean(); |
|
1325 | + } |
|
1326 | + } |
|
1327 | + |
|
1328 | + /** |
|
1329 | + * Checks whether the server is running on Mac OS X |
|
1330 | + * |
|
1331 | + * @return bool true if running on Mac OS X, false otherwise |
|
1332 | + */ |
|
1333 | + public static function runningOnMac() { |
|
1334 | + return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN'); |
|
1335 | + } |
|
1336 | + |
|
1337 | + /** |
|
1338 | + * Handles the case that there may not be a theme, then check if a "default" |
|
1339 | + * theme exists and take that one |
|
1340 | + * |
|
1341 | + * @return string the theme |
|
1342 | + */ |
|
1343 | + public static function getTheme() { |
|
1344 | + $theme = \OC::$server->getSystemConfig()->getValue("theme", ''); |
|
1345 | + |
|
1346 | + if ($theme === '') { |
|
1347 | + if (is_dir(OC::$SERVERROOT . '/themes/default')) { |
|
1348 | + $theme = 'default'; |
|
1349 | + } |
|
1350 | + } |
|
1351 | + |
|
1352 | + return $theme; |
|
1353 | + } |
|
1354 | + |
|
1355 | + /** |
|
1356 | + * Normalize a unicode string |
|
1357 | + * |
|
1358 | + * @param string $value a not normalized string |
|
1359 | + * @return bool|string |
|
1360 | + */ |
|
1361 | + public static function normalizeUnicode($value) { |
|
1362 | + if (Normalizer::isNormalized($value)) { |
|
1363 | + return $value; |
|
1364 | + } |
|
1365 | + |
|
1366 | + $normalizedValue = Normalizer::normalize($value); |
|
1367 | + if ($normalizedValue === null || $normalizedValue === false) { |
|
1368 | + \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); |
|
1369 | + return $value; |
|
1370 | + } |
|
1371 | + |
|
1372 | + return $normalizedValue; |
|
1373 | + } |
|
1374 | + |
|
1375 | + /** |
|
1376 | + * A human readable string is generated based on version and build number |
|
1377 | + * |
|
1378 | + * @return string |
|
1379 | + */ |
|
1380 | + public static function getHumanVersion() { |
|
1381 | + $version = OC_Util::getVersionString(); |
|
1382 | + $build = OC_Util::getBuild(); |
|
1383 | + if (!empty($build) and OC_Util::getChannel() === 'daily') { |
|
1384 | + $version .= ' Build:' . $build; |
|
1385 | + } |
|
1386 | + return $version; |
|
1387 | + } |
|
1388 | + |
|
1389 | + /** |
|
1390 | + * Returns whether the given file name is valid |
|
1391 | + * |
|
1392 | + * @param string $file file name to check |
|
1393 | + * @return bool true if the file name is valid, false otherwise |
|
1394 | + * @deprecated use \OC\Files\View::verifyPath() |
|
1395 | + */ |
|
1396 | + public static function isValidFileName($file) { |
|
1397 | + $trimmed = trim($file); |
|
1398 | + if ($trimmed === '') { |
|
1399 | + return false; |
|
1400 | + } |
|
1401 | + if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) { |
|
1402 | + return false; |
|
1403 | + } |
|
1404 | + |
|
1405 | + // detect part files |
|
1406 | + if (preg_match('/' . \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX . '/', $trimmed) !== 0) { |
|
1407 | + return false; |
|
1408 | + } |
|
1409 | + |
|
1410 | + foreach (str_split($trimmed) as $char) { |
|
1411 | + if (strpos(\OCP\Constants::FILENAME_INVALID_CHARS, $char) !== false) { |
|
1412 | + return false; |
|
1413 | + } |
|
1414 | + } |
|
1415 | + return true; |
|
1416 | + } |
|
1417 | + |
|
1418 | + /** |
|
1419 | + * Check whether the instance needs to perform an upgrade, |
|
1420 | + * either when the core version is higher or any app requires |
|
1421 | + * an upgrade. |
|
1422 | + * |
|
1423 | + * @param \OC\SystemConfig $config |
|
1424 | + * @return bool whether the core or any app needs an upgrade |
|
1425 | + * @throws \OC\HintException When the upgrade from the given version is not allowed |
|
1426 | + */ |
|
1427 | + public static function needUpgrade(\OC\SystemConfig $config) { |
|
1428 | + if ($config->getValue('installed', false)) { |
|
1429 | + $installedVersion = $config->getValue('version', '0.0.0'); |
|
1430 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
1431 | + $versionDiff = version_compare($currentVersion, $installedVersion); |
|
1432 | + if ($versionDiff > 0) { |
|
1433 | + return true; |
|
1434 | + } elseif ($config->getValue('debug', false) && $versionDiff < 0) { |
|
1435 | + // downgrade with debug |
|
1436 | + $installedMajor = explode('.', $installedVersion); |
|
1437 | + $installedMajor = $installedMajor[0] . '.' . $installedMajor[1]; |
|
1438 | + $currentMajor = explode('.', $currentVersion); |
|
1439 | + $currentMajor = $currentMajor[0] . '.' . $currentMajor[1]; |
|
1440 | + if ($installedMajor === $currentMajor) { |
|
1441 | + // Same major, allow downgrade for developers |
|
1442 | + return true; |
|
1443 | + } else { |
|
1444 | + // downgrade attempt, throw exception |
|
1445 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
1446 | + } |
|
1447 | + } elseif ($versionDiff < 0) { |
|
1448 | + // downgrade attempt, throw exception |
|
1449 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
1450 | + } |
|
1451 | + |
|
1452 | + // also check for upgrades for apps (independently from the user) |
|
1453 | + $apps = \OC_App::getEnabledApps(false, true); |
|
1454 | + $shouldUpgrade = false; |
|
1455 | + foreach ($apps as $app) { |
|
1456 | + if (\OC_App::shouldUpgrade($app)) { |
|
1457 | + $shouldUpgrade = true; |
|
1458 | + break; |
|
1459 | + } |
|
1460 | + } |
|
1461 | + return $shouldUpgrade; |
|
1462 | + } else { |
|
1463 | + return false; |
|
1464 | + } |
|
1465 | + } |
|
1466 | + |
|
1467 | + /** |
|
1468 | + * is this Internet explorer ? |
|
1469 | + * |
|
1470 | + * @return boolean |
|
1471 | + */ |
|
1472 | + public static function isIe() { |
|
1473 | + if (!isset($_SERVER['HTTP_USER_AGENT'])) { |
|
1474 | + return false; |
|
1475 | + } |
|
1476 | + |
|
1477 | + return preg_match(Request::USER_AGENT_IE, $_SERVER['HTTP_USER_AGENT']) === 1; |
|
1478 | + } |
|
1479 | 1479 | } |
@@ -79,1898 +79,1898 @@ |
||
79 | 79 | */ |
80 | 80 | class Manager implements IManager { |
81 | 81 | |
82 | - /** @var IProviderFactory */ |
|
83 | - private $factory; |
|
84 | - /** @var ILogger */ |
|
85 | - private $logger; |
|
86 | - /** @var IConfig */ |
|
87 | - private $config; |
|
88 | - /** @var ISecureRandom */ |
|
89 | - private $secureRandom; |
|
90 | - /** @var IHasher */ |
|
91 | - private $hasher; |
|
92 | - /** @var IMountManager */ |
|
93 | - private $mountManager; |
|
94 | - /** @var IGroupManager */ |
|
95 | - private $groupManager; |
|
96 | - /** @var IL10N */ |
|
97 | - private $l; |
|
98 | - /** @var IFactory */ |
|
99 | - private $l10nFactory; |
|
100 | - /** @var IUserManager */ |
|
101 | - private $userManager; |
|
102 | - /** @var IRootFolder */ |
|
103 | - private $rootFolder; |
|
104 | - /** @var CappedMemoryCache */ |
|
105 | - private $sharingDisabledForUsersCache; |
|
106 | - /** @var EventDispatcherInterface */ |
|
107 | - private $legacyDispatcher; |
|
108 | - /** @var IMailer */ |
|
109 | - private $mailer; |
|
110 | - /** @var IURLGenerator */ |
|
111 | - private $urlGenerator; |
|
112 | - /** @var \OC_Defaults */ |
|
113 | - private $defaults; |
|
114 | - /** @var IEventDispatcher */ |
|
115 | - private $dispatcher; |
|
116 | - private $userSession; |
|
117 | - |
|
118 | - public function __construct( |
|
119 | - ILogger $logger, |
|
120 | - IConfig $config, |
|
121 | - ISecureRandom $secureRandom, |
|
122 | - IHasher $hasher, |
|
123 | - IMountManager $mountManager, |
|
124 | - IGroupManager $groupManager, |
|
125 | - IL10N $l, |
|
126 | - IFactory $l10nFactory, |
|
127 | - IProviderFactory $factory, |
|
128 | - IUserManager $userManager, |
|
129 | - IRootFolder $rootFolder, |
|
130 | - EventDispatcherInterface $legacyDispatcher, |
|
131 | - IMailer $mailer, |
|
132 | - IURLGenerator $urlGenerator, |
|
133 | - \OC_Defaults $defaults, |
|
134 | - IEventDispatcher $dispatcher, |
|
135 | - IUserSession $userSession |
|
136 | - ) { |
|
137 | - $this->logger = $logger; |
|
138 | - $this->config = $config; |
|
139 | - $this->secureRandom = $secureRandom; |
|
140 | - $this->hasher = $hasher; |
|
141 | - $this->mountManager = $mountManager; |
|
142 | - $this->groupManager = $groupManager; |
|
143 | - $this->l = $l; |
|
144 | - $this->l10nFactory = $l10nFactory; |
|
145 | - $this->factory = $factory; |
|
146 | - $this->userManager = $userManager; |
|
147 | - $this->rootFolder = $rootFolder; |
|
148 | - $this->legacyDispatcher = $legacyDispatcher; |
|
149 | - $this->sharingDisabledForUsersCache = new CappedMemoryCache(); |
|
150 | - $this->mailer = $mailer; |
|
151 | - $this->urlGenerator = $urlGenerator; |
|
152 | - $this->defaults = $defaults; |
|
153 | - $this->dispatcher = $dispatcher; |
|
154 | - $this->userSession = $userSession; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Convert from a full share id to a tuple (providerId, shareId) |
|
159 | - * |
|
160 | - * @param string $id |
|
161 | - * @return string[] |
|
162 | - */ |
|
163 | - private function splitFullId($id) { |
|
164 | - return explode(':', $id, 2); |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Verify if a password meets all requirements |
|
169 | - * |
|
170 | - * @param string $password |
|
171 | - * @throws \Exception |
|
172 | - */ |
|
173 | - protected function verifyPassword($password) { |
|
174 | - if ($password === null) { |
|
175 | - // No password is set, check if this is allowed. |
|
176 | - if ($this->shareApiLinkEnforcePassword()) { |
|
177 | - throw new \InvalidArgumentException('Passwords are enforced for link and mail shares'); |
|
178 | - } |
|
179 | - |
|
180 | - return; |
|
181 | - } |
|
182 | - |
|
183 | - // Let others verify the password |
|
184 | - try { |
|
185 | - $this->legacyDispatcher->dispatch(new ValidatePasswordPolicyEvent($password)); |
|
186 | - } catch (HintException $e) { |
|
187 | - throw new \Exception($e->getHint()); |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Check for generic requirements before creating a share |
|
193 | - * |
|
194 | - * @param IShare $share |
|
195 | - * @throws \InvalidArgumentException |
|
196 | - * @throws GenericShareException |
|
197 | - * |
|
198 | - * @suppress PhanUndeclaredClassMethod |
|
199 | - */ |
|
200 | - protected function generalCreateChecks(IShare $share) { |
|
201 | - if ($share->getShareType() === IShare::TYPE_USER) { |
|
202 | - // We expect a valid user as sharedWith for user shares |
|
203 | - if (!$this->userManager->userExists($share->getSharedWith())) { |
|
204 | - throw new \InvalidArgumentException('SharedWith is not a valid user'); |
|
205 | - } |
|
206 | - } elseif ($share->getShareType() === IShare::TYPE_GROUP) { |
|
207 | - // We expect a valid group as sharedWith for group shares |
|
208 | - if (!$this->groupManager->groupExists($share->getSharedWith())) { |
|
209 | - throw new \InvalidArgumentException('SharedWith is not a valid group'); |
|
210 | - } |
|
211 | - } elseif ($share->getShareType() === IShare::TYPE_LINK) { |
|
212 | - // No check for TYPE_EMAIL here as we have a recipient for them |
|
213 | - if ($share->getSharedWith() !== null) { |
|
214 | - throw new \InvalidArgumentException('SharedWith should be empty'); |
|
215 | - } |
|
216 | - } elseif ($share->getShareType() === IShare::TYPE_EMAIL) { |
|
217 | - if ($share->getSharedWith() === null) { |
|
218 | - throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
219 | - } |
|
220 | - } elseif ($share->getShareType() === IShare::TYPE_REMOTE) { |
|
221 | - if ($share->getSharedWith() === null) { |
|
222 | - throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
223 | - } |
|
224 | - } elseif ($share->getShareType() === IShare::TYPE_REMOTE_GROUP) { |
|
225 | - if ($share->getSharedWith() === null) { |
|
226 | - throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
227 | - } |
|
228 | - } elseif ($share->getShareType() === IShare::TYPE_CIRCLE) { |
|
229 | - $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($share->getSharedWith()); |
|
230 | - if ($circle === null) { |
|
231 | - throw new \InvalidArgumentException('SharedWith is not a valid circle'); |
|
232 | - } |
|
233 | - } elseif ($share->getShareType() === IShare::TYPE_ROOM) { |
|
234 | - } elseif ($share->getShareType() === IShare::TYPE_DECK) { |
|
235 | - } else { |
|
236 | - // We cannot handle other types yet |
|
237 | - throw new \InvalidArgumentException('unknown share type'); |
|
238 | - } |
|
239 | - |
|
240 | - // Verify the initiator of the share is set |
|
241 | - if ($share->getSharedBy() === null) { |
|
242 | - throw new \InvalidArgumentException('SharedBy should be set'); |
|
243 | - } |
|
244 | - |
|
245 | - // Cannot share with yourself |
|
246 | - if ($share->getShareType() === IShare::TYPE_USER && |
|
247 | - $share->getSharedWith() === $share->getSharedBy()) { |
|
248 | - throw new \InvalidArgumentException('Cannot share with yourself'); |
|
249 | - } |
|
250 | - |
|
251 | - // The path should be set |
|
252 | - if ($share->getNode() === null) { |
|
253 | - throw new \InvalidArgumentException('Path should be set'); |
|
254 | - } |
|
255 | - |
|
256 | - // And it should be a file or a folder |
|
257 | - if (!($share->getNode() instanceof \OCP\Files\File) && |
|
258 | - !($share->getNode() instanceof \OCP\Files\Folder)) { |
|
259 | - throw new \InvalidArgumentException('Path should be either a file or a folder'); |
|
260 | - } |
|
261 | - |
|
262 | - // And you cannot share your rootfolder |
|
263 | - if ($this->userManager->userExists($share->getSharedBy())) { |
|
264 | - $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
265 | - } else { |
|
266 | - $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
267 | - } |
|
268 | - if ($userFolder->getId() === $share->getNode()->getId()) { |
|
269 | - throw new \InvalidArgumentException('You cannot share your root folder'); |
|
270 | - } |
|
271 | - |
|
272 | - // Check if we actually have share permissions |
|
273 | - if (!$share->getNode()->isShareable()) { |
|
274 | - $message_t = $this->l->t('You are not allowed to share %s', [$share->getNode()->getName()]); |
|
275 | - throw new GenericShareException($message_t, $message_t, 404); |
|
276 | - } |
|
277 | - |
|
278 | - // Permissions should be set |
|
279 | - if ($share->getPermissions() === null) { |
|
280 | - throw new \InvalidArgumentException('A share requires permissions'); |
|
281 | - } |
|
282 | - |
|
283 | - $isFederatedShare = $share->getNode()->getStorage()->instanceOfStorage('\OCA\Files_Sharing\External\Storage'); |
|
284 | - $permissions = 0; |
|
285 | - |
|
286 | - if (!$isFederatedShare && $share->getNode()->getOwner() && $share->getNode()->getOwner()->getUID() !== $share->getSharedBy()) { |
|
287 | - $userMounts = array_filter($userFolder->getById($share->getNode()->getId()), function ($mount) { |
|
288 | - // We need to filter since there might be other mountpoints that contain the file |
|
289 | - // e.g. if the user has access to the same external storage that the file is originating from |
|
290 | - return $mount->getStorage()->instanceOfStorage(ISharedStorage::class); |
|
291 | - }); |
|
292 | - $userMount = array_shift($userMounts); |
|
293 | - if ($userMount === null) { |
|
294 | - throw new GenericShareException('Could not get proper share mount for ' . $share->getNode()->getId() . '. Failing since else the next calls are called with null'); |
|
295 | - } |
|
296 | - $mount = $userMount->getMountPoint(); |
|
297 | - // When it's a reshare use the parent share permissions as maximum |
|
298 | - $userMountPointId = $mount->getStorageRootId(); |
|
299 | - $userMountPoints = $userFolder->getById($userMountPointId); |
|
300 | - $userMountPoint = array_shift($userMountPoints); |
|
301 | - |
|
302 | - if ($userMountPoint === null) { |
|
303 | - throw new GenericShareException('Could not get proper user mount for ' . $userMountPointId . '. Failing since else the next calls are called with null'); |
|
304 | - } |
|
305 | - |
|
306 | - /* Check if this is an incoming share */ |
|
307 | - $incomingShares = $this->getSharedWith($share->getSharedBy(), IShare::TYPE_USER, $userMountPoint, -1, 0); |
|
308 | - $incomingShares = array_merge($incomingShares, $this->getSharedWith($share->getSharedBy(), IShare::TYPE_GROUP, $userMountPoint, -1, 0)); |
|
309 | - $incomingShares = array_merge($incomingShares, $this->getSharedWith($share->getSharedBy(), IShare::TYPE_CIRCLE, $userMountPoint, -1, 0)); |
|
310 | - $incomingShares = array_merge($incomingShares, $this->getSharedWith($share->getSharedBy(), IShare::TYPE_ROOM, $userMountPoint, -1, 0)); |
|
311 | - |
|
312 | - /** @var IShare[] $incomingShares */ |
|
313 | - if (!empty($incomingShares)) { |
|
314 | - foreach ($incomingShares as $incomingShare) { |
|
315 | - $permissions |= $incomingShare->getPermissions(); |
|
316 | - } |
|
317 | - } |
|
318 | - } else { |
|
319 | - /* |
|
82 | + /** @var IProviderFactory */ |
|
83 | + private $factory; |
|
84 | + /** @var ILogger */ |
|
85 | + private $logger; |
|
86 | + /** @var IConfig */ |
|
87 | + private $config; |
|
88 | + /** @var ISecureRandom */ |
|
89 | + private $secureRandom; |
|
90 | + /** @var IHasher */ |
|
91 | + private $hasher; |
|
92 | + /** @var IMountManager */ |
|
93 | + private $mountManager; |
|
94 | + /** @var IGroupManager */ |
|
95 | + private $groupManager; |
|
96 | + /** @var IL10N */ |
|
97 | + private $l; |
|
98 | + /** @var IFactory */ |
|
99 | + private $l10nFactory; |
|
100 | + /** @var IUserManager */ |
|
101 | + private $userManager; |
|
102 | + /** @var IRootFolder */ |
|
103 | + private $rootFolder; |
|
104 | + /** @var CappedMemoryCache */ |
|
105 | + private $sharingDisabledForUsersCache; |
|
106 | + /** @var EventDispatcherInterface */ |
|
107 | + private $legacyDispatcher; |
|
108 | + /** @var IMailer */ |
|
109 | + private $mailer; |
|
110 | + /** @var IURLGenerator */ |
|
111 | + private $urlGenerator; |
|
112 | + /** @var \OC_Defaults */ |
|
113 | + private $defaults; |
|
114 | + /** @var IEventDispatcher */ |
|
115 | + private $dispatcher; |
|
116 | + private $userSession; |
|
117 | + |
|
118 | + public function __construct( |
|
119 | + ILogger $logger, |
|
120 | + IConfig $config, |
|
121 | + ISecureRandom $secureRandom, |
|
122 | + IHasher $hasher, |
|
123 | + IMountManager $mountManager, |
|
124 | + IGroupManager $groupManager, |
|
125 | + IL10N $l, |
|
126 | + IFactory $l10nFactory, |
|
127 | + IProviderFactory $factory, |
|
128 | + IUserManager $userManager, |
|
129 | + IRootFolder $rootFolder, |
|
130 | + EventDispatcherInterface $legacyDispatcher, |
|
131 | + IMailer $mailer, |
|
132 | + IURLGenerator $urlGenerator, |
|
133 | + \OC_Defaults $defaults, |
|
134 | + IEventDispatcher $dispatcher, |
|
135 | + IUserSession $userSession |
|
136 | + ) { |
|
137 | + $this->logger = $logger; |
|
138 | + $this->config = $config; |
|
139 | + $this->secureRandom = $secureRandom; |
|
140 | + $this->hasher = $hasher; |
|
141 | + $this->mountManager = $mountManager; |
|
142 | + $this->groupManager = $groupManager; |
|
143 | + $this->l = $l; |
|
144 | + $this->l10nFactory = $l10nFactory; |
|
145 | + $this->factory = $factory; |
|
146 | + $this->userManager = $userManager; |
|
147 | + $this->rootFolder = $rootFolder; |
|
148 | + $this->legacyDispatcher = $legacyDispatcher; |
|
149 | + $this->sharingDisabledForUsersCache = new CappedMemoryCache(); |
|
150 | + $this->mailer = $mailer; |
|
151 | + $this->urlGenerator = $urlGenerator; |
|
152 | + $this->defaults = $defaults; |
|
153 | + $this->dispatcher = $dispatcher; |
|
154 | + $this->userSession = $userSession; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Convert from a full share id to a tuple (providerId, shareId) |
|
159 | + * |
|
160 | + * @param string $id |
|
161 | + * @return string[] |
|
162 | + */ |
|
163 | + private function splitFullId($id) { |
|
164 | + return explode(':', $id, 2); |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Verify if a password meets all requirements |
|
169 | + * |
|
170 | + * @param string $password |
|
171 | + * @throws \Exception |
|
172 | + */ |
|
173 | + protected function verifyPassword($password) { |
|
174 | + if ($password === null) { |
|
175 | + // No password is set, check if this is allowed. |
|
176 | + if ($this->shareApiLinkEnforcePassword()) { |
|
177 | + throw new \InvalidArgumentException('Passwords are enforced for link and mail shares'); |
|
178 | + } |
|
179 | + |
|
180 | + return; |
|
181 | + } |
|
182 | + |
|
183 | + // Let others verify the password |
|
184 | + try { |
|
185 | + $this->legacyDispatcher->dispatch(new ValidatePasswordPolicyEvent($password)); |
|
186 | + } catch (HintException $e) { |
|
187 | + throw new \Exception($e->getHint()); |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Check for generic requirements before creating a share |
|
193 | + * |
|
194 | + * @param IShare $share |
|
195 | + * @throws \InvalidArgumentException |
|
196 | + * @throws GenericShareException |
|
197 | + * |
|
198 | + * @suppress PhanUndeclaredClassMethod |
|
199 | + */ |
|
200 | + protected function generalCreateChecks(IShare $share) { |
|
201 | + if ($share->getShareType() === IShare::TYPE_USER) { |
|
202 | + // We expect a valid user as sharedWith for user shares |
|
203 | + if (!$this->userManager->userExists($share->getSharedWith())) { |
|
204 | + throw new \InvalidArgumentException('SharedWith is not a valid user'); |
|
205 | + } |
|
206 | + } elseif ($share->getShareType() === IShare::TYPE_GROUP) { |
|
207 | + // We expect a valid group as sharedWith for group shares |
|
208 | + if (!$this->groupManager->groupExists($share->getSharedWith())) { |
|
209 | + throw new \InvalidArgumentException('SharedWith is not a valid group'); |
|
210 | + } |
|
211 | + } elseif ($share->getShareType() === IShare::TYPE_LINK) { |
|
212 | + // No check for TYPE_EMAIL here as we have a recipient for them |
|
213 | + if ($share->getSharedWith() !== null) { |
|
214 | + throw new \InvalidArgumentException('SharedWith should be empty'); |
|
215 | + } |
|
216 | + } elseif ($share->getShareType() === IShare::TYPE_EMAIL) { |
|
217 | + if ($share->getSharedWith() === null) { |
|
218 | + throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
219 | + } |
|
220 | + } elseif ($share->getShareType() === IShare::TYPE_REMOTE) { |
|
221 | + if ($share->getSharedWith() === null) { |
|
222 | + throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
223 | + } |
|
224 | + } elseif ($share->getShareType() === IShare::TYPE_REMOTE_GROUP) { |
|
225 | + if ($share->getSharedWith() === null) { |
|
226 | + throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
227 | + } |
|
228 | + } elseif ($share->getShareType() === IShare::TYPE_CIRCLE) { |
|
229 | + $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($share->getSharedWith()); |
|
230 | + if ($circle === null) { |
|
231 | + throw new \InvalidArgumentException('SharedWith is not a valid circle'); |
|
232 | + } |
|
233 | + } elseif ($share->getShareType() === IShare::TYPE_ROOM) { |
|
234 | + } elseif ($share->getShareType() === IShare::TYPE_DECK) { |
|
235 | + } else { |
|
236 | + // We cannot handle other types yet |
|
237 | + throw new \InvalidArgumentException('unknown share type'); |
|
238 | + } |
|
239 | + |
|
240 | + // Verify the initiator of the share is set |
|
241 | + if ($share->getSharedBy() === null) { |
|
242 | + throw new \InvalidArgumentException('SharedBy should be set'); |
|
243 | + } |
|
244 | + |
|
245 | + // Cannot share with yourself |
|
246 | + if ($share->getShareType() === IShare::TYPE_USER && |
|
247 | + $share->getSharedWith() === $share->getSharedBy()) { |
|
248 | + throw new \InvalidArgumentException('Cannot share with yourself'); |
|
249 | + } |
|
250 | + |
|
251 | + // The path should be set |
|
252 | + if ($share->getNode() === null) { |
|
253 | + throw new \InvalidArgumentException('Path should be set'); |
|
254 | + } |
|
255 | + |
|
256 | + // And it should be a file or a folder |
|
257 | + if (!($share->getNode() instanceof \OCP\Files\File) && |
|
258 | + !($share->getNode() instanceof \OCP\Files\Folder)) { |
|
259 | + throw new \InvalidArgumentException('Path should be either a file or a folder'); |
|
260 | + } |
|
261 | + |
|
262 | + // And you cannot share your rootfolder |
|
263 | + if ($this->userManager->userExists($share->getSharedBy())) { |
|
264 | + $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
265 | + } else { |
|
266 | + $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
267 | + } |
|
268 | + if ($userFolder->getId() === $share->getNode()->getId()) { |
|
269 | + throw new \InvalidArgumentException('You cannot share your root folder'); |
|
270 | + } |
|
271 | + |
|
272 | + // Check if we actually have share permissions |
|
273 | + if (!$share->getNode()->isShareable()) { |
|
274 | + $message_t = $this->l->t('You are not allowed to share %s', [$share->getNode()->getName()]); |
|
275 | + throw new GenericShareException($message_t, $message_t, 404); |
|
276 | + } |
|
277 | + |
|
278 | + // Permissions should be set |
|
279 | + if ($share->getPermissions() === null) { |
|
280 | + throw new \InvalidArgumentException('A share requires permissions'); |
|
281 | + } |
|
282 | + |
|
283 | + $isFederatedShare = $share->getNode()->getStorage()->instanceOfStorage('\OCA\Files_Sharing\External\Storage'); |
|
284 | + $permissions = 0; |
|
285 | + |
|
286 | + if (!$isFederatedShare && $share->getNode()->getOwner() && $share->getNode()->getOwner()->getUID() !== $share->getSharedBy()) { |
|
287 | + $userMounts = array_filter($userFolder->getById($share->getNode()->getId()), function ($mount) { |
|
288 | + // We need to filter since there might be other mountpoints that contain the file |
|
289 | + // e.g. if the user has access to the same external storage that the file is originating from |
|
290 | + return $mount->getStorage()->instanceOfStorage(ISharedStorage::class); |
|
291 | + }); |
|
292 | + $userMount = array_shift($userMounts); |
|
293 | + if ($userMount === null) { |
|
294 | + throw new GenericShareException('Could not get proper share mount for ' . $share->getNode()->getId() . '. Failing since else the next calls are called with null'); |
|
295 | + } |
|
296 | + $mount = $userMount->getMountPoint(); |
|
297 | + // When it's a reshare use the parent share permissions as maximum |
|
298 | + $userMountPointId = $mount->getStorageRootId(); |
|
299 | + $userMountPoints = $userFolder->getById($userMountPointId); |
|
300 | + $userMountPoint = array_shift($userMountPoints); |
|
301 | + |
|
302 | + if ($userMountPoint === null) { |
|
303 | + throw new GenericShareException('Could not get proper user mount for ' . $userMountPointId . '. Failing since else the next calls are called with null'); |
|
304 | + } |
|
305 | + |
|
306 | + /* Check if this is an incoming share */ |
|
307 | + $incomingShares = $this->getSharedWith($share->getSharedBy(), IShare::TYPE_USER, $userMountPoint, -1, 0); |
|
308 | + $incomingShares = array_merge($incomingShares, $this->getSharedWith($share->getSharedBy(), IShare::TYPE_GROUP, $userMountPoint, -1, 0)); |
|
309 | + $incomingShares = array_merge($incomingShares, $this->getSharedWith($share->getSharedBy(), IShare::TYPE_CIRCLE, $userMountPoint, -1, 0)); |
|
310 | + $incomingShares = array_merge($incomingShares, $this->getSharedWith($share->getSharedBy(), IShare::TYPE_ROOM, $userMountPoint, -1, 0)); |
|
311 | + |
|
312 | + /** @var IShare[] $incomingShares */ |
|
313 | + if (!empty($incomingShares)) { |
|
314 | + foreach ($incomingShares as $incomingShare) { |
|
315 | + $permissions |= $incomingShare->getPermissions(); |
|
316 | + } |
|
317 | + } |
|
318 | + } else { |
|
319 | + /* |
|
320 | 320 | * Quick fix for #23536 |
321 | 321 | * Non moveable mount points do not have update and delete permissions |
322 | 322 | * while we 'most likely' do have that on the storage. |
323 | 323 | */ |
324 | - $permissions = $share->getNode()->getPermissions(); |
|
325 | - if (!($share->getNode()->getMountPoint() instanceof MoveableMount)) { |
|
326 | - $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
327 | - } |
|
328 | - } |
|
329 | - |
|
330 | - // Check that we do not share with more permissions than we have |
|
331 | - if ($share->getPermissions() & ~$permissions) { |
|
332 | - $path = $userFolder->getRelativePath($share->getNode()->getPath()); |
|
333 | - $message_t = $this->l->t('Cannot increase permissions of %s', [$path]); |
|
334 | - throw new GenericShareException($message_t, $message_t, 404); |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - // Check that read permissions are always set |
|
339 | - // Link shares are allowed to have no read permissions to allow upload to hidden folders |
|
340 | - $noReadPermissionRequired = $share->getShareType() === IShare::TYPE_LINK |
|
341 | - || $share->getShareType() === IShare::TYPE_EMAIL; |
|
342 | - if (!$noReadPermissionRequired && |
|
343 | - ($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) { |
|
344 | - throw new \InvalidArgumentException('Shares need at least read permissions'); |
|
345 | - } |
|
346 | - |
|
347 | - if ($share->getNode() instanceof \OCP\Files\File) { |
|
348 | - if ($share->getPermissions() & \OCP\Constants::PERMISSION_DELETE) { |
|
349 | - $message_t = $this->l->t('Files cannot be shared with delete permissions'); |
|
350 | - throw new GenericShareException($message_t); |
|
351 | - } |
|
352 | - if ($share->getPermissions() & \OCP\Constants::PERMISSION_CREATE) { |
|
353 | - $message_t = $this->l->t('Files cannot be shared with create permissions'); |
|
354 | - throw new GenericShareException($message_t); |
|
355 | - } |
|
356 | - } |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Validate if the expiration date fits the system settings |
|
361 | - * |
|
362 | - * @param IShare $share The share to validate the expiration date of |
|
363 | - * @return IShare The modified share object |
|
364 | - * @throws GenericShareException |
|
365 | - * @throws \InvalidArgumentException |
|
366 | - * @throws \Exception |
|
367 | - */ |
|
368 | - protected function validateExpirationDateInternal(IShare $share) { |
|
369 | - $isRemote = $share->getShareType() === IShare::TYPE_REMOTE || $share->getShareType() === IShare::TYPE_REMOTE_GROUP; |
|
370 | - |
|
371 | - $expirationDate = $share->getExpirationDate(); |
|
372 | - |
|
373 | - if ($expirationDate !== null) { |
|
374 | - //Make sure the expiration date is a date |
|
375 | - $expirationDate->setTime(0, 0, 0); |
|
376 | - |
|
377 | - $date = new \DateTime(); |
|
378 | - $date->setTime(0, 0, 0); |
|
379 | - if ($date >= $expirationDate) { |
|
380 | - $message = $this->l->t('Expiration date is in the past'); |
|
381 | - throw new GenericShareException($message, $message, 404); |
|
382 | - } |
|
383 | - } |
|
384 | - |
|
385 | - // If expiredate is empty set a default one if there is a default |
|
386 | - $fullId = null; |
|
387 | - try { |
|
388 | - $fullId = $share->getFullId(); |
|
389 | - } catch (\UnexpectedValueException $e) { |
|
390 | - // This is a new share |
|
391 | - } |
|
392 | - |
|
393 | - if ($isRemote) { |
|
394 | - $defaultExpireDate = $this->shareApiRemoteDefaultExpireDate(); |
|
395 | - $defaultExpireDays = $this->shareApiRemoteDefaultExpireDays(); |
|
396 | - $configProp = 'remote_defaultExpDays'; |
|
397 | - $isEnforced = $this->shareApiRemoteDefaultExpireDateEnforced(); |
|
398 | - } else { |
|
399 | - $defaultExpireDate = $this->shareApiInternalDefaultExpireDate(); |
|
400 | - $defaultExpireDays = $this->shareApiInternalDefaultExpireDays(); |
|
401 | - $configProp = 'internal_defaultExpDays'; |
|
402 | - $isEnforced = $this->shareApiInternalDefaultExpireDateEnforced(); |
|
403 | - } |
|
404 | - if ($fullId === null && $expirationDate === null && $defaultExpireDate) { |
|
405 | - $expirationDate = new \DateTime(); |
|
406 | - $expirationDate->setTime(0, 0, 0); |
|
407 | - |
|
408 | - $days = (int)$this->config->getAppValue('core', $configProp, (string)$defaultExpireDays); |
|
409 | - if ($days > $defaultExpireDays) { |
|
410 | - $days = $defaultExpireDays; |
|
411 | - } |
|
412 | - $expirationDate->add(new \DateInterval('P' . $days . 'D')); |
|
413 | - } |
|
414 | - |
|
415 | - // If we enforce the expiration date check that is does not exceed |
|
416 | - if ($isEnforced) { |
|
417 | - if ($expirationDate === null) { |
|
418 | - throw new \InvalidArgumentException('Expiration date is enforced'); |
|
419 | - } |
|
420 | - |
|
421 | - $date = new \DateTime(); |
|
422 | - $date->setTime(0, 0, 0); |
|
423 | - $date->add(new \DateInterval('P' . $defaultExpireDays . 'D')); |
|
424 | - if ($date < $expirationDate) { |
|
425 | - $message = $this->l->n('Cannot set expiration date more than %n day in the future', 'Cannot set expiration date more than %n days in the future', $defaultExpireDays); |
|
426 | - throw new GenericShareException($message, $message, 404); |
|
427 | - } |
|
428 | - } |
|
429 | - |
|
430 | - $accepted = true; |
|
431 | - $message = ''; |
|
432 | - \OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [ |
|
433 | - 'expirationDate' => &$expirationDate, |
|
434 | - 'accepted' => &$accepted, |
|
435 | - 'message' => &$message, |
|
436 | - 'passwordSet' => $share->getPassword() !== null, |
|
437 | - ]); |
|
438 | - |
|
439 | - if (!$accepted) { |
|
440 | - throw new \Exception($message); |
|
441 | - } |
|
442 | - |
|
443 | - $share->setExpirationDate($expirationDate); |
|
444 | - |
|
445 | - return $share; |
|
446 | - } |
|
447 | - |
|
448 | - /** |
|
449 | - * Validate if the expiration date fits the system settings |
|
450 | - * |
|
451 | - * @param IShare $share The share to validate the expiration date of |
|
452 | - * @return IShare The modified share object |
|
453 | - * @throws GenericShareException |
|
454 | - * @throws \InvalidArgumentException |
|
455 | - * @throws \Exception |
|
456 | - */ |
|
457 | - protected function validateExpirationDateLink(IShare $share) { |
|
458 | - $expirationDate = $share->getExpirationDate(); |
|
459 | - |
|
460 | - if ($expirationDate !== null) { |
|
461 | - //Make sure the expiration date is a date |
|
462 | - $expirationDate->setTime(0, 0, 0); |
|
463 | - |
|
464 | - $date = new \DateTime(); |
|
465 | - $date->setTime(0, 0, 0); |
|
466 | - if ($date >= $expirationDate) { |
|
467 | - $message = $this->l->t('Expiration date is in the past'); |
|
468 | - throw new GenericShareException($message, $message, 404); |
|
469 | - } |
|
470 | - } |
|
471 | - |
|
472 | - // If expiredate is empty set a default one if there is a default |
|
473 | - $fullId = null; |
|
474 | - try { |
|
475 | - $fullId = $share->getFullId(); |
|
476 | - } catch (\UnexpectedValueException $e) { |
|
477 | - // This is a new share |
|
478 | - } |
|
479 | - |
|
480 | - if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) { |
|
481 | - $expirationDate = new \DateTime(); |
|
482 | - $expirationDate->setTime(0, 0, 0); |
|
483 | - |
|
484 | - $days = (int)$this->config->getAppValue('core', 'link_defaultExpDays', $this->shareApiLinkDefaultExpireDays()); |
|
485 | - if ($days > $this->shareApiLinkDefaultExpireDays()) { |
|
486 | - $days = $this->shareApiLinkDefaultExpireDays(); |
|
487 | - } |
|
488 | - $expirationDate->add(new \DateInterval('P' . $days . 'D')); |
|
489 | - } |
|
490 | - |
|
491 | - // If we enforce the expiration date check that is does not exceed |
|
492 | - if ($this->shareApiLinkDefaultExpireDateEnforced()) { |
|
493 | - if ($expirationDate === null) { |
|
494 | - throw new \InvalidArgumentException('Expiration date is enforced'); |
|
495 | - } |
|
496 | - |
|
497 | - $date = new \DateTime(); |
|
498 | - $date->setTime(0, 0, 0); |
|
499 | - $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D')); |
|
500 | - if ($date < $expirationDate) { |
|
501 | - $message = $this->l->n('Cannot set expiration date more than %n day in the future', 'Cannot set expiration date more than %n days in the future', $this->shareApiLinkDefaultExpireDays()); |
|
502 | - throw new GenericShareException($message, $message, 404); |
|
503 | - } |
|
504 | - } |
|
505 | - |
|
506 | - $accepted = true; |
|
507 | - $message = ''; |
|
508 | - \OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [ |
|
509 | - 'expirationDate' => &$expirationDate, |
|
510 | - 'accepted' => &$accepted, |
|
511 | - 'message' => &$message, |
|
512 | - 'passwordSet' => $share->getPassword() !== null, |
|
513 | - ]); |
|
514 | - |
|
515 | - if (!$accepted) { |
|
516 | - throw new \Exception($message); |
|
517 | - } |
|
518 | - |
|
519 | - $share->setExpirationDate($expirationDate); |
|
520 | - |
|
521 | - return $share; |
|
522 | - } |
|
523 | - |
|
524 | - /** |
|
525 | - * Check for pre share requirements for user shares |
|
526 | - * |
|
527 | - * @param IShare $share |
|
528 | - * @throws \Exception |
|
529 | - */ |
|
530 | - protected function userCreateChecks(IShare $share) { |
|
531 | - // Check if we can share with group members only |
|
532 | - if ($this->shareWithGroupMembersOnly()) { |
|
533 | - $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
534 | - $sharedWith = $this->userManager->get($share->getSharedWith()); |
|
535 | - // Verify we can share with this user |
|
536 | - $groups = array_intersect( |
|
537 | - $this->groupManager->getUserGroupIds($sharedBy), |
|
538 | - $this->groupManager->getUserGroupIds($sharedWith) |
|
539 | - ); |
|
540 | - if (empty($groups)) { |
|
541 | - $message_t = $this->l->t('Sharing is only allowed with group members'); |
|
542 | - throw new \Exception($message_t); |
|
543 | - } |
|
544 | - } |
|
545 | - |
|
546 | - /* |
|
324 | + $permissions = $share->getNode()->getPermissions(); |
|
325 | + if (!($share->getNode()->getMountPoint() instanceof MoveableMount)) { |
|
326 | + $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
327 | + } |
|
328 | + } |
|
329 | + |
|
330 | + // Check that we do not share with more permissions than we have |
|
331 | + if ($share->getPermissions() & ~$permissions) { |
|
332 | + $path = $userFolder->getRelativePath($share->getNode()->getPath()); |
|
333 | + $message_t = $this->l->t('Cannot increase permissions of %s', [$path]); |
|
334 | + throw new GenericShareException($message_t, $message_t, 404); |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + // Check that read permissions are always set |
|
339 | + // Link shares are allowed to have no read permissions to allow upload to hidden folders |
|
340 | + $noReadPermissionRequired = $share->getShareType() === IShare::TYPE_LINK |
|
341 | + || $share->getShareType() === IShare::TYPE_EMAIL; |
|
342 | + if (!$noReadPermissionRequired && |
|
343 | + ($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) { |
|
344 | + throw new \InvalidArgumentException('Shares need at least read permissions'); |
|
345 | + } |
|
346 | + |
|
347 | + if ($share->getNode() instanceof \OCP\Files\File) { |
|
348 | + if ($share->getPermissions() & \OCP\Constants::PERMISSION_DELETE) { |
|
349 | + $message_t = $this->l->t('Files cannot be shared with delete permissions'); |
|
350 | + throw new GenericShareException($message_t); |
|
351 | + } |
|
352 | + if ($share->getPermissions() & \OCP\Constants::PERMISSION_CREATE) { |
|
353 | + $message_t = $this->l->t('Files cannot be shared with create permissions'); |
|
354 | + throw new GenericShareException($message_t); |
|
355 | + } |
|
356 | + } |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Validate if the expiration date fits the system settings |
|
361 | + * |
|
362 | + * @param IShare $share The share to validate the expiration date of |
|
363 | + * @return IShare The modified share object |
|
364 | + * @throws GenericShareException |
|
365 | + * @throws \InvalidArgumentException |
|
366 | + * @throws \Exception |
|
367 | + */ |
|
368 | + protected function validateExpirationDateInternal(IShare $share) { |
|
369 | + $isRemote = $share->getShareType() === IShare::TYPE_REMOTE || $share->getShareType() === IShare::TYPE_REMOTE_GROUP; |
|
370 | + |
|
371 | + $expirationDate = $share->getExpirationDate(); |
|
372 | + |
|
373 | + if ($expirationDate !== null) { |
|
374 | + //Make sure the expiration date is a date |
|
375 | + $expirationDate->setTime(0, 0, 0); |
|
376 | + |
|
377 | + $date = new \DateTime(); |
|
378 | + $date->setTime(0, 0, 0); |
|
379 | + if ($date >= $expirationDate) { |
|
380 | + $message = $this->l->t('Expiration date is in the past'); |
|
381 | + throw new GenericShareException($message, $message, 404); |
|
382 | + } |
|
383 | + } |
|
384 | + |
|
385 | + // If expiredate is empty set a default one if there is a default |
|
386 | + $fullId = null; |
|
387 | + try { |
|
388 | + $fullId = $share->getFullId(); |
|
389 | + } catch (\UnexpectedValueException $e) { |
|
390 | + // This is a new share |
|
391 | + } |
|
392 | + |
|
393 | + if ($isRemote) { |
|
394 | + $defaultExpireDate = $this->shareApiRemoteDefaultExpireDate(); |
|
395 | + $defaultExpireDays = $this->shareApiRemoteDefaultExpireDays(); |
|
396 | + $configProp = 'remote_defaultExpDays'; |
|
397 | + $isEnforced = $this->shareApiRemoteDefaultExpireDateEnforced(); |
|
398 | + } else { |
|
399 | + $defaultExpireDate = $this->shareApiInternalDefaultExpireDate(); |
|
400 | + $defaultExpireDays = $this->shareApiInternalDefaultExpireDays(); |
|
401 | + $configProp = 'internal_defaultExpDays'; |
|
402 | + $isEnforced = $this->shareApiInternalDefaultExpireDateEnforced(); |
|
403 | + } |
|
404 | + if ($fullId === null && $expirationDate === null && $defaultExpireDate) { |
|
405 | + $expirationDate = new \DateTime(); |
|
406 | + $expirationDate->setTime(0, 0, 0); |
|
407 | + |
|
408 | + $days = (int)$this->config->getAppValue('core', $configProp, (string)$defaultExpireDays); |
|
409 | + if ($days > $defaultExpireDays) { |
|
410 | + $days = $defaultExpireDays; |
|
411 | + } |
|
412 | + $expirationDate->add(new \DateInterval('P' . $days . 'D')); |
|
413 | + } |
|
414 | + |
|
415 | + // If we enforce the expiration date check that is does not exceed |
|
416 | + if ($isEnforced) { |
|
417 | + if ($expirationDate === null) { |
|
418 | + throw new \InvalidArgumentException('Expiration date is enforced'); |
|
419 | + } |
|
420 | + |
|
421 | + $date = new \DateTime(); |
|
422 | + $date->setTime(0, 0, 0); |
|
423 | + $date->add(new \DateInterval('P' . $defaultExpireDays . 'D')); |
|
424 | + if ($date < $expirationDate) { |
|
425 | + $message = $this->l->n('Cannot set expiration date more than %n day in the future', 'Cannot set expiration date more than %n days in the future', $defaultExpireDays); |
|
426 | + throw new GenericShareException($message, $message, 404); |
|
427 | + } |
|
428 | + } |
|
429 | + |
|
430 | + $accepted = true; |
|
431 | + $message = ''; |
|
432 | + \OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [ |
|
433 | + 'expirationDate' => &$expirationDate, |
|
434 | + 'accepted' => &$accepted, |
|
435 | + 'message' => &$message, |
|
436 | + 'passwordSet' => $share->getPassword() !== null, |
|
437 | + ]); |
|
438 | + |
|
439 | + if (!$accepted) { |
|
440 | + throw new \Exception($message); |
|
441 | + } |
|
442 | + |
|
443 | + $share->setExpirationDate($expirationDate); |
|
444 | + |
|
445 | + return $share; |
|
446 | + } |
|
447 | + |
|
448 | + /** |
|
449 | + * Validate if the expiration date fits the system settings |
|
450 | + * |
|
451 | + * @param IShare $share The share to validate the expiration date of |
|
452 | + * @return IShare The modified share object |
|
453 | + * @throws GenericShareException |
|
454 | + * @throws \InvalidArgumentException |
|
455 | + * @throws \Exception |
|
456 | + */ |
|
457 | + protected function validateExpirationDateLink(IShare $share) { |
|
458 | + $expirationDate = $share->getExpirationDate(); |
|
459 | + |
|
460 | + if ($expirationDate !== null) { |
|
461 | + //Make sure the expiration date is a date |
|
462 | + $expirationDate->setTime(0, 0, 0); |
|
463 | + |
|
464 | + $date = new \DateTime(); |
|
465 | + $date->setTime(0, 0, 0); |
|
466 | + if ($date >= $expirationDate) { |
|
467 | + $message = $this->l->t('Expiration date is in the past'); |
|
468 | + throw new GenericShareException($message, $message, 404); |
|
469 | + } |
|
470 | + } |
|
471 | + |
|
472 | + // If expiredate is empty set a default one if there is a default |
|
473 | + $fullId = null; |
|
474 | + try { |
|
475 | + $fullId = $share->getFullId(); |
|
476 | + } catch (\UnexpectedValueException $e) { |
|
477 | + // This is a new share |
|
478 | + } |
|
479 | + |
|
480 | + if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) { |
|
481 | + $expirationDate = new \DateTime(); |
|
482 | + $expirationDate->setTime(0, 0, 0); |
|
483 | + |
|
484 | + $days = (int)$this->config->getAppValue('core', 'link_defaultExpDays', $this->shareApiLinkDefaultExpireDays()); |
|
485 | + if ($days > $this->shareApiLinkDefaultExpireDays()) { |
|
486 | + $days = $this->shareApiLinkDefaultExpireDays(); |
|
487 | + } |
|
488 | + $expirationDate->add(new \DateInterval('P' . $days . 'D')); |
|
489 | + } |
|
490 | + |
|
491 | + // If we enforce the expiration date check that is does not exceed |
|
492 | + if ($this->shareApiLinkDefaultExpireDateEnforced()) { |
|
493 | + if ($expirationDate === null) { |
|
494 | + throw new \InvalidArgumentException('Expiration date is enforced'); |
|
495 | + } |
|
496 | + |
|
497 | + $date = new \DateTime(); |
|
498 | + $date->setTime(0, 0, 0); |
|
499 | + $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D')); |
|
500 | + if ($date < $expirationDate) { |
|
501 | + $message = $this->l->n('Cannot set expiration date more than %n day in the future', 'Cannot set expiration date more than %n days in the future', $this->shareApiLinkDefaultExpireDays()); |
|
502 | + throw new GenericShareException($message, $message, 404); |
|
503 | + } |
|
504 | + } |
|
505 | + |
|
506 | + $accepted = true; |
|
507 | + $message = ''; |
|
508 | + \OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [ |
|
509 | + 'expirationDate' => &$expirationDate, |
|
510 | + 'accepted' => &$accepted, |
|
511 | + 'message' => &$message, |
|
512 | + 'passwordSet' => $share->getPassword() !== null, |
|
513 | + ]); |
|
514 | + |
|
515 | + if (!$accepted) { |
|
516 | + throw new \Exception($message); |
|
517 | + } |
|
518 | + |
|
519 | + $share->setExpirationDate($expirationDate); |
|
520 | + |
|
521 | + return $share; |
|
522 | + } |
|
523 | + |
|
524 | + /** |
|
525 | + * Check for pre share requirements for user shares |
|
526 | + * |
|
527 | + * @param IShare $share |
|
528 | + * @throws \Exception |
|
529 | + */ |
|
530 | + protected function userCreateChecks(IShare $share) { |
|
531 | + // Check if we can share with group members only |
|
532 | + if ($this->shareWithGroupMembersOnly()) { |
|
533 | + $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
534 | + $sharedWith = $this->userManager->get($share->getSharedWith()); |
|
535 | + // Verify we can share with this user |
|
536 | + $groups = array_intersect( |
|
537 | + $this->groupManager->getUserGroupIds($sharedBy), |
|
538 | + $this->groupManager->getUserGroupIds($sharedWith) |
|
539 | + ); |
|
540 | + if (empty($groups)) { |
|
541 | + $message_t = $this->l->t('Sharing is only allowed with group members'); |
|
542 | + throw new \Exception($message_t); |
|
543 | + } |
|
544 | + } |
|
545 | + |
|
546 | + /* |
|
547 | 547 | * TODO: Could be costly, fix |
548 | 548 | * |
549 | 549 | * Also this is not what we want in the future.. then we want to squash identical shares. |
550 | 550 | */ |
551 | - $provider = $this->factory->getProviderForType(IShare::TYPE_USER); |
|
552 | - $existingShares = $provider->getSharesByPath($share->getNode()); |
|
553 | - foreach ($existingShares as $existingShare) { |
|
554 | - // Ignore if it is the same share |
|
555 | - try { |
|
556 | - if ($existingShare->getFullId() === $share->getFullId()) { |
|
557 | - continue; |
|
558 | - } |
|
559 | - } catch (\UnexpectedValueException $e) { |
|
560 | - //Shares are not identical |
|
561 | - } |
|
562 | - |
|
563 | - // Identical share already exists |
|
564 | - if ($existingShare->getSharedWith() === $share->getSharedWith() && $existingShare->getShareType() === $share->getShareType()) { |
|
565 | - $message = $this->l->t('Sharing %s failed, because this item is already shared with user %s', [$share->getNode()->getName(), $share->getSharedWithDisplayName()]); |
|
566 | - throw new AlreadySharedException($message, $existingShare); |
|
567 | - } |
|
568 | - |
|
569 | - // The share is already shared with this user via a group share |
|
570 | - if ($existingShare->getShareType() === IShare::TYPE_GROUP) { |
|
571 | - $group = $this->groupManager->get($existingShare->getSharedWith()); |
|
572 | - if (!is_null($group)) { |
|
573 | - $user = $this->userManager->get($share->getSharedWith()); |
|
574 | - |
|
575 | - if ($group->inGroup($user) && $existingShare->getShareOwner() !== $share->getShareOwner()) { |
|
576 | - $message = $this->l->t('Sharing %s failed, because this item is already shared with user %s', [$share->getNode()->getName(), $share->getSharedWithDisplayName()]); |
|
577 | - throw new AlreadySharedException($message, $existingShare); |
|
578 | - } |
|
579 | - } |
|
580 | - } |
|
581 | - } |
|
582 | - } |
|
583 | - |
|
584 | - /** |
|
585 | - * Check for pre share requirements for group shares |
|
586 | - * |
|
587 | - * @param IShare $share |
|
588 | - * @throws \Exception |
|
589 | - */ |
|
590 | - protected function groupCreateChecks(IShare $share) { |
|
591 | - // Verify group shares are allowed |
|
592 | - if (!$this->allowGroupSharing()) { |
|
593 | - throw new \Exception('Group sharing is now allowed'); |
|
594 | - } |
|
595 | - |
|
596 | - // Verify if the user can share with this group |
|
597 | - if ($this->shareWithGroupMembersOnly()) { |
|
598 | - $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
599 | - $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
600 | - if (is_null($sharedWith) || !$sharedWith->inGroup($sharedBy)) { |
|
601 | - throw new \Exception('Sharing is only allowed within your own groups'); |
|
602 | - } |
|
603 | - } |
|
604 | - |
|
605 | - /* |
|
551 | + $provider = $this->factory->getProviderForType(IShare::TYPE_USER); |
|
552 | + $existingShares = $provider->getSharesByPath($share->getNode()); |
|
553 | + foreach ($existingShares as $existingShare) { |
|
554 | + // Ignore if it is the same share |
|
555 | + try { |
|
556 | + if ($existingShare->getFullId() === $share->getFullId()) { |
|
557 | + continue; |
|
558 | + } |
|
559 | + } catch (\UnexpectedValueException $e) { |
|
560 | + //Shares are not identical |
|
561 | + } |
|
562 | + |
|
563 | + // Identical share already exists |
|
564 | + if ($existingShare->getSharedWith() === $share->getSharedWith() && $existingShare->getShareType() === $share->getShareType()) { |
|
565 | + $message = $this->l->t('Sharing %s failed, because this item is already shared with user %s', [$share->getNode()->getName(), $share->getSharedWithDisplayName()]); |
|
566 | + throw new AlreadySharedException($message, $existingShare); |
|
567 | + } |
|
568 | + |
|
569 | + // The share is already shared with this user via a group share |
|
570 | + if ($existingShare->getShareType() === IShare::TYPE_GROUP) { |
|
571 | + $group = $this->groupManager->get($existingShare->getSharedWith()); |
|
572 | + if (!is_null($group)) { |
|
573 | + $user = $this->userManager->get($share->getSharedWith()); |
|
574 | + |
|
575 | + if ($group->inGroup($user) && $existingShare->getShareOwner() !== $share->getShareOwner()) { |
|
576 | + $message = $this->l->t('Sharing %s failed, because this item is already shared with user %s', [$share->getNode()->getName(), $share->getSharedWithDisplayName()]); |
|
577 | + throw new AlreadySharedException($message, $existingShare); |
|
578 | + } |
|
579 | + } |
|
580 | + } |
|
581 | + } |
|
582 | + } |
|
583 | + |
|
584 | + /** |
|
585 | + * Check for pre share requirements for group shares |
|
586 | + * |
|
587 | + * @param IShare $share |
|
588 | + * @throws \Exception |
|
589 | + */ |
|
590 | + protected function groupCreateChecks(IShare $share) { |
|
591 | + // Verify group shares are allowed |
|
592 | + if (!$this->allowGroupSharing()) { |
|
593 | + throw new \Exception('Group sharing is now allowed'); |
|
594 | + } |
|
595 | + |
|
596 | + // Verify if the user can share with this group |
|
597 | + if ($this->shareWithGroupMembersOnly()) { |
|
598 | + $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
599 | + $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
600 | + if (is_null($sharedWith) || !$sharedWith->inGroup($sharedBy)) { |
|
601 | + throw new \Exception('Sharing is only allowed within your own groups'); |
|
602 | + } |
|
603 | + } |
|
604 | + |
|
605 | + /* |
|
606 | 606 | * TODO: Could be costly, fix |
607 | 607 | * |
608 | 608 | * Also this is not what we want in the future.. then we want to squash identical shares. |
609 | 609 | */ |
610 | - $provider = $this->factory->getProviderForType(IShare::TYPE_GROUP); |
|
611 | - $existingShares = $provider->getSharesByPath($share->getNode()); |
|
612 | - foreach ($existingShares as $existingShare) { |
|
613 | - try { |
|
614 | - if ($existingShare->getFullId() === $share->getFullId()) { |
|
615 | - continue; |
|
616 | - } |
|
617 | - } catch (\UnexpectedValueException $e) { |
|
618 | - //It is a new share so just continue |
|
619 | - } |
|
620 | - |
|
621 | - if ($existingShare->getSharedWith() === $share->getSharedWith() && $existingShare->getShareType() === $share->getShareType()) { |
|
622 | - throw new AlreadySharedException('Path is already shared with this group', $existingShare); |
|
623 | - } |
|
624 | - } |
|
625 | - } |
|
626 | - |
|
627 | - /** |
|
628 | - * Check for pre share requirements for link shares |
|
629 | - * |
|
630 | - * @param IShare $share |
|
631 | - * @throws \Exception |
|
632 | - */ |
|
633 | - protected function linkCreateChecks(IShare $share) { |
|
634 | - // Are link shares allowed? |
|
635 | - if (!$this->shareApiAllowLinks()) { |
|
636 | - throw new \Exception('Link sharing is not allowed'); |
|
637 | - } |
|
638 | - |
|
639 | - // Check if public upload is allowed |
|
640 | - if (!$this->shareApiLinkAllowPublicUpload() && |
|
641 | - ($share->getPermissions() & (\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE))) { |
|
642 | - throw new \InvalidArgumentException('Public upload is not allowed'); |
|
643 | - } |
|
644 | - } |
|
645 | - |
|
646 | - /** |
|
647 | - * To make sure we don't get invisible link shares we set the parent |
|
648 | - * of a link if it is a reshare. This is a quick word around |
|
649 | - * until we can properly display multiple link shares in the UI |
|
650 | - * |
|
651 | - * See: https://github.com/owncloud/core/issues/22295 |
|
652 | - * |
|
653 | - * FIXME: Remove once multiple link shares can be properly displayed |
|
654 | - * |
|
655 | - * @param IShare $share |
|
656 | - */ |
|
657 | - protected function setLinkParent(IShare $share) { |
|
658 | - |
|
659 | - // No sense in checking if the method is not there. |
|
660 | - if (method_exists($share, 'setParent')) { |
|
661 | - $storage = $share->getNode()->getStorage(); |
|
662 | - if ($storage->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
663 | - /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
664 | - $share->setParent($storage->getShareId()); |
|
665 | - } |
|
666 | - } |
|
667 | - } |
|
668 | - |
|
669 | - /** |
|
670 | - * @param File|Folder $path |
|
671 | - */ |
|
672 | - protected function pathCreateChecks($path) { |
|
673 | - // Make sure that we do not share a path that contains a shared mountpoint |
|
674 | - if ($path instanceof \OCP\Files\Folder) { |
|
675 | - $mounts = $this->mountManager->findIn($path->getPath()); |
|
676 | - foreach ($mounts as $mount) { |
|
677 | - if ($mount->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
678 | - throw new \InvalidArgumentException('Path contains files shared with you'); |
|
679 | - } |
|
680 | - } |
|
681 | - } |
|
682 | - } |
|
683 | - |
|
684 | - /** |
|
685 | - * Check if the user that is sharing can actually share |
|
686 | - * |
|
687 | - * @param IShare $share |
|
688 | - * @throws \Exception |
|
689 | - */ |
|
690 | - protected function canShare(IShare $share) { |
|
691 | - if (!$this->shareApiEnabled()) { |
|
692 | - throw new \Exception('Sharing is disabled'); |
|
693 | - } |
|
694 | - |
|
695 | - if ($this->sharingDisabledForUser($share->getSharedBy())) { |
|
696 | - throw new \Exception('Sharing is disabled for you'); |
|
697 | - } |
|
698 | - } |
|
699 | - |
|
700 | - /** |
|
701 | - * Share a path |
|
702 | - * |
|
703 | - * @param IShare $share |
|
704 | - * @return IShare The share object |
|
705 | - * @throws \Exception |
|
706 | - * |
|
707 | - * TODO: handle link share permissions or check them |
|
708 | - */ |
|
709 | - public function createShare(IShare $share) { |
|
710 | - $this->canShare($share); |
|
711 | - |
|
712 | - $this->generalCreateChecks($share); |
|
713 | - |
|
714 | - // Verify if there are any issues with the path |
|
715 | - $this->pathCreateChecks($share->getNode()); |
|
716 | - |
|
717 | - /* |
|
610 | + $provider = $this->factory->getProviderForType(IShare::TYPE_GROUP); |
|
611 | + $existingShares = $provider->getSharesByPath($share->getNode()); |
|
612 | + foreach ($existingShares as $existingShare) { |
|
613 | + try { |
|
614 | + if ($existingShare->getFullId() === $share->getFullId()) { |
|
615 | + continue; |
|
616 | + } |
|
617 | + } catch (\UnexpectedValueException $e) { |
|
618 | + //It is a new share so just continue |
|
619 | + } |
|
620 | + |
|
621 | + if ($existingShare->getSharedWith() === $share->getSharedWith() && $existingShare->getShareType() === $share->getShareType()) { |
|
622 | + throw new AlreadySharedException('Path is already shared with this group', $existingShare); |
|
623 | + } |
|
624 | + } |
|
625 | + } |
|
626 | + |
|
627 | + /** |
|
628 | + * Check for pre share requirements for link shares |
|
629 | + * |
|
630 | + * @param IShare $share |
|
631 | + * @throws \Exception |
|
632 | + */ |
|
633 | + protected function linkCreateChecks(IShare $share) { |
|
634 | + // Are link shares allowed? |
|
635 | + if (!$this->shareApiAllowLinks()) { |
|
636 | + throw new \Exception('Link sharing is not allowed'); |
|
637 | + } |
|
638 | + |
|
639 | + // Check if public upload is allowed |
|
640 | + if (!$this->shareApiLinkAllowPublicUpload() && |
|
641 | + ($share->getPermissions() & (\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE))) { |
|
642 | + throw new \InvalidArgumentException('Public upload is not allowed'); |
|
643 | + } |
|
644 | + } |
|
645 | + |
|
646 | + /** |
|
647 | + * To make sure we don't get invisible link shares we set the parent |
|
648 | + * of a link if it is a reshare. This is a quick word around |
|
649 | + * until we can properly display multiple link shares in the UI |
|
650 | + * |
|
651 | + * See: https://github.com/owncloud/core/issues/22295 |
|
652 | + * |
|
653 | + * FIXME: Remove once multiple link shares can be properly displayed |
|
654 | + * |
|
655 | + * @param IShare $share |
|
656 | + */ |
|
657 | + protected function setLinkParent(IShare $share) { |
|
658 | + |
|
659 | + // No sense in checking if the method is not there. |
|
660 | + if (method_exists($share, 'setParent')) { |
|
661 | + $storage = $share->getNode()->getStorage(); |
|
662 | + if ($storage->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
663 | + /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
664 | + $share->setParent($storage->getShareId()); |
|
665 | + } |
|
666 | + } |
|
667 | + } |
|
668 | + |
|
669 | + /** |
|
670 | + * @param File|Folder $path |
|
671 | + */ |
|
672 | + protected function pathCreateChecks($path) { |
|
673 | + // Make sure that we do not share a path that contains a shared mountpoint |
|
674 | + if ($path instanceof \OCP\Files\Folder) { |
|
675 | + $mounts = $this->mountManager->findIn($path->getPath()); |
|
676 | + foreach ($mounts as $mount) { |
|
677 | + if ($mount->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
678 | + throw new \InvalidArgumentException('Path contains files shared with you'); |
|
679 | + } |
|
680 | + } |
|
681 | + } |
|
682 | + } |
|
683 | + |
|
684 | + /** |
|
685 | + * Check if the user that is sharing can actually share |
|
686 | + * |
|
687 | + * @param IShare $share |
|
688 | + * @throws \Exception |
|
689 | + */ |
|
690 | + protected function canShare(IShare $share) { |
|
691 | + if (!$this->shareApiEnabled()) { |
|
692 | + throw new \Exception('Sharing is disabled'); |
|
693 | + } |
|
694 | + |
|
695 | + if ($this->sharingDisabledForUser($share->getSharedBy())) { |
|
696 | + throw new \Exception('Sharing is disabled for you'); |
|
697 | + } |
|
698 | + } |
|
699 | + |
|
700 | + /** |
|
701 | + * Share a path |
|
702 | + * |
|
703 | + * @param IShare $share |
|
704 | + * @return IShare The share object |
|
705 | + * @throws \Exception |
|
706 | + * |
|
707 | + * TODO: handle link share permissions or check them |
|
708 | + */ |
|
709 | + public function createShare(IShare $share) { |
|
710 | + $this->canShare($share); |
|
711 | + |
|
712 | + $this->generalCreateChecks($share); |
|
713 | + |
|
714 | + // Verify if there are any issues with the path |
|
715 | + $this->pathCreateChecks($share->getNode()); |
|
716 | + |
|
717 | + /* |
|
718 | 718 | * On creation of a share the owner is always the owner of the path |
719 | 719 | * Except for mounted federated shares. |
720 | 720 | */ |
721 | - $storage = $share->getNode()->getStorage(); |
|
722 | - if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
723 | - $parent = $share->getNode()->getParent(); |
|
724 | - while ($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
725 | - $parent = $parent->getParent(); |
|
726 | - } |
|
727 | - $share->setShareOwner($parent->getOwner()->getUID()); |
|
728 | - } else { |
|
729 | - if ($share->getNode()->getOwner()) { |
|
730 | - $share->setShareOwner($share->getNode()->getOwner()->getUID()); |
|
731 | - } else { |
|
732 | - $share->setShareOwner($share->getSharedBy()); |
|
733 | - } |
|
734 | - } |
|
735 | - |
|
736 | - try { |
|
737 | - // Verify share type |
|
738 | - if ($share->getShareType() === IShare::TYPE_USER) { |
|
739 | - $this->userCreateChecks($share); |
|
740 | - |
|
741 | - // Verify the expiration date |
|
742 | - $share = $this->validateExpirationDateInternal($share); |
|
743 | - } elseif ($share->getShareType() === IShare::TYPE_GROUP) { |
|
744 | - $this->groupCreateChecks($share); |
|
745 | - |
|
746 | - // Verify the expiration date |
|
747 | - $share = $this->validateExpirationDateInternal($share); |
|
748 | - } elseif ($share->getShareType() === IShare::TYPE_REMOTE || $share->getShareType() === IShare::TYPE_REMOTE_GROUP) { |
|
749 | - //Verify the expiration date |
|
750 | - $share = $this->validateExpirationDateInternal($share); |
|
751 | - } elseif ($share->getShareType() === IShare::TYPE_LINK |
|
752 | - || $share->getShareType() === IShare::TYPE_EMAIL) { |
|
753 | - $this->linkCreateChecks($share); |
|
754 | - $this->setLinkParent($share); |
|
755 | - |
|
756 | - // For now ignore a set token. |
|
757 | - $share->setToken( |
|
758 | - $this->secureRandom->generate( |
|
759 | - \OC\Share\Constants::TOKEN_LENGTH, |
|
760 | - \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE |
|
761 | - ) |
|
762 | - ); |
|
763 | - |
|
764 | - // Verify the expiration date |
|
765 | - $share = $this->validateExpirationDateLink($share); |
|
766 | - |
|
767 | - // Verify the password |
|
768 | - $this->verifyPassword($share->getPassword()); |
|
769 | - |
|
770 | - // If a password is set. Hash it! |
|
771 | - if ($share->getShareType() === IShare::TYPE_LINK |
|
772 | - && $share->getPassword() !== null) { |
|
773 | - $share->setPassword($this->hasher->hash($share->getPassword())); |
|
774 | - } |
|
775 | - } |
|
776 | - |
|
777 | - // Cannot share with the owner |
|
778 | - if ($share->getShareType() === IShare::TYPE_USER && |
|
779 | - $share->getSharedWith() === $share->getShareOwner()) { |
|
780 | - throw new \InvalidArgumentException('Cannot share with the share owner'); |
|
781 | - } |
|
782 | - |
|
783 | - // Generate the target |
|
784 | - $target = $this->config->getSystemValue('share_folder', '/') . '/' . $share->getNode()->getName(); |
|
785 | - $target = \OC\Files\Filesystem::normalizePath($target); |
|
786 | - $share->setTarget($target); |
|
787 | - |
|
788 | - // Pre share event |
|
789 | - $event = new GenericEvent($share); |
|
790 | - $this->legacyDispatcher->dispatch('OCP\Share::preShare', $event); |
|
791 | - if ($event->isPropagationStopped() && $event->hasArgument('error')) { |
|
792 | - throw new \Exception($event->getArgument('error')); |
|
793 | - } |
|
794 | - |
|
795 | - $oldShare = $share; |
|
796 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
797 | - $share = $provider->create($share); |
|
798 | - |
|
799 | - // Reuse the node we already have |
|
800 | - $share->setNode($oldShare->getNode()); |
|
801 | - |
|
802 | - // Reset the target if it is null for the new share |
|
803 | - if ($share->getTarget() === '') { |
|
804 | - $share->setTarget($target); |
|
805 | - } |
|
806 | - } catch (AlreadySharedException $e) { |
|
807 | - // if a share for the same target already exists, dont create a new one, but do trigger the hooks and notifications again |
|
808 | - $share = $e->getExistingShare(); |
|
809 | - } |
|
810 | - |
|
811 | - // Post share event |
|
812 | - $event = new GenericEvent($share); |
|
813 | - $this->legacyDispatcher->dispatch('OCP\Share::postShare', $event); |
|
814 | - |
|
815 | - $this->dispatcher->dispatchTyped(new Share\Events\ShareCreatedEvent($share)); |
|
816 | - |
|
817 | - if ($this->config->getSystemValueBool('sharing.enable_share_mail', true) |
|
818 | - && $share->getShareType() === IShare::TYPE_USER) { |
|
819 | - $mailSend = $share->getMailSend(); |
|
820 | - if ($mailSend === true) { |
|
821 | - $user = $this->userManager->get($share->getSharedWith()); |
|
822 | - if ($user !== null) { |
|
823 | - $emailAddress = $user->getEMailAddress(); |
|
824 | - if ($emailAddress !== null && $emailAddress !== '') { |
|
825 | - $userLang = $this->l10nFactory->getUserLanguage($user); |
|
826 | - $l = $this->l10nFactory->get('lib', $userLang); |
|
827 | - $this->sendMailNotification( |
|
828 | - $l, |
|
829 | - $share->getNode()->getName(), |
|
830 | - $this->urlGenerator->linkToRouteAbsolute('files_sharing.Accept.accept', ['shareId' => $share->getFullId()]), |
|
831 | - $share->getSharedBy(), |
|
832 | - $emailAddress, |
|
833 | - $share->getExpirationDate() |
|
834 | - ); |
|
835 | - $this->logger->debug('Sent share notification to ' . $emailAddress . ' for share with ID ' . $share->getId(), ['app' => 'share']); |
|
836 | - } else { |
|
837 | - $this->logger->debug('Share notification not sent to ' . $share->getSharedWith() . ' because email address is not set.', ['app' => 'share']); |
|
838 | - } |
|
839 | - } else { |
|
840 | - $this->logger->debug('Share notification not sent to ' . $share->getSharedWith() . ' because user could not be found.', ['app' => 'share']); |
|
841 | - } |
|
842 | - } else { |
|
843 | - $this->logger->debug('Share notification not sent because mailsend is false.', ['app' => 'share']); |
|
844 | - } |
|
845 | - } |
|
846 | - |
|
847 | - return $share; |
|
848 | - } |
|
849 | - |
|
850 | - /** |
|
851 | - * Send mail notifications |
|
852 | - * |
|
853 | - * This method will catch and log mail transmission errors |
|
854 | - * |
|
855 | - * @param IL10N $l Language of the recipient |
|
856 | - * @param string $filename file/folder name |
|
857 | - * @param string $link link to the file/folder |
|
858 | - * @param string $initiator user ID of share sender |
|
859 | - * @param string $shareWith email address of share receiver |
|
860 | - * @param \DateTime|null $expiration |
|
861 | - */ |
|
862 | - protected function sendMailNotification(IL10N $l, |
|
863 | - $filename, |
|
864 | - $link, |
|
865 | - $initiator, |
|
866 | - $shareWith, |
|
867 | - \DateTime $expiration = null) { |
|
868 | - $initiatorUser = $this->userManager->get($initiator); |
|
869 | - $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
870 | - |
|
871 | - $message = $this->mailer->createMessage(); |
|
872 | - |
|
873 | - $emailTemplate = $this->mailer->createEMailTemplate('files_sharing.RecipientNotification', [ |
|
874 | - 'filename' => $filename, |
|
875 | - 'link' => $link, |
|
876 | - 'initiator' => $initiatorDisplayName, |
|
877 | - 'expiration' => $expiration, |
|
878 | - 'shareWith' => $shareWith, |
|
879 | - ]); |
|
880 | - |
|
881 | - $emailTemplate->setSubject($l->t('%1$s shared »%2$s« with you', [$initiatorDisplayName, $filename])); |
|
882 | - $emailTemplate->addHeader(); |
|
883 | - $emailTemplate->addHeading($l->t('%1$s shared »%2$s« with you', [$initiatorDisplayName, $filename]), false); |
|
884 | - $text = $l->t('%1$s shared »%2$s« with you.', [$initiatorDisplayName, $filename]); |
|
885 | - |
|
886 | - $emailTemplate->addBodyText( |
|
887 | - htmlspecialchars($text . ' ' . $l->t('Click the button below to open it.')), |
|
888 | - $text |
|
889 | - ); |
|
890 | - $emailTemplate->addBodyButton( |
|
891 | - $l->t('Open »%s«', [$filename]), |
|
892 | - $link |
|
893 | - ); |
|
894 | - |
|
895 | - $message->setTo([$shareWith]); |
|
896 | - |
|
897 | - // The "From" contains the sharers name |
|
898 | - $instanceName = $this->defaults->getName(); |
|
899 | - $senderName = $l->t( |
|
900 | - '%1$s via %2$s', |
|
901 | - [ |
|
902 | - $initiatorDisplayName, |
|
903 | - $instanceName, |
|
904 | - ] |
|
905 | - ); |
|
906 | - $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]); |
|
907 | - |
|
908 | - // The "Reply-To" is set to the sharer if an mail address is configured |
|
909 | - // also the default footer contains a "Do not reply" which needs to be adjusted. |
|
910 | - $initiatorEmail = $initiatorUser->getEMailAddress(); |
|
911 | - if ($initiatorEmail !== null) { |
|
912 | - $message->setReplyTo([$initiatorEmail => $initiatorDisplayName]); |
|
913 | - $emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan($l->getLanguageCode()) !== '' ? ' - ' . $this->defaults->getSlogan($l->getLanguageCode()) : '')); |
|
914 | - } else { |
|
915 | - $emailTemplate->addFooter('', $l->getLanguageCode()); |
|
916 | - } |
|
917 | - |
|
918 | - $message->useTemplate($emailTemplate); |
|
919 | - try { |
|
920 | - $failedRecipients = $this->mailer->send($message); |
|
921 | - if (!empty($failedRecipients)) { |
|
922 | - $this->logger->error('Share notification mail could not be sent to: ' . implode(', ', $failedRecipients)); |
|
923 | - return; |
|
924 | - } |
|
925 | - } catch (\Exception $e) { |
|
926 | - $this->logger->logException($e, ['message' => 'Share notification mail could not be sent']); |
|
927 | - } |
|
928 | - } |
|
929 | - |
|
930 | - /** |
|
931 | - * Update a share |
|
932 | - * |
|
933 | - * @param IShare $share |
|
934 | - * @return IShare The share object |
|
935 | - * @throws \InvalidArgumentException |
|
936 | - */ |
|
937 | - public function updateShare(IShare $share) { |
|
938 | - $expirationDateUpdated = false; |
|
939 | - |
|
940 | - $this->canShare($share); |
|
941 | - |
|
942 | - try { |
|
943 | - $originalShare = $this->getShareById($share->getFullId()); |
|
944 | - } catch (\UnexpectedValueException $e) { |
|
945 | - throw new \InvalidArgumentException('Share does not have a full id'); |
|
946 | - } |
|
947 | - |
|
948 | - // We cannot change the share type! |
|
949 | - if ($share->getShareType() !== $originalShare->getShareType()) { |
|
950 | - throw new \InvalidArgumentException('Cannot change share type'); |
|
951 | - } |
|
952 | - |
|
953 | - // We can only change the recipient on user shares |
|
954 | - if ($share->getSharedWith() !== $originalShare->getSharedWith() && |
|
955 | - $share->getShareType() !== IShare::TYPE_USER) { |
|
956 | - throw new \InvalidArgumentException('Can only update recipient on user shares'); |
|
957 | - } |
|
958 | - |
|
959 | - // Cannot share with the owner |
|
960 | - if ($share->getShareType() === IShare::TYPE_USER && |
|
961 | - $share->getSharedWith() === $share->getShareOwner()) { |
|
962 | - throw new \InvalidArgumentException('Cannot share with the share owner'); |
|
963 | - } |
|
964 | - |
|
965 | - $this->generalCreateChecks($share); |
|
966 | - |
|
967 | - if ($share->getShareType() === IShare::TYPE_USER) { |
|
968 | - $this->userCreateChecks($share); |
|
969 | - |
|
970 | - if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
971 | - //Verify the expiration date |
|
972 | - $this->validateExpirationDateInternal($share); |
|
973 | - $expirationDateUpdated = true; |
|
974 | - } |
|
975 | - } elseif ($share->getShareType() === IShare::TYPE_GROUP) { |
|
976 | - $this->groupCreateChecks($share); |
|
977 | - |
|
978 | - if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
979 | - //Verify the expiration date |
|
980 | - $this->validateExpirationDateInternal($share); |
|
981 | - $expirationDateUpdated = true; |
|
982 | - } |
|
983 | - } elseif ($share->getShareType() === IShare::TYPE_LINK |
|
984 | - || $share->getShareType() === IShare::TYPE_EMAIL) { |
|
985 | - $this->linkCreateChecks($share); |
|
986 | - |
|
987 | - // The new password is not set again if it is the same as the old |
|
988 | - // one, unless when switching from sending by Talk to sending by |
|
989 | - // mail. |
|
990 | - $plainTextPassword = $share->getPassword(); |
|
991 | - $updatedPassword = $this->updateSharePasswordIfNeeded($share, $originalShare); |
|
992 | - |
|
993 | - /** |
|
994 | - * Cannot enable the getSendPasswordByTalk if there is no password set |
|
995 | - */ |
|
996 | - if (empty($plainTextPassword) && $share->getSendPasswordByTalk()) { |
|
997 | - throw new \InvalidArgumentException('Cannot enable sending the password by Talk with an empty password'); |
|
998 | - } |
|
999 | - |
|
1000 | - /** |
|
1001 | - * If we're in a mail share, we need to force a password change |
|
1002 | - * as either the user is not aware of the password or is already (received by mail) |
|
1003 | - * Thus the SendPasswordByTalk feature would not make sense |
|
1004 | - */ |
|
1005 | - if (!$updatedPassword && $share->getShareType() === IShare::TYPE_EMAIL) { |
|
1006 | - if (!$originalShare->getSendPasswordByTalk() && $share->getSendPasswordByTalk()) { |
|
1007 | - throw new \InvalidArgumentException('Cannot enable sending the password by Talk without setting a new password'); |
|
1008 | - } |
|
1009 | - if ($originalShare->getSendPasswordByTalk() && !$share->getSendPasswordByTalk()) { |
|
1010 | - throw new \InvalidArgumentException('Cannot disable sending the password by Talk without setting a new password'); |
|
1011 | - } |
|
1012 | - } |
|
1013 | - |
|
1014 | - if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
1015 | - // Verify the expiration date |
|
1016 | - $this->validateExpirationDateLink($share); |
|
1017 | - $expirationDateUpdated = true; |
|
1018 | - } |
|
1019 | - } elseif ($share->getShareType() === IShare::TYPE_REMOTE || $share->getShareType() === IShare::TYPE_REMOTE_GROUP) { |
|
1020 | - if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
1021 | - //Verify the expiration date |
|
1022 | - $this->validateExpirationDateInternal($share); |
|
1023 | - $expirationDateUpdated = true; |
|
1024 | - } |
|
1025 | - } |
|
1026 | - |
|
1027 | - $this->pathCreateChecks($share->getNode()); |
|
1028 | - |
|
1029 | - // Now update the share! |
|
1030 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
1031 | - if ($share->getShareType() === IShare::TYPE_EMAIL) { |
|
1032 | - $share = $provider->update($share, $plainTextPassword); |
|
1033 | - } else { |
|
1034 | - $share = $provider->update($share); |
|
1035 | - } |
|
1036 | - |
|
1037 | - if ($expirationDateUpdated === true) { |
|
1038 | - \OC_Hook::emit(Share::class, 'post_set_expiration_date', [ |
|
1039 | - 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
1040 | - 'itemSource' => $share->getNode()->getId(), |
|
1041 | - 'date' => $share->getExpirationDate(), |
|
1042 | - 'uidOwner' => $share->getSharedBy(), |
|
1043 | - ]); |
|
1044 | - } |
|
1045 | - |
|
1046 | - if ($share->getPassword() !== $originalShare->getPassword()) { |
|
1047 | - \OC_Hook::emit(Share::class, 'post_update_password', [ |
|
1048 | - 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
1049 | - 'itemSource' => $share->getNode()->getId(), |
|
1050 | - 'uidOwner' => $share->getSharedBy(), |
|
1051 | - 'token' => $share->getToken(), |
|
1052 | - 'disabled' => is_null($share->getPassword()), |
|
1053 | - ]); |
|
1054 | - } |
|
1055 | - |
|
1056 | - if ($share->getPermissions() !== $originalShare->getPermissions()) { |
|
1057 | - if ($this->userManager->userExists($share->getShareOwner())) { |
|
1058 | - $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
1059 | - } else { |
|
1060 | - $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
1061 | - } |
|
1062 | - \OC_Hook::emit(Share::class, 'post_update_permissions', [ |
|
1063 | - 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
1064 | - 'itemSource' => $share->getNode()->getId(), |
|
1065 | - 'shareType' => $share->getShareType(), |
|
1066 | - 'shareWith' => $share->getSharedWith(), |
|
1067 | - 'uidOwner' => $share->getSharedBy(), |
|
1068 | - 'permissions' => $share->getPermissions(), |
|
1069 | - 'path' => $userFolder->getRelativePath($share->getNode()->getPath()), |
|
1070 | - ]); |
|
1071 | - } |
|
1072 | - |
|
1073 | - return $share; |
|
1074 | - } |
|
1075 | - |
|
1076 | - /** |
|
1077 | - * Accept a share. |
|
1078 | - * |
|
1079 | - * @param IShare $share |
|
1080 | - * @param string $recipientId |
|
1081 | - * @return IShare The share object |
|
1082 | - * @throws \InvalidArgumentException |
|
1083 | - * @since 9.0.0 |
|
1084 | - */ |
|
1085 | - public function acceptShare(IShare $share, string $recipientId): IShare { |
|
1086 | - [$providerId,] = $this->splitFullId($share->getFullId()); |
|
1087 | - $provider = $this->factory->getProvider($providerId); |
|
1088 | - |
|
1089 | - if (!method_exists($provider, 'acceptShare')) { |
|
1090 | - // TODO FIX ME |
|
1091 | - throw new \InvalidArgumentException('Share provider does not support accepting'); |
|
1092 | - } |
|
1093 | - $provider->acceptShare($share, $recipientId); |
|
1094 | - $event = new GenericEvent($share); |
|
1095 | - $this->legacyDispatcher->dispatch('OCP\Share::postAcceptShare', $event); |
|
1096 | - |
|
1097 | - return $share; |
|
1098 | - } |
|
1099 | - |
|
1100 | - /** |
|
1101 | - * Updates the password of the given share if it is not the same as the |
|
1102 | - * password of the original share. |
|
1103 | - * |
|
1104 | - * @param IShare $share the share to update its password. |
|
1105 | - * @param IShare $originalShare the original share to compare its |
|
1106 | - * password with. |
|
1107 | - * @return boolean whether the password was updated or not. |
|
1108 | - */ |
|
1109 | - private function updateSharePasswordIfNeeded(IShare $share, IShare $originalShare) { |
|
1110 | - $passwordsAreDifferent = ($share->getPassword() !== $originalShare->getPassword()) && |
|
1111 | - (($share->getPassword() !== null && $originalShare->getPassword() === null) || |
|
1112 | - ($share->getPassword() === null && $originalShare->getPassword() !== null) || |
|
1113 | - ($share->getPassword() !== null && $originalShare->getPassword() !== null && |
|
1114 | - !$this->hasher->verify($share->getPassword(), $originalShare->getPassword()))); |
|
1115 | - |
|
1116 | - // Password updated. |
|
1117 | - if ($passwordsAreDifferent) { |
|
1118 | - //Verify the password |
|
1119 | - $this->verifyPassword($share->getPassword()); |
|
1120 | - |
|
1121 | - // If a password is set. Hash it! |
|
1122 | - if (!empty($share->getPassword())) { |
|
1123 | - $share->setPassword($this->hasher->hash($share->getPassword())); |
|
1124 | - |
|
1125 | - return true; |
|
1126 | - } else { |
|
1127 | - // Empty string and null are seen as NOT password protected |
|
1128 | - $share->setPassword(null); |
|
1129 | - return true; |
|
1130 | - } |
|
1131 | - } else { |
|
1132 | - // Reset the password to the original one, as it is either the same |
|
1133 | - // as the "new" password or a hashed version of it. |
|
1134 | - $share->setPassword($originalShare->getPassword()); |
|
1135 | - } |
|
1136 | - |
|
1137 | - return false; |
|
1138 | - } |
|
1139 | - |
|
1140 | - /** |
|
1141 | - * Delete all the children of this share |
|
1142 | - * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
|
1143 | - * |
|
1144 | - * @param IShare $share |
|
1145 | - * @return IShare[] List of deleted shares |
|
1146 | - */ |
|
1147 | - protected function deleteChildren(IShare $share) { |
|
1148 | - $deletedShares = []; |
|
1149 | - |
|
1150 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
1151 | - |
|
1152 | - foreach ($provider->getChildren($share) as $child) { |
|
1153 | - $deletedChildren = $this->deleteChildren($child); |
|
1154 | - $deletedShares = array_merge($deletedShares, $deletedChildren); |
|
1155 | - |
|
1156 | - $provider->delete($child); |
|
1157 | - $this->dispatcher->dispatchTyped(new Share\Events\ShareDeletedEvent($child)); |
|
1158 | - $deletedShares[] = $child; |
|
1159 | - } |
|
1160 | - |
|
1161 | - return $deletedShares; |
|
1162 | - } |
|
1163 | - |
|
1164 | - /** |
|
1165 | - * Delete a share |
|
1166 | - * |
|
1167 | - * @param IShare $share |
|
1168 | - * @throws ShareNotFound |
|
1169 | - * @throws \InvalidArgumentException |
|
1170 | - */ |
|
1171 | - public function deleteShare(IShare $share) { |
|
1172 | - try { |
|
1173 | - $share->getFullId(); |
|
1174 | - } catch (\UnexpectedValueException $e) { |
|
1175 | - throw new \InvalidArgumentException('Share does not have a full id'); |
|
1176 | - } |
|
1177 | - |
|
1178 | - $event = new GenericEvent($share); |
|
1179 | - $this->legacyDispatcher->dispatch('OCP\Share::preUnshare', $event); |
|
1180 | - |
|
1181 | - // Get all children and delete them as well |
|
1182 | - $deletedShares = $this->deleteChildren($share); |
|
1183 | - |
|
1184 | - // Do the actual delete |
|
1185 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
1186 | - $provider->delete($share); |
|
1187 | - |
|
1188 | - $this->dispatcher->dispatchTyped(new Share\Events\ShareDeletedEvent($share)); |
|
1189 | - |
|
1190 | - // All the deleted shares caused by this delete |
|
1191 | - $deletedShares[] = $share; |
|
1192 | - |
|
1193 | - // Emit post hook |
|
1194 | - $event->setArgument('deletedShares', $deletedShares); |
|
1195 | - $this->legacyDispatcher->dispatch('OCP\Share::postUnshare', $event); |
|
1196 | - } |
|
1197 | - |
|
1198 | - |
|
1199 | - /** |
|
1200 | - * Unshare a file as the recipient. |
|
1201 | - * This can be different from a regular delete for example when one of |
|
1202 | - * the users in a groups deletes that share. But the provider should |
|
1203 | - * handle this. |
|
1204 | - * |
|
1205 | - * @param IShare $share |
|
1206 | - * @param string $recipientId |
|
1207 | - */ |
|
1208 | - public function deleteFromSelf(IShare $share, $recipientId) { |
|
1209 | - [$providerId,] = $this->splitFullId($share->getFullId()); |
|
1210 | - $provider = $this->factory->getProvider($providerId); |
|
1211 | - |
|
1212 | - $provider->deleteFromSelf($share, $recipientId); |
|
1213 | - $event = new GenericEvent($share); |
|
1214 | - $this->legacyDispatcher->dispatch('OCP\Share::postUnshareFromSelf', $event); |
|
1215 | - } |
|
1216 | - |
|
1217 | - public function restoreShare(IShare $share, string $recipientId): IShare { |
|
1218 | - [$providerId,] = $this->splitFullId($share->getFullId()); |
|
1219 | - $provider = $this->factory->getProvider($providerId); |
|
1220 | - |
|
1221 | - return $provider->restore($share, $recipientId); |
|
1222 | - } |
|
1223 | - |
|
1224 | - /** |
|
1225 | - * @inheritdoc |
|
1226 | - */ |
|
1227 | - public function moveShare(IShare $share, $recipientId) { |
|
1228 | - if ($share->getShareType() === IShare::TYPE_LINK |
|
1229 | - || $share->getShareType() === IShare::TYPE_EMAIL) { |
|
1230 | - throw new \InvalidArgumentException('Cannot change target of link share'); |
|
1231 | - } |
|
1232 | - |
|
1233 | - if ($share->getShareType() === IShare::TYPE_USER && $share->getSharedWith() !== $recipientId) { |
|
1234 | - throw new \InvalidArgumentException('Invalid recipient'); |
|
1235 | - } |
|
1236 | - |
|
1237 | - if ($share->getShareType() === IShare::TYPE_GROUP) { |
|
1238 | - $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
1239 | - if (is_null($sharedWith)) { |
|
1240 | - throw new \InvalidArgumentException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
1241 | - } |
|
1242 | - $recipient = $this->userManager->get($recipientId); |
|
1243 | - if (!$sharedWith->inGroup($recipient)) { |
|
1244 | - throw new \InvalidArgumentException('Invalid recipient'); |
|
1245 | - } |
|
1246 | - } |
|
1247 | - |
|
1248 | - [$providerId,] = $this->splitFullId($share->getFullId()); |
|
1249 | - $provider = $this->factory->getProvider($providerId); |
|
1250 | - |
|
1251 | - return $provider->move($share, $recipientId); |
|
1252 | - } |
|
1253 | - |
|
1254 | - public function getSharesInFolder($userId, Folder $node, $reshares = false) { |
|
1255 | - $providers = $this->factory->getAllProviders(); |
|
1256 | - |
|
1257 | - return array_reduce($providers, function ($shares, IShareProvider $provider) use ($userId, $node, $reshares) { |
|
1258 | - $newShares = $provider->getSharesInFolder($userId, $node, $reshares); |
|
1259 | - foreach ($newShares as $fid => $data) { |
|
1260 | - if (!isset($shares[$fid])) { |
|
1261 | - $shares[$fid] = []; |
|
1262 | - } |
|
1263 | - |
|
1264 | - $shares[$fid] = array_merge($shares[$fid], $data); |
|
1265 | - } |
|
1266 | - return $shares; |
|
1267 | - }, []); |
|
1268 | - } |
|
1269 | - |
|
1270 | - /** |
|
1271 | - * @inheritdoc |
|
1272 | - */ |
|
1273 | - public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) { |
|
1274 | - if ($path !== null && |
|
1275 | - !($path instanceof \OCP\Files\File) && |
|
1276 | - !($path instanceof \OCP\Files\Folder)) { |
|
1277 | - throw new \InvalidArgumentException('invalid path'); |
|
1278 | - } |
|
1279 | - |
|
1280 | - try { |
|
1281 | - $provider = $this->factory->getProviderForType($shareType); |
|
1282 | - } catch (ProviderException $e) { |
|
1283 | - return []; |
|
1284 | - } |
|
1285 | - |
|
1286 | - $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
1287 | - |
|
1288 | - /* |
|
721 | + $storage = $share->getNode()->getStorage(); |
|
722 | + if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
723 | + $parent = $share->getNode()->getParent(); |
|
724 | + while ($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
725 | + $parent = $parent->getParent(); |
|
726 | + } |
|
727 | + $share->setShareOwner($parent->getOwner()->getUID()); |
|
728 | + } else { |
|
729 | + if ($share->getNode()->getOwner()) { |
|
730 | + $share->setShareOwner($share->getNode()->getOwner()->getUID()); |
|
731 | + } else { |
|
732 | + $share->setShareOwner($share->getSharedBy()); |
|
733 | + } |
|
734 | + } |
|
735 | + |
|
736 | + try { |
|
737 | + // Verify share type |
|
738 | + if ($share->getShareType() === IShare::TYPE_USER) { |
|
739 | + $this->userCreateChecks($share); |
|
740 | + |
|
741 | + // Verify the expiration date |
|
742 | + $share = $this->validateExpirationDateInternal($share); |
|
743 | + } elseif ($share->getShareType() === IShare::TYPE_GROUP) { |
|
744 | + $this->groupCreateChecks($share); |
|
745 | + |
|
746 | + // Verify the expiration date |
|
747 | + $share = $this->validateExpirationDateInternal($share); |
|
748 | + } elseif ($share->getShareType() === IShare::TYPE_REMOTE || $share->getShareType() === IShare::TYPE_REMOTE_GROUP) { |
|
749 | + //Verify the expiration date |
|
750 | + $share = $this->validateExpirationDateInternal($share); |
|
751 | + } elseif ($share->getShareType() === IShare::TYPE_LINK |
|
752 | + || $share->getShareType() === IShare::TYPE_EMAIL) { |
|
753 | + $this->linkCreateChecks($share); |
|
754 | + $this->setLinkParent($share); |
|
755 | + |
|
756 | + // For now ignore a set token. |
|
757 | + $share->setToken( |
|
758 | + $this->secureRandom->generate( |
|
759 | + \OC\Share\Constants::TOKEN_LENGTH, |
|
760 | + \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE |
|
761 | + ) |
|
762 | + ); |
|
763 | + |
|
764 | + // Verify the expiration date |
|
765 | + $share = $this->validateExpirationDateLink($share); |
|
766 | + |
|
767 | + // Verify the password |
|
768 | + $this->verifyPassword($share->getPassword()); |
|
769 | + |
|
770 | + // If a password is set. Hash it! |
|
771 | + if ($share->getShareType() === IShare::TYPE_LINK |
|
772 | + && $share->getPassword() !== null) { |
|
773 | + $share->setPassword($this->hasher->hash($share->getPassword())); |
|
774 | + } |
|
775 | + } |
|
776 | + |
|
777 | + // Cannot share with the owner |
|
778 | + if ($share->getShareType() === IShare::TYPE_USER && |
|
779 | + $share->getSharedWith() === $share->getShareOwner()) { |
|
780 | + throw new \InvalidArgumentException('Cannot share with the share owner'); |
|
781 | + } |
|
782 | + |
|
783 | + // Generate the target |
|
784 | + $target = $this->config->getSystemValue('share_folder', '/') . '/' . $share->getNode()->getName(); |
|
785 | + $target = \OC\Files\Filesystem::normalizePath($target); |
|
786 | + $share->setTarget($target); |
|
787 | + |
|
788 | + // Pre share event |
|
789 | + $event = new GenericEvent($share); |
|
790 | + $this->legacyDispatcher->dispatch('OCP\Share::preShare', $event); |
|
791 | + if ($event->isPropagationStopped() && $event->hasArgument('error')) { |
|
792 | + throw new \Exception($event->getArgument('error')); |
|
793 | + } |
|
794 | + |
|
795 | + $oldShare = $share; |
|
796 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
797 | + $share = $provider->create($share); |
|
798 | + |
|
799 | + // Reuse the node we already have |
|
800 | + $share->setNode($oldShare->getNode()); |
|
801 | + |
|
802 | + // Reset the target if it is null for the new share |
|
803 | + if ($share->getTarget() === '') { |
|
804 | + $share->setTarget($target); |
|
805 | + } |
|
806 | + } catch (AlreadySharedException $e) { |
|
807 | + // if a share for the same target already exists, dont create a new one, but do trigger the hooks and notifications again |
|
808 | + $share = $e->getExistingShare(); |
|
809 | + } |
|
810 | + |
|
811 | + // Post share event |
|
812 | + $event = new GenericEvent($share); |
|
813 | + $this->legacyDispatcher->dispatch('OCP\Share::postShare', $event); |
|
814 | + |
|
815 | + $this->dispatcher->dispatchTyped(new Share\Events\ShareCreatedEvent($share)); |
|
816 | + |
|
817 | + if ($this->config->getSystemValueBool('sharing.enable_share_mail', true) |
|
818 | + && $share->getShareType() === IShare::TYPE_USER) { |
|
819 | + $mailSend = $share->getMailSend(); |
|
820 | + if ($mailSend === true) { |
|
821 | + $user = $this->userManager->get($share->getSharedWith()); |
|
822 | + if ($user !== null) { |
|
823 | + $emailAddress = $user->getEMailAddress(); |
|
824 | + if ($emailAddress !== null && $emailAddress !== '') { |
|
825 | + $userLang = $this->l10nFactory->getUserLanguage($user); |
|
826 | + $l = $this->l10nFactory->get('lib', $userLang); |
|
827 | + $this->sendMailNotification( |
|
828 | + $l, |
|
829 | + $share->getNode()->getName(), |
|
830 | + $this->urlGenerator->linkToRouteAbsolute('files_sharing.Accept.accept', ['shareId' => $share->getFullId()]), |
|
831 | + $share->getSharedBy(), |
|
832 | + $emailAddress, |
|
833 | + $share->getExpirationDate() |
|
834 | + ); |
|
835 | + $this->logger->debug('Sent share notification to ' . $emailAddress . ' for share with ID ' . $share->getId(), ['app' => 'share']); |
|
836 | + } else { |
|
837 | + $this->logger->debug('Share notification not sent to ' . $share->getSharedWith() . ' because email address is not set.', ['app' => 'share']); |
|
838 | + } |
|
839 | + } else { |
|
840 | + $this->logger->debug('Share notification not sent to ' . $share->getSharedWith() . ' because user could not be found.', ['app' => 'share']); |
|
841 | + } |
|
842 | + } else { |
|
843 | + $this->logger->debug('Share notification not sent because mailsend is false.', ['app' => 'share']); |
|
844 | + } |
|
845 | + } |
|
846 | + |
|
847 | + return $share; |
|
848 | + } |
|
849 | + |
|
850 | + /** |
|
851 | + * Send mail notifications |
|
852 | + * |
|
853 | + * This method will catch and log mail transmission errors |
|
854 | + * |
|
855 | + * @param IL10N $l Language of the recipient |
|
856 | + * @param string $filename file/folder name |
|
857 | + * @param string $link link to the file/folder |
|
858 | + * @param string $initiator user ID of share sender |
|
859 | + * @param string $shareWith email address of share receiver |
|
860 | + * @param \DateTime|null $expiration |
|
861 | + */ |
|
862 | + protected function sendMailNotification(IL10N $l, |
|
863 | + $filename, |
|
864 | + $link, |
|
865 | + $initiator, |
|
866 | + $shareWith, |
|
867 | + \DateTime $expiration = null) { |
|
868 | + $initiatorUser = $this->userManager->get($initiator); |
|
869 | + $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
870 | + |
|
871 | + $message = $this->mailer->createMessage(); |
|
872 | + |
|
873 | + $emailTemplate = $this->mailer->createEMailTemplate('files_sharing.RecipientNotification', [ |
|
874 | + 'filename' => $filename, |
|
875 | + 'link' => $link, |
|
876 | + 'initiator' => $initiatorDisplayName, |
|
877 | + 'expiration' => $expiration, |
|
878 | + 'shareWith' => $shareWith, |
|
879 | + ]); |
|
880 | + |
|
881 | + $emailTemplate->setSubject($l->t('%1$s shared »%2$s« with you', [$initiatorDisplayName, $filename])); |
|
882 | + $emailTemplate->addHeader(); |
|
883 | + $emailTemplate->addHeading($l->t('%1$s shared »%2$s« with you', [$initiatorDisplayName, $filename]), false); |
|
884 | + $text = $l->t('%1$s shared »%2$s« with you.', [$initiatorDisplayName, $filename]); |
|
885 | + |
|
886 | + $emailTemplate->addBodyText( |
|
887 | + htmlspecialchars($text . ' ' . $l->t('Click the button below to open it.')), |
|
888 | + $text |
|
889 | + ); |
|
890 | + $emailTemplate->addBodyButton( |
|
891 | + $l->t('Open »%s«', [$filename]), |
|
892 | + $link |
|
893 | + ); |
|
894 | + |
|
895 | + $message->setTo([$shareWith]); |
|
896 | + |
|
897 | + // The "From" contains the sharers name |
|
898 | + $instanceName = $this->defaults->getName(); |
|
899 | + $senderName = $l->t( |
|
900 | + '%1$s via %2$s', |
|
901 | + [ |
|
902 | + $initiatorDisplayName, |
|
903 | + $instanceName, |
|
904 | + ] |
|
905 | + ); |
|
906 | + $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]); |
|
907 | + |
|
908 | + // The "Reply-To" is set to the sharer if an mail address is configured |
|
909 | + // also the default footer contains a "Do not reply" which needs to be adjusted. |
|
910 | + $initiatorEmail = $initiatorUser->getEMailAddress(); |
|
911 | + if ($initiatorEmail !== null) { |
|
912 | + $message->setReplyTo([$initiatorEmail => $initiatorDisplayName]); |
|
913 | + $emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan($l->getLanguageCode()) !== '' ? ' - ' . $this->defaults->getSlogan($l->getLanguageCode()) : '')); |
|
914 | + } else { |
|
915 | + $emailTemplate->addFooter('', $l->getLanguageCode()); |
|
916 | + } |
|
917 | + |
|
918 | + $message->useTemplate($emailTemplate); |
|
919 | + try { |
|
920 | + $failedRecipients = $this->mailer->send($message); |
|
921 | + if (!empty($failedRecipients)) { |
|
922 | + $this->logger->error('Share notification mail could not be sent to: ' . implode(', ', $failedRecipients)); |
|
923 | + return; |
|
924 | + } |
|
925 | + } catch (\Exception $e) { |
|
926 | + $this->logger->logException($e, ['message' => 'Share notification mail could not be sent']); |
|
927 | + } |
|
928 | + } |
|
929 | + |
|
930 | + /** |
|
931 | + * Update a share |
|
932 | + * |
|
933 | + * @param IShare $share |
|
934 | + * @return IShare The share object |
|
935 | + * @throws \InvalidArgumentException |
|
936 | + */ |
|
937 | + public function updateShare(IShare $share) { |
|
938 | + $expirationDateUpdated = false; |
|
939 | + |
|
940 | + $this->canShare($share); |
|
941 | + |
|
942 | + try { |
|
943 | + $originalShare = $this->getShareById($share->getFullId()); |
|
944 | + } catch (\UnexpectedValueException $e) { |
|
945 | + throw new \InvalidArgumentException('Share does not have a full id'); |
|
946 | + } |
|
947 | + |
|
948 | + // We cannot change the share type! |
|
949 | + if ($share->getShareType() !== $originalShare->getShareType()) { |
|
950 | + throw new \InvalidArgumentException('Cannot change share type'); |
|
951 | + } |
|
952 | + |
|
953 | + // We can only change the recipient on user shares |
|
954 | + if ($share->getSharedWith() !== $originalShare->getSharedWith() && |
|
955 | + $share->getShareType() !== IShare::TYPE_USER) { |
|
956 | + throw new \InvalidArgumentException('Can only update recipient on user shares'); |
|
957 | + } |
|
958 | + |
|
959 | + // Cannot share with the owner |
|
960 | + if ($share->getShareType() === IShare::TYPE_USER && |
|
961 | + $share->getSharedWith() === $share->getShareOwner()) { |
|
962 | + throw new \InvalidArgumentException('Cannot share with the share owner'); |
|
963 | + } |
|
964 | + |
|
965 | + $this->generalCreateChecks($share); |
|
966 | + |
|
967 | + if ($share->getShareType() === IShare::TYPE_USER) { |
|
968 | + $this->userCreateChecks($share); |
|
969 | + |
|
970 | + if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
971 | + //Verify the expiration date |
|
972 | + $this->validateExpirationDateInternal($share); |
|
973 | + $expirationDateUpdated = true; |
|
974 | + } |
|
975 | + } elseif ($share->getShareType() === IShare::TYPE_GROUP) { |
|
976 | + $this->groupCreateChecks($share); |
|
977 | + |
|
978 | + if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
979 | + //Verify the expiration date |
|
980 | + $this->validateExpirationDateInternal($share); |
|
981 | + $expirationDateUpdated = true; |
|
982 | + } |
|
983 | + } elseif ($share->getShareType() === IShare::TYPE_LINK |
|
984 | + || $share->getShareType() === IShare::TYPE_EMAIL) { |
|
985 | + $this->linkCreateChecks($share); |
|
986 | + |
|
987 | + // The new password is not set again if it is the same as the old |
|
988 | + // one, unless when switching from sending by Talk to sending by |
|
989 | + // mail. |
|
990 | + $plainTextPassword = $share->getPassword(); |
|
991 | + $updatedPassword = $this->updateSharePasswordIfNeeded($share, $originalShare); |
|
992 | + |
|
993 | + /** |
|
994 | + * Cannot enable the getSendPasswordByTalk if there is no password set |
|
995 | + */ |
|
996 | + if (empty($plainTextPassword) && $share->getSendPasswordByTalk()) { |
|
997 | + throw new \InvalidArgumentException('Cannot enable sending the password by Talk with an empty password'); |
|
998 | + } |
|
999 | + |
|
1000 | + /** |
|
1001 | + * If we're in a mail share, we need to force a password change |
|
1002 | + * as either the user is not aware of the password or is already (received by mail) |
|
1003 | + * Thus the SendPasswordByTalk feature would not make sense |
|
1004 | + */ |
|
1005 | + if (!$updatedPassword && $share->getShareType() === IShare::TYPE_EMAIL) { |
|
1006 | + if (!$originalShare->getSendPasswordByTalk() && $share->getSendPasswordByTalk()) { |
|
1007 | + throw new \InvalidArgumentException('Cannot enable sending the password by Talk without setting a new password'); |
|
1008 | + } |
|
1009 | + if ($originalShare->getSendPasswordByTalk() && !$share->getSendPasswordByTalk()) { |
|
1010 | + throw new \InvalidArgumentException('Cannot disable sending the password by Talk without setting a new password'); |
|
1011 | + } |
|
1012 | + } |
|
1013 | + |
|
1014 | + if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
1015 | + // Verify the expiration date |
|
1016 | + $this->validateExpirationDateLink($share); |
|
1017 | + $expirationDateUpdated = true; |
|
1018 | + } |
|
1019 | + } elseif ($share->getShareType() === IShare::TYPE_REMOTE || $share->getShareType() === IShare::TYPE_REMOTE_GROUP) { |
|
1020 | + if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
1021 | + //Verify the expiration date |
|
1022 | + $this->validateExpirationDateInternal($share); |
|
1023 | + $expirationDateUpdated = true; |
|
1024 | + } |
|
1025 | + } |
|
1026 | + |
|
1027 | + $this->pathCreateChecks($share->getNode()); |
|
1028 | + |
|
1029 | + // Now update the share! |
|
1030 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
1031 | + if ($share->getShareType() === IShare::TYPE_EMAIL) { |
|
1032 | + $share = $provider->update($share, $plainTextPassword); |
|
1033 | + } else { |
|
1034 | + $share = $provider->update($share); |
|
1035 | + } |
|
1036 | + |
|
1037 | + if ($expirationDateUpdated === true) { |
|
1038 | + \OC_Hook::emit(Share::class, 'post_set_expiration_date', [ |
|
1039 | + 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
1040 | + 'itemSource' => $share->getNode()->getId(), |
|
1041 | + 'date' => $share->getExpirationDate(), |
|
1042 | + 'uidOwner' => $share->getSharedBy(), |
|
1043 | + ]); |
|
1044 | + } |
|
1045 | + |
|
1046 | + if ($share->getPassword() !== $originalShare->getPassword()) { |
|
1047 | + \OC_Hook::emit(Share::class, 'post_update_password', [ |
|
1048 | + 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
1049 | + 'itemSource' => $share->getNode()->getId(), |
|
1050 | + 'uidOwner' => $share->getSharedBy(), |
|
1051 | + 'token' => $share->getToken(), |
|
1052 | + 'disabled' => is_null($share->getPassword()), |
|
1053 | + ]); |
|
1054 | + } |
|
1055 | + |
|
1056 | + if ($share->getPermissions() !== $originalShare->getPermissions()) { |
|
1057 | + if ($this->userManager->userExists($share->getShareOwner())) { |
|
1058 | + $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
1059 | + } else { |
|
1060 | + $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
1061 | + } |
|
1062 | + \OC_Hook::emit(Share::class, 'post_update_permissions', [ |
|
1063 | + 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
1064 | + 'itemSource' => $share->getNode()->getId(), |
|
1065 | + 'shareType' => $share->getShareType(), |
|
1066 | + 'shareWith' => $share->getSharedWith(), |
|
1067 | + 'uidOwner' => $share->getSharedBy(), |
|
1068 | + 'permissions' => $share->getPermissions(), |
|
1069 | + 'path' => $userFolder->getRelativePath($share->getNode()->getPath()), |
|
1070 | + ]); |
|
1071 | + } |
|
1072 | + |
|
1073 | + return $share; |
|
1074 | + } |
|
1075 | + |
|
1076 | + /** |
|
1077 | + * Accept a share. |
|
1078 | + * |
|
1079 | + * @param IShare $share |
|
1080 | + * @param string $recipientId |
|
1081 | + * @return IShare The share object |
|
1082 | + * @throws \InvalidArgumentException |
|
1083 | + * @since 9.0.0 |
|
1084 | + */ |
|
1085 | + public function acceptShare(IShare $share, string $recipientId): IShare { |
|
1086 | + [$providerId,] = $this->splitFullId($share->getFullId()); |
|
1087 | + $provider = $this->factory->getProvider($providerId); |
|
1088 | + |
|
1089 | + if (!method_exists($provider, 'acceptShare')) { |
|
1090 | + // TODO FIX ME |
|
1091 | + throw new \InvalidArgumentException('Share provider does not support accepting'); |
|
1092 | + } |
|
1093 | + $provider->acceptShare($share, $recipientId); |
|
1094 | + $event = new GenericEvent($share); |
|
1095 | + $this->legacyDispatcher->dispatch('OCP\Share::postAcceptShare', $event); |
|
1096 | + |
|
1097 | + return $share; |
|
1098 | + } |
|
1099 | + |
|
1100 | + /** |
|
1101 | + * Updates the password of the given share if it is not the same as the |
|
1102 | + * password of the original share. |
|
1103 | + * |
|
1104 | + * @param IShare $share the share to update its password. |
|
1105 | + * @param IShare $originalShare the original share to compare its |
|
1106 | + * password with. |
|
1107 | + * @return boolean whether the password was updated or not. |
|
1108 | + */ |
|
1109 | + private function updateSharePasswordIfNeeded(IShare $share, IShare $originalShare) { |
|
1110 | + $passwordsAreDifferent = ($share->getPassword() !== $originalShare->getPassword()) && |
|
1111 | + (($share->getPassword() !== null && $originalShare->getPassword() === null) || |
|
1112 | + ($share->getPassword() === null && $originalShare->getPassword() !== null) || |
|
1113 | + ($share->getPassword() !== null && $originalShare->getPassword() !== null && |
|
1114 | + !$this->hasher->verify($share->getPassword(), $originalShare->getPassword()))); |
|
1115 | + |
|
1116 | + // Password updated. |
|
1117 | + if ($passwordsAreDifferent) { |
|
1118 | + //Verify the password |
|
1119 | + $this->verifyPassword($share->getPassword()); |
|
1120 | + |
|
1121 | + // If a password is set. Hash it! |
|
1122 | + if (!empty($share->getPassword())) { |
|
1123 | + $share->setPassword($this->hasher->hash($share->getPassword())); |
|
1124 | + |
|
1125 | + return true; |
|
1126 | + } else { |
|
1127 | + // Empty string and null are seen as NOT password protected |
|
1128 | + $share->setPassword(null); |
|
1129 | + return true; |
|
1130 | + } |
|
1131 | + } else { |
|
1132 | + // Reset the password to the original one, as it is either the same |
|
1133 | + // as the "new" password or a hashed version of it. |
|
1134 | + $share->setPassword($originalShare->getPassword()); |
|
1135 | + } |
|
1136 | + |
|
1137 | + return false; |
|
1138 | + } |
|
1139 | + |
|
1140 | + /** |
|
1141 | + * Delete all the children of this share |
|
1142 | + * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
|
1143 | + * |
|
1144 | + * @param IShare $share |
|
1145 | + * @return IShare[] List of deleted shares |
|
1146 | + */ |
|
1147 | + protected function deleteChildren(IShare $share) { |
|
1148 | + $deletedShares = []; |
|
1149 | + |
|
1150 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
1151 | + |
|
1152 | + foreach ($provider->getChildren($share) as $child) { |
|
1153 | + $deletedChildren = $this->deleteChildren($child); |
|
1154 | + $deletedShares = array_merge($deletedShares, $deletedChildren); |
|
1155 | + |
|
1156 | + $provider->delete($child); |
|
1157 | + $this->dispatcher->dispatchTyped(new Share\Events\ShareDeletedEvent($child)); |
|
1158 | + $deletedShares[] = $child; |
|
1159 | + } |
|
1160 | + |
|
1161 | + return $deletedShares; |
|
1162 | + } |
|
1163 | + |
|
1164 | + /** |
|
1165 | + * Delete a share |
|
1166 | + * |
|
1167 | + * @param IShare $share |
|
1168 | + * @throws ShareNotFound |
|
1169 | + * @throws \InvalidArgumentException |
|
1170 | + */ |
|
1171 | + public function deleteShare(IShare $share) { |
|
1172 | + try { |
|
1173 | + $share->getFullId(); |
|
1174 | + } catch (\UnexpectedValueException $e) { |
|
1175 | + throw new \InvalidArgumentException('Share does not have a full id'); |
|
1176 | + } |
|
1177 | + |
|
1178 | + $event = new GenericEvent($share); |
|
1179 | + $this->legacyDispatcher->dispatch('OCP\Share::preUnshare', $event); |
|
1180 | + |
|
1181 | + // Get all children and delete them as well |
|
1182 | + $deletedShares = $this->deleteChildren($share); |
|
1183 | + |
|
1184 | + // Do the actual delete |
|
1185 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
1186 | + $provider->delete($share); |
|
1187 | + |
|
1188 | + $this->dispatcher->dispatchTyped(new Share\Events\ShareDeletedEvent($share)); |
|
1189 | + |
|
1190 | + // All the deleted shares caused by this delete |
|
1191 | + $deletedShares[] = $share; |
|
1192 | + |
|
1193 | + // Emit post hook |
|
1194 | + $event->setArgument('deletedShares', $deletedShares); |
|
1195 | + $this->legacyDispatcher->dispatch('OCP\Share::postUnshare', $event); |
|
1196 | + } |
|
1197 | + |
|
1198 | + |
|
1199 | + /** |
|
1200 | + * Unshare a file as the recipient. |
|
1201 | + * This can be different from a regular delete for example when one of |
|
1202 | + * the users in a groups deletes that share. But the provider should |
|
1203 | + * handle this. |
|
1204 | + * |
|
1205 | + * @param IShare $share |
|
1206 | + * @param string $recipientId |
|
1207 | + */ |
|
1208 | + public function deleteFromSelf(IShare $share, $recipientId) { |
|
1209 | + [$providerId,] = $this->splitFullId($share->getFullId()); |
|
1210 | + $provider = $this->factory->getProvider($providerId); |
|
1211 | + |
|
1212 | + $provider->deleteFromSelf($share, $recipientId); |
|
1213 | + $event = new GenericEvent($share); |
|
1214 | + $this->legacyDispatcher->dispatch('OCP\Share::postUnshareFromSelf', $event); |
|
1215 | + } |
|
1216 | + |
|
1217 | + public function restoreShare(IShare $share, string $recipientId): IShare { |
|
1218 | + [$providerId,] = $this->splitFullId($share->getFullId()); |
|
1219 | + $provider = $this->factory->getProvider($providerId); |
|
1220 | + |
|
1221 | + return $provider->restore($share, $recipientId); |
|
1222 | + } |
|
1223 | + |
|
1224 | + /** |
|
1225 | + * @inheritdoc |
|
1226 | + */ |
|
1227 | + public function moveShare(IShare $share, $recipientId) { |
|
1228 | + if ($share->getShareType() === IShare::TYPE_LINK |
|
1229 | + || $share->getShareType() === IShare::TYPE_EMAIL) { |
|
1230 | + throw new \InvalidArgumentException('Cannot change target of link share'); |
|
1231 | + } |
|
1232 | + |
|
1233 | + if ($share->getShareType() === IShare::TYPE_USER && $share->getSharedWith() !== $recipientId) { |
|
1234 | + throw new \InvalidArgumentException('Invalid recipient'); |
|
1235 | + } |
|
1236 | + |
|
1237 | + if ($share->getShareType() === IShare::TYPE_GROUP) { |
|
1238 | + $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
1239 | + if (is_null($sharedWith)) { |
|
1240 | + throw new \InvalidArgumentException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
1241 | + } |
|
1242 | + $recipient = $this->userManager->get($recipientId); |
|
1243 | + if (!$sharedWith->inGroup($recipient)) { |
|
1244 | + throw new \InvalidArgumentException('Invalid recipient'); |
|
1245 | + } |
|
1246 | + } |
|
1247 | + |
|
1248 | + [$providerId,] = $this->splitFullId($share->getFullId()); |
|
1249 | + $provider = $this->factory->getProvider($providerId); |
|
1250 | + |
|
1251 | + return $provider->move($share, $recipientId); |
|
1252 | + } |
|
1253 | + |
|
1254 | + public function getSharesInFolder($userId, Folder $node, $reshares = false) { |
|
1255 | + $providers = $this->factory->getAllProviders(); |
|
1256 | + |
|
1257 | + return array_reduce($providers, function ($shares, IShareProvider $provider) use ($userId, $node, $reshares) { |
|
1258 | + $newShares = $provider->getSharesInFolder($userId, $node, $reshares); |
|
1259 | + foreach ($newShares as $fid => $data) { |
|
1260 | + if (!isset($shares[$fid])) { |
|
1261 | + $shares[$fid] = []; |
|
1262 | + } |
|
1263 | + |
|
1264 | + $shares[$fid] = array_merge($shares[$fid], $data); |
|
1265 | + } |
|
1266 | + return $shares; |
|
1267 | + }, []); |
|
1268 | + } |
|
1269 | + |
|
1270 | + /** |
|
1271 | + * @inheritdoc |
|
1272 | + */ |
|
1273 | + public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) { |
|
1274 | + if ($path !== null && |
|
1275 | + !($path instanceof \OCP\Files\File) && |
|
1276 | + !($path instanceof \OCP\Files\Folder)) { |
|
1277 | + throw new \InvalidArgumentException('invalid path'); |
|
1278 | + } |
|
1279 | + |
|
1280 | + try { |
|
1281 | + $provider = $this->factory->getProviderForType($shareType); |
|
1282 | + } catch (ProviderException $e) { |
|
1283 | + return []; |
|
1284 | + } |
|
1285 | + |
|
1286 | + $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
1287 | + |
|
1288 | + /* |
|
1289 | 1289 | * Work around so we don't return expired shares but still follow |
1290 | 1290 | * proper pagination. |
1291 | 1291 | */ |
1292 | 1292 | |
1293 | - $shares2 = []; |
|
1294 | - |
|
1295 | - while (true) { |
|
1296 | - $added = 0; |
|
1297 | - foreach ($shares as $share) { |
|
1298 | - try { |
|
1299 | - $this->checkExpireDate($share); |
|
1300 | - } catch (ShareNotFound $e) { |
|
1301 | - //Ignore since this basically means the share is deleted |
|
1302 | - continue; |
|
1303 | - } |
|
1304 | - |
|
1305 | - $added++; |
|
1306 | - $shares2[] = $share; |
|
1307 | - |
|
1308 | - if (count($shares2) === $limit) { |
|
1309 | - break; |
|
1310 | - } |
|
1311 | - } |
|
1312 | - |
|
1313 | - // If we did not fetch more shares than the limit then there are no more shares |
|
1314 | - if (count($shares) < $limit) { |
|
1315 | - break; |
|
1316 | - } |
|
1317 | - |
|
1318 | - if (count($shares2) === $limit) { |
|
1319 | - break; |
|
1320 | - } |
|
1321 | - |
|
1322 | - // If there was no limit on the select we are done |
|
1323 | - if ($limit === -1) { |
|
1324 | - break; |
|
1325 | - } |
|
1326 | - |
|
1327 | - $offset += $added; |
|
1328 | - |
|
1329 | - // Fetch again $limit shares |
|
1330 | - $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
1331 | - |
|
1332 | - // No more shares means we are done |
|
1333 | - if (empty($shares)) { |
|
1334 | - break; |
|
1335 | - } |
|
1336 | - } |
|
1337 | - |
|
1338 | - $shares = $shares2; |
|
1339 | - |
|
1340 | - return $shares; |
|
1341 | - } |
|
1342 | - |
|
1343 | - /** |
|
1344 | - * @inheritdoc |
|
1345 | - */ |
|
1346 | - public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { |
|
1347 | - try { |
|
1348 | - $provider = $this->factory->getProviderForType($shareType); |
|
1349 | - } catch (ProviderException $e) { |
|
1350 | - return []; |
|
1351 | - } |
|
1352 | - |
|
1353 | - $shares = $provider->getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
1354 | - |
|
1355 | - // remove all shares which are already expired |
|
1356 | - foreach ($shares as $key => $share) { |
|
1357 | - try { |
|
1358 | - $this->checkExpireDate($share); |
|
1359 | - } catch (ShareNotFound $e) { |
|
1360 | - unset($shares[$key]); |
|
1361 | - } |
|
1362 | - } |
|
1363 | - |
|
1364 | - return $shares; |
|
1365 | - } |
|
1366 | - |
|
1367 | - /** |
|
1368 | - * @inheritdoc |
|
1369 | - */ |
|
1370 | - public function getDeletedSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { |
|
1371 | - $shares = $this->getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
1372 | - |
|
1373 | - // Only get deleted shares |
|
1374 | - $shares = array_filter($shares, function (IShare $share) { |
|
1375 | - return $share->getPermissions() === 0; |
|
1376 | - }); |
|
1377 | - |
|
1378 | - // Only get shares where the owner still exists |
|
1379 | - $shares = array_filter($shares, function (IShare $share) { |
|
1380 | - return $this->userManager->userExists($share->getShareOwner()); |
|
1381 | - }); |
|
1382 | - |
|
1383 | - return $shares; |
|
1384 | - } |
|
1385 | - |
|
1386 | - /** |
|
1387 | - * @inheritdoc |
|
1388 | - */ |
|
1389 | - public function getShareById($id, $recipient = null) { |
|
1390 | - if ($id === null) { |
|
1391 | - throw new ShareNotFound(); |
|
1392 | - } |
|
1393 | - |
|
1394 | - [$providerId, $id] = $this->splitFullId($id); |
|
1395 | - |
|
1396 | - try { |
|
1397 | - $provider = $this->factory->getProvider($providerId); |
|
1398 | - } catch (ProviderException $e) { |
|
1399 | - throw new ShareNotFound(); |
|
1400 | - } |
|
1401 | - |
|
1402 | - $share = $provider->getShareById($id, $recipient); |
|
1403 | - |
|
1404 | - $this->checkExpireDate($share); |
|
1405 | - |
|
1406 | - return $share; |
|
1407 | - } |
|
1408 | - |
|
1409 | - /** |
|
1410 | - * Get all the shares for a given path |
|
1411 | - * |
|
1412 | - * @param \OCP\Files\Node $path |
|
1413 | - * @param int $page |
|
1414 | - * @param int $perPage |
|
1415 | - * |
|
1416 | - * @return Share[] |
|
1417 | - */ |
|
1418 | - public function getSharesByPath(\OCP\Files\Node $path, $page = 0, $perPage = 50) { |
|
1419 | - return []; |
|
1420 | - } |
|
1421 | - |
|
1422 | - /** |
|
1423 | - * Get the share by token possible with password |
|
1424 | - * |
|
1425 | - * @param string $token |
|
1426 | - * @return IShare |
|
1427 | - * |
|
1428 | - * @throws ShareNotFound |
|
1429 | - */ |
|
1430 | - public function getShareByToken($token) { |
|
1431 | - // tokens cannot be valid local user names |
|
1432 | - if ($this->userManager->userExists($token)) { |
|
1433 | - throw new ShareNotFound(); |
|
1434 | - } |
|
1435 | - $share = null; |
|
1436 | - try { |
|
1437 | - if ($this->shareApiAllowLinks()) { |
|
1438 | - $provider = $this->factory->getProviderForType(IShare::TYPE_LINK); |
|
1439 | - $share = $provider->getShareByToken($token); |
|
1440 | - } |
|
1441 | - } catch (ProviderException $e) { |
|
1442 | - } catch (ShareNotFound $e) { |
|
1443 | - } |
|
1444 | - |
|
1445 | - |
|
1446 | - // If it is not a link share try to fetch a federated share by token |
|
1447 | - if ($share === null) { |
|
1448 | - try { |
|
1449 | - $provider = $this->factory->getProviderForType(IShare::TYPE_REMOTE); |
|
1450 | - $share = $provider->getShareByToken($token); |
|
1451 | - } catch (ProviderException $e) { |
|
1452 | - } catch (ShareNotFound $e) { |
|
1453 | - } |
|
1454 | - } |
|
1455 | - |
|
1456 | - // If it is not a link share try to fetch a mail share by token |
|
1457 | - if ($share === null && $this->shareProviderExists(IShare::TYPE_EMAIL)) { |
|
1458 | - try { |
|
1459 | - $provider = $this->factory->getProviderForType(IShare::TYPE_EMAIL); |
|
1460 | - $share = $provider->getShareByToken($token); |
|
1461 | - } catch (ProviderException $e) { |
|
1462 | - } catch (ShareNotFound $e) { |
|
1463 | - } |
|
1464 | - } |
|
1465 | - |
|
1466 | - if ($share === null && $this->shareProviderExists(IShare::TYPE_CIRCLE)) { |
|
1467 | - try { |
|
1468 | - $provider = $this->factory->getProviderForType(IShare::TYPE_CIRCLE); |
|
1469 | - $share = $provider->getShareByToken($token); |
|
1470 | - } catch (ProviderException $e) { |
|
1471 | - } catch (ShareNotFound $e) { |
|
1472 | - } |
|
1473 | - } |
|
1474 | - |
|
1475 | - if ($share === null && $this->shareProviderExists(IShare::TYPE_ROOM)) { |
|
1476 | - try { |
|
1477 | - $provider = $this->factory->getProviderForType(IShare::TYPE_ROOM); |
|
1478 | - $share = $provider->getShareByToken($token); |
|
1479 | - } catch (ProviderException $e) { |
|
1480 | - } catch (ShareNotFound $e) { |
|
1481 | - } |
|
1482 | - } |
|
1483 | - |
|
1484 | - if ($share === null) { |
|
1485 | - throw new ShareNotFound($this->l->t('The requested share does not exist anymore')); |
|
1486 | - } |
|
1487 | - |
|
1488 | - $this->checkExpireDate($share); |
|
1489 | - |
|
1490 | - /* |
|
1293 | + $shares2 = []; |
|
1294 | + |
|
1295 | + while (true) { |
|
1296 | + $added = 0; |
|
1297 | + foreach ($shares as $share) { |
|
1298 | + try { |
|
1299 | + $this->checkExpireDate($share); |
|
1300 | + } catch (ShareNotFound $e) { |
|
1301 | + //Ignore since this basically means the share is deleted |
|
1302 | + continue; |
|
1303 | + } |
|
1304 | + |
|
1305 | + $added++; |
|
1306 | + $shares2[] = $share; |
|
1307 | + |
|
1308 | + if (count($shares2) === $limit) { |
|
1309 | + break; |
|
1310 | + } |
|
1311 | + } |
|
1312 | + |
|
1313 | + // If we did not fetch more shares than the limit then there are no more shares |
|
1314 | + if (count($shares) < $limit) { |
|
1315 | + break; |
|
1316 | + } |
|
1317 | + |
|
1318 | + if (count($shares2) === $limit) { |
|
1319 | + break; |
|
1320 | + } |
|
1321 | + |
|
1322 | + // If there was no limit on the select we are done |
|
1323 | + if ($limit === -1) { |
|
1324 | + break; |
|
1325 | + } |
|
1326 | + |
|
1327 | + $offset += $added; |
|
1328 | + |
|
1329 | + // Fetch again $limit shares |
|
1330 | + $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
1331 | + |
|
1332 | + // No more shares means we are done |
|
1333 | + if (empty($shares)) { |
|
1334 | + break; |
|
1335 | + } |
|
1336 | + } |
|
1337 | + |
|
1338 | + $shares = $shares2; |
|
1339 | + |
|
1340 | + return $shares; |
|
1341 | + } |
|
1342 | + |
|
1343 | + /** |
|
1344 | + * @inheritdoc |
|
1345 | + */ |
|
1346 | + public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { |
|
1347 | + try { |
|
1348 | + $provider = $this->factory->getProviderForType($shareType); |
|
1349 | + } catch (ProviderException $e) { |
|
1350 | + return []; |
|
1351 | + } |
|
1352 | + |
|
1353 | + $shares = $provider->getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
1354 | + |
|
1355 | + // remove all shares which are already expired |
|
1356 | + foreach ($shares as $key => $share) { |
|
1357 | + try { |
|
1358 | + $this->checkExpireDate($share); |
|
1359 | + } catch (ShareNotFound $e) { |
|
1360 | + unset($shares[$key]); |
|
1361 | + } |
|
1362 | + } |
|
1363 | + |
|
1364 | + return $shares; |
|
1365 | + } |
|
1366 | + |
|
1367 | + /** |
|
1368 | + * @inheritdoc |
|
1369 | + */ |
|
1370 | + public function getDeletedSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { |
|
1371 | + $shares = $this->getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
1372 | + |
|
1373 | + // Only get deleted shares |
|
1374 | + $shares = array_filter($shares, function (IShare $share) { |
|
1375 | + return $share->getPermissions() === 0; |
|
1376 | + }); |
|
1377 | + |
|
1378 | + // Only get shares where the owner still exists |
|
1379 | + $shares = array_filter($shares, function (IShare $share) { |
|
1380 | + return $this->userManager->userExists($share->getShareOwner()); |
|
1381 | + }); |
|
1382 | + |
|
1383 | + return $shares; |
|
1384 | + } |
|
1385 | + |
|
1386 | + /** |
|
1387 | + * @inheritdoc |
|
1388 | + */ |
|
1389 | + public function getShareById($id, $recipient = null) { |
|
1390 | + if ($id === null) { |
|
1391 | + throw new ShareNotFound(); |
|
1392 | + } |
|
1393 | + |
|
1394 | + [$providerId, $id] = $this->splitFullId($id); |
|
1395 | + |
|
1396 | + try { |
|
1397 | + $provider = $this->factory->getProvider($providerId); |
|
1398 | + } catch (ProviderException $e) { |
|
1399 | + throw new ShareNotFound(); |
|
1400 | + } |
|
1401 | + |
|
1402 | + $share = $provider->getShareById($id, $recipient); |
|
1403 | + |
|
1404 | + $this->checkExpireDate($share); |
|
1405 | + |
|
1406 | + return $share; |
|
1407 | + } |
|
1408 | + |
|
1409 | + /** |
|
1410 | + * Get all the shares for a given path |
|
1411 | + * |
|
1412 | + * @param \OCP\Files\Node $path |
|
1413 | + * @param int $page |
|
1414 | + * @param int $perPage |
|
1415 | + * |
|
1416 | + * @return Share[] |
|
1417 | + */ |
|
1418 | + public function getSharesByPath(\OCP\Files\Node $path, $page = 0, $perPage = 50) { |
|
1419 | + return []; |
|
1420 | + } |
|
1421 | + |
|
1422 | + /** |
|
1423 | + * Get the share by token possible with password |
|
1424 | + * |
|
1425 | + * @param string $token |
|
1426 | + * @return IShare |
|
1427 | + * |
|
1428 | + * @throws ShareNotFound |
|
1429 | + */ |
|
1430 | + public function getShareByToken($token) { |
|
1431 | + // tokens cannot be valid local user names |
|
1432 | + if ($this->userManager->userExists($token)) { |
|
1433 | + throw new ShareNotFound(); |
|
1434 | + } |
|
1435 | + $share = null; |
|
1436 | + try { |
|
1437 | + if ($this->shareApiAllowLinks()) { |
|
1438 | + $provider = $this->factory->getProviderForType(IShare::TYPE_LINK); |
|
1439 | + $share = $provider->getShareByToken($token); |
|
1440 | + } |
|
1441 | + } catch (ProviderException $e) { |
|
1442 | + } catch (ShareNotFound $e) { |
|
1443 | + } |
|
1444 | + |
|
1445 | + |
|
1446 | + // If it is not a link share try to fetch a federated share by token |
|
1447 | + if ($share === null) { |
|
1448 | + try { |
|
1449 | + $provider = $this->factory->getProviderForType(IShare::TYPE_REMOTE); |
|
1450 | + $share = $provider->getShareByToken($token); |
|
1451 | + } catch (ProviderException $e) { |
|
1452 | + } catch (ShareNotFound $e) { |
|
1453 | + } |
|
1454 | + } |
|
1455 | + |
|
1456 | + // If it is not a link share try to fetch a mail share by token |
|
1457 | + if ($share === null && $this->shareProviderExists(IShare::TYPE_EMAIL)) { |
|
1458 | + try { |
|
1459 | + $provider = $this->factory->getProviderForType(IShare::TYPE_EMAIL); |
|
1460 | + $share = $provider->getShareByToken($token); |
|
1461 | + } catch (ProviderException $e) { |
|
1462 | + } catch (ShareNotFound $e) { |
|
1463 | + } |
|
1464 | + } |
|
1465 | + |
|
1466 | + if ($share === null && $this->shareProviderExists(IShare::TYPE_CIRCLE)) { |
|
1467 | + try { |
|
1468 | + $provider = $this->factory->getProviderForType(IShare::TYPE_CIRCLE); |
|
1469 | + $share = $provider->getShareByToken($token); |
|
1470 | + } catch (ProviderException $e) { |
|
1471 | + } catch (ShareNotFound $e) { |
|
1472 | + } |
|
1473 | + } |
|
1474 | + |
|
1475 | + if ($share === null && $this->shareProviderExists(IShare::TYPE_ROOM)) { |
|
1476 | + try { |
|
1477 | + $provider = $this->factory->getProviderForType(IShare::TYPE_ROOM); |
|
1478 | + $share = $provider->getShareByToken($token); |
|
1479 | + } catch (ProviderException $e) { |
|
1480 | + } catch (ShareNotFound $e) { |
|
1481 | + } |
|
1482 | + } |
|
1483 | + |
|
1484 | + if ($share === null) { |
|
1485 | + throw new ShareNotFound($this->l->t('The requested share does not exist anymore')); |
|
1486 | + } |
|
1487 | + |
|
1488 | + $this->checkExpireDate($share); |
|
1489 | + |
|
1490 | + /* |
|
1491 | 1491 | * Reduce the permissions for link or email shares if public upload is not enabled |
1492 | 1492 | */ |
1493 | - if (($share->getShareType() === IShare::TYPE_LINK || $share->getShareType() === IShare::TYPE_EMAIL) |
|
1494 | - && !$this->shareApiLinkAllowPublicUpload()) { |
|
1495 | - $share->setPermissions($share->getPermissions() & ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE)); |
|
1496 | - } |
|
1497 | - |
|
1498 | - return $share; |
|
1499 | - } |
|
1500 | - |
|
1501 | - protected function checkExpireDate($share) { |
|
1502 | - if ($share->isExpired()) { |
|
1503 | - $this->deleteShare($share); |
|
1504 | - throw new ShareNotFound($this->l->t('The requested share does not exist anymore')); |
|
1505 | - } |
|
1506 | - } |
|
1507 | - |
|
1508 | - /** |
|
1509 | - * Verify the password of a public share |
|
1510 | - * |
|
1511 | - * @param IShare $share |
|
1512 | - * @param string $password |
|
1513 | - * @return bool |
|
1514 | - */ |
|
1515 | - public function checkPassword(IShare $share, $password) { |
|
1516 | - $passwordProtected = $share->getShareType() !== IShare::TYPE_LINK |
|
1517 | - || $share->getShareType() !== IShare::TYPE_EMAIL |
|
1518 | - || $share->getShareType() !== IShare::TYPE_CIRCLE; |
|
1519 | - if (!$passwordProtected) { |
|
1520 | - //TODO maybe exception? |
|
1521 | - return false; |
|
1522 | - } |
|
1523 | - |
|
1524 | - if ($password === null || $share->getPassword() === null) { |
|
1525 | - return false; |
|
1526 | - } |
|
1527 | - |
|
1528 | - $newHash = ''; |
|
1529 | - if (!$this->hasher->verify($password, $share->getPassword(), $newHash)) { |
|
1530 | - return false; |
|
1531 | - } |
|
1532 | - |
|
1533 | - if (!empty($newHash)) { |
|
1534 | - $share->setPassword($newHash); |
|
1535 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
1536 | - $provider->update($share); |
|
1537 | - } |
|
1538 | - |
|
1539 | - return true; |
|
1540 | - } |
|
1541 | - |
|
1542 | - /** |
|
1543 | - * @inheritdoc |
|
1544 | - */ |
|
1545 | - public function userDeleted($uid) { |
|
1546 | - $types = [IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_LINK, IShare::TYPE_REMOTE, IShare::TYPE_EMAIL]; |
|
1547 | - |
|
1548 | - foreach ($types as $type) { |
|
1549 | - try { |
|
1550 | - $provider = $this->factory->getProviderForType($type); |
|
1551 | - } catch (ProviderException $e) { |
|
1552 | - continue; |
|
1553 | - } |
|
1554 | - $provider->userDeleted($uid, $type); |
|
1555 | - } |
|
1556 | - } |
|
1557 | - |
|
1558 | - /** |
|
1559 | - * @inheritdoc |
|
1560 | - */ |
|
1561 | - public function groupDeleted($gid) { |
|
1562 | - $provider = $this->factory->getProviderForType(IShare::TYPE_GROUP); |
|
1563 | - $provider->groupDeleted($gid); |
|
1564 | - |
|
1565 | - $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
1566 | - if ($excludedGroups === '') { |
|
1567 | - return; |
|
1568 | - } |
|
1569 | - |
|
1570 | - $excludedGroups = json_decode($excludedGroups, true); |
|
1571 | - if (json_last_error() !== JSON_ERROR_NONE) { |
|
1572 | - return; |
|
1573 | - } |
|
1574 | - |
|
1575 | - $excludedGroups = array_diff($excludedGroups, [$gid]); |
|
1576 | - $this->config->setAppValue('core', 'shareapi_exclude_groups_list', json_encode($excludedGroups)); |
|
1577 | - } |
|
1578 | - |
|
1579 | - /** |
|
1580 | - * @inheritdoc |
|
1581 | - */ |
|
1582 | - public function userDeletedFromGroup($uid, $gid) { |
|
1583 | - $provider = $this->factory->getProviderForType(IShare::TYPE_GROUP); |
|
1584 | - $provider->userDeletedFromGroup($uid, $gid); |
|
1585 | - } |
|
1586 | - |
|
1587 | - /** |
|
1588 | - * Get access list to a path. This means |
|
1589 | - * all the users that can access a given path. |
|
1590 | - * |
|
1591 | - * Consider: |
|
1592 | - * -root |
|
1593 | - * |-folder1 (23) |
|
1594 | - * |-folder2 (32) |
|
1595 | - * |-fileA (42) |
|
1596 | - * |
|
1597 | - * fileA is shared with user1 and user1@server1 |
|
1598 | - * folder2 is shared with group2 (user4 is a member of group2) |
|
1599 | - * folder1 is shared with user2 (renamed to "folder (1)") and user2@server2 |
|
1600 | - * |
|
1601 | - * Then the access list to '/folder1/folder2/fileA' with $currentAccess is: |
|
1602 | - * [ |
|
1603 | - * users => [ |
|
1604 | - * 'user1' => ['node_id' => 42, 'node_path' => '/fileA'], |
|
1605 | - * 'user4' => ['node_id' => 32, 'node_path' => '/folder2'], |
|
1606 | - * 'user2' => ['node_id' => 23, 'node_path' => '/folder (1)'], |
|
1607 | - * ], |
|
1608 | - * remote => [ |
|
1609 | - * 'user1@server1' => ['node_id' => 42, 'token' => 'SeCr3t'], |
|
1610 | - * 'user2@server2' => ['node_id' => 23, 'token' => 'FooBaR'], |
|
1611 | - * ], |
|
1612 | - * public => bool |
|
1613 | - * mail => bool |
|
1614 | - * ] |
|
1615 | - * |
|
1616 | - * The access list to '/folder1/folder2/fileA' **without** $currentAccess is: |
|
1617 | - * [ |
|
1618 | - * users => ['user1', 'user2', 'user4'], |
|
1619 | - * remote => bool, |
|
1620 | - * public => bool |
|
1621 | - * mail => bool |
|
1622 | - * ] |
|
1623 | - * |
|
1624 | - * This is required for encryption/activity |
|
1625 | - * |
|
1626 | - * @param \OCP\Files\Node $path |
|
1627 | - * @param bool $recursive Should we check all parent folders as well |
|
1628 | - * @param bool $currentAccess Ensure the recipient has access to the file (e.g. did not unshare it) |
|
1629 | - * @return array |
|
1630 | - */ |
|
1631 | - public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false) { |
|
1632 | - $owner = $path->getOwner(); |
|
1633 | - |
|
1634 | - if ($owner === null) { |
|
1635 | - return []; |
|
1636 | - } |
|
1637 | - |
|
1638 | - $owner = $owner->getUID(); |
|
1639 | - |
|
1640 | - if ($currentAccess) { |
|
1641 | - $al = ['users' => [], 'remote' => [], 'public' => false]; |
|
1642 | - } else { |
|
1643 | - $al = ['users' => [], 'remote' => false, 'public' => false]; |
|
1644 | - } |
|
1645 | - if (!$this->userManager->userExists($owner)) { |
|
1646 | - return $al; |
|
1647 | - } |
|
1648 | - |
|
1649 | - //Get node for the owner and correct the owner in case of external storage |
|
1650 | - $userFolder = $this->rootFolder->getUserFolder($owner); |
|
1651 | - if ($path->getId() !== $userFolder->getId() && !$userFolder->isSubNode($path)) { |
|
1652 | - $nodes = $userFolder->getById($path->getId()); |
|
1653 | - $path = array_shift($nodes); |
|
1654 | - if ($path->getOwner() === null) { |
|
1655 | - return []; |
|
1656 | - } |
|
1657 | - $owner = $path->getOwner()->getUID(); |
|
1658 | - } |
|
1659 | - |
|
1660 | - $providers = $this->factory->getAllProviders(); |
|
1661 | - |
|
1662 | - /** @var Node[] $nodes */ |
|
1663 | - $nodes = []; |
|
1664 | - |
|
1665 | - |
|
1666 | - if ($currentAccess) { |
|
1667 | - $ownerPath = $path->getPath(); |
|
1668 | - $ownerPath = explode('/', $ownerPath, 4); |
|
1669 | - if (count($ownerPath) < 4) { |
|
1670 | - $ownerPath = ''; |
|
1671 | - } else { |
|
1672 | - $ownerPath = $ownerPath[3]; |
|
1673 | - } |
|
1674 | - $al['users'][$owner] = [ |
|
1675 | - 'node_id' => $path->getId(), |
|
1676 | - 'node_path' => '/' . $ownerPath, |
|
1677 | - ]; |
|
1678 | - } else { |
|
1679 | - $al['users'][] = $owner; |
|
1680 | - } |
|
1681 | - |
|
1682 | - // Collect all the shares |
|
1683 | - while ($path->getPath() !== $userFolder->getPath()) { |
|
1684 | - $nodes[] = $path; |
|
1685 | - if (!$recursive) { |
|
1686 | - break; |
|
1687 | - } |
|
1688 | - $path = $path->getParent(); |
|
1689 | - } |
|
1690 | - |
|
1691 | - foreach ($providers as $provider) { |
|
1692 | - $tmp = $provider->getAccessList($nodes, $currentAccess); |
|
1693 | - |
|
1694 | - foreach ($tmp as $k => $v) { |
|
1695 | - if (isset($al[$k])) { |
|
1696 | - if (is_array($al[$k])) { |
|
1697 | - if ($currentAccess) { |
|
1698 | - $al[$k] += $v; |
|
1699 | - } else { |
|
1700 | - $al[$k] = array_merge($al[$k], $v); |
|
1701 | - $al[$k] = array_unique($al[$k]); |
|
1702 | - $al[$k] = array_values($al[$k]); |
|
1703 | - } |
|
1704 | - } else { |
|
1705 | - $al[$k] = $al[$k] || $v; |
|
1706 | - } |
|
1707 | - } else { |
|
1708 | - $al[$k] = $v; |
|
1709 | - } |
|
1710 | - } |
|
1711 | - } |
|
1712 | - |
|
1713 | - return $al; |
|
1714 | - } |
|
1715 | - |
|
1716 | - /** |
|
1717 | - * Create a new share |
|
1718 | - * |
|
1719 | - * @return IShare |
|
1720 | - */ |
|
1721 | - public function newShare() { |
|
1722 | - return new \OC\Share20\Share($this->rootFolder, $this->userManager); |
|
1723 | - } |
|
1724 | - |
|
1725 | - /** |
|
1726 | - * Is the share API enabled |
|
1727 | - * |
|
1728 | - * @return bool |
|
1729 | - */ |
|
1730 | - public function shareApiEnabled() { |
|
1731 | - return $this->config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes'; |
|
1732 | - } |
|
1733 | - |
|
1734 | - /** |
|
1735 | - * Is public link sharing enabled |
|
1736 | - * |
|
1737 | - * @return bool |
|
1738 | - */ |
|
1739 | - public function shareApiAllowLinks() { |
|
1740 | - if ($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') !== 'yes') { |
|
1741 | - return false; |
|
1742 | - } |
|
1743 | - |
|
1744 | - $user = $this->userSession->getUser(); |
|
1745 | - if ($user) { |
|
1746 | - $excludedGroups = json_decode($this->config->getAppValue('core', 'shareapi_allow_links_exclude_groups', '[]')); |
|
1747 | - if ($excludedGroups) { |
|
1748 | - $userGroups = $this->groupManager->getUserGroupIds($user); |
|
1749 | - return !(bool)array_intersect($excludedGroups, $userGroups); |
|
1750 | - } |
|
1751 | - } |
|
1752 | - |
|
1753 | - return true; |
|
1754 | - } |
|
1755 | - |
|
1756 | - /** |
|
1757 | - * Is password on public link requires |
|
1758 | - * |
|
1759 | - * @return bool |
|
1760 | - */ |
|
1761 | - public function shareApiLinkEnforcePassword() { |
|
1762 | - return $this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes'; |
|
1763 | - } |
|
1764 | - |
|
1765 | - /** |
|
1766 | - * Is default link expire date enabled |
|
1767 | - * |
|
1768 | - * @return bool |
|
1769 | - */ |
|
1770 | - public function shareApiLinkDefaultExpireDate() { |
|
1771 | - return $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
1772 | - } |
|
1773 | - |
|
1774 | - /** |
|
1775 | - * Is default link expire date enforced |
|
1776 | - *` |
|
1777 | - * |
|
1778 | - * @return bool |
|
1779 | - */ |
|
1780 | - public function shareApiLinkDefaultExpireDateEnforced() { |
|
1781 | - return $this->shareApiLinkDefaultExpireDate() && |
|
1782 | - $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
1783 | - } |
|
1784 | - |
|
1785 | - |
|
1786 | - /** |
|
1787 | - * Number of default link expire days |
|
1788 | - * |
|
1789 | - * @return int |
|
1790 | - */ |
|
1791 | - public function shareApiLinkDefaultExpireDays() { |
|
1792 | - return (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
1793 | - } |
|
1794 | - |
|
1795 | - /** |
|
1796 | - * Is default internal expire date enabled |
|
1797 | - * |
|
1798 | - * @return bool |
|
1799 | - */ |
|
1800 | - public function shareApiInternalDefaultExpireDate(): bool { |
|
1801 | - return $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no') === 'yes'; |
|
1802 | - } |
|
1803 | - |
|
1804 | - /** |
|
1805 | - * Is default remote expire date enabled |
|
1806 | - * |
|
1807 | - * @return bool |
|
1808 | - */ |
|
1809 | - public function shareApiRemoteDefaultExpireDate(): bool { |
|
1810 | - return $this->config->getAppValue('core', 'shareapi_default_remote_expire_date', 'no') === 'yes'; |
|
1811 | - } |
|
1812 | - |
|
1813 | - /** |
|
1814 | - * Is default expire date enforced |
|
1815 | - * |
|
1816 | - * @return bool |
|
1817 | - */ |
|
1818 | - public function shareApiInternalDefaultExpireDateEnforced(): bool { |
|
1819 | - return $this->shareApiInternalDefaultExpireDate() && |
|
1820 | - $this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no') === 'yes'; |
|
1821 | - } |
|
1822 | - |
|
1823 | - /** |
|
1824 | - * Is default expire date enforced for remote shares |
|
1825 | - * |
|
1826 | - * @return bool |
|
1827 | - */ |
|
1828 | - public function shareApiRemoteDefaultExpireDateEnforced(): bool { |
|
1829 | - return $this->shareApiRemoteDefaultExpireDate() && |
|
1830 | - $this->config->getAppValue('core', 'shareapi_enforce_remote_expire_date', 'no') === 'yes'; |
|
1831 | - } |
|
1832 | - |
|
1833 | - /** |
|
1834 | - * Number of default expire days |
|
1835 | - * |
|
1836 | - * @return int |
|
1837 | - */ |
|
1838 | - public function shareApiInternalDefaultExpireDays(): int { |
|
1839 | - return (int)$this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'); |
|
1840 | - } |
|
1841 | - |
|
1842 | - /** |
|
1843 | - * Number of default expire days for remote shares |
|
1844 | - * |
|
1845 | - * @return int |
|
1846 | - */ |
|
1847 | - public function shareApiRemoteDefaultExpireDays(): int { |
|
1848 | - return (int)$this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7'); |
|
1849 | - } |
|
1850 | - |
|
1851 | - /** |
|
1852 | - * Allow public upload on link shares |
|
1853 | - * |
|
1854 | - * @return bool |
|
1855 | - */ |
|
1856 | - public function shareApiLinkAllowPublicUpload() { |
|
1857 | - return $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes'; |
|
1858 | - } |
|
1859 | - |
|
1860 | - /** |
|
1861 | - * check if user can only share with group members |
|
1862 | - * |
|
1863 | - * @return bool |
|
1864 | - */ |
|
1865 | - public function shareWithGroupMembersOnly() { |
|
1866 | - return $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
1867 | - } |
|
1868 | - |
|
1869 | - /** |
|
1870 | - * Check if users can share with groups |
|
1871 | - * |
|
1872 | - * @return bool |
|
1873 | - */ |
|
1874 | - public function allowGroupSharing() { |
|
1875 | - return $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
|
1876 | - } |
|
1877 | - |
|
1878 | - public function allowEnumeration(): bool { |
|
1879 | - return $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
1880 | - } |
|
1881 | - |
|
1882 | - public function limitEnumerationToGroups(): bool { |
|
1883 | - return $this->allowEnumeration() && |
|
1884 | - $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes'; |
|
1885 | - } |
|
1886 | - |
|
1887 | - public function limitEnumerationToPhone(): bool { |
|
1888 | - return $this->allowEnumeration() && |
|
1889 | - $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes'; |
|
1890 | - } |
|
1891 | - |
|
1892 | - public function allowEnumerationFullMatch(): bool { |
|
1893 | - return $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes'; |
|
1894 | - } |
|
1895 | - |
|
1896 | - /** |
|
1897 | - * Copied from \OC_Util::isSharingDisabledForUser |
|
1898 | - * |
|
1899 | - * TODO: Deprecate fuction from OC_Util |
|
1900 | - * |
|
1901 | - * @param string $userId |
|
1902 | - * @return bool |
|
1903 | - */ |
|
1904 | - public function sharingDisabledForUser($userId) { |
|
1905 | - if ($userId === null) { |
|
1906 | - return false; |
|
1907 | - } |
|
1908 | - |
|
1909 | - if (isset($this->sharingDisabledForUsersCache[$userId])) { |
|
1910 | - return $this->sharingDisabledForUsersCache[$userId]; |
|
1911 | - } |
|
1912 | - |
|
1913 | - if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
1914 | - $groupsList = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
1915 | - $excludedGroups = json_decode($groupsList); |
|
1916 | - if (is_null($excludedGroups)) { |
|
1917 | - $excludedGroups = explode(',', $groupsList); |
|
1918 | - $newValue = json_encode($excludedGroups); |
|
1919 | - $this->config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
1920 | - } |
|
1921 | - $user = $this->userManager->get($userId); |
|
1922 | - $usersGroups = $this->groupManager->getUserGroupIds($user); |
|
1923 | - if (!empty($usersGroups)) { |
|
1924 | - $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
1925 | - // if the user is only in groups which are disabled for sharing then |
|
1926 | - // sharing is also disabled for the user |
|
1927 | - if (empty($remainingGroups)) { |
|
1928 | - $this->sharingDisabledForUsersCache[$userId] = true; |
|
1929 | - return true; |
|
1930 | - } |
|
1931 | - } |
|
1932 | - } |
|
1933 | - |
|
1934 | - $this->sharingDisabledForUsersCache[$userId] = false; |
|
1935 | - return false; |
|
1936 | - } |
|
1937 | - |
|
1938 | - /** |
|
1939 | - * @inheritdoc |
|
1940 | - */ |
|
1941 | - public function outgoingServer2ServerSharesAllowed() { |
|
1942 | - return $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
|
1943 | - } |
|
1944 | - |
|
1945 | - /** |
|
1946 | - * @inheritdoc |
|
1947 | - */ |
|
1948 | - public function outgoingServer2ServerGroupSharesAllowed() { |
|
1949 | - return $this->config->getAppValue('files_sharing', 'outgoing_server2server_group_share_enabled', 'no') === 'yes'; |
|
1950 | - } |
|
1951 | - |
|
1952 | - /** |
|
1953 | - * @inheritdoc |
|
1954 | - */ |
|
1955 | - public function shareProviderExists($shareType) { |
|
1956 | - try { |
|
1957 | - $this->factory->getProviderForType($shareType); |
|
1958 | - } catch (ProviderException $e) { |
|
1959 | - return false; |
|
1960 | - } |
|
1961 | - |
|
1962 | - return true; |
|
1963 | - } |
|
1964 | - |
|
1965 | - public function registerShareProvider(string $shareProviderClass): void { |
|
1966 | - $this->factory->registerProvider($shareProviderClass); |
|
1967 | - } |
|
1968 | - |
|
1969 | - public function getAllShares(): iterable { |
|
1970 | - $providers = $this->factory->getAllProviders(); |
|
1971 | - |
|
1972 | - foreach ($providers as $provider) { |
|
1973 | - yield from $provider->getAllShares(); |
|
1974 | - } |
|
1975 | - } |
|
1493 | + if (($share->getShareType() === IShare::TYPE_LINK || $share->getShareType() === IShare::TYPE_EMAIL) |
|
1494 | + && !$this->shareApiLinkAllowPublicUpload()) { |
|
1495 | + $share->setPermissions($share->getPermissions() & ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE)); |
|
1496 | + } |
|
1497 | + |
|
1498 | + return $share; |
|
1499 | + } |
|
1500 | + |
|
1501 | + protected function checkExpireDate($share) { |
|
1502 | + if ($share->isExpired()) { |
|
1503 | + $this->deleteShare($share); |
|
1504 | + throw new ShareNotFound($this->l->t('The requested share does not exist anymore')); |
|
1505 | + } |
|
1506 | + } |
|
1507 | + |
|
1508 | + /** |
|
1509 | + * Verify the password of a public share |
|
1510 | + * |
|
1511 | + * @param IShare $share |
|
1512 | + * @param string $password |
|
1513 | + * @return bool |
|
1514 | + */ |
|
1515 | + public function checkPassword(IShare $share, $password) { |
|
1516 | + $passwordProtected = $share->getShareType() !== IShare::TYPE_LINK |
|
1517 | + || $share->getShareType() !== IShare::TYPE_EMAIL |
|
1518 | + || $share->getShareType() !== IShare::TYPE_CIRCLE; |
|
1519 | + if (!$passwordProtected) { |
|
1520 | + //TODO maybe exception? |
|
1521 | + return false; |
|
1522 | + } |
|
1523 | + |
|
1524 | + if ($password === null || $share->getPassword() === null) { |
|
1525 | + return false; |
|
1526 | + } |
|
1527 | + |
|
1528 | + $newHash = ''; |
|
1529 | + if (!$this->hasher->verify($password, $share->getPassword(), $newHash)) { |
|
1530 | + return false; |
|
1531 | + } |
|
1532 | + |
|
1533 | + if (!empty($newHash)) { |
|
1534 | + $share->setPassword($newHash); |
|
1535 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
1536 | + $provider->update($share); |
|
1537 | + } |
|
1538 | + |
|
1539 | + return true; |
|
1540 | + } |
|
1541 | + |
|
1542 | + /** |
|
1543 | + * @inheritdoc |
|
1544 | + */ |
|
1545 | + public function userDeleted($uid) { |
|
1546 | + $types = [IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_LINK, IShare::TYPE_REMOTE, IShare::TYPE_EMAIL]; |
|
1547 | + |
|
1548 | + foreach ($types as $type) { |
|
1549 | + try { |
|
1550 | + $provider = $this->factory->getProviderForType($type); |
|
1551 | + } catch (ProviderException $e) { |
|
1552 | + continue; |
|
1553 | + } |
|
1554 | + $provider->userDeleted($uid, $type); |
|
1555 | + } |
|
1556 | + } |
|
1557 | + |
|
1558 | + /** |
|
1559 | + * @inheritdoc |
|
1560 | + */ |
|
1561 | + public function groupDeleted($gid) { |
|
1562 | + $provider = $this->factory->getProviderForType(IShare::TYPE_GROUP); |
|
1563 | + $provider->groupDeleted($gid); |
|
1564 | + |
|
1565 | + $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
1566 | + if ($excludedGroups === '') { |
|
1567 | + return; |
|
1568 | + } |
|
1569 | + |
|
1570 | + $excludedGroups = json_decode($excludedGroups, true); |
|
1571 | + if (json_last_error() !== JSON_ERROR_NONE) { |
|
1572 | + return; |
|
1573 | + } |
|
1574 | + |
|
1575 | + $excludedGroups = array_diff($excludedGroups, [$gid]); |
|
1576 | + $this->config->setAppValue('core', 'shareapi_exclude_groups_list', json_encode($excludedGroups)); |
|
1577 | + } |
|
1578 | + |
|
1579 | + /** |
|
1580 | + * @inheritdoc |
|
1581 | + */ |
|
1582 | + public function userDeletedFromGroup($uid, $gid) { |
|
1583 | + $provider = $this->factory->getProviderForType(IShare::TYPE_GROUP); |
|
1584 | + $provider->userDeletedFromGroup($uid, $gid); |
|
1585 | + } |
|
1586 | + |
|
1587 | + /** |
|
1588 | + * Get access list to a path. This means |
|
1589 | + * all the users that can access a given path. |
|
1590 | + * |
|
1591 | + * Consider: |
|
1592 | + * -root |
|
1593 | + * |-folder1 (23) |
|
1594 | + * |-folder2 (32) |
|
1595 | + * |-fileA (42) |
|
1596 | + * |
|
1597 | + * fileA is shared with user1 and user1@server1 |
|
1598 | + * folder2 is shared with group2 (user4 is a member of group2) |
|
1599 | + * folder1 is shared with user2 (renamed to "folder (1)") and user2@server2 |
|
1600 | + * |
|
1601 | + * Then the access list to '/folder1/folder2/fileA' with $currentAccess is: |
|
1602 | + * [ |
|
1603 | + * users => [ |
|
1604 | + * 'user1' => ['node_id' => 42, 'node_path' => '/fileA'], |
|
1605 | + * 'user4' => ['node_id' => 32, 'node_path' => '/folder2'], |
|
1606 | + * 'user2' => ['node_id' => 23, 'node_path' => '/folder (1)'], |
|
1607 | + * ], |
|
1608 | + * remote => [ |
|
1609 | + * 'user1@server1' => ['node_id' => 42, 'token' => 'SeCr3t'], |
|
1610 | + * 'user2@server2' => ['node_id' => 23, 'token' => 'FooBaR'], |
|
1611 | + * ], |
|
1612 | + * public => bool |
|
1613 | + * mail => bool |
|
1614 | + * ] |
|
1615 | + * |
|
1616 | + * The access list to '/folder1/folder2/fileA' **without** $currentAccess is: |
|
1617 | + * [ |
|
1618 | + * users => ['user1', 'user2', 'user4'], |
|
1619 | + * remote => bool, |
|
1620 | + * public => bool |
|
1621 | + * mail => bool |
|
1622 | + * ] |
|
1623 | + * |
|
1624 | + * This is required for encryption/activity |
|
1625 | + * |
|
1626 | + * @param \OCP\Files\Node $path |
|
1627 | + * @param bool $recursive Should we check all parent folders as well |
|
1628 | + * @param bool $currentAccess Ensure the recipient has access to the file (e.g. did not unshare it) |
|
1629 | + * @return array |
|
1630 | + */ |
|
1631 | + public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false) { |
|
1632 | + $owner = $path->getOwner(); |
|
1633 | + |
|
1634 | + if ($owner === null) { |
|
1635 | + return []; |
|
1636 | + } |
|
1637 | + |
|
1638 | + $owner = $owner->getUID(); |
|
1639 | + |
|
1640 | + if ($currentAccess) { |
|
1641 | + $al = ['users' => [], 'remote' => [], 'public' => false]; |
|
1642 | + } else { |
|
1643 | + $al = ['users' => [], 'remote' => false, 'public' => false]; |
|
1644 | + } |
|
1645 | + if (!$this->userManager->userExists($owner)) { |
|
1646 | + return $al; |
|
1647 | + } |
|
1648 | + |
|
1649 | + //Get node for the owner and correct the owner in case of external storage |
|
1650 | + $userFolder = $this->rootFolder->getUserFolder($owner); |
|
1651 | + if ($path->getId() !== $userFolder->getId() && !$userFolder->isSubNode($path)) { |
|
1652 | + $nodes = $userFolder->getById($path->getId()); |
|
1653 | + $path = array_shift($nodes); |
|
1654 | + if ($path->getOwner() === null) { |
|
1655 | + return []; |
|
1656 | + } |
|
1657 | + $owner = $path->getOwner()->getUID(); |
|
1658 | + } |
|
1659 | + |
|
1660 | + $providers = $this->factory->getAllProviders(); |
|
1661 | + |
|
1662 | + /** @var Node[] $nodes */ |
|
1663 | + $nodes = []; |
|
1664 | + |
|
1665 | + |
|
1666 | + if ($currentAccess) { |
|
1667 | + $ownerPath = $path->getPath(); |
|
1668 | + $ownerPath = explode('/', $ownerPath, 4); |
|
1669 | + if (count($ownerPath) < 4) { |
|
1670 | + $ownerPath = ''; |
|
1671 | + } else { |
|
1672 | + $ownerPath = $ownerPath[3]; |
|
1673 | + } |
|
1674 | + $al['users'][$owner] = [ |
|
1675 | + 'node_id' => $path->getId(), |
|
1676 | + 'node_path' => '/' . $ownerPath, |
|
1677 | + ]; |
|
1678 | + } else { |
|
1679 | + $al['users'][] = $owner; |
|
1680 | + } |
|
1681 | + |
|
1682 | + // Collect all the shares |
|
1683 | + while ($path->getPath() !== $userFolder->getPath()) { |
|
1684 | + $nodes[] = $path; |
|
1685 | + if (!$recursive) { |
|
1686 | + break; |
|
1687 | + } |
|
1688 | + $path = $path->getParent(); |
|
1689 | + } |
|
1690 | + |
|
1691 | + foreach ($providers as $provider) { |
|
1692 | + $tmp = $provider->getAccessList($nodes, $currentAccess); |
|
1693 | + |
|
1694 | + foreach ($tmp as $k => $v) { |
|
1695 | + if (isset($al[$k])) { |
|
1696 | + if (is_array($al[$k])) { |
|
1697 | + if ($currentAccess) { |
|
1698 | + $al[$k] += $v; |
|
1699 | + } else { |
|
1700 | + $al[$k] = array_merge($al[$k], $v); |
|
1701 | + $al[$k] = array_unique($al[$k]); |
|
1702 | + $al[$k] = array_values($al[$k]); |
|
1703 | + } |
|
1704 | + } else { |
|
1705 | + $al[$k] = $al[$k] || $v; |
|
1706 | + } |
|
1707 | + } else { |
|
1708 | + $al[$k] = $v; |
|
1709 | + } |
|
1710 | + } |
|
1711 | + } |
|
1712 | + |
|
1713 | + return $al; |
|
1714 | + } |
|
1715 | + |
|
1716 | + /** |
|
1717 | + * Create a new share |
|
1718 | + * |
|
1719 | + * @return IShare |
|
1720 | + */ |
|
1721 | + public function newShare() { |
|
1722 | + return new \OC\Share20\Share($this->rootFolder, $this->userManager); |
|
1723 | + } |
|
1724 | + |
|
1725 | + /** |
|
1726 | + * Is the share API enabled |
|
1727 | + * |
|
1728 | + * @return bool |
|
1729 | + */ |
|
1730 | + public function shareApiEnabled() { |
|
1731 | + return $this->config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes'; |
|
1732 | + } |
|
1733 | + |
|
1734 | + /** |
|
1735 | + * Is public link sharing enabled |
|
1736 | + * |
|
1737 | + * @return bool |
|
1738 | + */ |
|
1739 | + public function shareApiAllowLinks() { |
|
1740 | + if ($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') !== 'yes') { |
|
1741 | + return false; |
|
1742 | + } |
|
1743 | + |
|
1744 | + $user = $this->userSession->getUser(); |
|
1745 | + if ($user) { |
|
1746 | + $excludedGroups = json_decode($this->config->getAppValue('core', 'shareapi_allow_links_exclude_groups', '[]')); |
|
1747 | + if ($excludedGroups) { |
|
1748 | + $userGroups = $this->groupManager->getUserGroupIds($user); |
|
1749 | + return !(bool)array_intersect($excludedGroups, $userGroups); |
|
1750 | + } |
|
1751 | + } |
|
1752 | + |
|
1753 | + return true; |
|
1754 | + } |
|
1755 | + |
|
1756 | + /** |
|
1757 | + * Is password on public link requires |
|
1758 | + * |
|
1759 | + * @return bool |
|
1760 | + */ |
|
1761 | + public function shareApiLinkEnforcePassword() { |
|
1762 | + return $this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes'; |
|
1763 | + } |
|
1764 | + |
|
1765 | + /** |
|
1766 | + * Is default link expire date enabled |
|
1767 | + * |
|
1768 | + * @return bool |
|
1769 | + */ |
|
1770 | + public function shareApiLinkDefaultExpireDate() { |
|
1771 | + return $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
1772 | + } |
|
1773 | + |
|
1774 | + /** |
|
1775 | + * Is default link expire date enforced |
|
1776 | + *` |
|
1777 | + * |
|
1778 | + * @return bool |
|
1779 | + */ |
|
1780 | + public function shareApiLinkDefaultExpireDateEnforced() { |
|
1781 | + return $this->shareApiLinkDefaultExpireDate() && |
|
1782 | + $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
1783 | + } |
|
1784 | + |
|
1785 | + |
|
1786 | + /** |
|
1787 | + * Number of default link expire days |
|
1788 | + * |
|
1789 | + * @return int |
|
1790 | + */ |
|
1791 | + public function shareApiLinkDefaultExpireDays() { |
|
1792 | + return (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
1793 | + } |
|
1794 | + |
|
1795 | + /** |
|
1796 | + * Is default internal expire date enabled |
|
1797 | + * |
|
1798 | + * @return bool |
|
1799 | + */ |
|
1800 | + public function shareApiInternalDefaultExpireDate(): bool { |
|
1801 | + return $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no') === 'yes'; |
|
1802 | + } |
|
1803 | + |
|
1804 | + /** |
|
1805 | + * Is default remote expire date enabled |
|
1806 | + * |
|
1807 | + * @return bool |
|
1808 | + */ |
|
1809 | + public function shareApiRemoteDefaultExpireDate(): bool { |
|
1810 | + return $this->config->getAppValue('core', 'shareapi_default_remote_expire_date', 'no') === 'yes'; |
|
1811 | + } |
|
1812 | + |
|
1813 | + /** |
|
1814 | + * Is default expire date enforced |
|
1815 | + * |
|
1816 | + * @return bool |
|
1817 | + */ |
|
1818 | + public function shareApiInternalDefaultExpireDateEnforced(): bool { |
|
1819 | + return $this->shareApiInternalDefaultExpireDate() && |
|
1820 | + $this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no') === 'yes'; |
|
1821 | + } |
|
1822 | + |
|
1823 | + /** |
|
1824 | + * Is default expire date enforced for remote shares |
|
1825 | + * |
|
1826 | + * @return bool |
|
1827 | + */ |
|
1828 | + public function shareApiRemoteDefaultExpireDateEnforced(): bool { |
|
1829 | + return $this->shareApiRemoteDefaultExpireDate() && |
|
1830 | + $this->config->getAppValue('core', 'shareapi_enforce_remote_expire_date', 'no') === 'yes'; |
|
1831 | + } |
|
1832 | + |
|
1833 | + /** |
|
1834 | + * Number of default expire days |
|
1835 | + * |
|
1836 | + * @return int |
|
1837 | + */ |
|
1838 | + public function shareApiInternalDefaultExpireDays(): int { |
|
1839 | + return (int)$this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'); |
|
1840 | + } |
|
1841 | + |
|
1842 | + /** |
|
1843 | + * Number of default expire days for remote shares |
|
1844 | + * |
|
1845 | + * @return int |
|
1846 | + */ |
|
1847 | + public function shareApiRemoteDefaultExpireDays(): int { |
|
1848 | + return (int)$this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7'); |
|
1849 | + } |
|
1850 | + |
|
1851 | + /** |
|
1852 | + * Allow public upload on link shares |
|
1853 | + * |
|
1854 | + * @return bool |
|
1855 | + */ |
|
1856 | + public function shareApiLinkAllowPublicUpload() { |
|
1857 | + return $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes'; |
|
1858 | + } |
|
1859 | + |
|
1860 | + /** |
|
1861 | + * check if user can only share with group members |
|
1862 | + * |
|
1863 | + * @return bool |
|
1864 | + */ |
|
1865 | + public function shareWithGroupMembersOnly() { |
|
1866 | + return $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
1867 | + } |
|
1868 | + |
|
1869 | + /** |
|
1870 | + * Check if users can share with groups |
|
1871 | + * |
|
1872 | + * @return bool |
|
1873 | + */ |
|
1874 | + public function allowGroupSharing() { |
|
1875 | + return $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
|
1876 | + } |
|
1877 | + |
|
1878 | + public function allowEnumeration(): bool { |
|
1879 | + return $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
1880 | + } |
|
1881 | + |
|
1882 | + public function limitEnumerationToGroups(): bool { |
|
1883 | + return $this->allowEnumeration() && |
|
1884 | + $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes'; |
|
1885 | + } |
|
1886 | + |
|
1887 | + public function limitEnumerationToPhone(): bool { |
|
1888 | + return $this->allowEnumeration() && |
|
1889 | + $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes'; |
|
1890 | + } |
|
1891 | + |
|
1892 | + public function allowEnumerationFullMatch(): bool { |
|
1893 | + return $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes'; |
|
1894 | + } |
|
1895 | + |
|
1896 | + /** |
|
1897 | + * Copied from \OC_Util::isSharingDisabledForUser |
|
1898 | + * |
|
1899 | + * TODO: Deprecate fuction from OC_Util |
|
1900 | + * |
|
1901 | + * @param string $userId |
|
1902 | + * @return bool |
|
1903 | + */ |
|
1904 | + public function sharingDisabledForUser($userId) { |
|
1905 | + if ($userId === null) { |
|
1906 | + return false; |
|
1907 | + } |
|
1908 | + |
|
1909 | + if (isset($this->sharingDisabledForUsersCache[$userId])) { |
|
1910 | + return $this->sharingDisabledForUsersCache[$userId]; |
|
1911 | + } |
|
1912 | + |
|
1913 | + if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
1914 | + $groupsList = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
1915 | + $excludedGroups = json_decode($groupsList); |
|
1916 | + if (is_null($excludedGroups)) { |
|
1917 | + $excludedGroups = explode(',', $groupsList); |
|
1918 | + $newValue = json_encode($excludedGroups); |
|
1919 | + $this->config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
1920 | + } |
|
1921 | + $user = $this->userManager->get($userId); |
|
1922 | + $usersGroups = $this->groupManager->getUserGroupIds($user); |
|
1923 | + if (!empty($usersGroups)) { |
|
1924 | + $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
1925 | + // if the user is only in groups which are disabled for sharing then |
|
1926 | + // sharing is also disabled for the user |
|
1927 | + if (empty($remainingGroups)) { |
|
1928 | + $this->sharingDisabledForUsersCache[$userId] = true; |
|
1929 | + return true; |
|
1930 | + } |
|
1931 | + } |
|
1932 | + } |
|
1933 | + |
|
1934 | + $this->sharingDisabledForUsersCache[$userId] = false; |
|
1935 | + return false; |
|
1936 | + } |
|
1937 | + |
|
1938 | + /** |
|
1939 | + * @inheritdoc |
|
1940 | + */ |
|
1941 | + public function outgoingServer2ServerSharesAllowed() { |
|
1942 | + return $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
|
1943 | + } |
|
1944 | + |
|
1945 | + /** |
|
1946 | + * @inheritdoc |
|
1947 | + */ |
|
1948 | + public function outgoingServer2ServerGroupSharesAllowed() { |
|
1949 | + return $this->config->getAppValue('files_sharing', 'outgoing_server2server_group_share_enabled', 'no') === 'yes'; |
|
1950 | + } |
|
1951 | + |
|
1952 | + /** |
|
1953 | + * @inheritdoc |
|
1954 | + */ |
|
1955 | + public function shareProviderExists($shareType) { |
|
1956 | + try { |
|
1957 | + $this->factory->getProviderForType($shareType); |
|
1958 | + } catch (ProviderException $e) { |
|
1959 | + return false; |
|
1960 | + } |
|
1961 | + |
|
1962 | + return true; |
|
1963 | + } |
|
1964 | + |
|
1965 | + public function registerShareProvider(string $shareProviderClass): void { |
|
1966 | + $this->factory->registerProvider($shareProviderClass); |
|
1967 | + } |
|
1968 | + |
|
1969 | + public function getAllShares(): iterable { |
|
1970 | + $providers = $this->factory->getAllProviders(); |
|
1971 | + |
|
1972 | + foreach ($providers as $provider) { |
|
1973 | + yield from $provider->getAllShares(); |
|
1974 | + } |
|
1975 | + } |
|
1976 | 1976 | } |
@@ -284,14 +284,14 @@ discard block |
||
284 | 284 | $permissions = 0; |
285 | 285 | |
286 | 286 | if (!$isFederatedShare && $share->getNode()->getOwner() && $share->getNode()->getOwner()->getUID() !== $share->getSharedBy()) { |
287 | - $userMounts = array_filter($userFolder->getById($share->getNode()->getId()), function ($mount) { |
|
287 | + $userMounts = array_filter($userFolder->getById($share->getNode()->getId()), function($mount) { |
|
288 | 288 | // We need to filter since there might be other mountpoints that contain the file |
289 | 289 | // e.g. if the user has access to the same external storage that the file is originating from |
290 | 290 | return $mount->getStorage()->instanceOfStorage(ISharedStorage::class); |
291 | 291 | }); |
292 | 292 | $userMount = array_shift($userMounts); |
293 | 293 | if ($userMount === null) { |
294 | - throw new GenericShareException('Could not get proper share mount for ' . $share->getNode()->getId() . '. Failing since else the next calls are called with null'); |
|
294 | + throw new GenericShareException('Could not get proper share mount for '.$share->getNode()->getId().'. Failing since else the next calls are called with null'); |
|
295 | 295 | } |
296 | 296 | $mount = $userMount->getMountPoint(); |
297 | 297 | // When it's a reshare use the parent share permissions as maximum |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | $userMountPoint = array_shift($userMountPoints); |
301 | 301 | |
302 | 302 | if ($userMountPoint === null) { |
303 | - throw new GenericShareException('Could not get proper user mount for ' . $userMountPointId . '. Failing since else the next calls are called with null'); |
|
303 | + throw new GenericShareException('Could not get proper user mount for '.$userMountPointId.'. Failing since else the next calls are called with null'); |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | /* Check if this is an incoming share */ |
@@ -405,11 +405,11 @@ discard block |
||
405 | 405 | $expirationDate = new \DateTime(); |
406 | 406 | $expirationDate->setTime(0, 0, 0); |
407 | 407 | |
408 | - $days = (int)$this->config->getAppValue('core', $configProp, (string)$defaultExpireDays); |
|
408 | + $days = (int) $this->config->getAppValue('core', $configProp, (string) $defaultExpireDays); |
|
409 | 409 | if ($days > $defaultExpireDays) { |
410 | 410 | $days = $defaultExpireDays; |
411 | 411 | } |
412 | - $expirationDate->add(new \DateInterval('P' . $days . 'D')); |
|
412 | + $expirationDate->add(new \DateInterval('P'.$days.'D')); |
|
413 | 413 | } |
414 | 414 | |
415 | 415 | // If we enforce the expiration date check that is does not exceed |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | |
421 | 421 | $date = new \DateTime(); |
422 | 422 | $date->setTime(0, 0, 0); |
423 | - $date->add(new \DateInterval('P' . $defaultExpireDays . 'D')); |
|
423 | + $date->add(new \DateInterval('P'.$defaultExpireDays.'D')); |
|
424 | 424 | if ($date < $expirationDate) { |
425 | 425 | $message = $this->l->n('Cannot set expiration date more than %n day in the future', 'Cannot set expiration date more than %n days in the future', $defaultExpireDays); |
426 | 426 | throw new GenericShareException($message, $message, 404); |
@@ -481,11 +481,11 @@ discard block |
||
481 | 481 | $expirationDate = new \DateTime(); |
482 | 482 | $expirationDate->setTime(0, 0, 0); |
483 | 483 | |
484 | - $days = (int)$this->config->getAppValue('core', 'link_defaultExpDays', $this->shareApiLinkDefaultExpireDays()); |
|
484 | + $days = (int) $this->config->getAppValue('core', 'link_defaultExpDays', $this->shareApiLinkDefaultExpireDays()); |
|
485 | 485 | if ($days > $this->shareApiLinkDefaultExpireDays()) { |
486 | 486 | $days = $this->shareApiLinkDefaultExpireDays(); |
487 | 487 | } |
488 | - $expirationDate->add(new \DateInterval('P' . $days . 'D')); |
|
488 | + $expirationDate->add(new \DateInterval('P'.$days.'D')); |
|
489 | 489 | } |
490 | 490 | |
491 | 491 | // If we enforce the expiration date check that is does not exceed |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | |
497 | 497 | $date = new \DateTime(); |
498 | 498 | $date->setTime(0, 0, 0); |
499 | - $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D')); |
|
499 | + $date->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D')); |
|
500 | 500 | if ($date < $expirationDate) { |
501 | 501 | $message = $this->l->n('Cannot set expiration date more than %n day in the future', 'Cannot set expiration date more than %n days in the future', $this->shareApiLinkDefaultExpireDays()); |
502 | 502 | throw new GenericShareException($message, $message, 404); |
@@ -781,7 +781,7 @@ discard block |
||
781 | 781 | } |
782 | 782 | |
783 | 783 | // Generate the target |
784 | - $target = $this->config->getSystemValue('share_folder', '/') . '/' . $share->getNode()->getName(); |
|
784 | + $target = $this->config->getSystemValue('share_folder', '/').'/'.$share->getNode()->getName(); |
|
785 | 785 | $target = \OC\Files\Filesystem::normalizePath($target); |
786 | 786 | $share->setTarget($target); |
787 | 787 | |
@@ -832,12 +832,12 @@ discard block |
||
832 | 832 | $emailAddress, |
833 | 833 | $share->getExpirationDate() |
834 | 834 | ); |
835 | - $this->logger->debug('Sent share notification to ' . $emailAddress . ' for share with ID ' . $share->getId(), ['app' => 'share']); |
|
835 | + $this->logger->debug('Sent share notification to '.$emailAddress.' for share with ID '.$share->getId(), ['app' => 'share']); |
|
836 | 836 | } else { |
837 | - $this->logger->debug('Share notification not sent to ' . $share->getSharedWith() . ' because email address is not set.', ['app' => 'share']); |
|
837 | + $this->logger->debug('Share notification not sent to '.$share->getSharedWith().' because email address is not set.', ['app' => 'share']); |
|
838 | 838 | } |
839 | 839 | } else { |
840 | - $this->logger->debug('Share notification not sent to ' . $share->getSharedWith() . ' because user could not be found.', ['app' => 'share']); |
|
840 | + $this->logger->debug('Share notification not sent to '.$share->getSharedWith().' because user could not be found.', ['app' => 'share']); |
|
841 | 841 | } |
842 | 842 | } else { |
843 | 843 | $this->logger->debug('Share notification not sent because mailsend is false.', ['app' => 'share']); |
@@ -884,7 +884,7 @@ discard block |
||
884 | 884 | $text = $l->t('%1$s shared »%2$s« with you.', [$initiatorDisplayName, $filename]); |
885 | 885 | |
886 | 886 | $emailTemplate->addBodyText( |
887 | - htmlspecialchars($text . ' ' . $l->t('Click the button below to open it.')), |
|
887 | + htmlspecialchars($text.' '.$l->t('Click the button below to open it.')), |
|
888 | 888 | $text |
889 | 889 | ); |
890 | 890 | $emailTemplate->addBodyButton( |
@@ -910,7 +910,7 @@ discard block |
||
910 | 910 | $initiatorEmail = $initiatorUser->getEMailAddress(); |
911 | 911 | if ($initiatorEmail !== null) { |
912 | 912 | $message->setReplyTo([$initiatorEmail => $initiatorDisplayName]); |
913 | - $emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan($l->getLanguageCode()) !== '' ? ' - ' . $this->defaults->getSlogan($l->getLanguageCode()) : '')); |
|
913 | + $emailTemplate->addFooter($instanceName.($this->defaults->getSlogan($l->getLanguageCode()) !== '' ? ' - '.$this->defaults->getSlogan($l->getLanguageCode()) : '')); |
|
914 | 914 | } else { |
915 | 915 | $emailTemplate->addFooter('', $l->getLanguageCode()); |
916 | 916 | } |
@@ -919,7 +919,7 @@ discard block |
||
919 | 919 | try { |
920 | 920 | $failedRecipients = $this->mailer->send($message); |
921 | 921 | if (!empty($failedRecipients)) { |
922 | - $this->logger->error('Share notification mail could not be sent to: ' . implode(', ', $failedRecipients)); |
|
922 | + $this->logger->error('Share notification mail could not be sent to: '.implode(', ', $failedRecipients)); |
|
923 | 923 | return; |
924 | 924 | } |
925 | 925 | } catch (\Exception $e) { |
@@ -1083,7 +1083,7 @@ discard block |
||
1083 | 1083 | * @since 9.0.0 |
1084 | 1084 | */ |
1085 | 1085 | public function acceptShare(IShare $share, string $recipientId): IShare { |
1086 | - [$providerId,] = $this->splitFullId($share->getFullId()); |
|
1086 | + [$providerId, ] = $this->splitFullId($share->getFullId()); |
|
1087 | 1087 | $provider = $this->factory->getProvider($providerId); |
1088 | 1088 | |
1089 | 1089 | if (!method_exists($provider, 'acceptShare')) { |
@@ -1206,7 +1206,7 @@ discard block |
||
1206 | 1206 | * @param string $recipientId |
1207 | 1207 | */ |
1208 | 1208 | public function deleteFromSelf(IShare $share, $recipientId) { |
1209 | - [$providerId,] = $this->splitFullId($share->getFullId()); |
|
1209 | + [$providerId, ] = $this->splitFullId($share->getFullId()); |
|
1210 | 1210 | $provider = $this->factory->getProvider($providerId); |
1211 | 1211 | |
1212 | 1212 | $provider->deleteFromSelf($share, $recipientId); |
@@ -1215,7 +1215,7 @@ discard block |
||
1215 | 1215 | } |
1216 | 1216 | |
1217 | 1217 | public function restoreShare(IShare $share, string $recipientId): IShare { |
1218 | - [$providerId,] = $this->splitFullId($share->getFullId()); |
|
1218 | + [$providerId, ] = $this->splitFullId($share->getFullId()); |
|
1219 | 1219 | $provider = $this->factory->getProvider($providerId); |
1220 | 1220 | |
1221 | 1221 | return $provider->restore($share, $recipientId); |
@@ -1237,7 +1237,7 @@ discard block |
||
1237 | 1237 | if ($share->getShareType() === IShare::TYPE_GROUP) { |
1238 | 1238 | $sharedWith = $this->groupManager->get($share->getSharedWith()); |
1239 | 1239 | if (is_null($sharedWith)) { |
1240 | - throw new \InvalidArgumentException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
1240 | + throw new \InvalidArgumentException('Group "'.$share->getSharedWith().'" does not exist'); |
|
1241 | 1241 | } |
1242 | 1242 | $recipient = $this->userManager->get($recipientId); |
1243 | 1243 | if (!$sharedWith->inGroup($recipient)) { |
@@ -1245,7 +1245,7 @@ discard block |
||
1245 | 1245 | } |
1246 | 1246 | } |
1247 | 1247 | |
1248 | - [$providerId,] = $this->splitFullId($share->getFullId()); |
|
1248 | + [$providerId, ] = $this->splitFullId($share->getFullId()); |
|
1249 | 1249 | $provider = $this->factory->getProvider($providerId); |
1250 | 1250 | |
1251 | 1251 | return $provider->move($share, $recipientId); |
@@ -1254,7 +1254,7 @@ discard block |
||
1254 | 1254 | public function getSharesInFolder($userId, Folder $node, $reshares = false) { |
1255 | 1255 | $providers = $this->factory->getAllProviders(); |
1256 | 1256 | |
1257 | - return array_reduce($providers, function ($shares, IShareProvider $provider) use ($userId, $node, $reshares) { |
|
1257 | + return array_reduce($providers, function($shares, IShareProvider $provider) use ($userId, $node, $reshares) { |
|
1258 | 1258 | $newShares = $provider->getSharesInFolder($userId, $node, $reshares); |
1259 | 1259 | foreach ($newShares as $fid => $data) { |
1260 | 1260 | if (!isset($shares[$fid])) { |
@@ -1371,12 +1371,12 @@ discard block |
||
1371 | 1371 | $shares = $this->getSharedWith($userId, $shareType, $node, $limit, $offset); |
1372 | 1372 | |
1373 | 1373 | // Only get deleted shares |
1374 | - $shares = array_filter($shares, function (IShare $share) { |
|
1374 | + $shares = array_filter($shares, function(IShare $share) { |
|
1375 | 1375 | return $share->getPermissions() === 0; |
1376 | 1376 | }); |
1377 | 1377 | |
1378 | 1378 | // Only get shares where the owner still exists |
1379 | - $shares = array_filter($shares, function (IShare $share) { |
|
1379 | + $shares = array_filter($shares, function(IShare $share) { |
|
1380 | 1380 | return $this->userManager->userExists($share->getShareOwner()); |
1381 | 1381 | }); |
1382 | 1382 | |
@@ -1673,7 +1673,7 @@ discard block |
||
1673 | 1673 | } |
1674 | 1674 | $al['users'][$owner] = [ |
1675 | 1675 | 'node_id' => $path->getId(), |
1676 | - 'node_path' => '/' . $ownerPath, |
|
1676 | + 'node_path' => '/'.$ownerPath, |
|
1677 | 1677 | ]; |
1678 | 1678 | } else { |
1679 | 1679 | $al['users'][] = $owner; |
@@ -1746,7 +1746,7 @@ discard block |
||
1746 | 1746 | $excludedGroups = json_decode($this->config->getAppValue('core', 'shareapi_allow_links_exclude_groups', '[]')); |
1747 | 1747 | if ($excludedGroups) { |
1748 | 1748 | $userGroups = $this->groupManager->getUserGroupIds($user); |
1749 | - return !(bool)array_intersect($excludedGroups, $userGroups); |
|
1749 | + return !(bool) array_intersect($excludedGroups, $userGroups); |
|
1750 | 1750 | } |
1751 | 1751 | } |
1752 | 1752 | |
@@ -1789,7 +1789,7 @@ discard block |
||
1789 | 1789 | * @return int |
1790 | 1790 | */ |
1791 | 1791 | public function shareApiLinkDefaultExpireDays() { |
1792 | - return (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
1792 | + return (int) $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
1793 | 1793 | } |
1794 | 1794 | |
1795 | 1795 | /** |
@@ -1836,7 +1836,7 @@ discard block |
||
1836 | 1836 | * @return int |
1837 | 1837 | */ |
1838 | 1838 | public function shareApiInternalDefaultExpireDays(): int { |
1839 | - return (int)$this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'); |
|
1839 | + return (int) $this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'); |
|
1840 | 1840 | } |
1841 | 1841 | |
1842 | 1842 | /** |
@@ -1845,7 +1845,7 @@ discard block |
||
1845 | 1845 | * @return int |
1846 | 1846 | */ |
1847 | 1847 | public function shareApiRemoteDefaultExpireDays(): int { |
1848 | - return (int)$this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7'); |
|
1848 | + return (int) $this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7'); |
|
1849 | 1849 | } |
1850 | 1850 | |
1851 | 1851 | /** |
@@ -260,2067 +260,2067 @@ |
||
260 | 260 | */ |
261 | 261 | class Server extends ServerContainer implements IServerContainer { |
262 | 262 | |
263 | - /** @var string */ |
|
264 | - private $webRoot; |
|
265 | - |
|
266 | - /** |
|
267 | - * @param string $webRoot |
|
268 | - * @param \OC\Config $config |
|
269 | - */ |
|
270 | - public function __construct($webRoot, \OC\Config $config) { |
|
271 | - parent::__construct(); |
|
272 | - $this->webRoot = $webRoot; |
|
273 | - |
|
274 | - // To find out if we are running from CLI or not |
|
275 | - $this->registerParameter('isCLI', \OC::$CLI); |
|
276 | - $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
277 | - |
|
278 | - $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
279 | - return $c; |
|
280 | - }); |
|
281 | - $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) { |
|
282 | - return $c; |
|
283 | - }); |
|
284 | - |
|
285 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
286 | - /** @deprecated 19.0.0 */ |
|
287 | - $this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
288 | - |
|
289 | - $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
290 | - /** @deprecated 19.0.0 */ |
|
291 | - $this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
292 | - |
|
293 | - $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
294 | - /** @deprecated 19.0.0 */ |
|
295 | - $this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
296 | - |
|
297 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
298 | - /** @deprecated 19.0.0 */ |
|
299 | - $this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
300 | - |
|
301 | - $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
302 | - $this->registerAlias(ITemplateManager::class, TemplateManager::class); |
|
303 | - |
|
304 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
305 | - |
|
306 | - $this->registerService(View::class, function (Server $c) { |
|
307 | - return new View(); |
|
308 | - }, false); |
|
309 | - |
|
310 | - $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
311 | - return new PreviewManager( |
|
312 | - $c->get(\OCP\IConfig::class), |
|
313 | - $c->get(IRootFolder::class), |
|
314 | - new \OC\Preview\Storage\Root( |
|
315 | - $c->get(IRootFolder::class), |
|
316 | - $c->get(SystemConfig::class) |
|
317 | - ), |
|
318 | - $c->get(SymfonyAdapter::class), |
|
319 | - $c->get(GeneratorHelper::class), |
|
320 | - $c->get(ISession::class)->get('user_id') |
|
321 | - ); |
|
322 | - }); |
|
323 | - /** @deprecated 19.0.0 */ |
|
324 | - $this->registerDeprecatedAlias('PreviewManager', IPreview::class); |
|
325 | - |
|
326 | - $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) { |
|
327 | - return new \OC\Preview\Watcher( |
|
328 | - new \OC\Preview\Storage\Root( |
|
329 | - $c->get(IRootFolder::class), |
|
330 | - $c->get(SystemConfig::class) |
|
331 | - ) |
|
332 | - ); |
|
333 | - }); |
|
334 | - |
|
335 | - $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
336 | - $view = new View(); |
|
337 | - $util = new Encryption\Util( |
|
338 | - $view, |
|
339 | - $c->get(IUserManager::class), |
|
340 | - $c->get(IGroupManager::class), |
|
341 | - $c->get(\OCP\IConfig::class) |
|
342 | - ); |
|
343 | - return new Encryption\Manager( |
|
344 | - $c->get(\OCP\IConfig::class), |
|
345 | - $c->get(ILogger::class), |
|
346 | - $c->getL10N('core'), |
|
347 | - new View(), |
|
348 | - $util, |
|
349 | - new ArrayCache() |
|
350 | - ); |
|
351 | - }); |
|
352 | - /** @deprecated 19.0.0 */ |
|
353 | - $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
354 | - |
|
355 | - /** @deprecated 21.0.0 */ |
|
356 | - $this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class); |
|
357 | - $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
358 | - $util = new Encryption\Util( |
|
359 | - new View(), |
|
360 | - $c->get(IUserManager::class), |
|
361 | - $c->get(IGroupManager::class), |
|
362 | - $c->get(\OCP\IConfig::class) |
|
363 | - ); |
|
364 | - return new Encryption\File( |
|
365 | - $util, |
|
366 | - $c->get(IRootFolder::class), |
|
367 | - $c->get(\OCP\Share\IManager::class) |
|
368 | - ); |
|
369 | - }); |
|
370 | - |
|
371 | - /** @deprecated 21.0.0 */ |
|
372 | - $this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class); |
|
373 | - $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
374 | - $view = new View(); |
|
375 | - $util = new Encryption\Util( |
|
376 | - $view, |
|
377 | - $c->get(IUserManager::class), |
|
378 | - $c->get(IGroupManager::class), |
|
379 | - $c->get(\OCP\IConfig::class) |
|
380 | - ); |
|
381 | - |
|
382 | - return new Encryption\Keys\Storage( |
|
383 | - $view, |
|
384 | - $util, |
|
385 | - $c->get(ICrypto::class), |
|
386 | - $c->get(\OCP\IConfig::class) |
|
387 | - ); |
|
388 | - }); |
|
389 | - /** @deprecated 20.0.0 */ |
|
390 | - $this->registerDeprecatedAlias('TagMapper', TagMapper::class); |
|
391 | - |
|
392 | - $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
393 | - /** @deprecated 19.0.0 */ |
|
394 | - $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class); |
|
395 | - |
|
396 | - $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
397 | - /** @var \OCP\IConfig $config */ |
|
398 | - $config = $c->get(\OCP\IConfig::class); |
|
399 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
400 | - return new $factoryClass($this); |
|
401 | - }); |
|
402 | - $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
403 | - return $c->get('SystemTagManagerFactory')->getManager(); |
|
404 | - }); |
|
405 | - /** @deprecated 19.0.0 */ |
|
406 | - $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
407 | - |
|
408 | - $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
409 | - return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
|
410 | - }); |
|
411 | - $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
412 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
413 | - $view = new View(); |
|
414 | - $root = new Root( |
|
415 | - $manager, |
|
416 | - $view, |
|
417 | - null, |
|
418 | - $c->get(IUserMountCache::class), |
|
419 | - $this->get(ILogger::class), |
|
420 | - $this->get(IUserManager::class) |
|
421 | - ); |
|
422 | - |
|
423 | - $previewConnector = new \OC\Preview\WatcherConnector( |
|
424 | - $root, |
|
425 | - $c->get(SystemConfig::class) |
|
426 | - ); |
|
427 | - $previewConnector->connectWatcher(); |
|
428 | - |
|
429 | - return $root; |
|
430 | - }); |
|
431 | - $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
432 | - return new HookConnector( |
|
433 | - $c->get(IRootFolder::class), |
|
434 | - new View(), |
|
435 | - $c->get(\OC\EventDispatcher\SymfonyAdapter::class), |
|
436 | - $c->get(IEventDispatcher::class) |
|
437 | - ); |
|
438 | - }); |
|
439 | - |
|
440 | - /** @deprecated 19.0.0 */ |
|
441 | - $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class); |
|
442 | - |
|
443 | - $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
444 | - return new LazyRoot(function () use ($c) { |
|
445 | - return $c->get('RootFolder'); |
|
446 | - }); |
|
447 | - }); |
|
448 | - /** @deprecated 19.0.0 */ |
|
449 | - $this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class); |
|
450 | - |
|
451 | - /** @deprecated 19.0.0 */ |
|
452 | - $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class); |
|
453 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
454 | - |
|
455 | - $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
456 | - $groupManager = new \OC\Group\Manager($this->get(IUserManager::class), $c->get(SymfonyAdapter::class), $this->get(ILogger::class)); |
|
457 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
458 | - /** @var IEventDispatcher $dispatcher */ |
|
459 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
460 | - $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid)); |
|
461 | - }); |
|
462 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) { |
|
463 | - /** @var IEventDispatcher $dispatcher */ |
|
464 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
465 | - $dispatcher->dispatchTyped(new GroupCreatedEvent($group)); |
|
466 | - }); |
|
467 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
468 | - /** @var IEventDispatcher $dispatcher */ |
|
469 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
470 | - $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group)); |
|
471 | - }); |
|
472 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
473 | - /** @var IEventDispatcher $dispatcher */ |
|
474 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
475 | - $dispatcher->dispatchTyped(new GroupDeletedEvent($group)); |
|
476 | - }); |
|
477 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
478 | - /** @var IEventDispatcher $dispatcher */ |
|
479 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
480 | - $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user)); |
|
481 | - }); |
|
482 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
483 | - /** @var IEventDispatcher $dispatcher */ |
|
484 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
485 | - $dispatcher->dispatchTyped(new UserAddedEvent($group, $user)); |
|
486 | - }); |
|
487 | - $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
488 | - /** @var IEventDispatcher $dispatcher */ |
|
489 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
490 | - $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user)); |
|
491 | - }); |
|
492 | - $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
493 | - /** @var IEventDispatcher $dispatcher */ |
|
494 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
495 | - $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user)); |
|
496 | - }); |
|
497 | - return $groupManager; |
|
498 | - }); |
|
499 | - /** @deprecated 19.0.0 */ |
|
500 | - $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class); |
|
501 | - |
|
502 | - $this->registerService(Store::class, function (ContainerInterface $c) { |
|
503 | - $session = $c->get(ISession::class); |
|
504 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
505 | - $tokenProvider = $c->get(IProvider::class); |
|
506 | - } else { |
|
507 | - $tokenProvider = null; |
|
508 | - } |
|
509 | - $logger = $c->get(LoggerInterface::class); |
|
510 | - return new Store($session, $logger, $tokenProvider); |
|
511 | - }); |
|
512 | - $this->registerAlias(IStore::class, Store::class); |
|
513 | - $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
514 | - |
|
515 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
516 | - $manager = $c->get(IUserManager::class); |
|
517 | - $session = new \OC\Session\Memory(''); |
|
518 | - $timeFactory = new TimeFactory(); |
|
519 | - // Token providers might require a working database. This code |
|
520 | - // might however be called when ownCloud is not yet setup. |
|
521 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
522 | - $defaultTokenProvider = $c->get(IProvider::class); |
|
523 | - } else { |
|
524 | - $defaultTokenProvider = null; |
|
525 | - } |
|
526 | - |
|
527 | - $legacyDispatcher = $c->get(SymfonyAdapter::class); |
|
528 | - |
|
529 | - $userSession = new \OC\User\Session( |
|
530 | - $manager, |
|
531 | - $session, |
|
532 | - $timeFactory, |
|
533 | - $defaultTokenProvider, |
|
534 | - $c->get(\OCP\IConfig::class), |
|
535 | - $c->get(ISecureRandom::class), |
|
536 | - $c->getLockdownManager(), |
|
537 | - $c->get(ILogger::class), |
|
538 | - $c->get(IEventDispatcher::class) |
|
539 | - ); |
|
540 | - /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
|
541 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
542 | - \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
543 | - }); |
|
544 | - /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
|
545 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
546 | - /** @var \OC\User\User $user */ |
|
547 | - \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
548 | - }); |
|
549 | - /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
|
550 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) { |
|
551 | - /** @var \OC\User\User $user */ |
|
552 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
553 | - $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
554 | - }); |
|
555 | - /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
|
556 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
557 | - /** @var \OC\User\User $user */ |
|
558 | - \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
559 | - }); |
|
560 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
561 | - /** @var \OC\User\User $user */ |
|
562 | - \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
563 | - |
|
564 | - /** @var IEventDispatcher $dispatcher */ |
|
565 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
566 | - $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
567 | - }); |
|
568 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
569 | - /** @var \OC\User\User $user */ |
|
570 | - \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
571 | - |
|
572 | - /** @var IEventDispatcher $dispatcher */ |
|
573 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
574 | - $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
575 | - }); |
|
576 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
577 | - \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
578 | - |
|
579 | - /** @var IEventDispatcher $dispatcher */ |
|
580 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
581 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
582 | - }); |
|
583 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
584 | - /** @var \OC\User\User $user */ |
|
585 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
586 | - |
|
587 | - /** @var IEventDispatcher $dispatcher */ |
|
588 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
589 | - $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin)); |
|
590 | - }); |
|
591 | - $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
592 | - /** @var IEventDispatcher $dispatcher */ |
|
593 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
594 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
595 | - }); |
|
596 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
597 | - /** @var \OC\User\User $user */ |
|
598 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
599 | - |
|
600 | - /** @var IEventDispatcher $dispatcher */ |
|
601 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
602 | - $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
603 | - }); |
|
604 | - $userSession->listen('\OC\User', 'logout', function ($user) { |
|
605 | - \OC_Hook::emit('OC_User', 'logout', []); |
|
606 | - |
|
607 | - /** @var IEventDispatcher $dispatcher */ |
|
608 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
609 | - $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
610 | - }); |
|
611 | - $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
612 | - /** @var IEventDispatcher $dispatcher */ |
|
613 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
614 | - $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
615 | - }); |
|
616 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
617 | - /** @var \OC\User\User $user */ |
|
618 | - \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
619 | - |
|
620 | - /** @var IEventDispatcher $dispatcher */ |
|
621 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
622 | - $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue)); |
|
623 | - }); |
|
624 | - return $userSession; |
|
625 | - }); |
|
626 | - $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
627 | - /** @deprecated 19.0.0 */ |
|
628 | - $this->registerDeprecatedAlias('UserSession', \OC\User\Session::class); |
|
629 | - |
|
630 | - $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
631 | - |
|
632 | - $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
633 | - /** @deprecated 19.0.0 */ |
|
634 | - $this->registerDeprecatedAlias('NavigationManager', INavigationManager::class); |
|
635 | - |
|
636 | - /** @deprecated 19.0.0 */ |
|
637 | - $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class); |
|
638 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
639 | - |
|
640 | - $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
641 | - return new \OC\SystemConfig($config); |
|
642 | - }); |
|
643 | - /** @deprecated 19.0.0 */ |
|
644 | - $this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class); |
|
645 | - |
|
646 | - /** @deprecated 19.0.0 */ |
|
647 | - $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class); |
|
648 | - $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
649 | - |
|
650 | - $this->registerService(IFactory::class, function (Server $c) { |
|
651 | - return new \OC\L10N\Factory( |
|
652 | - $c->get(\OCP\IConfig::class), |
|
653 | - $c->getRequest(), |
|
654 | - $c->get(IUserSession::class), |
|
655 | - \OC::$SERVERROOT |
|
656 | - ); |
|
657 | - }); |
|
658 | - /** @deprecated 19.0.0 */ |
|
659 | - $this->registerDeprecatedAlias('L10NFactory', IFactory::class); |
|
660 | - |
|
661 | - $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
|
662 | - /** @deprecated 19.0.0 */ |
|
663 | - $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class); |
|
664 | - |
|
665 | - /** @deprecated 19.0.0 */ |
|
666 | - $this->registerDeprecatedAlias('AppFetcher', AppFetcher::class); |
|
667 | - /** @deprecated 19.0.0 */ |
|
668 | - $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class); |
|
669 | - |
|
670 | - $this->registerService(ICache::class, function ($c) { |
|
671 | - return new Cache\File(); |
|
672 | - }); |
|
673 | - /** @deprecated 19.0.0 */ |
|
674 | - $this->registerDeprecatedAlias('UserCache', ICache::class); |
|
675 | - |
|
676 | - $this->registerService(Factory::class, function (Server $c) { |
|
677 | - $arrayCacheFactory = new \OC\Memcache\Factory('', $c->get(ILogger::class), |
|
678 | - ArrayCache::class, |
|
679 | - ArrayCache::class, |
|
680 | - ArrayCache::class |
|
681 | - ); |
|
682 | - /** @var \OCP\IConfig $config */ |
|
683 | - $config = $c->get(\OCP\IConfig::class); |
|
684 | - |
|
685 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
686 | - $v = \OC_App::getAppVersions(); |
|
687 | - $v['core'] = implode(',', \OC_Util::getVersion()); |
|
688 | - $version = implode(',', $v); |
|
689 | - $instanceId = \OC_Util::getInstanceId(); |
|
690 | - $path = \OC::$SERVERROOT; |
|
691 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
692 | - return new \OC\Memcache\Factory($prefix, $c->get(ILogger::class), |
|
693 | - $config->getSystemValue('memcache.local', null), |
|
694 | - $config->getSystemValue('memcache.distributed', null), |
|
695 | - $config->getSystemValue('memcache.locking', null) |
|
696 | - ); |
|
697 | - } |
|
698 | - return $arrayCacheFactory; |
|
699 | - }); |
|
700 | - /** @deprecated 19.0.0 */ |
|
701 | - $this->registerDeprecatedAlias('MemCacheFactory', Factory::class); |
|
702 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
703 | - |
|
704 | - $this->registerService('RedisFactory', function (Server $c) { |
|
705 | - $systemConfig = $c->get(SystemConfig::class); |
|
706 | - return new RedisFactory($systemConfig); |
|
707 | - }); |
|
708 | - |
|
709 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
710 | - $l10n = $this->get(IFactory::class)->get('lib'); |
|
711 | - return new \OC\Activity\Manager( |
|
712 | - $c->getRequest(), |
|
713 | - $c->get(IUserSession::class), |
|
714 | - $c->get(\OCP\IConfig::class), |
|
715 | - $c->get(IValidator::class), |
|
716 | - $l10n |
|
717 | - ); |
|
718 | - }); |
|
719 | - /** @deprecated 19.0.0 */ |
|
720 | - $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
721 | - |
|
722 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
723 | - return new \OC\Activity\EventMerger( |
|
724 | - $c->getL10N('lib') |
|
725 | - ); |
|
726 | - }); |
|
727 | - $this->registerAlias(IValidator::class, Validator::class); |
|
728 | - |
|
729 | - $this->registerService(AvatarManager::class, function (Server $c) { |
|
730 | - return new AvatarManager( |
|
731 | - $c->get(IUserSession::class), |
|
732 | - $c->get(\OC\User\Manager::class), |
|
733 | - $c->getAppDataDir('avatar'), |
|
734 | - $c->getL10N('lib'), |
|
735 | - $c->get(LoggerInterface::class), |
|
736 | - $c->get(\OCP\IConfig::class), |
|
737 | - $c->get(IAccountManager::class), |
|
738 | - $c->get(KnownUserService::class) |
|
739 | - ); |
|
740 | - }); |
|
741 | - $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
742 | - /** @deprecated 19.0.0 */ |
|
743 | - $this->registerDeprecatedAlias('AvatarManager', AvatarManager::class); |
|
744 | - |
|
745 | - $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
746 | - $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
747 | - |
|
748 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
749 | - $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
750 | - $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
|
751 | - $logger = $factory->get($logType); |
|
752 | - $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class); |
|
753 | - |
|
754 | - return new Log($logger, $this->get(SystemConfig::class), null, $registry); |
|
755 | - }); |
|
756 | - $this->registerAlias(ILogger::class, \OC\Log::class); |
|
757 | - /** @deprecated 19.0.0 */ |
|
758 | - $this->registerDeprecatedAlias('Logger', \OC\Log::class); |
|
759 | - // PSR-3 logger |
|
760 | - $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
761 | - |
|
762 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
763 | - return new LogFactory($c, $this->get(SystemConfig::class)); |
|
764 | - }); |
|
765 | - |
|
766 | - $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
767 | - /** @deprecated 19.0.0 */ |
|
768 | - $this->registerDeprecatedAlias('JobList', IJobList::class); |
|
769 | - |
|
770 | - $this->registerService(Router::class, function (Server $c) { |
|
771 | - $cacheFactory = $c->get(ICacheFactory::class); |
|
772 | - $logger = $c->get(ILogger::class); |
|
773 | - if ($cacheFactory->isLocalCacheAvailable()) { |
|
774 | - $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
775 | - } else { |
|
776 | - $router = new \OC\Route\Router($logger); |
|
777 | - } |
|
778 | - return $router; |
|
779 | - }); |
|
780 | - $this->registerAlias(IRouter::class, Router::class); |
|
781 | - /** @deprecated 19.0.0 */ |
|
782 | - $this->registerDeprecatedAlias('Router', IRouter::class); |
|
783 | - |
|
784 | - $this->registerAlias(ISearch::class, Search::class); |
|
785 | - /** @deprecated 19.0.0 */ |
|
786 | - $this->registerDeprecatedAlias('Search', ISearch::class); |
|
787 | - |
|
788 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
789 | - return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
790 | - $this->get(ICacheFactory::class), |
|
791 | - new \OC\AppFramework\Utility\TimeFactory() |
|
792 | - ); |
|
793 | - }); |
|
794 | - |
|
795 | - $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
796 | - /** @deprecated 19.0.0 */ |
|
797 | - $this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
798 | - |
|
799 | - $this->registerAlias(ICrypto::class, Crypto::class); |
|
800 | - /** @deprecated 19.0.0 */ |
|
801 | - $this->registerDeprecatedAlias('Crypto', ICrypto::class); |
|
802 | - |
|
803 | - $this->registerAlias(IHasher::class, Hasher::class); |
|
804 | - /** @deprecated 19.0.0 */ |
|
805 | - $this->registerDeprecatedAlias('Hasher', IHasher::class); |
|
806 | - |
|
807 | - $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
808 | - /** @deprecated 19.0.0 */ |
|
809 | - $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class); |
|
810 | - |
|
811 | - $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
|
812 | - $this->registerService(Connection::class, function (Server $c) { |
|
813 | - $systemConfig = $c->get(SystemConfig::class); |
|
814 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
815 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
816 | - if (!$factory->isValidType($type)) { |
|
817 | - throw new \OC\DatabaseException('Invalid database type'); |
|
818 | - } |
|
819 | - $connectionParams = $factory->createConnectionParams(); |
|
820 | - $connection = $factory->getConnection($type, $connectionParams); |
|
821 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
822 | - return $connection; |
|
823 | - }); |
|
824 | - /** @deprecated 19.0.0 */ |
|
825 | - $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class); |
|
826 | - |
|
827 | - $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
|
828 | - $this->registerAlias(IClientService::class, ClientService::class); |
|
829 | - $this->registerService(LocalAddressChecker::class, function (ContainerInterface $c) { |
|
830 | - return new LocalAddressChecker( |
|
831 | - $c->get(ILogger::class), |
|
832 | - ); |
|
833 | - }); |
|
834 | - $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) { |
|
835 | - return new NegativeDnsCache( |
|
836 | - $c->get(ICacheFactory::class), |
|
837 | - ); |
|
838 | - }); |
|
839 | - $this->registerService(DnsPinMiddleware::class, function (ContainerInterface $c) { |
|
840 | - return new DnsPinMiddleware( |
|
841 | - $c->get(NegativeDnsCache::class), |
|
842 | - $c->get(LocalAddressChecker::class) |
|
843 | - ); |
|
844 | - }); |
|
845 | - $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
846 | - $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
847 | - $eventLogger = new EventLogger(); |
|
848 | - if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
849 | - // In debug mode, module is being activated by default |
|
850 | - $eventLogger->activate(); |
|
851 | - } |
|
852 | - return $eventLogger; |
|
853 | - }); |
|
854 | - /** @deprecated 19.0.0 */ |
|
855 | - $this->registerDeprecatedAlias('EventLogger', IEventLogger::class); |
|
856 | - |
|
857 | - $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
858 | - $queryLogger = new QueryLogger(); |
|
859 | - if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
860 | - // In debug mode, module is being activated by default |
|
861 | - $queryLogger->activate(); |
|
862 | - } |
|
863 | - return $queryLogger; |
|
864 | - }); |
|
865 | - /** @deprecated 19.0.0 */ |
|
866 | - $this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class); |
|
867 | - |
|
868 | - /** @deprecated 19.0.0 */ |
|
869 | - $this->registerDeprecatedAlias('TempManager', TempManager::class); |
|
870 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
871 | - |
|
872 | - $this->registerService(AppManager::class, function (ContainerInterface $c) { |
|
873 | - // TODO: use auto-wiring |
|
874 | - return new \OC\App\AppManager( |
|
875 | - $c->get(IUserSession::class), |
|
876 | - $c->get(\OCP\IConfig::class), |
|
877 | - $c->get(\OC\AppConfig::class), |
|
878 | - $c->get(IGroupManager::class), |
|
879 | - $c->get(ICacheFactory::class), |
|
880 | - $c->get(SymfonyAdapter::class), |
|
881 | - $c->get(LoggerInterface::class) |
|
882 | - ); |
|
883 | - }); |
|
884 | - /** @deprecated 19.0.0 */ |
|
885 | - $this->registerDeprecatedAlias('AppManager', AppManager::class); |
|
886 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
887 | - |
|
888 | - $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
889 | - /** @deprecated 19.0.0 */ |
|
890 | - $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class); |
|
891 | - |
|
892 | - $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
893 | - $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
|
894 | - |
|
895 | - return new DateTimeFormatter( |
|
896 | - $c->get(IDateTimeZone::class)->getTimeZone(), |
|
897 | - $c->getL10N('lib', $language) |
|
898 | - ); |
|
899 | - }); |
|
900 | - /** @deprecated 19.0.0 */ |
|
901 | - $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class); |
|
902 | - |
|
903 | - $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
904 | - $mountCache = new UserMountCache( |
|
905 | - $c->get(IDBConnection::class), |
|
906 | - $c->get(IUserManager::class), |
|
907 | - $c->get(ILogger::class) |
|
908 | - ); |
|
909 | - $listener = new UserMountCacheListener($mountCache); |
|
910 | - $listener->listen($c->get(IUserManager::class)); |
|
911 | - return $mountCache; |
|
912 | - }); |
|
913 | - /** @deprecated 19.0.0 */ |
|
914 | - $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class); |
|
915 | - |
|
916 | - $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
917 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
918 | - $mountCache = $c->get(IUserMountCache::class); |
|
919 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
920 | - |
|
921 | - // builtin providers |
|
922 | - |
|
923 | - $config = $c->get(\OCP\IConfig::class); |
|
924 | - $logger = $c->get(ILogger::class); |
|
925 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
926 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
927 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
928 | - $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config)); |
|
929 | - |
|
930 | - return $manager; |
|
931 | - }); |
|
932 | - /** @deprecated 19.0.0 */ |
|
933 | - $this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class); |
|
934 | - |
|
935 | - /** @deprecated 20.0.0 */ |
|
936 | - $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class); |
|
937 | - $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
938 | - $busClass = $c->get(\OCP\IConfig::class)->getSystemValue('commandbus'); |
|
939 | - if ($busClass) { |
|
940 | - [$app, $class] = explode('::', $busClass, 2); |
|
941 | - if ($c->get(IAppManager::class)->isInstalled($app)) { |
|
942 | - \OC_App::loadApp($app); |
|
943 | - return $c->get($class); |
|
944 | - } else { |
|
945 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
946 | - } |
|
947 | - } else { |
|
948 | - $jobList = $c->get(IJobList::class); |
|
949 | - return new CronBus($jobList); |
|
950 | - } |
|
951 | - }); |
|
952 | - $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class); |
|
953 | - /** @deprecated 20.0.0 */ |
|
954 | - $this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class); |
|
955 | - /** @deprecated 19.0.0 */ |
|
956 | - $this->registerDeprecatedAlias('Throttler', Throttler::class); |
|
957 | - $this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) { |
|
958 | - // IConfig and IAppManager requires a working database. This code |
|
959 | - // might however be called when ownCloud is not yet setup. |
|
960 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
961 | - $config = $c->get(\OCP\IConfig::class); |
|
962 | - $appManager = $c->get(IAppManager::class); |
|
963 | - } else { |
|
964 | - $config = null; |
|
965 | - $appManager = null; |
|
966 | - } |
|
967 | - |
|
968 | - return new Checker( |
|
969 | - new EnvironmentHelper(), |
|
970 | - new FileAccessHelper(), |
|
971 | - new AppLocator(), |
|
972 | - $config, |
|
973 | - $c->get(ICacheFactory::class), |
|
974 | - $appManager, |
|
975 | - $c->get(IMimeTypeDetector::class) |
|
976 | - ); |
|
977 | - }); |
|
978 | - $this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) { |
|
979 | - if (isset($this['urlParams'])) { |
|
980 | - $urlParams = $this['urlParams']; |
|
981 | - } else { |
|
982 | - $urlParams = []; |
|
983 | - } |
|
984 | - |
|
985 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
986 | - && in_array('fakeinput', stream_get_wrappers()) |
|
987 | - ) { |
|
988 | - $stream = 'fakeinput://data'; |
|
989 | - } else { |
|
990 | - $stream = 'php://input'; |
|
991 | - } |
|
992 | - |
|
993 | - return new Request( |
|
994 | - [ |
|
995 | - 'get' => $_GET, |
|
996 | - 'post' => $_POST, |
|
997 | - 'files' => $_FILES, |
|
998 | - 'server' => $_SERVER, |
|
999 | - 'env' => $_ENV, |
|
1000 | - 'cookies' => $_COOKIE, |
|
1001 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1002 | - ? $_SERVER['REQUEST_METHOD'] |
|
1003 | - : '', |
|
1004 | - 'urlParams' => $urlParams, |
|
1005 | - ], |
|
1006 | - $this->get(ISecureRandom::class), |
|
1007 | - $this->get(\OCP\IConfig::class), |
|
1008 | - $this->get(CsrfTokenManager::class), |
|
1009 | - $stream |
|
1010 | - ); |
|
1011 | - }); |
|
1012 | - /** @deprecated 19.0.0 */ |
|
1013 | - $this->registerDeprecatedAlias('Request', \OCP\IRequest::class); |
|
1014 | - |
|
1015 | - $this->registerService(IMailer::class, function (Server $c) { |
|
1016 | - return new Mailer( |
|
1017 | - $c->get(\OCP\IConfig::class), |
|
1018 | - $c->get(ILogger::class), |
|
1019 | - $c->get(Defaults::class), |
|
1020 | - $c->get(IURLGenerator::class), |
|
1021 | - $c->getL10N('lib'), |
|
1022 | - $c->get(IEventDispatcher::class), |
|
1023 | - $c->get(IFactory::class) |
|
1024 | - ); |
|
1025 | - }); |
|
1026 | - /** @deprecated 19.0.0 */ |
|
1027 | - $this->registerDeprecatedAlias('Mailer', IMailer::class); |
|
1028 | - |
|
1029 | - /** @deprecated 21.0.0 */ |
|
1030 | - $this->registerDeprecatedAlias('LDAPProvider', ILDAPProvider::class); |
|
1031 | - |
|
1032 | - $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) { |
|
1033 | - $config = $c->get(\OCP\IConfig::class); |
|
1034 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
1035 | - if (is_null($factoryClass)) { |
|
1036 | - return new NullLDAPProviderFactory($this); |
|
1037 | - } |
|
1038 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
1039 | - return new $factoryClass($this); |
|
1040 | - }); |
|
1041 | - $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) { |
|
1042 | - $factory = $c->get(ILDAPProviderFactory::class); |
|
1043 | - return $factory->getLDAPProvider(); |
|
1044 | - }); |
|
1045 | - $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
1046 | - $ini = $c->get(IniGetWrapper::class); |
|
1047 | - $config = $c->get(\OCP\IConfig::class); |
|
1048 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
1049 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
1050 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
1051 | - $memcacheFactory = $c->get(ICacheFactory::class); |
|
1052 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
1053 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
1054 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
1055 | - } |
|
1056 | - return new DBLockingProvider( |
|
1057 | - $c->get(IDBConnection::class), |
|
1058 | - $c->get(ILogger::class), |
|
1059 | - new TimeFactory(), |
|
1060 | - $ttl, |
|
1061 | - !\OC::$CLI |
|
1062 | - ); |
|
1063 | - } |
|
1064 | - return new NoopLockingProvider(); |
|
1065 | - }); |
|
1066 | - /** @deprecated 19.0.0 */ |
|
1067 | - $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class); |
|
1068 | - |
|
1069 | - $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
1070 | - /** @deprecated 19.0.0 */ |
|
1071 | - $this->registerDeprecatedAlias('MountManager', IMountManager::class); |
|
1072 | - |
|
1073 | - $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
1074 | - return new \OC\Files\Type\Detection( |
|
1075 | - $c->get(IURLGenerator::class), |
|
1076 | - $c->get(ILogger::class), |
|
1077 | - \OC::$configDir, |
|
1078 | - \OC::$SERVERROOT . '/resources/config/' |
|
1079 | - ); |
|
1080 | - }); |
|
1081 | - /** @deprecated 19.0.0 */ |
|
1082 | - $this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class); |
|
1083 | - |
|
1084 | - $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
1085 | - /** @deprecated 19.0.0 */ |
|
1086 | - $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class); |
|
1087 | - $this->registerService(BundleFetcher::class, function () { |
|
1088 | - return new BundleFetcher($this->getL10N('lib')); |
|
1089 | - }); |
|
1090 | - $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
1091 | - /** @deprecated 19.0.0 */ |
|
1092 | - $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
1093 | - |
|
1094 | - $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
1095 | - $manager = new CapabilitiesManager($c->get(LoggerInterface::class)); |
|
1096 | - $manager->registerCapability(function () use ($c) { |
|
1097 | - return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
|
1098 | - }); |
|
1099 | - $manager->registerCapability(function () use ($c) { |
|
1100 | - return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
|
1101 | - }); |
|
1102 | - return $manager; |
|
1103 | - }); |
|
1104 | - /** @deprecated 19.0.0 */ |
|
1105 | - $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class); |
|
1106 | - |
|
1107 | - $this->registerService(ICommentsManager::class, function (Server $c) { |
|
1108 | - $config = $c->get(\OCP\IConfig::class); |
|
1109 | - $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
1110 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
1111 | - $factory = new $factoryClass($this); |
|
1112 | - $manager = $factory->getManager(); |
|
1113 | - |
|
1114 | - $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
1115 | - $manager = $c->get(IUserManager::class); |
|
1116 | - $user = $manager->get($id); |
|
1117 | - if (is_null($user)) { |
|
1118 | - $l = $c->getL10N('core'); |
|
1119 | - $displayName = $l->t('Unknown user'); |
|
1120 | - } else { |
|
1121 | - $displayName = $user->getDisplayName(); |
|
1122 | - } |
|
1123 | - return $displayName; |
|
1124 | - }); |
|
1125 | - |
|
1126 | - return $manager; |
|
1127 | - }); |
|
1128 | - /** @deprecated 19.0.0 */ |
|
1129 | - $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class); |
|
1130 | - |
|
1131 | - $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
1132 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
1133 | - /* |
|
263 | + /** @var string */ |
|
264 | + private $webRoot; |
|
265 | + |
|
266 | + /** |
|
267 | + * @param string $webRoot |
|
268 | + * @param \OC\Config $config |
|
269 | + */ |
|
270 | + public function __construct($webRoot, \OC\Config $config) { |
|
271 | + parent::__construct(); |
|
272 | + $this->webRoot = $webRoot; |
|
273 | + |
|
274 | + // To find out if we are running from CLI or not |
|
275 | + $this->registerParameter('isCLI', \OC::$CLI); |
|
276 | + $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
277 | + |
|
278 | + $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
279 | + return $c; |
|
280 | + }); |
|
281 | + $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) { |
|
282 | + return $c; |
|
283 | + }); |
|
284 | + |
|
285 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
286 | + /** @deprecated 19.0.0 */ |
|
287 | + $this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
288 | + |
|
289 | + $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
290 | + /** @deprecated 19.0.0 */ |
|
291 | + $this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
292 | + |
|
293 | + $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
294 | + /** @deprecated 19.0.0 */ |
|
295 | + $this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
296 | + |
|
297 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
298 | + /** @deprecated 19.0.0 */ |
|
299 | + $this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
300 | + |
|
301 | + $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
302 | + $this->registerAlias(ITemplateManager::class, TemplateManager::class); |
|
303 | + |
|
304 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
305 | + |
|
306 | + $this->registerService(View::class, function (Server $c) { |
|
307 | + return new View(); |
|
308 | + }, false); |
|
309 | + |
|
310 | + $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
311 | + return new PreviewManager( |
|
312 | + $c->get(\OCP\IConfig::class), |
|
313 | + $c->get(IRootFolder::class), |
|
314 | + new \OC\Preview\Storage\Root( |
|
315 | + $c->get(IRootFolder::class), |
|
316 | + $c->get(SystemConfig::class) |
|
317 | + ), |
|
318 | + $c->get(SymfonyAdapter::class), |
|
319 | + $c->get(GeneratorHelper::class), |
|
320 | + $c->get(ISession::class)->get('user_id') |
|
321 | + ); |
|
322 | + }); |
|
323 | + /** @deprecated 19.0.0 */ |
|
324 | + $this->registerDeprecatedAlias('PreviewManager', IPreview::class); |
|
325 | + |
|
326 | + $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) { |
|
327 | + return new \OC\Preview\Watcher( |
|
328 | + new \OC\Preview\Storage\Root( |
|
329 | + $c->get(IRootFolder::class), |
|
330 | + $c->get(SystemConfig::class) |
|
331 | + ) |
|
332 | + ); |
|
333 | + }); |
|
334 | + |
|
335 | + $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
336 | + $view = new View(); |
|
337 | + $util = new Encryption\Util( |
|
338 | + $view, |
|
339 | + $c->get(IUserManager::class), |
|
340 | + $c->get(IGroupManager::class), |
|
341 | + $c->get(\OCP\IConfig::class) |
|
342 | + ); |
|
343 | + return new Encryption\Manager( |
|
344 | + $c->get(\OCP\IConfig::class), |
|
345 | + $c->get(ILogger::class), |
|
346 | + $c->getL10N('core'), |
|
347 | + new View(), |
|
348 | + $util, |
|
349 | + new ArrayCache() |
|
350 | + ); |
|
351 | + }); |
|
352 | + /** @deprecated 19.0.0 */ |
|
353 | + $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
354 | + |
|
355 | + /** @deprecated 21.0.0 */ |
|
356 | + $this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class); |
|
357 | + $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
358 | + $util = new Encryption\Util( |
|
359 | + new View(), |
|
360 | + $c->get(IUserManager::class), |
|
361 | + $c->get(IGroupManager::class), |
|
362 | + $c->get(\OCP\IConfig::class) |
|
363 | + ); |
|
364 | + return new Encryption\File( |
|
365 | + $util, |
|
366 | + $c->get(IRootFolder::class), |
|
367 | + $c->get(\OCP\Share\IManager::class) |
|
368 | + ); |
|
369 | + }); |
|
370 | + |
|
371 | + /** @deprecated 21.0.0 */ |
|
372 | + $this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class); |
|
373 | + $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
374 | + $view = new View(); |
|
375 | + $util = new Encryption\Util( |
|
376 | + $view, |
|
377 | + $c->get(IUserManager::class), |
|
378 | + $c->get(IGroupManager::class), |
|
379 | + $c->get(\OCP\IConfig::class) |
|
380 | + ); |
|
381 | + |
|
382 | + return new Encryption\Keys\Storage( |
|
383 | + $view, |
|
384 | + $util, |
|
385 | + $c->get(ICrypto::class), |
|
386 | + $c->get(\OCP\IConfig::class) |
|
387 | + ); |
|
388 | + }); |
|
389 | + /** @deprecated 20.0.0 */ |
|
390 | + $this->registerDeprecatedAlias('TagMapper', TagMapper::class); |
|
391 | + |
|
392 | + $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
393 | + /** @deprecated 19.0.0 */ |
|
394 | + $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class); |
|
395 | + |
|
396 | + $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
397 | + /** @var \OCP\IConfig $config */ |
|
398 | + $config = $c->get(\OCP\IConfig::class); |
|
399 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
400 | + return new $factoryClass($this); |
|
401 | + }); |
|
402 | + $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
403 | + return $c->get('SystemTagManagerFactory')->getManager(); |
|
404 | + }); |
|
405 | + /** @deprecated 19.0.0 */ |
|
406 | + $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
407 | + |
|
408 | + $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
409 | + return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
|
410 | + }); |
|
411 | + $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
412 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
413 | + $view = new View(); |
|
414 | + $root = new Root( |
|
415 | + $manager, |
|
416 | + $view, |
|
417 | + null, |
|
418 | + $c->get(IUserMountCache::class), |
|
419 | + $this->get(ILogger::class), |
|
420 | + $this->get(IUserManager::class) |
|
421 | + ); |
|
422 | + |
|
423 | + $previewConnector = new \OC\Preview\WatcherConnector( |
|
424 | + $root, |
|
425 | + $c->get(SystemConfig::class) |
|
426 | + ); |
|
427 | + $previewConnector->connectWatcher(); |
|
428 | + |
|
429 | + return $root; |
|
430 | + }); |
|
431 | + $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
432 | + return new HookConnector( |
|
433 | + $c->get(IRootFolder::class), |
|
434 | + new View(), |
|
435 | + $c->get(\OC\EventDispatcher\SymfonyAdapter::class), |
|
436 | + $c->get(IEventDispatcher::class) |
|
437 | + ); |
|
438 | + }); |
|
439 | + |
|
440 | + /** @deprecated 19.0.0 */ |
|
441 | + $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class); |
|
442 | + |
|
443 | + $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
444 | + return new LazyRoot(function () use ($c) { |
|
445 | + return $c->get('RootFolder'); |
|
446 | + }); |
|
447 | + }); |
|
448 | + /** @deprecated 19.0.0 */ |
|
449 | + $this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class); |
|
450 | + |
|
451 | + /** @deprecated 19.0.0 */ |
|
452 | + $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class); |
|
453 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
454 | + |
|
455 | + $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
456 | + $groupManager = new \OC\Group\Manager($this->get(IUserManager::class), $c->get(SymfonyAdapter::class), $this->get(ILogger::class)); |
|
457 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
458 | + /** @var IEventDispatcher $dispatcher */ |
|
459 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
460 | + $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid)); |
|
461 | + }); |
|
462 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) { |
|
463 | + /** @var IEventDispatcher $dispatcher */ |
|
464 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
465 | + $dispatcher->dispatchTyped(new GroupCreatedEvent($group)); |
|
466 | + }); |
|
467 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
468 | + /** @var IEventDispatcher $dispatcher */ |
|
469 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
470 | + $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group)); |
|
471 | + }); |
|
472 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
473 | + /** @var IEventDispatcher $dispatcher */ |
|
474 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
475 | + $dispatcher->dispatchTyped(new GroupDeletedEvent($group)); |
|
476 | + }); |
|
477 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
478 | + /** @var IEventDispatcher $dispatcher */ |
|
479 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
480 | + $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user)); |
|
481 | + }); |
|
482 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
483 | + /** @var IEventDispatcher $dispatcher */ |
|
484 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
485 | + $dispatcher->dispatchTyped(new UserAddedEvent($group, $user)); |
|
486 | + }); |
|
487 | + $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
488 | + /** @var IEventDispatcher $dispatcher */ |
|
489 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
490 | + $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user)); |
|
491 | + }); |
|
492 | + $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
493 | + /** @var IEventDispatcher $dispatcher */ |
|
494 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
495 | + $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user)); |
|
496 | + }); |
|
497 | + return $groupManager; |
|
498 | + }); |
|
499 | + /** @deprecated 19.0.0 */ |
|
500 | + $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class); |
|
501 | + |
|
502 | + $this->registerService(Store::class, function (ContainerInterface $c) { |
|
503 | + $session = $c->get(ISession::class); |
|
504 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
505 | + $tokenProvider = $c->get(IProvider::class); |
|
506 | + } else { |
|
507 | + $tokenProvider = null; |
|
508 | + } |
|
509 | + $logger = $c->get(LoggerInterface::class); |
|
510 | + return new Store($session, $logger, $tokenProvider); |
|
511 | + }); |
|
512 | + $this->registerAlias(IStore::class, Store::class); |
|
513 | + $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
514 | + |
|
515 | + $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
516 | + $manager = $c->get(IUserManager::class); |
|
517 | + $session = new \OC\Session\Memory(''); |
|
518 | + $timeFactory = new TimeFactory(); |
|
519 | + // Token providers might require a working database. This code |
|
520 | + // might however be called when ownCloud is not yet setup. |
|
521 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
522 | + $defaultTokenProvider = $c->get(IProvider::class); |
|
523 | + } else { |
|
524 | + $defaultTokenProvider = null; |
|
525 | + } |
|
526 | + |
|
527 | + $legacyDispatcher = $c->get(SymfonyAdapter::class); |
|
528 | + |
|
529 | + $userSession = new \OC\User\Session( |
|
530 | + $manager, |
|
531 | + $session, |
|
532 | + $timeFactory, |
|
533 | + $defaultTokenProvider, |
|
534 | + $c->get(\OCP\IConfig::class), |
|
535 | + $c->get(ISecureRandom::class), |
|
536 | + $c->getLockdownManager(), |
|
537 | + $c->get(ILogger::class), |
|
538 | + $c->get(IEventDispatcher::class) |
|
539 | + ); |
|
540 | + /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
|
541 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
542 | + \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
543 | + }); |
|
544 | + /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
|
545 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
546 | + /** @var \OC\User\User $user */ |
|
547 | + \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
548 | + }); |
|
549 | + /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
|
550 | + $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) { |
|
551 | + /** @var \OC\User\User $user */ |
|
552 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
553 | + $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
554 | + }); |
|
555 | + /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
|
556 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
557 | + /** @var \OC\User\User $user */ |
|
558 | + \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
559 | + }); |
|
560 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
561 | + /** @var \OC\User\User $user */ |
|
562 | + \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
563 | + |
|
564 | + /** @var IEventDispatcher $dispatcher */ |
|
565 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
566 | + $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
567 | + }); |
|
568 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
569 | + /** @var \OC\User\User $user */ |
|
570 | + \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
571 | + |
|
572 | + /** @var IEventDispatcher $dispatcher */ |
|
573 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
574 | + $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
575 | + }); |
|
576 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
577 | + \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
578 | + |
|
579 | + /** @var IEventDispatcher $dispatcher */ |
|
580 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
581 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
582 | + }); |
|
583 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
584 | + /** @var \OC\User\User $user */ |
|
585 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
586 | + |
|
587 | + /** @var IEventDispatcher $dispatcher */ |
|
588 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
589 | + $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin)); |
|
590 | + }); |
|
591 | + $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
592 | + /** @var IEventDispatcher $dispatcher */ |
|
593 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
594 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
595 | + }); |
|
596 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
597 | + /** @var \OC\User\User $user */ |
|
598 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
599 | + |
|
600 | + /** @var IEventDispatcher $dispatcher */ |
|
601 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
602 | + $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
603 | + }); |
|
604 | + $userSession->listen('\OC\User', 'logout', function ($user) { |
|
605 | + \OC_Hook::emit('OC_User', 'logout', []); |
|
606 | + |
|
607 | + /** @var IEventDispatcher $dispatcher */ |
|
608 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
609 | + $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
610 | + }); |
|
611 | + $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
612 | + /** @var IEventDispatcher $dispatcher */ |
|
613 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
614 | + $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
615 | + }); |
|
616 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
617 | + /** @var \OC\User\User $user */ |
|
618 | + \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
619 | + |
|
620 | + /** @var IEventDispatcher $dispatcher */ |
|
621 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
622 | + $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue)); |
|
623 | + }); |
|
624 | + return $userSession; |
|
625 | + }); |
|
626 | + $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
627 | + /** @deprecated 19.0.0 */ |
|
628 | + $this->registerDeprecatedAlias('UserSession', \OC\User\Session::class); |
|
629 | + |
|
630 | + $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
631 | + |
|
632 | + $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
633 | + /** @deprecated 19.0.0 */ |
|
634 | + $this->registerDeprecatedAlias('NavigationManager', INavigationManager::class); |
|
635 | + |
|
636 | + /** @deprecated 19.0.0 */ |
|
637 | + $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class); |
|
638 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
639 | + |
|
640 | + $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
641 | + return new \OC\SystemConfig($config); |
|
642 | + }); |
|
643 | + /** @deprecated 19.0.0 */ |
|
644 | + $this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class); |
|
645 | + |
|
646 | + /** @deprecated 19.0.0 */ |
|
647 | + $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class); |
|
648 | + $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
649 | + |
|
650 | + $this->registerService(IFactory::class, function (Server $c) { |
|
651 | + return new \OC\L10N\Factory( |
|
652 | + $c->get(\OCP\IConfig::class), |
|
653 | + $c->getRequest(), |
|
654 | + $c->get(IUserSession::class), |
|
655 | + \OC::$SERVERROOT |
|
656 | + ); |
|
657 | + }); |
|
658 | + /** @deprecated 19.0.0 */ |
|
659 | + $this->registerDeprecatedAlias('L10NFactory', IFactory::class); |
|
660 | + |
|
661 | + $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
|
662 | + /** @deprecated 19.0.0 */ |
|
663 | + $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class); |
|
664 | + |
|
665 | + /** @deprecated 19.0.0 */ |
|
666 | + $this->registerDeprecatedAlias('AppFetcher', AppFetcher::class); |
|
667 | + /** @deprecated 19.0.0 */ |
|
668 | + $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class); |
|
669 | + |
|
670 | + $this->registerService(ICache::class, function ($c) { |
|
671 | + return new Cache\File(); |
|
672 | + }); |
|
673 | + /** @deprecated 19.0.0 */ |
|
674 | + $this->registerDeprecatedAlias('UserCache', ICache::class); |
|
675 | + |
|
676 | + $this->registerService(Factory::class, function (Server $c) { |
|
677 | + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->get(ILogger::class), |
|
678 | + ArrayCache::class, |
|
679 | + ArrayCache::class, |
|
680 | + ArrayCache::class |
|
681 | + ); |
|
682 | + /** @var \OCP\IConfig $config */ |
|
683 | + $config = $c->get(\OCP\IConfig::class); |
|
684 | + |
|
685 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
686 | + $v = \OC_App::getAppVersions(); |
|
687 | + $v['core'] = implode(',', \OC_Util::getVersion()); |
|
688 | + $version = implode(',', $v); |
|
689 | + $instanceId = \OC_Util::getInstanceId(); |
|
690 | + $path = \OC::$SERVERROOT; |
|
691 | + $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
692 | + return new \OC\Memcache\Factory($prefix, $c->get(ILogger::class), |
|
693 | + $config->getSystemValue('memcache.local', null), |
|
694 | + $config->getSystemValue('memcache.distributed', null), |
|
695 | + $config->getSystemValue('memcache.locking', null) |
|
696 | + ); |
|
697 | + } |
|
698 | + return $arrayCacheFactory; |
|
699 | + }); |
|
700 | + /** @deprecated 19.0.0 */ |
|
701 | + $this->registerDeprecatedAlias('MemCacheFactory', Factory::class); |
|
702 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
703 | + |
|
704 | + $this->registerService('RedisFactory', function (Server $c) { |
|
705 | + $systemConfig = $c->get(SystemConfig::class); |
|
706 | + return new RedisFactory($systemConfig); |
|
707 | + }); |
|
708 | + |
|
709 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
710 | + $l10n = $this->get(IFactory::class)->get('lib'); |
|
711 | + return new \OC\Activity\Manager( |
|
712 | + $c->getRequest(), |
|
713 | + $c->get(IUserSession::class), |
|
714 | + $c->get(\OCP\IConfig::class), |
|
715 | + $c->get(IValidator::class), |
|
716 | + $l10n |
|
717 | + ); |
|
718 | + }); |
|
719 | + /** @deprecated 19.0.0 */ |
|
720 | + $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
721 | + |
|
722 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
723 | + return new \OC\Activity\EventMerger( |
|
724 | + $c->getL10N('lib') |
|
725 | + ); |
|
726 | + }); |
|
727 | + $this->registerAlias(IValidator::class, Validator::class); |
|
728 | + |
|
729 | + $this->registerService(AvatarManager::class, function (Server $c) { |
|
730 | + return new AvatarManager( |
|
731 | + $c->get(IUserSession::class), |
|
732 | + $c->get(\OC\User\Manager::class), |
|
733 | + $c->getAppDataDir('avatar'), |
|
734 | + $c->getL10N('lib'), |
|
735 | + $c->get(LoggerInterface::class), |
|
736 | + $c->get(\OCP\IConfig::class), |
|
737 | + $c->get(IAccountManager::class), |
|
738 | + $c->get(KnownUserService::class) |
|
739 | + ); |
|
740 | + }); |
|
741 | + $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
742 | + /** @deprecated 19.0.0 */ |
|
743 | + $this->registerDeprecatedAlias('AvatarManager', AvatarManager::class); |
|
744 | + |
|
745 | + $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
746 | + $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
747 | + |
|
748 | + $this->registerService(\OC\Log::class, function (Server $c) { |
|
749 | + $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
750 | + $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
|
751 | + $logger = $factory->get($logType); |
|
752 | + $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class); |
|
753 | + |
|
754 | + return new Log($logger, $this->get(SystemConfig::class), null, $registry); |
|
755 | + }); |
|
756 | + $this->registerAlias(ILogger::class, \OC\Log::class); |
|
757 | + /** @deprecated 19.0.0 */ |
|
758 | + $this->registerDeprecatedAlias('Logger', \OC\Log::class); |
|
759 | + // PSR-3 logger |
|
760 | + $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
761 | + |
|
762 | + $this->registerService(ILogFactory::class, function (Server $c) { |
|
763 | + return new LogFactory($c, $this->get(SystemConfig::class)); |
|
764 | + }); |
|
765 | + |
|
766 | + $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
767 | + /** @deprecated 19.0.0 */ |
|
768 | + $this->registerDeprecatedAlias('JobList', IJobList::class); |
|
769 | + |
|
770 | + $this->registerService(Router::class, function (Server $c) { |
|
771 | + $cacheFactory = $c->get(ICacheFactory::class); |
|
772 | + $logger = $c->get(ILogger::class); |
|
773 | + if ($cacheFactory->isLocalCacheAvailable()) { |
|
774 | + $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
775 | + } else { |
|
776 | + $router = new \OC\Route\Router($logger); |
|
777 | + } |
|
778 | + return $router; |
|
779 | + }); |
|
780 | + $this->registerAlias(IRouter::class, Router::class); |
|
781 | + /** @deprecated 19.0.0 */ |
|
782 | + $this->registerDeprecatedAlias('Router', IRouter::class); |
|
783 | + |
|
784 | + $this->registerAlias(ISearch::class, Search::class); |
|
785 | + /** @deprecated 19.0.0 */ |
|
786 | + $this->registerDeprecatedAlias('Search', ISearch::class); |
|
787 | + |
|
788 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
789 | + return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
790 | + $this->get(ICacheFactory::class), |
|
791 | + new \OC\AppFramework\Utility\TimeFactory() |
|
792 | + ); |
|
793 | + }); |
|
794 | + |
|
795 | + $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
796 | + /** @deprecated 19.0.0 */ |
|
797 | + $this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
798 | + |
|
799 | + $this->registerAlias(ICrypto::class, Crypto::class); |
|
800 | + /** @deprecated 19.0.0 */ |
|
801 | + $this->registerDeprecatedAlias('Crypto', ICrypto::class); |
|
802 | + |
|
803 | + $this->registerAlias(IHasher::class, Hasher::class); |
|
804 | + /** @deprecated 19.0.0 */ |
|
805 | + $this->registerDeprecatedAlias('Hasher', IHasher::class); |
|
806 | + |
|
807 | + $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
808 | + /** @deprecated 19.0.0 */ |
|
809 | + $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class); |
|
810 | + |
|
811 | + $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
|
812 | + $this->registerService(Connection::class, function (Server $c) { |
|
813 | + $systemConfig = $c->get(SystemConfig::class); |
|
814 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
815 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
816 | + if (!$factory->isValidType($type)) { |
|
817 | + throw new \OC\DatabaseException('Invalid database type'); |
|
818 | + } |
|
819 | + $connectionParams = $factory->createConnectionParams(); |
|
820 | + $connection = $factory->getConnection($type, $connectionParams); |
|
821 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
822 | + return $connection; |
|
823 | + }); |
|
824 | + /** @deprecated 19.0.0 */ |
|
825 | + $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class); |
|
826 | + |
|
827 | + $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
|
828 | + $this->registerAlias(IClientService::class, ClientService::class); |
|
829 | + $this->registerService(LocalAddressChecker::class, function (ContainerInterface $c) { |
|
830 | + return new LocalAddressChecker( |
|
831 | + $c->get(ILogger::class), |
|
832 | + ); |
|
833 | + }); |
|
834 | + $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) { |
|
835 | + return new NegativeDnsCache( |
|
836 | + $c->get(ICacheFactory::class), |
|
837 | + ); |
|
838 | + }); |
|
839 | + $this->registerService(DnsPinMiddleware::class, function (ContainerInterface $c) { |
|
840 | + return new DnsPinMiddleware( |
|
841 | + $c->get(NegativeDnsCache::class), |
|
842 | + $c->get(LocalAddressChecker::class) |
|
843 | + ); |
|
844 | + }); |
|
845 | + $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
846 | + $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
847 | + $eventLogger = new EventLogger(); |
|
848 | + if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
849 | + // In debug mode, module is being activated by default |
|
850 | + $eventLogger->activate(); |
|
851 | + } |
|
852 | + return $eventLogger; |
|
853 | + }); |
|
854 | + /** @deprecated 19.0.0 */ |
|
855 | + $this->registerDeprecatedAlias('EventLogger', IEventLogger::class); |
|
856 | + |
|
857 | + $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
858 | + $queryLogger = new QueryLogger(); |
|
859 | + if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
860 | + // In debug mode, module is being activated by default |
|
861 | + $queryLogger->activate(); |
|
862 | + } |
|
863 | + return $queryLogger; |
|
864 | + }); |
|
865 | + /** @deprecated 19.0.0 */ |
|
866 | + $this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class); |
|
867 | + |
|
868 | + /** @deprecated 19.0.0 */ |
|
869 | + $this->registerDeprecatedAlias('TempManager', TempManager::class); |
|
870 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
871 | + |
|
872 | + $this->registerService(AppManager::class, function (ContainerInterface $c) { |
|
873 | + // TODO: use auto-wiring |
|
874 | + return new \OC\App\AppManager( |
|
875 | + $c->get(IUserSession::class), |
|
876 | + $c->get(\OCP\IConfig::class), |
|
877 | + $c->get(\OC\AppConfig::class), |
|
878 | + $c->get(IGroupManager::class), |
|
879 | + $c->get(ICacheFactory::class), |
|
880 | + $c->get(SymfonyAdapter::class), |
|
881 | + $c->get(LoggerInterface::class) |
|
882 | + ); |
|
883 | + }); |
|
884 | + /** @deprecated 19.0.0 */ |
|
885 | + $this->registerDeprecatedAlias('AppManager', AppManager::class); |
|
886 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
887 | + |
|
888 | + $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
889 | + /** @deprecated 19.0.0 */ |
|
890 | + $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class); |
|
891 | + |
|
892 | + $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
893 | + $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
|
894 | + |
|
895 | + return new DateTimeFormatter( |
|
896 | + $c->get(IDateTimeZone::class)->getTimeZone(), |
|
897 | + $c->getL10N('lib', $language) |
|
898 | + ); |
|
899 | + }); |
|
900 | + /** @deprecated 19.0.0 */ |
|
901 | + $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class); |
|
902 | + |
|
903 | + $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
904 | + $mountCache = new UserMountCache( |
|
905 | + $c->get(IDBConnection::class), |
|
906 | + $c->get(IUserManager::class), |
|
907 | + $c->get(ILogger::class) |
|
908 | + ); |
|
909 | + $listener = new UserMountCacheListener($mountCache); |
|
910 | + $listener->listen($c->get(IUserManager::class)); |
|
911 | + return $mountCache; |
|
912 | + }); |
|
913 | + /** @deprecated 19.0.0 */ |
|
914 | + $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class); |
|
915 | + |
|
916 | + $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
917 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
918 | + $mountCache = $c->get(IUserMountCache::class); |
|
919 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
920 | + |
|
921 | + // builtin providers |
|
922 | + |
|
923 | + $config = $c->get(\OCP\IConfig::class); |
|
924 | + $logger = $c->get(ILogger::class); |
|
925 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
926 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
927 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
928 | + $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config)); |
|
929 | + |
|
930 | + return $manager; |
|
931 | + }); |
|
932 | + /** @deprecated 19.0.0 */ |
|
933 | + $this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class); |
|
934 | + |
|
935 | + /** @deprecated 20.0.0 */ |
|
936 | + $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class); |
|
937 | + $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
938 | + $busClass = $c->get(\OCP\IConfig::class)->getSystemValue('commandbus'); |
|
939 | + if ($busClass) { |
|
940 | + [$app, $class] = explode('::', $busClass, 2); |
|
941 | + if ($c->get(IAppManager::class)->isInstalled($app)) { |
|
942 | + \OC_App::loadApp($app); |
|
943 | + return $c->get($class); |
|
944 | + } else { |
|
945 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
946 | + } |
|
947 | + } else { |
|
948 | + $jobList = $c->get(IJobList::class); |
|
949 | + return new CronBus($jobList); |
|
950 | + } |
|
951 | + }); |
|
952 | + $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class); |
|
953 | + /** @deprecated 20.0.0 */ |
|
954 | + $this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class); |
|
955 | + /** @deprecated 19.0.0 */ |
|
956 | + $this->registerDeprecatedAlias('Throttler', Throttler::class); |
|
957 | + $this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) { |
|
958 | + // IConfig and IAppManager requires a working database. This code |
|
959 | + // might however be called when ownCloud is not yet setup. |
|
960 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
961 | + $config = $c->get(\OCP\IConfig::class); |
|
962 | + $appManager = $c->get(IAppManager::class); |
|
963 | + } else { |
|
964 | + $config = null; |
|
965 | + $appManager = null; |
|
966 | + } |
|
967 | + |
|
968 | + return new Checker( |
|
969 | + new EnvironmentHelper(), |
|
970 | + new FileAccessHelper(), |
|
971 | + new AppLocator(), |
|
972 | + $config, |
|
973 | + $c->get(ICacheFactory::class), |
|
974 | + $appManager, |
|
975 | + $c->get(IMimeTypeDetector::class) |
|
976 | + ); |
|
977 | + }); |
|
978 | + $this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) { |
|
979 | + if (isset($this['urlParams'])) { |
|
980 | + $urlParams = $this['urlParams']; |
|
981 | + } else { |
|
982 | + $urlParams = []; |
|
983 | + } |
|
984 | + |
|
985 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
986 | + && in_array('fakeinput', stream_get_wrappers()) |
|
987 | + ) { |
|
988 | + $stream = 'fakeinput://data'; |
|
989 | + } else { |
|
990 | + $stream = 'php://input'; |
|
991 | + } |
|
992 | + |
|
993 | + return new Request( |
|
994 | + [ |
|
995 | + 'get' => $_GET, |
|
996 | + 'post' => $_POST, |
|
997 | + 'files' => $_FILES, |
|
998 | + 'server' => $_SERVER, |
|
999 | + 'env' => $_ENV, |
|
1000 | + 'cookies' => $_COOKIE, |
|
1001 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1002 | + ? $_SERVER['REQUEST_METHOD'] |
|
1003 | + : '', |
|
1004 | + 'urlParams' => $urlParams, |
|
1005 | + ], |
|
1006 | + $this->get(ISecureRandom::class), |
|
1007 | + $this->get(\OCP\IConfig::class), |
|
1008 | + $this->get(CsrfTokenManager::class), |
|
1009 | + $stream |
|
1010 | + ); |
|
1011 | + }); |
|
1012 | + /** @deprecated 19.0.0 */ |
|
1013 | + $this->registerDeprecatedAlias('Request', \OCP\IRequest::class); |
|
1014 | + |
|
1015 | + $this->registerService(IMailer::class, function (Server $c) { |
|
1016 | + return new Mailer( |
|
1017 | + $c->get(\OCP\IConfig::class), |
|
1018 | + $c->get(ILogger::class), |
|
1019 | + $c->get(Defaults::class), |
|
1020 | + $c->get(IURLGenerator::class), |
|
1021 | + $c->getL10N('lib'), |
|
1022 | + $c->get(IEventDispatcher::class), |
|
1023 | + $c->get(IFactory::class) |
|
1024 | + ); |
|
1025 | + }); |
|
1026 | + /** @deprecated 19.0.0 */ |
|
1027 | + $this->registerDeprecatedAlias('Mailer', IMailer::class); |
|
1028 | + |
|
1029 | + /** @deprecated 21.0.0 */ |
|
1030 | + $this->registerDeprecatedAlias('LDAPProvider', ILDAPProvider::class); |
|
1031 | + |
|
1032 | + $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) { |
|
1033 | + $config = $c->get(\OCP\IConfig::class); |
|
1034 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
1035 | + if (is_null($factoryClass)) { |
|
1036 | + return new NullLDAPProviderFactory($this); |
|
1037 | + } |
|
1038 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
1039 | + return new $factoryClass($this); |
|
1040 | + }); |
|
1041 | + $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) { |
|
1042 | + $factory = $c->get(ILDAPProviderFactory::class); |
|
1043 | + return $factory->getLDAPProvider(); |
|
1044 | + }); |
|
1045 | + $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
1046 | + $ini = $c->get(IniGetWrapper::class); |
|
1047 | + $config = $c->get(\OCP\IConfig::class); |
|
1048 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
1049 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
1050 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
1051 | + $memcacheFactory = $c->get(ICacheFactory::class); |
|
1052 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
1053 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
1054 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
1055 | + } |
|
1056 | + return new DBLockingProvider( |
|
1057 | + $c->get(IDBConnection::class), |
|
1058 | + $c->get(ILogger::class), |
|
1059 | + new TimeFactory(), |
|
1060 | + $ttl, |
|
1061 | + !\OC::$CLI |
|
1062 | + ); |
|
1063 | + } |
|
1064 | + return new NoopLockingProvider(); |
|
1065 | + }); |
|
1066 | + /** @deprecated 19.0.0 */ |
|
1067 | + $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class); |
|
1068 | + |
|
1069 | + $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
1070 | + /** @deprecated 19.0.0 */ |
|
1071 | + $this->registerDeprecatedAlias('MountManager', IMountManager::class); |
|
1072 | + |
|
1073 | + $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
1074 | + return new \OC\Files\Type\Detection( |
|
1075 | + $c->get(IURLGenerator::class), |
|
1076 | + $c->get(ILogger::class), |
|
1077 | + \OC::$configDir, |
|
1078 | + \OC::$SERVERROOT . '/resources/config/' |
|
1079 | + ); |
|
1080 | + }); |
|
1081 | + /** @deprecated 19.0.0 */ |
|
1082 | + $this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class); |
|
1083 | + |
|
1084 | + $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
1085 | + /** @deprecated 19.0.0 */ |
|
1086 | + $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class); |
|
1087 | + $this->registerService(BundleFetcher::class, function () { |
|
1088 | + return new BundleFetcher($this->getL10N('lib')); |
|
1089 | + }); |
|
1090 | + $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
1091 | + /** @deprecated 19.0.0 */ |
|
1092 | + $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
1093 | + |
|
1094 | + $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
1095 | + $manager = new CapabilitiesManager($c->get(LoggerInterface::class)); |
|
1096 | + $manager->registerCapability(function () use ($c) { |
|
1097 | + return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
|
1098 | + }); |
|
1099 | + $manager->registerCapability(function () use ($c) { |
|
1100 | + return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
|
1101 | + }); |
|
1102 | + return $manager; |
|
1103 | + }); |
|
1104 | + /** @deprecated 19.0.0 */ |
|
1105 | + $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class); |
|
1106 | + |
|
1107 | + $this->registerService(ICommentsManager::class, function (Server $c) { |
|
1108 | + $config = $c->get(\OCP\IConfig::class); |
|
1109 | + $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
1110 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
1111 | + $factory = new $factoryClass($this); |
|
1112 | + $manager = $factory->getManager(); |
|
1113 | + |
|
1114 | + $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
1115 | + $manager = $c->get(IUserManager::class); |
|
1116 | + $user = $manager->get($id); |
|
1117 | + if (is_null($user)) { |
|
1118 | + $l = $c->getL10N('core'); |
|
1119 | + $displayName = $l->t('Unknown user'); |
|
1120 | + } else { |
|
1121 | + $displayName = $user->getDisplayName(); |
|
1122 | + } |
|
1123 | + return $displayName; |
|
1124 | + }); |
|
1125 | + |
|
1126 | + return $manager; |
|
1127 | + }); |
|
1128 | + /** @deprecated 19.0.0 */ |
|
1129 | + $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class); |
|
1130 | + |
|
1131 | + $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
1132 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
1133 | + /* |
|
1134 | 1134 | * Dark magic for autoloader. |
1135 | 1135 | * If we do a class_exists it will try to load the class which will |
1136 | 1136 | * make composer cache the result. Resulting in errors when enabling |
1137 | 1137 | * the theming app. |
1138 | 1138 | */ |
1139 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
1140 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
1141 | - $classExists = true; |
|
1142 | - } else { |
|
1143 | - $classExists = false; |
|
1144 | - } |
|
1145 | - |
|
1146 | - if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValue('installed', false) && $c->get(IAppManager::class)->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
1147 | - return new ThemingDefaults( |
|
1148 | - $c->get(\OCP\IConfig::class), |
|
1149 | - $c->getL10N('theming'), |
|
1150 | - $c->get(IURLGenerator::class), |
|
1151 | - $c->get(ICacheFactory::class), |
|
1152 | - new Util($c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming')), |
|
1153 | - new ImageManager( |
|
1154 | - $c->get(\OCP\IConfig::class), |
|
1155 | - $c->getAppDataDir('theming'), |
|
1156 | - $c->get(IURLGenerator::class), |
|
1157 | - $this->get(ICacheFactory::class), |
|
1158 | - $this->get(ILogger::class), |
|
1159 | - $this->get(ITempManager::class) |
|
1160 | - ), |
|
1161 | - $c->get(IAppManager::class), |
|
1162 | - $c->get(INavigationManager::class) |
|
1163 | - ); |
|
1164 | - } |
|
1165 | - return new \OC_Defaults(); |
|
1166 | - }); |
|
1167 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
1168 | - return new JSCombiner( |
|
1169 | - $c->getAppDataDir('js'), |
|
1170 | - $c->get(IURLGenerator::class), |
|
1171 | - $this->get(ICacheFactory::class), |
|
1172 | - $c->get(SystemConfig::class), |
|
1173 | - $c->get(ILogger::class) |
|
1174 | - ); |
|
1175 | - }); |
|
1176 | - $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
1177 | - /** @deprecated 19.0.0 */ |
|
1178 | - $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
|
1179 | - $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
|
1180 | - |
|
1181 | - $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
1182 | - // FIXME: Instantiiated here due to cyclic dependency |
|
1183 | - $request = new Request( |
|
1184 | - [ |
|
1185 | - 'get' => $_GET, |
|
1186 | - 'post' => $_POST, |
|
1187 | - 'files' => $_FILES, |
|
1188 | - 'server' => $_SERVER, |
|
1189 | - 'env' => $_ENV, |
|
1190 | - 'cookies' => $_COOKIE, |
|
1191 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1192 | - ? $_SERVER['REQUEST_METHOD'] |
|
1193 | - : null, |
|
1194 | - ], |
|
1195 | - $c->get(ISecureRandom::class), |
|
1196 | - $c->get(\OCP\IConfig::class) |
|
1197 | - ); |
|
1198 | - |
|
1199 | - return new CryptoWrapper( |
|
1200 | - $c->get(\OCP\IConfig::class), |
|
1201 | - $c->get(ICrypto::class), |
|
1202 | - $c->get(ISecureRandom::class), |
|
1203 | - $request |
|
1204 | - ); |
|
1205 | - }); |
|
1206 | - /** @deprecated 19.0.0 */ |
|
1207 | - $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class); |
|
1208 | - $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
1209 | - return new SessionStorage($c->get(ISession::class)); |
|
1210 | - }); |
|
1211 | - $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
1212 | - /** @deprecated 19.0.0 */ |
|
1213 | - $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class); |
|
1214 | - |
|
1215 | - $this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) { |
|
1216 | - $config = $c->get(\OCP\IConfig::class); |
|
1217 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1218 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
1219 | - $factory = new $factoryClass($this); |
|
1220 | - |
|
1221 | - $manager = new \OC\Share20\Manager( |
|
1222 | - $c->get(ILogger::class), |
|
1223 | - $c->get(\OCP\IConfig::class), |
|
1224 | - $c->get(ISecureRandom::class), |
|
1225 | - $c->get(IHasher::class), |
|
1226 | - $c->get(IMountManager::class), |
|
1227 | - $c->get(IGroupManager::class), |
|
1228 | - $c->getL10N('lib'), |
|
1229 | - $c->get(IFactory::class), |
|
1230 | - $factory, |
|
1231 | - $c->get(IUserManager::class), |
|
1232 | - $c->get(IRootFolder::class), |
|
1233 | - $c->get(SymfonyAdapter::class), |
|
1234 | - $c->get(IMailer::class), |
|
1235 | - $c->get(IURLGenerator::class), |
|
1236 | - $c->get('ThemingDefaults'), |
|
1237 | - $c->get(IEventDispatcher::class), |
|
1238 | - $c->get(IUserSession::class) |
|
1239 | - ); |
|
1240 | - |
|
1241 | - return $manager; |
|
1242 | - }); |
|
1243 | - /** @deprecated 19.0.0 */ |
|
1244 | - $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class); |
|
1245 | - |
|
1246 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
1247 | - $instance = new Collaboration\Collaborators\Search($c); |
|
1248 | - |
|
1249 | - // register default plugins |
|
1250 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1251 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1252 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1253 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1254 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
1255 | - |
|
1256 | - return $instance; |
|
1257 | - }); |
|
1258 | - /** @deprecated 19.0.0 */ |
|
1259 | - $this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1260 | - $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
1261 | - |
|
1262 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1263 | - |
|
1264 | - $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
1265 | - $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
1266 | - |
|
1267 | - $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
|
1268 | - $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
|
1269 | - $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
1270 | - return new \OC\Files\AppData\Factory( |
|
1271 | - $c->get(IRootFolder::class), |
|
1272 | - $c->get(SystemConfig::class) |
|
1273 | - ); |
|
1274 | - }); |
|
1275 | - |
|
1276 | - $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
1277 | - return new LockdownManager(function () use ($c) { |
|
1278 | - return $c->get(ISession::class); |
|
1279 | - }); |
|
1280 | - }); |
|
1281 | - |
|
1282 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
1283 | - return new DiscoveryService( |
|
1284 | - $c->get(ICacheFactory::class), |
|
1285 | - $c->get(IClientService::class) |
|
1286 | - ); |
|
1287 | - }); |
|
1288 | - |
|
1289 | - $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
1290 | - return new CloudIdManager($c->get(\OCP\Contacts\IManager::class)); |
|
1291 | - }); |
|
1292 | - |
|
1293 | - $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
1294 | - |
|
1295 | - $this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) { |
|
1296 | - return new CloudFederationProviderManager( |
|
1297 | - $c->get(IAppManager::class), |
|
1298 | - $c->get(IClientService::class), |
|
1299 | - $c->get(ICloudIdManager::class), |
|
1300 | - $c->get(ILogger::class) |
|
1301 | - ); |
|
1302 | - }); |
|
1303 | - |
|
1304 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1305 | - return new CloudFederationFactory(); |
|
1306 | - }); |
|
1307 | - |
|
1308 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1309 | - /** @deprecated 19.0.0 */ |
|
1310 | - $this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1311 | - |
|
1312 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1313 | - /** @deprecated 19.0.0 */ |
|
1314 | - $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1315 | - |
|
1316 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1317 | - return new Defaults( |
|
1318 | - $c->getThemingDefaults() |
|
1319 | - ); |
|
1320 | - }); |
|
1321 | - /** @deprecated 19.0.0 */ |
|
1322 | - $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class); |
|
1323 | - |
|
1324 | - $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
1325 | - return $c->get(\OCP\IUserSession::class)->getSession(); |
|
1326 | - }, false); |
|
1327 | - |
|
1328 | - $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
1329 | - return new ShareHelper( |
|
1330 | - $c->get(\OCP\Share\IManager::class) |
|
1331 | - ); |
|
1332 | - }); |
|
1333 | - |
|
1334 | - $this->registerService(Installer::class, function (ContainerInterface $c) { |
|
1335 | - return new Installer( |
|
1336 | - $c->get(AppFetcher::class), |
|
1337 | - $c->get(IClientService::class), |
|
1338 | - $c->get(ITempManager::class), |
|
1339 | - $c->get(LoggerInterface::class), |
|
1340 | - $c->get(\OCP\IConfig::class), |
|
1341 | - \OC::$CLI |
|
1342 | - ); |
|
1343 | - }); |
|
1344 | - |
|
1345 | - $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
1346 | - return new ApiFactory($c->get(IClientService::class)); |
|
1347 | - }); |
|
1348 | - |
|
1349 | - $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
1350 | - $memcacheFactory = $c->get(ICacheFactory::class); |
|
1351 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
|
1352 | - }); |
|
1353 | - |
|
1354 | - $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1355 | - $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
1356 | - |
|
1357 | - $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
1358 | - |
|
1359 | - $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
|
1360 | - $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
1361 | - $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
1362 | - |
|
1363 | - $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
1364 | - |
|
1365 | - $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
1366 | - |
|
1367 | - $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
1368 | - |
|
1369 | - $this->connectDispatcher(); |
|
1370 | - } |
|
1371 | - |
|
1372 | - public function boot() { |
|
1373 | - /** @var HookConnector $hookConnector */ |
|
1374 | - $hookConnector = $this->get(HookConnector::class); |
|
1375 | - $hookConnector->viewToNode(); |
|
1376 | - } |
|
1377 | - |
|
1378 | - /** |
|
1379 | - * @return \OCP\Calendar\IManager |
|
1380 | - * @deprecated 20.0.0 |
|
1381 | - */ |
|
1382 | - public function getCalendarManager() { |
|
1383 | - return $this->get(\OC\Calendar\Manager::class); |
|
1384 | - } |
|
1385 | - |
|
1386 | - /** |
|
1387 | - * @return \OCP\Calendar\Resource\IManager |
|
1388 | - * @deprecated 20.0.0 |
|
1389 | - */ |
|
1390 | - public function getCalendarResourceBackendManager() { |
|
1391 | - return $this->get(\OC\Calendar\Resource\Manager::class); |
|
1392 | - } |
|
1393 | - |
|
1394 | - /** |
|
1395 | - * @return \OCP\Calendar\Room\IManager |
|
1396 | - * @deprecated 20.0.0 |
|
1397 | - */ |
|
1398 | - public function getCalendarRoomBackendManager() { |
|
1399 | - return $this->get(\OC\Calendar\Room\Manager::class); |
|
1400 | - } |
|
1401 | - |
|
1402 | - private function connectDispatcher() { |
|
1403 | - $dispatcher = $this->get(SymfonyAdapter::class); |
|
1404 | - |
|
1405 | - // Delete avatar on user deletion |
|
1406 | - $dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) { |
|
1407 | - $logger = $this->get(ILogger::class); |
|
1408 | - $manager = $this->getAvatarManager(); |
|
1409 | - /** @var IUser $user */ |
|
1410 | - $user = $e->getSubject(); |
|
1411 | - |
|
1412 | - try { |
|
1413 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1414 | - $avatar->remove(); |
|
1415 | - } catch (NotFoundException $e) { |
|
1416 | - // no avatar to remove |
|
1417 | - } catch (\Exception $e) { |
|
1418 | - // Ignore exceptions |
|
1419 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1420 | - } |
|
1421 | - }); |
|
1422 | - |
|
1423 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1424 | - $manager = $this->getAvatarManager(); |
|
1425 | - /** @var IUser $user */ |
|
1426 | - $user = $e->getSubject(); |
|
1427 | - $feature = $e->getArgument('feature'); |
|
1428 | - $oldValue = $e->getArgument('oldValue'); |
|
1429 | - $value = $e->getArgument('value'); |
|
1430 | - |
|
1431 | - // We only change the avatar on display name changes |
|
1432 | - if ($feature !== 'displayName') { |
|
1433 | - return; |
|
1434 | - } |
|
1435 | - |
|
1436 | - try { |
|
1437 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1438 | - $avatar->userChanged($feature, $oldValue, $value); |
|
1439 | - } catch (NotFoundException $e) { |
|
1440 | - // no avatar to remove |
|
1441 | - } |
|
1442 | - }); |
|
1443 | - |
|
1444 | - /** @var IEventDispatcher $eventDispatched */ |
|
1445 | - $eventDispatched = $this->get(IEventDispatcher::class); |
|
1446 | - $eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
1447 | - $eventDispatched->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class); |
|
1448 | - } |
|
1449 | - |
|
1450 | - /** |
|
1451 | - * @return \OCP\Contacts\IManager |
|
1452 | - * @deprecated 20.0.0 |
|
1453 | - */ |
|
1454 | - public function getContactsManager() { |
|
1455 | - return $this->get(\OCP\Contacts\IManager::class); |
|
1456 | - } |
|
1457 | - |
|
1458 | - /** |
|
1459 | - * @return \OC\Encryption\Manager |
|
1460 | - * @deprecated 20.0.0 |
|
1461 | - */ |
|
1462 | - public function getEncryptionManager() { |
|
1463 | - return $this->get(\OCP\Encryption\IManager::class); |
|
1464 | - } |
|
1465 | - |
|
1466 | - /** |
|
1467 | - * @return \OC\Encryption\File |
|
1468 | - * @deprecated 20.0.0 |
|
1469 | - */ |
|
1470 | - public function getEncryptionFilesHelper() { |
|
1471 | - return $this->get(IFile::class); |
|
1472 | - } |
|
1473 | - |
|
1474 | - /** |
|
1475 | - * @return \OCP\Encryption\Keys\IStorage |
|
1476 | - * @deprecated 20.0.0 |
|
1477 | - */ |
|
1478 | - public function getEncryptionKeyStorage() { |
|
1479 | - return $this->get(IStorage::class); |
|
1480 | - } |
|
1481 | - |
|
1482 | - /** |
|
1483 | - * The current request object holding all information about the request |
|
1484 | - * currently being processed is returned from this method. |
|
1485 | - * In case the current execution was not initiated by a web request null is returned |
|
1486 | - * |
|
1487 | - * @return \OCP\IRequest |
|
1488 | - * @deprecated 20.0.0 |
|
1489 | - */ |
|
1490 | - public function getRequest() { |
|
1491 | - return $this->get(IRequest::class); |
|
1492 | - } |
|
1493 | - |
|
1494 | - /** |
|
1495 | - * Returns the preview manager which can create preview images for a given file |
|
1496 | - * |
|
1497 | - * @return IPreview |
|
1498 | - * @deprecated 20.0.0 |
|
1499 | - */ |
|
1500 | - public function getPreviewManager() { |
|
1501 | - return $this->get(IPreview::class); |
|
1502 | - } |
|
1503 | - |
|
1504 | - /** |
|
1505 | - * Returns the tag manager which can get and set tags for different object types |
|
1506 | - * |
|
1507 | - * @see \OCP\ITagManager::load() |
|
1508 | - * @return ITagManager |
|
1509 | - * @deprecated 20.0.0 |
|
1510 | - */ |
|
1511 | - public function getTagManager() { |
|
1512 | - return $this->get(ITagManager::class); |
|
1513 | - } |
|
1514 | - |
|
1515 | - /** |
|
1516 | - * Returns the system-tag manager |
|
1517 | - * |
|
1518 | - * @return ISystemTagManager |
|
1519 | - * |
|
1520 | - * @since 9.0.0 |
|
1521 | - * @deprecated 20.0.0 |
|
1522 | - */ |
|
1523 | - public function getSystemTagManager() { |
|
1524 | - return $this->get(ISystemTagManager::class); |
|
1525 | - } |
|
1526 | - |
|
1527 | - /** |
|
1528 | - * Returns the system-tag object mapper |
|
1529 | - * |
|
1530 | - * @return ISystemTagObjectMapper |
|
1531 | - * |
|
1532 | - * @since 9.0.0 |
|
1533 | - * @deprecated 20.0.0 |
|
1534 | - */ |
|
1535 | - public function getSystemTagObjectMapper() { |
|
1536 | - return $this->get(ISystemTagObjectMapper::class); |
|
1537 | - } |
|
1538 | - |
|
1539 | - /** |
|
1540 | - * Returns the avatar manager, used for avatar functionality |
|
1541 | - * |
|
1542 | - * @return IAvatarManager |
|
1543 | - * @deprecated 20.0.0 |
|
1544 | - */ |
|
1545 | - public function getAvatarManager() { |
|
1546 | - return $this->get(IAvatarManager::class); |
|
1547 | - } |
|
1548 | - |
|
1549 | - /** |
|
1550 | - * Returns the root folder of ownCloud's data directory |
|
1551 | - * |
|
1552 | - * @return IRootFolder |
|
1553 | - * @deprecated 20.0.0 |
|
1554 | - */ |
|
1555 | - public function getRootFolder() { |
|
1556 | - return $this->get(IRootFolder::class); |
|
1557 | - } |
|
1558 | - |
|
1559 | - /** |
|
1560 | - * Returns the root folder of ownCloud's data directory |
|
1561 | - * This is the lazy variant so this gets only initialized once it |
|
1562 | - * is actually used. |
|
1563 | - * |
|
1564 | - * @return IRootFolder |
|
1565 | - * @deprecated 20.0.0 |
|
1566 | - */ |
|
1567 | - public function getLazyRootFolder() { |
|
1568 | - return $this->get(IRootFolder::class); |
|
1569 | - } |
|
1570 | - |
|
1571 | - /** |
|
1572 | - * Returns a view to ownCloud's files folder |
|
1573 | - * |
|
1574 | - * @param string $userId user ID |
|
1575 | - * @return \OCP\Files\Folder|null |
|
1576 | - * @deprecated 20.0.0 |
|
1577 | - */ |
|
1578 | - public function getUserFolder($userId = null) { |
|
1579 | - if ($userId === null) { |
|
1580 | - $user = $this->get(IUserSession::class)->getUser(); |
|
1581 | - if (!$user) { |
|
1582 | - return null; |
|
1583 | - } |
|
1584 | - $userId = $user->getUID(); |
|
1585 | - } |
|
1586 | - $root = $this->get(IRootFolder::class); |
|
1587 | - return $root->getUserFolder($userId); |
|
1588 | - } |
|
1589 | - |
|
1590 | - /** |
|
1591 | - * @return \OC\User\Manager |
|
1592 | - * @deprecated 20.0.0 |
|
1593 | - */ |
|
1594 | - public function getUserManager() { |
|
1595 | - return $this->get(IUserManager::class); |
|
1596 | - } |
|
1597 | - |
|
1598 | - /** |
|
1599 | - * @return \OC\Group\Manager |
|
1600 | - * @deprecated 20.0.0 |
|
1601 | - */ |
|
1602 | - public function getGroupManager() { |
|
1603 | - return $this->get(IGroupManager::class); |
|
1604 | - } |
|
1605 | - |
|
1606 | - /** |
|
1607 | - * @return \OC\User\Session |
|
1608 | - * @deprecated 20.0.0 |
|
1609 | - */ |
|
1610 | - public function getUserSession() { |
|
1611 | - return $this->get(IUserSession::class); |
|
1612 | - } |
|
1613 | - |
|
1614 | - /** |
|
1615 | - * @return \OCP\ISession |
|
1616 | - * @deprecated 20.0.0 |
|
1617 | - */ |
|
1618 | - public function getSession() { |
|
1619 | - return $this->get(IUserSession::class)->getSession(); |
|
1620 | - } |
|
1621 | - |
|
1622 | - /** |
|
1623 | - * @param \OCP\ISession $session |
|
1624 | - */ |
|
1625 | - public function setSession(\OCP\ISession $session) { |
|
1626 | - $this->get(SessionStorage::class)->setSession($session); |
|
1627 | - $this->get(IUserSession::class)->setSession($session); |
|
1628 | - $this->get(Store::class)->setSession($session); |
|
1629 | - } |
|
1630 | - |
|
1631 | - /** |
|
1632 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1633 | - * @deprecated 20.0.0 |
|
1634 | - */ |
|
1635 | - public function getTwoFactorAuthManager() { |
|
1636 | - return $this->get(\OC\Authentication\TwoFactorAuth\Manager::class); |
|
1637 | - } |
|
1638 | - |
|
1639 | - /** |
|
1640 | - * @return \OC\NavigationManager |
|
1641 | - * @deprecated 20.0.0 |
|
1642 | - */ |
|
1643 | - public function getNavigationManager() { |
|
1644 | - return $this->get(INavigationManager::class); |
|
1645 | - } |
|
1646 | - |
|
1647 | - /** |
|
1648 | - * @return \OCP\IConfig |
|
1649 | - * @deprecated 20.0.0 |
|
1650 | - */ |
|
1651 | - public function getConfig() { |
|
1652 | - return $this->get(AllConfig::class); |
|
1653 | - } |
|
1654 | - |
|
1655 | - /** |
|
1656 | - * @return \OC\SystemConfig |
|
1657 | - * @deprecated 20.0.0 |
|
1658 | - */ |
|
1659 | - public function getSystemConfig() { |
|
1660 | - return $this->get(SystemConfig::class); |
|
1661 | - } |
|
1662 | - |
|
1663 | - /** |
|
1664 | - * Returns the app config manager |
|
1665 | - * |
|
1666 | - * @return IAppConfig |
|
1667 | - * @deprecated 20.0.0 |
|
1668 | - */ |
|
1669 | - public function getAppConfig() { |
|
1670 | - return $this->get(IAppConfig::class); |
|
1671 | - } |
|
1672 | - |
|
1673 | - /** |
|
1674 | - * @return IFactory |
|
1675 | - * @deprecated 20.0.0 |
|
1676 | - */ |
|
1677 | - public function getL10NFactory() { |
|
1678 | - return $this->get(IFactory::class); |
|
1679 | - } |
|
1680 | - |
|
1681 | - /** |
|
1682 | - * get an L10N instance |
|
1683 | - * |
|
1684 | - * @param string $app appid |
|
1685 | - * @param string $lang |
|
1686 | - * @return IL10N |
|
1687 | - * @deprecated 20.0.0 |
|
1688 | - */ |
|
1689 | - public function getL10N($app, $lang = null) { |
|
1690 | - return $this->get(IFactory::class)->get($app, $lang); |
|
1691 | - } |
|
1692 | - |
|
1693 | - /** |
|
1694 | - * @return IURLGenerator |
|
1695 | - * @deprecated 20.0.0 |
|
1696 | - */ |
|
1697 | - public function getURLGenerator() { |
|
1698 | - return $this->get(IURLGenerator::class); |
|
1699 | - } |
|
1700 | - |
|
1701 | - /** |
|
1702 | - * @return AppFetcher |
|
1703 | - * @deprecated 20.0.0 |
|
1704 | - */ |
|
1705 | - public function getAppFetcher() { |
|
1706 | - return $this->get(AppFetcher::class); |
|
1707 | - } |
|
1708 | - |
|
1709 | - /** |
|
1710 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1711 | - * getMemCacheFactory() instead. |
|
1712 | - * |
|
1713 | - * @return ICache |
|
1714 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1715 | - */ |
|
1716 | - public function getCache() { |
|
1717 | - return $this->get(ICache::class); |
|
1718 | - } |
|
1719 | - |
|
1720 | - /** |
|
1721 | - * Returns an \OCP\CacheFactory instance |
|
1722 | - * |
|
1723 | - * @return \OCP\ICacheFactory |
|
1724 | - * @deprecated 20.0.0 |
|
1725 | - */ |
|
1726 | - public function getMemCacheFactory() { |
|
1727 | - return $this->get(ICacheFactory::class); |
|
1728 | - } |
|
1729 | - |
|
1730 | - /** |
|
1731 | - * Returns an \OC\RedisFactory instance |
|
1732 | - * |
|
1733 | - * @return \OC\RedisFactory |
|
1734 | - * @deprecated 20.0.0 |
|
1735 | - */ |
|
1736 | - public function getGetRedisFactory() { |
|
1737 | - return $this->get('RedisFactory'); |
|
1738 | - } |
|
1739 | - |
|
1740 | - |
|
1741 | - /** |
|
1742 | - * Returns the current session |
|
1743 | - * |
|
1744 | - * @return \OCP\IDBConnection |
|
1745 | - * @deprecated 20.0.0 |
|
1746 | - */ |
|
1747 | - public function getDatabaseConnection() { |
|
1748 | - return $this->get(IDBConnection::class); |
|
1749 | - } |
|
1750 | - |
|
1751 | - /** |
|
1752 | - * Returns the activity manager |
|
1753 | - * |
|
1754 | - * @return \OCP\Activity\IManager |
|
1755 | - * @deprecated 20.0.0 |
|
1756 | - */ |
|
1757 | - public function getActivityManager() { |
|
1758 | - return $this->get(\OCP\Activity\IManager::class); |
|
1759 | - } |
|
1760 | - |
|
1761 | - /** |
|
1762 | - * Returns an job list for controlling background jobs |
|
1763 | - * |
|
1764 | - * @return IJobList |
|
1765 | - * @deprecated 20.0.0 |
|
1766 | - */ |
|
1767 | - public function getJobList() { |
|
1768 | - return $this->get(IJobList::class); |
|
1769 | - } |
|
1770 | - |
|
1771 | - /** |
|
1772 | - * Returns a logger instance |
|
1773 | - * |
|
1774 | - * @return ILogger |
|
1775 | - * @deprecated 20.0.0 |
|
1776 | - */ |
|
1777 | - public function getLogger() { |
|
1778 | - return $this->get(ILogger::class); |
|
1779 | - } |
|
1780 | - |
|
1781 | - /** |
|
1782 | - * @return ILogFactory |
|
1783 | - * @throws \OCP\AppFramework\QueryException |
|
1784 | - * @deprecated 20.0.0 |
|
1785 | - */ |
|
1786 | - public function getLogFactory() { |
|
1787 | - return $this->get(ILogFactory::class); |
|
1788 | - } |
|
1789 | - |
|
1790 | - /** |
|
1791 | - * Returns a router for generating and matching urls |
|
1792 | - * |
|
1793 | - * @return IRouter |
|
1794 | - * @deprecated 20.0.0 |
|
1795 | - */ |
|
1796 | - public function getRouter() { |
|
1797 | - return $this->get(IRouter::class); |
|
1798 | - } |
|
1799 | - |
|
1800 | - /** |
|
1801 | - * Returns a search instance |
|
1802 | - * |
|
1803 | - * @return ISearch |
|
1804 | - * @deprecated 20.0.0 |
|
1805 | - */ |
|
1806 | - public function getSearch() { |
|
1807 | - return $this->get(ISearch::class); |
|
1808 | - } |
|
1809 | - |
|
1810 | - /** |
|
1811 | - * Returns a SecureRandom instance |
|
1812 | - * |
|
1813 | - * @return \OCP\Security\ISecureRandom |
|
1814 | - * @deprecated 20.0.0 |
|
1815 | - */ |
|
1816 | - public function getSecureRandom() { |
|
1817 | - return $this->get(ISecureRandom::class); |
|
1818 | - } |
|
1819 | - |
|
1820 | - /** |
|
1821 | - * Returns a Crypto instance |
|
1822 | - * |
|
1823 | - * @return ICrypto |
|
1824 | - * @deprecated 20.0.0 |
|
1825 | - */ |
|
1826 | - public function getCrypto() { |
|
1827 | - return $this->get(ICrypto::class); |
|
1828 | - } |
|
1829 | - |
|
1830 | - /** |
|
1831 | - * Returns a Hasher instance |
|
1832 | - * |
|
1833 | - * @return IHasher |
|
1834 | - * @deprecated 20.0.0 |
|
1835 | - */ |
|
1836 | - public function getHasher() { |
|
1837 | - return $this->get(IHasher::class); |
|
1838 | - } |
|
1839 | - |
|
1840 | - /** |
|
1841 | - * Returns a CredentialsManager instance |
|
1842 | - * |
|
1843 | - * @return ICredentialsManager |
|
1844 | - * @deprecated 20.0.0 |
|
1845 | - */ |
|
1846 | - public function getCredentialsManager() { |
|
1847 | - return $this->get(ICredentialsManager::class); |
|
1848 | - } |
|
1849 | - |
|
1850 | - /** |
|
1851 | - * Get the certificate manager |
|
1852 | - * |
|
1853 | - * @return \OCP\ICertificateManager |
|
1854 | - */ |
|
1855 | - public function getCertificateManager() { |
|
1856 | - return $this->get(ICertificateManager::class); |
|
1857 | - } |
|
1858 | - |
|
1859 | - /** |
|
1860 | - * Returns an instance of the HTTP client service |
|
1861 | - * |
|
1862 | - * @return IClientService |
|
1863 | - * @deprecated 20.0.0 |
|
1864 | - */ |
|
1865 | - public function getHTTPClientService() { |
|
1866 | - return $this->get(IClientService::class); |
|
1867 | - } |
|
1868 | - |
|
1869 | - /** |
|
1870 | - * Create a new event source |
|
1871 | - * |
|
1872 | - * @return \OCP\IEventSource |
|
1873 | - * @deprecated 20.0.0 |
|
1874 | - */ |
|
1875 | - public function createEventSource() { |
|
1876 | - return new \OC_EventSource(); |
|
1877 | - } |
|
1878 | - |
|
1879 | - /** |
|
1880 | - * Get the active event logger |
|
1881 | - * |
|
1882 | - * The returned logger only logs data when debug mode is enabled |
|
1883 | - * |
|
1884 | - * @return IEventLogger |
|
1885 | - * @deprecated 20.0.0 |
|
1886 | - */ |
|
1887 | - public function getEventLogger() { |
|
1888 | - return $this->get(IEventLogger::class); |
|
1889 | - } |
|
1890 | - |
|
1891 | - /** |
|
1892 | - * Get the active query logger |
|
1893 | - * |
|
1894 | - * The returned logger only logs data when debug mode is enabled |
|
1895 | - * |
|
1896 | - * @return IQueryLogger |
|
1897 | - * @deprecated 20.0.0 |
|
1898 | - */ |
|
1899 | - public function getQueryLogger() { |
|
1900 | - return $this->get(IQueryLogger::class); |
|
1901 | - } |
|
1902 | - |
|
1903 | - /** |
|
1904 | - * Get the manager for temporary files and folders |
|
1905 | - * |
|
1906 | - * @return \OCP\ITempManager |
|
1907 | - * @deprecated 20.0.0 |
|
1908 | - */ |
|
1909 | - public function getTempManager() { |
|
1910 | - return $this->get(ITempManager::class); |
|
1911 | - } |
|
1912 | - |
|
1913 | - /** |
|
1914 | - * Get the app manager |
|
1915 | - * |
|
1916 | - * @return \OCP\App\IAppManager |
|
1917 | - * @deprecated 20.0.0 |
|
1918 | - */ |
|
1919 | - public function getAppManager() { |
|
1920 | - return $this->get(IAppManager::class); |
|
1921 | - } |
|
1922 | - |
|
1923 | - /** |
|
1924 | - * Creates a new mailer |
|
1925 | - * |
|
1926 | - * @return IMailer |
|
1927 | - * @deprecated 20.0.0 |
|
1928 | - */ |
|
1929 | - public function getMailer() { |
|
1930 | - return $this->get(IMailer::class); |
|
1931 | - } |
|
1932 | - |
|
1933 | - /** |
|
1934 | - * Get the webroot |
|
1935 | - * |
|
1936 | - * @return string |
|
1937 | - * @deprecated 20.0.0 |
|
1938 | - */ |
|
1939 | - public function getWebRoot() { |
|
1940 | - return $this->webRoot; |
|
1941 | - } |
|
1942 | - |
|
1943 | - /** |
|
1944 | - * @return \OC\OCSClient |
|
1945 | - * @deprecated 20.0.0 |
|
1946 | - */ |
|
1947 | - public function getOcsClient() { |
|
1948 | - return $this->get('OcsClient'); |
|
1949 | - } |
|
1950 | - |
|
1951 | - /** |
|
1952 | - * @return IDateTimeZone |
|
1953 | - * @deprecated 20.0.0 |
|
1954 | - */ |
|
1955 | - public function getDateTimeZone() { |
|
1956 | - return $this->get(IDateTimeZone::class); |
|
1957 | - } |
|
1958 | - |
|
1959 | - /** |
|
1960 | - * @return IDateTimeFormatter |
|
1961 | - * @deprecated 20.0.0 |
|
1962 | - */ |
|
1963 | - public function getDateTimeFormatter() { |
|
1964 | - return $this->get(IDateTimeFormatter::class); |
|
1965 | - } |
|
1966 | - |
|
1967 | - /** |
|
1968 | - * @return IMountProviderCollection |
|
1969 | - * @deprecated 20.0.0 |
|
1970 | - */ |
|
1971 | - public function getMountProviderCollection() { |
|
1972 | - return $this->get(IMountProviderCollection::class); |
|
1973 | - } |
|
1974 | - |
|
1975 | - /** |
|
1976 | - * Get the IniWrapper |
|
1977 | - * |
|
1978 | - * @return IniGetWrapper |
|
1979 | - * @deprecated 20.0.0 |
|
1980 | - */ |
|
1981 | - public function getIniWrapper() { |
|
1982 | - return $this->get(IniGetWrapper::class); |
|
1983 | - } |
|
1984 | - |
|
1985 | - /** |
|
1986 | - * @return \OCP\Command\IBus |
|
1987 | - * @deprecated 20.0.0 |
|
1988 | - */ |
|
1989 | - public function getCommandBus() { |
|
1990 | - return $this->get(IBus::class); |
|
1991 | - } |
|
1992 | - |
|
1993 | - /** |
|
1994 | - * Get the trusted domain helper |
|
1995 | - * |
|
1996 | - * @return TrustedDomainHelper |
|
1997 | - * @deprecated 20.0.0 |
|
1998 | - */ |
|
1999 | - public function getTrustedDomainHelper() { |
|
2000 | - return $this->get(TrustedDomainHelper::class); |
|
2001 | - } |
|
2002 | - |
|
2003 | - /** |
|
2004 | - * Get the locking provider |
|
2005 | - * |
|
2006 | - * @return ILockingProvider |
|
2007 | - * @since 8.1.0 |
|
2008 | - * @deprecated 20.0.0 |
|
2009 | - */ |
|
2010 | - public function getLockingProvider() { |
|
2011 | - return $this->get(ILockingProvider::class); |
|
2012 | - } |
|
2013 | - |
|
2014 | - /** |
|
2015 | - * @return IMountManager |
|
2016 | - * @deprecated 20.0.0 |
|
2017 | - **/ |
|
2018 | - public function getMountManager() { |
|
2019 | - return $this->get(IMountManager::class); |
|
2020 | - } |
|
2021 | - |
|
2022 | - /** |
|
2023 | - * @return IUserMountCache |
|
2024 | - * @deprecated 20.0.0 |
|
2025 | - */ |
|
2026 | - public function getUserMountCache() { |
|
2027 | - return $this->get(IUserMountCache::class); |
|
2028 | - } |
|
2029 | - |
|
2030 | - /** |
|
2031 | - * Get the MimeTypeDetector |
|
2032 | - * |
|
2033 | - * @return IMimeTypeDetector |
|
2034 | - * @deprecated 20.0.0 |
|
2035 | - */ |
|
2036 | - public function getMimeTypeDetector() { |
|
2037 | - return $this->get(IMimeTypeDetector::class); |
|
2038 | - } |
|
2039 | - |
|
2040 | - /** |
|
2041 | - * Get the MimeTypeLoader |
|
2042 | - * |
|
2043 | - * @return IMimeTypeLoader |
|
2044 | - * @deprecated 20.0.0 |
|
2045 | - */ |
|
2046 | - public function getMimeTypeLoader() { |
|
2047 | - return $this->get(IMimeTypeLoader::class); |
|
2048 | - } |
|
2049 | - |
|
2050 | - /** |
|
2051 | - * Get the manager of all the capabilities |
|
2052 | - * |
|
2053 | - * @return CapabilitiesManager |
|
2054 | - * @deprecated 20.0.0 |
|
2055 | - */ |
|
2056 | - public function getCapabilitiesManager() { |
|
2057 | - return $this->get(CapabilitiesManager::class); |
|
2058 | - } |
|
2059 | - |
|
2060 | - /** |
|
2061 | - * Get the EventDispatcher |
|
2062 | - * |
|
2063 | - * @return EventDispatcherInterface |
|
2064 | - * @since 8.2.0 |
|
2065 | - * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher |
|
2066 | - */ |
|
2067 | - public function getEventDispatcher() { |
|
2068 | - return $this->get(\OC\EventDispatcher\SymfonyAdapter::class); |
|
2069 | - } |
|
2070 | - |
|
2071 | - /** |
|
2072 | - * Get the Notification Manager |
|
2073 | - * |
|
2074 | - * @return \OCP\Notification\IManager |
|
2075 | - * @since 8.2.0 |
|
2076 | - * @deprecated 20.0.0 |
|
2077 | - */ |
|
2078 | - public function getNotificationManager() { |
|
2079 | - return $this->get(\OCP\Notification\IManager::class); |
|
2080 | - } |
|
2081 | - |
|
2082 | - /** |
|
2083 | - * @return ICommentsManager |
|
2084 | - * @deprecated 20.0.0 |
|
2085 | - */ |
|
2086 | - public function getCommentsManager() { |
|
2087 | - return $this->get(ICommentsManager::class); |
|
2088 | - } |
|
2089 | - |
|
2090 | - /** |
|
2091 | - * @return \OCA\Theming\ThemingDefaults |
|
2092 | - * @deprecated 20.0.0 |
|
2093 | - */ |
|
2094 | - public function getThemingDefaults() { |
|
2095 | - return $this->get('ThemingDefaults'); |
|
2096 | - } |
|
2097 | - |
|
2098 | - /** |
|
2099 | - * @return \OC\IntegrityCheck\Checker |
|
2100 | - * @deprecated 20.0.0 |
|
2101 | - */ |
|
2102 | - public function getIntegrityCodeChecker() { |
|
2103 | - return $this->get('IntegrityCodeChecker'); |
|
2104 | - } |
|
2105 | - |
|
2106 | - /** |
|
2107 | - * @return \OC\Session\CryptoWrapper |
|
2108 | - * @deprecated 20.0.0 |
|
2109 | - */ |
|
2110 | - public function getSessionCryptoWrapper() { |
|
2111 | - return $this->get('CryptoWrapper'); |
|
2112 | - } |
|
2113 | - |
|
2114 | - /** |
|
2115 | - * @return CsrfTokenManager |
|
2116 | - * @deprecated 20.0.0 |
|
2117 | - */ |
|
2118 | - public function getCsrfTokenManager() { |
|
2119 | - return $this->get(CsrfTokenManager::class); |
|
2120 | - } |
|
2121 | - |
|
2122 | - /** |
|
2123 | - * @return Throttler |
|
2124 | - * @deprecated 20.0.0 |
|
2125 | - */ |
|
2126 | - public function getBruteForceThrottler() { |
|
2127 | - return $this->get(Throttler::class); |
|
2128 | - } |
|
2129 | - |
|
2130 | - /** |
|
2131 | - * @return IContentSecurityPolicyManager |
|
2132 | - * @deprecated 20.0.0 |
|
2133 | - */ |
|
2134 | - public function getContentSecurityPolicyManager() { |
|
2135 | - return $this->get(ContentSecurityPolicyManager::class); |
|
2136 | - } |
|
2137 | - |
|
2138 | - /** |
|
2139 | - * @return ContentSecurityPolicyNonceManager |
|
2140 | - * @deprecated 20.0.0 |
|
2141 | - */ |
|
2142 | - public function getContentSecurityPolicyNonceManager() { |
|
2143 | - return $this->get(ContentSecurityPolicyNonceManager::class); |
|
2144 | - } |
|
2145 | - |
|
2146 | - /** |
|
2147 | - * Not a public API as of 8.2, wait for 9.0 |
|
2148 | - * |
|
2149 | - * @return \OCA\Files_External\Service\BackendService |
|
2150 | - * @deprecated 20.0.0 |
|
2151 | - */ |
|
2152 | - public function getStoragesBackendService() { |
|
2153 | - return $this->get(BackendService::class); |
|
2154 | - } |
|
2155 | - |
|
2156 | - /** |
|
2157 | - * Not a public API as of 8.2, wait for 9.0 |
|
2158 | - * |
|
2159 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
2160 | - * @deprecated 20.0.0 |
|
2161 | - */ |
|
2162 | - public function getGlobalStoragesService() { |
|
2163 | - return $this->get(GlobalStoragesService::class); |
|
2164 | - } |
|
2165 | - |
|
2166 | - /** |
|
2167 | - * Not a public API as of 8.2, wait for 9.0 |
|
2168 | - * |
|
2169 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
2170 | - * @deprecated 20.0.0 |
|
2171 | - */ |
|
2172 | - public function getUserGlobalStoragesService() { |
|
2173 | - return $this->get(UserGlobalStoragesService::class); |
|
2174 | - } |
|
2175 | - |
|
2176 | - /** |
|
2177 | - * Not a public API as of 8.2, wait for 9.0 |
|
2178 | - * |
|
2179 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
2180 | - * @deprecated 20.0.0 |
|
2181 | - */ |
|
2182 | - public function getUserStoragesService() { |
|
2183 | - return $this->get(UserStoragesService::class); |
|
2184 | - } |
|
2185 | - |
|
2186 | - /** |
|
2187 | - * @return \OCP\Share\IManager |
|
2188 | - * @deprecated 20.0.0 |
|
2189 | - */ |
|
2190 | - public function getShareManager() { |
|
2191 | - return $this->get(\OCP\Share\IManager::class); |
|
2192 | - } |
|
2193 | - |
|
2194 | - /** |
|
2195 | - * @return \OCP\Collaboration\Collaborators\ISearch |
|
2196 | - * @deprecated 20.0.0 |
|
2197 | - */ |
|
2198 | - public function getCollaboratorSearch() { |
|
2199 | - return $this->get(\OCP\Collaboration\Collaborators\ISearch::class); |
|
2200 | - } |
|
2201 | - |
|
2202 | - /** |
|
2203 | - * @return \OCP\Collaboration\AutoComplete\IManager |
|
2204 | - * @deprecated 20.0.0 |
|
2205 | - */ |
|
2206 | - public function getAutoCompleteManager() { |
|
2207 | - return $this->get(IManager::class); |
|
2208 | - } |
|
2209 | - |
|
2210 | - /** |
|
2211 | - * Returns the LDAP Provider |
|
2212 | - * |
|
2213 | - * @return \OCP\LDAP\ILDAPProvider |
|
2214 | - * @deprecated 20.0.0 |
|
2215 | - */ |
|
2216 | - public function getLDAPProvider() { |
|
2217 | - return $this->get('LDAPProvider'); |
|
2218 | - } |
|
2219 | - |
|
2220 | - /** |
|
2221 | - * @return \OCP\Settings\IManager |
|
2222 | - * @deprecated 20.0.0 |
|
2223 | - */ |
|
2224 | - public function getSettingsManager() { |
|
2225 | - return $this->get(\OC\Settings\Manager::class); |
|
2226 | - } |
|
2227 | - |
|
2228 | - /** |
|
2229 | - * @return \OCP\Files\IAppData |
|
2230 | - * @deprecated 20.0.0 |
|
2231 | - */ |
|
2232 | - public function getAppDataDir($app) { |
|
2233 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
2234 | - $factory = $this->get(\OC\Files\AppData\Factory::class); |
|
2235 | - return $factory->get($app); |
|
2236 | - } |
|
2237 | - |
|
2238 | - /** |
|
2239 | - * @return \OCP\Lockdown\ILockdownManager |
|
2240 | - * @deprecated 20.0.0 |
|
2241 | - */ |
|
2242 | - public function getLockdownManager() { |
|
2243 | - return $this->get('LockdownManager'); |
|
2244 | - } |
|
2245 | - |
|
2246 | - /** |
|
2247 | - * @return \OCP\Federation\ICloudIdManager |
|
2248 | - * @deprecated 20.0.0 |
|
2249 | - */ |
|
2250 | - public function getCloudIdManager() { |
|
2251 | - return $this->get(ICloudIdManager::class); |
|
2252 | - } |
|
2253 | - |
|
2254 | - /** |
|
2255 | - * @return \OCP\GlobalScale\IConfig |
|
2256 | - * @deprecated 20.0.0 |
|
2257 | - */ |
|
2258 | - public function getGlobalScaleConfig() { |
|
2259 | - return $this->get(IConfig::class); |
|
2260 | - } |
|
2261 | - |
|
2262 | - /** |
|
2263 | - * @return \OCP\Federation\ICloudFederationProviderManager |
|
2264 | - * @deprecated 20.0.0 |
|
2265 | - */ |
|
2266 | - public function getCloudFederationProviderManager() { |
|
2267 | - return $this->get(ICloudFederationProviderManager::class); |
|
2268 | - } |
|
2269 | - |
|
2270 | - /** |
|
2271 | - * @return \OCP\Remote\Api\IApiFactory |
|
2272 | - * @deprecated 20.0.0 |
|
2273 | - */ |
|
2274 | - public function getRemoteApiFactory() { |
|
2275 | - return $this->get(IApiFactory::class); |
|
2276 | - } |
|
2277 | - |
|
2278 | - /** |
|
2279 | - * @return \OCP\Federation\ICloudFederationFactory |
|
2280 | - * @deprecated 20.0.0 |
|
2281 | - */ |
|
2282 | - public function getCloudFederationFactory() { |
|
2283 | - return $this->get(ICloudFederationFactory::class); |
|
2284 | - } |
|
2285 | - |
|
2286 | - /** |
|
2287 | - * @return \OCP\Remote\IInstanceFactory |
|
2288 | - * @deprecated 20.0.0 |
|
2289 | - */ |
|
2290 | - public function getRemoteInstanceFactory() { |
|
2291 | - return $this->get(IInstanceFactory::class); |
|
2292 | - } |
|
2293 | - |
|
2294 | - /** |
|
2295 | - * @return IStorageFactory |
|
2296 | - * @deprecated 20.0.0 |
|
2297 | - */ |
|
2298 | - public function getStorageFactory() { |
|
2299 | - return $this->get(IStorageFactory::class); |
|
2300 | - } |
|
2301 | - |
|
2302 | - /** |
|
2303 | - * Get the Preview GeneratorHelper |
|
2304 | - * |
|
2305 | - * @return GeneratorHelper |
|
2306 | - * @since 17.0.0 |
|
2307 | - * @deprecated 20.0.0 |
|
2308 | - */ |
|
2309 | - public function getGeneratorHelper() { |
|
2310 | - return $this->get(\OC\Preview\GeneratorHelper::class); |
|
2311 | - } |
|
2312 | - |
|
2313 | - private function registerDeprecatedAlias(string $alias, string $target) { |
|
2314 | - $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) { |
|
2315 | - try { |
|
2316 | - /** @var ILogger $logger */ |
|
2317 | - $logger = $container->get(ILogger::class); |
|
2318 | - $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
2319 | - } catch (ContainerExceptionInterface $e) { |
|
2320 | - // Could not get logger. Continue |
|
2321 | - } |
|
2322 | - |
|
2323 | - return $container->get($target); |
|
2324 | - }, false); |
|
2325 | - } |
|
1139 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
1140 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
1141 | + $classExists = true; |
|
1142 | + } else { |
|
1143 | + $classExists = false; |
|
1144 | + } |
|
1145 | + |
|
1146 | + if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValue('installed', false) && $c->get(IAppManager::class)->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
1147 | + return new ThemingDefaults( |
|
1148 | + $c->get(\OCP\IConfig::class), |
|
1149 | + $c->getL10N('theming'), |
|
1150 | + $c->get(IURLGenerator::class), |
|
1151 | + $c->get(ICacheFactory::class), |
|
1152 | + new Util($c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming')), |
|
1153 | + new ImageManager( |
|
1154 | + $c->get(\OCP\IConfig::class), |
|
1155 | + $c->getAppDataDir('theming'), |
|
1156 | + $c->get(IURLGenerator::class), |
|
1157 | + $this->get(ICacheFactory::class), |
|
1158 | + $this->get(ILogger::class), |
|
1159 | + $this->get(ITempManager::class) |
|
1160 | + ), |
|
1161 | + $c->get(IAppManager::class), |
|
1162 | + $c->get(INavigationManager::class) |
|
1163 | + ); |
|
1164 | + } |
|
1165 | + return new \OC_Defaults(); |
|
1166 | + }); |
|
1167 | + $this->registerService(JSCombiner::class, function (Server $c) { |
|
1168 | + return new JSCombiner( |
|
1169 | + $c->getAppDataDir('js'), |
|
1170 | + $c->get(IURLGenerator::class), |
|
1171 | + $this->get(ICacheFactory::class), |
|
1172 | + $c->get(SystemConfig::class), |
|
1173 | + $c->get(ILogger::class) |
|
1174 | + ); |
|
1175 | + }); |
|
1176 | + $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
1177 | + /** @deprecated 19.0.0 */ |
|
1178 | + $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
|
1179 | + $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
|
1180 | + |
|
1181 | + $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
1182 | + // FIXME: Instantiiated here due to cyclic dependency |
|
1183 | + $request = new Request( |
|
1184 | + [ |
|
1185 | + 'get' => $_GET, |
|
1186 | + 'post' => $_POST, |
|
1187 | + 'files' => $_FILES, |
|
1188 | + 'server' => $_SERVER, |
|
1189 | + 'env' => $_ENV, |
|
1190 | + 'cookies' => $_COOKIE, |
|
1191 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1192 | + ? $_SERVER['REQUEST_METHOD'] |
|
1193 | + : null, |
|
1194 | + ], |
|
1195 | + $c->get(ISecureRandom::class), |
|
1196 | + $c->get(\OCP\IConfig::class) |
|
1197 | + ); |
|
1198 | + |
|
1199 | + return new CryptoWrapper( |
|
1200 | + $c->get(\OCP\IConfig::class), |
|
1201 | + $c->get(ICrypto::class), |
|
1202 | + $c->get(ISecureRandom::class), |
|
1203 | + $request |
|
1204 | + ); |
|
1205 | + }); |
|
1206 | + /** @deprecated 19.0.0 */ |
|
1207 | + $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class); |
|
1208 | + $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
1209 | + return new SessionStorage($c->get(ISession::class)); |
|
1210 | + }); |
|
1211 | + $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
1212 | + /** @deprecated 19.0.0 */ |
|
1213 | + $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class); |
|
1214 | + |
|
1215 | + $this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) { |
|
1216 | + $config = $c->get(\OCP\IConfig::class); |
|
1217 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1218 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
1219 | + $factory = new $factoryClass($this); |
|
1220 | + |
|
1221 | + $manager = new \OC\Share20\Manager( |
|
1222 | + $c->get(ILogger::class), |
|
1223 | + $c->get(\OCP\IConfig::class), |
|
1224 | + $c->get(ISecureRandom::class), |
|
1225 | + $c->get(IHasher::class), |
|
1226 | + $c->get(IMountManager::class), |
|
1227 | + $c->get(IGroupManager::class), |
|
1228 | + $c->getL10N('lib'), |
|
1229 | + $c->get(IFactory::class), |
|
1230 | + $factory, |
|
1231 | + $c->get(IUserManager::class), |
|
1232 | + $c->get(IRootFolder::class), |
|
1233 | + $c->get(SymfonyAdapter::class), |
|
1234 | + $c->get(IMailer::class), |
|
1235 | + $c->get(IURLGenerator::class), |
|
1236 | + $c->get('ThemingDefaults'), |
|
1237 | + $c->get(IEventDispatcher::class), |
|
1238 | + $c->get(IUserSession::class) |
|
1239 | + ); |
|
1240 | + |
|
1241 | + return $manager; |
|
1242 | + }); |
|
1243 | + /** @deprecated 19.0.0 */ |
|
1244 | + $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class); |
|
1245 | + |
|
1246 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
1247 | + $instance = new Collaboration\Collaborators\Search($c); |
|
1248 | + |
|
1249 | + // register default plugins |
|
1250 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1251 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1252 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1253 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1254 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
1255 | + |
|
1256 | + return $instance; |
|
1257 | + }); |
|
1258 | + /** @deprecated 19.0.0 */ |
|
1259 | + $this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1260 | + $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
1261 | + |
|
1262 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1263 | + |
|
1264 | + $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
1265 | + $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
1266 | + |
|
1267 | + $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
|
1268 | + $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
|
1269 | + $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
1270 | + return new \OC\Files\AppData\Factory( |
|
1271 | + $c->get(IRootFolder::class), |
|
1272 | + $c->get(SystemConfig::class) |
|
1273 | + ); |
|
1274 | + }); |
|
1275 | + |
|
1276 | + $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
1277 | + return new LockdownManager(function () use ($c) { |
|
1278 | + return $c->get(ISession::class); |
|
1279 | + }); |
|
1280 | + }); |
|
1281 | + |
|
1282 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
1283 | + return new DiscoveryService( |
|
1284 | + $c->get(ICacheFactory::class), |
|
1285 | + $c->get(IClientService::class) |
|
1286 | + ); |
|
1287 | + }); |
|
1288 | + |
|
1289 | + $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
1290 | + return new CloudIdManager($c->get(\OCP\Contacts\IManager::class)); |
|
1291 | + }); |
|
1292 | + |
|
1293 | + $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
1294 | + |
|
1295 | + $this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) { |
|
1296 | + return new CloudFederationProviderManager( |
|
1297 | + $c->get(IAppManager::class), |
|
1298 | + $c->get(IClientService::class), |
|
1299 | + $c->get(ICloudIdManager::class), |
|
1300 | + $c->get(ILogger::class) |
|
1301 | + ); |
|
1302 | + }); |
|
1303 | + |
|
1304 | + $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1305 | + return new CloudFederationFactory(); |
|
1306 | + }); |
|
1307 | + |
|
1308 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1309 | + /** @deprecated 19.0.0 */ |
|
1310 | + $this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1311 | + |
|
1312 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1313 | + /** @deprecated 19.0.0 */ |
|
1314 | + $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1315 | + |
|
1316 | + $this->registerService(Defaults::class, function (Server $c) { |
|
1317 | + return new Defaults( |
|
1318 | + $c->getThemingDefaults() |
|
1319 | + ); |
|
1320 | + }); |
|
1321 | + /** @deprecated 19.0.0 */ |
|
1322 | + $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class); |
|
1323 | + |
|
1324 | + $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
1325 | + return $c->get(\OCP\IUserSession::class)->getSession(); |
|
1326 | + }, false); |
|
1327 | + |
|
1328 | + $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
1329 | + return new ShareHelper( |
|
1330 | + $c->get(\OCP\Share\IManager::class) |
|
1331 | + ); |
|
1332 | + }); |
|
1333 | + |
|
1334 | + $this->registerService(Installer::class, function (ContainerInterface $c) { |
|
1335 | + return new Installer( |
|
1336 | + $c->get(AppFetcher::class), |
|
1337 | + $c->get(IClientService::class), |
|
1338 | + $c->get(ITempManager::class), |
|
1339 | + $c->get(LoggerInterface::class), |
|
1340 | + $c->get(\OCP\IConfig::class), |
|
1341 | + \OC::$CLI |
|
1342 | + ); |
|
1343 | + }); |
|
1344 | + |
|
1345 | + $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
1346 | + return new ApiFactory($c->get(IClientService::class)); |
|
1347 | + }); |
|
1348 | + |
|
1349 | + $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
1350 | + $memcacheFactory = $c->get(ICacheFactory::class); |
|
1351 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
|
1352 | + }); |
|
1353 | + |
|
1354 | + $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1355 | + $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
1356 | + |
|
1357 | + $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
1358 | + |
|
1359 | + $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
|
1360 | + $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
1361 | + $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
1362 | + |
|
1363 | + $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
1364 | + |
|
1365 | + $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
1366 | + |
|
1367 | + $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
1368 | + |
|
1369 | + $this->connectDispatcher(); |
|
1370 | + } |
|
1371 | + |
|
1372 | + public function boot() { |
|
1373 | + /** @var HookConnector $hookConnector */ |
|
1374 | + $hookConnector = $this->get(HookConnector::class); |
|
1375 | + $hookConnector->viewToNode(); |
|
1376 | + } |
|
1377 | + |
|
1378 | + /** |
|
1379 | + * @return \OCP\Calendar\IManager |
|
1380 | + * @deprecated 20.0.0 |
|
1381 | + */ |
|
1382 | + public function getCalendarManager() { |
|
1383 | + return $this->get(\OC\Calendar\Manager::class); |
|
1384 | + } |
|
1385 | + |
|
1386 | + /** |
|
1387 | + * @return \OCP\Calendar\Resource\IManager |
|
1388 | + * @deprecated 20.0.0 |
|
1389 | + */ |
|
1390 | + public function getCalendarResourceBackendManager() { |
|
1391 | + return $this->get(\OC\Calendar\Resource\Manager::class); |
|
1392 | + } |
|
1393 | + |
|
1394 | + /** |
|
1395 | + * @return \OCP\Calendar\Room\IManager |
|
1396 | + * @deprecated 20.0.0 |
|
1397 | + */ |
|
1398 | + public function getCalendarRoomBackendManager() { |
|
1399 | + return $this->get(\OC\Calendar\Room\Manager::class); |
|
1400 | + } |
|
1401 | + |
|
1402 | + private function connectDispatcher() { |
|
1403 | + $dispatcher = $this->get(SymfonyAdapter::class); |
|
1404 | + |
|
1405 | + // Delete avatar on user deletion |
|
1406 | + $dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) { |
|
1407 | + $logger = $this->get(ILogger::class); |
|
1408 | + $manager = $this->getAvatarManager(); |
|
1409 | + /** @var IUser $user */ |
|
1410 | + $user = $e->getSubject(); |
|
1411 | + |
|
1412 | + try { |
|
1413 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1414 | + $avatar->remove(); |
|
1415 | + } catch (NotFoundException $e) { |
|
1416 | + // no avatar to remove |
|
1417 | + } catch (\Exception $e) { |
|
1418 | + // Ignore exceptions |
|
1419 | + $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1420 | + } |
|
1421 | + }); |
|
1422 | + |
|
1423 | + $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1424 | + $manager = $this->getAvatarManager(); |
|
1425 | + /** @var IUser $user */ |
|
1426 | + $user = $e->getSubject(); |
|
1427 | + $feature = $e->getArgument('feature'); |
|
1428 | + $oldValue = $e->getArgument('oldValue'); |
|
1429 | + $value = $e->getArgument('value'); |
|
1430 | + |
|
1431 | + // We only change the avatar on display name changes |
|
1432 | + if ($feature !== 'displayName') { |
|
1433 | + return; |
|
1434 | + } |
|
1435 | + |
|
1436 | + try { |
|
1437 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1438 | + $avatar->userChanged($feature, $oldValue, $value); |
|
1439 | + } catch (NotFoundException $e) { |
|
1440 | + // no avatar to remove |
|
1441 | + } |
|
1442 | + }); |
|
1443 | + |
|
1444 | + /** @var IEventDispatcher $eventDispatched */ |
|
1445 | + $eventDispatched = $this->get(IEventDispatcher::class); |
|
1446 | + $eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
1447 | + $eventDispatched->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class); |
|
1448 | + } |
|
1449 | + |
|
1450 | + /** |
|
1451 | + * @return \OCP\Contacts\IManager |
|
1452 | + * @deprecated 20.0.0 |
|
1453 | + */ |
|
1454 | + public function getContactsManager() { |
|
1455 | + return $this->get(\OCP\Contacts\IManager::class); |
|
1456 | + } |
|
1457 | + |
|
1458 | + /** |
|
1459 | + * @return \OC\Encryption\Manager |
|
1460 | + * @deprecated 20.0.0 |
|
1461 | + */ |
|
1462 | + public function getEncryptionManager() { |
|
1463 | + return $this->get(\OCP\Encryption\IManager::class); |
|
1464 | + } |
|
1465 | + |
|
1466 | + /** |
|
1467 | + * @return \OC\Encryption\File |
|
1468 | + * @deprecated 20.0.0 |
|
1469 | + */ |
|
1470 | + public function getEncryptionFilesHelper() { |
|
1471 | + return $this->get(IFile::class); |
|
1472 | + } |
|
1473 | + |
|
1474 | + /** |
|
1475 | + * @return \OCP\Encryption\Keys\IStorage |
|
1476 | + * @deprecated 20.0.0 |
|
1477 | + */ |
|
1478 | + public function getEncryptionKeyStorage() { |
|
1479 | + return $this->get(IStorage::class); |
|
1480 | + } |
|
1481 | + |
|
1482 | + /** |
|
1483 | + * The current request object holding all information about the request |
|
1484 | + * currently being processed is returned from this method. |
|
1485 | + * In case the current execution was not initiated by a web request null is returned |
|
1486 | + * |
|
1487 | + * @return \OCP\IRequest |
|
1488 | + * @deprecated 20.0.0 |
|
1489 | + */ |
|
1490 | + public function getRequest() { |
|
1491 | + return $this->get(IRequest::class); |
|
1492 | + } |
|
1493 | + |
|
1494 | + /** |
|
1495 | + * Returns the preview manager which can create preview images for a given file |
|
1496 | + * |
|
1497 | + * @return IPreview |
|
1498 | + * @deprecated 20.0.0 |
|
1499 | + */ |
|
1500 | + public function getPreviewManager() { |
|
1501 | + return $this->get(IPreview::class); |
|
1502 | + } |
|
1503 | + |
|
1504 | + /** |
|
1505 | + * Returns the tag manager which can get and set tags for different object types |
|
1506 | + * |
|
1507 | + * @see \OCP\ITagManager::load() |
|
1508 | + * @return ITagManager |
|
1509 | + * @deprecated 20.0.0 |
|
1510 | + */ |
|
1511 | + public function getTagManager() { |
|
1512 | + return $this->get(ITagManager::class); |
|
1513 | + } |
|
1514 | + |
|
1515 | + /** |
|
1516 | + * Returns the system-tag manager |
|
1517 | + * |
|
1518 | + * @return ISystemTagManager |
|
1519 | + * |
|
1520 | + * @since 9.0.0 |
|
1521 | + * @deprecated 20.0.0 |
|
1522 | + */ |
|
1523 | + public function getSystemTagManager() { |
|
1524 | + return $this->get(ISystemTagManager::class); |
|
1525 | + } |
|
1526 | + |
|
1527 | + /** |
|
1528 | + * Returns the system-tag object mapper |
|
1529 | + * |
|
1530 | + * @return ISystemTagObjectMapper |
|
1531 | + * |
|
1532 | + * @since 9.0.0 |
|
1533 | + * @deprecated 20.0.0 |
|
1534 | + */ |
|
1535 | + public function getSystemTagObjectMapper() { |
|
1536 | + return $this->get(ISystemTagObjectMapper::class); |
|
1537 | + } |
|
1538 | + |
|
1539 | + /** |
|
1540 | + * Returns the avatar manager, used for avatar functionality |
|
1541 | + * |
|
1542 | + * @return IAvatarManager |
|
1543 | + * @deprecated 20.0.0 |
|
1544 | + */ |
|
1545 | + public function getAvatarManager() { |
|
1546 | + return $this->get(IAvatarManager::class); |
|
1547 | + } |
|
1548 | + |
|
1549 | + /** |
|
1550 | + * Returns the root folder of ownCloud's data directory |
|
1551 | + * |
|
1552 | + * @return IRootFolder |
|
1553 | + * @deprecated 20.0.0 |
|
1554 | + */ |
|
1555 | + public function getRootFolder() { |
|
1556 | + return $this->get(IRootFolder::class); |
|
1557 | + } |
|
1558 | + |
|
1559 | + /** |
|
1560 | + * Returns the root folder of ownCloud's data directory |
|
1561 | + * This is the lazy variant so this gets only initialized once it |
|
1562 | + * is actually used. |
|
1563 | + * |
|
1564 | + * @return IRootFolder |
|
1565 | + * @deprecated 20.0.0 |
|
1566 | + */ |
|
1567 | + public function getLazyRootFolder() { |
|
1568 | + return $this->get(IRootFolder::class); |
|
1569 | + } |
|
1570 | + |
|
1571 | + /** |
|
1572 | + * Returns a view to ownCloud's files folder |
|
1573 | + * |
|
1574 | + * @param string $userId user ID |
|
1575 | + * @return \OCP\Files\Folder|null |
|
1576 | + * @deprecated 20.0.0 |
|
1577 | + */ |
|
1578 | + public function getUserFolder($userId = null) { |
|
1579 | + if ($userId === null) { |
|
1580 | + $user = $this->get(IUserSession::class)->getUser(); |
|
1581 | + if (!$user) { |
|
1582 | + return null; |
|
1583 | + } |
|
1584 | + $userId = $user->getUID(); |
|
1585 | + } |
|
1586 | + $root = $this->get(IRootFolder::class); |
|
1587 | + return $root->getUserFolder($userId); |
|
1588 | + } |
|
1589 | + |
|
1590 | + /** |
|
1591 | + * @return \OC\User\Manager |
|
1592 | + * @deprecated 20.0.0 |
|
1593 | + */ |
|
1594 | + public function getUserManager() { |
|
1595 | + return $this->get(IUserManager::class); |
|
1596 | + } |
|
1597 | + |
|
1598 | + /** |
|
1599 | + * @return \OC\Group\Manager |
|
1600 | + * @deprecated 20.0.0 |
|
1601 | + */ |
|
1602 | + public function getGroupManager() { |
|
1603 | + return $this->get(IGroupManager::class); |
|
1604 | + } |
|
1605 | + |
|
1606 | + /** |
|
1607 | + * @return \OC\User\Session |
|
1608 | + * @deprecated 20.0.0 |
|
1609 | + */ |
|
1610 | + public function getUserSession() { |
|
1611 | + return $this->get(IUserSession::class); |
|
1612 | + } |
|
1613 | + |
|
1614 | + /** |
|
1615 | + * @return \OCP\ISession |
|
1616 | + * @deprecated 20.0.0 |
|
1617 | + */ |
|
1618 | + public function getSession() { |
|
1619 | + return $this->get(IUserSession::class)->getSession(); |
|
1620 | + } |
|
1621 | + |
|
1622 | + /** |
|
1623 | + * @param \OCP\ISession $session |
|
1624 | + */ |
|
1625 | + public function setSession(\OCP\ISession $session) { |
|
1626 | + $this->get(SessionStorage::class)->setSession($session); |
|
1627 | + $this->get(IUserSession::class)->setSession($session); |
|
1628 | + $this->get(Store::class)->setSession($session); |
|
1629 | + } |
|
1630 | + |
|
1631 | + /** |
|
1632 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1633 | + * @deprecated 20.0.0 |
|
1634 | + */ |
|
1635 | + public function getTwoFactorAuthManager() { |
|
1636 | + return $this->get(\OC\Authentication\TwoFactorAuth\Manager::class); |
|
1637 | + } |
|
1638 | + |
|
1639 | + /** |
|
1640 | + * @return \OC\NavigationManager |
|
1641 | + * @deprecated 20.0.0 |
|
1642 | + */ |
|
1643 | + public function getNavigationManager() { |
|
1644 | + return $this->get(INavigationManager::class); |
|
1645 | + } |
|
1646 | + |
|
1647 | + /** |
|
1648 | + * @return \OCP\IConfig |
|
1649 | + * @deprecated 20.0.0 |
|
1650 | + */ |
|
1651 | + public function getConfig() { |
|
1652 | + return $this->get(AllConfig::class); |
|
1653 | + } |
|
1654 | + |
|
1655 | + /** |
|
1656 | + * @return \OC\SystemConfig |
|
1657 | + * @deprecated 20.0.0 |
|
1658 | + */ |
|
1659 | + public function getSystemConfig() { |
|
1660 | + return $this->get(SystemConfig::class); |
|
1661 | + } |
|
1662 | + |
|
1663 | + /** |
|
1664 | + * Returns the app config manager |
|
1665 | + * |
|
1666 | + * @return IAppConfig |
|
1667 | + * @deprecated 20.0.0 |
|
1668 | + */ |
|
1669 | + public function getAppConfig() { |
|
1670 | + return $this->get(IAppConfig::class); |
|
1671 | + } |
|
1672 | + |
|
1673 | + /** |
|
1674 | + * @return IFactory |
|
1675 | + * @deprecated 20.0.0 |
|
1676 | + */ |
|
1677 | + public function getL10NFactory() { |
|
1678 | + return $this->get(IFactory::class); |
|
1679 | + } |
|
1680 | + |
|
1681 | + /** |
|
1682 | + * get an L10N instance |
|
1683 | + * |
|
1684 | + * @param string $app appid |
|
1685 | + * @param string $lang |
|
1686 | + * @return IL10N |
|
1687 | + * @deprecated 20.0.0 |
|
1688 | + */ |
|
1689 | + public function getL10N($app, $lang = null) { |
|
1690 | + return $this->get(IFactory::class)->get($app, $lang); |
|
1691 | + } |
|
1692 | + |
|
1693 | + /** |
|
1694 | + * @return IURLGenerator |
|
1695 | + * @deprecated 20.0.0 |
|
1696 | + */ |
|
1697 | + public function getURLGenerator() { |
|
1698 | + return $this->get(IURLGenerator::class); |
|
1699 | + } |
|
1700 | + |
|
1701 | + /** |
|
1702 | + * @return AppFetcher |
|
1703 | + * @deprecated 20.0.0 |
|
1704 | + */ |
|
1705 | + public function getAppFetcher() { |
|
1706 | + return $this->get(AppFetcher::class); |
|
1707 | + } |
|
1708 | + |
|
1709 | + /** |
|
1710 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1711 | + * getMemCacheFactory() instead. |
|
1712 | + * |
|
1713 | + * @return ICache |
|
1714 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1715 | + */ |
|
1716 | + public function getCache() { |
|
1717 | + return $this->get(ICache::class); |
|
1718 | + } |
|
1719 | + |
|
1720 | + /** |
|
1721 | + * Returns an \OCP\CacheFactory instance |
|
1722 | + * |
|
1723 | + * @return \OCP\ICacheFactory |
|
1724 | + * @deprecated 20.0.0 |
|
1725 | + */ |
|
1726 | + public function getMemCacheFactory() { |
|
1727 | + return $this->get(ICacheFactory::class); |
|
1728 | + } |
|
1729 | + |
|
1730 | + /** |
|
1731 | + * Returns an \OC\RedisFactory instance |
|
1732 | + * |
|
1733 | + * @return \OC\RedisFactory |
|
1734 | + * @deprecated 20.0.0 |
|
1735 | + */ |
|
1736 | + public function getGetRedisFactory() { |
|
1737 | + return $this->get('RedisFactory'); |
|
1738 | + } |
|
1739 | + |
|
1740 | + |
|
1741 | + /** |
|
1742 | + * Returns the current session |
|
1743 | + * |
|
1744 | + * @return \OCP\IDBConnection |
|
1745 | + * @deprecated 20.0.0 |
|
1746 | + */ |
|
1747 | + public function getDatabaseConnection() { |
|
1748 | + return $this->get(IDBConnection::class); |
|
1749 | + } |
|
1750 | + |
|
1751 | + /** |
|
1752 | + * Returns the activity manager |
|
1753 | + * |
|
1754 | + * @return \OCP\Activity\IManager |
|
1755 | + * @deprecated 20.0.0 |
|
1756 | + */ |
|
1757 | + public function getActivityManager() { |
|
1758 | + return $this->get(\OCP\Activity\IManager::class); |
|
1759 | + } |
|
1760 | + |
|
1761 | + /** |
|
1762 | + * Returns an job list for controlling background jobs |
|
1763 | + * |
|
1764 | + * @return IJobList |
|
1765 | + * @deprecated 20.0.0 |
|
1766 | + */ |
|
1767 | + public function getJobList() { |
|
1768 | + return $this->get(IJobList::class); |
|
1769 | + } |
|
1770 | + |
|
1771 | + /** |
|
1772 | + * Returns a logger instance |
|
1773 | + * |
|
1774 | + * @return ILogger |
|
1775 | + * @deprecated 20.0.0 |
|
1776 | + */ |
|
1777 | + public function getLogger() { |
|
1778 | + return $this->get(ILogger::class); |
|
1779 | + } |
|
1780 | + |
|
1781 | + /** |
|
1782 | + * @return ILogFactory |
|
1783 | + * @throws \OCP\AppFramework\QueryException |
|
1784 | + * @deprecated 20.0.0 |
|
1785 | + */ |
|
1786 | + public function getLogFactory() { |
|
1787 | + return $this->get(ILogFactory::class); |
|
1788 | + } |
|
1789 | + |
|
1790 | + /** |
|
1791 | + * Returns a router for generating and matching urls |
|
1792 | + * |
|
1793 | + * @return IRouter |
|
1794 | + * @deprecated 20.0.0 |
|
1795 | + */ |
|
1796 | + public function getRouter() { |
|
1797 | + return $this->get(IRouter::class); |
|
1798 | + } |
|
1799 | + |
|
1800 | + /** |
|
1801 | + * Returns a search instance |
|
1802 | + * |
|
1803 | + * @return ISearch |
|
1804 | + * @deprecated 20.0.0 |
|
1805 | + */ |
|
1806 | + public function getSearch() { |
|
1807 | + return $this->get(ISearch::class); |
|
1808 | + } |
|
1809 | + |
|
1810 | + /** |
|
1811 | + * Returns a SecureRandom instance |
|
1812 | + * |
|
1813 | + * @return \OCP\Security\ISecureRandom |
|
1814 | + * @deprecated 20.0.0 |
|
1815 | + */ |
|
1816 | + public function getSecureRandom() { |
|
1817 | + return $this->get(ISecureRandom::class); |
|
1818 | + } |
|
1819 | + |
|
1820 | + /** |
|
1821 | + * Returns a Crypto instance |
|
1822 | + * |
|
1823 | + * @return ICrypto |
|
1824 | + * @deprecated 20.0.0 |
|
1825 | + */ |
|
1826 | + public function getCrypto() { |
|
1827 | + return $this->get(ICrypto::class); |
|
1828 | + } |
|
1829 | + |
|
1830 | + /** |
|
1831 | + * Returns a Hasher instance |
|
1832 | + * |
|
1833 | + * @return IHasher |
|
1834 | + * @deprecated 20.0.0 |
|
1835 | + */ |
|
1836 | + public function getHasher() { |
|
1837 | + return $this->get(IHasher::class); |
|
1838 | + } |
|
1839 | + |
|
1840 | + /** |
|
1841 | + * Returns a CredentialsManager instance |
|
1842 | + * |
|
1843 | + * @return ICredentialsManager |
|
1844 | + * @deprecated 20.0.0 |
|
1845 | + */ |
|
1846 | + public function getCredentialsManager() { |
|
1847 | + return $this->get(ICredentialsManager::class); |
|
1848 | + } |
|
1849 | + |
|
1850 | + /** |
|
1851 | + * Get the certificate manager |
|
1852 | + * |
|
1853 | + * @return \OCP\ICertificateManager |
|
1854 | + */ |
|
1855 | + public function getCertificateManager() { |
|
1856 | + return $this->get(ICertificateManager::class); |
|
1857 | + } |
|
1858 | + |
|
1859 | + /** |
|
1860 | + * Returns an instance of the HTTP client service |
|
1861 | + * |
|
1862 | + * @return IClientService |
|
1863 | + * @deprecated 20.0.0 |
|
1864 | + */ |
|
1865 | + public function getHTTPClientService() { |
|
1866 | + return $this->get(IClientService::class); |
|
1867 | + } |
|
1868 | + |
|
1869 | + /** |
|
1870 | + * Create a new event source |
|
1871 | + * |
|
1872 | + * @return \OCP\IEventSource |
|
1873 | + * @deprecated 20.0.0 |
|
1874 | + */ |
|
1875 | + public function createEventSource() { |
|
1876 | + return new \OC_EventSource(); |
|
1877 | + } |
|
1878 | + |
|
1879 | + /** |
|
1880 | + * Get the active event logger |
|
1881 | + * |
|
1882 | + * The returned logger only logs data when debug mode is enabled |
|
1883 | + * |
|
1884 | + * @return IEventLogger |
|
1885 | + * @deprecated 20.0.0 |
|
1886 | + */ |
|
1887 | + public function getEventLogger() { |
|
1888 | + return $this->get(IEventLogger::class); |
|
1889 | + } |
|
1890 | + |
|
1891 | + /** |
|
1892 | + * Get the active query logger |
|
1893 | + * |
|
1894 | + * The returned logger only logs data when debug mode is enabled |
|
1895 | + * |
|
1896 | + * @return IQueryLogger |
|
1897 | + * @deprecated 20.0.0 |
|
1898 | + */ |
|
1899 | + public function getQueryLogger() { |
|
1900 | + return $this->get(IQueryLogger::class); |
|
1901 | + } |
|
1902 | + |
|
1903 | + /** |
|
1904 | + * Get the manager for temporary files and folders |
|
1905 | + * |
|
1906 | + * @return \OCP\ITempManager |
|
1907 | + * @deprecated 20.0.0 |
|
1908 | + */ |
|
1909 | + public function getTempManager() { |
|
1910 | + return $this->get(ITempManager::class); |
|
1911 | + } |
|
1912 | + |
|
1913 | + /** |
|
1914 | + * Get the app manager |
|
1915 | + * |
|
1916 | + * @return \OCP\App\IAppManager |
|
1917 | + * @deprecated 20.0.0 |
|
1918 | + */ |
|
1919 | + public function getAppManager() { |
|
1920 | + return $this->get(IAppManager::class); |
|
1921 | + } |
|
1922 | + |
|
1923 | + /** |
|
1924 | + * Creates a new mailer |
|
1925 | + * |
|
1926 | + * @return IMailer |
|
1927 | + * @deprecated 20.0.0 |
|
1928 | + */ |
|
1929 | + public function getMailer() { |
|
1930 | + return $this->get(IMailer::class); |
|
1931 | + } |
|
1932 | + |
|
1933 | + /** |
|
1934 | + * Get the webroot |
|
1935 | + * |
|
1936 | + * @return string |
|
1937 | + * @deprecated 20.0.0 |
|
1938 | + */ |
|
1939 | + public function getWebRoot() { |
|
1940 | + return $this->webRoot; |
|
1941 | + } |
|
1942 | + |
|
1943 | + /** |
|
1944 | + * @return \OC\OCSClient |
|
1945 | + * @deprecated 20.0.0 |
|
1946 | + */ |
|
1947 | + public function getOcsClient() { |
|
1948 | + return $this->get('OcsClient'); |
|
1949 | + } |
|
1950 | + |
|
1951 | + /** |
|
1952 | + * @return IDateTimeZone |
|
1953 | + * @deprecated 20.0.0 |
|
1954 | + */ |
|
1955 | + public function getDateTimeZone() { |
|
1956 | + return $this->get(IDateTimeZone::class); |
|
1957 | + } |
|
1958 | + |
|
1959 | + /** |
|
1960 | + * @return IDateTimeFormatter |
|
1961 | + * @deprecated 20.0.0 |
|
1962 | + */ |
|
1963 | + public function getDateTimeFormatter() { |
|
1964 | + return $this->get(IDateTimeFormatter::class); |
|
1965 | + } |
|
1966 | + |
|
1967 | + /** |
|
1968 | + * @return IMountProviderCollection |
|
1969 | + * @deprecated 20.0.0 |
|
1970 | + */ |
|
1971 | + public function getMountProviderCollection() { |
|
1972 | + return $this->get(IMountProviderCollection::class); |
|
1973 | + } |
|
1974 | + |
|
1975 | + /** |
|
1976 | + * Get the IniWrapper |
|
1977 | + * |
|
1978 | + * @return IniGetWrapper |
|
1979 | + * @deprecated 20.0.0 |
|
1980 | + */ |
|
1981 | + public function getIniWrapper() { |
|
1982 | + return $this->get(IniGetWrapper::class); |
|
1983 | + } |
|
1984 | + |
|
1985 | + /** |
|
1986 | + * @return \OCP\Command\IBus |
|
1987 | + * @deprecated 20.0.0 |
|
1988 | + */ |
|
1989 | + public function getCommandBus() { |
|
1990 | + return $this->get(IBus::class); |
|
1991 | + } |
|
1992 | + |
|
1993 | + /** |
|
1994 | + * Get the trusted domain helper |
|
1995 | + * |
|
1996 | + * @return TrustedDomainHelper |
|
1997 | + * @deprecated 20.0.0 |
|
1998 | + */ |
|
1999 | + public function getTrustedDomainHelper() { |
|
2000 | + return $this->get(TrustedDomainHelper::class); |
|
2001 | + } |
|
2002 | + |
|
2003 | + /** |
|
2004 | + * Get the locking provider |
|
2005 | + * |
|
2006 | + * @return ILockingProvider |
|
2007 | + * @since 8.1.0 |
|
2008 | + * @deprecated 20.0.0 |
|
2009 | + */ |
|
2010 | + public function getLockingProvider() { |
|
2011 | + return $this->get(ILockingProvider::class); |
|
2012 | + } |
|
2013 | + |
|
2014 | + /** |
|
2015 | + * @return IMountManager |
|
2016 | + * @deprecated 20.0.0 |
|
2017 | + **/ |
|
2018 | + public function getMountManager() { |
|
2019 | + return $this->get(IMountManager::class); |
|
2020 | + } |
|
2021 | + |
|
2022 | + /** |
|
2023 | + * @return IUserMountCache |
|
2024 | + * @deprecated 20.0.0 |
|
2025 | + */ |
|
2026 | + public function getUserMountCache() { |
|
2027 | + return $this->get(IUserMountCache::class); |
|
2028 | + } |
|
2029 | + |
|
2030 | + /** |
|
2031 | + * Get the MimeTypeDetector |
|
2032 | + * |
|
2033 | + * @return IMimeTypeDetector |
|
2034 | + * @deprecated 20.0.0 |
|
2035 | + */ |
|
2036 | + public function getMimeTypeDetector() { |
|
2037 | + return $this->get(IMimeTypeDetector::class); |
|
2038 | + } |
|
2039 | + |
|
2040 | + /** |
|
2041 | + * Get the MimeTypeLoader |
|
2042 | + * |
|
2043 | + * @return IMimeTypeLoader |
|
2044 | + * @deprecated 20.0.0 |
|
2045 | + */ |
|
2046 | + public function getMimeTypeLoader() { |
|
2047 | + return $this->get(IMimeTypeLoader::class); |
|
2048 | + } |
|
2049 | + |
|
2050 | + /** |
|
2051 | + * Get the manager of all the capabilities |
|
2052 | + * |
|
2053 | + * @return CapabilitiesManager |
|
2054 | + * @deprecated 20.0.0 |
|
2055 | + */ |
|
2056 | + public function getCapabilitiesManager() { |
|
2057 | + return $this->get(CapabilitiesManager::class); |
|
2058 | + } |
|
2059 | + |
|
2060 | + /** |
|
2061 | + * Get the EventDispatcher |
|
2062 | + * |
|
2063 | + * @return EventDispatcherInterface |
|
2064 | + * @since 8.2.0 |
|
2065 | + * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher |
|
2066 | + */ |
|
2067 | + public function getEventDispatcher() { |
|
2068 | + return $this->get(\OC\EventDispatcher\SymfonyAdapter::class); |
|
2069 | + } |
|
2070 | + |
|
2071 | + /** |
|
2072 | + * Get the Notification Manager |
|
2073 | + * |
|
2074 | + * @return \OCP\Notification\IManager |
|
2075 | + * @since 8.2.0 |
|
2076 | + * @deprecated 20.0.0 |
|
2077 | + */ |
|
2078 | + public function getNotificationManager() { |
|
2079 | + return $this->get(\OCP\Notification\IManager::class); |
|
2080 | + } |
|
2081 | + |
|
2082 | + /** |
|
2083 | + * @return ICommentsManager |
|
2084 | + * @deprecated 20.0.0 |
|
2085 | + */ |
|
2086 | + public function getCommentsManager() { |
|
2087 | + return $this->get(ICommentsManager::class); |
|
2088 | + } |
|
2089 | + |
|
2090 | + /** |
|
2091 | + * @return \OCA\Theming\ThemingDefaults |
|
2092 | + * @deprecated 20.0.0 |
|
2093 | + */ |
|
2094 | + public function getThemingDefaults() { |
|
2095 | + return $this->get('ThemingDefaults'); |
|
2096 | + } |
|
2097 | + |
|
2098 | + /** |
|
2099 | + * @return \OC\IntegrityCheck\Checker |
|
2100 | + * @deprecated 20.0.0 |
|
2101 | + */ |
|
2102 | + public function getIntegrityCodeChecker() { |
|
2103 | + return $this->get('IntegrityCodeChecker'); |
|
2104 | + } |
|
2105 | + |
|
2106 | + /** |
|
2107 | + * @return \OC\Session\CryptoWrapper |
|
2108 | + * @deprecated 20.0.0 |
|
2109 | + */ |
|
2110 | + public function getSessionCryptoWrapper() { |
|
2111 | + return $this->get('CryptoWrapper'); |
|
2112 | + } |
|
2113 | + |
|
2114 | + /** |
|
2115 | + * @return CsrfTokenManager |
|
2116 | + * @deprecated 20.0.0 |
|
2117 | + */ |
|
2118 | + public function getCsrfTokenManager() { |
|
2119 | + return $this->get(CsrfTokenManager::class); |
|
2120 | + } |
|
2121 | + |
|
2122 | + /** |
|
2123 | + * @return Throttler |
|
2124 | + * @deprecated 20.0.0 |
|
2125 | + */ |
|
2126 | + public function getBruteForceThrottler() { |
|
2127 | + return $this->get(Throttler::class); |
|
2128 | + } |
|
2129 | + |
|
2130 | + /** |
|
2131 | + * @return IContentSecurityPolicyManager |
|
2132 | + * @deprecated 20.0.0 |
|
2133 | + */ |
|
2134 | + public function getContentSecurityPolicyManager() { |
|
2135 | + return $this->get(ContentSecurityPolicyManager::class); |
|
2136 | + } |
|
2137 | + |
|
2138 | + /** |
|
2139 | + * @return ContentSecurityPolicyNonceManager |
|
2140 | + * @deprecated 20.0.0 |
|
2141 | + */ |
|
2142 | + public function getContentSecurityPolicyNonceManager() { |
|
2143 | + return $this->get(ContentSecurityPolicyNonceManager::class); |
|
2144 | + } |
|
2145 | + |
|
2146 | + /** |
|
2147 | + * Not a public API as of 8.2, wait for 9.0 |
|
2148 | + * |
|
2149 | + * @return \OCA\Files_External\Service\BackendService |
|
2150 | + * @deprecated 20.0.0 |
|
2151 | + */ |
|
2152 | + public function getStoragesBackendService() { |
|
2153 | + return $this->get(BackendService::class); |
|
2154 | + } |
|
2155 | + |
|
2156 | + /** |
|
2157 | + * Not a public API as of 8.2, wait for 9.0 |
|
2158 | + * |
|
2159 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
2160 | + * @deprecated 20.0.0 |
|
2161 | + */ |
|
2162 | + public function getGlobalStoragesService() { |
|
2163 | + return $this->get(GlobalStoragesService::class); |
|
2164 | + } |
|
2165 | + |
|
2166 | + /** |
|
2167 | + * Not a public API as of 8.2, wait for 9.0 |
|
2168 | + * |
|
2169 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
2170 | + * @deprecated 20.0.0 |
|
2171 | + */ |
|
2172 | + public function getUserGlobalStoragesService() { |
|
2173 | + return $this->get(UserGlobalStoragesService::class); |
|
2174 | + } |
|
2175 | + |
|
2176 | + /** |
|
2177 | + * Not a public API as of 8.2, wait for 9.0 |
|
2178 | + * |
|
2179 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
2180 | + * @deprecated 20.0.0 |
|
2181 | + */ |
|
2182 | + public function getUserStoragesService() { |
|
2183 | + return $this->get(UserStoragesService::class); |
|
2184 | + } |
|
2185 | + |
|
2186 | + /** |
|
2187 | + * @return \OCP\Share\IManager |
|
2188 | + * @deprecated 20.0.0 |
|
2189 | + */ |
|
2190 | + public function getShareManager() { |
|
2191 | + return $this->get(\OCP\Share\IManager::class); |
|
2192 | + } |
|
2193 | + |
|
2194 | + /** |
|
2195 | + * @return \OCP\Collaboration\Collaborators\ISearch |
|
2196 | + * @deprecated 20.0.0 |
|
2197 | + */ |
|
2198 | + public function getCollaboratorSearch() { |
|
2199 | + return $this->get(\OCP\Collaboration\Collaborators\ISearch::class); |
|
2200 | + } |
|
2201 | + |
|
2202 | + /** |
|
2203 | + * @return \OCP\Collaboration\AutoComplete\IManager |
|
2204 | + * @deprecated 20.0.0 |
|
2205 | + */ |
|
2206 | + public function getAutoCompleteManager() { |
|
2207 | + return $this->get(IManager::class); |
|
2208 | + } |
|
2209 | + |
|
2210 | + /** |
|
2211 | + * Returns the LDAP Provider |
|
2212 | + * |
|
2213 | + * @return \OCP\LDAP\ILDAPProvider |
|
2214 | + * @deprecated 20.0.0 |
|
2215 | + */ |
|
2216 | + public function getLDAPProvider() { |
|
2217 | + return $this->get('LDAPProvider'); |
|
2218 | + } |
|
2219 | + |
|
2220 | + /** |
|
2221 | + * @return \OCP\Settings\IManager |
|
2222 | + * @deprecated 20.0.0 |
|
2223 | + */ |
|
2224 | + public function getSettingsManager() { |
|
2225 | + return $this->get(\OC\Settings\Manager::class); |
|
2226 | + } |
|
2227 | + |
|
2228 | + /** |
|
2229 | + * @return \OCP\Files\IAppData |
|
2230 | + * @deprecated 20.0.0 |
|
2231 | + */ |
|
2232 | + public function getAppDataDir($app) { |
|
2233 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
2234 | + $factory = $this->get(\OC\Files\AppData\Factory::class); |
|
2235 | + return $factory->get($app); |
|
2236 | + } |
|
2237 | + |
|
2238 | + /** |
|
2239 | + * @return \OCP\Lockdown\ILockdownManager |
|
2240 | + * @deprecated 20.0.0 |
|
2241 | + */ |
|
2242 | + public function getLockdownManager() { |
|
2243 | + return $this->get('LockdownManager'); |
|
2244 | + } |
|
2245 | + |
|
2246 | + /** |
|
2247 | + * @return \OCP\Federation\ICloudIdManager |
|
2248 | + * @deprecated 20.0.0 |
|
2249 | + */ |
|
2250 | + public function getCloudIdManager() { |
|
2251 | + return $this->get(ICloudIdManager::class); |
|
2252 | + } |
|
2253 | + |
|
2254 | + /** |
|
2255 | + * @return \OCP\GlobalScale\IConfig |
|
2256 | + * @deprecated 20.0.0 |
|
2257 | + */ |
|
2258 | + public function getGlobalScaleConfig() { |
|
2259 | + return $this->get(IConfig::class); |
|
2260 | + } |
|
2261 | + |
|
2262 | + /** |
|
2263 | + * @return \OCP\Federation\ICloudFederationProviderManager |
|
2264 | + * @deprecated 20.0.0 |
|
2265 | + */ |
|
2266 | + public function getCloudFederationProviderManager() { |
|
2267 | + return $this->get(ICloudFederationProviderManager::class); |
|
2268 | + } |
|
2269 | + |
|
2270 | + /** |
|
2271 | + * @return \OCP\Remote\Api\IApiFactory |
|
2272 | + * @deprecated 20.0.0 |
|
2273 | + */ |
|
2274 | + public function getRemoteApiFactory() { |
|
2275 | + return $this->get(IApiFactory::class); |
|
2276 | + } |
|
2277 | + |
|
2278 | + /** |
|
2279 | + * @return \OCP\Federation\ICloudFederationFactory |
|
2280 | + * @deprecated 20.0.0 |
|
2281 | + */ |
|
2282 | + public function getCloudFederationFactory() { |
|
2283 | + return $this->get(ICloudFederationFactory::class); |
|
2284 | + } |
|
2285 | + |
|
2286 | + /** |
|
2287 | + * @return \OCP\Remote\IInstanceFactory |
|
2288 | + * @deprecated 20.0.0 |
|
2289 | + */ |
|
2290 | + public function getRemoteInstanceFactory() { |
|
2291 | + return $this->get(IInstanceFactory::class); |
|
2292 | + } |
|
2293 | + |
|
2294 | + /** |
|
2295 | + * @return IStorageFactory |
|
2296 | + * @deprecated 20.0.0 |
|
2297 | + */ |
|
2298 | + public function getStorageFactory() { |
|
2299 | + return $this->get(IStorageFactory::class); |
|
2300 | + } |
|
2301 | + |
|
2302 | + /** |
|
2303 | + * Get the Preview GeneratorHelper |
|
2304 | + * |
|
2305 | + * @return GeneratorHelper |
|
2306 | + * @since 17.0.0 |
|
2307 | + * @deprecated 20.0.0 |
|
2308 | + */ |
|
2309 | + public function getGeneratorHelper() { |
|
2310 | + return $this->get(\OC\Preview\GeneratorHelper::class); |
|
2311 | + } |
|
2312 | + |
|
2313 | + private function registerDeprecatedAlias(string $alias, string $target) { |
|
2314 | + $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) { |
|
2315 | + try { |
|
2316 | + /** @var ILogger $logger */ |
|
2317 | + $logger = $container->get(ILogger::class); |
|
2318 | + $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
2319 | + } catch (ContainerExceptionInterface $e) { |
|
2320 | + // Could not get logger. Continue |
|
2321 | + } |
|
2322 | + |
|
2323 | + return $container->get($target); |
|
2324 | + }, false); |
|
2325 | + } |
|
2326 | 2326 | } |
@@ -63,309 +63,309 @@ |
||
63 | 63 | * @package OCA\Files\Controller |
64 | 64 | */ |
65 | 65 | class ViewController extends Controller { |
66 | - /** @var string */ |
|
67 | - protected $appName; |
|
68 | - /** @var IRequest */ |
|
69 | - protected $request; |
|
70 | - /** @var IURLGenerator */ |
|
71 | - protected $urlGenerator; |
|
72 | - /** @var IL10N */ |
|
73 | - protected $l10n; |
|
74 | - /** @var IConfig */ |
|
75 | - protected $config; |
|
76 | - /** @var IEventDispatcher */ |
|
77 | - protected $eventDispatcher; |
|
78 | - /** @var IUserSession */ |
|
79 | - protected $userSession; |
|
80 | - /** @var IAppManager */ |
|
81 | - protected $appManager; |
|
82 | - /** @var IRootFolder */ |
|
83 | - protected $rootFolder; |
|
84 | - /** @var Helper */ |
|
85 | - protected $activityHelper; |
|
86 | - /** @var IInitialState */ |
|
87 | - private $initialState; |
|
88 | - /** @var ITemplateManager */ |
|
89 | - private $templateManager; |
|
90 | - /** @var IManager */ |
|
91 | - private $shareManager; |
|
92 | - |
|
93 | - public function __construct(string $appName, |
|
94 | - IRequest $request, |
|
95 | - IURLGenerator $urlGenerator, |
|
96 | - IL10N $l10n, |
|
97 | - IConfig $config, |
|
98 | - IEventDispatcher $eventDispatcher, |
|
99 | - IUserSession $userSession, |
|
100 | - IAppManager $appManager, |
|
101 | - IRootFolder $rootFolder, |
|
102 | - Helper $activityHelper, |
|
103 | - IInitialState $initialState, |
|
104 | - ITemplateManager $templateManager, |
|
105 | - IManager $shareManager |
|
106 | - ) { |
|
107 | - parent::__construct($appName, $request); |
|
108 | - $this->appName = $appName; |
|
109 | - $this->request = $request; |
|
110 | - $this->urlGenerator = $urlGenerator; |
|
111 | - $this->l10n = $l10n; |
|
112 | - $this->config = $config; |
|
113 | - $this->eventDispatcher = $eventDispatcher; |
|
114 | - $this->userSession = $userSession; |
|
115 | - $this->appManager = $appManager; |
|
116 | - $this->rootFolder = $rootFolder; |
|
117 | - $this->activityHelper = $activityHelper; |
|
118 | - $this->initialState = $initialState; |
|
119 | - $this->templateManager = $templateManager; |
|
120 | - $this->shareManager = $shareManager; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * @param string $appName |
|
125 | - * @param string $scriptName |
|
126 | - * @return string |
|
127 | - */ |
|
128 | - protected function renderScript($appName, $scriptName) { |
|
129 | - $content = ''; |
|
130 | - $appPath = \OC_App::getAppPath($appName); |
|
131 | - $scriptPath = $appPath . '/' . $scriptName; |
|
132 | - if (file_exists($scriptPath)) { |
|
133 | - // TODO: sanitize path / script name ? |
|
134 | - ob_start(); |
|
135 | - include $scriptPath; |
|
136 | - $content = ob_get_contents(); |
|
137 | - @ob_end_clean(); |
|
138 | - } |
|
139 | - |
|
140 | - return $content; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * FIXME: Replace with non static code |
|
145 | - * |
|
146 | - * @return array |
|
147 | - * @throws \OCP\Files\NotFoundException |
|
148 | - */ |
|
149 | - protected function getStorageInfo() { |
|
150 | - \OC_Util::setupFS(); |
|
151 | - $dirInfo = \OC\Files\Filesystem::getFileInfo('/', false); |
|
152 | - |
|
153 | - return \OC_Helper::getStorageInfo('/', $dirInfo); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * @NoCSRFRequired |
|
158 | - * @NoAdminRequired |
|
159 | - * |
|
160 | - * @param string $fileid |
|
161 | - * @return TemplateResponse|RedirectResponse |
|
162 | - * @throws NotFoundException |
|
163 | - */ |
|
164 | - public function showFile(string $fileid = null): Response { |
|
165 | - // This is the entry point from the `/f/{fileid}` URL which is hardcoded in the server. |
|
166 | - try { |
|
167 | - return $this->redirectToFile($fileid); |
|
168 | - } catch (NotFoundException $e) { |
|
169 | - return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); |
|
170 | - } |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * @NoCSRFRequired |
|
175 | - * @NoAdminRequired |
|
176 | - * |
|
177 | - * @param string $dir |
|
178 | - * @param string $view |
|
179 | - * @param string $fileid |
|
180 | - * @param bool $fileNotFound |
|
181 | - * @return TemplateResponse|RedirectResponse |
|
182 | - * @throws NotFoundException |
|
183 | - */ |
|
184 | - public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) { |
|
185 | - if ($fileid !== null) { |
|
186 | - try { |
|
187 | - return $this->redirectToFile($fileid); |
|
188 | - } catch (NotFoundException $e) { |
|
189 | - return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); |
|
190 | - } |
|
191 | - } |
|
192 | - |
|
193 | - $nav = new \OCP\Template('files', 'appnavigation', ''); |
|
194 | - |
|
195 | - // Load the files we need |
|
196 | - \OCP\Util::addStyle('files', 'merged'); |
|
197 | - \OCP\Util::addScript('files', 'merged-index'); |
|
198 | - \OCP\Util::addScript('files', 'dist/templates'); |
|
199 | - |
|
200 | - // mostly for the home storage's free space |
|
201 | - // FIXME: Make non static |
|
202 | - $storageInfo = $this->getStorageInfo(); |
|
203 | - |
|
204 | - $user = $this->userSession->getUser()->getUID(); |
|
205 | - |
|
206 | - // Get all the user favorites to create a submenu |
|
207 | - try { |
|
208 | - $favElements = $this->activityHelper->getFavoriteFilePaths($this->userSession->getUser()->getUID()); |
|
209 | - } catch (\RuntimeException $e) { |
|
210 | - $favElements['folders'] = []; |
|
211 | - } |
|
212 | - |
|
213 | - $collapseClasses = ''; |
|
214 | - if (count($favElements['folders']) > 0) { |
|
215 | - $collapseClasses = 'collapsible'; |
|
216 | - } |
|
217 | - |
|
218 | - $favoritesSublistArray = []; |
|
219 | - |
|
220 | - $navBarPositionPosition = 6; |
|
221 | - $currentCount = 0; |
|
222 | - foreach ($favElements['folders'] as $dir) { |
|
223 | - $link = $this->urlGenerator->linkToRoute('files.view.index', ['dir' => $dir, 'view' => 'files']); |
|
224 | - $sortingValue = ++$currentCount; |
|
225 | - $element = [ |
|
226 | - 'id' => str_replace('/', '-', $dir), |
|
227 | - 'view' => 'files', |
|
228 | - 'href' => $link, |
|
229 | - 'dir' => $dir, |
|
230 | - 'order' => $navBarPositionPosition, |
|
231 | - 'folderPosition' => $sortingValue, |
|
232 | - 'name' => basename($dir), |
|
233 | - 'icon' => 'files', |
|
234 | - 'quickaccesselement' => 'true' |
|
235 | - ]; |
|
236 | - |
|
237 | - array_push($favoritesSublistArray, $element); |
|
238 | - $navBarPositionPosition++; |
|
239 | - } |
|
240 | - |
|
241 | - $navItems = \OCA\Files\App::getNavigationManager()->getAll(); |
|
242 | - |
|
243 | - // add the favorites entry in menu |
|
244 | - $navItems['favorites']['sublist'] = $favoritesSublistArray; |
|
245 | - $navItems['favorites']['classes'] = $collapseClasses; |
|
246 | - |
|
247 | - // parse every menu and add the expandedState user value |
|
248 | - foreach ($navItems as $key => $item) { |
|
249 | - if (isset($item['expandedState'])) { |
|
250 | - $navItems[$key]['defaultExpandedState'] = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1'; |
|
251 | - } |
|
252 | - } |
|
253 | - |
|
254 | - $nav->assign('navigationItems', $navItems); |
|
255 | - |
|
256 | - $nav->assign('usage', \OC_Helper::humanFileSize($storageInfo['used'])); |
|
257 | - if ($storageInfo['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
258 | - $totalSpace = $this->l10n->t('Unlimited'); |
|
259 | - } else { |
|
260 | - $totalSpace = \OC_Helper::humanFileSize($storageInfo['total']); |
|
261 | - } |
|
262 | - $nav->assign('total_space', $totalSpace); |
|
263 | - $nav->assign('quota', $storageInfo['quota']); |
|
264 | - $nav->assign('usage_relative', $storageInfo['relative']); |
|
265 | - |
|
266 | - $nav->assign('webdav_url', \OCP\Util::linkToRemote('dav/files/' . $user)); |
|
267 | - |
|
268 | - $contentItems = []; |
|
269 | - |
|
270 | - // render the container content for every navigation item |
|
271 | - foreach ($navItems as $item) { |
|
272 | - $content = ''; |
|
273 | - if (isset($item['script'])) { |
|
274 | - $content = $this->renderScript($item['appname'], $item['script']); |
|
275 | - } |
|
276 | - // parse submenus |
|
277 | - if (isset($item['sublist'])) { |
|
278 | - foreach ($item['sublist'] as $subitem) { |
|
279 | - $subcontent = ''; |
|
280 | - if (isset($subitem['script'])) { |
|
281 | - $subcontent = $this->renderScript($subitem['appname'], $subitem['script']); |
|
282 | - } |
|
283 | - $contentItems[$subitem['id']] = [ |
|
284 | - 'id' => $subitem['id'], |
|
285 | - 'content' => $subcontent |
|
286 | - ]; |
|
287 | - } |
|
288 | - } |
|
289 | - $contentItems[$item['id']] = [ |
|
290 | - 'id' => $item['id'], |
|
291 | - 'content' => $content |
|
292 | - ]; |
|
293 | - } |
|
294 | - |
|
295 | - $event = new LoadAdditionalScriptsEvent(); |
|
296 | - $this->eventDispatcher->dispatchTyped($event); |
|
297 | - $this->eventDispatcher->dispatchTyped(new LoadSidebar()); |
|
298 | - // Load Viewer scripts |
|
299 | - if (class_exists(LoadViewer::class)) { |
|
300 | - $this->eventDispatcher->dispatchTyped(new LoadViewer()); |
|
301 | - } |
|
302 | - $this->initialState->provideInitialState('templates_path', $this->templateManager->hasTemplateDirectory() ? $this->templateManager->getTemplatePath() : false); |
|
303 | - $this->initialState->provideInitialState('templates', $this->templateManager->listCreators()); |
|
304 | - |
|
305 | - $params = []; |
|
306 | - $params['usedSpacePercent'] = (int) $storageInfo['relative']; |
|
307 | - $params['owner'] = $storageInfo['owner'] ?? ''; |
|
308 | - $params['ownerDisplayName'] = $storageInfo['ownerDisplayName'] ?? ''; |
|
309 | - $params['isPublic'] = false; |
|
310 | - $params['allowShareWithLink'] = $this->shareManager->shareApiAllowLinks() ? 'yes' : 'no'; |
|
311 | - $params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name'); |
|
312 | - $params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc'); |
|
313 | - $params['showgridview'] = $this->config->getUserValue($user, 'files', 'show_grid', false); |
|
314 | - $params['isIE'] = \OC_Util::isIe(); |
|
315 | - $showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false); |
|
316 | - $params['showHiddenFiles'] = $showHidden ? 1 : 0; |
|
317 | - $cropImagePreviews = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', true); |
|
318 | - $params['cropImagePreviews'] = $cropImagePreviews ? 1 : 0; |
|
319 | - $params['fileNotFound'] = $fileNotFound ? 1 : 0; |
|
320 | - $params['appNavigation'] = $nav; |
|
321 | - $params['appContents'] = $contentItems; |
|
322 | - $params['hiddenFields'] = $event->getHiddenFields(); |
|
323 | - |
|
324 | - $response = new TemplateResponse( |
|
325 | - $this->appName, |
|
326 | - 'index', |
|
327 | - $params |
|
328 | - ); |
|
329 | - $policy = new ContentSecurityPolicy(); |
|
330 | - $policy->addAllowedFrameDomain('\'self\''); |
|
331 | - $response->setContentSecurityPolicy($policy); |
|
332 | - |
|
333 | - return $response; |
|
334 | - } |
|
335 | - |
|
336 | - /** |
|
337 | - * Redirects to the file list and highlight the given file id |
|
338 | - * |
|
339 | - * @param string $fileId file id to show |
|
340 | - * @return RedirectResponse redirect response or not found response |
|
341 | - * @throws \OCP\Files\NotFoundException |
|
342 | - */ |
|
343 | - private function redirectToFile($fileId) { |
|
344 | - $uid = $this->userSession->getUser()->getUID(); |
|
345 | - $baseFolder = $this->rootFolder->getUserFolder($uid); |
|
346 | - $files = $baseFolder->getById($fileId); |
|
347 | - $params = []; |
|
348 | - |
|
349 | - if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) { |
|
350 | - $baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/'); |
|
351 | - $files = $baseFolder->getById($fileId); |
|
352 | - $params['view'] = 'trashbin'; |
|
353 | - } |
|
354 | - |
|
355 | - if (!empty($files)) { |
|
356 | - $file = current($files); |
|
357 | - if ($file instanceof Folder) { |
|
358 | - // set the full path to enter the folder |
|
359 | - $params['dir'] = $baseFolder->getRelativePath($file->getPath()); |
|
360 | - } else { |
|
361 | - // set parent path as dir |
|
362 | - $params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath()); |
|
363 | - // and scroll to the entry |
|
364 | - $params['scrollto'] = $file->getName(); |
|
365 | - } |
|
366 | - |
|
367 | - return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params)); |
|
368 | - } |
|
369 | - throw new \OCP\Files\NotFoundException(); |
|
370 | - } |
|
66 | + /** @var string */ |
|
67 | + protected $appName; |
|
68 | + /** @var IRequest */ |
|
69 | + protected $request; |
|
70 | + /** @var IURLGenerator */ |
|
71 | + protected $urlGenerator; |
|
72 | + /** @var IL10N */ |
|
73 | + protected $l10n; |
|
74 | + /** @var IConfig */ |
|
75 | + protected $config; |
|
76 | + /** @var IEventDispatcher */ |
|
77 | + protected $eventDispatcher; |
|
78 | + /** @var IUserSession */ |
|
79 | + protected $userSession; |
|
80 | + /** @var IAppManager */ |
|
81 | + protected $appManager; |
|
82 | + /** @var IRootFolder */ |
|
83 | + protected $rootFolder; |
|
84 | + /** @var Helper */ |
|
85 | + protected $activityHelper; |
|
86 | + /** @var IInitialState */ |
|
87 | + private $initialState; |
|
88 | + /** @var ITemplateManager */ |
|
89 | + private $templateManager; |
|
90 | + /** @var IManager */ |
|
91 | + private $shareManager; |
|
92 | + |
|
93 | + public function __construct(string $appName, |
|
94 | + IRequest $request, |
|
95 | + IURLGenerator $urlGenerator, |
|
96 | + IL10N $l10n, |
|
97 | + IConfig $config, |
|
98 | + IEventDispatcher $eventDispatcher, |
|
99 | + IUserSession $userSession, |
|
100 | + IAppManager $appManager, |
|
101 | + IRootFolder $rootFolder, |
|
102 | + Helper $activityHelper, |
|
103 | + IInitialState $initialState, |
|
104 | + ITemplateManager $templateManager, |
|
105 | + IManager $shareManager |
|
106 | + ) { |
|
107 | + parent::__construct($appName, $request); |
|
108 | + $this->appName = $appName; |
|
109 | + $this->request = $request; |
|
110 | + $this->urlGenerator = $urlGenerator; |
|
111 | + $this->l10n = $l10n; |
|
112 | + $this->config = $config; |
|
113 | + $this->eventDispatcher = $eventDispatcher; |
|
114 | + $this->userSession = $userSession; |
|
115 | + $this->appManager = $appManager; |
|
116 | + $this->rootFolder = $rootFolder; |
|
117 | + $this->activityHelper = $activityHelper; |
|
118 | + $this->initialState = $initialState; |
|
119 | + $this->templateManager = $templateManager; |
|
120 | + $this->shareManager = $shareManager; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * @param string $appName |
|
125 | + * @param string $scriptName |
|
126 | + * @return string |
|
127 | + */ |
|
128 | + protected function renderScript($appName, $scriptName) { |
|
129 | + $content = ''; |
|
130 | + $appPath = \OC_App::getAppPath($appName); |
|
131 | + $scriptPath = $appPath . '/' . $scriptName; |
|
132 | + if (file_exists($scriptPath)) { |
|
133 | + // TODO: sanitize path / script name ? |
|
134 | + ob_start(); |
|
135 | + include $scriptPath; |
|
136 | + $content = ob_get_contents(); |
|
137 | + @ob_end_clean(); |
|
138 | + } |
|
139 | + |
|
140 | + return $content; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * FIXME: Replace with non static code |
|
145 | + * |
|
146 | + * @return array |
|
147 | + * @throws \OCP\Files\NotFoundException |
|
148 | + */ |
|
149 | + protected function getStorageInfo() { |
|
150 | + \OC_Util::setupFS(); |
|
151 | + $dirInfo = \OC\Files\Filesystem::getFileInfo('/', false); |
|
152 | + |
|
153 | + return \OC_Helper::getStorageInfo('/', $dirInfo); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * @NoCSRFRequired |
|
158 | + * @NoAdminRequired |
|
159 | + * |
|
160 | + * @param string $fileid |
|
161 | + * @return TemplateResponse|RedirectResponse |
|
162 | + * @throws NotFoundException |
|
163 | + */ |
|
164 | + public function showFile(string $fileid = null): Response { |
|
165 | + // This is the entry point from the `/f/{fileid}` URL which is hardcoded in the server. |
|
166 | + try { |
|
167 | + return $this->redirectToFile($fileid); |
|
168 | + } catch (NotFoundException $e) { |
|
169 | + return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); |
|
170 | + } |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * @NoCSRFRequired |
|
175 | + * @NoAdminRequired |
|
176 | + * |
|
177 | + * @param string $dir |
|
178 | + * @param string $view |
|
179 | + * @param string $fileid |
|
180 | + * @param bool $fileNotFound |
|
181 | + * @return TemplateResponse|RedirectResponse |
|
182 | + * @throws NotFoundException |
|
183 | + */ |
|
184 | + public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) { |
|
185 | + if ($fileid !== null) { |
|
186 | + try { |
|
187 | + return $this->redirectToFile($fileid); |
|
188 | + } catch (NotFoundException $e) { |
|
189 | + return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); |
|
190 | + } |
|
191 | + } |
|
192 | + |
|
193 | + $nav = new \OCP\Template('files', 'appnavigation', ''); |
|
194 | + |
|
195 | + // Load the files we need |
|
196 | + \OCP\Util::addStyle('files', 'merged'); |
|
197 | + \OCP\Util::addScript('files', 'merged-index'); |
|
198 | + \OCP\Util::addScript('files', 'dist/templates'); |
|
199 | + |
|
200 | + // mostly for the home storage's free space |
|
201 | + // FIXME: Make non static |
|
202 | + $storageInfo = $this->getStorageInfo(); |
|
203 | + |
|
204 | + $user = $this->userSession->getUser()->getUID(); |
|
205 | + |
|
206 | + // Get all the user favorites to create a submenu |
|
207 | + try { |
|
208 | + $favElements = $this->activityHelper->getFavoriteFilePaths($this->userSession->getUser()->getUID()); |
|
209 | + } catch (\RuntimeException $e) { |
|
210 | + $favElements['folders'] = []; |
|
211 | + } |
|
212 | + |
|
213 | + $collapseClasses = ''; |
|
214 | + if (count($favElements['folders']) > 0) { |
|
215 | + $collapseClasses = 'collapsible'; |
|
216 | + } |
|
217 | + |
|
218 | + $favoritesSublistArray = []; |
|
219 | + |
|
220 | + $navBarPositionPosition = 6; |
|
221 | + $currentCount = 0; |
|
222 | + foreach ($favElements['folders'] as $dir) { |
|
223 | + $link = $this->urlGenerator->linkToRoute('files.view.index', ['dir' => $dir, 'view' => 'files']); |
|
224 | + $sortingValue = ++$currentCount; |
|
225 | + $element = [ |
|
226 | + 'id' => str_replace('/', '-', $dir), |
|
227 | + 'view' => 'files', |
|
228 | + 'href' => $link, |
|
229 | + 'dir' => $dir, |
|
230 | + 'order' => $navBarPositionPosition, |
|
231 | + 'folderPosition' => $sortingValue, |
|
232 | + 'name' => basename($dir), |
|
233 | + 'icon' => 'files', |
|
234 | + 'quickaccesselement' => 'true' |
|
235 | + ]; |
|
236 | + |
|
237 | + array_push($favoritesSublistArray, $element); |
|
238 | + $navBarPositionPosition++; |
|
239 | + } |
|
240 | + |
|
241 | + $navItems = \OCA\Files\App::getNavigationManager()->getAll(); |
|
242 | + |
|
243 | + // add the favorites entry in menu |
|
244 | + $navItems['favorites']['sublist'] = $favoritesSublistArray; |
|
245 | + $navItems['favorites']['classes'] = $collapseClasses; |
|
246 | + |
|
247 | + // parse every menu and add the expandedState user value |
|
248 | + foreach ($navItems as $key => $item) { |
|
249 | + if (isset($item['expandedState'])) { |
|
250 | + $navItems[$key]['defaultExpandedState'] = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1'; |
|
251 | + } |
|
252 | + } |
|
253 | + |
|
254 | + $nav->assign('navigationItems', $navItems); |
|
255 | + |
|
256 | + $nav->assign('usage', \OC_Helper::humanFileSize($storageInfo['used'])); |
|
257 | + if ($storageInfo['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
258 | + $totalSpace = $this->l10n->t('Unlimited'); |
|
259 | + } else { |
|
260 | + $totalSpace = \OC_Helper::humanFileSize($storageInfo['total']); |
|
261 | + } |
|
262 | + $nav->assign('total_space', $totalSpace); |
|
263 | + $nav->assign('quota', $storageInfo['quota']); |
|
264 | + $nav->assign('usage_relative', $storageInfo['relative']); |
|
265 | + |
|
266 | + $nav->assign('webdav_url', \OCP\Util::linkToRemote('dav/files/' . $user)); |
|
267 | + |
|
268 | + $contentItems = []; |
|
269 | + |
|
270 | + // render the container content for every navigation item |
|
271 | + foreach ($navItems as $item) { |
|
272 | + $content = ''; |
|
273 | + if (isset($item['script'])) { |
|
274 | + $content = $this->renderScript($item['appname'], $item['script']); |
|
275 | + } |
|
276 | + // parse submenus |
|
277 | + if (isset($item['sublist'])) { |
|
278 | + foreach ($item['sublist'] as $subitem) { |
|
279 | + $subcontent = ''; |
|
280 | + if (isset($subitem['script'])) { |
|
281 | + $subcontent = $this->renderScript($subitem['appname'], $subitem['script']); |
|
282 | + } |
|
283 | + $contentItems[$subitem['id']] = [ |
|
284 | + 'id' => $subitem['id'], |
|
285 | + 'content' => $subcontent |
|
286 | + ]; |
|
287 | + } |
|
288 | + } |
|
289 | + $contentItems[$item['id']] = [ |
|
290 | + 'id' => $item['id'], |
|
291 | + 'content' => $content |
|
292 | + ]; |
|
293 | + } |
|
294 | + |
|
295 | + $event = new LoadAdditionalScriptsEvent(); |
|
296 | + $this->eventDispatcher->dispatchTyped($event); |
|
297 | + $this->eventDispatcher->dispatchTyped(new LoadSidebar()); |
|
298 | + // Load Viewer scripts |
|
299 | + if (class_exists(LoadViewer::class)) { |
|
300 | + $this->eventDispatcher->dispatchTyped(new LoadViewer()); |
|
301 | + } |
|
302 | + $this->initialState->provideInitialState('templates_path', $this->templateManager->hasTemplateDirectory() ? $this->templateManager->getTemplatePath() : false); |
|
303 | + $this->initialState->provideInitialState('templates', $this->templateManager->listCreators()); |
|
304 | + |
|
305 | + $params = []; |
|
306 | + $params['usedSpacePercent'] = (int) $storageInfo['relative']; |
|
307 | + $params['owner'] = $storageInfo['owner'] ?? ''; |
|
308 | + $params['ownerDisplayName'] = $storageInfo['ownerDisplayName'] ?? ''; |
|
309 | + $params['isPublic'] = false; |
|
310 | + $params['allowShareWithLink'] = $this->shareManager->shareApiAllowLinks() ? 'yes' : 'no'; |
|
311 | + $params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name'); |
|
312 | + $params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc'); |
|
313 | + $params['showgridview'] = $this->config->getUserValue($user, 'files', 'show_grid', false); |
|
314 | + $params['isIE'] = \OC_Util::isIe(); |
|
315 | + $showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false); |
|
316 | + $params['showHiddenFiles'] = $showHidden ? 1 : 0; |
|
317 | + $cropImagePreviews = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', true); |
|
318 | + $params['cropImagePreviews'] = $cropImagePreviews ? 1 : 0; |
|
319 | + $params['fileNotFound'] = $fileNotFound ? 1 : 0; |
|
320 | + $params['appNavigation'] = $nav; |
|
321 | + $params['appContents'] = $contentItems; |
|
322 | + $params['hiddenFields'] = $event->getHiddenFields(); |
|
323 | + |
|
324 | + $response = new TemplateResponse( |
|
325 | + $this->appName, |
|
326 | + 'index', |
|
327 | + $params |
|
328 | + ); |
|
329 | + $policy = new ContentSecurityPolicy(); |
|
330 | + $policy->addAllowedFrameDomain('\'self\''); |
|
331 | + $response->setContentSecurityPolicy($policy); |
|
332 | + |
|
333 | + return $response; |
|
334 | + } |
|
335 | + |
|
336 | + /** |
|
337 | + * Redirects to the file list and highlight the given file id |
|
338 | + * |
|
339 | + * @param string $fileId file id to show |
|
340 | + * @return RedirectResponse redirect response or not found response |
|
341 | + * @throws \OCP\Files\NotFoundException |
|
342 | + */ |
|
343 | + private function redirectToFile($fileId) { |
|
344 | + $uid = $this->userSession->getUser()->getUID(); |
|
345 | + $baseFolder = $this->rootFolder->getUserFolder($uid); |
|
346 | + $files = $baseFolder->getById($fileId); |
|
347 | + $params = []; |
|
348 | + |
|
349 | + if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) { |
|
350 | + $baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/'); |
|
351 | + $files = $baseFolder->getById($fileId); |
|
352 | + $params['view'] = 'trashbin'; |
|
353 | + } |
|
354 | + |
|
355 | + if (!empty($files)) { |
|
356 | + $file = current($files); |
|
357 | + if ($file instanceof Folder) { |
|
358 | + // set the full path to enter the folder |
|
359 | + $params['dir'] = $baseFolder->getRelativePath($file->getPath()); |
|
360 | + } else { |
|
361 | + // set parent path as dir |
|
362 | + $params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath()); |
|
363 | + // and scroll to the entry |
|
364 | + $params['scrollto'] = $file->getName(); |
|
365 | + } |
|
366 | + |
|
367 | + return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params)); |
|
368 | + } |
|
369 | + throw new \OCP\Files\NotFoundException(); |
|
370 | + } |
|
371 | 371 | } |
@@ -29,7 +29,7 @@ |
||
29 | 29 | // TODO: move this to the generated config.js |
30 | 30 | /** @var IManager $shareManager */ |
31 | 31 | $shareManager = \OC::$server->get(IManager::class); |
32 | -$publicUploadEnabled = $shareManager->shareApiLinkAllowPublicUpload() ? 'yes' : 'no';; |
|
32 | +$publicUploadEnabled = $shareManager->shareApiLinkAllowPublicUpload() ? 'yes' : 'no'; ; |
|
33 | 33 | |
34 | 34 | $showgridview = $config->getUserValue($userSession->getUser()->getUID(), 'files', 'show_grid', false); |
35 | 35 | $isIE = OC_Util::isIe(); |
@@ -65,183 +65,183 @@ |
||
65 | 65 | use Symfony\Component\EventDispatcher\GenericEvent; |
66 | 66 | |
67 | 67 | class Application extends App { |
68 | - public const APP_ID = 'files_sharing'; |
|
69 | - |
|
70 | - public function __construct(array $urlParams = []) { |
|
71 | - parent::__construct(self::APP_ID, $urlParams); |
|
72 | - |
|
73 | - $container = $this->getContainer(); |
|
74 | - |
|
75 | - /** @var IServerContainer $server */ |
|
76 | - $server = $container->getServer(); |
|
77 | - |
|
78 | - /** @var IEventDispatcher $dispatcher */ |
|
79 | - $dispatcher = $container->query(IEventDispatcher::class); |
|
80 | - $oldDispatcher = $container->getServer()->getEventDispatcher(); |
|
81 | - $mountProviderCollection = $server->getMountProviderCollection(); |
|
82 | - $notifications = $server->getNotificationManager(); |
|
83 | - |
|
84 | - /** |
|
85 | - * Core class wrappers |
|
86 | - */ |
|
87 | - $container->registerService(Manager::class, function (SimpleContainer $c) use ($server) { |
|
88 | - $user = $server->getUserSession()->getUser(); |
|
89 | - $uid = $user ? $user->getUID() : null; |
|
90 | - return new \OCA\Files_Sharing\External\Manager( |
|
91 | - $server->getDatabaseConnection(), |
|
92 | - \OC\Files\Filesystem::getMountManager(), |
|
93 | - \OC\Files\Filesystem::getLoader(), |
|
94 | - $server->getHTTPClientService(), |
|
95 | - $server->getNotificationManager(), |
|
96 | - $server->query(\OCP\OCS\IDiscoveryService::class), |
|
97 | - $server->getCloudFederationProviderManager(), |
|
98 | - $server->getCloudFederationFactory(), |
|
99 | - $server->getGroupManager(), |
|
100 | - $server->getUserManager(), |
|
101 | - $uid, |
|
102 | - $server->query(IEventDispatcher::class) |
|
103 | - ); |
|
104 | - }); |
|
105 | - |
|
106 | - /** |
|
107 | - * Middleware |
|
108 | - */ |
|
109 | - $container->registerMiddleWare(SharingCheckMiddleware::class); |
|
110 | - $container->registerMiddleWare(OCSShareAPIMiddleware::class); |
|
111 | - $container->registerMiddleWare(ShareInfoMiddleware::class); |
|
112 | - |
|
113 | - $container->registerService('ExternalMountProvider', function (ContainerInterface $c) { |
|
114 | - return new \OCA\Files_Sharing\External\MountProvider( |
|
115 | - $c->get(IDBConnection::class), |
|
116 | - function () use ($c) { |
|
117 | - return $c->get(Manager::class); |
|
118 | - }, |
|
119 | - $c->get(ICloudIdManager::class) |
|
120 | - ); |
|
121 | - }); |
|
122 | - |
|
123 | - /** |
|
124 | - * Register capabilities |
|
125 | - */ |
|
126 | - $container->registerCapability(Capabilities::class); |
|
127 | - |
|
128 | - $notifications->registerNotifierService(Notifier::class); |
|
129 | - |
|
130 | - $this->registerMountProviders($mountProviderCollection); |
|
131 | - $this->registerEventsScripts($dispatcher, $oldDispatcher); |
|
132 | - $this->setupSharingMenus(); |
|
133 | - |
|
134 | - /** |
|
135 | - * Always add main sharing script |
|
136 | - */ |
|
137 | - Util::addScript(self::APP_ID, 'dist/main'); |
|
138 | - } |
|
139 | - |
|
140 | - protected function registerMountProviders(IMountProviderCollection $mountProviderCollection) { |
|
141 | - $mountProviderCollection->registerProvider($this->getContainer()->query(MountProvider::class)); |
|
142 | - $mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider')); |
|
143 | - } |
|
144 | - |
|
145 | - protected function registerEventsScripts(IEventDispatcher $dispatcher, EventDispatcherInterface $oldDispatcher) { |
|
146 | - // sidebar and files scripts |
|
147 | - $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class); |
|
148 | - $dispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, LegacyBeforeTemplateRenderedListener::class); |
|
149 | - $dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarListener::class); |
|
150 | - $dispatcher->addServiceListener(ShareCreatedEvent::class, ShareInteractionListener::class); |
|
151 | - $dispatcher->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', function () { |
|
152 | - \OCP\Util::addScript('files_sharing', 'dist/collaboration'); |
|
153 | - }); |
|
154 | - $dispatcher->addServiceListener(ShareCreatedEvent::class, UserShareAcceptanceListener::class); |
|
155 | - $dispatcher->addServiceListener(UserAddedEvent::class, UserAddedToGroupListener::class); |
|
156 | - |
|
157 | - // notifications api to accept incoming user shares |
|
158 | - $oldDispatcher->addListener('OCP\Share::postShare', function (GenericEvent $event) { |
|
159 | - /** @var Listener $listener */ |
|
160 | - $listener = $this->getContainer()->query(Listener::class); |
|
161 | - $listener->shareNotification($event); |
|
162 | - }); |
|
163 | - $oldDispatcher->addListener(IGroup::class . '::postAddUser', function (GenericEvent $event) { |
|
164 | - /** @var Listener $listener */ |
|
165 | - $listener = $this->getContainer()->query(Listener::class); |
|
166 | - $listener->userAddedToGroup($event); |
|
167 | - }); |
|
168 | - } |
|
169 | - |
|
170 | - protected function setupSharingMenus() { |
|
171 | - /** @var IManager $shareManager */ |
|
172 | - $shareManager = \OC::$server->get(IManager::class); |
|
173 | - |
|
174 | - if (!$shareManager->shareApiEnabled() || !class_exists('\OCA\Files\App')) { |
|
175 | - return; |
|
176 | - } |
|
177 | - |
|
178 | - // show_Quick_Access stored as string |
|
179 | - \OCA\Files\App::getNavigationManager()->add(function () use ($shareManager) { |
|
180 | - $l = \OC::$server->getL10N('files_sharing'); |
|
181 | - /** @var IUserSession $userSession */ |
|
182 | - $userSession = \OC::$server->get(IUserSession::class); |
|
183 | - $user = $userSession->getUser(); |
|
184 | - $userId = $user ? $user->getUID() : null; |
|
185 | - |
|
186 | - $sharingSublistArray = []; |
|
187 | - |
|
188 | - if ($shareManager->sharingDisabledForUser($userId) === false) { |
|
189 | - $sharingSublistArray[] = [ |
|
190 | - 'id' => 'sharingout', |
|
191 | - 'appname' => 'files_sharing', |
|
192 | - 'script' => 'list.php', |
|
193 | - 'order' => 16, |
|
194 | - 'name' => $l->t('Shared with others'), |
|
195 | - ]; |
|
196 | - } |
|
197 | - |
|
198 | - $sharingSublistArray[] = [ |
|
199 | - 'id' => 'sharingin', |
|
200 | - 'appname' => 'files_sharing', |
|
201 | - 'script' => 'list.php', |
|
202 | - 'order' => 15, |
|
203 | - 'name' => $l->t('Shared with you'), |
|
204 | - ]; |
|
205 | - |
|
206 | - if ($shareManager->sharingDisabledForUser($userId) === false) { |
|
207 | - // Check if sharing by link is enabled |
|
208 | - if ($shareManager->shareApiAllowLinks()) { |
|
209 | - $sharingSublistArray[] = [ |
|
210 | - 'id' => 'sharinglinks', |
|
211 | - 'appname' => 'files_sharing', |
|
212 | - 'script' => 'list.php', |
|
213 | - 'order' => 17, |
|
214 | - 'name' => $l->t('Shared by link'), |
|
215 | - ]; |
|
216 | - } |
|
217 | - } |
|
218 | - |
|
219 | - $sharingSublistArray[] = [ |
|
220 | - 'id' => 'deletedshares', |
|
221 | - 'appname' => 'files_sharing', |
|
222 | - 'script' => 'list.php', |
|
223 | - 'order' => 19, |
|
224 | - 'name' => $l->t('Deleted shares'), |
|
225 | - ]; |
|
226 | - |
|
227 | - $sharingSublistArray[] = [ |
|
228 | - 'id' => 'pendingshares', |
|
229 | - 'appname' => 'files_sharing', |
|
230 | - 'script' => 'list.php', |
|
231 | - 'order' => 19, |
|
232 | - 'name' => $l->t('Pending shares'), |
|
233 | - ]; |
|
234 | - |
|
235 | - return [ |
|
236 | - 'id' => 'shareoverview', |
|
237 | - 'appname' => 'files_sharing', |
|
238 | - 'script' => 'list.php', |
|
239 | - 'order' => 18, |
|
240 | - 'name' => $l->t('Shares'), |
|
241 | - 'classes' => 'collapsible', |
|
242 | - 'sublist' => $sharingSublistArray, |
|
243 | - 'expandedState' => 'show_sharing_menu' |
|
244 | - ]; |
|
245 | - }); |
|
246 | - } |
|
68 | + public const APP_ID = 'files_sharing'; |
|
69 | + |
|
70 | + public function __construct(array $urlParams = []) { |
|
71 | + parent::__construct(self::APP_ID, $urlParams); |
|
72 | + |
|
73 | + $container = $this->getContainer(); |
|
74 | + |
|
75 | + /** @var IServerContainer $server */ |
|
76 | + $server = $container->getServer(); |
|
77 | + |
|
78 | + /** @var IEventDispatcher $dispatcher */ |
|
79 | + $dispatcher = $container->query(IEventDispatcher::class); |
|
80 | + $oldDispatcher = $container->getServer()->getEventDispatcher(); |
|
81 | + $mountProviderCollection = $server->getMountProviderCollection(); |
|
82 | + $notifications = $server->getNotificationManager(); |
|
83 | + |
|
84 | + /** |
|
85 | + * Core class wrappers |
|
86 | + */ |
|
87 | + $container->registerService(Manager::class, function (SimpleContainer $c) use ($server) { |
|
88 | + $user = $server->getUserSession()->getUser(); |
|
89 | + $uid = $user ? $user->getUID() : null; |
|
90 | + return new \OCA\Files_Sharing\External\Manager( |
|
91 | + $server->getDatabaseConnection(), |
|
92 | + \OC\Files\Filesystem::getMountManager(), |
|
93 | + \OC\Files\Filesystem::getLoader(), |
|
94 | + $server->getHTTPClientService(), |
|
95 | + $server->getNotificationManager(), |
|
96 | + $server->query(\OCP\OCS\IDiscoveryService::class), |
|
97 | + $server->getCloudFederationProviderManager(), |
|
98 | + $server->getCloudFederationFactory(), |
|
99 | + $server->getGroupManager(), |
|
100 | + $server->getUserManager(), |
|
101 | + $uid, |
|
102 | + $server->query(IEventDispatcher::class) |
|
103 | + ); |
|
104 | + }); |
|
105 | + |
|
106 | + /** |
|
107 | + * Middleware |
|
108 | + */ |
|
109 | + $container->registerMiddleWare(SharingCheckMiddleware::class); |
|
110 | + $container->registerMiddleWare(OCSShareAPIMiddleware::class); |
|
111 | + $container->registerMiddleWare(ShareInfoMiddleware::class); |
|
112 | + |
|
113 | + $container->registerService('ExternalMountProvider', function (ContainerInterface $c) { |
|
114 | + return new \OCA\Files_Sharing\External\MountProvider( |
|
115 | + $c->get(IDBConnection::class), |
|
116 | + function () use ($c) { |
|
117 | + return $c->get(Manager::class); |
|
118 | + }, |
|
119 | + $c->get(ICloudIdManager::class) |
|
120 | + ); |
|
121 | + }); |
|
122 | + |
|
123 | + /** |
|
124 | + * Register capabilities |
|
125 | + */ |
|
126 | + $container->registerCapability(Capabilities::class); |
|
127 | + |
|
128 | + $notifications->registerNotifierService(Notifier::class); |
|
129 | + |
|
130 | + $this->registerMountProviders($mountProviderCollection); |
|
131 | + $this->registerEventsScripts($dispatcher, $oldDispatcher); |
|
132 | + $this->setupSharingMenus(); |
|
133 | + |
|
134 | + /** |
|
135 | + * Always add main sharing script |
|
136 | + */ |
|
137 | + Util::addScript(self::APP_ID, 'dist/main'); |
|
138 | + } |
|
139 | + |
|
140 | + protected function registerMountProviders(IMountProviderCollection $mountProviderCollection) { |
|
141 | + $mountProviderCollection->registerProvider($this->getContainer()->query(MountProvider::class)); |
|
142 | + $mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider')); |
|
143 | + } |
|
144 | + |
|
145 | + protected function registerEventsScripts(IEventDispatcher $dispatcher, EventDispatcherInterface $oldDispatcher) { |
|
146 | + // sidebar and files scripts |
|
147 | + $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class); |
|
148 | + $dispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, LegacyBeforeTemplateRenderedListener::class); |
|
149 | + $dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarListener::class); |
|
150 | + $dispatcher->addServiceListener(ShareCreatedEvent::class, ShareInteractionListener::class); |
|
151 | + $dispatcher->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', function () { |
|
152 | + \OCP\Util::addScript('files_sharing', 'dist/collaboration'); |
|
153 | + }); |
|
154 | + $dispatcher->addServiceListener(ShareCreatedEvent::class, UserShareAcceptanceListener::class); |
|
155 | + $dispatcher->addServiceListener(UserAddedEvent::class, UserAddedToGroupListener::class); |
|
156 | + |
|
157 | + // notifications api to accept incoming user shares |
|
158 | + $oldDispatcher->addListener('OCP\Share::postShare', function (GenericEvent $event) { |
|
159 | + /** @var Listener $listener */ |
|
160 | + $listener = $this->getContainer()->query(Listener::class); |
|
161 | + $listener->shareNotification($event); |
|
162 | + }); |
|
163 | + $oldDispatcher->addListener(IGroup::class . '::postAddUser', function (GenericEvent $event) { |
|
164 | + /** @var Listener $listener */ |
|
165 | + $listener = $this->getContainer()->query(Listener::class); |
|
166 | + $listener->userAddedToGroup($event); |
|
167 | + }); |
|
168 | + } |
|
169 | + |
|
170 | + protected function setupSharingMenus() { |
|
171 | + /** @var IManager $shareManager */ |
|
172 | + $shareManager = \OC::$server->get(IManager::class); |
|
173 | + |
|
174 | + if (!$shareManager->shareApiEnabled() || !class_exists('\OCA\Files\App')) { |
|
175 | + return; |
|
176 | + } |
|
177 | + |
|
178 | + // show_Quick_Access stored as string |
|
179 | + \OCA\Files\App::getNavigationManager()->add(function () use ($shareManager) { |
|
180 | + $l = \OC::$server->getL10N('files_sharing'); |
|
181 | + /** @var IUserSession $userSession */ |
|
182 | + $userSession = \OC::$server->get(IUserSession::class); |
|
183 | + $user = $userSession->getUser(); |
|
184 | + $userId = $user ? $user->getUID() : null; |
|
185 | + |
|
186 | + $sharingSublistArray = []; |
|
187 | + |
|
188 | + if ($shareManager->sharingDisabledForUser($userId) === false) { |
|
189 | + $sharingSublistArray[] = [ |
|
190 | + 'id' => 'sharingout', |
|
191 | + 'appname' => 'files_sharing', |
|
192 | + 'script' => 'list.php', |
|
193 | + 'order' => 16, |
|
194 | + 'name' => $l->t('Shared with others'), |
|
195 | + ]; |
|
196 | + } |
|
197 | + |
|
198 | + $sharingSublistArray[] = [ |
|
199 | + 'id' => 'sharingin', |
|
200 | + 'appname' => 'files_sharing', |
|
201 | + 'script' => 'list.php', |
|
202 | + 'order' => 15, |
|
203 | + 'name' => $l->t('Shared with you'), |
|
204 | + ]; |
|
205 | + |
|
206 | + if ($shareManager->sharingDisabledForUser($userId) === false) { |
|
207 | + // Check if sharing by link is enabled |
|
208 | + if ($shareManager->shareApiAllowLinks()) { |
|
209 | + $sharingSublistArray[] = [ |
|
210 | + 'id' => 'sharinglinks', |
|
211 | + 'appname' => 'files_sharing', |
|
212 | + 'script' => 'list.php', |
|
213 | + 'order' => 17, |
|
214 | + 'name' => $l->t('Shared by link'), |
|
215 | + ]; |
|
216 | + } |
|
217 | + } |
|
218 | + |
|
219 | + $sharingSublistArray[] = [ |
|
220 | + 'id' => 'deletedshares', |
|
221 | + 'appname' => 'files_sharing', |
|
222 | + 'script' => 'list.php', |
|
223 | + 'order' => 19, |
|
224 | + 'name' => $l->t('Deleted shares'), |
|
225 | + ]; |
|
226 | + |
|
227 | + $sharingSublistArray[] = [ |
|
228 | + 'id' => 'pendingshares', |
|
229 | + 'appname' => 'files_sharing', |
|
230 | + 'script' => 'list.php', |
|
231 | + 'order' => 19, |
|
232 | + 'name' => $l->t('Pending shares'), |
|
233 | + ]; |
|
234 | + |
|
235 | + return [ |
|
236 | + 'id' => 'shareoverview', |
|
237 | + 'appname' => 'files_sharing', |
|
238 | + 'script' => 'list.php', |
|
239 | + 'order' => 18, |
|
240 | + 'name' => $l->t('Shares'), |
|
241 | + 'classes' => 'collapsible', |
|
242 | + 'sublist' => $sharingSublistArray, |
|
243 | + 'expandedState' => 'show_sharing_menu' |
|
244 | + ]; |
|
245 | + }); |
|
246 | + } |
|
247 | 247 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | /** |
85 | 85 | * Core class wrappers |
86 | 86 | */ |
87 | - $container->registerService(Manager::class, function (SimpleContainer $c) use ($server) { |
|
87 | + $container->registerService(Manager::class, function(SimpleContainer $c) use ($server) { |
|
88 | 88 | $user = $server->getUserSession()->getUser(); |
89 | 89 | $uid = $user ? $user->getUID() : null; |
90 | 90 | return new \OCA\Files_Sharing\External\Manager( |
@@ -110,10 +110,10 @@ discard block |
||
110 | 110 | $container->registerMiddleWare(OCSShareAPIMiddleware::class); |
111 | 111 | $container->registerMiddleWare(ShareInfoMiddleware::class); |
112 | 112 | |
113 | - $container->registerService('ExternalMountProvider', function (ContainerInterface $c) { |
|
113 | + $container->registerService('ExternalMountProvider', function(ContainerInterface $c) { |
|
114 | 114 | return new \OCA\Files_Sharing\External\MountProvider( |
115 | 115 | $c->get(IDBConnection::class), |
116 | - function () use ($c) { |
|
116 | + function() use ($c) { |
|
117 | 117 | return $c->get(Manager::class); |
118 | 118 | }, |
119 | 119 | $c->get(ICloudIdManager::class) |
@@ -148,19 +148,19 @@ discard block |
||
148 | 148 | $dispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, LegacyBeforeTemplateRenderedListener::class); |
149 | 149 | $dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarListener::class); |
150 | 150 | $dispatcher->addServiceListener(ShareCreatedEvent::class, ShareInteractionListener::class); |
151 | - $dispatcher->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', function () { |
|
151 | + $dispatcher->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', function() { |
|
152 | 152 | \OCP\Util::addScript('files_sharing', 'dist/collaboration'); |
153 | 153 | }); |
154 | 154 | $dispatcher->addServiceListener(ShareCreatedEvent::class, UserShareAcceptanceListener::class); |
155 | 155 | $dispatcher->addServiceListener(UserAddedEvent::class, UserAddedToGroupListener::class); |
156 | 156 | |
157 | 157 | // notifications api to accept incoming user shares |
158 | - $oldDispatcher->addListener('OCP\Share::postShare', function (GenericEvent $event) { |
|
158 | + $oldDispatcher->addListener('OCP\Share::postShare', function(GenericEvent $event) { |
|
159 | 159 | /** @var Listener $listener */ |
160 | 160 | $listener = $this->getContainer()->query(Listener::class); |
161 | 161 | $listener->shareNotification($event); |
162 | 162 | }); |
163 | - $oldDispatcher->addListener(IGroup::class . '::postAddUser', function (GenericEvent $event) { |
|
163 | + $oldDispatcher->addListener(IGroup::class.'::postAddUser', function(GenericEvent $event) { |
|
164 | 164 | /** @var Listener $listener */ |
165 | 165 | $listener = $this->getContainer()->query(Listener::class); |
166 | 166 | $listener->userAddedToGroup($event); |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | } |
177 | 177 | |
178 | 178 | // show_Quick_Access stored as string |
179 | - \OCA\Files\App::getNavigationManager()->add(function () use ($shareManager) { |
|
179 | + \OCA\Files\App::getNavigationManager()->add(function() use ($shareManager) { |
|
180 | 180 | $l = \OC::$server->getL10N('files_sharing'); |
181 | 181 | /** @var IUserSession $userSession */ |
182 | 182 | $userSession = \OC::$server->get(IUserSession::class); |
@@ -37,105 +37,105 @@ |
||
37 | 37 | */ |
38 | 38 | class Capabilities implements ICapability { |
39 | 39 | |
40 | - /** @var IConfig */ |
|
41 | - private $config; |
|
42 | - /** @var IManager */ |
|
43 | - private $shareManager; |
|
44 | - |
|
45 | - public function __construct(IConfig $config, IManager $shareManager) { |
|
46 | - $this->config = $config; |
|
47 | - $this->shareManager = $shareManager; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Return this classes capabilities |
|
52 | - * |
|
53 | - * @return array |
|
54 | - */ |
|
55 | - public function getCapabilities() { |
|
56 | - $res = []; |
|
57 | - |
|
58 | - if (!$this->shareManager->shareApiEnabled()) { |
|
59 | - $res['api_enabled'] = false; |
|
60 | - $res['public'] = ['enabled' => false]; |
|
61 | - $res['user'] = ['send_mail' => false]; |
|
62 | - $res['resharing'] = false; |
|
63 | - } else { |
|
64 | - $res['api_enabled'] = true; |
|
65 | - |
|
66 | - $public = []; |
|
67 | - $public['enabled'] = $this->shareManager->shareApiAllowLinks(); |
|
68 | - if ($public['enabled']) { |
|
69 | - $public['password'] = []; |
|
70 | - $public['password']['enforced'] = $this->shareManager->shareApiLinkEnforcePassword(); |
|
71 | - |
|
72 | - if ($public['password']['enforced']) { |
|
73 | - $public['password']['askForOptionalPassword'] = false; |
|
74 | - } else { |
|
75 | - $public['password']['askForOptionalPassword'] = ($this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no') === 'yes'); |
|
76 | - } |
|
77 | - |
|
78 | - $public['expire_date'] = []; |
|
79 | - $public['multiple_links'] = true; |
|
80 | - $public['expire_date']['enabled'] = $this->shareManager->shareApiLinkDefaultExpireDate(); |
|
81 | - if ($public['expire_date']['enabled']) { |
|
82 | - $public['expire_date']['days'] = $this->shareManager->shareApiLinkDefaultExpireDays(); |
|
83 | - $public['expire_date']['enforced'] = $this->shareManager->shareApiLinkDefaultExpireDateEnforced(); |
|
84 | - } |
|
85 | - |
|
86 | - $public['expire_date_internal'] = []; |
|
87 | - $public['expire_date_internal']['enabled'] = $this->shareManager->shareApiInternalDefaultExpireDate(); |
|
88 | - if ($public['expire_date_internal']['enabled']) { |
|
89 | - $public['expire_date_internal']['days'] = $this->shareManager->shareApiInternalDefaultExpireDays(); |
|
90 | - $public['expire_date_internal']['enforced'] = $this->shareManager->shareApiInternalDefaultExpireDateEnforced(); |
|
91 | - } |
|
92 | - |
|
93 | - $public['expire_date_remote'] = []; |
|
94 | - $public['expire_date_remote']['enabled'] = $this->shareManager->shareApiRemoteDefaultExpireDate(); |
|
95 | - if ($public['expire_date_remote']['enabled']) { |
|
96 | - $public['expire_date_remote']['days'] = $this->shareManager->shareApiRemoteDefaultExpireDays(); |
|
97 | - $public['expire_date_remote']['enforced'] = $this->shareManager->shareApiRemoteDefaultExpireDateEnforced(); |
|
98 | - } |
|
99 | - |
|
100 | - $public['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no') === 'yes'; |
|
101 | - $public['upload'] = $this->shareManager->shareApiLinkAllowPublicUpload(); |
|
102 | - $public['upload_files_drop'] = $public['upload']; |
|
103 | - } |
|
104 | - $res['public'] = $public; |
|
105 | - |
|
106 | - $res['resharing'] = $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') === 'yes'; |
|
107 | - |
|
108 | - $res['user']['send_mail'] = false; |
|
109 | - $res['user']['expire_date']['enabled'] = true; |
|
110 | - |
|
111 | - // deprecated in favour of 'group', but we need to keep it for now |
|
112 | - // in order to stay compatible with older clients |
|
113 | - $res['group_sharing'] = $this->shareManager->allowGroupSharing(); |
|
114 | - |
|
115 | - $res['group'] = []; |
|
116 | - $res['group']['enabled'] = $this->shareManager->allowGroupSharing(); |
|
117 | - $res['group']['expire_date']['enabled'] = true; |
|
118 | - $res['default_permissions'] = (int)$this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL); |
|
119 | - } |
|
120 | - |
|
121 | - //Federated sharing |
|
122 | - $res['federation'] = [ |
|
123 | - 'outgoing' => $this->shareManager->outgoingServer2ServerSharesAllowed(), |
|
124 | - 'incoming' => $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'yes', |
|
125 | - // old bogus one, expire_date was not working before, keeping for compatibility |
|
126 | - 'expire_date' => ['enabled' => true], |
|
127 | - // the real deal, signifies that expiration date can be set on federated shares |
|
128 | - 'expire_date_supported' => ['enabled' => true], |
|
129 | - ]; |
|
130 | - |
|
131 | - // Sharee searches |
|
132 | - $res['sharee'] = [ |
|
133 | - 'query_lookup_default' => $this->config->getSystemValueBool('gs.enabled', false), |
|
134 | - 'always_show_unique' => $this->config->getAppValue('files_sharing', 'always_show_unique', 'yes') === 'yes', |
|
135 | - ]; |
|
136 | - |
|
137 | - return [ |
|
138 | - 'files_sharing' => $res, |
|
139 | - ]; |
|
140 | - } |
|
40 | + /** @var IConfig */ |
|
41 | + private $config; |
|
42 | + /** @var IManager */ |
|
43 | + private $shareManager; |
|
44 | + |
|
45 | + public function __construct(IConfig $config, IManager $shareManager) { |
|
46 | + $this->config = $config; |
|
47 | + $this->shareManager = $shareManager; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Return this classes capabilities |
|
52 | + * |
|
53 | + * @return array |
|
54 | + */ |
|
55 | + public function getCapabilities() { |
|
56 | + $res = []; |
|
57 | + |
|
58 | + if (!$this->shareManager->shareApiEnabled()) { |
|
59 | + $res['api_enabled'] = false; |
|
60 | + $res['public'] = ['enabled' => false]; |
|
61 | + $res['user'] = ['send_mail' => false]; |
|
62 | + $res['resharing'] = false; |
|
63 | + } else { |
|
64 | + $res['api_enabled'] = true; |
|
65 | + |
|
66 | + $public = []; |
|
67 | + $public['enabled'] = $this->shareManager->shareApiAllowLinks(); |
|
68 | + if ($public['enabled']) { |
|
69 | + $public['password'] = []; |
|
70 | + $public['password']['enforced'] = $this->shareManager->shareApiLinkEnforcePassword(); |
|
71 | + |
|
72 | + if ($public['password']['enforced']) { |
|
73 | + $public['password']['askForOptionalPassword'] = false; |
|
74 | + } else { |
|
75 | + $public['password']['askForOptionalPassword'] = ($this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no') === 'yes'); |
|
76 | + } |
|
77 | + |
|
78 | + $public['expire_date'] = []; |
|
79 | + $public['multiple_links'] = true; |
|
80 | + $public['expire_date']['enabled'] = $this->shareManager->shareApiLinkDefaultExpireDate(); |
|
81 | + if ($public['expire_date']['enabled']) { |
|
82 | + $public['expire_date']['days'] = $this->shareManager->shareApiLinkDefaultExpireDays(); |
|
83 | + $public['expire_date']['enforced'] = $this->shareManager->shareApiLinkDefaultExpireDateEnforced(); |
|
84 | + } |
|
85 | + |
|
86 | + $public['expire_date_internal'] = []; |
|
87 | + $public['expire_date_internal']['enabled'] = $this->shareManager->shareApiInternalDefaultExpireDate(); |
|
88 | + if ($public['expire_date_internal']['enabled']) { |
|
89 | + $public['expire_date_internal']['days'] = $this->shareManager->shareApiInternalDefaultExpireDays(); |
|
90 | + $public['expire_date_internal']['enforced'] = $this->shareManager->shareApiInternalDefaultExpireDateEnforced(); |
|
91 | + } |
|
92 | + |
|
93 | + $public['expire_date_remote'] = []; |
|
94 | + $public['expire_date_remote']['enabled'] = $this->shareManager->shareApiRemoteDefaultExpireDate(); |
|
95 | + if ($public['expire_date_remote']['enabled']) { |
|
96 | + $public['expire_date_remote']['days'] = $this->shareManager->shareApiRemoteDefaultExpireDays(); |
|
97 | + $public['expire_date_remote']['enforced'] = $this->shareManager->shareApiRemoteDefaultExpireDateEnforced(); |
|
98 | + } |
|
99 | + |
|
100 | + $public['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no') === 'yes'; |
|
101 | + $public['upload'] = $this->shareManager->shareApiLinkAllowPublicUpload(); |
|
102 | + $public['upload_files_drop'] = $public['upload']; |
|
103 | + } |
|
104 | + $res['public'] = $public; |
|
105 | + |
|
106 | + $res['resharing'] = $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') === 'yes'; |
|
107 | + |
|
108 | + $res['user']['send_mail'] = false; |
|
109 | + $res['user']['expire_date']['enabled'] = true; |
|
110 | + |
|
111 | + // deprecated in favour of 'group', but we need to keep it for now |
|
112 | + // in order to stay compatible with older clients |
|
113 | + $res['group_sharing'] = $this->shareManager->allowGroupSharing(); |
|
114 | + |
|
115 | + $res['group'] = []; |
|
116 | + $res['group']['enabled'] = $this->shareManager->allowGroupSharing(); |
|
117 | + $res['group']['expire_date']['enabled'] = true; |
|
118 | + $res['default_permissions'] = (int)$this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL); |
|
119 | + } |
|
120 | + |
|
121 | + //Federated sharing |
|
122 | + $res['federation'] = [ |
|
123 | + 'outgoing' => $this->shareManager->outgoingServer2ServerSharesAllowed(), |
|
124 | + 'incoming' => $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'yes', |
|
125 | + // old bogus one, expire_date was not working before, keeping for compatibility |
|
126 | + 'expire_date' => ['enabled' => true], |
|
127 | + // the real deal, signifies that expiration date can be set on federated shares |
|
128 | + 'expire_date_supported' => ['enabled' => true], |
|
129 | + ]; |
|
130 | + |
|
131 | + // Sharee searches |
|
132 | + $res['sharee'] = [ |
|
133 | + 'query_lookup_default' => $this->config->getSystemValueBool('gs.enabled', false), |
|
134 | + 'always_show_unique' => $this->config->getAppValue('files_sharing', 'always_show_unique', 'yes') === 'yes', |
|
135 | + ]; |
|
136 | + |
|
137 | + return [ |
|
138 | + 'files_sharing' => $res, |
|
139 | + ]; |
|
140 | + } |
|
141 | 141 | } |
@@ -115,7 +115,7 @@ |
||
115 | 115 | $res['group'] = []; |
116 | 116 | $res['group']['enabled'] = $this->shareManager->allowGroupSharing(); |
117 | 117 | $res['group']['expire_date']['enabled'] = true; |
118 | - $res['default_permissions'] = (int)$this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL); |
|
118 | + $res['default_permissions'] = (int) $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | //Federated sharing |
@@ -39,114 +39,114 @@ |
||
39 | 39 | use OCP\Util; |
40 | 40 | |
41 | 41 | class Sharing implements ISettings { |
42 | - /** @var IConfig */ |
|
43 | - private $config; |
|
42 | + /** @var IConfig */ |
|
43 | + private $config; |
|
44 | 44 | |
45 | - /** @var IL10N */ |
|
46 | - private $l; |
|
45 | + /** @var IL10N */ |
|
46 | + private $l; |
|
47 | 47 | |
48 | - /** @var IManager */ |
|
49 | - private $shareManager; |
|
48 | + /** @var IManager */ |
|
49 | + private $shareManager; |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param IConfig $config |
|
53 | - */ |
|
54 | - public function __construct(IConfig $config, IL10N $l, IManager $shareManager) { |
|
55 | - $this->config = $config; |
|
56 | - $this->l = $l; |
|
57 | - $this->shareManager = $shareManager; |
|
58 | - } |
|
51 | + /** |
|
52 | + * @param IConfig $config |
|
53 | + */ |
|
54 | + public function __construct(IConfig $config, IL10N $l, IManager $shareManager) { |
|
55 | + $this->config = $config; |
|
56 | + $this->l = $l; |
|
57 | + $this->shareManager = $shareManager; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @return TemplateResponse |
|
62 | - */ |
|
63 | - public function getForm() { |
|
64 | - $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
65 | - $excludeGroupsList = !is_null(json_decode($excludedGroups)) |
|
66 | - ? implode('|', json_decode($excludedGroups, true)) : ''; |
|
67 | - $linksExcludedGroups = $this->config->getAppValue('core', 'shareapi_allow_links_exclude_groups', ''); |
|
68 | - $linksExcludeGroupsList = !is_null(json_decode($linksExcludedGroups)) |
|
69 | - ? implode('|', json_decode($linksExcludedGroups, true)) : ''; |
|
60 | + /** |
|
61 | + * @return TemplateResponse |
|
62 | + */ |
|
63 | + public function getForm() { |
|
64 | + $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
65 | + $excludeGroupsList = !is_null(json_decode($excludedGroups)) |
|
66 | + ? implode('|', json_decode($excludedGroups, true)) : ''; |
|
67 | + $linksExcludedGroups = $this->config->getAppValue('core', 'shareapi_allow_links_exclude_groups', ''); |
|
68 | + $linksExcludeGroupsList = !is_null(json_decode($linksExcludedGroups)) |
|
69 | + ? implode('|', json_decode($linksExcludedGroups, true)) : ''; |
|
70 | 70 | |
71 | - $parameters = [ |
|
72 | - // Built-In Sharing |
|
73 | - 'allowGroupSharing' => $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes'), |
|
74 | - 'allowLinks' => $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'), |
|
75 | - 'allowLinksExcludeGroups' => $linksExcludeGroupsList, |
|
76 | - 'allowPublicUpload' => $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes'), |
|
77 | - 'allowResharing' => $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes'), |
|
78 | - 'allowShareDialogUserEnumeration' => $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes'), |
|
79 | - 'restrictUserEnumerationToGroup' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no'), |
|
80 | - 'restrictUserEnumerationToPhone' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no'), |
|
81 | - 'restrictUserEnumerationFullMatch' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes'), |
|
82 | - 'enforceLinkPassword' => Util::isPublicLinkPasswordRequired(), |
|
83 | - 'onlyShareWithGroupMembers' => $this->shareManager->shareWithGroupMembersOnly(), |
|
84 | - 'shareAPIEnabled' => $this->config->getAppValue('core', 'shareapi_enabled', 'yes'), |
|
85 | - 'shareDefaultExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no'), |
|
86 | - 'shareExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'), |
|
87 | - 'shareEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'), |
|
88 | - 'shareExcludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes', |
|
89 | - 'shareExcludedGroupsList' => $excludeGroupsList, |
|
90 | - 'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null), |
|
91 | - 'enableLinkPasswordByDefault' => $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'), |
|
92 | - 'shareApiDefaultPermissions' => $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL), |
|
93 | - 'shareApiDefaultPermissionsCheckboxes' => $this->getSharePermissionList(), |
|
94 | - 'shareDefaultInternalExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no'), |
|
95 | - 'shareInternalExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'), |
|
96 | - 'shareInternalEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no'), |
|
97 | - 'shareDefaultRemoteExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_remote_expire_date', 'no'), |
|
98 | - 'shareRemoteExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7'), |
|
99 | - 'shareRemoteEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_remote_expire_date', 'no'), |
|
100 | - ]; |
|
71 | + $parameters = [ |
|
72 | + // Built-In Sharing |
|
73 | + 'allowGroupSharing' => $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes'), |
|
74 | + 'allowLinks' => $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'), |
|
75 | + 'allowLinksExcludeGroups' => $linksExcludeGroupsList, |
|
76 | + 'allowPublicUpload' => $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes'), |
|
77 | + 'allowResharing' => $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes'), |
|
78 | + 'allowShareDialogUserEnumeration' => $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes'), |
|
79 | + 'restrictUserEnumerationToGroup' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no'), |
|
80 | + 'restrictUserEnumerationToPhone' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no'), |
|
81 | + 'restrictUserEnumerationFullMatch' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes'), |
|
82 | + 'enforceLinkPassword' => Util::isPublicLinkPasswordRequired(), |
|
83 | + 'onlyShareWithGroupMembers' => $this->shareManager->shareWithGroupMembersOnly(), |
|
84 | + 'shareAPIEnabled' => $this->config->getAppValue('core', 'shareapi_enabled', 'yes'), |
|
85 | + 'shareDefaultExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no'), |
|
86 | + 'shareExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'), |
|
87 | + 'shareEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'), |
|
88 | + 'shareExcludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes', |
|
89 | + 'shareExcludedGroupsList' => $excludeGroupsList, |
|
90 | + 'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null), |
|
91 | + 'enableLinkPasswordByDefault' => $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'), |
|
92 | + 'shareApiDefaultPermissions' => $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL), |
|
93 | + 'shareApiDefaultPermissionsCheckboxes' => $this->getSharePermissionList(), |
|
94 | + 'shareDefaultInternalExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no'), |
|
95 | + 'shareInternalExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'), |
|
96 | + 'shareInternalEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no'), |
|
97 | + 'shareDefaultRemoteExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_remote_expire_date', 'no'), |
|
98 | + 'shareRemoteExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7'), |
|
99 | + 'shareRemoteEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_remote_expire_date', 'no'), |
|
100 | + ]; |
|
101 | 101 | |
102 | - return new TemplateResponse('settings', 'settings/admin/sharing', $parameters, ''); |
|
103 | - } |
|
102 | + return new TemplateResponse('settings', 'settings/admin/sharing', $parameters, ''); |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * get share permission list for template |
|
107 | - * |
|
108 | - * @return array |
|
109 | - */ |
|
110 | - private function getSharePermissionList() { |
|
111 | - return [ |
|
112 | - [ |
|
113 | - 'id' => 'cancreate', |
|
114 | - 'label' => $this->l->t('Create'), |
|
115 | - 'value' => Constants::PERMISSION_CREATE |
|
116 | - ], |
|
117 | - [ |
|
118 | - 'id' => 'canupdate', |
|
119 | - 'label' => $this->l->t('Change'), |
|
120 | - 'value' => Constants::PERMISSION_UPDATE |
|
121 | - ], |
|
122 | - [ |
|
123 | - 'id' => 'candelete', |
|
124 | - 'label' => $this->l->t('Delete'), |
|
125 | - 'value' => Constants::PERMISSION_DELETE |
|
126 | - ], |
|
127 | - [ |
|
128 | - 'id' => 'canshare', |
|
129 | - 'label' => $this->l->t('Reshare'), |
|
130 | - 'value' => Constants::PERMISSION_SHARE |
|
131 | - ], |
|
132 | - ]; |
|
133 | - } |
|
105 | + /** |
|
106 | + * get share permission list for template |
|
107 | + * |
|
108 | + * @return array |
|
109 | + */ |
|
110 | + private function getSharePermissionList() { |
|
111 | + return [ |
|
112 | + [ |
|
113 | + 'id' => 'cancreate', |
|
114 | + 'label' => $this->l->t('Create'), |
|
115 | + 'value' => Constants::PERMISSION_CREATE |
|
116 | + ], |
|
117 | + [ |
|
118 | + 'id' => 'canupdate', |
|
119 | + 'label' => $this->l->t('Change'), |
|
120 | + 'value' => Constants::PERMISSION_UPDATE |
|
121 | + ], |
|
122 | + [ |
|
123 | + 'id' => 'candelete', |
|
124 | + 'label' => $this->l->t('Delete'), |
|
125 | + 'value' => Constants::PERMISSION_DELETE |
|
126 | + ], |
|
127 | + [ |
|
128 | + 'id' => 'canshare', |
|
129 | + 'label' => $this->l->t('Reshare'), |
|
130 | + 'value' => Constants::PERMISSION_SHARE |
|
131 | + ], |
|
132 | + ]; |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * @return string the section ID, e.g. 'sharing' |
|
137 | - */ |
|
138 | - public function getSection() { |
|
139 | - return 'sharing'; |
|
140 | - } |
|
135 | + /** |
|
136 | + * @return string the section ID, e.g. 'sharing' |
|
137 | + */ |
|
138 | + public function getSection() { |
|
139 | + return 'sharing'; |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * @return int whether the form should be rather on the top or bottom of |
|
144 | - * the admin section. The forms are arranged in ascending order of the |
|
145 | - * priority values. It is required to return a value between 0 and 100. |
|
146 | - * |
|
147 | - * E.g.: 70 |
|
148 | - */ |
|
149 | - public function getPriority() { |
|
150 | - return 0; |
|
151 | - } |
|
142 | + /** |
|
143 | + * @return int whether the form should be rather on the top or bottom of |
|
144 | + * the admin section. The forms are arranged in ascending order of the |
|
145 | + * priority values. It is required to return a value between 0 and 100. |
|
146 | + * |
|
147 | + * E.g.: 70 |
|
148 | + */ |
|
149 | + public function getPriority() { |
|
150 | + return 0; |
|
151 | + } |
|
152 | 152 | } |