@@ -48,576 +48,576 @@ |
||
48 | 48 | |
49 | 49 | class RequestHandlerController extends OCSController { |
50 | 50 | |
51 | - /** @var FederatedShareProvider */ |
|
52 | - private $federatedShareProvider; |
|
53 | - |
|
54 | - /** @var IDBConnection */ |
|
55 | - private $connection; |
|
56 | - |
|
57 | - /** @var Share\IManager */ |
|
58 | - private $shareManager; |
|
59 | - |
|
60 | - /** @var Notifications */ |
|
61 | - private $notifications; |
|
62 | - |
|
63 | - /** @var AddressHandler */ |
|
64 | - private $addressHandler; |
|
65 | - |
|
66 | - /** @var IUserManager */ |
|
67 | - private $userManager; |
|
68 | - |
|
69 | - /** @var string */ |
|
70 | - private $shareTable = 'share'; |
|
71 | - |
|
72 | - /** @var ICloudIdManager */ |
|
73 | - private $cloudIdManager; |
|
74 | - |
|
75 | - /** |
|
76 | - * Server2Server constructor. |
|
77 | - * |
|
78 | - * @param string $appName |
|
79 | - * @param IRequest $request |
|
80 | - * @param FederatedShareProvider $federatedShareProvider |
|
81 | - * @param IDBConnection $connection |
|
82 | - * @param Share\IManager $shareManager |
|
83 | - * @param Notifications $notifications |
|
84 | - * @param AddressHandler $addressHandler |
|
85 | - * @param IUserManager $userManager |
|
86 | - * @param ICloudIdManager $cloudIdManager |
|
87 | - */ |
|
88 | - public function __construct($appName, |
|
89 | - IRequest $request, |
|
90 | - FederatedShareProvider $federatedShareProvider, |
|
91 | - IDBConnection $connection, |
|
92 | - Share\IManager $shareManager, |
|
93 | - Notifications $notifications, |
|
94 | - AddressHandler $addressHandler, |
|
95 | - IUserManager $userManager, |
|
96 | - ICloudIdManager $cloudIdManager |
|
97 | - ) { |
|
98 | - parent::__construct($appName, $request); |
|
99 | - |
|
100 | - $this->federatedShareProvider = $federatedShareProvider; |
|
101 | - $this->connection = $connection; |
|
102 | - $this->shareManager = $shareManager; |
|
103 | - $this->notifications = $notifications; |
|
104 | - $this->addressHandler = $addressHandler; |
|
105 | - $this->userManager = $userManager; |
|
106 | - $this->cloudIdManager = $cloudIdManager; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @NoCSRFRequired |
|
111 | - * @PublicPage |
|
112 | - * |
|
113 | - * create a new share |
|
114 | - * |
|
115 | - * @return Http\DataResponse |
|
116 | - * @throws OCSException |
|
117 | - */ |
|
118 | - public function createShare() { |
|
119 | - |
|
120 | - if (!$this->isS2SEnabled(true)) { |
|
121 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
122 | - } |
|
123 | - |
|
124 | - $remote = isset($_POST['remote']) ? $_POST['remote'] : null; |
|
125 | - $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
126 | - $name = isset($_POST['name']) ? $_POST['name'] : null; |
|
127 | - $owner = isset($_POST['owner']) ? $_POST['owner'] : null; |
|
128 | - $sharedBy = isset($_POST['sharedBy']) ? $_POST['sharedBy'] : null; |
|
129 | - $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null; |
|
130 | - $remoteId = isset($_POST['remoteId']) ? (int)$_POST['remoteId'] : null; |
|
131 | - $sharedByFederatedId = isset($_POST['sharedByFederatedId']) ? $_POST['sharedByFederatedId'] : null; |
|
132 | - $ownerFederatedId = isset($_POST['ownerFederatedId']) ? $_POST['ownerFederatedId'] : null; |
|
133 | - |
|
134 | - if ($remote && $token && $name && $owner && $remoteId && $shareWith) { |
|
135 | - |
|
136 | - if(!\OCP\Util::isValidFileName($name)) { |
|
137 | - throw new OCSException('The mountpoint name contains invalid characters.', 400); |
|
138 | - } |
|
139 | - |
|
140 | - // FIXME this should be a method in the user management instead |
|
141 | - \OCP\Util::writeLog('files_sharing', 'shareWith before, ' . $shareWith, \OCP\Util::DEBUG); |
|
142 | - \OCP\Util::emitHook( |
|
143 | - '\OCA\Files_Sharing\API\Server2Server', |
|
144 | - 'preLoginNameUsedAsUserName', |
|
145 | - array('uid' => &$shareWith) |
|
146 | - ); |
|
147 | - \OCP\Util::writeLog('files_sharing', 'shareWith after, ' . $shareWith, \OCP\Util::DEBUG); |
|
148 | - |
|
149 | - if (!\OCP\User::userExists($shareWith)) { |
|
150 | - throw new OCSException('User does not exists', 400); |
|
151 | - } |
|
152 | - |
|
153 | - \OC_Util::setupFS($shareWith); |
|
154 | - |
|
155 | - $discoveryManager = new DiscoveryManager( |
|
156 | - \OC::$server->getMemCacheFactory(), |
|
157 | - \OC::$server->getHTTPClientService() |
|
158 | - ); |
|
159 | - $externalManager = new \OCA\Files_Sharing\External\Manager( |
|
160 | - \OC::$server->getDatabaseConnection(), |
|
161 | - \OC\Files\Filesystem::getMountManager(), |
|
162 | - \OC\Files\Filesystem::getLoader(), |
|
163 | - \OC::$server->getHTTPClientService(), |
|
164 | - \OC::$server->getNotificationManager(), |
|
165 | - $discoveryManager, |
|
166 | - $shareWith |
|
167 | - ); |
|
168 | - |
|
169 | - try { |
|
170 | - $externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId); |
|
171 | - $shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external'); |
|
172 | - |
|
173 | - if ($ownerFederatedId === null) { |
|
174 | - $ownerFederatedId = $this->cloudIdManager->getCloudId($owner, $this->cleanupRemote($remote))->getId(); |
|
175 | - } |
|
176 | - // if the owner of the share and the initiator are the same user |
|
177 | - // we also complete the federated share ID for the initiator |
|
178 | - if ($sharedByFederatedId === null && $owner === $sharedBy) { |
|
179 | - $sharedByFederatedId = $ownerFederatedId; |
|
180 | - } |
|
181 | - |
|
182 | - $event = \OC::$server->getActivityManager()->generateEvent(); |
|
183 | - $event->setApp('files_sharing') |
|
184 | - ->setType('remote_share') |
|
185 | - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')]) |
|
186 | - ->setAffectedUser($shareWith) |
|
187 | - ->setObject('remote_share', (int) $shareId, $name); |
|
188 | - \OC::$server->getActivityManager()->publish($event); |
|
189 | - |
|
190 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
191 | - |
|
192 | - $notificationManager = \OC::$server->getNotificationManager(); |
|
193 | - $notification = $notificationManager->createNotification(); |
|
194 | - $notification->setApp('files_sharing') |
|
195 | - ->setUser($shareWith) |
|
196 | - ->setDateTime(new \DateTime()) |
|
197 | - ->setObject('remote_share', $shareId) |
|
198 | - ->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/')]); |
|
199 | - |
|
200 | - $declineAction = $notification->createAction(); |
|
201 | - $declineAction->setLabel('decline') |
|
202 | - ->setLink($urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'ocs/v1.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'DELETE'); |
|
203 | - $notification->addAction($declineAction); |
|
204 | - |
|
205 | - $acceptAction = $notification->createAction(); |
|
206 | - $acceptAction->setLabel('accept') |
|
207 | - ->setLink($urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'ocs/v1.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'POST'); |
|
208 | - $notification->addAction($acceptAction); |
|
209 | - |
|
210 | - $notificationManager->notify($notification); |
|
211 | - |
|
212 | - return new Http\DataResponse(); |
|
213 | - } catch (\Exception $e) { |
|
214 | - \OCP\Util::writeLog('files_sharing', 'server can not add remote share, ' . $e->getMessage(), \OCP\Util::ERROR); |
|
215 | - throw new OCSException('internal server error, was not able to add share from ' . $remote, 500); |
|
216 | - } |
|
217 | - } |
|
218 | - |
|
219 | - throw new OCSException('server can not add remote share, missing parameter', 400); |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * @NoCSRFRequired |
|
224 | - * @PublicPage |
|
225 | - * |
|
226 | - * create re-share on behalf of another user |
|
227 | - * |
|
228 | - * @param int $id |
|
229 | - * @return Http\DataResponse |
|
230 | - * @throws OCSBadRequestException |
|
231 | - * @throws OCSForbiddenException |
|
232 | - * @throws OCSNotFoundException |
|
233 | - */ |
|
234 | - public function reShare($id) { |
|
235 | - |
|
236 | - $token = $this->request->getParam('token', null); |
|
237 | - $shareWith = $this->request->getParam('shareWith', null); |
|
238 | - $permission = (int)$this->request->getParam('permission', null); |
|
239 | - $remoteId = (int)$this->request->getParam('remoteId', null); |
|
240 | - |
|
241 | - if ($id === null || |
|
242 | - $token === null || |
|
243 | - $shareWith === null || |
|
244 | - $permission === null || |
|
245 | - $remoteId === null |
|
246 | - ) { |
|
247 | - throw new OCSBadRequestException(); |
|
248 | - } |
|
249 | - |
|
250 | - try { |
|
251 | - $share = $this->federatedShareProvider->getShareById($id); |
|
252 | - } catch (Share\Exceptions\ShareNotFound $e) { |
|
253 | - throw new OCSNotFoundException(); |
|
254 | - } |
|
255 | - |
|
256 | - // don't allow to share a file back to the owner |
|
257 | - list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith); |
|
258 | - $owner = $share->getShareOwner(); |
|
259 | - $currentServer = $this->addressHandler->generateRemoteURL(); |
|
260 | - if ($this->addressHandler->compareAddresses($user, $remote,$owner , $currentServer)) { |
|
261 | - throw new OCSForbiddenException(); |
|
262 | - } |
|
263 | - |
|
264 | - if ($this->verifyShare($share, $token)) { |
|
265 | - |
|
266 | - // check if re-sharing is allowed |
|
267 | - if ($share->getPermissions() | ~Constants::PERMISSION_SHARE) { |
|
268 | - $share->setPermissions($share->getPermissions() & $permission); |
|
269 | - // the recipient of the initial share is now the initiator for the re-share |
|
270 | - $share->setSharedBy($share->getSharedWith()); |
|
271 | - $share->setSharedWith($shareWith); |
|
272 | - try { |
|
273 | - $result = $this->federatedShareProvider->create($share); |
|
274 | - $this->federatedShareProvider->storeRemoteId((int)$result->getId(), $remoteId); |
|
275 | - return new Http\DataResponse([ |
|
276 | - 'token' => $result->getToken(), |
|
277 | - 'remoteId' => $result->getId() |
|
278 | - ]); |
|
279 | - } catch (\Exception $e) { |
|
280 | - throw new OCSBadRequestException(); |
|
281 | - } |
|
282 | - } else { |
|
283 | - throw new OCSForbiddenException(); |
|
284 | - } |
|
285 | - } |
|
286 | - throw new OCSBadRequestException(); |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * @NoCSRFRequired |
|
291 | - * @PublicPage |
|
292 | - * |
|
293 | - * accept server-to-server share |
|
294 | - * |
|
295 | - * @param int $id |
|
296 | - * @return Http\DataResponse |
|
297 | - * @throws OCSException |
|
298 | - */ |
|
299 | - public function acceptShare($id) { |
|
300 | - |
|
301 | - if (!$this->isS2SEnabled()) { |
|
302 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
303 | - } |
|
304 | - |
|
305 | - $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
306 | - |
|
307 | - try { |
|
308 | - $share = $this->federatedShareProvider->getShareById($id); |
|
309 | - } catch (Share\Exceptions\ShareNotFound $e) { |
|
310 | - return new Http\DataResponse(); |
|
311 | - } |
|
312 | - |
|
313 | - if ($this->verifyShare($share, $token)) { |
|
314 | - $this->executeAcceptShare($share); |
|
315 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
316 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
317 | - $remoteId = $this->federatedShareProvider->getRemoteId($share); |
|
318 | - $this->notifications->sendAcceptShare($remote, $remoteId, $share->getToken()); |
|
319 | - } |
|
320 | - } |
|
321 | - |
|
322 | - return new Http\DataResponse(); |
|
323 | - } |
|
324 | - |
|
325 | - protected function executeAcceptShare(Share\IShare $share) { |
|
326 | - list($file, $link) = $this->getFile($this->getCorrectUid($share), $share->getNode()->getId()); |
|
327 | - |
|
328 | - $event = \OC::$server->getActivityManager()->generateEvent(); |
|
329 | - $event->setApp('files_sharing') |
|
330 | - ->setType('remote_share') |
|
331 | - ->setAffectedUser($this->getCorrectUid($share)) |
|
332 | - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_ACCEPTED, [$share->getSharedWith(), $file]) |
|
333 | - ->setObject('files', (int) $share->getNode()->getId(), $file) |
|
334 | - ->setLink($link); |
|
335 | - \OC::$server->getActivityManager()->publish($event); |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * @NoCSRFRequired |
|
340 | - * @PublicPage |
|
341 | - * |
|
342 | - * decline server-to-server share |
|
343 | - * |
|
344 | - * @param int $id |
|
345 | - * @return Http\DataResponse |
|
346 | - * @throws OCSException |
|
347 | - */ |
|
348 | - public function declineShare($id) { |
|
349 | - |
|
350 | - if (!$this->isS2SEnabled()) { |
|
351 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
352 | - } |
|
353 | - |
|
354 | - $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
355 | - |
|
356 | - try { |
|
357 | - $share = $this->federatedShareProvider->getShareById($id); |
|
358 | - } catch (Share\Exceptions\ShareNotFound $e) { |
|
359 | - return new Http\DataResponse(); |
|
360 | - } |
|
361 | - |
|
362 | - if($this->verifyShare($share, $token)) { |
|
363 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
364 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
365 | - $remoteId = $this->federatedShareProvider->getRemoteId($share); |
|
366 | - $this->notifications->sendDeclineShare($remote, $remoteId, $share->getToken()); |
|
367 | - } |
|
368 | - $this->executeDeclineShare($share); |
|
369 | - } |
|
370 | - |
|
371 | - return new Http\DataResponse(); |
|
372 | - } |
|
373 | - |
|
374 | - /** |
|
375 | - * delete declined share and create a activity |
|
376 | - * |
|
377 | - * @param Share\IShare $share |
|
378 | - */ |
|
379 | - protected function executeDeclineShare(Share\IShare $share) { |
|
380 | - $this->federatedShareProvider->removeShareFromTable($share); |
|
381 | - list($file, $link) = $this->getFile($this->getCorrectUid($share), $share->getNode()->getId()); |
|
382 | - |
|
383 | - $event = \OC::$server->getActivityManager()->generateEvent(); |
|
384 | - $event->setApp('files_sharing') |
|
385 | - ->setType('remote_share') |
|
386 | - ->setAffectedUser($this->getCorrectUid($share)) |
|
387 | - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_DECLINED, [$share->getSharedWith(), $file]) |
|
388 | - ->setObject('files', (int) $share->getNode()->getId(), $file) |
|
389 | - ->setLink($link); |
|
390 | - \OC::$server->getActivityManager()->publish($event); |
|
391 | - |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * check if we are the initiator or the owner of a re-share and return the correct UID |
|
396 | - * |
|
397 | - * @param Share\IShare $share |
|
398 | - * @return string |
|
399 | - */ |
|
400 | - protected function getCorrectUid(Share\IShare $share) { |
|
401 | - if($this->userManager->userExists($share->getShareOwner())) { |
|
402 | - return $share->getShareOwner(); |
|
403 | - } |
|
404 | - |
|
405 | - return $share->getSharedBy(); |
|
406 | - } |
|
407 | - |
|
408 | - /** |
|
409 | - * @NoCSRFRequired |
|
410 | - * @PublicPage |
|
411 | - * |
|
412 | - * remove server-to-server share if it was unshared by the owner |
|
413 | - * |
|
414 | - * @param int $id |
|
415 | - * @return Http\DataResponse |
|
416 | - * @throws OCSException |
|
417 | - */ |
|
418 | - public function unshare($id) { |
|
419 | - |
|
420 | - if (!$this->isS2SEnabled()) { |
|
421 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
422 | - } |
|
423 | - |
|
424 | - $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
425 | - |
|
426 | - $query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*share_external` WHERE `remote_id` = ? AND `share_token` = ?'); |
|
427 | - $query->execute(array($id, $token)); |
|
428 | - $share = $query->fetchRow(); |
|
429 | - |
|
430 | - if ($token && $id && !empty($share)) { |
|
431 | - |
|
432 | - $remote = $this->cleanupRemote($share['remote']); |
|
433 | - |
|
434 | - $owner = $this->cloudIdManager->getCloudId($share['owner'], $remote); |
|
435 | - $mountpoint = $share['mountpoint']; |
|
436 | - $user = $share['user']; |
|
437 | - |
|
438 | - $query = \OCP\DB::prepare('DELETE FROM `*PREFIX*share_external` WHERE `remote_id` = ? AND `share_token` = ?'); |
|
439 | - $query->execute(array($id, $token)); |
|
440 | - |
|
441 | - if ($share['accepted']) { |
|
442 | - $path = trim($mountpoint, '/'); |
|
443 | - } else { |
|
444 | - $path = trim($share['name'], '/'); |
|
445 | - } |
|
446 | - |
|
447 | - $notificationManager = \OC::$server->getNotificationManager(); |
|
448 | - $notification = $notificationManager->createNotification(); |
|
449 | - $notification->setApp('files_sharing') |
|
450 | - ->setUser($share['user']) |
|
451 | - ->setObject('remote_share', (int) $share['id']); |
|
452 | - $notificationManager->markProcessed($notification); |
|
453 | - |
|
454 | - $event = \OC::$server->getActivityManager()->generateEvent(); |
|
455 | - $event->setApp('files_sharing') |
|
456 | - ->setType('remote_share') |
|
457 | - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_UNSHARED, [$owner, $path]) |
|
458 | - ->setAffectedUser($user) |
|
459 | - ->setObject('remote_share', (int) $share['id'], $path); |
|
460 | - \OC::$server->getActivityManager()->publish($event); |
|
461 | - } |
|
462 | - |
|
463 | - return new Http\DataResponse(); |
|
464 | - } |
|
465 | - |
|
466 | - private function cleanupRemote($remote) { |
|
467 | - $remote = substr($remote, strpos($remote, '://') + 3); |
|
468 | - |
|
469 | - return rtrim($remote, '/'); |
|
470 | - } |
|
471 | - |
|
472 | - |
|
473 | - /** |
|
474 | - * @NoCSRFRequired |
|
475 | - * @PublicPage |
|
476 | - * |
|
477 | - * federated share was revoked, either by the owner or the re-sharer |
|
478 | - * |
|
479 | - * @param int $id |
|
480 | - * @return Http\DataResponse |
|
481 | - * @throws OCSBadRequestException |
|
482 | - */ |
|
483 | - public function revoke($id) { |
|
484 | - $token = $this->request->getParam('token'); |
|
51 | + /** @var FederatedShareProvider */ |
|
52 | + private $federatedShareProvider; |
|
53 | + |
|
54 | + /** @var IDBConnection */ |
|
55 | + private $connection; |
|
56 | + |
|
57 | + /** @var Share\IManager */ |
|
58 | + private $shareManager; |
|
59 | + |
|
60 | + /** @var Notifications */ |
|
61 | + private $notifications; |
|
62 | + |
|
63 | + /** @var AddressHandler */ |
|
64 | + private $addressHandler; |
|
65 | + |
|
66 | + /** @var IUserManager */ |
|
67 | + private $userManager; |
|
68 | + |
|
69 | + /** @var string */ |
|
70 | + private $shareTable = 'share'; |
|
71 | + |
|
72 | + /** @var ICloudIdManager */ |
|
73 | + private $cloudIdManager; |
|
74 | + |
|
75 | + /** |
|
76 | + * Server2Server constructor. |
|
77 | + * |
|
78 | + * @param string $appName |
|
79 | + * @param IRequest $request |
|
80 | + * @param FederatedShareProvider $federatedShareProvider |
|
81 | + * @param IDBConnection $connection |
|
82 | + * @param Share\IManager $shareManager |
|
83 | + * @param Notifications $notifications |
|
84 | + * @param AddressHandler $addressHandler |
|
85 | + * @param IUserManager $userManager |
|
86 | + * @param ICloudIdManager $cloudIdManager |
|
87 | + */ |
|
88 | + public function __construct($appName, |
|
89 | + IRequest $request, |
|
90 | + FederatedShareProvider $federatedShareProvider, |
|
91 | + IDBConnection $connection, |
|
92 | + Share\IManager $shareManager, |
|
93 | + Notifications $notifications, |
|
94 | + AddressHandler $addressHandler, |
|
95 | + IUserManager $userManager, |
|
96 | + ICloudIdManager $cloudIdManager |
|
97 | + ) { |
|
98 | + parent::__construct($appName, $request); |
|
99 | + |
|
100 | + $this->federatedShareProvider = $federatedShareProvider; |
|
101 | + $this->connection = $connection; |
|
102 | + $this->shareManager = $shareManager; |
|
103 | + $this->notifications = $notifications; |
|
104 | + $this->addressHandler = $addressHandler; |
|
105 | + $this->userManager = $userManager; |
|
106 | + $this->cloudIdManager = $cloudIdManager; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @NoCSRFRequired |
|
111 | + * @PublicPage |
|
112 | + * |
|
113 | + * create a new share |
|
114 | + * |
|
115 | + * @return Http\DataResponse |
|
116 | + * @throws OCSException |
|
117 | + */ |
|
118 | + public function createShare() { |
|
119 | + |
|
120 | + if (!$this->isS2SEnabled(true)) { |
|
121 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
122 | + } |
|
123 | + |
|
124 | + $remote = isset($_POST['remote']) ? $_POST['remote'] : null; |
|
125 | + $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
126 | + $name = isset($_POST['name']) ? $_POST['name'] : null; |
|
127 | + $owner = isset($_POST['owner']) ? $_POST['owner'] : null; |
|
128 | + $sharedBy = isset($_POST['sharedBy']) ? $_POST['sharedBy'] : null; |
|
129 | + $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null; |
|
130 | + $remoteId = isset($_POST['remoteId']) ? (int)$_POST['remoteId'] : null; |
|
131 | + $sharedByFederatedId = isset($_POST['sharedByFederatedId']) ? $_POST['sharedByFederatedId'] : null; |
|
132 | + $ownerFederatedId = isset($_POST['ownerFederatedId']) ? $_POST['ownerFederatedId'] : null; |
|
133 | + |
|
134 | + if ($remote && $token && $name && $owner && $remoteId && $shareWith) { |
|
135 | + |
|
136 | + if(!\OCP\Util::isValidFileName($name)) { |
|
137 | + throw new OCSException('The mountpoint name contains invalid characters.', 400); |
|
138 | + } |
|
139 | + |
|
140 | + // FIXME this should be a method in the user management instead |
|
141 | + \OCP\Util::writeLog('files_sharing', 'shareWith before, ' . $shareWith, \OCP\Util::DEBUG); |
|
142 | + \OCP\Util::emitHook( |
|
143 | + '\OCA\Files_Sharing\API\Server2Server', |
|
144 | + 'preLoginNameUsedAsUserName', |
|
145 | + array('uid' => &$shareWith) |
|
146 | + ); |
|
147 | + \OCP\Util::writeLog('files_sharing', 'shareWith after, ' . $shareWith, \OCP\Util::DEBUG); |
|
148 | + |
|
149 | + if (!\OCP\User::userExists($shareWith)) { |
|
150 | + throw new OCSException('User does not exists', 400); |
|
151 | + } |
|
152 | + |
|
153 | + \OC_Util::setupFS($shareWith); |
|
154 | + |
|
155 | + $discoveryManager = new DiscoveryManager( |
|
156 | + \OC::$server->getMemCacheFactory(), |
|
157 | + \OC::$server->getHTTPClientService() |
|
158 | + ); |
|
159 | + $externalManager = new \OCA\Files_Sharing\External\Manager( |
|
160 | + \OC::$server->getDatabaseConnection(), |
|
161 | + \OC\Files\Filesystem::getMountManager(), |
|
162 | + \OC\Files\Filesystem::getLoader(), |
|
163 | + \OC::$server->getHTTPClientService(), |
|
164 | + \OC::$server->getNotificationManager(), |
|
165 | + $discoveryManager, |
|
166 | + $shareWith |
|
167 | + ); |
|
168 | + |
|
169 | + try { |
|
170 | + $externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId); |
|
171 | + $shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external'); |
|
172 | + |
|
173 | + if ($ownerFederatedId === null) { |
|
174 | + $ownerFederatedId = $this->cloudIdManager->getCloudId($owner, $this->cleanupRemote($remote))->getId(); |
|
175 | + } |
|
176 | + // if the owner of the share and the initiator are the same user |
|
177 | + // we also complete the federated share ID for the initiator |
|
178 | + if ($sharedByFederatedId === null && $owner === $sharedBy) { |
|
179 | + $sharedByFederatedId = $ownerFederatedId; |
|
180 | + } |
|
181 | + |
|
182 | + $event = \OC::$server->getActivityManager()->generateEvent(); |
|
183 | + $event->setApp('files_sharing') |
|
184 | + ->setType('remote_share') |
|
185 | + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')]) |
|
186 | + ->setAffectedUser($shareWith) |
|
187 | + ->setObject('remote_share', (int) $shareId, $name); |
|
188 | + \OC::$server->getActivityManager()->publish($event); |
|
189 | + |
|
190 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
191 | + |
|
192 | + $notificationManager = \OC::$server->getNotificationManager(); |
|
193 | + $notification = $notificationManager->createNotification(); |
|
194 | + $notification->setApp('files_sharing') |
|
195 | + ->setUser($shareWith) |
|
196 | + ->setDateTime(new \DateTime()) |
|
197 | + ->setObject('remote_share', $shareId) |
|
198 | + ->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/')]); |
|
199 | + |
|
200 | + $declineAction = $notification->createAction(); |
|
201 | + $declineAction->setLabel('decline') |
|
202 | + ->setLink($urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'ocs/v1.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'DELETE'); |
|
203 | + $notification->addAction($declineAction); |
|
204 | + |
|
205 | + $acceptAction = $notification->createAction(); |
|
206 | + $acceptAction->setLabel('accept') |
|
207 | + ->setLink($urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'ocs/v1.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'POST'); |
|
208 | + $notification->addAction($acceptAction); |
|
209 | + |
|
210 | + $notificationManager->notify($notification); |
|
211 | + |
|
212 | + return new Http\DataResponse(); |
|
213 | + } catch (\Exception $e) { |
|
214 | + \OCP\Util::writeLog('files_sharing', 'server can not add remote share, ' . $e->getMessage(), \OCP\Util::ERROR); |
|
215 | + throw new OCSException('internal server error, was not able to add share from ' . $remote, 500); |
|
216 | + } |
|
217 | + } |
|
218 | + |
|
219 | + throw new OCSException('server can not add remote share, missing parameter', 400); |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * @NoCSRFRequired |
|
224 | + * @PublicPage |
|
225 | + * |
|
226 | + * create re-share on behalf of another user |
|
227 | + * |
|
228 | + * @param int $id |
|
229 | + * @return Http\DataResponse |
|
230 | + * @throws OCSBadRequestException |
|
231 | + * @throws OCSForbiddenException |
|
232 | + * @throws OCSNotFoundException |
|
233 | + */ |
|
234 | + public function reShare($id) { |
|
235 | + |
|
236 | + $token = $this->request->getParam('token', null); |
|
237 | + $shareWith = $this->request->getParam('shareWith', null); |
|
238 | + $permission = (int)$this->request->getParam('permission', null); |
|
239 | + $remoteId = (int)$this->request->getParam('remoteId', null); |
|
240 | + |
|
241 | + if ($id === null || |
|
242 | + $token === null || |
|
243 | + $shareWith === null || |
|
244 | + $permission === null || |
|
245 | + $remoteId === null |
|
246 | + ) { |
|
247 | + throw new OCSBadRequestException(); |
|
248 | + } |
|
249 | + |
|
250 | + try { |
|
251 | + $share = $this->federatedShareProvider->getShareById($id); |
|
252 | + } catch (Share\Exceptions\ShareNotFound $e) { |
|
253 | + throw new OCSNotFoundException(); |
|
254 | + } |
|
255 | + |
|
256 | + // don't allow to share a file back to the owner |
|
257 | + list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith); |
|
258 | + $owner = $share->getShareOwner(); |
|
259 | + $currentServer = $this->addressHandler->generateRemoteURL(); |
|
260 | + if ($this->addressHandler->compareAddresses($user, $remote,$owner , $currentServer)) { |
|
261 | + throw new OCSForbiddenException(); |
|
262 | + } |
|
263 | + |
|
264 | + if ($this->verifyShare($share, $token)) { |
|
265 | + |
|
266 | + // check if re-sharing is allowed |
|
267 | + if ($share->getPermissions() | ~Constants::PERMISSION_SHARE) { |
|
268 | + $share->setPermissions($share->getPermissions() & $permission); |
|
269 | + // the recipient of the initial share is now the initiator for the re-share |
|
270 | + $share->setSharedBy($share->getSharedWith()); |
|
271 | + $share->setSharedWith($shareWith); |
|
272 | + try { |
|
273 | + $result = $this->federatedShareProvider->create($share); |
|
274 | + $this->federatedShareProvider->storeRemoteId((int)$result->getId(), $remoteId); |
|
275 | + return new Http\DataResponse([ |
|
276 | + 'token' => $result->getToken(), |
|
277 | + 'remoteId' => $result->getId() |
|
278 | + ]); |
|
279 | + } catch (\Exception $e) { |
|
280 | + throw new OCSBadRequestException(); |
|
281 | + } |
|
282 | + } else { |
|
283 | + throw new OCSForbiddenException(); |
|
284 | + } |
|
285 | + } |
|
286 | + throw new OCSBadRequestException(); |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * @NoCSRFRequired |
|
291 | + * @PublicPage |
|
292 | + * |
|
293 | + * accept server-to-server share |
|
294 | + * |
|
295 | + * @param int $id |
|
296 | + * @return Http\DataResponse |
|
297 | + * @throws OCSException |
|
298 | + */ |
|
299 | + public function acceptShare($id) { |
|
300 | + |
|
301 | + if (!$this->isS2SEnabled()) { |
|
302 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
303 | + } |
|
304 | + |
|
305 | + $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
306 | + |
|
307 | + try { |
|
308 | + $share = $this->federatedShareProvider->getShareById($id); |
|
309 | + } catch (Share\Exceptions\ShareNotFound $e) { |
|
310 | + return new Http\DataResponse(); |
|
311 | + } |
|
312 | + |
|
313 | + if ($this->verifyShare($share, $token)) { |
|
314 | + $this->executeAcceptShare($share); |
|
315 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
316 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
317 | + $remoteId = $this->federatedShareProvider->getRemoteId($share); |
|
318 | + $this->notifications->sendAcceptShare($remote, $remoteId, $share->getToken()); |
|
319 | + } |
|
320 | + } |
|
321 | + |
|
322 | + return new Http\DataResponse(); |
|
323 | + } |
|
324 | + |
|
325 | + protected function executeAcceptShare(Share\IShare $share) { |
|
326 | + list($file, $link) = $this->getFile($this->getCorrectUid($share), $share->getNode()->getId()); |
|
327 | + |
|
328 | + $event = \OC::$server->getActivityManager()->generateEvent(); |
|
329 | + $event->setApp('files_sharing') |
|
330 | + ->setType('remote_share') |
|
331 | + ->setAffectedUser($this->getCorrectUid($share)) |
|
332 | + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_ACCEPTED, [$share->getSharedWith(), $file]) |
|
333 | + ->setObject('files', (int) $share->getNode()->getId(), $file) |
|
334 | + ->setLink($link); |
|
335 | + \OC::$server->getActivityManager()->publish($event); |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * @NoCSRFRequired |
|
340 | + * @PublicPage |
|
341 | + * |
|
342 | + * decline server-to-server share |
|
343 | + * |
|
344 | + * @param int $id |
|
345 | + * @return Http\DataResponse |
|
346 | + * @throws OCSException |
|
347 | + */ |
|
348 | + public function declineShare($id) { |
|
349 | + |
|
350 | + if (!$this->isS2SEnabled()) { |
|
351 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
352 | + } |
|
353 | + |
|
354 | + $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
355 | + |
|
356 | + try { |
|
357 | + $share = $this->federatedShareProvider->getShareById($id); |
|
358 | + } catch (Share\Exceptions\ShareNotFound $e) { |
|
359 | + return new Http\DataResponse(); |
|
360 | + } |
|
361 | + |
|
362 | + if($this->verifyShare($share, $token)) { |
|
363 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
364 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
365 | + $remoteId = $this->federatedShareProvider->getRemoteId($share); |
|
366 | + $this->notifications->sendDeclineShare($remote, $remoteId, $share->getToken()); |
|
367 | + } |
|
368 | + $this->executeDeclineShare($share); |
|
369 | + } |
|
370 | + |
|
371 | + return new Http\DataResponse(); |
|
372 | + } |
|
373 | + |
|
374 | + /** |
|
375 | + * delete declined share and create a activity |
|
376 | + * |
|
377 | + * @param Share\IShare $share |
|
378 | + */ |
|
379 | + protected function executeDeclineShare(Share\IShare $share) { |
|
380 | + $this->federatedShareProvider->removeShareFromTable($share); |
|
381 | + list($file, $link) = $this->getFile($this->getCorrectUid($share), $share->getNode()->getId()); |
|
382 | + |
|
383 | + $event = \OC::$server->getActivityManager()->generateEvent(); |
|
384 | + $event->setApp('files_sharing') |
|
385 | + ->setType('remote_share') |
|
386 | + ->setAffectedUser($this->getCorrectUid($share)) |
|
387 | + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_DECLINED, [$share->getSharedWith(), $file]) |
|
388 | + ->setObject('files', (int) $share->getNode()->getId(), $file) |
|
389 | + ->setLink($link); |
|
390 | + \OC::$server->getActivityManager()->publish($event); |
|
391 | + |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * check if we are the initiator or the owner of a re-share and return the correct UID |
|
396 | + * |
|
397 | + * @param Share\IShare $share |
|
398 | + * @return string |
|
399 | + */ |
|
400 | + protected function getCorrectUid(Share\IShare $share) { |
|
401 | + if($this->userManager->userExists($share->getShareOwner())) { |
|
402 | + return $share->getShareOwner(); |
|
403 | + } |
|
404 | + |
|
405 | + return $share->getSharedBy(); |
|
406 | + } |
|
407 | + |
|
408 | + /** |
|
409 | + * @NoCSRFRequired |
|
410 | + * @PublicPage |
|
411 | + * |
|
412 | + * remove server-to-server share if it was unshared by the owner |
|
413 | + * |
|
414 | + * @param int $id |
|
415 | + * @return Http\DataResponse |
|
416 | + * @throws OCSException |
|
417 | + */ |
|
418 | + public function unshare($id) { |
|
419 | + |
|
420 | + if (!$this->isS2SEnabled()) { |
|
421 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
422 | + } |
|
423 | + |
|
424 | + $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
425 | + |
|
426 | + $query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*share_external` WHERE `remote_id` = ? AND `share_token` = ?'); |
|
427 | + $query->execute(array($id, $token)); |
|
428 | + $share = $query->fetchRow(); |
|
429 | + |
|
430 | + if ($token && $id && !empty($share)) { |
|
431 | + |
|
432 | + $remote = $this->cleanupRemote($share['remote']); |
|
433 | + |
|
434 | + $owner = $this->cloudIdManager->getCloudId($share['owner'], $remote); |
|
435 | + $mountpoint = $share['mountpoint']; |
|
436 | + $user = $share['user']; |
|
437 | + |
|
438 | + $query = \OCP\DB::prepare('DELETE FROM `*PREFIX*share_external` WHERE `remote_id` = ? AND `share_token` = ?'); |
|
439 | + $query->execute(array($id, $token)); |
|
440 | + |
|
441 | + if ($share['accepted']) { |
|
442 | + $path = trim($mountpoint, '/'); |
|
443 | + } else { |
|
444 | + $path = trim($share['name'], '/'); |
|
445 | + } |
|
446 | + |
|
447 | + $notificationManager = \OC::$server->getNotificationManager(); |
|
448 | + $notification = $notificationManager->createNotification(); |
|
449 | + $notification->setApp('files_sharing') |
|
450 | + ->setUser($share['user']) |
|
451 | + ->setObject('remote_share', (int) $share['id']); |
|
452 | + $notificationManager->markProcessed($notification); |
|
453 | + |
|
454 | + $event = \OC::$server->getActivityManager()->generateEvent(); |
|
455 | + $event->setApp('files_sharing') |
|
456 | + ->setType('remote_share') |
|
457 | + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_UNSHARED, [$owner, $path]) |
|
458 | + ->setAffectedUser($user) |
|
459 | + ->setObject('remote_share', (int) $share['id'], $path); |
|
460 | + \OC::$server->getActivityManager()->publish($event); |
|
461 | + } |
|
462 | + |
|
463 | + return new Http\DataResponse(); |
|
464 | + } |
|
465 | + |
|
466 | + private function cleanupRemote($remote) { |
|
467 | + $remote = substr($remote, strpos($remote, '://') + 3); |
|
468 | + |
|
469 | + return rtrim($remote, '/'); |
|
470 | + } |
|
471 | + |
|
472 | + |
|
473 | + /** |
|
474 | + * @NoCSRFRequired |
|
475 | + * @PublicPage |
|
476 | + * |
|
477 | + * federated share was revoked, either by the owner or the re-sharer |
|
478 | + * |
|
479 | + * @param int $id |
|
480 | + * @return Http\DataResponse |
|
481 | + * @throws OCSBadRequestException |
|
482 | + */ |
|
483 | + public function revoke($id) { |
|
484 | + $token = $this->request->getParam('token'); |
|
485 | 485 | |
486 | - $share = $this->federatedShareProvider->getShareById($id); |
|
486 | + $share = $this->federatedShareProvider->getShareById($id); |
|
487 | 487 | |
488 | - if ($this->verifyShare($share, $token)) { |
|
489 | - $this->federatedShareProvider->removeShareFromTable($share); |
|
490 | - return new Http\DataResponse(); |
|
491 | - } |
|
488 | + if ($this->verifyShare($share, $token)) { |
|
489 | + $this->federatedShareProvider->removeShareFromTable($share); |
|
490 | + return new Http\DataResponse(); |
|
491 | + } |
|
492 | 492 | |
493 | - throw new OCSBadRequestException(); |
|
494 | - } |
|
493 | + throw new OCSBadRequestException(); |
|
494 | + } |
|
495 | 495 | |
496 | - /** |
|
497 | - * get share |
|
498 | - * |
|
499 | - * @param int $id |
|
500 | - * @param string $token |
|
501 | - * @return array|bool |
|
502 | - */ |
|
503 | - protected function getShare($id, $token) { |
|
504 | - $query = $this->connection->getQueryBuilder(); |
|
505 | - $query->select('*')->from($this->shareTable) |
|
506 | - ->where($query->expr()->eq('token', $query->createNamedParameter($token))) |
|
507 | - ->andWhere($query->expr()->eq('share_type', $query->createNamedParameter(FederatedShareProvider::SHARE_TYPE_REMOTE))) |
|
508 | - ->andWhere($query->expr()->eq('id', $query->createNamedParameter($id))); |
|
509 | - |
|
510 | - $result = $query->execute()->fetchAll(); |
|
511 | - |
|
512 | - if (!empty($result) && isset($result[0])) { |
|
513 | - return $result[0]; |
|
514 | - } |
|
515 | - |
|
516 | - return false; |
|
517 | - } |
|
518 | - |
|
519 | - /** |
|
520 | - * get file |
|
521 | - * |
|
522 | - * @param string $user |
|
523 | - * @param int $fileSource |
|
524 | - * @return array with internal path of the file and a absolute link to it |
|
525 | - */ |
|
526 | - private function getFile($user, $fileSource) { |
|
527 | - \OC_Util::setupFS($user); |
|
528 | - |
|
529 | - try { |
|
530 | - $file = \OC\Files\Filesystem::getPath($fileSource); |
|
531 | - } catch (NotFoundException $e) { |
|
532 | - $file = null; |
|
533 | - } |
|
534 | - $args = \OC\Files\Filesystem::is_dir($file) ? array('dir' => $file) : array('dir' => dirname($file), 'scrollto' => $file); |
|
535 | - $link = \OCP\Util::linkToAbsolute('files', 'index.php', $args); |
|
536 | - |
|
537 | - return array($file, $link); |
|
538 | - |
|
539 | - } |
|
540 | - |
|
541 | - /** |
|
542 | - * check if server-to-server sharing is enabled |
|
543 | - * |
|
544 | - * @param bool $incoming |
|
545 | - * @return bool |
|
546 | - */ |
|
547 | - private function isS2SEnabled($incoming = false) { |
|
548 | - |
|
549 | - $result = \OCP\App::isEnabled('files_sharing'); |
|
550 | - |
|
551 | - if ($incoming) { |
|
552 | - $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled(); |
|
553 | - } else { |
|
554 | - $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
555 | - } |
|
556 | - |
|
557 | - return $result; |
|
558 | - } |
|
559 | - |
|
560 | - /** |
|
561 | - * check if we got the right share |
|
562 | - * |
|
563 | - * @param Share\IShare $share |
|
564 | - * @param string $token |
|
565 | - * @return bool |
|
566 | - */ |
|
567 | - protected function verifyShare(Share\IShare $share, $token) { |
|
568 | - if ( |
|
569 | - $share->getShareType() === FederatedShareProvider::SHARE_TYPE_REMOTE && |
|
570 | - $share->getToken() === $token |
|
571 | - ) { |
|
572 | - return true; |
|
573 | - } |
|
574 | - |
|
575 | - return false; |
|
576 | - } |
|
577 | - |
|
578 | - /** |
|
579 | - * @NoCSRFRequired |
|
580 | - * @PublicPage |
|
581 | - * |
|
582 | - * update share information to keep federated re-shares in sync |
|
583 | - * |
|
584 | - * @param int $id |
|
585 | - * @return Http\DataResponse |
|
586 | - * @throws OCSBadRequestException |
|
587 | - */ |
|
588 | - public function updatePermissions($id) { |
|
589 | - $token = $this->request->getParam('token', null); |
|
590 | - $permissions = $this->request->getParam('permissions', null); |
|
591 | - |
|
592 | - try { |
|
593 | - $share = $this->federatedShareProvider->getShareById($id); |
|
594 | - } catch (Share\Exceptions\ShareNotFound $e) { |
|
595 | - throw new OCSBadRequestException(); |
|
596 | - } |
|
597 | - |
|
598 | - $validPermission = ctype_digit($permissions); |
|
599 | - $validToken = $this->verifyShare($share, $token); |
|
600 | - if ($validPermission && $validToken) { |
|
601 | - $this->updatePermissionsInDatabase($share, (int)$permissions); |
|
602 | - } else { |
|
603 | - throw new OCSBadRequestException(); |
|
604 | - } |
|
605 | - |
|
606 | - return new Http\DataResponse(); |
|
607 | - } |
|
608 | - |
|
609 | - /** |
|
610 | - * update permissions in database |
|
611 | - * |
|
612 | - * @param IShare $share |
|
613 | - * @param int $permissions |
|
614 | - */ |
|
615 | - protected function updatePermissionsInDatabase(IShare $share, $permissions) { |
|
616 | - $query = $this->connection->getQueryBuilder(); |
|
617 | - $query->update('share') |
|
618 | - ->where($query->expr()->eq('id', $query->createNamedParameter($share->getId()))) |
|
619 | - ->set('permissions', $query->createNamedParameter($permissions)) |
|
620 | - ->execute(); |
|
621 | - } |
|
496 | + /** |
|
497 | + * get share |
|
498 | + * |
|
499 | + * @param int $id |
|
500 | + * @param string $token |
|
501 | + * @return array|bool |
|
502 | + */ |
|
503 | + protected function getShare($id, $token) { |
|
504 | + $query = $this->connection->getQueryBuilder(); |
|
505 | + $query->select('*')->from($this->shareTable) |
|
506 | + ->where($query->expr()->eq('token', $query->createNamedParameter($token))) |
|
507 | + ->andWhere($query->expr()->eq('share_type', $query->createNamedParameter(FederatedShareProvider::SHARE_TYPE_REMOTE))) |
|
508 | + ->andWhere($query->expr()->eq('id', $query->createNamedParameter($id))); |
|
509 | + |
|
510 | + $result = $query->execute()->fetchAll(); |
|
511 | + |
|
512 | + if (!empty($result) && isset($result[0])) { |
|
513 | + return $result[0]; |
|
514 | + } |
|
515 | + |
|
516 | + return false; |
|
517 | + } |
|
518 | + |
|
519 | + /** |
|
520 | + * get file |
|
521 | + * |
|
522 | + * @param string $user |
|
523 | + * @param int $fileSource |
|
524 | + * @return array with internal path of the file and a absolute link to it |
|
525 | + */ |
|
526 | + private function getFile($user, $fileSource) { |
|
527 | + \OC_Util::setupFS($user); |
|
528 | + |
|
529 | + try { |
|
530 | + $file = \OC\Files\Filesystem::getPath($fileSource); |
|
531 | + } catch (NotFoundException $e) { |
|
532 | + $file = null; |
|
533 | + } |
|
534 | + $args = \OC\Files\Filesystem::is_dir($file) ? array('dir' => $file) : array('dir' => dirname($file), 'scrollto' => $file); |
|
535 | + $link = \OCP\Util::linkToAbsolute('files', 'index.php', $args); |
|
536 | + |
|
537 | + return array($file, $link); |
|
538 | + |
|
539 | + } |
|
540 | + |
|
541 | + /** |
|
542 | + * check if server-to-server sharing is enabled |
|
543 | + * |
|
544 | + * @param bool $incoming |
|
545 | + * @return bool |
|
546 | + */ |
|
547 | + private function isS2SEnabled($incoming = false) { |
|
548 | + |
|
549 | + $result = \OCP\App::isEnabled('files_sharing'); |
|
550 | + |
|
551 | + if ($incoming) { |
|
552 | + $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled(); |
|
553 | + } else { |
|
554 | + $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
555 | + } |
|
556 | + |
|
557 | + return $result; |
|
558 | + } |
|
559 | + |
|
560 | + /** |
|
561 | + * check if we got the right share |
|
562 | + * |
|
563 | + * @param Share\IShare $share |
|
564 | + * @param string $token |
|
565 | + * @return bool |
|
566 | + */ |
|
567 | + protected function verifyShare(Share\IShare $share, $token) { |
|
568 | + if ( |
|
569 | + $share->getShareType() === FederatedShareProvider::SHARE_TYPE_REMOTE && |
|
570 | + $share->getToken() === $token |
|
571 | + ) { |
|
572 | + return true; |
|
573 | + } |
|
574 | + |
|
575 | + return false; |
|
576 | + } |
|
577 | + |
|
578 | + /** |
|
579 | + * @NoCSRFRequired |
|
580 | + * @PublicPage |
|
581 | + * |
|
582 | + * update share information to keep federated re-shares in sync |
|
583 | + * |
|
584 | + * @param int $id |
|
585 | + * @return Http\DataResponse |
|
586 | + * @throws OCSBadRequestException |
|
587 | + */ |
|
588 | + public function updatePermissions($id) { |
|
589 | + $token = $this->request->getParam('token', null); |
|
590 | + $permissions = $this->request->getParam('permissions', null); |
|
591 | + |
|
592 | + try { |
|
593 | + $share = $this->federatedShareProvider->getShareById($id); |
|
594 | + } catch (Share\Exceptions\ShareNotFound $e) { |
|
595 | + throw new OCSBadRequestException(); |
|
596 | + } |
|
597 | + |
|
598 | + $validPermission = ctype_digit($permissions); |
|
599 | + $validToken = $this->verifyShare($share, $token); |
|
600 | + if ($validPermission && $validToken) { |
|
601 | + $this->updatePermissionsInDatabase($share, (int)$permissions); |
|
602 | + } else { |
|
603 | + throw new OCSBadRequestException(); |
|
604 | + } |
|
605 | + |
|
606 | + return new Http\DataResponse(); |
|
607 | + } |
|
608 | + |
|
609 | + /** |
|
610 | + * update permissions in database |
|
611 | + * |
|
612 | + * @param IShare $share |
|
613 | + * @param int $permissions |
|
614 | + */ |
|
615 | + protected function updatePermissionsInDatabase(IShare $share, $permissions) { |
|
616 | + $query = $this->connection->getQueryBuilder(); |
|
617 | + $query->update('share') |
|
618 | + ->where($query->expr()->eq('id', $query->createNamedParameter($share->getId()))) |
|
619 | + ->set('permissions', $query->createNamedParameter($permissions)) |
|
620 | + ->execute(); |
|
621 | + } |
|
622 | 622 | |
623 | 623 | } |
@@ -33,98 +33,98 @@ |
||
33 | 33 | |
34 | 34 | class Application extends App { |
35 | 35 | |
36 | - /** @var FederatedShareProvider */ |
|
37 | - protected $federatedShareProvider; |
|
36 | + /** @var FederatedShareProvider */ |
|
37 | + protected $federatedShareProvider; |
|
38 | 38 | |
39 | - public function __construct() { |
|
40 | - parent::__construct('federatedfilesharing'); |
|
39 | + public function __construct() { |
|
40 | + parent::__construct('federatedfilesharing'); |
|
41 | 41 | |
42 | - $container = $this->getContainer(); |
|
43 | - $server = $container->getServer(); |
|
42 | + $container = $this->getContainer(); |
|
43 | + $server = $container->getServer(); |
|
44 | 44 | |
45 | - $container->registerService('RequestHandlerController', function(SimpleContainer $c) use ($server) { |
|
46 | - $addressHandler = new AddressHandler( |
|
47 | - $server->getURLGenerator(), |
|
48 | - $server->getL10N('federatedfilesharing'), |
|
49 | - $server->getCloudIdManager() |
|
50 | - ); |
|
51 | - $notification = new Notifications( |
|
52 | - $addressHandler, |
|
53 | - $server->getHTTPClientService(), |
|
54 | - new \OCA\FederatedFileSharing\DiscoveryManager( |
|
55 | - $server->getMemCacheFactory(), |
|
56 | - $server->getHTTPClientService() |
|
57 | - ), |
|
58 | - \OC::$server->getJobList() |
|
59 | - ); |
|
60 | - return new RequestHandlerController( |
|
61 | - $c->query('AppName'), |
|
62 | - $server->getRequest(), |
|
63 | - $this->getFederatedShareProvider(), |
|
64 | - $server->getDatabaseConnection(), |
|
65 | - $server->getShareManager(), |
|
66 | - $notification, |
|
67 | - $addressHandler, |
|
68 | - $server->getUserManager(), |
|
69 | - $server->getCloudIdManager() |
|
70 | - ); |
|
71 | - }); |
|
72 | - } |
|
45 | + $container->registerService('RequestHandlerController', function(SimpleContainer $c) use ($server) { |
|
46 | + $addressHandler = new AddressHandler( |
|
47 | + $server->getURLGenerator(), |
|
48 | + $server->getL10N('federatedfilesharing'), |
|
49 | + $server->getCloudIdManager() |
|
50 | + ); |
|
51 | + $notification = new Notifications( |
|
52 | + $addressHandler, |
|
53 | + $server->getHTTPClientService(), |
|
54 | + new \OCA\FederatedFileSharing\DiscoveryManager( |
|
55 | + $server->getMemCacheFactory(), |
|
56 | + $server->getHTTPClientService() |
|
57 | + ), |
|
58 | + \OC::$server->getJobList() |
|
59 | + ); |
|
60 | + return new RequestHandlerController( |
|
61 | + $c->query('AppName'), |
|
62 | + $server->getRequest(), |
|
63 | + $this->getFederatedShareProvider(), |
|
64 | + $server->getDatabaseConnection(), |
|
65 | + $server->getShareManager(), |
|
66 | + $notification, |
|
67 | + $addressHandler, |
|
68 | + $server->getUserManager(), |
|
69 | + $server->getCloudIdManager() |
|
70 | + ); |
|
71 | + }); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * register personal and admin settings page |
|
76 | - */ |
|
77 | - public function registerSettings() { |
|
78 | - \OCP\App::registerPersonal('federatedfilesharing', 'settings-personal'); |
|
79 | - } |
|
74 | + /** |
|
75 | + * register personal and admin settings page |
|
76 | + */ |
|
77 | + public function registerSettings() { |
|
78 | + \OCP\App::registerPersonal('federatedfilesharing', 'settings-personal'); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * get instance of federated share provider |
|
83 | - * |
|
84 | - * @return FederatedShareProvider |
|
85 | - */ |
|
86 | - public function getFederatedShareProvider() { |
|
87 | - if ($this->federatedShareProvider === null) { |
|
88 | - $this->initFederatedShareProvider(); |
|
89 | - } |
|
90 | - return $this->federatedShareProvider; |
|
91 | - } |
|
81 | + /** |
|
82 | + * get instance of federated share provider |
|
83 | + * |
|
84 | + * @return FederatedShareProvider |
|
85 | + */ |
|
86 | + public function getFederatedShareProvider() { |
|
87 | + if ($this->federatedShareProvider === null) { |
|
88 | + $this->initFederatedShareProvider(); |
|
89 | + } |
|
90 | + return $this->federatedShareProvider; |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * initialize federated share provider |
|
95 | - */ |
|
96 | - protected function initFederatedShareProvider() { |
|
97 | - $addressHandler = new \OCA\FederatedFileSharing\AddressHandler( |
|
98 | - \OC::$server->getURLGenerator(), |
|
99 | - \OC::$server->getL10N('federatedfilesharing'), |
|
100 | - \OC::$server->getCloudIdManager() |
|
101 | - ); |
|
102 | - $discoveryManager = new \OCA\FederatedFileSharing\DiscoveryManager( |
|
103 | - \OC::$server->getMemCacheFactory(), |
|
104 | - \OC::$server->getHTTPClientService() |
|
105 | - ); |
|
106 | - $notifications = new \OCA\FederatedFileSharing\Notifications( |
|
107 | - $addressHandler, |
|
108 | - \OC::$server->getHTTPClientService(), |
|
109 | - $discoveryManager, |
|
110 | - \OC::$server->getJobList() |
|
111 | - ); |
|
112 | - $tokenHandler = new \OCA\FederatedFileSharing\TokenHandler( |
|
113 | - \OC::$server->getSecureRandom() |
|
114 | - ); |
|
93 | + /** |
|
94 | + * initialize federated share provider |
|
95 | + */ |
|
96 | + protected function initFederatedShareProvider() { |
|
97 | + $addressHandler = new \OCA\FederatedFileSharing\AddressHandler( |
|
98 | + \OC::$server->getURLGenerator(), |
|
99 | + \OC::$server->getL10N('federatedfilesharing'), |
|
100 | + \OC::$server->getCloudIdManager() |
|
101 | + ); |
|
102 | + $discoveryManager = new \OCA\FederatedFileSharing\DiscoveryManager( |
|
103 | + \OC::$server->getMemCacheFactory(), |
|
104 | + \OC::$server->getHTTPClientService() |
|
105 | + ); |
|
106 | + $notifications = new \OCA\FederatedFileSharing\Notifications( |
|
107 | + $addressHandler, |
|
108 | + \OC::$server->getHTTPClientService(), |
|
109 | + $discoveryManager, |
|
110 | + \OC::$server->getJobList() |
|
111 | + ); |
|
112 | + $tokenHandler = new \OCA\FederatedFileSharing\TokenHandler( |
|
113 | + \OC::$server->getSecureRandom() |
|
114 | + ); |
|
115 | 115 | |
116 | - $this->federatedShareProvider = new \OCA\FederatedFileSharing\FederatedShareProvider( |
|
117 | - \OC::$server->getDatabaseConnection(), |
|
118 | - $addressHandler, |
|
119 | - $notifications, |
|
120 | - $tokenHandler, |
|
121 | - \OC::$server->getL10N('federatedfilesharing'), |
|
122 | - \OC::$server->getLogger(), |
|
123 | - \OC::$server->getLazyRootFolder(), |
|
124 | - \OC::$server->getConfig(), |
|
125 | - \OC::$server->getUserManager(), |
|
126 | - \OC::$server->getCloudIdManager() |
|
127 | - ); |
|
128 | - } |
|
116 | + $this->federatedShareProvider = new \OCA\FederatedFileSharing\FederatedShareProvider( |
|
117 | + \OC::$server->getDatabaseConnection(), |
|
118 | + $addressHandler, |
|
119 | + $notifications, |
|
120 | + $tokenHandler, |
|
121 | + \OC::$server->getL10N('federatedfilesharing'), |
|
122 | + \OC::$server->getLogger(), |
|
123 | + \OC::$server->getLazyRootFolder(), |
|
124 | + \OC::$server->getConfig(), |
|
125 | + \OC::$server->getUserManager(), |
|
126 | + \OC::$server->getCloudIdManager() |
|
127 | + ); |
|
128 | + } |
|
129 | 129 | |
130 | 130 | } |
@@ -42,107 +42,107 @@ |
||
42 | 42 | */ |
43 | 43 | class RetryJob extends Job { |
44 | 44 | |
45 | - /** @var bool */ |
|
46 | - private $retainJob = true; |
|
47 | - |
|
48 | - /** @var Notifications */ |
|
49 | - private $notifications; |
|
50 | - |
|
51 | - /** @var int max number of attempts to send the request */ |
|
52 | - private $maxTry = 20; |
|
53 | - |
|
54 | - /** @var int how much time should be between two tries (10 minutes) */ |
|
55 | - private $interval = 600; |
|
56 | - |
|
57 | - /** |
|
58 | - * UnShare constructor. |
|
59 | - * |
|
60 | - * @param Notifications $notifications |
|
61 | - */ |
|
62 | - public function __construct(Notifications $notifications = null) { |
|
63 | - if ($notifications) { |
|
64 | - $this->notifications = $notifications; |
|
65 | - } else { |
|
66 | - $addressHandler = new AddressHandler( |
|
67 | - \OC::$server->getURLGenerator(), |
|
68 | - \OC::$server->getL10N('federatedfilesharing'), |
|
69 | - \OC::$server->getCloudIdManager() |
|
70 | - ); |
|
71 | - $discoveryManager = new DiscoveryManager( |
|
72 | - \OC::$server->getMemCacheFactory(), |
|
73 | - \OC::$server->getHTTPClientService() |
|
74 | - ); |
|
75 | - $this->notifications = new Notifications( |
|
76 | - $addressHandler, |
|
77 | - \OC::$server->getHTTPClientService(), |
|
78 | - $discoveryManager, |
|
79 | - \OC::$server->getJobList() |
|
80 | - ); |
|
81 | - } |
|
82 | - |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * run the job, then remove it from the jobList |
|
87 | - * |
|
88 | - * @param JobList $jobList |
|
89 | - * @param ILogger $logger |
|
90 | - */ |
|
91 | - public function execute($jobList, ILogger $logger = null) { |
|
92 | - |
|
93 | - if ($this->shouldRun($this->argument)) { |
|
94 | - parent::execute($jobList, $logger); |
|
95 | - $jobList->remove($this, $this->argument); |
|
96 | - if ($this->retainJob) { |
|
97 | - $this->reAddJob($jobList, $this->argument); |
|
98 | - } |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - protected function run($argument) { |
|
103 | - $remote = $argument['remote']; |
|
104 | - $remoteId = $argument['remoteId']; |
|
105 | - $token = $argument['token']; |
|
106 | - $action = $argument['action']; |
|
107 | - $data = json_decode($argument['data'], true); |
|
108 | - $try = (int)$argument['try'] + 1; |
|
109 | - |
|
110 | - $result = $this->notifications->sendUpdateToRemote($remote, $remoteId, $token, $action, $data, $try); |
|
45 | + /** @var bool */ |
|
46 | + private $retainJob = true; |
|
47 | + |
|
48 | + /** @var Notifications */ |
|
49 | + private $notifications; |
|
50 | + |
|
51 | + /** @var int max number of attempts to send the request */ |
|
52 | + private $maxTry = 20; |
|
53 | + |
|
54 | + /** @var int how much time should be between two tries (10 minutes) */ |
|
55 | + private $interval = 600; |
|
56 | + |
|
57 | + /** |
|
58 | + * UnShare constructor. |
|
59 | + * |
|
60 | + * @param Notifications $notifications |
|
61 | + */ |
|
62 | + public function __construct(Notifications $notifications = null) { |
|
63 | + if ($notifications) { |
|
64 | + $this->notifications = $notifications; |
|
65 | + } else { |
|
66 | + $addressHandler = new AddressHandler( |
|
67 | + \OC::$server->getURLGenerator(), |
|
68 | + \OC::$server->getL10N('federatedfilesharing'), |
|
69 | + \OC::$server->getCloudIdManager() |
|
70 | + ); |
|
71 | + $discoveryManager = new DiscoveryManager( |
|
72 | + \OC::$server->getMemCacheFactory(), |
|
73 | + \OC::$server->getHTTPClientService() |
|
74 | + ); |
|
75 | + $this->notifications = new Notifications( |
|
76 | + $addressHandler, |
|
77 | + \OC::$server->getHTTPClientService(), |
|
78 | + $discoveryManager, |
|
79 | + \OC::$server->getJobList() |
|
80 | + ); |
|
81 | + } |
|
82 | + |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * run the job, then remove it from the jobList |
|
87 | + * |
|
88 | + * @param JobList $jobList |
|
89 | + * @param ILogger $logger |
|
90 | + */ |
|
91 | + public function execute($jobList, ILogger $logger = null) { |
|
92 | + |
|
93 | + if ($this->shouldRun($this->argument)) { |
|
94 | + parent::execute($jobList, $logger); |
|
95 | + $jobList->remove($this, $this->argument); |
|
96 | + if ($this->retainJob) { |
|
97 | + $this->reAddJob($jobList, $this->argument); |
|
98 | + } |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + protected function run($argument) { |
|
103 | + $remote = $argument['remote']; |
|
104 | + $remoteId = $argument['remoteId']; |
|
105 | + $token = $argument['token']; |
|
106 | + $action = $argument['action']; |
|
107 | + $data = json_decode($argument['data'], true); |
|
108 | + $try = (int)$argument['try'] + 1; |
|
109 | + |
|
110 | + $result = $this->notifications->sendUpdateToRemote($remote, $remoteId, $token, $action, $data, $try); |
|
111 | 111 | |
112 | - if ($result === true || $try > $this->maxTry) { |
|
113 | - $this->retainJob = false; |
|
114 | - } |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * re-add background job with new arguments |
|
119 | - * |
|
120 | - * @param IJobList $jobList |
|
121 | - * @param array $argument |
|
122 | - */ |
|
123 | - protected function reAddJob(IJobList $jobList, array $argument) { |
|
124 | - $jobList->add('OCA\FederatedFileSharing\BackgroundJob\RetryJob', |
|
125 | - [ |
|
126 | - 'remote' => $argument['remote'], |
|
127 | - 'remoteId' => $argument['remoteId'], |
|
128 | - 'token' => $argument['token'], |
|
129 | - 'data' => $argument['data'], |
|
130 | - 'action' => $argument['action'], |
|
131 | - 'try' => (int)$argument['try'] + 1, |
|
132 | - 'lastRun' => time() |
|
133 | - ] |
|
134 | - ); |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * test if it is time for the next run |
|
139 | - * |
|
140 | - * @param array $argument |
|
141 | - * @return bool |
|
142 | - */ |
|
143 | - protected function shouldRun(array $argument) { |
|
144 | - $lastRun = (int)$argument['lastRun']; |
|
145 | - return ((time() - $lastRun) > $this->interval); |
|
146 | - } |
|
112 | + if ($result === true || $try > $this->maxTry) { |
|
113 | + $this->retainJob = false; |
|
114 | + } |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * re-add background job with new arguments |
|
119 | + * |
|
120 | + * @param IJobList $jobList |
|
121 | + * @param array $argument |
|
122 | + */ |
|
123 | + protected function reAddJob(IJobList $jobList, array $argument) { |
|
124 | + $jobList->add('OCA\FederatedFileSharing\BackgroundJob\RetryJob', |
|
125 | + [ |
|
126 | + 'remote' => $argument['remote'], |
|
127 | + 'remoteId' => $argument['remoteId'], |
|
128 | + 'token' => $argument['token'], |
|
129 | + 'data' => $argument['data'], |
|
130 | + 'action' => $argument['action'], |
|
131 | + 'try' => (int)$argument['try'] + 1, |
|
132 | + 'lastRun' => time() |
|
133 | + ] |
|
134 | + ); |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * test if it is time for the next run |
|
139 | + * |
|
140 | + * @param array $argument |
|
141 | + * @return bool |
|
142 | + */ |
|
143 | + protected function shouldRun(array $argument) { |
|
144 | + $lastRun = (int)$argument['lastRun']; |
|
145 | + return ((time() - $lastRun) > $this->interval); |
|
146 | + } |
|
147 | 147 | |
148 | 148 | } |
@@ -29,42 +29,42 @@ |
||
29 | 29 | |
30 | 30 | class Admin implements ISettings { |
31 | 31 | |
32 | - /** @var FederatedShareProvider */ |
|
33 | - private $fedShareProvider; |
|
32 | + /** @var FederatedShareProvider */ |
|
33 | + private $fedShareProvider; |
|
34 | 34 | |
35 | - public function __construct(FederatedShareProvider $fedShareProvider) { |
|
36 | - $this->fedShareProvider = $fedShareProvider; |
|
37 | - } |
|
35 | + public function __construct(FederatedShareProvider $fedShareProvider) { |
|
36 | + $this->fedShareProvider = $fedShareProvider; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return TemplateResponse |
|
41 | - */ |
|
42 | - public function getForm() { |
|
43 | - $parameters = [ |
|
44 | - 'outgoingServer2serverShareEnabled' => $this->fedShareProvider->isOutgoingServer2serverShareEnabled(), |
|
45 | - 'incomingServer2serverShareEnabled' => $this->fedShareProvider->isIncomingServer2serverShareEnabled(), |
|
46 | - 'lookupServerEnabled' => $this->fedShareProvider->isLookupServerQueriesEnabled(), |
|
47 | - ]; |
|
39 | + /** |
|
40 | + * @return TemplateResponse |
|
41 | + */ |
|
42 | + public function getForm() { |
|
43 | + $parameters = [ |
|
44 | + 'outgoingServer2serverShareEnabled' => $this->fedShareProvider->isOutgoingServer2serverShareEnabled(), |
|
45 | + 'incomingServer2serverShareEnabled' => $this->fedShareProvider->isIncomingServer2serverShareEnabled(), |
|
46 | + 'lookupServerEnabled' => $this->fedShareProvider->isLookupServerQueriesEnabled(), |
|
47 | + ]; |
|
48 | 48 | |
49 | - return new TemplateResponse('federatedfilesharing', 'settings-admin', $parameters, ''); |
|
50 | - } |
|
49 | + return new TemplateResponse('federatedfilesharing', 'settings-admin', $parameters, ''); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @return string the section ID, e.g. 'sharing' |
|
54 | - */ |
|
55 | - public function getSection() { |
|
56 | - return 'sharing'; |
|
57 | - } |
|
52 | + /** |
|
53 | + * @return string the section ID, e.g. 'sharing' |
|
54 | + */ |
|
55 | + public function getSection() { |
|
56 | + return 'sharing'; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @return int whether the form should be rather on the top or bottom of |
|
61 | - * the admin section. The forms are arranged in ascending order of the |
|
62 | - * priority values. It is required to return a value between 0 and 100. |
|
63 | - * |
|
64 | - * E.g.: 70 |
|
65 | - */ |
|
66 | - public function getPriority() { |
|
67 | - return 20; |
|
68 | - } |
|
59 | + /** |
|
60 | + * @return int whether the form should be rather on the top or bottom of |
|
61 | + * the admin section. The forms are arranged in ascending order of the |
|
62 | + * priority values. It is required to return a value between 0 and 100. |
|
63 | + * |
|
64 | + * E.g.: 70 |
|
65 | + */ |
|
66 | + public function getPriority() { |
|
67 | + return 20; |
|
68 | + } |
|
69 | 69 | |
70 | 70 | } |
@@ -33,30 +33,30 @@ |
||
33 | 33 | */ |
34 | 34 | class TokenHandler { |
35 | 35 | |
36 | - const TOKEN_LENGTH = 15; |
|
37 | - |
|
38 | - /** @var ISecureRandom */ |
|
39 | - private $secureRandom; |
|
40 | - |
|
41 | - /** |
|
42 | - * TokenHandler constructor. |
|
43 | - * |
|
44 | - * @param ISecureRandom $secureRandom |
|
45 | - */ |
|
46 | - public function __construct(ISecureRandom $secureRandom) { |
|
47 | - $this->secureRandom = $secureRandom; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * generate to token used to authenticate federated shares |
|
52 | - * |
|
53 | - * @return string |
|
54 | - */ |
|
55 | - public function generateToken() { |
|
56 | - $token = $this->secureRandom->generate( |
|
57 | - self::TOKEN_LENGTH, |
|
58 | - ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); |
|
59 | - return $token; |
|
60 | - } |
|
36 | + const TOKEN_LENGTH = 15; |
|
37 | + |
|
38 | + /** @var ISecureRandom */ |
|
39 | + private $secureRandom; |
|
40 | + |
|
41 | + /** |
|
42 | + * TokenHandler constructor. |
|
43 | + * |
|
44 | + * @param ISecureRandom $secureRandom |
|
45 | + */ |
|
46 | + public function __construct(ISecureRandom $secureRandom) { |
|
47 | + $this->secureRandom = $secureRandom; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * generate to token used to authenticate federated shares |
|
52 | + * |
|
53 | + * @return string |
|
54 | + */ |
|
55 | + public function generateToken() { |
|
56 | + $token = $this->secureRandom->generate( |
|
57 | + self::TOKEN_LENGTH, |
|
58 | + ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); |
|
59 | + return $token; |
|
60 | + } |
|
61 | 61 | |
62 | 62 | } |
@@ -33,122 +33,122 @@ |
||
33 | 33 | */ |
34 | 34 | class AddressHandler { |
35 | 35 | |
36 | - /** @var IL10N */ |
|
37 | - private $l; |
|
38 | - |
|
39 | - /** @var IURLGenerator */ |
|
40 | - private $urlGenerator; |
|
41 | - |
|
42 | - /** @var ICloudIdManager */ |
|
43 | - private $cloudIdManager; |
|
44 | - |
|
45 | - /** |
|
46 | - * AddressHandler constructor. |
|
47 | - * |
|
48 | - * @param IURLGenerator $urlGenerator |
|
49 | - * @param IL10N $il10n |
|
50 | - * @param ICloudIdManager $cloudIdManager |
|
51 | - */ |
|
52 | - public function __construct( |
|
53 | - IURLGenerator $urlGenerator, |
|
54 | - IL10N $il10n, |
|
55 | - ICloudIdManager $cloudIdManager |
|
56 | - ) { |
|
57 | - $this->l = $il10n; |
|
58 | - $this->urlGenerator = $urlGenerator; |
|
59 | - $this->cloudIdManager = $cloudIdManager; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * split user and remote from federated cloud id |
|
64 | - * |
|
65 | - * @param string $address federated share address |
|
66 | - * @return array [user, remoteURL] |
|
67 | - * @throws HintException |
|
68 | - */ |
|
69 | - public function splitUserRemote($address) { |
|
70 | - try { |
|
71 | - $cloudId = $this->cloudIdManager->resolveCloudId($address); |
|
72 | - return [$cloudId->getUser(), $cloudId->getRemote()]; |
|
73 | - } catch (\InvalidArgumentException $e) { |
|
74 | - $hint = $this->l->t('Invalid Federated Cloud ID'); |
|
75 | - throw new HintException('Invalid Federated Cloud ID', $hint, 0, $e); |
|
76 | - } |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * generate remote URL part of federated ID |
|
81 | - * |
|
82 | - * @return string url of the current server |
|
83 | - */ |
|
84 | - public function generateRemoteURL() { |
|
85 | - $url = $this->urlGenerator->getAbsoluteURL('/'); |
|
86 | - return $url; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * check if two federated cloud IDs refer to the same user |
|
91 | - * |
|
92 | - * @param string $user1 |
|
93 | - * @param string $server1 |
|
94 | - * @param string $user2 |
|
95 | - * @param string $server2 |
|
96 | - * @return bool true if both users and servers are the same |
|
97 | - */ |
|
98 | - public function compareAddresses($user1, $server1, $user2, $server2) { |
|
99 | - $normalizedServer1 = strtolower($this->removeProtocolFromUrl($server1)); |
|
100 | - $normalizedServer2 = strtolower($this->removeProtocolFromUrl($server2)); |
|
101 | - |
|
102 | - if (rtrim($normalizedServer1, '/') === rtrim($normalizedServer2, '/')) { |
|
103 | - // FIXME this should be a method in the user management instead |
|
104 | - \OCP\Util::emitHook( |
|
105 | - '\OCA\Files_Sharing\API\Server2Server', |
|
106 | - 'preLoginNameUsedAsUserName', |
|
107 | - array('uid' => &$user1) |
|
108 | - ); |
|
109 | - \OCP\Util::emitHook( |
|
110 | - '\OCA\Files_Sharing\API\Server2Server', |
|
111 | - 'preLoginNameUsedAsUserName', |
|
112 | - array('uid' => &$user2) |
|
113 | - ); |
|
114 | - |
|
115 | - if ($user1 === $user2) { |
|
116 | - return true; |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - return false; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * remove protocol from URL |
|
125 | - * |
|
126 | - * @param string $url |
|
127 | - * @return string |
|
128 | - */ |
|
129 | - public function removeProtocolFromUrl($url) { |
|
130 | - if (strpos($url, 'https://') === 0) { |
|
131 | - return substr($url, strlen('https://')); |
|
132 | - } else if (strpos($url, 'http://') === 0) { |
|
133 | - return substr($url, strlen('http://')); |
|
134 | - } |
|
135 | - |
|
136 | - return $url; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * check if the url contain the protocol (http or https) |
|
141 | - * |
|
142 | - * @param string $url |
|
143 | - * @return bool |
|
144 | - */ |
|
145 | - public function urlContainProtocol($url) { |
|
146 | - if (strpos($url, 'https://') === 0 || |
|
147 | - strpos($url, 'http://') === 0) { |
|
148 | - |
|
149 | - return true; |
|
150 | - } |
|
151 | - |
|
152 | - return false; |
|
153 | - } |
|
36 | + /** @var IL10N */ |
|
37 | + private $l; |
|
38 | + |
|
39 | + /** @var IURLGenerator */ |
|
40 | + private $urlGenerator; |
|
41 | + |
|
42 | + /** @var ICloudIdManager */ |
|
43 | + private $cloudIdManager; |
|
44 | + |
|
45 | + /** |
|
46 | + * AddressHandler constructor. |
|
47 | + * |
|
48 | + * @param IURLGenerator $urlGenerator |
|
49 | + * @param IL10N $il10n |
|
50 | + * @param ICloudIdManager $cloudIdManager |
|
51 | + */ |
|
52 | + public function __construct( |
|
53 | + IURLGenerator $urlGenerator, |
|
54 | + IL10N $il10n, |
|
55 | + ICloudIdManager $cloudIdManager |
|
56 | + ) { |
|
57 | + $this->l = $il10n; |
|
58 | + $this->urlGenerator = $urlGenerator; |
|
59 | + $this->cloudIdManager = $cloudIdManager; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * split user and remote from federated cloud id |
|
64 | + * |
|
65 | + * @param string $address federated share address |
|
66 | + * @return array [user, remoteURL] |
|
67 | + * @throws HintException |
|
68 | + */ |
|
69 | + public function splitUserRemote($address) { |
|
70 | + try { |
|
71 | + $cloudId = $this->cloudIdManager->resolveCloudId($address); |
|
72 | + return [$cloudId->getUser(), $cloudId->getRemote()]; |
|
73 | + } catch (\InvalidArgumentException $e) { |
|
74 | + $hint = $this->l->t('Invalid Federated Cloud ID'); |
|
75 | + throw new HintException('Invalid Federated Cloud ID', $hint, 0, $e); |
|
76 | + } |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * generate remote URL part of federated ID |
|
81 | + * |
|
82 | + * @return string url of the current server |
|
83 | + */ |
|
84 | + public function generateRemoteURL() { |
|
85 | + $url = $this->urlGenerator->getAbsoluteURL('/'); |
|
86 | + return $url; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * check if two federated cloud IDs refer to the same user |
|
91 | + * |
|
92 | + * @param string $user1 |
|
93 | + * @param string $server1 |
|
94 | + * @param string $user2 |
|
95 | + * @param string $server2 |
|
96 | + * @return bool true if both users and servers are the same |
|
97 | + */ |
|
98 | + public function compareAddresses($user1, $server1, $user2, $server2) { |
|
99 | + $normalizedServer1 = strtolower($this->removeProtocolFromUrl($server1)); |
|
100 | + $normalizedServer2 = strtolower($this->removeProtocolFromUrl($server2)); |
|
101 | + |
|
102 | + if (rtrim($normalizedServer1, '/') === rtrim($normalizedServer2, '/')) { |
|
103 | + // FIXME this should be a method in the user management instead |
|
104 | + \OCP\Util::emitHook( |
|
105 | + '\OCA\Files_Sharing\API\Server2Server', |
|
106 | + 'preLoginNameUsedAsUserName', |
|
107 | + array('uid' => &$user1) |
|
108 | + ); |
|
109 | + \OCP\Util::emitHook( |
|
110 | + '\OCA\Files_Sharing\API\Server2Server', |
|
111 | + 'preLoginNameUsedAsUserName', |
|
112 | + array('uid' => &$user2) |
|
113 | + ); |
|
114 | + |
|
115 | + if ($user1 === $user2) { |
|
116 | + return true; |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + return false; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * remove protocol from URL |
|
125 | + * |
|
126 | + * @param string $url |
|
127 | + * @return string |
|
128 | + */ |
|
129 | + public function removeProtocolFromUrl($url) { |
|
130 | + if (strpos($url, 'https://') === 0) { |
|
131 | + return substr($url, strlen('https://')); |
|
132 | + } else if (strpos($url, 'http://') === 0) { |
|
133 | + return substr($url, strlen('http://')); |
|
134 | + } |
|
135 | + |
|
136 | + return $url; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * check if the url contain the protocol (http or https) |
|
141 | + * |
|
142 | + * @param string $url |
|
143 | + * @return bool |
|
144 | + */ |
|
145 | + public function urlContainProtocol($url) { |
|
146 | + if (strpos($url, 'https://') === 0 || |
|
147 | + strpos($url, 'http://') === 0) { |
|
148 | + |
|
149 | + return true; |
|
150 | + } |
|
151 | + |
|
152 | + return false; |
|
153 | + } |
|
154 | 154 | } |
@@ -23,17 +23,17 @@ |
||
23 | 23 | */ |
24 | 24 | |
25 | 25 | return [ |
26 | - 'routes' => [ |
|
27 | - ['name' => 'MountPublicLink#createFederatedShare', 'url' => '/createFederatedShare', 'verb' => 'POST'], |
|
28 | - ['name' => 'MountPublicLink#askForFederatedShare', 'url' => '/askForFederatedShare', 'verb' => 'POST'], |
|
29 | - ], |
|
30 | - 'ocs' => [ |
|
31 | - ['root' => '/cloud', 'name' => 'RequestHandler#createShare', 'url' => '/shares', 'verb' => 'POST'], |
|
32 | - ['root' => '/cloud', 'name' => 'RequestHandler#reShare', 'url' => '/shares/{id}/reshare', 'verb' => 'POST'], |
|
33 | - ['root' => '/cloud', 'name' => 'RequestHandler#updatePermissions', 'url' => '/shares/{id}/permissions', 'verb' => 'POST'], |
|
34 | - ['root' => '/cloud', 'name' => 'RequestHandler#acceptShare', 'url' => '/shares/{id}/accept', 'verb' => 'POST'], |
|
35 | - ['root' => '/cloud', 'name' => 'RequestHandler#declineShare', 'url' => '/shares/{id}/decline', 'verb' => 'POST'], |
|
36 | - ['root' => '/cloud', 'name' => 'RequestHandler#unshare', 'url' => '/shares/{id}/unshare', 'verb' => 'POST'], |
|
37 | - ['root' => '/cloud', 'name' => 'RequestHandler#revoke', 'url' => '/shares/{id}/revoke', 'verb' => 'POST'], |
|
38 | - ], |
|
26 | + 'routes' => [ |
|
27 | + ['name' => 'MountPublicLink#createFederatedShare', 'url' => '/createFederatedShare', 'verb' => 'POST'], |
|
28 | + ['name' => 'MountPublicLink#askForFederatedShare', 'url' => '/askForFederatedShare', 'verb' => 'POST'], |
|
29 | + ], |
|
30 | + 'ocs' => [ |
|
31 | + ['root' => '/cloud', 'name' => 'RequestHandler#createShare', 'url' => '/shares', 'verb' => 'POST'], |
|
32 | + ['root' => '/cloud', 'name' => 'RequestHandler#reShare', 'url' => '/shares/{id}/reshare', 'verb' => 'POST'], |
|
33 | + ['root' => '/cloud', 'name' => 'RequestHandler#updatePermissions', 'url' => '/shares/{id}/permissions', 'verb' => 'POST'], |
|
34 | + ['root' => '/cloud', 'name' => 'RequestHandler#acceptShare', 'url' => '/shares/{id}/accept', 'verb' => 'POST'], |
|
35 | + ['root' => '/cloud', 'name' => 'RequestHandler#declineShare', 'url' => '/shares/{id}/decline', 'verb' => 'POST'], |
|
36 | + ['root' => '/cloud', 'name' => 'RequestHandler#unshare', 'url' => '/shares/{id}/unshare', 'verb' => 'POST'], |
|
37 | + ['root' => '/cloud', 'name' => 'RequestHandler#revoke', 'url' => '/shares/{id}/revoke', 'verb' => 'POST'], |
|
38 | + ], |
|
39 | 39 | ]; |
@@ -31,21 +31,21 @@ |
||
31 | 31 | |
32 | 32 | $manager = \OC::$server->getNotificationManager(); |
33 | 33 | $manager->registerNotifier(function() { |
34 | - return \OC::$server->query(Notifier::class); |
|
34 | + return \OC::$server->query(Notifier::class); |
|
35 | 35 | }, function() use ($l) { |
36 | - return [ |
|
37 | - 'id' => 'files_sharing', |
|
38 | - 'name' => $l->t('Federated sharing'), |
|
39 | - ]; |
|
36 | + return [ |
|
37 | + 'id' => 'files_sharing', |
|
38 | + 'name' => $l->t('Federated sharing'), |
|
39 | + ]; |
|
40 | 40 | }); |
41 | 41 | |
42 | 42 | $federatedShareProvider = $app->getFederatedShareProvider(); |
43 | 43 | |
44 | 44 | $eventDispatcher->addListener( |
45 | - 'OCA\Files::loadAdditionalScripts', |
|
46 | - function() use ($federatedShareProvider) { |
|
47 | - if ($federatedShareProvider->isIncomingServer2serverShareEnabled()) { |
|
48 | - \OCP\Util::addScript('federatedfilesharing', 'external'); |
|
49 | - } |
|
50 | - } |
|
45 | + 'OCA\Files::loadAdditionalScripts', |
|
46 | + function() use ($federatedShareProvider) { |
|
47 | + if ($federatedShareProvider->isIncomingServer2serverShareEnabled()) { |
|
48 | + \OCP\Util::addScript('federatedfilesharing', 'external'); |
|
49 | + } |
|
50 | + } |
|
51 | 51 | ); |
@@ -28,10 +28,10 @@ |
||
28 | 28 | <?php if((int)$trustedServer['status'] === TrustedServers::STATUS_OK) { ?> |
29 | 29 | <span class="status success"></span> |
30 | 30 | <?php |
31 | - } elseif( |
|
32 | - (int)$trustedServer['status'] === TrustedServers::STATUS_PENDING || |
|
33 | - (int)$trustedServer['status'] === TrustedServers::STATUS_ACCESS_REVOKED |
|
34 | - ) { ?> |
|
31 | + } elseif( |
|
32 | + (int)$trustedServer['status'] === TrustedServers::STATUS_PENDING || |
|
33 | + (int)$trustedServer['status'] === TrustedServers::STATUS_ACCESS_REVOKED |
|
34 | + ) { ?> |
|
35 | 35 | <span class="status indeterminate"></span> |
36 | 36 | <?php } else {?> |
37 | 37 | <span class="status error"></span> |