@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | * |
325 | 325 | * @param string $remoteDomain |
326 | 326 | * @param string $token |
327 | - * @param $remoteId id of the share |
|
327 | + * @param integer $remoteId id of the share |
|
328 | 328 | * @param string $feedback |
329 | 329 | * @return bool |
330 | 330 | */ |
@@ -421,6 +421,9 @@ discard block |
||
421 | 421 | return $result; |
422 | 422 | } |
423 | 423 | |
424 | + /** |
|
425 | + * @param string $mountPoint |
|
426 | + */ |
|
424 | 427 | public function removeShare($mountPoint) { |
425 | 428 | |
426 | 429 | $mountPointObj = $this->mountManager->find($mountPoint); |
@@ -44,520 +44,520 @@ |
||
44 | 44 | use OCP\Share; |
45 | 45 | |
46 | 46 | class Manager { |
47 | - const STORAGE = '\OCA\Files_Sharing\External\Storage'; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - private $uid; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var IDBConnection |
|
56 | - */ |
|
57 | - private $connection; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var \OC\Files\Mount\Manager |
|
61 | - */ |
|
62 | - private $mountManager; |
|
63 | - |
|
64 | - /** |
|
65 | - * @var IStorageFactory |
|
66 | - */ |
|
67 | - private $storageLoader; |
|
68 | - |
|
69 | - /** |
|
70 | - * @var IClientService |
|
71 | - */ |
|
72 | - private $clientService; |
|
73 | - |
|
74 | - /** |
|
75 | - * @var IManager |
|
76 | - */ |
|
77 | - private $notificationManager; |
|
78 | - |
|
79 | - /** |
|
80 | - * @var IDiscoveryService |
|
81 | - */ |
|
82 | - private $discoveryService; |
|
83 | - |
|
84 | - /** @var ICloudFederationProviderManager */ |
|
85 | - private $cloudFederationProviderManager; |
|
86 | - |
|
87 | - /** @var ICloudFederationFactory */ |
|
88 | - private $cloudFederationFactory; |
|
89 | - |
|
90 | - /** |
|
91 | - * @param IDBConnection $connection |
|
92 | - * @param \OC\Files\Mount\Manager $mountManager |
|
93 | - * @param IStorageFactory $storageLoader |
|
94 | - * @param IClientService $clientService |
|
95 | - * @param IManager $notificationManager |
|
96 | - * @param IDiscoveryService $discoveryService |
|
97 | - * @param ICloudFederationProviderManager $cloudFederationProviderManager |
|
98 | - * @param ICloudFederationFactory $cloudFederationFactory |
|
99 | - * @param string $uid |
|
100 | - */ |
|
101 | - public function __construct(IDBConnection $connection, |
|
102 | - \OC\Files\Mount\Manager $mountManager, |
|
103 | - IStorageFactory $storageLoader, |
|
104 | - IClientService $clientService, |
|
105 | - IManager $notificationManager, |
|
106 | - IDiscoveryService $discoveryService, |
|
107 | - ICloudFederationProviderManager $cloudFederationProviderManager, |
|
108 | - ICloudFederationFactory $cloudFederationFactory, |
|
109 | - $uid) { |
|
110 | - $this->connection = $connection; |
|
111 | - $this->mountManager = $mountManager; |
|
112 | - $this->storageLoader = $storageLoader; |
|
113 | - $this->clientService = $clientService; |
|
114 | - $this->uid = $uid; |
|
115 | - $this->notificationManager = $notificationManager; |
|
116 | - $this->discoveryService = $discoveryService; |
|
117 | - $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
118 | - $this->cloudFederationFactory = $cloudFederationFactory; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * add new server-to-server share |
|
123 | - * |
|
124 | - * @param string $remote |
|
125 | - * @param string $token |
|
126 | - * @param string $password |
|
127 | - * @param string $name |
|
128 | - * @param string $owner |
|
129 | - * @param int $shareType |
|
130 | - * @param boolean $accepted |
|
131 | - * @param string $user |
|
132 | - * @param int $remoteId |
|
133 | - * @param int $parent |
|
134 | - * @return Mount|null |
|
135 | - * @throws \Doctrine\DBAL\DBALException |
|
136 | - */ |
|
137 | - public function addShare($remote, $token, $password, $name, $owner, $shareType, $accepted=false, $user = null, $remoteId = -1, $parent = -1) { |
|
138 | - |
|
139 | - $user = $user ? $user : $this->uid; |
|
140 | - $accepted = $accepted ? 1 : 0; |
|
141 | - $name = Filesystem::normalizePath('/' . $name); |
|
142 | - |
|
143 | - if (!$accepted) { |
|
144 | - // To avoid conflicts with the mount point generation later, |
|
145 | - // we only use a temporary mount point name here. The real |
|
146 | - // mount point name will be generated when accepting the share, |
|
147 | - // using the original share item name. |
|
148 | - $tmpMountPointName = '{{TemporaryMountPointName#' . $name . '}}'; |
|
149 | - $mountPoint = $tmpMountPointName; |
|
150 | - $hash = md5($tmpMountPointName); |
|
151 | - $data = [ |
|
152 | - 'remote' => $remote, |
|
153 | - 'share_token' => $token, |
|
154 | - 'password' => $password, |
|
155 | - 'name' => $name, |
|
156 | - 'owner' => $owner, |
|
157 | - 'user' => $user, |
|
158 | - 'mountpoint' => $mountPoint, |
|
159 | - 'mountpoint_hash' => $hash, |
|
160 | - 'accepted' => $accepted, |
|
161 | - 'remote_id' => $remoteId, |
|
162 | - 'share_type' => $shareType, |
|
163 | - ]; |
|
164 | - |
|
165 | - $i = 1; |
|
166 | - while (!$this->connection->insertIfNotExist('*PREFIX*share_external', $data, ['user', 'mountpoint_hash'])) { |
|
167 | - // The external share already exists for the user |
|
168 | - $data['mountpoint'] = $tmpMountPointName . '-' . $i; |
|
169 | - $data['mountpoint_hash'] = md5($data['mountpoint']); |
|
170 | - $i++; |
|
171 | - } |
|
172 | - return null; |
|
173 | - } |
|
174 | - |
|
175 | - $mountPoint = Files::buildNotExistingFileName('/', $name); |
|
176 | - $mountPoint = Filesystem::normalizePath('/' . $mountPoint); |
|
177 | - $hash = md5($mountPoint); |
|
178 | - |
|
179 | - $query = $this->connection->prepare(' |
|
47 | + const STORAGE = '\OCA\Files_Sharing\External\Storage'; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + private $uid; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var IDBConnection |
|
56 | + */ |
|
57 | + private $connection; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var \OC\Files\Mount\Manager |
|
61 | + */ |
|
62 | + private $mountManager; |
|
63 | + |
|
64 | + /** |
|
65 | + * @var IStorageFactory |
|
66 | + */ |
|
67 | + private $storageLoader; |
|
68 | + |
|
69 | + /** |
|
70 | + * @var IClientService |
|
71 | + */ |
|
72 | + private $clientService; |
|
73 | + |
|
74 | + /** |
|
75 | + * @var IManager |
|
76 | + */ |
|
77 | + private $notificationManager; |
|
78 | + |
|
79 | + /** |
|
80 | + * @var IDiscoveryService |
|
81 | + */ |
|
82 | + private $discoveryService; |
|
83 | + |
|
84 | + /** @var ICloudFederationProviderManager */ |
|
85 | + private $cloudFederationProviderManager; |
|
86 | + |
|
87 | + /** @var ICloudFederationFactory */ |
|
88 | + private $cloudFederationFactory; |
|
89 | + |
|
90 | + /** |
|
91 | + * @param IDBConnection $connection |
|
92 | + * @param \OC\Files\Mount\Manager $mountManager |
|
93 | + * @param IStorageFactory $storageLoader |
|
94 | + * @param IClientService $clientService |
|
95 | + * @param IManager $notificationManager |
|
96 | + * @param IDiscoveryService $discoveryService |
|
97 | + * @param ICloudFederationProviderManager $cloudFederationProviderManager |
|
98 | + * @param ICloudFederationFactory $cloudFederationFactory |
|
99 | + * @param string $uid |
|
100 | + */ |
|
101 | + public function __construct(IDBConnection $connection, |
|
102 | + \OC\Files\Mount\Manager $mountManager, |
|
103 | + IStorageFactory $storageLoader, |
|
104 | + IClientService $clientService, |
|
105 | + IManager $notificationManager, |
|
106 | + IDiscoveryService $discoveryService, |
|
107 | + ICloudFederationProviderManager $cloudFederationProviderManager, |
|
108 | + ICloudFederationFactory $cloudFederationFactory, |
|
109 | + $uid) { |
|
110 | + $this->connection = $connection; |
|
111 | + $this->mountManager = $mountManager; |
|
112 | + $this->storageLoader = $storageLoader; |
|
113 | + $this->clientService = $clientService; |
|
114 | + $this->uid = $uid; |
|
115 | + $this->notificationManager = $notificationManager; |
|
116 | + $this->discoveryService = $discoveryService; |
|
117 | + $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
118 | + $this->cloudFederationFactory = $cloudFederationFactory; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * add new server-to-server share |
|
123 | + * |
|
124 | + * @param string $remote |
|
125 | + * @param string $token |
|
126 | + * @param string $password |
|
127 | + * @param string $name |
|
128 | + * @param string $owner |
|
129 | + * @param int $shareType |
|
130 | + * @param boolean $accepted |
|
131 | + * @param string $user |
|
132 | + * @param int $remoteId |
|
133 | + * @param int $parent |
|
134 | + * @return Mount|null |
|
135 | + * @throws \Doctrine\DBAL\DBALException |
|
136 | + */ |
|
137 | + public function addShare($remote, $token, $password, $name, $owner, $shareType, $accepted=false, $user = null, $remoteId = -1, $parent = -1) { |
|
138 | + |
|
139 | + $user = $user ? $user : $this->uid; |
|
140 | + $accepted = $accepted ? 1 : 0; |
|
141 | + $name = Filesystem::normalizePath('/' . $name); |
|
142 | + |
|
143 | + if (!$accepted) { |
|
144 | + // To avoid conflicts with the mount point generation later, |
|
145 | + // we only use a temporary mount point name here. The real |
|
146 | + // mount point name will be generated when accepting the share, |
|
147 | + // using the original share item name. |
|
148 | + $tmpMountPointName = '{{TemporaryMountPointName#' . $name . '}}'; |
|
149 | + $mountPoint = $tmpMountPointName; |
|
150 | + $hash = md5($tmpMountPointName); |
|
151 | + $data = [ |
|
152 | + 'remote' => $remote, |
|
153 | + 'share_token' => $token, |
|
154 | + 'password' => $password, |
|
155 | + 'name' => $name, |
|
156 | + 'owner' => $owner, |
|
157 | + 'user' => $user, |
|
158 | + 'mountpoint' => $mountPoint, |
|
159 | + 'mountpoint_hash' => $hash, |
|
160 | + 'accepted' => $accepted, |
|
161 | + 'remote_id' => $remoteId, |
|
162 | + 'share_type' => $shareType, |
|
163 | + ]; |
|
164 | + |
|
165 | + $i = 1; |
|
166 | + while (!$this->connection->insertIfNotExist('*PREFIX*share_external', $data, ['user', 'mountpoint_hash'])) { |
|
167 | + // The external share already exists for the user |
|
168 | + $data['mountpoint'] = $tmpMountPointName . '-' . $i; |
|
169 | + $data['mountpoint_hash'] = md5($data['mountpoint']); |
|
170 | + $i++; |
|
171 | + } |
|
172 | + return null; |
|
173 | + } |
|
174 | + |
|
175 | + $mountPoint = Files::buildNotExistingFileName('/', $name); |
|
176 | + $mountPoint = Filesystem::normalizePath('/' . $mountPoint); |
|
177 | + $hash = md5($mountPoint); |
|
178 | + |
|
179 | + $query = $this->connection->prepare(' |
|
180 | 180 | INSERT INTO `*PREFIX*share_external` |
181 | 181 | (`remote`, `share_token`, `password`, `name`, `owner`, `user`, `mountpoint`, `mountpoint_hash`, `accepted`, `remote_id`, `parent`, `share_type`) |
182 | 182 | VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) |
183 | 183 | '); |
184 | - $query->execute(array($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType)); |
|
185 | - |
|
186 | - $options = array( |
|
187 | - 'remote' => $remote, |
|
188 | - 'token' => $token, |
|
189 | - 'password' => $password, |
|
190 | - 'mountpoint' => $mountPoint, |
|
191 | - 'owner' => $owner |
|
192 | - ); |
|
193 | - return $this->mountShare($options); |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * get share |
|
198 | - * |
|
199 | - * @param int $id share id |
|
200 | - * @return mixed share of false |
|
201 | - */ |
|
202 | - public function getShare($id) { |
|
203 | - $getShare = $this->connection->prepare(' |
|
184 | + $query->execute(array($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType)); |
|
185 | + |
|
186 | + $options = array( |
|
187 | + 'remote' => $remote, |
|
188 | + 'token' => $token, |
|
189 | + 'password' => $password, |
|
190 | + 'mountpoint' => $mountPoint, |
|
191 | + 'owner' => $owner |
|
192 | + ); |
|
193 | + return $this->mountShare($options); |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * get share |
|
198 | + * |
|
199 | + * @param int $id share id |
|
200 | + * @return mixed share of false |
|
201 | + */ |
|
202 | + public function getShare($id) { |
|
203 | + $getShare = $this->connection->prepare(' |
|
204 | 204 | SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted` |
205 | 205 | FROM `*PREFIX*share_external` |
206 | 206 | WHERE `id` = ? AND `user` = ?'); |
207 | - $result = $getShare->execute(array($id, $this->uid)); |
|
208 | - |
|
209 | - return $result ? $getShare->fetch() : false; |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * accept server-to-server share |
|
214 | - * |
|
215 | - * @param int $id |
|
216 | - * @return bool True if the share could be accepted, false otherwise |
|
217 | - */ |
|
218 | - public function acceptShare($id) { |
|
219 | - |
|
220 | - $share = $this->getShare($id); |
|
221 | - $result = false; |
|
222 | - |
|
223 | - if ($share) { |
|
224 | - \OC_Util::setupFS($this->uid); |
|
225 | - $shareFolder = Helper::getShareFolder(); |
|
226 | - $mountPoint = Files::buildNotExistingFileName($shareFolder, $share['name']); |
|
227 | - $mountPoint = Filesystem::normalizePath($mountPoint); |
|
228 | - $hash = md5($mountPoint); |
|
229 | - |
|
230 | - if($share['share_type'] === \OCP\Share::SHARE_TYPE_USER) { |
|
231 | - $acceptShare = $this->connection->prepare(' |
|
207 | + $result = $getShare->execute(array($id, $this->uid)); |
|
208 | + |
|
209 | + return $result ? $getShare->fetch() : false; |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * accept server-to-server share |
|
214 | + * |
|
215 | + * @param int $id |
|
216 | + * @return bool True if the share could be accepted, false otherwise |
|
217 | + */ |
|
218 | + public function acceptShare($id) { |
|
219 | + |
|
220 | + $share = $this->getShare($id); |
|
221 | + $result = false; |
|
222 | + |
|
223 | + if ($share) { |
|
224 | + \OC_Util::setupFS($this->uid); |
|
225 | + $shareFolder = Helper::getShareFolder(); |
|
226 | + $mountPoint = Files::buildNotExistingFileName($shareFolder, $share['name']); |
|
227 | + $mountPoint = Filesystem::normalizePath($mountPoint); |
|
228 | + $hash = md5($mountPoint); |
|
229 | + |
|
230 | + if($share['share_type'] === \OCP\Share::SHARE_TYPE_USER) { |
|
231 | + $acceptShare = $this->connection->prepare(' |
|
232 | 232 | UPDATE `*PREFIX*share_external` |
233 | 233 | SET `accepted` = ?, |
234 | 234 | `mountpoint` = ?, |
235 | 235 | `mountpoint_hash` = ? |
236 | 236 | WHERE `id` = ? AND `user` = ?'); |
237 | - $updated = $acceptShare->execute(array(1, $mountPoint, $hash, $id, $this->uid)); |
|
238 | - } else { |
|
239 | - // TODO group share, add additional row for the user who accepted it |
|
240 | - } |
|
241 | - if ($updated === true) { |
|
242 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'accept'); |
|
243 | - \OC_Hook::emit(Share::class, 'federated_share_added', ['server' => $share['remote']]); |
|
244 | - $result = true; |
|
245 | - } |
|
246 | - } |
|
247 | - |
|
248 | - // Make sure the user has no notification for something that does not exist anymore. |
|
249 | - $this->processNotification($id); |
|
250 | - |
|
251 | - return $result; |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * decline server-to-server share |
|
256 | - * |
|
257 | - * @param int $id |
|
258 | - * @return bool True if the share could be declined, false otherwise |
|
259 | - */ |
|
260 | - public function declineShare($id) { |
|
261 | - |
|
262 | - $share = $this->getShare($id); |
|
263 | - |
|
264 | - if ($share) { |
|
265 | - $removeShare = $this->connection->prepare(' |
|
237 | + $updated = $acceptShare->execute(array(1, $mountPoint, $hash, $id, $this->uid)); |
|
238 | + } else { |
|
239 | + // TODO group share, add additional row for the user who accepted it |
|
240 | + } |
|
241 | + if ($updated === true) { |
|
242 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'accept'); |
|
243 | + \OC_Hook::emit(Share::class, 'federated_share_added', ['server' => $share['remote']]); |
|
244 | + $result = true; |
|
245 | + } |
|
246 | + } |
|
247 | + |
|
248 | + // Make sure the user has no notification for something that does not exist anymore. |
|
249 | + $this->processNotification($id); |
|
250 | + |
|
251 | + return $result; |
|
252 | + } |
|
253 | + |
|
254 | + /** |
|
255 | + * decline server-to-server share |
|
256 | + * |
|
257 | + * @param int $id |
|
258 | + * @return bool True if the share could be declined, false otherwise |
|
259 | + */ |
|
260 | + public function declineShare($id) { |
|
261 | + |
|
262 | + $share = $this->getShare($id); |
|
263 | + |
|
264 | + if ($share) { |
|
265 | + $removeShare = $this->connection->prepare(' |
|
266 | 266 | DELETE FROM `*PREFIX*share_external` WHERE `id` = ? AND `user` = ?'); |
267 | - $removeShare->execute(array($id, $this->uid)); |
|
268 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
269 | - |
|
270 | - $this->processNotification($id); |
|
271 | - return true; |
|
272 | - } |
|
273 | - |
|
274 | - return false; |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * @param int $remoteShare |
|
279 | - */ |
|
280 | - public function processNotification($remoteShare) { |
|
281 | - $filter = $this->notificationManager->createNotification(); |
|
282 | - $filter->setApp('files_sharing') |
|
283 | - ->setUser($this->uid) |
|
284 | - ->setObject('remote_share', (int) $remoteShare); |
|
285 | - $this->notificationManager->markProcessed($filter); |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * inform remote server whether server-to-server share was accepted/declined |
|
290 | - * |
|
291 | - * @param string $remote |
|
292 | - * @param string $token |
|
293 | - * @param int $remoteId Share id on the remote host |
|
294 | - * @param string $feedback |
|
295 | - * @return boolean |
|
296 | - */ |
|
297 | - private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) { |
|
298 | - |
|
299 | - $result = $this->tryOCMEndPoint($remote, $token, $remoteId, $feedback); |
|
300 | - |
|
301 | - if($result === true) { |
|
302 | - return true; |
|
303 | - } |
|
304 | - |
|
305 | - $federationEndpoints = $this->discoveryService->discover($remote, 'FEDERATED_SHARING'); |
|
306 | - $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
|
307 | - |
|
308 | - $url = rtrim($remote, '/') . $endpoint . '/' . $remoteId . '/' . $feedback . '?format=' . \OCP\Share::RESPONSE_FORMAT; |
|
309 | - $fields = array('token' => $token); |
|
310 | - |
|
311 | - $client = $this->clientService->newClient(); |
|
312 | - |
|
313 | - try { |
|
314 | - $response = $client->post( |
|
315 | - $url, |
|
316 | - [ |
|
317 | - 'body' => $fields, |
|
318 | - 'connect_timeout' => 10, |
|
319 | - ] |
|
320 | - ); |
|
321 | - } catch (\Exception $e) { |
|
322 | - return false; |
|
323 | - } |
|
324 | - |
|
325 | - $status = json_decode($response->getBody(), true); |
|
326 | - |
|
327 | - return ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); |
|
328 | - } |
|
329 | - |
|
330 | - /** |
|
331 | - * try send accept message to ocm end-point |
|
332 | - * |
|
333 | - * @param string $remoteDomain |
|
334 | - * @param string $token |
|
335 | - * @param $remoteId id of the share |
|
336 | - * @param string $feedback |
|
337 | - * @return bool |
|
338 | - */ |
|
339 | - protected function tryOCMEndPoint($remoteDomain, $token, $remoteId, $feedback) { |
|
340 | - switch ($feedback) { |
|
341 | - case 'accept': |
|
342 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
343 | - $notification->setMessage( |
|
344 | - 'SHARE_ACCEPTED', |
|
345 | - 'file', |
|
346 | - $remoteId, |
|
347 | - [ |
|
348 | - 'sharedSecret' => $token, |
|
349 | - 'message' => 'Recipient accept the share' |
|
350 | - ] |
|
351 | - |
|
352 | - ); |
|
353 | - return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
354 | - case 'decline': |
|
355 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
356 | - $notification->setMessage( |
|
357 | - 'SHARE_DECLINED', |
|
358 | - 'file', |
|
359 | - $remoteId, |
|
360 | - [ |
|
361 | - 'sharedSecret' => $token, |
|
362 | - 'message' => 'Recipient declined the share' |
|
363 | - ] |
|
364 | - |
|
365 | - ); |
|
366 | - return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
367 | - } |
|
368 | - |
|
369 | - return false; |
|
370 | - |
|
371 | - } |
|
372 | - |
|
373 | - |
|
374 | - /** |
|
375 | - * remove '/user/files' from the path and trailing slashes |
|
376 | - * |
|
377 | - * @param string $path |
|
378 | - * @return string |
|
379 | - */ |
|
380 | - protected function stripPath($path) { |
|
381 | - $prefix = '/' . $this->uid . '/files'; |
|
382 | - return rtrim(substr($path, strlen($prefix)), '/'); |
|
383 | - } |
|
384 | - |
|
385 | - public function getMount($data) { |
|
386 | - $data['manager'] = $this; |
|
387 | - $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; |
|
388 | - $data['mountpoint'] = $mountPoint; |
|
389 | - $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid); |
|
390 | - return new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader); |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * @param array $data |
|
395 | - * @return Mount |
|
396 | - */ |
|
397 | - protected function mountShare($data) { |
|
398 | - $mount = $this->getMount($data); |
|
399 | - $this->mountManager->addMount($mount); |
|
400 | - return $mount; |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * @return \OC\Files\Mount\Manager |
|
405 | - */ |
|
406 | - public function getMountManager() { |
|
407 | - return $this->mountManager; |
|
408 | - } |
|
409 | - |
|
410 | - /** |
|
411 | - * @param string $source |
|
412 | - * @param string $target |
|
413 | - * @return bool |
|
414 | - */ |
|
415 | - public function setMountPoint($source, $target) { |
|
416 | - $source = $this->stripPath($source); |
|
417 | - $target = $this->stripPath($target); |
|
418 | - $sourceHash = md5($source); |
|
419 | - $targetHash = md5($target); |
|
420 | - |
|
421 | - $query = $this->connection->prepare(' |
|
267 | + $removeShare->execute(array($id, $this->uid)); |
|
268 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
269 | + |
|
270 | + $this->processNotification($id); |
|
271 | + return true; |
|
272 | + } |
|
273 | + |
|
274 | + return false; |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * @param int $remoteShare |
|
279 | + */ |
|
280 | + public function processNotification($remoteShare) { |
|
281 | + $filter = $this->notificationManager->createNotification(); |
|
282 | + $filter->setApp('files_sharing') |
|
283 | + ->setUser($this->uid) |
|
284 | + ->setObject('remote_share', (int) $remoteShare); |
|
285 | + $this->notificationManager->markProcessed($filter); |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * inform remote server whether server-to-server share was accepted/declined |
|
290 | + * |
|
291 | + * @param string $remote |
|
292 | + * @param string $token |
|
293 | + * @param int $remoteId Share id on the remote host |
|
294 | + * @param string $feedback |
|
295 | + * @return boolean |
|
296 | + */ |
|
297 | + private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) { |
|
298 | + |
|
299 | + $result = $this->tryOCMEndPoint($remote, $token, $remoteId, $feedback); |
|
300 | + |
|
301 | + if($result === true) { |
|
302 | + return true; |
|
303 | + } |
|
304 | + |
|
305 | + $federationEndpoints = $this->discoveryService->discover($remote, 'FEDERATED_SHARING'); |
|
306 | + $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
|
307 | + |
|
308 | + $url = rtrim($remote, '/') . $endpoint . '/' . $remoteId . '/' . $feedback . '?format=' . \OCP\Share::RESPONSE_FORMAT; |
|
309 | + $fields = array('token' => $token); |
|
310 | + |
|
311 | + $client = $this->clientService->newClient(); |
|
312 | + |
|
313 | + try { |
|
314 | + $response = $client->post( |
|
315 | + $url, |
|
316 | + [ |
|
317 | + 'body' => $fields, |
|
318 | + 'connect_timeout' => 10, |
|
319 | + ] |
|
320 | + ); |
|
321 | + } catch (\Exception $e) { |
|
322 | + return false; |
|
323 | + } |
|
324 | + |
|
325 | + $status = json_decode($response->getBody(), true); |
|
326 | + |
|
327 | + return ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); |
|
328 | + } |
|
329 | + |
|
330 | + /** |
|
331 | + * try send accept message to ocm end-point |
|
332 | + * |
|
333 | + * @param string $remoteDomain |
|
334 | + * @param string $token |
|
335 | + * @param $remoteId id of the share |
|
336 | + * @param string $feedback |
|
337 | + * @return bool |
|
338 | + */ |
|
339 | + protected function tryOCMEndPoint($remoteDomain, $token, $remoteId, $feedback) { |
|
340 | + switch ($feedback) { |
|
341 | + case 'accept': |
|
342 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
343 | + $notification->setMessage( |
|
344 | + 'SHARE_ACCEPTED', |
|
345 | + 'file', |
|
346 | + $remoteId, |
|
347 | + [ |
|
348 | + 'sharedSecret' => $token, |
|
349 | + 'message' => 'Recipient accept the share' |
|
350 | + ] |
|
351 | + |
|
352 | + ); |
|
353 | + return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
354 | + case 'decline': |
|
355 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
356 | + $notification->setMessage( |
|
357 | + 'SHARE_DECLINED', |
|
358 | + 'file', |
|
359 | + $remoteId, |
|
360 | + [ |
|
361 | + 'sharedSecret' => $token, |
|
362 | + 'message' => 'Recipient declined the share' |
|
363 | + ] |
|
364 | + |
|
365 | + ); |
|
366 | + return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
367 | + } |
|
368 | + |
|
369 | + return false; |
|
370 | + |
|
371 | + } |
|
372 | + |
|
373 | + |
|
374 | + /** |
|
375 | + * remove '/user/files' from the path and trailing slashes |
|
376 | + * |
|
377 | + * @param string $path |
|
378 | + * @return string |
|
379 | + */ |
|
380 | + protected function stripPath($path) { |
|
381 | + $prefix = '/' . $this->uid . '/files'; |
|
382 | + return rtrim(substr($path, strlen($prefix)), '/'); |
|
383 | + } |
|
384 | + |
|
385 | + public function getMount($data) { |
|
386 | + $data['manager'] = $this; |
|
387 | + $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; |
|
388 | + $data['mountpoint'] = $mountPoint; |
|
389 | + $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid); |
|
390 | + return new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader); |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * @param array $data |
|
395 | + * @return Mount |
|
396 | + */ |
|
397 | + protected function mountShare($data) { |
|
398 | + $mount = $this->getMount($data); |
|
399 | + $this->mountManager->addMount($mount); |
|
400 | + return $mount; |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * @return \OC\Files\Mount\Manager |
|
405 | + */ |
|
406 | + public function getMountManager() { |
|
407 | + return $this->mountManager; |
|
408 | + } |
|
409 | + |
|
410 | + /** |
|
411 | + * @param string $source |
|
412 | + * @param string $target |
|
413 | + * @return bool |
|
414 | + */ |
|
415 | + public function setMountPoint($source, $target) { |
|
416 | + $source = $this->stripPath($source); |
|
417 | + $target = $this->stripPath($target); |
|
418 | + $sourceHash = md5($source); |
|
419 | + $targetHash = md5($target); |
|
420 | + |
|
421 | + $query = $this->connection->prepare(' |
|
422 | 422 | UPDATE `*PREFIX*share_external` |
423 | 423 | SET `mountpoint` = ?, `mountpoint_hash` = ? |
424 | 424 | WHERE `mountpoint_hash` = ? |
425 | 425 | AND `user` = ? |
426 | 426 | '); |
427 | - $result = (bool)$query->execute(array($target, $targetHash, $sourceHash, $this->uid)); |
|
427 | + $result = (bool)$query->execute(array($target, $targetHash, $sourceHash, $this->uid)); |
|
428 | 428 | |
429 | - return $result; |
|
430 | - } |
|
429 | + return $result; |
|
430 | + } |
|
431 | 431 | |
432 | - public function removeShare($mountPoint) { |
|
432 | + public function removeShare($mountPoint) { |
|
433 | 433 | |
434 | - $mountPointObj = $this->mountManager->find($mountPoint); |
|
435 | - $id = $mountPointObj->getStorage()->getCache()->getId(''); |
|
434 | + $mountPointObj = $this->mountManager->find($mountPoint); |
|
435 | + $id = $mountPointObj->getStorage()->getCache()->getId(''); |
|
436 | 436 | |
437 | - $mountPoint = $this->stripPath($mountPoint); |
|
438 | - $hash = md5($mountPoint); |
|
437 | + $mountPoint = $this->stripPath($mountPoint); |
|
438 | + $hash = md5($mountPoint); |
|
439 | 439 | |
440 | - $getShare = $this->connection->prepare(' |
|
440 | + $getShare = $this->connection->prepare(' |
|
441 | 441 | SELECT `remote`, `share_token`, `remote_id` |
442 | 442 | FROM `*PREFIX*share_external` |
443 | 443 | WHERE `mountpoint_hash` = ? AND `user` = ?'); |
444 | - $result = $getShare->execute(array($hash, $this->uid)); |
|
445 | - |
|
446 | - if ($result) { |
|
447 | - try { |
|
448 | - $share = $getShare->fetch(); |
|
449 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
450 | - } catch (\Exception $e) { |
|
451 | - // if we fail to notify the remote (probably cause the remote is down) |
|
452 | - // we still want the share to be gone to prevent undeletable remotes |
|
453 | - } |
|
454 | - } |
|
455 | - $getShare->closeCursor(); |
|
456 | - |
|
457 | - $query = $this->connection->prepare(' |
|
444 | + $result = $getShare->execute(array($hash, $this->uid)); |
|
445 | + |
|
446 | + if ($result) { |
|
447 | + try { |
|
448 | + $share = $getShare->fetch(); |
|
449 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
450 | + } catch (\Exception $e) { |
|
451 | + // if we fail to notify the remote (probably cause the remote is down) |
|
452 | + // we still want the share to be gone to prevent undeletable remotes |
|
453 | + } |
|
454 | + } |
|
455 | + $getShare->closeCursor(); |
|
456 | + |
|
457 | + $query = $this->connection->prepare(' |
|
458 | 458 | DELETE FROM `*PREFIX*share_external` |
459 | 459 | WHERE `mountpoint_hash` = ? |
460 | 460 | AND `user` = ? |
461 | 461 | '); |
462 | - $result = (bool)$query->execute(array($hash, $this->uid)); |
|
463 | - |
|
464 | - if($result) { |
|
465 | - $this->removeReShares($id); |
|
466 | - } |
|
467 | - |
|
468 | - return $result; |
|
469 | - } |
|
470 | - |
|
471 | - /** |
|
472 | - * remove re-shares from share table and mapping in the federated_reshares table |
|
473 | - * |
|
474 | - * @param $mountPointId |
|
475 | - */ |
|
476 | - protected function removeReShares($mountPointId) { |
|
477 | - $selectQuery = $this->connection->getQueryBuilder(); |
|
478 | - $query = $this->connection->getQueryBuilder(); |
|
479 | - $selectQuery->select('id')->from('share') |
|
480 | - ->where($selectQuery->expr()->eq('file_source', $query->createNamedParameter($mountPointId))); |
|
481 | - $select = $selectQuery->getSQL(); |
|
482 | - |
|
483 | - |
|
484 | - $query->delete('federated_reshares') |
|
485 | - ->where($query->expr()->in('share_id', $query->createFunction('(' . $select . ')'))); |
|
486 | - $query->execute(); |
|
487 | - |
|
488 | - $deleteReShares = $this->connection->getQueryBuilder(); |
|
489 | - $deleteReShares->delete('share') |
|
490 | - ->where($deleteReShares->expr()->eq('file_source', $deleteReShares->createNamedParameter($mountPointId))); |
|
491 | - $deleteReShares->execute(); |
|
492 | - } |
|
493 | - |
|
494 | - /** |
|
495 | - * remove all shares for user $uid if the user was deleted |
|
496 | - * |
|
497 | - * @param string $uid |
|
498 | - * @return bool |
|
499 | - */ |
|
500 | - public function removeUserShares($uid) { |
|
501 | - $getShare = $this->connection->prepare(' |
|
462 | + $result = (bool)$query->execute(array($hash, $this->uid)); |
|
463 | + |
|
464 | + if($result) { |
|
465 | + $this->removeReShares($id); |
|
466 | + } |
|
467 | + |
|
468 | + return $result; |
|
469 | + } |
|
470 | + |
|
471 | + /** |
|
472 | + * remove re-shares from share table and mapping in the federated_reshares table |
|
473 | + * |
|
474 | + * @param $mountPointId |
|
475 | + */ |
|
476 | + protected function removeReShares($mountPointId) { |
|
477 | + $selectQuery = $this->connection->getQueryBuilder(); |
|
478 | + $query = $this->connection->getQueryBuilder(); |
|
479 | + $selectQuery->select('id')->from('share') |
|
480 | + ->where($selectQuery->expr()->eq('file_source', $query->createNamedParameter($mountPointId))); |
|
481 | + $select = $selectQuery->getSQL(); |
|
482 | + |
|
483 | + |
|
484 | + $query->delete('federated_reshares') |
|
485 | + ->where($query->expr()->in('share_id', $query->createFunction('(' . $select . ')'))); |
|
486 | + $query->execute(); |
|
487 | + |
|
488 | + $deleteReShares = $this->connection->getQueryBuilder(); |
|
489 | + $deleteReShares->delete('share') |
|
490 | + ->where($deleteReShares->expr()->eq('file_source', $deleteReShares->createNamedParameter($mountPointId))); |
|
491 | + $deleteReShares->execute(); |
|
492 | + } |
|
493 | + |
|
494 | + /** |
|
495 | + * remove all shares for user $uid if the user was deleted |
|
496 | + * |
|
497 | + * @param string $uid |
|
498 | + * @return bool |
|
499 | + */ |
|
500 | + public function removeUserShares($uid) { |
|
501 | + $getShare = $this->connection->prepare(' |
|
502 | 502 | SELECT `remote`, `share_token`, `remote_id` |
503 | 503 | FROM `*PREFIX*share_external` |
504 | 504 | WHERE `user` = ?'); |
505 | - $result = $getShare->execute(array($uid)); |
|
505 | + $result = $getShare->execute(array($uid)); |
|
506 | 506 | |
507 | - if ($result) { |
|
508 | - $shares = $getShare->fetchAll(); |
|
509 | - foreach($shares as $share) { |
|
510 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
511 | - } |
|
512 | - } |
|
507 | + if ($result) { |
|
508 | + $shares = $getShare->fetchAll(); |
|
509 | + foreach($shares as $share) { |
|
510 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
511 | + } |
|
512 | + } |
|
513 | 513 | |
514 | - $query = $this->connection->prepare(' |
|
514 | + $query = $this->connection->prepare(' |
|
515 | 515 | DELETE FROM `*PREFIX*share_external` |
516 | 516 | WHERE `user` = ? |
517 | 517 | '); |
518 | - return (bool)$query->execute(array($uid)); |
|
519 | - } |
|
520 | - |
|
521 | - /** |
|
522 | - * return a list of shares which are not yet accepted by the user |
|
523 | - * |
|
524 | - * @return array list of open server-to-server shares |
|
525 | - */ |
|
526 | - public function getOpenShares() { |
|
527 | - return $this->getShares(false); |
|
528 | - } |
|
529 | - |
|
530 | - /** |
|
531 | - * return a list of shares which are accepted by the user |
|
532 | - * |
|
533 | - * @return array list of accepted server-to-server shares |
|
534 | - */ |
|
535 | - public function getAcceptedShares() { |
|
536 | - return $this->getShares(true); |
|
537 | - } |
|
538 | - |
|
539 | - /** |
|
540 | - * return a list of shares for the user |
|
541 | - * |
|
542 | - * @param bool|null $accepted True for accepted only, |
|
543 | - * false for not accepted, |
|
544 | - * null for all shares of the user |
|
545 | - * @return array list of open server-to-server shares |
|
546 | - */ |
|
547 | - private function getShares($accepted) { |
|
548 | - $query = 'SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted` |
|
518 | + return (bool)$query->execute(array($uid)); |
|
519 | + } |
|
520 | + |
|
521 | + /** |
|
522 | + * return a list of shares which are not yet accepted by the user |
|
523 | + * |
|
524 | + * @return array list of open server-to-server shares |
|
525 | + */ |
|
526 | + public function getOpenShares() { |
|
527 | + return $this->getShares(false); |
|
528 | + } |
|
529 | + |
|
530 | + /** |
|
531 | + * return a list of shares which are accepted by the user |
|
532 | + * |
|
533 | + * @return array list of accepted server-to-server shares |
|
534 | + */ |
|
535 | + public function getAcceptedShares() { |
|
536 | + return $this->getShares(true); |
|
537 | + } |
|
538 | + |
|
539 | + /** |
|
540 | + * return a list of shares for the user |
|
541 | + * |
|
542 | + * @param bool|null $accepted True for accepted only, |
|
543 | + * false for not accepted, |
|
544 | + * null for all shares of the user |
|
545 | + * @return array list of open server-to-server shares |
|
546 | + */ |
|
547 | + private function getShares($accepted) { |
|
548 | + $query = 'SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted` |
|
549 | 549 | FROM `*PREFIX*share_external` |
550 | 550 | WHERE `user` = ?'; |
551 | - $parameters = [$this->uid]; |
|
552 | - if (!is_null($accepted)) { |
|
553 | - $query .= ' AND `accepted` = ?'; |
|
554 | - $parameters[] = (int) $accepted; |
|
555 | - } |
|
556 | - $query .= ' ORDER BY `id` ASC'; |
|
557 | - |
|
558 | - $shares = $this->connection->prepare($query); |
|
559 | - $result = $shares->execute($parameters); |
|
560 | - |
|
561 | - return $result ? $shares->fetchAll() : []; |
|
562 | - } |
|
551 | + $parameters = [$this->uid]; |
|
552 | + if (!is_null($accepted)) { |
|
553 | + $query .= ' AND `accepted` = ?'; |
|
554 | + $parameters[] = (int) $accepted; |
|
555 | + } |
|
556 | + $query .= ' ORDER BY `id` ASC'; |
|
557 | + |
|
558 | + $shares = $this->connection->prepare($query); |
|
559 | + $result = $shares->execute($parameters); |
|
560 | + |
|
561 | + return $result ? $shares->fetchAll() : []; |
|
562 | + } |
|
563 | 563 | } |
@@ -134,18 +134,18 @@ discard block |
||
134 | 134 | * @return Mount|null |
135 | 135 | * @throws \Doctrine\DBAL\DBALException |
136 | 136 | */ |
137 | - public function addShare($remote, $token, $password, $name, $owner, $shareType, $accepted=false, $user = null, $remoteId = -1, $parent = -1) { |
|
137 | + public function addShare($remote, $token, $password, $name, $owner, $shareType, $accepted = false, $user = null, $remoteId = -1, $parent = -1) { |
|
138 | 138 | |
139 | 139 | $user = $user ? $user : $this->uid; |
140 | 140 | $accepted = $accepted ? 1 : 0; |
141 | - $name = Filesystem::normalizePath('/' . $name); |
|
141 | + $name = Filesystem::normalizePath('/'.$name); |
|
142 | 142 | |
143 | 143 | if (!$accepted) { |
144 | 144 | // To avoid conflicts with the mount point generation later, |
145 | 145 | // we only use a temporary mount point name here. The real |
146 | 146 | // mount point name will be generated when accepting the share, |
147 | 147 | // using the original share item name. |
148 | - $tmpMountPointName = '{{TemporaryMountPointName#' . $name . '}}'; |
|
148 | + $tmpMountPointName = '{{TemporaryMountPointName#'.$name.'}}'; |
|
149 | 149 | $mountPoint = $tmpMountPointName; |
150 | 150 | $hash = md5($tmpMountPointName); |
151 | 151 | $data = [ |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | $i = 1; |
166 | 166 | while (!$this->connection->insertIfNotExist('*PREFIX*share_external', $data, ['user', 'mountpoint_hash'])) { |
167 | 167 | // The external share already exists for the user |
168 | - $data['mountpoint'] = $tmpMountPointName . '-' . $i; |
|
168 | + $data['mountpoint'] = $tmpMountPointName.'-'.$i; |
|
169 | 169 | $data['mountpoint_hash'] = md5($data['mountpoint']); |
170 | 170 | $i++; |
171 | 171 | } |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | } |
174 | 174 | |
175 | 175 | $mountPoint = Files::buildNotExistingFileName('/', $name); |
176 | - $mountPoint = Filesystem::normalizePath('/' . $mountPoint); |
|
176 | + $mountPoint = Filesystem::normalizePath('/'.$mountPoint); |
|
177 | 177 | $hash = md5($mountPoint); |
178 | 178 | |
179 | 179 | $query = $this->connection->prepare(' |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | $mountPoint = Filesystem::normalizePath($mountPoint); |
228 | 228 | $hash = md5($mountPoint); |
229 | 229 | |
230 | - if($share['share_type'] === \OCP\Share::SHARE_TYPE_USER) { |
|
230 | + if ($share['share_type'] === \OCP\Share::SHARE_TYPE_USER) { |
|
231 | 231 | $acceptShare = $this->connection->prepare(' |
232 | 232 | UPDATE `*PREFIX*share_external` |
233 | 233 | SET `accepted` = ?, |
@@ -298,14 +298,14 @@ discard block |
||
298 | 298 | |
299 | 299 | $result = $this->tryOCMEndPoint($remote, $token, $remoteId, $feedback); |
300 | 300 | |
301 | - if($result === true) { |
|
301 | + if ($result === true) { |
|
302 | 302 | return true; |
303 | 303 | } |
304 | 304 | |
305 | 305 | $federationEndpoints = $this->discoveryService->discover($remote, 'FEDERATED_SHARING'); |
306 | 306 | $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
307 | 307 | |
308 | - $url = rtrim($remote, '/') . $endpoint . '/' . $remoteId . '/' . $feedback . '?format=' . \OCP\Share::RESPONSE_FORMAT; |
|
308 | + $url = rtrim($remote, '/').$endpoint.'/'.$remoteId.'/'.$feedback.'?format='.\OCP\Share::RESPONSE_FORMAT; |
|
309 | 309 | $fields = array('token' => $token); |
310 | 310 | |
311 | 311 | $client = $this->clientService->newClient(); |
@@ -378,13 +378,13 @@ discard block |
||
378 | 378 | * @return string |
379 | 379 | */ |
380 | 380 | protected function stripPath($path) { |
381 | - $prefix = '/' . $this->uid . '/files'; |
|
381 | + $prefix = '/'.$this->uid.'/files'; |
|
382 | 382 | return rtrim(substr($path, strlen($prefix)), '/'); |
383 | 383 | } |
384 | 384 | |
385 | 385 | public function getMount($data) { |
386 | 386 | $data['manager'] = $this; |
387 | - $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; |
|
387 | + $mountPoint = '/'.$this->uid.'/files'.$data['mountpoint']; |
|
388 | 388 | $data['mountpoint'] = $mountPoint; |
389 | 389 | $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid); |
390 | 390 | return new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader); |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | WHERE `mountpoint_hash` = ? |
425 | 425 | AND `user` = ? |
426 | 426 | '); |
427 | - $result = (bool)$query->execute(array($target, $targetHash, $sourceHash, $this->uid)); |
|
427 | + $result = (bool) $query->execute(array($target, $targetHash, $sourceHash, $this->uid)); |
|
428 | 428 | |
429 | 429 | return $result; |
430 | 430 | } |
@@ -459,9 +459,9 @@ discard block |
||
459 | 459 | WHERE `mountpoint_hash` = ? |
460 | 460 | AND `user` = ? |
461 | 461 | '); |
462 | - $result = (bool)$query->execute(array($hash, $this->uid)); |
|
462 | + $result = (bool) $query->execute(array($hash, $this->uid)); |
|
463 | 463 | |
464 | - if($result) { |
|
464 | + if ($result) { |
|
465 | 465 | $this->removeReShares($id); |
466 | 466 | } |
467 | 467 | |
@@ -482,7 +482,7 @@ discard block |
||
482 | 482 | |
483 | 483 | |
484 | 484 | $query->delete('federated_reshares') |
485 | - ->where($query->expr()->in('share_id', $query->createFunction('(' . $select . ')'))); |
|
485 | + ->where($query->expr()->in('share_id', $query->createFunction('('.$select.')'))); |
|
486 | 486 | $query->execute(); |
487 | 487 | |
488 | 488 | $deleteReShares = $this->connection->getQueryBuilder(); |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | |
507 | 507 | if ($result) { |
508 | 508 | $shares = $getShare->fetchAll(); |
509 | - foreach($shares as $share) { |
|
509 | + foreach ($shares as $share) { |
|
510 | 510 | $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
511 | 511 | } |
512 | 512 | } |
@@ -515,7 +515,7 @@ discard block |
||
515 | 515 | DELETE FROM `*PREFIX*share_external` |
516 | 516 | WHERE `user` = ? |
517 | 517 | '); |
518 | - return (bool)$query->execute(array($uid)); |
|
518 | + return (bool) $query->execute(array($uid)); |
|
519 | 519 | } |
520 | 520 | |
521 | 521 | /** |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | $ocsStatus = isset($status['ocs']); |
118 | 118 | $ocsSuccess = $ocsStatus && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); |
119 | 119 | |
120 | - if ($result['success'] && (!$ocsStatus ||$ocsSuccess)) { |
|
120 | + if ($result['success'] && (!$ocsStatus || $ocsSuccess)) { |
|
121 | 121 | \OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $remote]); |
122 | 122 | return true; |
123 | 123 | } |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | return [$ocmResult['token'], $ocmResult['providerId']]; |
161 | 161 | } |
162 | 162 | |
163 | - $result = $this->tryLegacyEndPoint(rtrim($remote, '/'), '/' . $id . '/reshare', $fields); |
|
163 | + $result = $this->tryLegacyEndPoint(rtrim($remote, '/'), '/'.$id.'/reshare', $fields); |
|
164 | 164 | $status = json_decode($result['result'], true); |
165 | 165 | |
166 | 166 | $httpRequestSuccessful = $result['success']; |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | if ($httpRequestSuccessful && $ocsCallSuccessful && $validToken && $validRemoteId) { |
172 | 172 | return [ |
173 | 173 | $status['ocs']['data']['token'], |
174 | - (int)$status['ocs']['data']['remoteId'] |
|
174 | + (int) $status['ocs']['data']['remoteId'] |
|
175 | 175 | ]; |
176 | 176 | } |
177 | 177 | |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | $fields[$key] = $value; |
259 | 259 | } |
260 | 260 | |
261 | - $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $remoteId . '/' . $action, $fields, $action); |
|
261 | + $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/'.$remoteId.'/'.$action, $fields, $action); |
|
262 | 262 | $status = json_decode($result['result'], true); |
263 | 263 | |
264 | 264 | if ($result['success'] && |
@@ -306,10 +306,10 @@ discard block |
||
306 | 306 | * @return array |
307 | 307 | * @throws \Exception |
308 | 308 | */ |
309 | - protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields, $action="share") { |
|
309 | + protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields, $action = "share") { |
|
310 | 310 | |
311 | 311 | if ($this->addressHandler->urlContainProtocol($remoteDomain) === false) { |
312 | - $remoteDomain = 'https://' . $remoteDomain; |
|
312 | + $remoteDomain = 'https://'.$remoteDomain; |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | $result = [ |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | $federationEndpoints = $this->discoveryService->discover($remoteDomain, 'FEDERATED_SHARING'); |
349 | 349 | $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
350 | 350 | try { |
351 | - $response = $client->post($remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, [ |
|
351 | + $response = $client->post($remoteDomain.$endpoint.$urlSuffix.'?format='.self::RESPONSE_FORMAT, [ |
|
352 | 352 | 'body' => $fields, |
353 | 353 | 'timeout' => 10, |
354 | 354 | 'connect_timeout' => 10, |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | switch ($action) { |
406 | 406 | case 'share': |
407 | 407 | $share = $this->cloudFederationFactory->getCloudFederationShare( |
408 | - $fields['shareWith'] . '@' . $remoteDomain, |
|
408 | + $fields['shareWith'].'@'.$remoteDomain, |
|
409 | 409 | $fields['name'], |
410 | 410 | '', |
411 | 411 | $fields['remoteId'], |
@@ -33,437 +33,437 @@ |
||
33 | 33 | use OCP\OCS\IDiscoveryService; |
34 | 34 | |
35 | 35 | class Notifications { |
36 | - const RESPONSE_FORMAT = 'json'; // default response format for ocs calls |
|
37 | - |
|
38 | - /** @var AddressHandler */ |
|
39 | - private $addressHandler; |
|
40 | - |
|
41 | - /** @var IClientService */ |
|
42 | - private $httpClientService; |
|
43 | - |
|
44 | - /** @var IDiscoveryService */ |
|
45 | - private $discoveryService; |
|
46 | - |
|
47 | - /** @var IJobList */ |
|
48 | - private $jobList; |
|
49 | - |
|
50 | - /** @var ICloudFederationProviderManager */ |
|
51 | - private $federationProviderManager; |
|
52 | - |
|
53 | - /** @var ICloudFederationFactory */ |
|
54 | - private $cloudFederationFactory; |
|
55 | - |
|
56 | - /** |
|
57 | - * @param AddressHandler $addressHandler |
|
58 | - * @param IClientService $httpClientService |
|
59 | - * @param IDiscoveryService $discoveryService |
|
60 | - * @param IJobList $jobList |
|
61 | - * @param ICloudFederationProviderManager $federationProviderManager |
|
62 | - * @param ICloudFederationFactory $cloudFederationFactory |
|
63 | - */ |
|
64 | - public function __construct( |
|
65 | - AddressHandler $addressHandler, |
|
66 | - IClientService $httpClientService, |
|
67 | - IDiscoveryService $discoveryService, |
|
68 | - IJobList $jobList, |
|
69 | - ICloudFederationProviderManager $federationProviderManager, |
|
70 | - ICloudFederationFactory $cloudFederationFactory |
|
71 | - ) { |
|
72 | - $this->addressHandler = $addressHandler; |
|
73 | - $this->httpClientService = $httpClientService; |
|
74 | - $this->discoveryService = $discoveryService; |
|
75 | - $this->jobList = $jobList; |
|
76 | - $this->federationProviderManager = $federationProviderManager; |
|
77 | - $this->cloudFederationFactory = $cloudFederationFactory; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * send server-to-server share to remote server |
|
82 | - * |
|
83 | - * @param string $token |
|
84 | - * @param string $shareWith |
|
85 | - * @param string $name |
|
86 | - * @param int $remote_id |
|
87 | - * @param string $owner |
|
88 | - * @param string $ownerFederatedId |
|
89 | - * @param string $sharedBy |
|
90 | - * @param string $sharedByFederatedId |
|
91 | - * @param int $shareType (can be a remote user or group share) |
|
92 | - * @return bool |
|
93 | - * @throws \OC\HintException |
|
94 | - * @throws \OC\ServerNotAvailableException |
|
95 | - */ |
|
96 | - public function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner, $ownerFederatedId, $sharedBy, $sharedByFederatedId, $shareType) { |
|
97 | - |
|
98 | - list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith); |
|
99 | - |
|
100 | - if ($user && $remote) { |
|
101 | - $local = $this->addressHandler->generateRemoteURL(); |
|
102 | - |
|
103 | - $fields = array( |
|
104 | - 'shareWith' => $user, |
|
105 | - 'token' => $token, |
|
106 | - 'name' => $name, |
|
107 | - 'remoteId' => $remote_id, |
|
108 | - 'owner' => $owner, |
|
109 | - 'ownerFederatedId' => $ownerFederatedId, |
|
110 | - 'sharedBy' => $sharedBy, |
|
111 | - 'sharedByFederatedId' => $sharedByFederatedId, |
|
112 | - 'remote' => $local, |
|
113 | - 'shareType' => $shareType |
|
114 | - ); |
|
115 | - |
|
116 | - $result = $this->tryHttpPostToShareEndpoint($remote, '', $fields); |
|
117 | - $status = json_decode($result['result'], true); |
|
118 | - |
|
119 | - $ocsStatus = isset($status['ocs']); |
|
120 | - $ocsSuccess = $ocsStatus && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); |
|
121 | - |
|
122 | - if ($result['success'] && (!$ocsStatus ||$ocsSuccess)) { |
|
123 | - \OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $remote]); |
|
124 | - return true; |
|
125 | - } |
|
126 | - |
|
127 | - } |
|
128 | - |
|
129 | - return false; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * ask owner to re-share the file with the given user |
|
134 | - * |
|
135 | - * @param string $token |
|
136 | - * @param int $id remote Id |
|
137 | - * @param int $shareId internal share Id |
|
138 | - * @param string $remote remote address of the owner |
|
139 | - * @param string $shareWith |
|
140 | - * @param int $permission |
|
141 | - * @param string $filename |
|
142 | - * @return bool |
|
143 | - * @throws \OC\HintException |
|
144 | - * @throws \OC\ServerNotAvailableException |
|
145 | - */ |
|
146 | - public function requestReShare($token, $id, $shareId, $remote, $shareWith, $permission, $filename) { |
|
147 | - |
|
148 | - $fields = array( |
|
149 | - 'shareWith' => $shareWith, |
|
150 | - 'token' => $token, |
|
151 | - 'permission' => $permission, |
|
152 | - 'remoteId' => $shareId, |
|
153 | - ); |
|
154 | - |
|
155 | - $ocmFields = $fields; |
|
156 | - $ocmFields['remoteId'] = $id; |
|
157 | - $ocmFields['localId'] = $shareId; |
|
158 | - $ocmFields['name'] = $filename; |
|
159 | - |
|
160 | - $ocmResult = $this->tryOCMEndPoint($remote, $ocmFields, 'reshare'); |
|
161 | - if (is_array($ocmResult) && isset($ocmResult['token']) && isset($ocmResult['providerId'])) { |
|
162 | - return [$ocmResult['token'], $ocmResult['providerId']]; |
|
163 | - } |
|
164 | - |
|
165 | - $result = $this->tryLegacyEndPoint(rtrim($remote, '/'), '/' . $id . '/reshare', $fields); |
|
166 | - $status = json_decode($result['result'], true); |
|
167 | - |
|
168 | - $httpRequestSuccessful = $result['success']; |
|
169 | - $ocsCallSuccessful = $status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200; |
|
170 | - $validToken = isset($status['ocs']['data']['token']) && is_string($status['ocs']['data']['token']); |
|
171 | - $validRemoteId = isset($status['ocs']['data']['remoteId']); |
|
172 | - |
|
173 | - if ($httpRequestSuccessful && $ocsCallSuccessful && $validToken && $validRemoteId) { |
|
174 | - return [ |
|
175 | - $status['ocs']['data']['token'], |
|
176 | - (int)$status['ocs']['data']['remoteId'] |
|
177 | - ]; |
|
178 | - } |
|
179 | - |
|
180 | - return false; |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * send server-to-server unshare to remote server |
|
185 | - * |
|
186 | - * @param string $remote url |
|
187 | - * @param int $id share id |
|
188 | - * @param string $token |
|
189 | - * @return bool |
|
190 | - */ |
|
191 | - public function sendRemoteUnShare($remote, $id, $token) { |
|
192 | - $this->sendUpdateToRemote($remote, $id, $token, 'unshare'); |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * send server-to-server unshare to remote server |
|
197 | - * |
|
198 | - * @param string $remote url |
|
199 | - * @param int $id share id |
|
200 | - * @param string $token |
|
201 | - * @return bool |
|
202 | - */ |
|
203 | - public function sendRevokeShare($remote, $id, $token) { |
|
204 | - $this->sendUpdateToRemote($remote, $id, $token, 'reshare_undo'); |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * send notification to remote server if the permissions was changed |
|
209 | - * |
|
210 | - * @param string $remote |
|
211 | - * @param int $remoteId |
|
212 | - * @param string $token |
|
213 | - * @param int $permissions |
|
214 | - * @return bool |
|
215 | - */ |
|
216 | - public function sendPermissionChange($remote, $remoteId, $token, $permissions) { |
|
217 | - $this->sendUpdateToRemote($remote, $remoteId, $token, 'permissions', ['permissions' => $permissions]); |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * forward accept reShare to remote server |
|
222 | - * |
|
223 | - * @param string $remote |
|
224 | - * @param int $remoteId |
|
225 | - * @param string $token |
|
226 | - */ |
|
227 | - public function sendAcceptShare($remote, $remoteId, $token) { |
|
228 | - $this->sendUpdateToRemote($remote, $remoteId, $token, 'accept'); |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * forward decline reShare to remote server |
|
233 | - * |
|
234 | - * @param string $remote |
|
235 | - * @param int $remoteId |
|
236 | - * @param string $token |
|
237 | - */ |
|
238 | - public function sendDeclineShare($remote, $remoteId, $token) { |
|
239 | - $this->sendUpdateToRemote($remote, $remoteId, $token, 'decline'); |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * inform remote server whether server-to-server share was accepted/declined |
|
244 | - * |
|
245 | - * @param string $remote |
|
246 | - * @param string $token |
|
247 | - * @param int $remoteId Share id on the remote host |
|
248 | - * @param string $action possible actions: accept, decline, unshare, revoke, permissions |
|
249 | - * @param array $data |
|
250 | - * @param int $try |
|
251 | - * @return boolean |
|
252 | - */ |
|
253 | - public function sendUpdateToRemote($remote, $remoteId, $token, $action, $data = [], $try = 0) { |
|
254 | - |
|
255 | - $fields = [ |
|
256 | - 'token' => $token, |
|
257 | - 'remoteId' => $remoteId |
|
258 | - ]; |
|
259 | - foreach ($data as $key => $value) { |
|
260 | - $fields[$key] = $value; |
|
261 | - } |
|
262 | - |
|
263 | - $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $remoteId . '/' . $action, $fields, $action); |
|
264 | - $status = json_decode($result['result'], true); |
|
265 | - |
|
266 | - if ($result['success'] && |
|
267 | - ($status['ocs']['meta']['statuscode'] === 100 || |
|
268 | - $status['ocs']['meta']['statuscode'] === 200 |
|
269 | - ) |
|
270 | - ) { |
|
271 | - return true; |
|
272 | - } elseif ($try === 0) { |
|
273 | - // only add new job on first try |
|
274 | - $this->jobList->add('OCA\FederatedFileSharing\BackgroundJob\RetryJob', |
|
275 | - [ |
|
276 | - 'remote' => $remote, |
|
277 | - 'remoteId' => $remoteId, |
|
278 | - 'token' => $token, |
|
279 | - 'action' => $action, |
|
280 | - 'data' => json_encode($data), |
|
281 | - 'try' => $try, |
|
282 | - 'lastRun' => $this->getTimestamp() |
|
283 | - ] |
|
284 | - ); |
|
285 | - } |
|
286 | - |
|
287 | - return false; |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - /** |
|
292 | - * return current timestamp |
|
293 | - * |
|
294 | - * @return int |
|
295 | - */ |
|
296 | - protected function getTimestamp() { |
|
297 | - return time(); |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * try http post with the given protocol, if no protocol is given we pick |
|
302 | - * the secure one (https) |
|
303 | - * |
|
304 | - * @param string $remoteDomain |
|
305 | - * @param string $urlSuffix |
|
306 | - * @param array $fields post parameters |
|
307 | - * @param string $action define the action (possible values: share, reshare, accept, decline, unshare, revoke, permissions) |
|
308 | - * @return array |
|
309 | - * @throws \Exception |
|
310 | - */ |
|
311 | - protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields, $action="share") { |
|
312 | - |
|
313 | - if ($this->addressHandler->urlContainProtocol($remoteDomain) === false) { |
|
314 | - $remoteDomain = 'https://' . $remoteDomain; |
|
315 | - } |
|
316 | - |
|
317 | - $result = [ |
|
318 | - 'success' => false, |
|
319 | - 'result' => '', |
|
320 | - ]; |
|
321 | - |
|
322 | - // if possible we use the new OCM API |
|
323 | - $ocmResult = $this->tryOCMEndPoint($remoteDomain, $fields, $action); |
|
324 | - if (is_array($ocmResult)) { |
|
325 | - $result['success'] = true; |
|
326 | - $result['result'] = json_encode([ |
|
327 | - 'ocs' => ['meta' => ['statuscode' => 200]]]); |
|
328 | - return $result; |
|
329 | - } |
|
330 | - |
|
331 | - return $this->tryLegacyEndPoint($remoteDomain, $urlSuffix, $fields); |
|
332 | - } |
|
333 | - |
|
334 | - /** |
|
335 | - * try old federated sharing API if the OCM api doesn't work |
|
336 | - * |
|
337 | - * @param $remoteDomain |
|
338 | - * @param $urlSuffix |
|
339 | - * @param array $fields |
|
340 | - * @return mixed |
|
341 | - * @throws \Exception |
|
342 | - */ |
|
343 | - protected function tryLegacyEndPoint($remoteDomain, $urlSuffix, array $fields) { |
|
344 | - |
|
345 | - $result = [ |
|
346 | - 'success' => false, |
|
347 | - 'result' => '', |
|
348 | - ]; |
|
349 | - |
|
350 | - // Fall back to old API |
|
351 | - $client = $this->httpClientService->newClient(); |
|
352 | - $federationEndpoints = $this->discoveryService->discover($remoteDomain, 'FEDERATED_SHARING'); |
|
353 | - $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
|
354 | - try { |
|
355 | - $response = $client->post($remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, [ |
|
356 | - 'body' => $fields, |
|
357 | - 'timeout' => 10, |
|
358 | - 'connect_timeout' => 10, |
|
359 | - ]); |
|
360 | - $result['result'] = $response->getBody(); |
|
361 | - $result['success'] = true; |
|
362 | - } catch (\Exception $e) { |
|
363 | - // if flat re-sharing is not supported by the remote server |
|
364 | - // we re-throw the exception and fall back to the old behaviour. |
|
365 | - // (flat re-shares has been introduced in Nextcloud 9.1) |
|
366 | - if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) { |
|
367 | - throw $e; |
|
368 | - } |
|
369 | - } |
|
370 | - |
|
371 | - return $result; |
|
372 | - |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * check if server supports the new OCM api and ask for the correct end-point |
|
377 | - * |
|
378 | - * @param string $url |
|
379 | - * @return string |
|
380 | - */ |
|
381 | - protected function getOCMEndPoint($url) { |
|
382 | - $client = $this->httpClientService->newClient(); |
|
383 | - try { |
|
384 | - $response = $client->get($url, ['timeout' => 10, 'connect_timeout' => 10]); |
|
385 | - } catch (\Exception $e) { |
|
386 | - return ''; |
|
387 | - } |
|
388 | - |
|
389 | - $result = $response->getBody(); |
|
390 | - $result = json_decode($result, true); |
|
391 | - |
|
392 | - if (isset($result['end-point'])) { |
|
393 | - return $result['end-point']; |
|
394 | - } |
|
395 | - |
|
396 | - return ''; |
|
397 | - } |
|
398 | - |
|
399 | - /** |
|
400 | - * send action regarding federated sharing to the remote server using the OCM API |
|
401 | - * |
|
402 | - * @param $remoteDomain |
|
403 | - * @param $fields |
|
404 | - * @param $action |
|
405 | - * |
|
406 | - * @return bool |
|
407 | - */ |
|
408 | - protected function tryOCMEndPoint($remoteDomain, $fields, $action) { |
|
409 | - switch ($action) { |
|
410 | - case 'share': |
|
411 | - $share = $this->cloudFederationFactory->getCloudFederationShare( |
|
412 | - $fields['shareWith'] . '@' . $remoteDomain, |
|
413 | - $fields['name'], |
|
414 | - '', |
|
415 | - $fields['remoteId'], |
|
416 | - $fields['ownerFederatedId'], |
|
417 | - $fields['owner'], |
|
418 | - $fields['sharedByFederatedId'], |
|
419 | - $fields['sharedBy'], |
|
420 | - $fields['token'], |
|
421 | - $fields['shareType'], |
|
422 | - 'file' |
|
423 | - ); |
|
424 | - return $this->federationProviderManager->sendShare($share); |
|
425 | - case 'reshare': |
|
426 | - // ask owner to reshare a file |
|
427 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
428 | - $notification->setMessage('REQUEST_RESHARE', |
|
429 | - 'file', |
|
430 | - $fields['remoteId'], |
|
431 | - [ |
|
432 | - 'sharedSecret' => $fields['token'], |
|
433 | - 'shareWith' => $fields['shareWith'], |
|
434 | - 'senderId' => $fields['localId'], |
|
435 | - 'shareType' => $fields['shareType'], |
|
436 | - 'message' => 'Ask owner to reshare the file' |
|
437 | - ] |
|
438 | - ); |
|
439 | - return $this->federationProviderManager->sendNotification($remoteDomain, $notification); |
|
440 | - case 'unshare': |
|
441 | - //owner unshares the file from the recipient again |
|
442 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
443 | - $notification->setMessage('SHARE_UNSHARED', |
|
444 | - 'file', |
|
445 | - $fields['remoteId'], |
|
446 | - [ |
|
447 | - 'sharedSecret' => $fields['token'], |
|
448 | - 'messgage' => 'file is no longer shared with you' |
|
449 | - ] |
|
450 | - ); |
|
451 | - return $this->federationProviderManager->sendNotification($remoteDomain, $notification); |
|
452 | - case 'reshare_undo': |
|
453 | - // if a reshare was unshared we send the information to the initiator/owner |
|
454 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
455 | - $notification->setMessage('RESHARE_UNDO', |
|
456 | - 'file', |
|
457 | - $fields['remoteId'], |
|
458 | - [ |
|
459 | - 'sharedSecret' => $fields['token'], |
|
460 | - 'message' => 'reshare was revoked' |
|
461 | - ] |
|
462 | - ); |
|
463 | - return $this->federationProviderManager->sendNotification($remoteDomain, $notification); |
|
464 | - } |
|
465 | - |
|
466 | - return false; |
|
467 | - |
|
468 | - } |
|
36 | + const RESPONSE_FORMAT = 'json'; // default response format for ocs calls |
|
37 | + |
|
38 | + /** @var AddressHandler */ |
|
39 | + private $addressHandler; |
|
40 | + |
|
41 | + /** @var IClientService */ |
|
42 | + private $httpClientService; |
|
43 | + |
|
44 | + /** @var IDiscoveryService */ |
|
45 | + private $discoveryService; |
|
46 | + |
|
47 | + /** @var IJobList */ |
|
48 | + private $jobList; |
|
49 | + |
|
50 | + /** @var ICloudFederationProviderManager */ |
|
51 | + private $federationProviderManager; |
|
52 | + |
|
53 | + /** @var ICloudFederationFactory */ |
|
54 | + private $cloudFederationFactory; |
|
55 | + |
|
56 | + /** |
|
57 | + * @param AddressHandler $addressHandler |
|
58 | + * @param IClientService $httpClientService |
|
59 | + * @param IDiscoveryService $discoveryService |
|
60 | + * @param IJobList $jobList |
|
61 | + * @param ICloudFederationProviderManager $federationProviderManager |
|
62 | + * @param ICloudFederationFactory $cloudFederationFactory |
|
63 | + */ |
|
64 | + public function __construct( |
|
65 | + AddressHandler $addressHandler, |
|
66 | + IClientService $httpClientService, |
|
67 | + IDiscoveryService $discoveryService, |
|
68 | + IJobList $jobList, |
|
69 | + ICloudFederationProviderManager $federationProviderManager, |
|
70 | + ICloudFederationFactory $cloudFederationFactory |
|
71 | + ) { |
|
72 | + $this->addressHandler = $addressHandler; |
|
73 | + $this->httpClientService = $httpClientService; |
|
74 | + $this->discoveryService = $discoveryService; |
|
75 | + $this->jobList = $jobList; |
|
76 | + $this->federationProviderManager = $federationProviderManager; |
|
77 | + $this->cloudFederationFactory = $cloudFederationFactory; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * send server-to-server share to remote server |
|
82 | + * |
|
83 | + * @param string $token |
|
84 | + * @param string $shareWith |
|
85 | + * @param string $name |
|
86 | + * @param int $remote_id |
|
87 | + * @param string $owner |
|
88 | + * @param string $ownerFederatedId |
|
89 | + * @param string $sharedBy |
|
90 | + * @param string $sharedByFederatedId |
|
91 | + * @param int $shareType (can be a remote user or group share) |
|
92 | + * @return bool |
|
93 | + * @throws \OC\HintException |
|
94 | + * @throws \OC\ServerNotAvailableException |
|
95 | + */ |
|
96 | + public function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner, $ownerFederatedId, $sharedBy, $sharedByFederatedId, $shareType) { |
|
97 | + |
|
98 | + list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith); |
|
99 | + |
|
100 | + if ($user && $remote) { |
|
101 | + $local = $this->addressHandler->generateRemoteURL(); |
|
102 | + |
|
103 | + $fields = array( |
|
104 | + 'shareWith' => $user, |
|
105 | + 'token' => $token, |
|
106 | + 'name' => $name, |
|
107 | + 'remoteId' => $remote_id, |
|
108 | + 'owner' => $owner, |
|
109 | + 'ownerFederatedId' => $ownerFederatedId, |
|
110 | + 'sharedBy' => $sharedBy, |
|
111 | + 'sharedByFederatedId' => $sharedByFederatedId, |
|
112 | + 'remote' => $local, |
|
113 | + 'shareType' => $shareType |
|
114 | + ); |
|
115 | + |
|
116 | + $result = $this->tryHttpPostToShareEndpoint($remote, '', $fields); |
|
117 | + $status = json_decode($result['result'], true); |
|
118 | + |
|
119 | + $ocsStatus = isset($status['ocs']); |
|
120 | + $ocsSuccess = $ocsStatus && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); |
|
121 | + |
|
122 | + if ($result['success'] && (!$ocsStatus ||$ocsSuccess)) { |
|
123 | + \OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $remote]); |
|
124 | + return true; |
|
125 | + } |
|
126 | + |
|
127 | + } |
|
128 | + |
|
129 | + return false; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * ask owner to re-share the file with the given user |
|
134 | + * |
|
135 | + * @param string $token |
|
136 | + * @param int $id remote Id |
|
137 | + * @param int $shareId internal share Id |
|
138 | + * @param string $remote remote address of the owner |
|
139 | + * @param string $shareWith |
|
140 | + * @param int $permission |
|
141 | + * @param string $filename |
|
142 | + * @return bool |
|
143 | + * @throws \OC\HintException |
|
144 | + * @throws \OC\ServerNotAvailableException |
|
145 | + */ |
|
146 | + public function requestReShare($token, $id, $shareId, $remote, $shareWith, $permission, $filename) { |
|
147 | + |
|
148 | + $fields = array( |
|
149 | + 'shareWith' => $shareWith, |
|
150 | + 'token' => $token, |
|
151 | + 'permission' => $permission, |
|
152 | + 'remoteId' => $shareId, |
|
153 | + ); |
|
154 | + |
|
155 | + $ocmFields = $fields; |
|
156 | + $ocmFields['remoteId'] = $id; |
|
157 | + $ocmFields['localId'] = $shareId; |
|
158 | + $ocmFields['name'] = $filename; |
|
159 | + |
|
160 | + $ocmResult = $this->tryOCMEndPoint($remote, $ocmFields, 'reshare'); |
|
161 | + if (is_array($ocmResult) && isset($ocmResult['token']) && isset($ocmResult['providerId'])) { |
|
162 | + return [$ocmResult['token'], $ocmResult['providerId']]; |
|
163 | + } |
|
164 | + |
|
165 | + $result = $this->tryLegacyEndPoint(rtrim($remote, '/'), '/' . $id . '/reshare', $fields); |
|
166 | + $status = json_decode($result['result'], true); |
|
167 | + |
|
168 | + $httpRequestSuccessful = $result['success']; |
|
169 | + $ocsCallSuccessful = $status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200; |
|
170 | + $validToken = isset($status['ocs']['data']['token']) && is_string($status['ocs']['data']['token']); |
|
171 | + $validRemoteId = isset($status['ocs']['data']['remoteId']); |
|
172 | + |
|
173 | + if ($httpRequestSuccessful && $ocsCallSuccessful && $validToken && $validRemoteId) { |
|
174 | + return [ |
|
175 | + $status['ocs']['data']['token'], |
|
176 | + (int)$status['ocs']['data']['remoteId'] |
|
177 | + ]; |
|
178 | + } |
|
179 | + |
|
180 | + return false; |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * send server-to-server unshare to remote server |
|
185 | + * |
|
186 | + * @param string $remote url |
|
187 | + * @param int $id share id |
|
188 | + * @param string $token |
|
189 | + * @return bool |
|
190 | + */ |
|
191 | + public function sendRemoteUnShare($remote, $id, $token) { |
|
192 | + $this->sendUpdateToRemote($remote, $id, $token, 'unshare'); |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * send server-to-server unshare to remote server |
|
197 | + * |
|
198 | + * @param string $remote url |
|
199 | + * @param int $id share id |
|
200 | + * @param string $token |
|
201 | + * @return bool |
|
202 | + */ |
|
203 | + public function sendRevokeShare($remote, $id, $token) { |
|
204 | + $this->sendUpdateToRemote($remote, $id, $token, 'reshare_undo'); |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * send notification to remote server if the permissions was changed |
|
209 | + * |
|
210 | + * @param string $remote |
|
211 | + * @param int $remoteId |
|
212 | + * @param string $token |
|
213 | + * @param int $permissions |
|
214 | + * @return bool |
|
215 | + */ |
|
216 | + public function sendPermissionChange($remote, $remoteId, $token, $permissions) { |
|
217 | + $this->sendUpdateToRemote($remote, $remoteId, $token, 'permissions', ['permissions' => $permissions]); |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * forward accept reShare to remote server |
|
222 | + * |
|
223 | + * @param string $remote |
|
224 | + * @param int $remoteId |
|
225 | + * @param string $token |
|
226 | + */ |
|
227 | + public function sendAcceptShare($remote, $remoteId, $token) { |
|
228 | + $this->sendUpdateToRemote($remote, $remoteId, $token, 'accept'); |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * forward decline reShare to remote server |
|
233 | + * |
|
234 | + * @param string $remote |
|
235 | + * @param int $remoteId |
|
236 | + * @param string $token |
|
237 | + */ |
|
238 | + public function sendDeclineShare($remote, $remoteId, $token) { |
|
239 | + $this->sendUpdateToRemote($remote, $remoteId, $token, 'decline'); |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * inform remote server whether server-to-server share was accepted/declined |
|
244 | + * |
|
245 | + * @param string $remote |
|
246 | + * @param string $token |
|
247 | + * @param int $remoteId Share id on the remote host |
|
248 | + * @param string $action possible actions: accept, decline, unshare, revoke, permissions |
|
249 | + * @param array $data |
|
250 | + * @param int $try |
|
251 | + * @return boolean |
|
252 | + */ |
|
253 | + public function sendUpdateToRemote($remote, $remoteId, $token, $action, $data = [], $try = 0) { |
|
254 | + |
|
255 | + $fields = [ |
|
256 | + 'token' => $token, |
|
257 | + 'remoteId' => $remoteId |
|
258 | + ]; |
|
259 | + foreach ($data as $key => $value) { |
|
260 | + $fields[$key] = $value; |
|
261 | + } |
|
262 | + |
|
263 | + $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $remoteId . '/' . $action, $fields, $action); |
|
264 | + $status = json_decode($result['result'], true); |
|
265 | + |
|
266 | + if ($result['success'] && |
|
267 | + ($status['ocs']['meta']['statuscode'] === 100 || |
|
268 | + $status['ocs']['meta']['statuscode'] === 200 |
|
269 | + ) |
|
270 | + ) { |
|
271 | + return true; |
|
272 | + } elseif ($try === 0) { |
|
273 | + // only add new job on first try |
|
274 | + $this->jobList->add('OCA\FederatedFileSharing\BackgroundJob\RetryJob', |
|
275 | + [ |
|
276 | + 'remote' => $remote, |
|
277 | + 'remoteId' => $remoteId, |
|
278 | + 'token' => $token, |
|
279 | + 'action' => $action, |
|
280 | + 'data' => json_encode($data), |
|
281 | + 'try' => $try, |
|
282 | + 'lastRun' => $this->getTimestamp() |
|
283 | + ] |
|
284 | + ); |
|
285 | + } |
|
286 | + |
|
287 | + return false; |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + /** |
|
292 | + * return current timestamp |
|
293 | + * |
|
294 | + * @return int |
|
295 | + */ |
|
296 | + protected function getTimestamp() { |
|
297 | + return time(); |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * try http post with the given protocol, if no protocol is given we pick |
|
302 | + * the secure one (https) |
|
303 | + * |
|
304 | + * @param string $remoteDomain |
|
305 | + * @param string $urlSuffix |
|
306 | + * @param array $fields post parameters |
|
307 | + * @param string $action define the action (possible values: share, reshare, accept, decline, unshare, revoke, permissions) |
|
308 | + * @return array |
|
309 | + * @throws \Exception |
|
310 | + */ |
|
311 | + protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields, $action="share") { |
|
312 | + |
|
313 | + if ($this->addressHandler->urlContainProtocol($remoteDomain) === false) { |
|
314 | + $remoteDomain = 'https://' . $remoteDomain; |
|
315 | + } |
|
316 | + |
|
317 | + $result = [ |
|
318 | + 'success' => false, |
|
319 | + 'result' => '', |
|
320 | + ]; |
|
321 | + |
|
322 | + // if possible we use the new OCM API |
|
323 | + $ocmResult = $this->tryOCMEndPoint($remoteDomain, $fields, $action); |
|
324 | + if (is_array($ocmResult)) { |
|
325 | + $result['success'] = true; |
|
326 | + $result['result'] = json_encode([ |
|
327 | + 'ocs' => ['meta' => ['statuscode' => 200]]]); |
|
328 | + return $result; |
|
329 | + } |
|
330 | + |
|
331 | + return $this->tryLegacyEndPoint($remoteDomain, $urlSuffix, $fields); |
|
332 | + } |
|
333 | + |
|
334 | + /** |
|
335 | + * try old federated sharing API if the OCM api doesn't work |
|
336 | + * |
|
337 | + * @param $remoteDomain |
|
338 | + * @param $urlSuffix |
|
339 | + * @param array $fields |
|
340 | + * @return mixed |
|
341 | + * @throws \Exception |
|
342 | + */ |
|
343 | + protected function tryLegacyEndPoint($remoteDomain, $urlSuffix, array $fields) { |
|
344 | + |
|
345 | + $result = [ |
|
346 | + 'success' => false, |
|
347 | + 'result' => '', |
|
348 | + ]; |
|
349 | + |
|
350 | + // Fall back to old API |
|
351 | + $client = $this->httpClientService->newClient(); |
|
352 | + $federationEndpoints = $this->discoveryService->discover($remoteDomain, 'FEDERATED_SHARING'); |
|
353 | + $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
|
354 | + try { |
|
355 | + $response = $client->post($remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, [ |
|
356 | + 'body' => $fields, |
|
357 | + 'timeout' => 10, |
|
358 | + 'connect_timeout' => 10, |
|
359 | + ]); |
|
360 | + $result['result'] = $response->getBody(); |
|
361 | + $result['success'] = true; |
|
362 | + } catch (\Exception $e) { |
|
363 | + // if flat re-sharing is not supported by the remote server |
|
364 | + // we re-throw the exception and fall back to the old behaviour. |
|
365 | + // (flat re-shares has been introduced in Nextcloud 9.1) |
|
366 | + if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) { |
|
367 | + throw $e; |
|
368 | + } |
|
369 | + } |
|
370 | + |
|
371 | + return $result; |
|
372 | + |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * check if server supports the new OCM api and ask for the correct end-point |
|
377 | + * |
|
378 | + * @param string $url |
|
379 | + * @return string |
|
380 | + */ |
|
381 | + protected function getOCMEndPoint($url) { |
|
382 | + $client = $this->httpClientService->newClient(); |
|
383 | + try { |
|
384 | + $response = $client->get($url, ['timeout' => 10, 'connect_timeout' => 10]); |
|
385 | + } catch (\Exception $e) { |
|
386 | + return ''; |
|
387 | + } |
|
388 | + |
|
389 | + $result = $response->getBody(); |
|
390 | + $result = json_decode($result, true); |
|
391 | + |
|
392 | + if (isset($result['end-point'])) { |
|
393 | + return $result['end-point']; |
|
394 | + } |
|
395 | + |
|
396 | + return ''; |
|
397 | + } |
|
398 | + |
|
399 | + /** |
|
400 | + * send action regarding federated sharing to the remote server using the OCM API |
|
401 | + * |
|
402 | + * @param $remoteDomain |
|
403 | + * @param $fields |
|
404 | + * @param $action |
|
405 | + * |
|
406 | + * @return bool |
|
407 | + */ |
|
408 | + protected function tryOCMEndPoint($remoteDomain, $fields, $action) { |
|
409 | + switch ($action) { |
|
410 | + case 'share': |
|
411 | + $share = $this->cloudFederationFactory->getCloudFederationShare( |
|
412 | + $fields['shareWith'] . '@' . $remoteDomain, |
|
413 | + $fields['name'], |
|
414 | + '', |
|
415 | + $fields['remoteId'], |
|
416 | + $fields['ownerFederatedId'], |
|
417 | + $fields['owner'], |
|
418 | + $fields['sharedByFederatedId'], |
|
419 | + $fields['sharedBy'], |
|
420 | + $fields['token'], |
|
421 | + $fields['shareType'], |
|
422 | + 'file' |
|
423 | + ); |
|
424 | + return $this->federationProviderManager->sendShare($share); |
|
425 | + case 'reshare': |
|
426 | + // ask owner to reshare a file |
|
427 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
428 | + $notification->setMessage('REQUEST_RESHARE', |
|
429 | + 'file', |
|
430 | + $fields['remoteId'], |
|
431 | + [ |
|
432 | + 'sharedSecret' => $fields['token'], |
|
433 | + 'shareWith' => $fields['shareWith'], |
|
434 | + 'senderId' => $fields['localId'], |
|
435 | + 'shareType' => $fields['shareType'], |
|
436 | + 'message' => 'Ask owner to reshare the file' |
|
437 | + ] |
|
438 | + ); |
|
439 | + return $this->federationProviderManager->sendNotification($remoteDomain, $notification); |
|
440 | + case 'unshare': |
|
441 | + //owner unshares the file from the recipient again |
|
442 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
443 | + $notification->setMessage('SHARE_UNSHARED', |
|
444 | + 'file', |
|
445 | + $fields['remoteId'], |
|
446 | + [ |
|
447 | + 'sharedSecret' => $fields['token'], |
|
448 | + 'messgage' => 'file is no longer shared with you' |
|
449 | + ] |
|
450 | + ); |
|
451 | + return $this->federationProviderManager->sendNotification($remoteDomain, $notification); |
|
452 | + case 'reshare_undo': |
|
453 | + // if a reshare was unshared we send the information to the initiator/owner |
|
454 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
455 | + $notification->setMessage('RESHARE_UNDO', |
|
456 | + 'file', |
|
457 | + $fields['remoteId'], |
|
458 | + [ |
|
459 | + 'sharedSecret' => $fields['token'], |
|
460 | + 'message' => 'reshare was revoked' |
|
461 | + ] |
|
462 | + ); |
|
463 | + return $this->federationProviderManager->sendNotification($remoteDomain, $notification); |
|
464 | + } |
|
465 | + |
|
466 | + return false; |
|
467 | + |
|
468 | + } |
|
469 | 469 | } |
@@ -39,114 +39,114 @@ |
||
39 | 39 | |
40 | 40 | class Application extends App { |
41 | 41 | |
42 | - /** @var FederatedShareProvider */ |
|
43 | - protected $federatedShareProvider; |
|
42 | + /** @var FederatedShareProvider */ |
|
43 | + protected $federatedShareProvider; |
|
44 | 44 | |
45 | - public function __construct() { |
|
46 | - parent::__construct('federatedfilesharing'); |
|
45 | + public function __construct() { |
|
46 | + parent::__construct('federatedfilesharing'); |
|
47 | 47 | |
48 | - $container = $this->getContainer(); |
|
49 | - $server = $container->getServer(); |
|
48 | + $container = $this->getContainer(); |
|
49 | + $server = $container->getServer(); |
|
50 | 50 | |
51 | - $cloudFederationManager = $server->getCloudFederationProviderManager(); |
|
52 | - $cloudFederationManager->addCloudFederationProvider('file', |
|
53 | - 'Federated Files Sharing', |
|
54 | - function() use ($container) { |
|
55 | - $server = $container->getServer(); |
|
56 | - return new CloudFederationProviderFiles( |
|
57 | - $server->getAppManager(), |
|
58 | - $server->query(FederatedShareProvider::class), |
|
59 | - $server->query(AddressHandler::class), |
|
60 | - $server->getLogger(), |
|
61 | - $server->getUserManager(), |
|
62 | - $server->getCloudIdManager(), |
|
63 | - $server->getActivityManager(), |
|
64 | - $server->getNotificationManager(), |
|
65 | - $server->getURLGenerator(), |
|
66 | - $server->getCloudFederationFactory(), |
|
67 | - $server->getCloudFederationProviderManager(), |
|
68 | - $server->getDatabaseConnection() |
|
69 | - ); |
|
70 | - }); |
|
51 | + $cloudFederationManager = $server->getCloudFederationProviderManager(); |
|
52 | + $cloudFederationManager->addCloudFederationProvider('file', |
|
53 | + 'Federated Files Sharing', |
|
54 | + function() use ($container) { |
|
55 | + $server = $container->getServer(); |
|
56 | + return new CloudFederationProviderFiles( |
|
57 | + $server->getAppManager(), |
|
58 | + $server->query(FederatedShareProvider::class), |
|
59 | + $server->query(AddressHandler::class), |
|
60 | + $server->getLogger(), |
|
61 | + $server->getUserManager(), |
|
62 | + $server->getCloudIdManager(), |
|
63 | + $server->getActivityManager(), |
|
64 | + $server->getNotificationManager(), |
|
65 | + $server->getURLGenerator(), |
|
66 | + $server->getCloudFederationFactory(), |
|
67 | + $server->getCloudFederationProviderManager(), |
|
68 | + $server->getDatabaseConnection() |
|
69 | + ); |
|
70 | + }); |
|
71 | 71 | |
72 | - $container->registerService('RequestHandlerController', function(SimpleContainer $c) use ($server) { |
|
73 | - $addressHandler = new AddressHandler( |
|
74 | - $server->getURLGenerator(), |
|
75 | - $server->getL10N('federatedfilesharing'), |
|
76 | - $server->getCloudIdManager() |
|
77 | - ); |
|
78 | - $notification = new Notifications( |
|
79 | - $addressHandler, |
|
80 | - $server->getHTTPClientService(), |
|
81 | - $server->query(\OCP\OCS\IDiscoveryService::class), |
|
82 | - \OC::$server->getJobList(), |
|
83 | - \OC::$server->getCloudFederationProviderManager(), |
|
84 | - \OC::$server->getCloudFederationFactory() |
|
85 | - ); |
|
86 | - return new RequestHandlerController( |
|
87 | - $c->query('AppName'), |
|
88 | - $server->getRequest(), |
|
89 | - $this->getFederatedShareProvider(), |
|
90 | - $server->getDatabaseConnection(), |
|
91 | - $server->getShareManager(), |
|
92 | - $notification, |
|
93 | - $addressHandler, |
|
94 | - $server->getUserManager(), |
|
95 | - $server->getCloudIdManager(), |
|
96 | - $server->getLogger(), |
|
97 | - $server->getCloudFederationFactory(), |
|
98 | - $server->getCloudFederationProviderManager() |
|
99 | - ); |
|
100 | - }); |
|
101 | - } |
|
72 | + $container->registerService('RequestHandlerController', function(SimpleContainer $c) use ($server) { |
|
73 | + $addressHandler = new AddressHandler( |
|
74 | + $server->getURLGenerator(), |
|
75 | + $server->getL10N('federatedfilesharing'), |
|
76 | + $server->getCloudIdManager() |
|
77 | + ); |
|
78 | + $notification = new Notifications( |
|
79 | + $addressHandler, |
|
80 | + $server->getHTTPClientService(), |
|
81 | + $server->query(\OCP\OCS\IDiscoveryService::class), |
|
82 | + \OC::$server->getJobList(), |
|
83 | + \OC::$server->getCloudFederationProviderManager(), |
|
84 | + \OC::$server->getCloudFederationFactory() |
|
85 | + ); |
|
86 | + return new RequestHandlerController( |
|
87 | + $c->query('AppName'), |
|
88 | + $server->getRequest(), |
|
89 | + $this->getFederatedShareProvider(), |
|
90 | + $server->getDatabaseConnection(), |
|
91 | + $server->getShareManager(), |
|
92 | + $notification, |
|
93 | + $addressHandler, |
|
94 | + $server->getUserManager(), |
|
95 | + $server->getCloudIdManager(), |
|
96 | + $server->getLogger(), |
|
97 | + $server->getCloudFederationFactory(), |
|
98 | + $server->getCloudFederationProviderManager() |
|
99 | + ); |
|
100 | + }); |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * get instance of federated share provider |
|
105 | - * |
|
106 | - * @return FederatedShareProvider |
|
107 | - */ |
|
108 | - public function getFederatedShareProvider() { |
|
109 | - if ($this->federatedShareProvider === null) { |
|
110 | - $this->initFederatedShareProvider(); |
|
111 | - } |
|
112 | - return $this->federatedShareProvider; |
|
113 | - } |
|
103 | + /** |
|
104 | + * get instance of federated share provider |
|
105 | + * |
|
106 | + * @return FederatedShareProvider |
|
107 | + */ |
|
108 | + public function getFederatedShareProvider() { |
|
109 | + if ($this->federatedShareProvider === null) { |
|
110 | + $this->initFederatedShareProvider(); |
|
111 | + } |
|
112 | + return $this->federatedShareProvider; |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * initialize federated share provider |
|
117 | - */ |
|
118 | - protected function initFederatedShareProvider() { |
|
119 | - $c = $this->getContainer(); |
|
120 | - $addressHandler = new \OCA\FederatedFileSharing\AddressHandler( |
|
121 | - \OC::$server->getURLGenerator(), |
|
122 | - \OC::$server->getL10N('federatedfilesharing'), |
|
123 | - \OC::$server->getCloudIdManager() |
|
124 | - ); |
|
125 | - $notifications = new \OCA\FederatedFileSharing\Notifications( |
|
126 | - $addressHandler, |
|
127 | - \OC::$server->getHTTPClientService(), |
|
128 | - \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
129 | - \OC::$server->getJobList(), |
|
130 | - \OC::$server->getCloudFederationProviderManager(), |
|
131 | - \OC::$server->getCloudFederationFactory() |
|
132 | - ); |
|
133 | - $tokenHandler = new \OCA\FederatedFileSharing\TokenHandler( |
|
134 | - \OC::$server->getSecureRandom() |
|
135 | - ); |
|
115 | + /** |
|
116 | + * initialize federated share provider |
|
117 | + */ |
|
118 | + protected function initFederatedShareProvider() { |
|
119 | + $c = $this->getContainer(); |
|
120 | + $addressHandler = new \OCA\FederatedFileSharing\AddressHandler( |
|
121 | + \OC::$server->getURLGenerator(), |
|
122 | + \OC::$server->getL10N('federatedfilesharing'), |
|
123 | + \OC::$server->getCloudIdManager() |
|
124 | + ); |
|
125 | + $notifications = new \OCA\FederatedFileSharing\Notifications( |
|
126 | + $addressHandler, |
|
127 | + \OC::$server->getHTTPClientService(), |
|
128 | + \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
129 | + \OC::$server->getJobList(), |
|
130 | + \OC::$server->getCloudFederationProviderManager(), |
|
131 | + \OC::$server->getCloudFederationFactory() |
|
132 | + ); |
|
133 | + $tokenHandler = new \OCA\FederatedFileSharing\TokenHandler( |
|
134 | + \OC::$server->getSecureRandom() |
|
135 | + ); |
|
136 | 136 | |
137 | - $this->federatedShareProvider = new \OCA\FederatedFileSharing\FederatedShareProvider( |
|
138 | - \OC::$server->getDatabaseConnection(), |
|
139 | - $addressHandler, |
|
140 | - $notifications, |
|
141 | - $tokenHandler, |
|
142 | - \OC::$server->getL10N('federatedfilesharing'), |
|
143 | - \OC::$server->getLogger(), |
|
144 | - \OC::$server->getLazyRootFolder(), |
|
145 | - \OC::$server->getConfig(), |
|
146 | - \OC::$server->getUserManager(), |
|
147 | - \OC::$server->getCloudIdManager(), |
|
148 | - $c->query(IConfig::class) |
|
149 | - ); |
|
150 | - } |
|
137 | + $this->federatedShareProvider = new \OCA\FederatedFileSharing\FederatedShareProvider( |
|
138 | + \OC::$server->getDatabaseConnection(), |
|
139 | + $addressHandler, |
|
140 | + $notifications, |
|
141 | + $tokenHandler, |
|
142 | + \OC::$server->getL10N('federatedfilesharing'), |
|
143 | + \OC::$server->getLogger(), |
|
144 | + \OC::$server->getLazyRootFolder(), |
|
145 | + \OC::$server->getConfig(), |
|
146 | + \OC::$server->getUserManager(), |
|
147 | + \OC::$server->getCloudIdManager(), |
|
148 | + $c->query(IConfig::class) |
|
149 | + ); |
|
150 | + } |
|
151 | 151 | |
152 | 152 | } |
@@ -32,7 +32,6 @@ |
||
32 | 32 | use OCA\FederatedFileSharing\Controller\RequestHandlerController; |
33 | 33 | use OCA\FederatedFileSharing\FederatedShareProvider; |
34 | 34 | use OCA\FederatedFileSharing\Notifications; |
35 | -use OCA\FederatedFileSharing\OCM\CloudFederationProvider; |
|
36 | 35 | use OCA\FederatedFileSharing\OCM\CloudFederationProviderFiles; |
37 | 36 | use OCP\AppFramework\App; |
38 | 37 | use OCP\GlobalScale\IConfig; |
@@ -450,7 +450,7 @@ |
||
450 | 450 | /** |
451 | 451 | * translate Nextcloud permissions to OCM Permissions |
452 | 452 | * |
453 | - * @param $ncPermissions |
|
453 | + * @param integer $ncPermissions |
|
454 | 454 | * @return array |
455 | 455 | */ |
456 | 456 | protected function ncPermissions2ocmPermissions($ncPermissions) { |
@@ -52,431 +52,431 @@ |
||
52 | 52 | |
53 | 53 | class RequestHandlerController extends OCSController { |
54 | 54 | |
55 | - /** @var FederatedShareProvider */ |
|
56 | - private $federatedShareProvider; |
|
57 | - |
|
58 | - /** @var IDBConnection */ |
|
59 | - private $connection; |
|
60 | - |
|
61 | - /** @var Share\IManager */ |
|
62 | - private $shareManager; |
|
63 | - |
|
64 | - /** @var Notifications */ |
|
65 | - private $notifications; |
|
66 | - |
|
67 | - /** @var AddressHandler */ |
|
68 | - private $addressHandler; |
|
69 | - |
|
70 | - /** @var IUserManager */ |
|
71 | - private $userManager; |
|
72 | - |
|
73 | - /** @var string */ |
|
74 | - private $shareTable = 'share'; |
|
75 | - |
|
76 | - /** @var ICloudIdManager */ |
|
77 | - private $cloudIdManager; |
|
78 | - |
|
79 | - /** @var ILogger */ |
|
80 | - private $logger; |
|
81 | - |
|
82 | - /** @var ICloudFederationFactory */ |
|
83 | - private $cloudFederationFactory; |
|
84 | - |
|
85 | - /** @var ICloudFederationProviderManager */ |
|
86 | - private $cloudFederationProviderManager; |
|
87 | - |
|
88 | - /** |
|
89 | - * Server2Server constructor. |
|
90 | - * |
|
91 | - * @param string $appName |
|
92 | - * @param IRequest $request |
|
93 | - * @param FederatedShareProvider $federatedShareProvider |
|
94 | - * @param IDBConnection $connection |
|
95 | - * @param Share\IManager $shareManager |
|
96 | - * @param Notifications $notifications |
|
97 | - * @param AddressHandler $addressHandler |
|
98 | - * @param IUserManager $userManager |
|
99 | - * @param ICloudIdManager $cloudIdManager |
|
100 | - * @param ILogger $logger |
|
101 | - * @param ICloudFederationFactory $cloudFederationFactory |
|
102 | - * @param ICloudFederationProviderManager $cloudFederationProviderManager |
|
103 | - */ |
|
104 | - public function __construct($appName, |
|
105 | - IRequest $request, |
|
106 | - FederatedShareProvider $federatedShareProvider, |
|
107 | - IDBConnection $connection, |
|
108 | - Share\IManager $shareManager, |
|
109 | - Notifications $notifications, |
|
110 | - AddressHandler $addressHandler, |
|
111 | - IUserManager $userManager, |
|
112 | - ICloudIdManager $cloudIdManager, |
|
113 | - ILogger $logger, |
|
114 | - ICloudFederationFactory $cloudFederationFactory, |
|
115 | - ICloudFederationProviderManager $cloudFederationProviderManager |
|
116 | - ) { |
|
117 | - parent::__construct($appName, $request); |
|
118 | - |
|
119 | - $this->federatedShareProvider = $federatedShareProvider; |
|
120 | - $this->connection = $connection; |
|
121 | - $this->shareManager = $shareManager; |
|
122 | - $this->notifications = $notifications; |
|
123 | - $this->addressHandler = $addressHandler; |
|
124 | - $this->userManager = $userManager; |
|
125 | - $this->cloudIdManager = $cloudIdManager; |
|
126 | - $this->logger = $logger; |
|
127 | - $this->cloudFederationFactory = $cloudFederationFactory; |
|
128 | - $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * @NoCSRFRequired |
|
133 | - * @PublicPage |
|
134 | - * |
|
135 | - * create a new share |
|
136 | - * |
|
137 | - * @return Http\DataResponse |
|
138 | - * @throws OCSException |
|
139 | - */ |
|
140 | - public function createShare() { |
|
141 | - |
|
142 | - $remote = isset($_POST['remote']) ? $_POST['remote'] : null; |
|
143 | - $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
144 | - $name = isset($_POST['name']) ? $_POST['name'] : null; |
|
145 | - $owner = isset($_POST['owner']) ? $_POST['owner'] : null; |
|
146 | - $sharedBy = isset($_POST['sharedBy']) ? $_POST['sharedBy'] : null; |
|
147 | - $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null; |
|
148 | - $remoteId = isset($_POST['remoteId']) ? (int)$_POST['remoteId'] : null; |
|
149 | - $sharedByFederatedId = isset($_POST['sharedByFederatedId']) ? $_POST['sharedByFederatedId'] : null; |
|
150 | - $ownerFederatedId = isset($_POST['ownerFederatedId']) ? $_POST['ownerFederatedId'] : null; |
|
151 | - |
|
152 | - if ($ownerFederatedId === null) { |
|
153 | - $ownerFederatedId = $this->cloudIdManager->getCloudId($owner, $this->cleanupRemote($remote))->getId(); |
|
154 | - } |
|
155 | - // if the owner of the share and the initiator are the same user |
|
156 | - // we also complete the federated share ID for the initiator |
|
157 | - if ($sharedByFederatedId === null && $owner === $sharedBy) { |
|
158 | - $sharedByFederatedId = $ownerFederatedId; |
|
159 | - } |
|
160 | - |
|
161 | - $share = $this->cloudFederationFactory->getCloudFederationShare( |
|
162 | - $shareWith, |
|
163 | - $name, |
|
164 | - '', |
|
165 | - $remoteId, |
|
166 | - $ownerFederatedId, |
|
167 | - $owner, |
|
168 | - $sharedByFederatedId, |
|
169 | - $sharedBy, |
|
170 | - $token, |
|
171 | - 'user', |
|
172 | - 'file' |
|
173 | - ); |
|
174 | - |
|
175 | - try { |
|
176 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
177 | - $provider->shareReceived($share); |
|
178 | - } catch (ProviderDoesNotExistsException $e) { |
|
179 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
180 | - } catch (ProviderCouldNotAddShareException $e) { |
|
181 | - throw new OCSException($e->getMessage(), 400); |
|
182 | - } catch (\Exception $e) { |
|
183 | - throw new OCSException('internal server error, was not able to add share from ' . $remote, 500); |
|
184 | - } |
|
185 | - |
|
186 | - return new Http\DataResponse(); |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * @NoCSRFRequired |
|
191 | - * @PublicPage |
|
192 | - * |
|
193 | - * create re-share on behalf of another user |
|
194 | - * |
|
195 | - * @param int $id |
|
196 | - * @return Http\DataResponse |
|
197 | - * @throws OCSBadRequestException |
|
198 | - * @throws OCSException |
|
199 | - * @throws OCSForbiddenException |
|
200 | - */ |
|
201 | - public function reShare($id) { |
|
202 | - |
|
203 | - $token = $this->request->getParam('token', null); |
|
204 | - $shareWith = $this->request->getParam('shareWith', null); |
|
205 | - $permission = (int)$this->request->getParam('permission', null); |
|
206 | - $remoteId = (int)$this->request->getParam('remoteId', null); |
|
207 | - |
|
208 | - if ($id === null || |
|
209 | - $token === null || |
|
210 | - $shareWith === null || |
|
211 | - $permission === null || |
|
212 | - $remoteId === null |
|
213 | - ) { |
|
214 | - throw new OCSBadRequestException(); |
|
215 | - } |
|
216 | - |
|
217 | - $notification = [ |
|
218 | - 'sharedSecret' => $token, |
|
219 | - 'shareWith' => $shareWith, |
|
220 | - 'senderId' => $remoteId, |
|
221 | - 'message' => 'Recipient of a share ask the owner to reshare the file' |
|
222 | - ]; |
|
223 | - |
|
224 | - try { |
|
225 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
226 | - list($newToken, $localId) = $provider->notificationReceived('REQUEST_RESHARE', $id, $notification); |
|
227 | - return new Http\DataResponse([ |
|
228 | - 'token' => $newToken, |
|
229 | - 'remoteId' => $localId |
|
230 | - ]); |
|
231 | - } catch (ProviderDoesNotExistsException $e) { |
|
232 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
233 | - } catch (ShareNotFound $e) { |
|
234 | - $this->logger->debug('Share not found: ' . $e->getMessage()); |
|
235 | - } catch (\Exception $e) { |
|
236 | - $this->logger->debug('internal server error, can not process notification: ' . $e->getMessage()); |
|
237 | - } |
|
238 | - |
|
239 | - throw new OCSBadRequestException(); |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * @NoCSRFRequired |
|
245 | - * @PublicPage |
|
246 | - * |
|
247 | - * accept server-to-server share |
|
248 | - * |
|
249 | - * @param int $id |
|
250 | - * @return Http\DataResponse |
|
251 | - * @throws OCSException |
|
252 | - * @throws ShareNotFound |
|
253 | - * @throws \OC\HintException |
|
254 | - */ |
|
255 | - public function acceptShare($id) { |
|
256 | - |
|
257 | - $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
258 | - |
|
259 | - $notification = [ |
|
260 | - 'sharedSecret' => $token, |
|
261 | - 'message' => 'Recipient accept the share' |
|
262 | - ]; |
|
263 | - |
|
264 | - try { |
|
265 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
266 | - $provider->notificationReceived('SHARE_ACCEPTED', $id, $notification); |
|
267 | - } catch (ProviderDoesNotExistsException $e) { |
|
268 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
269 | - } catch (ShareNotFound $e) { |
|
270 | - $this->logger->debug('Share not found: ' . $e->getMessage()); |
|
271 | - } catch (\Exception $e) { |
|
272 | - $this->logger->debug('internal server error, can not process notification: ' . $e->getMessage()); |
|
273 | - } |
|
274 | - |
|
275 | - return new Http\DataResponse(); |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * @NoCSRFRequired |
|
280 | - * @PublicPage |
|
281 | - * |
|
282 | - * decline server-to-server share |
|
283 | - * |
|
284 | - * @param int $id |
|
285 | - * @return Http\DataResponse |
|
286 | - * @throws OCSException |
|
287 | - */ |
|
288 | - public function declineShare($id) { |
|
289 | - |
|
290 | - $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
291 | - |
|
292 | - $notification = [ |
|
293 | - 'sharedSecret' => $token, |
|
294 | - 'message' => 'Recipient declined the share' |
|
295 | - ]; |
|
296 | - |
|
297 | - try { |
|
298 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
299 | - $provider->notificationReceived('SHARE_DECLINED', $id, $notification); |
|
300 | - } catch (ProviderDoesNotExistsException $e) { |
|
301 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
302 | - } catch (ShareNotFound $e) { |
|
303 | - $this->logger->debug('Share not found: ' . $e->getMessage()); |
|
304 | - } catch (\Exception $e) { |
|
305 | - $this->logger->debug('internal server error, can not process notification: ' . $e->getMessage()); |
|
306 | - } |
|
307 | - |
|
308 | - return new Http\DataResponse(); |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * @NoCSRFRequired |
|
313 | - * @PublicPage |
|
314 | - * |
|
315 | - * remove server-to-server share if it was unshared by the owner |
|
316 | - * |
|
317 | - * @param int $id |
|
318 | - * @return Http\DataResponse |
|
319 | - * @throws OCSException |
|
320 | - */ |
|
321 | - public function unshare($id) { |
|
322 | - |
|
323 | - if (!$this->isS2SEnabled()) { |
|
324 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
325 | - } |
|
326 | - |
|
327 | - $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
328 | - |
|
329 | - try { |
|
330 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
331 | - $notification = ['sharedSecret' => $token]; |
|
332 | - $provider->notificationReceived('SHARE_UNSHARED', $id, $notification); |
|
333 | - } catch (\Exception $e) { |
|
334 | - $this->logger->debug('processing unshare notification failed: ' . $e->getMessage()); |
|
335 | - } |
|
336 | - |
|
337 | - return new Http\DataResponse(); |
|
338 | - } |
|
339 | - |
|
340 | - private function cleanupRemote($remote) { |
|
341 | - $remote = substr($remote, strpos($remote, '://') + 3); |
|
342 | - |
|
343 | - return rtrim($remote, '/'); |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * @NoCSRFRequired |
|
349 | - * @PublicPage |
|
350 | - * |
|
351 | - * federated share was revoked, either by the owner or the re-sharer |
|
352 | - * |
|
353 | - * @param int $id |
|
354 | - * @return Http\DataResponse |
|
355 | - * @throws OCSBadRequestException |
|
356 | - */ |
|
357 | - public function revoke($id) { |
|
358 | - |
|
359 | - $token = $this->request->getParam('token'); |
|
360 | - |
|
361 | - try { |
|
362 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
363 | - $notification = ['sharedSecret' => $token]; |
|
364 | - $provider->notificationReceived('RESHARE_UNDO', $id, $notification); |
|
365 | - return new Http\DataResponse(); |
|
366 | - } catch (\Exception $e) { |
|
367 | - throw new OCSBadRequestException(); |
|
368 | - } |
|
369 | - |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * check if server-to-server sharing is enabled |
|
374 | - * |
|
375 | - * @param bool $incoming |
|
376 | - * @return bool |
|
377 | - */ |
|
378 | - private function isS2SEnabled($incoming = false) { |
|
379 | - |
|
380 | - $result = \OCP\App::isEnabled('files_sharing'); |
|
381 | - |
|
382 | - if ($incoming) { |
|
383 | - $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled(); |
|
384 | - } else { |
|
385 | - $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
386 | - } |
|
387 | - |
|
388 | - return $result; |
|
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * @NoCSRFRequired |
|
393 | - * @PublicPage |
|
394 | - * |
|
395 | - * update share information to keep federated re-shares in sync |
|
396 | - * |
|
397 | - * @param int $id |
|
398 | - * @return Http\DataResponse |
|
399 | - * @throws OCSBadRequestException |
|
400 | - */ |
|
401 | - public function updatePermissions($id) { |
|
402 | - $token = $this->request->getParam('token', null); |
|
403 | - $ncPermissions = $this->request->getParam('permissions', null); |
|
404 | - |
|
405 | - try { |
|
406 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
407 | - $ocmPermissions = $this->ncPermissions2ocmPermissions((int)$ncPermissions); |
|
408 | - $notification = ['sharedSecret' => $token, 'permission' => $ocmPermissions]; |
|
409 | - $provider->notificationReceived('RESHARE_CHANGE_PERMISSION', $id, $notification); |
|
410 | - } catch (\Exception $e) { |
|
411 | - $this->logger->debug($e->getMessage()); |
|
412 | - throw new OCSBadRequestException(); |
|
413 | - } |
|
414 | - |
|
415 | - return new Http\DataResponse(); |
|
416 | - } |
|
417 | - |
|
418 | - /** |
|
419 | - * translate Nextcloud permissions to OCM Permissions |
|
420 | - * |
|
421 | - * @param $ncPermissions |
|
422 | - * @return array |
|
423 | - */ |
|
424 | - protected function ncPermissions2ocmPermissions($ncPermissions) { |
|
425 | - |
|
426 | - $ocmPermissions = []; |
|
427 | - |
|
428 | - if ($ncPermissions & Constants::PERMISSION_SHARE) { |
|
429 | - $ocmPermissions[] = 'share'; |
|
430 | - } |
|
431 | - |
|
432 | - if ($ncPermissions & Constants::PERMISSION_READ) { |
|
433 | - $ocmPermissions[] = 'read'; |
|
434 | - } |
|
435 | - |
|
436 | - if (($ncPermissions & Constants::PERMISSION_CREATE) || |
|
437 | - ($ncPermissions & Constants::PERMISSION_UPDATE)) { |
|
438 | - $ocmPermissions[] = 'write'; |
|
439 | - } |
|
440 | - |
|
441 | - return $ocmPermissions; |
|
442 | - |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
446 | - * @NoCSRFRequired |
|
447 | - * @PublicPage |
|
448 | - * |
|
449 | - * change the owner of a server-to-server share |
|
450 | - * |
|
451 | - * @param int $id |
|
452 | - * @return Http\DataResponse |
|
453 | - * @throws \InvalidArgumentException |
|
454 | - * @throws OCSException |
|
455 | - */ |
|
456 | - public function move($id) { |
|
457 | - |
|
458 | - if (!$this->isS2SEnabled()) { |
|
459 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
460 | - } |
|
461 | - |
|
462 | - $token = $this->request->getParam('token'); |
|
463 | - $remote = $this->request->getParam('remote'); |
|
464 | - $newRemoteId = $this->request->getParam('remote_id', $id); |
|
465 | - $cloudId = $this->cloudIdManager->resolveCloudId($remote); |
|
466 | - |
|
467 | - $qb = $this->connection->getQueryBuilder(); |
|
468 | - $query = $qb->update('share_external') |
|
469 | - ->set('remote', $qb->createNamedParameter($cloudId->getRemote())) |
|
470 | - ->set('owner', $qb->createNamedParameter($cloudId->getUser())) |
|
471 | - ->set('remote_id', $qb->createNamedParameter($newRemoteId)) |
|
472 | - ->where($qb->expr()->eq('remote_id', $qb->createNamedParameter($id))) |
|
473 | - ->andWhere($qb->expr()->eq('share_token', $qb->createNamedParameter($token))); |
|
474 | - $affected = $query->execute(); |
|
475 | - |
|
476 | - if ($affected > 0) { |
|
477 | - return new Http\DataResponse(['remote' => $cloudId->getRemote(), 'owner' => $cloudId->getUser()]); |
|
478 | - } else { |
|
479 | - throw new OCSBadRequestException('Share not found or token invalid'); |
|
480 | - } |
|
481 | - } |
|
55 | + /** @var FederatedShareProvider */ |
|
56 | + private $federatedShareProvider; |
|
57 | + |
|
58 | + /** @var IDBConnection */ |
|
59 | + private $connection; |
|
60 | + |
|
61 | + /** @var Share\IManager */ |
|
62 | + private $shareManager; |
|
63 | + |
|
64 | + /** @var Notifications */ |
|
65 | + private $notifications; |
|
66 | + |
|
67 | + /** @var AddressHandler */ |
|
68 | + private $addressHandler; |
|
69 | + |
|
70 | + /** @var IUserManager */ |
|
71 | + private $userManager; |
|
72 | + |
|
73 | + /** @var string */ |
|
74 | + private $shareTable = 'share'; |
|
75 | + |
|
76 | + /** @var ICloudIdManager */ |
|
77 | + private $cloudIdManager; |
|
78 | + |
|
79 | + /** @var ILogger */ |
|
80 | + private $logger; |
|
81 | + |
|
82 | + /** @var ICloudFederationFactory */ |
|
83 | + private $cloudFederationFactory; |
|
84 | + |
|
85 | + /** @var ICloudFederationProviderManager */ |
|
86 | + private $cloudFederationProviderManager; |
|
87 | + |
|
88 | + /** |
|
89 | + * Server2Server constructor. |
|
90 | + * |
|
91 | + * @param string $appName |
|
92 | + * @param IRequest $request |
|
93 | + * @param FederatedShareProvider $federatedShareProvider |
|
94 | + * @param IDBConnection $connection |
|
95 | + * @param Share\IManager $shareManager |
|
96 | + * @param Notifications $notifications |
|
97 | + * @param AddressHandler $addressHandler |
|
98 | + * @param IUserManager $userManager |
|
99 | + * @param ICloudIdManager $cloudIdManager |
|
100 | + * @param ILogger $logger |
|
101 | + * @param ICloudFederationFactory $cloudFederationFactory |
|
102 | + * @param ICloudFederationProviderManager $cloudFederationProviderManager |
|
103 | + */ |
|
104 | + public function __construct($appName, |
|
105 | + IRequest $request, |
|
106 | + FederatedShareProvider $federatedShareProvider, |
|
107 | + IDBConnection $connection, |
|
108 | + Share\IManager $shareManager, |
|
109 | + Notifications $notifications, |
|
110 | + AddressHandler $addressHandler, |
|
111 | + IUserManager $userManager, |
|
112 | + ICloudIdManager $cloudIdManager, |
|
113 | + ILogger $logger, |
|
114 | + ICloudFederationFactory $cloudFederationFactory, |
|
115 | + ICloudFederationProviderManager $cloudFederationProviderManager |
|
116 | + ) { |
|
117 | + parent::__construct($appName, $request); |
|
118 | + |
|
119 | + $this->federatedShareProvider = $federatedShareProvider; |
|
120 | + $this->connection = $connection; |
|
121 | + $this->shareManager = $shareManager; |
|
122 | + $this->notifications = $notifications; |
|
123 | + $this->addressHandler = $addressHandler; |
|
124 | + $this->userManager = $userManager; |
|
125 | + $this->cloudIdManager = $cloudIdManager; |
|
126 | + $this->logger = $logger; |
|
127 | + $this->cloudFederationFactory = $cloudFederationFactory; |
|
128 | + $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * @NoCSRFRequired |
|
133 | + * @PublicPage |
|
134 | + * |
|
135 | + * create a new share |
|
136 | + * |
|
137 | + * @return Http\DataResponse |
|
138 | + * @throws OCSException |
|
139 | + */ |
|
140 | + public function createShare() { |
|
141 | + |
|
142 | + $remote = isset($_POST['remote']) ? $_POST['remote'] : null; |
|
143 | + $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
144 | + $name = isset($_POST['name']) ? $_POST['name'] : null; |
|
145 | + $owner = isset($_POST['owner']) ? $_POST['owner'] : null; |
|
146 | + $sharedBy = isset($_POST['sharedBy']) ? $_POST['sharedBy'] : null; |
|
147 | + $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null; |
|
148 | + $remoteId = isset($_POST['remoteId']) ? (int)$_POST['remoteId'] : null; |
|
149 | + $sharedByFederatedId = isset($_POST['sharedByFederatedId']) ? $_POST['sharedByFederatedId'] : null; |
|
150 | + $ownerFederatedId = isset($_POST['ownerFederatedId']) ? $_POST['ownerFederatedId'] : null; |
|
151 | + |
|
152 | + if ($ownerFederatedId === null) { |
|
153 | + $ownerFederatedId = $this->cloudIdManager->getCloudId($owner, $this->cleanupRemote($remote))->getId(); |
|
154 | + } |
|
155 | + // if the owner of the share and the initiator are the same user |
|
156 | + // we also complete the federated share ID for the initiator |
|
157 | + if ($sharedByFederatedId === null && $owner === $sharedBy) { |
|
158 | + $sharedByFederatedId = $ownerFederatedId; |
|
159 | + } |
|
160 | + |
|
161 | + $share = $this->cloudFederationFactory->getCloudFederationShare( |
|
162 | + $shareWith, |
|
163 | + $name, |
|
164 | + '', |
|
165 | + $remoteId, |
|
166 | + $ownerFederatedId, |
|
167 | + $owner, |
|
168 | + $sharedByFederatedId, |
|
169 | + $sharedBy, |
|
170 | + $token, |
|
171 | + 'user', |
|
172 | + 'file' |
|
173 | + ); |
|
174 | + |
|
175 | + try { |
|
176 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
177 | + $provider->shareReceived($share); |
|
178 | + } catch (ProviderDoesNotExistsException $e) { |
|
179 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
180 | + } catch (ProviderCouldNotAddShareException $e) { |
|
181 | + throw new OCSException($e->getMessage(), 400); |
|
182 | + } catch (\Exception $e) { |
|
183 | + throw new OCSException('internal server error, was not able to add share from ' . $remote, 500); |
|
184 | + } |
|
185 | + |
|
186 | + return new Http\DataResponse(); |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * @NoCSRFRequired |
|
191 | + * @PublicPage |
|
192 | + * |
|
193 | + * create re-share on behalf of another user |
|
194 | + * |
|
195 | + * @param int $id |
|
196 | + * @return Http\DataResponse |
|
197 | + * @throws OCSBadRequestException |
|
198 | + * @throws OCSException |
|
199 | + * @throws OCSForbiddenException |
|
200 | + */ |
|
201 | + public function reShare($id) { |
|
202 | + |
|
203 | + $token = $this->request->getParam('token', null); |
|
204 | + $shareWith = $this->request->getParam('shareWith', null); |
|
205 | + $permission = (int)$this->request->getParam('permission', null); |
|
206 | + $remoteId = (int)$this->request->getParam('remoteId', null); |
|
207 | + |
|
208 | + if ($id === null || |
|
209 | + $token === null || |
|
210 | + $shareWith === null || |
|
211 | + $permission === null || |
|
212 | + $remoteId === null |
|
213 | + ) { |
|
214 | + throw new OCSBadRequestException(); |
|
215 | + } |
|
216 | + |
|
217 | + $notification = [ |
|
218 | + 'sharedSecret' => $token, |
|
219 | + 'shareWith' => $shareWith, |
|
220 | + 'senderId' => $remoteId, |
|
221 | + 'message' => 'Recipient of a share ask the owner to reshare the file' |
|
222 | + ]; |
|
223 | + |
|
224 | + try { |
|
225 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
226 | + list($newToken, $localId) = $provider->notificationReceived('REQUEST_RESHARE', $id, $notification); |
|
227 | + return new Http\DataResponse([ |
|
228 | + 'token' => $newToken, |
|
229 | + 'remoteId' => $localId |
|
230 | + ]); |
|
231 | + } catch (ProviderDoesNotExistsException $e) { |
|
232 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
233 | + } catch (ShareNotFound $e) { |
|
234 | + $this->logger->debug('Share not found: ' . $e->getMessage()); |
|
235 | + } catch (\Exception $e) { |
|
236 | + $this->logger->debug('internal server error, can not process notification: ' . $e->getMessage()); |
|
237 | + } |
|
238 | + |
|
239 | + throw new OCSBadRequestException(); |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * @NoCSRFRequired |
|
245 | + * @PublicPage |
|
246 | + * |
|
247 | + * accept server-to-server share |
|
248 | + * |
|
249 | + * @param int $id |
|
250 | + * @return Http\DataResponse |
|
251 | + * @throws OCSException |
|
252 | + * @throws ShareNotFound |
|
253 | + * @throws \OC\HintException |
|
254 | + */ |
|
255 | + public function acceptShare($id) { |
|
256 | + |
|
257 | + $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
258 | + |
|
259 | + $notification = [ |
|
260 | + 'sharedSecret' => $token, |
|
261 | + 'message' => 'Recipient accept the share' |
|
262 | + ]; |
|
263 | + |
|
264 | + try { |
|
265 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
266 | + $provider->notificationReceived('SHARE_ACCEPTED', $id, $notification); |
|
267 | + } catch (ProviderDoesNotExistsException $e) { |
|
268 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
269 | + } catch (ShareNotFound $e) { |
|
270 | + $this->logger->debug('Share not found: ' . $e->getMessage()); |
|
271 | + } catch (\Exception $e) { |
|
272 | + $this->logger->debug('internal server error, can not process notification: ' . $e->getMessage()); |
|
273 | + } |
|
274 | + |
|
275 | + return new Http\DataResponse(); |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * @NoCSRFRequired |
|
280 | + * @PublicPage |
|
281 | + * |
|
282 | + * decline server-to-server share |
|
283 | + * |
|
284 | + * @param int $id |
|
285 | + * @return Http\DataResponse |
|
286 | + * @throws OCSException |
|
287 | + */ |
|
288 | + public function declineShare($id) { |
|
289 | + |
|
290 | + $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
291 | + |
|
292 | + $notification = [ |
|
293 | + 'sharedSecret' => $token, |
|
294 | + 'message' => 'Recipient declined the share' |
|
295 | + ]; |
|
296 | + |
|
297 | + try { |
|
298 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
299 | + $provider->notificationReceived('SHARE_DECLINED', $id, $notification); |
|
300 | + } catch (ProviderDoesNotExistsException $e) { |
|
301 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
302 | + } catch (ShareNotFound $e) { |
|
303 | + $this->logger->debug('Share not found: ' . $e->getMessage()); |
|
304 | + } catch (\Exception $e) { |
|
305 | + $this->logger->debug('internal server error, can not process notification: ' . $e->getMessage()); |
|
306 | + } |
|
307 | + |
|
308 | + return new Http\DataResponse(); |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * @NoCSRFRequired |
|
313 | + * @PublicPage |
|
314 | + * |
|
315 | + * remove server-to-server share if it was unshared by the owner |
|
316 | + * |
|
317 | + * @param int $id |
|
318 | + * @return Http\DataResponse |
|
319 | + * @throws OCSException |
|
320 | + */ |
|
321 | + public function unshare($id) { |
|
322 | + |
|
323 | + if (!$this->isS2SEnabled()) { |
|
324 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
325 | + } |
|
326 | + |
|
327 | + $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
328 | + |
|
329 | + try { |
|
330 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
331 | + $notification = ['sharedSecret' => $token]; |
|
332 | + $provider->notificationReceived('SHARE_UNSHARED', $id, $notification); |
|
333 | + } catch (\Exception $e) { |
|
334 | + $this->logger->debug('processing unshare notification failed: ' . $e->getMessage()); |
|
335 | + } |
|
336 | + |
|
337 | + return new Http\DataResponse(); |
|
338 | + } |
|
339 | + |
|
340 | + private function cleanupRemote($remote) { |
|
341 | + $remote = substr($remote, strpos($remote, '://') + 3); |
|
342 | + |
|
343 | + return rtrim($remote, '/'); |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * @NoCSRFRequired |
|
349 | + * @PublicPage |
|
350 | + * |
|
351 | + * federated share was revoked, either by the owner or the re-sharer |
|
352 | + * |
|
353 | + * @param int $id |
|
354 | + * @return Http\DataResponse |
|
355 | + * @throws OCSBadRequestException |
|
356 | + */ |
|
357 | + public function revoke($id) { |
|
358 | + |
|
359 | + $token = $this->request->getParam('token'); |
|
360 | + |
|
361 | + try { |
|
362 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
363 | + $notification = ['sharedSecret' => $token]; |
|
364 | + $provider->notificationReceived('RESHARE_UNDO', $id, $notification); |
|
365 | + return new Http\DataResponse(); |
|
366 | + } catch (\Exception $e) { |
|
367 | + throw new OCSBadRequestException(); |
|
368 | + } |
|
369 | + |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * check if server-to-server sharing is enabled |
|
374 | + * |
|
375 | + * @param bool $incoming |
|
376 | + * @return bool |
|
377 | + */ |
|
378 | + private function isS2SEnabled($incoming = false) { |
|
379 | + |
|
380 | + $result = \OCP\App::isEnabled('files_sharing'); |
|
381 | + |
|
382 | + if ($incoming) { |
|
383 | + $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled(); |
|
384 | + } else { |
|
385 | + $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
386 | + } |
|
387 | + |
|
388 | + return $result; |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * @NoCSRFRequired |
|
393 | + * @PublicPage |
|
394 | + * |
|
395 | + * update share information to keep federated re-shares in sync |
|
396 | + * |
|
397 | + * @param int $id |
|
398 | + * @return Http\DataResponse |
|
399 | + * @throws OCSBadRequestException |
|
400 | + */ |
|
401 | + public function updatePermissions($id) { |
|
402 | + $token = $this->request->getParam('token', null); |
|
403 | + $ncPermissions = $this->request->getParam('permissions', null); |
|
404 | + |
|
405 | + try { |
|
406 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
407 | + $ocmPermissions = $this->ncPermissions2ocmPermissions((int)$ncPermissions); |
|
408 | + $notification = ['sharedSecret' => $token, 'permission' => $ocmPermissions]; |
|
409 | + $provider->notificationReceived('RESHARE_CHANGE_PERMISSION', $id, $notification); |
|
410 | + } catch (\Exception $e) { |
|
411 | + $this->logger->debug($e->getMessage()); |
|
412 | + throw new OCSBadRequestException(); |
|
413 | + } |
|
414 | + |
|
415 | + return new Http\DataResponse(); |
|
416 | + } |
|
417 | + |
|
418 | + /** |
|
419 | + * translate Nextcloud permissions to OCM Permissions |
|
420 | + * |
|
421 | + * @param $ncPermissions |
|
422 | + * @return array |
|
423 | + */ |
|
424 | + protected function ncPermissions2ocmPermissions($ncPermissions) { |
|
425 | + |
|
426 | + $ocmPermissions = []; |
|
427 | + |
|
428 | + if ($ncPermissions & Constants::PERMISSION_SHARE) { |
|
429 | + $ocmPermissions[] = 'share'; |
|
430 | + } |
|
431 | + |
|
432 | + if ($ncPermissions & Constants::PERMISSION_READ) { |
|
433 | + $ocmPermissions[] = 'read'; |
|
434 | + } |
|
435 | + |
|
436 | + if (($ncPermissions & Constants::PERMISSION_CREATE) || |
|
437 | + ($ncPermissions & Constants::PERMISSION_UPDATE)) { |
|
438 | + $ocmPermissions[] = 'write'; |
|
439 | + } |
|
440 | + |
|
441 | + return $ocmPermissions; |
|
442 | + |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | + * @NoCSRFRequired |
|
447 | + * @PublicPage |
|
448 | + * |
|
449 | + * change the owner of a server-to-server share |
|
450 | + * |
|
451 | + * @param int $id |
|
452 | + * @return Http\DataResponse |
|
453 | + * @throws \InvalidArgumentException |
|
454 | + * @throws OCSException |
|
455 | + */ |
|
456 | + public function move($id) { |
|
457 | + |
|
458 | + if (!$this->isS2SEnabled()) { |
|
459 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
460 | + } |
|
461 | + |
|
462 | + $token = $this->request->getParam('token'); |
|
463 | + $remote = $this->request->getParam('remote'); |
|
464 | + $newRemoteId = $this->request->getParam('remote_id', $id); |
|
465 | + $cloudId = $this->cloudIdManager->resolveCloudId($remote); |
|
466 | + |
|
467 | + $qb = $this->connection->getQueryBuilder(); |
|
468 | + $query = $qb->update('share_external') |
|
469 | + ->set('remote', $qb->createNamedParameter($cloudId->getRemote())) |
|
470 | + ->set('owner', $qb->createNamedParameter($cloudId->getUser())) |
|
471 | + ->set('remote_id', $qb->createNamedParameter($newRemoteId)) |
|
472 | + ->where($qb->expr()->eq('remote_id', $qb->createNamedParameter($id))) |
|
473 | + ->andWhere($qb->expr()->eq('share_token', $qb->createNamedParameter($token))); |
|
474 | + $affected = $query->execute(); |
|
475 | + |
|
476 | + if ($affected > 0) { |
|
477 | + return new Http\DataResponse(['remote' => $cloudId->getRemote(), 'owner' => $cloudId->getUser()]); |
|
478 | + } else { |
|
479 | + throw new OCSBadRequestException('Share not found or token invalid'); |
|
480 | + } |
|
481 | + } |
|
482 | 482 | } |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | $owner = isset($_POST['owner']) ? $_POST['owner'] : null; |
146 | 146 | $sharedBy = isset($_POST['sharedBy']) ? $_POST['sharedBy'] : null; |
147 | 147 | $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null; |
148 | - $remoteId = isset($_POST['remoteId']) ? (int)$_POST['remoteId'] : null; |
|
148 | + $remoteId = isset($_POST['remoteId']) ? (int) $_POST['remoteId'] : null; |
|
149 | 149 | $sharedByFederatedId = isset($_POST['sharedByFederatedId']) ? $_POST['sharedByFederatedId'] : null; |
150 | 150 | $ownerFederatedId = isset($_POST['ownerFederatedId']) ? $_POST['ownerFederatedId'] : null; |
151 | 151 | |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | } catch (ProviderCouldNotAddShareException $e) { |
181 | 181 | throw new OCSException($e->getMessage(), 400); |
182 | 182 | } catch (\Exception $e) { |
183 | - throw new OCSException('internal server error, was not able to add share from ' . $remote, 500); |
|
183 | + throw new OCSException('internal server error, was not able to add share from '.$remote, 500); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | return new Http\DataResponse(); |
@@ -202,8 +202,8 @@ discard block |
||
202 | 202 | |
203 | 203 | $token = $this->request->getParam('token', null); |
204 | 204 | $shareWith = $this->request->getParam('shareWith', null); |
205 | - $permission = (int)$this->request->getParam('permission', null); |
|
206 | - $remoteId = (int)$this->request->getParam('remoteId', null); |
|
205 | + $permission = (int) $this->request->getParam('permission', null); |
|
206 | + $remoteId = (int) $this->request->getParam('remoteId', null); |
|
207 | 207 | |
208 | 208 | if ($id === null || |
209 | 209 | $token === null || |
@@ -231,9 +231,9 @@ discard block |
||
231 | 231 | } catch (ProviderDoesNotExistsException $e) { |
232 | 232 | throw new OCSException('Server does not support federated cloud sharing', 503); |
233 | 233 | } catch (ShareNotFound $e) { |
234 | - $this->logger->debug('Share not found: ' . $e->getMessage()); |
|
234 | + $this->logger->debug('Share not found: '.$e->getMessage()); |
|
235 | 235 | } catch (\Exception $e) { |
236 | - $this->logger->debug('internal server error, can not process notification: ' . $e->getMessage()); |
|
236 | + $this->logger->debug('internal server error, can not process notification: '.$e->getMessage()); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | throw new OCSBadRequestException(); |
@@ -267,9 +267,9 @@ discard block |
||
267 | 267 | } catch (ProviderDoesNotExistsException $e) { |
268 | 268 | throw new OCSException('Server does not support federated cloud sharing', 503); |
269 | 269 | } catch (ShareNotFound $e) { |
270 | - $this->logger->debug('Share not found: ' . $e->getMessage()); |
|
270 | + $this->logger->debug('Share not found: '.$e->getMessage()); |
|
271 | 271 | } catch (\Exception $e) { |
272 | - $this->logger->debug('internal server error, can not process notification: ' . $e->getMessage()); |
|
272 | + $this->logger->debug('internal server error, can not process notification: '.$e->getMessage()); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | return new Http\DataResponse(); |
@@ -300,9 +300,9 @@ discard block |
||
300 | 300 | } catch (ProviderDoesNotExistsException $e) { |
301 | 301 | throw new OCSException('Server does not support federated cloud sharing', 503); |
302 | 302 | } catch (ShareNotFound $e) { |
303 | - $this->logger->debug('Share not found: ' . $e->getMessage()); |
|
303 | + $this->logger->debug('Share not found: '.$e->getMessage()); |
|
304 | 304 | } catch (\Exception $e) { |
305 | - $this->logger->debug('internal server error, can not process notification: ' . $e->getMessage()); |
|
305 | + $this->logger->debug('internal server error, can not process notification: '.$e->getMessage()); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | return new Http\DataResponse(); |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | $notification = ['sharedSecret' => $token]; |
332 | 332 | $provider->notificationReceived('SHARE_UNSHARED', $id, $notification); |
333 | 333 | } catch (\Exception $e) { |
334 | - $this->logger->debug('processing unshare notification failed: ' . $e->getMessage()); |
|
334 | + $this->logger->debug('processing unshare notification failed: '.$e->getMessage()); |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | return new Http\DataResponse(); |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | |
405 | 405 | try { |
406 | 406 | $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
407 | - $ocmPermissions = $this->ncPermissions2ocmPermissions((int)$ncPermissions); |
|
407 | + $ocmPermissions = $this->ncPermissions2ocmPermissions((int) $ncPermissions); |
|
408 | 408 | $notification = ['sharedSecret' => $token, 'permission' => $ocmPermissions]; |
409 | 409 | $provider->notificationReceived('RESHARE_CHANGE_PERMISSION', $id, $notification); |
410 | 410 | } catch (\Exception $e) { |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | if ($remoteShare) { |
193 | 193 | try { |
194 | 194 | $ownerCloudId = $this->cloudIdManager->getCloudId($remoteShare['owner'], $remoteShare['remote']); |
195 | - $shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, 'tmp_token_' . time()); |
|
195 | + $shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, 'tmp_token_'.time()); |
|
196 | 196 | $share->setId($shareId); |
197 | 197 | list($token, $remoteId) = $this->askOwnerToReShare($shareWith, $share, $shareId); |
198 | 198 | // remote share was create successfully if we get a valid token as return |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | $failure = true; |
273 | 273 | } |
274 | 274 | |
275 | - if($failure) { |
|
275 | + if ($failure) { |
|
276 | 276 | $this->removeShareFromTableById($shareId); |
277 | 277 | $message_t = $this->l->t('Sharing %s failed, could not find %s, maybe the server is currently unreachable or uses a self-signed certificate.', |
278 | 278 | [$share->getNode()->getName(), $share->getSharedWith()]); |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | ->andWhere($query->expr()->eq('mountpoint', $query->createNamedParameter($share->getTarget()))); |
325 | 325 | $result = $query->execute()->fetchAll(); |
326 | 326 | |
327 | - if (isset($result[0]) && (int)$result[0]['remote_id'] > 0) { |
|
327 | + if (isset($result[0]) && (int) $result[0]['remote_id'] > 0) { |
|
328 | 328 | return $result[0]; |
329 | 329 | } |
330 | 330 | |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | $qb->execute(); |
367 | 367 | $id = $qb->getLastInsertId(); |
368 | 368 | |
369 | - return (int)$id; |
|
369 | + return (int) $id; |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | /** |
@@ -456,14 +456,14 @@ discard block |
||
456 | 456 | public function getRemoteId(IShare $share) { |
457 | 457 | $query = $this->dbConnection->getQueryBuilder(); |
458 | 458 | $query->select('remote_id')->from('federated_reshares') |
459 | - ->where($query->expr()->eq('share_id', $query->createNamedParameter((int)$share->getId()))); |
|
459 | + ->where($query->expr()->eq('share_id', $query->createNamedParameter((int) $share->getId()))); |
|
460 | 460 | $data = $query->execute()->fetch(); |
461 | 461 | |
462 | 462 | if (!is_array($data) || !isset($data['remote_id'])) { |
463 | 463 | throw new ShareNotFound(); |
464 | 464 | } |
465 | 465 | |
466 | - return (int)$data['remote_id']; |
|
466 | + return (int) $data['remote_id']; |
|
467 | 467 | } |
468 | 468 | |
469 | 469 | /** |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | ->orderBy('id'); |
495 | 495 | |
496 | 496 | $cursor = $qb->execute(); |
497 | - while($data = $cursor->fetch()) { |
|
497 | + while ($data = $cursor->fetch()) { |
|
498 | 498 | $children[] = $this->createShareObject($data); |
499 | 499 | } |
500 | 500 | $cursor->closeCursor(); |
@@ -612,7 +612,7 @@ discard block |
||
612 | 612 | ); |
613 | 613 | } |
614 | 614 | |
615 | - $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
615 | + $qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
616 | 616 | $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
617 | 617 | |
618 | 618 | $qb->orderBy('id'); |
@@ -675,7 +675,7 @@ discard block |
||
675 | 675 | |
676 | 676 | $cursor = $qb->execute(); |
677 | 677 | $shares = []; |
678 | - while($data = $cursor->fetch()) { |
|
678 | + while ($data = $cursor->fetch()) { |
|
679 | 679 | $shares[] = $this->createShareObject($data); |
680 | 680 | } |
681 | 681 | $cursor->closeCursor(); |
@@ -699,7 +699,7 @@ discard block |
||
699 | 699 | $cursor->closeCursor(); |
700 | 700 | |
701 | 701 | if ($data === false) { |
702 | - throw new ShareNotFound('Can not find share with ID: ' . $id); |
|
702 | + throw new ShareNotFound('Can not find share with ID: '.$id); |
|
703 | 703 | } |
704 | 704 | |
705 | 705 | try { |
@@ -727,7 +727,7 @@ discard block |
||
727 | 727 | ->execute(); |
728 | 728 | |
729 | 729 | $shares = []; |
730 | - while($data = $cursor->fetch()) { |
|
730 | + while ($data = $cursor->fetch()) { |
|
731 | 731 | $shares[] = $this->createShareObject($data); |
732 | 732 | } |
733 | 733 | $cursor->closeCursor(); |
@@ -766,7 +766,7 @@ discard block |
||
766 | 766 | |
767 | 767 | $cursor = $qb->execute(); |
768 | 768 | |
769 | - while($data = $cursor->fetch()) { |
|
769 | + while ($data = $cursor->fetch()) { |
|
770 | 770 | $shares[] = $this->createShareObject($data); |
771 | 771 | } |
772 | 772 | $cursor->closeCursor(); |
@@ -843,15 +843,15 @@ discard block |
||
843 | 843 | private function createShareObject($data) { |
844 | 844 | |
845 | 845 | $share = new Share($this->rootFolder, $this->userManager); |
846 | - $share->setId((int)$data['id']) |
|
847 | - ->setShareType((int)$data['share_type']) |
|
848 | - ->setPermissions((int)$data['permissions']) |
|
846 | + $share->setId((int) $data['id']) |
|
847 | + ->setShareType((int) $data['share_type']) |
|
848 | + ->setPermissions((int) $data['permissions']) |
|
849 | 849 | ->setTarget($data['file_target']) |
850 | - ->setMailSend((bool)$data['mail_send']) |
|
850 | + ->setMailSend((bool) $data['mail_send']) |
|
851 | 851 | ->setToken($data['token']); |
852 | 852 | |
853 | 853 | $shareTime = new \DateTime(); |
854 | - $shareTime->setTimestamp((int)$data['stime']); |
|
854 | + $shareTime->setTimestamp((int) $data['stime']); |
|
855 | 855 | $share->setShareTime($shareTime); |
856 | 856 | $share->setSharedWith($data['share_with']); |
857 | 857 | |
@@ -861,13 +861,13 @@ discard block |
||
861 | 861 | } else { |
862 | 862 | //OLD SHARE |
863 | 863 | $share->setSharedBy($data['uid_owner']); |
864 | - $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
864 | + $path = $this->getNode($share->getSharedBy(), (int) $data['file_source']); |
|
865 | 865 | |
866 | 866 | $owner = $path->getOwner(); |
867 | 867 | $share->setShareOwner($owner->getUID()); |
868 | 868 | } |
869 | 869 | |
870 | - $share->setNodeId((int)$data['file_source']); |
|
870 | + $share->setNodeId((int) $data['file_source']); |
|
871 | 871 | $share->setNodeType($data['item_type']); |
872 | 872 | |
873 | 873 | $share->setProviderId($this->identifier()); |
@@ -53,981 +53,981 @@ |
||
53 | 53 | */ |
54 | 54 | class FederatedShareProvider implements IShareProvider { |
55 | 55 | |
56 | - const SHARE_TYPE_REMOTE = 6; |
|
57 | - |
|
58 | - /** @var IDBConnection */ |
|
59 | - private $dbConnection; |
|
60 | - |
|
61 | - /** @var AddressHandler */ |
|
62 | - private $addressHandler; |
|
63 | - |
|
64 | - /** @var Notifications */ |
|
65 | - private $notifications; |
|
66 | - |
|
67 | - /** @var TokenHandler */ |
|
68 | - private $tokenHandler; |
|
69 | - |
|
70 | - /** @var IL10N */ |
|
71 | - private $l; |
|
72 | - |
|
73 | - /** @var ILogger */ |
|
74 | - private $logger; |
|
75 | - |
|
76 | - /** @var IRootFolder */ |
|
77 | - private $rootFolder; |
|
78 | - |
|
79 | - /** @var IConfig */ |
|
80 | - private $config; |
|
81 | - |
|
82 | - /** @var string */ |
|
83 | - private $externalShareTable = 'share_external'; |
|
84 | - |
|
85 | - /** @var IUserManager */ |
|
86 | - private $userManager; |
|
87 | - |
|
88 | - /** @var ICloudIdManager */ |
|
89 | - private $cloudIdManager; |
|
90 | - |
|
91 | - /** @var \OCP\GlobalScale\IConfig */ |
|
92 | - private $gsConfig; |
|
93 | - |
|
94 | - /** |
|
95 | - * DefaultShareProvider constructor. |
|
96 | - * |
|
97 | - * @param IDBConnection $connection |
|
98 | - * @param AddressHandler $addressHandler |
|
99 | - * @param Notifications $notifications |
|
100 | - * @param TokenHandler $tokenHandler |
|
101 | - * @param IL10N $l10n |
|
102 | - * @param ILogger $logger |
|
103 | - * @param IRootFolder $rootFolder |
|
104 | - * @param IConfig $config |
|
105 | - * @param IUserManager $userManager |
|
106 | - * @param ICloudIdManager $cloudIdManager |
|
107 | - * @param \OCP\GlobalScale\IConfig $globalScaleConfig |
|
108 | - */ |
|
109 | - public function __construct( |
|
110 | - IDBConnection $connection, |
|
111 | - AddressHandler $addressHandler, |
|
112 | - Notifications $notifications, |
|
113 | - TokenHandler $tokenHandler, |
|
114 | - IL10N $l10n, |
|
115 | - ILogger $logger, |
|
116 | - IRootFolder $rootFolder, |
|
117 | - IConfig $config, |
|
118 | - IUserManager $userManager, |
|
119 | - ICloudIdManager $cloudIdManager, |
|
120 | - \OCP\GlobalScale\IConfig $globalScaleConfig |
|
121 | - ) { |
|
122 | - $this->dbConnection = $connection; |
|
123 | - $this->addressHandler = $addressHandler; |
|
124 | - $this->notifications = $notifications; |
|
125 | - $this->tokenHandler = $tokenHandler; |
|
126 | - $this->l = $l10n; |
|
127 | - $this->logger = $logger; |
|
128 | - $this->rootFolder = $rootFolder; |
|
129 | - $this->config = $config; |
|
130 | - $this->userManager = $userManager; |
|
131 | - $this->cloudIdManager = $cloudIdManager; |
|
132 | - $this->gsConfig = $globalScaleConfig; |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Return the identifier of this provider. |
|
137 | - * |
|
138 | - * @return string Containing only [a-zA-Z0-9] |
|
139 | - */ |
|
140 | - public function identifier() { |
|
141 | - return 'ocFederatedSharing'; |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Share a path |
|
146 | - * |
|
147 | - * @param IShare $share |
|
148 | - * @return IShare The share object |
|
149 | - * @throws ShareNotFound |
|
150 | - * @throws \Exception |
|
151 | - */ |
|
152 | - public function create(IShare $share) { |
|
153 | - |
|
154 | - $shareWith = $share->getSharedWith(); |
|
155 | - $itemSource = $share->getNodeId(); |
|
156 | - $itemType = $share->getNodeType(); |
|
157 | - $permissions = $share->getPermissions(); |
|
158 | - $sharedBy = $share->getSharedBy(); |
|
159 | - |
|
160 | - /* |
|
56 | + const SHARE_TYPE_REMOTE = 6; |
|
57 | + |
|
58 | + /** @var IDBConnection */ |
|
59 | + private $dbConnection; |
|
60 | + |
|
61 | + /** @var AddressHandler */ |
|
62 | + private $addressHandler; |
|
63 | + |
|
64 | + /** @var Notifications */ |
|
65 | + private $notifications; |
|
66 | + |
|
67 | + /** @var TokenHandler */ |
|
68 | + private $tokenHandler; |
|
69 | + |
|
70 | + /** @var IL10N */ |
|
71 | + private $l; |
|
72 | + |
|
73 | + /** @var ILogger */ |
|
74 | + private $logger; |
|
75 | + |
|
76 | + /** @var IRootFolder */ |
|
77 | + private $rootFolder; |
|
78 | + |
|
79 | + /** @var IConfig */ |
|
80 | + private $config; |
|
81 | + |
|
82 | + /** @var string */ |
|
83 | + private $externalShareTable = 'share_external'; |
|
84 | + |
|
85 | + /** @var IUserManager */ |
|
86 | + private $userManager; |
|
87 | + |
|
88 | + /** @var ICloudIdManager */ |
|
89 | + private $cloudIdManager; |
|
90 | + |
|
91 | + /** @var \OCP\GlobalScale\IConfig */ |
|
92 | + private $gsConfig; |
|
93 | + |
|
94 | + /** |
|
95 | + * DefaultShareProvider constructor. |
|
96 | + * |
|
97 | + * @param IDBConnection $connection |
|
98 | + * @param AddressHandler $addressHandler |
|
99 | + * @param Notifications $notifications |
|
100 | + * @param TokenHandler $tokenHandler |
|
101 | + * @param IL10N $l10n |
|
102 | + * @param ILogger $logger |
|
103 | + * @param IRootFolder $rootFolder |
|
104 | + * @param IConfig $config |
|
105 | + * @param IUserManager $userManager |
|
106 | + * @param ICloudIdManager $cloudIdManager |
|
107 | + * @param \OCP\GlobalScale\IConfig $globalScaleConfig |
|
108 | + */ |
|
109 | + public function __construct( |
|
110 | + IDBConnection $connection, |
|
111 | + AddressHandler $addressHandler, |
|
112 | + Notifications $notifications, |
|
113 | + TokenHandler $tokenHandler, |
|
114 | + IL10N $l10n, |
|
115 | + ILogger $logger, |
|
116 | + IRootFolder $rootFolder, |
|
117 | + IConfig $config, |
|
118 | + IUserManager $userManager, |
|
119 | + ICloudIdManager $cloudIdManager, |
|
120 | + \OCP\GlobalScale\IConfig $globalScaleConfig |
|
121 | + ) { |
|
122 | + $this->dbConnection = $connection; |
|
123 | + $this->addressHandler = $addressHandler; |
|
124 | + $this->notifications = $notifications; |
|
125 | + $this->tokenHandler = $tokenHandler; |
|
126 | + $this->l = $l10n; |
|
127 | + $this->logger = $logger; |
|
128 | + $this->rootFolder = $rootFolder; |
|
129 | + $this->config = $config; |
|
130 | + $this->userManager = $userManager; |
|
131 | + $this->cloudIdManager = $cloudIdManager; |
|
132 | + $this->gsConfig = $globalScaleConfig; |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Return the identifier of this provider. |
|
137 | + * |
|
138 | + * @return string Containing only [a-zA-Z0-9] |
|
139 | + */ |
|
140 | + public function identifier() { |
|
141 | + return 'ocFederatedSharing'; |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Share a path |
|
146 | + * |
|
147 | + * @param IShare $share |
|
148 | + * @return IShare The share object |
|
149 | + * @throws ShareNotFound |
|
150 | + * @throws \Exception |
|
151 | + */ |
|
152 | + public function create(IShare $share) { |
|
153 | + |
|
154 | + $shareWith = $share->getSharedWith(); |
|
155 | + $itemSource = $share->getNodeId(); |
|
156 | + $itemType = $share->getNodeType(); |
|
157 | + $permissions = $share->getPermissions(); |
|
158 | + $sharedBy = $share->getSharedBy(); |
|
159 | + |
|
160 | + /* |
|
161 | 161 | * Check if file is not already shared with the remote user |
162 | 162 | */ |
163 | - $alreadyShared = $this->getSharedWith($shareWith, self::SHARE_TYPE_REMOTE, $share->getNode(), 1, 0); |
|
164 | - if (!empty($alreadyShared)) { |
|
165 | - $message = 'Sharing %s failed, because this item is already shared with %s'; |
|
166 | - $message_t = $this->l->t('Sharing %s failed, because this item is already shared with %s', array($share->getNode()->getName(), $shareWith)); |
|
167 | - $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']); |
|
168 | - throw new \Exception($message_t); |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - // don't allow federated shares if source and target server are the same |
|
173 | - $cloudId = $this->cloudIdManager->resolveCloudId($shareWith); |
|
174 | - $currentServer = $this->addressHandler->generateRemoteURL(); |
|
175 | - $currentUser = $sharedBy; |
|
176 | - if ($this->addressHandler->compareAddresses($cloudId->getUser(), $cloudId->getRemote(), $currentUser, $currentServer)) { |
|
177 | - $message = 'Not allowed to create a federated share with the same user.'; |
|
178 | - $message_t = $this->l->t('Not allowed to create a federated share with the same user'); |
|
179 | - $this->logger->debug($message, ['app' => 'Federated File Sharing']); |
|
180 | - throw new \Exception($message_t); |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - $share->setSharedWith($cloudId->getId()); |
|
185 | - |
|
186 | - try { |
|
187 | - $remoteShare = $this->getShareFromExternalShareTable($share); |
|
188 | - } catch (ShareNotFound $e) { |
|
189 | - $remoteShare = null; |
|
190 | - } |
|
191 | - |
|
192 | - if ($remoteShare) { |
|
193 | - try { |
|
194 | - $ownerCloudId = $this->cloudIdManager->getCloudId($remoteShare['owner'], $remoteShare['remote']); |
|
195 | - $shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, 'tmp_token_' . time()); |
|
196 | - $share->setId($shareId); |
|
197 | - list($token, $remoteId) = $this->askOwnerToReShare($shareWith, $share, $shareId); |
|
198 | - // remote share was create successfully if we get a valid token as return |
|
199 | - $send = is_string($token) && $token !== ''; |
|
200 | - } catch (\Exception $e) { |
|
201 | - // fall back to old re-share behavior if the remote server |
|
202 | - // doesn't support flat re-shares (was introduced with Nextcloud 9.1) |
|
203 | - $this->removeShareFromTable($share); |
|
204 | - $shareId = $this->createFederatedShare($share); |
|
205 | - } |
|
206 | - if ($send) { |
|
207 | - $this->updateSuccessfulReshare($shareId, $token); |
|
208 | - $this->storeRemoteId($shareId, $remoteId); |
|
209 | - } else { |
|
210 | - $this->removeShareFromTable($share); |
|
211 | - $message_t = $this->l->t('File is already shared with %s', [$shareWith]); |
|
212 | - throw new \Exception($message_t); |
|
213 | - } |
|
214 | - |
|
215 | - } else { |
|
216 | - $shareId = $this->createFederatedShare($share); |
|
217 | - } |
|
218 | - |
|
219 | - $data = $this->getRawShare($shareId); |
|
220 | - return $this->createShareObject($data); |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * create federated share and inform the recipient |
|
225 | - * |
|
226 | - * @param IShare $share |
|
227 | - * @return int |
|
228 | - * @throws ShareNotFound |
|
229 | - * @throws \Exception |
|
230 | - */ |
|
231 | - protected function createFederatedShare(IShare $share) { |
|
232 | - $token = $this->tokenHandler->generateToken(); |
|
233 | - $shareId = $this->addShareToDB( |
|
234 | - $share->getNodeId(), |
|
235 | - $share->getNodeType(), |
|
236 | - $share->getSharedWith(), |
|
237 | - $share->getSharedBy(), |
|
238 | - $share->getShareOwner(), |
|
239 | - $share->getPermissions(), |
|
240 | - $token |
|
241 | - ); |
|
242 | - |
|
243 | - $failure = false; |
|
244 | - |
|
245 | - try { |
|
246 | - $sharedByFederatedId = $share->getSharedBy(); |
|
247 | - if ($this->userManager->userExists($sharedByFederatedId)) { |
|
248 | - $cloudId = $this->cloudIdManager->getCloudId($sharedByFederatedId, $this->addressHandler->generateRemoteURL()); |
|
249 | - $sharedByFederatedId = $cloudId->getId(); |
|
250 | - } |
|
251 | - $ownerCloudId = $this->cloudIdManager->getCloudId($share->getShareOwner(), $this->addressHandler->generateRemoteURL()); |
|
252 | - $send = $this->notifications->sendRemoteShare( |
|
253 | - $token, |
|
254 | - $share->getSharedWith(), |
|
255 | - $share->getNode()->getName(), |
|
256 | - $shareId, |
|
257 | - $share->getShareOwner(), |
|
258 | - $ownerCloudId->getId(), |
|
259 | - $share->getSharedBy(), |
|
260 | - $sharedByFederatedId, |
|
261 | - $share->setShareType() |
|
262 | - ); |
|
263 | - |
|
264 | - if ($send === false) { |
|
265 | - $failure = true; |
|
266 | - } |
|
267 | - } catch (\Exception $e) { |
|
268 | - $this->logger->logException($e, [ |
|
269 | - 'message' => 'Failed to notify remote server of federated share, removing share.', |
|
270 | - 'level' => ILogger::ERROR, |
|
271 | - 'app' => 'federatedfilesharing', |
|
272 | - ]); |
|
273 | - $failure = true; |
|
274 | - } |
|
275 | - |
|
276 | - if($failure) { |
|
277 | - $this->removeShareFromTableById($shareId); |
|
278 | - $message_t = $this->l->t('Sharing %s failed, could not find %s, maybe the server is currently unreachable or uses a self-signed certificate.', |
|
279 | - [$share->getNode()->getName(), $share->getSharedWith()]); |
|
280 | - throw new \Exception($message_t); |
|
281 | - } |
|
282 | - |
|
283 | - return $shareId; |
|
284 | - |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * @param string $shareWith |
|
289 | - * @param IShare $share |
|
290 | - * @param string $shareId internal share Id |
|
291 | - * @return array |
|
292 | - * @throws \Exception |
|
293 | - */ |
|
294 | - protected function askOwnerToReShare($shareWith, IShare $share, $shareId) { |
|
295 | - |
|
296 | - $remoteShare = $this->getShareFromExternalShareTable($share); |
|
297 | - $token = $remoteShare['share_token']; |
|
298 | - $remoteId = $remoteShare['remote_id']; |
|
299 | - $remote = $remoteShare['remote']; |
|
300 | - |
|
301 | - list($token, $remoteId) = $this->notifications->requestReShare( |
|
302 | - $token, |
|
303 | - $remoteId, |
|
304 | - $shareId, |
|
305 | - $remote, |
|
306 | - $shareWith, |
|
307 | - $share->getPermissions(), |
|
308 | - $share->getNode()->getName() |
|
309 | - ); |
|
310 | - |
|
311 | - return [$token, $remoteId]; |
|
312 | - } |
|
313 | - |
|
314 | - /** |
|
315 | - * get federated share from the share_external table but exclude mounted link shares |
|
316 | - * |
|
317 | - * @param IShare $share |
|
318 | - * @return array |
|
319 | - * @throws ShareNotFound |
|
320 | - */ |
|
321 | - protected function getShareFromExternalShareTable(IShare $share) { |
|
322 | - $query = $this->dbConnection->getQueryBuilder(); |
|
323 | - $query->select('*')->from($this->externalShareTable) |
|
324 | - ->where($query->expr()->eq('user', $query->createNamedParameter($share->getShareOwner()))) |
|
325 | - ->andWhere($query->expr()->eq('mountpoint', $query->createNamedParameter($share->getTarget()))); |
|
326 | - $result = $query->execute()->fetchAll(); |
|
327 | - |
|
328 | - if (isset($result[0]) && (int)$result[0]['remote_id'] > 0) { |
|
329 | - return $result[0]; |
|
330 | - } |
|
331 | - |
|
332 | - throw new ShareNotFound('share not found in share_external table'); |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * add share to the database and return the ID |
|
337 | - * |
|
338 | - * @param int $itemSource |
|
339 | - * @param string $itemType |
|
340 | - * @param string $shareWith |
|
341 | - * @param string $sharedBy |
|
342 | - * @param string $uidOwner |
|
343 | - * @param int $permissions |
|
344 | - * @param string $token |
|
345 | - * @return int |
|
346 | - */ |
|
347 | - private function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token) { |
|
348 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
349 | - $qb->insert('share') |
|
350 | - ->setValue('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE)) |
|
351 | - ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
352 | - ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
353 | - ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
354 | - ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
355 | - ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
356 | - ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
357 | - ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
358 | - ->setValue('token', $qb->createNamedParameter($token)) |
|
359 | - ->setValue('stime', $qb->createNamedParameter(time())); |
|
360 | - |
|
361 | - /* |
|
163 | + $alreadyShared = $this->getSharedWith($shareWith, self::SHARE_TYPE_REMOTE, $share->getNode(), 1, 0); |
|
164 | + if (!empty($alreadyShared)) { |
|
165 | + $message = 'Sharing %s failed, because this item is already shared with %s'; |
|
166 | + $message_t = $this->l->t('Sharing %s failed, because this item is already shared with %s', array($share->getNode()->getName(), $shareWith)); |
|
167 | + $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']); |
|
168 | + throw new \Exception($message_t); |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + // don't allow federated shares if source and target server are the same |
|
173 | + $cloudId = $this->cloudIdManager->resolveCloudId($shareWith); |
|
174 | + $currentServer = $this->addressHandler->generateRemoteURL(); |
|
175 | + $currentUser = $sharedBy; |
|
176 | + if ($this->addressHandler->compareAddresses($cloudId->getUser(), $cloudId->getRemote(), $currentUser, $currentServer)) { |
|
177 | + $message = 'Not allowed to create a federated share with the same user.'; |
|
178 | + $message_t = $this->l->t('Not allowed to create a federated share with the same user'); |
|
179 | + $this->logger->debug($message, ['app' => 'Federated File Sharing']); |
|
180 | + throw new \Exception($message_t); |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + $share->setSharedWith($cloudId->getId()); |
|
185 | + |
|
186 | + try { |
|
187 | + $remoteShare = $this->getShareFromExternalShareTable($share); |
|
188 | + } catch (ShareNotFound $e) { |
|
189 | + $remoteShare = null; |
|
190 | + } |
|
191 | + |
|
192 | + if ($remoteShare) { |
|
193 | + try { |
|
194 | + $ownerCloudId = $this->cloudIdManager->getCloudId($remoteShare['owner'], $remoteShare['remote']); |
|
195 | + $shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, 'tmp_token_' . time()); |
|
196 | + $share->setId($shareId); |
|
197 | + list($token, $remoteId) = $this->askOwnerToReShare($shareWith, $share, $shareId); |
|
198 | + // remote share was create successfully if we get a valid token as return |
|
199 | + $send = is_string($token) && $token !== ''; |
|
200 | + } catch (\Exception $e) { |
|
201 | + // fall back to old re-share behavior if the remote server |
|
202 | + // doesn't support flat re-shares (was introduced with Nextcloud 9.1) |
|
203 | + $this->removeShareFromTable($share); |
|
204 | + $shareId = $this->createFederatedShare($share); |
|
205 | + } |
|
206 | + if ($send) { |
|
207 | + $this->updateSuccessfulReshare($shareId, $token); |
|
208 | + $this->storeRemoteId($shareId, $remoteId); |
|
209 | + } else { |
|
210 | + $this->removeShareFromTable($share); |
|
211 | + $message_t = $this->l->t('File is already shared with %s', [$shareWith]); |
|
212 | + throw new \Exception($message_t); |
|
213 | + } |
|
214 | + |
|
215 | + } else { |
|
216 | + $shareId = $this->createFederatedShare($share); |
|
217 | + } |
|
218 | + |
|
219 | + $data = $this->getRawShare($shareId); |
|
220 | + return $this->createShareObject($data); |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * create federated share and inform the recipient |
|
225 | + * |
|
226 | + * @param IShare $share |
|
227 | + * @return int |
|
228 | + * @throws ShareNotFound |
|
229 | + * @throws \Exception |
|
230 | + */ |
|
231 | + protected function createFederatedShare(IShare $share) { |
|
232 | + $token = $this->tokenHandler->generateToken(); |
|
233 | + $shareId = $this->addShareToDB( |
|
234 | + $share->getNodeId(), |
|
235 | + $share->getNodeType(), |
|
236 | + $share->getSharedWith(), |
|
237 | + $share->getSharedBy(), |
|
238 | + $share->getShareOwner(), |
|
239 | + $share->getPermissions(), |
|
240 | + $token |
|
241 | + ); |
|
242 | + |
|
243 | + $failure = false; |
|
244 | + |
|
245 | + try { |
|
246 | + $sharedByFederatedId = $share->getSharedBy(); |
|
247 | + if ($this->userManager->userExists($sharedByFederatedId)) { |
|
248 | + $cloudId = $this->cloudIdManager->getCloudId($sharedByFederatedId, $this->addressHandler->generateRemoteURL()); |
|
249 | + $sharedByFederatedId = $cloudId->getId(); |
|
250 | + } |
|
251 | + $ownerCloudId = $this->cloudIdManager->getCloudId($share->getShareOwner(), $this->addressHandler->generateRemoteURL()); |
|
252 | + $send = $this->notifications->sendRemoteShare( |
|
253 | + $token, |
|
254 | + $share->getSharedWith(), |
|
255 | + $share->getNode()->getName(), |
|
256 | + $shareId, |
|
257 | + $share->getShareOwner(), |
|
258 | + $ownerCloudId->getId(), |
|
259 | + $share->getSharedBy(), |
|
260 | + $sharedByFederatedId, |
|
261 | + $share->setShareType() |
|
262 | + ); |
|
263 | + |
|
264 | + if ($send === false) { |
|
265 | + $failure = true; |
|
266 | + } |
|
267 | + } catch (\Exception $e) { |
|
268 | + $this->logger->logException($e, [ |
|
269 | + 'message' => 'Failed to notify remote server of federated share, removing share.', |
|
270 | + 'level' => ILogger::ERROR, |
|
271 | + 'app' => 'federatedfilesharing', |
|
272 | + ]); |
|
273 | + $failure = true; |
|
274 | + } |
|
275 | + |
|
276 | + if($failure) { |
|
277 | + $this->removeShareFromTableById($shareId); |
|
278 | + $message_t = $this->l->t('Sharing %s failed, could not find %s, maybe the server is currently unreachable or uses a self-signed certificate.', |
|
279 | + [$share->getNode()->getName(), $share->getSharedWith()]); |
|
280 | + throw new \Exception($message_t); |
|
281 | + } |
|
282 | + |
|
283 | + return $shareId; |
|
284 | + |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * @param string $shareWith |
|
289 | + * @param IShare $share |
|
290 | + * @param string $shareId internal share Id |
|
291 | + * @return array |
|
292 | + * @throws \Exception |
|
293 | + */ |
|
294 | + protected function askOwnerToReShare($shareWith, IShare $share, $shareId) { |
|
295 | + |
|
296 | + $remoteShare = $this->getShareFromExternalShareTable($share); |
|
297 | + $token = $remoteShare['share_token']; |
|
298 | + $remoteId = $remoteShare['remote_id']; |
|
299 | + $remote = $remoteShare['remote']; |
|
300 | + |
|
301 | + list($token, $remoteId) = $this->notifications->requestReShare( |
|
302 | + $token, |
|
303 | + $remoteId, |
|
304 | + $shareId, |
|
305 | + $remote, |
|
306 | + $shareWith, |
|
307 | + $share->getPermissions(), |
|
308 | + $share->getNode()->getName() |
|
309 | + ); |
|
310 | + |
|
311 | + return [$token, $remoteId]; |
|
312 | + } |
|
313 | + |
|
314 | + /** |
|
315 | + * get federated share from the share_external table but exclude mounted link shares |
|
316 | + * |
|
317 | + * @param IShare $share |
|
318 | + * @return array |
|
319 | + * @throws ShareNotFound |
|
320 | + */ |
|
321 | + protected function getShareFromExternalShareTable(IShare $share) { |
|
322 | + $query = $this->dbConnection->getQueryBuilder(); |
|
323 | + $query->select('*')->from($this->externalShareTable) |
|
324 | + ->where($query->expr()->eq('user', $query->createNamedParameter($share->getShareOwner()))) |
|
325 | + ->andWhere($query->expr()->eq('mountpoint', $query->createNamedParameter($share->getTarget()))); |
|
326 | + $result = $query->execute()->fetchAll(); |
|
327 | + |
|
328 | + if (isset($result[0]) && (int)$result[0]['remote_id'] > 0) { |
|
329 | + return $result[0]; |
|
330 | + } |
|
331 | + |
|
332 | + throw new ShareNotFound('share not found in share_external table'); |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * add share to the database and return the ID |
|
337 | + * |
|
338 | + * @param int $itemSource |
|
339 | + * @param string $itemType |
|
340 | + * @param string $shareWith |
|
341 | + * @param string $sharedBy |
|
342 | + * @param string $uidOwner |
|
343 | + * @param int $permissions |
|
344 | + * @param string $token |
|
345 | + * @return int |
|
346 | + */ |
|
347 | + private function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token) { |
|
348 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
349 | + $qb->insert('share') |
|
350 | + ->setValue('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE)) |
|
351 | + ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
352 | + ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
353 | + ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
354 | + ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
355 | + ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
356 | + ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
357 | + ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
358 | + ->setValue('token', $qb->createNamedParameter($token)) |
|
359 | + ->setValue('stime', $qb->createNamedParameter(time())); |
|
360 | + |
|
361 | + /* |
|
362 | 362 | * Added to fix https://github.com/owncloud/core/issues/22215 |
363 | 363 | * Can be removed once we get rid of ajax/share.php |
364 | 364 | */ |
365 | - $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
366 | - |
|
367 | - $qb->execute(); |
|
368 | - $id = $qb->getLastInsertId(); |
|
369 | - |
|
370 | - return (int)$id; |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * Update a share |
|
375 | - * |
|
376 | - * @param IShare $share |
|
377 | - * @return IShare The share object |
|
378 | - */ |
|
379 | - public function update(IShare $share) { |
|
380 | - /* |
|
365 | + $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
366 | + |
|
367 | + $qb->execute(); |
|
368 | + $id = $qb->getLastInsertId(); |
|
369 | + |
|
370 | + return (int)$id; |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * Update a share |
|
375 | + * |
|
376 | + * @param IShare $share |
|
377 | + * @return IShare The share object |
|
378 | + */ |
|
379 | + public function update(IShare $share) { |
|
380 | + /* |
|
381 | 381 | * We allow updating the permissions of federated shares |
382 | 382 | */ |
383 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
384 | - $qb->update('share') |
|
385 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
386 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
387 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
388 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
389 | - ->execute(); |
|
390 | - |
|
391 | - // send the updated permission to the owner/initiator, if they are not the same |
|
392 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
393 | - $this->sendPermissionUpdate($share); |
|
394 | - } |
|
395 | - |
|
396 | - return $share; |
|
397 | - } |
|
398 | - |
|
399 | - /** |
|
400 | - * send the updated permission to the owner/initiator, if they are not the same |
|
401 | - * |
|
402 | - * @param IShare $share |
|
403 | - * @throws ShareNotFound |
|
404 | - * @throws \OC\HintException |
|
405 | - */ |
|
406 | - protected function sendPermissionUpdate(IShare $share) { |
|
407 | - $remoteId = $this->getRemoteId($share); |
|
408 | - // if the local user is the owner we send the permission change to the initiator |
|
409 | - if ($this->userManager->userExists($share->getShareOwner())) { |
|
410 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
411 | - } else { // ... if not we send the permission change to the owner |
|
412 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
413 | - } |
|
414 | - $this->notifications->sendPermissionChange($remote, $remoteId, $share->getToken(), $share->getPermissions()); |
|
415 | - } |
|
416 | - |
|
417 | - |
|
418 | - /** |
|
419 | - * update successful reShare with the correct token |
|
420 | - * |
|
421 | - * @param int $shareId |
|
422 | - * @param string $token |
|
423 | - */ |
|
424 | - protected function updateSuccessfulReShare($shareId, $token) { |
|
425 | - $query = $this->dbConnection->getQueryBuilder(); |
|
426 | - $query->update('share') |
|
427 | - ->where($query->expr()->eq('id', $query->createNamedParameter($shareId))) |
|
428 | - ->set('token', $query->createNamedParameter($token)) |
|
429 | - ->execute(); |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * store remote ID in federated reShare table |
|
434 | - * |
|
435 | - * @param $shareId |
|
436 | - * @param $remoteId |
|
437 | - */ |
|
438 | - public function storeRemoteId($shareId, $remoteId) { |
|
439 | - $query = $this->dbConnection->getQueryBuilder(); |
|
440 | - $query->insert('federated_reshares') |
|
441 | - ->values( |
|
442 | - [ |
|
443 | - 'share_id' => $query->createNamedParameter($shareId), |
|
444 | - 'remote_id' => $query->createNamedParameter($remoteId), |
|
445 | - ] |
|
446 | - ); |
|
447 | - $query->execute(); |
|
448 | - } |
|
449 | - |
|
450 | - /** |
|
451 | - * get share ID on remote server for federated re-shares |
|
452 | - * |
|
453 | - * @param IShare $share |
|
454 | - * @return int |
|
455 | - * @throws ShareNotFound |
|
456 | - */ |
|
457 | - public function getRemoteId(IShare $share) { |
|
458 | - $query = $this->dbConnection->getQueryBuilder(); |
|
459 | - $query->select('remote_id')->from('federated_reshares') |
|
460 | - ->where($query->expr()->eq('share_id', $query->createNamedParameter((int)$share->getId()))); |
|
461 | - $data = $query->execute()->fetch(); |
|
462 | - |
|
463 | - if (!is_array($data) || !isset($data['remote_id'])) { |
|
464 | - throw new ShareNotFound(); |
|
465 | - } |
|
466 | - |
|
467 | - return (int)$data['remote_id']; |
|
468 | - } |
|
469 | - |
|
470 | - /** |
|
471 | - * @inheritdoc |
|
472 | - */ |
|
473 | - public function move(IShare $share, $recipient) { |
|
474 | - /* |
|
383 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
384 | + $qb->update('share') |
|
385 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
386 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
387 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
388 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
389 | + ->execute(); |
|
390 | + |
|
391 | + // send the updated permission to the owner/initiator, if they are not the same |
|
392 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
393 | + $this->sendPermissionUpdate($share); |
|
394 | + } |
|
395 | + |
|
396 | + return $share; |
|
397 | + } |
|
398 | + |
|
399 | + /** |
|
400 | + * send the updated permission to the owner/initiator, if they are not the same |
|
401 | + * |
|
402 | + * @param IShare $share |
|
403 | + * @throws ShareNotFound |
|
404 | + * @throws \OC\HintException |
|
405 | + */ |
|
406 | + protected function sendPermissionUpdate(IShare $share) { |
|
407 | + $remoteId = $this->getRemoteId($share); |
|
408 | + // if the local user is the owner we send the permission change to the initiator |
|
409 | + if ($this->userManager->userExists($share->getShareOwner())) { |
|
410 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
411 | + } else { // ... if not we send the permission change to the owner |
|
412 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
413 | + } |
|
414 | + $this->notifications->sendPermissionChange($remote, $remoteId, $share->getToken(), $share->getPermissions()); |
|
415 | + } |
|
416 | + |
|
417 | + |
|
418 | + /** |
|
419 | + * update successful reShare with the correct token |
|
420 | + * |
|
421 | + * @param int $shareId |
|
422 | + * @param string $token |
|
423 | + */ |
|
424 | + protected function updateSuccessfulReShare($shareId, $token) { |
|
425 | + $query = $this->dbConnection->getQueryBuilder(); |
|
426 | + $query->update('share') |
|
427 | + ->where($query->expr()->eq('id', $query->createNamedParameter($shareId))) |
|
428 | + ->set('token', $query->createNamedParameter($token)) |
|
429 | + ->execute(); |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * store remote ID in federated reShare table |
|
434 | + * |
|
435 | + * @param $shareId |
|
436 | + * @param $remoteId |
|
437 | + */ |
|
438 | + public function storeRemoteId($shareId, $remoteId) { |
|
439 | + $query = $this->dbConnection->getQueryBuilder(); |
|
440 | + $query->insert('federated_reshares') |
|
441 | + ->values( |
|
442 | + [ |
|
443 | + 'share_id' => $query->createNamedParameter($shareId), |
|
444 | + 'remote_id' => $query->createNamedParameter($remoteId), |
|
445 | + ] |
|
446 | + ); |
|
447 | + $query->execute(); |
|
448 | + } |
|
449 | + |
|
450 | + /** |
|
451 | + * get share ID on remote server for federated re-shares |
|
452 | + * |
|
453 | + * @param IShare $share |
|
454 | + * @return int |
|
455 | + * @throws ShareNotFound |
|
456 | + */ |
|
457 | + public function getRemoteId(IShare $share) { |
|
458 | + $query = $this->dbConnection->getQueryBuilder(); |
|
459 | + $query->select('remote_id')->from('federated_reshares') |
|
460 | + ->where($query->expr()->eq('share_id', $query->createNamedParameter((int)$share->getId()))); |
|
461 | + $data = $query->execute()->fetch(); |
|
462 | + |
|
463 | + if (!is_array($data) || !isset($data['remote_id'])) { |
|
464 | + throw new ShareNotFound(); |
|
465 | + } |
|
466 | + |
|
467 | + return (int)$data['remote_id']; |
|
468 | + } |
|
469 | + |
|
470 | + /** |
|
471 | + * @inheritdoc |
|
472 | + */ |
|
473 | + public function move(IShare $share, $recipient) { |
|
474 | + /* |
|
475 | 475 | * This function does nothing yet as it is just for outgoing |
476 | 476 | * federated shares. |
477 | 477 | */ |
478 | - return $share; |
|
479 | - } |
|
480 | - |
|
481 | - /** |
|
482 | - * Get all children of this share |
|
483 | - * |
|
484 | - * @param IShare $parent |
|
485 | - * @return IShare[] |
|
486 | - */ |
|
487 | - public function getChildren(IShare $parent) { |
|
488 | - $children = []; |
|
489 | - |
|
490 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
491 | - $qb->select('*') |
|
492 | - ->from('share') |
|
493 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
494 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
495 | - ->orderBy('id'); |
|
496 | - |
|
497 | - $cursor = $qb->execute(); |
|
498 | - while($data = $cursor->fetch()) { |
|
499 | - $children[] = $this->createShareObject($data); |
|
500 | - } |
|
501 | - $cursor->closeCursor(); |
|
502 | - |
|
503 | - return $children; |
|
504 | - } |
|
505 | - |
|
506 | - /** |
|
507 | - * Delete a share (owner unShares the file) |
|
508 | - * |
|
509 | - * @param IShare $share |
|
510 | - * @throws ShareNotFound |
|
511 | - * @throws \OC\HintException |
|
512 | - */ |
|
513 | - public function delete(IShare $share) { |
|
514 | - |
|
515 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedWith()); |
|
516 | - |
|
517 | - // if the local user is the owner we can send the unShare request directly... |
|
518 | - if ($this->userManager->userExists($share->getShareOwner())) { |
|
519 | - $this->notifications->sendRemoteUnShare($remote, $share->getId(), $share->getToken()); |
|
520 | - $this->revokeShare($share, true); |
|
521 | - } else { // ... if not we need to correct ID for the unShare request |
|
522 | - $remoteId = $this->getRemoteId($share); |
|
523 | - $this->notifications->sendRemoteUnShare($remote, $remoteId, $share->getToken()); |
|
524 | - $this->revokeShare($share, false); |
|
525 | - } |
|
526 | - |
|
527 | - // only remove the share when all messages are send to not lose information |
|
528 | - // about the share to early |
|
529 | - $this->removeShareFromTable($share); |
|
530 | - } |
|
531 | - |
|
532 | - /** |
|
533 | - * in case of a re-share we need to send the other use (initiator or owner) |
|
534 | - * a message that the file was unshared |
|
535 | - * |
|
536 | - * @param IShare $share |
|
537 | - * @param bool $isOwner the user can either be the owner or the user who re-sahred it |
|
538 | - * @throws ShareNotFound |
|
539 | - * @throws \OC\HintException |
|
540 | - */ |
|
541 | - protected function revokeShare($share, $isOwner) { |
|
542 | - // also send a unShare request to the initiator, if this is a different user than the owner |
|
543 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
544 | - if ($isOwner) { |
|
545 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
546 | - } else { |
|
547 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
548 | - } |
|
549 | - $remoteId = $this->getRemoteId($share); |
|
550 | - $this->notifications->sendRevokeShare($remote, $remoteId, $share->getToken()); |
|
551 | - } |
|
552 | - } |
|
553 | - |
|
554 | - /** |
|
555 | - * remove share from table |
|
556 | - * |
|
557 | - * @param IShare $share |
|
558 | - */ |
|
559 | - public function removeShareFromTable(IShare $share) { |
|
560 | - $this->removeShareFromTableById($share->getId()); |
|
561 | - } |
|
562 | - |
|
563 | - /** |
|
564 | - * remove share from table |
|
565 | - * |
|
566 | - * @param string $shareId |
|
567 | - */ |
|
568 | - private function removeShareFromTableById($shareId) { |
|
569 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
570 | - $qb->delete('share') |
|
571 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
572 | - $qb->execute(); |
|
573 | - |
|
574 | - $qb->delete('federated_reshares') |
|
575 | - ->where($qb->expr()->eq('share_id', $qb->createNamedParameter($shareId))); |
|
576 | - $qb->execute(); |
|
577 | - } |
|
578 | - |
|
579 | - /** |
|
580 | - * @inheritdoc |
|
581 | - */ |
|
582 | - public function deleteFromSelf(IShare $share, $recipient) { |
|
583 | - // nothing to do here. Technically deleteFromSelf in the context of federated |
|
584 | - // shares is a umount of a external storage. This is handled here |
|
585 | - // apps/files_sharing/lib/external/manager.php |
|
586 | - // TODO move this code over to this app |
|
587 | - } |
|
588 | - |
|
589 | - |
|
590 | - public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
591 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
592 | - $qb->select('*') |
|
593 | - ->from('share', 's') |
|
594 | - ->andWhere($qb->expr()->orX( |
|
595 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
596 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
597 | - )) |
|
598 | - ->andWhere( |
|
599 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE)) |
|
600 | - ); |
|
601 | - |
|
602 | - /** |
|
603 | - * Reshares for this user are shares where they are the owner. |
|
604 | - */ |
|
605 | - if ($reshares === false) { |
|
606 | - $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
607 | - } else { |
|
608 | - $qb->andWhere( |
|
609 | - $qb->expr()->orX( |
|
610 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
611 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
612 | - ) |
|
613 | - ); |
|
614 | - } |
|
615 | - |
|
616 | - $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
617 | - $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
618 | - |
|
619 | - $qb->orderBy('id'); |
|
620 | - |
|
621 | - $cursor = $qb->execute(); |
|
622 | - $shares = []; |
|
623 | - while ($data = $cursor->fetch()) { |
|
624 | - $shares[$data['fileid']][] = $this->createShareObject($data); |
|
625 | - } |
|
626 | - $cursor->closeCursor(); |
|
627 | - |
|
628 | - return $shares; |
|
629 | - } |
|
630 | - |
|
631 | - /** |
|
632 | - * @inheritdoc |
|
633 | - */ |
|
634 | - public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
635 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
636 | - $qb->select('*') |
|
637 | - ->from('share'); |
|
638 | - |
|
639 | - $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
640 | - |
|
641 | - /** |
|
642 | - * Reshares for this user are shares where they are the owner. |
|
643 | - */ |
|
644 | - if ($reshares === false) { |
|
645 | - //Special case for old shares created via the web UI |
|
646 | - $or1 = $qb->expr()->andX( |
|
647 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
648 | - $qb->expr()->isNull('uid_initiator') |
|
649 | - ); |
|
650 | - |
|
651 | - $qb->andWhere( |
|
652 | - $qb->expr()->orX( |
|
653 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
654 | - $or1 |
|
655 | - ) |
|
656 | - ); |
|
657 | - } else { |
|
658 | - $qb->andWhere( |
|
659 | - $qb->expr()->orX( |
|
660 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
661 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
662 | - ) |
|
663 | - ); |
|
664 | - } |
|
665 | - |
|
666 | - if ($node !== null) { |
|
667 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
668 | - } |
|
669 | - |
|
670 | - if ($limit !== -1) { |
|
671 | - $qb->setMaxResults($limit); |
|
672 | - } |
|
673 | - |
|
674 | - $qb->setFirstResult($offset); |
|
675 | - $qb->orderBy('id'); |
|
676 | - |
|
677 | - $cursor = $qb->execute(); |
|
678 | - $shares = []; |
|
679 | - while($data = $cursor->fetch()) { |
|
680 | - $shares[] = $this->createShareObject($data); |
|
681 | - } |
|
682 | - $cursor->closeCursor(); |
|
683 | - |
|
684 | - return $shares; |
|
685 | - } |
|
686 | - |
|
687 | - /** |
|
688 | - * @inheritdoc |
|
689 | - */ |
|
690 | - public function getShareById($id, $recipientId = null) { |
|
691 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
692 | - |
|
693 | - $qb->select('*') |
|
694 | - ->from('share') |
|
695 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
696 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
697 | - |
|
698 | - $cursor = $qb->execute(); |
|
699 | - $data = $cursor->fetch(); |
|
700 | - $cursor->closeCursor(); |
|
701 | - |
|
702 | - if ($data === false) { |
|
703 | - throw new ShareNotFound('Can not find share with ID: ' . $id); |
|
704 | - } |
|
705 | - |
|
706 | - try { |
|
707 | - $share = $this->createShareObject($data); |
|
708 | - } catch (InvalidShare $e) { |
|
709 | - throw new ShareNotFound(); |
|
710 | - } |
|
711 | - |
|
712 | - return $share; |
|
713 | - } |
|
714 | - |
|
715 | - /** |
|
716 | - * Get shares for a given path |
|
717 | - * |
|
718 | - * @param \OCP\Files\Node $path |
|
719 | - * @return IShare[] |
|
720 | - */ |
|
721 | - public function getSharesByPath(Node $path) { |
|
722 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
723 | - |
|
724 | - $cursor = $qb->select('*') |
|
725 | - ->from('share') |
|
726 | - ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
727 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
728 | - ->execute(); |
|
729 | - |
|
730 | - $shares = []; |
|
731 | - while($data = $cursor->fetch()) { |
|
732 | - $shares[] = $this->createShareObject($data); |
|
733 | - } |
|
734 | - $cursor->closeCursor(); |
|
735 | - |
|
736 | - return $shares; |
|
737 | - } |
|
738 | - |
|
739 | - /** |
|
740 | - * @inheritdoc |
|
741 | - */ |
|
742 | - public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
743 | - /** @var IShare[] $shares */ |
|
744 | - $shares = []; |
|
745 | - |
|
746 | - //Get shares directly with this user |
|
747 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
748 | - $qb->select('*') |
|
749 | - ->from('share'); |
|
750 | - |
|
751 | - // Order by id |
|
752 | - $qb->orderBy('id'); |
|
753 | - |
|
754 | - // Set limit and offset |
|
755 | - if ($limit !== -1) { |
|
756 | - $qb->setMaxResults($limit); |
|
757 | - } |
|
758 | - $qb->setFirstResult($offset); |
|
759 | - |
|
760 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
761 | - $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
762 | - |
|
763 | - // Filter by node if provided |
|
764 | - if ($node !== null) { |
|
765 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
766 | - } |
|
767 | - |
|
768 | - $cursor = $qb->execute(); |
|
769 | - |
|
770 | - while($data = $cursor->fetch()) { |
|
771 | - $shares[] = $this->createShareObject($data); |
|
772 | - } |
|
773 | - $cursor->closeCursor(); |
|
774 | - |
|
775 | - |
|
776 | - return $shares; |
|
777 | - } |
|
778 | - |
|
779 | - /** |
|
780 | - * Get a share by token |
|
781 | - * |
|
782 | - * @param string $token |
|
783 | - * @return IShare |
|
784 | - * @throws ShareNotFound |
|
785 | - */ |
|
786 | - public function getShareByToken($token) { |
|
787 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
788 | - |
|
789 | - $cursor = $qb->select('*') |
|
790 | - ->from('share') |
|
791 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
792 | - ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
793 | - ->execute(); |
|
794 | - |
|
795 | - $data = $cursor->fetch(); |
|
796 | - |
|
797 | - if ($data === false) { |
|
798 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
799 | - } |
|
800 | - |
|
801 | - try { |
|
802 | - $share = $this->createShareObject($data); |
|
803 | - } catch (InvalidShare $e) { |
|
804 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
805 | - } |
|
806 | - |
|
807 | - return $share; |
|
808 | - } |
|
809 | - |
|
810 | - /** |
|
811 | - * get database row of a give share |
|
812 | - * |
|
813 | - * @param $id |
|
814 | - * @return array |
|
815 | - * @throws ShareNotFound |
|
816 | - */ |
|
817 | - private function getRawShare($id) { |
|
818 | - |
|
819 | - // Now fetch the inserted share and create a complete share object |
|
820 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
821 | - $qb->select('*') |
|
822 | - ->from('share') |
|
823 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
824 | - |
|
825 | - $cursor = $qb->execute(); |
|
826 | - $data = $cursor->fetch(); |
|
827 | - $cursor->closeCursor(); |
|
828 | - |
|
829 | - if ($data === false) { |
|
830 | - throw new ShareNotFound; |
|
831 | - } |
|
832 | - |
|
833 | - return $data; |
|
834 | - } |
|
835 | - |
|
836 | - /** |
|
837 | - * Create a share object from an database row |
|
838 | - * |
|
839 | - * @param array $data |
|
840 | - * @return IShare |
|
841 | - * @throws InvalidShare |
|
842 | - * @throws ShareNotFound |
|
843 | - */ |
|
844 | - private function createShareObject($data) { |
|
845 | - |
|
846 | - $share = new Share($this->rootFolder, $this->userManager); |
|
847 | - $share->setId((int)$data['id']) |
|
848 | - ->setShareType((int)$data['share_type']) |
|
849 | - ->setPermissions((int)$data['permissions']) |
|
850 | - ->setTarget($data['file_target']) |
|
851 | - ->setMailSend((bool)$data['mail_send']) |
|
852 | - ->setToken($data['token']); |
|
853 | - |
|
854 | - $shareTime = new \DateTime(); |
|
855 | - $shareTime->setTimestamp((int)$data['stime']); |
|
856 | - $share->setShareTime($shareTime); |
|
857 | - $share->setSharedWith($data['share_with']); |
|
858 | - |
|
859 | - if ($data['uid_initiator'] !== null) { |
|
860 | - $share->setShareOwner($data['uid_owner']); |
|
861 | - $share->setSharedBy($data['uid_initiator']); |
|
862 | - } else { |
|
863 | - //OLD SHARE |
|
864 | - $share->setSharedBy($data['uid_owner']); |
|
865 | - $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
866 | - |
|
867 | - $owner = $path->getOwner(); |
|
868 | - $share->setShareOwner($owner->getUID()); |
|
869 | - } |
|
870 | - |
|
871 | - $share->setNodeId((int)$data['file_source']); |
|
872 | - $share->setNodeType($data['item_type']); |
|
873 | - |
|
874 | - $share->setProviderId($this->identifier()); |
|
875 | - |
|
876 | - return $share; |
|
877 | - } |
|
878 | - |
|
879 | - /** |
|
880 | - * Get the node with file $id for $user |
|
881 | - * |
|
882 | - * @param string $userId |
|
883 | - * @param int $id |
|
884 | - * @return \OCP\Files\File|\OCP\Files\Folder |
|
885 | - * @throws InvalidShare |
|
886 | - */ |
|
887 | - private function getNode($userId, $id) { |
|
888 | - try { |
|
889 | - $userFolder = $this->rootFolder->getUserFolder($userId); |
|
890 | - } catch (NotFoundException $e) { |
|
891 | - throw new InvalidShare(); |
|
892 | - } |
|
893 | - |
|
894 | - $nodes = $userFolder->getById($id); |
|
895 | - |
|
896 | - if (empty($nodes)) { |
|
897 | - throw new InvalidShare(); |
|
898 | - } |
|
899 | - |
|
900 | - return $nodes[0]; |
|
901 | - } |
|
902 | - |
|
903 | - /** |
|
904 | - * A user is deleted from the system |
|
905 | - * So clean up the relevant shares. |
|
906 | - * |
|
907 | - * @param string $uid |
|
908 | - * @param int $shareType |
|
909 | - */ |
|
910 | - public function userDeleted($uid, $shareType) { |
|
911 | - //TODO: probabaly a good idea to send unshare info to remote servers |
|
912 | - |
|
913 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
914 | - |
|
915 | - $qb->delete('share') |
|
916 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE))) |
|
917 | - ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
918 | - ->execute(); |
|
919 | - } |
|
920 | - |
|
921 | - /** |
|
922 | - * This provider does not handle groups |
|
923 | - * |
|
924 | - * @param string $gid |
|
925 | - */ |
|
926 | - public function groupDeleted($gid) { |
|
927 | - // We don't handle groups here |
|
928 | - } |
|
929 | - |
|
930 | - /** |
|
931 | - * This provider does not handle groups |
|
932 | - * |
|
933 | - * @param string $uid |
|
934 | - * @param string $gid |
|
935 | - */ |
|
936 | - public function userDeletedFromGroup($uid, $gid) { |
|
937 | - // We don't handle groups here |
|
938 | - } |
|
939 | - |
|
940 | - /** |
|
941 | - * check if users from other Nextcloud instances are allowed to mount public links share by this instance |
|
942 | - * |
|
943 | - * @return bool |
|
944 | - */ |
|
945 | - public function isOutgoingServer2serverShareEnabled() { |
|
946 | - if ($this->gsConfig->onlyInternalFederation()) { |
|
947 | - return false; |
|
948 | - } |
|
949 | - $result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes'); |
|
950 | - return ($result === 'yes'); |
|
951 | - } |
|
952 | - |
|
953 | - /** |
|
954 | - * check if users are allowed to mount public links from other Nextclouds |
|
955 | - * |
|
956 | - * @return bool |
|
957 | - */ |
|
958 | - public function isIncomingServer2serverShareEnabled() { |
|
959 | - if ($this->gsConfig->onlyInternalFederation()) { |
|
960 | - return false; |
|
961 | - } |
|
962 | - $result = $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes'); |
|
963 | - return ($result === 'yes'); |
|
964 | - } |
|
965 | - |
|
966 | - /** |
|
967 | - * Check if querying sharees on the lookup server is enabled |
|
968 | - * |
|
969 | - * @return bool |
|
970 | - */ |
|
971 | - public function isLookupServerQueriesEnabled() { |
|
972 | - // in a global scale setup we should always query the lookup server |
|
973 | - if ($this->gsConfig->isGlobalScaleEnabled()) { |
|
974 | - return true; |
|
975 | - } |
|
976 | - $result = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no'); |
|
977 | - return ($result === 'yes'); |
|
978 | - } |
|
979 | - |
|
980 | - |
|
981 | - /** |
|
982 | - * Check if it is allowed to publish user specific data to the lookup server |
|
983 | - * |
|
984 | - * @return bool |
|
985 | - */ |
|
986 | - public function isLookupServerUploadEnabled() { |
|
987 | - // in a global scale setup the admin is responsible to keep the lookup server up-to-date |
|
988 | - if ($this->gsConfig->isGlobalScaleEnabled()) { |
|
989 | - return false; |
|
990 | - } |
|
991 | - $result = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes'); |
|
992 | - return ($result === 'yes'); |
|
993 | - } |
|
994 | - |
|
995 | - /** |
|
996 | - * @inheritdoc |
|
997 | - */ |
|
998 | - public function getAccessList($nodes, $currentAccess) { |
|
999 | - $ids = []; |
|
1000 | - foreach ($nodes as $node) { |
|
1001 | - $ids[] = $node->getId(); |
|
1002 | - } |
|
1003 | - |
|
1004 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
1005 | - $qb->select('share_with', 'token', 'file_source') |
|
1006 | - ->from('share') |
|
1007 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE))) |
|
1008 | - ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
1009 | - ->andWhere($qb->expr()->orX( |
|
1010 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
1011 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
1012 | - )); |
|
1013 | - $cursor = $qb->execute(); |
|
1014 | - |
|
1015 | - if ($currentAccess === false) { |
|
1016 | - $remote = $cursor->fetch() !== false; |
|
1017 | - $cursor->closeCursor(); |
|
1018 | - |
|
1019 | - return ['remote' => $remote]; |
|
1020 | - } |
|
1021 | - |
|
1022 | - $remote = []; |
|
1023 | - while ($row = $cursor->fetch()) { |
|
1024 | - $remote[$row['share_with']] = [ |
|
1025 | - 'node_id' => $row['file_source'], |
|
1026 | - 'token' => $row['token'], |
|
1027 | - ]; |
|
1028 | - } |
|
1029 | - $cursor->closeCursor(); |
|
1030 | - |
|
1031 | - return ['remote' => $remote]; |
|
1032 | - } |
|
478 | + return $share; |
|
479 | + } |
|
480 | + |
|
481 | + /** |
|
482 | + * Get all children of this share |
|
483 | + * |
|
484 | + * @param IShare $parent |
|
485 | + * @return IShare[] |
|
486 | + */ |
|
487 | + public function getChildren(IShare $parent) { |
|
488 | + $children = []; |
|
489 | + |
|
490 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
491 | + $qb->select('*') |
|
492 | + ->from('share') |
|
493 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
494 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
495 | + ->orderBy('id'); |
|
496 | + |
|
497 | + $cursor = $qb->execute(); |
|
498 | + while($data = $cursor->fetch()) { |
|
499 | + $children[] = $this->createShareObject($data); |
|
500 | + } |
|
501 | + $cursor->closeCursor(); |
|
502 | + |
|
503 | + return $children; |
|
504 | + } |
|
505 | + |
|
506 | + /** |
|
507 | + * Delete a share (owner unShares the file) |
|
508 | + * |
|
509 | + * @param IShare $share |
|
510 | + * @throws ShareNotFound |
|
511 | + * @throws \OC\HintException |
|
512 | + */ |
|
513 | + public function delete(IShare $share) { |
|
514 | + |
|
515 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedWith()); |
|
516 | + |
|
517 | + // if the local user is the owner we can send the unShare request directly... |
|
518 | + if ($this->userManager->userExists($share->getShareOwner())) { |
|
519 | + $this->notifications->sendRemoteUnShare($remote, $share->getId(), $share->getToken()); |
|
520 | + $this->revokeShare($share, true); |
|
521 | + } else { // ... if not we need to correct ID for the unShare request |
|
522 | + $remoteId = $this->getRemoteId($share); |
|
523 | + $this->notifications->sendRemoteUnShare($remote, $remoteId, $share->getToken()); |
|
524 | + $this->revokeShare($share, false); |
|
525 | + } |
|
526 | + |
|
527 | + // only remove the share when all messages are send to not lose information |
|
528 | + // about the share to early |
|
529 | + $this->removeShareFromTable($share); |
|
530 | + } |
|
531 | + |
|
532 | + /** |
|
533 | + * in case of a re-share we need to send the other use (initiator or owner) |
|
534 | + * a message that the file was unshared |
|
535 | + * |
|
536 | + * @param IShare $share |
|
537 | + * @param bool $isOwner the user can either be the owner or the user who re-sahred it |
|
538 | + * @throws ShareNotFound |
|
539 | + * @throws \OC\HintException |
|
540 | + */ |
|
541 | + protected function revokeShare($share, $isOwner) { |
|
542 | + // also send a unShare request to the initiator, if this is a different user than the owner |
|
543 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
544 | + if ($isOwner) { |
|
545 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
546 | + } else { |
|
547 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
548 | + } |
|
549 | + $remoteId = $this->getRemoteId($share); |
|
550 | + $this->notifications->sendRevokeShare($remote, $remoteId, $share->getToken()); |
|
551 | + } |
|
552 | + } |
|
553 | + |
|
554 | + /** |
|
555 | + * remove share from table |
|
556 | + * |
|
557 | + * @param IShare $share |
|
558 | + */ |
|
559 | + public function removeShareFromTable(IShare $share) { |
|
560 | + $this->removeShareFromTableById($share->getId()); |
|
561 | + } |
|
562 | + |
|
563 | + /** |
|
564 | + * remove share from table |
|
565 | + * |
|
566 | + * @param string $shareId |
|
567 | + */ |
|
568 | + private function removeShareFromTableById($shareId) { |
|
569 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
570 | + $qb->delete('share') |
|
571 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
572 | + $qb->execute(); |
|
573 | + |
|
574 | + $qb->delete('federated_reshares') |
|
575 | + ->where($qb->expr()->eq('share_id', $qb->createNamedParameter($shareId))); |
|
576 | + $qb->execute(); |
|
577 | + } |
|
578 | + |
|
579 | + /** |
|
580 | + * @inheritdoc |
|
581 | + */ |
|
582 | + public function deleteFromSelf(IShare $share, $recipient) { |
|
583 | + // nothing to do here. Technically deleteFromSelf in the context of federated |
|
584 | + // shares is a umount of a external storage. This is handled here |
|
585 | + // apps/files_sharing/lib/external/manager.php |
|
586 | + // TODO move this code over to this app |
|
587 | + } |
|
588 | + |
|
589 | + |
|
590 | + public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
591 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
592 | + $qb->select('*') |
|
593 | + ->from('share', 's') |
|
594 | + ->andWhere($qb->expr()->orX( |
|
595 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
596 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
597 | + )) |
|
598 | + ->andWhere( |
|
599 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE)) |
|
600 | + ); |
|
601 | + |
|
602 | + /** |
|
603 | + * Reshares for this user are shares where they are the owner. |
|
604 | + */ |
|
605 | + if ($reshares === false) { |
|
606 | + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
607 | + } else { |
|
608 | + $qb->andWhere( |
|
609 | + $qb->expr()->orX( |
|
610 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
611 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
612 | + ) |
|
613 | + ); |
|
614 | + } |
|
615 | + |
|
616 | + $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
617 | + $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
618 | + |
|
619 | + $qb->orderBy('id'); |
|
620 | + |
|
621 | + $cursor = $qb->execute(); |
|
622 | + $shares = []; |
|
623 | + while ($data = $cursor->fetch()) { |
|
624 | + $shares[$data['fileid']][] = $this->createShareObject($data); |
|
625 | + } |
|
626 | + $cursor->closeCursor(); |
|
627 | + |
|
628 | + return $shares; |
|
629 | + } |
|
630 | + |
|
631 | + /** |
|
632 | + * @inheritdoc |
|
633 | + */ |
|
634 | + public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
635 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
636 | + $qb->select('*') |
|
637 | + ->from('share'); |
|
638 | + |
|
639 | + $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
640 | + |
|
641 | + /** |
|
642 | + * Reshares for this user are shares where they are the owner. |
|
643 | + */ |
|
644 | + if ($reshares === false) { |
|
645 | + //Special case for old shares created via the web UI |
|
646 | + $or1 = $qb->expr()->andX( |
|
647 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
648 | + $qb->expr()->isNull('uid_initiator') |
|
649 | + ); |
|
650 | + |
|
651 | + $qb->andWhere( |
|
652 | + $qb->expr()->orX( |
|
653 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
654 | + $or1 |
|
655 | + ) |
|
656 | + ); |
|
657 | + } else { |
|
658 | + $qb->andWhere( |
|
659 | + $qb->expr()->orX( |
|
660 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
661 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
662 | + ) |
|
663 | + ); |
|
664 | + } |
|
665 | + |
|
666 | + if ($node !== null) { |
|
667 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
668 | + } |
|
669 | + |
|
670 | + if ($limit !== -1) { |
|
671 | + $qb->setMaxResults($limit); |
|
672 | + } |
|
673 | + |
|
674 | + $qb->setFirstResult($offset); |
|
675 | + $qb->orderBy('id'); |
|
676 | + |
|
677 | + $cursor = $qb->execute(); |
|
678 | + $shares = []; |
|
679 | + while($data = $cursor->fetch()) { |
|
680 | + $shares[] = $this->createShareObject($data); |
|
681 | + } |
|
682 | + $cursor->closeCursor(); |
|
683 | + |
|
684 | + return $shares; |
|
685 | + } |
|
686 | + |
|
687 | + /** |
|
688 | + * @inheritdoc |
|
689 | + */ |
|
690 | + public function getShareById($id, $recipientId = null) { |
|
691 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
692 | + |
|
693 | + $qb->select('*') |
|
694 | + ->from('share') |
|
695 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
696 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
697 | + |
|
698 | + $cursor = $qb->execute(); |
|
699 | + $data = $cursor->fetch(); |
|
700 | + $cursor->closeCursor(); |
|
701 | + |
|
702 | + if ($data === false) { |
|
703 | + throw new ShareNotFound('Can not find share with ID: ' . $id); |
|
704 | + } |
|
705 | + |
|
706 | + try { |
|
707 | + $share = $this->createShareObject($data); |
|
708 | + } catch (InvalidShare $e) { |
|
709 | + throw new ShareNotFound(); |
|
710 | + } |
|
711 | + |
|
712 | + return $share; |
|
713 | + } |
|
714 | + |
|
715 | + /** |
|
716 | + * Get shares for a given path |
|
717 | + * |
|
718 | + * @param \OCP\Files\Node $path |
|
719 | + * @return IShare[] |
|
720 | + */ |
|
721 | + public function getSharesByPath(Node $path) { |
|
722 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
723 | + |
|
724 | + $cursor = $qb->select('*') |
|
725 | + ->from('share') |
|
726 | + ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
727 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
728 | + ->execute(); |
|
729 | + |
|
730 | + $shares = []; |
|
731 | + while($data = $cursor->fetch()) { |
|
732 | + $shares[] = $this->createShareObject($data); |
|
733 | + } |
|
734 | + $cursor->closeCursor(); |
|
735 | + |
|
736 | + return $shares; |
|
737 | + } |
|
738 | + |
|
739 | + /** |
|
740 | + * @inheritdoc |
|
741 | + */ |
|
742 | + public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
743 | + /** @var IShare[] $shares */ |
|
744 | + $shares = []; |
|
745 | + |
|
746 | + //Get shares directly with this user |
|
747 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
748 | + $qb->select('*') |
|
749 | + ->from('share'); |
|
750 | + |
|
751 | + // Order by id |
|
752 | + $qb->orderBy('id'); |
|
753 | + |
|
754 | + // Set limit and offset |
|
755 | + if ($limit !== -1) { |
|
756 | + $qb->setMaxResults($limit); |
|
757 | + } |
|
758 | + $qb->setFirstResult($offset); |
|
759 | + |
|
760 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
761 | + $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
762 | + |
|
763 | + // Filter by node if provided |
|
764 | + if ($node !== null) { |
|
765 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
766 | + } |
|
767 | + |
|
768 | + $cursor = $qb->execute(); |
|
769 | + |
|
770 | + while($data = $cursor->fetch()) { |
|
771 | + $shares[] = $this->createShareObject($data); |
|
772 | + } |
|
773 | + $cursor->closeCursor(); |
|
774 | + |
|
775 | + |
|
776 | + return $shares; |
|
777 | + } |
|
778 | + |
|
779 | + /** |
|
780 | + * Get a share by token |
|
781 | + * |
|
782 | + * @param string $token |
|
783 | + * @return IShare |
|
784 | + * @throws ShareNotFound |
|
785 | + */ |
|
786 | + public function getShareByToken($token) { |
|
787 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
788 | + |
|
789 | + $cursor = $qb->select('*') |
|
790 | + ->from('share') |
|
791 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
792 | + ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
793 | + ->execute(); |
|
794 | + |
|
795 | + $data = $cursor->fetch(); |
|
796 | + |
|
797 | + if ($data === false) { |
|
798 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
799 | + } |
|
800 | + |
|
801 | + try { |
|
802 | + $share = $this->createShareObject($data); |
|
803 | + } catch (InvalidShare $e) { |
|
804 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
805 | + } |
|
806 | + |
|
807 | + return $share; |
|
808 | + } |
|
809 | + |
|
810 | + /** |
|
811 | + * get database row of a give share |
|
812 | + * |
|
813 | + * @param $id |
|
814 | + * @return array |
|
815 | + * @throws ShareNotFound |
|
816 | + */ |
|
817 | + private function getRawShare($id) { |
|
818 | + |
|
819 | + // Now fetch the inserted share and create a complete share object |
|
820 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
821 | + $qb->select('*') |
|
822 | + ->from('share') |
|
823 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
824 | + |
|
825 | + $cursor = $qb->execute(); |
|
826 | + $data = $cursor->fetch(); |
|
827 | + $cursor->closeCursor(); |
|
828 | + |
|
829 | + if ($data === false) { |
|
830 | + throw new ShareNotFound; |
|
831 | + } |
|
832 | + |
|
833 | + return $data; |
|
834 | + } |
|
835 | + |
|
836 | + /** |
|
837 | + * Create a share object from an database row |
|
838 | + * |
|
839 | + * @param array $data |
|
840 | + * @return IShare |
|
841 | + * @throws InvalidShare |
|
842 | + * @throws ShareNotFound |
|
843 | + */ |
|
844 | + private function createShareObject($data) { |
|
845 | + |
|
846 | + $share = new Share($this->rootFolder, $this->userManager); |
|
847 | + $share->setId((int)$data['id']) |
|
848 | + ->setShareType((int)$data['share_type']) |
|
849 | + ->setPermissions((int)$data['permissions']) |
|
850 | + ->setTarget($data['file_target']) |
|
851 | + ->setMailSend((bool)$data['mail_send']) |
|
852 | + ->setToken($data['token']); |
|
853 | + |
|
854 | + $shareTime = new \DateTime(); |
|
855 | + $shareTime->setTimestamp((int)$data['stime']); |
|
856 | + $share->setShareTime($shareTime); |
|
857 | + $share->setSharedWith($data['share_with']); |
|
858 | + |
|
859 | + if ($data['uid_initiator'] !== null) { |
|
860 | + $share->setShareOwner($data['uid_owner']); |
|
861 | + $share->setSharedBy($data['uid_initiator']); |
|
862 | + } else { |
|
863 | + //OLD SHARE |
|
864 | + $share->setSharedBy($data['uid_owner']); |
|
865 | + $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
866 | + |
|
867 | + $owner = $path->getOwner(); |
|
868 | + $share->setShareOwner($owner->getUID()); |
|
869 | + } |
|
870 | + |
|
871 | + $share->setNodeId((int)$data['file_source']); |
|
872 | + $share->setNodeType($data['item_type']); |
|
873 | + |
|
874 | + $share->setProviderId($this->identifier()); |
|
875 | + |
|
876 | + return $share; |
|
877 | + } |
|
878 | + |
|
879 | + /** |
|
880 | + * Get the node with file $id for $user |
|
881 | + * |
|
882 | + * @param string $userId |
|
883 | + * @param int $id |
|
884 | + * @return \OCP\Files\File|\OCP\Files\Folder |
|
885 | + * @throws InvalidShare |
|
886 | + */ |
|
887 | + private function getNode($userId, $id) { |
|
888 | + try { |
|
889 | + $userFolder = $this->rootFolder->getUserFolder($userId); |
|
890 | + } catch (NotFoundException $e) { |
|
891 | + throw new InvalidShare(); |
|
892 | + } |
|
893 | + |
|
894 | + $nodes = $userFolder->getById($id); |
|
895 | + |
|
896 | + if (empty($nodes)) { |
|
897 | + throw new InvalidShare(); |
|
898 | + } |
|
899 | + |
|
900 | + return $nodes[0]; |
|
901 | + } |
|
902 | + |
|
903 | + /** |
|
904 | + * A user is deleted from the system |
|
905 | + * So clean up the relevant shares. |
|
906 | + * |
|
907 | + * @param string $uid |
|
908 | + * @param int $shareType |
|
909 | + */ |
|
910 | + public function userDeleted($uid, $shareType) { |
|
911 | + //TODO: probabaly a good idea to send unshare info to remote servers |
|
912 | + |
|
913 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
914 | + |
|
915 | + $qb->delete('share') |
|
916 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE))) |
|
917 | + ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
918 | + ->execute(); |
|
919 | + } |
|
920 | + |
|
921 | + /** |
|
922 | + * This provider does not handle groups |
|
923 | + * |
|
924 | + * @param string $gid |
|
925 | + */ |
|
926 | + public function groupDeleted($gid) { |
|
927 | + // We don't handle groups here |
|
928 | + } |
|
929 | + |
|
930 | + /** |
|
931 | + * This provider does not handle groups |
|
932 | + * |
|
933 | + * @param string $uid |
|
934 | + * @param string $gid |
|
935 | + */ |
|
936 | + public function userDeletedFromGroup($uid, $gid) { |
|
937 | + // We don't handle groups here |
|
938 | + } |
|
939 | + |
|
940 | + /** |
|
941 | + * check if users from other Nextcloud instances are allowed to mount public links share by this instance |
|
942 | + * |
|
943 | + * @return bool |
|
944 | + */ |
|
945 | + public function isOutgoingServer2serverShareEnabled() { |
|
946 | + if ($this->gsConfig->onlyInternalFederation()) { |
|
947 | + return false; |
|
948 | + } |
|
949 | + $result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes'); |
|
950 | + return ($result === 'yes'); |
|
951 | + } |
|
952 | + |
|
953 | + /** |
|
954 | + * check if users are allowed to mount public links from other Nextclouds |
|
955 | + * |
|
956 | + * @return bool |
|
957 | + */ |
|
958 | + public function isIncomingServer2serverShareEnabled() { |
|
959 | + if ($this->gsConfig->onlyInternalFederation()) { |
|
960 | + return false; |
|
961 | + } |
|
962 | + $result = $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes'); |
|
963 | + return ($result === 'yes'); |
|
964 | + } |
|
965 | + |
|
966 | + /** |
|
967 | + * Check if querying sharees on the lookup server is enabled |
|
968 | + * |
|
969 | + * @return bool |
|
970 | + */ |
|
971 | + public function isLookupServerQueriesEnabled() { |
|
972 | + // in a global scale setup we should always query the lookup server |
|
973 | + if ($this->gsConfig->isGlobalScaleEnabled()) { |
|
974 | + return true; |
|
975 | + } |
|
976 | + $result = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no'); |
|
977 | + return ($result === 'yes'); |
|
978 | + } |
|
979 | + |
|
980 | + |
|
981 | + /** |
|
982 | + * Check if it is allowed to publish user specific data to the lookup server |
|
983 | + * |
|
984 | + * @return bool |
|
985 | + */ |
|
986 | + public function isLookupServerUploadEnabled() { |
|
987 | + // in a global scale setup the admin is responsible to keep the lookup server up-to-date |
|
988 | + if ($this->gsConfig->isGlobalScaleEnabled()) { |
|
989 | + return false; |
|
990 | + } |
|
991 | + $result = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes'); |
|
992 | + return ($result === 'yes'); |
|
993 | + } |
|
994 | + |
|
995 | + /** |
|
996 | + * @inheritdoc |
|
997 | + */ |
|
998 | + public function getAccessList($nodes, $currentAccess) { |
|
999 | + $ids = []; |
|
1000 | + foreach ($nodes as $node) { |
|
1001 | + $ids[] = $node->getId(); |
|
1002 | + } |
|
1003 | + |
|
1004 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
1005 | + $qb->select('share_with', 'token', 'file_source') |
|
1006 | + ->from('share') |
|
1007 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE))) |
|
1008 | + ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
1009 | + ->andWhere($qb->expr()->orX( |
|
1010 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
1011 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
1012 | + )); |
|
1013 | + $cursor = $qb->execute(); |
|
1014 | + |
|
1015 | + if ($currentAccess === false) { |
|
1016 | + $remote = $cursor->fetch() !== false; |
|
1017 | + $cursor->closeCursor(); |
|
1018 | + |
|
1019 | + return ['remote' => $remote]; |
|
1020 | + } |
|
1021 | + |
|
1022 | + $remote = []; |
|
1023 | + while ($row = $cursor->fetch()) { |
|
1024 | + $remote[$row['share_with']] = [ |
|
1025 | + 'node_id' => $row['file_source'], |
|
1026 | + 'token' => $row['token'], |
|
1027 | + ]; |
|
1028 | + } |
|
1029 | + $cursor->closeCursor(); |
|
1030 | + |
|
1031 | + return ['remote' => $remote]; |
|
1032 | + } |
|
1033 | 1033 | } |
@@ -32,36 +32,36 @@ |
||
32 | 32 | */ |
33 | 33 | class CloudFederationNotification implements ICloudFederationNotification { |
34 | 34 | |
35 | - private $message = []; |
|
35 | + private $message = []; |
|
36 | 36 | |
37 | - /** |
|
38 | - * add a message to the notification |
|
39 | - * |
|
40 | - * @param string $notificationType (e.g. SHARE_ACCEPTED) |
|
41 | - * @param string $resourceType (e.g. file, calendar, contact,...) |
|
42 | - * @param string $providerId id of the share |
|
43 | - * @param array $notification payload of the notification |
|
44 | - * |
|
45 | - * @since 14.0.0 |
|
46 | - */ |
|
47 | - public function setMessage($notificationType, $resourceType, $providerId, array $notification) { |
|
48 | - $this->message = [ |
|
49 | - 'notificationType' => $notificationType, |
|
50 | - 'resourceType' => $resourceType, |
|
51 | - 'providerId' => $providerId, |
|
52 | - 'notification' => $notification, |
|
53 | - ]; |
|
37 | + /** |
|
38 | + * add a message to the notification |
|
39 | + * |
|
40 | + * @param string $notificationType (e.g. SHARE_ACCEPTED) |
|
41 | + * @param string $resourceType (e.g. file, calendar, contact,...) |
|
42 | + * @param string $providerId id of the share |
|
43 | + * @param array $notification payload of the notification |
|
44 | + * |
|
45 | + * @since 14.0.0 |
|
46 | + */ |
|
47 | + public function setMessage($notificationType, $resourceType, $providerId, array $notification) { |
|
48 | + $this->message = [ |
|
49 | + 'notificationType' => $notificationType, |
|
50 | + 'resourceType' => $resourceType, |
|
51 | + 'providerId' => $providerId, |
|
52 | + 'notification' => $notification, |
|
53 | + ]; |
|
54 | 54 | |
55 | - } |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * get message, ready to send out |
|
59 | - * |
|
60 | - * @return array |
|
61 | - * |
|
62 | - * @since 14.0.0 |
|
63 | - */ |
|
64 | - public function getMessage() { |
|
65 | - return $this->message; |
|
66 | - } |
|
57 | + /** |
|
58 | + * get message, ready to send out |
|
59 | + * |
|
60 | + * @return array |
|
61 | + * |
|
62 | + * @since 14.0.0 |
|
63 | + */ |
|
64 | + public function getMessage() { |
|
65 | + return $this->message; |
|
66 | + } |
|
67 | 67 | } |
@@ -30,24 +30,24 @@ |
||
30 | 30 | */ |
31 | 31 | interface ICloudFederationNotification { |
32 | 32 | |
33 | - /** |
|
34 | - * add a message to the notification |
|
35 | - * |
|
36 | - * @param string $notificationType (e.g. SHARE_ACCEPTED) |
|
37 | - * @param string $resourceType (e.g. file, calendar, contact,...) |
|
38 | - * @param $providerId id of the share |
|
39 | - * @param array $notification , payload of the notification |
|
40 | - * |
|
41 | - * @since 14.0.0 |
|
42 | - */ |
|
43 | - public function setMessage($notificationType, $resourceType, $providerId, array $notification); |
|
33 | + /** |
|
34 | + * add a message to the notification |
|
35 | + * |
|
36 | + * @param string $notificationType (e.g. SHARE_ACCEPTED) |
|
37 | + * @param string $resourceType (e.g. file, calendar, contact,...) |
|
38 | + * @param $providerId id of the share |
|
39 | + * @param array $notification , payload of the notification |
|
40 | + * |
|
41 | + * @since 14.0.0 |
|
42 | + */ |
|
43 | + public function setMessage($notificationType, $resourceType, $providerId, array $notification); |
|
44 | 44 | |
45 | - /** |
|
46 | - * get message, ready to send out |
|
47 | - * |
|
48 | - * @return array |
|
49 | - * |
|
50 | - * @since 14.0.0 |
|
51 | - */ |
|
52 | - public function getMessage(); |
|
45 | + /** |
|
46 | + * get message, ready to send out |
|
47 | + * |
|
48 | + * @return array |
|
49 | + * |
|
50 | + * @since 14.0.0 |
|
51 | + */ |
|
52 | + public function getMessage(); |
|
53 | 53 | } |
@@ -30,221 +30,221 @@ |
||
30 | 30 | */ |
31 | 31 | interface ICloudFederationShare { |
32 | 32 | |
33 | - /** |
|
34 | - * set uid of the recipient |
|
35 | - * |
|
36 | - * @param string $user |
|
37 | - * |
|
38 | - * @since 14.0.0 |
|
39 | - */ |
|
40 | - public function setShareWith($user); |
|
41 | - |
|
42 | - /** |
|
43 | - * set resource name (e.g. file, calendar, contact,...) |
|
44 | - * |
|
45 | - * @param string $name |
|
46 | - * |
|
47 | - * @since 14.0.0 |
|
48 | - */ |
|
49 | - public function setResourceName($name); |
|
50 | - |
|
51 | - /** |
|
52 | - * set resource type (e.g. file, calendar, contact,...) |
|
53 | - * |
|
54 | - * @param string $resourceType |
|
55 | - * |
|
56 | - * @since 14.0.0 |
|
57 | - */ |
|
58 | - public function setResourceType($resourceType); |
|
59 | - |
|
60 | - /** |
|
61 | - * set resource description (optional) |
|
62 | - * |
|
63 | - * @param string $description |
|
64 | - * |
|
65 | - * @since 14.0.0 |
|
66 | - */ |
|
67 | - public function setDescription($description); |
|
68 | - |
|
69 | - /** |
|
70 | - * set provider ID (e.g. file ID) |
|
71 | - * |
|
72 | - * @param string $providerId |
|
73 | - * |
|
74 | - * @since 14.0.0 |
|
75 | - */ |
|
76 | - public function setProviderId($providerId); |
|
77 | - |
|
78 | - /** |
|
79 | - * set owner UID |
|
80 | - * |
|
81 | - * @param string $owner |
|
82 | - * |
|
83 | - * @since 14.0.0 |
|
84 | - */ |
|
85 | - public function setOwner($owner); |
|
86 | - |
|
87 | - /** |
|
88 | - * set owner display name |
|
89 | - * |
|
90 | - * @param string $ownerDisplayName |
|
91 | - * |
|
92 | - * @since 14.0.0 |
|
93 | - */ |
|
94 | - public function setOwnerDisplayName($ownerDisplayName); |
|
95 | - |
|
96 | - /** |
|
97 | - * set UID of the user who sends the share |
|
98 | - * |
|
99 | - * @param string $sharedBy |
|
100 | - * |
|
101 | - * @since 14.0.0 |
|
102 | - */ |
|
103 | - public function setSharedBy($sharedBy); |
|
104 | - |
|
105 | - /** |
|
106 | - * set display name of the user who sends the share |
|
107 | - * |
|
108 | - * @param $sharedByDisplayName |
|
109 | - * |
|
110 | - * @since 14.0.0 |
|
111 | - */ |
|
112 | - public function setSharedByDisplayName($sharedByDisplayName); |
|
113 | - |
|
114 | - /** |
|
115 | - * set protocol specification |
|
116 | - * |
|
117 | - * @param array $protocol |
|
118 | - * |
|
119 | - * @since 14.0.0 |
|
120 | - */ |
|
121 | - public function setProtocol(array $protocol); |
|
122 | - |
|
123 | - /** |
|
124 | - * share type (group or user) |
|
125 | - * |
|
126 | - * @param string $shareType |
|
127 | - * |
|
128 | - * @since 14.0.0 |
|
129 | - */ |
|
130 | - public function setShareType($shareType); |
|
131 | - |
|
132 | - /** |
|
133 | - * get the whole share, ready to send out |
|
134 | - * |
|
135 | - * @return array |
|
136 | - * |
|
137 | - * @since 14.0.0 |
|
138 | - */ |
|
139 | - public function getShare(); |
|
140 | - |
|
141 | - /** |
|
142 | - * get uid of the recipient |
|
143 | - * |
|
144 | - * @return string |
|
145 | - * |
|
146 | - * @since 14.0.0 |
|
147 | - */ |
|
148 | - public function getShareWith(); |
|
149 | - |
|
150 | - /** |
|
151 | - * get resource name (e.g. file, calendar, contact,...) |
|
152 | - * |
|
153 | - * @return string |
|
154 | - * |
|
155 | - * @since 14.0.0 |
|
156 | - */ |
|
157 | - public function getResourceName(); |
|
158 | - |
|
159 | - /** |
|
160 | - * get resource type (e.g. file, calendar, contact,...) |
|
161 | - * |
|
162 | - * @return string |
|
163 | - * |
|
164 | - * @since 14.0.0 |
|
165 | - */ |
|
166 | - public function getResourceType(); |
|
167 | - |
|
168 | - /** |
|
169 | - * get resource description (optional) |
|
170 | - * |
|
171 | - * @return string |
|
172 | - * |
|
173 | - * @since 14.0.0 |
|
174 | - */ |
|
175 | - public function getDescription(); |
|
176 | - |
|
177 | - /** |
|
178 | - * get provider ID (e.g. file ID) |
|
179 | - * |
|
180 | - * @return string |
|
181 | - * |
|
182 | - * @since 14.0.0 |
|
183 | - */ |
|
184 | - public function getProviderId(); |
|
185 | - |
|
186 | - /** |
|
187 | - * get owner UID |
|
188 | - * |
|
189 | - * @return string |
|
190 | - * |
|
191 | - * @since 14.0.0 |
|
192 | - */ |
|
193 | - public function getOwner(); |
|
194 | - |
|
195 | - /** |
|
196 | - * get owner display name |
|
197 | - * |
|
198 | - * @return string |
|
199 | - * |
|
200 | - * @since 14.0.0 |
|
201 | - */ |
|
202 | - public function getOwnerDisplayName(); |
|
203 | - |
|
204 | - /** |
|
205 | - * get UID of the user who sends the share |
|
206 | - * |
|
207 | - * @return string |
|
208 | - * |
|
209 | - * @since 14.0.0 |
|
210 | - */ |
|
211 | - public function getSharedBy(); |
|
212 | - |
|
213 | - /** |
|
214 | - * get display name of the user who sends the share |
|
215 | - * |
|
216 | - * @return string |
|
217 | - * |
|
218 | - * @since 14.0.0 |
|
219 | - */ |
|
220 | - public function getSharedByDisplayName(); |
|
221 | - |
|
222 | - /** |
|
223 | - * get share type (group or user) |
|
224 | - * |
|
225 | - * @return string |
|
226 | - * |
|
227 | - * @since 14.0.0 |
|
228 | - */ |
|
229 | - public function getShareType(); |
|
230 | - |
|
231 | - /** |
|
232 | - * get share Secret |
|
233 | - * |
|
234 | - * @return string |
|
235 | - * |
|
236 | - * @since 14.0.0 |
|
237 | - */ |
|
238 | - public function getShareSecret(); |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * get protocol specification |
|
243 | - * |
|
244 | - * @return array |
|
245 | - * |
|
246 | - * @since 14.0.0 |
|
247 | - */ |
|
248 | - public function getProtocol(); |
|
33 | + /** |
|
34 | + * set uid of the recipient |
|
35 | + * |
|
36 | + * @param string $user |
|
37 | + * |
|
38 | + * @since 14.0.0 |
|
39 | + */ |
|
40 | + public function setShareWith($user); |
|
41 | + |
|
42 | + /** |
|
43 | + * set resource name (e.g. file, calendar, contact,...) |
|
44 | + * |
|
45 | + * @param string $name |
|
46 | + * |
|
47 | + * @since 14.0.0 |
|
48 | + */ |
|
49 | + public function setResourceName($name); |
|
50 | + |
|
51 | + /** |
|
52 | + * set resource type (e.g. file, calendar, contact,...) |
|
53 | + * |
|
54 | + * @param string $resourceType |
|
55 | + * |
|
56 | + * @since 14.0.0 |
|
57 | + */ |
|
58 | + public function setResourceType($resourceType); |
|
59 | + |
|
60 | + /** |
|
61 | + * set resource description (optional) |
|
62 | + * |
|
63 | + * @param string $description |
|
64 | + * |
|
65 | + * @since 14.0.0 |
|
66 | + */ |
|
67 | + public function setDescription($description); |
|
68 | + |
|
69 | + /** |
|
70 | + * set provider ID (e.g. file ID) |
|
71 | + * |
|
72 | + * @param string $providerId |
|
73 | + * |
|
74 | + * @since 14.0.0 |
|
75 | + */ |
|
76 | + public function setProviderId($providerId); |
|
77 | + |
|
78 | + /** |
|
79 | + * set owner UID |
|
80 | + * |
|
81 | + * @param string $owner |
|
82 | + * |
|
83 | + * @since 14.0.0 |
|
84 | + */ |
|
85 | + public function setOwner($owner); |
|
86 | + |
|
87 | + /** |
|
88 | + * set owner display name |
|
89 | + * |
|
90 | + * @param string $ownerDisplayName |
|
91 | + * |
|
92 | + * @since 14.0.0 |
|
93 | + */ |
|
94 | + public function setOwnerDisplayName($ownerDisplayName); |
|
95 | + |
|
96 | + /** |
|
97 | + * set UID of the user who sends the share |
|
98 | + * |
|
99 | + * @param string $sharedBy |
|
100 | + * |
|
101 | + * @since 14.0.0 |
|
102 | + */ |
|
103 | + public function setSharedBy($sharedBy); |
|
104 | + |
|
105 | + /** |
|
106 | + * set display name of the user who sends the share |
|
107 | + * |
|
108 | + * @param $sharedByDisplayName |
|
109 | + * |
|
110 | + * @since 14.0.0 |
|
111 | + */ |
|
112 | + public function setSharedByDisplayName($sharedByDisplayName); |
|
113 | + |
|
114 | + /** |
|
115 | + * set protocol specification |
|
116 | + * |
|
117 | + * @param array $protocol |
|
118 | + * |
|
119 | + * @since 14.0.0 |
|
120 | + */ |
|
121 | + public function setProtocol(array $protocol); |
|
122 | + |
|
123 | + /** |
|
124 | + * share type (group or user) |
|
125 | + * |
|
126 | + * @param string $shareType |
|
127 | + * |
|
128 | + * @since 14.0.0 |
|
129 | + */ |
|
130 | + public function setShareType($shareType); |
|
131 | + |
|
132 | + /** |
|
133 | + * get the whole share, ready to send out |
|
134 | + * |
|
135 | + * @return array |
|
136 | + * |
|
137 | + * @since 14.0.0 |
|
138 | + */ |
|
139 | + public function getShare(); |
|
140 | + |
|
141 | + /** |
|
142 | + * get uid of the recipient |
|
143 | + * |
|
144 | + * @return string |
|
145 | + * |
|
146 | + * @since 14.0.0 |
|
147 | + */ |
|
148 | + public function getShareWith(); |
|
149 | + |
|
150 | + /** |
|
151 | + * get resource name (e.g. file, calendar, contact,...) |
|
152 | + * |
|
153 | + * @return string |
|
154 | + * |
|
155 | + * @since 14.0.0 |
|
156 | + */ |
|
157 | + public function getResourceName(); |
|
158 | + |
|
159 | + /** |
|
160 | + * get resource type (e.g. file, calendar, contact,...) |
|
161 | + * |
|
162 | + * @return string |
|
163 | + * |
|
164 | + * @since 14.0.0 |
|
165 | + */ |
|
166 | + public function getResourceType(); |
|
167 | + |
|
168 | + /** |
|
169 | + * get resource description (optional) |
|
170 | + * |
|
171 | + * @return string |
|
172 | + * |
|
173 | + * @since 14.0.0 |
|
174 | + */ |
|
175 | + public function getDescription(); |
|
176 | + |
|
177 | + /** |
|
178 | + * get provider ID (e.g. file ID) |
|
179 | + * |
|
180 | + * @return string |
|
181 | + * |
|
182 | + * @since 14.0.0 |
|
183 | + */ |
|
184 | + public function getProviderId(); |
|
185 | + |
|
186 | + /** |
|
187 | + * get owner UID |
|
188 | + * |
|
189 | + * @return string |
|
190 | + * |
|
191 | + * @since 14.0.0 |
|
192 | + */ |
|
193 | + public function getOwner(); |
|
194 | + |
|
195 | + /** |
|
196 | + * get owner display name |
|
197 | + * |
|
198 | + * @return string |
|
199 | + * |
|
200 | + * @since 14.0.0 |
|
201 | + */ |
|
202 | + public function getOwnerDisplayName(); |
|
203 | + |
|
204 | + /** |
|
205 | + * get UID of the user who sends the share |
|
206 | + * |
|
207 | + * @return string |
|
208 | + * |
|
209 | + * @since 14.0.0 |
|
210 | + */ |
|
211 | + public function getSharedBy(); |
|
212 | + |
|
213 | + /** |
|
214 | + * get display name of the user who sends the share |
|
215 | + * |
|
216 | + * @return string |
|
217 | + * |
|
218 | + * @since 14.0.0 |
|
219 | + */ |
|
220 | + public function getSharedByDisplayName(); |
|
221 | + |
|
222 | + /** |
|
223 | + * get share type (group or user) |
|
224 | + * |
|
225 | + * @return string |
|
226 | + * |
|
227 | + * @since 14.0.0 |
|
228 | + */ |
|
229 | + public function getShareType(); |
|
230 | + |
|
231 | + /** |
|
232 | + * get share Secret |
|
233 | + * |
|
234 | + * @return string |
|
235 | + * |
|
236 | + * @since 14.0.0 |
|
237 | + */ |
|
238 | + public function getShareSecret(); |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * get protocol specification |
|
243 | + * |
|
244 | + * @return array |
|
245 | + * |
|
246 | + * @since 14.0.0 |
|
247 | + */ |
|
248 | + public function getProtocol(); |
|
249 | 249 | |
250 | 250 | } |
@@ -33,19 +33,19 @@ |
||
33 | 33 | */ |
34 | 34 | class ProviderCouldNotAddShareException extends HintException { |
35 | 35 | |
36 | - /** |
|
37 | - * ProviderCouldNotAddShareException constructor. |
|
38 | - * |
|
39 | - * @since 14.0.0 |
|
40 | - * |
|
41 | - * @param string $message |
|
42 | - * @param string $hint |
|
43 | - * @param int $code |
|
44 | - * @param \Exception|null $previous |
|
45 | - */ |
|
46 | - public function __construct($message, $hint = '', $code = Http::STATUS_BAD_REQUEST, \Exception $previous = null) { |
|
47 | - parent::__construct($message, $hint, $code, $previous); |
|
48 | - } |
|
36 | + /** |
|
37 | + * ProviderCouldNotAddShareException constructor. |
|
38 | + * |
|
39 | + * @since 14.0.0 |
|
40 | + * |
|
41 | + * @param string $message |
|
42 | + * @param string $hint |
|
43 | + * @param int $code |
|
44 | + * @param \Exception|null $previous |
|
45 | + */ |
|
46 | + public function __construct($message, $hint = '', $code = Http::STATUS_BAD_REQUEST, \Exception $previous = null) { |
|
47 | + parent::__construct($message, $hint, $code, $previous); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | 51 | } |