@@ -165,6 +165,7 @@ discard block |
||
165 | 165 | * @param string $url |
166 | 166 | * @param string $sharedSecret |
167 | 167 | * @param string $resourcePath |
168 | + * @param string $userName |
|
168 | 169 | * @return array |
169 | 170 | */ |
170 | 171 | protected function download($url, $userName, $sharedSecret, $resourcePath) { |
@@ -265,7 +266,7 @@ discard block |
||
265 | 266 | } |
266 | 267 | |
267 | 268 | /** |
268 | - * @return array|null |
|
269 | + * @return string |
|
269 | 270 | */ |
270 | 271 | public function getLocalSystemAddressBook() { |
271 | 272 | if (is_null($this->localSystemAddressBook)) { |
@@ -37,267 +37,267 @@ |
||
37 | 37 | |
38 | 38 | class SyncService { |
39 | 39 | |
40 | - /** @var CardDavBackend */ |
|
41 | - private $backend; |
|
42 | - |
|
43 | - /** @var IUserManager */ |
|
44 | - private $userManager; |
|
45 | - |
|
46 | - /** @var ILogger */ |
|
47 | - private $logger; |
|
48 | - |
|
49 | - /** @var array */ |
|
50 | - private $localSystemAddressBook; |
|
51 | - |
|
52 | - /** @var AccountManager */ |
|
53 | - private $accountManager; |
|
54 | - |
|
55 | - /** |
|
56 | - * SyncService constructor. |
|
57 | - * |
|
58 | - * @param CardDavBackend $backend |
|
59 | - * @param IUserManager $userManager |
|
60 | - * @param ILogger $logger |
|
61 | - * @param AccountManager $accountManager |
|
62 | - */ |
|
63 | - public function __construct(CardDavBackend $backend, IUserManager $userManager, ILogger $logger, AccountManager $accountManager) { |
|
64 | - $this->backend = $backend; |
|
65 | - $this->userManager = $userManager; |
|
66 | - $this->logger = $logger; |
|
67 | - $this->accountManager = $accountManager; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @param string $url |
|
72 | - * @param string $userName |
|
73 | - * @param string $addressBookUrl |
|
74 | - * @param string $sharedSecret |
|
75 | - * @param string $syncToken |
|
76 | - * @param int $targetBookId |
|
77 | - * @param string $targetPrincipal |
|
78 | - * @param array $targetProperties |
|
79 | - * @return string |
|
80 | - * @throws \Exception |
|
81 | - */ |
|
82 | - public function syncRemoteAddressBook($url, $userName, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetProperties) { |
|
83 | - // 1. create addressbook |
|
84 | - $book = $this->ensureSystemAddressBookExists($targetPrincipal, $targetBookId, $targetProperties); |
|
85 | - $addressBookId = $book['id']; |
|
86 | - |
|
87 | - // 2. query changes |
|
88 | - try { |
|
89 | - $response = $this->requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken); |
|
90 | - } catch (ClientHttpException $ex) { |
|
91 | - if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { |
|
92 | - // remote server revoked access to the address book, remove it |
|
93 | - $this->backend->deleteAddressBook($addressBookId); |
|
94 | - $this->logger->info('Authorization failed, remove address book: ' . $url, ['app' => 'dav']); |
|
95 | - throw $ex; |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - // 3. apply changes |
|
100 | - // TODO: use multi-get for download |
|
101 | - foreach ($response['response'] as $resource => $status) { |
|
102 | - $cardUri = basename($resource); |
|
103 | - if (isset($status[200])) { |
|
104 | - $vCard = $this->download($url, $userName, $sharedSecret, $resource); |
|
105 | - $existingCard = $this->backend->getCard($addressBookId, $cardUri); |
|
106 | - if ($existingCard === false) { |
|
107 | - $this->backend->createCard($addressBookId, $cardUri, $vCard['body']); |
|
108 | - } else { |
|
109 | - $this->backend->updateCard($addressBookId, $cardUri, $vCard['body']); |
|
110 | - } |
|
111 | - } else { |
|
112 | - $this->backend->deleteCard($addressBookId, $cardUri); |
|
113 | - } |
|
114 | - } |
|
115 | - |
|
116 | - return $response['token']; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * @param string $principal |
|
121 | - * @param string $id |
|
122 | - * @param array $properties |
|
123 | - * @return array|null |
|
124 | - * @throws \Sabre\DAV\Exception\BadRequest |
|
125 | - */ |
|
126 | - public function ensureSystemAddressBookExists($principal, $id, $properties) { |
|
127 | - $book = $this->backend->getAddressBooksByUri($principal, $id); |
|
128 | - if (!is_null($book)) { |
|
129 | - return $book; |
|
130 | - } |
|
131 | - $this->backend->createAddressBook($principal, $id, $properties); |
|
132 | - |
|
133 | - return $this->backend->getAddressBooksByUri($principal, $id); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @param string $url |
|
138 | - * @param string $userName |
|
139 | - * @param string $addressBookUrl |
|
140 | - * @param string $sharedSecret |
|
141 | - * @param string $syncToken |
|
142 | - * @return array |
|
143 | - */ |
|
144 | - protected function requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken) { |
|
145 | - $settings = [ |
|
146 | - 'baseUri' => $url . '/', |
|
147 | - 'userName' => $userName, |
|
148 | - 'password' => $sharedSecret, |
|
149 | - ]; |
|
150 | - $client = new Client($settings); |
|
151 | - $client->setThrowExceptions(true); |
|
152 | - |
|
153 | - $body = $this->buildSyncCollectionRequestBody($syncToken); |
|
154 | - |
|
155 | - $response = $client->request('REPORT', $addressBookUrl, $body, [ |
|
156 | - 'Content-Type' => 'application/xml' |
|
157 | - ]); |
|
158 | - |
|
159 | - $result = $this->parseMultiStatus($response['body']); |
|
160 | - |
|
161 | - return $result; |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * @param string $url |
|
166 | - * @param string $sharedSecret |
|
167 | - * @param string $resourcePath |
|
168 | - * @return array |
|
169 | - */ |
|
170 | - protected function download($url, $userName, $sharedSecret, $resourcePath) { |
|
171 | - $settings = [ |
|
172 | - 'baseUri' => $url, |
|
173 | - 'userName' => $userName, |
|
174 | - 'password' => $sharedSecret, |
|
175 | - ]; |
|
176 | - $client = new Client($settings); |
|
177 | - $client->setThrowExceptions(true); |
|
178 | - |
|
179 | - $response = $client->request('GET', $resourcePath); |
|
180 | - return $response; |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * @param string|null $syncToken |
|
185 | - * @return string |
|
186 | - */ |
|
187 | - private function buildSyncCollectionRequestBody($syncToken) { |
|
188 | - |
|
189 | - $dom = new \DOMDocument('1.0', 'UTF-8'); |
|
190 | - $dom->formatOutput = true; |
|
191 | - $root = $dom->createElementNS('DAV:', 'd:sync-collection'); |
|
192 | - $sync = $dom->createElement('d:sync-token', $syncToken); |
|
193 | - $prop = $dom->createElement('d:prop'); |
|
194 | - $cont = $dom->createElement('d:getcontenttype'); |
|
195 | - $etag = $dom->createElement('d:getetag'); |
|
196 | - |
|
197 | - $prop->appendChild($cont); |
|
198 | - $prop->appendChild($etag); |
|
199 | - $root->appendChild($sync); |
|
200 | - $root->appendChild($prop); |
|
201 | - $dom->appendChild($root); |
|
202 | - $body = $dom->saveXML(); |
|
203 | - |
|
204 | - return $body; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * @param string $body |
|
209 | - * @return array |
|
210 | - * @throws \Sabre\Xml\ParseException |
|
211 | - */ |
|
212 | - private function parseMultiStatus($body) { |
|
213 | - $xml = new Service(); |
|
214 | - |
|
215 | - /** @var MultiStatus $multiStatus */ |
|
216 | - $multiStatus = $xml->expect('{DAV:}multistatus', $body); |
|
217 | - |
|
218 | - $result = []; |
|
219 | - foreach ($multiStatus->getResponses() as $response) { |
|
220 | - $result[$response->getHref()] = $response->getResponseProperties(); |
|
221 | - } |
|
222 | - |
|
223 | - return ['response' => $result, 'token' => $multiStatus->getSyncToken()]; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * @param IUser $user |
|
228 | - */ |
|
229 | - public function updateUser($user) { |
|
230 | - $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
231 | - $addressBookId = $systemAddressBook['id']; |
|
232 | - $converter = new Converter($this->accountManager); |
|
233 | - $name = $user->getBackendClassName(); |
|
234 | - $userId = $user->getUID(); |
|
235 | - |
|
236 | - $cardId = "$name:$userId.vcf"; |
|
237 | - $card = $this->backend->getCard($addressBookId, $cardId); |
|
238 | - if ($card === false) { |
|
239 | - $vCard = $converter->createCardFromUser($user); |
|
240 | - if ($vCard !== null) { |
|
241 | - $this->backend->createCard($addressBookId, $cardId, $vCard->serialize()); |
|
242 | - } |
|
243 | - } else { |
|
244 | - $vCard = $converter->createCardFromUser($user); |
|
245 | - if (is_null($vCard)) { |
|
246 | - $this->backend->deleteCard($addressBookId, $cardId); |
|
247 | - } else { |
|
248 | - $this->backend->updateCard($addressBookId, $cardId, $vCard->serialize()); |
|
249 | - } |
|
250 | - } |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * @param IUser|string $userOrCardId |
|
255 | - */ |
|
256 | - public function deleteUser($userOrCardId) { |
|
257 | - $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
258 | - if ($userOrCardId instanceof IUser){ |
|
259 | - $name = $userOrCardId->getBackendClassName(); |
|
260 | - $userId = $userOrCardId->getUID(); |
|
261 | - |
|
262 | - $userOrCardId = "$name:$userId.vcf"; |
|
263 | - } |
|
264 | - $this->backend->deleteCard($systemAddressBook['id'], $userOrCardId); |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * @return array|null |
|
269 | - */ |
|
270 | - public function getLocalSystemAddressBook() { |
|
271 | - if (is_null($this->localSystemAddressBook)) { |
|
272 | - $systemPrincipal = "principals/system/system"; |
|
273 | - $this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [ |
|
274 | - '{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance' |
|
275 | - ]); |
|
276 | - } |
|
277 | - |
|
278 | - return $this->localSystemAddressBook; |
|
279 | - } |
|
280 | - |
|
281 | - public function syncInstance(\Closure $progressCallback = null) { |
|
282 | - $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
283 | - $this->userManager->callForAllUsers(function($user) use ($systemAddressBook, $progressCallback) { |
|
284 | - $this->updateUser($user); |
|
285 | - if (!is_null($progressCallback)) { |
|
286 | - $progressCallback(); |
|
287 | - } |
|
288 | - }); |
|
289 | - |
|
290 | - // remove no longer existing |
|
291 | - $allCards = $this->backend->getCards($systemAddressBook['id']); |
|
292 | - foreach($allCards as $card) { |
|
293 | - $vCard = Reader::read($card['carddata']); |
|
294 | - $uid = $vCard->UID->getValue(); |
|
295 | - // load backend and see if user exists |
|
296 | - if (!$this->userManager->userExists($uid)) { |
|
297 | - $this->deleteUser($card['uri']); |
|
298 | - } |
|
299 | - } |
|
300 | - } |
|
40 | + /** @var CardDavBackend */ |
|
41 | + private $backend; |
|
42 | + |
|
43 | + /** @var IUserManager */ |
|
44 | + private $userManager; |
|
45 | + |
|
46 | + /** @var ILogger */ |
|
47 | + private $logger; |
|
48 | + |
|
49 | + /** @var array */ |
|
50 | + private $localSystemAddressBook; |
|
51 | + |
|
52 | + /** @var AccountManager */ |
|
53 | + private $accountManager; |
|
54 | + |
|
55 | + /** |
|
56 | + * SyncService constructor. |
|
57 | + * |
|
58 | + * @param CardDavBackend $backend |
|
59 | + * @param IUserManager $userManager |
|
60 | + * @param ILogger $logger |
|
61 | + * @param AccountManager $accountManager |
|
62 | + */ |
|
63 | + public function __construct(CardDavBackend $backend, IUserManager $userManager, ILogger $logger, AccountManager $accountManager) { |
|
64 | + $this->backend = $backend; |
|
65 | + $this->userManager = $userManager; |
|
66 | + $this->logger = $logger; |
|
67 | + $this->accountManager = $accountManager; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @param string $url |
|
72 | + * @param string $userName |
|
73 | + * @param string $addressBookUrl |
|
74 | + * @param string $sharedSecret |
|
75 | + * @param string $syncToken |
|
76 | + * @param int $targetBookId |
|
77 | + * @param string $targetPrincipal |
|
78 | + * @param array $targetProperties |
|
79 | + * @return string |
|
80 | + * @throws \Exception |
|
81 | + */ |
|
82 | + public function syncRemoteAddressBook($url, $userName, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetProperties) { |
|
83 | + // 1. create addressbook |
|
84 | + $book = $this->ensureSystemAddressBookExists($targetPrincipal, $targetBookId, $targetProperties); |
|
85 | + $addressBookId = $book['id']; |
|
86 | + |
|
87 | + // 2. query changes |
|
88 | + try { |
|
89 | + $response = $this->requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken); |
|
90 | + } catch (ClientHttpException $ex) { |
|
91 | + if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { |
|
92 | + // remote server revoked access to the address book, remove it |
|
93 | + $this->backend->deleteAddressBook($addressBookId); |
|
94 | + $this->logger->info('Authorization failed, remove address book: ' . $url, ['app' => 'dav']); |
|
95 | + throw $ex; |
|
96 | + } |
|
97 | + } |
|
98 | + |
|
99 | + // 3. apply changes |
|
100 | + // TODO: use multi-get for download |
|
101 | + foreach ($response['response'] as $resource => $status) { |
|
102 | + $cardUri = basename($resource); |
|
103 | + if (isset($status[200])) { |
|
104 | + $vCard = $this->download($url, $userName, $sharedSecret, $resource); |
|
105 | + $existingCard = $this->backend->getCard($addressBookId, $cardUri); |
|
106 | + if ($existingCard === false) { |
|
107 | + $this->backend->createCard($addressBookId, $cardUri, $vCard['body']); |
|
108 | + } else { |
|
109 | + $this->backend->updateCard($addressBookId, $cardUri, $vCard['body']); |
|
110 | + } |
|
111 | + } else { |
|
112 | + $this->backend->deleteCard($addressBookId, $cardUri); |
|
113 | + } |
|
114 | + } |
|
115 | + |
|
116 | + return $response['token']; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * @param string $principal |
|
121 | + * @param string $id |
|
122 | + * @param array $properties |
|
123 | + * @return array|null |
|
124 | + * @throws \Sabre\DAV\Exception\BadRequest |
|
125 | + */ |
|
126 | + public function ensureSystemAddressBookExists($principal, $id, $properties) { |
|
127 | + $book = $this->backend->getAddressBooksByUri($principal, $id); |
|
128 | + if (!is_null($book)) { |
|
129 | + return $book; |
|
130 | + } |
|
131 | + $this->backend->createAddressBook($principal, $id, $properties); |
|
132 | + |
|
133 | + return $this->backend->getAddressBooksByUri($principal, $id); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @param string $url |
|
138 | + * @param string $userName |
|
139 | + * @param string $addressBookUrl |
|
140 | + * @param string $sharedSecret |
|
141 | + * @param string $syncToken |
|
142 | + * @return array |
|
143 | + */ |
|
144 | + protected function requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken) { |
|
145 | + $settings = [ |
|
146 | + 'baseUri' => $url . '/', |
|
147 | + 'userName' => $userName, |
|
148 | + 'password' => $sharedSecret, |
|
149 | + ]; |
|
150 | + $client = new Client($settings); |
|
151 | + $client->setThrowExceptions(true); |
|
152 | + |
|
153 | + $body = $this->buildSyncCollectionRequestBody($syncToken); |
|
154 | + |
|
155 | + $response = $client->request('REPORT', $addressBookUrl, $body, [ |
|
156 | + 'Content-Type' => 'application/xml' |
|
157 | + ]); |
|
158 | + |
|
159 | + $result = $this->parseMultiStatus($response['body']); |
|
160 | + |
|
161 | + return $result; |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * @param string $url |
|
166 | + * @param string $sharedSecret |
|
167 | + * @param string $resourcePath |
|
168 | + * @return array |
|
169 | + */ |
|
170 | + protected function download($url, $userName, $sharedSecret, $resourcePath) { |
|
171 | + $settings = [ |
|
172 | + 'baseUri' => $url, |
|
173 | + 'userName' => $userName, |
|
174 | + 'password' => $sharedSecret, |
|
175 | + ]; |
|
176 | + $client = new Client($settings); |
|
177 | + $client->setThrowExceptions(true); |
|
178 | + |
|
179 | + $response = $client->request('GET', $resourcePath); |
|
180 | + return $response; |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * @param string|null $syncToken |
|
185 | + * @return string |
|
186 | + */ |
|
187 | + private function buildSyncCollectionRequestBody($syncToken) { |
|
188 | + |
|
189 | + $dom = new \DOMDocument('1.0', 'UTF-8'); |
|
190 | + $dom->formatOutput = true; |
|
191 | + $root = $dom->createElementNS('DAV:', 'd:sync-collection'); |
|
192 | + $sync = $dom->createElement('d:sync-token', $syncToken); |
|
193 | + $prop = $dom->createElement('d:prop'); |
|
194 | + $cont = $dom->createElement('d:getcontenttype'); |
|
195 | + $etag = $dom->createElement('d:getetag'); |
|
196 | + |
|
197 | + $prop->appendChild($cont); |
|
198 | + $prop->appendChild($etag); |
|
199 | + $root->appendChild($sync); |
|
200 | + $root->appendChild($prop); |
|
201 | + $dom->appendChild($root); |
|
202 | + $body = $dom->saveXML(); |
|
203 | + |
|
204 | + return $body; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * @param string $body |
|
209 | + * @return array |
|
210 | + * @throws \Sabre\Xml\ParseException |
|
211 | + */ |
|
212 | + private function parseMultiStatus($body) { |
|
213 | + $xml = new Service(); |
|
214 | + |
|
215 | + /** @var MultiStatus $multiStatus */ |
|
216 | + $multiStatus = $xml->expect('{DAV:}multistatus', $body); |
|
217 | + |
|
218 | + $result = []; |
|
219 | + foreach ($multiStatus->getResponses() as $response) { |
|
220 | + $result[$response->getHref()] = $response->getResponseProperties(); |
|
221 | + } |
|
222 | + |
|
223 | + return ['response' => $result, 'token' => $multiStatus->getSyncToken()]; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * @param IUser $user |
|
228 | + */ |
|
229 | + public function updateUser($user) { |
|
230 | + $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
231 | + $addressBookId = $systemAddressBook['id']; |
|
232 | + $converter = new Converter($this->accountManager); |
|
233 | + $name = $user->getBackendClassName(); |
|
234 | + $userId = $user->getUID(); |
|
235 | + |
|
236 | + $cardId = "$name:$userId.vcf"; |
|
237 | + $card = $this->backend->getCard($addressBookId, $cardId); |
|
238 | + if ($card === false) { |
|
239 | + $vCard = $converter->createCardFromUser($user); |
|
240 | + if ($vCard !== null) { |
|
241 | + $this->backend->createCard($addressBookId, $cardId, $vCard->serialize()); |
|
242 | + } |
|
243 | + } else { |
|
244 | + $vCard = $converter->createCardFromUser($user); |
|
245 | + if (is_null($vCard)) { |
|
246 | + $this->backend->deleteCard($addressBookId, $cardId); |
|
247 | + } else { |
|
248 | + $this->backend->updateCard($addressBookId, $cardId, $vCard->serialize()); |
|
249 | + } |
|
250 | + } |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * @param IUser|string $userOrCardId |
|
255 | + */ |
|
256 | + public function deleteUser($userOrCardId) { |
|
257 | + $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
258 | + if ($userOrCardId instanceof IUser){ |
|
259 | + $name = $userOrCardId->getBackendClassName(); |
|
260 | + $userId = $userOrCardId->getUID(); |
|
261 | + |
|
262 | + $userOrCardId = "$name:$userId.vcf"; |
|
263 | + } |
|
264 | + $this->backend->deleteCard($systemAddressBook['id'], $userOrCardId); |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * @return array|null |
|
269 | + */ |
|
270 | + public function getLocalSystemAddressBook() { |
|
271 | + if (is_null($this->localSystemAddressBook)) { |
|
272 | + $systemPrincipal = "principals/system/system"; |
|
273 | + $this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [ |
|
274 | + '{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance' |
|
275 | + ]); |
|
276 | + } |
|
277 | + |
|
278 | + return $this->localSystemAddressBook; |
|
279 | + } |
|
280 | + |
|
281 | + public function syncInstance(\Closure $progressCallback = null) { |
|
282 | + $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
283 | + $this->userManager->callForAllUsers(function($user) use ($systemAddressBook, $progressCallback) { |
|
284 | + $this->updateUser($user); |
|
285 | + if (!is_null($progressCallback)) { |
|
286 | + $progressCallback(); |
|
287 | + } |
|
288 | + }); |
|
289 | + |
|
290 | + // remove no longer existing |
|
291 | + $allCards = $this->backend->getCards($systemAddressBook['id']); |
|
292 | + foreach($allCards as $card) { |
|
293 | + $vCard = Reader::read($card['carddata']); |
|
294 | + $uid = $vCard->UID->getValue(); |
|
295 | + // load backend and see if user exists |
|
296 | + if (!$this->userManager->userExists($uid)) { |
|
297 | + $this->deleteUser($card['uri']); |
|
298 | + } |
|
299 | + } |
|
300 | + } |
|
301 | 301 | |
302 | 302 | |
303 | 303 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { |
92 | 92 | // remote server revoked access to the address book, remove it |
93 | 93 | $this->backend->deleteAddressBook($addressBookId); |
94 | - $this->logger->info('Authorization failed, remove address book: ' . $url, ['app' => 'dav']); |
|
94 | + $this->logger->info('Authorization failed, remove address book: '.$url, ['app' => 'dav']); |
|
95 | 95 | throw $ex; |
96 | 96 | } |
97 | 97 | } |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | */ |
144 | 144 | protected function requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken) { |
145 | 145 | $settings = [ |
146 | - 'baseUri' => $url . '/', |
|
146 | + 'baseUri' => $url.'/', |
|
147 | 147 | 'userName' => $userName, |
148 | 148 | 'password' => $sharedSecret, |
149 | 149 | ]; |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | */ |
256 | 256 | public function deleteUser($userOrCardId) { |
257 | 257 | $systemAddressBook = $this->getLocalSystemAddressBook(); |
258 | - if ($userOrCardId instanceof IUser){ |
|
258 | + if ($userOrCardId instanceof IUser) { |
|
259 | 259 | $name = $userOrCardId->getBackendClassName(); |
260 | 260 | $userId = $userOrCardId->getUID(); |
261 | 261 | |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | if (is_null($this->localSystemAddressBook)) { |
272 | 272 | $systemPrincipal = "principals/system/system"; |
273 | 273 | $this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [ |
274 | - '{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance' |
|
274 | + '{'.Plugin::NS_CARDDAV.'}addressbook-description' => 'System addressbook which holds all users of this instance' |
|
275 | 275 | ]); |
276 | 276 | } |
277 | 277 | |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | |
290 | 290 | // remove no longer existing |
291 | 291 | $allCards = $this->backend->getCards($systemAddressBook['id']); |
292 | - foreach($allCards as $card) { |
|
292 | + foreach ($allCards as $card) { |
|
293 | 293 | $vCard = Reader::read($card['carddata']); |
294 | 294 | $uid = $vCard->UID->getValue(); |
295 | 295 | // load backend and see if user exists |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @package OCA\Federation\Backgroundjob |
48 | 48 | */ |
49 | -class GetSharedSecret extends Job{ |
|
49 | +class GetSharedSecret extends Job { |
|
50 | 50 | |
51 | 51 | /** @var IClient */ |
52 | 52 | private $httpClient; |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | $endPoint = isset($endPoints['shared-secret']) ? $endPoints['shared-secret'] : $this->defaultEndPoint; |
156 | 156 | |
157 | 157 | // make sure that we have a well formated url |
158 | - $url = rtrim($target, '/') . '/' . trim($endPoint, '/') . $this->format; |
|
158 | + $url = rtrim($target, '/').'/'.trim($endPoint, '/').$this->format; |
|
159 | 159 | |
160 | 160 | $result = null; |
161 | 161 | try { |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | } catch (ClientException $e) { |
178 | 178 | $status = $e->getCode(); |
179 | 179 | if ($status === Http::STATUS_FORBIDDEN) { |
180 | - $this->logger->info($target . ' refused to exchange a shared secret with you.', ['app' => 'federation']); |
|
180 | + $this->logger->info($target.' refused to exchange a shared secret with you.', ['app' => 'federation']); |
|
181 | 181 | } else { |
182 | 182 | $this->logger->logException($e, ['app' => 'federation']); |
183 | 183 | } |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | && $status !== Http::STATUS_FORBIDDEN |
193 | 193 | ) { |
194 | 194 | $this->retainJob = true; |
195 | - } else { |
|
195 | + } else { |
|
196 | 196 | // reset token if we received a valid response |
197 | 197 | $this->dbHandler->addToken($target, ''); |
198 | 198 | } |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | ); |
208 | 208 | } else { |
209 | 209 | $this->logger->error( |
210 | - 'remote server "' . $target . '"" does not return a valid shared secret', |
|
210 | + 'remote server "'.$target.'"" does not return a valid shared secret', |
|
211 | 211 | ['app' => 'federation'] |
212 | 212 | ); |
213 | 213 | $this->trustedServers->setServerStatus($target, TrustedServers::STATUS_FAILURE); |
@@ -48,171 +48,171 @@ |
||
48 | 48 | */ |
49 | 49 | class GetSharedSecret extends Job{ |
50 | 50 | |
51 | - /** @var IClient */ |
|
52 | - private $httpClient; |
|
53 | - |
|
54 | - /** @var IJobList */ |
|
55 | - private $jobList; |
|
56 | - |
|
57 | - /** @var IURLGenerator */ |
|
58 | - private $urlGenerator; |
|
59 | - |
|
60 | - /** @var TrustedServers */ |
|
61 | - private $trustedServers; |
|
62 | - |
|
63 | - /** @var DbHandler */ |
|
64 | - private $dbHandler; |
|
65 | - |
|
66 | - /** @var IDiscoveryService */ |
|
67 | - private $ocsDiscoveryService; |
|
68 | - |
|
69 | - /** @var ILogger */ |
|
70 | - private $logger; |
|
71 | - |
|
72 | - /** @var bool */ |
|
73 | - protected $retainJob = false; |
|
74 | - |
|
75 | - private $format = '?format=json'; |
|
76 | - |
|
77 | - private $defaultEndPoint = '/ocs/v2.php/apps/federation/api/v1/shared-secret'; |
|
78 | - |
|
79 | - /** |
|
80 | - * RequestSharedSecret constructor. |
|
81 | - * |
|
82 | - * @param IClient $httpClient |
|
83 | - * @param IURLGenerator $urlGenerator |
|
84 | - * @param IJobList $jobList |
|
85 | - * @param TrustedServers $trustedServers |
|
86 | - * @param ILogger $logger |
|
87 | - * @param DbHandler $dbHandler |
|
88 | - * @param IDiscoveryService $ocsDiscoveryService |
|
89 | - */ |
|
90 | - public function __construct( |
|
91 | - IClient $httpClient = null, |
|
92 | - IURLGenerator $urlGenerator = null, |
|
93 | - IJobList $jobList = null, |
|
94 | - TrustedServers $trustedServers = null, |
|
95 | - ILogger $logger = null, |
|
96 | - DbHandler $dbHandler = null, |
|
97 | - IDiscoveryService $ocsDiscoveryService = null |
|
98 | - ) { |
|
99 | - $this->logger = $logger ? $logger : \OC::$server->getLogger(); |
|
100 | - $this->httpClient = $httpClient ? $httpClient : \OC::$server->getHTTPClientService()->newClient(); |
|
101 | - $this->jobList = $jobList ? $jobList : \OC::$server->getJobList(); |
|
102 | - $this->urlGenerator = $urlGenerator ? $urlGenerator : \OC::$server->getURLGenerator(); |
|
103 | - $this->dbHandler = $dbHandler ? $dbHandler : new DbHandler(\OC::$server->getDatabaseConnection(), \OC::$server->getL10N('federation')); |
|
104 | - $this->ocsDiscoveryService = $ocsDiscoveryService ? $ocsDiscoveryService : \OC::$server->getOCSDiscoveryService(); |
|
105 | - if ($trustedServers) { |
|
106 | - $this->trustedServers = $trustedServers; |
|
107 | - } else { |
|
108 | - $this->trustedServers = new TrustedServers( |
|
109 | - $this->dbHandler, |
|
110 | - \OC::$server->getHTTPClientService(), |
|
111 | - $this->logger, |
|
112 | - $this->jobList, |
|
113 | - \OC::$server->getSecureRandom(), |
|
114 | - \OC::$server->getConfig(), |
|
115 | - \OC::$server->getEventDispatcher() |
|
116 | - ); |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * run the job, then remove it from the joblist |
|
122 | - * |
|
123 | - * @param JobList $jobList |
|
124 | - * @param ILogger $logger |
|
125 | - */ |
|
126 | - public function execute($jobList, ILogger $logger = null) { |
|
127 | - $target = $this->argument['url']; |
|
128 | - // only execute if target is still in the list of trusted domains |
|
129 | - if ($this->trustedServers->isTrustedServer($target)) { |
|
130 | - $this->parentExecute($jobList, $logger); |
|
131 | - } |
|
132 | - |
|
133 | - if (!$this->retainJob) { |
|
134 | - $jobList->remove($this, $this->argument); |
|
135 | - } |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * call execute() method of parent |
|
140 | - * |
|
141 | - * @param JobList $jobList |
|
142 | - * @param ILogger $logger |
|
143 | - */ |
|
144 | - protected function parentExecute($jobList, $logger = null) { |
|
145 | - parent::execute($jobList, $logger); |
|
146 | - } |
|
147 | - |
|
148 | - protected function run($argument) { |
|
149 | - $target = $argument['url']; |
|
150 | - $source = $this->urlGenerator->getAbsoluteURL('/'); |
|
151 | - $source = rtrim($source, '/'); |
|
152 | - $token = $argument['token']; |
|
153 | - |
|
154 | - $endPoints = $this->ocsDiscoveryService->discover($target, 'FEDERATED_SHARING'); |
|
155 | - $endPoint = isset($endPoints['shared-secret']) ? $endPoints['shared-secret'] : $this->defaultEndPoint; |
|
156 | - |
|
157 | - // make sure that we have a well formated url |
|
158 | - $url = rtrim($target, '/') . '/' . trim($endPoint, '/') . $this->format; |
|
159 | - |
|
160 | - $result = null; |
|
161 | - try { |
|
162 | - $result = $this->httpClient->get( |
|
163 | - $url, |
|
164 | - [ |
|
165 | - 'query' => |
|
166 | - [ |
|
167 | - 'url' => $source, |
|
168 | - 'token' => $token |
|
169 | - ], |
|
170 | - 'timeout' => 3, |
|
171 | - 'connect_timeout' => 3, |
|
172 | - ] |
|
173 | - ); |
|
174 | - |
|
175 | - $status = $result->getStatusCode(); |
|
176 | - |
|
177 | - } catch (ClientException $e) { |
|
178 | - $status = $e->getCode(); |
|
179 | - if ($status === Http::STATUS_FORBIDDEN) { |
|
180 | - $this->logger->info($target . ' refused to exchange a shared secret with you.', ['app' => 'federation']); |
|
181 | - } else { |
|
182 | - $this->logger->logException($e, ['app' => 'federation']); |
|
183 | - } |
|
184 | - } catch (\Exception $e) { |
|
185 | - $status = Http::STATUS_INTERNAL_SERVER_ERROR; |
|
186 | - $this->logger->logException($e, ['app' => 'federation']); |
|
187 | - } |
|
188 | - |
|
189 | - // if we received a unexpected response we try again later |
|
190 | - if ( |
|
191 | - $status !== Http::STATUS_OK |
|
192 | - && $status !== Http::STATUS_FORBIDDEN |
|
193 | - ) { |
|
194 | - $this->retainJob = true; |
|
195 | - } else { |
|
196 | - // reset token if we received a valid response |
|
197 | - $this->dbHandler->addToken($target, ''); |
|
198 | - } |
|
199 | - |
|
200 | - if ($status === Http::STATUS_OK && $result instanceof IResponse) { |
|
201 | - $body = $result->getBody(); |
|
202 | - $result = json_decode($body, true); |
|
203 | - if (isset($result['ocs']['data']['sharedSecret'])) { |
|
204 | - $this->trustedServers->addSharedSecret( |
|
205 | - $target, |
|
206 | - $result['ocs']['data']['sharedSecret'] |
|
207 | - ); |
|
208 | - } else { |
|
209 | - $this->logger->error( |
|
210 | - 'remote server "' . $target . '"" does not return a valid shared secret', |
|
211 | - ['app' => 'federation'] |
|
212 | - ); |
|
213 | - $this->trustedServers->setServerStatus($target, TrustedServers::STATUS_FAILURE); |
|
214 | - } |
|
215 | - } |
|
216 | - |
|
217 | - } |
|
51 | + /** @var IClient */ |
|
52 | + private $httpClient; |
|
53 | + |
|
54 | + /** @var IJobList */ |
|
55 | + private $jobList; |
|
56 | + |
|
57 | + /** @var IURLGenerator */ |
|
58 | + private $urlGenerator; |
|
59 | + |
|
60 | + /** @var TrustedServers */ |
|
61 | + private $trustedServers; |
|
62 | + |
|
63 | + /** @var DbHandler */ |
|
64 | + private $dbHandler; |
|
65 | + |
|
66 | + /** @var IDiscoveryService */ |
|
67 | + private $ocsDiscoveryService; |
|
68 | + |
|
69 | + /** @var ILogger */ |
|
70 | + private $logger; |
|
71 | + |
|
72 | + /** @var bool */ |
|
73 | + protected $retainJob = false; |
|
74 | + |
|
75 | + private $format = '?format=json'; |
|
76 | + |
|
77 | + private $defaultEndPoint = '/ocs/v2.php/apps/federation/api/v1/shared-secret'; |
|
78 | + |
|
79 | + /** |
|
80 | + * RequestSharedSecret constructor. |
|
81 | + * |
|
82 | + * @param IClient $httpClient |
|
83 | + * @param IURLGenerator $urlGenerator |
|
84 | + * @param IJobList $jobList |
|
85 | + * @param TrustedServers $trustedServers |
|
86 | + * @param ILogger $logger |
|
87 | + * @param DbHandler $dbHandler |
|
88 | + * @param IDiscoveryService $ocsDiscoveryService |
|
89 | + */ |
|
90 | + public function __construct( |
|
91 | + IClient $httpClient = null, |
|
92 | + IURLGenerator $urlGenerator = null, |
|
93 | + IJobList $jobList = null, |
|
94 | + TrustedServers $trustedServers = null, |
|
95 | + ILogger $logger = null, |
|
96 | + DbHandler $dbHandler = null, |
|
97 | + IDiscoveryService $ocsDiscoveryService = null |
|
98 | + ) { |
|
99 | + $this->logger = $logger ? $logger : \OC::$server->getLogger(); |
|
100 | + $this->httpClient = $httpClient ? $httpClient : \OC::$server->getHTTPClientService()->newClient(); |
|
101 | + $this->jobList = $jobList ? $jobList : \OC::$server->getJobList(); |
|
102 | + $this->urlGenerator = $urlGenerator ? $urlGenerator : \OC::$server->getURLGenerator(); |
|
103 | + $this->dbHandler = $dbHandler ? $dbHandler : new DbHandler(\OC::$server->getDatabaseConnection(), \OC::$server->getL10N('federation')); |
|
104 | + $this->ocsDiscoveryService = $ocsDiscoveryService ? $ocsDiscoveryService : \OC::$server->getOCSDiscoveryService(); |
|
105 | + if ($trustedServers) { |
|
106 | + $this->trustedServers = $trustedServers; |
|
107 | + } else { |
|
108 | + $this->trustedServers = new TrustedServers( |
|
109 | + $this->dbHandler, |
|
110 | + \OC::$server->getHTTPClientService(), |
|
111 | + $this->logger, |
|
112 | + $this->jobList, |
|
113 | + \OC::$server->getSecureRandom(), |
|
114 | + \OC::$server->getConfig(), |
|
115 | + \OC::$server->getEventDispatcher() |
|
116 | + ); |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * run the job, then remove it from the joblist |
|
122 | + * |
|
123 | + * @param JobList $jobList |
|
124 | + * @param ILogger $logger |
|
125 | + */ |
|
126 | + public function execute($jobList, ILogger $logger = null) { |
|
127 | + $target = $this->argument['url']; |
|
128 | + // only execute if target is still in the list of trusted domains |
|
129 | + if ($this->trustedServers->isTrustedServer($target)) { |
|
130 | + $this->parentExecute($jobList, $logger); |
|
131 | + } |
|
132 | + |
|
133 | + if (!$this->retainJob) { |
|
134 | + $jobList->remove($this, $this->argument); |
|
135 | + } |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * call execute() method of parent |
|
140 | + * |
|
141 | + * @param JobList $jobList |
|
142 | + * @param ILogger $logger |
|
143 | + */ |
|
144 | + protected function parentExecute($jobList, $logger = null) { |
|
145 | + parent::execute($jobList, $logger); |
|
146 | + } |
|
147 | + |
|
148 | + protected function run($argument) { |
|
149 | + $target = $argument['url']; |
|
150 | + $source = $this->urlGenerator->getAbsoluteURL('/'); |
|
151 | + $source = rtrim($source, '/'); |
|
152 | + $token = $argument['token']; |
|
153 | + |
|
154 | + $endPoints = $this->ocsDiscoveryService->discover($target, 'FEDERATED_SHARING'); |
|
155 | + $endPoint = isset($endPoints['shared-secret']) ? $endPoints['shared-secret'] : $this->defaultEndPoint; |
|
156 | + |
|
157 | + // make sure that we have a well formated url |
|
158 | + $url = rtrim($target, '/') . '/' . trim($endPoint, '/') . $this->format; |
|
159 | + |
|
160 | + $result = null; |
|
161 | + try { |
|
162 | + $result = $this->httpClient->get( |
|
163 | + $url, |
|
164 | + [ |
|
165 | + 'query' => |
|
166 | + [ |
|
167 | + 'url' => $source, |
|
168 | + 'token' => $token |
|
169 | + ], |
|
170 | + 'timeout' => 3, |
|
171 | + 'connect_timeout' => 3, |
|
172 | + ] |
|
173 | + ); |
|
174 | + |
|
175 | + $status = $result->getStatusCode(); |
|
176 | + |
|
177 | + } catch (ClientException $e) { |
|
178 | + $status = $e->getCode(); |
|
179 | + if ($status === Http::STATUS_FORBIDDEN) { |
|
180 | + $this->logger->info($target . ' refused to exchange a shared secret with you.', ['app' => 'federation']); |
|
181 | + } else { |
|
182 | + $this->logger->logException($e, ['app' => 'federation']); |
|
183 | + } |
|
184 | + } catch (\Exception $e) { |
|
185 | + $status = Http::STATUS_INTERNAL_SERVER_ERROR; |
|
186 | + $this->logger->logException($e, ['app' => 'federation']); |
|
187 | + } |
|
188 | + |
|
189 | + // if we received a unexpected response we try again later |
|
190 | + if ( |
|
191 | + $status !== Http::STATUS_OK |
|
192 | + && $status !== Http::STATUS_FORBIDDEN |
|
193 | + ) { |
|
194 | + $this->retainJob = true; |
|
195 | + } else { |
|
196 | + // reset token if we received a valid response |
|
197 | + $this->dbHandler->addToken($target, ''); |
|
198 | + } |
|
199 | + |
|
200 | + if ($status === Http::STATUS_OK && $result instanceof IResponse) { |
|
201 | + $body = $result->getBody(); |
|
202 | + $result = json_decode($body, true); |
|
203 | + if (isset($result['ocs']['data']['sharedSecret'])) { |
|
204 | + $this->trustedServers->addSharedSecret( |
|
205 | + $target, |
|
206 | + $result['ocs']['data']['sharedSecret'] |
|
207 | + ); |
|
208 | + } else { |
|
209 | + $this->logger->error( |
|
210 | + 'remote server "' . $target . '"" does not return a valid shared secret', |
|
211 | + ['app' => 'federation'] |
|
212 | + ); |
|
213 | + $this->trustedServers->setServerStatus($target, TrustedServers::STATUS_FAILURE); |
|
214 | + } |
|
215 | + } |
|
216 | + |
|
217 | + } |
|
218 | 218 | } |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | $endPoint = isset($endPoints['shared-secret']) ? $endPoints['shared-secret'] : $this->defaultEndPoint; |
156 | 156 | |
157 | 157 | // make sure that we have a well formated url |
158 | - $url = rtrim($target, '/') . '/' . trim($endPoint, '/') . $this->format; |
|
158 | + $url = rtrim($target, '/').'/'.trim($endPoint, '/').$this->format; |
|
159 | 159 | |
160 | 160 | try { |
161 | 161 | $result = $this->httpClient->post( |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | } catch (ClientException $e) { |
176 | 176 | $status = $e->getCode(); |
177 | 177 | if ($status === Http::STATUS_FORBIDDEN) { |
178 | - $this->logger->info($target . ' refused to ask for a shared secret.', ['app' => 'federation']); |
|
178 | + $this->logger->info($target.' refused to ask for a shared secret.', ['app' => 'federation']); |
|
179 | 179 | } else { |
180 | 180 | $this->logger->logException($e, ['app' => 'federation']); |
181 | 181 | } |
@@ -48,154 +48,154 @@ |
||
48 | 48 | */ |
49 | 49 | class RequestSharedSecret extends Job { |
50 | 50 | |
51 | - /** @var IClient */ |
|
52 | - private $httpClient; |
|
53 | - |
|
54 | - /** @var IJobList */ |
|
55 | - private $jobList; |
|
56 | - |
|
57 | - /** @var IURLGenerator */ |
|
58 | - private $urlGenerator; |
|
59 | - |
|
60 | - /** @var DbHandler */ |
|
61 | - private $dbHandler; |
|
62 | - |
|
63 | - /** @var TrustedServers */ |
|
64 | - private $trustedServers; |
|
65 | - |
|
66 | - /** @var IDiscoveryService */ |
|
67 | - private $ocsDiscoveryService; |
|
68 | - |
|
69 | - /** @var ILogger */ |
|
70 | - private $logger; |
|
71 | - |
|
72 | - /** @var bool */ |
|
73 | - protected $retainJob = false; |
|
74 | - |
|
75 | - private $format = '?format=json'; |
|
76 | - |
|
77 | - private $defaultEndPoint = '/ocs/v2.php/apps/federation/api/v1/request-shared-secret'; |
|
78 | - |
|
79 | - /** |
|
80 | - * RequestSharedSecret constructor. |
|
81 | - * |
|
82 | - * @param IClient $httpClient |
|
83 | - * @param IURLGenerator $urlGenerator |
|
84 | - * @param IJobList $jobList |
|
85 | - * @param TrustedServers $trustedServers |
|
86 | - * @param DbHandler $dbHandler |
|
87 | - * @param IDiscoveryService $ocsDiscoveryService |
|
88 | - */ |
|
89 | - public function __construct( |
|
90 | - IClient $httpClient = null, |
|
91 | - IURLGenerator $urlGenerator = null, |
|
92 | - IJobList $jobList = null, |
|
93 | - TrustedServers $trustedServers = null, |
|
94 | - DbHandler $dbHandler = null, |
|
95 | - IDiscoveryService $ocsDiscoveryService = null |
|
96 | - ) { |
|
97 | - $this->httpClient = $httpClient ? $httpClient : \OC::$server->getHTTPClientService()->newClient(); |
|
98 | - $this->jobList = $jobList ? $jobList : \OC::$server->getJobList(); |
|
99 | - $this->urlGenerator = $urlGenerator ? $urlGenerator : \OC::$server->getURLGenerator(); |
|
100 | - $this->dbHandler = $dbHandler ? $dbHandler : new DbHandler(\OC::$server->getDatabaseConnection(), \OC::$server->getL10N('federation')); |
|
101 | - $this->logger = \OC::$server->getLogger(); |
|
102 | - $this->ocsDiscoveryService = $ocsDiscoveryService ? $ocsDiscoveryService : \OC::$server->getOCSDiscoveryService(); |
|
103 | - if ($trustedServers) { |
|
104 | - $this->trustedServers = $trustedServers; |
|
105 | - } else { |
|
106 | - $this->trustedServers = new TrustedServers( |
|
107 | - $this->dbHandler, |
|
108 | - \OC::$server->getHTTPClientService(), |
|
109 | - $this->logger, |
|
110 | - $this->jobList, |
|
111 | - \OC::$server->getSecureRandom(), |
|
112 | - \OC::$server->getConfig(), |
|
113 | - \OC::$server->getEventDispatcher() |
|
114 | - ); |
|
115 | - } |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * run the job, then remove it from the joblist |
|
121 | - * |
|
122 | - * @param JobList $jobList |
|
123 | - * @param ILogger $logger |
|
124 | - */ |
|
125 | - public function execute($jobList, ILogger $logger = null) { |
|
126 | - $target = $this->argument['url']; |
|
127 | - // only execute if target is still in the list of trusted domains |
|
128 | - if ($this->trustedServers->isTrustedServer($target)) { |
|
129 | - $this->parentExecute($jobList, $logger); |
|
130 | - } |
|
131 | - |
|
132 | - if (!$this->retainJob) { |
|
133 | - $jobList->remove($this, $this->argument); |
|
134 | - } |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * call execute() method of parent |
|
139 | - * |
|
140 | - * @param JobList $jobList |
|
141 | - * @param ILogger $logger |
|
142 | - */ |
|
143 | - protected function parentExecute($jobList, $logger) { |
|
144 | - parent::execute($jobList, $logger); |
|
145 | - } |
|
146 | - |
|
147 | - protected function run($argument) { |
|
148 | - |
|
149 | - $target = $argument['url']; |
|
150 | - $source = $this->urlGenerator->getAbsoluteURL('/'); |
|
151 | - $source = rtrim($source, '/'); |
|
152 | - $token = $argument['token']; |
|
153 | - |
|
154 | - $endPoints = $this->ocsDiscoveryService->discover($target, 'FEDERATED_SHARING'); |
|
155 | - $endPoint = isset($endPoints['shared-secret']) ? $endPoints['shared-secret'] : $this->defaultEndPoint; |
|
156 | - |
|
157 | - // make sure that we have a well formated url |
|
158 | - $url = rtrim($target, '/') . '/' . trim($endPoint, '/') . $this->format; |
|
159 | - |
|
160 | - try { |
|
161 | - $result = $this->httpClient->post( |
|
162 | - $url, |
|
163 | - [ |
|
164 | - 'body' => [ |
|
165 | - 'url' => $source, |
|
166 | - 'token' => $token, |
|
167 | - ], |
|
168 | - 'timeout' => 3, |
|
169 | - 'connect_timeout' => 3, |
|
170 | - ] |
|
171 | - ); |
|
172 | - |
|
173 | - $status = $result->getStatusCode(); |
|
174 | - |
|
175 | - } catch (ClientException $e) { |
|
176 | - $status = $e->getCode(); |
|
177 | - if ($status === Http::STATUS_FORBIDDEN) { |
|
178 | - $this->logger->info($target . ' refused to ask for a shared secret.', ['app' => 'federation']); |
|
179 | - } else { |
|
180 | - $this->logger->logException($e, ['app' => 'federation']); |
|
181 | - } |
|
182 | - } catch (\Exception $e) { |
|
183 | - $status = Http::STATUS_INTERNAL_SERVER_ERROR; |
|
184 | - $this->logger->logException($e, ['app' => 'federation']); |
|
185 | - } |
|
186 | - |
|
187 | - // if we received a unexpected response we try again later |
|
188 | - if ( |
|
189 | - $status !== Http::STATUS_OK |
|
190 | - && $status !== Http::STATUS_FORBIDDEN |
|
191 | - ) { |
|
192 | - $this->retainJob = true; |
|
193 | - } |
|
194 | - |
|
195 | - if ($status === Http::STATUS_FORBIDDEN) { |
|
196 | - // clear token if remote server refuses to ask for shared secret |
|
197 | - $this->dbHandler->addToken($target, ''); |
|
198 | - } |
|
199 | - |
|
200 | - } |
|
51 | + /** @var IClient */ |
|
52 | + private $httpClient; |
|
53 | + |
|
54 | + /** @var IJobList */ |
|
55 | + private $jobList; |
|
56 | + |
|
57 | + /** @var IURLGenerator */ |
|
58 | + private $urlGenerator; |
|
59 | + |
|
60 | + /** @var DbHandler */ |
|
61 | + private $dbHandler; |
|
62 | + |
|
63 | + /** @var TrustedServers */ |
|
64 | + private $trustedServers; |
|
65 | + |
|
66 | + /** @var IDiscoveryService */ |
|
67 | + private $ocsDiscoveryService; |
|
68 | + |
|
69 | + /** @var ILogger */ |
|
70 | + private $logger; |
|
71 | + |
|
72 | + /** @var bool */ |
|
73 | + protected $retainJob = false; |
|
74 | + |
|
75 | + private $format = '?format=json'; |
|
76 | + |
|
77 | + private $defaultEndPoint = '/ocs/v2.php/apps/federation/api/v1/request-shared-secret'; |
|
78 | + |
|
79 | + /** |
|
80 | + * RequestSharedSecret constructor. |
|
81 | + * |
|
82 | + * @param IClient $httpClient |
|
83 | + * @param IURLGenerator $urlGenerator |
|
84 | + * @param IJobList $jobList |
|
85 | + * @param TrustedServers $trustedServers |
|
86 | + * @param DbHandler $dbHandler |
|
87 | + * @param IDiscoveryService $ocsDiscoveryService |
|
88 | + */ |
|
89 | + public function __construct( |
|
90 | + IClient $httpClient = null, |
|
91 | + IURLGenerator $urlGenerator = null, |
|
92 | + IJobList $jobList = null, |
|
93 | + TrustedServers $trustedServers = null, |
|
94 | + DbHandler $dbHandler = null, |
|
95 | + IDiscoveryService $ocsDiscoveryService = null |
|
96 | + ) { |
|
97 | + $this->httpClient = $httpClient ? $httpClient : \OC::$server->getHTTPClientService()->newClient(); |
|
98 | + $this->jobList = $jobList ? $jobList : \OC::$server->getJobList(); |
|
99 | + $this->urlGenerator = $urlGenerator ? $urlGenerator : \OC::$server->getURLGenerator(); |
|
100 | + $this->dbHandler = $dbHandler ? $dbHandler : new DbHandler(\OC::$server->getDatabaseConnection(), \OC::$server->getL10N('federation')); |
|
101 | + $this->logger = \OC::$server->getLogger(); |
|
102 | + $this->ocsDiscoveryService = $ocsDiscoveryService ? $ocsDiscoveryService : \OC::$server->getOCSDiscoveryService(); |
|
103 | + if ($trustedServers) { |
|
104 | + $this->trustedServers = $trustedServers; |
|
105 | + } else { |
|
106 | + $this->trustedServers = new TrustedServers( |
|
107 | + $this->dbHandler, |
|
108 | + \OC::$server->getHTTPClientService(), |
|
109 | + $this->logger, |
|
110 | + $this->jobList, |
|
111 | + \OC::$server->getSecureRandom(), |
|
112 | + \OC::$server->getConfig(), |
|
113 | + \OC::$server->getEventDispatcher() |
|
114 | + ); |
|
115 | + } |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * run the job, then remove it from the joblist |
|
121 | + * |
|
122 | + * @param JobList $jobList |
|
123 | + * @param ILogger $logger |
|
124 | + */ |
|
125 | + public function execute($jobList, ILogger $logger = null) { |
|
126 | + $target = $this->argument['url']; |
|
127 | + // only execute if target is still in the list of trusted domains |
|
128 | + if ($this->trustedServers->isTrustedServer($target)) { |
|
129 | + $this->parentExecute($jobList, $logger); |
|
130 | + } |
|
131 | + |
|
132 | + if (!$this->retainJob) { |
|
133 | + $jobList->remove($this, $this->argument); |
|
134 | + } |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * call execute() method of parent |
|
139 | + * |
|
140 | + * @param JobList $jobList |
|
141 | + * @param ILogger $logger |
|
142 | + */ |
|
143 | + protected function parentExecute($jobList, $logger) { |
|
144 | + parent::execute($jobList, $logger); |
|
145 | + } |
|
146 | + |
|
147 | + protected function run($argument) { |
|
148 | + |
|
149 | + $target = $argument['url']; |
|
150 | + $source = $this->urlGenerator->getAbsoluteURL('/'); |
|
151 | + $source = rtrim($source, '/'); |
|
152 | + $token = $argument['token']; |
|
153 | + |
|
154 | + $endPoints = $this->ocsDiscoveryService->discover($target, 'FEDERATED_SHARING'); |
|
155 | + $endPoint = isset($endPoints['shared-secret']) ? $endPoints['shared-secret'] : $this->defaultEndPoint; |
|
156 | + |
|
157 | + // make sure that we have a well formated url |
|
158 | + $url = rtrim($target, '/') . '/' . trim($endPoint, '/') . $this->format; |
|
159 | + |
|
160 | + try { |
|
161 | + $result = $this->httpClient->post( |
|
162 | + $url, |
|
163 | + [ |
|
164 | + 'body' => [ |
|
165 | + 'url' => $source, |
|
166 | + 'token' => $token, |
|
167 | + ], |
|
168 | + 'timeout' => 3, |
|
169 | + 'connect_timeout' => 3, |
|
170 | + ] |
|
171 | + ); |
|
172 | + |
|
173 | + $status = $result->getStatusCode(); |
|
174 | + |
|
175 | + } catch (ClientException $e) { |
|
176 | + $status = $e->getCode(); |
|
177 | + if ($status === Http::STATUS_FORBIDDEN) { |
|
178 | + $this->logger->info($target . ' refused to ask for a shared secret.', ['app' => 'federation']); |
|
179 | + } else { |
|
180 | + $this->logger->logException($e, ['app' => 'federation']); |
|
181 | + } |
|
182 | + } catch (\Exception $e) { |
|
183 | + $status = Http::STATUS_INTERNAL_SERVER_ERROR; |
|
184 | + $this->logger->logException($e, ['app' => 'federation']); |
|
185 | + } |
|
186 | + |
|
187 | + // if we received a unexpected response we try again later |
|
188 | + if ( |
|
189 | + $status !== Http::STATUS_OK |
|
190 | + && $status !== Http::STATUS_FORBIDDEN |
|
191 | + ) { |
|
192 | + $this->retainJob = true; |
|
193 | + } |
|
194 | + |
|
195 | + if ($status === Http::STATUS_FORBIDDEN) { |
|
196 | + // clear token if remote server refuses to ask for shared secret |
|
197 | + $this->dbHandler->addToken($target, ''); |
|
198 | + } |
|
199 | + |
|
200 | + } |
|
201 | 201 | } |
@@ -109,1491 +109,1491 @@ |
||
109 | 109 | * TODO: hookup all manager classes |
110 | 110 | */ |
111 | 111 | class Server extends ServerContainer implements IServerContainer { |
112 | - /** @var string */ |
|
113 | - private $webRoot; |
|
114 | - |
|
115 | - /** |
|
116 | - * @param string $webRoot |
|
117 | - * @param \OC\Config $config |
|
118 | - */ |
|
119 | - public function __construct($webRoot, \OC\Config $config) { |
|
120 | - parent::__construct(); |
|
121 | - $this->webRoot = $webRoot; |
|
122 | - |
|
123 | - $this->registerService('ContactsManager', function ($c) { |
|
124 | - return new ContactsManager(); |
|
125 | - }); |
|
126 | - |
|
127 | - $this->registerService('PreviewManager', function (Server $c) { |
|
128 | - return new PreviewManager( |
|
129 | - $c->getConfig(), |
|
130 | - $c->getRootFolder(), |
|
131 | - $c->getAppDataDir('preview'), |
|
132 | - $c->getEventDispatcher(), |
|
133 | - $c->getSession()->get('user_id') |
|
134 | - ); |
|
135 | - }); |
|
136 | - |
|
137 | - $this->registerService('OCSDiscoveryService', function (Server $c) { |
|
138 | - return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
112 | + /** @var string */ |
|
113 | + private $webRoot; |
|
114 | + |
|
115 | + /** |
|
116 | + * @param string $webRoot |
|
117 | + * @param \OC\Config $config |
|
118 | + */ |
|
119 | + public function __construct($webRoot, \OC\Config $config) { |
|
120 | + parent::__construct(); |
|
121 | + $this->webRoot = $webRoot; |
|
122 | + |
|
123 | + $this->registerService('ContactsManager', function ($c) { |
|
124 | + return new ContactsManager(); |
|
125 | + }); |
|
126 | + |
|
127 | + $this->registerService('PreviewManager', function (Server $c) { |
|
128 | + return new PreviewManager( |
|
129 | + $c->getConfig(), |
|
130 | + $c->getRootFolder(), |
|
131 | + $c->getAppDataDir('preview'), |
|
132 | + $c->getEventDispatcher(), |
|
133 | + $c->getSession()->get('user_id') |
|
134 | + ); |
|
135 | + }); |
|
136 | + |
|
137 | + $this->registerService('OCSDiscoveryService', function (Server $c) { |
|
138 | + return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
139 | 139 | ; }); |
140 | 140 | |
141 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
142 | - return new \OC\Preview\Watcher( |
|
143 | - $c->getAppDataDir('preview') |
|
144 | - ); |
|
145 | - }); |
|
146 | - |
|
147 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
148 | - $view = new View(); |
|
149 | - $util = new Encryption\Util( |
|
150 | - $view, |
|
151 | - $c->getUserManager(), |
|
152 | - $c->getGroupManager(), |
|
153 | - $c->getConfig() |
|
154 | - ); |
|
155 | - return new Encryption\Manager( |
|
156 | - $c->getConfig(), |
|
157 | - $c->getLogger(), |
|
158 | - $c->getL10N('core'), |
|
159 | - new View(), |
|
160 | - $util, |
|
161 | - new ArrayCache() |
|
162 | - ); |
|
163 | - }); |
|
164 | - |
|
165 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
166 | - $util = new Encryption\Util( |
|
167 | - new View(), |
|
168 | - $c->getUserManager(), |
|
169 | - $c->getGroupManager(), |
|
170 | - $c->getConfig() |
|
171 | - ); |
|
172 | - return new Encryption\File($util); |
|
173 | - }); |
|
174 | - |
|
175 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
176 | - $view = new View(); |
|
177 | - $util = new Encryption\Util( |
|
178 | - $view, |
|
179 | - $c->getUserManager(), |
|
180 | - $c->getGroupManager(), |
|
181 | - $c->getConfig() |
|
182 | - ); |
|
183 | - |
|
184 | - return new Encryption\Keys\Storage($view, $util); |
|
185 | - }); |
|
186 | - $this->registerService('TagMapper', function (Server $c) { |
|
187 | - return new TagMapper($c->getDatabaseConnection()); |
|
188 | - }); |
|
189 | - $this->registerService('TagManager', function (Server $c) { |
|
190 | - $tagMapper = $c->query('TagMapper'); |
|
191 | - return new TagManager($tagMapper, $c->getUserSession()); |
|
192 | - }); |
|
193 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
194 | - $config = $c->getConfig(); |
|
195 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
|
196 | - /** @var \OC\SystemTag\ManagerFactory $factory */ |
|
197 | - $factory = new $factoryClass($this); |
|
198 | - return $factory; |
|
199 | - }); |
|
200 | - $this->registerService('SystemTagManager', function (Server $c) { |
|
201 | - return $c->query('SystemTagManagerFactory')->getManager(); |
|
202 | - }); |
|
203 | - $this->registerService('SystemTagObjectMapper', function (Server $c) { |
|
204 | - return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
205 | - }); |
|
206 | - $this->registerService('RootFolder', function (Server $c) { |
|
207 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
208 | - $view = new View(); |
|
209 | - $root = new Root( |
|
210 | - $manager, |
|
211 | - $view, |
|
212 | - null, |
|
213 | - $c->getUserMountCache(), |
|
214 | - $this->getLogger(), |
|
215 | - $this->getUserManager() |
|
216 | - ); |
|
217 | - $connector = new HookConnector($root, $view); |
|
218 | - $connector->viewToNode(); |
|
219 | - |
|
220 | - $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
221 | - $previewConnector->connectWatcher(); |
|
222 | - |
|
223 | - return $root; |
|
224 | - }); |
|
225 | - $this->registerService('LazyRootFolder', function(Server $c) { |
|
226 | - return new LazyRoot(function() use ($c) { |
|
227 | - return $c->query('RootFolder'); |
|
228 | - }); |
|
229 | - }); |
|
230 | - $this->registerService('UserManager', function (Server $c) { |
|
231 | - $config = $c->getConfig(); |
|
232 | - return new \OC\User\Manager($config); |
|
233 | - }); |
|
234 | - $this->registerService('GroupManager', function (Server $c) { |
|
235 | - $groupManager = new \OC\Group\Manager($this->getUserManager()); |
|
236 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
237 | - \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
238 | - }); |
|
239 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
240 | - \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
241 | - }); |
|
242 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
243 | - \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
244 | - }); |
|
245 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
246 | - \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
247 | - }); |
|
248 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
249 | - \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
250 | - }); |
|
251 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
252 | - \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
253 | - //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
254 | - \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
255 | - }); |
|
256 | - return $groupManager; |
|
257 | - }); |
|
258 | - $this->registerService(Store::class, function(Server $c) { |
|
259 | - $session = $c->getSession(); |
|
260 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
261 | - $tokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
262 | - } else { |
|
263 | - $tokenProvider = null; |
|
264 | - } |
|
265 | - $logger = $c->getLogger(); |
|
266 | - return new Store($session, $logger, $tokenProvider); |
|
267 | - }); |
|
268 | - $this->registerAlias(IStore::class, Store::class); |
|
269 | - $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
270 | - $dbConnection = $c->getDatabaseConnection(); |
|
271 | - return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
272 | - }); |
|
273 | - $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
274 | - $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
|
275 | - $crypto = $c->getCrypto(); |
|
276 | - $config = $c->getConfig(); |
|
277 | - $logger = $c->getLogger(); |
|
278 | - $timeFactory = new TimeFactory(); |
|
279 | - return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
280 | - }); |
|
281 | - $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
|
282 | - $this->registerService('UserSession', function (Server $c) { |
|
283 | - $manager = $c->getUserManager(); |
|
284 | - $session = new \OC\Session\Memory(''); |
|
285 | - $timeFactory = new TimeFactory(); |
|
286 | - // Token providers might require a working database. This code |
|
287 | - // might however be called when ownCloud is not yet setup. |
|
288 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
289 | - $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
290 | - } else { |
|
291 | - $defaultTokenProvider = null; |
|
292 | - } |
|
293 | - |
|
294 | - $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom()); |
|
295 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
296 | - \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
297 | - }); |
|
298 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
299 | - /** @var $user \OC\User\User */ |
|
300 | - \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
301 | - }); |
|
302 | - $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
303 | - /** @var $user \OC\User\User */ |
|
304 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
305 | - }); |
|
306 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
307 | - /** @var $user \OC\User\User */ |
|
308 | - \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
309 | - }); |
|
310 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
311 | - /** @var $user \OC\User\User */ |
|
312 | - \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
313 | - }); |
|
314 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
315 | - /** @var $user \OC\User\User */ |
|
316 | - \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
317 | - }); |
|
318 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
319 | - \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
320 | - }); |
|
321 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
322 | - /** @var $user \OC\User\User */ |
|
323 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
324 | - }); |
|
325 | - $userSession->listen('\OC\User', 'logout', function () { |
|
326 | - \OC_Hook::emit('OC_User', 'logout', array()); |
|
327 | - }); |
|
328 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) { |
|
329 | - /** @var $user \OC\User\User */ |
|
330 | - \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value)); |
|
331 | - }); |
|
332 | - return $userSession; |
|
333 | - }); |
|
334 | - |
|
335 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
336 | - return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger()); |
|
337 | - }); |
|
338 | - |
|
339 | - $this->registerService('NavigationManager', function (Server $c) { |
|
340 | - return new \OC\NavigationManager($c->getAppManager(), |
|
341 | - $c->getURLGenerator(), |
|
342 | - $c->getL10NFactory(), |
|
343 | - $c->getUserSession(), |
|
344 | - $c->getGroupManager()); |
|
345 | - }); |
|
346 | - $this->registerService('AllConfig', function (Server $c) { |
|
347 | - return new \OC\AllConfig( |
|
348 | - $c->getSystemConfig() |
|
349 | - ); |
|
350 | - }); |
|
351 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
352 | - return new \OC\SystemConfig($config); |
|
353 | - }); |
|
354 | - $this->registerService('AppConfig', function (Server $c) { |
|
355 | - return new \OC\AppConfig($c->getDatabaseConnection()); |
|
356 | - }); |
|
357 | - $this->registerService('L10NFactory', function (Server $c) { |
|
358 | - return new \OC\L10N\Factory( |
|
359 | - $c->getConfig(), |
|
360 | - $c->getRequest(), |
|
361 | - $c->getUserSession(), |
|
362 | - \OC::$SERVERROOT |
|
363 | - ); |
|
364 | - }); |
|
365 | - $this->registerService('URLGenerator', function (Server $c) { |
|
366 | - $config = $c->getConfig(); |
|
367 | - $cacheFactory = $c->getMemCacheFactory(); |
|
368 | - return new \OC\URLGenerator( |
|
369 | - $config, |
|
370 | - $cacheFactory |
|
371 | - ); |
|
372 | - }); |
|
373 | - $this->registerService('AppHelper', function ($c) { |
|
374 | - return new \OC\AppHelper(); |
|
375 | - }); |
|
376 | - $this->registerService('AppFetcher', function ($c) { |
|
377 | - return new AppFetcher( |
|
378 | - $this->getAppDataDir('appstore'), |
|
379 | - $this->getHTTPClientService(), |
|
380 | - $this->query(TimeFactory::class), |
|
381 | - $this->getConfig() |
|
382 | - ); |
|
383 | - }); |
|
384 | - $this->registerService('CategoryFetcher', function ($c) { |
|
385 | - return new CategoryFetcher( |
|
386 | - $this->getAppDataDir('appstore'), |
|
387 | - $this->getHTTPClientService(), |
|
388 | - $this->query(TimeFactory::class), |
|
389 | - $this->getConfig() |
|
390 | - ); |
|
391 | - }); |
|
392 | - $this->registerService('UserCache', function ($c) { |
|
393 | - return new Cache\File(); |
|
394 | - }); |
|
395 | - $this->registerService('MemCacheFactory', function (Server $c) { |
|
396 | - $config = $c->getConfig(); |
|
397 | - |
|
398 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
399 | - $v = \OC_App::getAppVersions(); |
|
400 | - $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php')); |
|
401 | - $version = implode(',', $v); |
|
402 | - $instanceId = \OC_Util::getInstanceId(); |
|
403 | - $path = \OC::$SERVERROOT; |
|
404 | - $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT); |
|
405 | - return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
406 | - $config->getSystemValue('memcache.local', null), |
|
407 | - $config->getSystemValue('memcache.distributed', null), |
|
408 | - $config->getSystemValue('memcache.locking', null) |
|
409 | - ); |
|
410 | - } |
|
411 | - |
|
412 | - return new \OC\Memcache\Factory('', $c->getLogger(), |
|
413 | - '\\OC\\Memcache\\ArrayCache', |
|
414 | - '\\OC\\Memcache\\ArrayCache', |
|
415 | - '\\OC\\Memcache\\ArrayCache' |
|
416 | - ); |
|
417 | - }); |
|
418 | - $this->registerService('RedisFactory', function (Server $c) { |
|
419 | - $systemConfig = $c->getSystemConfig(); |
|
420 | - return new RedisFactory($systemConfig); |
|
421 | - }); |
|
422 | - $this->registerService('ActivityManager', function (Server $c) { |
|
423 | - return new \OC\Activity\Manager( |
|
424 | - $c->getRequest(), |
|
425 | - $c->getUserSession(), |
|
426 | - $c->getConfig(), |
|
427 | - $c->query(IValidator::class) |
|
428 | - ); |
|
429 | - }); |
|
430 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
431 | - return new \OC\Activity\EventMerger( |
|
432 | - $c->getL10N('lib') |
|
433 | - ); |
|
434 | - }); |
|
435 | - $this->registerAlias(IValidator::class, Validator::class); |
|
436 | - $this->registerService('AvatarManager', function (Server $c) { |
|
437 | - return new AvatarManager( |
|
438 | - $c->getUserManager(), |
|
439 | - $c->getAppDataDir('avatar'), |
|
440 | - $c->getL10N('lib'), |
|
441 | - $c->getLogger(), |
|
442 | - $c->getConfig() |
|
443 | - ); |
|
444 | - }); |
|
445 | - $this->registerService('Logger', function (Server $c) { |
|
446 | - $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
447 | - $logger = Log::getLogClass($logType); |
|
448 | - call_user_func(array($logger, 'init')); |
|
449 | - |
|
450 | - return new Log($logger); |
|
451 | - }); |
|
452 | - $this->registerService('JobList', function (Server $c) { |
|
453 | - $config = $c->getConfig(); |
|
454 | - return new \OC\BackgroundJob\JobList( |
|
455 | - $c->getDatabaseConnection(), |
|
456 | - $config, |
|
457 | - new TimeFactory() |
|
458 | - ); |
|
459 | - }); |
|
460 | - $this->registerService('Router', function (Server $c) { |
|
461 | - $cacheFactory = $c->getMemCacheFactory(); |
|
462 | - $logger = $c->getLogger(); |
|
463 | - if ($cacheFactory->isAvailable()) { |
|
464 | - $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger); |
|
465 | - } else { |
|
466 | - $router = new \OC\Route\Router($logger); |
|
467 | - } |
|
468 | - return $router; |
|
469 | - }); |
|
470 | - $this->registerService('Search', function ($c) { |
|
471 | - return new Search(); |
|
472 | - }); |
|
473 | - $this->registerService('SecureRandom', function ($c) { |
|
474 | - return new SecureRandom(); |
|
475 | - }); |
|
476 | - $this->registerService('Crypto', function (Server $c) { |
|
477 | - return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
478 | - }); |
|
479 | - $this->registerService('Hasher', function (Server $c) { |
|
480 | - return new Hasher($c->getConfig()); |
|
481 | - }); |
|
482 | - $this->registerService('CredentialsManager', function (Server $c) { |
|
483 | - return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
484 | - }); |
|
485 | - $this->registerService('DatabaseConnection', function (Server $c) { |
|
486 | - $systemConfig = $c->getSystemConfig(); |
|
487 | - $factory = new \OC\DB\ConnectionFactory($c->getConfig()); |
|
488 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
489 | - if (!$factory->isValidType($type)) { |
|
490 | - throw new \OC\DatabaseException('Invalid database type'); |
|
491 | - } |
|
492 | - $connectionParams = $factory->createConnectionParams($systemConfig); |
|
493 | - $connection = $factory->getConnection($type, $connectionParams); |
|
494 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
495 | - return $connection; |
|
496 | - }); |
|
497 | - $this->registerService('HTTPHelper', function (Server $c) { |
|
498 | - $config = $c->getConfig(); |
|
499 | - return new HTTPHelper( |
|
500 | - $config, |
|
501 | - $c->getHTTPClientService() |
|
502 | - ); |
|
503 | - }); |
|
504 | - $this->registerService('HttpClientService', function (Server $c) { |
|
505 | - $user = \OC_User::getUser(); |
|
506 | - $uid = $user ? $user : null; |
|
507 | - return new ClientService( |
|
508 | - $c->getConfig(), |
|
509 | - new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger()) |
|
510 | - ); |
|
511 | - }); |
|
512 | - $this->registerService('EventLogger', function (Server $c) { |
|
513 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
514 | - return new EventLogger(); |
|
515 | - } else { |
|
516 | - return new NullEventLogger(); |
|
517 | - } |
|
518 | - }); |
|
519 | - $this->registerService('QueryLogger', function (Server $c) { |
|
520 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
521 | - return new QueryLogger(); |
|
522 | - } else { |
|
523 | - return new NullQueryLogger(); |
|
524 | - } |
|
525 | - }); |
|
526 | - $this->registerService('TempManager', function (Server $c) { |
|
527 | - return new TempManager( |
|
528 | - $c->getLogger(), |
|
529 | - $c->getConfig() |
|
530 | - ); |
|
531 | - }); |
|
532 | - $this->registerService('AppManager', function (Server $c) { |
|
533 | - return new \OC\App\AppManager( |
|
534 | - $c->getUserSession(), |
|
535 | - $c->getAppConfig(), |
|
536 | - $c->getGroupManager(), |
|
537 | - $c->getMemCacheFactory(), |
|
538 | - $c->getEventDispatcher() |
|
539 | - ); |
|
540 | - }); |
|
541 | - $this->registerService('DateTimeZone', function (Server $c) { |
|
542 | - return new DateTimeZone( |
|
543 | - $c->getConfig(), |
|
544 | - $c->getSession() |
|
545 | - ); |
|
546 | - }); |
|
547 | - $this->registerService('DateTimeFormatter', function (Server $c) { |
|
548 | - $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
549 | - |
|
550 | - return new DateTimeFormatter( |
|
551 | - $c->getDateTimeZone()->getTimeZone(), |
|
552 | - $c->getL10N('lib', $language) |
|
553 | - ); |
|
554 | - }); |
|
555 | - $this->registerService('UserMountCache', function (Server $c) { |
|
556 | - $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
557 | - $listener = new UserMountCacheListener($mountCache); |
|
558 | - $listener->listen($c->getUserManager()); |
|
559 | - return $mountCache; |
|
560 | - }); |
|
561 | - $this->registerService('MountConfigManager', function (Server $c) { |
|
562 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
563 | - $mountCache = $c->query('UserMountCache'); |
|
564 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
565 | - |
|
566 | - // builtin providers |
|
567 | - |
|
568 | - $config = $c->getConfig(); |
|
569 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
570 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
571 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
572 | - |
|
573 | - return $manager; |
|
574 | - }); |
|
575 | - $this->registerService('IniWrapper', function ($c) { |
|
576 | - return new IniGetWrapper(); |
|
577 | - }); |
|
578 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
579 | - $jobList = $c->getJobList(); |
|
580 | - return new AsyncBus($jobList); |
|
581 | - }); |
|
582 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
583 | - return new TrustedDomainHelper($this->getConfig()); |
|
584 | - }); |
|
585 | - $this->registerService('Throttler', function(Server $c) { |
|
586 | - return new Throttler( |
|
587 | - $c->getDatabaseConnection(), |
|
588 | - new TimeFactory(), |
|
589 | - $c->getLogger(), |
|
590 | - $c->getConfig() |
|
591 | - ); |
|
592 | - }); |
|
593 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
594 | - // IConfig and IAppManager requires a working database. This code |
|
595 | - // might however be called when ownCloud is not yet setup. |
|
596 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
597 | - $config = $c->getConfig(); |
|
598 | - $appManager = $c->getAppManager(); |
|
599 | - } else { |
|
600 | - $config = null; |
|
601 | - $appManager = null; |
|
602 | - } |
|
603 | - |
|
604 | - return new Checker( |
|
605 | - new EnvironmentHelper(), |
|
606 | - new FileAccessHelper(), |
|
607 | - new AppLocator(), |
|
608 | - $config, |
|
609 | - $c->getMemCacheFactory(), |
|
610 | - $appManager, |
|
611 | - $c->getTempManager() |
|
612 | - ); |
|
613 | - }); |
|
614 | - $this->registerService('Request', function ($c) { |
|
615 | - if (isset($this['urlParams'])) { |
|
616 | - $urlParams = $this['urlParams']; |
|
617 | - } else { |
|
618 | - $urlParams = []; |
|
619 | - } |
|
620 | - |
|
621 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
622 | - && in_array('fakeinput', stream_get_wrappers()) |
|
623 | - ) { |
|
624 | - $stream = 'fakeinput://data'; |
|
625 | - } else { |
|
626 | - $stream = 'php://input'; |
|
627 | - } |
|
628 | - |
|
629 | - return new Request( |
|
630 | - [ |
|
631 | - 'get' => $_GET, |
|
632 | - 'post' => $_POST, |
|
633 | - 'files' => $_FILES, |
|
634 | - 'server' => $_SERVER, |
|
635 | - 'env' => $_ENV, |
|
636 | - 'cookies' => $_COOKIE, |
|
637 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
638 | - ? $_SERVER['REQUEST_METHOD'] |
|
639 | - : null, |
|
640 | - 'urlParams' => $urlParams, |
|
641 | - ], |
|
642 | - $this->getSecureRandom(), |
|
643 | - $this->getConfig(), |
|
644 | - $this->getCsrfTokenManager(), |
|
645 | - $stream |
|
646 | - ); |
|
647 | - }); |
|
648 | - $this->registerService('Mailer', function (Server $c) { |
|
649 | - return new Mailer( |
|
650 | - $c->getConfig(), |
|
651 | - $c->getLogger(), |
|
652 | - $c->getThemingDefaults() |
|
653 | - ); |
|
654 | - }); |
|
655 | - $this->registerService('LDAPProvider', function(Server $c) { |
|
656 | - $config = $c->getConfig(); |
|
657 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
658 | - if(is_null($factoryClass)) { |
|
659 | - throw new \Exception('ldapProviderFactory not set'); |
|
660 | - } |
|
661 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
662 | - $factory = new $factoryClass($this); |
|
663 | - return $factory->getLDAPProvider(); |
|
664 | - }); |
|
665 | - $this->registerService('LockingProvider', function (Server $c) { |
|
666 | - $ini = $c->getIniWrapper(); |
|
667 | - $config = $c->getConfig(); |
|
668 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
669 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
670 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
671 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
672 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
673 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
674 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
675 | - } |
|
676 | - return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
677 | - } |
|
678 | - return new NoopLockingProvider(); |
|
679 | - }); |
|
680 | - $this->registerService('MountManager', function () { |
|
681 | - return new \OC\Files\Mount\Manager(); |
|
682 | - }); |
|
683 | - $this->registerService('MimeTypeDetector', function (Server $c) { |
|
684 | - return new \OC\Files\Type\Detection( |
|
685 | - $c->getURLGenerator(), |
|
686 | - \OC::$configDir, |
|
687 | - \OC::$SERVERROOT . '/resources/config/' |
|
688 | - ); |
|
689 | - }); |
|
690 | - $this->registerService('MimeTypeLoader', function (Server $c) { |
|
691 | - return new \OC\Files\Type\Loader( |
|
692 | - $c->getDatabaseConnection() |
|
693 | - ); |
|
694 | - }); |
|
695 | - $this->registerService('NotificationManager', function (Server $c) { |
|
696 | - return new Manager( |
|
697 | - $c->query(IValidator::class) |
|
698 | - ); |
|
699 | - }); |
|
700 | - $this->registerService('CapabilitiesManager', function (Server $c) { |
|
701 | - $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
702 | - $manager->registerCapability(function () use ($c) { |
|
703 | - return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
704 | - }); |
|
705 | - return $manager; |
|
706 | - }); |
|
707 | - $this->registerService('CommentsManager', function(Server $c) { |
|
708 | - $config = $c->getConfig(); |
|
709 | - $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
|
710 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
711 | - $factory = new $factoryClass($this); |
|
712 | - return $factory->getManager(); |
|
713 | - }); |
|
714 | - $this->registerService('ThemingDefaults', function(Server $c) { |
|
715 | - /* |
|
141 | + $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
142 | + return new \OC\Preview\Watcher( |
|
143 | + $c->getAppDataDir('preview') |
|
144 | + ); |
|
145 | + }); |
|
146 | + |
|
147 | + $this->registerService('EncryptionManager', function (Server $c) { |
|
148 | + $view = new View(); |
|
149 | + $util = new Encryption\Util( |
|
150 | + $view, |
|
151 | + $c->getUserManager(), |
|
152 | + $c->getGroupManager(), |
|
153 | + $c->getConfig() |
|
154 | + ); |
|
155 | + return new Encryption\Manager( |
|
156 | + $c->getConfig(), |
|
157 | + $c->getLogger(), |
|
158 | + $c->getL10N('core'), |
|
159 | + new View(), |
|
160 | + $util, |
|
161 | + new ArrayCache() |
|
162 | + ); |
|
163 | + }); |
|
164 | + |
|
165 | + $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
166 | + $util = new Encryption\Util( |
|
167 | + new View(), |
|
168 | + $c->getUserManager(), |
|
169 | + $c->getGroupManager(), |
|
170 | + $c->getConfig() |
|
171 | + ); |
|
172 | + return new Encryption\File($util); |
|
173 | + }); |
|
174 | + |
|
175 | + $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
176 | + $view = new View(); |
|
177 | + $util = new Encryption\Util( |
|
178 | + $view, |
|
179 | + $c->getUserManager(), |
|
180 | + $c->getGroupManager(), |
|
181 | + $c->getConfig() |
|
182 | + ); |
|
183 | + |
|
184 | + return new Encryption\Keys\Storage($view, $util); |
|
185 | + }); |
|
186 | + $this->registerService('TagMapper', function (Server $c) { |
|
187 | + return new TagMapper($c->getDatabaseConnection()); |
|
188 | + }); |
|
189 | + $this->registerService('TagManager', function (Server $c) { |
|
190 | + $tagMapper = $c->query('TagMapper'); |
|
191 | + return new TagManager($tagMapper, $c->getUserSession()); |
|
192 | + }); |
|
193 | + $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
194 | + $config = $c->getConfig(); |
|
195 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
|
196 | + /** @var \OC\SystemTag\ManagerFactory $factory */ |
|
197 | + $factory = new $factoryClass($this); |
|
198 | + return $factory; |
|
199 | + }); |
|
200 | + $this->registerService('SystemTagManager', function (Server $c) { |
|
201 | + return $c->query('SystemTagManagerFactory')->getManager(); |
|
202 | + }); |
|
203 | + $this->registerService('SystemTagObjectMapper', function (Server $c) { |
|
204 | + return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
205 | + }); |
|
206 | + $this->registerService('RootFolder', function (Server $c) { |
|
207 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
208 | + $view = new View(); |
|
209 | + $root = new Root( |
|
210 | + $manager, |
|
211 | + $view, |
|
212 | + null, |
|
213 | + $c->getUserMountCache(), |
|
214 | + $this->getLogger(), |
|
215 | + $this->getUserManager() |
|
216 | + ); |
|
217 | + $connector = new HookConnector($root, $view); |
|
218 | + $connector->viewToNode(); |
|
219 | + |
|
220 | + $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
221 | + $previewConnector->connectWatcher(); |
|
222 | + |
|
223 | + return $root; |
|
224 | + }); |
|
225 | + $this->registerService('LazyRootFolder', function(Server $c) { |
|
226 | + return new LazyRoot(function() use ($c) { |
|
227 | + return $c->query('RootFolder'); |
|
228 | + }); |
|
229 | + }); |
|
230 | + $this->registerService('UserManager', function (Server $c) { |
|
231 | + $config = $c->getConfig(); |
|
232 | + return new \OC\User\Manager($config); |
|
233 | + }); |
|
234 | + $this->registerService('GroupManager', function (Server $c) { |
|
235 | + $groupManager = new \OC\Group\Manager($this->getUserManager()); |
|
236 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
237 | + \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
238 | + }); |
|
239 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
240 | + \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
241 | + }); |
|
242 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
243 | + \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
244 | + }); |
|
245 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
246 | + \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
247 | + }); |
|
248 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
249 | + \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
250 | + }); |
|
251 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
252 | + \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
253 | + //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
254 | + \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
255 | + }); |
|
256 | + return $groupManager; |
|
257 | + }); |
|
258 | + $this->registerService(Store::class, function(Server $c) { |
|
259 | + $session = $c->getSession(); |
|
260 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
261 | + $tokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
262 | + } else { |
|
263 | + $tokenProvider = null; |
|
264 | + } |
|
265 | + $logger = $c->getLogger(); |
|
266 | + return new Store($session, $logger, $tokenProvider); |
|
267 | + }); |
|
268 | + $this->registerAlias(IStore::class, Store::class); |
|
269 | + $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
270 | + $dbConnection = $c->getDatabaseConnection(); |
|
271 | + return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
272 | + }); |
|
273 | + $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
274 | + $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
|
275 | + $crypto = $c->getCrypto(); |
|
276 | + $config = $c->getConfig(); |
|
277 | + $logger = $c->getLogger(); |
|
278 | + $timeFactory = new TimeFactory(); |
|
279 | + return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
280 | + }); |
|
281 | + $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
|
282 | + $this->registerService('UserSession', function (Server $c) { |
|
283 | + $manager = $c->getUserManager(); |
|
284 | + $session = new \OC\Session\Memory(''); |
|
285 | + $timeFactory = new TimeFactory(); |
|
286 | + // Token providers might require a working database. This code |
|
287 | + // might however be called when ownCloud is not yet setup. |
|
288 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
289 | + $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
290 | + } else { |
|
291 | + $defaultTokenProvider = null; |
|
292 | + } |
|
293 | + |
|
294 | + $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom()); |
|
295 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
296 | + \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
297 | + }); |
|
298 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
299 | + /** @var $user \OC\User\User */ |
|
300 | + \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
301 | + }); |
|
302 | + $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
303 | + /** @var $user \OC\User\User */ |
|
304 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
305 | + }); |
|
306 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
307 | + /** @var $user \OC\User\User */ |
|
308 | + \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
309 | + }); |
|
310 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
311 | + /** @var $user \OC\User\User */ |
|
312 | + \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
313 | + }); |
|
314 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
315 | + /** @var $user \OC\User\User */ |
|
316 | + \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
317 | + }); |
|
318 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
319 | + \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
320 | + }); |
|
321 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
322 | + /** @var $user \OC\User\User */ |
|
323 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
324 | + }); |
|
325 | + $userSession->listen('\OC\User', 'logout', function () { |
|
326 | + \OC_Hook::emit('OC_User', 'logout', array()); |
|
327 | + }); |
|
328 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) { |
|
329 | + /** @var $user \OC\User\User */ |
|
330 | + \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value)); |
|
331 | + }); |
|
332 | + return $userSession; |
|
333 | + }); |
|
334 | + |
|
335 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
336 | + return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger()); |
|
337 | + }); |
|
338 | + |
|
339 | + $this->registerService('NavigationManager', function (Server $c) { |
|
340 | + return new \OC\NavigationManager($c->getAppManager(), |
|
341 | + $c->getURLGenerator(), |
|
342 | + $c->getL10NFactory(), |
|
343 | + $c->getUserSession(), |
|
344 | + $c->getGroupManager()); |
|
345 | + }); |
|
346 | + $this->registerService('AllConfig', function (Server $c) { |
|
347 | + return new \OC\AllConfig( |
|
348 | + $c->getSystemConfig() |
|
349 | + ); |
|
350 | + }); |
|
351 | + $this->registerService('SystemConfig', function ($c) use ($config) { |
|
352 | + return new \OC\SystemConfig($config); |
|
353 | + }); |
|
354 | + $this->registerService('AppConfig', function (Server $c) { |
|
355 | + return new \OC\AppConfig($c->getDatabaseConnection()); |
|
356 | + }); |
|
357 | + $this->registerService('L10NFactory', function (Server $c) { |
|
358 | + return new \OC\L10N\Factory( |
|
359 | + $c->getConfig(), |
|
360 | + $c->getRequest(), |
|
361 | + $c->getUserSession(), |
|
362 | + \OC::$SERVERROOT |
|
363 | + ); |
|
364 | + }); |
|
365 | + $this->registerService('URLGenerator', function (Server $c) { |
|
366 | + $config = $c->getConfig(); |
|
367 | + $cacheFactory = $c->getMemCacheFactory(); |
|
368 | + return new \OC\URLGenerator( |
|
369 | + $config, |
|
370 | + $cacheFactory |
|
371 | + ); |
|
372 | + }); |
|
373 | + $this->registerService('AppHelper', function ($c) { |
|
374 | + return new \OC\AppHelper(); |
|
375 | + }); |
|
376 | + $this->registerService('AppFetcher', function ($c) { |
|
377 | + return new AppFetcher( |
|
378 | + $this->getAppDataDir('appstore'), |
|
379 | + $this->getHTTPClientService(), |
|
380 | + $this->query(TimeFactory::class), |
|
381 | + $this->getConfig() |
|
382 | + ); |
|
383 | + }); |
|
384 | + $this->registerService('CategoryFetcher', function ($c) { |
|
385 | + return new CategoryFetcher( |
|
386 | + $this->getAppDataDir('appstore'), |
|
387 | + $this->getHTTPClientService(), |
|
388 | + $this->query(TimeFactory::class), |
|
389 | + $this->getConfig() |
|
390 | + ); |
|
391 | + }); |
|
392 | + $this->registerService('UserCache', function ($c) { |
|
393 | + return new Cache\File(); |
|
394 | + }); |
|
395 | + $this->registerService('MemCacheFactory', function (Server $c) { |
|
396 | + $config = $c->getConfig(); |
|
397 | + |
|
398 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
399 | + $v = \OC_App::getAppVersions(); |
|
400 | + $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php')); |
|
401 | + $version = implode(',', $v); |
|
402 | + $instanceId = \OC_Util::getInstanceId(); |
|
403 | + $path = \OC::$SERVERROOT; |
|
404 | + $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT); |
|
405 | + return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
406 | + $config->getSystemValue('memcache.local', null), |
|
407 | + $config->getSystemValue('memcache.distributed', null), |
|
408 | + $config->getSystemValue('memcache.locking', null) |
|
409 | + ); |
|
410 | + } |
|
411 | + |
|
412 | + return new \OC\Memcache\Factory('', $c->getLogger(), |
|
413 | + '\\OC\\Memcache\\ArrayCache', |
|
414 | + '\\OC\\Memcache\\ArrayCache', |
|
415 | + '\\OC\\Memcache\\ArrayCache' |
|
416 | + ); |
|
417 | + }); |
|
418 | + $this->registerService('RedisFactory', function (Server $c) { |
|
419 | + $systemConfig = $c->getSystemConfig(); |
|
420 | + return new RedisFactory($systemConfig); |
|
421 | + }); |
|
422 | + $this->registerService('ActivityManager', function (Server $c) { |
|
423 | + return new \OC\Activity\Manager( |
|
424 | + $c->getRequest(), |
|
425 | + $c->getUserSession(), |
|
426 | + $c->getConfig(), |
|
427 | + $c->query(IValidator::class) |
|
428 | + ); |
|
429 | + }); |
|
430 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
431 | + return new \OC\Activity\EventMerger( |
|
432 | + $c->getL10N('lib') |
|
433 | + ); |
|
434 | + }); |
|
435 | + $this->registerAlias(IValidator::class, Validator::class); |
|
436 | + $this->registerService('AvatarManager', function (Server $c) { |
|
437 | + return new AvatarManager( |
|
438 | + $c->getUserManager(), |
|
439 | + $c->getAppDataDir('avatar'), |
|
440 | + $c->getL10N('lib'), |
|
441 | + $c->getLogger(), |
|
442 | + $c->getConfig() |
|
443 | + ); |
|
444 | + }); |
|
445 | + $this->registerService('Logger', function (Server $c) { |
|
446 | + $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
447 | + $logger = Log::getLogClass($logType); |
|
448 | + call_user_func(array($logger, 'init')); |
|
449 | + |
|
450 | + return new Log($logger); |
|
451 | + }); |
|
452 | + $this->registerService('JobList', function (Server $c) { |
|
453 | + $config = $c->getConfig(); |
|
454 | + return new \OC\BackgroundJob\JobList( |
|
455 | + $c->getDatabaseConnection(), |
|
456 | + $config, |
|
457 | + new TimeFactory() |
|
458 | + ); |
|
459 | + }); |
|
460 | + $this->registerService('Router', function (Server $c) { |
|
461 | + $cacheFactory = $c->getMemCacheFactory(); |
|
462 | + $logger = $c->getLogger(); |
|
463 | + if ($cacheFactory->isAvailable()) { |
|
464 | + $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger); |
|
465 | + } else { |
|
466 | + $router = new \OC\Route\Router($logger); |
|
467 | + } |
|
468 | + return $router; |
|
469 | + }); |
|
470 | + $this->registerService('Search', function ($c) { |
|
471 | + return new Search(); |
|
472 | + }); |
|
473 | + $this->registerService('SecureRandom', function ($c) { |
|
474 | + return new SecureRandom(); |
|
475 | + }); |
|
476 | + $this->registerService('Crypto', function (Server $c) { |
|
477 | + return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
478 | + }); |
|
479 | + $this->registerService('Hasher', function (Server $c) { |
|
480 | + return new Hasher($c->getConfig()); |
|
481 | + }); |
|
482 | + $this->registerService('CredentialsManager', function (Server $c) { |
|
483 | + return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
484 | + }); |
|
485 | + $this->registerService('DatabaseConnection', function (Server $c) { |
|
486 | + $systemConfig = $c->getSystemConfig(); |
|
487 | + $factory = new \OC\DB\ConnectionFactory($c->getConfig()); |
|
488 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
489 | + if (!$factory->isValidType($type)) { |
|
490 | + throw new \OC\DatabaseException('Invalid database type'); |
|
491 | + } |
|
492 | + $connectionParams = $factory->createConnectionParams($systemConfig); |
|
493 | + $connection = $factory->getConnection($type, $connectionParams); |
|
494 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
495 | + return $connection; |
|
496 | + }); |
|
497 | + $this->registerService('HTTPHelper', function (Server $c) { |
|
498 | + $config = $c->getConfig(); |
|
499 | + return new HTTPHelper( |
|
500 | + $config, |
|
501 | + $c->getHTTPClientService() |
|
502 | + ); |
|
503 | + }); |
|
504 | + $this->registerService('HttpClientService', function (Server $c) { |
|
505 | + $user = \OC_User::getUser(); |
|
506 | + $uid = $user ? $user : null; |
|
507 | + return new ClientService( |
|
508 | + $c->getConfig(), |
|
509 | + new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger()) |
|
510 | + ); |
|
511 | + }); |
|
512 | + $this->registerService('EventLogger', function (Server $c) { |
|
513 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
514 | + return new EventLogger(); |
|
515 | + } else { |
|
516 | + return new NullEventLogger(); |
|
517 | + } |
|
518 | + }); |
|
519 | + $this->registerService('QueryLogger', function (Server $c) { |
|
520 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
521 | + return new QueryLogger(); |
|
522 | + } else { |
|
523 | + return new NullQueryLogger(); |
|
524 | + } |
|
525 | + }); |
|
526 | + $this->registerService('TempManager', function (Server $c) { |
|
527 | + return new TempManager( |
|
528 | + $c->getLogger(), |
|
529 | + $c->getConfig() |
|
530 | + ); |
|
531 | + }); |
|
532 | + $this->registerService('AppManager', function (Server $c) { |
|
533 | + return new \OC\App\AppManager( |
|
534 | + $c->getUserSession(), |
|
535 | + $c->getAppConfig(), |
|
536 | + $c->getGroupManager(), |
|
537 | + $c->getMemCacheFactory(), |
|
538 | + $c->getEventDispatcher() |
|
539 | + ); |
|
540 | + }); |
|
541 | + $this->registerService('DateTimeZone', function (Server $c) { |
|
542 | + return new DateTimeZone( |
|
543 | + $c->getConfig(), |
|
544 | + $c->getSession() |
|
545 | + ); |
|
546 | + }); |
|
547 | + $this->registerService('DateTimeFormatter', function (Server $c) { |
|
548 | + $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
549 | + |
|
550 | + return new DateTimeFormatter( |
|
551 | + $c->getDateTimeZone()->getTimeZone(), |
|
552 | + $c->getL10N('lib', $language) |
|
553 | + ); |
|
554 | + }); |
|
555 | + $this->registerService('UserMountCache', function (Server $c) { |
|
556 | + $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
557 | + $listener = new UserMountCacheListener($mountCache); |
|
558 | + $listener->listen($c->getUserManager()); |
|
559 | + return $mountCache; |
|
560 | + }); |
|
561 | + $this->registerService('MountConfigManager', function (Server $c) { |
|
562 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
563 | + $mountCache = $c->query('UserMountCache'); |
|
564 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
565 | + |
|
566 | + // builtin providers |
|
567 | + |
|
568 | + $config = $c->getConfig(); |
|
569 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
570 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
571 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
572 | + |
|
573 | + return $manager; |
|
574 | + }); |
|
575 | + $this->registerService('IniWrapper', function ($c) { |
|
576 | + return new IniGetWrapper(); |
|
577 | + }); |
|
578 | + $this->registerService('AsyncCommandBus', function (Server $c) { |
|
579 | + $jobList = $c->getJobList(); |
|
580 | + return new AsyncBus($jobList); |
|
581 | + }); |
|
582 | + $this->registerService('TrustedDomainHelper', function ($c) { |
|
583 | + return new TrustedDomainHelper($this->getConfig()); |
|
584 | + }); |
|
585 | + $this->registerService('Throttler', function(Server $c) { |
|
586 | + return new Throttler( |
|
587 | + $c->getDatabaseConnection(), |
|
588 | + new TimeFactory(), |
|
589 | + $c->getLogger(), |
|
590 | + $c->getConfig() |
|
591 | + ); |
|
592 | + }); |
|
593 | + $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
594 | + // IConfig and IAppManager requires a working database. This code |
|
595 | + // might however be called when ownCloud is not yet setup. |
|
596 | + if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
597 | + $config = $c->getConfig(); |
|
598 | + $appManager = $c->getAppManager(); |
|
599 | + } else { |
|
600 | + $config = null; |
|
601 | + $appManager = null; |
|
602 | + } |
|
603 | + |
|
604 | + return new Checker( |
|
605 | + new EnvironmentHelper(), |
|
606 | + new FileAccessHelper(), |
|
607 | + new AppLocator(), |
|
608 | + $config, |
|
609 | + $c->getMemCacheFactory(), |
|
610 | + $appManager, |
|
611 | + $c->getTempManager() |
|
612 | + ); |
|
613 | + }); |
|
614 | + $this->registerService('Request', function ($c) { |
|
615 | + if (isset($this['urlParams'])) { |
|
616 | + $urlParams = $this['urlParams']; |
|
617 | + } else { |
|
618 | + $urlParams = []; |
|
619 | + } |
|
620 | + |
|
621 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
622 | + && in_array('fakeinput', stream_get_wrappers()) |
|
623 | + ) { |
|
624 | + $stream = 'fakeinput://data'; |
|
625 | + } else { |
|
626 | + $stream = 'php://input'; |
|
627 | + } |
|
628 | + |
|
629 | + return new Request( |
|
630 | + [ |
|
631 | + 'get' => $_GET, |
|
632 | + 'post' => $_POST, |
|
633 | + 'files' => $_FILES, |
|
634 | + 'server' => $_SERVER, |
|
635 | + 'env' => $_ENV, |
|
636 | + 'cookies' => $_COOKIE, |
|
637 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
638 | + ? $_SERVER['REQUEST_METHOD'] |
|
639 | + : null, |
|
640 | + 'urlParams' => $urlParams, |
|
641 | + ], |
|
642 | + $this->getSecureRandom(), |
|
643 | + $this->getConfig(), |
|
644 | + $this->getCsrfTokenManager(), |
|
645 | + $stream |
|
646 | + ); |
|
647 | + }); |
|
648 | + $this->registerService('Mailer', function (Server $c) { |
|
649 | + return new Mailer( |
|
650 | + $c->getConfig(), |
|
651 | + $c->getLogger(), |
|
652 | + $c->getThemingDefaults() |
|
653 | + ); |
|
654 | + }); |
|
655 | + $this->registerService('LDAPProvider', function(Server $c) { |
|
656 | + $config = $c->getConfig(); |
|
657 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
658 | + if(is_null($factoryClass)) { |
|
659 | + throw new \Exception('ldapProviderFactory not set'); |
|
660 | + } |
|
661 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
662 | + $factory = new $factoryClass($this); |
|
663 | + return $factory->getLDAPProvider(); |
|
664 | + }); |
|
665 | + $this->registerService('LockingProvider', function (Server $c) { |
|
666 | + $ini = $c->getIniWrapper(); |
|
667 | + $config = $c->getConfig(); |
|
668 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
669 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
670 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
671 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
672 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
673 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
674 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
675 | + } |
|
676 | + return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
677 | + } |
|
678 | + return new NoopLockingProvider(); |
|
679 | + }); |
|
680 | + $this->registerService('MountManager', function () { |
|
681 | + return new \OC\Files\Mount\Manager(); |
|
682 | + }); |
|
683 | + $this->registerService('MimeTypeDetector', function (Server $c) { |
|
684 | + return new \OC\Files\Type\Detection( |
|
685 | + $c->getURLGenerator(), |
|
686 | + \OC::$configDir, |
|
687 | + \OC::$SERVERROOT . '/resources/config/' |
|
688 | + ); |
|
689 | + }); |
|
690 | + $this->registerService('MimeTypeLoader', function (Server $c) { |
|
691 | + return new \OC\Files\Type\Loader( |
|
692 | + $c->getDatabaseConnection() |
|
693 | + ); |
|
694 | + }); |
|
695 | + $this->registerService('NotificationManager', function (Server $c) { |
|
696 | + return new Manager( |
|
697 | + $c->query(IValidator::class) |
|
698 | + ); |
|
699 | + }); |
|
700 | + $this->registerService('CapabilitiesManager', function (Server $c) { |
|
701 | + $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
702 | + $manager->registerCapability(function () use ($c) { |
|
703 | + return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
704 | + }); |
|
705 | + return $manager; |
|
706 | + }); |
|
707 | + $this->registerService('CommentsManager', function(Server $c) { |
|
708 | + $config = $c->getConfig(); |
|
709 | + $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
|
710 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
711 | + $factory = new $factoryClass($this); |
|
712 | + return $factory->getManager(); |
|
713 | + }); |
|
714 | + $this->registerService('ThemingDefaults', function(Server $c) { |
|
715 | + /* |
|
716 | 716 | * Dark magic for autoloader. |
717 | 717 | * If we do a class_exists it will try to load the class which will |
718 | 718 | * make composer cache the result. Resulting in errors when enabling |
719 | 719 | * the theming app. |
720 | 720 | */ |
721 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
722 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
723 | - $classExists = true; |
|
724 | - } else { |
|
725 | - $classExists = false; |
|
726 | - } |
|
727 | - |
|
728 | - if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) { |
|
729 | - return new ThemingDefaults( |
|
730 | - $c->getConfig(), |
|
731 | - $c->getL10N('theming'), |
|
732 | - $c->getURLGenerator(), |
|
733 | - new \OC_Defaults(), |
|
734 | - $c->getLazyRootFolder(), |
|
735 | - $c->getMemCacheFactory() |
|
736 | - ); |
|
737 | - } |
|
738 | - return new \OC_Defaults(); |
|
739 | - }); |
|
740 | - $this->registerService('EventDispatcher', function () { |
|
741 | - return new EventDispatcher(); |
|
742 | - }); |
|
743 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
744 | - // FIXME: Instantiiated here due to cyclic dependency |
|
745 | - $request = new Request( |
|
746 | - [ |
|
747 | - 'get' => $_GET, |
|
748 | - 'post' => $_POST, |
|
749 | - 'files' => $_FILES, |
|
750 | - 'server' => $_SERVER, |
|
751 | - 'env' => $_ENV, |
|
752 | - 'cookies' => $_COOKIE, |
|
753 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
754 | - ? $_SERVER['REQUEST_METHOD'] |
|
755 | - : null, |
|
756 | - ], |
|
757 | - $c->getSecureRandom(), |
|
758 | - $c->getConfig() |
|
759 | - ); |
|
760 | - |
|
761 | - return new CryptoWrapper( |
|
762 | - $c->getConfig(), |
|
763 | - $c->getCrypto(), |
|
764 | - $c->getSecureRandom(), |
|
765 | - $request |
|
766 | - ); |
|
767 | - }); |
|
768 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
769 | - $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
770 | - |
|
771 | - return new CsrfTokenManager( |
|
772 | - $tokenGenerator, |
|
773 | - $c->query(SessionStorage::class) |
|
774 | - ); |
|
775 | - }); |
|
776 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
777 | - return new SessionStorage($c->getSession()); |
|
778 | - }); |
|
779 | - $this->registerService('ContentSecurityPolicyManager', function (Server $c) { |
|
780 | - return new ContentSecurityPolicyManager(); |
|
781 | - }); |
|
782 | - $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
|
783 | - return new ContentSecurityPolicyNonceManager( |
|
784 | - $c->getCsrfTokenManager(), |
|
785 | - $c->getRequest() |
|
786 | - ); |
|
787 | - }); |
|
788 | - $this->registerService('ShareManager', function(Server $c) { |
|
789 | - $config = $c->getConfig(); |
|
790 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
|
791 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
792 | - $factory = new $factoryClass($this); |
|
793 | - |
|
794 | - $manager = new \OC\Share20\Manager( |
|
795 | - $c->getLogger(), |
|
796 | - $c->getConfig(), |
|
797 | - $c->getSecureRandom(), |
|
798 | - $c->getHasher(), |
|
799 | - $c->getMountManager(), |
|
800 | - $c->getGroupManager(), |
|
801 | - $c->getL10N('core'), |
|
802 | - $factory, |
|
803 | - $c->getUserManager(), |
|
804 | - $c->getLazyRootFolder(), |
|
805 | - $c->getEventDispatcher() |
|
806 | - ); |
|
807 | - |
|
808 | - return $manager; |
|
809 | - }); |
|
810 | - $this->registerService('SettingsManager', function(Server $c) { |
|
811 | - $manager = new \OC\Settings\Manager( |
|
812 | - $c->getLogger(), |
|
813 | - $c->getDatabaseConnection(), |
|
814 | - $c->getL10N('lib'), |
|
815 | - $c->getConfig(), |
|
816 | - $c->getEncryptionManager(), |
|
817 | - $c->getUserManager(), |
|
818 | - $c->getLockingProvider(), |
|
819 | - new \OC\Settings\Mapper($c->getDatabaseConnection()), |
|
820 | - $c->getURLGenerator() |
|
821 | - ); |
|
822 | - return $manager; |
|
823 | - }); |
|
824 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
825 | - return new \OC\Files\AppData\Factory( |
|
826 | - $c->getRootFolder(), |
|
827 | - $c->getSystemConfig() |
|
828 | - ); |
|
829 | - }); |
|
830 | - |
|
831 | - $this->registerService('LockdownManager', function (Server $c) { |
|
832 | - return new LockdownManager(); |
|
833 | - }); |
|
834 | - |
|
835 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
836 | - return new CloudIdManager(); |
|
837 | - }); |
|
838 | - |
|
839 | - /* To trick DI since we don't extend the DIContainer here */ |
|
840 | - $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
841 | - return new CleanPreviewsBackgroundJob( |
|
842 | - $c->getRootFolder(), |
|
843 | - $c->getLogger(), |
|
844 | - $c->getJobList(), |
|
845 | - new TimeFactory() |
|
846 | - ); |
|
847 | - }); |
|
848 | - } |
|
849 | - |
|
850 | - /** |
|
851 | - * @return \OCP\Contacts\IManager |
|
852 | - */ |
|
853 | - public function getContactsManager() { |
|
854 | - return $this->query('ContactsManager'); |
|
855 | - } |
|
856 | - |
|
857 | - /** |
|
858 | - * @return \OC\Encryption\Manager |
|
859 | - */ |
|
860 | - public function getEncryptionManager() { |
|
861 | - return $this->query('EncryptionManager'); |
|
862 | - } |
|
863 | - |
|
864 | - /** |
|
865 | - * @return \OC\Encryption\File |
|
866 | - */ |
|
867 | - public function getEncryptionFilesHelper() { |
|
868 | - return $this->query('EncryptionFileHelper'); |
|
869 | - } |
|
870 | - |
|
871 | - /** |
|
872 | - * @return \OCP\Encryption\Keys\IStorage |
|
873 | - */ |
|
874 | - public function getEncryptionKeyStorage() { |
|
875 | - return $this->query('EncryptionKeyStorage'); |
|
876 | - } |
|
877 | - |
|
878 | - /** |
|
879 | - * @return \OC\OCS\DiscoveryService |
|
880 | - */ |
|
881 | - public function getOCSDiscoveryService() { |
|
882 | - return $this->query('OCSDiscoveryService'); |
|
883 | - } |
|
884 | - |
|
885 | - |
|
886 | - /** |
|
887 | - * The current request object holding all information about the request |
|
888 | - * currently being processed is returned from this method. |
|
889 | - * In case the current execution was not initiated by a web request null is returned |
|
890 | - * |
|
891 | - * @return \OCP\IRequest |
|
892 | - */ |
|
893 | - public function getRequest() { |
|
894 | - return $this->query('Request'); |
|
895 | - } |
|
896 | - |
|
897 | - /** |
|
898 | - * Returns the preview manager which can create preview images for a given file |
|
899 | - * |
|
900 | - * @return \OCP\IPreview |
|
901 | - */ |
|
902 | - public function getPreviewManager() { |
|
903 | - return $this->query('PreviewManager'); |
|
904 | - } |
|
905 | - |
|
906 | - /** |
|
907 | - * Returns the tag manager which can get and set tags for different object types |
|
908 | - * |
|
909 | - * @see \OCP\ITagManager::load() |
|
910 | - * @return \OCP\ITagManager |
|
911 | - */ |
|
912 | - public function getTagManager() { |
|
913 | - return $this->query('TagManager'); |
|
914 | - } |
|
915 | - |
|
916 | - /** |
|
917 | - * Returns the system-tag manager |
|
918 | - * |
|
919 | - * @return \OCP\SystemTag\ISystemTagManager |
|
920 | - * |
|
921 | - * @since 9.0.0 |
|
922 | - */ |
|
923 | - public function getSystemTagManager() { |
|
924 | - return $this->query('SystemTagManager'); |
|
925 | - } |
|
926 | - |
|
927 | - /** |
|
928 | - * Returns the system-tag object mapper |
|
929 | - * |
|
930 | - * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
931 | - * |
|
932 | - * @since 9.0.0 |
|
933 | - */ |
|
934 | - public function getSystemTagObjectMapper() { |
|
935 | - return $this->query('SystemTagObjectMapper'); |
|
936 | - } |
|
937 | - |
|
938 | - /** |
|
939 | - * Returns the avatar manager, used for avatar functionality |
|
940 | - * |
|
941 | - * @return \OCP\IAvatarManager |
|
942 | - */ |
|
943 | - public function getAvatarManager() { |
|
944 | - return $this->query('AvatarManager'); |
|
945 | - } |
|
946 | - |
|
947 | - /** |
|
948 | - * Returns the root folder of ownCloud's data directory |
|
949 | - * |
|
950 | - * @return \OCP\Files\IRootFolder |
|
951 | - */ |
|
952 | - public function getRootFolder() { |
|
953 | - return $this->query('LazyRootFolder'); |
|
954 | - } |
|
955 | - |
|
956 | - /** |
|
957 | - * Returns the root folder of ownCloud's data directory |
|
958 | - * This is the lazy variant so this gets only initialized once it |
|
959 | - * is actually used. |
|
960 | - * |
|
961 | - * @return \OCP\Files\IRootFolder |
|
962 | - */ |
|
963 | - public function getLazyRootFolder() { |
|
964 | - return $this->query('LazyRootFolder'); |
|
965 | - } |
|
966 | - |
|
967 | - /** |
|
968 | - * Returns a view to ownCloud's files folder |
|
969 | - * |
|
970 | - * @param string $userId user ID |
|
971 | - * @return \OCP\Files\Folder|null |
|
972 | - */ |
|
973 | - public function getUserFolder($userId = null) { |
|
974 | - if ($userId === null) { |
|
975 | - $user = $this->getUserSession()->getUser(); |
|
976 | - if (!$user) { |
|
977 | - return null; |
|
978 | - } |
|
979 | - $userId = $user->getUID(); |
|
980 | - } |
|
981 | - $root = $this->getRootFolder(); |
|
982 | - return $root->getUserFolder($userId); |
|
983 | - } |
|
984 | - |
|
985 | - /** |
|
986 | - * Returns an app-specific view in ownClouds data directory |
|
987 | - * |
|
988 | - * @return \OCP\Files\Folder |
|
989 | - * @deprecated since 9.2.0 use IAppData |
|
990 | - */ |
|
991 | - public function getAppFolder() { |
|
992 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
993 | - $root = $this->getRootFolder(); |
|
994 | - if (!$root->nodeExists($dir)) { |
|
995 | - $folder = $root->newFolder($dir); |
|
996 | - } else { |
|
997 | - $folder = $root->get($dir); |
|
998 | - } |
|
999 | - return $folder; |
|
1000 | - } |
|
1001 | - |
|
1002 | - /** |
|
1003 | - * @return \OC\User\Manager |
|
1004 | - */ |
|
1005 | - public function getUserManager() { |
|
1006 | - return $this->query('UserManager'); |
|
1007 | - } |
|
1008 | - |
|
1009 | - /** |
|
1010 | - * @return \OC\Group\Manager |
|
1011 | - */ |
|
1012 | - public function getGroupManager() { |
|
1013 | - return $this->query('GroupManager'); |
|
1014 | - } |
|
1015 | - |
|
1016 | - /** |
|
1017 | - * @return \OC\User\Session |
|
1018 | - */ |
|
1019 | - public function getUserSession() { |
|
1020 | - return $this->query('UserSession'); |
|
1021 | - } |
|
1022 | - |
|
1023 | - /** |
|
1024 | - * @return \OCP\ISession |
|
1025 | - */ |
|
1026 | - public function getSession() { |
|
1027 | - return $this->query('UserSession')->getSession(); |
|
1028 | - } |
|
1029 | - |
|
1030 | - /** |
|
1031 | - * @param \OCP\ISession $session |
|
1032 | - */ |
|
1033 | - public function setSession(\OCP\ISession $session) { |
|
1034 | - $this->query(SessionStorage::class)->setSession($session); |
|
1035 | - $this->query('UserSession')->setSession($session); |
|
1036 | - $this->query(Store::class)->setSession($session); |
|
1037 | - } |
|
1038 | - |
|
1039 | - /** |
|
1040 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1041 | - */ |
|
1042 | - public function getTwoFactorAuthManager() { |
|
1043 | - return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1044 | - } |
|
1045 | - |
|
1046 | - /** |
|
1047 | - * @return \OC\NavigationManager |
|
1048 | - */ |
|
1049 | - public function getNavigationManager() { |
|
1050 | - return $this->query('NavigationManager'); |
|
1051 | - } |
|
1052 | - |
|
1053 | - /** |
|
1054 | - * @return \OCP\IConfig |
|
1055 | - */ |
|
1056 | - public function getConfig() { |
|
1057 | - return $this->query('AllConfig'); |
|
1058 | - } |
|
1059 | - |
|
1060 | - /** |
|
1061 | - * @internal For internal use only |
|
1062 | - * @return \OC\SystemConfig |
|
1063 | - */ |
|
1064 | - public function getSystemConfig() { |
|
1065 | - return $this->query('SystemConfig'); |
|
1066 | - } |
|
1067 | - |
|
1068 | - /** |
|
1069 | - * Returns the app config manager |
|
1070 | - * |
|
1071 | - * @return \OCP\IAppConfig |
|
1072 | - */ |
|
1073 | - public function getAppConfig() { |
|
1074 | - return $this->query('AppConfig'); |
|
1075 | - } |
|
1076 | - |
|
1077 | - /** |
|
1078 | - * @return \OCP\L10N\IFactory |
|
1079 | - */ |
|
1080 | - public function getL10NFactory() { |
|
1081 | - return $this->query('L10NFactory'); |
|
1082 | - } |
|
1083 | - |
|
1084 | - /** |
|
1085 | - * get an L10N instance |
|
1086 | - * |
|
1087 | - * @param string $app appid |
|
1088 | - * @param string $lang |
|
1089 | - * @return IL10N |
|
1090 | - */ |
|
1091 | - public function getL10N($app, $lang = null) { |
|
1092 | - return $this->getL10NFactory()->get($app, $lang); |
|
1093 | - } |
|
1094 | - |
|
1095 | - /** |
|
1096 | - * @return \OCP\IURLGenerator |
|
1097 | - */ |
|
1098 | - public function getURLGenerator() { |
|
1099 | - return $this->query('URLGenerator'); |
|
1100 | - } |
|
1101 | - |
|
1102 | - /** |
|
1103 | - * @return \OCP\IHelper |
|
1104 | - */ |
|
1105 | - public function getHelper() { |
|
1106 | - return $this->query('AppHelper'); |
|
1107 | - } |
|
1108 | - |
|
1109 | - /** |
|
1110 | - * @return AppFetcher |
|
1111 | - */ |
|
1112 | - public function getAppFetcher() { |
|
1113 | - return $this->query('AppFetcher'); |
|
1114 | - } |
|
1115 | - |
|
1116 | - /** |
|
1117 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1118 | - * getMemCacheFactory() instead. |
|
1119 | - * |
|
1120 | - * @return \OCP\ICache |
|
1121 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1122 | - */ |
|
1123 | - public function getCache() { |
|
1124 | - return $this->query('UserCache'); |
|
1125 | - } |
|
1126 | - |
|
1127 | - /** |
|
1128 | - * Returns an \OCP\CacheFactory instance |
|
1129 | - * |
|
1130 | - * @return \OCP\ICacheFactory |
|
1131 | - */ |
|
1132 | - public function getMemCacheFactory() { |
|
1133 | - return $this->query('MemCacheFactory'); |
|
1134 | - } |
|
1135 | - |
|
1136 | - /** |
|
1137 | - * Returns an \OC\RedisFactory instance |
|
1138 | - * |
|
1139 | - * @return \OC\RedisFactory |
|
1140 | - */ |
|
1141 | - public function getGetRedisFactory() { |
|
1142 | - return $this->query('RedisFactory'); |
|
1143 | - } |
|
1144 | - |
|
1145 | - |
|
1146 | - /** |
|
1147 | - * Returns the current session |
|
1148 | - * |
|
1149 | - * @return \OCP\IDBConnection |
|
1150 | - */ |
|
1151 | - public function getDatabaseConnection() { |
|
1152 | - return $this->query('DatabaseConnection'); |
|
1153 | - } |
|
1154 | - |
|
1155 | - /** |
|
1156 | - * Returns the activity manager |
|
1157 | - * |
|
1158 | - * @return \OCP\Activity\IManager |
|
1159 | - */ |
|
1160 | - public function getActivityManager() { |
|
1161 | - return $this->query('ActivityManager'); |
|
1162 | - } |
|
1163 | - |
|
1164 | - /** |
|
1165 | - * Returns an job list for controlling background jobs |
|
1166 | - * |
|
1167 | - * @return \OCP\BackgroundJob\IJobList |
|
1168 | - */ |
|
1169 | - public function getJobList() { |
|
1170 | - return $this->query('JobList'); |
|
1171 | - } |
|
1172 | - |
|
1173 | - /** |
|
1174 | - * Returns a logger instance |
|
1175 | - * |
|
1176 | - * @return \OCP\ILogger |
|
1177 | - */ |
|
1178 | - public function getLogger() { |
|
1179 | - return $this->query('Logger'); |
|
1180 | - } |
|
1181 | - |
|
1182 | - /** |
|
1183 | - * Returns a router for generating and matching urls |
|
1184 | - * |
|
1185 | - * @return \OCP\Route\IRouter |
|
1186 | - */ |
|
1187 | - public function getRouter() { |
|
1188 | - return $this->query('Router'); |
|
1189 | - } |
|
1190 | - |
|
1191 | - /** |
|
1192 | - * Returns a search instance |
|
1193 | - * |
|
1194 | - * @return \OCP\ISearch |
|
1195 | - */ |
|
1196 | - public function getSearch() { |
|
1197 | - return $this->query('Search'); |
|
1198 | - } |
|
1199 | - |
|
1200 | - /** |
|
1201 | - * Returns a SecureRandom instance |
|
1202 | - * |
|
1203 | - * @return \OCP\Security\ISecureRandom |
|
1204 | - */ |
|
1205 | - public function getSecureRandom() { |
|
1206 | - return $this->query('SecureRandom'); |
|
1207 | - } |
|
1208 | - |
|
1209 | - /** |
|
1210 | - * Returns a Crypto instance |
|
1211 | - * |
|
1212 | - * @return \OCP\Security\ICrypto |
|
1213 | - */ |
|
1214 | - public function getCrypto() { |
|
1215 | - return $this->query('Crypto'); |
|
1216 | - } |
|
1217 | - |
|
1218 | - /** |
|
1219 | - * Returns a Hasher instance |
|
1220 | - * |
|
1221 | - * @return \OCP\Security\IHasher |
|
1222 | - */ |
|
1223 | - public function getHasher() { |
|
1224 | - return $this->query('Hasher'); |
|
1225 | - } |
|
1226 | - |
|
1227 | - /** |
|
1228 | - * Returns a CredentialsManager instance |
|
1229 | - * |
|
1230 | - * @return \OCP\Security\ICredentialsManager |
|
1231 | - */ |
|
1232 | - public function getCredentialsManager() { |
|
1233 | - return $this->query('CredentialsManager'); |
|
1234 | - } |
|
1235 | - |
|
1236 | - /** |
|
1237 | - * Returns an instance of the HTTP helper class |
|
1238 | - * |
|
1239 | - * @deprecated Use getHTTPClientService() |
|
1240 | - * @return \OC\HTTPHelper |
|
1241 | - */ |
|
1242 | - public function getHTTPHelper() { |
|
1243 | - return $this->query('HTTPHelper'); |
|
1244 | - } |
|
1245 | - |
|
1246 | - /** |
|
1247 | - * Get the certificate manager for the user |
|
1248 | - * |
|
1249 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1250 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1251 | - */ |
|
1252 | - public function getCertificateManager($userId = '') { |
|
1253 | - if ($userId === '') { |
|
1254 | - $userSession = $this->getUserSession(); |
|
1255 | - $user = $userSession->getUser(); |
|
1256 | - if (is_null($user)) { |
|
1257 | - return null; |
|
1258 | - } |
|
1259 | - $userId = $user->getUID(); |
|
1260 | - } |
|
1261 | - return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger()); |
|
1262 | - } |
|
1263 | - |
|
1264 | - /** |
|
1265 | - * Returns an instance of the HTTP client service |
|
1266 | - * |
|
1267 | - * @return \OCP\Http\Client\IClientService |
|
1268 | - */ |
|
1269 | - public function getHTTPClientService() { |
|
1270 | - return $this->query('HttpClientService'); |
|
1271 | - } |
|
1272 | - |
|
1273 | - /** |
|
1274 | - * Create a new event source |
|
1275 | - * |
|
1276 | - * @return \OCP\IEventSource |
|
1277 | - */ |
|
1278 | - public function createEventSource() { |
|
1279 | - return new \OC_EventSource(); |
|
1280 | - } |
|
1281 | - |
|
1282 | - /** |
|
1283 | - * Get the active event logger |
|
1284 | - * |
|
1285 | - * The returned logger only logs data when debug mode is enabled |
|
1286 | - * |
|
1287 | - * @return \OCP\Diagnostics\IEventLogger |
|
1288 | - */ |
|
1289 | - public function getEventLogger() { |
|
1290 | - return $this->query('EventLogger'); |
|
1291 | - } |
|
1292 | - |
|
1293 | - /** |
|
1294 | - * Get the active query logger |
|
1295 | - * |
|
1296 | - * The returned logger only logs data when debug mode is enabled |
|
1297 | - * |
|
1298 | - * @return \OCP\Diagnostics\IQueryLogger |
|
1299 | - */ |
|
1300 | - public function getQueryLogger() { |
|
1301 | - return $this->query('QueryLogger'); |
|
1302 | - } |
|
1303 | - |
|
1304 | - /** |
|
1305 | - * Get the manager for temporary files and folders |
|
1306 | - * |
|
1307 | - * @return \OCP\ITempManager |
|
1308 | - */ |
|
1309 | - public function getTempManager() { |
|
1310 | - return $this->query('TempManager'); |
|
1311 | - } |
|
1312 | - |
|
1313 | - /** |
|
1314 | - * Get the app manager |
|
1315 | - * |
|
1316 | - * @return \OCP\App\IAppManager |
|
1317 | - */ |
|
1318 | - public function getAppManager() { |
|
1319 | - return $this->query('AppManager'); |
|
1320 | - } |
|
1321 | - |
|
1322 | - /** |
|
1323 | - * Creates a new mailer |
|
1324 | - * |
|
1325 | - * @return \OCP\Mail\IMailer |
|
1326 | - */ |
|
1327 | - public function getMailer() { |
|
1328 | - return $this->query('Mailer'); |
|
1329 | - } |
|
1330 | - |
|
1331 | - /** |
|
1332 | - * Get the webroot |
|
1333 | - * |
|
1334 | - * @return string |
|
1335 | - */ |
|
1336 | - public function getWebRoot() { |
|
1337 | - return $this->webRoot; |
|
1338 | - } |
|
1339 | - |
|
1340 | - /** |
|
1341 | - * @return \OC\OCSClient |
|
1342 | - */ |
|
1343 | - public function getOcsClient() { |
|
1344 | - return $this->query('OcsClient'); |
|
1345 | - } |
|
1346 | - |
|
1347 | - /** |
|
1348 | - * @return \OCP\IDateTimeZone |
|
1349 | - */ |
|
1350 | - public function getDateTimeZone() { |
|
1351 | - return $this->query('DateTimeZone'); |
|
1352 | - } |
|
1353 | - |
|
1354 | - /** |
|
1355 | - * @return \OCP\IDateTimeFormatter |
|
1356 | - */ |
|
1357 | - public function getDateTimeFormatter() { |
|
1358 | - return $this->query('DateTimeFormatter'); |
|
1359 | - } |
|
1360 | - |
|
1361 | - /** |
|
1362 | - * @return \OCP\Files\Config\IMountProviderCollection |
|
1363 | - */ |
|
1364 | - public function getMountProviderCollection() { |
|
1365 | - return $this->query('MountConfigManager'); |
|
1366 | - } |
|
1367 | - |
|
1368 | - /** |
|
1369 | - * Get the IniWrapper |
|
1370 | - * |
|
1371 | - * @return IniGetWrapper |
|
1372 | - */ |
|
1373 | - public function getIniWrapper() { |
|
1374 | - return $this->query('IniWrapper'); |
|
1375 | - } |
|
1376 | - |
|
1377 | - /** |
|
1378 | - * @return \OCP\Command\IBus |
|
1379 | - */ |
|
1380 | - public function getCommandBus() { |
|
1381 | - return $this->query('AsyncCommandBus'); |
|
1382 | - } |
|
1383 | - |
|
1384 | - /** |
|
1385 | - * Get the trusted domain helper |
|
1386 | - * |
|
1387 | - * @return TrustedDomainHelper |
|
1388 | - */ |
|
1389 | - public function getTrustedDomainHelper() { |
|
1390 | - return $this->query('TrustedDomainHelper'); |
|
1391 | - } |
|
1392 | - |
|
1393 | - /** |
|
1394 | - * Get the locking provider |
|
1395 | - * |
|
1396 | - * @return \OCP\Lock\ILockingProvider |
|
1397 | - * @since 8.1.0 |
|
1398 | - */ |
|
1399 | - public function getLockingProvider() { |
|
1400 | - return $this->query('LockingProvider'); |
|
1401 | - } |
|
1402 | - |
|
1403 | - /** |
|
1404 | - * @return \OCP\Files\Mount\IMountManager |
|
1405 | - **/ |
|
1406 | - function getMountManager() { |
|
1407 | - return $this->query('MountManager'); |
|
1408 | - } |
|
1409 | - |
|
1410 | - /** @return \OCP\Files\Config\IUserMountCache */ |
|
1411 | - function getUserMountCache() { |
|
1412 | - return $this->query('UserMountCache'); |
|
1413 | - } |
|
1414 | - |
|
1415 | - /** |
|
1416 | - * Get the MimeTypeDetector |
|
1417 | - * |
|
1418 | - * @return \OCP\Files\IMimeTypeDetector |
|
1419 | - */ |
|
1420 | - public function getMimeTypeDetector() { |
|
1421 | - return $this->query('MimeTypeDetector'); |
|
1422 | - } |
|
1423 | - |
|
1424 | - /** |
|
1425 | - * Get the MimeTypeLoader |
|
1426 | - * |
|
1427 | - * @return \OCP\Files\IMimeTypeLoader |
|
1428 | - */ |
|
1429 | - public function getMimeTypeLoader() { |
|
1430 | - return $this->query('MimeTypeLoader'); |
|
1431 | - } |
|
1432 | - |
|
1433 | - /** |
|
1434 | - * Get the manager of all the capabilities |
|
1435 | - * |
|
1436 | - * @return \OC\CapabilitiesManager |
|
1437 | - */ |
|
1438 | - public function getCapabilitiesManager() { |
|
1439 | - return $this->query('CapabilitiesManager'); |
|
1440 | - } |
|
1441 | - |
|
1442 | - /** |
|
1443 | - * Get the EventDispatcher |
|
1444 | - * |
|
1445 | - * @return EventDispatcherInterface |
|
1446 | - * @since 8.2.0 |
|
1447 | - */ |
|
1448 | - public function getEventDispatcher() { |
|
1449 | - return $this->query('EventDispatcher'); |
|
1450 | - } |
|
1451 | - |
|
1452 | - /** |
|
1453 | - * Get the Notification Manager |
|
1454 | - * |
|
1455 | - * @return \OCP\Notification\IManager |
|
1456 | - * @since 8.2.0 |
|
1457 | - */ |
|
1458 | - public function getNotificationManager() { |
|
1459 | - return $this->query('NotificationManager'); |
|
1460 | - } |
|
1461 | - |
|
1462 | - /** |
|
1463 | - * @return \OCP\Comments\ICommentsManager |
|
1464 | - */ |
|
1465 | - public function getCommentsManager() { |
|
1466 | - return $this->query('CommentsManager'); |
|
1467 | - } |
|
1468 | - |
|
1469 | - /** |
|
1470 | - * @return \OC_Defaults |
|
1471 | - */ |
|
1472 | - public function getThemingDefaults() { |
|
1473 | - return $this->query('ThemingDefaults'); |
|
1474 | - } |
|
1475 | - |
|
1476 | - /** |
|
1477 | - * @return \OC\IntegrityCheck\Checker |
|
1478 | - */ |
|
1479 | - public function getIntegrityCodeChecker() { |
|
1480 | - return $this->query('IntegrityCodeChecker'); |
|
1481 | - } |
|
1482 | - |
|
1483 | - /** |
|
1484 | - * @return \OC\Session\CryptoWrapper |
|
1485 | - */ |
|
1486 | - public function getSessionCryptoWrapper() { |
|
1487 | - return $this->query('CryptoWrapper'); |
|
1488 | - } |
|
1489 | - |
|
1490 | - /** |
|
1491 | - * @return CsrfTokenManager |
|
1492 | - */ |
|
1493 | - public function getCsrfTokenManager() { |
|
1494 | - return $this->query('CsrfTokenManager'); |
|
1495 | - } |
|
1496 | - |
|
1497 | - /** |
|
1498 | - * @return Throttler |
|
1499 | - */ |
|
1500 | - public function getBruteForceThrottler() { |
|
1501 | - return $this->query('Throttler'); |
|
1502 | - } |
|
1503 | - |
|
1504 | - /** |
|
1505 | - * @return IContentSecurityPolicyManager |
|
1506 | - */ |
|
1507 | - public function getContentSecurityPolicyManager() { |
|
1508 | - return $this->query('ContentSecurityPolicyManager'); |
|
1509 | - } |
|
1510 | - |
|
1511 | - /** |
|
1512 | - * @return ContentSecurityPolicyNonceManager |
|
1513 | - */ |
|
1514 | - public function getContentSecurityPolicyNonceManager() { |
|
1515 | - return $this->query('ContentSecurityPolicyNonceManager'); |
|
1516 | - } |
|
1517 | - |
|
1518 | - /** |
|
1519 | - * Not a public API as of 8.2, wait for 9.0 |
|
1520 | - * |
|
1521 | - * @return \OCA\Files_External\Service\BackendService |
|
1522 | - */ |
|
1523 | - public function getStoragesBackendService() { |
|
1524 | - return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1525 | - } |
|
1526 | - |
|
1527 | - /** |
|
1528 | - * Not a public API as of 8.2, wait for 9.0 |
|
1529 | - * |
|
1530 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1531 | - */ |
|
1532 | - public function getGlobalStoragesService() { |
|
1533 | - return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1534 | - } |
|
1535 | - |
|
1536 | - /** |
|
1537 | - * Not a public API as of 8.2, wait for 9.0 |
|
1538 | - * |
|
1539 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1540 | - */ |
|
1541 | - public function getUserGlobalStoragesService() { |
|
1542 | - return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1543 | - } |
|
1544 | - |
|
1545 | - /** |
|
1546 | - * Not a public API as of 8.2, wait for 9.0 |
|
1547 | - * |
|
1548 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
1549 | - */ |
|
1550 | - public function getUserStoragesService() { |
|
1551 | - return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1552 | - } |
|
1553 | - |
|
1554 | - /** |
|
1555 | - * @return \OCP\Share\IManager |
|
1556 | - */ |
|
1557 | - public function getShareManager() { |
|
1558 | - return $this->query('ShareManager'); |
|
1559 | - } |
|
1560 | - |
|
1561 | - /** |
|
1562 | - * Returns the LDAP Provider |
|
1563 | - * |
|
1564 | - * @return \OCP\LDAP\ILDAPProvider |
|
1565 | - */ |
|
1566 | - public function getLDAPProvider() { |
|
1567 | - return $this->query('LDAPProvider'); |
|
1568 | - } |
|
1569 | - |
|
1570 | - /** |
|
1571 | - * @return \OCP\Settings\IManager |
|
1572 | - */ |
|
1573 | - public function getSettingsManager() { |
|
1574 | - return $this->query('SettingsManager'); |
|
1575 | - } |
|
1576 | - |
|
1577 | - /** |
|
1578 | - * @return \OCP\Files\IAppData |
|
1579 | - */ |
|
1580 | - public function getAppDataDir($app) { |
|
1581 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
1582 | - $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1583 | - return $factory->get($app); |
|
1584 | - } |
|
1585 | - |
|
1586 | - /** |
|
1587 | - * @return \OCP\Lockdown\ILockdownManager |
|
1588 | - */ |
|
1589 | - public function getLockdownManager() { |
|
1590 | - return $this->query('LockdownManager'); |
|
1591 | - } |
|
1592 | - |
|
1593 | - /** |
|
1594 | - * @return \OCP\Federation\ICloudIdManager |
|
1595 | - */ |
|
1596 | - public function getCloudIdManager() { |
|
1597 | - return $this->query(ICloudIdManager::class); |
|
1598 | - } |
|
721 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
722 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
723 | + $classExists = true; |
|
724 | + } else { |
|
725 | + $classExists = false; |
|
726 | + } |
|
727 | + |
|
728 | + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) { |
|
729 | + return new ThemingDefaults( |
|
730 | + $c->getConfig(), |
|
731 | + $c->getL10N('theming'), |
|
732 | + $c->getURLGenerator(), |
|
733 | + new \OC_Defaults(), |
|
734 | + $c->getLazyRootFolder(), |
|
735 | + $c->getMemCacheFactory() |
|
736 | + ); |
|
737 | + } |
|
738 | + return new \OC_Defaults(); |
|
739 | + }); |
|
740 | + $this->registerService('EventDispatcher', function () { |
|
741 | + return new EventDispatcher(); |
|
742 | + }); |
|
743 | + $this->registerService('CryptoWrapper', function (Server $c) { |
|
744 | + // FIXME: Instantiiated here due to cyclic dependency |
|
745 | + $request = new Request( |
|
746 | + [ |
|
747 | + 'get' => $_GET, |
|
748 | + 'post' => $_POST, |
|
749 | + 'files' => $_FILES, |
|
750 | + 'server' => $_SERVER, |
|
751 | + 'env' => $_ENV, |
|
752 | + 'cookies' => $_COOKIE, |
|
753 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
754 | + ? $_SERVER['REQUEST_METHOD'] |
|
755 | + : null, |
|
756 | + ], |
|
757 | + $c->getSecureRandom(), |
|
758 | + $c->getConfig() |
|
759 | + ); |
|
760 | + |
|
761 | + return new CryptoWrapper( |
|
762 | + $c->getConfig(), |
|
763 | + $c->getCrypto(), |
|
764 | + $c->getSecureRandom(), |
|
765 | + $request |
|
766 | + ); |
|
767 | + }); |
|
768 | + $this->registerService('CsrfTokenManager', function (Server $c) { |
|
769 | + $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
770 | + |
|
771 | + return new CsrfTokenManager( |
|
772 | + $tokenGenerator, |
|
773 | + $c->query(SessionStorage::class) |
|
774 | + ); |
|
775 | + }); |
|
776 | + $this->registerService(SessionStorage::class, function (Server $c) { |
|
777 | + return new SessionStorage($c->getSession()); |
|
778 | + }); |
|
779 | + $this->registerService('ContentSecurityPolicyManager', function (Server $c) { |
|
780 | + return new ContentSecurityPolicyManager(); |
|
781 | + }); |
|
782 | + $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
|
783 | + return new ContentSecurityPolicyNonceManager( |
|
784 | + $c->getCsrfTokenManager(), |
|
785 | + $c->getRequest() |
|
786 | + ); |
|
787 | + }); |
|
788 | + $this->registerService('ShareManager', function(Server $c) { |
|
789 | + $config = $c->getConfig(); |
|
790 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
|
791 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
792 | + $factory = new $factoryClass($this); |
|
793 | + |
|
794 | + $manager = new \OC\Share20\Manager( |
|
795 | + $c->getLogger(), |
|
796 | + $c->getConfig(), |
|
797 | + $c->getSecureRandom(), |
|
798 | + $c->getHasher(), |
|
799 | + $c->getMountManager(), |
|
800 | + $c->getGroupManager(), |
|
801 | + $c->getL10N('core'), |
|
802 | + $factory, |
|
803 | + $c->getUserManager(), |
|
804 | + $c->getLazyRootFolder(), |
|
805 | + $c->getEventDispatcher() |
|
806 | + ); |
|
807 | + |
|
808 | + return $manager; |
|
809 | + }); |
|
810 | + $this->registerService('SettingsManager', function(Server $c) { |
|
811 | + $manager = new \OC\Settings\Manager( |
|
812 | + $c->getLogger(), |
|
813 | + $c->getDatabaseConnection(), |
|
814 | + $c->getL10N('lib'), |
|
815 | + $c->getConfig(), |
|
816 | + $c->getEncryptionManager(), |
|
817 | + $c->getUserManager(), |
|
818 | + $c->getLockingProvider(), |
|
819 | + new \OC\Settings\Mapper($c->getDatabaseConnection()), |
|
820 | + $c->getURLGenerator() |
|
821 | + ); |
|
822 | + return $manager; |
|
823 | + }); |
|
824 | + $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
825 | + return new \OC\Files\AppData\Factory( |
|
826 | + $c->getRootFolder(), |
|
827 | + $c->getSystemConfig() |
|
828 | + ); |
|
829 | + }); |
|
830 | + |
|
831 | + $this->registerService('LockdownManager', function (Server $c) { |
|
832 | + return new LockdownManager(); |
|
833 | + }); |
|
834 | + |
|
835 | + $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
836 | + return new CloudIdManager(); |
|
837 | + }); |
|
838 | + |
|
839 | + /* To trick DI since we don't extend the DIContainer here */ |
|
840 | + $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
841 | + return new CleanPreviewsBackgroundJob( |
|
842 | + $c->getRootFolder(), |
|
843 | + $c->getLogger(), |
|
844 | + $c->getJobList(), |
|
845 | + new TimeFactory() |
|
846 | + ); |
|
847 | + }); |
|
848 | + } |
|
849 | + |
|
850 | + /** |
|
851 | + * @return \OCP\Contacts\IManager |
|
852 | + */ |
|
853 | + public function getContactsManager() { |
|
854 | + return $this->query('ContactsManager'); |
|
855 | + } |
|
856 | + |
|
857 | + /** |
|
858 | + * @return \OC\Encryption\Manager |
|
859 | + */ |
|
860 | + public function getEncryptionManager() { |
|
861 | + return $this->query('EncryptionManager'); |
|
862 | + } |
|
863 | + |
|
864 | + /** |
|
865 | + * @return \OC\Encryption\File |
|
866 | + */ |
|
867 | + public function getEncryptionFilesHelper() { |
|
868 | + return $this->query('EncryptionFileHelper'); |
|
869 | + } |
|
870 | + |
|
871 | + /** |
|
872 | + * @return \OCP\Encryption\Keys\IStorage |
|
873 | + */ |
|
874 | + public function getEncryptionKeyStorage() { |
|
875 | + return $this->query('EncryptionKeyStorage'); |
|
876 | + } |
|
877 | + |
|
878 | + /** |
|
879 | + * @return \OC\OCS\DiscoveryService |
|
880 | + */ |
|
881 | + public function getOCSDiscoveryService() { |
|
882 | + return $this->query('OCSDiscoveryService'); |
|
883 | + } |
|
884 | + |
|
885 | + |
|
886 | + /** |
|
887 | + * The current request object holding all information about the request |
|
888 | + * currently being processed is returned from this method. |
|
889 | + * In case the current execution was not initiated by a web request null is returned |
|
890 | + * |
|
891 | + * @return \OCP\IRequest |
|
892 | + */ |
|
893 | + public function getRequest() { |
|
894 | + return $this->query('Request'); |
|
895 | + } |
|
896 | + |
|
897 | + /** |
|
898 | + * Returns the preview manager which can create preview images for a given file |
|
899 | + * |
|
900 | + * @return \OCP\IPreview |
|
901 | + */ |
|
902 | + public function getPreviewManager() { |
|
903 | + return $this->query('PreviewManager'); |
|
904 | + } |
|
905 | + |
|
906 | + /** |
|
907 | + * Returns the tag manager which can get and set tags for different object types |
|
908 | + * |
|
909 | + * @see \OCP\ITagManager::load() |
|
910 | + * @return \OCP\ITagManager |
|
911 | + */ |
|
912 | + public function getTagManager() { |
|
913 | + return $this->query('TagManager'); |
|
914 | + } |
|
915 | + |
|
916 | + /** |
|
917 | + * Returns the system-tag manager |
|
918 | + * |
|
919 | + * @return \OCP\SystemTag\ISystemTagManager |
|
920 | + * |
|
921 | + * @since 9.0.0 |
|
922 | + */ |
|
923 | + public function getSystemTagManager() { |
|
924 | + return $this->query('SystemTagManager'); |
|
925 | + } |
|
926 | + |
|
927 | + /** |
|
928 | + * Returns the system-tag object mapper |
|
929 | + * |
|
930 | + * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
931 | + * |
|
932 | + * @since 9.0.0 |
|
933 | + */ |
|
934 | + public function getSystemTagObjectMapper() { |
|
935 | + return $this->query('SystemTagObjectMapper'); |
|
936 | + } |
|
937 | + |
|
938 | + /** |
|
939 | + * Returns the avatar manager, used for avatar functionality |
|
940 | + * |
|
941 | + * @return \OCP\IAvatarManager |
|
942 | + */ |
|
943 | + public function getAvatarManager() { |
|
944 | + return $this->query('AvatarManager'); |
|
945 | + } |
|
946 | + |
|
947 | + /** |
|
948 | + * Returns the root folder of ownCloud's data directory |
|
949 | + * |
|
950 | + * @return \OCP\Files\IRootFolder |
|
951 | + */ |
|
952 | + public function getRootFolder() { |
|
953 | + return $this->query('LazyRootFolder'); |
|
954 | + } |
|
955 | + |
|
956 | + /** |
|
957 | + * Returns the root folder of ownCloud's data directory |
|
958 | + * This is the lazy variant so this gets only initialized once it |
|
959 | + * is actually used. |
|
960 | + * |
|
961 | + * @return \OCP\Files\IRootFolder |
|
962 | + */ |
|
963 | + public function getLazyRootFolder() { |
|
964 | + return $this->query('LazyRootFolder'); |
|
965 | + } |
|
966 | + |
|
967 | + /** |
|
968 | + * Returns a view to ownCloud's files folder |
|
969 | + * |
|
970 | + * @param string $userId user ID |
|
971 | + * @return \OCP\Files\Folder|null |
|
972 | + */ |
|
973 | + public function getUserFolder($userId = null) { |
|
974 | + if ($userId === null) { |
|
975 | + $user = $this->getUserSession()->getUser(); |
|
976 | + if (!$user) { |
|
977 | + return null; |
|
978 | + } |
|
979 | + $userId = $user->getUID(); |
|
980 | + } |
|
981 | + $root = $this->getRootFolder(); |
|
982 | + return $root->getUserFolder($userId); |
|
983 | + } |
|
984 | + |
|
985 | + /** |
|
986 | + * Returns an app-specific view in ownClouds data directory |
|
987 | + * |
|
988 | + * @return \OCP\Files\Folder |
|
989 | + * @deprecated since 9.2.0 use IAppData |
|
990 | + */ |
|
991 | + public function getAppFolder() { |
|
992 | + $dir = '/' . \OC_App::getCurrentApp(); |
|
993 | + $root = $this->getRootFolder(); |
|
994 | + if (!$root->nodeExists($dir)) { |
|
995 | + $folder = $root->newFolder($dir); |
|
996 | + } else { |
|
997 | + $folder = $root->get($dir); |
|
998 | + } |
|
999 | + return $folder; |
|
1000 | + } |
|
1001 | + |
|
1002 | + /** |
|
1003 | + * @return \OC\User\Manager |
|
1004 | + */ |
|
1005 | + public function getUserManager() { |
|
1006 | + return $this->query('UserManager'); |
|
1007 | + } |
|
1008 | + |
|
1009 | + /** |
|
1010 | + * @return \OC\Group\Manager |
|
1011 | + */ |
|
1012 | + public function getGroupManager() { |
|
1013 | + return $this->query('GroupManager'); |
|
1014 | + } |
|
1015 | + |
|
1016 | + /** |
|
1017 | + * @return \OC\User\Session |
|
1018 | + */ |
|
1019 | + public function getUserSession() { |
|
1020 | + return $this->query('UserSession'); |
|
1021 | + } |
|
1022 | + |
|
1023 | + /** |
|
1024 | + * @return \OCP\ISession |
|
1025 | + */ |
|
1026 | + public function getSession() { |
|
1027 | + return $this->query('UserSession')->getSession(); |
|
1028 | + } |
|
1029 | + |
|
1030 | + /** |
|
1031 | + * @param \OCP\ISession $session |
|
1032 | + */ |
|
1033 | + public function setSession(\OCP\ISession $session) { |
|
1034 | + $this->query(SessionStorage::class)->setSession($session); |
|
1035 | + $this->query('UserSession')->setSession($session); |
|
1036 | + $this->query(Store::class)->setSession($session); |
|
1037 | + } |
|
1038 | + |
|
1039 | + /** |
|
1040 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1041 | + */ |
|
1042 | + public function getTwoFactorAuthManager() { |
|
1043 | + return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1044 | + } |
|
1045 | + |
|
1046 | + /** |
|
1047 | + * @return \OC\NavigationManager |
|
1048 | + */ |
|
1049 | + public function getNavigationManager() { |
|
1050 | + return $this->query('NavigationManager'); |
|
1051 | + } |
|
1052 | + |
|
1053 | + /** |
|
1054 | + * @return \OCP\IConfig |
|
1055 | + */ |
|
1056 | + public function getConfig() { |
|
1057 | + return $this->query('AllConfig'); |
|
1058 | + } |
|
1059 | + |
|
1060 | + /** |
|
1061 | + * @internal For internal use only |
|
1062 | + * @return \OC\SystemConfig |
|
1063 | + */ |
|
1064 | + public function getSystemConfig() { |
|
1065 | + return $this->query('SystemConfig'); |
|
1066 | + } |
|
1067 | + |
|
1068 | + /** |
|
1069 | + * Returns the app config manager |
|
1070 | + * |
|
1071 | + * @return \OCP\IAppConfig |
|
1072 | + */ |
|
1073 | + public function getAppConfig() { |
|
1074 | + return $this->query('AppConfig'); |
|
1075 | + } |
|
1076 | + |
|
1077 | + /** |
|
1078 | + * @return \OCP\L10N\IFactory |
|
1079 | + */ |
|
1080 | + public function getL10NFactory() { |
|
1081 | + return $this->query('L10NFactory'); |
|
1082 | + } |
|
1083 | + |
|
1084 | + /** |
|
1085 | + * get an L10N instance |
|
1086 | + * |
|
1087 | + * @param string $app appid |
|
1088 | + * @param string $lang |
|
1089 | + * @return IL10N |
|
1090 | + */ |
|
1091 | + public function getL10N($app, $lang = null) { |
|
1092 | + return $this->getL10NFactory()->get($app, $lang); |
|
1093 | + } |
|
1094 | + |
|
1095 | + /** |
|
1096 | + * @return \OCP\IURLGenerator |
|
1097 | + */ |
|
1098 | + public function getURLGenerator() { |
|
1099 | + return $this->query('URLGenerator'); |
|
1100 | + } |
|
1101 | + |
|
1102 | + /** |
|
1103 | + * @return \OCP\IHelper |
|
1104 | + */ |
|
1105 | + public function getHelper() { |
|
1106 | + return $this->query('AppHelper'); |
|
1107 | + } |
|
1108 | + |
|
1109 | + /** |
|
1110 | + * @return AppFetcher |
|
1111 | + */ |
|
1112 | + public function getAppFetcher() { |
|
1113 | + return $this->query('AppFetcher'); |
|
1114 | + } |
|
1115 | + |
|
1116 | + /** |
|
1117 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1118 | + * getMemCacheFactory() instead. |
|
1119 | + * |
|
1120 | + * @return \OCP\ICache |
|
1121 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1122 | + */ |
|
1123 | + public function getCache() { |
|
1124 | + return $this->query('UserCache'); |
|
1125 | + } |
|
1126 | + |
|
1127 | + /** |
|
1128 | + * Returns an \OCP\CacheFactory instance |
|
1129 | + * |
|
1130 | + * @return \OCP\ICacheFactory |
|
1131 | + */ |
|
1132 | + public function getMemCacheFactory() { |
|
1133 | + return $this->query('MemCacheFactory'); |
|
1134 | + } |
|
1135 | + |
|
1136 | + /** |
|
1137 | + * Returns an \OC\RedisFactory instance |
|
1138 | + * |
|
1139 | + * @return \OC\RedisFactory |
|
1140 | + */ |
|
1141 | + public function getGetRedisFactory() { |
|
1142 | + return $this->query('RedisFactory'); |
|
1143 | + } |
|
1144 | + |
|
1145 | + |
|
1146 | + /** |
|
1147 | + * Returns the current session |
|
1148 | + * |
|
1149 | + * @return \OCP\IDBConnection |
|
1150 | + */ |
|
1151 | + public function getDatabaseConnection() { |
|
1152 | + return $this->query('DatabaseConnection'); |
|
1153 | + } |
|
1154 | + |
|
1155 | + /** |
|
1156 | + * Returns the activity manager |
|
1157 | + * |
|
1158 | + * @return \OCP\Activity\IManager |
|
1159 | + */ |
|
1160 | + public function getActivityManager() { |
|
1161 | + return $this->query('ActivityManager'); |
|
1162 | + } |
|
1163 | + |
|
1164 | + /** |
|
1165 | + * Returns an job list for controlling background jobs |
|
1166 | + * |
|
1167 | + * @return \OCP\BackgroundJob\IJobList |
|
1168 | + */ |
|
1169 | + public function getJobList() { |
|
1170 | + return $this->query('JobList'); |
|
1171 | + } |
|
1172 | + |
|
1173 | + /** |
|
1174 | + * Returns a logger instance |
|
1175 | + * |
|
1176 | + * @return \OCP\ILogger |
|
1177 | + */ |
|
1178 | + public function getLogger() { |
|
1179 | + return $this->query('Logger'); |
|
1180 | + } |
|
1181 | + |
|
1182 | + /** |
|
1183 | + * Returns a router for generating and matching urls |
|
1184 | + * |
|
1185 | + * @return \OCP\Route\IRouter |
|
1186 | + */ |
|
1187 | + public function getRouter() { |
|
1188 | + return $this->query('Router'); |
|
1189 | + } |
|
1190 | + |
|
1191 | + /** |
|
1192 | + * Returns a search instance |
|
1193 | + * |
|
1194 | + * @return \OCP\ISearch |
|
1195 | + */ |
|
1196 | + public function getSearch() { |
|
1197 | + return $this->query('Search'); |
|
1198 | + } |
|
1199 | + |
|
1200 | + /** |
|
1201 | + * Returns a SecureRandom instance |
|
1202 | + * |
|
1203 | + * @return \OCP\Security\ISecureRandom |
|
1204 | + */ |
|
1205 | + public function getSecureRandom() { |
|
1206 | + return $this->query('SecureRandom'); |
|
1207 | + } |
|
1208 | + |
|
1209 | + /** |
|
1210 | + * Returns a Crypto instance |
|
1211 | + * |
|
1212 | + * @return \OCP\Security\ICrypto |
|
1213 | + */ |
|
1214 | + public function getCrypto() { |
|
1215 | + return $this->query('Crypto'); |
|
1216 | + } |
|
1217 | + |
|
1218 | + /** |
|
1219 | + * Returns a Hasher instance |
|
1220 | + * |
|
1221 | + * @return \OCP\Security\IHasher |
|
1222 | + */ |
|
1223 | + public function getHasher() { |
|
1224 | + return $this->query('Hasher'); |
|
1225 | + } |
|
1226 | + |
|
1227 | + /** |
|
1228 | + * Returns a CredentialsManager instance |
|
1229 | + * |
|
1230 | + * @return \OCP\Security\ICredentialsManager |
|
1231 | + */ |
|
1232 | + public function getCredentialsManager() { |
|
1233 | + return $this->query('CredentialsManager'); |
|
1234 | + } |
|
1235 | + |
|
1236 | + /** |
|
1237 | + * Returns an instance of the HTTP helper class |
|
1238 | + * |
|
1239 | + * @deprecated Use getHTTPClientService() |
|
1240 | + * @return \OC\HTTPHelper |
|
1241 | + */ |
|
1242 | + public function getHTTPHelper() { |
|
1243 | + return $this->query('HTTPHelper'); |
|
1244 | + } |
|
1245 | + |
|
1246 | + /** |
|
1247 | + * Get the certificate manager for the user |
|
1248 | + * |
|
1249 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1250 | + * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1251 | + */ |
|
1252 | + public function getCertificateManager($userId = '') { |
|
1253 | + if ($userId === '') { |
|
1254 | + $userSession = $this->getUserSession(); |
|
1255 | + $user = $userSession->getUser(); |
|
1256 | + if (is_null($user)) { |
|
1257 | + return null; |
|
1258 | + } |
|
1259 | + $userId = $user->getUID(); |
|
1260 | + } |
|
1261 | + return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger()); |
|
1262 | + } |
|
1263 | + |
|
1264 | + /** |
|
1265 | + * Returns an instance of the HTTP client service |
|
1266 | + * |
|
1267 | + * @return \OCP\Http\Client\IClientService |
|
1268 | + */ |
|
1269 | + public function getHTTPClientService() { |
|
1270 | + return $this->query('HttpClientService'); |
|
1271 | + } |
|
1272 | + |
|
1273 | + /** |
|
1274 | + * Create a new event source |
|
1275 | + * |
|
1276 | + * @return \OCP\IEventSource |
|
1277 | + */ |
|
1278 | + public function createEventSource() { |
|
1279 | + return new \OC_EventSource(); |
|
1280 | + } |
|
1281 | + |
|
1282 | + /** |
|
1283 | + * Get the active event logger |
|
1284 | + * |
|
1285 | + * The returned logger only logs data when debug mode is enabled |
|
1286 | + * |
|
1287 | + * @return \OCP\Diagnostics\IEventLogger |
|
1288 | + */ |
|
1289 | + public function getEventLogger() { |
|
1290 | + return $this->query('EventLogger'); |
|
1291 | + } |
|
1292 | + |
|
1293 | + /** |
|
1294 | + * Get the active query logger |
|
1295 | + * |
|
1296 | + * The returned logger only logs data when debug mode is enabled |
|
1297 | + * |
|
1298 | + * @return \OCP\Diagnostics\IQueryLogger |
|
1299 | + */ |
|
1300 | + public function getQueryLogger() { |
|
1301 | + return $this->query('QueryLogger'); |
|
1302 | + } |
|
1303 | + |
|
1304 | + /** |
|
1305 | + * Get the manager for temporary files and folders |
|
1306 | + * |
|
1307 | + * @return \OCP\ITempManager |
|
1308 | + */ |
|
1309 | + public function getTempManager() { |
|
1310 | + return $this->query('TempManager'); |
|
1311 | + } |
|
1312 | + |
|
1313 | + /** |
|
1314 | + * Get the app manager |
|
1315 | + * |
|
1316 | + * @return \OCP\App\IAppManager |
|
1317 | + */ |
|
1318 | + public function getAppManager() { |
|
1319 | + return $this->query('AppManager'); |
|
1320 | + } |
|
1321 | + |
|
1322 | + /** |
|
1323 | + * Creates a new mailer |
|
1324 | + * |
|
1325 | + * @return \OCP\Mail\IMailer |
|
1326 | + */ |
|
1327 | + public function getMailer() { |
|
1328 | + return $this->query('Mailer'); |
|
1329 | + } |
|
1330 | + |
|
1331 | + /** |
|
1332 | + * Get the webroot |
|
1333 | + * |
|
1334 | + * @return string |
|
1335 | + */ |
|
1336 | + public function getWebRoot() { |
|
1337 | + return $this->webRoot; |
|
1338 | + } |
|
1339 | + |
|
1340 | + /** |
|
1341 | + * @return \OC\OCSClient |
|
1342 | + */ |
|
1343 | + public function getOcsClient() { |
|
1344 | + return $this->query('OcsClient'); |
|
1345 | + } |
|
1346 | + |
|
1347 | + /** |
|
1348 | + * @return \OCP\IDateTimeZone |
|
1349 | + */ |
|
1350 | + public function getDateTimeZone() { |
|
1351 | + return $this->query('DateTimeZone'); |
|
1352 | + } |
|
1353 | + |
|
1354 | + /** |
|
1355 | + * @return \OCP\IDateTimeFormatter |
|
1356 | + */ |
|
1357 | + public function getDateTimeFormatter() { |
|
1358 | + return $this->query('DateTimeFormatter'); |
|
1359 | + } |
|
1360 | + |
|
1361 | + /** |
|
1362 | + * @return \OCP\Files\Config\IMountProviderCollection |
|
1363 | + */ |
|
1364 | + public function getMountProviderCollection() { |
|
1365 | + return $this->query('MountConfigManager'); |
|
1366 | + } |
|
1367 | + |
|
1368 | + /** |
|
1369 | + * Get the IniWrapper |
|
1370 | + * |
|
1371 | + * @return IniGetWrapper |
|
1372 | + */ |
|
1373 | + public function getIniWrapper() { |
|
1374 | + return $this->query('IniWrapper'); |
|
1375 | + } |
|
1376 | + |
|
1377 | + /** |
|
1378 | + * @return \OCP\Command\IBus |
|
1379 | + */ |
|
1380 | + public function getCommandBus() { |
|
1381 | + return $this->query('AsyncCommandBus'); |
|
1382 | + } |
|
1383 | + |
|
1384 | + /** |
|
1385 | + * Get the trusted domain helper |
|
1386 | + * |
|
1387 | + * @return TrustedDomainHelper |
|
1388 | + */ |
|
1389 | + public function getTrustedDomainHelper() { |
|
1390 | + return $this->query('TrustedDomainHelper'); |
|
1391 | + } |
|
1392 | + |
|
1393 | + /** |
|
1394 | + * Get the locking provider |
|
1395 | + * |
|
1396 | + * @return \OCP\Lock\ILockingProvider |
|
1397 | + * @since 8.1.0 |
|
1398 | + */ |
|
1399 | + public function getLockingProvider() { |
|
1400 | + return $this->query('LockingProvider'); |
|
1401 | + } |
|
1402 | + |
|
1403 | + /** |
|
1404 | + * @return \OCP\Files\Mount\IMountManager |
|
1405 | + **/ |
|
1406 | + function getMountManager() { |
|
1407 | + return $this->query('MountManager'); |
|
1408 | + } |
|
1409 | + |
|
1410 | + /** @return \OCP\Files\Config\IUserMountCache */ |
|
1411 | + function getUserMountCache() { |
|
1412 | + return $this->query('UserMountCache'); |
|
1413 | + } |
|
1414 | + |
|
1415 | + /** |
|
1416 | + * Get the MimeTypeDetector |
|
1417 | + * |
|
1418 | + * @return \OCP\Files\IMimeTypeDetector |
|
1419 | + */ |
|
1420 | + public function getMimeTypeDetector() { |
|
1421 | + return $this->query('MimeTypeDetector'); |
|
1422 | + } |
|
1423 | + |
|
1424 | + /** |
|
1425 | + * Get the MimeTypeLoader |
|
1426 | + * |
|
1427 | + * @return \OCP\Files\IMimeTypeLoader |
|
1428 | + */ |
|
1429 | + public function getMimeTypeLoader() { |
|
1430 | + return $this->query('MimeTypeLoader'); |
|
1431 | + } |
|
1432 | + |
|
1433 | + /** |
|
1434 | + * Get the manager of all the capabilities |
|
1435 | + * |
|
1436 | + * @return \OC\CapabilitiesManager |
|
1437 | + */ |
|
1438 | + public function getCapabilitiesManager() { |
|
1439 | + return $this->query('CapabilitiesManager'); |
|
1440 | + } |
|
1441 | + |
|
1442 | + /** |
|
1443 | + * Get the EventDispatcher |
|
1444 | + * |
|
1445 | + * @return EventDispatcherInterface |
|
1446 | + * @since 8.2.0 |
|
1447 | + */ |
|
1448 | + public function getEventDispatcher() { |
|
1449 | + return $this->query('EventDispatcher'); |
|
1450 | + } |
|
1451 | + |
|
1452 | + /** |
|
1453 | + * Get the Notification Manager |
|
1454 | + * |
|
1455 | + * @return \OCP\Notification\IManager |
|
1456 | + * @since 8.2.0 |
|
1457 | + */ |
|
1458 | + public function getNotificationManager() { |
|
1459 | + return $this->query('NotificationManager'); |
|
1460 | + } |
|
1461 | + |
|
1462 | + /** |
|
1463 | + * @return \OCP\Comments\ICommentsManager |
|
1464 | + */ |
|
1465 | + public function getCommentsManager() { |
|
1466 | + return $this->query('CommentsManager'); |
|
1467 | + } |
|
1468 | + |
|
1469 | + /** |
|
1470 | + * @return \OC_Defaults |
|
1471 | + */ |
|
1472 | + public function getThemingDefaults() { |
|
1473 | + return $this->query('ThemingDefaults'); |
|
1474 | + } |
|
1475 | + |
|
1476 | + /** |
|
1477 | + * @return \OC\IntegrityCheck\Checker |
|
1478 | + */ |
|
1479 | + public function getIntegrityCodeChecker() { |
|
1480 | + return $this->query('IntegrityCodeChecker'); |
|
1481 | + } |
|
1482 | + |
|
1483 | + /** |
|
1484 | + * @return \OC\Session\CryptoWrapper |
|
1485 | + */ |
|
1486 | + public function getSessionCryptoWrapper() { |
|
1487 | + return $this->query('CryptoWrapper'); |
|
1488 | + } |
|
1489 | + |
|
1490 | + /** |
|
1491 | + * @return CsrfTokenManager |
|
1492 | + */ |
|
1493 | + public function getCsrfTokenManager() { |
|
1494 | + return $this->query('CsrfTokenManager'); |
|
1495 | + } |
|
1496 | + |
|
1497 | + /** |
|
1498 | + * @return Throttler |
|
1499 | + */ |
|
1500 | + public function getBruteForceThrottler() { |
|
1501 | + return $this->query('Throttler'); |
|
1502 | + } |
|
1503 | + |
|
1504 | + /** |
|
1505 | + * @return IContentSecurityPolicyManager |
|
1506 | + */ |
|
1507 | + public function getContentSecurityPolicyManager() { |
|
1508 | + return $this->query('ContentSecurityPolicyManager'); |
|
1509 | + } |
|
1510 | + |
|
1511 | + /** |
|
1512 | + * @return ContentSecurityPolicyNonceManager |
|
1513 | + */ |
|
1514 | + public function getContentSecurityPolicyNonceManager() { |
|
1515 | + return $this->query('ContentSecurityPolicyNonceManager'); |
|
1516 | + } |
|
1517 | + |
|
1518 | + /** |
|
1519 | + * Not a public API as of 8.2, wait for 9.0 |
|
1520 | + * |
|
1521 | + * @return \OCA\Files_External\Service\BackendService |
|
1522 | + */ |
|
1523 | + public function getStoragesBackendService() { |
|
1524 | + return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1525 | + } |
|
1526 | + |
|
1527 | + /** |
|
1528 | + * Not a public API as of 8.2, wait for 9.0 |
|
1529 | + * |
|
1530 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1531 | + */ |
|
1532 | + public function getGlobalStoragesService() { |
|
1533 | + return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1534 | + } |
|
1535 | + |
|
1536 | + /** |
|
1537 | + * Not a public API as of 8.2, wait for 9.0 |
|
1538 | + * |
|
1539 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1540 | + */ |
|
1541 | + public function getUserGlobalStoragesService() { |
|
1542 | + return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1543 | + } |
|
1544 | + |
|
1545 | + /** |
|
1546 | + * Not a public API as of 8.2, wait for 9.0 |
|
1547 | + * |
|
1548 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
1549 | + */ |
|
1550 | + public function getUserStoragesService() { |
|
1551 | + return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1552 | + } |
|
1553 | + |
|
1554 | + /** |
|
1555 | + * @return \OCP\Share\IManager |
|
1556 | + */ |
|
1557 | + public function getShareManager() { |
|
1558 | + return $this->query('ShareManager'); |
|
1559 | + } |
|
1560 | + |
|
1561 | + /** |
|
1562 | + * Returns the LDAP Provider |
|
1563 | + * |
|
1564 | + * @return \OCP\LDAP\ILDAPProvider |
|
1565 | + */ |
|
1566 | + public function getLDAPProvider() { |
|
1567 | + return $this->query('LDAPProvider'); |
|
1568 | + } |
|
1569 | + |
|
1570 | + /** |
|
1571 | + * @return \OCP\Settings\IManager |
|
1572 | + */ |
|
1573 | + public function getSettingsManager() { |
|
1574 | + return $this->query('SettingsManager'); |
|
1575 | + } |
|
1576 | + |
|
1577 | + /** |
|
1578 | + * @return \OCP\Files\IAppData |
|
1579 | + */ |
|
1580 | + public function getAppDataDir($app) { |
|
1581 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
1582 | + $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1583 | + return $factory->get($app); |
|
1584 | + } |
|
1585 | + |
|
1586 | + /** |
|
1587 | + * @return \OCP\Lockdown\ILockdownManager |
|
1588 | + */ |
|
1589 | + public function getLockdownManager() { |
|
1590 | + return $this->query('LockdownManager'); |
|
1591 | + } |
|
1592 | + |
|
1593 | + /** |
|
1594 | + * @return \OCP\Federation\ICloudIdManager |
|
1595 | + */ |
|
1596 | + public function getCloudIdManager() { |
|
1597 | + return $this->query(ICloudIdManager::class); |
|
1598 | + } |
|
1599 | 1599 | } |
@@ -120,11 +120,11 @@ discard block |
||
120 | 120 | parent::__construct(); |
121 | 121 | $this->webRoot = $webRoot; |
122 | 122 | |
123 | - $this->registerService('ContactsManager', function ($c) { |
|
123 | + $this->registerService('ContactsManager', function($c) { |
|
124 | 124 | return new ContactsManager(); |
125 | 125 | }); |
126 | 126 | |
127 | - $this->registerService('PreviewManager', function (Server $c) { |
|
127 | + $this->registerService('PreviewManager', function(Server $c) { |
|
128 | 128 | return new PreviewManager( |
129 | 129 | $c->getConfig(), |
130 | 130 | $c->getRootFolder(), |
@@ -134,17 +134,17 @@ discard block |
||
134 | 134 | ); |
135 | 135 | }); |
136 | 136 | |
137 | - $this->registerService('OCSDiscoveryService', function (Server $c) { |
|
137 | + $this->registerService('OCSDiscoveryService', function(Server $c) { |
|
138 | 138 | return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
139 | 139 | ; }); |
140 | 140 | |
141 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
141 | + $this->registerService(\OC\Preview\Watcher::class, function(Server $c) { |
|
142 | 142 | return new \OC\Preview\Watcher( |
143 | 143 | $c->getAppDataDir('preview') |
144 | 144 | ); |
145 | 145 | }); |
146 | 146 | |
147 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
147 | + $this->registerService('EncryptionManager', function(Server $c) { |
|
148 | 148 | $view = new View(); |
149 | 149 | $util = new Encryption\Util( |
150 | 150 | $view, |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | ); |
163 | 163 | }); |
164 | 164 | |
165 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
165 | + $this->registerService('EncryptionFileHelper', function(Server $c) { |
|
166 | 166 | $util = new Encryption\Util( |
167 | 167 | new View(), |
168 | 168 | $c->getUserManager(), |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | return new Encryption\File($util); |
173 | 173 | }); |
174 | 174 | |
175 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
175 | + $this->registerService('EncryptionKeyStorage', function(Server $c) { |
|
176 | 176 | $view = new View(); |
177 | 177 | $util = new Encryption\Util( |
178 | 178 | $view, |
@@ -183,27 +183,27 @@ discard block |
||
183 | 183 | |
184 | 184 | return new Encryption\Keys\Storage($view, $util); |
185 | 185 | }); |
186 | - $this->registerService('TagMapper', function (Server $c) { |
|
186 | + $this->registerService('TagMapper', function(Server $c) { |
|
187 | 187 | return new TagMapper($c->getDatabaseConnection()); |
188 | 188 | }); |
189 | - $this->registerService('TagManager', function (Server $c) { |
|
189 | + $this->registerService('TagManager', function(Server $c) { |
|
190 | 190 | $tagMapper = $c->query('TagMapper'); |
191 | 191 | return new TagManager($tagMapper, $c->getUserSession()); |
192 | 192 | }); |
193 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
193 | + $this->registerService('SystemTagManagerFactory', function(Server $c) { |
|
194 | 194 | $config = $c->getConfig(); |
195 | 195 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
196 | 196 | /** @var \OC\SystemTag\ManagerFactory $factory */ |
197 | 197 | $factory = new $factoryClass($this); |
198 | 198 | return $factory; |
199 | 199 | }); |
200 | - $this->registerService('SystemTagManager', function (Server $c) { |
|
200 | + $this->registerService('SystemTagManager', function(Server $c) { |
|
201 | 201 | return $c->query('SystemTagManagerFactory')->getManager(); |
202 | 202 | }); |
203 | - $this->registerService('SystemTagObjectMapper', function (Server $c) { |
|
203 | + $this->registerService('SystemTagObjectMapper', function(Server $c) { |
|
204 | 204 | return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
205 | 205 | }); |
206 | - $this->registerService('RootFolder', function (Server $c) { |
|
206 | + $this->registerService('RootFolder', function(Server $c) { |
|
207 | 207 | $manager = \OC\Files\Filesystem::getMountManager(null); |
208 | 208 | $view = new View(); |
209 | 209 | $root = new Root( |
@@ -227,28 +227,28 @@ discard block |
||
227 | 227 | return $c->query('RootFolder'); |
228 | 228 | }); |
229 | 229 | }); |
230 | - $this->registerService('UserManager', function (Server $c) { |
|
230 | + $this->registerService('UserManager', function(Server $c) { |
|
231 | 231 | $config = $c->getConfig(); |
232 | 232 | return new \OC\User\Manager($config); |
233 | 233 | }); |
234 | - $this->registerService('GroupManager', function (Server $c) { |
|
234 | + $this->registerService('GroupManager', function(Server $c) { |
|
235 | 235 | $groupManager = new \OC\Group\Manager($this->getUserManager()); |
236 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
236 | + $groupManager->listen('\OC\Group', 'preCreate', function($gid) { |
|
237 | 237 | \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
238 | 238 | }); |
239 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
239 | + $groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) { |
|
240 | 240 | \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
241 | 241 | }); |
242 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
242 | + $groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) { |
|
243 | 243 | \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
244 | 244 | }); |
245 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
245 | + $groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) { |
|
246 | 246 | \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
247 | 247 | }); |
248 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
248 | + $groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
249 | 249 | \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
250 | 250 | }); |
251 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
251 | + $groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
252 | 252 | \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
253 | 253 | //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
254 | 254 | \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
@@ -266,11 +266,11 @@ discard block |
||
266 | 266 | return new Store($session, $logger, $tokenProvider); |
267 | 267 | }); |
268 | 268 | $this->registerAlias(IStore::class, Store::class); |
269 | - $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
269 | + $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function(Server $c) { |
|
270 | 270 | $dbConnection = $c->getDatabaseConnection(); |
271 | 271 | return new Authentication\Token\DefaultTokenMapper($dbConnection); |
272 | 272 | }); |
273 | - $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
273 | + $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function(Server $c) { |
|
274 | 274 | $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
275 | 275 | $crypto = $c->getCrypto(); |
276 | 276 | $config = $c->getConfig(); |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
280 | 280 | }); |
281 | 281 | $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
282 | - $this->registerService('UserSession', function (Server $c) { |
|
282 | + $this->registerService('UserSession', function(Server $c) { |
|
283 | 283 | $manager = $c->getUserManager(); |
284 | 284 | $session = new \OC\Session\Memory(''); |
285 | 285 | $timeFactory = new TimeFactory(); |
@@ -292,69 +292,69 @@ discard block |
||
292 | 292 | } |
293 | 293 | |
294 | 294 | $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom()); |
295 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
295 | + $userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) { |
|
296 | 296 | \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
297 | 297 | }); |
298 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
298 | + $userSession->listen('\OC\User', 'postCreateUser', function($user, $password) { |
|
299 | 299 | /** @var $user \OC\User\User */ |
300 | 300 | \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
301 | 301 | }); |
302 | - $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
302 | + $userSession->listen('\OC\User', 'preDelete', function($user) { |
|
303 | 303 | /** @var $user \OC\User\User */ |
304 | 304 | \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
305 | 305 | }); |
306 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
306 | + $userSession->listen('\OC\User', 'postDelete', function($user) { |
|
307 | 307 | /** @var $user \OC\User\User */ |
308 | 308 | \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
309 | 309 | }); |
310 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
310 | + $userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) { |
|
311 | 311 | /** @var $user \OC\User\User */ |
312 | 312 | \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
313 | 313 | }); |
314 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
314 | + $userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) { |
|
315 | 315 | /** @var $user \OC\User\User */ |
316 | 316 | \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
317 | 317 | }); |
318 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
318 | + $userSession->listen('\OC\User', 'preLogin', function($uid, $password) { |
|
319 | 319 | \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
320 | 320 | }); |
321 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
321 | + $userSession->listen('\OC\User', 'postLogin', function($user, $password) { |
|
322 | 322 | /** @var $user \OC\User\User */ |
323 | 323 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
324 | 324 | }); |
325 | - $userSession->listen('\OC\User', 'logout', function () { |
|
325 | + $userSession->listen('\OC\User', 'logout', function() { |
|
326 | 326 | \OC_Hook::emit('OC_User', 'logout', array()); |
327 | 327 | }); |
328 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) { |
|
328 | + $userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value) { |
|
329 | 329 | /** @var $user \OC\User\User */ |
330 | 330 | \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value)); |
331 | 331 | }); |
332 | 332 | return $userSession; |
333 | 333 | }); |
334 | 334 | |
335 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
335 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function(Server $c) { |
|
336 | 336 | return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger()); |
337 | 337 | }); |
338 | 338 | |
339 | - $this->registerService('NavigationManager', function (Server $c) { |
|
339 | + $this->registerService('NavigationManager', function(Server $c) { |
|
340 | 340 | return new \OC\NavigationManager($c->getAppManager(), |
341 | 341 | $c->getURLGenerator(), |
342 | 342 | $c->getL10NFactory(), |
343 | 343 | $c->getUserSession(), |
344 | 344 | $c->getGroupManager()); |
345 | 345 | }); |
346 | - $this->registerService('AllConfig', function (Server $c) { |
|
346 | + $this->registerService('AllConfig', function(Server $c) { |
|
347 | 347 | return new \OC\AllConfig( |
348 | 348 | $c->getSystemConfig() |
349 | 349 | ); |
350 | 350 | }); |
351 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
351 | + $this->registerService('SystemConfig', function($c) use ($config) { |
|
352 | 352 | return new \OC\SystemConfig($config); |
353 | 353 | }); |
354 | - $this->registerService('AppConfig', function (Server $c) { |
|
354 | + $this->registerService('AppConfig', function(Server $c) { |
|
355 | 355 | return new \OC\AppConfig($c->getDatabaseConnection()); |
356 | 356 | }); |
357 | - $this->registerService('L10NFactory', function (Server $c) { |
|
357 | + $this->registerService('L10NFactory', function(Server $c) { |
|
358 | 358 | return new \OC\L10N\Factory( |
359 | 359 | $c->getConfig(), |
360 | 360 | $c->getRequest(), |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | \OC::$SERVERROOT |
363 | 363 | ); |
364 | 364 | }); |
365 | - $this->registerService('URLGenerator', function (Server $c) { |
|
365 | + $this->registerService('URLGenerator', function(Server $c) { |
|
366 | 366 | $config = $c->getConfig(); |
367 | 367 | $cacheFactory = $c->getMemCacheFactory(); |
368 | 368 | return new \OC\URLGenerator( |
@@ -370,10 +370,10 @@ discard block |
||
370 | 370 | $cacheFactory |
371 | 371 | ); |
372 | 372 | }); |
373 | - $this->registerService('AppHelper', function ($c) { |
|
373 | + $this->registerService('AppHelper', function($c) { |
|
374 | 374 | return new \OC\AppHelper(); |
375 | 375 | }); |
376 | - $this->registerService('AppFetcher', function ($c) { |
|
376 | + $this->registerService('AppFetcher', function($c) { |
|
377 | 377 | return new AppFetcher( |
378 | 378 | $this->getAppDataDir('appstore'), |
379 | 379 | $this->getHTTPClientService(), |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | $this->getConfig() |
382 | 382 | ); |
383 | 383 | }); |
384 | - $this->registerService('CategoryFetcher', function ($c) { |
|
384 | + $this->registerService('CategoryFetcher', function($c) { |
|
385 | 385 | return new CategoryFetcher( |
386 | 386 | $this->getAppDataDir('appstore'), |
387 | 387 | $this->getHTTPClientService(), |
@@ -389,19 +389,19 @@ discard block |
||
389 | 389 | $this->getConfig() |
390 | 390 | ); |
391 | 391 | }); |
392 | - $this->registerService('UserCache', function ($c) { |
|
392 | + $this->registerService('UserCache', function($c) { |
|
393 | 393 | return new Cache\File(); |
394 | 394 | }); |
395 | - $this->registerService('MemCacheFactory', function (Server $c) { |
|
395 | + $this->registerService('MemCacheFactory', function(Server $c) { |
|
396 | 396 | $config = $c->getConfig(); |
397 | 397 | |
398 | 398 | if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
399 | 399 | $v = \OC_App::getAppVersions(); |
400 | - $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php')); |
|
400 | + $v['core'] = md5(file_get_contents(\OC::$SERVERROOT.'/version.php')); |
|
401 | 401 | $version = implode(',', $v); |
402 | 402 | $instanceId = \OC_Util::getInstanceId(); |
403 | 403 | $path = \OC::$SERVERROOT; |
404 | - $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT); |
|
404 | + $prefix = md5($instanceId.'-'.$version.'-'.$path.'-'.\OC::$WEBROOT); |
|
405 | 405 | return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
406 | 406 | $config->getSystemValue('memcache.local', null), |
407 | 407 | $config->getSystemValue('memcache.distributed', null), |
@@ -415,11 +415,11 @@ discard block |
||
415 | 415 | '\\OC\\Memcache\\ArrayCache' |
416 | 416 | ); |
417 | 417 | }); |
418 | - $this->registerService('RedisFactory', function (Server $c) { |
|
418 | + $this->registerService('RedisFactory', function(Server $c) { |
|
419 | 419 | $systemConfig = $c->getSystemConfig(); |
420 | 420 | return new RedisFactory($systemConfig); |
421 | 421 | }); |
422 | - $this->registerService('ActivityManager', function (Server $c) { |
|
422 | + $this->registerService('ActivityManager', function(Server $c) { |
|
423 | 423 | return new \OC\Activity\Manager( |
424 | 424 | $c->getRequest(), |
425 | 425 | $c->getUserSession(), |
@@ -427,13 +427,13 @@ discard block |
||
427 | 427 | $c->query(IValidator::class) |
428 | 428 | ); |
429 | 429 | }); |
430 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
430 | + $this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) { |
|
431 | 431 | return new \OC\Activity\EventMerger( |
432 | 432 | $c->getL10N('lib') |
433 | 433 | ); |
434 | 434 | }); |
435 | 435 | $this->registerAlias(IValidator::class, Validator::class); |
436 | - $this->registerService('AvatarManager', function (Server $c) { |
|
436 | + $this->registerService('AvatarManager', function(Server $c) { |
|
437 | 437 | return new AvatarManager( |
438 | 438 | $c->getUserManager(), |
439 | 439 | $c->getAppDataDir('avatar'), |
@@ -442,14 +442,14 @@ discard block |
||
442 | 442 | $c->getConfig() |
443 | 443 | ); |
444 | 444 | }); |
445 | - $this->registerService('Logger', function (Server $c) { |
|
445 | + $this->registerService('Logger', function(Server $c) { |
|
446 | 446 | $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
447 | 447 | $logger = Log::getLogClass($logType); |
448 | 448 | call_user_func(array($logger, 'init')); |
449 | 449 | |
450 | 450 | return new Log($logger); |
451 | 451 | }); |
452 | - $this->registerService('JobList', function (Server $c) { |
|
452 | + $this->registerService('JobList', function(Server $c) { |
|
453 | 453 | $config = $c->getConfig(); |
454 | 454 | return new \OC\BackgroundJob\JobList( |
455 | 455 | $c->getDatabaseConnection(), |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | new TimeFactory() |
458 | 458 | ); |
459 | 459 | }); |
460 | - $this->registerService('Router', function (Server $c) { |
|
460 | + $this->registerService('Router', function(Server $c) { |
|
461 | 461 | $cacheFactory = $c->getMemCacheFactory(); |
462 | 462 | $logger = $c->getLogger(); |
463 | 463 | if ($cacheFactory->isAvailable()) { |
@@ -467,22 +467,22 @@ discard block |
||
467 | 467 | } |
468 | 468 | return $router; |
469 | 469 | }); |
470 | - $this->registerService('Search', function ($c) { |
|
470 | + $this->registerService('Search', function($c) { |
|
471 | 471 | return new Search(); |
472 | 472 | }); |
473 | - $this->registerService('SecureRandom', function ($c) { |
|
473 | + $this->registerService('SecureRandom', function($c) { |
|
474 | 474 | return new SecureRandom(); |
475 | 475 | }); |
476 | - $this->registerService('Crypto', function (Server $c) { |
|
476 | + $this->registerService('Crypto', function(Server $c) { |
|
477 | 477 | return new Crypto($c->getConfig(), $c->getSecureRandom()); |
478 | 478 | }); |
479 | - $this->registerService('Hasher', function (Server $c) { |
|
479 | + $this->registerService('Hasher', function(Server $c) { |
|
480 | 480 | return new Hasher($c->getConfig()); |
481 | 481 | }); |
482 | - $this->registerService('CredentialsManager', function (Server $c) { |
|
482 | + $this->registerService('CredentialsManager', function(Server $c) { |
|
483 | 483 | return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
484 | 484 | }); |
485 | - $this->registerService('DatabaseConnection', function (Server $c) { |
|
485 | + $this->registerService('DatabaseConnection', function(Server $c) { |
|
486 | 486 | $systemConfig = $c->getSystemConfig(); |
487 | 487 | $factory = new \OC\DB\ConnectionFactory($c->getConfig()); |
488 | 488 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
@@ -494,14 +494,14 @@ discard block |
||
494 | 494 | $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
495 | 495 | return $connection; |
496 | 496 | }); |
497 | - $this->registerService('HTTPHelper', function (Server $c) { |
|
497 | + $this->registerService('HTTPHelper', function(Server $c) { |
|
498 | 498 | $config = $c->getConfig(); |
499 | 499 | return new HTTPHelper( |
500 | 500 | $config, |
501 | 501 | $c->getHTTPClientService() |
502 | 502 | ); |
503 | 503 | }); |
504 | - $this->registerService('HttpClientService', function (Server $c) { |
|
504 | + $this->registerService('HttpClientService', function(Server $c) { |
|
505 | 505 | $user = \OC_User::getUser(); |
506 | 506 | $uid = $user ? $user : null; |
507 | 507 | return new ClientService( |
@@ -509,27 +509,27 @@ discard block |
||
509 | 509 | new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger()) |
510 | 510 | ); |
511 | 511 | }); |
512 | - $this->registerService('EventLogger', function (Server $c) { |
|
512 | + $this->registerService('EventLogger', function(Server $c) { |
|
513 | 513 | if ($c->getSystemConfig()->getValue('debug', false)) { |
514 | 514 | return new EventLogger(); |
515 | 515 | } else { |
516 | 516 | return new NullEventLogger(); |
517 | 517 | } |
518 | 518 | }); |
519 | - $this->registerService('QueryLogger', function (Server $c) { |
|
519 | + $this->registerService('QueryLogger', function(Server $c) { |
|
520 | 520 | if ($c->getSystemConfig()->getValue('debug', false)) { |
521 | 521 | return new QueryLogger(); |
522 | 522 | } else { |
523 | 523 | return new NullQueryLogger(); |
524 | 524 | } |
525 | 525 | }); |
526 | - $this->registerService('TempManager', function (Server $c) { |
|
526 | + $this->registerService('TempManager', function(Server $c) { |
|
527 | 527 | return new TempManager( |
528 | 528 | $c->getLogger(), |
529 | 529 | $c->getConfig() |
530 | 530 | ); |
531 | 531 | }); |
532 | - $this->registerService('AppManager', function (Server $c) { |
|
532 | + $this->registerService('AppManager', function(Server $c) { |
|
533 | 533 | return new \OC\App\AppManager( |
534 | 534 | $c->getUserSession(), |
535 | 535 | $c->getAppConfig(), |
@@ -538,13 +538,13 @@ discard block |
||
538 | 538 | $c->getEventDispatcher() |
539 | 539 | ); |
540 | 540 | }); |
541 | - $this->registerService('DateTimeZone', function (Server $c) { |
|
541 | + $this->registerService('DateTimeZone', function(Server $c) { |
|
542 | 542 | return new DateTimeZone( |
543 | 543 | $c->getConfig(), |
544 | 544 | $c->getSession() |
545 | 545 | ); |
546 | 546 | }); |
547 | - $this->registerService('DateTimeFormatter', function (Server $c) { |
|
547 | + $this->registerService('DateTimeFormatter', function(Server $c) { |
|
548 | 548 | $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
549 | 549 | |
550 | 550 | return new DateTimeFormatter( |
@@ -552,16 +552,16 @@ discard block |
||
552 | 552 | $c->getL10N('lib', $language) |
553 | 553 | ); |
554 | 554 | }); |
555 | - $this->registerService('UserMountCache', function (Server $c) { |
|
555 | + $this->registerService('UserMountCache', function(Server $c) { |
|
556 | 556 | $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
557 | 557 | $listener = new UserMountCacheListener($mountCache); |
558 | 558 | $listener->listen($c->getUserManager()); |
559 | 559 | return $mountCache; |
560 | 560 | }); |
561 | - $this->registerService('MountConfigManager', function (Server $c) { |
|
561 | + $this->registerService('MountConfigManager', function(Server $c) { |
|
562 | 562 | $loader = \OC\Files\Filesystem::getLoader(); |
563 | 563 | $mountCache = $c->query('UserMountCache'); |
564 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
564 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
565 | 565 | |
566 | 566 | // builtin providers |
567 | 567 | |
@@ -572,14 +572,14 @@ discard block |
||
572 | 572 | |
573 | 573 | return $manager; |
574 | 574 | }); |
575 | - $this->registerService('IniWrapper', function ($c) { |
|
575 | + $this->registerService('IniWrapper', function($c) { |
|
576 | 576 | return new IniGetWrapper(); |
577 | 577 | }); |
578 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
578 | + $this->registerService('AsyncCommandBus', function(Server $c) { |
|
579 | 579 | $jobList = $c->getJobList(); |
580 | 580 | return new AsyncBus($jobList); |
581 | 581 | }); |
582 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
582 | + $this->registerService('TrustedDomainHelper', function($c) { |
|
583 | 583 | return new TrustedDomainHelper($this->getConfig()); |
584 | 584 | }); |
585 | 585 | $this->registerService('Throttler', function(Server $c) { |
@@ -590,10 +590,10 @@ discard block |
||
590 | 590 | $c->getConfig() |
591 | 591 | ); |
592 | 592 | }); |
593 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
593 | + $this->registerService('IntegrityCodeChecker', function(Server $c) { |
|
594 | 594 | // IConfig and IAppManager requires a working database. This code |
595 | 595 | // might however be called when ownCloud is not yet setup. |
596 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
596 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
597 | 597 | $config = $c->getConfig(); |
598 | 598 | $appManager = $c->getAppManager(); |
599 | 599 | } else { |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | $c->getTempManager() |
612 | 612 | ); |
613 | 613 | }); |
614 | - $this->registerService('Request', function ($c) { |
|
614 | + $this->registerService('Request', function($c) { |
|
615 | 615 | if (isset($this['urlParams'])) { |
616 | 616 | $urlParams = $this['urlParams']; |
617 | 617 | } else { |
@@ -645,7 +645,7 @@ discard block |
||
645 | 645 | $stream |
646 | 646 | ); |
647 | 647 | }); |
648 | - $this->registerService('Mailer', function (Server $c) { |
|
648 | + $this->registerService('Mailer', function(Server $c) { |
|
649 | 649 | return new Mailer( |
650 | 650 | $c->getConfig(), |
651 | 651 | $c->getLogger(), |
@@ -655,14 +655,14 @@ discard block |
||
655 | 655 | $this->registerService('LDAPProvider', function(Server $c) { |
656 | 656 | $config = $c->getConfig(); |
657 | 657 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
658 | - if(is_null($factoryClass)) { |
|
658 | + if (is_null($factoryClass)) { |
|
659 | 659 | throw new \Exception('ldapProviderFactory not set'); |
660 | 660 | } |
661 | 661 | /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
662 | 662 | $factory = new $factoryClass($this); |
663 | 663 | return $factory->getLDAPProvider(); |
664 | 664 | }); |
665 | - $this->registerService('LockingProvider', function (Server $c) { |
|
665 | + $this->registerService('LockingProvider', function(Server $c) { |
|
666 | 666 | $ini = $c->getIniWrapper(); |
667 | 667 | $config = $c->getConfig(); |
668 | 668 | $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
@@ -677,29 +677,29 @@ discard block |
||
677 | 677 | } |
678 | 678 | return new NoopLockingProvider(); |
679 | 679 | }); |
680 | - $this->registerService('MountManager', function () { |
|
680 | + $this->registerService('MountManager', function() { |
|
681 | 681 | return new \OC\Files\Mount\Manager(); |
682 | 682 | }); |
683 | - $this->registerService('MimeTypeDetector', function (Server $c) { |
|
683 | + $this->registerService('MimeTypeDetector', function(Server $c) { |
|
684 | 684 | return new \OC\Files\Type\Detection( |
685 | 685 | $c->getURLGenerator(), |
686 | 686 | \OC::$configDir, |
687 | - \OC::$SERVERROOT . '/resources/config/' |
|
687 | + \OC::$SERVERROOT.'/resources/config/' |
|
688 | 688 | ); |
689 | 689 | }); |
690 | - $this->registerService('MimeTypeLoader', function (Server $c) { |
|
690 | + $this->registerService('MimeTypeLoader', function(Server $c) { |
|
691 | 691 | return new \OC\Files\Type\Loader( |
692 | 692 | $c->getDatabaseConnection() |
693 | 693 | ); |
694 | 694 | }); |
695 | - $this->registerService('NotificationManager', function (Server $c) { |
|
695 | + $this->registerService('NotificationManager', function(Server $c) { |
|
696 | 696 | return new Manager( |
697 | 697 | $c->query(IValidator::class) |
698 | 698 | ); |
699 | 699 | }); |
700 | - $this->registerService('CapabilitiesManager', function (Server $c) { |
|
700 | + $this->registerService('CapabilitiesManager', function(Server $c) { |
|
701 | 701 | $manager = new \OC\CapabilitiesManager($c->getLogger()); |
702 | - $manager->registerCapability(function () use ($c) { |
|
702 | + $manager->registerCapability(function() use ($c) { |
|
703 | 703 | return new \OC\OCS\CoreCapabilities($c->getConfig()); |
704 | 704 | }); |
705 | 705 | return $manager; |
@@ -737,10 +737,10 @@ discard block |
||
737 | 737 | } |
738 | 738 | return new \OC_Defaults(); |
739 | 739 | }); |
740 | - $this->registerService('EventDispatcher', function () { |
|
740 | + $this->registerService('EventDispatcher', function() { |
|
741 | 741 | return new EventDispatcher(); |
742 | 742 | }); |
743 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
743 | + $this->registerService('CryptoWrapper', function(Server $c) { |
|
744 | 744 | // FIXME: Instantiiated here due to cyclic dependency |
745 | 745 | $request = new Request( |
746 | 746 | [ |
@@ -765,7 +765,7 @@ discard block |
||
765 | 765 | $request |
766 | 766 | ); |
767 | 767 | }); |
768 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
768 | + $this->registerService('CsrfTokenManager', function(Server $c) { |
|
769 | 769 | $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
770 | 770 | |
771 | 771 | return new CsrfTokenManager( |
@@ -773,10 +773,10 @@ discard block |
||
773 | 773 | $c->query(SessionStorage::class) |
774 | 774 | ); |
775 | 775 | }); |
776 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
776 | + $this->registerService(SessionStorage::class, function(Server $c) { |
|
777 | 777 | return new SessionStorage($c->getSession()); |
778 | 778 | }); |
779 | - $this->registerService('ContentSecurityPolicyManager', function (Server $c) { |
|
779 | + $this->registerService('ContentSecurityPolicyManager', function(Server $c) { |
|
780 | 780 | return new ContentSecurityPolicyManager(); |
781 | 781 | }); |
782 | 782 | $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
@@ -821,23 +821,23 @@ discard block |
||
821 | 821 | ); |
822 | 822 | return $manager; |
823 | 823 | }); |
824 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
824 | + $this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) { |
|
825 | 825 | return new \OC\Files\AppData\Factory( |
826 | 826 | $c->getRootFolder(), |
827 | 827 | $c->getSystemConfig() |
828 | 828 | ); |
829 | 829 | }); |
830 | 830 | |
831 | - $this->registerService('LockdownManager', function (Server $c) { |
|
831 | + $this->registerService('LockdownManager', function(Server $c) { |
|
832 | 832 | return new LockdownManager(); |
833 | 833 | }); |
834 | 834 | |
835 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
835 | + $this->registerService(ICloudIdManager::class, function(Server $c) { |
|
836 | 836 | return new CloudIdManager(); |
837 | 837 | }); |
838 | 838 | |
839 | 839 | /* To trick DI since we don't extend the DIContainer here */ |
840 | - $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
840 | + $this->registerService(CleanPreviewsBackgroundJob::class, function(Server $c) { |
|
841 | 841 | return new CleanPreviewsBackgroundJob( |
842 | 842 | $c->getRootFolder(), |
843 | 843 | $c->getLogger(), |
@@ -989,7 +989,7 @@ discard block |
||
989 | 989 | * @deprecated since 9.2.0 use IAppData |
990 | 990 | */ |
991 | 991 | public function getAppFolder() { |
992 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
992 | + $dir = '/'.\OC_App::getCurrentApp(); |
|
993 | 993 | $root = $this->getRootFolder(); |
994 | 994 | if (!$root->nodeExists($dir)) { |
995 | 995 | $folder = $root->newFolder($dir); |
@@ -32,17 +32,17 @@ |
||
32 | 32 | */ |
33 | 33 | interface IDiscoveryService { |
34 | 34 | |
35 | - /** |
|
36 | - * Discover OCS end-points |
|
37 | - * |
|
38 | - * If no valid discovery data is found the defaults are returned |
|
39 | - * |
|
40 | - * @since 12.0.0 |
|
41 | - * |
|
42 | - * @param string $remote |
|
43 | - * @param string $service the service you want to discover |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - public function discover($remote, $service); |
|
35 | + /** |
|
36 | + * Discover OCS end-points |
|
37 | + * |
|
38 | + * If no valid discovery data is found the defaults are returned |
|
39 | + * |
|
40 | + * @since 12.0.0 |
|
41 | + * |
|
42 | + * @param string $remote |
|
43 | + * @param string $service the service you want to discover |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + public function discover($remote, $service); |
|
47 | 47 | |
48 | 48 | } |
@@ -29,64 +29,64 @@ |
||
29 | 29 | |
30 | 30 | class SyncFederationAddressBooks { |
31 | 31 | |
32 | - /** @var DbHandler */ |
|
33 | - protected $dbHandler; |
|
32 | + /** @var DbHandler */ |
|
33 | + protected $dbHandler; |
|
34 | 34 | |
35 | - /** @var SyncService */ |
|
36 | - private $syncService; |
|
35 | + /** @var SyncService */ |
|
36 | + private $syncService; |
|
37 | 37 | |
38 | - /** @var DiscoveryService */ |
|
39 | - private $ocsDiscoveryService; |
|
38 | + /** @var DiscoveryService */ |
|
39 | + private $ocsDiscoveryService; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param DbHandler $dbHandler |
|
43 | - * @param SyncService $syncService |
|
44 | - * @param DiscoveryService $ocsDiscoveryService |
|
45 | - */ |
|
46 | - public function __construct(DbHandler $dbHandler, |
|
47 | - SyncService $syncService, |
|
48 | - DiscoveryService $ocsDiscoveryService |
|
49 | - ) { |
|
50 | - $this->syncService = $syncService; |
|
51 | - $this->dbHandler = $dbHandler; |
|
52 | - $this->ocsDiscoveryService = $ocsDiscoveryService; |
|
53 | - } |
|
41 | + /** |
|
42 | + * @param DbHandler $dbHandler |
|
43 | + * @param SyncService $syncService |
|
44 | + * @param DiscoveryService $ocsDiscoveryService |
|
45 | + */ |
|
46 | + public function __construct(DbHandler $dbHandler, |
|
47 | + SyncService $syncService, |
|
48 | + DiscoveryService $ocsDiscoveryService |
|
49 | + ) { |
|
50 | + $this->syncService = $syncService; |
|
51 | + $this->dbHandler = $dbHandler; |
|
52 | + $this->ocsDiscoveryService = $ocsDiscoveryService; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @param \Closure $callback |
|
57 | - */ |
|
58 | - public function syncThemAll(\Closure $callback) { |
|
55 | + /** |
|
56 | + * @param \Closure $callback |
|
57 | + */ |
|
58 | + public function syncThemAll(\Closure $callback) { |
|
59 | 59 | |
60 | - $trustedServers = $this->dbHandler->getAllServer(); |
|
61 | - foreach ($trustedServers as $trustedServer) { |
|
62 | - $url = $trustedServer['url']; |
|
63 | - $callback($url, null); |
|
64 | - $sharedSecret = $trustedServer['shared_secret']; |
|
65 | - $syncToken = $trustedServer['sync_token']; |
|
60 | + $trustedServers = $this->dbHandler->getAllServer(); |
|
61 | + foreach ($trustedServers as $trustedServer) { |
|
62 | + $url = $trustedServer['url']; |
|
63 | + $callback($url, null); |
|
64 | + $sharedSecret = $trustedServer['shared_secret']; |
|
65 | + $syncToken = $trustedServer['sync_token']; |
|
66 | 66 | |
67 | - $endPoints = $this->ocsDiscoveryService->discover($url, 'FEDERATED_SHARING'); |
|
68 | - $cardDavUser = isset($endPoints['carddav-user']) ? $endPoints['carddav-user'] : 'system'; |
|
69 | - $addressBookUrl = isset($endPoints['system-address-book']) ? trim($endPoints['system-address-book'], '/') : 'remote.php/dav/addressbooks/system/system/system'; |
|
67 | + $endPoints = $this->ocsDiscoveryService->discover($url, 'FEDERATED_SHARING'); |
|
68 | + $cardDavUser = isset($endPoints['carddav-user']) ? $endPoints['carddav-user'] : 'system'; |
|
69 | + $addressBookUrl = isset($endPoints['system-address-book']) ? trim($endPoints['system-address-book'], '/') : 'remote.php/dav/addressbooks/system/system/system'; |
|
70 | 70 | |
71 | - if (is_null($sharedSecret)) { |
|
72 | - continue; |
|
73 | - } |
|
74 | - $targetBookId = $trustedServer['url_hash']; |
|
75 | - $targetPrincipal = "principals/system/system"; |
|
76 | - $targetBookProperties = [ |
|
77 | - '{DAV:}displayname' => $url |
|
78 | - ]; |
|
79 | - try { |
|
80 | - $newToken = $this->syncService->syncRemoteAddressBook($url, $cardDavUser, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties); |
|
81 | - if ($newToken !== $syncToken) { |
|
82 | - $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $newToken); |
|
83 | - } |
|
84 | - } catch (\Exception $ex) { |
|
85 | - if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { |
|
86 | - $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_ACCESS_REVOKED); |
|
87 | - } |
|
88 | - $callback($url, $ex); |
|
89 | - } |
|
90 | - } |
|
91 | - } |
|
71 | + if (is_null($sharedSecret)) { |
|
72 | + continue; |
|
73 | + } |
|
74 | + $targetBookId = $trustedServer['url_hash']; |
|
75 | + $targetPrincipal = "principals/system/system"; |
|
76 | + $targetBookProperties = [ |
|
77 | + '{DAV:}displayname' => $url |
|
78 | + ]; |
|
79 | + try { |
|
80 | + $newToken = $this->syncService->syncRemoteAddressBook($url, $cardDavUser, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties); |
|
81 | + if ($newToken !== $syncToken) { |
|
82 | + $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $newToken); |
|
83 | + } |
|
84 | + } catch (\Exception $ex) { |
|
85 | + if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { |
|
86 | + $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_ACCESS_REVOKED); |
|
87 | + } |
|
88 | + $callback($url, $ex); |
|
89 | + } |
|
90 | + } |
|
91 | + } |
|
92 | 92 | } |
@@ -42,101 +42,101 @@ |
||
42 | 42 | |
43 | 43 | class Application extends \OCP\AppFramework\App { |
44 | 44 | |
45 | - /** |
|
46 | - * @param array $urlParams |
|
47 | - */ |
|
48 | - public function __construct($urlParams = array()) { |
|
49 | - parent::__construct('federation', $urlParams); |
|
50 | - $this->registerService(); |
|
51 | - $this->registerMiddleware(); |
|
52 | - } |
|
53 | - |
|
54 | - private function registerService() { |
|
55 | - $container = $this->getContainer(); |
|
56 | - |
|
57 | - $container->registerService('addServerMiddleware', function(IAppContainer $c) { |
|
58 | - return new AddServerMiddleware( |
|
59 | - $c->getAppName(), |
|
60 | - \OC::$server->getL10N($c->getAppName()), |
|
61 | - \OC::$server->getLogger() |
|
62 | - ); |
|
63 | - }); |
|
64 | - |
|
65 | - $container->registerService('DbHandler', function(IAppContainer $c) { |
|
66 | - return new DbHandler( |
|
67 | - \OC::$server->getDatabaseConnection(), |
|
68 | - \OC::$server->getL10N($c->getAppName()) |
|
69 | - ); |
|
70 | - }); |
|
71 | - |
|
72 | - $container->registerService('TrustedServers', function(IAppContainer $c) { |
|
73 | - $server = $c->getServer(); |
|
74 | - return new TrustedServers( |
|
75 | - $c->query('DbHandler'), |
|
76 | - $server->getHTTPClientService(), |
|
77 | - $server->getLogger(), |
|
78 | - $server->getJobList(), |
|
79 | - $server->getSecureRandom(), |
|
80 | - $server->getConfig(), |
|
81 | - $server->getEventDispatcher() |
|
82 | - ); |
|
83 | - }); |
|
84 | - |
|
85 | - $container->registerService('SettingsController', function (IAppContainer $c) { |
|
86 | - $server = $c->getServer(); |
|
87 | - return new SettingsController( |
|
88 | - $c->getAppName(), |
|
89 | - $server->getRequest(), |
|
90 | - $server->getL10N($c->getAppName()), |
|
91 | - $c->query('TrustedServers') |
|
92 | - ); |
|
93 | - }); |
|
94 | - |
|
95 | - } |
|
96 | - |
|
97 | - private function registerMiddleware() { |
|
98 | - $container = $this->getContainer(); |
|
99 | - $container->registerMiddleware('addServerMiddleware'); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * listen to federated_share_added hooks to auto-add new servers to the |
|
104 | - * list of trusted servers. |
|
105 | - */ |
|
106 | - public function registerHooks() { |
|
107 | - |
|
108 | - $container = $this->getContainer(); |
|
109 | - $hooksManager = new Hooks($container->query('TrustedServers')); |
|
110 | - |
|
111 | - Util::connectHook( |
|
112 | - 'OCP\Share', |
|
113 | - 'federated_share_added', |
|
114 | - $hooksManager, |
|
115 | - 'addServerHook' |
|
116 | - ); |
|
117 | - |
|
118 | - $dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
|
119 | - $dispatcher->addListener('OCA\DAV\Connector\Sabre::authInit', function($event) use($container) { |
|
120 | - if ($event instanceof SabrePluginEvent) { |
|
121 | - $authPlugin = $event->getServer()->getPlugin('auth'); |
|
122 | - if ($authPlugin instanceof Plugin) { |
|
123 | - $h = new DbHandler($container->getServer()->getDatabaseConnection(), |
|
124 | - $container->getServer()->getL10N('federation') |
|
125 | - ); |
|
126 | - $authPlugin->addBackend(new FedAuth($h)); |
|
127 | - } |
|
128 | - } |
|
129 | - }); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * @return SyncFederationAddressBooks |
|
134 | - */ |
|
135 | - public function getSyncService() { |
|
136 | - $syncService = \OC::$server->query('CardDAVSyncService'); |
|
137 | - $dbHandler = $this->getContainer()->query('DbHandler'); |
|
138 | - $discoveryService = \OC::$server->getOCSDiscoveryService(); |
|
139 | - return new SyncFederationAddressBooks($dbHandler, $syncService, $discoveryService); |
|
140 | - } |
|
45 | + /** |
|
46 | + * @param array $urlParams |
|
47 | + */ |
|
48 | + public function __construct($urlParams = array()) { |
|
49 | + parent::__construct('federation', $urlParams); |
|
50 | + $this->registerService(); |
|
51 | + $this->registerMiddleware(); |
|
52 | + } |
|
53 | + |
|
54 | + private function registerService() { |
|
55 | + $container = $this->getContainer(); |
|
56 | + |
|
57 | + $container->registerService('addServerMiddleware', function(IAppContainer $c) { |
|
58 | + return new AddServerMiddleware( |
|
59 | + $c->getAppName(), |
|
60 | + \OC::$server->getL10N($c->getAppName()), |
|
61 | + \OC::$server->getLogger() |
|
62 | + ); |
|
63 | + }); |
|
64 | + |
|
65 | + $container->registerService('DbHandler', function(IAppContainer $c) { |
|
66 | + return new DbHandler( |
|
67 | + \OC::$server->getDatabaseConnection(), |
|
68 | + \OC::$server->getL10N($c->getAppName()) |
|
69 | + ); |
|
70 | + }); |
|
71 | + |
|
72 | + $container->registerService('TrustedServers', function(IAppContainer $c) { |
|
73 | + $server = $c->getServer(); |
|
74 | + return new TrustedServers( |
|
75 | + $c->query('DbHandler'), |
|
76 | + $server->getHTTPClientService(), |
|
77 | + $server->getLogger(), |
|
78 | + $server->getJobList(), |
|
79 | + $server->getSecureRandom(), |
|
80 | + $server->getConfig(), |
|
81 | + $server->getEventDispatcher() |
|
82 | + ); |
|
83 | + }); |
|
84 | + |
|
85 | + $container->registerService('SettingsController', function (IAppContainer $c) { |
|
86 | + $server = $c->getServer(); |
|
87 | + return new SettingsController( |
|
88 | + $c->getAppName(), |
|
89 | + $server->getRequest(), |
|
90 | + $server->getL10N($c->getAppName()), |
|
91 | + $c->query('TrustedServers') |
|
92 | + ); |
|
93 | + }); |
|
94 | + |
|
95 | + } |
|
96 | + |
|
97 | + private function registerMiddleware() { |
|
98 | + $container = $this->getContainer(); |
|
99 | + $container->registerMiddleware('addServerMiddleware'); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * listen to federated_share_added hooks to auto-add new servers to the |
|
104 | + * list of trusted servers. |
|
105 | + */ |
|
106 | + public function registerHooks() { |
|
107 | + |
|
108 | + $container = $this->getContainer(); |
|
109 | + $hooksManager = new Hooks($container->query('TrustedServers')); |
|
110 | + |
|
111 | + Util::connectHook( |
|
112 | + 'OCP\Share', |
|
113 | + 'federated_share_added', |
|
114 | + $hooksManager, |
|
115 | + 'addServerHook' |
|
116 | + ); |
|
117 | + |
|
118 | + $dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
|
119 | + $dispatcher->addListener('OCA\DAV\Connector\Sabre::authInit', function($event) use($container) { |
|
120 | + if ($event instanceof SabrePluginEvent) { |
|
121 | + $authPlugin = $event->getServer()->getPlugin('auth'); |
|
122 | + if ($authPlugin instanceof Plugin) { |
|
123 | + $h = new DbHandler($container->getServer()->getDatabaseConnection(), |
|
124 | + $container->getServer()->getL10N('federation') |
|
125 | + ); |
|
126 | + $authPlugin->addBackend(new FedAuth($h)); |
|
127 | + } |
|
128 | + } |
|
129 | + }); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * @return SyncFederationAddressBooks |
|
134 | + */ |
|
135 | + public function getSyncService() { |
|
136 | + $syncService = \OC::$server->query('CardDAVSyncService'); |
|
137 | + $dbHandler = $this->getContainer()->query('DbHandler'); |
|
138 | + $discoveryService = \OC::$server->getOCSDiscoveryService(); |
|
139 | + return new SyncFederationAddressBooks($dbHandler, $syncService, $discoveryService); |
|
140 | + } |
|
141 | 141 | |
142 | 142 | } |
@@ -29,7 +29,6 @@ |
||
29 | 29 | use OC\HintException; |
30 | 30 | use OC\Share\Helper; |
31 | 31 | use OCA\FederatedFileSharing\AddressHandler; |
32 | -use OCA\FederatedFileSharing\DiscoveryManager; |
|
33 | 32 | use OCA\FederatedFileSharing\FederatedShareProvider; |
34 | 33 | use OCA\Files_Sharing\External\Manager; |
35 | 34 | use OCP\AppFramework\Controller; |
@@ -54,283 +54,283 @@ |
||
54 | 54 | */ |
55 | 55 | class MountPublicLinkController extends Controller { |
56 | 56 | |
57 | - /** @var FederatedShareProvider */ |
|
58 | - private $federatedShareProvider; |
|
59 | - |
|
60 | - /** @var AddressHandler */ |
|
61 | - private $addressHandler; |
|
62 | - |
|
63 | - /** @var IManager */ |
|
64 | - private $shareManager; |
|
65 | - |
|
66 | - /** @var ISession */ |
|
67 | - private $session; |
|
68 | - |
|
69 | - /** @var IL10N */ |
|
70 | - private $l; |
|
71 | - |
|
72 | - /** @var IUserSession */ |
|
73 | - private $userSession; |
|
74 | - |
|
75 | - /** @var IClientService */ |
|
76 | - private $clientService; |
|
77 | - |
|
78 | - /** @var ICloudIdManager */ |
|
79 | - private $cloudIdManager; |
|
80 | - |
|
81 | - /** |
|
82 | - * MountPublicLinkController constructor. |
|
83 | - * |
|
84 | - * @param string $appName |
|
85 | - * @param IRequest $request |
|
86 | - * @param FederatedShareProvider $federatedShareProvider |
|
87 | - * @param IManager $shareManager |
|
88 | - * @param AddressHandler $addressHandler |
|
89 | - * @param ISession $session |
|
90 | - * @param IL10N $l |
|
91 | - * @param IUserSession $userSession |
|
92 | - * @param IClientService $clientService |
|
93 | - * @param ICloudIdManager $cloudIdManager |
|
94 | - */ |
|
95 | - public function __construct($appName, |
|
96 | - IRequest $request, |
|
97 | - FederatedShareProvider $federatedShareProvider, |
|
98 | - IManager $shareManager, |
|
99 | - AddressHandler $addressHandler, |
|
100 | - ISession $session, |
|
101 | - IL10N $l, |
|
102 | - IUserSession $userSession, |
|
103 | - IClientService $clientService, |
|
104 | - ICloudIdManager $cloudIdManager |
|
105 | - ) { |
|
106 | - parent::__construct($appName, $request); |
|
107 | - |
|
108 | - $this->federatedShareProvider = $federatedShareProvider; |
|
109 | - $this->shareManager = $shareManager; |
|
110 | - $this->addressHandler = $addressHandler; |
|
111 | - $this->session = $session; |
|
112 | - $this->l = $l; |
|
113 | - $this->userSession = $userSession; |
|
114 | - $this->clientService = $clientService; |
|
115 | - $this->cloudIdManager = $cloudIdManager; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * send federated share to a user of a public link |
|
120 | - * |
|
121 | - * @NoCSRFRequired |
|
122 | - * @PublicPage |
|
123 | - * @BruteForceProtection publicLink2FederatedShare |
|
124 | - * |
|
125 | - * @param string $shareWith |
|
126 | - * @param string $token |
|
127 | - * @param string $password |
|
128 | - * @return JSONResponse |
|
129 | - */ |
|
130 | - public function createFederatedShare($shareWith, $token, $password = '') { |
|
131 | - |
|
132 | - if (!$this->federatedShareProvider->isOutgoingServer2serverShareEnabled()) { |
|
133 | - return new JSONResponse( |
|
134 | - ['message' => 'This server doesn\'t support outgoing federated shares'], |
|
135 | - Http::STATUS_BAD_REQUEST |
|
136 | - ); |
|
137 | - } |
|
138 | - |
|
139 | - try { |
|
140 | - list(, $server) = $this->addressHandler->splitUserRemote($shareWith); |
|
141 | - $share = $this->shareManager->getShareByToken($token); |
|
142 | - } catch (HintException $e) { |
|
143 | - return new JSONResponse(['message' => $e->getHint()], Http::STATUS_BAD_REQUEST); |
|
144 | - } |
|
145 | - |
|
146 | - // make sure that user is authenticated in case of a password protected link |
|
147 | - $storedPassword = $share->getPassword(); |
|
148 | - $authenticated = $this->session->get('public_link_authenticated') === $share->getId() || |
|
149 | - $this->shareManager->checkPassword($share, $password); |
|
150 | - if (!empty($storedPassword) && !$authenticated ) { |
|
151 | - return new JSONResponse( |
|
152 | - ['message' => 'No permission to access the share'], |
|
153 | - Http::STATUS_BAD_REQUEST |
|
154 | - ); |
|
155 | - } |
|
156 | - |
|
157 | - $share->setSharedWith($shareWith); |
|
158 | - |
|
159 | - try { |
|
160 | - $this->federatedShareProvider->create($share); |
|
161 | - } catch (\Exception $e) { |
|
162 | - return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST); |
|
163 | - } |
|
164 | - |
|
165 | - return new JSONResponse(['remoteUrl' => $server]); |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * ask other server to get a federated share |
|
170 | - * |
|
171 | - * @NoAdminRequired |
|
172 | - * |
|
173 | - * @param string $token |
|
174 | - * @param string $remote |
|
175 | - * @param string $password |
|
176 | - * @param string $owner (only for legacy reasons, can be removed with legacyMountPublicLink()) |
|
177 | - * @param string $ownerDisplayName (only for legacy reasons, can be removed with legacyMountPublicLink()) |
|
178 | - * @param string $name (only for legacy reasons, can be removed with legacyMountPublicLink()) |
|
179 | - * @return JSONResponse |
|
180 | - */ |
|
181 | - public function askForFederatedShare($token, $remote, $password = '', $owner = '', $ownerDisplayName = '', $name = '') { |
|
182 | - // check if server admin allows to mount public links from other servers |
|
183 | - if ($this->federatedShareProvider->isIncomingServer2serverShareEnabled() === false) { |
|
184 | - return new JSONResponse(['message' => $this->l->t('Server to server sharing is not enabled on this server')], Http::STATUS_BAD_REQUEST); |
|
185 | - } |
|
186 | - |
|
187 | - $cloudId = $this->cloudIdManager->getCloudId($this->userSession->getUser()->getUID(), $this->addressHandler->generateRemoteURL()); |
|
188 | - |
|
189 | - $httpClient = $this->clientService->newClient(); |
|
190 | - |
|
191 | - try { |
|
192 | - $response = $httpClient->post($remote . '/index.php/apps/federatedfilesharing/createFederatedShare', |
|
193 | - [ |
|
194 | - 'body' => |
|
195 | - [ |
|
196 | - 'token' => $token, |
|
197 | - 'shareWith' => rtrim($cloudId->getId(), '/'), |
|
198 | - 'password' => $password |
|
199 | - ], |
|
200 | - 'connect_timeout' => 10, |
|
201 | - ] |
|
202 | - ); |
|
203 | - } catch (\Exception $e) { |
|
204 | - if (empty($password)) { |
|
205 | - $message = $this->l->t("Couldn't establish a federated share."); |
|
206 | - } else { |
|
207 | - $message = $this->l->t("Couldn't establish a federated share, maybe the password was wrong."); |
|
208 | - } |
|
209 | - return new JSONResponse(['message' => $message], Http::STATUS_BAD_REQUEST); |
|
210 | - } |
|
211 | - |
|
212 | - $body = $response->getBody(); |
|
213 | - $result = json_decode($body, true); |
|
214 | - |
|
215 | - if (is_array($result) && isset($result['remoteUrl'])) { |
|
216 | - return new JSONResponse(['message' => $this->l->t('Federated Share request was successful, you will receive a invitation. Check your notifications.')]); |
|
217 | - } |
|
218 | - |
|
219 | - // if we doesn't get the expected response we assume that we try to add |
|
220 | - // a federated share from a Nextcloud <= 9 server |
|
221 | - return $this->legacyMountPublicLink($token, $remote, $password, $name, $owner, $ownerDisplayName); |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * Allow Nextcloud to mount a public link directly |
|
226 | - * |
|
227 | - * This code was copied from the apps/files_sharing/ajax/external.php with |
|
228 | - * minimal changes, just to guarantee backward compatibility |
|
229 | - * |
|
230 | - * ToDo: Remove this method once Nextcloud 9 reaches end of life |
|
231 | - * |
|
232 | - * @param string $token |
|
233 | - * @param string $remote |
|
234 | - * @param string $password |
|
235 | - * @param string $name |
|
236 | - * @param string $owner |
|
237 | - * @param string $ownerDisplayName |
|
238 | - * @return JSONResponse |
|
239 | - */ |
|
240 | - private function legacyMountPublicLink($token, $remote, $password, $name, $owner, $ownerDisplayName) { |
|
241 | - |
|
242 | - // Check for invalid name |
|
243 | - if (!Util::isValidFileName($name)) { |
|
244 | - return new JSONResponse(['message' => $this->l->t('The mountpoint name contains invalid characters.')], Http::STATUS_BAD_REQUEST); |
|
245 | - } |
|
246 | - $currentUser = $this->userSession->getUser()->getUID(); |
|
247 | - $currentServer = $this->addressHandler->generateRemoteURL(); |
|
248 | - if (Helper::isSameUserOnSameServer($owner, $remote, $currentUser, $currentServer)) { |
|
249 | - return new JSONResponse(['message' => $this->l->t('Not allowed to create a federated share with the owner.')], Http::STATUS_BAD_REQUEST); |
|
250 | - } |
|
251 | - $externalManager = new Manager( |
|
252 | - \OC::$server->getDatabaseConnection(), |
|
253 | - Filesystem::getMountManager(), |
|
254 | - Filesystem::getLoader(), |
|
255 | - \OC::$server->getHTTPClientService(), |
|
256 | - \OC::$server->getNotificationManager(), |
|
257 | - \OC::$server->getOCSDiscoveryService(), |
|
258 | - \OC::$server->getUserSession()->getUser()->getUID() |
|
259 | - ); |
|
260 | - |
|
261 | - // check for ssl cert |
|
262 | - |
|
263 | - if (strpos($remote, 'https') === 0) { |
|
264 | - try { |
|
265 | - $client = $this->clientService->newClient(); |
|
266 | - $client->get($remote, [ |
|
267 | - 'timeout' => 10, |
|
268 | - 'connect_timeout' => 10, |
|
269 | - ])->getBody(); |
|
270 | - } catch (\Exception $e) { |
|
271 | - return new JSONResponse(['message' => $this->l->t('Invalid or untrusted SSL certificate')], Http::STATUS_BAD_REQUEST); |
|
272 | - } |
|
273 | - } |
|
274 | - $mount = $externalManager->addShare($remote, $token, $password, $name, $ownerDisplayName, true); |
|
275 | - /** |
|
276 | - * @var \OCA\Files_Sharing\External\Storage $storage |
|
277 | - */ |
|
278 | - $storage = $mount->getStorage(); |
|
279 | - try { |
|
280 | - // check if storage exists |
|
281 | - $storage->checkStorageAvailability(); |
|
282 | - } catch (StorageInvalidException $e) { |
|
283 | - // note: checkStorageAvailability will already remove the invalid share |
|
284 | - Util::writeLog( |
|
285 | - 'federatedfilesharing', |
|
286 | - 'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), |
|
287 | - Util::DEBUG |
|
288 | - ); |
|
289 | - return new JSONResponse(['message' => $this->l->t('Could not authenticate to remote share, password might be wrong')], Http::STATUS_BAD_REQUEST); |
|
290 | - } catch (\Exception $e) { |
|
291 | - Util::writeLog( |
|
292 | - 'federatedfilesharing', |
|
293 | - 'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), |
|
294 | - Util::DEBUG |
|
295 | - ); |
|
296 | - $externalManager->removeShare($mount->getMountPoint()); |
|
297 | - return new JSONResponse(['message' => $this->l->t('Storage not valid')], Http::STATUS_BAD_REQUEST); |
|
298 | - } |
|
299 | - $result = $storage->file_exists(''); |
|
300 | - if ($result) { |
|
301 | - try { |
|
302 | - $storage->getScanner()->scanAll(); |
|
303 | - return new JSONResponse( |
|
304 | - [ |
|
305 | - 'message' => $this->l->t('Federated Share successfully added'), |
|
306 | - 'legacyMount' => '1' |
|
307 | - ] |
|
308 | - ); |
|
309 | - } catch (StorageInvalidException $e) { |
|
310 | - Util::writeLog( |
|
311 | - 'federatedfilesharing', |
|
312 | - 'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), |
|
313 | - Util::DEBUG |
|
314 | - ); |
|
315 | - return new JSONResponse(['message' => $this->l->t('Storage not valid')], Http::STATUS_BAD_REQUEST); |
|
316 | - } catch (\Exception $e) { |
|
317 | - Util::writeLog( |
|
318 | - 'federatedfilesharing', |
|
319 | - 'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), |
|
320 | - Util::DEBUG |
|
321 | - ); |
|
322 | - return new JSONResponse(['message' => $this->l->t('Couldn\'t add remote share')], Http::STATUS_BAD_REQUEST); |
|
323 | - } |
|
324 | - } else { |
|
325 | - $externalManager->removeShare($mount->getMountPoint()); |
|
326 | - Util::writeLog( |
|
327 | - 'federatedfilesharing', |
|
328 | - 'Couldn\'t add remote share', |
|
329 | - Util::DEBUG |
|
330 | - ); |
|
331 | - return new JSONResponse(['message' => $this->l->t('Couldn\'t add remote share')], Http::STATUS_BAD_REQUEST); |
|
332 | - } |
|
333 | - |
|
334 | - } |
|
57 | + /** @var FederatedShareProvider */ |
|
58 | + private $federatedShareProvider; |
|
59 | + |
|
60 | + /** @var AddressHandler */ |
|
61 | + private $addressHandler; |
|
62 | + |
|
63 | + /** @var IManager */ |
|
64 | + private $shareManager; |
|
65 | + |
|
66 | + /** @var ISession */ |
|
67 | + private $session; |
|
68 | + |
|
69 | + /** @var IL10N */ |
|
70 | + private $l; |
|
71 | + |
|
72 | + /** @var IUserSession */ |
|
73 | + private $userSession; |
|
74 | + |
|
75 | + /** @var IClientService */ |
|
76 | + private $clientService; |
|
77 | + |
|
78 | + /** @var ICloudIdManager */ |
|
79 | + private $cloudIdManager; |
|
80 | + |
|
81 | + /** |
|
82 | + * MountPublicLinkController constructor. |
|
83 | + * |
|
84 | + * @param string $appName |
|
85 | + * @param IRequest $request |
|
86 | + * @param FederatedShareProvider $federatedShareProvider |
|
87 | + * @param IManager $shareManager |
|
88 | + * @param AddressHandler $addressHandler |
|
89 | + * @param ISession $session |
|
90 | + * @param IL10N $l |
|
91 | + * @param IUserSession $userSession |
|
92 | + * @param IClientService $clientService |
|
93 | + * @param ICloudIdManager $cloudIdManager |
|
94 | + */ |
|
95 | + public function __construct($appName, |
|
96 | + IRequest $request, |
|
97 | + FederatedShareProvider $federatedShareProvider, |
|
98 | + IManager $shareManager, |
|
99 | + AddressHandler $addressHandler, |
|
100 | + ISession $session, |
|
101 | + IL10N $l, |
|
102 | + IUserSession $userSession, |
|
103 | + IClientService $clientService, |
|
104 | + ICloudIdManager $cloudIdManager |
|
105 | + ) { |
|
106 | + parent::__construct($appName, $request); |
|
107 | + |
|
108 | + $this->federatedShareProvider = $federatedShareProvider; |
|
109 | + $this->shareManager = $shareManager; |
|
110 | + $this->addressHandler = $addressHandler; |
|
111 | + $this->session = $session; |
|
112 | + $this->l = $l; |
|
113 | + $this->userSession = $userSession; |
|
114 | + $this->clientService = $clientService; |
|
115 | + $this->cloudIdManager = $cloudIdManager; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * send federated share to a user of a public link |
|
120 | + * |
|
121 | + * @NoCSRFRequired |
|
122 | + * @PublicPage |
|
123 | + * @BruteForceProtection publicLink2FederatedShare |
|
124 | + * |
|
125 | + * @param string $shareWith |
|
126 | + * @param string $token |
|
127 | + * @param string $password |
|
128 | + * @return JSONResponse |
|
129 | + */ |
|
130 | + public function createFederatedShare($shareWith, $token, $password = '') { |
|
131 | + |
|
132 | + if (!$this->federatedShareProvider->isOutgoingServer2serverShareEnabled()) { |
|
133 | + return new JSONResponse( |
|
134 | + ['message' => 'This server doesn\'t support outgoing federated shares'], |
|
135 | + Http::STATUS_BAD_REQUEST |
|
136 | + ); |
|
137 | + } |
|
138 | + |
|
139 | + try { |
|
140 | + list(, $server) = $this->addressHandler->splitUserRemote($shareWith); |
|
141 | + $share = $this->shareManager->getShareByToken($token); |
|
142 | + } catch (HintException $e) { |
|
143 | + return new JSONResponse(['message' => $e->getHint()], Http::STATUS_BAD_REQUEST); |
|
144 | + } |
|
145 | + |
|
146 | + // make sure that user is authenticated in case of a password protected link |
|
147 | + $storedPassword = $share->getPassword(); |
|
148 | + $authenticated = $this->session->get('public_link_authenticated') === $share->getId() || |
|
149 | + $this->shareManager->checkPassword($share, $password); |
|
150 | + if (!empty($storedPassword) && !$authenticated ) { |
|
151 | + return new JSONResponse( |
|
152 | + ['message' => 'No permission to access the share'], |
|
153 | + Http::STATUS_BAD_REQUEST |
|
154 | + ); |
|
155 | + } |
|
156 | + |
|
157 | + $share->setSharedWith($shareWith); |
|
158 | + |
|
159 | + try { |
|
160 | + $this->federatedShareProvider->create($share); |
|
161 | + } catch (\Exception $e) { |
|
162 | + return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST); |
|
163 | + } |
|
164 | + |
|
165 | + return new JSONResponse(['remoteUrl' => $server]); |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * ask other server to get a federated share |
|
170 | + * |
|
171 | + * @NoAdminRequired |
|
172 | + * |
|
173 | + * @param string $token |
|
174 | + * @param string $remote |
|
175 | + * @param string $password |
|
176 | + * @param string $owner (only for legacy reasons, can be removed with legacyMountPublicLink()) |
|
177 | + * @param string $ownerDisplayName (only for legacy reasons, can be removed with legacyMountPublicLink()) |
|
178 | + * @param string $name (only for legacy reasons, can be removed with legacyMountPublicLink()) |
|
179 | + * @return JSONResponse |
|
180 | + */ |
|
181 | + public function askForFederatedShare($token, $remote, $password = '', $owner = '', $ownerDisplayName = '', $name = '') { |
|
182 | + // check if server admin allows to mount public links from other servers |
|
183 | + if ($this->federatedShareProvider->isIncomingServer2serverShareEnabled() === false) { |
|
184 | + return new JSONResponse(['message' => $this->l->t('Server to server sharing is not enabled on this server')], Http::STATUS_BAD_REQUEST); |
|
185 | + } |
|
186 | + |
|
187 | + $cloudId = $this->cloudIdManager->getCloudId($this->userSession->getUser()->getUID(), $this->addressHandler->generateRemoteURL()); |
|
188 | + |
|
189 | + $httpClient = $this->clientService->newClient(); |
|
190 | + |
|
191 | + try { |
|
192 | + $response = $httpClient->post($remote . '/index.php/apps/federatedfilesharing/createFederatedShare', |
|
193 | + [ |
|
194 | + 'body' => |
|
195 | + [ |
|
196 | + 'token' => $token, |
|
197 | + 'shareWith' => rtrim($cloudId->getId(), '/'), |
|
198 | + 'password' => $password |
|
199 | + ], |
|
200 | + 'connect_timeout' => 10, |
|
201 | + ] |
|
202 | + ); |
|
203 | + } catch (\Exception $e) { |
|
204 | + if (empty($password)) { |
|
205 | + $message = $this->l->t("Couldn't establish a federated share."); |
|
206 | + } else { |
|
207 | + $message = $this->l->t("Couldn't establish a federated share, maybe the password was wrong."); |
|
208 | + } |
|
209 | + return new JSONResponse(['message' => $message], Http::STATUS_BAD_REQUEST); |
|
210 | + } |
|
211 | + |
|
212 | + $body = $response->getBody(); |
|
213 | + $result = json_decode($body, true); |
|
214 | + |
|
215 | + if (is_array($result) && isset($result['remoteUrl'])) { |
|
216 | + return new JSONResponse(['message' => $this->l->t('Federated Share request was successful, you will receive a invitation. Check your notifications.')]); |
|
217 | + } |
|
218 | + |
|
219 | + // if we doesn't get the expected response we assume that we try to add |
|
220 | + // a federated share from a Nextcloud <= 9 server |
|
221 | + return $this->legacyMountPublicLink($token, $remote, $password, $name, $owner, $ownerDisplayName); |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * Allow Nextcloud to mount a public link directly |
|
226 | + * |
|
227 | + * This code was copied from the apps/files_sharing/ajax/external.php with |
|
228 | + * minimal changes, just to guarantee backward compatibility |
|
229 | + * |
|
230 | + * ToDo: Remove this method once Nextcloud 9 reaches end of life |
|
231 | + * |
|
232 | + * @param string $token |
|
233 | + * @param string $remote |
|
234 | + * @param string $password |
|
235 | + * @param string $name |
|
236 | + * @param string $owner |
|
237 | + * @param string $ownerDisplayName |
|
238 | + * @return JSONResponse |
|
239 | + */ |
|
240 | + private function legacyMountPublicLink($token, $remote, $password, $name, $owner, $ownerDisplayName) { |
|
241 | + |
|
242 | + // Check for invalid name |
|
243 | + if (!Util::isValidFileName($name)) { |
|
244 | + return new JSONResponse(['message' => $this->l->t('The mountpoint name contains invalid characters.')], Http::STATUS_BAD_REQUEST); |
|
245 | + } |
|
246 | + $currentUser = $this->userSession->getUser()->getUID(); |
|
247 | + $currentServer = $this->addressHandler->generateRemoteURL(); |
|
248 | + if (Helper::isSameUserOnSameServer($owner, $remote, $currentUser, $currentServer)) { |
|
249 | + return new JSONResponse(['message' => $this->l->t('Not allowed to create a federated share with the owner.')], Http::STATUS_BAD_REQUEST); |
|
250 | + } |
|
251 | + $externalManager = new Manager( |
|
252 | + \OC::$server->getDatabaseConnection(), |
|
253 | + Filesystem::getMountManager(), |
|
254 | + Filesystem::getLoader(), |
|
255 | + \OC::$server->getHTTPClientService(), |
|
256 | + \OC::$server->getNotificationManager(), |
|
257 | + \OC::$server->getOCSDiscoveryService(), |
|
258 | + \OC::$server->getUserSession()->getUser()->getUID() |
|
259 | + ); |
|
260 | + |
|
261 | + // check for ssl cert |
|
262 | + |
|
263 | + if (strpos($remote, 'https') === 0) { |
|
264 | + try { |
|
265 | + $client = $this->clientService->newClient(); |
|
266 | + $client->get($remote, [ |
|
267 | + 'timeout' => 10, |
|
268 | + 'connect_timeout' => 10, |
|
269 | + ])->getBody(); |
|
270 | + } catch (\Exception $e) { |
|
271 | + return new JSONResponse(['message' => $this->l->t('Invalid or untrusted SSL certificate')], Http::STATUS_BAD_REQUEST); |
|
272 | + } |
|
273 | + } |
|
274 | + $mount = $externalManager->addShare($remote, $token, $password, $name, $ownerDisplayName, true); |
|
275 | + /** |
|
276 | + * @var \OCA\Files_Sharing\External\Storage $storage |
|
277 | + */ |
|
278 | + $storage = $mount->getStorage(); |
|
279 | + try { |
|
280 | + // check if storage exists |
|
281 | + $storage->checkStorageAvailability(); |
|
282 | + } catch (StorageInvalidException $e) { |
|
283 | + // note: checkStorageAvailability will already remove the invalid share |
|
284 | + Util::writeLog( |
|
285 | + 'federatedfilesharing', |
|
286 | + 'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), |
|
287 | + Util::DEBUG |
|
288 | + ); |
|
289 | + return new JSONResponse(['message' => $this->l->t('Could not authenticate to remote share, password might be wrong')], Http::STATUS_BAD_REQUEST); |
|
290 | + } catch (\Exception $e) { |
|
291 | + Util::writeLog( |
|
292 | + 'federatedfilesharing', |
|
293 | + 'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), |
|
294 | + Util::DEBUG |
|
295 | + ); |
|
296 | + $externalManager->removeShare($mount->getMountPoint()); |
|
297 | + return new JSONResponse(['message' => $this->l->t('Storage not valid')], Http::STATUS_BAD_REQUEST); |
|
298 | + } |
|
299 | + $result = $storage->file_exists(''); |
|
300 | + if ($result) { |
|
301 | + try { |
|
302 | + $storage->getScanner()->scanAll(); |
|
303 | + return new JSONResponse( |
|
304 | + [ |
|
305 | + 'message' => $this->l->t('Federated Share successfully added'), |
|
306 | + 'legacyMount' => '1' |
|
307 | + ] |
|
308 | + ); |
|
309 | + } catch (StorageInvalidException $e) { |
|
310 | + Util::writeLog( |
|
311 | + 'federatedfilesharing', |
|
312 | + 'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), |
|
313 | + Util::DEBUG |
|
314 | + ); |
|
315 | + return new JSONResponse(['message' => $this->l->t('Storage not valid')], Http::STATUS_BAD_REQUEST); |
|
316 | + } catch (\Exception $e) { |
|
317 | + Util::writeLog( |
|
318 | + 'federatedfilesharing', |
|
319 | + 'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), |
|
320 | + Util::DEBUG |
|
321 | + ); |
|
322 | + return new JSONResponse(['message' => $this->l->t('Couldn\'t add remote share')], Http::STATUS_BAD_REQUEST); |
|
323 | + } |
|
324 | + } else { |
|
325 | + $externalManager->removeShare($mount->getMountPoint()); |
|
326 | + Util::writeLog( |
|
327 | + 'federatedfilesharing', |
|
328 | + 'Couldn\'t add remote share', |
|
329 | + Util::DEBUG |
|
330 | + ); |
|
331 | + return new JSONResponse(['message' => $this->l->t('Couldn\'t add remote share')], Http::STATUS_BAD_REQUEST); |
|
332 | + } |
|
333 | + |
|
334 | + } |
|
335 | 335 | |
336 | 336 | } |
@@ -26,7 +26,6 @@ |
||
26 | 26 | |
27 | 27 | namespace OCA\FederatedFileSharing\Controller; |
28 | 28 | |
29 | -use OCA\FederatedFileSharing\DiscoveryManager; |
|
30 | 29 | use OCA\Files_Sharing\Activity\Providers\RemoteShares; |
31 | 30 | use OCA\FederatedFileSharing\AddressHandler; |
32 | 31 | use OCA\FederatedFileSharing\FederatedShareProvider; |
@@ -48,572 +48,572 @@ |
||
48 | 48 | |
49 | 49 | class RequestHandlerController extends OCSController { |
50 | 50 | |
51 | - /** @var FederatedShareProvider */ |
|
52 | - private $federatedShareProvider; |
|
53 | - |
|
54 | - /** @var IDBConnection */ |
|
55 | - private $connection; |
|
56 | - |
|
57 | - /** @var Share\IManager */ |
|
58 | - private $shareManager; |
|
59 | - |
|
60 | - /** @var Notifications */ |
|
61 | - private $notifications; |
|
62 | - |
|
63 | - /** @var AddressHandler */ |
|
64 | - private $addressHandler; |
|
65 | - |
|
66 | - /** @var IUserManager */ |
|
67 | - private $userManager; |
|
68 | - |
|
69 | - /** @var string */ |
|
70 | - private $shareTable = 'share'; |
|
71 | - |
|
72 | - /** @var ICloudIdManager */ |
|
73 | - private $cloudIdManager; |
|
74 | - |
|
75 | - /** |
|
76 | - * Server2Server constructor. |
|
77 | - * |
|
78 | - * @param string $appName |
|
79 | - * @param IRequest $request |
|
80 | - * @param FederatedShareProvider $federatedShareProvider |
|
81 | - * @param IDBConnection $connection |
|
82 | - * @param Share\IManager $shareManager |
|
83 | - * @param Notifications $notifications |
|
84 | - * @param AddressHandler $addressHandler |
|
85 | - * @param IUserManager $userManager |
|
86 | - * @param ICloudIdManager $cloudIdManager |
|
87 | - */ |
|
88 | - public function __construct($appName, |
|
89 | - IRequest $request, |
|
90 | - FederatedShareProvider $federatedShareProvider, |
|
91 | - IDBConnection $connection, |
|
92 | - Share\IManager $shareManager, |
|
93 | - Notifications $notifications, |
|
94 | - AddressHandler $addressHandler, |
|
95 | - IUserManager $userManager, |
|
96 | - ICloudIdManager $cloudIdManager |
|
97 | - ) { |
|
98 | - parent::__construct($appName, $request); |
|
99 | - |
|
100 | - $this->federatedShareProvider = $federatedShareProvider; |
|
101 | - $this->connection = $connection; |
|
102 | - $this->shareManager = $shareManager; |
|
103 | - $this->notifications = $notifications; |
|
104 | - $this->addressHandler = $addressHandler; |
|
105 | - $this->userManager = $userManager; |
|
106 | - $this->cloudIdManager = $cloudIdManager; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @NoCSRFRequired |
|
111 | - * @PublicPage |
|
112 | - * |
|
113 | - * create a new share |
|
114 | - * |
|
115 | - * @return Http\DataResponse |
|
116 | - * @throws OCSException |
|
117 | - */ |
|
118 | - public function createShare() { |
|
119 | - |
|
120 | - if (!$this->isS2SEnabled(true)) { |
|
121 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
122 | - } |
|
123 | - |
|
124 | - $remote = isset($_POST['remote']) ? $_POST['remote'] : null; |
|
125 | - $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
126 | - $name = isset($_POST['name']) ? $_POST['name'] : null; |
|
127 | - $owner = isset($_POST['owner']) ? $_POST['owner'] : null; |
|
128 | - $sharedBy = isset($_POST['sharedBy']) ? $_POST['sharedBy'] : null; |
|
129 | - $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null; |
|
130 | - $remoteId = isset($_POST['remoteId']) ? (int)$_POST['remoteId'] : null; |
|
131 | - $sharedByFederatedId = isset($_POST['sharedByFederatedId']) ? $_POST['sharedByFederatedId'] : null; |
|
132 | - $ownerFederatedId = isset($_POST['ownerFederatedId']) ? $_POST['ownerFederatedId'] : null; |
|
133 | - |
|
134 | - if ($remote && $token && $name && $owner && $remoteId && $shareWith) { |
|
135 | - |
|
136 | - if(!\OCP\Util::isValidFileName($name)) { |
|
137 | - throw new OCSException('The mountpoint name contains invalid characters.', 400); |
|
138 | - } |
|
139 | - |
|
140 | - // FIXME this should be a method in the user management instead |
|
141 | - \OCP\Util::writeLog('files_sharing', 'shareWith before, ' . $shareWith, \OCP\Util::DEBUG); |
|
142 | - \OCP\Util::emitHook( |
|
143 | - '\OCA\Files_Sharing\API\Server2Server', |
|
144 | - 'preLoginNameUsedAsUserName', |
|
145 | - array('uid' => &$shareWith) |
|
146 | - ); |
|
147 | - \OCP\Util::writeLog('files_sharing', 'shareWith after, ' . $shareWith, \OCP\Util::DEBUG); |
|
148 | - |
|
149 | - if (!\OCP\User::userExists($shareWith)) { |
|
150 | - throw new OCSException('User does not exists', 400); |
|
151 | - } |
|
152 | - |
|
153 | - \OC_Util::setupFS($shareWith); |
|
154 | - |
|
155 | - $externalManager = new \OCA\Files_Sharing\External\Manager( |
|
156 | - \OC::$server->getDatabaseConnection(), |
|
157 | - \OC\Files\Filesystem::getMountManager(), |
|
158 | - \OC\Files\Filesystem::getLoader(), |
|
159 | - \OC::$server->getHTTPClientService(), |
|
160 | - \OC::$server->getNotificationManager(), |
|
161 | - \OC::$server->getOCSDiscoveryService(), |
|
162 | - $shareWith |
|
163 | - ); |
|
164 | - |
|
165 | - try { |
|
166 | - $externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId); |
|
167 | - $shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external'); |
|
168 | - |
|
169 | - if ($ownerFederatedId === null) { |
|
170 | - $ownerFederatedId = $this->cloudIdManager->getCloudId($owner, $this->cleanupRemote($remote))->getId(); |
|
171 | - } |
|
172 | - // if the owner of the share and the initiator are the same user |
|
173 | - // we also complete the federated share ID for the initiator |
|
174 | - if ($sharedByFederatedId === null && $owner === $sharedBy) { |
|
175 | - $sharedByFederatedId = $ownerFederatedId; |
|
176 | - } |
|
177 | - |
|
178 | - $event = \OC::$server->getActivityManager()->generateEvent(); |
|
179 | - $event->setApp('files_sharing') |
|
180 | - ->setType('remote_share') |
|
181 | - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')]) |
|
182 | - ->setAffectedUser($shareWith) |
|
183 | - ->setObject('remote_share', (int) $shareId, $name); |
|
184 | - \OC::$server->getActivityManager()->publish($event); |
|
185 | - |
|
186 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
187 | - |
|
188 | - $notificationManager = \OC::$server->getNotificationManager(); |
|
189 | - $notification = $notificationManager->createNotification(); |
|
190 | - $notification->setApp('files_sharing') |
|
191 | - ->setUser($shareWith) |
|
192 | - ->setDateTime(new \DateTime()) |
|
193 | - ->setObject('remote_share', $shareId) |
|
194 | - ->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/')]); |
|
195 | - |
|
196 | - $declineAction = $notification->createAction(); |
|
197 | - $declineAction->setLabel('decline') |
|
198 | - ->setLink($urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'ocs/v1.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'DELETE'); |
|
199 | - $notification->addAction($declineAction); |
|
200 | - |
|
201 | - $acceptAction = $notification->createAction(); |
|
202 | - $acceptAction->setLabel('accept') |
|
203 | - ->setLink($urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'ocs/v1.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'POST'); |
|
204 | - $notification->addAction($acceptAction); |
|
205 | - |
|
206 | - $notificationManager->notify($notification); |
|
207 | - |
|
208 | - return new Http\DataResponse(); |
|
209 | - } catch (\Exception $e) { |
|
210 | - \OCP\Util::writeLog('files_sharing', 'server can not add remote share, ' . $e->getMessage(), \OCP\Util::ERROR); |
|
211 | - throw new OCSException('internal server error, was not able to add share from ' . $remote, 500); |
|
212 | - } |
|
213 | - } |
|
214 | - |
|
215 | - throw new OCSException('server can not add remote share, missing parameter', 400); |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * @NoCSRFRequired |
|
220 | - * @PublicPage |
|
221 | - * |
|
222 | - * create re-share on behalf of another user |
|
223 | - * |
|
224 | - * @param int $id |
|
225 | - * @return Http\DataResponse |
|
226 | - * @throws OCSBadRequestException |
|
227 | - * @throws OCSForbiddenException |
|
228 | - * @throws OCSNotFoundException |
|
229 | - */ |
|
230 | - public function reShare($id) { |
|
231 | - |
|
232 | - $token = $this->request->getParam('token', null); |
|
233 | - $shareWith = $this->request->getParam('shareWith', null); |
|
234 | - $permission = (int)$this->request->getParam('permission', null); |
|
235 | - $remoteId = (int)$this->request->getParam('remoteId', null); |
|
236 | - |
|
237 | - if ($id === null || |
|
238 | - $token === null || |
|
239 | - $shareWith === null || |
|
240 | - $permission === null || |
|
241 | - $remoteId === null |
|
242 | - ) { |
|
243 | - throw new OCSBadRequestException(); |
|
244 | - } |
|
245 | - |
|
246 | - try { |
|
247 | - $share = $this->federatedShareProvider->getShareById($id); |
|
248 | - } catch (Share\Exceptions\ShareNotFound $e) { |
|
249 | - throw new OCSNotFoundException(); |
|
250 | - } |
|
251 | - |
|
252 | - // don't allow to share a file back to the owner |
|
253 | - list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith); |
|
254 | - $owner = $share->getShareOwner(); |
|
255 | - $currentServer = $this->addressHandler->generateRemoteURL(); |
|
256 | - if ($this->addressHandler->compareAddresses($user, $remote,$owner , $currentServer)) { |
|
257 | - throw new OCSForbiddenException(); |
|
258 | - } |
|
259 | - |
|
260 | - if ($this->verifyShare($share, $token)) { |
|
261 | - |
|
262 | - // check if re-sharing is allowed |
|
263 | - if ($share->getPermissions() | ~Constants::PERMISSION_SHARE) { |
|
264 | - $share->setPermissions($share->getPermissions() & $permission); |
|
265 | - // the recipient of the initial share is now the initiator for the re-share |
|
266 | - $share->setSharedBy($share->getSharedWith()); |
|
267 | - $share->setSharedWith($shareWith); |
|
268 | - try { |
|
269 | - $result = $this->federatedShareProvider->create($share); |
|
270 | - $this->federatedShareProvider->storeRemoteId((int)$result->getId(), $remoteId); |
|
271 | - return new Http\DataResponse([ |
|
272 | - 'token' => $result->getToken(), |
|
273 | - 'remoteId' => $result->getId() |
|
274 | - ]); |
|
275 | - } catch (\Exception $e) { |
|
276 | - throw new OCSBadRequestException(); |
|
277 | - } |
|
278 | - } else { |
|
279 | - throw new OCSForbiddenException(); |
|
280 | - } |
|
281 | - } |
|
282 | - throw new OCSBadRequestException(); |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * @NoCSRFRequired |
|
287 | - * @PublicPage |
|
288 | - * |
|
289 | - * accept server-to-server share |
|
290 | - * |
|
291 | - * @param int $id |
|
292 | - * @return Http\DataResponse |
|
293 | - * @throws OCSException |
|
294 | - */ |
|
295 | - public function acceptShare($id) { |
|
296 | - |
|
297 | - if (!$this->isS2SEnabled()) { |
|
298 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
299 | - } |
|
300 | - |
|
301 | - $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
302 | - |
|
303 | - try { |
|
304 | - $share = $this->federatedShareProvider->getShareById($id); |
|
305 | - } catch (Share\Exceptions\ShareNotFound $e) { |
|
306 | - return new Http\DataResponse(); |
|
307 | - } |
|
308 | - |
|
309 | - if ($this->verifyShare($share, $token)) { |
|
310 | - $this->executeAcceptShare($share); |
|
311 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
312 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
313 | - $remoteId = $this->federatedShareProvider->getRemoteId($share); |
|
314 | - $this->notifications->sendAcceptShare($remote, $remoteId, $share->getToken()); |
|
315 | - } |
|
316 | - } |
|
317 | - |
|
318 | - return new Http\DataResponse(); |
|
319 | - } |
|
320 | - |
|
321 | - protected function executeAcceptShare(Share\IShare $share) { |
|
322 | - list($file, $link) = $this->getFile($this->getCorrectUid($share), $share->getNode()->getId()); |
|
323 | - |
|
324 | - $event = \OC::$server->getActivityManager()->generateEvent(); |
|
325 | - $event->setApp('files_sharing') |
|
326 | - ->setType('remote_share') |
|
327 | - ->setAffectedUser($this->getCorrectUid($share)) |
|
328 | - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_ACCEPTED, [$share->getSharedWith(), $file]) |
|
329 | - ->setObject('files', (int) $share->getNode()->getId(), $file) |
|
330 | - ->setLink($link); |
|
331 | - \OC::$server->getActivityManager()->publish($event); |
|
332 | - } |
|
333 | - |
|
334 | - /** |
|
335 | - * @NoCSRFRequired |
|
336 | - * @PublicPage |
|
337 | - * |
|
338 | - * decline server-to-server share |
|
339 | - * |
|
340 | - * @param int $id |
|
341 | - * @return Http\DataResponse |
|
342 | - * @throws OCSException |
|
343 | - */ |
|
344 | - public function declineShare($id) { |
|
345 | - |
|
346 | - if (!$this->isS2SEnabled()) { |
|
347 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
348 | - } |
|
349 | - |
|
350 | - $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
351 | - |
|
352 | - try { |
|
353 | - $share = $this->federatedShareProvider->getShareById($id); |
|
354 | - } catch (Share\Exceptions\ShareNotFound $e) { |
|
355 | - return new Http\DataResponse(); |
|
356 | - } |
|
357 | - |
|
358 | - if($this->verifyShare($share, $token)) { |
|
359 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
360 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
361 | - $remoteId = $this->federatedShareProvider->getRemoteId($share); |
|
362 | - $this->notifications->sendDeclineShare($remote, $remoteId, $share->getToken()); |
|
363 | - } |
|
364 | - $this->executeDeclineShare($share); |
|
365 | - } |
|
366 | - |
|
367 | - return new Http\DataResponse(); |
|
368 | - } |
|
369 | - |
|
370 | - /** |
|
371 | - * delete declined share and create a activity |
|
372 | - * |
|
373 | - * @param Share\IShare $share |
|
374 | - */ |
|
375 | - protected function executeDeclineShare(Share\IShare $share) { |
|
376 | - $this->federatedShareProvider->removeShareFromTable($share); |
|
377 | - list($file, $link) = $this->getFile($this->getCorrectUid($share), $share->getNode()->getId()); |
|
378 | - |
|
379 | - $event = \OC::$server->getActivityManager()->generateEvent(); |
|
380 | - $event->setApp('files_sharing') |
|
381 | - ->setType('remote_share') |
|
382 | - ->setAffectedUser($this->getCorrectUid($share)) |
|
383 | - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_DECLINED, [$share->getSharedWith(), $file]) |
|
384 | - ->setObject('files', (int) $share->getNode()->getId(), $file) |
|
385 | - ->setLink($link); |
|
386 | - \OC::$server->getActivityManager()->publish($event); |
|
387 | - |
|
388 | - } |
|
389 | - |
|
390 | - /** |
|
391 | - * check if we are the initiator or the owner of a re-share and return the correct UID |
|
392 | - * |
|
393 | - * @param Share\IShare $share |
|
394 | - * @return string |
|
395 | - */ |
|
396 | - protected function getCorrectUid(Share\IShare $share) { |
|
397 | - if($this->userManager->userExists($share->getShareOwner())) { |
|
398 | - return $share->getShareOwner(); |
|
399 | - } |
|
400 | - |
|
401 | - return $share->getSharedBy(); |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * @NoCSRFRequired |
|
406 | - * @PublicPage |
|
407 | - * |
|
408 | - * remove server-to-server share if it was unshared by the owner |
|
409 | - * |
|
410 | - * @param int $id |
|
411 | - * @return Http\DataResponse |
|
412 | - * @throws OCSException |
|
413 | - */ |
|
414 | - public function unshare($id) { |
|
415 | - |
|
416 | - if (!$this->isS2SEnabled()) { |
|
417 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
418 | - } |
|
419 | - |
|
420 | - $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
421 | - |
|
422 | - $query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*share_external` WHERE `remote_id` = ? AND `share_token` = ?'); |
|
423 | - $query->execute(array($id, $token)); |
|
424 | - $share = $query->fetchRow(); |
|
425 | - |
|
426 | - if ($token && $id && !empty($share)) { |
|
427 | - |
|
428 | - $remote = $this->cleanupRemote($share['remote']); |
|
429 | - |
|
430 | - $owner = $this->cloudIdManager->getCloudId($share['owner'], $remote); |
|
431 | - $mountpoint = $share['mountpoint']; |
|
432 | - $user = $share['user']; |
|
433 | - |
|
434 | - $query = \OCP\DB::prepare('DELETE FROM `*PREFIX*share_external` WHERE `remote_id` = ? AND `share_token` = ?'); |
|
435 | - $query->execute(array($id, $token)); |
|
436 | - |
|
437 | - if ($share['accepted']) { |
|
438 | - $path = trim($mountpoint, '/'); |
|
439 | - } else { |
|
440 | - $path = trim($share['name'], '/'); |
|
441 | - } |
|
442 | - |
|
443 | - $notificationManager = \OC::$server->getNotificationManager(); |
|
444 | - $notification = $notificationManager->createNotification(); |
|
445 | - $notification->setApp('files_sharing') |
|
446 | - ->setUser($share['user']) |
|
447 | - ->setObject('remote_share', (int) $share['id']); |
|
448 | - $notificationManager->markProcessed($notification); |
|
449 | - |
|
450 | - $event = \OC::$server->getActivityManager()->generateEvent(); |
|
451 | - $event->setApp('files_sharing') |
|
452 | - ->setType('remote_share') |
|
453 | - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_UNSHARED, [$owner, $path]) |
|
454 | - ->setAffectedUser($user) |
|
455 | - ->setObject('remote_share', (int) $share['id'], $path); |
|
456 | - \OC::$server->getActivityManager()->publish($event); |
|
457 | - } |
|
458 | - |
|
459 | - return new Http\DataResponse(); |
|
460 | - } |
|
461 | - |
|
462 | - private function cleanupRemote($remote) { |
|
463 | - $remote = substr($remote, strpos($remote, '://') + 3); |
|
464 | - |
|
465 | - return rtrim($remote, '/'); |
|
466 | - } |
|
467 | - |
|
468 | - |
|
469 | - /** |
|
470 | - * @NoCSRFRequired |
|
471 | - * @PublicPage |
|
472 | - * |
|
473 | - * federated share was revoked, either by the owner or the re-sharer |
|
474 | - * |
|
475 | - * @param int $id |
|
476 | - * @return Http\DataResponse |
|
477 | - * @throws OCSBadRequestException |
|
478 | - */ |
|
479 | - public function revoke($id) { |
|
480 | - $token = $this->request->getParam('token'); |
|
481 | - |
|
482 | - $share = $this->federatedShareProvider->getShareById($id); |
|
483 | - |
|
484 | - if ($this->verifyShare($share, $token)) { |
|
485 | - $this->federatedShareProvider->removeShareFromTable($share); |
|
486 | - return new Http\DataResponse(); |
|
487 | - } |
|
488 | - |
|
489 | - throw new OCSBadRequestException(); |
|
490 | - } |
|
491 | - |
|
492 | - /** |
|
493 | - * get share |
|
494 | - * |
|
495 | - * @param int $id |
|
496 | - * @param string $token |
|
497 | - * @return array|bool |
|
498 | - */ |
|
499 | - protected function getShare($id, $token) { |
|
500 | - $query = $this->connection->getQueryBuilder(); |
|
501 | - $query->select('*')->from($this->shareTable) |
|
502 | - ->where($query->expr()->eq('token', $query->createNamedParameter($token))) |
|
503 | - ->andWhere($query->expr()->eq('share_type', $query->createNamedParameter(FederatedShareProvider::SHARE_TYPE_REMOTE))) |
|
504 | - ->andWhere($query->expr()->eq('id', $query->createNamedParameter($id))); |
|
505 | - |
|
506 | - $result = $query->execute()->fetchAll(); |
|
507 | - |
|
508 | - if (!empty($result) && isset($result[0])) { |
|
509 | - return $result[0]; |
|
510 | - } |
|
511 | - |
|
512 | - return false; |
|
513 | - } |
|
514 | - |
|
515 | - /** |
|
516 | - * get file |
|
517 | - * |
|
518 | - * @param string $user |
|
519 | - * @param int $fileSource |
|
520 | - * @return array with internal path of the file and a absolute link to it |
|
521 | - */ |
|
522 | - private function getFile($user, $fileSource) { |
|
523 | - \OC_Util::setupFS($user); |
|
524 | - |
|
525 | - try { |
|
526 | - $file = \OC\Files\Filesystem::getPath($fileSource); |
|
527 | - } catch (NotFoundException $e) { |
|
528 | - $file = null; |
|
529 | - } |
|
530 | - $args = \OC\Files\Filesystem::is_dir($file) ? array('dir' => $file) : array('dir' => dirname($file), 'scrollto' => $file); |
|
531 | - $link = \OCP\Util::linkToAbsolute('files', 'index.php', $args); |
|
532 | - |
|
533 | - return array($file, $link); |
|
534 | - |
|
535 | - } |
|
536 | - |
|
537 | - /** |
|
538 | - * check if server-to-server sharing is enabled |
|
539 | - * |
|
540 | - * @param bool $incoming |
|
541 | - * @return bool |
|
542 | - */ |
|
543 | - private function isS2SEnabled($incoming = false) { |
|
544 | - |
|
545 | - $result = \OCP\App::isEnabled('files_sharing'); |
|
546 | - |
|
547 | - if ($incoming) { |
|
548 | - $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled(); |
|
549 | - } else { |
|
550 | - $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
551 | - } |
|
552 | - |
|
553 | - return $result; |
|
554 | - } |
|
555 | - |
|
556 | - /** |
|
557 | - * check if we got the right share |
|
558 | - * |
|
559 | - * @param Share\IShare $share |
|
560 | - * @param string $token |
|
561 | - * @return bool |
|
562 | - */ |
|
563 | - protected function verifyShare(Share\IShare $share, $token) { |
|
564 | - if ( |
|
565 | - $share->getShareType() === FederatedShareProvider::SHARE_TYPE_REMOTE && |
|
566 | - $share->getToken() === $token |
|
567 | - ) { |
|
568 | - return true; |
|
569 | - } |
|
570 | - |
|
571 | - return false; |
|
572 | - } |
|
573 | - |
|
574 | - /** |
|
575 | - * @NoCSRFRequired |
|
576 | - * @PublicPage |
|
577 | - * |
|
578 | - * update share information to keep federated re-shares in sync |
|
579 | - * |
|
580 | - * @param int $id |
|
581 | - * @return Http\DataResponse |
|
582 | - * @throws OCSBadRequestException |
|
583 | - */ |
|
584 | - public function updatePermissions($id) { |
|
585 | - $token = $this->request->getParam('token', null); |
|
586 | - $permissions = $this->request->getParam('permissions', null); |
|
587 | - |
|
588 | - try { |
|
589 | - $share = $this->federatedShareProvider->getShareById($id); |
|
590 | - } catch (Share\Exceptions\ShareNotFound $e) { |
|
591 | - throw new OCSBadRequestException(); |
|
592 | - } |
|
593 | - |
|
594 | - $validPermission = ctype_digit($permissions); |
|
595 | - $validToken = $this->verifyShare($share, $token); |
|
596 | - if ($validPermission && $validToken) { |
|
597 | - $this->updatePermissionsInDatabase($share, (int)$permissions); |
|
598 | - } else { |
|
599 | - throw new OCSBadRequestException(); |
|
600 | - } |
|
601 | - |
|
602 | - return new Http\DataResponse(); |
|
603 | - } |
|
604 | - |
|
605 | - /** |
|
606 | - * update permissions in database |
|
607 | - * |
|
608 | - * @param IShare $share |
|
609 | - * @param int $permissions |
|
610 | - */ |
|
611 | - protected function updatePermissionsInDatabase(IShare $share, $permissions) { |
|
612 | - $query = $this->connection->getQueryBuilder(); |
|
613 | - $query->update('share') |
|
614 | - ->where($query->expr()->eq('id', $query->createNamedParameter($share->getId()))) |
|
615 | - ->set('permissions', $query->createNamedParameter($permissions)) |
|
616 | - ->execute(); |
|
617 | - } |
|
51 | + /** @var FederatedShareProvider */ |
|
52 | + private $federatedShareProvider; |
|
53 | + |
|
54 | + /** @var IDBConnection */ |
|
55 | + private $connection; |
|
56 | + |
|
57 | + /** @var Share\IManager */ |
|
58 | + private $shareManager; |
|
59 | + |
|
60 | + /** @var Notifications */ |
|
61 | + private $notifications; |
|
62 | + |
|
63 | + /** @var AddressHandler */ |
|
64 | + private $addressHandler; |
|
65 | + |
|
66 | + /** @var IUserManager */ |
|
67 | + private $userManager; |
|
68 | + |
|
69 | + /** @var string */ |
|
70 | + private $shareTable = 'share'; |
|
71 | + |
|
72 | + /** @var ICloudIdManager */ |
|
73 | + private $cloudIdManager; |
|
74 | + |
|
75 | + /** |
|
76 | + * Server2Server constructor. |
|
77 | + * |
|
78 | + * @param string $appName |
|
79 | + * @param IRequest $request |
|
80 | + * @param FederatedShareProvider $federatedShareProvider |
|
81 | + * @param IDBConnection $connection |
|
82 | + * @param Share\IManager $shareManager |
|
83 | + * @param Notifications $notifications |
|
84 | + * @param AddressHandler $addressHandler |
|
85 | + * @param IUserManager $userManager |
|
86 | + * @param ICloudIdManager $cloudIdManager |
|
87 | + */ |
|
88 | + public function __construct($appName, |
|
89 | + IRequest $request, |
|
90 | + FederatedShareProvider $federatedShareProvider, |
|
91 | + IDBConnection $connection, |
|
92 | + Share\IManager $shareManager, |
|
93 | + Notifications $notifications, |
|
94 | + AddressHandler $addressHandler, |
|
95 | + IUserManager $userManager, |
|
96 | + ICloudIdManager $cloudIdManager |
|
97 | + ) { |
|
98 | + parent::__construct($appName, $request); |
|
99 | + |
|
100 | + $this->federatedShareProvider = $federatedShareProvider; |
|
101 | + $this->connection = $connection; |
|
102 | + $this->shareManager = $shareManager; |
|
103 | + $this->notifications = $notifications; |
|
104 | + $this->addressHandler = $addressHandler; |
|
105 | + $this->userManager = $userManager; |
|
106 | + $this->cloudIdManager = $cloudIdManager; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @NoCSRFRequired |
|
111 | + * @PublicPage |
|
112 | + * |
|
113 | + * create a new share |
|
114 | + * |
|
115 | + * @return Http\DataResponse |
|
116 | + * @throws OCSException |
|
117 | + */ |
|
118 | + public function createShare() { |
|
119 | + |
|
120 | + if (!$this->isS2SEnabled(true)) { |
|
121 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
122 | + } |
|
123 | + |
|
124 | + $remote = isset($_POST['remote']) ? $_POST['remote'] : null; |
|
125 | + $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
126 | + $name = isset($_POST['name']) ? $_POST['name'] : null; |
|
127 | + $owner = isset($_POST['owner']) ? $_POST['owner'] : null; |
|
128 | + $sharedBy = isset($_POST['sharedBy']) ? $_POST['sharedBy'] : null; |
|
129 | + $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null; |
|
130 | + $remoteId = isset($_POST['remoteId']) ? (int)$_POST['remoteId'] : null; |
|
131 | + $sharedByFederatedId = isset($_POST['sharedByFederatedId']) ? $_POST['sharedByFederatedId'] : null; |
|
132 | + $ownerFederatedId = isset($_POST['ownerFederatedId']) ? $_POST['ownerFederatedId'] : null; |
|
133 | + |
|
134 | + if ($remote && $token && $name && $owner && $remoteId && $shareWith) { |
|
135 | + |
|
136 | + if(!\OCP\Util::isValidFileName($name)) { |
|
137 | + throw new OCSException('The mountpoint name contains invalid characters.', 400); |
|
138 | + } |
|
139 | + |
|
140 | + // FIXME this should be a method in the user management instead |
|
141 | + \OCP\Util::writeLog('files_sharing', 'shareWith before, ' . $shareWith, \OCP\Util::DEBUG); |
|
142 | + \OCP\Util::emitHook( |
|
143 | + '\OCA\Files_Sharing\API\Server2Server', |
|
144 | + 'preLoginNameUsedAsUserName', |
|
145 | + array('uid' => &$shareWith) |
|
146 | + ); |
|
147 | + \OCP\Util::writeLog('files_sharing', 'shareWith after, ' . $shareWith, \OCP\Util::DEBUG); |
|
148 | + |
|
149 | + if (!\OCP\User::userExists($shareWith)) { |
|
150 | + throw new OCSException('User does not exists', 400); |
|
151 | + } |
|
152 | + |
|
153 | + \OC_Util::setupFS($shareWith); |
|
154 | + |
|
155 | + $externalManager = new \OCA\Files_Sharing\External\Manager( |
|
156 | + \OC::$server->getDatabaseConnection(), |
|
157 | + \OC\Files\Filesystem::getMountManager(), |
|
158 | + \OC\Files\Filesystem::getLoader(), |
|
159 | + \OC::$server->getHTTPClientService(), |
|
160 | + \OC::$server->getNotificationManager(), |
|
161 | + \OC::$server->getOCSDiscoveryService(), |
|
162 | + $shareWith |
|
163 | + ); |
|
164 | + |
|
165 | + try { |
|
166 | + $externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId); |
|
167 | + $shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external'); |
|
168 | + |
|
169 | + if ($ownerFederatedId === null) { |
|
170 | + $ownerFederatedId = $this->cloudIdManager->getCloudId($owner, $this->cleanupRemote($remote))->getId(); |
|
171 | + } |
|
172 | + // if the owner of the share and the initiator are the same user |
|
173 | + // we also complete the federated share ID for the initiator |
|
174 | + if ($sharedByFederatedId === null && $owner === $sharedBy) { |
|
175 | + $sharedByFederatedId = $ownerFederatedId; |
|
176 | + } |
|
177 | + |
|
178 | + $event = \OC::$server->getActivityManager()->generateEvent(); |
|
179 | + $event->setApp('files_sharing') |
|
180 | + ->setType('remote_share') |
|
181 | + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')]) |
|
182 | + ->setAffectedUser($shareWith) |
|
183 | + ->setObject('remote_share', (int) $shareId, $name); |
|
184 | + \OC::$server->getActivityManager()->publish($event); |
|
185 | + |
|
186 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
187 | + |
|
188 | + $notificationManager = \OC::$server->getNotificationManager(); |
|
189 | + $notification = $notificationManager->createNotification(); |
|
190 | + $notification->setApp('files_sharing') |
|
191 | + ->setUser($shareWith) |
|
192 | + ->setDateTime(new \DateTime()) |
|
193 | + ->setObject('remote_share', $shareId) |
|
194 | + ->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/')]); |
|
195 | + |
|
196 | + $declineAction = $notification->createAction(); |
|
197 | + $declineAction->setLabel('decline') |
|
198 | + ->setLink($urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'ocs/v1.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'DELETE'); |
|
199 | + $notification->addAction($declineAction); |
|
200 | + |
|
201 | + $acceptAction = $notification->createAction(); |
|
202 | + $acceptAction->setLabel('accept') |
|
203 | + ->setLink($urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'ocs/v1.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'POST'); |
|
204 | + $notification->addAction($acceptAction); |
|
205 | + |
|
206 | + $notificationManager->notify($notification); |
|
207 | + |
|
208 | + return new Http\DataResponse(); |
|
209 | + } catch (\Exception $e) { |
|
210 | + \OCP\Util::writeLog('files_sharing', 'server can not add remote share, ' . $e->getMessage(), \OCP\Util::ERROR); |
|
211 | + throw new OCSException('internal server error, was not able to add share from ' . $remote, 500); |
|
212 | + } |
|
213 | + } |
|
214 | + |
|
215 | + throw new OCSException('server can not add remote share, missing parameter', 400); |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * @NoCSRFRequired |
|
220 | + * @PublicPage |
|
221 | + * |
|
222 | + * create re-share on behalf of another user |
|
223 | + * |
|
224 | + * @param int $id |
|
225 | + * @return Http\DataResponse |
|
226 | + * @throws OCSBadRequestException |
|
227 | + * @throws OCSForbiddenException |
|
228 | + * @throws OCSNotFoundException |
|
229 | + */ |
|
230 | + public function reShare($id) { |
|
231 | + |
|
232 | + $token = $this->request->getParam('token', null); |
|
233 | + $shareWith = $this->request->getParam('shareWith', null); |
|
234 | + $permission = (int)$this->request->getParam('permission', null); |
|
235 | + $remoteId = (int)$this->request->getParam('remoteId', null); |
|
236 | + |
|
237 | + if ($id === null || |
|
238 | + $token === null || |
|
239 | + $shareWith === null || |
|
240 | + $permission === null || |
|
241 | + $remoteId === null |
|
242 | + ) { |
|
243 | + throw new OCSBadRequestException(); |
|
244 | + } |
|
245 | + |
|
246 | + try { |
|
247 | + $share = $this->federatedShareProvider->getShareById($id); |
|
248 | + } catch (Share\Exceptions\ShareNotFound $e) { |
|
249 | + throw new OCSNotFoundException(); |
|
250 | + } |
|
251 | + |
|
252 | + // don't allow to share a file back to the owner |
|
253 | + list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith); |
|
254 | + $owner = $share->getShareOwner(); |
|
255 | + $currentServer = $this->addressHandler->generateRemoteURL(); |
|
256 | + if ($this->addressHandler->compareAddresses($user, $remote,$owner , $currentServer)) { |
|
257 | + throw new OCSForbiddenException(); |
|
258 | + } |
|
259 | + |
|
260 | + if ($this->verifyShare($share, $token)) { |
|
261 | + |
|
262 | + // check if re-sharing is allowed |
|
263 | + if ($share->getPermissions() | ~Constants::PERMISSION_SHARE) { |
|
264 | + $share->setPermissions($share->getPermissions() & $permission); |
|
265 | + // the recipient of the initial share is now the initiator for the re-share |
|
266 | + $share->setSharedBy($share->getSharedWith()); |
|
267 | + $share->setSharedWith($shareWith); |
|
268 | + try { |
|
269 | + $result = $this->federatedShareProvider->create($share); |
|
270 | + $this->federatedShareProvider->storeRemoteId((int)$result->getId(), $remoteId); |
|
271 | + return new Http\DataResponse([ |
|
272 | + 'token' => $result->getToken(), |
|
273 | + 'remoteId' => $result->getId() |
|
274 | + ]); |
|
275 | + } catch (\Exception $e) { |
|
276 | + throw new OCSBadRequestException(); |
|
277 | + } |
|
278 | + } else { |
|
279 | + throw new OCSForbiddenException(); |
|
280 | + } |
|
281 | + } |
|
282 | + throw new OCSBadRequestException(); |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * @NoCSRFRequired |
|
287 | + * @PublicPage |
|
288 | + * |
|
289 | + * accept server-to-server share |
|
290 | + * |
|
291 | + * @param int $id |
|
292 | + * @return Http\DataResponse |
|
293 | + * @throws OCSException |
|
294 | + */ |
|
295 | + public function acceptShare($id) { |
|
296 | + |
|
297 | + if (!$this->isS2SEnabled()) { |
|
298 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
299 | + } |
|
300 | + |
|
301 | + $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
302 | + |
|
303 | + try { |
|
304 | + $share = $this->federatedShareProvider->getShareById($id); |
|
305 | + } catch (Share\Exceptions\ShareNotFound $e) { |
|
306 | + return new Http\DataResponse(); |
|
307 | + } |
|
308 | + |
|
309 | + if ($this->verifyShare($share, $token)) { |
|
310 | + $this->executeAcceptShare($share); |
|
311 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
312 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
313 | + $remoteId = $this->federatedShareProvider->getRemoteId($share); |
|
314 | + $this->notifications->sendAcceptShare($remote, $remoteId, $share->getToken()); |
|
315 | + } |
|
316 | + } |
|
317 | + |
|
318 | + return new Http\DataResponse(); |
|
319 | + } |
|
320 | + |
|
321 | + protected function executeAcceptShare(Share\IShare $share) { |
|
322 | + list($file, $link) = $this->getFile($this->getCorrectUid($share), $share->getNode()->getId()); |
|
323 | + |
|
324 | + $event = \OC::$server->getActivityManager()->generateEvent(); |
|
325 | + $event->setApp('files_sharing') |
|
326 | + ->setType('remote_share') |
|
327 | + ->setAffectedUser($this->getCorrectUid($share)) |
|
328 | + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_ACCEPTED, [$share->getSharedWith(), $file]) |
|
329 | + ->setObject('files', (int) $share->getNode()->getId(), $file) |
|
330 | + ->setLink($link); |
|
331 | + \OC::$server->getActivityManager()->publish($event); |
|
332 | + } |
|
333 | + |
|
334 | + /** |
|
335 | + * @NoCSRFRequired |
|
336 | + * @PublicPage |
|
337 | + * |
|
338 | + * decline server-to-server share |
|
339 | + * |
|
340 | + * @param int $id |
|
341 | + * @return Http\DataResponse |
|
342 | + * @throws OCSException |
|
343 | + */ |
|
344 | + public function declineShare($id) { |
|
345 | + |
|
346 | + if (!$this->isS2SEnabled()) { |
|
347 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
348 | + } |
|
349 | + |
|
350 | + $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
351 | + |
|
352 | + try { |
|
353 | + $share = $this->federatedShareProvider->getShareById($id); |
|
354 | + } catch (Share\Exceptions\ShareNotFound $e) { |
|
355 | + return new Http\DataResponse(); |
|
356 | + } |
|
357 | + |
|
358 | + if($this->verifyShare($share, $token)) { |
|
359 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
360 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
361 | + $remoteId = $this->federatedShareProvider->getRemoteId($share); |
|
362 | + $this->notifications->sendDeclineShare($remote, $remoteId, $share->getToken()); |
|
363 | + } |
|
364 | + $this->executeDeclineShare($share); |
|
365 | + } |
|
366 | + |
|
367 | + return new Http\DataResponse(); |
|
368 | + } |
|
369 | + |
|
370 | + /** |
|
371 | + * delete declined share and create a activity |
|
372 | + * |
|
373 | + * @param Share\IShare $share |
|
374 | + */ |
|
375 | + protected function executeDeclineShare(Share\IShare $share) { |
|
376 | + $this->federatedShareProvider->removeShareFromTable($share); |
|
377 | + list($file, $link) = $this->getFile($this->getCorrectUid($share), $share->getNode()->getId()); |
|
378 | + |
|
379 | + $event = \OC::$server->getActivityManager()->generateEvent(); |
|
380 | + $event->setApp('files_sharing') |
|
381 | + ->setType('remote_share') |
|
382 | + ->setAffectedUser($this->getCorrectUid($share)) |
|
383 | + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_DECLINED, [$share->getSharedWith(), $file]) |
|
384 | + ->setObject('files', (int) $share->getNode()->getId(), $file) |
|
385 | + ->setLink($link); |
|
386 | + \OC::$server->getActivityManager()->publish($event); |
|
387 | + |
|
388 | + } |
|
389 | + |
|
390 | + /** |
|
391 | + * check if we are the initiator or the owner of a re-share and return the correct UID |
|
392 | + * |
|
393 | + * @param Share\IShare $share |
|
394 | + * @return string |
|
395 | + */ |
|
396 | + protected function getCorrectUid(Share\IShare $share) { |
|
397 | + if($this->userManager->userExists($share->getShareOwner())) { |
|
398 | + return $share->getShareOwner(); |
|
399 | + } |
|
400 | + |
|
401 | + return $share->getSharedBy(); |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * @NoCSRFRequired |
|
406 | + * @PublicPage |
|
407 | + * |
|
408 | + * remove server-to-server share if it was unshared by the owner |
|
409 | + * |
|
410 | + * @param int $id |
|
411 | + * @return Http\DataResponse |
|
412 | + * @throws OCSException |
|
413 | + */ |
|
414 | + public function unshare($id) { |
|
415 | + |
|
416 | + if (!$this->isS2SEnabled()) { |
|
417 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
418 | + } |
|
419 | + |
|
420 | + $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
421 | + |
|
422 | + $query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*share_external` WHERE `remote_id` = ? AND `share_token` = ?'); |
|
423 | + $query->execute(array($id, $token)); |
|
424 | + $share = $query->fetchRow(); |
|
425 | + |
|
426 | + if ($token && $id && !empty($share)) { |
|
427 | + |
|
428 | + $remote = $this->cleanupRemote($share['remote']); |
|
429 | + |
|
430 | + $owner = $this->cloudIdManager->getCloudId($share['owner'], $remote); |
|
431 | + $mountpoint = $share['mountpoint']; |
|
432 | + $user = $share['user']; |
|
433 | + |
|
434 | + $query = \OCP\DB::prepare('DELETE FROM `*PREFIX*share_external` WHERE `remote_id` = ? AND `share_token` = ?'); |
|
435 | + $query->execute(array($id, $token)); |
|
436 | + |
|
437 | + if ($share['accepted']) { |
|
438 | + $path = trim($mountpoint, '/'); |
|
439 | + } else { |
|
440 | + $path = trim($share['name'], '/'); |
|
441 | + } |
|
442 | + |
|
443 | + $notificationManager = \OC::$server->getNotificationManager(); |
|
444 | + $notification = $notificationManager->createNotification(); |
|
445 | + $notification->setApp('files_sharing') |
|
446 | + ->setUser($share['user']) |
|
447 | + ->setObject('remote_share', (int) $share['id']); |
|
448 | + $notificationManager->markProcessed($notification); |
|
449 | + |
|
450 | + $event = \OC::$server->getActivityManager()->generateEvent(); |
|
451 | + $event->setApp('files_sharing') |
|
452 | + ->setType('remote_share') |
|
453 | + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_UNSHARED, [$owner, $path]) |
|
454 | + ->setAffectedUser($user) |
|
455 | + ->setObject('remote_share', (int) $share['id'], $path); |
|
456 | + \OC::$server->getActivityManager()->publish($event); |
|
457 | + } |
|
458 | + |
|
459 | + return new Http\DataResponse(); |
|
460 | + } |
|
461 | + |
|
462 | + private function cleanupRemote($remote) { |
|
463 | + $remote = substr($remote, strpos($remote, '://') + 3); |
|
464 | + |
|
465 | + return rtrim($remote, '/'); |
|
466 | + } |
|
467 | + |
|
468 | + |
|
469 | + /** |
|
470 | + * @NoCSRFRequired |
|
471 | + * @PublicPage |
|
472 | + * |
|
473 | + * federated share was revoked, either by the owner or the re-sharer |
|
474 | + * |
|
475 | + * @param int $id |
|
476 | + * @return Http\DataResponse |
|
477 | + * @throws OCSBadRequestException |
|
478 | + */ |
|
479 | + public function revoke($id) { |
|
480 | + $token = $this->request->getParam('token'); |
|
481 | + |
|
482 | + $share = $this->federatedShareProvider->getShareById($id); |
|
483 | + |
|
484 | + if ($this->verifyShare($share, $token)) { |
|
485 | + $this->federatedShareProvider->removeShareFromTable($share); |
|
486 | + return new Http\DataResponse(); |
|
487 | + } |
|
488 | + |
|
489 | + throw new OCSBadRequestException(); |
|
490 | + } |
|
491 | + |
|
492 | + /** |
|
493 | + * get share |
|
494 | + * |
|
495 | + * @param int $id |
|
496 | + * @param string $token |
|
497 | + * @return array|bool |
|
498 | + */ |
|
499 | + protected function getShare($id, $token) { |
|
500 | + $query = $this->connection->getQueryBuilder(); |
|
501 | + $query->select('*')->from($this->shareTable) |
|
502 | + ->where($query->expr()->eq('token', $query->createNamedParameter($token))) |
|
503 | + ->andWhere($query->expr()->eq('share_type', $query->createNamedParameter(FederatedShareProvider::SHARE_TYPE_REMOTE))) |
|
504 | + ->andWhere($query->expr()->eq('id', $query->createNamedParameter($id))); |
|
505 | + |
|
506 | + $result = $query->execute()->fetchAll(); |
|
507 | + |
|
508 | + if (!empty($result) && isset($result[0])) { |
|
509 | + return $result[0]; |
|
510 | + } |
|
511 | + |
|
512 | + return false; |
|
513 | + } |
|
514 | + |
|
515 | + /** |
|
516 | + * get file |
|
517 | + * |
|
518 | + * @param string $user |
|
519 | + * @param int $fileSource |
|
520 | + * @return array with internal path of the file and a absolute link to it |
|
521 | + */ |
|
522 | + private function getFile($user, $fileSource) { |
|
523 | + \OC_Util::setupFS($user); |
|
524 | + |
|
525 | + try { |
|
526 | + $file = \OC\Files\Filesystem::getPath($fileSource); |
|
527 | + } catch (NotFoundException $e) { |
|
528 | + $file = null; |
|
529 | + } |
|
530 | + $args = \OC\Files\Filesystem::is_dir($file) ? array('dir' => $file) : array('dir' => dirname($file), 'scrollto' => $file); |
|
531 | + $link = \OCP\Util::linkToAbsolute('files', 'index.php', $args); |
|
532 | + |
|
533 | + return array($file, $link); |
|
534 | + |
|
535 | + } |
|
536 | + |
|
537 | + /** |
|
538 | + * check if server-to-server sharing is enabled |
|
539 | + * |
|
540 | + * @param bool $incoming |
|
541 | + * @return bool |
|
542 | + */ |
|
543 | + private function isS2SEnabled($incoming = false) { |
|
544 | + |
|
545 | + $result = \OCP\App::isEnabled('files_sharing'); |
|
546 | + |
|
547 | + if ($incoming) { |
|
548 | + $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled(); |
|
549 | + } else { |
|
550 | + $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
551 | + } |
|
552 | + |
|
553 | + return $result; |
|
554 | + } |
|
555 | + |
|
556 | + /** |
|
557 | + * check if we got the right share |
|
558 | + * |
|
559 | + * @param Share\IShare $share |
|
560 | + * @param string $token |
|
561 | + * @return bool |
|
562 | + */ |
|
563 | + protected function verifyShare(Share\IShare $share, $token) { |
|
564 | + if ( |
|
565 | + $share->getShareType() === FederatedShareProvider::SHARE_TYPE_REMOTE && |
|
566 | + $share->getToken() === $token |
|
567 | + ) { |
|
568 | + return true; |
|
569 | + } |
|
570 | + |
|
571 | + return false; |
|
572 | + } |
|
573 | + |
|
574 | + /** |
|
575 | + * @NoCSRFRequired |
|
576 | + * @PublicPage |
|
577 | + * |
|
578 | + * update share information to keep federated re-shares in sync |
|
579 | + * |
|
580 | + * @param int $id |
|
581 | + * @return Http\DataResponse |
|
582 | + * @throws OCSBadRequestException |
|
583 | + */ |
|
584 | + public function updatePermissions($id) { |
|
585 | + $token = $this->request->getParam('token', null); |
|
586 | + $permissions = $this->request->getParam('permissions', null); |
|
587 | + |
|
588 | + try { |
|
589 | + $share = $this->federatedShareProvider->getShareById($id); |
|
590 | + } catch (Share\Exceptions\ShareNotFound $e) { |
|
591 | + throw new OCSBadRequestException(); |
|
592 | + } |
|
593 | + |
|
594 | + $validPermission = ctype_digit($permissions); |
|
595 | + $validToken = $this->verifyShare($share, $token); |
|
596 | + if ($validPermission && $validToken) { |
|
597 | + $this->updatePermissionsInDatabase($share, (int)$permissions); |
|
598 | + } else { |
|
599 | + throw new OCSBadRequestException(); |
|
600 | + } |
|
601 | + |
|
602 | + return new Http\DataResponse(); |
|
603 | + } |
|
604 | + |
|
605 | + /** |
|
606 | + * update permissions in database |
|
607 | + * |
|
608 | + * @param IShare $share |
|
609 | + * @param int $permissions |
|
610 | + */ |
|
611 | + protected function updatePermissionsInDatabase(IShare $share, $permissions) { |
|
612 | + $query = $this->connection->getQueryBuilder(); |
|
613 | + $query->update('share') |
|
614 | + ->where($query->expr()->eq('id', $query->createNamedParameter($share->getId()))) |
|
615 | + ->set('permissions', $query->createNamedParameter($permissions)) |
|
616 | + ->execute(); |
|
617 | + } |
|
618 | 618 | |
619 | 619 | } |