@@ -39,181 +39,181 @@ |
||
39 | 39 | * @deprecated 26.0.0 |
40 | 40 | */ |
41 | 41 | class File implements ICache { |
42 | - /** @var View */ |
|
43 | - protected $storage; |
|
42 | + /** @var View */ |
|
43 | + protected $storage; |
|
44 | 44 | |
45 | - /** |
|
46 | - * Set the cache storage for a user |
|
47 | - */ |
|
48 | - public function setUpStorage(string $userId) { |
|
49 | - Filesystem::initMountPoints($userId); |
|
50 | - $rootView = new View(); |
|
51 | - if (!$rootView->file_exists('/' . $userId . '/cache')) { |
|
52 | - $rootView->mkdir('/' . $userId . '/cache'); |
|
53 | - } |
|
54 | - $this->storage = new View('/' . $userId . '/cache'); |
|
55 | - return $this->storage; |
|
56 | - } |
|
45 | + /** |
|
46 | + * Set the cache storage for a user |
|
47 | + */ |
|
48 | + public function setUpStorage(string $userId) { |
|
49 | + Filesystem::initMountPoints($userId); |
|
50 | + $rootView = new View(); |
|
51 | + if (!$rootView->file_exists('/' . $userId . '/cache')) { |
|
52 | + $rootView->mkdir('/' . $userId . '/cache'); |
|
53 | + } |
|
54 | + $this->storage = new View('/' . $userId . '/cache'); |
|
55 | + return $this->storage; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Returns the cache storage for the logged in user |
|
60 | - * |
|
61 | - * @return \OC\Files\View cache storage |
|
62 | - * @throws \OC\ForbiddenException |
|
63 | - * @throws \OC\User\NoUserException |
|
64 | - */ |
|
65 | - protected function getStorage() { |
|
66 | - if ($this->storage !== null) { |
|
67 | - return $this->storage; |
|
68 | - } |
|
69 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
70 | - $user = \OC::$server->getUserSession()->getUser(); |
|
71 | - return $this->setUpStorage($user->getUID()); |
|
72 | - } else { |
|
73 | - \OC::$server->get(LoggerInterface::class)->error('Can\'t get cache storage, user not logged in', ['app' => 'core']); |
|
74 | - throw new \OC\ForbiddenException('Can\t get cache storage, user not logged in'); |
|
75 | - } |
|
76 | - } |
|
58 | + /** |
|
59 | + * Returns the cache storage for the logged in user |
|
60 | + * |
|
61 | + * @return \OC\Files\View cache storage |
|
62 | + * @throws \OC\ForbiddenException |
|
63 | + * @throws \OC\User\NoUserException |
|
64 | + */ |
|
65 | + protected function getStorage() { |
|
66 | + if ($this->storage !== null) { |
|
67 | + return $this->storage; |
|
68 | + } |
|
69 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
70 | + $user = \OC::$server->getUserSession()->getUser(); |
|
71 | + return $this->setUpStorage($user->getUID()); |
|
72 | + } else { |
|
73 | + \OC::$server->get(LoggerInterface::class)->error('Can\'t get cache storage, user not logged in', ['app' => 'core']); |
|
74 | + throw new \OC\ForbiddenException('Can\t get cache storage, user not logged in'); |
|
75 | + } |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @param string $key |
|
80 | - * @return mixed|null |
|
81 | - * @throws \OC\ForbiddenException |
|
82 | - */ |
|
83 | - public function get($key) { |
|
84 | - $result = null; |
|
85 | - if ($this->hasKey($key)) { |
|
86 | - $storage = $this->getStorage(); |
|
87 | - $result = $storage->file_get_contents($key); |
|
88 | - } |
|
89 | - return $result; |
|
90 | - } |
|
78 | + /** |
|
79 | + * @param string $key |
|
80 | + * @return mixed|null |
|
81 | + * @throws \OC\ForbiddenException |
|
82 | + */ |
|
83 | + public function get($key) { |
|
84 | + $result = null; |
|
85 | + if ($this->hasKey($key)) { |
|
86 | + $storage = $this->getStorage(); |
|
87 | + $result = $storage->file_get_contents($key); |
|
88 | + } |
|
89 | + return $result; |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Returns the size of the stored/cached data |
|
94 | - * |
|
95 | - * @param string $key |
|
96 | - * @return int |
|
97 | - */ |
|
98 | - public function size($key) { |
|
99 | - $result = 0; |
|
100 | - if ($this->hasKey($key)) { |
|
101 | - $storage = $this->getStorage(); |
|
102 | - $result = $storage->filesize($key); |
|
103 | - } |
|
104 | - return $result; |
|
105 | - } |
|
92 | + /** |
|
93 | + * Returns the size of the stored/cached data |
|
94 | + * |
|
95 | + * @param string $key |
|
96 | + * @return int |
|
97 | + */ |
|
98 | + public function size($key) { |
|
99 | + $result = 0; |
|
100 | + if ($this->hasKey($key)) { |
|
101 | + $storage = $this->getStorage(); |
|
102 | + $result = $storage->filesize($key); |
|
103 | + } |
|
104 | + return $result; |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * @param string $key |
|
109 | - * @param mixed $value |
|
110 | - * @param int $ttl |
|
111 | - * @return bool|mixed |
|
112 | - * @throws \OC\ForbiddenException |
|
113 | - */ |
|
114 | - public function set($key, $value, $ttl = 0) { |
|
115 | - $storage = $this->getStorage(); |
|
116 | - $result = false; |
|
117 | - // unique id to avoid chunk collision, just in case |
|
118 | - $uniqueId = \OC::$server->getSecureRandom()->generate( |
|
119 | - 16, |
|
120 | - ISecureRandom::CHAR_ALPHANUMERIC |
|
121 | - ); |
|
107 | + /** |
|
108 | + * @param string $key |
|
109 | + * @param mixed $value |
|
110 | + * @param int $ttl |
|
111 | + * @return bool|mixed |
|
112 | + * @throws \OC\ForbiddenException |
|
113 | + */ |
|
114 | + public function set($key, $value, $ttl = 0) { |
|
115 | + $storage = $this->getStorage(); |
|
116 | + $result = false; |
|
117 | + // unique id to avoid chunk collision, just in case |
|
118 | + $uniqueId = \OC::$server->getSecureRandom()->generate( |
|
119 | + 16, |
|
120 | + ISecureRandom::CHAR_ALPHANUMERIC |
|
121 | + ); |
|
122 | 122 | |
123 | - // use part file to prevent hasKey() to find the key |
|
124 | - // while it is being written |
|
125 | - $keyPart = $key . '.' . $uniqueId . '.part'; |
|
126 | - if ($storage and $storage->file_put_contents($keyPart, $value)) { |
|
127 | - if ($ttl === 0) { |
|
128 | - $ttl = 86400; // 60*60*24 |
|
129 | - } |
|
130 | - $result = $storage->touch($keyPart, time() + $ttl); |
|
131 | - $result &= $storage->rename($keyPart, $key); |
|
132 | - } |
|
133 | - return $result; |
|
134 | - } |
|
123 | + // use part file to prevent hasKey() to find the key |
|
124 | + // while it is being written |
|
125 | + $keyPart = $key . '.' . $uniqueId . '.part'; |
|
126 | + if ($storage and $storage->file_put_contents($keyPart, $value)) { |
|
127 | + if ($ttl === 0) { |
|
128 | + $ttl = 86400; // 60*60*24 |
|
129 | + } |
|
130 | + $result = $storage->touch($keyPart, time() + $ttl); |
|
131 | + $result &= $storage->rename($keyPart, $key); |
|
132 | + } |
|
133 | + return $result; |
|
134 | + } |
|
135 | 135 | |
136 | - /** |
|
137 | - * @param string $key |
|
138 | - * @return bool |
|
139 | - * @throws \OC\ForbiddenException |
|
140 | - */ |
|
141 | - public function hasKey($key) { |
|
142 | - $storage = $this->getStorage(); |
|
143 | - if ($storage && $storage->is_file($key) && $storage->isReadable($key)) { |
|
144 | - return true; |
|
145 | - } |
|
146 | - return false; |
|
147 | - } |
|
136 | + /** |
|
137 | + * @param string $key |
|
138 | + * @return bool |
|
139 | + * @throws \OC\ForbiddenException |
|
140 | + */ |
|
141 | + public function hasKey($key) { |
|
142 | + $storage = $this->getStorage(); |
|
143 | + if ($storage && $storage->is_file($key) && $storage->isReadable($key)) { |
|
144 | + return true; |
|
145 | + } |
|
146 | + return false; |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * @param string $key |
|
151 | - * @return bool|mixed |
|
152 | - * @throws \OC\ForbiddenException |
|
153 | - */ |
|
154 | - public function remove($key) { |
|
155 | - $storage = $this->getStorage(); |
|
156 | - if (!$storage) { |
|
157 | - return false; |
|
158 | - } |
|
159 | - return $storage->unlink($key); |
|
160 | - } |
|
149 | + /** |
|
150 | + * @param string $key |
|
151 | + * @return bool|mixed |
|
152 | + * @throws \OC\ForbiddenException |
|
153 | + */ |
|
154 | + public function remove($key) { |
|
155 | + $storage = $this->getStorage(); |
|
156 | + if (!$storage) { |
|
157 | + return false; |
|
158 | + } |
|
159 | + return $storage->unlink($key); |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * @param string $prefix |
|
164 | - * @return bool |
|
165 | - * @throws \OC\ForbiddenException |
|
166 | - */ |
|
167 | - public function clear($prefix = '') { |
|
168 | - $storage = $this->getStorage(); |
|
169 | - if ($storage and $storage->is_dir('/')) { |
|
170 | - $dh = $storage->opendir('/'); |
|
171 | - if (is_resource($dh)) { |
|
172 | - while (($file = readdir($dh)) !== false) { |
|
173 | - if ($file != '.' and $file != '..' and ($prefix === '' || strpos($file, $prefix) === 0)) { |
|
174 | - $storage->unlink('/' . $file); |
|
175 | - } |
|
176 | - } |
|
177 | - } |
|
178 | - } |
|
179 | - return true; |
|
180 | - } |
|
162 | + /** |
|
163 | + * @param string $prefix |
|
164 | + * @return bool |
|
165 | + * @throws \OC\ForbiddenException |
|
166 | + */ |
|
167 | + public function clear($prefix = '') { |
|
168 | + $storage = $this->getStorage(); |
|
169 | + if ($storage and $storage->is_dir('/')) { |
|
170 | + $dh = $storage->opendir('/'); |
|
171 | + if (is_resource($dh)) { |
|
172 | + while (($file = readdir($dh)) !== false) { |
|
173 | + if ($file != '.' and $file != '..' and ($prefix === '' || strpos($file, $prefix) === 0)) { |
|
174 | + $storage->unlink('/' . $file); |
|
175 | + } |
|
176 | + } |
|
177 | + } |
|
178 | + } |
|
179 | + return true; |
|
180 | + } |
|
181 | 181 | |
182 | - /** |
|
183 | - * Runs GC |
|
184 | - * @throws \OC\ForbiddenException |
|
185 | - */ |
|
186 | - public function gc() { |
|
187 | - $storage = $this->getStorage(); |
|
188 | - if ($storage) { |
|
189 | - // extra hour safety, in case of stray part chunks that take longer to write, |
|
190 | - // because touch() is only called after the chunk was finished |
|
191 | - $now = time() - 3600; |
|
192 | - $dh = $storage->opendir('/'); |
|
193 | - if (!is_resource($dh)) { |
|
194 | - return null; |
|
195 | - } |
|
196 | - while (($file = readdir($dh)) !== false) { |
|
197 | - if ($file != '.' and $file != '..') { |
|
198 | - try { |
|
199 | - $mtime = $storage->filemtime('/' . $file); |
|
200 | - if ($mtime < $now) { |
|
201 | - $storage->unlink('/' . $file); |
|
202 | - } |
|
203 | - } catch (\OCP\Lock\LockedException $e) { |
|
204 | - // ignore locked chunks |
|
205 | - \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', ['app' => 'core']); |
|
206 | - } catch (\OCP\Files\ForbiddenException $e) { |
|
207 | - \OC::$server->getLogger()->debug('Could not cleanup forbidden chunk "' . $file . '"', ['app' => 'core']); |
|
208 | - } catch (\OCP\Files\LockNotAcquiredException $e) { |
|
209 | - \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', ['app' => 'core']); |
|
210 | - } |
|
211 | - } |
|
212 | - } |
|
213 | - } |
|
214 | - } |
|
182 | + /** |
|
183 | + * Runs GC |
|
184 | + * @throws \OC\ForbiddenException |
|
185 | + */ |
|
186 | + public function gc() { |
|
187 | + $storage = $this->getStorage(); |
|
188 | + if ($storage) { |
|
189 | + // extra hour safety, in case of stray part chunks that take longer to write, |
|
190 | + // because touch() is only called after the chunk was finished |
|
191 | + $now = time() - 3600; |
|
192 | + $dh = $storage->opendir('/'); |
|
193 | + if (!is_resource($dh)) { |
|
194 | + return null; |
|
195 | + } |
|
196 | + while (($file = readdir($dh)) !== false) { |
|
197 | + if ($file != '.' and $file != '..') { |
|
198 | + try { |
|
199 | + $mtime = $storage->filemtime('/' . $file); |
|
200 | + if ($mtime < $now) { |
|
201 | + $storage->unlink('/' . $file); |
|
202 | + } |
|
203 | + } catch (\OCP\Lock\LockedException $e) { |
|
204 | + // ignore locked chunks |
|
205 | + \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', ['app' => 'core']); |
|
206 | + } catch (\OCP\Files\ForbiddenException $e) { |
|
207 | + \OC::$server->getLogger()->debug('Could not cleanup forbidden chunk "' . $file . '"', ['app' => 'core']); |
|
208 | + } catch (\OCP\Files\LockNotAcquiredException $e) { |
|
209 | + \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', ['app' => 'core']); |
|
210 | + } |
|
211 | + } |
|
212 | + } |
|
213 | + } |
|
214 | + } |
|
215 | 215 | |
216 | - public static function isAvailable(): bool { |
|
217 | - return true; |
|
218 | - } |
|
216 | + public static function isAvailable(): bool { |
|
217 | + return true; |
|
218 | + } |
|
219 | 219 | } |
@@ -48,10 +48,10 @@ discard block |
||
48 | 48 | public function setUpStorage(string $userId) { |
49 | 49 | Filesystem::initMountPoints($userId); |
50 | 50 | $rootView = new View(); |
51 | - if (!$rootView->file_exists('/' . $userId . '/cache')) { |
|
52 | - $rootView->mkdir('/' . $userId . '/cache'); |
|
51 | + if (!$rootView->file_exists('/'.$userId.'/cache')) { |
|
52 | + $rootView->mkdir('/'.$userId.'/cache'); |
|
53 | 53 | } |
54 | - $this->storage = new View('/' . $userId . '/cache'); |
|
54 | + $this->storage = new View('/'.$userId.'/cache'); |
|
55 | 55 | return $this->storage; |
56 | 56 | } |
57 | 57 | |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | |
123 | 123 | // use part file to prevent hasKey() to find the key |
124 | 124 | // while it is being written |
125 | - $keyPart = $key . '.' . $uniqueId . '.part'; |
|
125 | + $keyPart = $key.'.'.$uniqueId.'.part'; |
|
126 | 126 | if ($storage and $storage->file_put_contents($keyPart, $value)) { |
127 | 127 | if ($ttl === 0) { |
128 | 128 | $ttl = 86400; // 60*60*24 |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | if (is_resource($dh)) { |
172 | 172 | while (($file = readdir($dh)) !== false) { |
173 | 173 | if ($file != '.' and $file != '..' and ($prefix === '' || strpos($file, $prefix) === 0)) { |
174 | - $storage->unlink('/' . $file); |
|
174 | + $storage->unlink('/'.$file); |
|
175 | 175 | } |
176 | 176 | } |
177 | 177 | } |
@@ -196,17 +196,17 @@ discard block |
||
196 | 196 | while (($file = readdir($dh)) !== false) { |
197 | 197 | if ($file != '.' and $file != '..') { |
198 | 198 | try { |
199 | - $mtime = $storage->filemtime('/' . $file); |
|
199 | + $mtime = $storage->filemtime('/'.$file); |
|
200 | 200 | if ($mtime < $now) { |
201 | - $storage->unlink('/' . $file); |
|
201 | + $storage->unlink('/'.$file); |
|
202 | 202 | } |
203 | 203 | } catch (\OCP\Lock\LockedException $e) { |
204 | 204 | // ignore locked chunks |
205 | - \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', ['app' => 'core']); |
|
205 | + \OC::$server->getLogger()->debug('Could not cleanup locked chunk "'.$file.'"', ['app' => 'core']); |
|
206 | 206 | } catch (\OCP\Files\ForbiddenException $e) { |
207 | - \OC::$server->getLogger()->debug('Could not cleanup forbidden chunk "' . $file . '"', ['app' => 'core']); |
|
207 | + \OC::$server->getLogger()->debug('Could not cleanup forbidden chunk "'.$file.'"', ['app' => 'core']); |
|
208 | 208 | } catch (\OCP\Files\LockNotAcquiredException $e) { |
209 | - \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', ['app' => 'core']); |
|
209 | + \OC::$server->getLogger()->debug('Could not cleanup locked chunk "'.$file.'"', ['app' => 'core']); |
|
210 | 210 | } |
211 | 211 | } |
212 | 212 | } |
@@ -278,2098 +278,2098 @@ |
||
278 | 278 | * TODO: hookup all manager classes |
279 | 279 | */ |
280 | 280 | class Server extends ServerContainer implements IServerContainer { |
281 | - /** @var string */ |
|
282 | - private $webRoot; |
|
283 | - |
|
284 | - /** |
|
285 | - * @param string $webRoot |
|
286 | - * @param \OC\Config $config |
|
287 | - */ |
|
288 | - public function __construct($webRoot, \OC\Config $config) { |
|
289 | - parent::__construct(); |
|
290 | - $this->webRoot = $webRoot; |
|
291 | - |
|
292 | - // To find out if we are running from CLI or not |
|
293 | - $this->registerParameter('isCLI', \OC::$CLI); |
|
294 | - $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
295 | - |
|
296 | - $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
297 | - return $c; |
|
298 | - }); |
|
299 | - $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) { |
|
300 | - return $c; |
|
301 | - }); |
|
302 | - |
|
303 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
304 | - /** @deprecated 19.0.0 */ |
|
305 | - $this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
306 | - |
|
307 | - $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
308 | - /** @deprecated 19.0.0 */ |
|
309 | - $this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
310 | - |
|
311 | - $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
312 | - /** @deprecated 19.0.0 */ |
|
313 | - $this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
314 | - |
|
315 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
316 | - /** @deprecated 19.0.0 */ |
|
317 | - $this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
318 | - |
|
319 | - $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
320 | - $this->registerAlias(ITemplateManager::class, TemplateManager::class); |
|
321 | - |
|
322 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
323 | - |
|
324 | - $this->registerService(View::class, function (Server $c) { |
|
325 | - return new View(); |
|
326 | - }, false); |
|
327 | - |
|
328 | - $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
329 | - return new PreviewManager( |
|
330 | - $c->get(\OCP\IConfig::class), |
|
331 | - $c->get(IRootFolder::class), |
|
332 | - new \OC\Preview\Storage\Root( |
|
333 | - $c->get(IRootFolder::class), |
|
334 | - $c->get(SystemConfig::class) |
|
335 | - ), |
|
336 | - $c->get(IEventDispatcher::class), |
|
337 | - $c->get(SymfonyAdapter::class), |
|
338 | - $c->get(GeneratorHelper::class), |
|
339 | - $c->get(ISession::class)->get('user_id'), |
|
340 | - $c->get(Coordinator::class), |
|
341 | - $c->get(IServerContainer::class), |
|
342 | - $c->get(IBinaryFinder::class), |
|
343 | - $c->get(IMagickSupport::class) |
|
344 | - ); |
|
345 | - }); |
|
346 | - /** @deprecated 19.0.0 */ |
|
347 | - $this->registerDeprecatedAlias('PreviewManager', IPreview::class); |
|
348 | - |
|
349 | - $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) { |
|
350 | - return new \OC\Preview\Watcher( |
|
351 | - new \OC\Preview\Storage\Root( |
|
352 | - $c->get(IRootFolder::class), |
|
353 | - $c->get(SystemConfig::class) |
|
354 | - ) |
|
355 | - ); |
|
356 | - }); |
|
357 | - |
|
358 | - $this->registerService(IProfiler::class, function (Server $c) { |
|
359 | - return new Profiler($c->get(SystemConfig::class)); |
|
360 | - }); |
|
361 | - |
|
362 | - $this->registerService(\OCP\Encryption\IManager::class, function (Server $c): Encryption\Manager { |
|
363 | - $view = new View(); |
|
364 | - $util = new Encryption\Util( |
|
365 | - $view, |
|
366 | - $c->get(IUserManager::class), |
|
367 | - $c->get(IGroupManager::class), |
|
368 | - $c->get(\OCP\IConfig::class) |
|
369 | - ); |
|
370 | - return new Encryption\Manager( |
|
371 | - $c->get(\OCP\IConfig::class), |
|
372 | - $c->get(LoggerInterface::class), |
|
373 | - $c->getL10N('core'), |
|
374 | - new View(), |
|
375 | - $util, |
|
376 | - new ArrayCache() |
|
377 | - ); |
|
378 | - }); |
|
379 | - /** @deprecated 19.0.0 */ |
|
380 | - $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
381 | - |
|
382 | - /** @deprecated 21.0.0 */ |
|
383 | - $this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class); |
|
384 | - $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
385 | - $util = new Encryption\Util( |
|
386 | - new View(), |
|
387 | - $c->get(IUserManager::class), |
|
388 | - $c->get(IGroupManager::class), |
|
389 | - $c->get(\OCP\IConfig::class) |
|
390 | - ); |
|
391 | - return new Encryption\File( |
|
392 | - $util, |
|
393 | - $c->get(IRootFolder::class), |
|
394 | - $c->get(\OCP\Share\IManager::class) |
|
395 | - ); |
|
396 | - }); |
|
397 | - |
|
398 | - /** @deprecated 21.0.0 */ |
|
399 | - $this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class); |
|
400 | - $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
401 | - $view = new View(); |
|
402 | - $util = new Encryption\Util( |
|
403 | - $view, |
|
404 | - $c->get(IUserManager::class), |
|
405 | - $c->get(IGroupManager::class), |
|
406 | - $c->get(\OCP\IConfig::class) |
|
407 | - ); |
|
408 | - |
|
409 | - return new Encryption\Keys\Storage( |
|
410 | - $view, |
|
411 | - $util, |
|
412 | - $c->get(ICrypto::class), |
|
413 | - $c->get(\OCP\IConfig::class) |
|
414 | - ); |
|
415 | - }); |
|
416 | - /** @deprecated 20.0.0 */ |
|
417 | - $this->registerDeprecatedAlias('TagMapper', TagMapper::class); |
|
418 | - |
|
419 | - $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
420 | - /** @deprecated 19.0.0 */ |
|
421 | - $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class); |
|
422 | - |
|
423 | - $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
424 | - /** @var \OCP\IConfig $config */ |
|
425 | - $config = $c->get(\OCP\IConfig::class); |
|
426 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
427 | - return new $factoryClass($this); |
|
428 | - }); |
|
429 | - $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
430 | - return $c->get('SystemTagManagerFactory')->getManager(); |
|
431 | - }); |
|
432 | - /** @deprecated 19.0.0 */ |
|
433 | - $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
434 | - |
|
435 | - $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
436 | - return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
|
437 | - }); |
|
438 | - $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
439 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
440 | - $view = new View(); |
|
441 | - $root = new Root( |
|
442 | - $manager, |
|
443 | - $view, |
|
444 | - null, |
|
445 | - $c->get(IUserMountCache::class), |
|
446 | - $this->get(LoggerInterface::class), |
|
447 | - $this->get(IUserManager::class), |
|
448 | - $this->get(IEventDispatcher::class), |
|
449 | - ); |
|
450 | - |
|
451 | - $previewConnector = new \OC\Preview\WatcherConnector( |
|
452 | - $root, |
|
453 | - $c->get(SystemConfig::class) |
|
454 | - ); |
|
455 | - $previewConnector->connectWatcher(); |
|
456 | - |
|
457 | - return $root; |
|
458 | - }); |
|
459 | - $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
460 | - return new HookConnector( |
|
461 | - $c->get(IRootFolder::class), |
|
462 | - new View(), |
|
463 | - $c->get(\OC\EventDispatcher\SymfonyAdapter::class), |
|
464 | - $c->get(IEventDispatcher::class) |
|
465 | - ); |
|
466 | - }); |
|
467 | - |
|
468 | - /** @deprecated 19.0.0 */ |
|
469 | - $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class); |
|
470 | - |
|
471 | - $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
472 | - return new LazyRoot(function () use ($c) { |
|
473 | - return $c->get('RootFolder'); |
|
474 | - }); |
|
475 | - }); |
|
476 | - /** @deprecated 19.0.0 */ |
|
477 | - $this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class); |
|
478 | - |
|
479 | - /** @deprecated 19.0.0 */ |
|
480 | - $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class); |
|
481 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
482 | - |
|
483 | - $this->registerService(DisplayNameCache::class, function (ContainerInterface $c) { |
|
484 | - return $c->get(\OC\User\Manager::class)->getDisplayNameCache(); |
|
485 | - }); |
|
486 | - |
|
487 | - $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
488 | - $groupManager = new \OC\Group\Manager( |
|
489 | - $this->get(IUserManager::class), |
|
490 | - $c->get(SymfonyAdapter::class), |
|
491 | - $this->get(LoggerInterface::class), |
|
492 | - $this->get(ICacheFactory::class) |
|
493 | - ); |
|
494 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
495 | - /** @var IEventDispatcher $dispatcher */ |
|
496 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
497 | - $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid)); |
|
498 | - }); |
|
499 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) { |
|
500 | - /** @var IEventDispatcher $dispatcher */ |
|
501 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
502 | - $dispatcher->dispatchTyped(new GroupCreatedEvent($group)); |
|
503 | - }); |
|
504 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
505 | - /** @var IEventDispatcher $dispatcher */ |
|
506 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
507 | - $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group)); |
|
508 | - }); |
|
509 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
510 | - /** @var IEventDispatcher $dispatcher */ |
|
511 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
512 | - $dispatcher->dispatchTyped(new GroupDeletedEvent($group)); |
|
513 | - }); |
|
514 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
515 | - /** @var IEventDispatcher $dispatcher */ |
|
516 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
517 | - $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user)); |
|
518 | - }); |
|
519 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
520 | - /** @var IEventDispatcher $dispatcher */ |
|
521 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
522 | - $dispatcher->dispatchTyped(new UserAddedEvent($group, $user)); |
|
523 | - }); |
|
524 | - $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
525 | - /** @var IEventDispatcher $dispatcher */ |
|
526 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
527 | - $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user)); |
|
528 | - }); |
|
529 | - $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
530 | - /** @var IEventDispatcher $dispatcher */ |
|
531 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
532 | - $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user)); |
|
533 | - }); |
|
534 | - return $groupManager; |
|
535 | - }); |
|
536 | - /** @deprecated 19.0.0 */ |
|
537 | - $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class); |
|
538 | - |
|
539 | - $this->registerService(Store::class, function (ContainerInterface $c) { |
|
540 | - $session = $c->get(ISession::class); |
|
541 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
542 | - $tokenProvider = $c->get(IProvider::class); |
|
543 | - } else { |
|
544 | - $tokenProvider = null; |
|
545 | - } |
|
546 | - $logger = $c->get(LoggerInterface::class); |
|
547 | - return new Store($session, $logger, $tokenProvider); |
|
548 | - }); |
|
549 | - $this->registerAlias(IStore::class, Store::class); |
|
550 | - $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
551 | - |
|
552 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
553 | - $manager = $c->get(IUserManager::class); |
|
554 | - $session = new \OC\Session\Memory(''); |
|
555 | - $timeFactory = new TimeFactory(); |
|
556 | - // Token providers might require a working database. This code |
|
557 | - // might however be called when Nextcloud is not yet setup. |
|
558 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
559 | - $provider = $c->get(IProvider::class); |
|
560 | - } else { |
|
561 | - $provider = null; |
|
562 | - } |
|
563 | - |
|
564 | - $legacyDispatcher = $c->get(SymfonyAdapter::class); |
|
565 | - |
|
566 | - $userSession = new \OC\User\Session( |
|
567 | - $manager, |
|
568 | - $session, |
|
569 | - $timeFactory, |
|
570 | - $provider, |
|
571 | - $c->get(\OCP\IConfig::class), |
|
572 | - $c->get(ISecureRandom::class), |
|
573 | - $c->getLockdownManager(), |
|
574 | - $c->get(LoggerInterface::class), |
|
575 | - $c->get(IEventDispatcher::class) |
|
576 | - ); |
|
577 | - /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
|
578 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
579 | - \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
580 | - }); |
|
581 | - /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
|
582 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
583 | - /** @var \OC\User\User $user */ |
|
584 | - \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
585 | - }); |
|
586 | - /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
|
587 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) { |
|
588 | - /** @var \OC\User\User $user */ |
|
589 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
590 | - $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
591 | - }); |
|
592 | - /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
|
593 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
594 | - /** @var \OC\User\User $user */ |
|
595 | - \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
596 | - }); |
|
597 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
598 | - /** @var \OC\User\User $user */ |
|
599 | - \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
600 | - |
|
601 | - /** @var IEventDispatcher $dispatcher */ |
|
602 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
603 | - $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
604 | - }); |
|
605 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
606 | - /** @var \OC\User\User $user */ |
|
607 | - \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
608 | - |
|
609 | - /** @var IEventDispatcher $dispatcher */ |
|
610 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
611 | - $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
612 | - }); |
|
613 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
614 | - \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
615 | - |
|
616 | - /** @var IEventDispatcher $dispatcher */ |
|
617 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
618 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
619 | - }); |
|
620 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
621 | - /** @var \OC\User\User $user */ |
|
622 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
623 | - |
|
624 | - /** @var IEventDispatcher $dispatcher */ |
|
625 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
626 | - $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin)); |
|
627 | - }); |
|
628 | - $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
629 | - /** @var IEventDispatcher $dispatcher */ |
|
630 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
631 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
632 | - }); |
|
633 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
634 | - /** @var \OC\User\User $user */ |
|
635 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
636 | - |
|
637 | - /** @var IEventDispatcher $dispatcher */ |
|
638 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
639 | - $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
640 | - }); |
|
641 | - $userSession->listen('\OC\User', 'logout', function ($user) { |
|
642 | - \OC_Hook::emit('OC_User', 'logout', []); |
|
643 | - |
|
644 | - /** @var IEventDispatcher $dispatcher */ |
|
645 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
646 | - $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
647 | - }); |
|
648 | - $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
649 | - /** @var IEventDispatcher $dispatcher */ |
|
650 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
651 | - $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
652 | - }); |
|
653 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
654 | - /** @var \OC\User\User $user */ |
|
655 | - \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
656 | - |
|
657 | - /** @var IEventDispatcher $dispatcher */ |
|
658 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
659 | - $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue)); |
|
660 | - }); |
|
661 | - return $userSession; |
|
662 | - }); |
|
663 | - $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
664 | - /** @deprecated 19.0.0 */ |
|
665 | - $this->registerDeprecatedAlias('UserSession', \OC\User\Session::class); |
|
666 | - |
|
667 | - $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
668 | - |
|
669 | - $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
670 | - /** @deprecated 19.0.0 */ |
|
671 | - $this->registerDeprecatedAlias('NavigationManager', INavigationManager::class); |
|
672 | - |
|
673 | - /** @deprecated 19.0.0 */ |
|
674 | - $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class); |
|
675 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
676 | - |
|
677 | - $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
678 | - return new \OC\SystemConfig($config); |
|
679 | - }); |
|
680 | - /** @deprecated 19.0.0 */ |
|
681 | - $this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class); |
|
682 | - |
|
683 | - /** @deprecated 19.0.0 */ |
|
684 | - $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class); |
|
685 | - $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
686 | - |
|
687 | - $this->registerService(IFactory::class, function (Server $c) { |
|
688 | - return new \OC\L10N\Factory( |
|
689 | - $c->get(\OCP\IConfig::class), |
|
690 | - $c->getRequest(), |
|
691 | - $c->get(IUserSession::class), |
|
692 | - $c->get(ICacheFactory::class), |
|
693 | - \OC::$SERVERROOT |
|
694 | - ); |
|
695 | - }); |
|
696 | - /** @deprecated 19.0.0 */ |
|
697 | - $this->registerDeprecatedAlias('L10NFactory', IFactory::class); |
|
698 | - |
|
699 | - $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
|
700 | - /** @deprecated 19.0.0 */ |
|
701 | - $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class); |
|
702 | - |
|
703 | - /** @deprecated 19.0.0 */ |
|
704 | - $this->registerDeprecatedAlias('AppFetcher', AppFetcher::class); |
|
705 | - /** @deprecated 19.0.0 */ |
|
706 | - $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class); |
|
707 | - |
|
708 | - $this->registerService(ICache::class, function ($c) { |
|
709 | - return new Cache\File(); |
|
710 | - }); |
|
711 | - |
|
712 | - /** @deprecated 19.0.0 */ |
|
713 | - $this->registerDeprecatedAlias('UserCache', ICache::class); |
|
714 | - |
|
715 | - $this->registerService(Factory::class, function (Server $c) { |
|
716 | - $profiler = $c->get(IProfiler::class); |
|
717 | - $arrayCacheFactory = new \OC\Memcache\Factory('', $c->get(LoggerInterface::class), |
|
718 | - $profiler, |
|
719 | - ArrayCache::class, |
|
720 | - ArrayCache::class, |
|
721 | - ArrayCache::class |
|
722 | - ); |
|
723 | - /** @var \OCP\IConfig $config */ |
|
724 | - $config = $c->get(\OCP\IConfig::class); |
|
725 | - |
|
726 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
727 | - if (!$config->getSystemValueBool('log_query')) { |
|
728 | - $v = \OC_App::getAppVersions(); |
|
729 | - } else { |
|
730 | - // If the log_query is enabled, we can not get the app versions |
|
731 | - // as that does a query, which will be logged and the logging |
|
732 | - // depends on redis and here we are back again in the same function. |
|
733 | - $v = [ |
|
734 | - 'log_query' => 'enabled', |
|
735 | - ]; |
|
736 | - } |
|
737 | - $v['core'] = implode(',', \OC_Util::getVersion()); |
|
738 | - $version = implode(',', $v); |
|
739 | - $instanceId = \OC_Util::getInstanceId(); |
|
740 | - $path = \OC::$SERVERROOT; |
|
741 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
742 | - return new \OC\Memcache\Factory($prefix, |
|
743 | - $c->get(LoggerInterface::class), |
|
744 | - $profiler, |
|
745 | - $config->getSystemValue('memcache.local', null), |
|
746 | - $config->getSystemValue('memcache.distributed', null), |
|
747 | - $config->getSystemValue('memcache.locking', null), |
|
748 | - $config->getSystemValueString('redis_log_file') |
|
749 | - ); |
|
750 | - } |
|
751 | - return $arrayCacheFactory; |
|
752 | - }); |
|
753 | - /** @deprecated 19.0.0 */ |
|
754 | - $this->registerDeprecatedAlias('MemCacheFactory', Factory::class); |
|
755 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
756 | - |
|
757 | - $this->registerService('RedisFactory', function (Server $c) { |
|
758 | - $systemConfig = $c->get(SystemConfig::class); |
|
759 | - return new RedisFactory($systemConfig, $c->getEventLogger()); |
|
760 | - }); |
|
761 | - |
|
762 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
763 | - $l10n = $this->get(IFactory::class)->get('lib'); |
|
764 | - return new \OC\Activity\Manager( |
|
765 | - $c->getRequest(), |
|
766 | - $c->get(IUserSession::class), |
|
767 | - $c->get(\OCP\IConfig::class), |
|
768 | - $c->get(IValidator::class), |
|
769 | - $l10n |
|
770 | - ); |
|
771 | - }); |
|
772 | - /** @deprecated 19.0.0 */ |
|
773 | - $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
774 | - |
|
775 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
776 | - return new \OC\Activity\EventMerger( |
|
777 | - $c->getL10N('lib') |
|
778 | - ); |
|
779 | - }); |
|
780 | - $this->registerAlias(IValidator::class, Validator::class); |
|
781 | - |
|
782 | - $this->registerService(AvatarManager::class, function (Server $c) { |
|
783 | - return new AvatarManager( |
|
784 | - $c->get(IUserSession::class), |
|
785 | - $c->get(\OC\User\Manager::class), |
|
786 | - $c->getAppDataDir('avatar'), |
|
787 | - $c->getL10N('lib'), |
|
788 | - $c->get(LoggerInterface::class), |
|
789 | - $c->get(\OCP\IConfig::class), |
|
790 | - $c->get(IAccountManager::class), |
|
791 | - $c->get(KnownUserService::class) |
|
792 | - ); |
|
793 | - }); |
|
794 | - |
|
795 | - $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
796 | - /** @deprecated 19.0.0 */ |
|
797 | - $this->registerDeprecatedAlias('AvatarManager', AvatarManager::class); |
|
798 | - |
|
799 | - $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
800 | - $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
801 | - $this->registerAlias(\OCP\Support\Subscription\IAssertion::class, \OC\Support\Subscription\Assertion::class); |
|
802 | - |
|
803 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
804 | - $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
805 | - $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
|
806 | - $logger = $factory->get($logType); |
|
807 | - $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class); |
|
808 | - |
|
809 | - return new Log($logger, $this->get(SystemConfig::class), null, $registry); |
|
810 | - }); |
|
811 | - $this->registerAlias(ILogger::class, \OC\Log::class); |
|
812 | - /** @deprecated 19.0.0 */ |
|
813 | - $this->registerDeprecatedAlias('Logger', \OC\Log::class); |
|
814 | - // PSR-3 logger |
|
815 | - $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
816 | - |
|
817 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
818 | - return new LogFactory($c, $this->get(SystemConfig::class)); |
|
819 | - }); |
|
820 | - |
|
821 | - $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
822 | - /** @deprecated 19.0.0 */ |
|
823 | - $this->registerDeprecatedAlias('JobList', IJobList::class); |
|
824 | - |
|
825 | - $this->registerService(Router::class, function (Server $c) { |
|
826 | - $cacheFactory = $c->get(ICacheFactory::class); |
|
827 | - if ($cacheFactory->isLocalCacheAvailable()) { |
|
828 | - $router = $c->resolve(CachingRouter::class); |
|
829 | - } else { |
|
830 | - $router = $c->resolve(Router::class); |
|
831 | - } |
|
832 | - return $router; |
|
833 | - }); |
|
834 | - $this->registerAlias(IRouter::class, Router::class); |
|
835 | - /** @deprecated 19.0.0 */ |
|
836 | - $this->registerDeprecatedAlias('Router', IRouter::class); |
|
837 | - |
|
838 | - $this->registerAlias(ISearch::class, Search::class); |
|
839 | - /** @deprecated 19.0.0 */ |
|
840 | - $this->registerDeprecatedAlias('Search', ISearch::class); |
|
841 | - |
|
842 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
843 | - $cacheFactory = $c->get(ICacheFactory::class); |
|
844 | - if ($cacheFactory->isAvailable()) { |
|
845 | - $backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend( |
|
846 | - $this->get(ICacheFactory::class), |
|
847 | - new \OC\AppFramework\Utility\TimeFactory() |
|
848 | - ); |
|
849 | - } else { |
|
850 | - $backend = new \OC\Security\RateLimiting\Backend\DatabaseBackend( |
|
851 | - $c->get(IDBConnection::class), |
|
852 | - new \OC\AppFramework\Utility\TimeFactory() |
|
853 | - ); |
|
854 | - } |
|
855 | - |
|
856 | - return $backend; |
|
857 | - }); |
|
858 | - |
|
859 | - $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
860 | - /** @deprecated 19.0.0 */ |
|
861 | - $this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
862 | - $this->registerAlias(\OCP\Security\IRemoteHostValidator::class, \OC\Security\RemoteHostValidator::class); |
|
863 | - $this->registerAlias(IVerificationToken::class, VerificationToken::class); |
|
864 | - |
|
865 | - $this->registerAlias(ICrypto::class, Crypto::class); |
|
866 | - /** @deprecated 19.0.0 */ |
|
867 | - $this->registerDeprecatedAlias('Crypto', ICrypto::class); |
|
868 | - |
|
869 | - $this->registerAlias(IHasher::class, Hasher::class); |
|
870 | - /** @deprecated 19.0.0 */ |
|
871 | - $this->registerDeprecatedAlias('Hasher', IHasher::class); |
|
872 | - |
|
873 | - $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
874 | - /** @deprecated 19.0.0 */ |
|
875 | - $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class); |
|
876 | - |
|
877 | - $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
|
878 | - $this->registerService(Connection::class, function (Server $c) { |
|
879 | - $systemConfig = $c->get(SystemConfig::class); |
|
880 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
881 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
882 | - if (!$factory->isValidType($type)) { |
|
883 | - throw new \OC\DatabaseException('Invalid database type'); |
|
884 | - } |
|
885 | - $connectionParams = $factory->createConnectionParams(); |
|
886 | - $connection = $factory->getConnection($type, $connectionParams); |
|
887 | - return $connection; |
|
888 | - }); |
|
889 | - /** @deprecated 19.0.0 */ |
|
890 | - $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class); |
|
891 | - |
|
892 | - $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
|
893 | - $this->registerAlias(IClientService::class, ClientService::class); |
|
894 | - $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) { |
|
895 | - return new NegativeDnsCache( |
|
896 | - $c->get(ICacheFactory::class), |
|
897 | - ); |
|
898 | - }); |
|
899 | - $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
900 | - $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
901 | - return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class)); |
|
902 | - }); |
|
903 | - /** @deprecated 19.0.0 */ |
|
904 | - $this->registerDeprecatedAlias('EventLogger', IEventLogger::class); |
|
905 | - |
|
906 | - $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
907 | - $queryLogger = new QueryLogger(); |
|
908 | - if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
909 | - // In debug mode, module is being activated by default |
|
910 | - $queryLogger->activate(); |
|
911 | - } |
|
912 | - return $queryLogger; |
|
913 | - }); |
|
914 | - /** @deprecated 19.0.0 */ |
|
915 | - $this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class); |
|
916 | - |
|
917 | - /** @deprecated 19.0.0 */ |
|
918 | - $this->registerDeprecatedAlias('TempManager', TempManager::class); |
|
919 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
920 | - |
|
921 | - $this->registerService(AppManager::class, function (ContainerInterface $c) { |
|
922 | - // TODO: use auto-wiring |
|
923 | - return new \OC\App\AppManager( |
|
924 | - $c->get(IUserSession::class), |
|
925 | - $c->get(\OCP\IConfig::class), |
|
926 | - $c->get(\OC\AppConfig::class), |
|
927 | - $c->get(IGroupManager::class), |
|
928 | - $c->get(ICacheFactory::class), |
|
929 | - $c->get(SymfonyAdapter::class), |
|
930 | - $c->get(LoggerInterface::class) |
|
931 | - ); |
|
932 | - }); |
|
933 | - /** @deprecated 19.0.0 */ |
|
934 | - $this->registerDeprecatedAlias('AppManager', AppManager::class); |
|
935 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
936 | - |
|
937 | - $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
938 | - /** @deprecated 19.0.0 */ |
|
939 | - $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class); |
|
940 | - |
|
941 | - $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
942 | - $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
|
943 | - |
|
944 | - return new DateTimeFormatter( |
|
945 | - $c->get(IDateTimeZone::class)->getTimeZone(), |
|
946 | - $c->getL10N('lib', $language) |
|
947 | - ); |
|
948 | - }); |
|
949 | - /** @deprecated 19.0.0 */ |
|
950 | - $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class); |
|
951 | - |
|
952 | - $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
953 | - $mountCache = $c->get(UserMountCache::class); |
|
954 | - $listener = new UserMountCacheListener($mountCache); |
|
955 | - $listener->listen($c->get(IUserManager::class)); |
|
956 | - return $mountCache; |
|
957 | - }); |
|
958 | - /** @deprecated 19.0.0 */ |
|
959 | - $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class); |
|
960 | - |
|
961 | - $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
962 | - $loader = $c->get(IStorageFactory::class); |
|
963 | - $mountCache = $c->get(IUserMountCache::class); |
|
964 | - $eventLogger = $c->get(IEventLogger::class); |
|
965 | - $manager = new MountProviderCollection($loader, $mountCache, $eventLogger); |
|
966 | - |
|
967 | - // builtin providers |
|
968 | - |
|
969 | - $config = $c->get(\OCP\IConfig::class); |
|
970 | - $logger = $c->get(LoggerInterface::class); |
|
971 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
972 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
973 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
974 | - $manager->registerRootProvider(new RootMountProvider($config, $c->get(LoggerInterface::class))); |
|
975 | - $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config)); |
|
976 | - |
|
977 | - return $manager; |
|
978 | - }); |
|
979 | - /** @deprecated 19.0.0 */ |
|
980 | - $this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class); |
|
981 | - |
|
982 | - /** @deprecated 20.0.0 */ |
|
983 | - $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class); |
|
984 | - $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
985 | - $busClass = $c->get(\OCP\IConfig::class)->getSystemValue('commandbus'); |
|
986 | - if ($busClass) { |
|
987 | - [$app, $class] = explode('::', $busClass, 2); |
|
988 | - if ($c->get(IAppManager::class)->isInstalled($app)) { |
|
989 | - \OC_App::loadApp($app); |
|
990 | - return $c->get($class); |
|
991 | - } else { |
|
992 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
993 | - } |
|
994 | - } else { |
|
995 | - $jobList = $c->get(IJobList::class); |
|
996 | - return new CronBus($jobList); |
|
997 | - } |
|
998 | - }); |
|
999 | - $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class); |
|
1000 | - /** @deprecated 20.0.0 */ |
|
1001 | - $this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class); |
|
1002 | - $this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class); |
|
1003 | - /** @deprecated 19.0.0 */ |
|
1004 | - $this->registerDeprecatedAlias('Throttler', Throttler::class); |
|
1005 | - $this->registerAlias(IThrottler::class, Throttler::class); |
|
1006 | - $this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) { |
|
1007 | - // IConfig and IAppManager requires a working database. This code |
|
1008 | - // might however be called when ownCloud is not yet setup. |
|
1009 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
1010 | - $config = $c->get(\OCP\IConfig::class); |
|
1011 | - $appManager = $c->get(IAppManager::class); |
|
1012 | - } else { |
|
1013 | - $config = null; |
|
1014 | - $appManager = null; |
|
1015 | - } |
|
1016 | - |
|
1017 | - return new Checker( |
|
1018 | - new EnvironmentHelper(), |
|
1019 | - new FileAccessHelper(), |
|
1020 | - new AppLocator(), |
|
1021 | - $config, |
|
1022 | - $c->get(ICacheFactory::class), |
|
1023 | - $appManager, |
|
1024 | - $c->get(IMimeTypeDetector::class) |
|
1025 | - ); |
|
1026 | - }); |
|
1027 | - $this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) { |
|
1028 | - if (isset($this['urlParams'])) { |
|
1029 | - $urlParams = $this['urlParams']; |
|
1030 | - } else { |
|
1031 | - $urlParams = []; |
|
1032 | - } |
|
1033 | - |
|
1034 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
1035 | - && in_array('fakeinput', stream_get_wrappers()) |
|
1036 | - ) { |
|
1037 | - $stream = 'fakeinput://data'; |
|
1038 | - } else { |
|
1039 | - $stream = 'php://input'; |
|
1040 | - } |
|
1041 | - |
|
1042 | - return new Request( |
|
1043 | - [ |
|
1044 | - 'get' => $_GET, |
|
1045 | - 'post' => $_POST, |
|
1046 | - 'files' => $_FILES, |
|
1047 | - 'server' => $_SERVER, |
|
1048 | - 'env' => $_ENV, |
|
1049 | - 'cookies' => $_COOKIE, |
|
1050 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1051 | - ? $_SERVER['REQUEST_METHOD'] |
|
1052 | - : '', |
|
1053 | - 'urlParams' => $urlParams, |
|
1054 | - ], |
|
1055 | - $this->get(IRequestId::class), |
|
1056 | - $this->get(\OCP\IConfig::class), |
|
1057 | - $this->get(CsrfTokenManager::class), |
|
1058 | - $stream |
|
1059 | - ); |
|
1060 | - }); |
|
1061 | - /** @deprecated 19.0.0 */ |
|
1062 | - $this->registerDeprecatedAlias('Request', \OCP\IRequest::class); |
|
1063 | - |
|
1064 | - $this->registerService(IRequestId::class, function (ContainerInterface $c): IRequestId { |
|
1065 | - return new RequestId( |
|
1066 | - $_SERVER['UNIQUE_ID'] ?? '', |
|
1067 | - $this->get(ISecureRandom::class) |
|
1068 | - ); |
|
1069 | - }); |
|
1070 | - |
|
1071 | - $this->registerService(IMailer::class, function (Server $c) { |
|
1072 | - return new Mailer( |
|
1073 | - $c->get(\OCP\IConfig::class), |
|
1074 | - $c->get(LoggerInterface::class), |
|
1075 | - $c->get(Defaults::class), |
|
1076 | - $c->get(IURLGenerator::class), |
|
1077 | - $c->getL10N('lib'), |
|
1078 | - $c->get(IEventDispatcher::class), |
|
1079 | - $c->get(IFactory::class) |
|
1080 | - ); |
|
1081 | - }); |
|
1082 | - /** @deprecated 19.0.0 */ |
|
1083 | - $this->registerDeprecatedAlias('Mailer', IMailer::class); |
|
1084 | - |
|
1085 | - /** @deprecated 21.0.0 */ |
|
1086 | - $this->registerDeprecatedAlias('LDAPProvider', ILDAPProvider::class); |
|
1087 | - |
|
1088 | - $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) { |
|
1089 | - $config = $c->get(\OCP\IConfig::class); |
|
1090 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
1091 | - if (is_null($factoryClass) || !class_exists($factoryClass)) { |
|
1092 | - return new NullLDAPProviderFactory($this); |
|
1093 | - } |
|
1094 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
1095 | - return new $factoryClass($this); |
|
1096 | - }); |
|
1097 | - $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) { |
|
1098 | - $factory = $c->get(ILDAPProviderFactory::class); |
|
1099 | - return $factory->getLDAPProvider(); |
|
1100 | - }); |
|
1101 | - $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
1102 | - $ini = $c->get(IniGetWrapper::class); |
|
1103 | - $config = $c->get(\OCP\IConfig::class); |
|
1104 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
1105 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
1106 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
1107 | - $memcacheFactory = $c->get(ICacheFactory::class); |
|
1108 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
1109 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
1110 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
1111 | - } |
|
1112 | - return new DBLockingProvider( |
|
1113 | - $c->get(IDBConnection::class), |
|
1114 | - new TimeFactory(), |
|
1115 | - $ttl, |
|
1116 | - !\OC::$CLI |
|
1117 | - ); |
|
1118 | - } |
|
1119 | - return new NoopLockingProvider(); |
|
1120 | - }); |
|
1121 | - /** @deprecated 19.0.0 */ |
|
1122 | - $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class); |
|
1123 | - |
|
1124 | - $this->registerService(ILockManager::class, function (Server $c): LockManager { |
|
1125 | - return new LockManager(); |
|
1126 | - }); |
|
1127 | - |
|
1128 | - $this->registerAlias(ILockdownManager::class, 'LockdownManager'); |
|
1129 | - $this->registerService(SetupManager::class, function ($c) { |
|
1130 | - // create the setupmanager through the mount manager to resolve the cyclic dependency |
|
1131 | - return $c->get(\OC\Files\Mount\Manager::class)->getSetupManager(); |
|
1132 | - }); |
|
1133 | - $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
1134 | - /** @deprecated 19.0.0 */ |
|
1135 | - $this->registerDeprecatedAlias('MountManager', IMountManager::class); |
|
1136 | - |
|
1137 | - $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
1138 | - return new \OC\Files\Type\Detection( |
|
1139 | - $c->get(IURLGenerator::class), |
|
1140 | - $c->get(LoggerInterface::class), |
|
1141 | - \OC::$configDir, |
|
1142 | - \OC::$SERVERROOT . '/resources/config/' |
|
1143 | - ); |
|
1144 | - }); |
|
1145 | - /** @deprecated 19.0.0 */ |
|
1146 | - $this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class); |
|
1147 | - |
|
1148 | - $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
1149 | - /** @deprecated 19.0.0 */ |
|
1150 | - $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class); |
|
1151 | - $this->registerService(BundleFetcher::class, function () { |
|
1152 | - return new BundleFetcher($this->getL10N('lib')); |
|
1153 | - }); |
|
1154 | - $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
1155 | - /** @deprecated 19.0.0 */ |
|
1156 | - $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
1157 | - |
|
1158 | - $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
1159 | - $manager = new CapabilitiesManager($c->get(LoggerInterface::class)); |
|
1160 | - $manager->registerCapability(function () use ($c) { |
|
1161 | - return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
|
1162 | - }); |
|
1163 | - $manager->registerCapability(function () use ($c) { |
|
1164 | - return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
|
1165 | - }); |
|
1166 | - $manager->registerCapability(function () use ($c) { |
|
1167 | - return $c->get(MetadataCapabilities::class); |
|
1168 | - }); |
|
1169 | - return $manager; |
|
1170 | - }); |
|
1171 | - /** @deprecated 19.0.0 */ |
|
1172 | - $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class); |
|
1173 | - |
|
1174 | - $this->registerService(ICommentsManager::class, function (Server $c) { |
|
1175 | - $config = $c->get(\OCP\IConfig::class); |
|
1176 | - $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
1177 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
1178 | - $factory = new $factoryClass($this); |
|
1179 | - $manager = $factory->getManager(); |
|
1180 | - |
|
1181 | - $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
1182 | - $manager = $c->get(IUserManager::class); |
|
1183 | - $userDisplayName = $manager->getDisplayName($id); |
|
1184 | - if ($userDisplayName === null) { |
|
1185 | - $l = $c->get(IFactory::class)->get('core'); |
|
1186 | - return $l->t('Unknown user'); |
|
1187 | - } |
|
1188 | - return $userDisplayName; |
|
1189 | - }); |
|
1190 | - |
|
1191 | - return $manager; |
|
1192 | - }); |
|
1193 | - /** @deprecated 19.0.0 */ |
|
1194 | - $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class); |
|
1195 | - |
|
1196 | - $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
1197 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
1198 | - /* |
|
281 | + /** @var string */ |
|
282 | + private $webRoot; |
|
283 | + |
|
284 | + /** |
|
285 | + * @param string $webRoot |
|
286 | + * @param \OC\Config $config |
|
287 | + */ |
|
288 | + public function __construct($webRoot, \OC\Config $config) { |
|
289 | + parent::__construct(); |
|
290 | + $this->webRoot = $webRoot; |
|
291 | + |
|
292 | + // To find out if we are running from CLI or not |
|
293 | + $this->registerParameter('isCLI', \OC::$CLI); |
|
294 | + $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
295 | + |
|
296 | + $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
297 | + return $c; |
|
298 | + }); |
|
299 | + $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) { |
|
300 | + return $c; |
|
301 | + }); |
|
302 | + |
|
303 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
304 | + /** @deprecated 19.0.0 */ |
|
305 | + $this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
306 | + |
|
307 | + $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
308 | + /** @deprecated 19.0.0 */ |
|
309 | + $this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
310 | + |
|
311 | + $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
312 | + /** @deprecated 19.0.0 */ |
|
313 | + $this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
314 | + |
|
315 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
316 | + /** @deprecated 19.0.0 */ |
|
317 | + $this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
318 | + |
|
319 | + $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
320 | + $this->registerAlias(ITemplateManager::class, TemplateManager::class); |
|
321 | + |
|
322 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
323 | + |
|
324 | + $this->registerService(View::class, function (Server $c) { |
|
325 | + return new View(); |
|
326 | + }, false); |
|
327 | + |
|
328 | + $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
329 | + return new PreviewManager( |
|
330 | + $c->get(\OCP\IConfig::class), |
|
331 | + $c->get(IRootFolder::class), |
|
332 | + new \OC\Preview\Storage\Root( |
|
333 | + $c->get(IRootFolder::class), |
|
334 | + $c->get(SystemConfig::class) |
|
335 | + ), |
|
336 | + $c->get(IEventDispatcher::class), |
|
337 | + $c->get(SymfonyAdapter::class), |
|
338 | + $c->get(GeneratorHelper::class), |
|
339 | + $c->get(ISession::class)->get('user_id'), |
|
340 | + $c->get(Coordinator::class), |
|
341 | + $c->get(IServerContainer::class), |
|
342 | + $c->get(IBinaryFinder::class), |
|
343 | + $c->get(IMagickSupport::class) |
|
344 | + ); |
|
345 | + }); |
|
346 | + /** @deprecated 19.0.0 */ |
|
347 | + $this->registerDeprecatedAlias('PreviewManager', IPreview::class); |
|
348 | + |
|
349 | + $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) { |
|
350 | + return new \OC\Preview\Watcher( |
|
351 | + new \OC\Preview\Storage\Root( |
|
352 | + $c->get(IRootFolder::class), |
|
353 | + $c->get(SystemConfig::class) |
|
354 | + ) |
|
355 | + ); |
|
356 | + }); |
|
357 | + |
|
358 | + $this->registerService(IProfiler::class, function (Server $c) { |
|
359 | + return new Profiler($c->get(SystemConfig::class)); |
|
360 | + }); |
|
361 | + |
|
362 | + $this->registerService(\OCP\Encryption\IManager::class, function (Server $c): Encryption\Manager { |
|
363 | + $view = new View(); |
|
364 | + $util = new Encryption\Util( |
|
365 | + $view, |
|
366 | + $c->get(IUserManager::class), |
|
367 | + $c->get(IGroupManager::class), |
|
368 | + $c->get(\OCP\IConfig::class) |
|
369 | + ); |
|
370 | + return new Encryption\Manager( |
|
371 | + $c->get(\OCP\IConfig::class), |
|
372 | + $c->get(LoggerInterface::class), |
|
373 | + $c->getL10N('core'), |
|
374 | + new View(), |
|
375 | + $util, |
|
376 | + new ArrayCache() |
|
377 | + ); |
|
378 | + }); |
|
379 | + /** @deprecated 19.0.0 */ |
|
380 | + $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
381 | + |
|
382 | + /** @deprecated 21.0.0 */ |
|
383 | + $this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class); |
|
384 | + $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
385 | + $util = new Encryption\Util( |
|
386 | + new View(), |
|
387 | + $c->get(IUserManager::class), |
|
388 | + $c->get(IGroupManager::class), |
|
389 | + $c->get(\OCP\IConfig::class) |
|
390 | + ); |
|
391 | + return new Encryption\File( |
|
392 | + $util, |
|
393 | + $c->get(IRootFolder::class), |
|
394 | + $c->get(\OCP\Share\IManager::class) |
|
395 | + ); |
|
396 | + }); |
|
397 | + |
|
398 | + /** @deprecated 21.0.0 */ |
|
399 | + $this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class); |
|
400 | + $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
401 | + $view = new View(); |
|
402 | + $util = new Encryption\Util( |
|
403 | + $view, |
|
404 | + $c->get(IUserManager::class), |
|
405 | + $c->get(IGroupManager::class), |
|
406 | + $c->get(\OCP\IConfig::class) |
|
407 | + ); |
|
408 | + |
|
409 | + return new Encryption\Keys\Storage( |
|
410 | + $view, |
|
411 | + $util, |
|
412 | + $c->get(ICrypto::class), |
|
413 | + $c->get(\OCP\IConfig::class) |
|
414 | + ); |
|
415 | + }); |
|
416 | + /** @deprecated 20.0.0 */ |
|
417 | + $this->registerDeprecatedAlias('TagMapper', TagMapper::class); |
|
418 | + |
|
419 | + $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
420 | + /** @deprecated 19.0.0 */ |
|
421 | + $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class); |
|
422 | + |
|
423 | + $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
424 | + /** @var \OCP\IConfig $config */ |
|
425 | + $config = $c->get(\OCP\IConfig::class); |
|
426 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
427 | + return new $factoryClass($this); |
|
428 | + }); |
|
429 | + $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
430 | + return $c->get('SystemTagManagerFactory')->getManager(); |
|
431 | + }); |
|
432 | + /** @deprecated 19.0.0 */ |
|
433 | + $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
434 | + |
|
435 | + $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
436 | + return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
|
437 | + }); |
|
438 | + $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
439 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
440 | + $view = new View(); |
|
441 | + $root = new Root( |
|
442 | + $manager, |
|
443 | + $view, |
|
444 | + null, |
|
445 | + $c->get(IUserMountCache::class), |
|
446 | + $this->get(LoggerInterface::class), |
|
447 | + $this->get(IUserManager::class), |
|
448 | + $this->get(IEventDispatcher::class), |
|
449 | + ); |
|
450 | + |
|
451 | + $previewConnector = new \OC\Preview\WatcherConnector( |
|
452 | + $root, |
|
453 | + $c->get(SystemConfig::class) |
|
454 | + ); |
|
455 | + $previewConnector->connectWatcher(); |
|
456 | + |
|
457 | + return $root; |
|
458 | + }); |
|
459 | + $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
460 | + return new HookConnector( |
|
461 | + $c->get(IRootFolder::class), |
|
462 | + new View(), |
|
463 | + $c->get(\OC\EventDispatcher\SymfonyAdapter::class), |
|
464 | + $c->get(IEventDispatcher::class) |
|
465 | + ); |
|
466 | + }); |
|
467 | + |
|
468 | + /** @deprecated 19.0.0 */ |
|
469 | + $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class); |
|
470 | + |
|
471 | + $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
472 | + return new LazyRoot(function () use ($c) { |
|
473 | + return $c->get('RootFolder'); |
|
474 | + }); |
|
475 | + }); |
|
476 | + /** @deprecated 19.0.0 */ |
|
477 | + $this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class); |
|
478 | + |
|
479 | + /** @deprecated 19.0.0 */ |
|
480 | + $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class); |
|
481 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
482 | + |
|
483 | + $this->registerService(DisplayNameCache::class, function (ContainerInterface $c) { |
|
484 | + return $c->get(\OC\User\Manager::class)->getDisplayNameCache(); |
|
485 | + }); |
|
486 | + |
|
487 | + $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
488 | + $groupManager = new \OC\Group\Manager( |
|
489 | + $this->get(IUserManager::class), |
|
490 | + $c->get(SymfonyAdapter::class), |
|
491 | + $this->get(LoggerInterface::class), |
|
492 | + $this->get(ICacheFactory::class) |
|
493 | + ); |
|
494 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
495 | + /** @var IEventDispatcher $dispatcher */ |
|
496 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
497 | + $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid)); |
|
498 | + }); |
|
499 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) { |
|
500 | + /** @var IEventDispatcher $dispatcher */ |
|
501 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
502 | + $dispatcher->dispatchTyped(new GroupCreatedEvent($group)); |
|
503 | + }); |
|
504 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
505 | + /** @var IEventDispatcher $dispatcher */ |
|
506 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
507 | + $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group)); |
|
508 | + }); |
|
509 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
510 | + /** @var IEventDispatcher $dispatcher */ |
|
511 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
512 | + $dispatcher->dispatchTyped(new GroupDeletedEvent($group)); |
|
513 | + }); |
|
514 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
515 | + /** @var IEventDispatcher $dispatcher */ |
|
516 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
517 | + $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user)); |
|
518 | + }); |
|
519 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
520 | + /** @var IEventDispatcher $dispatcher */ |
|
521 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
522 | + $dispatcher->dispatchTyped(new UserAddedEvent($group, $user)); |
|
523 | + }); |
|
524 | + $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
525 | + /** @var IEventDispatcher $dispatcher */ |
|
526 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
527 | + $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user)); |
|
528 | + }); |
|
529 | + $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
530 | + /** @var IEventDispatcher $dispatcher */ |
|
531 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
532 | + $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user)); |
|
533 | + }); |
|
534 | + return $groupManager; |
|
535 | + }); |
|
536 | + /** @deprecated 19.0.0 */ |
|
537 | + $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class); |
|
538 | + |
|
539 | + $this->registerService(Store::class, function (ContainerInterface $c) { |
|
540 | + $session = $c->get(ISession::class); |
|
541 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
542 | + $tokenProvider = $c->get(IProvider::class); |
|
543 | + } else { |
|
544 | + $tokenProvider = null; |
|
545 | + } |
|
546 | + $logger = $c->get(LoggerInterface::class); |
|
547 | + return new Store($session, $logger, $tokenProvider); |
|
548 | + }); |
|
549 | + $this->registerAlias(IStore::class, Store::class); |
|
550 | + $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
551 | + |
|
552 | + $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
553 | + $manager = $c->get(IUserManager::class); |
|
554 | + $session = new \OC\Session\Memory(''); |
|
555 | + $timeFactory = new TimeFactory(); |
|
556 | + // Token providers might require a working database. This code |
|
557 | + // might however be called when Nextcloud is not yet setup. |
|
558 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
559 | + $provider = $c->get(IProvider::class); |
|
560 | + } else { |
|
561 | + $provider = null; |
|
562 | + } |
|
563 | + |
|
564 | + $legacyDispatcher = $c->get(SymfonyAdapter::class); |
|
565 | + |
|
566 | + $userSession = new \OC\User\Session( |
|
567 | + $manager, |
|
568 | + $session, |
|
569 | + $timeFactory, |
|
570 | + $provider, |
|
571 | + $c->get(\OCP\IConfig::class), |
|
572 | + $c->get(ISecureRandom::class), |
|
573 | + $c->getLockdownManager(), |
|
574 | + $c->get(LoggerInterface::class), |
|
575 | + $c->get(IEventDispatcher::class) |
|
576 | + ); |
|
577 | + /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
|
578 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
579 | + \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
580 | + }); |
|
581 | + /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
|
582 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
583 | + /** @var \OC\User\User $user */ |
|
584 | + \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
585 | + }); |
|
586 | + /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
|
587 | + $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) { |
|
588 | + /** @var \OC\User\User $user */ |
|
589 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
590 | + $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
591 | + }); |
|
592 | + /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
|
593 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
594 | + /** @var \OC\User\User $user */ |
|
595 | + \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
596 | + }); |
|
597 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
598 | + /** @var \OC\User\User $user */ |
|
599 | + \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
600 | + |
|
601 | + /** @var IEventDispatcher $dispatcher */ |
|
602 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
603 | + $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
604 | + }); |
|
605 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
606 | + /** @var \OC\User\User $user */ |
|
607 | + \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
608 | + |
|
609 | + /** @var IEventDispatcher $dispatcher */ |
|
610 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
611 | + $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
612 | + }); |
|
613 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
614 | + \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
615 | + |
|
616 | + /** @var IEventDispatcher $dispatcher */ |
|
617 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
618 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
619 | + }); |
|
620 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
621 | + /** @var \OC\User\User $user */ |
|
622 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
623 | + |
|
624 | + /** @var IEventDispatcher $dispatcher */ |
|
625 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
626 | + $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin)); |
|
627 | + }); |
|
628 | + $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
629 | + /** @var IEventDispatcher $dispatcher */ |
|
630 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
631 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
632 | + }); |
|
633 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
634 | + /** @var \OC\User\User $user */ |
|
635 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
636 | + |
|
637 | + /** @var IEventDispatcher $dispatcher */ |
|
638 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
639 | + $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
640 | + }); |
|
641 | + $userSession->listen('\OC\User', 'logout', function ($user) { |
|
642 | + \OC_Hook::emit('OC_User', 'logout', []); |
|
643 | + |
|
644 | + /** @var IEventDispatcher $dispatcher */ |
|
645 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
646 | + $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
647 | + }); |
|
648 | + $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
649 | + /** @var IEventDispatcher $dispatcher */ |
|
650 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
651 | + $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
652 | + }); |
|
653 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
654 | + /** @var \OC\User\User $user */ |
|
655 | + \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
656 | + |
|
657 | + /** @var IEventDispatcher $dispatcher */ |
|
658 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
659 | + $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue)); |
|
660 | + }); |
|
661 | + return $userSession; |
|
662 | + }); |
|
663 | + $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
664 | + /** @deprecated 19.0.0 */ |
|
665 | + $this->registerDeprecatedAlias('UserSession', \OC\User\Session::class); |
|
666 | + |
|
667 | + $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
668 | + |
|
669 | + $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
670 | + /** @deprecated 19.0.0 */ |
|
671 | + $this->registerDeprecatedAlias('NavigationManager', INavigationManager::class); |
|
672 | + |
|
673 | + /** @deprecated 19.0.0 */ |
|
674 | + $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class); |
|
675 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
676 | + |
|
677 | + $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
678 | + return new \OC\SystemConfig($config); |
|
679 | + }); |
|
680 | + /** @deprecated 19.0.0 */ |
|
681 | + $this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class); |
|
682 | + |
|
683 | + /** @deprecated 19.0.0 */ |
|
684 | + $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class); |
|
685 | + $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
686 | + |
|
687 | + $this->registerService(IFactory::class, function (Server $c) { |
|
688 | + return new \OC\L10N\Factory( |
|
689 | + $c->get(\OCP\IConfig::class), |
|
690 | + $c->getRequest(), |
|
691 | + $c->get(IUserSession::class), |
|
692 | + $c->get(ICacheFactory::class), |
|
693 | + \OC::$SERVERROOT |
|
694 | + ); |
|
695 | + }); |
|
696 | + /** @deprecated 19.0.0 */ |
|
697 | + $this->registerDeprecatedAlias('L10NFactory', IFactory::class); |
|
698 | + |
|
699 | + $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
|
700 | + /** @deprecated 19.0.0 */ |
|
701 | + $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class); |
|
702 | + |
|
703 | + /** @deprecated 19.0.0 */ |
|
704 | + $this->registerDeprecatedAlias('AppFetcher', AppFetcher::class); |
|
705 | + /** @deprecated 19.0.0 */ |
|
706 | + $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class); |
|
707 | + |
|
708 | + $this->registerService(ICache::class, function ($c) { |
|
709 | + return new Cache\File(); |
|
710 | + }); |
|
711 | + |
|
712 | + /** @deprecated 19.0.0 */ |
|
713 | + $this->registerDeprecatedAlias('UserCache', ICache::class); |
|
714 | + |
|
715 | + $this->registerService(Factory::class, function (Server $c) { |
|
716 | + $profiler = $c->get(IProfiler::class); |
|
717 | + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->get(LoggerInterface::class), |
|
718 | + $profiler, |
|
719 | + ArrayCache::class, |
|
720 | + ArrayCache::class, |
|
721 | + ArrayCache::class |
|
722 | + ); |
|
723 | + /** @var \OCP\IConfig $config */ |
|
724 | + $config = $c->get(\OCP\IConfig::class); |
|
725 | + |
|
726 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
727 | + if (!$config->getSystemValueBool('log_query')) { |
|
728 | + $v = \OC_App::getAppVersions(); |
|
729 | + } else { |
|
730 | + // If the log_query is enabled, we can not get the app versions |
|
731 | + // as that does a query, which will be logged and the logging |
|
732 | + // depends on redis and here we are back again in the same function. |
|
733 | + $v = [ |
|
734 | + 'log_query' => 'enabled', |
|
735 | + ]; |
|
736 | + } |
|
737 | + $v['core'] = implode(',', \OC_Util::getVersion()); |
|
738 | + $version = implode(',', $v); |
|
739 | + $instanceId = \OC_Util::getInstanceId(); |
|
740 | + $path = \OC::$SERVERROOT; |
|
741 | + $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
742 | + return new \OC\Memcache\Factory($prefix, |
|
743 | + $c->get(LoggerInterface::class), |
|
744 | + $profiler, |
|
745 | + $config->getSystemValue('memcache.local', null), |
|
746 | + $config->getSystemValue('memcache.distributed', null), |
|
747 | + $config->getSystemValue('memcache.locking', null), |
|
748 | + $config->getSystemValueString('redis_log_file') |
|
749 | + ); |
|
750 | + } |
|
751 | + return $arrayCacheFactory; |
|
752 | + }); |
|
753 | + /** @deprecated 19.0.0 */ |
|
754 | + $this->registerDeprecatedAlias('MemCacheFactory', Factory::class); |
|
755 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
756 | + |
|
757 | + $this->registerService('RedisFactory', function (Server $c) { |
|
758 | + $systemConfig = $c->get(SystemConfig::class); |
|
759 | + return new RedisFactory($systemConfig, $c->getEventLogger()); |
|
760 | + }); |
|
761 | + |
|
762 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
763 | + $l10n = $this->get(IFactory::class)->get('lib'); |
|
764 | + return new \OC\Activity\Manager( |
|
765 | + $c->getRequest(), |
|
766 | + $c->get(IUserSession::class), |
|
767 | + $c->get(\OCP\IConfig::class), |
|
768 | + $c->get(IValidator::class), |
|
769 | + $l10n |
|
770 | + ); |
|
771 | + }); |
|
772 | + /** @deprecated 19.0.0 */ |
|
773 | + $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
774 | + |
|
775 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
776 | + return new \OC\Activity\EventMerger( |
|
777 | + $c->getL10N('lib') |
|
778 | + ); |
|
779 | + }); |
|
780 | + $this->registerAlias(IValidator::class, Validator::class); |
|
781 | + |
|
782 | + $this->registerService(AvatarManager::class, function (Server $c) { |
|
783 | + return new AvatarManager( |
|
784 | + $c->get(IUserSession::class), |
|
785 | + $c->get(\OC\User\Manager::class), |
|
786 | + $c->getAppDataDir('avatar'), |
|
787 | + $c->getL10N('lib'), |
|
788 | + $c->get(LoggerInterface::class), |
|
789 | + $c->get(\OCP\IConfig::class), |
|
790 | + $c->get(IAccountManager::class), |
|
791 | + $c->get(KnownUserService::class) |
|
792 | + ); |
|
793 | + }); |
|
794 | + |
|
795 | + $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
796 | + /** @deprecated 19.0.0 */ |
|
797 | + $this->registerDeprecatedAlias('AvatarManager', AvatarManager::class); |
|
798 | + |
|
799 | + $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
800 | + $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
801 | + $this->registerAlias(\OCP\Support\Subscription\IAssertion::class, \OC\Support\Subscription\Assertion::class); |
|
802 | + |
|
803 | + $this->registerService(\OC\Log::class, function (Server $c) { |
|
804 | + $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
805 | + $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
|
806 | + $logger = $factory->get($logType); |
|
807 | + $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class); |
|
808 | + |
|
809 | + return new Log($logger, $this->get(SystemConfig::class), null, $registry); |
|
810 | + }); |
|
811 | + $this->registerAlias(ILogger::class, \OC\Log::class); |
|
812 | + /** @deprecated 19.0.0 */ |
|
813 | + $this->registerDeprecatedAlias('Logger', \OC\Log::class); |
|
814 | + // PSR-3 logger |
|
815 | + $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
816 | + |
|
817 | + $this->registerService(ILogFactory::class, function (Server $c) { |
|
818 | + return new LogFactory($c, $this->get(SystemConfig::class)); |
|
819 | + }); |
|
820 | + |
|
821 | + $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
822 | + /** @deprecated 19.0.0 */ |
|
823 | + $this->registerDeprecatedAlias('JobList', IJobList::class); |
|
824 | + |
|
825 | + $this->registerService(Router::class, function (Server $c) { |
|
826 | + $cacheFactory = $c->get(ICacheFactory::class); |
|
827 | + if ($cacheFactory->isLocalCacheAvailable()) { |
|
828 | + $router = $c->resolve(CachingRouter::class); |
|
829 | + } else { |
|
830 | + $router = $c->resolve(Router::class); |
|
831 | + } |
|
832 | + return $router; |
|
833 | + }); |
|
834 | + $this->registerAlias(IRouter::class, Router::class); |
|
835 | + /** @deprecated 19.0.0 */ |
|
836 | + $this->registerDeprecatedAlias('Router', IRouter::class); |
|
837 | + |
|
838 | + $this->registerAlias(ISearch::class, Search::class); |
|
839 | + /** @deprecated 19.0.0 */ |
|
840 | + $this->registerDeprecatedAlias('Search', ISearch::class); |
|
841 | + |
|
842 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
843 | + $cacheFactory = $c->get(ICacheFactory::class); |
|
844 | + if ($cacheFactory->isAvailable()) { |
|
845 | + $backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend( |
|
846 | + $this->get(ICacheFactory::class), |
|
847 | + new \OC\AppFramework\Utility\TimeFactory() |
|
848 | + ); |
|
849 | + } else { |
|
850 | + $backend = new \OC\Security\RateLimiting\Backend\DatabaseBackend( |
|
851 | + $c->get(IDBConnection::class), |
|
852 | + new \OC\AppFramework\Utility\TimeFactory() |
|
853 | + ); |
|
854 | + } |
|
855 | + |
|
856 | + return $backend; |
|
857 | + }); |
|
858 | + |
|
859 | + $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
860 | + /** @deprecated 19.0.0 */ |
|
861 | + $this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
862 | + $this->registerAlias(\OCP\Security\IRemoteHostValidator::class, \OC\Security\RemoteHostValidator::class); |
|
863 | + $this->registerAlias(IVerificationToken::class, VerificationToken::class); |
|
864 | + |
|
865 | + $this->registerAlias(ICrypto::class, Crypto::class); |
|
866 | + /** @deprecated 19.0.0 */ |
|
867 | + $this->registerDeprecatedAlias('Crypto', ICrypto::class); |
|
868 | + |
|
869 | + $this->registerAlias(IHasher::class, Hasher::class); |
|
870 | + /** @deprecated 19.0.0 */ |
|
871 | + $this->registerDeprecatedAlias('Hasher', IHasher::class); |
|
872 | + |
|
873 | + $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
874 | + /** @deprecated 19.0.0 */ |
|
875 | + $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class); |
|
876 | + |
|
877 | + $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
|
878 | + $this->registerService(Connection::class, function (Server $c) { |
|
879 | + $systemConfig = $c->get(SystemConfig::class); |
|
880 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
881 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
882 | + if (!$factory->isValidType($type)) { |
|
883 | + throw new \OC\DatabaseException('Invalid database type'); |
|
884 | + } |
|
885 | + $connectionParams = $factory->createConnectionParams(); |
|
886 | + $connection = $factory->getConnection($type, $connectionParams); |
|
887 | + return $connection; |
|
888 | + }); |
|
889 | + /** @deprecated 19.0.0 */ |
|
890 | + $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class); |
|
891 | + |
|
892 | + $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
|
893 | + $this->registerAlias(IClientService::class, ClientService::class); |
|
894 | + $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) { |
|
895 | + return new NegativeDnsCache( |
|
896 | + $c->get(ICacheFactory::class), |
|
897 | + ); |
|
898 | + }); |
|
899 | + $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
900 | + $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
901 | + return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class)); |
|
902 | + }); |
|
903 | + /** @deprecated 19.0.0 */ |
|
904 | + $this->registerDeprecatedAlias('EventLogger', IEventLogger::class); |
|
905 | + |
|
906 | + $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
907 | + $queryLogger = new QueryLogger(); |
|
908 | + if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
909 | + // In debug mode, module is being activated by default |
|
910 | + $queryLogger->activate(); |
|
911 | + } |
|
912 | + return $queryLogger; |
|
913 | + }); |
|
914 | + /** @deprecated 19.0.0 */ |
|
915 | + $this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class); |
|
916 | + |
|
917 | + /** @deprecated 19.0.0 */ |
|
918 | + $this->registerDeprecatedAlias('TempManager', TempManager::class); |
|
919 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
920 | + |
|
921 | + $this->registerService(AppManager::class, function (ContainerInterface $c) { |
|
922 | + // TODO: use auto-wiring |
|
923 | + return new \OC\App\AppManager( |
|
924 | + $c->get(IUserSession::class), |
|
925 | + $c->get(\OCP\IConfig::class), |
|
926 | + $c->get(\OC\AppConfig::class), |
|
927 | + $c->get(IGroupManager::class), |
|
928 | + $c->get(ICacheFactory::class), |
|
929 | + $c->get(SymfonyAdapter::class), |
|
930 | + $c->get(LoggerInterface::class) |
|
931 | + ); |
|
932 | + }); |
|
933 | + /** @deprecated 19.0.0 */ |
|
934 | + $this->registerDeprecatedAlias('AppManager', AppManager::class); |
|
935 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
936 | + |
|
937 | + $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
938 | + /** @deprecated 19.0.0 */ |
|
939 | + $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class); |
|
940 | + |
|
941 | + $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
942 | + $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
|
943 | + |
|
944 | + return new DateTimeFormatter( |
|
945 | + $c->get(IDateTimeZone::class)->getTimeZone(), |
|
946 | + $c->getL10N('lib', $language) |
|
947 | + ); |
|
948 | + }); |
|
949 | + /** @deprecated 19.0.0 */ |
|
950 | + $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class); |
|
951 | + |
|
952 | + $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
953 | + $mountCache = $c->get(UserMountCache::class); |
|
954 | + $listener = new UserMountCacheListener($mountCache); |
|
955 | + $listener->listen($c->get(IUserManager::class)); |
|
956 | + return $mountCache; |
|
957 | + }); |
|
958 | + /** @deprecated 19.0.0 */ |
|
959 | + $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class); |
|
960 | + |
|
961 | + $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
962 | + $loader = $c->get(IStorageFactory::class); |
|
963 | + $mountCache = $c->get(IUserMountCache::class); |
|
964 | + $eventLogger = $c->get(IEventLogger::class); |
|
965 | + $manager = new MountProviderCollection($loader, $mountCache, $eventLogger); |
|
966 | + |
|
967 | + // builtin providers |
|
968 | + |
|
969 | + $config = $c->get(\OCP\IConfig::class); |
|
970 | + $logger = $c->get(LoggerInterface::class); |
|
971 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
972 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
973 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
974 | + $manager->registerRootProvider(new RootMountProvider($config, $c->get(LoggerInterface::class))); |
|
975 | + $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config)); |
|
976 | + |
|
977 | + return $manager; |
|
978 | + }); |
|
979 | + /** @deprecated 19.0.0 */ |
|
980 | + $this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class); |
|
981 | + |
|
982 | + /** @deprecated 20.0.0 */ |
|
983 | + $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class); |
|
984 | + $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
985 | + $busClass = $c->get(\OCP\IConfig::class)->getSystemValue('commandbus'); |
|
986 | + if ($busClass) { |
|
987 | + [$app, $class] = explode('::', $busClass, 2); |
|
988 | + if ($c->get(IAppManager::class)->isInstalled($app)) { |
|
989 | + \OC_App::loadApp($app); |
|
990 | + return $c->get($class); |
|
991 | + } else { |
|
992 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
993 | + } |
|
994 | + } else { |
|
995 | + $jobList = $c->get(IJobList::class); |
|
996 | + return new CronBus($jobList); |
|
997 | + } |
|
998 | + }); |
|
999 | + $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class); |
|
1000 | + /** @deprecated 20.0.0 */ |
|
1001 | + $this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class); |
|
1002 | + $this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class); |
|
1003 | + /** @deprecated 19.0.0 */ |
|
1004 | + $this->registerDeprecatedAlias('Throttler', Throttler::class); |
|
1005 | + $this->registerAlias(IThrottler::class, Throttler::class); |
|
1006 | + $this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) { |
|
1007 | + // IConfig and IAppManager requires a working database. This code |
|
1008 | + // might however be called when ownCloud is not yet setup. |
|
1009 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
1010 | + $config = $c->get(\OCP\IConfig::class); |
|
1011 | + $appManager = $c->get(IAppManager::class); |
|
1012 | + } else { |
|
1013 | + $config = null; |
|
1014 | + $appManager = null; |
|
1015 | + } |
|
1016 | + |
|
1017 | + return new Checker( |
|
1018 | + new EnvironmentHelper(), |
|
1019 | + new FileAccessHelper(), |
|
1020 | + new AppLocator(), |
|
1021 | + $config, |
|
1022 | + $c->get(ICacheFactory::class), |
|
1023 | + $appManager, |
|
1024 | + $c->get(IMimeTypeDetector::class) |
|
1025 | + ); |
|
1026 | + }); |
|
1027 | + $this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) { |
|
1028 | + if (isset($this['urlParams'])) { |
|
1029 | + $urlParams = $this['urlParams']; |
|
1030 | + } else { |
|
1031 | + $urlParams = []; |
|
1032 | + } |
|
1033 | + |
|
1034 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
1035 | + && in_array('fakeinput', stream_get_wrappers()) |
|
1036 | + ) { |
|
1037 | + $stream = 'fakeinput://data'; |
|
1038 | + } else { |
|
1039 | + $stream = 'php://input'; |
|
1040 | + } |
|
1041 | + |
|
1042 | + return new Request( |
|
1043 | + [ |
|
1044 | + 'get' => $_GET, |
|
1045 | + 'post' => $_POST, |
|
1046 | + 'files' => $_FILES, |
|
1047 | + 'server' => $_SERVER, |
|
1048 | + 'env' => $_ENV, |
|
1049 | + 'cookies' => $_COOKIE, |
|
1050 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1051 | + ? $_SERVER['REQUEST_METHOD'] |
|
1052 | + : '', |
|
1053 | + 'urlParams' => $urlParams, |
|
1054 | + ], |
|
1055 | + $this->get(IRequestId::class), |
|
1056 | + $this->get(\OCP\IConfig::class), |
|
1057 | + $this->get(CsrfTokenManager::class), |
|
1058 | + $stream |
|
1059 | + ); |
|
1060 | + }); |
|
1061 | + /** @deprecated 19.0.0 */ |
|
1062 | + $this->registerDeprecatedAlias('Request', \OCP\IRequest::class); |
|
1063 | + |
|
1064 | + $this->registerService(IRequestId::class, function (ContainerInterface $c): IRequestId { |
|
1065 | + return new RequestId( |
|
1066 | + $_SERVER['UNIQUE_ID'] ?? '', |
|
1067 | + $this->get(ISecureRandom::class) |
|
1068 | + ); |
|
1069 | + }); |
|
1070 | + |
|
1071 | + $this->registerService(IMailer::class, function (Server $c) { |
|
1072 | + return new Mailer( |
|
1073 | + $c->get(\OCP\IConfig::class), |
|
1074 | + $c->get(LoggerInterface::class), |
|
1075 | + $c->get(Defaults::class), |
|
1076 | + $c->get(IURLGenerator::class), |
|
1077 | + $c->getL10N('lib'), |
|
1078 | + $c->get(IEventDispatcher::class), |
|
1079 | + $c->get(IFactory::class) |
|
1080 | + ); |
|
1081 | + }); |
|
1082 | + /** @deprecated 19.0.0 */ |
|
1083 | + $this->registerDeprecatedAlias('Mailer', IMailer::class); |
|
1084 | + |
|
1085 | + /** @deprecated 21.0.0 */ |
|
1086 | + $this->registerDeprecatedAlias('LDAPProvider', ILDAPProvider::class); |
|
1087 | + |
|
1088 | + $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) { |
|
1089 | + $config = $c->get(\OCP\IConfig::class); |
|
1090 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
1091 | + if (is_null($factoryClass) || !class_exists($factoryClass)) { |
|
1092 | + return new NullLDAPProviderFactory($this); |
|
1093 | + } |
|
1094 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
1095 | + return new $factoryClass($this); |
|
1096 | + }); |
|
1097 | + $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) { |
|
1098 | + $factory = $c->get(ILDAPProviderFactory::class); |
|
1099 | + return $factory->getLDAPProvider(); |
|
1100 | + }); |
|
1101 | + $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
1102 | + $ini = $c->get(IniGetWrapper::class); |
|
1103 | + $config = $c->get(\OCP\IConfig::class); |
|
1104 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
1105 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
1106 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
1107 | + $memcacheFactory = $c->get(ICacheFactory::class); |
|
1108 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
1109 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
1110 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
1111 | + } |
|
1112 | + return new DBLockingProvider( |
|
1113 | + $c->get(IDBConnection::class), |
|
1114 | + new TimeFactory(), |
|
1115 | + $ttl, |
|
1116 | + !\OC::$CLI |
|
1117 | + ); |
|
1118 | + } |
|
1119 | + return new NoopLockingProvider(); |
|
1120 | + }); |
|
1121 | + /** @deprecated 19.0.0 */ |
|
1122 | + $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class); |
|
1123 | + |
|
1124 | + $this->registerService(ILockManager::class, function (Server $c): LockManager { |
|
1125 | + return new LockManager(); |
|
1126 | + }); |
|
1127 | + |
|
1128 | + $this->registerAlias(ILockdownManager::class, 'LockdownManager'); |
|
1129 | + $this->registerService(SetupManager::class, function ($c) { |
|
1130 | + // create the setupmanager through the mount manager to resolve the cyclic dependency |
|
1131 | + return $c->get(\OC\Files\Mount\Manager::class)->getSetupManager(); |
|
1132 | + }); |
|
1133 | + $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
1134 | + /** @deprecated 19.0.0 */ |
|
1135 | + $this->registerDeprecatedAlias('MountManager', IMountManager::class); |
|
1136 | + |
|
1137 | + $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
1138 | + return new \OC\Files\Type\Detection( |
|
1139 | + $c->get(IURLGenerator::class), |
|
1140 | + $c->get(LoggerInterface::class), |
|
1141 | + \OC::$configDir, |
|
1142 | + \OC::$SERVERROOT . '/resources/config/' |
|
1143 | + ); |
|
1144 | + }); |
|
1145 | + /** @deprecated 19.0.0 */ |
|
1146 | + $this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class); |
|
1147 | + |
|
1148 | + $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
1149 | + /** @deprecated 19.0.0 */ |
|
1150 | + $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class); |
|
1151 | + $this->registerService(BundleFetcher::class, function () { |
|
1152 | + return new BundleFetcher($this->getL10N('lib')); |
|
1153 | + }); |
|
1154 | + $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
1155 | + /** @deprecated 19.0.0 */ |
|
1156 | + $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
1157 | + |
|
1158 | + $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
1159 | + $manager = new CapabilitiesManager($c->get(LoggerInterface::class)); |
|
1160 | + $manager->registerCapability(function () use ($c) { |
|
1161 | + return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
|
1162 | + }); |
|
1163 | + $manager->registerCapability(function () use ($c) { |
|
1164 | + return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
|
1165 | + }); |
|
1166 | + $manager->registerCapability(function () use ($c) { |
|
1167 | + return $c->get(MetadataCapabilities::class); |
|
1168 | + }); |
|
1169 | + return $manager; |
|
1170 | + }); |
|
1171 | + /** @deprecated 19.0.0 */ |
|
1172 | + $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class); |
|
1173 | + |
|
1174 | + $this->registerService(ICommentsManager::class, function (Server $c) { |
|
1175 | + $config = $c->get(\OCP\IConfig::class); |
|
1176 | + $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
1177 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
1178 | + $factory = new $factoryClass($this); |
|
1179 | + $manager = $factory->getManager(); |
|
1180 | + |
|
1181 | + $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
1182 | + $manager = $c->get(IUserManager::class); |
|
1183 | + $userDisplayName = $manager->getDisplayName($id); |
|
1184 | + if ($userDisplayName === null) { |
|
1185 | + $l = $c->get(IFactory::class)->get('core'); |
|
1186 | + return $l->t('Unknown user'); |
|
1187 | + } |
|
1188 | + return $userDisplayName; |
|
1189 | + }); |
|
1190 | + |
|
1191 | + return $manager; |
|
1192 | + }); |
|
1193 | + /** @deprecated 19.0.0 */ |
|
1194 | + $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class); |
|
1195 | + |
|
1196 | + $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
1197 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
1198 | + /* |
|
1199 | 1199 | * Dark magic for autoloader. |
1200 | 1200 | * If we do a class_exists it will try to load the class which will |
1201 | 1201 | * make composer cache the result. Resulting in errors when enabling |
1202 | 1202 | * the theming app. |
1203 | 1203 | */ |
1204 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
1205 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
1206 | - $classExists = true; |
|
1207 | - } else { |
|
1208 | - $classExists = false; |
|
1209 | - } |
|
1210 | - |
|
1211 | - if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValue('installed', false) && $c->get(IAppManager::class)->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
1212 | - $imageManager = new ImageManager( |
|
1213 | - $c->get(\OCP\IConfig::class), |
|
1214 | - $c->getAppDataDir('theming'), |
|
1215 | - $c->get(IURLGenerator::class), |
|
1216 | - $this->get(ICacheFactory::class), |
|
1217 | - $this->get(ILogger::class), |
|
1218 | - $this->get(ITempManager::class) |
|
1219 | - ); |
|
1220 | - return new ThemingDefaults( |
|
1221 | - $c->get(\OCP\IConfig::class), |
|
1222 | - $c->getL10N('theming'), |
|
1223 | - $c->get(IUserSession::class), |
|
1224 | - $c->get(IURLGenerator::class), |
|
1225 | - $c->get(ICacheFactory::class), |
|
1226 | - new Util($c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming'), $imageManager), |
|
1227 | - $imageManager, |
|
1228 | - $c->get(IAppManager::class), |
|
1229 | - $c->get(INavigationManager::class) |
|
1230 | - ); |
|
1231 | - } |
|
1232 | - return new \OC_Defaults(); |
|
1233 | - }); |
|
1234 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
1235 | - return new JSCombiner( |
|
1236 | - $c->getAppDataDir('js'), |
|
1237 | - $c->get(IURLGenerator::class), |
|
1238 | - $this->get(ICacheFactory::class), |
|
1239 | - $c->get(SystemConfig::class), |
|
1240 | - $c->get(LoggerInterface::class) |
|
1241 | - ); |
|
1242 | - }); |
|
1243 | - $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
1244 | - /** @deprecated 19.0.0 */ |
|
1245 | - $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
|
1246 | - $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
|
1247 | - |
|
1248 | - $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
1249 | - // FIXME: Instantiated here due to cyclic dependency |
|
1250 | - $request = new Request( |
|
1251 | - [ |
|
1252 | - 'get' => $_GET, |
|
1253 | - 'post' => $_POST, |
|
1254 | - 'files' => $_FILES, |
|
1255 | - 'server' => $_SERVER, |
|
1256 | - 'env' => $_ENV, |
|
1257 | - 'cookies' => $_COOKIE, |
|
1258 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1259 | - ? $_SERVER['REQUEST_METHOD'] |
|
1260 | - : null, |
|
1261 | - ], |
|
1262 | - $c->get(IRequestId::class), |
|
1263 | - $c->get(\OCP\IConfig::class) |
|
1264 | - ); |
|
1265 | - |
|
1266 | - return new CryptoWrapper( |
|
1267 | - $c->get(\OCP\IConfig::class), |
|
1268 | - $c->get(ICrypto::class), |
|
1269 | - $c->get(ISecureRandom::class), |
|
1270 | - $request |
|
1271 | - ); |
|
1272 | - }); |
|
1273 | - /** @deprecated 19.0.0 */ |
|
1274 | - $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class); |
|
1275 | - $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
1276 | - return new SessionStorage($c->get(ISession::class)); |
|
1277 | - }); |
|
1278 | - $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
1279 | - /** @deprecated 19.0.0 */ |
|
1280 | - $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class); |
|
1281 | - |
|
1282 | - $this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) { |
|
1283 | - $config = $c->get(\OCP\IConfig::class); |
|
1284 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1285 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
1286 | - $factory = new $factoryClass($this); |
|
1287 | - |
|
1288 | - $manager = new \OC\Share20\Manager( |
|
1289 | - $c->get(LoggerInterface::class), |
|
1290 | - $c->get(\OCP\IConfig::class), |
|
1291 | - $c->get(ISecureRandom::class), |
|
1292 | - $c->get(IHasher::class), |
|
1293 | - $c->get(IMountManager::class), |
|
1294 | - $c->get(IGroupManager::class), |
|
1295 | - $c->getL10N('lib'), |
|
1296 | - $c->get(IFactory::class), |
|
1297 | - $factory, |
|
1298 | - $c->get(IUserManager::class), |
|
1299 | - $c->get(IRootFolder::class), |
|
1300 | - $c->get(SymfonyAdapter::class), |
|
1301 | - $c->get(IMailer::class), |
|
1302 | - $c->get(IURLGenerator::class), |
|
1303 | - $c->get('ThemingDefaults'), |
|
1304 | - $c->get(IEventDispatcher::class), |
|
1305 | - $c->get(IUserSession::class), |
|
1306 | - $c->get(KnownUserService::class) |
|
1307 | - ); |
|
1308 | - |
|
1309 | - return $manager; |
|
1310 | - }); |
|
1311 | - /** @deprecated 19.0.0 */ |
|
1312 | - $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class); |
|
1313 | - |
|
1314 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
1315 | - $instance = new Collaboration\Collaborators\Search($c); |
|
1316 | - |
|
1317 | - // register default plugins |
|
1318 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1319 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1320 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1321 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1322 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
1323 | - |
|
1324 | - return $instance; |
|
1325 | - }); |
|
1326 | - /** @deprecated 19.0.0 */ |
|
1327 | - $this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1328 | - $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
1329 | - |
|
1330 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1331 | - |
|
1332 | - $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
1333 | - $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
1334 | - |
|
1335 | - $this->registerAlias(IReferenceManager::class, ReferenceManager::class); |
|
1336 | - |
|
1337 | - $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
|
1338 | - $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
|
1339 | - $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
1340 | - return new \OC\Files\AppData\Factory( |
|
1341 | - $c->get(IRootFolder::class), |
|
1342 | - $c->get(SystemConfig::class) |
|
1343 | - ); |
|
1344 | - }); |
|
1345 | - |
|
1346 | - $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
1347 | - return new LockdownManager(function () use ($c) { |
|
1348 | - return $c->get(ISession::class); |
|
1349 | - }); |
|
1350 | - }); |
|
1351 | - |
|
1352 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
1353 | - return new DiscoveryService( |
|
1354 | - $c->get(ICacheFactory::class), |
|
1355 | - $c->get(IClientService::class) |
|
1356 | - ); |
|
1357 | - }); |
|
1358 | - |
|
1359 | - $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
1360 | - return new CloudIdManager( |
|
1361 | - $c->get(\OCP\Contacts\IManager::class), |
|
1362 | - $c->get(IURLGenerator::class), |
|
1363 | - $c->get(IUserManager::class), |
|
1364 | - $c->get(ICacheFactory::class), |
|
1365 | - $c->get(IEventDispatcher::class), |
|
1366 | - ); |
|
1367 | - }); |
|
1368 | - |
|
1369 | - $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
1370 | - |
|
1371 | - $this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) { |
|
1372 | - return new CloudFederationProviderManager( |
|
1373 | - $c->get(IAppManager::class), |
|
1374 | - $c->get(IClientService::class), |
|
1375 | - $c->get(ICloudIdManager::class), |
|
1376 | - $c->get(LoggerInterface::class) |
|
1377 | - ); |
|
1378 | - }); |
|
1379 | - |
|
1380 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1381 | - return new CloudFederationFactory(); |
|
1382 | - }); |
|
1383 | - |
|
1384 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1385 | - /** @deprecated 19.0.0 */ |
|
1386 | - $this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1387 | - |
|
1388 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1389 | - /** @deprecated 19.0.0 */ |
|
1390 | - $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1391 | - |
|
1392 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1393 | - return new Defaults( |
|
1394 | - $c->getThemingDefaults() |
|
1395 | - ); |
|
1396 | - }); |
|
1397 | - /** @deprecated 19.0.0 */ |
|
1398 | - $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class); |
|
1399 | - |
|
1400 | - $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
1401 | - return $c->get(\OCP\IUserSession::class)->getSession(); |
|
1402 | - }, false); |
|
1403 | - |
|
1404 | - $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
1405 | - return new ShareHelper( |
|
1406 | - $c->get(\OCP\Share\IManager::class) |
|
1407 | - ); |
|
1408 | - }); |
|
1409 | - |
|
1410 | - $this->registerService(Installer::class, function (ContainerInterface $c) { |
|
1411 | - return new Installer( |
|
1412 | - $c->get(AppFetcher::class), |
|
1413 | - $c->get(IClientService::class), |
|
1414 | - $c->get(ITempManager::class), |
|
1415 | - $c->get(LoggerInterface::class), |
|
1416 | - $c->get(\OCP\IConfig::class), |
|
1417 | - \OC::$CLI |
|
1418 | - ); |
|
1419 | - }); |
|
1420 | - |
|
1421 | - $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
1422 | - return new ApiFactory($c->get(IClientService::class)); |
|
1423 | - }); |
|
1424 | - |
|
1425 | - $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
1426 | - $memcacheFactory = $c->get(ICacheFactory::class); |
|
1427 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
|
1428 | - }); |
|
1429 | - |
|
1430 | - $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1431 | - $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
1432 | - |
|
1433 | - $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
1434 | - |
|
1435 | - $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
1436 | - |
|
1437 | - $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
1438 | - |
|
1439 | - $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
1440 | - |
|
1441 | - $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
1442 | - |
|
1443 | - $this->registerAlias(\OCP\IEmojiHelper::class, \OC\EmojiHelper::class); |
|
1444 | - |
|
1445 | - $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
1446 | - |
|
1447 | - $this->registerAlias(IBroker::class, Broker::class); |
|
1448 | - |
|
1449 | - $this->registerAlias(IMetadataManager::class, MetadataManager::class); |
|
1450 | - |
|
1451 | - $this->registerAlias(\OCP\Files\AppData\IAppDataFactory::class, \OC\Files\AppData\Factory::class); |
|
1452 | - |
|
1453 | - $this->registerAlias(IBinaryFinder::class, BinaryFinder::class); |
|
1454 | - |
|
1455 | - $this->registerAlias(\OCP\Share\IPublicShareTemplateFactory::class, \OC\Share20\PublicShareTemplateFactory::class); |
|
1456 | - |
|
1457 | - $this->connectDispatcher(); |
|
1458 | - } |
|
1459 | - |
|
1460 | - public function boot() { |
|
1461 | - /** @var HookConnector $hookConnector */ |
|
1462 | - $hookConnector = $this->get(HookConnector::class); |
|
1463 | - $hookConnector->viewToNode(); |
|
1464 | - } |
|
1465 | - |
|
1466 | - /** |
|
1467 | - * @return \OCP\Calendar\IManager |
|
1468 | - * @deprecated 20.0.0 |
|
1469 | - */ |
|
1470 | - public function getCalendarManager() { |
|
1471 | - return $this->get(\OC\Calendar\Manager::class); |
|
1472 | - } |
|
1473 | - |
|
1474 | - /** |
|
1475 | - * @return \OCP\Calendar\Resource\IManager |
|
1476 | - * @deprecated 20.0.0 |
|
1477 | - */ |
|
1478 | - public function getCalendarResourceBackendManager() { |
|
1479 | - return $this->get(\OC\Calendar\Resource\Manager::class); |
|
1480 | - } |
|
1481 | - |
|
1482 | - /** |
|
1483 | - * @return \OCP\Calendar\Room\IManager |
|
1484 | - * @deprecated 20.0.0 |
|
1485 | - */ |
|
1486 | - public function getCalendarRoomBackendManager() { |
|
1487 | - return $this->get(\OC\Calendar\Room\Manager::class); |
|
1488 | - } |
|
1489 | - |
|
1490 | - private function connectDispatcher(): void { |
|
1491 | - /** @var IEventDispatcher $eventDispatcher */ |
|
1492 | - $eventDispatcher = $this->get(IEventDispatcher::class); |
|
1493 | - $eventDispatcher->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
1494 | - $eventDispatcher->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class); |
|
1495 | - $eventDispatcher->addServiceListener(UserChangedEvent::class, UserChangedListener::class); |
|
1496 | - $eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, BeforeUserDeletedListener::class); |
|
1497 | - } |
|
1498 | - |
|
1499 | - /** |
|
1500 | - * @return \OCP\Contacts\IManager |
|
1501 | - * @deprecated 20.0.0 |
|
1502 | - */ |
|
1503 | - public function getContactsManager() { |
|
1504 | - return $this->get(\OCP\Contacts\IManager::class); |
|
1505 | - } |
|
1506 | - |
|
1507 | - /** |
|
1508 | - * @return \OC\Encryption\Manager |
|
1509 | - * @deprecated 20.0.0 |
|
1510 | - */ |
|
1511 | - public function getEncryptionManager() { |
|
1512 | - return $this->get(\OCP\Encryption\IManager::class); |
|
1513 | - } |
|
1514 | - |
|
1515 | - /** |
|
1516 | - * @return \OC\Encryption\File |
|
1517 | - * @deprecated 20.0.0 |
|
1518 | - */ |
|
1519 | - public function getEncryptionFilesHelper() { |
|
1520 | - return $this->get(IFile::class); |
|
1521 | - } |
|
1522 | - |
|
1523 | - /** |
|
1524 | - * @return \OCP\Encryption\Keys\IStorage |
|
1525 | - * @deprecated 20.0.0 |
|
1526 | - */ |
|
1527 | - public function getEncryptionKeyStorage() { |
|
1528 | - return $this->get(IStorage::class); |
|
1529 | - } |
|
1530 | - |
|
1531 | - /** |
|
1532 | - * The current request object holding all information about the request |
|
1533 | - * currently being processed is returned from this method. |
|
1534 | - * In case the current execution was not initiated by a web request null is returned |
|
1535 | - * |
|
1536 | - * @return \OCP\IRequest |
|
1537 | - * @deprecated 20.0.0 |
|
1538 | - */ |
|
1539 | - public function getRequest() { |
|
1540 | - return $this->get(IRequest::class); |
|
1541 | - } |
|
1542 | - |
|
1543 | - /** |
|
1544 | - * Returns the preview manager which can create preview images for a given file |
|
1545 | - * |
|
1546 | - * @return IPreview |
|
1547 | - * @deprecated 20.0.0 |
|
1548 | - */ |
|
1549 | - public function getPreviewManager() { |
|
1550 | - return $this->get(IPreview::class); |
|
1551 | - } |
|
1552 | - |
|
1553 | - /** |
|
1554 | - * Returns the tag manager which can get and set tags for different object types |
|
1555 | - * |
|
1556 | - * @see \OCP\ITagManager::load() |
|
1557 | - * @return ITagManager |
|
1558 | - * @deprecated 20.0.0 |
|
1559 | - */ |
|
1560 | - public function getTagManager() { |
|
1561 | - return $this->get(ITagManager::class); |
|
1562 | - } |
|
1563 | - |
|
1564 | - /** |
|
1565 | - * Returns the system-tag manager |
|
1566 | - * |
|
1567 | - * @return ISystemTagManager |
|
1568 | - * |
|
1569 | - * @since 9.0.0 |
|
1570 | - * @deprecated 20.0.0 |
|
1571 | - */ |
|
1572 | - public function getSystemTagManager() { |
|
1573 | - return $this->get(ISystemTagManager::class); |
|
1574 | - } |
|
1575 | - |
|
1576 | - /** |
|
1577 | - * Returns the system-tag object mapper |
|
1578 | - * |
|
1579 | - * @return ISystemTagObjectMapper |
|
1580 | - * |
|
1581 | - * @since 9.0.0 |
|
1582 | - * @deprecated 20.0.0 |
|
1583 | - */ |
|
1584 | - public function getSystemTagObjectMapper() { |
|
1585 | - return $this->get(ISystemTagObjectMapper::class); |
|
1586 | - } |
|
1587 | - |
|
1588 | - /** |
|
1589 | - * Returns the avatar manager, used for avatar functionality |
|
1590 | - * |
|
1591 | - * @return IAvatarManager |
|
1592 | - * @deprecated 20.0.0 |
|
1593 | - */ |
|
1594 | - public function getAvatarManager() { |
|
1595 | - return $this->get(IAvatarManager::class); |
|
1596 | - } |
|
1597 | - |
|
1598 | - /** |
|
1599 | - * Returns the root folder of ownCloud's data directory |
|
1600 | - * |
|
1601 | - * @return IRootFolder |
|
1602 | - * @deprecated 20.0.0 |
|
1603 | - */ |
|
1604 | - public function getRootFolder() { |
|
1605 | - return $this->get(IRootFolder::class); |
|
1606 | - } |
|
1607 | - |
|
1608 | - /** |
|
1609 | - * Returns the root folder of ownCloud's data directory |
|
1610 | - * This is the lazy variant so this gets only initialized once it |
|
1611 | - * is actually used. |
|
1612 | - * |
|
1613 | - * @return IRootFolder |
|
1614 | - * @deprecated 20.0.0 |
|
1615 | - */ |
|
1616 | - public function getLazyRootFolder() { |
|
1617 | - return $this->get(IRootFolder::class); |
|
1618 | - } |
|
1619 | - |
|
1620 | - /** |
|
1621 | - * Returns a view to ownCloud's files folder |
|
1622 | - * |
|
1623 | - * @param string $userId user ID |
|
1624 | - * @return \OCP\Files\Folder|null |
|
1625 | - * @deprecated 20.0.0 |
|
1626 | - */ |
|
1627 | - public function getUserFolder($userId = null) { |
|
1628 | - if ($userId === null) { |
|
1629 | - $user = $this->get(IUserSession::class)->getUser(); |
|
1630 | - if (!$user) { |
|
1631 | - return null; |
|
1632 | - } |
|
1633 | - $userId = $user->getUID(); |
|
1634 | - } |
|
1635 | - $root = $this->get(IRootFolder::class); |
|
1636 | - return $root->getUserFolder($userId); |
|
1637 | - } |
|
1638 | - |
|
1639 | - /** |
|
1640 | - * @return \OC\User\Manager |
|
1641 | - * @deprecated 20.0.0 |
|
1642 | - */ |
|
1643 | - public function getUserManager() { |
|
1644 | - return $this->get(IUserManager::class); |
|
1645 | - } |
|
1646 | - |
|
1647 | - /** |
|
1648 | - * @return \OC\Group\Manager |
|
1649 | - * @deprecated 20.0.0 |
|
1650 | - */ |
|
1651 | - public function getGroupManager() { |
|
1652 | - return $this->get(IGroupManager::class); |
|
1653 | - } |
|
1654 | - |
|
1655 | - /** |
|
1656 | - * @return \OC\User\Session |
|
1657 | - * @deprecated 20.0.0 |
|
1658 | - */ |
|
1659 | - public function getUserSession() { |
|
1660 | - return $this->get(IUserSession::class); |
|
1661 | - } |
|
1662 | - |
|
1663 | - /** |
|
1664 | - * @return \OCP\ISession |
|
1665 | - * @deprecated 20.0.0 |
|
1666 | - */ |
|
1667 | - public function getSession() { |
|
1668 | - return $this->get(Session::class)->getSession(); |
|
1669 | - } |
|
1670 | - |
|
1671 | - /** |
|
1672 | - * @param \OCP\ISession $session |
|
1673 | - */ |
|
1674 | - public function setSession(\OCP\ISession $session) { |
|
1675 | - $this->get(SessionStorage::class)->setSession($session); |
|
1676 | - $this->get(Session::class)->setSession($session); |
|
1677 | - $this->get(Store::class)->setSession($session); |
|
1678 | - } |
|
1679 | - |
|
1680 | - /** |
|
1681 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1682 | - * @deprecated 20.0.0 |
|
1683 | - */ |
|
1684 | - public function getTwoFactorAuthManager() { |
|
1685 | - return $this->get(\OC\Authentication\TwoFactorAuth\Manager::class); |
|
1686 | - } |
|
1687 | - |
|
1688 | - /** |
|
1689 | - * @return \OC\NavigationManager |
|
1690 | - * @deprecated 20.0.0 |
|
1691 | - */ |
|
1692 | - public function getNavigationManager() { |
|
1693 | - return $this->get(INavigationManager::class); |
|
1694 | - } |
|
1695 | - |
|
1696 | - /** |
|
1697 | - * @return \OCP\IConfig |
|
1698 | - * @deprecated 20.0.0 |
|
1699 | - */ |
|
1700 | - public function getConfig() { |
|
1701 | - return $this->get(AllConfig::class); |
|
1702 | - } |
|
1703 | - |
|
1704 | - /** |
|
1705 | - * @return \OC\SystemConfig |
|
1706 | - * @deprecated 20.0.0 |
|
1707 | - */ |
|
1708 | - public function getSystemConfig() { |
|
1709 | - return $this->get(SystemConfig::class); |
|
1710 | - } |
|
1711 | - |
|
1712 | - /** |
|
1713 | - * Returns the app config manager |
|
1714 | - * |
|
1715 | - * @return IAppConfig |
|
1716 | - * @deprecated 20.0.0 |
|
1717 | - */ |
|
1718 | - public function getAppConfig() { |
|
1719 | - return $this->get(IAppConfig::class); |
|
1720 | - } |
|
1721 | - |
|
1722 | - /** |
|
1723 | - * @return IFactory |
|
1724 | - * @deprecated 20.0.0 |
|
1725 | - */ |
|
1726 | - public function getL10NFactory() { |
|
1727 | - return $this->get(IFactory::class); |
|
1728 | - } |
|
1729 | - |
|
1730 | - /** |
|
1731 | - * get an L10N instance |
|
1732 | - * |
|
1733 | - * @param string $app appid |
|
1734 | - * @param string $lang |
|
1735 | - * @return IL10N |
|
1736 | - * @deprecated 20.0.0 |
|
1737 | - */ |
|
1738 | - public function getL10N($app, $lang = null) { |
|
1739 | - return $this->get(IFactory::class)->get($app, $lang); |
|
1740 | - } |
|
1741 | - |
|
1742 | - /** |
|
1743 | - * @return IURLGenerator |
|
1744 | - * @deprecated 20.0.0 |
|
1745 | - */ |
|
1746 | - public function getURLGenerator() { |
|
1747 | - return $this->get(IURLGenerator::class); |
|
1748 | - } |
|
1749 | - |
|
1750 | - /** |
|
1751 | - * @return AppFetcher |
|
1752 | - * @deprecated 20.0.0 |
|
1753 | - */ |
|
1754 | - public function getAppFetcher() { |
|
1755 | - return $this->get(AppFetcher::class); |
|
1756 | - } |
|
1757 | - |
|
1758 | - /** |
|
1759 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1760 | - * getMemCacheFactory() instead. |
|
1761 | - * |
|
1762 | - * @return ICache |
|
1763 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1764 | - */ |
|
1765 | - public function getCache() { |
|
1766 | - return $this->get(ICache::class); |
|
1767 | - } |
|
1768 | - |
|
1769 | - /** |
|
1770 | - * Returns an \OCP\CacheFactory instance |
|
1771 | - * |
|
1772 | - * @return \OCP\ICacheFactory |
|
1773 | - * @deprecated 20.0.0 |
|
1774 | - */ |
|
1775 | - public function getMemCacheFactory() { |
|
1776 | - return $this->get(ICacheFactory::class); |
|
1777 | - } |
|
1778 | - |
|
1779 | - /** |
|
1780 | - * Returns an \OC\RedisFactory instance |
|
1781 | - * |
|
1782 | - * @return \OC\RedisFactory |
|
1783 | - * @deprecated 20.0.0 |
|
1784 | - */ |
|
1785 | - public function getGetRedisFactory() { |
|
1786 | - return $this->get('RedisFactory'); |
|
1787 | - } |
|
1788 | - |
|
1789 | - |
|
1790 | - /** |
|
1791 | - * Returns the current session |
|
1792 | - * |
|
1793 | - * @return \OCP\IDBConnection |
|
1794 | - * @deprecated 20.0.0 |
|
1795 | - */ |
|
1796 | - public function getDatabaseConnection() { |
|
1797 | - return $this->get(IDBConnection::class); |
|
1798 | - } |
|
1799 | - |
|
1800 | - /** |
|
1801 | - * Returns the activity manager |
|
1802 | - * |
|
1803 | - * @return \OCP\Activity\IManager |
|
1804 | - * @deprecated 20.0.0 |
|
1805 | - */ |
|
1806 | - public function getActivityManager() { |
|
1807 | - return $this->get(\OCP\Activity\IManager::class); |
|
1808 | - } |
|
1809 | - |
|
1810 | - /** |
|
1811 | - * Returns an job list for controlling background jobs |
|
1812 | - * |
|
1813 | - * @return IJobList |
|
1814 | - * @deprecated 20.0.0 |
|
1815 | - */ |
|
1816 | - public function getJobList() { |
|
1817 | - return $this->get(IJobList::class); |
|
1818 | - } |
|
1819 | - |
|
1820 | - /** |
|
1821 | - * Returns a logger instance |
|
1822 | - * |
|
1823 | - * @return ILogger |
|
1824 | - * @deprecated 20.0.0 |
|
1825 | - */ |
|
1826 | - public function getLogger() { |
|
1827 | - return $this->get(ILogger::class); |
|
1828 | - } |
|
1829 | - |
|
1830 | - /** |
|
1831 | - * @return ILogFactory |
|
1832 | - * @throws \OCP\AppFramework\QueryException |
|
1833 | - * @deprecated 20.0.0 |
|
1834 | - */ |
|
1835 | - public function getLogFactory() { |
|
1836 | - return $this->get(ILogFactory::class); |
|
1837 | - } |
|
1838 | - |
|
1839 | - /** |
|
1840 | - * Returns a router for generating and matching urls |
|
1841 | - * |
|
1842 | - * @return IRouter |
|
1843 | - * @deprecated 20.0.0 |
|
1844 | - */ |
|
1845 | - public function getRouter() { |
|
1846 | - return $this->get(IRouter::class); |
|
1847 | - } |
|
1848 | - |
|
1849 | - /** |
|
1850 | - * Returns a search instance |
|
1851 | - * |
|
1852 | - * @return ISearch |
|
1853 | - * @deprecated 20.0.0 |
|
1854 | - */ |
|
1855 | - public function getSearch() { |
|
1856 | - return $this->get(ISearch::class); |
|
1857 | - } |
|
1858 | - |
|
1859 | - /** |
|
1860 | - * Returns a SecureRandom instance |
|
1861 | - * |
|
1862 | - * @return \OCP\Security\ISecureRandom |
|
1863 | - * @deprecated 20.0.0 |
|
1864 | - */ |
|
1865 | - public function getSecureRandom() { |
|
1866 | - return $this->get(ISecureRandom::class); |
|
1867 | - } |
|
1868 | - |
|
1869 | - /** |
|
1870 | - * Returns a Crypto instance |
|
1871 | - * |
|
1872 | - * @return ICrypto |
|
1873 | - * @deprecated 20.0.0 |
|
1874 | - */ |
|
1875 | - public function getCrypto() { |
|
1876 | - return $this->get(ICrypto::class); |
|
1877 | - } |
|
1878 | - |
|
1879 | - /** |
|
1880 | - * Returns a Hasher instance |
|
1881 | - * |
|
1882 | - * @return IHasher |
|
1883 | - * @deprecated 20.0.0 |
|
1884 | - */ |
|
1885 | - public function getHasher() { |
|
1886 | - return $this->get(IHasher::class); |
|
1887 | - } |
|
1888 | - |
|
1889 | - /** |
|
1890 | - * Returns a CredentialsManager instance |
|
1891 | - * |
|
1892 | - * @return ICredentialsManager |
|
1893 | - * @deprecated 20.0.0 |
|
1894 | - */ |
|
1895 | - public function getCredentialsManager() { |
|
1896 | - return $this->get(ICredentialsManager::class); |
|
1897 | - } |
|
1898 | - |
|
1899 | - /** |
|
1900 | - * Get the certificate manager |
|
1901 | - * |
|
1902 | - * @return \OCP\ICertificateManager |
|
1903 | - */ |
|
1904 | - public function getCertificateManager() { |
|
1905 | - return $this->get(ICertificateManager::class); |
|
1906 | - } |
|
1907 | - |
|
1908 | - /** |
|
1909 | - * Returns an instance of the HTTP client service |
|
1910 | - * |
|
1911 | - * @return IClientService |
|
1912 | - * @deprecated 20.0.0 |
|
1913 | - */ |
|
1914 | - public function getHTTPClientService() { |
|
1915 | - return $this->get(IClientService::class); |
|
1916 | - } |
|
1917 | - |
|
1918 | - /** |
|
1919 | - * Create a new event source |
|
1920 | - * |
|
1921 | - * @return \OCP\IEventSource |
|
1922 | - * @deprecated 20.0.0 |
|
1923 | - */ |
|
1924 | - public function createEventSource() { |
|
1925 | - return new \OC_EventSource(); |
|
1926 | - } |
|
1927 | - |
|
1928 | - /** |
|
1929 | - * Get the active event logger |
|
1930 | - * |
|
1931 | - * The returned logger only logs data when debug mode is enabled |
|
1932 | - * |
|
1933 | - * @return IEventLogger |
|
1934 | - * @deprecated 20.0.0 |
|
1935 | - */ |
|
1936 | - public function getEventLogger() { |
|
1937 | - return $this->get(IEventLogger::class); |
|
1938 | - } |
|
1939 | - |
|
1940 | - /** |
|
1941 | - * Get the active query logger |
|
1942 | - * |
|
1943 | - * The returned logger only logs data when debug mode is enabled |
|
1944 | - * |
|
1945 | - * @return IQueryLogger |
|
1946 | - * @deprecated 20.0.0 |
|
1947 | - */ |
|
1948 | - public function getQueryLogger() { |
|
1949 | - return $this->get(IQueryLogger::class); |
|
1950 | - } |
|
1951 | - |
|
1952 | - /** |
|
1953 | - * Get the manager for temporary files and folders |
|
1954 | - * |
|
1955 | - * @return \OCP\ITempManager |
|
1956 | - * @deprecated 20.0.0 |
|
1957 | - */ |
|
1958 | - public function getTempManager() { |
|
1959 | - return $this->get(ITempManager::class); |
|
1960 | - } |
|
1961 | - |
|
1962 | - /** |
|
1963 | - * Get the app manager |
|
1964 | - * |
|
1965 | - * @return \OCP\App\IAppManager |
|
1966 | - * @deprecated 20.0.0 |
|
1967 | - */ |
|
1968 | - public function getAppManager() { |
|
1969 | - return $this->get(IAppManager::class); |
|
1970 | - } |
|
1971 | - |
|
1972 | - /** |
|
1973 | - * Creates a new mailer |
|
1974 | - * |
|
1975 | - * @return IMailer |
|
1976 | - * @deprecated 20.0.0 |
|
1977 | - */ |
|
1978 | - public function getMailer() { |
|
1979 | - return $this->get(IMailer::class); |
|
1980 | - } |
|
1981 | - |
|
1982 | - /** |
|
1983 | - * Get the webroot |
|
1984 | - * |
|
1985 | - * @return string |
|
1986 | - * @deprecated 20.0.0 |
|
1987 | - */ |
|
1988 | - public function getWebRoot() { |
|
1989 | - return $this->webRoot; |
|
1990 | - } |
|
1991 | - |
|
1992 | - /** |
|
1993 | - * @return \OC\OCSClient |
|
1994 | - * @deprecated 20.0.0 |
|
1995 | - */ |
|
1996 | - public function getOcsClient() { |
|
1997 | - return $this->get('OcsClient'); |
|
1998 | - } |
|
1999 | - |
|
2000 | - /** |
|
2001 | - * @return IDateTimeZone |
|
2002 | - * @deprecated 20.0.0 |
|
2003 | - */ |
|
2004 | - public function getDateTimeZone() { |
|
2005 | - return $this->get(IDateTimeZone::class); |
|
2006 | - } |
|
2007 | - |
|
2008 | - /** |
|
2009 | - * @return IDateTimeFormatter |
|
2010 | - * @deprecated 20.0.0 |
|
2011 | - */ |
|
2012 | - public function getDateTimeFormatter() { |
|
2013 | - return $this->get(IDateTimeFormatter::class); |
|
2014 | - } |
|
2015 | - |
|
2016 | - /** |
|
2017 | - * @return IMountProviderCollection |
|
2018 | - * @deprecated 20.0.0 |
|
2019 | - */ |
|
2020 | - public function getMountProviderCollection() { |
|
2021 | - return $this->get(IMountProviderCollection::class); |
|
2022 | - } |
|
2023 | - |
|
2024 | - /** |
|
2025 | - * Get the IniWrapper |
|
2026 | - * |
|
2027 | - * @return IniGetWrapper |
|
2028 | - * @deprecated 20.0.0 |
|
2029 | - */ |
|
2030 | - public function getIniWrapper() { |
|
2031 | - return $this->get(IniGetWrapper::class); |
|
2032 | - } |
|
2033 | - |
|
2034 | - /** |
|
2035 | - * @return \OCP\Command\IBus |
|
2036 | - * @deprecated 20.0.0 |
|
2037 | - */ |
|
2038 | - public function getCommandBus() { |
|
2039 | - return $this->get(IBus::class); |
|
2040 | - } |
|
2041 | - |
|
2042 | - /** |
|
2043 | - * Get the trusted domain helper |
|
2044 | - * |
|
2045 | - * @return TrustedDomainHelper |
|
2046 | - * @deprecated 20.0.0 |
|
2047 | - */ |
|
2048 | - public function getTrustedDomainHelper() { |
|
2049 | - return $this->get(TrustedDomainHelper::class); |
|
2050 | - } |
|
2051 | - |
|
2052 | - /** |
|
2053 | - * Get the locking provider |
|
2054 | - * |
|
2055 | - * @return ILockingProvider |
|
2056 | - * @since 8.1.0 |
|
2057 | - * @deprecated 20.0.0 |
|
2058 | - */ |
|
2059 | - public function getLockingProvider() { |
|
2060 | - return $this->get(ILockingProvider::class); |
|
2061 | - } |
|
2062 | - |
|
2063 | - /** |
|
2064 | - * @return IMountManager |
|
2065 | - * @deprecated 20.0.0 |
|
2066 | - **/ |
|
2067 | - public function getMountManager() { |
|
2068 | - return $this->get(IMountManager::class); |
|
2069 | - } |
|
2070 | - |
|
2071 | - /** |
|
2072 | - * @return IUserMountCache |
|
2073 | - * @deprecated 20.0.0 |
|
2074 | - */ |
|
2075 | - public function getUserMountCache() { |
|
2076 | - return $this->get(IUserMountCache::class); |
|
2077 | - } |
|
2078 | - |
|
2079 | - /** |
|
2080 | - * Get the MimeTypeDetector |
|
2081 | - * |
|
2082 | - * @return IMimeTypeDetector |
|
2083 | - * @deprecated 20.0.0 |
|
2084 | - */ |
|
2085 | - public function getMimeTypeDetector() { |
|
2086 | - return $this->get(IMimeTypeDetector::class); |
|
2087 | - } |
|
2088 | - |
|
2089 | - /** |
|
2090 | - * Get the MimeTypeLoader |
|
2091 | - * |
|
2092 | - * @return IMimeTypeLoader |
|
2093 | - * @deprecated 20.0.0 |
|
2094 | - */ |
|
2095 | - public function getMimeTypeLoader() { |
|
2096 | - return $this->get(IMimeTypeLoader::class); |
|
2097 | - } |
|
2098 | - |
|
2099 | - /** |
|
2100 | - * Get the manager of all the capabilities |
|
2101 | - * |
|
2102 | - * @return CapabilitiesManager |
|
2103 | - * @deprecated 20.0.0 |
|
2104 | - */ |
|
2105 | - public function getCapabilitiesManager() { |
|
2106 | - return $this->get(CapabilitiesManager::class); |
|
2107 | - } |
|
2108 | - |
|
2109 | - /** |
|
2110 | - * Get the EventDispatcher |
|
2111 | - * |
|
2112 | - * @return EventDispatcherInterface |
|
2113 | - * @since 8.2.0 |
|
2114 | - * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher |
|
2115 | - */ |
|
2116 | - public function getEventDispatcher() { |
|
2117 | - return $this->get(\OC\EventDispatcher\SymfonyAdapter::class); |
|
2118 | - } |
|
2119 | - |
|
2120 | - /** |
|
2121 | - * Get the Notification Manager |
|
2122 | - * |
|
2123 | - * @return \OCP\Notification\IManager |
|
2124 | - * @since 8.2.0 |
|
2125 | - * @deprecated 20.0.0 |
|
2126 | - */ |
|
2127 | - public function getNotificationManager() { |
|
2128 | - return $this->get(\OCP\Notification\IManager::class); |
|
2129 | - } |
|
2130 | - |
|
2131 | - /** |
|
2132 | - * @return ICommentsManager |
|
2133 | - * @deprecated 20.0.0 |
|
2134 | - */ |
|
2135 | - public function getCommentsManager() { |
|
2136 | - return $this->get(ICommentsManager::class); |
|
2137 | - } |
|
2138 | - |
|
2139 | - /** |
|
2140 | - * @return \OCA\Theming\ThemingDefaults |
|
2141 | - * @deprecated 20.0.0 |
|
2142 | - */ |
|
2143 | - public function getThemingDefaults() { |
|
2144 | - return $this->get('ThemingDefaults'); |
|
2145 | - } |
|
2146 | - |
|
2147 | - /** |
|
2148 | - * @return \OC\IntegrityCheck\Checker |
|
2149 | - * @deprecated 20.0.0 |
|
2150 | - */ |
|
2151 | - public function getIntegrityCodeChecker() { |
|
2152 | - return $this->get('IntegrityCodeChecker'); |
|
2153 | - } |
|
2154 | - |
|
2155 | - /** |
|
2156 | - * @return \OC\Session\CryptoWrapper |
|
2157 | - * @deprecated 20.0.0 |
|
2158 | - */ |
|
2159 | - public function getSessionCryptoWrapper() { |
|
2160 | - return $this->get('CryptoWrapper'); |
|
2161 | - } |
|
2162 | - |
|
2163 | - /** |
|
2164 | - * @return CsrfTokenManager |
|
2165 | - * @deprecated 20.0.0 |
|
2166 | - */ |
|
2167 | - public function getCsrfTokenManager() { |
|
2168 | - return $this->get(CsrfTokenManager::class); |
|
2169 | - } |
|
2170 | - |
|
2171 | - /** |
|
2172 | - * @return Throttler |
|
2173 | - * @deprecated 20.0.0 |
|
2174 | - */ |
|
2175 | - public function getBruteForceThrottler() { |
|
2176 | - return $this->get(Throttler::class); |
|
2177 | - } |
|
2178 | - |
|
2179 | - /** |
|
2180 | - * @return IContentSecurityPolicyManager |
|
2181 | - * @deprecated 20.0.0 |
|
2182 | - */ |
|
2183 | - public function getContentSecurityPolicyManager() { |
|
2184 | - return $this->get(ContentSecurityPolicyManager::class); |
|
2185 | - } |
|
2186 | - |
|
2187 | - /** |
|
2188 | - * @return ContentSecurityPolicyNonceManager |
|
2189 | - * @deprecated 20.0.0 |
|
2190 | - */ |
|
2191 | - public function getContentSecurityPolicyNonceManager() { |
|
2192 | - return $this->get(ContentSecurityPolicyNonceManager::class); |
|
2193 | - } |
|
2194 | - |
|
2195 | - /** |
|
2196 | - * Not a public API as of 8.2, wait for 9.0 |
|
2197 | - * |
|
2198 | - * @return \OCA\Files_External\Service\BackendService |
|
2199 | - * @deprecated 20.0.0 |
|
2200 | - */ |
|
2201 | - public function getStoragesBackendService() { |
|
2202 | - return $this->get(BackendService::class); |
|
2203 | - } |
|
2204 | - |
|
2205 | - /** |
|
2206 | - * Not a public API as of 8.2, wait for 9.0 |
|
2207 | - * |
|
2208 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
2209 | - * @deprecated 20.0.0 |
|
2210 | - */ |
|
2211 | - public function getGlobalStoragesService() { |
|
2212 | - return $this->get(GlobalStoragesService::class); |
|
2213 | - } |
|
2214 | - |
|
2215 | - /** |
|
2216 | - * Not a public API as of 8.2, wait for 9.0 |
|
2217 | - * |
|
2218 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
2219 | - * @deprecated 20.0.0 |
|
2220 | - */ |
|
2221 | - public function getUserGlobalStoragesService() { |
|
2222 | - return $this->get(UserGlobalStoragesService::class); |
|
2223 | - } |
|
2224 | - |
|
2225 | - /** |
|
2226 | - * Not a public API as of 8.2, wait for 9.0 |
|
2227 | - * |
|
2228 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
2229 | - * @deprecated 20.0.0 |
|
2230 | - */ |
|
2231 | - public function getUserStoragesService() { |
|
2232 | - return $this->get(UserStoragesService::class); |
|
2233 | - } |
|
2234 | - |
|
2235 | - /** |
|
2236 | - * @return \OCP\Share\IManager |
|
2237 | - * @deprecated 20.0.0 |
|
2238 | - */ |
|
2239 | - public function getShareManager() { |
|
2240 | - return $this->get(\OCP\Share\IManager::class); |
|
2241 | - } |
|
2242 | - |
|
2243 | - /** |
|
2244 | - * @return \OCP\Collaboration\Collaborators\ISearch |
|
2245 | - * @deprecated 20.0.0 |
|
2246 | - */ |
|
2247 | - public function getCollaboratorSearch() { |
|
2248 | - return $this->get(\OCP\Collaboration\Collaborators\ISearch::class); |
|
2249 | - } |
|
2250 | - |
|
2251 | - /** |
|
2252 | - * @return \OCP\Collaboration\AutoComplete\IManager |
|
2253 | - * @deprecated 20.0.0 |
|
2254 | - */ |
|
2255 | - public function getAutoCompleteManager() { |
|
2256 | - return $this->get(IManager::class); |
|
2257 | - } |
|
2258 | - |
|
2259 | - /** |
|
2260 | - * Returns the LDAP Provider |
|
2261 | - * |
|
2262 | - * @return \OCP\LDAP\ILDAPProvider |
|
2263 | - * @deprecated 20.0.0 |
|
2264 | - */ |
|
2265 | - public function getLDAPProvider() { |
|
2266 | - return $this->get('LDAPProvider'); |
|
2267 | - } |
|
2268 | - |
|
2269 | - /** |
|
2270 | - * @return \OCP\Settings\IManager |
|
2271 | - * @deprecated 20.0.0 |
|
2272 | - */ |
|
2273 | - public function getSettingsManager() { |
|
2274 | - return $this->get(\OC\Settings\Manager::class); |
|
2275 | - } |
|
2276 | - |
|
2277 | - /** |
|
2278 | - * @return \OCP\Files\IAppData |
|
2279 | - * @deprecated 20.0.0 Use get(\OCP\Files\AppData\IAppDataFactory::class)->get($app) instead |
|
2280 | - */ |
|
2281 | - public function getAppDataDir($app) { |
|
2282 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
2283 | - $factory = $this->get(\OC\Files\AppData\Factory::class); |
|
2284 | - return $factory->get($app); |
|
2285 | - } |
|
2286 | - |
|
2287 | - /** |
|
2288 | - * @return \OCP\Lockdown\ILockdownManager |
|
2289 | - * @deprecated 20.0.0 |
|
2290 | - */ |
|
2291 | - public function getLockdownManager() { |
|
2292 | - return $this->get('LockdownManager'); |
|
2293 | - } |
|
2294 | - |
|
2295 | - /** |
|
2296 | - * @return \OCP\Federation\ICloudIdManager |
|
2297 | - * @deprecated 20.0.0 |
|
2298 | - */ |
|
2299 | - public function getCloudIdManager() { |
|
2300 | - return $this->get(ICloudIdManager::class); |
|
2301 | - } |
|
2302 | - |
|
2303 | - /** |
|
2304 | - * @return \OCP\GlobalScale\IConfig |
|
2305 | - * @deprecated 20.0.0 |
|
2306 | - */ |
|
2307 | - public function getGlobalScaleConfig() { |
|
2308 | - return $this->get(IConfig::class); |
|
2309 | - } |
|
2310 | - |
|
2311 | - /** |
|
2312 | - * @return \OCP\Federation\ICloudFederationProviderManager |
|
2313 | - * @deprecated 20.0.0 |
|
2314 | - */ |
|
2315 | - public function getCloudFederationProviderManager() { |
|
2316 | - return $this->get(ICloudFederationProviderManager::class); |
|
2317 | - } |
|
2318 | - |
|
2319 | - /** |
|
2320 | - * @return \OCP\Remote\Api\IApiFactory |
|
2321 | - * @deprecated 20.0.0 |
|
2322 | - */ |
|
2323 | - public function getRemoteApiFactory() { |
|
2324 | - return $this->get(IApiFactory::class); |
|
2325 | - } |
|
2326 | - |
|
2327 | - /** |
|
2328 | - * @return \OCP\Federation\ICloudFederationFactory |
|
2329 | - * @deprecated 20.0.0 |
|
2330 | - */ |
|
2331 | - public function getCloudFederationFactory() { |
|
2332 | - return $this->get(ICloudFederationFactory::class); |
|
2333 | - } |
|
2334 | - |
|
2335 | - /** |
|
2336 | - * @return \OCP\Remote\IInstanceFactory |
|
2337 | - * @deprecated 20.0.0 |
|
2338 | - */ |
|
2339 | - public function getRemoteInstanceFactory() { |
|
2340 | - return $this->get(IInstanceFactory::class); |
|
2341 | - } |
|
2342 | - |
|
2343 | - /** |
|
2344 | - * @return IStorageFactory |
|
2345 | - * @deprecated 20.0.0 |
|
2346 | - */ |
|
2347 | - public function getStorageFactory() { |
|
2348 | - return $this->get(IStorageFactory::class); |
|
2349 | - } |
|
2350 | - |
|
2351 | - /** |
|
2352 | - * Get the Preview GeneratorHelper |
|
2353 | - * |
|
2354 | - * @return GeneratorHelper |
|
2355 | - * @since 17.0.0 |
|
2356 | - * @deprecated 20.0.0 |
|
2357 | - */ |
|
2358 | - public function getGeneratorHelper() { |
|
2359 | - return $this->get(\OC\Preview\GeneratorHelper::class); |
|
2360 | - } |
|
2361 | - |
|
2362 | - private function registerDeprecatedAlias(string $alias, string $target) { |
|
2363 | - $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) { |
|
2364 | - try { |
|
2365 | - /** @var LoggerInterface $logger */ |
|
2366 | - $logger = $container->get(LoggerInterface::class); |
|
2367 | - $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
2368 | - } catch (ContainerExceptionInterface $e) { |
|
2369 | - // Could not get logger. Continue |
|
2370 | - } |
|
2371 | - |
|
2372 | - return $container->get($target); |
|
2373 | - }, false); |
|
2374 | - } |
|
1204 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
1205 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
1206 | + $classExists = true; |
|
1207 | + } else { |
|
1208 | + $classExists = false; |
|
1209 | + } |
|
1210 | + |
|
1211 | + if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValue('installed', false) && $c->get(IAppManager::class)->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
1212 | + $imageManager = new ImageManager( |
|
1213 | + $c->get(\OCP\IConfig::class), |
|
1214 | + $c->getAppDataDir('theming'), |
|
1215 | + $c->get(IURLGenerator::class), |
|
1216 | + $this->get(ICacheFactory::class), |
|
1217 | + $this->get(ILogger::class), |
|
1218 | + $this->get(ITempManager::class) |
|
1219 | + ); |
|
1220 | + return new ThemingDefaults( |
|
1221 | + $c->get(\OCP\IConfig::class), |
|
1222 | + $c->getL10N('theming'), |
|
1223 | + $c->get(IUserSession::class), |
|
1224 | + $c->get(IURLGenerator::class), |
|
1225 | + $c->get(ICacheFactory::class), |
|
1226 | + new Util($c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming'), $imageManager), |
|
1227 | + $imageManager, |
|
1228 | + $c->get(IAppManager::class), |
|
1229 | + $c->get(INavigationManager::class) |
|
1230 | + ); |
|
1231 | + } |
|
1232 | + return new \OC_Defaults(); |
|
1233 | + }); |
|
1234 | + $this->registerService(JSCombiner::class, function (Server $c) { |
|
1235 | + return new JSCombiner( |
|
1236 | + $c->getAppDataDir('js'), |
|
1237 | + $c->get(IURLGenerator::class), |
|
1238 | + $this->get(ICacheFactory::class), |
|
1239 | + $c->get(SystemConfig::class), |
|
1240 | + $c->get(LoggerInterface::class) |
|
1241 | + ); |
|
1242 | + }); |
|
1243 | + $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
1244 | + /** @deprecated 19.0.0 */ |
|
1245 | + $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
|
1246 | + $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
|
1247 | + |
|
1248 | + $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
1249 | + // FIXME: Instantiated here due to cyclic dependency |
|
1250 | + $request = new Request( |
|
1251 | + [ |
|
1252 | + 'get' => $_GET, |
|
1253 | + 'post' => $_POST, |
|
1254 | + 'files' => $_FILES, |
|
1255 | + 'server' => $_SERVER, |
|
1256 | + 'env' => $_ENV, |
|
1257 | + 'cookies' => $_COOKIE, |
|
1258 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1259 | + ? $_SERVER['REQUEST_METHOD'] |
|
1260 | + : null, |
|
1261 | + ], |
|
1262 | + $c->get(IRequestId::class), |
|
1263 | + $c->get(\OCP\IConfig::class) |
|
1264 | + ); |
|
1265 | + |
|
1266 | + return new CryptoWrapper( |
|
1267 | + $c->get(\OCP\IConfig::class), |
|
1268 | + $c->get(ICrypto::class), |
|
1269 | + $c->get(ISecureRandom::class), |
|
1270 | + $request |
|
1271 | + ); |
|
1272 | + }); |
|
1273 | + /** @deprecated 19.0.0 */ |
|
1274 | + $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class); |
|
1275 | + $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
1276 | + return new SessionStorage($c->get(ISession::class)); |
|
1277 | + }); |
|
1278 | + $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
1279 | + /** @deprecated 19.0.0 */ |
|
1280 | + $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class); |
|
1281 | + |
|
1282 | + $this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) { |
|
1283 | + $config = $c->get(\OCP\IConfig::class); |
|
1284 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1285 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
1286 | + $factory = new $factoryClass($this); |
|
1287 | + |
|
1288 | + $manager = new \OC\Share20\Manager( |
|
1289 | + $c->get(LoggerInterface::class), |
|
1290 | + $c->get(\OCP\IConfig::class), |
|
1291 | + $c->get(ISecureRandom::class), |
|
1292 | + $c->get(IHasher::class), |
|
1293 | + $c->get(IMountManager::class), |
|
1294 | + $c->get(IGroupManager::class), |
|
1295 | + $c->getL10N('lib'), |
|
1296 | + $c->get(IFactory::class), |
|
1297 | + $factory, |
|
1298 | + $c->get(IUserManager::class), |
|
1299 | + $c->get(IRootFolder::class), |
|
1300 | + $c->get(SymfonyAdapter::class), |
|
1301 | + $c->get(IMailer::class), |
|
1302 | + $c->get(IURLGenerator::class), |
|
1303 | + $c->get('ThemingDefaults'), |
|
1304 | + $c->get(IEventDispatcher::class), |
|
1305 | + $c->get(IUserSession::class), |
|
1306 | + $c->get(KnownUserService::class) |
|
1307 | + ); |
|
1308 | + |
|
1309 | + return $manager; |
|
1310 | + }); |
|
1311 | + /** @deprecated 19.0.0 */ |
|
1312 | + $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class); |
|
1313 | + |
|
1314 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
1315 | + $instance = new Collaboration\Collaborators\Search($c); |
|
1316 | + |
|
1317 | + // register default plugins |
|
1318 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1319 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1320 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1321 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1322 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
1323 | + |
|
1324 | + return $instance; |
|
1325 | + }); |
|
1326 | + /** @deprecated 19.0.0 */ |
|
1327 | + $this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1328 | + $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
1329 | + |
|
1330 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1331 | + |
|
1332 | + $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
1333 | + $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
1334 | + |
|
1335 | + $this->registerAlias(IReferenceManager::class, ReferenceManager::class); |
|
1336 | + |
|
1337 | + $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
|
1338 | + $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
|
1339 | + $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
1340 | + return new \OC\Files\AppData\Factory( |
|
1341 | + $c->get(IRootFolder::class), |
|
1342 | + $c->get(SystemConfig::class) |
|
1343 | + ); |
|
1344 | + }); |
|
1345 | + |
|
1346 | + $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
1347 | + return new LockdownManager(function () use ($c) { |
|
1348 | + return $c->get(ISession::class); |
|
1349 | + }); |
|
1350 | + }); |
|
1351 | + |
|
1352 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
1353 | + return new DiscoveryService( |
|
1354 | + $c->get(ICacheFactory::class), |
|
1355 | + $c->get(IClientService::class) |
|
1356 | + ); |
|
1357 | + }); |
|
1358 | + |
|
1359 | + $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
1360 | + return new CloudIdManager( |
|
1361 | + $c->get(\OCP\Contacts\IManager::class), |
|
1362 | + $c->get(IURLGenerator::class), |
|
1363 | + $c->get(IUserManager::class), |
|
1364 | + $c->get(ICacheFactory::class), |
|
1365 | + $c->get(IEventDispatcher::class), |
|
1366 | + ); |
|
1367 | + }); |
|
1368 | + |
|
1369 | + $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
1370 | + |
|
1371 | + $this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) { |
|
1372 | + return new CloudFederationProviderManager( |
|
1373 | + $c->get(IAppManager::class), |
|
1374 | + $c->get(IClientService::class), |
|
1375 | + $c->get(ICloudIdManager::class), |
|
1376 | + $c->get(LoggerInterface::class) |
|
1377 | + ); |
|
1378 | + }); |
|
1379 | + |
|
1380 | + $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1381 | + return new CloudFederationFactory(); |
|
1382 | + }); |
|
1383 | + |
|
1384 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1385 | + /** @deprecated 19.0.0 */ |
|
1386 | + $this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1387 | + |
|
1388 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1389 | + /** @deprecated 19.0.0 */ |
|
1390 | + $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1391 | + |
|
1392 | + $this->registerService(Defaults::class, function (Server $c) { |
|
1393 | + return new Defaults( |
|
1394 | + $c->getThemingDefaults() |
|
1395 | + ); |
|
1396 | + }); |
|
1397 | + /** @deprecated 19.0.0 */ |
|
1398 | + $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class); |
|
1399 | + |
|
1400 | + $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
1401 | + return $c->get(\OCP\IUserSession::class)->getSession(); |
|
1402 | + }, false); |
|
1403 | + |
|
1404 | + $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
1405 | + return new ShareHelper( |
|
1406 | + $c->get(\OCP\Share\IManager::class) |
|
1407 | + ); |
|
1408 | + }); |
|
1409 | + |
|
1410 | + $this->registerService(Installer::class, function (ContainerInterface $c) { |
|
1411 | + return new Installer( |
|
1412 | + $c->get(AppFetcher::class), |
|
1413 | + $c->get(IClientService::class), |
|
1414 | + $c->get(ITempManager::class), |
|
1415 | + $c->get(LoggerInterface::class), |
|
1416 | + $c->get(\OCP\IConfig::class), |
|
1417 | + \OC::$CLI |
|
1418 | + ); |
|
1419 | + }); |
|
1420 | + |
|
1421 | + $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
1422 | + return new ApiFactory($c->get(IClientService::class)); |
|
1423 | + }); |
|
1424 | + |
|
1425 | + $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
1426 | + $memcacheFactory = $c->get(ICacheFactory::class); |
|
1427 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
|
1428 | + }); |
|
1429 | + |
|
1430 | + $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1431 | + $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
1432 | + |
|
1433 | + $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
1434 | + |
|
1435 | + $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
1436 | + |
|
1437 | + $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
1438 | + |
|
1439 | + $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
1440 | + |
|
1441 | + $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
1442 | + |
|
1443 | + $this->registerAlias(\OCP\IEmojiHelper::class, \OC\EmojiHelper::class); |
|
1444 | + |
|
1445 | + $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
1446 | + |
|
1447 | + $this->registerAlias(IBroker::class, Broker::class); |
|
1448 | + |
|
1449 | + $this->registerAlias(IMetadataManager::class, MetadataManager::class); |
|
1450 | + |
|
1451 | + $this->registerAlias(\OCP\Files\AppData\IAppDataFactory::class, \OC\Files\AppData\Factory::class); |
|
1452 | + |
|
1453 | + $this->registerAlias(IBinaryFinder::class, BinaryFinder::class); |
|
1454 | + |
|
1455 | + $this->registerAlias(\OCP\Share\IPublicShareTemplateFactory::class, \OC\Share20\PublicShareTemplateFactory::class); |
|
1456 | + |
|
1457 | + $this->connectDispatcher(); |
|
1458 | + } |
|
1459 | + |
|
1460 | + public function boot() { |
|
1461 | + /** @var HookConnector $hookConnector */ |
|
1462 | + $hookConnector = $this->get(HookConnector::class); |
|
1463 | + $hookConnector->viewToNode(); |
|
1464 | + } |
|
1465 | + |
|
1466 | + /** |
|
1467 | + * @return \OCP\Calendar\IManager |
|
1468 | + * @deprecated 20.0.0 |
|
1469 | + */ |
|
1470 | + public function getCalendarManager() { |
|
1471 | + return $this->get(\OC\Calendar\Manager::class); |
|
1472 | + } |
|
1473 | + |
|
1474 | + /** |
|
1475 | + * @return \OCP\Calendar\Resource\IManager |
|
1476 | + * @deprecated 20.0.0 |
|
1477 | + */ |
|
1478 | + public function getCalendarResourceBackendManager() { |
|
1479 | + return $this->get(\OC\Calendar\Resource\Manager::class); |
|
1480 | + } |
|
1481 | + |
|
1482 | + /** |
|
1483 | + * @return \OCP\Calendar\Room\IManager |
|
1484 | + * @deprecated 20.0.0 |
|
1485 | + */ |
|
1486 | + public function getCalendarRoomBackendManager() { |
|
1487 | + return $this->get(\OC\Calendar\Room\Manager::class); |
|
1488 | + } |
|
1489 | + |
|
1490 | + private function connectDispatcher(): void { |
|
1491 | + /** @var IEventDispatcher $eventDispatcher */ |
|
1492 | + $eventDispatcher = $this->get(IEventDispatcher::class); |
|
1493 | + $eventDispatcher->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
1494 | + $eventDispatcher->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class); |
|
1495 | + $eventDispatcher->addServiceListener(UserChangedEvent::class, UserChangedListener::class); |
|
1496 | + $eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, BeforeUserDeletedListener::class); |
|
1497 | + } |
|
1498 | + |
|
1499 | + /** |
|
1500 | + * @return \OCP\Contacts\IManager |
|
1501 | + * @deprecated 20.0.0 |
|
1502 | + */ |
|
1503 | + public function getContactsManager() { |
|
1504 | + return $this->get(\OCP\Contacts\IManager::class); |
|
1505 | + } |
|
1506 | + |
|
1507 | + /** |
|
1508 | + * @return \OC\Encryption\Manager |
|
1509 | + * @deprecated 20.0.0 |
|
1510 | + */ |
|
1511 | + public function getEncryptionManager() { |
|
1512 | + return $this->get(\OCP\Encryption\IManager::class); |
|
1513 | + } |
|
1514 | + |
|
1515 | + /** |
|
1516 | + * @return \OC\Encryption\File |
|
1517 | + * @deprecated 20.0.0 |
|
1518 | + */ |
|
1519 | + public function getEncryptionFilesHelper() { |
|
1520 | + return $this->get(IFile::class); |
|
1521 | + } |
|
1522 | + |
|
1523 | + /** |
|
1524 | + * @return \OCP\Encryption\Keys\IStorage |
|
1525 | + * @deprecated 20.0.0 |
|
1526 | + */ |
|
1527 | + public function getEncryptionKeyStorage() { |
|
1528 | + return $this->get(IStorage::class); |
|
1529 | + } |
|
1530 | + |
|
1531 | + /** |
|
1532 | + * The current request object holding all information about the request |
|
1533 | + * currently being processed is returned from this method. |
|
1534 | + * In case the current execution was not initiated by a web request null is returned |
|
1535 | + * |
|
1536 | + * @return \OCP\IRequest |
|
1537 | + * @deprecated 20.0.0 |
|
1538 | + */ |
|
1539 | + public function getRequest() { |
|
1540 | + return $this->get(IRequest::class); |
|
1541 | + } |
|
1542 | + |
|
1543 | + /** |
|
1544 | + * Returns the preview manager which can create preview images for a given file |
|
1545 | + * |
|
1546 | + * @return IPreview |
|
1547 | + * @deprecated 20.0.0 |
|
1548 | + */ |
|
1549 | + public function getPreviewManager() { |
|
1550 | + return $this->get(IPreview::class); |
|
1551 | + } |
|
1552 | + |
|
1553 | + /** |
|
1554 | + * Returns the tag manager which can get and set tags for different object types |
|
1555 | + * |
|
1556 | + * @see \OCP\ITagManager::load() |
|
1557 | + * @return ITagManager |
|
1558 | + * @deprecated 20.0.0 |
|
1559 | + */ |
|
1560 | + public function getTagManager() { |
|
1561 | + return $this->get(ITagManager::class); |
|
1562 | + } |
|
1563 | + |
|
1564 | + /** |
|
1565 | + * Returns the system-tag manager |
|
1566 | + * |
|
1567 | + * @return ISystemTagManager |
|
1568 | + * |
|
1569 | + * @since 9.0.0 |
|
1570 | + * @deprecated 20.0.0 |
|
1571 | + */ |
|
1572 | + public function getSystemTagManager() { |
|
1573 | + return $this->get(ISystemTagManager::class); |
|
1574 | + } |
|
1575 | + |
|
1576 | + /** |
|
1577 | + * Returns the system-tag object mapper |
|
1578 | + * |
|
1579 | + * @return ISystemTagObjectMapper |
|
1580 | + * |
|
1581 | + * @since 9.0.0 |
|
1582 | + * @deprecated 20.0.0 |
|
1583 | + */ |
|
1584 | + public function getSystemTagObjectMapper() { |
|
1585 | + return $this->get(ISystemTagObjectMapper::class); |
|
1586 | + } |
|
1587 | + |
|
1588 | + /** |
|
1589 | + * Returns the avatar manager, used for avatar functionality |
|
1590 | + * |
|
1591 | + * @return IAvatarManager |
|
1592 | + * @deprecated 20.0.0 |
|
1593 | + */ |
|
1594 | + public function getAvatarManager() { |
|
1595 | + return $this->get(IAvatarManager::class); |
|
1596 | + } |
|
1597 | + |
|
1598 | + /** |
|
1599 | + * Returns the root folder of ownCloud's data directory |
|
1600 | + * |
|
1601 | + * @return IRootFolder |
|
1602 | + * @deprecated 20.0.0 |
|
1603 | + */ |
|
1604 | + public function getRootFolder() { |
|
1605 | + return $this->get(IRootFolder::class); |
|
1606 | + } |
|
1607 | + |
|
1608 | + /** |
|
1609 | + * Returns the root folder of ownCloud's data directory |
|
1610 | + * This is the lazy variant so this gets only initialized once it |
|
1611 | + * is actually used. |
|
1612 | + * |
|
1613 | + * @return IRootFolder |
|
1614 | + * @deprecated 20.0.0 |
|
1615 | + */ |
|
1616 | + public function getLazyRootFolder() { |
|
1617 | + return $this->get(IRootFolder::class); |
|
1618 | + } |
|
1619 | + |
|
1620 | + /** |
|
1621 | + * Returns a view to ownCloud's files folder |
|
1622 | + * |
|
1623 | + * @param string $userId user ID |
|
1624 | + * @return \OCP\Files\Folder|null |
|
1625 | + * @deprecated 20.0.0 |
|
1626 | + */ |
|
1627 | + public function getUserFolder($userId = null) { |
|
1628 | + if ($userId === null) { |
|
1629 | + $user = $this->get(IUserSession::class)->getUser(); |
|
1630 | + if (!$user) { |
|
1631 | + return null; |
|
1632 | + } |
|
1633 | + $userId = $user->getUID(); |
|
1634 | + } |
|
1635 | + $root = $this->get(IRootFolder::class); |
|
1636 | + return $root->getUserFolder($userId); |
|
1637 | + } |
|
1638 | + |
|
1639 | + /** |
|
1640 | + * @return \OC\User\Manager |
|
1641 | + * @deprecated 20.0.0 |
|
1642 | + */ |
|
1643 | + public function getUserManager() { |
|
1644 | + return $this->get(IUserManager::class); |
|
1645 | + } |
|
1646 | + |
|
1647 | + /** |
|
1648 | + * @return \OC\Group\Manager |
|
1649 | + * @deprecated 20.0.0 |
|
1650 | + */ |
|
1651 | + public function getGroupManager() { |
|
1652 | + return $this->get(IGroupManager::class); |
|
1653 | + } |
|
1654 | + |
|
1655 | + /** |
|
1656 | + * @return \OC\User\Session |
|
1657 | + * @deprecated 20.0.0 |
|
1658 | + */ |
|
1659 | + public function getUserSession() { |
|
1660 | + return $this->get(IUserSession::class); |
|
1661 | + } |
|
1662 | + |
|
1663 | + /** |
|
1664 | + * @return \OCP\ISession |
|
1665 | + * @deprecated 20.0.0 |
|
1666 | + */ |
|
1667 | + public function getSession() { |
|
1668 | + return $this->get(Session::class)->getSession(); |
|
1669 | + } |
|
1670 | + |
|
1671 | + /** |
|
1672 | + * @param \OCP\ISession $session |
|
1673 | + */ |
|
1674 | + public function setSession(\OCP\ISession $session) { |
|
1675 | + $this->get(SessionStorage::class)->setSession($session); |
|
1676 | + $this->get(Session::class)->setSession($session); |
|
1677 | + $this->get(Store::class)->setSession($session); |
|
1678 | + } |
|
1679 | + |
|
1680 | + /** |
|
1681 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1682 | + * @deprecated 20.0.0 |
|
1683 | + */ |
|
1684 | + public function getTwoFactorAuthManager() { |
|
1685 | + return $this->get(\OC\Authentication\TwoFactorAuth\Manager::class); |
|
1686 | + } |
|
1687 | + |
|
1688 | + /** |
|
1689 | + * @return \OC\NavigationManager |
|
1690 | + * @deprecated 20.0.0 |
|
1691 | + */ |
|
1692 | + public function getNavigationManager() { |
|
1693 | + return $this->get(INavigationManager::class); |
|
1694 | + } |
|
1695 | + |
|
1696 | + /** |
|
1697 | + * @return \OCP\IConfig |
|
1698 | + * @deprecated 20.0.0 |
|
1699 | + */ |
|
1700 | + public function getConfig() { |
|
1701 | + return $this->get(AllConfig::class); |
|
1702 | + } |
|
1703 | + |
|
1704 | + /** |
|
1705 | + * @return \OC\SystemConfig |
|
1706 | + * @deprecated 20.0.0 |
|
1707 | + */ |
|
1708 | + public function getSystemConfig() { |
|
1709 | + return $this->get(SystemConfig::class); |
|
1710 | + } |
|
1711 | + |
|
1712 | + /** |
|
1713 | + * Returns the app config manager |
|
1714 | + * |
|
1715 | + * @return IAppConfig |
|
1716 | + * @deprecated 20.0.0 |
|
1717 | + */ |
|
1718 | + public function getAppConfig() { |
|
1719 | + return $this->get(IAppConfig::class); |
|
1720 | + } |
|
1721 | + |
|
1722 | + /** |
|
1723 | + * @return IFactory |
|
1724 | + * @deprecated 20.0.0 |
|
1725 | + */ |
|
1726 | + public function getL10NFactory() { |
|
1727 | + return $this->get(IFactory::class); |
|
1728 | + } |
|
1729 | + |
|
1730 | + /** |
|
1731 | + * get an L10N instance |
|
1732 | + * |
|
1733 | + * @param string $app appid |
|
1734 | + * @param string $lang |
|
1735 | + * @return IL10N |
|
1736 | + * @deprecated 20.0.0 |
|
1737 | + */ |
|
1738 | + public function getL10N($app, $lang = null) { |
|
1739 | + return $this->get(IFactory::class)->get($app, $lang); |
|
1740 | + } |
|
1741 | + |
|
1742 | + /** |
|
1743 | + * @return IURLGenerator |
|
1744 | + * @deprecated 20.0.0 |
|
1745 | + */ |
|
1746 | + public function getURLGenerator() { |
|
1747 | + return $this->get(IURLGenerator::class); |
|
1748 | + } |
|
1749 | + |
|
1750 | + /** |
|
1751 | + * @return AppFetcher |
|
1752 | + * @deprecated 20.0.0 |
|
1753 | + */ |
|
1754 | + public function getAppFetcher() { |
|
1755 | + return $this->get(AppFetcher::class); |
|
1756 | + } |
|
1757 | + |
|
1758 | + /** |
|
1759 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1760 | + * getMemCacheFactory() instead. |
|
1761 | + * |
|
1762 | + * @return ICache |
|
1763 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1764 | + */ |
|
1765 | + public function getCache() { |
|
1766 | + return $this->get(ICache::class); |
|
1767 | + } |
|
1768 | + |
|
1769 | + /** |
|
1770 | + * Returns an \OCP\CacheFactory instance |
|
1771 | + * |
|
1772 | + * @return \OCP\ICacheFactory |
|
1773 | + * @deprecated 20.0.0 |
|
1774 | + */ |
|
1775 | + public function getMemCacheFactory() { |
|
1776 | + return $this->get(ICacheFactory::class); |
|
1777 | + } |
|
1778 | + |
|
1779 | + /** |
|
1780 | + * Returns an \OC\RedisFactory instance |
|
1781 | + * |
|
1782 | + * @return \OC\RedisFactory |
|
1783 | + * @deprecated 20.0.0 |
|
1784 | + */ |
|
1785 | + public function getGetRedisFactory() { |
|
1786 | + return $this->get('RedisFactory'); |
|
1787 | + } |
|
1788 | + |
|
1789 | + |
|
1790 | + /** |
|
1791 | + * Returns the current session |
|
1792 | + * |
|
1793 | + * @return \OCP\IDBConnection |
|
1794 | + * @deprecated 20.0.0 |
|
1795 | + */ |
|
1796 | + public function getDatabaseConnection() { |
|
1797 | + return $this->get(IDBConnection::class); |
|
1798 | + } |
|
1799 | + |
|
1800 | + /** |
|
1801 | + * Returns the activity manager |
|
1802 | + * |
|
1803 | + * @return \OCP\Activity\IManager |
|
1804 | + * @deprecated 20.0.0 |
|
1805 | + */ |
|
1806 | + public function getActivityManager() { |
|
1807 | + return $this->get(\OCP\Activity\IManager::class); |
|
1808 | + } |
|
1809 | + |
|
1810 | + /** |
|
1811 | + * Returns an job list for controlling background jobs |
|
1812 | + * |
|
1813 | + * @return IJobList |
|
1814 | + * @deprecated 20.0.0 |
|
1815 | + */ |
|
1816 | + public function getJobList() { |
|
1817 | + return $this->get(IJobList::class); |
|
1818 | + } |
|
1819 | + |
|
1820 | + /** |
|
1821 | + * Returns a logger instance |
|
1822 | + * |
|
1823 | + * @return ILogger |
|
1824 | + * @deprecated 20.0.0 |
|
1825 | + */ |
|
1826 | + public function getLogger() { |
|
1827 | + return $this->get(ILogger::class); |
|
1828 | + } |
|
1829 | + |
|
1830 | + /** |
|
1831 | + * @return ILogFactory |
|
1832 | + * @throws \OCP\AppFramework\QueryException |
|
1833 | + * @deprecated 20.0.0 |
|
1834 | + */ |
|
1835 | + public function getLogFactory() { |
|
1836 | + return $this->get(ILogFactory::class); |
|
1837 | + } |
|
1838 | + |
|
1839 | + /** |
|
1840 | + * Returns a router for generating and matching urls |
|
1841 | + * |
|
1842 | + * @return IRouter |
|
1843 | + * @deprecated 20.0.0 |
|
1844 | + */ |
|
1845 | + public function getRouter() { |
|
1846 | + return $this->get(IRouter::class); |
|
1847 | + } |
|
1848 | + |
|
1849 | + /** |
|
1850 | + * Returns a search instance |
|
1851 | + * |
|
1852 | + * @return ISearch |
|
1853 | + * @deprecated 20.0.0 |
|
1854 | + */ |
|
1855 | + public function getSearch() { |
|
1856 | + return $this->get(ISearch::class); |
|
1857 | + } |
|
1858 | + |
|
1859 | + /** |
|
1860 | + * Returns a SecureRandom instance |
|
1861 | + * |
|
1862 | + * @return \OCP\Security\ISecureRandom |
|
1863 | + * @deprecated 20.0.0 |
|
1864 | + */ |
|
1865 | + public function getSecureRandom() { |
|
1866 | + return $this->get(ISecureRandom::class); |
|
1867 | + } |
|
1868 | + |
|
1869 | + /** |
|
1870 | + * Returns a Crypto instance |
|
1871 | + * |
|
1872 | + * @return ICrypto |
|
1873 | + * @deprecated 20.0.0 |
|
1874 | + */ |
|
1875 | + public function getCrypto() { |
|
1876 | + return $this->get(ICrypto::class); |
|
1877 | + } |
|
1878 | + |
|
1879 | + /** |
|
1880 | + * Returns a Hasher instance |
|
1881 | + * |
|
1882 | + * @return IHasher |
|
1883 | + * @deprecated 20.0.0 |
|
1884 | + */ |
|
1885 | + public function getHasher() { |
|
1886 | + return $this->get(IHasher::class); |
|
1887 | + } |
|
1888 | + |
|
1889 | + /** |
|
1890 | + * Returns a CredentialsManager instance |
|
1891 | + * |
|
1892 | + * @return ICredentialsManager |
|
1893 | + * @deprecated 20.0.0 |
|
1894 | + */ |
|
1895 | + public function getCredentialsManager() { |
|
1896 | + return $this->get(ICredentialsManager::class); |
|
1897 | + } |
|
1898 | + |
|
1899 | + /** |
|
1900 | + * Get the certificate manager |
|
1901 | + * |
|
1902 | + * @return \OCP\ICertificateManager |
|
1903 | + */ |
|
1904 | + public function getCertificateManager() { |
|
1905 | + return $this->get(ICertificateManager::class); |
|
1906 | + } |
|
1907 | + |
|
1908 | + /** |
|
1909 | + * Returns an instance of the HTTP client service |
|
1910 | + * |
|
1911 | + * @return IClientService |
|
1912 | + * @deprecated 20.0.0 |
|
1913 | + */ |
|
1914 | + public function getHTTPClientService() { |
|
1915 | + return $this->get(IClientService::class); |
|
1916 | + } |
|
1917 | + |
|
1918 | + /** |
|
1919 | + * Create a new event source |
|
1920 | + * |
|
1921 | + * @return \OCP\IEventSource |
|
1922 | + * @deprecated 20.0.0 |
|
1923 | + */ |
|
1924 | + public function createEventSource() { |
|
1925 | + return new \OC_EventSource(); |
|
1926 | + } |
|
1927 | + |
|
1928 | + /** |
|
1929 | + * Get the active event logger |
|
1930 | + * |
|
1931 | + * The returned logger only logs data when debug mode is enabled |
|
1932 | + * |
|
1933 | + * @return IEventLogger |
|
1934 | + * @deprecated 20.0.0 |
|
1935 | + */ |
|
1936 | + public function getEventLogger() { |
|
1937 | + return $this->get(IEventLogger::class); |
|
1938 | + } |
|
1939 | + |
|
1940 | + /** |
|
1941 | + * Get the active query logger |
|
1942 | + * |
|
1943 | + * The returned logger only logs data when debug mode is enabled |
|
1944 | + * |
|
1945 | + * @return IQueryLogger |
|
1946 | + * @deprecated 20.0.0 |
|
1947 | + */ |
|
1948 | + public function getQueryLogger() { |
|
1949 | + return $this->get(IQueryLogger::class); |
|
1950 | + } |
|
1951 | + |
|
1952 | + /** |
|
1953 | + * Get the manager for temporary files and folders |
|
1954 | + * |
|
1955 | + * @return \OCP\ITempManager |
|
1956 | + * @deprecated 20.0.0 |
|
1957 | + */ |
|
1958 | + public function getTempManager() { |
|
1959 | + return $this->get(ITempManager::class); |
|
1960 | + } |
|
1961 | + |
|
1962 | + /** |
|
1963 | + * Get the app manager |
|
1964 | + * |
|
1965 | + * @return \OCP\App\IAppManager |
|
1966 | + * @deprecated 20.0.0 |
|
1967 | + */ |
|
1968 | + public function getAppManager() { |
|
1969 | + return $this->get(IAppManager::class); |
|
1970 | + } |
|
1971 | + |
|
1972 | + /** |
|
1973 | + * Creates a new mailer |
|
1974 | + * |
|
1975 | + * @return IMailer |
|
1976 | + * @deprecated 20.0.0 |
|
1977 | + */ |
|
1978 | + public function getMailer() { |
|
1979 | + return $this->get(IMailer::class); |
|
1980 | + } |
|
1981 | + |
|
1982 | + /** |
|
1983 | + * Get the webroot |
|
1984 | + * |
|
1985 | + * @return string |
|
1986 | + * @deprecated 20.0.0 |
|
1987 | + */ |
|
1988 | + public function getWebRoot() { |
|
1989 | + return $this->webRoot; |
|
1990 | + } |
|
1991 | + |
|
1992 | + /** |
|
1993 | + * @return \OC\OCSClient |
|
1994 | + * @deprecated 20.0.0 |
|
1995 | + */ |
|
1996 | + public function getOcsClient() { |
|
1997 | + return $this->get('OcsClient'); |
|
1998 | + } |
|
1999 | + |
|
2000 | + /** |
|
2001 | + * @return IDateTimeZone |
|
2002 | + * @deprecated 20.0.0 |
|
2003 | + */ |
|
2004 | + public function getDateTimeZone() { |
|
2005 | + return $this->get(IDateTimeZone::class); |
|
2006 | + } |
|
2007 | + |
|
2008 | + /** |
|
2009 | + * @return IDateTimeFormatter |
|
2010 | + * @deprecated 20.0.0 |
|
2011 | + */ |
|
2012 | + public function getDateTimeFormatter() { |
|
2013 | + return $this->get(IDateTimeFormatter::class); |
|
2014 | + } |
|
2015 | + |
|
2016 | + /** |
|
2017 | + * @return IMountProviderCollection |
|
2018 | + * @deprecated 20.0.0 |
|
2019 | + */ |
|
2020 | + public function getMountProviderCollection() { |
|
2021 | + return $this->get(IMountProviderCollection::class); |
|
2022 | + } |
|
2023 | + |
|
2024 | + /** |
|
2025 | + * Get the IniWrapper |
|
2026 | + * |
|
2027 | + * @return IniGetWrapper |
|
2028 | + * @deprecated 20.0.0 |
|
2029 | + */ |
|
2030 | + public function getIniWrapper() { |
|
2031 | + return $this->get(IniGetWrapper::class); |
|
2032 | + } |
|
2033 | + |
|
2034 | + /** |
|
2035 | + * @return \OCP\Command\IBus |
|
2036 | + * @deprecated 20.0.0 |
|
2037 | + */ |
|
2038 | + public function getCommandBus() { |
|
2039 | + return $this->get(IBus::class); |
|
2040 | + } |
|
2041 | + |
|
2042 | + /** |
|
2043 | + * Get the trusted domain helper |
|
2044 | + * |
|
2045 | + * @return TrustedDomainHelper |
|
2046 | + * @deprecated 20.0.0 |
|
2047 | + */ |
|
2048 | + public function getTrustedDomainHelper() { |
|
2049 | + return $this->get(TrustedDomainHelper::class); |
|
2050 | + } |
|
2051 | + |
|
2052 | + /** |
|
2053 | + * Get the locking provider |
|
2054 | + * |
|
2055 | + * @return ILockingProvider |
|
2056 | + * @since 8.1.0 |
|
2057 | + * @deprecated 20.0.0 |
|
2058 | + */ |
|
2059 | + public function getLockingProvider() { |
|
2060 | + return $this->get(ILockingProvider::class); |
|
2061 | + } |
|
2062 | + |
|
2063 | + /** |
|
2064 | + * @return IMountManager |
|
2065 | + * @deprecated 20.0.0 |
|
2066 | + **/ |
|
2067 | + public function getMountManager() { |
|
2068 | + return $this->get(IMountManager::class); |
|
2069 | + } |
|
2070 | + |
|
2071 | + /** |
|
2072 | + * @return IUserMountCache |
|
2073 | + * @deprecated 20.0.0 |
|
2074 | + */ |
|
2075 | + public function getUserMountCache() { |
|
2076 | + return $this->get(IUserMountCache::class); |
|
2077 | + } |
|
2078 | + |
|
2079 | + /** |
|
2080 | + * Get the MimeTypeDetector |
|
2081 | + * |
|
2082 | + * @return IMimeTypeDetector |
|
2083 | + * @deprecated 20.0.0 |
|
2084 | + */ |
|
2085 | + public function getMimeTypeDetector() { |
|
2086 | + return $this->get(IMimeTypeDetector::class); |
|
2087 | + } |
|
2088 | + |
|
2089 | + /** |
|
2090 | + * Get the MimeTypeLoader |
|
2091 | + * |
|
2092 | + * @return IMimeTypeLoader |
|
2093 | + * @deprecated 20.0.0 |
|
2094 | + */ |
|
2095 | + public function getMimeTypeLoader() { |
|
2096 | + return $this->get(IMimeTypeLoader::class); |
|
2097 | + } |
|
2098 | + |
|
2099 | + /** |
|
2100 | + * Get the manager of all the capabilities |
|
2101 | + * |
|
2102 | + * @return CapabilitiesManager |
|
2103 | + * @deprecated 20.0.0 |
|
2104 | + */ |
|
2105 | + public function getCapabilitiesManager() { |
|
2106 | + return $this->get(CapabilitiesManager::class); |
|
2107 | + } |
|
2108 | + |
|
2109 | + /** |
|
2110 | + * Get the EventDispatcher |
|
2111 | + * |
|
2112 | + * @return EventDispatcherInterface |
|
2113 | + * @since 8.2.0 |
|
2114 | + * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher |
|
2115 | + */ |
|
2116 | + public function getEventDispatcher() { |
|
2117 | + return $this->get(\OC\EventDispatcher\SymfonyAdapter::class); |
|
2118 | + } |
|
2119 | + |
|
2120 | + /** |
|
2121 | + * Get the Notification Manager |
|
2122 | + * |
|
2123 | + * @return \OCP\Notification\IManager |
|
2124 | + * @since 8.2.0 |
|
2125 | + * @deprecated 20.0.0 |
|
2126 | + */ |
|
2127 | + public function getNotificationManager() { |
|
2128 | + return $this->get(\OCP\Notification\IManager::class); |
|
2129 | + } |
|
2130 | + |
|
2131 | + /** |
|
2132 | + * @return ICommentsManager |
|
2133 | + * @deprecated 20.0.0 |
|
2134 | + */ |
|
2135 | + public function getCommentsManager() { |
|
2136 | + return $this->get(ICommentsManager::class); |
|
2137 | + } |
|
2138 | + |
|
2139 | + /** |
|
2140 | + * @return \OCA\Theming\ThemingDefaults |
|
2141 | + * @deprecated 20.0.0 |
|
2142 | + */ |
|
2143 | + public function getThemingDefaults() { |
|
2144 | + return $this->get('ThemingDefaults'); |
|
2145 | + } |
|
2146 | + |
|
2147 | + /** |
|
2148 | + * @return \OC\IntegrityCheck\Checker |
|
2149 | + * @deprecated 20.0.0 |
|
2150 | + */ |
|
2151 | + public function getIntegrityCodeChecker() { |
|
2152 | + return $this->get('IntegrityCodeChecker'); |
|
2153 | + } |
|
2154 | + |
|
2155 | + /** |
|
2156 | + * @return \OC\Session\CryptoWrapper |
|
2157 | + * @deprecated 20.0.0 |
|
2158 | + */ |
|
2159 | + public function getSessionCryptoWrapper() { |
|
2160 | + return $this->get('CryptoWrapper'); |
|
2161 | + } |
|
2162 | + |
|
2163 | + /** |
|
2164 | + * @return CsrfTokenManager |
|
2165 | + * @deprecated 20.0.0 |
|
2166 | + */ |
|
2167 | + public function getCsrfTokenManager() { |
|
2168 | + return $this->get(CsrfTokenManager::class); |
|
2169 | + } |
|
2170 | + |
|
2171 | + /** |
|
2172 | + * @return Throttler |
|
2173 | + * @deprecated 20.0.0 |
|
2174 | + */ |
|
2175 | + public function getBruteForceThrottler() { |
|
2176 | + return $this->get(Throttler::class); |
|
2177 | + } |
|
2178 | + |
|
2179 | + /** |
|
2180 | + * @return IContentSecurityPolicyManager |
|
2181 | + * @deprecated 20.0.0 |
|
2182 | + */ |
|
2183 | + public function getContentSecurityPolicyManager() { |
|
2184 | + return $this->get(ContentSecurityPolicyManager::class); |
|
2185 | + } |
|
2186 | + |
|
2187 | + /** |
|
2188 | + * @return ContentSecurityPolicyNonceManager |
|
2189 | + * @deprecated 20.0.0 |
|
2190 | + */ |
|
2191 | + public function getContentSecurityPolicyNonceManager() { |
|
2192 | + return $this->get(ContentSecurityPolicyNonceManager::class); |
|
2193 | + } |
|
2194 | + |
|
2195 | + /** |
|
2196 | + * Not a public API as of 8.2, wait for 9.0 |
|
2197 | + * |
|
2198 | + * @return \OCA\Files_External\Service\BackendService |
|
2199 | + * @deprecated 20.0.0 |
|
2200 | + */ |
|
2201 | + public function getStoragesBackendService() { |
|
2202 | + return $this->get(BackendService::class); |
|
2203 | + } |
|
2204 | + |
|
2205 | + /** |
|
2206 | + * Not a public API as of 8.2, wait for 9.0 |
|
2207 | + * |
|
2208 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
2209 | + * @deprecated 20.0.0 |
|
2210 | + */ |
|
2211 | + public function getGlobalStoragesService() { |
|
2212 | + return $this->get(GlobalStoragesService::class); |
|
2213 | + } |
|
2214 | + |
|
2215 | + /** |
|
2216 | + * Not a public API as of 8.2, wait for 9.0 |
|
2217 | + * |
|
2218 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
2219 | + * @deprecated 20.0.0 |
|
2220 | + */ |
|
2221 | + public function getUserGlobalStoragesService() { |
|
2222 | + return $this->get(UserGlobalStoragesService::class); |
|
2223 | + } |
|
2224 | + |
|
2225 | + /** |
|
2226 | + * Not a public API as of 8.2, wait for 9.0 |
|
2227 | + * |
|
2228 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
2229 | + * @deprecated 20.0.0 |
|
2230 | + */ |
|
2231 | + public function getUserStoragesService() { |
|
2232 | + return $this->get(UserStoragesService::class); |
|
2233 | + } |
|
2234 | + |
|
2235 | + /** |
|
2236 | + * @return \OCP\Share\IManager |
|
2237 | + * @deprecated 20.0.0 |
|
2238 | + */ |
|
2239 | + public function getShareManager() { |
|
2240 | + return $this->get(\OCP\Share\IManager::class); |
|
2241 | + } |
|
2242 | + |
|
2243 | + /** |
|
2244 | + * @return \OCP\Collaboration\Collaborators\ISearch |
|
2245 | + * @deprecated 20.0.0 |
|
2246 | + */ |
|
2247 | + public function getCollaboratorSearch() { |
|
2248 | + return $this->get(\OCP\Collaboration\Collaborators\ISearch::class); |
|
2249 | + } |
|
2250 | + |
|
2251 | + /** |
|
2252 | + * @return \OCP\Collaboration\AutoComplete\IManager |
|
2253 | + * @deprecated 20.0.0 |
|
2254 | + */ |
|
2255 | + public function getAutoCompleteManager() { |
|
2256 | + return $this->get(IManager::class); |
|
2257 | + } |
|
2258 | + |
|
2259 | + /** |
|
2260 | + * Returns the LDAP Provider |
|
2261 | + * |
|
2262 | + * @return \OCP\LDAP\ILDAPProvider |
|
2263 | + * @deprecated 20.0.0 |
|
2264 | + */ |
|
2265 | + public function getLDAPProvider() { |
|
2266 | + return $this->get('LDAPProvider'); |
|
2267 | + } |
|
2268 | + |
|
2269 | + /** |
|
2270 | + * @return \OCP\Settings\IManager |
|
2271 | + * @deprecated 20.0.0 |
|
2272 | + */ |
|
2273 | + public function getSettingsManager() { |
|
2274 | + return $this->get(\OC\Settings\Manager::class); |
|
2275 | + } |
|
2276 | + |
|
2277 | + /** |
|
2278 | + * @return \OCP\Files\IAppData |
|
2279 | + * @deprecated 20.0.0 Use get(\OCP\Files\AppData\IAppDataFactory::class)->get($app) instead |
|
2280 | + */ |
|
2281 | + public function getAppDataDir($app) { |
|
2282 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
2283 | + $factory = $this->get(\OC\Files\AppData\Factory::class); |
|
2284 | + return $factory->get($app); |
|
2285 | + } |
|
2286 | + |
|
2287 | + /** |
|
2288 | + * @return \OCP\Lockdown\ILockdownManager |
|
2289 | + * @deprecated 20.0.0 |
|
2290 | + */ |
|
2291 | + public function getLockdownManager() { |
|
2292 | + return $this->get('LockdownManager'); |
|
2293 | + } |
|
2294 | + |
|
2295 | + /** |
|
2296 | + * @return \OCP\Federation\ICloudIdManager |
|
2297 | + * @deprecated 20.0.0 |
|
2298 | + */ |
|
2299 | + public function getCloudIdManager() { |
|
2300 | + return $this->get(ICloudIdManager::class); |
|
2301 | + } |
|
2302 | + |
|
2303 | + /** |
|
2304 | + * @return \OCP\GlobalScale\IConfig |
|
2305 | + * @deprecated 20.0.0 |
|
2306 | + */ |
|
2307 | + public function getGlobalScaleConfig() { |
|
2308 | + return $this->get(IConfig::class); |
|
2309 | + } |
|
2310 | + |
|
2311 | + /** |
|
2312 | + * @return \OCP\Federation\ICloudFederationProviderManager |
|
2313 | + * @deprecated 20.0.0 |
|
2314 | + */ |
|
2315 | + public function getCloudFederationProviderManager() { |
|
2316 | + return $this->get(ICloudFederationProviderManager::class); |
|
2317 | + } |
|
2318 | + |
|
2319 | + /** |
|
2320 | + * @return \OCP\Remote\Api\IApiFactory |
|
2321 | + * @deprecated 20.0.0 |
|
2322 | + */ |
|
2323 | + public function getRemoteApiFactory() { |
|
2324 | + return $this->get(IApiFactory::class); |
|
2325 | + } |
|
2326 | + |
|
2327 | + /** |
|
2328 | + * @return \OCP\Federation\ICloudFederationFactory |
|
2329 | + * @deprecated 20.0.0 |
|
2330 | + */ |
|
2331 | + public function getCloudFederationFactory() { |
|
2332 | + return $this->get(ICloudFederationFactory::class); |
|
2333 | + } |
|
2334 | + |
|
2335 | + /** |
|
2336 | + * @return \OCP\Remote\IInstanceFactory |
|
2337 | + * @deprecated 20.0.0 |
|
2338 | + */ |
|
2339 | + public function getRemoteInstanceFactory() { |
|
2340 | + return $this->get(IInstanceFactory::class); |
|
2341 | + } |
|
2342 | + |
|
2343 | + /** |
|
2344 | + * @return IStorageFactory |
|
2345 | + * @deprecated 20.0.0 |
|
2346 | + */ |
|
2347 | + public function getStorageFactory() { |
|
2348 | + return $this->get(IStorageFactory::class); |
|
2349 | + } |
|
2350 | + |
|
2351 | + /** |
|
2352 | + * Get the Preview GeneratorHelper |
|
2353 | + * |
|
2354 | + * @return GeneratorHelper |
|
2355 | + * @since 17.0.0 |
|
2356 | + * @deprecated 20.0.0 |
|
2357 | + */ |
|
2358 | + public function getGeneratorHelper() { |
|
2359 | + return $this->get(\OC\Preview\GeneratorHelper::class); |
|
2360 | + } |
|
2361 | + |
|
2362 | + private function registerDeprecatedAlias(string $alias, string $target) { |
|
2363 | + $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) { |
|
2364 | + try { |
|
2365 | + /** @var LoggerInterface $logger */ |
|
2366 | + $logger = $container->get(LoggerInterface::class); |
|
2367 | + $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
2368 | + } catch (ContainerExceptionInterface $e) { |
|
2369 | + // Could not get logger. Continue |
|
2370 | + } |
|
2371 | + |
|
2372 | + return $container->get($target); |
|
2373 | + }, false); |
|
2374 | + } |
|
2375 | 2375 | } |
@@ -90,1051 +90,1051 @@ |
||
90 | 90 | * OC_autoload! |
91 | 91 | */ |
92 | 92 | class OC { |
93 | - /** |
|
94 | - * Associative array for autoloading. classname => filename |
|
95 | - */ |
|
96 | - public static array $CLASSPATH = []; |
|
97 | - /** |
|
98 | - * The installation path for Nextcloud on the server (e.g. /srv/http/nextcloud) |
|
99 | - */ |
|
100 | - public static string $SERVERROOT = ''; |
|
101 | - /** |
|
102 | - * the current request path relative to the Nextcloud root (e.g. files/index.php) |
|
103 | - */ |
|
104 | - private static string $SUBURI = ''; |
|
105 | - /** |
|
106 | - * the Nextcloud root path for http requests (e.g. nextcloud/) |
|
107 | - */ |
|
108 | - public static string $WEBROOT = ''; |
|
109 | - /** |
|
110 | - * The installation path array of the apps folder on the server (e.g. /srv/http/nextcloud) 'path' and |
|
111 | - * web path in 'url' |
|
112 | - */ |
|
113 | - public static array $APPSROOTS = []; |
|
114 | - |
|
115 | - public static string $configDir; |
|
116 | - |
|
117 | - /** |
|
118 | - * requested app |
|
119 | - */ |
|
120 | - public static string $REQUESTEDAPP = ''; |
|
121 | - |
|
122 | - /** |
|
123 | - * check if Nextcloud runs in cli mode |
|
124 | - */ |
|
125 | - public static bool $CLI = false; |
|
126 | - |
|
127 | - public static \OC\Autoloader $loader; |
|
128 | - |
|
129 | - public static \Composer\Autoload\ClassLoader $composerAutoloader; |
|
130 | - |
|
131 | - public static \OC\Server $server; |
|
132 | - |
|
133 | - private static \OC\Config $config; |
|
134 | - |
|
135 | - /** |
|
136 | - * @throws \RuntimeException when the 3rdparty directory is missing or |
|
137 | - * the app path list is empty or contains an invalid path |
|
138 | - */ |
|
139 | - public static function initPaths(): void { |
|
140 | - if (defined('PHPUNIT_CONFIG_DIR')) { |
|
141 | - self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
142 | - } elseif (defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
143 | - self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
144 | - } elseif ($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
145 | - self::$configDir = rtrim($dir, '/') . '/'; |
|
146 | - } else { |
|
147 | - self::$configDir = OC::$SERVERROOT . '/config/'; |
|
148 | - } |
|
149 | - self::$config = new \OC\Config(self::$configDir); |
|
150 | - |
|
151 | - OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"] ?? ''), strlen(OC::$SERVERROOT))); |
|
152 | - /** |
|
153 | - * FIXME: The following lines are required because we can't yet instantiate |
|
154 | - * Server::get(\OCP\IRequest::class) since \OC::$server does not yet exist. |
|
155 | - */ |
|
156 | - $params = [ |
|
157 | - 'server' => [ |
|
158 | - 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'] ?? null, |
|
159 | - 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'] ?? null, |
|
160 | - ], |
|
161 | - ]; |
|
162 | - $fakeRequest = new \OC\AppFramework\Http\Request( |
|
163 | - $params, |
|
164 | - new \OC\AppFramework\Http\RequestId($_SERVER['UNIQUE_ID'] ?? '', new \OC\Security\SecureRandom()), |
|
165 | - new \OC\AllConfig(new \OC\SystemConfig(self::$config)) |
|
166 | - ); |
|
167 | - $scriptName = $fakeRequest->getScriptName(); |
|
168 | - if (substr($scriptName, -1) == '/') { |
|
169 | - $scriptName .= 'index.php'; |
|
170 | - //make sure suburi follows the same rules as scriptName |
|
171 | - if (substr(OC::$SUBURI, -9) != 'index.php') { |
|
172 | - if (substr(OC::$SUBURI, -1) != '/') { |
|
173 | - OC::$SUBURI = OC::$SUBURI . '/'; |
|
174 | - } |
|
175 | - OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
176 | - } |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - if (OC::$CLI) { |
|
181 | - OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
182 | - } else { |
|
183 | - if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { |
|
184 | - OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
|
185 | - |
|
186 | - if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
|
187 | - OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
188 | - } |
|
189 | - } else { |
|
190 | - // The scriptName is not ending with OC::$SUBURI |
|
191 | - // This most likely means that we are calling from CLI. |
|
192 | - // However some cron jobs still need to generate |
|
193 | - // a web URL, so we use overwritewebroot as a fallback. |
|
194 | - OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
195 | - } |
|
196 | - |
|
197 | - // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
|
198 | - // slash which is required by URL generation. |
|
199 | - if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
200 | - substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
|
201 | - header('Location: '.\OC::$WEBROOT.'/'); |
|
202 | - exit(); |
|
203 | - } |
|
204 | - } |
|
205 | - |
|
206 | - // search the apps folder |
|
207 | - $config_paths = self::$config->getValue('apps_paths', []); |
|
208 | - if (!empty($config_paths)) { |
|
209 | - foreach ($config_paths as $paths) { |
|
210 | - if (isset($paths['url']) && isset($paths['path'])) { |
|
211 | - $paths['url'] = rtrim($paths['url'], '/'); |
|
212 | - $paths['path'] = rtrim($paths['path'], '/'); |
|
213 | - OC::$APPSROOTS[] = $paths; |
|
214 | - } |
|
215 | - } |
|
216 | - } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
217 | - OC::$APPSROOTS[] = ['path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true]; |
|
218 | - } |
|
219 | - |
|
220 | - if (empty(OC::$APPSROOTS)) { |
|
221 | - throw new \RuntimeException('apps directory not found! Please put the Nextcloud apps folder in the Nextcloud folder' |
|
222 | - . '. You can also configure the location in the config.php file.'); |
|
223 | - } |
|
224 | - $paths = []; |
|
225 | - foreach (OC::$APPSROOTS as $path) { |
|
226 | - $paths[] = $path['path']; |
|
227 | - if (!is_dir($path['path'])) { |
|
228 | - throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the Nextcloud apps folder in the' |
|
229 | - . ' Nextcloud folder. You can also configure the location in the config.php file.', $path['path'])); |
|
230 | - } |
|
231 | - } |
|
232 | - |
|
233 | - // set the right include path |
|
234 | - set_include_path( |
|
235 | - implode(PATH_SEPARATOR, $paths) |
|
236 | - ); |
|
237 | - } |
|
238 | - |
|
239 | - public static function checkConfig(): void { |
|
240 | - $l = Server::get(\OCP\L10N\IFactory::class)->get('lib'); |
|
241 | - |
|
242 | - // Create config if it does not already exist |
|
243 | - $configFilePath = self::$configDir .'/config.php'; |
|
244 | - if (!file_exists($configFilePath)) { |
|
245 | - @touch($configFilePath); |
|
246 | - } |
|
247 | - |
|
248 | - // Check if config is writable |
|
249 | - $configFileWritable = is_writable($configFilePath); |
|
250 | - if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled() |
|
251 | - || !$configFileWritable && \OCP\Util::needUpgrade()) { |
|
252 | - $urlGenerator = Server::get(IURLGenerator::class); |
|
253 | - |
|
254 | - if (self::$CLI) { |
|
255 | - echo $l->t('Cannot write into "config" directory!')."\n"; |
|
256 | - echo $l->t('This can usually be fixed by giving the web server write access to the config directory.')."\n"; |
|
257 | - echo "\n"; |
|
258 | - echo $l->t('But, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.')."\n"; |
|
259 | - echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-config') ])."\n"; |
|
260 | - exit; |
|
261 | - } else { |
|
262 | - OC_Template::printErrorPage( |
|
263 | - $l->t('Cannot write into "config" directory!'), |
|
264 | - $l->t('This can usually be fixed by giving the web server write access to the config directory.') . ' ' |
|
265 | - . $l->t('But, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.') . ' ' |
|
266 | - . $l->t('See %s', [ $urlGenerator->linkToDocs('admin-config') ]), |
|
267 | - 503 |
|
268 | - ); |
|
269 | - } |
|
270 | - } |
|
271 | - } |
|
272 | - |
|
273 | - public static function checkInstalled(\OC\SystemConfig $systemConfig): void { |
|
274 | - if (defined('OC_CONSOLE')) { |
|
275 | - return; |
|
276 | - } |
|
277 | - // Redirect to installer if not installed |
|
278 | - if (!$systemConfig->getValue('installed', false) && OC::$SUBURI !== '/index.php' && OC::$SUBURI !== '/status.php') { |
|
279 | - if (OC::$CLI) { |
|
280 | - throw new Exception('Not installed'); |
|
281 | - } else { |
|
282 | - $url = OC::$WEBROOT . '/index.php'; |
|
283 | - header('Location: ' . $url); |
|
284 | - } |
|
285 | - exit(); |
|
286 | - } |
|
287 | - } |
|
288 | - |
|
289 | - public static function checkMaintenanceMode(\OC\SystemConfig $systemConfig): void { |
|
290 | - // Allow ajax update script to execute without being stopped |
|
291 | - if (((bool) $systemConfig->getValue('maintenance', false)) && OC::$SUBURI != '/core/ajax/update.php') { |
|
292 | - // send http status 503 |
|
293 | - http_response_code(503); |
|
294 | - header('X-Nextcloud-Maintenance-Mode: 1'); |
|
295 | - header('Retry-After: 120'); |
|
296 | - |
|
297 | - // render error page |
|
298 | - $template = new OC_Template('', 'update.user', 'guest'); |
|
299 | - \OCP\Util::addScript('core', 'maintenance'); |
|
300 | - \OCP\Util::addStyle('core', 'guest'); |
|
301 | - $template->printPage(); |
|
302 | - die(); |
|
303 | - } |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Prints the upgrade page |
|
308 | - */ |
|
309 | - private static function printUpgradePage(\OC\SystemConfig $systemConfig): void { |
|
310 | - $disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false); |
|
311 | - $tooBig = false; |
|
312 | - if (!$disableWebUpdater) { |
|
313 | - $apps = Server::get(\OCP\App\IAppManager::class); |
|
314 | - if ($apps->isInstalled('user_ldap')) { |
|
315 | - $qb = Server::get(\OCP\IDBConnection::class)->getQueryBuilder(); |
|
316 | - |
|
317 | - $result = $qb->select($qb->func()->count('*', 'user_count')) |
|
318 | - ->from('ldap_user_mapping') |
|
319 | - ->executeQuery(); |
|
320 | - $row = $result->fetch(); |
|
321 | - $result->closeCursor(); |
|
322 | - |
|
323 | - $tooBig = ($row['user_count'] > 50); |
|
324 | - } |
|
325 | - if (!$tooBig && $apps->isInstalled('user_saml')) { |
|
326 | - $qb = Server::get(\OCP\IDBConnection::class)->getQueryBuilder(); |
|
327 | - |
|
328 | - $result = $qb->select($qb->func()->count('*', 'user_count')) |
|
329 | - ->from('user_saml_users') |
|
330 | - ->executeQuery(); |
|
331 | - $row = $result->fetch(); |
|
332 | - $result->closeCursor(); |
|
333 | - |
|
334 | - $tooBig = ($row['user_count'] > 50); |
|
335 | - } |
|
336 | - if (!$tooBig) { |
|
337 | - // count users |
|
338 | - $stats = Server::get(\OCP\IUserManager::class)->countUsers(); |
|
339 | - $totalUsers = array_sum($stats); |
|
340 | - $tooBig = ($totalUsers > 50); |
|
341 | - } |
|
342 | - } |
|
343 | - $ignoreTooBigWarning = isset($_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup']) && |
|
344 | - $_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup'] === 'IAmSuperSureToDoThis'; |
|
345 | - |
|
346 | - if ($disableWebUpdater || ($tooBig && !$ignoreTooBigWarning)) { |
|
347 | - // send http status 503 |
|
348 | - http_response_code(503); |
|
349 | - header('Retry-After: 120'); |
|
350 | - |
|
351 | - // render error page |
|
352 | - $template = new OC_Template('', 'update.use-cli', 'guest'); |
|
353 | - $template->assign('productName', 'nextcloud'); // for now |
|
354 | - $template->assign('version', OC_Util::getVersionString()); |
|
355 | - $template->assign('tooBig', $tooBig); |
|
356 | - |
|
357 | - $template->printPage(); |
|
358 | - die(); |
|
359 | - } |
|
360 | - |
|
361 | - // check whether this is a core update or apps update |
|
362 | - $installedVersion = $systemConfig->getValue('version', '0.0.0'); |
|
363 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
364 | - |
|
365 | - // if not a core upgrade, then it's apps upgrade |
|
366 | - $isAppsOnlyUpgrade = version_compare($currentVersion, $installedVersion, '='); |
|
367 | - |
|
368 | - $oldTheme = $systemConfig->getValue('theme'); |
|
369 | - $systemConfig->setValue('theme', ''); |
|
370 | - \OCP\Util::addScript('core', 'common'); |
|
371 | - \OCP\Util::addScript('core', 'main'); |
|
372 | - \OCP\Util::addTranslations('core'); |
|
373 | - \OCP\Util::addScript('core', 'update'); |
|
374 | - |
|
375 | - /** @var \OC\App\AppManager $appManager */ |
|
376 | - $appManager = Server::get(\OCP\App\IAppManager::class); |
|
377 | - |
|
378 | - $tmpl = new OC_Template('', 'update.admin', 'guest'); |
|
379 | - $tmpl->assign('version', OC_Util::getVersionString()); |
|
380 | - $tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade); |
|
381 | - |
|
382 | - // get third party apps |
|
383 | - $ocVersion = \OCP\Util::getVersion(); |
|
384 | - $ocVersion = implode('.', $ocVersion); |
|
385 | - $incompatibleApps = $appManager->getIncompatibleApps($ocVersion); |
|
386 | - $incompatibleShippedApps = []; |
|
387 | - foreach ($incompatibleApps as $appInfo) { |
|
388 | - if ($appManager->isShipped($appInfo['id'])) { |
|
389 | - $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
390 | - } |
|
391 | - } |
|
392 | - |
|
393 | - if (!empty($incompatibleShippedApps)) { |
|
394 | - $l = Server::get(\OCP\L10N\IFactory::class)->get('core'); |
|
395 | - $hint = $l->t('The files of the app %1$s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
|
396 | - throw new \OCP\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
397 | - } |
|
398 | - |
|
399 | - $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
|
400 | - $tmpl->assign('incompatibleAppsList', $incompatibleApps); |
|
401 | - try { |
|
402 | - $defaults = new \OC_Defaults(); |
|
403 | - $tmpl->assign('productName', $defaults->getName()); |
|
404 | - } catch (Throwable $error) { |
|
405 | - $tmpl->assign('productName', 'Nextcloud'); |
|
406 | - } |
|
407 | - $tmpl->assign('oldTheme', $oldTheme); |
|
408 | - $tmpl->printPage(); |
|
409 | - } |
|
410 | - |
|
411 | - public static function initSession(): void { |
|
412 | - $request = Server::get(IRequest::class); |
|
413 | - $isDavRequest = strpos($request->getRequestUri(), '/remote.php/dav') === 0 || strpos($request->getRequestUri(), '/remote.php/webdav') === 0; |
|
414 | - if ($request->getHeader('Authorization') !== '' && is_null($request->getCookie('cookie_test')) && $isDavRequest && !isset($_COOKIE['nc_session_id'])) { |
|
415 | - setcookie('cookie_test', 'test', time() + 3600); |
|
416 | - // Do not initialize the session if a request is authenticated directly |
|
417 | - // unless there is a session cookie already sent along |
|
418 | - return; |
|
419 | - } |
|
420 | - |
|
421 | - if ($request->getServerProtocol() === 'https') { |
|
422 | - ini_set('session.cookie_secure', 'true'); |
|
423 | - } |
|
424 | - |
|
425 | - // prevents javascript from accessing php session cookies |
|
426 | - ini_set('session.cookie_httponly', 'true'); |
|
427 | - |
|
428 | - // set the cookie path to the Nextcloud directory |
|
429 | - $cookie_path = OC::$WEBROOT ? : '/'; |
|
430 | - ini_set('session.cookie_path', $cookie_path); |
|
431 | - |
|
432 | - // Let the session name be changed in the initSession Hook |
|
433 | - $sessionName = OC_Util::getInstanceId(); |
|
434 | - |
|
435 | - try { |
|
436 | - // set the session name to the instance id - which is unique |
|
437 | - $session = new \OC\Session\Internal($sessionName); |
|
438 | - |
|
439 | - $cryptoWrapper = Server::get(\OC\Session\CryptoWrapper::class); |
|
440 | - $session = $cryptoWrapper->wrapSession($session); |
|
441 | - self::$server->setSession($session); |
|
442 | - |
|
443 | - // if session can't be started break with http 500 error |
|
444 | - } catch (Exception $e) { |
|
445 | - Server::get(LoggerInterface::class)->error($e->getMessage(), ['app' => 'base','exception' => $e]); |
|
446 | - //show the user a detailed error page |
|
447 | - OC_Template::printExceptionErrorPage($e, 500); |
|
448 | - die(); |
|
449 | - } |
|
450 | - |
|
451 | - //try to set the session lifetime |
|
452 | - $sessionLifeTime = self::getSessionLifeTime(); |
|
453 | - @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
454 | - |
|
455 | - // session timeout |
|
456 | - if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
|
457 | - if (isset($_COOKIE[session_name()])) { |
|
458 | - setcookie(session_name(), '', -1, self::$WEBROOT ? : '/'); |
|
459 | - } |
|
460 | - Server::get(IUserSession::class)->logout(); |
|
461 | - } |
|
462 | - |
|
463 | - if (!self::hasSessionRelaxedExpiry()) { |
|
464 | - $session->set('LAST_ACTIVITY', time()); |
|
465 | - } |
|
466 | - $session->close(); |
|
467 | - } |
|
468 | - |
|
469 | - private static function getSessionLifeTime(): int { |
|
470 | - return Server::get(\OC\AllConfig::class)->getSystemValueInt('session_lifetime', 60 * 60 * 24); |
|
471 | - } |
|
472 | - |
|
473 | - /** |
|
474 | - * @return bool true if the session expiry should only be done by gc instead of an explicit timeout |
|
475 | - */ |
|
476 | - public static function hasSessionRelaxedExpiry(): bool { |
|
477 | - return Server::get(\OC\AllConfig::class)->getSystemValueBool('session_relaxed_expiry', false); |
|
478 | - } |
|
479 | - |
|
480 | - /** |
|
481 | - * Try to set some values to the required Nextcloud default |
|
482 | - */ |
|
483 | - public static function setRequiredIniValues(): void { |
|
484 | - @ini_set('default_charset', 'UTF-8'); |
|
485 | - @ini_set('gd.jpeg_ignore_warning', '1'); |
|
486 | - } |
|
487 | - |
|
488 | - /** |
|
489 | - * Send the same site cookies |
|
490 | - */ |
|
491 | - private static function sendSameSiteCookies(): void { |
|
492 | - $cookieParams = session_get_cookie_params(); |
|
493 | - $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
494 | - $policies = [ |
|
495 | - 'lax', |
|
496 | - 'strict', |
|
497 | - ]; |
|
498 | - |
|
499 | - // Append __Host to the cookie if it meets the requirements |
|
500 | - $cookiePrefix = ''; |
|
501 | - if ($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
502 | - $cookiePrefix = '__Host-'; |
|
503 | - } |
|
504 | - |
|
505 | - foreach ($policies as $policy) { |
|
506 | - header( |
|
507 | - sprintf( |
|
508 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
509 | - $cookiePrefix, |
|
510 | - $policy, |
|
511 | - $cookieParams['path'], |
|
512 | - $policy |
|
513 | - ), |
|
514 | - false |
|
515 | - ); |
|
516 | - } |
|
517 | - } |
|
518 | - |
|
519 | - /** |
|
520 | - * Same Site cookie to further mitigate CSRF attacks. This cookie has to |
|
521 | - * be set in every request if cookies are sent to add a second level of |
|
522 | - * defense against CSRF. |
|
523 | - * |
|
524 | - * If the cookie is not sent this will set the cookie and reload the page. |
|
525 | - * We use an additional cookie since we want to protect logout CSRF and |
|
526 | - * also we can't directly interfere with PHP's session mechanism. |
|
527 | - */ |
|
528 | - private static function performSameSiteCookieProtection(\OCP\IConfig $config): void { |
|
529 | - $request = Server::get(IRequest::class); |
|
530 | - |
|
531 | - // Some user agents are notorious and don't really properly follow HTTP |
|
532 | - // specifications. For those, have an automated opt-out. Since the protection |
|
533 | - // for remote.php is applied in base.php as starting point we need to opt out |
|
534 | - // here. |
|
535 | - $incompatibleUserAgents = $config->getSystemValue('csrf.optout'); |
|
536 | - |
|
537 | - // Fallback, if csrf.optout is unset |
|
538 | - if (!is_array($incompatibleUserAgents)) { |
|
539 | - $incompatibleUserAgents = [ |
|
540 | - // OS X Finder |
|
541 | - '/^WebDAVFS/', |
|
542 | - // Windows webdav drive |
|
543 | - '/^Microsoft-WebDAV-MiniRedir/', |
|
544 | - ]; |
|
545 | - } |
|
546 | - |
|
547 | - if ($request->isUserAgent($incompatibleUserAgents)) { |
|
548 | - return; |
|
549 | - } |
|
550 | - |
|
551 | - if (count($_COOKIE) > 0) { |
|
552 | - $requestUri = $request->getScriptName(); |
|
553 | - $processingScript = explode('/', $requestUri); |
|
554 | - $processingScript = $processingScript[count($processingScript) - 1]; |
|
555 | - |
|
556 | - // index.php routes are handled in the middleware |
|
557 | - if ($processingScript === 'index.php') { |
|
558 | - return; |
|
559 | - } |
|
560 | - |
|
561 | - // All other endpoints require the lax and the strict cookie |
|
562 | - if (!$request->passesStrictCookieCheck()) { |
|
563 | - self::sendSameSiteCookies(); |
|
564 | - // Debug mode gets access to the resources without strict cookie |
|
565 | - // due to the fact that the SabreDAV browser also lives there. |
|
566 | - if (!$config->getSystemValue('debug', false)) { |
|
567 | - http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
|
568 | - exit(); |
|
569 | - } |
|
570 | - } |
|
571 | - } elseif (!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
572 | - self::sendSameSiteCookies(); |
|
573 | - } |
|
574 | - } |
|
575 | - |
|
576 | - public static function init(): void { |
|
577 | - // calculate the root directories |
|
578 | - OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); |
|
579 | - |
|
580 | - // register autoloader |
|
581 | - $loaderStart = microtime(true); |
|
582 | - require_once __DIR__ . '/autoloader.php'; |
|
583 | - self::$loader = new \OC\Autoloader([ |
|
584 | - OC::$SERVERROOT . '/lib/private/legacy', |
|
585 | - ]); |
|
586 | - if (defined('PHPUNIT_RUN')) { |
|
587 | - self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
588 | - } |
|
589 | - spl_autoload_register([self::$loader, 'load']); |
|
590 | - $loaderEnd = microtime(true); |
|
591 | - |
|
592 | - self::$CLI = (php_sapi_name() == 'cli'); |
|
593 | - |
|
594 | - // Add default composer PSR-4 autoloader |
|
595 | - self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
596 | - self::$composerAutoloader->setApcuPrefix('composer_autoload'); |
|
597 | - |
|
598 | - try { |
|
599 | - self::initPaths(); |
|
600 | - // setup 3rdparty autoloader |
|
601 | - $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
602 | - if (!file_exists($vendorAutoLoad)) { |
|
603 | - throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
|
604 | - } |
|
605 | - require_once $vendorAutoLoad; |
|
606 | - } catch (\RuntimeException $e) { |
|
607 | - if (!self::$CLI) { |
|
608 | - http_response_code(503); |
|
609 | - } |
|
610 | - // we can't use the template error page here, because this needs the |
|
611 | - // DI container which isn't available yet |
|
612 | - print($e->getMessage()); |
|
613 | - exit(); |
|
614 | - } |
|
615 | - |
|
616 | - // setup the basic server |
|
617 | - self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); |
|
618 | - self::$server->boot(); |
|
619 | - |
|
620 | - $eventLogger = Server::get(\OCP\Diagnostics\IEventLogger::class); |
|
621 | - $eventLogger->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); |
|
622 | - $eventLogger->start('boot', 'Initialize'); |
|
623 | - |
|
624 | - // Override php.ini and log everything if we're troubleshooting |
|
625 | - if (self::$config->getValue('loglevel') === ILogger::DEBUG) { |
|
626 | - error_reporting(E_ALL); |
|
627 | - } |
|
628 | - |
|
629 | - // Don't display errors and log them |
|
630 | - @ini_set('display_errors', '0'); |
|
631 | - @ini_set('log_errors', '1'); |
|
632 | - |
|
633 | - if (!date_default_timezone_set('UTC')) { |
|
634 | - throw new \RuntimeException('Could not set timezone to UTC'); |
|
635 | - } |
|
636 | - |
|
637 | - |
|
638 | - //try to configure php to enable big file uploads. |
|
639 | - //this doesn´t work always depending on the webserver and php configuration. |
|
640 | - //Let´s try to overwrite some defaults if they are smaller than 1 hour |
|
641 | - |
|
642 | - if (intval(@ini_get('max_execution_time') ?? 0) < 3600) { |
|
643 | - @ini_set('max_execution_time', strval(3600)); |
|
644 | - } |
|
645 | - |
|
646 | - if (intval(@ini_get('max_input_time') ?? 0) < 3600) { |
|
647 | - @ini_set('max_input_time', strval(3600)); |
|
648 | - } |
|
649 | - |
|
650 | - //try to set the maximum execution time to the largest time limit we have |
|
651 | - if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
652 | - @set_time_limit(max(intval(@ini_get('max_execution_time')), intval(@ini_get('max_input_time')))); |
|
653 | - } |
|
654 | - |
|
655 | - self::setRequiredIniValues(); |
|
656 | - self::handleAuthHeaders(); |
|
657 | - $systemConfig = Server::get(\OC\SystemConfig::class); |
|
658 | - self::registerAutoloaderCache($systemConfig); |
|
659 | - |
|
660 | - // initialize intl fallback if necessary |
|
661 | - OC_Util::isSetLocaleWorking(); |
|
662 | - |
|
663 | - $config = Server::get(\OCP\IConfig::class); |
|
664 | - if (!defined('PHPUNIT_RUN')) { |
|
665 | - $errorHandler = new OC\Log\ErrorHandler( |
|
666 | - \OCP\Server::get(\Psr\Log\LoggerInterface::class), |
|
667 | - ); |
|
668 | - $exceptionHandler = [$errorHandler, 'onException']; |
|
669 | - if ($config->getSystemValue('debug', false)) { |
|
670 | - set_error_handler([$errorHandler, 'onAll'], E_ALL); |
|
671 | - if (\OC::$CLI) { |
|
672 | - $exceptionHandler = ['OC_Template', 'printExceptionErrorPage']; |
|
673 | - } |
|
674 | - } else { |
|
675 | - set_error_handler([$errorHandler, 'onError']); |
|
676 | - } |
|
677 | - register_shutdown_function([$errorHandler, 'onShutdown']); |
|
678 | - set_exception_handler($exceptionHandler); |
|
679 | - } |
|
680 | - |
|
681 | - /** @var \OC\AppFramework\Bootstrap\Coordinator $bootstrapCoordinator */ |
|
682 | - $bootstrapCoordinator = Server::get(\OC\AppFramework\Bootstrap\Coordinator::class); |
|
683 | - $bootstrapCoordinator->runInitialRegistration(); |
|
684 | - |
|
685 | - $eventLogger->start('init_session', 'Initialize session'); |
|
686 | - OC_App::loadApps(['session']); |
|
687 | - if (!self::$CLI) { |
|
688 | - self::initSession(); |
|
689 | - } |
|
690 | - $eventLogger->end('init_session'); |
|
691 | - self::checkConfig(); |
|
692 | - self::checkInstalled($systemConfig); |
|
693 | - |
|
694 | - OC_Response::addSecurityHeaders(); |
|
695 | - |
|
696 | - self::performSameSiteCookieProtection($config); |
|
697 | - |
|
698 | - if (!defined('OC_CONSOLE')) { |
|
699 | - $errors = OC_Util::checkServer($systemConfig); |
|
700 | - if (count($errors) > 0) { |
|
701 | - if (!self::$CLI) { |
|
702 | - http_response_code(503); |
|
703 | - OC_Util::addStyle('guest'); |
|
704 | - try { |
|
705 | - OC_Template::printGuestPage('', 'error', ['errors' => $errors]); |
|
706 | - exit; |
|
707 | - } catch (\Exception $e) { |
|
708 | - // In case any error happens when showing the error page, we simply fall back to posting the text. |
|
709 | - // This might be the case when e.g. the data directory is broken and we can not load/write SCSS to/from it. |
|
710 | - } |
|
711 | - } |
|
712 | - |
|
713 | - // Convert l10n string into regular string for usage in database |
|
714 | - $staticErrors = []; |
|
715 | - foreach ($errors as $error) { |
|
716 | - echo $error['error'] . "\n"; |
|
717 | - echo $error['hint'] . "\n\n"; |
|
718 | - $staticErrors[] = [ |
|
719 | - 'error' => (string)$error['error'], |
|
720 | - 'hint' => (string)$error['hint'], |
|
721 | - ]; |
|
722 | - } |
|
723 | - |
|
724 | - try { |
|
725 | - $config->setAppValue('core', 'cronErrors', json_encode($staticErrors)); |
|
726 | - } catch (\Exception $e) { |
|
727 | - echo('Writing to database failed'); |
|
728 | - } |
|
729 | - exit(1); |
|
730 | - } elseif (self::$CLI && $config->getSystemValue('installed', false)) { |
|
731 | - $config->deleteAppValue('core', 'cronErrors'); |
|
732 | - } |
|
733 | - } |
|
734 | - |
|
735 | - // User and Groups |
|
736 | - if (!$systemConfig->getValue("installed", false)) { |
|
737 | - self::$server->getSession()->set('user_id', ''); |
|
738 | - } |
|
739 | - |
|
740 | - OC_User::useBackend(new \OC\User\Database()); |
|
741 | - Server::get(\OCP\IGroupManager::class)->addBackend(new \OC\Group\Database()); |
|
742 | - |
|
743 | - // Subscribe to the hook |
|
744 | - \OCP\Util::connectHook( |
|
745 | - '\OCA\Files_Sharing\API\Server2Server', |
|
746 | - 'preLoginNameUsedAsUserName', |
|
747 | - '\OC\User\Database', |
|
748 | - 'preLoginNameUsedAsUserName' |
|
749 | - ); |
|
750 | - |
|
751 | - //setup extra user backends |
|
752 | - if (!\OCP\Util::needUpgrade()) { |
|
753 | - OC_User::setupBackends(); |
|
754 | - } else { |
|
755 | - // Run upgrades in incognito mode |
|
756 | - OC_User::setIncognitoMode(true); |
|
757 | - } |
|
758 | - |
|
759 | - self::registerCleanupHooks($systemConfig); |
|
760 | - self::registerShareHooks($systemConfig); |
|
761 | - self::registerEncryptionWrapperAndHooks(); |
|
762 | - self::registerAccountHooks(); |
|
763 | - self::registerResourceCollectionHooks(); |
|
764 | - self::registerFileReferenceEventListener(); |
|
765 | - self::registerRenderReferenceEventListener(); |
|
766 | - self::registerAppRestrictionsHooks(); |
|
767 | - |
|
768 | - // Make sure that the application class is not loaded before the database is setup |
|
769 | - if ($systemConfig->getValue("installed", false)) { |
|
770 | - OC_App::loadApp('settings'); |
|
771 | - /* Build core application to make sure that listeners are registered */ |
|
772 | - Server::get(\OC\Core\Application::class); |
|
773 | - } |
|
774 | - |
|
775 | - //make sure temporary files are cleaned up |
|
776 | - $tmpManager = Server::get(\OCP\ITempManager::class); |
|
777 | - register_shutdown_function([$tmpManager, 'clean']); |
|
778 | - $lockProvider = Server::get(\OCP\Lock\ILockingProvider::class); |
|
779 | - register_shutdown_function([$lockProvider, 'releaseAll']); |
|
780 | - |
|
781 | - // Check whether the sample configuration has been copied |
|
782 | - if ($systemConfig->getValue('copied_sample_config', false)) { |
|
783 | - $l = Server::get(\OCP\L10N\IFactory::class)->get('lib'); |
|
784 | - OC_Template::printErrorPage( |
|
785 | - $l->t('Sample configuration detected'), |
|
786 | - $l->t('It has been detected that the sample configuration has been copied. This can break your installation and is unsupported. Please read the documentation before performing changes on config.php'), |
|
787 | - 503 |
|
788 | - ); |
|
789 | - return; |
|
790 | - } |
|
791 | - |
|
792 | - $request = Server::get(IRequest::class); |
|
793 | - $host = $request->getInsecureServerHost(); |
|
794 | - /** |
|
795 | - * if the host passed in headers isn't trusted |
|
796 | - * FIXME: Should not be in here at all :see_no_evil: |
|
797 | - */ |
|
798 | - if (!OC::$CLI |
|
799 | - && !Server::get(\OC\Security\TrustedDomainHelper::class)->isTrustedDomain($host) |
|
800 | - && $config->getSystemValue('installed', false) |
|
801 | - ) { |
|
802 | - // Allow access to CSS resources |
|
803 | - $isScssRequest = false; |
|
804 | - if (strpos($request->getPathInfo() ?: '', '/css/') === 0) { |
|
805 | - $isScssRequest = true; |
|
806 | - } |
|
807 | - |
|
808 | - if (substr($request->getRequestUri(), -11) === '/status.php') { |
|
809 | - http_response_code(400); |
|
810 | - header('Content-Type: application/json'); |
|
811 | - echo '{"error": "Trusted domain error.", "code": 15}'; |
|
812 | - exit(); |
|
813 | - } |
|
814 | - |
|
815 | - if (!$isScssRequest) { |
|
816 | - http_response_code(400); |
|
817 | - Server::get(LoggerInterface::class)->info( |
|
818 | - 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', |
|
819 | - [ |
|
820 | - 'app' => 'core', |
|
821 | - 'remoteAddress' => $request->getRemoteAddress(), |
|
822 | - 'host' => $host, |
|
823 | - ] |
|
824 | - ); |
|
825 | - |
|
826 | - $tmpl = new OCP\Template('core', 'untrustedDomain', 'guest'); |
|
827 | - $tmpl->assign('docUrl', Server::get(IURLGenerator::class)->linkToDocs('admin-trusted-domains')); |
|
828 | - $tmpl->printPage(); |
|
829 | - |
|
830 | - exit(); |
|
831 | - } |
|
832 | - } |
|
833 | - $eventLogger->end('boot'); |
|
834 | - $eventLogger->log('init', 'OC::init', $loaderStart, microtime(true)); |
|
835 | - $eventLogger->start('runtime', 'Runtime'); |
|
836 | - $eventLogger->start('request', 'Full request after boot'); |
|
837 | - register_shutdown_function(function () use ($eventLogger) { |
|
838 | - $eventLogger->end('request'); |
|
839 | - }); |
|
840 | - } |
|
841 | - |
|
842 | - /** |
|
843 | - * register hooks for the cleanup of cache and bruteforce protection |
|
844 | - */ |
|
845 | - public static function registerCleanupHooks(\OC\SystemConfig $systemConfig): void { |
|
846 | - //don't try to do this before we are properly setup |
|
847 | - if ($systemConfig->getValue('installed', false) && !\OCP\Util::needUpgrade()) { |
|
848 | - // NOTE: This will be replaced to use OCP |
|
849 | - $userSession = Server::get(\OC\User\Session::class); |
|
850 | - $userSession->listen('\OC\User', 'postLogin', function () use ($userSession) { |
|
851 | - if (!defined('PHPUNIT_RUN') && $userSession->isLoggedIn()) { |
|
852 | - // reset brute force delay for this IP address and username |
|
853 | - $uid = $userSession->getUser()->getUID(); |
|
854 | - $request = Server::get(IRequest::class); |
|
855 | - $throttler = Server::get(\OC\Security\Bruteforce\Throttler::class); |
|
856 | - $throttler->resetDelay($request->getRemoteAddress(), 'login', ['user' => $uid]); |
|
857 | - } |
|
858 | - }); |
|
859 | - } |
|
860 | - } |
|
861 | - |
|
862 | - private static function registerEncryptionWrapperAndHooks(): void { |
|
863 | - $manager = Server::get(\OCP\Encryption\IManager::class); |
|
864 | - \OCP\Util::connectHook('OC_Filesystem', 'preSetup', $manager, 'setupStorage'); |
|
865 | - |
|
866 | - $enabled = $manager->isEnabled(); |
|
867 | - if ($enabled) { |
|
868 | - \OCP\Util::connectHook(Share::class, 'post_shared', HookManager::class, 'postShared'); |
|
869 | - \OCP\Util::connectHook(Share::class, 'post_unshare', HookManager::class, 'postUnshared'); |
|
870 | - \OCP\Util::connectHook('OC_Filesystem', 'post_rename', HookManager::class, 'postRename'); |
|
871 | - \OCP\Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', HookManager::class, 'postRestore'); |
|
872 | - } |
|
873 | - } |
|
874 | - |
|
875 | - private static function registerAccountHooks(): void { |
|
876 | - /** @var IEventDispatcher $dispatcher */ |
|
877 | - $dispatcher = Server::get(IEventDispatcher::class); |
|
878 | - $dispatcher->addServiceListener(UserChangedEvent::class, \OC\Accounts\Hooks::class); |
|
879 | - } |
|
880 | - |
|
881 | - private static function registerAppRestrictionsHooks(): void { |
|
882 | - /** @var \OC\Group\Manager $groupManager */ |
|
883 | - $groupManager = Server::get(\OCP\IGroupManager::class); |
|
884 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OCP\IGroup $group) { |
|
885 | - $appManager = Server::get(\OCP\App\IAppManager::class); |
|
886 | - $apps = $appManager->getEnabledAppsForGroup($group); |
|
887 | - foreach ($apps as $appId) { |
|
888 | - $restrictions = $appManager->getAppRestriction($appId); |
|
889 | - if (empty($restrictions)) { |
|
890 | - continue; |
|
891 | - } |
|
892 | - $key = array_search($group->getGID(), $restrictions); |
|
893 | - unset($restrictions[$key]); |
|
894 | - $restrictions = array_values($restrictions); |
|
895 | - if (empty($restrictions)) { |
|
896 | - $appManager->disableApp($appId); |
|
897 | - } else { |
|
898 | - $appManager->enableAppForGroups($appId, $restrictions); |
|
899 | - } |
|
900 | - } |
|
901 | - }); |
|
902 | - } |
|
903 | - |
|
904 | - private static function registerResourceCollectionHooks(): void { |
|
905 | - \OC\Collaboration\Resources\Listener::register(Server::get(SymfonyAdapter::class), Server::get(IEventDispatcher::class)); |
|
906 | - } |
|
907 | - |
|
908 | - private static function registerFileReferenceEventListener(): void { |
|
909 | - \OC\Collaboration\Reference\File\FileReferenceEventListener::register(Server::get(IEventDispatcher::class)); |
|
910 | - } |
|
911 | - |
|
912 | - private static function registerRenderReferenceEventListener() { |
|
913 | - \OC\Collaboration\Reference\RenderReferenceEventListener::register(Server::get(IEventDispatcher::class)); |
|
914 | - } |
|
915 | - |
|
916 | - /** |
|
917 | - * register hooks for sharing |
|
918 | - */ |
|
919 | - public static function registerShareHooks(\OC\SystemConfig $systemConfig): void { |
|
920 | - if ($systemConfig->getValue('installed')) { |
|
921 | - OC_Hook::connect('OC_User', 'post_deleteUser', Hooks::class, 'post_deleteUser'); |
|
922 | - OC_Hook::connect('OC_User', 'post_deleteGroup', Hooks::class, 'post_deleteGroup'); |
|
923 | - |
|
924 | - /** @var IEventDispatcher $dispatcher */ |
|
925 | - $dispatcher = Server::get(IEventDispatcher::class); |
|
926 | - $dispatcher->addServiceListener(UserRemovedEvent::class, \OC\Share20\UserRemovedListener::class); |
|
927 | - } |
|
928 | - } |
|
929 | - |
|
930 | - protected static function registerAutoloaderCache(\OC\SystemConfig $systemConfig): void { |
|
931 | - // The class loader takes an optional low-latency cache, which MUST be |
|
932 | - // namespaced. The instanceid is used for namespacing, but might be |
|
933 | - // unavailable at this point. Furthermore, it might not be possible to |
|
934 | - // generate an instanceid via \OC_Util::getInstanceId() because the |
|
935 | - // config file may not be writable. As such, we only register a class |
|
936 | - // loader cache if instanceid is available without trying to create one. |
|
937 | - $instanceId = $systemConfig->getValue('instanceid', null); |
|
938 | - if ($instanceId) { |
|
939 | - try { |
|
940 | - $memcacheFactory = Server::get(\OCP\ICacheFactory::class); |
|
941 | - self::$loader->setMemoryCache($memcacheFactory->createLocal('Autoloader')); |
|
942 | - } catch (\Exception $ex) { |
|
943 | - } |
|
944 | - } |
|
945 | - } |
|
946 | - |
|
947 | - /** |
|
948 | - * Handle the request |
|
949 | - */ |
|
950 | - public static function handleRequest(): void { |
|
951 | - Server::get(\OCP\Diagnostics\IEventLogger::class)->start('handle_request', 'Handle request'); |
|
952 | - $systemConfig = Server::get(\OC\SystemConfig::class); |
|
953 | - |
|
954 | - // Check if Nextcloud is installed or in maintenance (update) mode |
|
955 | - if (!$systemConfig->getValue('installed', false)) { |
|
956 | - \OC::$server->getSession()->clear(); |
|
957 | - $setupHelper = new OC\Setup( |
|
958 | - $systemConfig, |
|
959 | - Server::get(\bantu\IniGetWrapper\IniGetWrapper::class), |
|
960 | - Server::get(\OCP\L10N\IFactory::class)->get('lib'), |
|
961 | - Server::get(\OCP\Defaults::class), |
|
962 | - Server::get(\Psr\Log\LoggerInterface::class), |
|
963 | - Server::get(\OCP\Security\ISecureRandom::class), |
|
964 | - Server::get(\OC\Installer::class) |
|
965 | - ); |
|
966 | - $controller = new OC\Core\Controller\SetupController($setupHelper); |
|
967 | - $controller->run($_POST); |
|
968 | - exit(); |
|
969 | - } |
|
970 | - |
|
971 | - $request = Server::get(IRequest::class); |
|
972 | - $requestPath = $request->getRawPathInfo(); |
|
973 | - if ($requestPath === '/heartbeat') { |
|
974 | - return; |
|
975 | - } |
|
976 | - if (substr($requestPath, -3) !== '.js') { // we need these files during the upgrade |
|
977 | - self::checkMaintenanceMode($systemConfig); |
|
978 | - |
|
979 | - if (\OCP\Util::needUpgrade()) { |
|
980 | - if (function_exists('opcache_reset')) { |
|
981 | - opcache_reset(); |
|
982 | - } |
|
983 | - if (!((bool) $systemConfig->getValue('maintenance', false))) { |
|
984 | - self::printUpgradePage($systemConfig); |
|
985 | - exit(); |
|
986 | - } |
|
987 | - } |
|
988 | - } |
|
989 | - |
|
990 | - // emergency app disabling |
|
991 | - if ($requestPath === '/disableapp' |
|
992 | - && $request->getMethod() === 'POST' |
|
993 | - ) { |
|
994 | - \OC_JSON::callCheck(); |
|
995 | - \OC_JSON::checkAdminUser(); |
|
996 | - $appIds = (array)$request->getParam('appid'); |
|
997 | - foreach ($appIds as $appId) { |
|
998 | - $appId = \OC_App::cleanAppId($appId); |
|
999 | - Server::get(\OCP\App\IAppManager::class)->disableApp($appId); |
|
1000 | - } |
|
1001 | - \OC_JSON::success(); |
|
1002 | - exit(); |
|
1003 | - } |
|
1004 | - |
|
1005 | - // Always load authentication apps |
|
1006 | - OC_App::loadApps(['authentication']); |
|
1007 | - |
|
1008 | - // Load minimum set of apps |
|
1009 | - if (!\OCP\Util::needUpgrade() |
|
1010 | - && !((bool) $systemConfig->getValue('maintenance', false))) { |
|
1011 | - // For logged-in users: Load everything |
|
1012 | - if (Server::get(IUserSession::class)->isLoggedIn()) { |
|
1013 | - OC_App::loadApps(); |
|
1014 | - } else { |
|
1015 | - // For guests: Load only filesystem and logging |
|
1016 | - OC_App::loadApps(['filesystem', 'logging']); |
|
1017 | - |
|
1018 | - // Don't try to login when a client is trying to get a OAuth token. |
|
1019 | - // OAuth needs to support basic auth too, so the login is not valid |
|
1020 | - // inside Nextcloud and the Login exception would ruin it. |
|
1021 | - if ($request->getRawPathInfo() !== '/apps/oauth2/api/v1/token') { |
|
1022 | - self::handleLogin($request); |
|
1023 | - } |
|
1024 | - } |
|
1025 | - } |
|
1026 | - |
|
1027 | - if (!self::$CLI) { |
|
1028 | - try { |
|
1029 | - if (!((bool) $systemConfig->getValue('maintenance', false)) && !\OCP\Util::needUpgrade()) { |
|
1030 | - OC_App::loadApps(['filesystem', 'logging']); |
|
1031 | - OC_App::loadApps(); |
|
1032 | - } |
|
1033 | - Server::get(\OC\Route\Router::class)->match($request->getRawPathInfo()); |
|
1034 | - return; |
|
1035 | - } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { |
|
1036 | - //header('HTTP/1.0 404 Not Found'); |
|
1037 | - } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { |
|
1038 | - http_response_code(405); |
|
1039 | - return; |
|
1040 | - } |
|
1041 | - } |
|
1042 | - |
|
1043 | - // Handle WebDAV |
|
1044 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
1045 | - // not allowed any more to prevent people |
|
1046 | - // mounting this root directly. |
|
1047 | - // Users need to mount remote.php/webdav instead. |
|
1048 | - http_response_code(405); |
|
1049 | - return; |
|
1050 | - } |
|
1051 | - |
|
1052 | - // Handle requests for JSON or XML |
|
1053 | - $acceptHeader = $request->getHeader('Accept'); |
|
1054 | - if (in_array($acceptHeader, ['application/json', 'application/xml'], true)) { |
|
1055 | - http_response_code(404); |
|
1056 | - return; |
|
1057 | - } |
|
1058 | - |
|
1059 | - // Handle resources that can't be found |
|
1060 | - // This prevents browsers from redirecting to the default page and then |
|
1061 | - // attempting to parse HTML as CSS and similar. |
|
1062 | - $destinationHeader = $request->getHeader('Sec-Fetch-Dest'); |
|
1063 | - if (in_array($destinationHeader, ['font', 'script', 'style'])) { |
|
1064 | - http_response_code(404); |
|
1065 | - return; |
|
1066 | - } |
|
1067 | - |
|
1068 | - // Redirect to the default app or login only as an entry point |
|
1069 | - if ($requestPath === '') { |
|
1070 | - // Someone is logged in |
|
1071 | - if (Server::get(IUserSession::class)->isLoggedIn()) { |
|
1072 | - header('Location: ' . Server::get(IURLGenerator::class)->linkToDefaultPageUrl()); |
|
1073 | - } else { |
|
1074 | - // Not handled and not logged in |
|
1075 | - header('Location: ' . Server::get(IURLGenerator::class)->linkToRouteAbsolute('core.login.showLoginForm')); |
|
1076 | - } |
|
1077 | - return; |
|
1078 | - } |
|
1079 | - |
|
1080 | - try { |
|
1081 | - Server::get(\OC\Route\Router::class)->match('/error/404'); |
|
1082 | - } catch (\Exception $e) { |
|
1083 | - logger('core')->emergency($e->getMessage(), ['exception' => $e]); |
|
1084 | - $l = Server::get(\OCP\L10N\IFactory::class)->get('lib'); |
|
1085 | - OC_Template::printErrorPage( |
|
1086 | - $l->t('404'), |
|
1087 | - $l->t('The page could not be found on the server.'), |
|
1088 | - 404 |
|
1089 | - ); |
|
1090 | - } |
|
1091 | - } |
|
1092 | - |
|
1093 | - /** |
|
1094 | - * Check login: apache auth, auth token, basic auth |
|
1095 | - */ |
|
1096 | - public static function handleLogin(OCP\IRequest $request): bool { |
|
1097 | - $userSession = Server::get(\OC\User\Session::class); |
|
1098 | - if (OC_User::handleApacheAuth()) { |
|
1099 | - return true; |
|
1100 | - } |
|
1101 | - if ($userSession->tryTokenLogin($request)) { |
|
1102 | - return true; |
|
1103 | - } |
|
1104 | - if (isset($_COOKIE['nc_username']) |
|
1105 | - && isset($_COOKIE['nc_token']) |
|
1106 | - && isset($_COOKIE['nc_session_id']) |
|
1107 | - && $userSession->loginWithCookie($_COOKIE['nc_username'], $_COOKIE['nc_token'], $_COOKIE['nc_session_id'])) { |
|
1108 | - return true; |
|
1109 | - } |
|
1110 | - if ($userSession->tryBasicAuthLogin($request, Server::get(\OC\Security\Bruteforce\Throttler::class))) { |
|
1111 | - return true; |
|
1112 | - } |
|
1113 | - return false; |
|
1114 | - } |
|
1115 | - |
|
1116 | - protected static function handleAuthHeaders(): void { |
|
1117 | - //copy http auth headers for apache+php-fcgid work around |
|
1118 | - if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { |
|
1119 | - $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; |
|
1120 | - } |
|
1121 | - |
|
1122 | - // Extract PHP_AUTH_USER/PHP_AUTH_PW from other headers if necessary. |
|
1123 | - $vars = [ |
|
1124 | - 'HTTP_AUTHORIZATION', // apache+php-cgi work around |
|
1125 | - 'REDIRECT_HTTP_AUTHORIZATION', // apache+php-cgi alternative |
|
1126 | - ]; |
|
1127 | - foreach ($vars as $var) { |
|
1128 | - if (isset($_SERVER[$var]) && is_string($_SERVER[$var]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$var], $matches)) { |
|
1129 | - $credentials = explode(':', base64_decode($matches[1]), 2); |
|
1130 | - if (count($credentials) === 2) { |
|
1131 | - $_SERVER['PHP_AUTH_USER'] = $credentials[0]; |
|
1132 | - $_SERVER['PHP_AUTH_PW'] = $credentials[1]; |
|
1133 | - break; |
|
1134 | - } |
|
1135 | - } |
|
1136 | - } |
|
1137 | - } |
|
93 | + /** |
|
94 | + * Associative array for autoloading. classname => filename |
|
95 | + */ |
|
96 | + public static array $CLASSPATH = []; |
|
97 | + /** |
|
98 | + * The installation path for Nextcloud on the server (e.g. /srv/http/nextcloud) |
|
99 | + */ |
|
100 | + public static string $SERVERROOT = ''; |
|
101 | + /** |
|
102 | + * the current request path relative to the Nextcloud root (e.g. files/index.php) |
|
103 | + */ |
|
104 | + private static string $SUBURI = ''; |
|
105 | + /** |
|
106 | + * the Nextcloud root path for http requests (e.g. nextcloud/) |
|
107 | + */ |
|
108 | + public static string $WEBROOT = ''; |
|
109 | + /** |
|
110 | + * The installation path array of the apps folder on the server (e.g. /srv/http/nextcloud) 'path' and |
|
111 | + * web path in 'url' |
|
112 | + */ |
|
113 | + public static array $APPSROOTS = []; |
|
114 | + |
|
115 | + public static string $configDir; |
|
116 | + |
|
117 | + /** |
|
118 | + * requested app |
|
119 | + */ |
|
120 | + public static string $REQUESTEDAPP = ''; |
|
121 | + |
|
122 | + /** |
|
123 | + * check if Nextcloud runs in cli mode |
|
124 | + */ |
|
125 | + public static bool $CLI = false; |
|
126 | + |
|
127 | + public static \OC\Autoloader $loader; |
|
128 | + |
|
129 | + public static \Composer\Autoload\ClassLoader $composerAutoloader; |
|
130 | + |
|
131 | + public static \OC\Server $server; |
|
132 | + |
|
133 | + private static \OC\Config $config; |
|
134 | + |
|
135 | + /** |
|
136 | + * @throws \RuntimeException when the 3rdparty directory is missing or |
|
137 | + * the app path list is empty or contains an invalid path |
|
138 | + */ |
|
139 | + public static function initPaths(): void { |
|
140 | + if (defined('PHPUNIT_CONFIG_DIR')) { |
|
141 | + self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
142 | + } elseif (defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
143 | + self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
144 | + } elseif ($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
145 | + self::$configDir = rtrim($dir, '/') . '/'; |
|
146 | + } else { |
|
147 | + self::$configDir = OC::$SERVERROOT . '/config/'; |
|
148 | + } |
|
149 | + self::$config = new \OC\Config(self::$configDir); |
|
150 | + |
|
151 | + OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"] ?? ''), strlen(OC::$SERVERROOT))); |
|
152 | + /** |
|
153 | + * FIXME: The following lines are required because we can't yet instantiate |
|
154 | + * Server::get(\OCP\IRequest::class) since \OC::$server does not yet exist. |
|
155 | + */ |
|
156 | + $params = [ |
|
157 | + 'server' => [ |
|
158 | + 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'] ?? null, |
|
159 | + 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'] ?? null, |
|
160 | + ], |
|
161 | + ]; |
|
162 | + $fakeRequest = new \OC\AppFramework\Http\Request( |
|
163 | + $params, |
|
164 | + new \OC\AppFramework\Http\RequestId($_SERVER['UNIQUE_ID'] ?? '', new \OC\Security\SecureRandom()), |
|
165 | + new \OC\AllConfig(new \OC\SystemConfig(self::$config)) |
|
166 | + ); |
|
167 | + $scriptName = $fakeRequest->getScriptName(); |
|
168 | + if (substr($scriptName, -1) == '/') { |
|
169 | + $scriptName .= 'index.php'; |
|
170 | + //make sure suburi follows the same rules as scriptName |
|
171 | + if (substr(OC::$SUBURI, -9) != 'index.php') { |
|
172 | + if (substr(OC::$SUBURI, -1) != '/') { |
|
173 | + OC::$SUBURI = OC::$SUBURI . '/'; |
|
174 | + } |
|
175 | + OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
176 | + } |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + if (OC::$CLI) { |
|
181 | + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
182 | + } else { |
|
183 | + if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { |
|
184 | + OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
|
185 | + |
|
186 | + if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
|
187 | + OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
188 | + } |
|
189 | + } else { |
|
190 | + // The scriptName is not ending with OC::$SUBURI |
|
191 | + // This most likely means that we are calling from CLI. |
|
192 | + // However some cron jobs still need to generate |
|
193 | + // a web URL, so we use overwritewebroot as a fallback. |
|
194 | + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
195 | + } |
|
196 | + |
|
197 | + // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
|
198 | + // slash which is required by URL generation. |
|
199 | + if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
200 | + substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
|
201 | + header('Location: '.\OC::$WEBROOT.'/'); |
|
202 | + exit(); |
|
203 | + } |
|
204 | + } |
|
205 | + |
|
206 | + // search the apps folder |
|
207 | + $config_paths = self::$config->getValue('apps_paths', []); |
|
208 | + if (!empty($config_paths)) { |
|
209 | + foreach ($config_paths as $paths) { |
|
210 | + if (isset($paths['url']) && isset($paths['path'])) { |
|
211 | + $paths['url'] = rtrim($paths['url'], '/'); |
|
212 | + $paths['path'] = rtrim($paths['path'], '/'); |
|
213 | + OC::$APPSROOTS[] = $paths; |
|
214 | + } |
|
215 | + } |
|
216 | + } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
217 | + OC::$APPSROOTS[] = ['path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true]; |
|
218 | + } |
|
219 | + |
|
220 | + if (empty(OC::$APPSROOTS)) { |
|
221 | + throw new \RuntimeException('apps directory not found! Please put the Nextcloud apps folder in the Nextcloud folder' |
|
222 | + . '. You can also configure the location in the config.php file.'); |
|
223 | + } |
|
224 | + $paths = []; |
|
225 | + foreach (OC::$APPSROOTS as $path) { |
|
226 | + $paths[] = $path['path']; |
|
227 | + if (!is_dir($path['path'])) { |
|
228 | + throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the Nextcloud apps folder in the' |
|
229 | + . ' Nextcloud folder. You can also configure the location in the config.php file.', $path['path'])); |
|
230 | + } |
|
231 | + } |
|
232 | + |
|
233 | + // set the right include path |
|
234 | + set_include_path( |
|
235 | + implode(PATH_SEPARATOR, $paths) |
|
236 | + ); |
|
237 | + } |
|
238 | + |
|
239 | + public static function checkConfig(): void { |
|
240 | + $l = Server::get(\OCP\L10N\IFactory::class)->get('lib'); |
|
241 | + |
|
242 | + // Create config if it does not already exist |
|
243 | + $configFilePath = self::$configDir .'/config.php'; |
|
244 | + if (!file_exists($configFilePath)) { |
|
245 | + @touch($configFilePath); |
|
246 | + } |
|
247 | + |
|
248 | + // Check if config is writable |
|
249 | + $configFileWritable = is_writable($configFilePath); |
|
250 | + if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled() |
|
251 | + || !$configFileWritable && \OCP\Util::needUpgrade()) { |
|
252 | + $urlGenerator = Server::get(IURLGenerator::class); |
|
253 | + |
|
254 | + if (self::$CLI) { |
|
255 | + echo $l->t('Cannot write into "config" directory!')."\n"; |
|
256 | + echo $l->t('This can usually be fixed by giving the web server write access to the config directory.')."\n"; |
|
257 | + echo "\n"; |
|
258 | + echo $l->t('But, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.')."\n"; |
|
259 | + echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-config') ])."\n"; |
|
260 | + exit; |
|
261 | + } else { |
|
262 | + OC_Template::printErrorPage( |
|
263 | + $l->t('Cannot write into "config" directory!'), |
|
264 | + $l->t('This can usually be fixed by giving the web server write access to the config directory.') . ' ' |
|
265 | + . $l->t('But, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.') . ' ' |
|
266 | + . $l->t('See %s', [ $urlGenerator->linkToDocs('admin-config') ]), |
|
267 | + 503 |
|
268 | + ); |
|
269 | + } |
|
270 | + } |
|
271 | + } |
|
272 | + |
|
273 | + public static function checkInstalled(\OC\SystemConfig $systemConfig): void { |
|
274 | + if (defined('OC_CONSOLE')) { |
|
275 | + return; |
|
276 | + } |
|
277 | + // Redirect to installer if not installed |
|
278 | + if (!$systemConfig->getValue('installed', false) && OC::$SUBURI !== '/index.php' && OC::$SUBURI !== '/status.php') { |
|
279 | + if (OC::$CLI) { |
|
280 | + throw new Exception('Not installed'); |
|
281 | + } else { |
|
282 | + $url = OC::$WEBROOT . '/index.php'; |
|
283 | + header('Location: ' . $url); |
|
284 | + } |
|
285 | + exit(); |
|
286 | + } |
|
287 | + } |
|
288 | + |
|
289 | + public static function checkMaintenanceMode(\OC\SystemConfig $systemConfig): void { |
|
290 | + // Allow ajax update script to execute without being stopped |
|
291 | + if (((bool) $systemConfig->getValue('maintenance', false)) && OC::$SUBURI != '/core/ajax/update.php') { |
|
292 | + // send http status 503 |
|
293 | + http_response_code(503); |
|
294 | + header('X-Nextcloud-Maintenance-Mode: 1'); |
|
295 | + header('Retry-After: 120'); |
|
296 | + |
|
297 | + // render error page |
|
298 | + $template = new OC_Template('', 'update.user', 'guest'); |
|
299 | + \OCP\Util::addScript('core', 'maintenance'); |
|
300 | + \OCP\Util::addStyle('core', 'guest'); |
|
301 | + $template->printPage(); |
|
302 | + die(); |
|
303 | + } |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Prints the upgrade page |
|
308 | + */ |
|
309 | + private static function printUpgradePage(\OC\SystemConfig $systemConfig): void { |
|
310 | + $disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false); |
|
311 | + $tooBig = false; |
|
312 | + if (!$disableWebUpdater) { |
|
313 | + $apps = Server::get(\OCP\App\IAppManager::class); |
|
314 | + if ($apps->isInstalled('user_ldap')) { |
|
315 | + $qb = Server::get(\OCP\IDBConnection::class)->getQueryBuilder(); |
|
316 | + |
|
317 | + $result = $qb->select($qb->func()->count('*', 'user_count')) |
|
318 | + ->from('ldap_user_mapping') |
|
319 | + ->executeQuery(); |
|
320 | + $row = $result->fetch(); |
|
321 | + $result->closeCursor(); |
|
322 | + |
|
323 | + $tooBig = ($row['user_count'] > 50); |
|
324 | + } |
|
325 | + if (!$tooBig && $apps->isInstalled('user_saml')) { |
|
326 | + $qb = Server::get(\OCP\IDBConnection::class)->getQueryBuilder(); |
|
327 | + |
|
328 | + $result = $qb->select($qb->func()->count('*', 'user_count')) |
|
329 | + ->from('user_saml_users') |
|
330 | + ->executeQuery(); |
|
331 | + $row = $result->fetch(); |
|
332 | + $result->closeCursor(); |
|
333 | + |
|
334 | + $tooBig = ($row['user_count'] > 50); |
|
335 | + } |
|
336 | + if (!$tooBig) { |
|
337 | + // count users |
|
338 | + $stats = Server::get(\OCP\IUserManager::class)->countUsers(); |
|
339 | + $totalUsers = array_sum($stats); |
|
340 | + $tooBig = ($totalUsers > 50); |
|
341 | + } |
|
342 | + } |
|
343 | + $ignoreTooBigWarning = isset($_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup']) && |
|
344 | + $_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup'] === 'IAmSuperSureToDoThis'; |
|
345 | + |
|
346 | + if ($disableWebUpdater || ($tooBig && !$ignoreTooBigWarning)) { |
|
347 | + // send http status 503 |
|
348 | + http_response_code(503); |
|
349 | + header('Retry-After: 120'); |
|
350 | + |
|
351 | + // render error page |
|
352 | + $template = new OC_Template('', 'update.use-cli', 'guest'); |
|
353 | + $template->assign('productName', 'nextcloud'); // for now |
|
354 | + $template->assign('version', OC_Util::getVersionString()); |
|
355 | + $template->assign('tooBig', $tooBig); |
|
356 | + |
|
357 | + $template->printPage(); |
|
358 | + die(); |
|
359 | + } |
|
360 | + |
|
361 | + // check whether this is a core update or apps update |
|
362 | + $installedVersion = $systemConfig->getValue('version', '0.0.0'); |
|
363 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
364 | + |
|
365 | + // if not a core upgrade, then it's apps upgrade |
|
366 | + $isAppsOnlyUpgrade = version_compare($currentVersion, $installedVersion, '='); |
|
367 | + |
|
368 | + $oldTheme = $systemConfig->getValue('theme'); |
|
369 | + $systemConfig->setValue('theme', ''); |
|
370 | + \OCP\Util::addScript('core', 'common'); |
|
371 | + \OCP\Util::addScript('core', 'main'); |
|
372 | + \OCP\Util::addTranslations('core'); |
|
373 | + \OCP\Util::addScript('core', 'update'); |
|
374 | + |
|
375 | + /** @var \OC\App\AppManager $appManager */ |
|
376 | + $appManager = Server::get(\OCP\App\IAppManager::class); |
|
377 | + |
|
378 | + $tmpl = new OC_Template('', 'update.admin', 'guest'); |
|
379 | + $tmpl->assign('version', OC_Util::getVersionString()); |
|
380 | + $tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade); |
|
381 | + |
|
382 | + // get third party apps |
|
383 | + $ocVersion = \OCP\Util::getVersion(); |
|
384 | + $ocVersion = implode('.', $ocVersion); |
|
385 | + $incompatibleApps = $appManager->getIncompatibleApps($ocVersion); |
|
386 | + $incompatibleShippedApps = []; |
|
387 | + foreach ($incompatibleApps as $appInfo) { |
|
388 | + if ($appManager->isShipped($appInfo['id'])) { |
|
389 | + $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
390 | + } |
|
391 | + } |
|
392 | + |
|
393 | + if (!empty($incompatibleShippedApps)) { |
|
394 | + $l = Server::get(\OCP\L10N\IFactory::class)->get('core'); |
|
395 | + $hint = $l->t('The files of the app %1$s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
|
396 | + throw new \OCP\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
397 | + } |
|
398 | + |
|
399 | + $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
|
400 | + $tmpl->assign('incompatibleAppsList', $incompatibleApps); |
|
401 | + try { |
|
402 | + $defaults = new \OC_Defaults(); |
|
403 | + $tmpl->assign('productName', $defaults->getName()); |
|
404 | + } catch (Throwable $error) { |
|
405 | + $tmpl->assign('productName', 'Nextcloud'); |
|
406 | + } |
|
407 | + $tmpl->assign('oldTheme', $oldTheme); |
|
408 | + $tmpl->printPage(); |
|
409 | + } |
|
410 | + |
|
411 | + public static function initSession(): void { |
|
412 | + $request = Server::get(IRequest::class); |
|
413 | + $isDavRequest = strpos($request->getRequestUri(), '/remote.php/dav') === 0 || strpos($request->getRequestUri(), '/remote.php/webdav') === 0; |
|
414 | + if ($request->getHeader('Authorization') !== '' && is_null($request->getCookie('cookie_test')) && $isDavRequest && !isset($_COOKIE['nc_session_id'])) { |
|
415 | + setcookie('cookie_test', 'test', time() + 3600); |
|
416 | + // Do not initialize the session if a request is authenticated directly |
|
417 | + // unless there is a session cookie already sent along |
|
418 | + return; |
|
419 | + } |
|
420 | + |
|
421 | + if ($request->getServerProtocol() === 'https') { |
|
422 | + ini_set('session.cookie_secure', 'true'); |
|
423 | + } |
|
424 | + |
|
425 | + // prevents javascript from accessing php session cookies |
|
426 | + ini_set('session.cookie_httponly', 'true'); |
|
427 | + |
|
428 | + // set the cookie path to the Nextcloud directory |
|
429 | + $cookie_path = OC::$WEBROOT ? : '/'; |
|
430 | + ini_set('session.cookie_path', $cookie_path); |
|
431 | + |
|
432 | + // Let the session name be changed in the initSession Hook |
|
433 | + $sessionName = OC_Util::getInstanceId(); |
|
434 | + |
|
435 | + try { |
|
436 | + // set the session name to the instance id - which is unique |
|
437 | + $session = new \OC\Session\Internal($sessionName); |
|
438 | + |
|
439 | + $cryptoWrapper = Server::get(\OC\Session\CryptoWrapper::class); |
|
440 | + $session = $cryptoWrapper->wrapSession($session); |
|
441 | + self::$server->setSession($session); |
|
442 | + |
|
443 | + // if session can't be started break with http 500 error |
|
444 | + } catch (Exception $e) { |
|
445 | + Server::get(LoggerInterface::class)->error($e->getMessage(), ['app' => 'base','exception' => $e]); |
|
446 | + //show the user a detailed error page |
|
447 | + OC_Template::printExceptionErrorPage($e, 500); |
|
448 | + die(); |
|
449 | + } |
|
450 | + |
|
451 | + //try to set the session lifetime |
|
452 | + $sessionLifeTime = self::getSessionLifeTime(); |
|
453 | + @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
454 | + |
|
455 | + // session timeout |
|
456 | + if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
|
457 | + if (isset($_COOKIE[session_name()])) { |
|
458 | + setcookie(session_name(), '', -1, self::$WEBROOT ? : '/'); |
|
459 | + } |
|
460 | + Server::get(IUserSession::class)->logout(); |
|
461 | + } |
|
462 | + |
|
463 | + if (!self::hasSessionRelaxedExpiry()) { |
|
464 | + $session->set('LAST_ACTIVITY', time()); |
|
465 | + } |
|
466 | + $session->close(); |
|
467 | + } |
|
468 | + |
|
469 | + private static function getSessionLifeTime(): int { |
|
470 | + return Server::get(\OC\AllConfig::class)->getSystemValueInt('session_lifetime', 60 * 60 * 24); |
|
471 | + } |
|
472 | + |
|
473 | + /** |
|
474 | + * @return bool true if the session expiry should only be done by gc instead of an explicit timeout |
|
475 | + */ |
|
476 | + public static function hasSessionRelaxedExpiry(): bool { |
|
477 | + return Server::get(\OC\AllConfig::class)->getSystemValueBool('session_relaxed_expiry', false); |
|
478 | + } |
|
479 | + |
|
480 | + /** |
|
481 | + * Try to set some values to the required Nextcloud default |
|
482 | + */ |
|
483 | + public static function setRequiredIniValues(): void { |
|
484 | + @ini_set('default_charset', 'UTF-8'); |
|
485 | + @ini_set('gd.jpeg_ignore_warning', '1'); |
|
486 | + } |
|
487 | + |
|
488 | + /** |
|
489 | + * Send the same site cookies |
|
490 | + */ |
|
491 | + private static function sendSameSiteCookies(): void { |
|
492 | + $cookieParams = session_get_cookie_params(); |
|
493 | + $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
494 | + $policies = [ |
|
495 | + 'lax', |
|
496 | + 'strict', |
|
497 | + ]; |
|
498 | + |
|
499 | + // Append __Host to the cookie if it meets the requirements |
|
500 | + $cookiePrefix = ''; |
|
501 | + if ($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
502 | + $cookiePrefix = '__Host-'; |
|
503 | + } |
|
504 | + |
|
505 | + foreach ($policies as $policy) { |
|
506 | + header( |
|
507 | + sprintf( |
|
508 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
509 | + $cookiePrefix, |
|
510 | + $policy, |
|
511 | + $cookieParams['path'], |
|
512 | + $policy |
|
513 | + ), |
|
514 | + false |
|
515 | + ); |
|
516 | + } |
|
517 | + } |
|
518 | + |
|
519 | + /** |
|
520 | + * Same Site cookie to further mitigate CSRF attacks. This cookie has to |
|
521 | + * be set in every request if cookies are sent to add a second level of |
|
522 | + * defense against CSRF. |
|
523 | + * |
|
524 | + * If the cookie is not sent this will set the cookie and reload the page. |
|
525 | + * We use an additional cookie since we want to protect logout CSRF and |
|
526 | + * also we can't directly interfere with PHP's session mechanism. |
|
527 | + */ |
|
528 | + private static function performSameSiteCookieProtection(\OCP\IConfig $config): void { |
|
529 | + $request = Server::get(IRequest::class); |
|
530 | + |
|
531 | + // Some user agents are notorious and don't really properly follow HTTP |
|
532 | + // specifications. For those, have an automated opt-out. Since the protection |
|
533 | + // for remote.php is applied in base.php as starting point we need to opt out |
|
534 | + // here. |
|
535 | + $incompatibleUserAgents = $config->getSystemValue('csrf.optout'); |
|
536 | + |
|
537 | + // Fallback, if csrf.optout is unset |
|
538 | + if (!is_array($incompatibleUserAgents)) { |
|
539 | + $incompatibleUserAgents = [ |
|
540 | + // OS X Finder |
|
541 | + '/^WebDAVFS/', |
|
542 | + // Windows webdav drive |
|
543 | + '/^Microsoft-WebDAV-MiniRedir/', |
|
544 | + ]; |
|
545 | + } |
|
546 | + |
|
547 | + if ($request->isUserAgent($incompatibleUserAgents)) { |
|
548 | + return; |
|
549 | + } |
|
550 | + |
|
551 | + if (count($_COOKIE) > 0) { |
|
552 | + $requestUri = $request->getScriptName(); |
|
553 | + $processingScript = explode('/', $requestUri); |
|
554 | + $processingScript = $processingScript[count($processingScript) - 1]; |
|
555 | + |
|
556 | + // index.php routes are handled in the middleware |
|
557 | + if ($processingScript === 'index.php') { |
|
558 | + return; |
|
559 | + } |
|
560 | + |
|
561 | + // All other endpoints require the lax and the strict cookie |
|
562 | + if (!$request->passesStrictCookieCheck()) { |
|
563 | + self::sendSameSiteCookies(); |
|
564 | + // Debug mode gets access to the resources without strict cookie |
|
565 | + // due to the fact that the SabreDAV browser also lives there. |
|
566 | + if (!$config->getSystemValue('debug', false)) { |
|
567 | + http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
|
568 | + exit(); |
|
569 | + } |
|
570 | + } |
|
571 | + } elseif (!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
572 | + self::sendSameSiteCookies(); |
|
573 | + } |
|
574 | + } |
|
575 | + |
|
576 | + public static function init(): void { |
|
577 | + // calculate the root directories |
|
578 | + OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); |
|
579 | + |
|
580 | + // register autoloader |
|
581 | + $loaderStart = microtime(true); |
|
582 | + require_once __DIR__ . '/autoloader.php'; |
|
583 | + self::$loader = new \OC\Autoloader([ |
|
584 | + OC::$SERVERROOT . '/lib/private/legacy', |
|
585 | + ]); |
|
586 | + if (defined('PHPUNIT_RUN')) { |
|
587 | + self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
588 | + } |
|
589 | + spl_autoload_register([self::$loader, 'load']); |
|
590 | + $loaderEnd = microtime(true); |
|
591 | + |
|
592 | + self::$CLI = (php_sapi_name() == 'cli'); |
|
593 | + |
|
594 | + // Add default composer PSR-4 autoloader |
|
595 | + self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
596 | + self::$composerAutoloader->setApcuPrefix('composer_autoload'); |
|
597 | + |
|
598 | + try { |
|
599 | + self::initPaths(); |
|
600 | + // setup 3rdparty autoloader |
|
601 | + $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
602 | + if (!file_exists($vendorAutoLoad)) { |
|
603 | + throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
|
604 | + } |
|
605 | + require_once $vendorAutoLoad; |
|
606 | + } catch (\RuntimeException $e) { |
|
607 | + if (!self::$CLI) { |
|
608 | + http_response_code(503); |
|
609 | + } |
|
610 | + // we can't use the template error page here, because this needs the |
|
611 | + // DI container which isn't available yet |
|
612 | + print($e->getMessage()); |
|
613 | + exit(); |
|
614 | + } |
|
615 | + |
|
616 | + // setup the basic server |
|
617 | + self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); |
|
618 | + self::$server->boot(); |
|
619 | + |
|
620 | + $eventLogger = Server::get(\OCP\Diagnostics\IEventLogger::class); |
|
621 | + $eventLogger->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); |
|
622 | + $eventLogger->start('boot', 'Initialize'); |
|
623 | + |
|
624 | + // Override php.ini and log everything if we're troubleshooting |
|
625 | + if (self::$config->getValue('loglevel') === ILogger::DEBUG) { |
|
626 | + error_reporting(E_ALL); |
|
627 | + } |
|
628 | + |
|
629 | + // Don't display errors and log them |
|
630 | + @ini_set('display_errors', '0'); |
|
631 | + @ini_set('log_errors', '1'); |
|
632 | + |
|
633 | + if (!date_default_timezone_set('UTC')) { |
|
634 | + throw new \RuntimeException('Could not set timezone to UTC'); |
|
635 | + } |
|
636 | + |
|
637 | + |
|
638 | + //try to configure php to enable big file uploads. |
|
639 | + //this doesn´t work always depending on the webserver and php configuration. |
|
640 | + //Let´s try to overwrite some defaults if they are smaller than 1 hour |
|
641 | + |
|
642 | + if (intval(@ini_get('max_execution_time') ?? 0) < 3600) { |
|
643 | + @ini_set('max_execution_time', strval(3600)); |
|
644 | + } |
|
645 | + |
|
646 | + if (intval(@ini_get('max_input_time') ?? 0) < 3600) { |
|
647 | + @ini_set('max_input_time', strval(3600)); |
|
648 | + } |
|
649 | + |
|
650 | + //try to set the maximum execution time to the largest time limit we have |
|
651 | + if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
652 | + @set_time_limit(max(intval(@ini_get('max_execution_time')), intval(@ini_get('max_input_time')))); |
|
653 | + } |
|
654 | + |
|
655 | + self::setRequiredIniValues(); |
|
656 | + self::handleAuthHeaders(); |
|
657 | + $systemConfig = Server::get(\OC\SystemConfig::class); |
|
658 | + self::registerAutoloaderCache($systemConfig); |
|
659 | + |
|
660 | + // initialize intl fallback if necessary |
|
661 | + OC_Util::isSetLocaleWorking(); |
|
662 | + |
|
663 | + $config = Server::get(\OCP\IConfig::class); |
|
664 | + if (!defined('PHPUNIT_RUN')) { |
|
665 | + $errorHandler = new OC\Log\ErrorHandler( |
|
666 | + \OCP\Server::get(\Psr\Log\LoggerInterface::class), |
|
667 | + ); |
|
668 | + $exceptionHandler = [$errorHandler, 'onException']; |
|
669 | + if ($config->getSystemValue('debug', false)) { |
|
670 | + set_error_handler([$errorHandler, 'onAll'], E_ALL); |
|
671 | + if (\OC::$CLI) { |
|
672 | + $exceptionHandler = ['OC_Template', 'printExceptionErrorPage']; |
|
673 | + } |
|
674 | + } else { |
|
675 | + set_error_handler([$errorHandler, 'onError']); |
|
676 | + } |
|
677 | + register_shutdown_function([$errorHandler, 'onShutdown']); |
|
678 | + set_exception_handler($exceptionHandler); |
|
679 | + } |
|
680 | + |
|
681 | + /** @var \OC\AppFramework\Bootstrap\Coordinator $bootstrapCoordinator */ |
|
682 | + $bootstrapCoordinator = Server::get(\OC\AppFramework\Bootstrap\Coordinator::class); |
|
683 | + $bootstrapCoordinator->runInitialRegistration(); |
|
684 | + |
|
685 | + $eventLogger->start('init_session', 'Initialize session'); |
|
686 | + OC_App::loadApps(['session']); |
|
687 | + if (!self::$CLI) { |
|
688 | + self::initSession(); |
|
689 | + } |
|
690 | + $eventLogger->end('init_session'); |
|
691 | + self::checkConfig(); |
|
692 | + self::checkInstalled($systemConfig); |
|
693 | + |
|
694 | + OC_Response::addSecurityHeaders(); |
|
695 | + |
|
696 | + self::performSameSiteCookieProtection($config); |
|
697 | + |
|
698 | + if (!defined('OC_CONSOLE')) { |
|
699 | + $errors = OC_Util::checkServer($systemConfig); |
|
700 | + if (count($errors) > 0) { |
|
701 | + if (!self::$CLI) { |
|
702 | + http_response_code(503); |
|
703 | + OC_Util::addStyle('guest'); |
|
704 | + try { |
|
705 | + OC_Template::printGuestPage('', 'error', ['errors' => $errors]); |
|
706 | + exit; |
|
707 | + } catch (\Exception $e) { |
|
708 | + // In case any error happens when showing the error page, we simply fall back to posting the text. |
|
709 | + // This might be the case when e.g. the data directory is broken and we can not load/write SCSS to/from it. |
|
710 | + } |
|
711 | + } |
|
712 | + |
|
713 | + // Convert l10n string into regular string for usage in database |
|
714 | + $staticErrors = []; |
|
715 | + foreach ($errors as $error) { |
|
716 | + echo $error['error'] . "\n"; |
|
717 | + echo $error['hint'] . "\n\n"; |
|
718 | + $staticErrors[] = [ |
|
719 | + 'error' => (string)$error['error'], |
|
720 | + 'hint' => (string)$error['hint'], |
|
721 | + ]; |
|
722 | + } |
|
723 | + |
|
724 | + try { |
|
725 | + $config->setAppValue('core', 'cronErrors', json_encode($staticErrors)); |
|
726 | + } catch (\Exception $e) { |
|
727 | + echo('Writing to database failed'); |
|
728 | + } |
|
729 | + exit(1); |
|
730 | + } elseif (self::$CLI && $config->getSystemValue('installed', false)) { |
|
731 | + $config->deleteAppValue('core', 'cronErrors'); |
|
732 | + } |
|
733 | + } |
|
734 | + |
|
735 | + // User and Groups |
|
736 | + if (!$systemConfig->getValue("installed", false)) { |
|
737 | + self::$server->getSession()->set('user_id', ''); |
|
738 | + } |
|
739 | + |
|
740 | + OC_User::useBackend(new \OC\User\Database()); |
|
741 | + Server::get(\OCP\IGroupManager::class)->addBackend(new \OC\Group\Database()); |
|
742 | + |
|
743 | + // Subscribe to the hook |
|
744 | + \OCP\Util::connectHook( |
|
745 | + '\OCA\Files_Sharing\API\Server2Server', |
|
746 | + 'preLoginNameUsedAsUserName', |
|
747 | + '\OC\User\Database', |
|
748 | + 'preLoginNameUsedAsUserName' |
|
749 | + ); |
|
750 | + |
|
751 | + //setup extra user backends |
|
752 | + if (!\OCP\Util::needUpgrade()) { |
|
753 | + OC_User::setupBackends(); |
|
754 | + } else { |
|
755 | + // Run upgrades in incognito mode |
|
756 | + OC_User::setIncognitoMode(true); |
|
757 | + } |
|
758 | + |
|
759 | + self::registerCleanupHooks($systemConfig); |
|
760 | + self::registerShareHooks($systemConfig); |
|
761 | + self::registerEncryptionWrapperAndHooks(); |
|
762 | + self::registerAccountHooks(); |
|
763 | + self::registerResourceCollectionHooks(); |
|
764 | + self::registerFileReferenceEventListener(); |
|
765 | + self::registerRenderReferenceEventListener(); |
|
766 | + self::registerAppRestrictionsHooks(); |
|
767 | + |
|
768 | + // Make sure that the application class is not loaded before the database is setup |
|
769 | + if ($systemConfig->getValue("installed", false)) { |
|
770 | + OC_App::loadApp('settings'); |
|
771 | + /* Build core application to make sure that listeners are registered */ |
|
772 | + Server::get(\OC\Core\Application::class); |
|
773 | + } |
|
774 | + |
|
775 | + //make sure temporary files are cleaned up |
|
776 | + $tmpManager = Server::get(\OCP\ITempManager::class); |
|
777 | + register_shutdown_function([$tmpManager, 'clean']); |
|
778 | + $lockProvider = Server::get(\OCP\Lock\ILockingProvider::class); |
|
779 | + register_shutdown_function([$lockProvider, 'releaseAll']); |
|
780 | + |
|
781 | + // Check whether the sample configuration has been copied |
|
782 | + if ($systemConfig->getValue('copied_sample_config', false)) { |
|
783 | + $l = Server::get(\OCP\L10N\IFactory::class)->get('lib'); |
|
784 | + OC_Template::printErrorPage( |
|
785 | + $l->t('Sample configuration detected'), |
|
786 | + $l->t('It has been detected that the sample configuration has been copied. This can break your installation and is unsupported. Please read the documentation before performing changes on config.php'), |
|
787 | + 503 |
|
788 | + ); |
|
789 | + return; |
|
790 | + } |
|
791 | + |
|
792 | + $request = Server::get(IRequest::class); |
|
793 | + $host = $request->getInsecureServerHost(); |
|
794 | + /** |
|
795 | + * if the host passed in headers isn't trusted |
|
796 | + * FIXME: Should not be in here at all :see_no_evil: |
|
797 | + */ |
|
798 | + if (!OC::$CLI |
|
799 | + && !Server::get(\OC\Security\TrustedDomainHelper::class)->isTrustedDomain($host) |
|
800 | + && $config->getSystemValue('installed', false) |
|
801 | + ) { |
|
802 | + // Allow access to CSS resources |
|
803 | + $isScssRequest = false; |
|
804 | + if (strpos($request->getPathInfo() ?: '', '/css/') === 0) { |
|
805 | + $isScssRequest = true; |
|
806 | + } |
|
807 | + |
|
808 | + if (substr($request->getRequestUri(), -11) === '/status.php') { |
|
809 | + http_response_code(400); |
|
810 | + header('Content-Type: application/json'); |
|
811 | + echo '{"error": "Trusted domain error.", "code": 15}'; |
|
812 | + exit(); |
|
813 | + } |
|
814 | + |
|
815 | + if (!$isScssRequest) { |
|
816 | + http_response_code(400); |
|
817 | + Server::get(LoggerInterface::class)->info( |
|
818 | + 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', |
|
819 | + [ |
|
820 | + 'app' => 'core', |
|
821 | + 'remoteAddress' => $request->getRemoteAddress(), |
|
822 | + 'host' => $host, |
|
823 | + ] |
|
824 | + ); |
|
825 | + |
|
826 | + $tmpl = new OCP\Template('core', 'untrustedDomain', 'guest'); |
|
827 | + $tmpl->assign('docUrl', Server::get(IURLGenerator::class)->linkToDocs('admin-trusted-domains')); |
|
828 | + $tmpl->printPage(); |
|
829 | + |
|
830 | + exit(); |
|
831 | + } |
|
832 | + } |
|
833 | + $eventLogger->end('boot'); |
|
834 | + $eventLogger->log('init', 'OC::init', $loaderStart, microtime(true)); |
|
835 | + $eventLogger->start('runtime', 'Runtime'); |
|
836 | + $eventLogger->start('request', 'Full request after boot'); |
|
837 | + register_shutdown_function(function () use ($eventLogger) { |
|
838 | + $eventLogger->end('request'); |
|
839 | + }); |
|
840 | + } |
|
841 | + |
|
842 | + /** |
|
843 | + * register hooks for the cleanup of cache and bruteforce protection |
|
844 | + */ |
|
845 | + public static function registerCleanupHooks(\OC\SystemConfig $systemConfig): void { |
|
846 | + //don't try to do this before we are properly setup |
|
847 | + if ($systemConfig->getValue('installed', false) && !\OCP\Util::needUpgrade()) { |
|
848 | + // NOTE: This will be replaced to use OCP |
|
849 | + $userSession = Server::get(\OC\User\Session::class); |
|
850 | + $userSession->listen('\OC\User', 'postLogin', function () use ($userSession) { |
|
851 | + if (!defined('PHPUNIT_RUN') && $userSession->isLoggedIn()) { |
|
852 | + // reset brute force delay for this IP address and username |
|
853 | + $uid = $userSession->getUser()->getUID(); |
|
854 | + $request = Server::get(IRequest::class); |
|
855 | + $throttler = Server::get(\OC\Security\Bruteforce\Throttler::class); |
|
856 | + $throttler->resetDelay($request->getRemoteAddress(), 'login', ['user' => $uid]); |
|
857 | + } |
|
858 | + }); |
|
859 | + } |
|
860 | + } |
|
861 | + |
|
862 | + private static function registerEncryptionWrapperAndHooks(): void { |
|
863 | + $manager = Server::get(\OCP\Encryption\IManager::class); |
|
864 | + \OCP\Util::connectHook('OC_Filesystem', 'preSetup', $manager, 'setupStorage'); |
|
865 | + |
|
866 | + $enabled = $manager->isEnabled(); |
|
867 | + if ($enabled) { |
|
868 | + \OCP\Util::connectHook(Share::class, 'post_shared', HookManager::class, 'postShared'); |
|
869 | + \OCP\Util::connectHook(Share::class, 'post_unshare', HookManager::class, 'postUnshared'); |
|
870 | + \OCP\Util::connectHook('OC_Filesystem', 'post_rename', HookManager::class, 'postRename'); |
|
871 | + \OCP\Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', HookManager::class, 'postRestore'); |
|
872 | + } |
|
873 | + } |
|
874 | + |
|
875 | + private static function registerAccountHooks(): void { |
|
876 | + /** @var IEventDispatcher $dispatcher */ |
|
877 | + $dispatcher = Server::get(IEventDispatcher::class); |
|
878 | + $dispatcher->addServiceListener(UserChangedEvent::class, \OC\Accounts\Hooks::class); |
|
879 | + } |
|
880 | + |
|
881 | + private static function registerAppRestrictionsHooks(): void { |
|
882 | + /** @var \OC\Group\Manager $groupManager */ |
|
883 | + $groupManager = Server::get(\OCP\IGroupManager::class); |
|
884 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OCP\IGroup $group) { |
|
885 | + $appManager = Server::get(\OCP\App\IAppManager::class); |
|
886 | + $apps = $appManager->getEnabledAppsForGroup($group); |
|
887 | + foreach ($apps as $appId) { |
|
888 | + $restrictions = $appManager->getAppRestriction($appId); |
|
889 | + if (empty($restrictions)) { |
|
890 | + continue; |
|
891 | + } |
|
892 | + $key = array_search($group->getGID(), $restrictions); |
|
893 | + unset($restrictions[$key]); |
|
894 | + $restrictions = array_values($restrictions); |
|
895 | + if (empty($restrictions)) { |
|
896 | + $appManager->disableApp($appId); |
|
897 | + } else { |
|
898 | + $appManager->enableAppForGroups($appId, $restrictions); |
|
899 | + } |
|
900 | + } |
|
901 | + }); |
|
902 | + } |
|
903 | + |
|
904 | + private static function registerResourceCollectionHooks(): void { |
|
905 | + \OC\Collaboration\Resources\Listener::register(Server::get(SymfonyAdapter::class), Server::get(IEventDispatcher::class)); |
|
906 | + } |
|
907 | + |
|
908 | + private static function registerFileReferenceEventListener(): void { |
|
909 | + \OC\Collaboration\Reference\File\FileReferenceEventListener::register(Server::get(IEventDispatcher::class)); |
|
910 | + } |
|
911 | + |
|
912 | + private static function registerRenderReferenceEventListener() { |
|
913 | + \OC\Collaboration\Reference\RenderReferenceEventListener::register(Server::get(IEventDispatcher::class)); |
|
914 | + } |
|
915 | + |
|
916 | + /** |
|
917 | + * register hooks for sharing |
|
918 | + */ |
|
919 | + public static function registerShareHooks(\OC\SystemConfig $systemConfig): void { |
|
920 | + if ($systemConfig->getValue('installed')) { |
|
921 | + OC_Hook::connect('OC_User', 'post_deleteUser', Hooks::class, 'post_deleteUser'); |
|
922 | + OC_Hook::connect('OC_User', 'post_deleteGroup', Hooks::class, 'post_deleteGroup'); |
|
923 | + |
|
924 | + /** @var IEventDispatcher $dispatcher */ |
|
925 | + $dispatcher = Server::get(IEventDispatcher::class); |
|
926 | + $dispatcher->addServiceListener(UserRemovedEvent::class, \OC\Share20\UserRemovedListener::class); |
|
927 | + } |
|
928 | + } |
|
929 | + |
|
930 | + protected static function registerAutoloaderCache(\OC\SystemConfig $systemConfig): void { |
|
931 | + // The class loader takes an optional low-latency cache, which MUST be |
|
932 | + // namespaced. The instanceid is used for namespacing, but might be |
|
933 | + // unavailable at this point. Furthermore, it might not be possible to |
|
934 | + // generate an instanceid via \OC_Util::getInstanceId() because the |
|
935 | + // config file may not be writable. As such, we only register a class |
|
936 | + // loader cache if instanceid is available without trying to create one. |
|
937 | + $instanceId = $systemConfig->getValue('instanceid', null); |
|
938 | + if ($instanceId) { |
|
939 | + try { |
|
940 | + $memcacheFactory = Server::get(\OCP\ICacheFactory::class); |
|
941 | + self::$loader->setMemoryCache($memcacheFactory->createLocal('Autoloader')); |
|
942 | + } catch (\Exception $ex) { |
|
943 | + } |
|
944 | + } |
|
945 | + } |
|
946 | + |
|
947 | + /** |
|
948 | + * Handle the request |
|
949 | + */ |
|
950 | + public static function handleRequest(): void { |
|
951 | + Server::get(\OCP\Diagnostics\IEventLogger::class)->start('handle_request', 'Handle request'); |
|
952 | + $systemConfig = Server::get(\OC\SystemConfig::class); |
|
953 | + |
|
954 | + // Check if Nextcloud is installed or in maintenance (update) mode |
|
955 | + if (!$systemConfig->getValue('installed', false)) { |
|
956 | + \OC::$server->getSession()->clear(); |
|
957 | + $setupHelper = new OC\Setup( |
|
958 | + $systemConfig, |
|
959 | + Server::get(\bantu\IniGetWrapper\IniGetWrapper::class), |
|
960 | + Server::get(\OCP\L10N\IFactory::class)->get('lib'), |
|
961 | + Server::get(\OCP\Defaults::class), |
|
962 | + Server::get(\Psr\Log\LoggerInterface::class), |
|
963 | + Server::get(\OCP\Security\ISecureRandom::class), |
|
964 | + Server::get(\OC\Installer::class) |
|
965 | + ); |
|
966 | + $controller = new OC\Core\Controller\SetupController($setupHelper); |
|
967 | + $controller->run($_POST); |
|
968 | + exit(); |
|
969 | + } |
|
970 | + |
|
971 | + $request = Server::get(IRequest::class); |
|
972 | + $requestPath = $request->getRawPathInfo(); |
|
973 | + if ($requestPath === '/heartbeat') { |
|
974 | + return; |
|
975 | + } |
|
976 | + if (substr($requestPath, -3) !== '.js') { // we need these files during the upgrade |
|
977 | + self::checkMaintenanceMode($systemConfig); |
|
978 | + |
|
979 | + if (\OCP\Util::needUpgrade()) { |
|
980 | + if (function_exists('opcache_reset')) { |
|
981 | + opcache_reset(); |
|
982 | + } |
|
983 | + if (!((bool) $systemConfig->getValue('maintenance', false))) { |
|
984 | + self::printUpgradePage($systemConfig); |
|
985 | + exit(); |
|
986 | + } |
|
987 | + } |
|
988 | + } |
|
989 | + |
|
990 | + // emergency app disabling |
|
991 | + if ($requestPath === '/disableapp' |
|
992 | + && $request->getMethod() === 'POST' |
|
993 | + ) { |
|
994 | + \OC_JSON::callCheck(); |
|
995 | + \OC_JSON::checkAdminUser(); |
|
996 | + $appIds = (array)$request->getParam('appid'); |
|
997 | + foreach ($appIds as $appId) { |
|
998 | + $appId = \OC_App::cleanAppId($appId); |
|
999 | + Server::get(\OCP\App\IAppManager::class)->disableApp($appId); |
|
1000 | + } |
|
1001 | + \OC_JSON::success(); |
|
1002 | + exit(); |
|
1003 | + } |
|
1004 | + |
|
1005 | + // Always load authentication apps |
|
1006 | + OC_App::loadApps(['authentication']); |
|
1007 | + |
|
1008 | + // Load minimum set of apps |
|
1009 | + if (!\OCP\Util::needUpgrade() |
|
1010 | + && !((bool) $systemConfig->getValue('maintenance', false))) { |
|
1011 | + // For logged-in users: Load everything |
|
1012 | + if (Server::get(IUserSession::class)->isLoggedIn()) { |
|
1013 | + OC_App::loadApps(); |
|
1014 | + } else { |
|
1015 | + // For guests: Load only filesystem and logging |
|
1016 | + OC_App::loadApps(['filesystem', 'logging']); |
|
1017 | + |
|
1018 | + // Don't try to login when a client is trying to get a OAuth token. |
|
1019 | + // OAuth needs to support basic auth too, so the login is not valid |
|
1020 | + // inside Nextcloud and the Login exception would ruin it. |
|
1021 | + if ($request->getRawPathInfo() !== '/apps/oauth2/api/v1/token') { |
|
1022 | + self::handleLogin($request); |
|
1023 | + } |
|
1024 | + } |
|
1025 | + } |
|
1026 | + |
|
1027 | + if (!self::$CLI) { |
|
1028 | + try { |
|
1029 | + if (!((bool) $systemConfig->getValue('maintenance', false)) && !\OCP\Util::needUpgrade()) { |
|
1030 | + OC_App::loadApps(['filesystem', 'logging']); |
|
1031 | + OC_App::loadApps(); |
|
1032 | + } |
|
1033 | + Server::get(\OC\Route\Router::class)->match($request->getRawPathInfo()); |
|
1034 | + return; |
|
1035 | + } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { |
|
1036 | + //header('HTTP/1.0 404 Not Found'); |
|
1037 | + } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { |
|
1038 | + http_response_code(405); |
|
1039 | + return; |
|
1040 | + } |
|
1041 | + } |
|
1042 | + |
|
1043 | + // Handle WebDAV |
|
1044 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
1045 | + // not allowed any more to prevent people |
|
1046 | + // mounting this root directly. |
|
1047 | + // Users need to mount remote.php/webdav instead. |
|
1048 | + http_response_code(405); |
|
1049 | + return; |
|
1050 | + } |
|
1051 | + |
|
1052 | + // Handle requests for JSON or XML |
|
1053 | + $acceptHeader = $request->getHeader('Accept'); |
|
1054 | + if (in_array($acceptHeader, ['application/json', 'application/xml'], true)) { |
|
1055 | + http_response_code(404); |
|
1056 | + return; |
|
1057 | + } |
|
1058 | + |
|
1059 | + // Handle resources that can't be found |
|
1060 | + // This prevents browsers from redirecting to the default page and then |
|
1061 | + // attempting to parse HTML as CSS and similar. |
|
1062 | + $destinationHeader = $request->getHeader('Sec-Fetch-Dest'); |
|
1063 | + if (in_array($destinationHeader, ['font', 'script', 'style'])) { |
|
1064 | + http_response_code(404); |
|
1065 | + return; |
|
1066 | + } |
|
1067 | + |
|
1068 | + // Redirect to the default app or login only as an entry point |
|
1069 | + if ($requestPath === '') { |
|
1070 | + // Someone is logged in |
|
1071 | + if (Server::get(IUserSession::class)->isLoggedIn()) { |
|
1072 | + header('Location: ' . Server::get(IURLGenerator::class)->linkToDefaultPageUrl()); |
|
1073 | + } else { |
|
1074 | + // Not handled and not logged in |
|
1075 | + header('Location: ' . Server::get(IURLGenerator::class)->linkToRouteAbsolute('core.login.showLoginForm')); |
|
1076 | + } |
|
1077 | + return; |
|
1078 | + } |
|
1079 | + |
|
1080 | + try { |
|
1081 | + Server::get(\OC\Route\Router::class)->match('/error/404'); |
|
1082 | + } catch (\Exception $e) { |
|
1083 | + logger('core')->emergency($e->getMessage(), ['exception' => $e]); |
|
1084 | + $l = Server::get(\OCP\L10N\IFactory::class)->get('lib'); |
|
1085 | + OC_Template::printErrorPage( |
|
1086 | + $l->t('404'), |
|
1087 | + $l->t('The page could not be found on the server.'), |
|
1088 | + 404 |
|
1089 | + ); |
|
1090 | + } |
|
1091 | + } |
|
1092 | + |
|
1093 | + /** |
|
1094 | + * Check login: apache auth, auth token, basic auth |
|
1095 | + */ |
|
1096 | + public static function handleLogin(OCP\IRequest $request): bool { |
|
1097 | + $userSession = Server::get(\OC\User\Session::class); |
|
1098 | + if (OC_User::handleApacheAuth()) { |
|
1099 | + return true; |
|
1100 | + } |
|
1101 | + if ($userSession->tryTokenLogin($request)) { |
|
1102 | + return true; |
|
1103 | + } |
|
1104 | + if (isset($_COOKIE['nc_username']) |
|
1105 | + && isset($_COOKIE['nc_token']) |
|
1106 | + && isset($_COOKIE['nc_session_id']) |
|
1107 | + && $userSession->loginWithCookie($_COOKIE['nc_username'], $_COOKIE['nc_token'], $_COOKIE['nc_session_id'])) { |
|
1108 | + return true; |
|
1109 | + } |
|
1110 | + if ($userSession->tryBasicAuthLogin($request, Server::get(\OC\Security\Bruteforce\Throttler::class))) { |
|
1111 | + return true; |
|
1112 | + } |
|
1113 | + return false; |
|
1114 | + } |
|
1115 | + |
|
1116 | + protected static function handleAuthHeaders(): void { |
|
1117 | + //copy http auth headers for apache+php-fcgid work around |
|
1118 | + if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { |
|
1119 | + $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; |
|
1120 | + } |
|
1121 | + |
|
1122 | + // Extract PHP_AUTH_USER/PHP_AUTH_PW from other headers if necessary. |
|
1123 | + $vars = [ |
|
1124 | + 'HTTP_AUTHORIZATION', // apache+php-cgi work around |
|
1125 | + 'REDIRECT_HTTP_AUTHORIZATION', // apache+php-cgi alternative |
|
1126 | + ]; |
|
1127 | + foreach ($vars as $var) { |
|
1128 | + if (isset($_SERVER[$var]) && is_string($_SERVER[$var]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$var], $matches)) { |
|
1129 | + $credentials = explode(':', base64_decode($matches[1]), 2); |
|
1130 | + if (count($credentials) === 2) { |
|
1131 | + $_SERVER['PHP_AUTH_USER'] = $credentials[0]; |
|
1132 | + $_SERVER['PHP_AUTH_PW'] = $credentials[1]; |
|
1133 | + break; |
|
1134 | + } |
|
1135 | + } |
|
1136 | + } |
|
1137 | + } |
|
1138 | 1138 | } |
1139 | 1139 | |
1140 | 1140 | OC::init(); |
@@ -40,165 +40,165 @@ |
||
40 | 40 | |
41 | 41 | class ObjectTree extends CachingTree { |
42 | 42 | |
43 | - /** |
|
44 | - * @var \OC\Files\View |
|
45 | - */ |
|
46 | - protected $fileView; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var \OCP\Files\Mount\IMountManager |
|
50 | - */ |
|
51 | - protected $mountManager; |
|
52 | - |
|
53 | - /** |
|
54 | - * Creates the object |
|
55 | - */ |
|
56 | - public function __construct() { |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * @param \Sabre\DAV\INode $rootNode |
|
61 | - * @param \OC\Files\View $view |
|
62 | - * @param \OCP\Files\Mount\IMountManager $mountManager |
|
63 | - */ |
|
64 | - public function init(\Sabre\DAV\INode $rootNode, \OC\Files\View $view, \OCP\Files\Mount\IMountManager $mountManager) { |
|
65 | - $this->rootNode = $rootNode; |
|
66 | - $this->fileView = $view; |
|
67 | - $this->mountManager = $mountManager; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Returns the INode object for the requested path |
|
72 | - * |
|
73 | - * @param string $path |
|
74 | - * @return \Sabre\DAV\INode |
|
75 | - * @throws InvalidPath |
|
76 | - * @throws \Sabre\DAV\Exception\Locked |
|
77 | - * @throws \Sabre\DAV\Exception\NotFound |
|
78 | - * @throws \Sabre\DAV\Exception\ServiceUnavailable |
|
79 | - */ |
|
80 | - public function getNodeForPath($path) { |
|
81 | - if (!$this->fileView) { |
|
82 | - throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup'); |
|
83 | - } |
|
84 | - |
|
85 | - $path = trim($path, '/'); |
|
86 | - |
|
87 | - if (isset($this->cache[$path])) { |
|
88 | - return $this->cache[$path]; |
|
89 | - } |
|
90 | - |
|
91 | - if ($path) { |
|
92 | - try { |
|
93 | - $this->fileView->verifyPath($path, basename($path)); |
|
94 | - } catch (\OCP\Files\InvalidPathException $ex) { |
|
95 | - throw new InvalidPath($ex->getMessage()); |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - // Is it the root node? |
|
100 | - if (!strlen($path)) { |
|
101 | - return $this->rootNode; |
|
102 | - } |
|
103 | - |
|
104 | - if (pathinfo($path, PATHINFO_EXTENSION) === 'part') { |
|
105 | - // read from storage |
|
106 | - $absPath = $this->fileView->getAbsolutePath($path); |
|
107 | - $mount = $this->fileView->getMount($path); |
|
108 | - $storage = $mount->getStorage(); |
|
109 | - $internalPath = $mount->getInternalPath($absPath); |
|
110 | - if ($storage && $storage->file_exists($internalPath)) { |
|
111 | - /** |
|
112 | - * @var \OC\Files\Storage\Storage $storage |
|
113 | - */ |
|
114 | - // get data directly |
|
115 | - $data = $storage->getMetaData($internalPath); |
|
116 | - $info = new FileInfo($absPath, $storage, $internalPath, $data, $mount); |
|
117 | - } else { |
|
118 | - $info = null; |
|
119 | - } |
|
120 | - } else { |
|
121 | - // read from cache |
|
122 | - try { |
|
123 | - $info = $this->fileView->getFileInfo($path); |
|
124 | - |
|
125 | - if ($info instanceof \OCP\Files\FileInfo && $info->getStorage()->instanceOfStorage(FailedStorage::class)) { |
|
126 | - throw new StorageNotAvailableException(); |
|
127 | - } |
|
128 | - } catch (StorageNotAvailableException $e) { |
|
129 | - throw new \Sabre\DAV\Exception\ServiceUnavailable('Storage is temporarily not available', 0, $e); |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - if (!$info) { |
|
134 | - throw new \Sabre\DAV\Exception\NotFound('File with name ' . $path . ' could not be located'); |
|
135 | - } |
|
136 | - |
|
137 | - if ($info->getType() === 'dir') { |
|
138 | - $node = new \OCA\DAV\Connector\Sabre\Directory($this->fileView, $info, $this); |
|
139 | - } else { |
|
140 | - $node = new \OCA\DAV\Connector\Sabre\File($this->fileView, $info); |
|
141 | - } |
|
142 | - |
|
143 | - $this->cache[$path] = $node; |
|
144 | - return $node; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Copies a file or directory. |
|
149 | - * |
|
150 | - * This method must work recursively and delete the destination |
|
151 | - * if it exists |
|
152 | - * |
|
153 | - * @param string $sourcePath |
|
154 | - * @param string $destinationPath |
|
155 | - * @throws FileLocked |
|
156 | - * @throws Forbidden |
|
157 | - * @throws InvalidPath |
|
158 | - * @throws \Exception |
|
159 | - * @throws \Sabre\DAV\Exception\Forbidden |
|
160 | - * @throws \Sabre\DAV\Exception\Locked |
|
161 | - * @throws \Sabre\DAV\Exception\NotFound |
|
162 | - * @throws \Sabre\DAV\Exception\ServiceUnavailable |
|
163 | - * @return void |
|
164 | - */ |
|
165 | - public function copy($sourcePath, $destinationPath) { |
|
166 | - if (!$this->fileView) { |
|
167 | - throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup'); |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - $info = $this->fileView->getFileInfo(dirname($destinationPath)); |
|
172 | - if ($this->fileView->file_exists($destinationPath)) { |
|
173 | - $destinationPermission = $info && $info->isUpdateable(); |
|
174 | - } else { |
|
175 | - $destinationPermission = $info && $info->isCreatable(); |
|
176 | - } |
|
177 | - if (!$destinationPermission) { |
|
178 | - throw new Forbidden('No permissions to copy object.'); |
|
179 | - } |
|
180 | - |
|
181 | - // this will trigger existence check |
|
182 | - $this->getNodeForPath($sourcePath); |
|
183 | - |
|
184 | - [$destinationDir, $destinationName] = \Sabre\Uri\split($destinationPath); |
|
185 | - try { |
|
186 | - $this->fileView->verifyPath($destinationDir, $destinationName); |
|
187 | - } catch (\OCP\Files\InvalidPathException $ex) { |
|
188 | - throw new InvalidPath($ex->getMessage()); |
|
189 | - } |
|
190 | - |
|
191 | - try { |
|
192 | - $this->fileView->copy($sourcePath, $destinationPath); |
|
193 | - } catch (StorageNotAvailableException $e) { |
|
194 | - throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage()); |
|
195 | - } catch (ForbiddenException $ex) { |
|
196 | - throw new Forbidden($ex->getMessage(), $ex->getRetry()); |
|
197 | - } catch (LockedException $e) { |
|
198 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
199 | - } |
|
200 | - |
|
201 | - [$destinationDir,] = \Sabre\Uri\split($destinationPath); |
|
202 | - $this->markDirty($destinationDir); |
|
203 | - } |
|
43 | + /** |
|
44 | + * @var \OC\Files\View |
|
45 | + */ |
|
46 | + protected $fileView; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var \OCP\Files\Mount\IMountManager |
|
50 | + */ |
|
51 | + protected $mountManager; |
|
52 | + |
|
53 | + /** |
|
54 | + * Creates the object |
|
55 | + */ |
|
56 | + public function __construct() { |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * @param \Sabre\DAV\INode $rootNode |
|
61 | + * @param \OC\Files\View $view |
|
62 | + * @param \OCP\Files\Mount\IMountManager $mountManager |
|
63 | + */ |
|
64 | + public function init(\Sabre\DAV\INode $rootNode, \OC\Files\View $view, \OCP\Files\Mount\IMountManager $mountManager) { |
|
65 | + $this->rootNode = $rootNode; |
|
66 | + $this->fileView = $view; |
|
67 | + $this->mountManager = $mountManager; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Returns the INode object for the requested path |
|
72 | + * |
|
73 | + * @param string $path |
|
74 | + * @return \Sabre\DAV\INode |
|
75 | + * @throws InvalidPath |
|
76 | + * @throws \Sabre\DAV\Exception\Locked |
|
77 | + * @throws \Sabre\DAV\Exception\NotFound |
|
78 | + * @throws \Sabre\DAV\Exception\ServiceUnavailable |
|
79 | + */ |
|
80 | + public function getNodeForPath($path) { |
|
81 | + if (!$this->fileView) { |
|
82 | + throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup'); |
|
83 | + } |
|
84 | + |
|
85 | + $path = trim($path, '/'); |
|
86 | + |
|
87 | + if (isset($this->cache[$path])) { |
|
88 | + return $this->cache[$path]; |
|
89 | + } |
|
90 | + |
|
91 | + if ($path) { |
|
92 | + try { |
|
93 | + $this->fileView->verifyPath($path, basename($path)); |
|
94 | + } catch (\OCP\Files\InvalidPathException $ex) { |
|
95 | + throw new InvalidPath($ex->getMessage()); |
|
96 | + } |
|
97 | + } |
|
98 | + |
|
99 | + // Is it the root node? |
|
100 | + if (!strlen($path)) { |
|
101 | + return $this->rootNode; |
|
102 | + } |
|
103 | + |
|
104 | + if (pathinfo($path, PATHINFO_EXTENSION) === 'part') { |
|
105 | + // read from storage |
|
106 | + $absPath = $this->fileView->getAbsolutePath($path); |
|
107 | + $mount = $this->fileView->getMount($path); |
|
108 | + $storage = $mount->getStorage(); |
|
109 | + $internalPath = $mount->getInternalPath($absPath); |
|
110 | + if ($storage && $storage->file_exists($internalPath)) { |
|
111 | + /** |
|
112 | + * @var \OC\Files\Storage\Storage $storage |
|
113 | + */ |
|
114 | + // get data directly |
|
115 | + $data = $storage->getMetaData($internalPath); |
|
116 | + $info = new FileInfo($absPath, $storage, $internalPath, $data, $mount); |
|
117 | + } else { |
|
118 | + $info = null; |
|
119 | + } |
|
120 | + } else { |
|
121 | + // read from cache |
|
122 | + try { |
|
123 | + $info = $this->fileView->getFileInfo($path); |
|
124 | + |
|
125 | + if ($info instanceof \OCP\Files\FileInfo && $info->getStorage()->instanceOfStorage(FailedStorage::class)) { |
|
126 | + throw new StorageNotAvailableException(); |
|
127 | + } |
|
128 | + } catch (StorageNotAvailableException $e) { |
|
129 | + throw new \Sabre\DAV\Exception\ServiceUnavailable('Storage is temporarily not available', 0, $e); |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + if (!$info) { |
|
134 | + throw new \Sabre\DAV\Exception\NotFound('File with name ' . $path . ' could not be located'); |
|
135 | + } |
|
136 | + |
|
137 | + if ($info->getType() === 'dir') { |
|
138 | + $node = new \OCA\DAV\Connector\Sabre\Directory($this->fileView, $info, $this); |
|
139 | + } else { |
|
140 | + $node = new \OCA\DAV\Connector\Sabre\File($this->fileView, $info); |
|
141 | + } |
|
142 | + |
|
143 | + $this->cache[$path] = $node; |
|
144 | + return $node; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Copies a file or directory. |
|
149 | + * |
|
150 | + * This method must work recursively and delete the destination |
|
151 | + * if it exists |
|
152 | + * |
|
153 | + * @param string $sourcePath |
|
154 | + * @param string $destinationPath |
|
155 | + * @throws FileLocked |
|
156 | + * @throws Forbidden |
|
157 | + * @throws InvalidPath |
|
158 | + * @throws \Exception |
|
159 | + * @throws \Sabre\DAV\Exception\Forbidden |
|
160 | + * @throws \Sabre\DAV\Exception\Locked |
|
161 | + * @throws \Sabre\DAV\Exception\NotFound |
|
162 | + * @throws \Sabre\DAV\Exception\ServiceUnavailable |
|
163 | + * @return void |
|
164 | + */ |
|
165 | + public function copy($sourcePath, $destinationPath) { |
|
166 | + if (!$this->fileView) { |
|
167 | + throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup'); |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + $info = $this->fileView->getFileInfo(dirname($destinationPath)); |
|
172 | + if ($this->fileView->file_exists($destinationPath)) { |
|
173 | + $destinationPermission = $info && $info->isUpdateable(); |
|
174 | + } else { |
|
175 | + $destinationPermission = $info && $info->isCreatable(); |
|
176 | + } |
|
177 | + if (!$destinationPermission) { |
|
178 | + throw new Forbidden('No permissions to copy object.'); |
|
179 | + } |
|
180 | + |
|
181 | + // this will trigger existence check |
|
182 | + $this->getNodeForPath($sourcePath); |
|
183 | + |
|
184 | + [$destinationDir, $destinationName] = \Sabre\Uri\split($destinationPath); |
|
185 | + try { |
|
186 | + $this->fileView->verifyPath($destinationDir, $destinationName); |
|
187 | + } catch (\OCP\Files\InvalidPathException $ex) { |
|
188 | + throw new InvalidPath($ex->getMessage()); |
|
189 | + } |
|
190 | + |
|
191 | + try { |
|
192 | + $this->fileView->copy($sourcePath, $destinationPath); |
|
193 | + } catch (StorageNotAvailableException $e) { |
|
194 | + throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage()); |
|
195 | + } catch (ForbiddenException $ex) { |
|
196 | + throw new Forbidden($ex->getMessage(), $ex->getRetry()); |
|
197 | + } catch (LockedException $e) { |
|
198 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
199 | + } |
|
200 | + |
|
201 | + [$destinationDir,] = \Sabre\Uri\split($destinationPath); |
|
202 | + $this->markDirty($destinationDir); |
|
203 | + } |
|
204 | 204 | } |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | } |
132 | 132 | |
133 | 133 | if (!$info) { |
134 | - throw new \Sabre\DAV\Exception\NotFound('File with name ' . $path . ' could not be located'); |
|
134 | + throw new \Sabre\DAV\Exception\NotFound('File with name '.$path.' could not be located'); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | if ($info->getType() === 'dir') { |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
199 | 199 | } |
200 | 200 | |
201 | - [$destinationDir,] = \Sabre\Uri\split($destinationPath); |
|
201 | + [$destinationDir, ] = \Sabre\Uri\split($destinationPath); |
|
202 | 202 | $this->markDirty($destinationDir); |
203 | 203 | } |
204 | 204 | } |
@@ -59,415 +59,415 @@ |
||
59 | 59 | |
60 | 60 | class Directory extends \OCA\DAV\Connector\Sabre\Node implements \Sabre\DAV\ICollection, \Sabre\DAV\IQuota, \Sabre\DAV\IMoveTarget, \Sabre\DAV\ICopyTarget { |
61 | 61 | |
62 | - /** |
|
63 | - * Cached directory content |
|
64 | - * @var \OCP\Files\FileInfo[] |
|
65 | - */ |
|
66 | - private ?array $dirContent = null; |
|
67 | - |
|
68 | - /** Cached quota info */ |
|
69 | - private ?array $quotaInfo = null; |
|
70 | - private ?CachingTree $tree = null; |
|
71 | - |
|
72 | - /** @var array<string, array<int, FileMetadata>> */ |
|
73 | - private array $metadata = []; |
|
74 | - |
|
75 | - /** |
|
76 | - * Sets up the node, expects a full path name |
|
77 | - */ |
|
78 | - public function __construct(View $view, FileInfo $info, ?CachingTree $tree = null, IShareManager $shareManager = null) { |
|
79 | - parent::__construct($view, $info, $shareManager); |
|
80 | - $this->tree = $tree; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Creates a new file in the directory |
|
85 | - * |
|
86 | - * Data will either be supplied as a stream resource, or in certain cases |
|
87 | - * as a string. Keep in mind that you may have to support either. |
|
88 | - * |
|
89 | - * After successful creation of the file, you may choose to return the ETag |
|
90 | - * of the new file here. |
|
91 | - * |
|
92 | - * The returned ETag must be surrounded by double-quotes (The quotes should |
|
93 | - * be part of the actual string). |
|
94 | - * |
|
95 | - * If you cannot accurately determine the ETag, you should not return it. |
|
96 | - * If you don't store the file exactly as-is (you're transforming it |
|
97 | - * somehow) you should also not return an ETag. |
|
98 | - * |
|
99 | - * This means that if a subsequent GET to this new file does not exactly |
|
100 | - * return the same contents of what was submitted here, you are strongly |
|
101 | - * recommended to omit the ETag. |
|
102 | - * |
|
103 | - * @param string $name Name of the file |
|
104 | - * @param resource|string $data Initial payload |
|
105 | - * @return null|string |
|
106 | - * @throws Exception\UnsupportedMediaType |
|
107 | - * @throws FileLocked |
|
108 | - * @throws InvalidPath |
|
109 | - * @throws Exception |
|
110 | - * @throws BadRequest |
|
111 | - * @throws Exception\Forbidden |
|
112 | - * @throws ServiceUnavailable |
|
113 | - */ |
|
114 | - public function createFile($name, $data = null) { |
|
115 | - try { |
|
116 | - // For non-chunked upload it is enough to check if we can create a new file |
|
117 | - if (!$this->fileView->isCreatable($this->path)) { |
|
118 | - throw new Exception\Forbidden(); |
|
119 | - } |
|
120 | - |
|
121 | - $this->fileView->verifyPath($this->path, $name); |
|
122 | - |
|
123 | - $path = $this->fileView->getAbsolutePath($this->path) . '/' . $name; |
|
124 | - // in case the file already exists/overwriting |
|
125 | - $info = $this->fileView->getFileInfo($this->path . '/' . $name); |
|
126 | - if (!$info) { |
|
127 | - // use a dummy FileInfo which is acceptable here since it will be refreshed after the put is complete |
|
128 | - $info = new \OC\Files\FileInfo($path, null, null, [ |
|
129 | - 'type' => FileInfo::TYPE_FILE |
|
130 | - ], null); |
|
131 | - } |
|
132 | - $node = new \OCA\DAV\Connector\Sabre\File($this->fileView, $info); |
|
133 | - |
|
134 | - // only allow 1 process to upload a file at once but still allow reading the file while writing the part file |
|
135 | - $node->acquireLock(ILockingProvider::LOCK_SHARED); |
|
136 | - $this->fileView->lockFile($path . '.upload.part', ILockingProvider::LOCK_EXCLUSIVE); |
|
137 | - |
|
138 | - $result = $node->put($data); |
|
139 | - |
|
140 | - $this->fileView->unlockFile($path . '.upload.part', ILockingProvider::LOCK_EXCLUSIVE); |
|
141 | - $node->releaseLock(ILockingProvider::LOCK_SHARED); |
|
142 | - return $result; |
|
143 | - } catch (StorageNotAvailableException $e) { |
|
144 | - throw new ServiceUnavailable($e->getMessage()); |
|
145 | - } catch (InvalidPathException $ex) { |
|
146 | - throw new InvalidPath($ex->getMessage(), false, $ex); |
|
147 | - } catch (ForbiddenException $ex) { |
|
148 | - throw new Forbidden($ex->getMessage(), $ex->getRetry(), $ex); |
|
149 | - } catch (LockedException $e) { |
|
150 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
151 | - } |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Creates a new subdirectory |
|
156 | - * |
|
157 | - * @param string $name |
|
158 | - * @throws FileLocked |
|
159 | - * @throws InvalidPath |
|
160 | - * @throws Exception\Forbidden |
|
161 | - * @throws ServiceUnavailable |
|
162 | - */ |
|
163 | - public function createDirectory($name) { |
|
164 | - try { |
|
165 | - if (!$this->info->isCreatable()) { |
|
166 | - throw new Exception\Forbidden(); |
|
167 | - } |
|
168 | - |
|
169 | - $this->fileView->verifyPath($this->path, $name); |
|
170 | - $newPath = $this->path . '/' . $name; |
|
171 | - if (!$this->fileView->mkdir($newPath)) { |
|
172 | - throw new Exception\Forbidden('Could not create directory ' . $newPath); |
|
173 | - } |
|
174 | - } catch (StorageNotAvailableException $e) { |
|
175 | - throw new ServiceUnavailable($e->getMessage()); |
|
176 | - } catch (InvalidPathException $ex) { |
|
177 | - throw new InvalidPath($ex->getMessage()); |
|
178 | - } catch (ForbiddenException $ex) { |
|
179 | - throw new Forbidden($ex->getMessage(), $ex->getRetry()); |
|
180 | - } catch (LockedException $e) { |
|
181 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
182 | - } |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Returns a specific child node, referenced by its name |
|
187 | - * |
|
188 | - * @param string $name |
|
189 | - * @param \OCP\Files\FileInfo $info |
|
190 | - * @return \Sabre\DAV\INode |
|
191 | - * @throws InvalidPath |
|
192 | - * @throws \Sabre\DAV\Exception\NotFound |
|
193 | - * @throws ServiceUnavailable |
|
194 | - */ |
|
195 | - public function getChild($name, $info = null) { |
|
196 | - if (!$this->info->isReadable()) { |
|
197 | - // avoid detecting files through this way |
|
198 | - throw new NotFound(); |
|
199 | - } |
|
200 | - |
|
201 | - $path = $this->path . '/' . $name; |
|
202 | - if (is_null($info)) { |
|
203 | - try { |
|
204 | - $this->fileView->verifyPath($this->path, $name); |
|
205 | - $info = $this->fileView->getFileInfo($path); |
|
206 | - } catch (StorageNotAvailableException $e) { |
|
207 | - throw new ServiceUnavailable($e->getMessage()); |
|
208 | - } catch (InvalidPathException $ex) { |
|
209 | - throw new InvalidPath($ex->getMessage()); |
|
210 | - } catch (ForbiddenException $e) { |
|
211 | - throw new Exception\Forbidden(); |
|
212 | - } |
|
213 | - } |
|
214 | - |
|
215 | - if (!$info) { |
|
216 | - throw new \Sabre\DAV\Exception\NotFound('File with name ' . $path . ' could not be located'); |
|
217 | - } |
|
218 | - |
|
219 | - if ($info->getMimeType() === FileInfo::MIMETYPE_FOLDER) { |
|
220 | - $node = new \OCA\DAV\Connector\Sabre\Directory($this->fileView, $info, $this->tree, $this->shareManager); |
|
221 | - } else { |
|
222 | - $node = new \OCA\DAV\Connector\Sabre\File($this->fileView, $info, $this->shareManager); |
|
223 | - } |
|
224 | - if ($this->tree) { |
|
225 | - $this->tree->cacheNode($node); |
|
226 | - } |
|
227 | - return $node; |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Returns an array with all the child nodes |
|
232 | - * |
|
233 | - * @return \Sabre\DAV\INode[] |
|
234 | - * @throws \Sabre\DAV\Exception\Locked |
|
235 | - * @throws \OCA\DAV\Connector\Sabre\Exception\Forbidden |
|
236 | - */ |
|
237 | - public function getChildren() { |
|
238 | - if (!is_null($this->dirContent)) { |
|
239 | - return $this->dirContent; |
|
240 | - } |
|
241 | - try { |
|
242 | - if (!$this->info->isReadable()) { |
|
243 | - // return 403 instead of 404 because a 404 would make |
|
244 | - // the caller believe that the collection itself does not exist |
|
245 | - if (\OCP\Server::get(\OCP\App\IAppManager::class)->isInstalled('files_accesscontrol')) { |
|
246 | - throw new Forbidden('No read permissions. This might be caused by files_accesscontrol, check your configured rules'); |
|
247 | - } else { |
|
248 | - throw new Forbidden('No read permissions'); |
|
249 | - } |
|
250 | - } |
|
251 | - $folderContent = $this->getNode()->getDirectoryListing(); |
|
252 | - } catch (LockedException $e) { |
|
253 | - throw new Locked(); |
|
254 | - } |
|
255 | - |
|
256 | - $nodes = []; |
|
257 | - foreach ($folderContent as $info) { |
|
258 | - $node = $this->getChild($info->getName(), $info); |
|
259 | - $nodes[] = $node; |
|
260 | - } |
|
261 | - $this->dirContent = $nodes; |
|
262 | - return $this->dirContent; |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * Checks if a child exists. |
|
267 | - * |
|
268 | - * @param string $name |
|
269 | - * @return bool |
|
270 | - */ |
|
271 | - public function childExists($name) { |
|
272 | - // note: here we do NOT resolve the chunk file name to the real file name |
|
273 | - // to make sure we return false when checking for file existence with a chunk |
|
274 | - // file name. |
|
275 | - // This is to make sure that "createFile" is still triggered |
|
276 | - // (required old code) instead of "updateFile". |
|
277 | - // |
|
278 | - // TODO: resolve chunk file name here and implement "updateFile" |
|
279 | - $path = $this->path . '/' . $name; |
|
280 | - return $this->fileView->file_exists($path); |
|
281 | - } |
|
282 | - |
|
283 | - /** |
|
284 | - * Deletes all files in this directory, and then itself |
|
285 | - * |
|
286 | - * @return void |
|
287 | - * @throws FileLocked |
|
288 | - * @throws Exception\Forbidden |
|
289 | - */ |
|
290 | - public function delete() { |
|
291 | - if ($this->path === '' || $this->path === '/' || !$this->info->isDeletable()) { |
|
292 | - throw new Exception\Forbidden(); |
|
293 | - } |
|
294 | - |
|
295 | - try { |
|
296 | - if (!$this->fileView->rmdir($this->path)) { |
|
297 | - // assume it wasn't possible to remove due to permission issue |
|
298 | - throw new Exception\Forbidden(); |
|
299 | - } |
|
300 | - } catch (ForbiddenException $ex) { |
|
301 | - throw new Forbidden($ex->getMessage(), $ex->getRetry()); |
|
302 | - } catch (LockedException $e) { |
|
303 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
304 | - } |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Returns available diskspace information |
|
309 | - * |
|
310 | - * @return array |
|
311 | - */ |
|
312 | - public function getQuotaInfo() { |
|
313 | - /** @var LoggerInterface $logger */ |
|
314 | - $logger = \OC::$server->get(LoggerInterface::class); |
|
315 | - if ($this->quotaInfo) { |
|
316 | - return $this->quotaInfo; |
|
317 | - } |
|
318 | - try { |
|
319 | - $storageInfo = \OC_Helper::getStorageInfo($this->info->getPath(), $this->info, false); |
|
320 | - if ($storageInfo['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
321 | - $free = \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
322 | - } else { |
|
323 | - $free = $storageInfo['free']; |
|
324 | - } |
|
325 | - $this->quotaInfo = [ |
|
326 | - $storageInfo['used'], |
|
327 | - $free |
|
328 | - ]; |
|
329 | - return $this->quotaInfo; |
|
330 | - } catch (\OCP\Files\NotFoundException $e) { |
|
331 | - $logger->warning("error while getting quota into", ['exception' => $e]); |
|
332 | - return [0, 0]; |
|
333 | - } catch (StorageNotAvailableException $e) { |
|
334 | - $logger->warning("error while getting quota into", ['exception' => $e]); |
|
335 | - return [0, 0]; |
|
336 | - } catch (NotPermittedException $e) { |
|
337 | - $logger->warning("error while getting quota into", ['exception' => $e]); |
|
338 | - return [0, 0]; |
|
339 | - } |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * Moves a node into this collection. |
|
344 | - * |
|
345 | - * It is up to the implementors to: |
|
346 | - * 1. Create the new resource. |
|
347 | - * 2. Remove the old resource. |
|
348 | - * 3. Transfer any properties or other data. |
|
349 | - * |
|
350 | - * Generally you should make very sure that your collection can easily move |
|
351 | - * the move. |
|
352 | - * |
|
353 | - * If you don't, just return false, which will trigger sabre/dav to handle |
|
354 | - * the move itself. If you return true from this function, the assumption |
|
355 | - * is that the move was successful. |
|
356 | - * |
|
357 | - * @param string $targetName New local file/collection name. |
|
358 | - * @param string $fullSourcePath Full path to source node |
|
359 | - * @param INode $sourceNode Source node itself |
|
360 | - * @return bool |
|
361 | - * @throws BadRequest |
|
362 | - * @throws ServiceUnavailable |
|
363 | - * @throws Forbidden |
|
364 | - * @throws FileLocked |
|
365 | - * @throws Exception\Forbidden |
|
366 | - */ |
|
367 | - public function moveInto($targetName, $fullSourcePath, INode $sourceNode) { |
|
368 | - if (!$sourceNode instanceof Node) { |
|
369 | - // it's a file of another kind, like FutureFile |
|
370 | - if ($sourceNode instanceof IFile) { |
|
371 | - // fallback to default copy+delete handling |
|
372 | - return false; |
|
373 | - } |
|
374 | - throw new BadRequest('Incompatible node types'); |
|
375 | - } |
|
376 | - |
|
377 | - if (!$this->fileView) { |
|
378 | - throw new ServiceUnavailable('filesystem not setup'); |
|
379 | - } |
|
380 | - |
|
381 | - $destinationPath = $this->getPath() . '/' . $targetName; |
|
382 | - |
|
383 | - |
|
384 | - $targetNodeExists = $this->childExists($targetName); |
|
385 | - |
|
386 | - // at getNodeForPath we also check the path for isForbiddenFileOrDir |
|
387 | - // with that we have covered both source and destination |
|
388 | - if ($sourceNode instanceof Directory && $targetNodeExists) { |
|
389 | - throw new Exception\Forbidden('Could not copy directory ' . $sourceNode->getName() . ', target exists'); |
|
390 | - } |
|
391 | - |
|
392 | - [$sourceDir,] = \Sabre\Uri\split($sourceNode->getPath()); |
|
393 | - $destinationDir = $this->getPath(); |
|
394 | - |
|
395 | - $sourcePath = $sourceNode->getPath(); |
|
396 | - |
|
397 | - $isMovableMount = false; |
|
398 | - $sourceMount = \OC::$server->getMountManager()->find($this->fileView->getAbsolutePath($sourcePath)); |
|
399 | - $internalPath = $sourceMount->getInternalPath($this->fileView->getAbsolutePath($sourcePath)); |
|
400 | - if ($sourceMount instanceof MoveableMount && $internalPath === '') { |
|
401 | - $isMovableMount = true; |
|
402 | - } |
|
403 | - |
|
404 | - try { |
|
405 | - $sameFolder = ($sourceDir === $destinationDir); |
|
406 | - // if we're overwriting or same folder |
|
407 | - if ($targetNodeExists || $sameFolder) { |
|
408 | - // note that renaming a share mount point is always allowed |
|
409 | - if (!$this->fileView->isUpdatable($destinationDir) && !$isMovableMount) { |
|
410 | - throw new Exception\Forbidden(); |
|
411 | - } |
|
412 | - } else { |
|
413 | - if (!$this->fileView->isCreatable($destinationDir)) { |
|
414 | - throw new Exception\Forbidden(); |
|
415 | - } |
|
416 | - } |
|
417 | - |
|
418 | - if (!$sameFolder) { |
|
419 | - // moving to a different folder, source will be gone, like a deletion |
|
420 | - // note that moving a share mount point is always allowed |
|
421 | - if (!$this->fileView->isDeletable($sourcePath) && !$isMovableMount) { |
|
422 | - throw new Exception\Forbidden(); |
|
423 | - } |
|
424 | - } |
|
425 | - |
|
426 | - $fileName = basename($destinationPath); |
|
427 | - try { |
|
428 | - $this->fileView->verifyPath($destinationDir, $fileName); |
|
429 | - } catch (InvalidPathException $ex) { |
|
430 | - throw new InvalidPath($ex->getMessage()); |
|
431 | - } |
|
432 | - |
|
433 | - $renameOkay = $this->fileView->rename($sourcePath, $destinationPath); |
|
434 | - if (!$renameOkay) { |
|
435 | - throw new Exception\Forbidden(''); |
|
436 | - } |
|
437 | - } catch (StorageNotAvailableException $e) { |
|
438 | - throw new ServiceUnavailable($e->getMessage()); |
|
439 | - } catch (ForbiddenException $ex) { |
|
440 | - throw new Forbidden($ex->getMessage(), $ex->getRetry()); |
|
441 | - } catch (LockedException $e) { |
|
442 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
443 | - } |
|
444 | - |
|
445 | - return true; |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - public function copyInto($targetName, $sourcePath, INode $sourceNode) { |
|
450 | - if ($sourceNode instanceof File || $sourceNode instanceof Directory) { |
|
451 | - $destinationPath = $this->getPath() . '/' . $targetName; |
|
452 | - $sourcePath = $sourceNode->getPath(); |
|
453 | - |
|
454 | - if (!$this->fileView->isCreatable($this->getPath())) { |
|
455 | - throw new Exception\Forbidden(); |
|
456 | - } |
|
457 | - |
|
458 | - try { |
|
459 | - $this->fileView->verifyPath($this->getPath(), $targetName); |
|
460 | - } catch (InvalidPathException $ex) { |
|
461 | - throw new InvalidPath($ex->getMessage()); |
|
462 | - } |
|
463 | - |
|
464 | - return $this->fileView->copy($sourcePath, $destinationPath); |
|
465 | - } |
|
466 | - |
|
467 | - return false; |
|
468 | - } |
|
469 | - |
|
470 | - public function getNode(): Folder { |
|
471 | - return $this->node; |
|
472 | - } |
|
62 | + /** |
|
63 | + * Cached directory content |
|
64 | + * @var \OCP\Files\FileInfo[] |
|
65 | + */ |
|
66 | + private ?array $dirContent = null; |
|
67 | + |
|
68 | + /** Cached quota info */ |
|
69 | + private ?array $quotaInfo = null; |
|
70 | + private ?CachingTree $tree = null; |
|
71 | + |
|
72 | + /** @var array<string, array<int, FileMetadata>> */ |
|
73 | + private array $metadata = []; |
|
74 | + |
|
75 | + /** |
|
76 | + * Sets up the node, expects a full path name |
|
77 | + */ |
|
78 | + public function __construct(View $view, FileInfo $info, ?CachingTree $tree = null, IShareManager $shareManager = null) { |
|
79 | + parent::__construct($view, $info, $shareManager); |
|
80 | + $this->tree = $tree; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Creates a new file in the directory |
|
85 | + * |
|
86 | + * Data will either be supplied as a stream resource, or in certain cases |
|
87 | + * as a string. Keep in mind that you may have to support either. |
|
88 | + * |
|
89 | + * After successful creation of the file, you may choose to return the ETag |
|
90 | + * of the new file here. |
|
91 | + * |
|
92 | + * The returned ETag must be surrounded by double-quotes (The quotes should |
|
93 | + * be part of the actual string). |
|
94 | + * |
|
95 | + * If you cannot accurately determine the ETag, you should not return it. |
|
96 | + * If you don't store the file exactly as-is (you're transforming it |
|
97 | + * somehow) you should also not return an ETag. |
|
98 | + * |
|
99 | + * This means that if a subsequent GET to this new file does not exactly |
|
100 | + * return the same contents of what was submitted here, you are strongly |
|
101 | + * recommended to omit the ETag. |
|
102 | + * |
|
103 | + * @param string $name Name of the file |
|
104 | + * @param resource|string $data Initial payload |
|
105 | + * @return null|string |
|
106 | + * @throws Exception\UnsupportedMediaType |
|
107 | + * @throws FileLocked |
|
108 | + * @throws InvalidPath |
|
109 | + * @throws Exception |
|
110 | + * @throws BadRequest |
|
111 | + * @throws Exception\Forbidden |
|
112 | + * @throws ServiceUnavailable |
|
113 | + */ |
|
114 | + public function createFile($name, $data = null) { |
|
115 | + try { |
|
116 | + // For non-chunked upload it is enough to check if we can create a new file |
|
117 | + if (!$this->fileView->isCreatable($this->path)) { |
|
118 | + throw new Exception\Forbidden(); |
|
119 | + } |
|
120 | + |
|
121 | + $this->fileView->verifyPath($this->path, $name); |
|
122 | + |
|
123 | + $path = $this->fileView->getAbsolutePath($this->path) . '/' . $name; |
|
124 | + // in case the file already exists/overwriting |
|
125 | + $info = $this->fileView->getFileInfo($this->path . '/' . $name); |
|
126 | + if (!$info) { |
|
127 | + // use a dummy FileInfo which is acceptable here since it will be refreshed after the put is complete |
|
128 | + $info = new \OC\Files\FileInfo($path, null, null, [ |
|
129 | + 'type' => FileInfo::TYPE_FILE |
|
130 | + ], null); |
|
131 | + } |
|
132 | + $node = new \OCA\DAV\Connector\Sabre\File($this->fileView, $info); |
|
133 | + |
|
134 | + // only allow 1 process to upload a file at once but still allow reading the file while writing the part file |
|
135 | + $node->acquireLock(ILockingProvider::LOCK_SHARED); |
|
136 | + $this->fileView->lockFile($path . '.upload.part', ILockingProvider::LOCK_EXCLUSIVE); |
|
137 | + |
|
138 | + $result = $node->put($data); |
|
139 | + |
|
140 | + $this->fileView->unlockFile($path . '.upload.part', ILockingProvider::LOCK_EXCLUSIVE); |
|
141 | + $node->releaseLock(ILockingProvider::LOCK_SHARED); |
|
142 | + return $result; |
|
143 | + } catch (StorageNotAvailableException $e) { |
|
144 | + throw new ServiceUnavailable($e->getMessage()); |
|
145 | + } catch (InvalidPathException $ex) { |
|
146 | + throw new InvalidPath($ex->getMessage(), false, $ex); |
|
147 | + } catch (ForbiddenException $ex) { |
|
148 | + throw new Forbidden($ex->getMessage(), $ex->getRetry(), $ex); |
|
149 | + } catch (LockedException $e) { |
|
150 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
151 | + } |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Creates a new subdirectory |
|
156 | + * |
|
157 | + * @param string $name |
|
158 | + * @throws FileLocked |
|
159 | + * @throws InvalidPath |
|
160 | + * @throws Exception\Forbidden |
|
161 | + * @throws ServiceUnavailable |
|
162 | + */ |
|
163 | + public function createDirectory($name) { |
|
164 | + try { |
|
165 | + if (!$this->info->isCreatable()) { |
|
166 | + throw new Exception\Forbidden(); |
|
167 | + } |
|
168 | + |
|
169 | + $this->fileView->verifyPath($this->path, $name); |
|
170 | + $newPath = $this->path . '/' . $name; |
|
171 | + if (!$this->fileView->mkdir($newPath)) { |
|
172 | + throw new Exception\Forbidden('Could not create directory ' . $newPath); |
|
173 | + } |
|
174 | + } catch (StorageNotAvailableException $e) { |
|
175 | + throw new ServiceUnavailable($e->getMessage()); |
|
176 | + } catch (InvalidPathException $ex) { |
|
177 | + throw new InvalidPath($ex->getMessage()); |
|
178 | + } catch (ForbiddenException $ex) { |
|
179 | + throw new Forbidden($ex->getMessage(), $ex->getRetry()); |
|
180 | + } catch (LockedException $e) { |
|
181 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
182 | + } |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Returns a specific child node, referenced by its name |
|
187 | + * |
|
188 | + * @param string $name |
|
189 | + * @param \OCP\Files\FileInfo $info |
|
190 | + * @return \Sabre\DAV\INode |
|
191 | + * @throws InvalidPath |
|
192 | + * @throws \Sabre\DAV\Exception\NotFound |
|
193 | + * @throws ServiceUnavailable |
|
194 | + */ |
|
195 | + public function getChild($name, $info = null) { |
|
196 | + if (!$this->info->isReadable()) { |
|
197 | + // avoid detecting files through this way |
|
198 | + throw new NotFound(); |
|
199 | + } |
|
200 | + |
|
201 | + $path = $this->path . '/' . $name; |
|
202 | + if (is_null($info)) { |
|
203 | + try { |
|
204 | + $this->fileView->verifyPath($this->path, $name); |
|
205 | + $info = $this->fileView->getFileInfo($path); |
|
206 | + } catch (StorageNotAvailableException $e) { |
|
207 | + throw new ServiceUnavailable($e->getMessage()); |
|
208 | + } catch (InvalidPathException $ex) { |
|
209 | + throw new InvalidPath($ex->getMessage()); |
|
210 | + } catch (ForbiddenException $e) { |
|
211 | + throw new Exception\Forbidden(); |
|
212 | + } |
|
213 | + } |
|
214 | + |
|
215 | + if (!$info) { |
|
216 | + throw new \Sabre\DAV\Exception\NotFound('File with name ' . $path . ' could not be located'); |
|
217 | + } |
|
218 | + |
|
219 | + if ($info->getMimeType() === FileInfo::MIMETYPE_FOLDER) { |
|
220 | + $node = new \OCA\DAV\Connector\Sabre\Directory($this->fileView, $info, $this->tree, $this->shareManager); |
|
221 | + } else { |
|
222 | + $node = new \OCA\DAV\Connector\Sabre\File($this->fileView, $info, $this->shareManager); |
|
223 | + } |
|
224 | + if ($this->tree) { |
|
225 | + $this->tree->cacheNode($node); |
|
226 | + } |
|
227 | + return $node; |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Returns an array with all the child nodes |
|
232 | + * |
|
233 | + * @return \Sabre\DAV\INode[] |
|
234 | + * @throws \Sabre\DAV\Exception\Locked |
|
235 | + * @throws \OCA\DAV\Connector\Sabre\Exception\Forbidden |
|
236 | + */ |
|
237 | + public function getChildren() { |
|
238 | + if (!is_null($this->dirContent)) { |
|
239 | + return $this->dirContent; |
|
240 | + } |
|
241 | + try { |
|
242 | + if (!$this->info->isReadable()) { |
|
243 | + // return 403 instead of 404 because a 404 would make |
|
244 | + // the caller believe that the collection itself does not exist |
|
245 | + if (\OCP\Server::get(\OCP\App\IAppManager::class)->isInstalled('files_accesscontrol')) { |
|
246 | + throw new Forbidden('No read permissions. This might be caused by files_accesscontrol, check your configured rules'); |
|
247 | + } else { |
|
248 | + throw new Forbidden('No read permissions'); |
|
249 | + } |
|
250 | + } |
|
251 | + $folderContent = $this->getNode()->getDirectoryListing(); |
|
252 | + } catch (LockedException $e) { |
|
253 | + throw new Locked(); |
|
254 | + } |
|
255 | + |
|
256 | + $nodes = []; |
|
257 | + foreach ($folderContent as $info) { |
|
258 | + $node = $this->getChild($info->getName(), $info); |
|
259 | + $nodes[] = $node; |
|
260 | + } |
|
261 | + $this->dirContent = $nodes; |
|
262 | + return $this->dirContent; |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * Checks if a child exists. |
|
267 | + * |
|
268 | + * @param string $name |
|
269 | + * @return bool |
|
270 | + */ |
|
271 | + public function childExists($name) { |
|
272 | + // note: here we do NOT resolve the chunk file name to the real file name |
|
273 | + // to make sure we return false when checking for file existence with a chunk |
|
274 | + // file name. |
|
275 | + // This is to make sure that "createFile" is still triggered |
|
276 | + // (required old code) instead of "updateFile". |
|
277 | + // |
|
278 | + // TODO: resolve chunk file name here and implement "updateFile" |
|
279 | + $path = $this->path . '/' . $name; |
|
280 | + return $this->fileView->file_exists($path); |
|
281 | + } |
|
282 | + |
|
283 | + /** |
|
284 | + * Deletes all files in this directory, and then itself |
|
285 | + * |
|
286 | + * @return void |
|
287 | + * @throws FileLocked |
|
288 | + * @throws Exception\Forbidden |
|
289 | + */ |
|
290 | + public function delete() { |
|
291 | + if ($this->path === '' || $this->path === '/' || !$this->info->isDeletable()) { |
|
292 | + throw new Exception\Forbidden(); |
|
293 | + } |
|
294 | + |
|
295 | + try { |
|
296 | + if (!$this->fileView->rmdir($this->path)) { |
|
297 | + // assume it wasn't possible to remove due to permission issue |
|
298 | + throw new Exception\Forbidden(); |
|
299 | + } |
|
300 | + } catch (ForbiddenException $ex) { |
|
301 | + throw new Forbidden($ex->getMessage(), $ex->getRetry()); |
|
302 | + } catch (LockedException $e) { |
|
303 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
304 | + } |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Returns available diskspace information |
|
309 | + * |
|
310 | + * @return array |
|
311 | + */ |
|
312 | + public function getQuotaInfo() { |
|
313 | + /** @var LoggerInterface $logger */ |
|
314 | + $logger = \OC::$server->get(LoggerInterface::class); |
|
315 | + if ($this->quotaInfo) { |
|
316 | + return $this->quotaInfo; |
|
317 | + } |
|
318 | + try { |
|
319 | + $storageInfo = \OC_Helper::getStorageInfo($this->info->getPath(), $this->info, false); |
|
320 | + if ($storageInfo['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
321 | + $free = \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
322 | + } else { |
|
323 | + $free = $storageInfo['free']; |
|
324 | + } |
|
325 | + $this->quotaInfo = [ |
|
326 | + $storageInfo['used'], |
|
327 | + $free |
|
328 | + ]; |
|
329 | + return $this->quotaInfo; |
|
330 | + } catch (\OCP\Files\NotFoundException $e) { |
|
331 | + $logger->warning("error while getting quota into", ['exception' => $e]); |
|
332 | + return [0, 0]; |
|
333 | + } catch (StorageNotAvailableException $e) { |
|
334 | + $logger->warning("error while getting quota into", ['exception' => $e]); |
|
335 | + return [0, 0]; |
|
336 | + } catch (NotPermittedException $e) { |
|
337 | + $logger->warning("error while getting quota into", ['exception' => $e]); |
|
338 | + return [0, 0]; |
|
339 | + } |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * Moves a node into this collection. |
|
344 | + * |
|
345 | + * It is up to the implementors to: |
|
346 | + * 1. Create the new resource. |
|
347 | + * 2. Remove the old resource. |
|
348 | + * 3. Transfer any properties or other data. |
|
349 | + * |
|
350 | + * Generally you should make very sure that your collection can easily move |
|
351 | + * the move. |
|
352 | + * |
|
353 | + * If you don't, just return false, which will trigger sabre/dav to handle |
|
354 | + * the move itself. If you return true from this function, the assumption |
|
355 | + * is that the move was successful. |
|
356 | + * |
|
357 | + * @param string $targetName New local file/collection name. |
|
358 | + * @param string $fullSourcePath Full path to source node |
|
359 | + * @param INode $sourceNode Source node itself |
|
360 | + * @return bool |
|
361 | + * @throws BadRequest |
|
362 | + * @throws ServiceUnavailable |
|
363 | + * @throws Forbidden |
|
364 | + * @throws FileLocked |
|
365 | + * @throws Exception\Forbidden |
|
366 | + */ |
|
367 | + public function moveInto($targetName, $fullSourcePath, INode $sourceNode) { |
|
368 | + if (!$sourceNode instanceof Node) { |
|
369 | + // it's a file of another kind, like FutureFile |
|
370 | + if ($sourceNode instanceof IFile) { |
|
371 | + // fallback to default copy+delete handling |
|
372 | + return false; |
|
373 | + } |
|
374 | + throw new BadRequest('Incompatible node types'); |
|
375 | + } |
|
376 | + |
|
377 | + if (!$this->fileView) { |
|
378 | + throw new ServiceUnavailable('filesystem not setup'); |
|
379 | + } |
|
380 | + |
|
381 | + $destinationPath = $this->getPath() . '/' . $targetName; |
|
382 | + |
|
383 | + |
|
384 | + $targetNodeExists = $this->childExists($targetName); |
|
385 | + |
|
386 | + // at getNodeForPath we also check the path for isForbiddenFileOrDir |
|
387 | + // with that we have covered both source and destination |
|
388 | + if ($sourceNode instanceof Directory && $targetNodeExists) { |
|
389 | + throw new Exception\Forbidden('Could not copy directory ' . $sourceNode->getName() . ', target exists'); |
|
390 | + } |
|
391 | + |
|
392 | + [$sourceDir,] = \Sabre\Uri\split($sourceNode->getPath()); |
|
393 | + $destinationDir = $this->getPath(); |
|
394 | + |
|
395 | + $sourcePath = $sourceNode->getPath(); |
|
396 | + |
|
397 | + $isMovableMount = false; |
|
398 | + $sourceMount = \OC::$server->getMountManager()->find($this->fileView->getAbsolutePath($sourcePath)); |
|
399 | + $internalPath = $sourceMount->getInternalPath($this->fileView->getAbsolutePath($sourcePath)); |
|
400 | + if ($sourceMount instanceof MoveableMount && $internalPath === '') { |
|
401 | + $isMovableMount = true; |
|
402 | + } |
|
403 | + |
|
404 | + try { |
|
405 | + $sameFolder = ($sourceDir === $destinationDir); |
|
406 | + // if we're overwriting or same folder |
|
407 | + if ($targetNodeExists || $sameFolder) { |
|
408 | + // note that renaming a share mount point is always allowed |
|
409 | + if (!$this->fileView->isUpdatable($destinationDir) && !$isMovableMount) { |
|
410 | + throw new Exception\Forbidden(); |
|
411 | + } |
|
412 | + } else { |
|
413 | + if (!$this->fileView->isCreatable($destinationDir)) { |
|
414 | + throw new Exception\Forbidden(); |
|
415 | + } |
|
416 | + } |
|
417 | + |
|
418 | + if (!$sameFolder) { |
|
419 | + // moving to a different folder, source will be gone, like a deletion |
|
420 | + // note that moving a share mount point is always allowed |
|
421 | + if (!$this->fileView->isDeletable($sourcePath) && !$isMovableMount) { |
|
422 | + throw new Exception\Forbidden(); |
|
423 | + } |
|
424 | + } |
|
425 | + |
|
426 | + $fileName = basename($destinationPath); |
|
427 | + try { |
|
428 | + $this->fileView->verifyPath($destinationDir, $fileName); |
|
429 | + } catch (InvalidPathException $ex) { |
|
430 | + throw new InvalidPath($ex->getMessage()); |
|
431 | + } |
|
432 | + |
|
433 | + $renameOkay = $this->fileView->rename($sourcePath, $destinationPath); |
|
434 | + if (!$renameOkay) { |
|
435 | + throw new Exception\Forbidden(''); |
|
436 | + } |
|
437 | + } catch (StorageNotAvailableException $e) { |
|
438 | + throw new ServiceUnavailable($e->getMessage()); |
|
439 | + } catch (ForbiddenException $ex) { |
|
440 | + throw new Forbidden($ex->getMessage(), $ex->getRetry()); |
|
441 | + } catch (LockedException $e) { |
|
442 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
443 | + } |
|
444 | + |
|
445 | + return true; |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + public function copyInto($targetName, $sourcePath, INode $sourceNode) { |
|
450 | + if ($sourceNode instanceof File || $sourceNode instanceof Directory) { |
|
451 | + $destinationPath = $this->getPath() . '/' . $targetName; |
|
452 | + $sourcePath = $sourceNode->getPath(); |
|
453 | + |
|
454 | + if (!$this->fileView->isCreatable($this->getPath())) { |
|
455 | + throw new Exception\Forbidden(); |
|
456 | + } |
|
457 | + |
|
458 | + try { |
|
459 | + $this->fileView->verifyPath($this->getPath(), $targetName); |
|
460 | + } catch (InvalidPathException $ex) { |
|
461 | + throw new InvalidPath($ex->getMessage()); |
|
462 | + } |
|
463 | + |
|
464 | + return $this->fileView->copy($sourcePath, $destinationPath); |
|
465 | + } |
|
466 | + |
|
467 | + return false; |
|
468 | + } |
|
469 | + |
|
470 | + public function getNode(): Folder { |
|
471 | + return $this->node; |
|
472 | + } |
|
473 | 473 | } |
@@ -120,9 +120,9 @@ discard block |
||
120 | 120 | |
121 | 121 | $this->fileView->verifyPath($this->path, $name); |
122 | 122 | |
123 | - $path = $this->fileView->getAbsolutePath($this->path) . '/' . $name; |
|
123 | + $path = $this->fileView->getAbsolutePath($this->path).'/'.$name; |
|
124 | 124 | // in case the file already exists/overwriting |
125 | - $info = $this->fileView->getFileInfo($this->path . '/' . $name); |
|
125 | + $info = $this->fileView->getFileInfo($this->path.'/'.$name); |
|
126 | 126 | if (!$info) { |
127 | 127 | // use a dummy FileInfo which is acceptable here since it will be refreshed after the put is complete |
128 | 128 | $info = new \OC\Files\FileInfo($path, null, null, [ |
@@ -133,11 +133,11 @@ discard block |
||
133 | 133 | |
134 | 134 | // only allow 1 process to upload a file at once but still allow reading the file while writing the part file |
135 | 135 | $node->acquireLock(ILockingProvider::LOCK_SHARED); |
136 | - $this->fileView->lockFile($path . '.upload.part', ILockingProvider::LOCK_EXCLUSIVE); |
|
136 | + $this->fileView->lockFile($path.'.upload.part', ILockingProvider::LOCK_EXCLUSIVE); |
|
137 | 137 | |
138 | 138 | $result = $node->put($data); |
139 | 139 | |
140 | - $this->fileView->unlockFile($path . '.upload.part', ILockingProvider::LOCK_EXCLUSIVE); |
|
140 | + $this->fileView->unlockFile($path.'.upload.part', ILockingProvider::LOCK_EXCLUSIVE); |
|
141 | 141 | $node->releaseLock(ILockingProvider::LOCK_SHARED); |
142 | 142 | return $result; |
143 | 143 | } catch (StorageNotAvailableException $e) { |
@@ -167,9 +167,9 @@ discard block |
||
167 | 167 | } |
168 | 168 | |
169 | 169 | $this->fileView->verifyPath($this->path, $name); |
170 | - $newPath = $this->path . '/' . $name; |
|
170 | + $newPath = $this->path.'/'.$name; |
|
171 | 171 | if (!$this->fileView->mkdir($newPath)) { |
172 | - throw new Exception\Forbidden('Could not create directory ' . $newPath); |
|
172 | + throw new Exception\Forbidden('Could not create directory '.$newPath); |
|
173 | 173 | } |
174 | 174 | } catch (StorageNotAvailableException $e) { |
175 | 175 | throw new ServiceUnavailable($e->getMessage()); |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | throw new NotFound(); |
199 | 199 | } |
200 | 200 | |
201 | - $path = $this->path . '/' . $name; |
|
201 | + $path = $this->path.'/'.$name; |
|
202 | 202 | if (is_null($info)) { |
203 | 203 | try { |
204 | 204 | $this->fileView->verifyPath($this->path, $name); |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | } |
214 | 214 | |
215 | 215 | if (!$info) { |
216 | - throw new \Sabre\DAV\Exception\NotFound('File with name ' . $path . ' could not be located'); |
|
216 | + throw new \Sabre\DAV\Exception\NotFound('File with name '.$path.' could not be located'); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | if ($info->getMimeType() === FileInfo::MIMETYPE_FOLDER) { |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | // (required old code) instead of "updateFile". |
277 | 277 | // |
278 | 278 | // TODO: resolve chunk file name here and implement "updateFile" |
279 | - $path = $this->path . '/' . $name; |
|
279 | + $path = $this->path.'/'.$name; |
|
280 | 280 | return $this->fileView->file_exists($path); |
281 | 281 | } |
282 | 282 | |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | throw new ServiceUnavailable('filesystem not setup'); |
379 | 379 | } |
380 | 380 | |
381 | - $destinationPath = $this->getPath() . '/' . $targetName; |
|
381 | + $destinationPath = $this->getPath().'/'.$targetName; |
|
382 | 382 | |
383 | 383 | |
384 | 384 | $targetNodeExists = $this->childExists($targetName); |
@@ -386,10 +386,10 @@ discard block |
||
386 | 386 | // at getNodeForPath we also check the path for isForbiddenFileOrDir |
387 | 387 | // with that we have covered both source and destination |
388 | 388 | if ($sourceNode instanceof Directory && $targetNodeExists) { |
389 | - throw new Exception\Forbidden('Could not copy directory ' . $sourceNode->getName() . ', target exists'); |
|
389 | + throw new Exception\Forbidden('Could not copy directory '.$sourceNode->getName().', target exists'); |
|
390 | 390 | } |
391 | 391 | |
392 | - [$sourceDir,] = \Sabre\Uri\split($sourceNode->getPath()); |
|
392 | + [$sourceDir, ] = \Sabre\Uri\split($sourceNode->getPath()); |
|
393 | 393 | $destinationDir = $this->getPath(); |
394 | 394 | |
395 | 395 | $sourcePath = $sourceNode->getPath(); |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | |
449 | 449 | public function copyInto($targetName, $sourcePath, INode $sourceNode) { |
450 | 450 | if ($sourceNode instanceof File || $sourceNode instanceof Directory) { |
451 | - $destinationPath = $this->getPath() . '/' . $targetName; |
|
451 | + $destinationPath = $this->getPath().'/'.$targetName; |
|
452 | 452 | $sourcePath = $sourceNode->getPath(); |
453 | 453 | |
454 | 454 | if (!$this->fileView->isCreatable($this->getPath())) { |
@@ -44,190 +44,190 @@ |
||
44 | 44 | * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License |
45 | 45 | */ |
46 | 46 | class QuotaPlugin extends \Sabre\DAV\ServerPlugin { |
47 | - /** @var \OC\Files\View */ |
|
48 | - private $view; |
|
49 | - |
|
50 | - /** |
|
51 | - * Reference to main server object |
|
52 | - * |
|
53 | - * @var \Sabre\DAV\Server |
|
54 | - */ |
|
55 | - private $server; |
|
56 | - |
|
57 | - /** |
|
58 | - * @param \OC\Files\View $view |
|
59 | - */ |
|
60 | - public function __construct($view) { |
|
61 | - $this->view = $view; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * This initializes the plugin. |
|
66 | - * |
|
67 | - * This function is called by \Sabre\DAV\Server, after |
|
68 | - * addPlugin is called. |
|
69 | - * |
|
70 | - * This method should set up the requires event subscriptions. |
|
71 | - * |
|
72 | - * @param \Sabre\DAV\Server $server |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - public function initialize(\Sabre\DAV\Server $server) { |
|
76 | - $this->server = $server; |
|
77 | - |
|
78 | - $server->on('beforeWriteContent', [$this, 'beforeWriteContent'], 10); |
|
79 | - $server->on('beforeCreateFile', [$this, 'beforeCreateFile'], 10); |
|
80 | - $server->on('beforeMove', [$this, 'beforeMove'], 10); |
|
81 | - $server->on('beforeCopy', [$this, 'beforeCopy'], 10); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Check quota before creating file |
|
86 | - * |
|
87 | - * @param string $uri target file URI |
|
88 | - * @param resource $data data |
|
89 | - * @param INode $parent Sabre Node |
|
90 | - * @param bool $modified modified |
|
91 | - */ |
|
92 | - public function beforeCreateFile($uri, $data, INode $parent, $modified) { |
|
93 | - if (!$parent instanceof Node) { |
|
94 | - return; |
|
95 | - } |
|
96 | - |
|
97 | - return $this->checkQuota($parent->getPath() . '/' . basename($uri)); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Check quota before writing content |
|
102 | - * |
|
103 | - * @param string $uri target file URI |
|
104 | - * @param INode $node Sabre Node |
|
105 | - * @param resource $data data |
|
106 | - * @param bool $modified modified |
|
107 | - */ |
|
108 | - public function beforeWriteContent($uri, INode $node, $data, $modified) { |
|
109 | - if (!$node instanceof Node) { |
|
110 | - return; |
|
111 | - } |
|
112 | - |
|
113 | - return $this->checkQuota($node->getPath()); |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Check if we're moving a Futurefile in which case we need to check |
|
118 | - * the quota on the target destination. |
|
119 | - * |
|
120 | - * @param string $source source path |
|
121 | - * @param string $destination destination path |
|
122 | - */ |
|
123 | - public function beforeMove($source, $destination) { |
|
124 | - $sourceNode = $this->server->tree->getNodeForPath($source); |
|
125 | - if (!$sourceNode instanceof FutureFile) { |
|
126 | - return; |
|
127 | - } |
|
128 | - |
|
129 | - // get target node for proper path conversion |
|
130 | - if ($this->server->tree->nodeExists($destination)) { |
|
131 | - $destinationNode = $this->server->tree->getNodeForPath($destination); |
|
132 | - $path = $destinationNode->getPath(); |
|
133 | - } else { |
|
134 | - $parent = dirname($destination); |
|
135 | - if ($parent === '.') { |
|
136 | - $parent = ''; |
|
137 | - } |
|
138 | - $parentNode = $this->server->tree->getNodeForPath($parent); |
|
139 | - $path = $parentNode->getPath(); |
|
140 | - } |
|
141 | - |
|
142 | - return $this->checkQuota($path, $sourceNode->getSize()); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Check quota on the target destination before a copy. |
|
147 | - */ |
|
148 | - public function beforeCopy(string $sourcePath, string $destinationPath): bool { |
|
149 | - $sourceNode = $this->server->tree->getNodeForPath($sourcePath); |
|
150 | - if (!$sourceNode instanceof Node) { |
|
151 | - return true; |
|
152 | - } |
|
153 | - |
|
154 | - // get target node for proper path conversion |
|
155 | - if ($this->server->tree->nodeExists($destinationPath)) { |
|
156 | - $destinationNode = $this->server->tree->getNodeForPath($destinationPath); |
|
157 | - if (!$destinationNode instanceof Node) { |
|
158 | - return true; |
|
159 | - } |
|
160 | - $path = $destinationNode->getPath(); |
|
161 | - } else { |
|
162 | - $parent = dirname($destinationPath); |
|
163 | - if ($parent === '.') { |
|
164 | - $parent = ''; |
|
165 | - } |
|
166 | - $parentNode = $this->server->tree->getNodeForPath($parent); |
|
167 | - if (!$parentNode instanceof Node) { |
|
168 | - return true; |
|
169 | - } |
|
170 | - $path = $parentNode->getPath(); |
|
171 | - } |
|
172 | - |
|
173 | - return $this->checkQuota($path, $sourceNode->getSize()); |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * This method is called before any HTTP method and validates there is enough free space to store the file |
|
179 | - * |
|
180 | - * @param string $path relative to the users home |
|
181 | - * @param int|float|null $length |
|
182 | - * @throws InsufficientStorage |
|
183 | - * @return bool |
|
184 | - */ |
|
185 | - public function checkQuota($path, $length = null) { |
|
186 | - if ($length === null) { |
|
187 | - $length = $this->getLength(); |
|
188 | - } |
|
189 | - |
|
190 | - if ($length) { |
|
191 | - [$parentPath, $newName] = \Sabre\Uri\split($path); |
|
192 | - if (is_null($parentPath)) { |
|
193 | - $parentPath = ''; |
|
194 | - } |
|
195 | - $req = $this->server->httpRequest; |
|
196 | - $freeSpace = $this->getFreeSpace($path); |
|
197 | - if ($freeSpace >= 0 && $length > $freeSpace) { |
|
198 | - throw new InsufficientStorage("Insufficient space in $path, $length required, $freeSpace available"); |
|
199 | - } |
|
200 | - } |
|
201 | - return true; |
|
202 | - } |
|
203 | - |
|
204 | - public function getLength() { |
|
205 | - $req = $this->server->httpRequest; |
|
206 | - $length = $req->getHeader('X-Expected-Entity-Length'); |
|
207 | - if (!is_numeric($length)) { |
|
208 | - $length = $req->getHeader('Content-Length'); |
|
209 | - $length = is_numeric($length) ? $length : null; |
|
210 | - } |
|
211 | - |
|
212 | - $ocLength = $req->getHeader('OC-Total-Length'); |
|
213 | - if (is_numeric($length) && is_numeric($ocLength)) { |
|
214 | - return max($length, $ocLength); |
|
215 | - } |
|
216 | - |
|
217 | - return $length; |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * @param string $uri |
|
222 | - * @return mixed |
|
223 | - * @throws ServiceUnavailable |
|
224 | - */ |
|
225 | - public function getFreeSpace($uri) { |
|
226 | - try { |
|
227 | - $freeSpace = $this->view->free_space(ltrim($uri, '/')); |
|
228 | - return $freeSpace; |
|
229 | - } catch (StorageNotAvailableException $e) { |
|
230 | - throw new ServiceUnavailable($e->getMessage()); |
|
231 | - } |
|
232 | - } |
|
47 | + /** @var \OC\Files\View */ |
|
48 | + private $view; |
|
49 | + |
|
50 | + /** |
|
51 | + * Reference to main server object |
|
52 | + * |
|
53 | + * @var \Sabre\DAV\Server |
|
54 | + */ |
|
55 | + private $server; |
|
56 | + |
|
57 | + /** |
|
58 | + * @param \OC\Files\View $view |
|
59 | + */ |
|
60 | + public function __construct($view) { |
|
61 | + $this->view = $view; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * This initializes the plugin. |
|
66 | + * |
|
67 | + * This function is called by \Sabre\DAV\Server, after |
|
68 | + * addPlugin is called. |
|
69 | + * |
|
70 | + * This method should set up the requires event subscriptions. |
|
71 | + * |
|
72 | + * @param \Sabre\DAV\Server $server |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + public function initialize(\Sabre\DAV\Server $server) { |
|
76 | + $this->server = $server; |
|
77 | + |
|
78 | + $server->on('beforeWriteContent', [$this, 'beforeWriteContent'], 10); |
|
79 | + $server->on('beforeCreateFile', [$this, 'beforeCreateFile'], 10); |
|
80 | + $server->on('beforeMove', [$this, 'beforeMove'], 10); |
|
81 | + $server->on('beforeCopy', [$this, 'beforeCopy'], 10); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Check quota before creating file |
|
86 | + * |
|
87 | + * @param string $uri target file URI |
|
88 | + * @param resource $data data |
|
89 | + * @param INode $parent Sabre Node |
|
90 | + * @param bool $modified modified |
|
91 | + */ |
|
92 | + public function beforeCreateFile($uri, $data, INode $parent, $modified) { |
|
93 | + if (!$parent instanceof Node) { |
|
94 | + return; |
|
95 | + } |
|
96 | + |
|
97 | + return $this->checkQuota($parent->getPath() . '/' . basename($uri)); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Check quota before writing content |
|
102 | + * |
|
103 | + * @param string $uri target file URI |
|
104 | + * @param INode $node Sabre Node |
|
105 | + * @param resource $data data |
|
106 | + * @param bool $modified modified |
|
107 | + */ |
|
108 | + public function beforeWriteContent($uri, INode $node, $data, $modified) { |
|
109 | + if (!$node instanceof Node) { |
|
110 | + return; |
|
111 | + } |
|
112 | + |
|
113 | + return $this->checkQuota($node->getPath()); |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Check if we're moving a Futurefile in which case we need to check |
|
118 | + * the quota on the target destination. |
|
119 | + * |
|
120 | + * @param string $source source path |
|
121 | + * @param string $destination destination path |
|
122 | + */ |
|
123 | + public function beforeMove($source, $destination) { |
|
124 | + $sourceNode = $this->server->tree->getNodeForPath($source); |
|
125 | + if (!$sourceNode instanceof FutureFile) { |
|
126 | + return; |
|
127 | + } |
|
128 | + |
|
129 | + // get target node for proper path conversion |
|
130 | + if ($this->server->tree->nodeExists($destination)) { |
|
131 | + $destinationNode = $this->server->tree->getNodeForPath($destination); |
|
132 | + $path = $destinationNode->getPath(); |
|
133 | + } else { |
|
134 | + $parent = dirname($destination); |
|
135 | + if ($parent === '.') { |
|
136 | + $parent = ''; |
|
137 | + } |
|
138 | + $parentNode = $this->server->tree->getNodeForPath($parent); |
|
139 | + $path = $parentNode->getPath(); |
|
140 | + } |
|
141 | + |
|
142 | + return $this->checkQuota($path, $sourceNode->getSize()); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Check quota on the target destination before a copy. |
|
147 | + */ |
|
148 | + public function beforeCopy(string $sourcePath, string $destinationPath): bool { |
|
149 | + $sourceNode = $this->server->tree->getNodeForPath($sourcePath); |
|
150 | + if (!$sourceNode instanceof Node) { |
|
151 | + return true; |
|
152 | + } |
|
153 | + |
|
154 | + // get target node for proper path conversion |
|
155 | + if ($this->server->tree->nodeExists($destinationPath)) { |
|
156 | + $destinationNode = $this->server->tree->getNodeForPath($destinationPath); |
|
157 | + if (!$destinationNode instanceof Node) { |
|
158 | + return true; |
|
159 | + } |
|
160 | + $path = $destinationNode->getPath(); |
|
161 | + } else { |
|
162 | + $parent = dirname($destinationPath); |
|
163 | + if ($parent === '.') { |
|
164 | + $parent = ''; |
|
165 | + } |
|
166 | + $parentNode = $this->server->tree->getNodeForPath($parent); |
|
167 | + if (!$parentNode instanceof Node) { |
|
168 | + return true; |
|
169 | + } |
|
170 | + $path = $parentNode->getPath(); |
|
171 | + } |
|
172 | + |
|
173 | + return $this->checkQuota($path, $sourceNode->getSize()); |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * This method is called before any HTTP method and validates there is enough free space to store the file |
|
179 | + * |
|
180 | + * @param string $path relative to the users home |
|
181 | + * @param int|float|null $length |
|
182 | + * @throws InsufficientStorage |
|
183 | + * @return bool |
|
184 | + */ |
|
185 | + public function checkQuota($path, $length = null) { |
|
186 | + if ($length === null) { |
|
187 | + $length = $this->getLength(); |
|
188 | + } |
|
189 | + |
|
190 | + if ($length) { |
|
191 | + [$parentPath, $newName] = \Sabre\Uri\split($path); |
|
192 | + if (is_null($parentPath)) { |
|
193 | + $parentPath = ''; |
|
194 | + } |
|
195 | + $req = $this->server->httpRequest; |
|
196 | + $freeSpace = $this->getFreeSpace($path); |
|
197 | + if ($freeSpace >= 0 && $length > $freeSpace) { |
|
198 | + throw new InsufficientStorage("Insufficient space in $path, $length required, $freeSpace available"); |
|
199 | + } |
|
200 | + } |
|
201 | + return true; |
|
202 | + } |
|
203 | + |
|
204 | + public function getLength() { |
|
205 | + $req = $this->server->httpRequest; |
|
206 | + $length = $req->getHeader('X-Expected-Entity-Length'); |
|
207 | + if (!is_numeric($length)) { |
|
208 | + $length = $req->getHeader('Content-Length'); |
|
209 | + $length = is_numeric($length) ? $length : null; |
|
210 | + } |
|
211 | + |
|
212 | + $ocLength = $req->getHeader('OC-Total-Length'); |
|
213 | + if (is_numeric($length) && is_numeric($ocLength)) { |
|
214 | + return max($length, $ocLength); |
|
215 | + } |
|
216 | + |
|
217 | + return $length; |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * @param string $uri |
|
222 | + * @return mixed |
|
223 | + * @throws ServiceUnavailable |
|
224 | + */ |
|
225 | + public function getFreeSpace($uri) { |
|
226 | + try { |
|
227 | + $freeSpace = $this->view->free_space(ltrim($uri, '/')); |
|
228 | + return $freeSpace; |
|
229 | + } catch (StorageNotAvailableException $e) { |
|
230 | + throw new ServiceUnavailable($e->getMessage()); |
|
231 | + } |
|
232 | + } |
|
233 | 233 | } |
@@ -94,7 +94,7 @@ |
||
94 | 94 | return; |
95 | 95 | } |
96 | 96 | |
97 | - return $this->checkQuota($parent->getPath() . '/' . basename($uri)); |
|
97 | + return $this->checkQuota($parent->getPath().'/'.basename($uri)); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -49,373 +49,373 @@ |
||
49 | 49 | use OCP\Share\IManager; |
50 | 50 | |
51 | 51 | abstract class Node implements \Sabre\DAV\INode { |
52 | - /** |
|
53 | - * @var View |
|
54 | - */ |
|
55 | - protected $fileView; |
|
56 | - |
|
57 | - /** |
|
58 | - * The path to the current node |
|
59 | - * |
|
60 | - * @var string |
|
61 | - */ |
|
62 | - protected $path; |
|
63 | - |
|
64 | - /** |
|
65 | - * node properties cache |
|
66 | - * |
|
67 | - * @var array |
|
68 | - */ |
|
69 | - protected $property_cache = null; |
|
70 | - |
|
71 | - protected FileInfo $info; |
|
72 | - |
|
73 | - /** |
|
74 | - * @var IManager |
|
75 | - */ |
|
76 | - protected $shareManager; |
|
77 | - |
|
78 | - protected \OCP\Files\Node $node; |
|
79 | - |
|
80 | - /** |
|
81 | - * Sets up the node, expects a full path name |
|
82 | - */ |
|
83 | - public function __construct(View $view, FileInfo $info, IManager $shareManager = null) { |
|
84 | - $this->fileView = $view; |
|
85 | - $this->path = $this->fileView->getRelativePath($info->getPath()); |
|
86 | - $this->info = $info; |
|
87 | - if ($shareManager) { |
|
88 | - $this->shareManager = $shareManager; |
|
89 | - } else { |
|
90 | - $this->shareManager = \OC::$server->getShareManager(); |
|
91 | - } |
|
92 | - if ($info instanceof Folder || $info instanceof File || $info instanceof LazyFolder) { |
|
93 | - $this->node = $info; |
|
94 | - } else { |
|
95 | - $root = \OC::$server->get(IRootFolder::class); |
|
96 | - if ($info->getType() === FileInfo::TYPE_FOLDER) { |
|
97 | - $this->node = new Folder($root, $view, $this->path, $info); |
|
98 | - } else { |
|
99 | - $this->node = new File($root, $view, $this->path, $info); |
|
100 | - } |
|
101 | - } |
|
102 | - } |
|
103 | - |
|
104 | - protected function refreshInfo(): void { |
|
105 | - $info = $this->fileView->getFileInfo($this->path); |
|
106 | - if ($info === false) { |
|
107 | - throw new \Sabre\DAV\Exception('Failed to get fileinfo for '. $this->path); |
|
108 | - } |
|
109 | - $this->info = $info; |
|
110 | - $root = \OC::$server->get(IRootFolder::class); |
|
111 | - if ($this->info->getType() === FileInfo::TYPE_FOLDER) { |
|
112 | - $this->node = new Folder($root, $this->fileView, $this->path, $this->info); |
|
113 | - } else { |
|
114 | - $this->node = new File($root, $this->fileView, $this->path, $this->info); |
|
115 | - } |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Returns the name of the node |
|
120 | - * |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function getName() { |
|
124 | - return $this->info->getName(); |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Returns the full path |
|
129 | - * |
|
130 | - * @return string |
|
131 | - */ |
|
132 | - public function getPath() { |
|
133 | - return $this->path; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Renames the node |
|
138 | - * |
|
139 | - * @param string $name The new name |
|
140 | - * @throws \Sabre\DAV\Exception\BadRequest |
|
141 | - * @throws \Sabre\DAV\Exception\Forbidden |
|
142 | - */ |
|
143 | - public function setName($name) { |
|
144 | - // rename is only allowed if the update privilege is granted |
|
145 | - if (!($this->info->isUpdateable() || ($this->info->getMountPoint() instanceof MoveableMount && $this->info->getInternalPath() === ''))) { |
|
146 | - throw new \Sabre\DAV\Exception\Forbidden(); |
|
147 | - } |
|
148 | - |
|
149 | - [$parentPath,] = \Sabre\Uri\split($this->path); |
|
150 | - [, $newName] = \Sabre\Uri\split($name); |
|
151 | - |
|
152 | - // verify path of the target |
|
153 | - $this->verifyPath(); |
|
154 | - |
|
155 | - $newPath = $parentPath . '/' . $newName; |
|
156 | - |
|
157 | - if (!$this->fileView->rename($this->path, $newPath)) { |
|
158 | - throw new \Sabre\DAV\Exception('Failed to rename '. $this->path . ' to ' . $newPath); |
|
159 | - } |
|
160 | - |
|
161 | - $this->path = $newPath; |
|
162 | - |
|
163 | - $this->refreshInfo(); |
|
164 | - } |
|
165 | - |
|
166 | - public function setPropertyCache($property_cache) { |
|
167 | - $this->property_cache = $property_cache; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Returns the last modification time, as a unix timestamp |
|
172 | - * |
|
173 | - * @return int timestamp as integer |
|
174 | - */ |
|
175 | - public function getLastModified() { |
|
176 | - $timestamp = $this->info->getMtime(); |
|
177 | - if (!empty($timestamp)) { |
|
178 | - return (int)$timestamp; |
|
179 | - } |
|
180 | - return $timestamp; |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * sets the last modification time of the file (mtime) to the value given |
|
185 | - * in the second parameter or to now if the second param is empty. |
|
186 | - * Even if the modification time is set to a custom value the access time is set to now. |
|
187 | - */ |
|
188 | - public function touch($mtime) { |
|
189 | - $mtime = $this->sanitizeMtime($mtime); |
|
190 | - $this->fileView->touch($this->path, $mtime); |
|
191 | - $this->refreshInfo(); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Returns the ETag for a file |
|
196 | - * |
|
197 | - * An ETag is a unique identifier representing the current version of the |
|
198 | - * file. If the file changes, the ETag MUST change. The ETag is an |
|
199 | - * arbitrary string, but MUST be surrounded by double-quotes. |
|
200 | - * |
|
201 | - * Return null if the ETag can not effectively be determined |
|
202 | - * |
|
203 | - * @return string |
|
204 | - */ |
|
205 | - public function getETag() { |
|
206 | - return '"' . $this->info->getEtag() . '"'; |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Sets the ETag |
|
211 | - * |
|
212 | - * @param string $etag |
|
213 | - * |
|
214 | - * @return int file id of updated file or -1 on failure |
|
215 | - */ |
|
216 | - public function setETag($etag) { |
|
217 | - return $this->fileView->putFileInfo($this->path, ['etag' => $etag]); |
|
218 | - } |
|
219 | - |
|
220 | - public function setCreationTime(int $time) { |
|
221 | - return $this->fileView->putFileInfo($this->path, ['creation_time' => $time]); |
|
222 | - } |
|
223 | - |
|
224 | - public function setUploadTime(int $time) { |
|
225 | - return $this->fileView->putFileInfo($this->path, ['upload_time' => $time]); |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * Returns the size of the node, in bytes |
|
230 | - * |
|
231 | - * @psalm-suppress ImplementedReturnTypeMismatch \Sabre\DAV\IFile::getSize signature does not support 32bit |
|
232 | - * @return int|float |
|
233 | - */ |
|
234 | - public function getSize(): int|float { |
|
235 | - return $this->info->getSize(); |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * Returns the cache's file id |
|
240 | - * |
|
241 | - * @return int |
|
242 | - */ |
|
243 | - public function getId() { |
|
244 | - return $this->info->getId(); |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * @return string|null |
|
249 | - */ |
|
250 | - public function getFileId() { |
|
251 | - if ($id = $this->info->getId()) { |
|
252 | - return DavUtil::getDavFileId($id); |
|
253 | - } |
|
254 | - |
|
255 | - return null; |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * @return integer |
|
260 | - */ |
|
261 | - public function getInternalFileId() { |
|
262 | - return $this->info->getId(); |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * @param string $user |
|
267 | - * @return int |
|
268 | - */ |
|
269 | - public function getSharePermissions($user) { |
|
270 | - // check of we access a federated share |
|
271 | - if ($user !== null) { |
|
272 | - try { |
|
273 | - $share = $this->shareManager->getShareByToken($user); |
|
274 | - return $share->getPermissions(); |
|
275 | - } catch (ShareNotFound $e) { |
|
276 | - // ignore |
|
277 | - } |
|
278 | - } |
|
279 | - |
|
280 | - try { |
|
281 | - $storage = $this->info->getStorage(); |
|
282 | - } catch (StorageNotAvailableException $e) { |
|
283 | - $storage = null; |
|
284 | - } |
|
285 | - |
|
286 | - if ($storage && $storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { |
|
287 | - /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
288 | - $permissions = (int)$storage->getShare()->getPermissions(); |
|
289 | - } else { |
|
290 | - $permissions = $this->info->getPermissions(); |
|
291 | - } |
|
292 | - |
|
293 | - /* |
|
52 | + /** |
|
53 | + * @var View |
|
54 | + */ |
|
55 | + protected $fileView; |
|
56 | + |
|
57 | + /** |
|
58 | + * The path to the current node |
|
59 | + * |
|
60 | + * @var string |
|
61 | + */ |
|
62 | + protected $path; |
|
63 | + |
|
64 | + /** |
|
65 | + * node properties cache |
|
66 | + * |
|
67 | + * @var array |
|
68 | + */ |
|
69 | + protected $property_cache = null; |
|
70 | + |
|
71 | + protected FileInfo $info; |
|
72 | + |
|
73 | + /** |
|
74 | + * @var IManager |
|
75 | + */ |
|
76 | + protected $shareManager; |
|
77 | + |
|
78 | + protected \OCP\Files\Node $node; |
|
79 | + |
|
80 | + /** |
|
81 | + * Sets up the node, expects a full path name |
|
82 | + */ |
|
83 | + public function __construct(View $view, FileInfo $info, IManager $shareManager = null) { |
|
84 | + $this->fileView = $view; |
|
85 | + $this->path = $this->fileView->getRelativePath($info->getPath()); |
|
86 | + $this->info = $info; |
|
87 | + if ($shareManager) { |
|
88 | + $this->shareManager = $shareManager; |
|
89 | + } else { |
|
90 | + $this->shareManager = \OC::$server->getShareManager(); |
|
91 | + } |
|
92 | + if ($info instanceof Folder || $info instanceof File || $info instanceof LazyFolder) { |
|
93 | + $this->node = $info; |
|
94 | + } else { |
|
95 | + $root = \OC::$server->get(IRootFolder::class); |
|
96 | + if ($info->getType() === FileInfo::TYPE_FOLDER) { |
|
97 | + $this->node = new Folder($root, $view, $this->path, $info); |
|
98 | + } else { |
|
99 | + $this->node = new File($root, $view, $this->path, $info); |
|
100 | + } |
|
101 | + } |
|
102 | + } |
|
103 | + |
|
104 | + protected function refreshInfo(): void { |
|
105 | + $info = $this->fileView->getFileInfo($this->path); |
|
106 | + if ($info === false) { |
|
107 | + throw new \Sabre\DAV\Exception('Failed to get fileinfo for '. $this->path); |
|
108 | + } |
|
109 | + $this->info = $info; |
|
110 | + $root = \OC::$server->get(IRootFolder::class); |
|
111 | + if ($this->info->getType() === FileInfo::TYPE_FOLDER) { |
|
112 | + $this->node = new Folder($root, $this->fileView, $this->path, $this->info); |
|
113 | + } else { |
|
114 | + $this->node = new File($root, $this->fileView, $this->path, $this->info); |
|
115 | + } |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Returns the name of the node |
|
120 | + * |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function getName() { |
|
124 | + return $this->info->getName(); |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Returns the full path |
|
129 | + * |
|
130 | + * @return string |
|
131 | + */ |
|
132 | + public function getPath() { |
|
133 | + return $this->path; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Renames the node |
|
138 | + * |
|
139 | + * @param string $name The new name |
|
140 | + * @throws \Sabre\DAV\Exception\BadRequest |
|
141 | + * @throws \Sabre\DAV\Exception\Forbidden |
|
142 | + */ |
|
143 | + public function setName($name) { |
|
144 | + // rename is only allowed if the update privilege is granted |
|
145 | + if (!($this->info->isUpdateable() || ($this->info->getMountPoint() instanceof MoveableMount && $this->info->getInternalPath() === ''))) { |
|
146 | + throw new \Sabre\DAV\Exception\Forbidden(); |
|
147 | + } |
|
148 | + |
|
149 | + [$parentPath,] = \Sabre\Uri\split($this->path); |
|
150 | + [, $newName] = \Sabre\Uri\split($name); |
|
151 | + |
|
152 | + // verify path of the target |
|
153 | + $this->verifyPath(); |
|
154 | + |
|
155 | + $newPath = $parentPath . '/' . $newName; |
|
156 | + |
|
157 | + if (!$this->fileView->rename($this->path, $newPath)) { |
|
158 | + throw new \Sabre\DAV\Exception('Failed to rename '. $this->path . ' to ' . $newPath); |
|
159 | + } |
|
160 | + |
|
161 | + $this->path = $newPath; |
|
162 | + |
|
163 | + $this->refreshInfo(); |
|
164 | + } |
|
165 | + |
|
166 | + public function setPropertyCache($property_cache) { |
|
167 | + $this->property_cache = $property_cache; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Returns the last modification time, as a unix timestamp |
|
172 | + * |
|
173 | + * @return int timestamp as integer |
|
174 | + */ |
|
175 | + public function getLastModified() { |
|
176 | + $timestamp = $this->info->getMtime(); |
|
177 | + if (!empty($timestamp)) { |
|
178 | + return (int)$timestamp; |
|
179 | + } |
|
180 | + return $timestamp; |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * sets the last modification time of the file (mtime) to the value given |
|
185 | + * in the second parameter or to now if the second param is empty. |
|
186 | + * Even if the modification time is set to a custom value the access time is set to now. |
|
187 | + */ |
|
188 | + public function touch($mtime) { |
|
189 | + $mtime = $this->sanitizeMtime($mtime); |
|
190 | + $this->fileView->touch($this->path, $mtime); |
|
191 | + $this->refreshInfo(); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Returns the ETag for a file |
|
196 | + * |
|
197 | + * An ETag is a unique identifier representing the current version of the |
|
198 | + * file. If the file changes, the ETag MUST change. The ETag is an |
|
199 | + * arbitrary string, but MUST be surrounded by double-quotes. |
|
200 | + * |
|
201 | + * Return null if the ETag can not effectively be determined |
|
202 | + * |
|
203 | + * @return string |
|
204 | + */ |
|
205 | + public function getETag() { |
|
206 | + return '"' . $this->info->getEtag() . '"'; |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Sets the ETag |
|
211 | + * |
|
212 | + * @param string $etag |
|
213 | + * |
|
214 | + * @return int file id of updated file or -1 on failure |
|
215 | + */ |
|
216 | + public function setETag($etag) { |
|
217 | + return $this->fileView->putFileInfo($this->path, ['etag' => $etag]); |
|
218 | + } |
|
219 | + |
|
220 | + public function setCreationTime(int $time) { |
|
221 | + return $this->fileView->putFileInfo($this->path, ['creation_time' => $time]); |
|
222 | + } |
|
223 | + |
|
224 | + public function setUploadTime(int $time) { |
|
225 | + return $this->fileView->putFileInfo($this->path, ['upload_time' => $time]); |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * Returns the size of the node, in bytes |
|
230 | + * |
|
231 | + * @psalm-suppress ImplementedReturnTypeMismatch \Sabre\DAV\IFile::getSize signature does not support 32bit |
|
232 | + * @return int|float |
|
233 | + */ |
|
234 | + public function getSize(): int|float { |
|
235 | + return $this->info->getSize(); |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Returns the cache's file id |
|
240 | + * |
|
241 | + * @return int |
|
242 | + */ |
|
243 | + public function getId() { |
|
244 | + return $this->info->getId(); |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * @return string|null |
|
249 | + */ |
|
250 | + public function getFileId() { |
|
251 | + if ($id = $this->info->getId()) { |
|
252 | + return DavUtil::getDavFileId($id); |
|
253 | + } |
|
254 | + |
|
255 | + return null; |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * @return integer |
|
260 | + */ |
|
261 | + public function getInternalFileId() { |
|
262 | + return $this->info->getId(); |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * @param string $user |
|
267 | + * @return int |
|
268 | + */ |
|
269 | + public function getSharePermissions($user) { |
|
270 | + // check of we access a federated share |
|
271 | + if ($user !== null) { |
|
272 | + try { |
|
273 | + $share = $this->shareManager->getShareByToken($user); |
|
274 | + return $share->getPermissions(); |
|
275 | + } catch (ShareNotFound $e) { |
|
276 | + // ignore |
|
277 | + } |
|
278 | + } |
|
279 | + |
|
280 | + try { |
|
281 | + $storage = $this->info->getStorage(); |
|
282 | + } catch (StorageNotAvailableException $e) { |
|
283 | + $storage = null; |
|
284 | + } |
|
285 | + |
|
286 | + if ($storage && $storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { |
|
287 | + /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
288 | + $permissions = (int)$storage->getShare()->getPermissions(); |
|
289 | + } else { |
|
290 | + $permissions = $this->info->getPermissions(); |
|
291 | + } |
|
292 | + |
|
293 | + /* |
|
294 | 294 | * We can always share non moveable mount points with DELETE and UPDATE |
295 | 295 | * Eventually we need to do this properly |
296 | 296 | */ |
297 | - $mountpoint = $this->info->getMountPoint(); |
|
298 | - if (!($mountpoint instanceof MoveableMount)) { |
|
299 | - $mountpointpath = $mountpoint->getMountPoint(); |
|
300 | - if (substr($mountpointpath, -1) === '/') { |
|
301 | - $mountpointpath = substr($mountpointpath, 0, -1); |
|
302 | - } |
|
303 | - |
|
304 | - if (!$mountpoint->getOption('readonly', false) && $mountpointpath === $this->info->getPath()) { |
|
305 | - $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
306 | - } |
|
307 | - } |
|
308 | - |
|
309 | - /* |
|
297 | + $mountpoint = $this->info->getMountPoint(); |
|
298 | + if (!($mountpoint instanceof MoveableMount)) { |
|
299 | + $mountpointpath = $mountpoint->getMountPoint(); |
|
300 | + if (substr($mountpointpath, -1) === '/') { |
|
301 | + $mountpointpath = substr($mountpointpath, 0, -1); |
|
302 | + } |
|
303 | + |
|
304 | + if (!$mountpoint->getOption('readonly', false) && $mountpointpath === $this->info->getPath()) { |
|
305 | + $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
306 | + } |
|
307 | + } |
|
308 | + |
|
309 | + /* |
|
310 | 310 | * Files can't have create or delete permissions |
311 | 311 | */ |
312 | - if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
313 | - $permissions &= ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE); |
|
314 | - } |
|
315 | - |
|
316 | - return $permissions; |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * @return array |
|
321 | - */ |
|
322 | - public function getShareAttributes(): array { |
|
323 | - $attributes = []; |
|
324 | - |
|
325 | - try { |
|
326 | - $storage = $this->info->getStorage(); |
|
327 | - } catch (StorageNotAvailableException $e) { |
|
328 | - $storage = null; |
|
329 | - } |
|
330 | - |
|
331 | - if ($storage && $storage->instanceOfStorage(\OCA\Files_Sharing\SharedStorage::class)) { |
|
332 | - /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
333 | - $attributes = $storage->getShare()->getAttributes(); |
|
334 | - if ($attributes === null) { |
|
335 | - return []; |
|
336 | - } else { |
|
337 | - return $attributes->toArray(); |
|
338 | - } |
|
339 | - } |
|
340 | - |
|
341 | - return $attributes; |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * @param string $user |
|
346 | - * @return string |
|
347 | - */ |
|
348 | - public function getNoteFromShare($user) { |
|
349 | - if ($user === null) { |
|
350 | - return ''; |
|
351 | - } |
|
352 | - |
|
353 | - // Retrieve note from the share object already loaded into |
|
354 | - // memory, to avoid additional database queries. |
|
355 | - $storage = $this->getNode()->getStorage(); |
|
356 | - if (!$storage->instanceOfStorage(\OCA\Files_Sharing\SharedStorage::class)) { |
|
357 | - return ''; |
|
358 | - } |
|
359 | - /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
360 | - |
|
361 | - $share = $storage->getShare(); |
|
362 | - $note = $share->getNote(); |
|
363 | - if ($share->getShareOwner() !== $user) { |
|
364 | - return $note; |
|
365 | - } |
|
366 | - return ''; |
|
367 | - } |
|
368 | - |
|
369 | - /** |
|
370 | - * @return string |
|
371 | - */ |
|
372 | - public function getDavPermissions() { |
|
373 | - return DavUtil::getDavPermissions($this->info); |
|
374 | - } |
|
375 | - |
|
376 | - public function getOwner() { |
|
377 | - return $this->info->getOwner(); |
|
378 | - } |
|
379 | - |
|
380 | - protected function verifyPath() { |
|
381 | - try { |
|
382 | - $fileName = basename($this->info->getPath()); |
|
383 | - $this->fileView->verifyPath($this->path, $fileName); |
|
384 | - } catch (\OCP\Files\InvalidPathException $ex) { |
|
385 | - throw new InvalidPath($ex->getMessage()); |
|
386 | - } |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
391 | - */ |
|
392 | - public function acquireLock($type) { |
|
393 | - $this->fileView->lockFile($this->path, $type); |
|
394 | - } |
|
395 | - |
|
396 | - /** |
|
397 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
398 | - */ |
|
399 | - public function releaseLock($type) { |
|
400 | - $this->fileView->unlockFile($this->path, $type); |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
405 | - */ |
|
406 | - public function changeLock($type) { |
|
407 | - $this->fileView->changeLock($this->path, $type); |
|
408 | - } |
|
409 | - |
|
410 | - public function getFileInfo() { |
|
411 | - return $this->info; |
|
412 | - } |
|
413 | - |
|
414 | - public function getNode(): \OCP\Files\Node { |
|
415 | - return $this->node; |
|
416 | - } |
|
417 | - |
|
418 | - protected function sanitizeMtime($mtimeFromRequest) { |
|
419 | - return MtimeSanitizer::sanitizeMtime($mtimeFromRequest); |
|
420 | - } |
|
312 | + if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
313 | + $permissions &= ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE); |
|
314 | + } |
|
315 | + |
|
316 | + return $permissions; |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * @return array |
|
321 | + */ |
|
322 | + public function getShareAttributes(): array { |
|
323 | + $attributes = []; |
|
324 | + |
|
325 | + try { |
|
326 | + $storage = $this->info->getStorage(); |
|
327 | + } catch (StorageNotAvailableException $e) { |
|
328 | + $storage = null; |
|
329 | + } |
|
330 | + |
|
331 | + if ($storage && $storage->instanceOfStorage(\OCA\Files_Sharing\SharedStorage::class)) { |
|
332 | + /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
333 | + $attributes = $storage->getShare()->getAttributes(); |
|
334 | + if ($attributes === null) { |
|
335 | + return []; |
|
336 | + } else { |
|
337 | + return $attributes->toArray(); |
|
338 | + } |
|
339 | + } |
|
340 | + |
|
341 | + return $attributes; |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * @param string $user |
|
346 | + * @return string |
|
347 | + */ |
|
348 | + public function getNoteFromShare($user) { |
|
349 | + if ($user === null) { |
|
350 | + return ''; |
|
351 | + } |
|
352 | + |
|
353 | + // Retrieve note from the share object already loaded into |
|
354 | + // memory, to avoid additional database queries. |
|
355 | + $storage = $this->getNode()->getStorage(); |
|
356 | + if (!$storage->instanceOfStorage(\OCA\Files_Sharing\SharedStorage::class)) { |
|
357 | + return ''; |
|
358 | + } |
|
359 | + /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
360 | + |
|
361 | + $share = $storage->getShare(); |
|
362 | + $note = $share->getNote(); |
|
363 | + if ($share->getShareOwner() !== $user) { |
|
364 | + return $note; |
|
365 | + } |
|
366 | + return ''; |
|
367 | + } |
|
368 | + |
|
369 | + /** |
|
370 | + * @return string |
|
371 | + */ |
|
372 | + public function getDavPermissions() { |
|
373 | + return DavUtil::getDavPermissions($this->info); |
|
374 | + } |
|
375 | + |
|
376 | + public function getOwner() { |
|
377 | + return $this->info->getOwner(); |
|
378 | + } |
|
379 | + |
|
380 | + protected function verifyPath() { |
|
381 | + try { |
|
382 | + $fileName = basename($this->info->getPath()); |
|
383 | + $this->fileView->verifyPath($this->path, $fileName); |
|
384 | + } catch (\OCP\Files\InvalidPathException $ex) { |
|
385 | + throw new InvalidPath($ex->getMessage()); |
|
386 | + } |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
391 | + */ |
|
392 | + public function acquireLock($type) { |
|
393 | + $this->fileView->lockFile($this->path, $type); |
|
394 | + } |
|
395 | + |
|
396 | + /** |
|
397 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
398 | + */ |
|
399 | + public function releaseLock($type) { |
|
400 | + $this->fileView->unlockFile($this->path, $type); |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
405 | + */ |
|
406 | + public function changeLock($type) { |
|
407 | + $this->fileView->changeLock($this->path, $type); |
|
408 | + } |
|
409 | + |
|
410 | + public function getFileInfo() { |
|
411 | + return $this->info; |
|
412 | + } |
|
413 | + |
|
414 | + public function getNode(): \OCP\Files\Node { |
|
415 | + return $this->node; |
|
416 | + } |
|
417 | + |
|
418 | + protected function sanitizeMtime($mtimeFromRequest) { |
|
419 | + return MtimeSanitizer::sanitizeMtime($mtimeFromRequest); |
|
420 | + } |
|
421 | 421 | } |
@@ -77,584 +77,584 @@ |
||
77 | 77 | use Sabre\DAV\IFile; |
78 | 78 | |
79 | 79 | class File extends Node implements IFile { |
80 | - protected $request; |
|
81 | - |
|
82 | - protected IL10N $l10n; |
|
83 | - |
|
84 | - /** @var array<string, FileMetadata> */ |
|
85 | - private array $metadata = []; |
|
86 | - |
|
87 | - /** |
|
88 | - * Sets up the node, expects a full path name |
|
89 | - * |
|
90 | - * @param \OC\Files\View $view |
|
91 | - * @param \OCP\Files\FileInfo $info |
|
92 | - * @param \OCP\Share\IManager $shareManager |
|
93 | - * @param \OC\AppFramework\Http\Request $request |
|
94 | - */ |
|
95 | - public function __construct(View $view, FileInfo $info, IManager $shareManager = null, Request $request = null) { |
|
96 | - parent::__construct($view, $info, $shareManager); |
|
97 | - |
|
98 | - // Querying IL10N directly results in a dependency loop |
|
99 | - /** @var IL10NFactory $l10nFactory */ |
|
100 | - $l10nFactory = \OC::$server->get(IL10NFactory::class); |
|
101 | - $this->l10n = $l10nFactory->get(Application::APP_ID); |
|
102 | - |
|
103 | - if (isset($request)) { |
|
104 | - $this->request = $request; |
|
105 | - } else { |
|
106 | - $this->request = \OC::$server->getRequest(); |
|
107 | - } |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Updates the data |
|
112 | - * |
|
113 | - * The data argument is a readable stream resource. |
|
114 | - * |
|
115 | - * After a successful put operation, you may choose to return an ETag. The |
|
116 | - * etag must always be surrounded by double-quotes. These quotes must |
|
117 | - * appear in the actual string you're returning. |
|
118 | - * |
|
119 | - * Clients may use the ETag from a PUT request to later on make sure that |
|
120 | - * when they update the file, the contents haven't changed in the mean |
|
121 | - * time. |
|
122 | - * |
|
123 | - * If you don't plan to store the file byte-by-byte, and you return a |
|
124 | - * different object on a subsequent GET you are strongly recommended to not |
|
125 | - * return an ETag, and just return null. |
|
126 | - * |
|
127 | - * @param resource $data |
|
128 | - * |
|
129 | - * @throws Forbidden |
|
130 | - * @throws UnsupportedMediaType |
|
131 | - * @throws BadRequest |
|
132 | - * @throws Exception |
|
133 | - * @throws EntityTooLarge |
|
134 | - * @throws ServiceUnavailable |
|
135 | - * @throws FileLocked |
|
136 | - * @return string|null |
|
137 | - */ |
|
138 | - public function put($data) { |
|
139 | - try { |
|
140 | - $exists = $this->fileView->file_exists($this->path); |
|
141 | - if ($exists && !$this->info->isUpdateable()) { |
|
142 | - throw new Forbidden(); |
|
143 | - } |
|
144 | - } catch (StorageNotAvailableException $e) { |
|
145 | - throw new ServiceUnavailable($this->l10n->t('File is not updatable: %1$s', [$e->getMessage()])); |
|
146 | - } |
|
147 | - |
|
148 | - // verify path of the target |
|
149 | - $this->verifyPath(); |
|
150 | - |
|
151 | - /** @var Storage $partStorage */ |
|
152 | - [$partStorage] = $this->fileView->resolvePath($this->path); |
|
153 | - $needsPartFile = $partStorage->needsPartFile() && (strlen($this->path) > 1); |
|
154 | - |
|
155 | - $view = \OC\Files\Filesystem::getView(); |
|
156 | - |
|
157 | - if ($needsPartFile) { |
|
158 | - // mark file as partial while uploading (ignored by the scanner) |
|
159 | - $partFilePath = $this->getPartFileBasePath($this->path) . '.ocTransferId' . rand() . '.part'; |
|
160 | - |
|
161 | - if (!$view->isCreatable($partFilePath) && $view->isUpdatable($this->path)) { |
|
162 | - $needsPartFile = false; |
|
163 | - } |
|
164 | - } |
|
165 | - if (!$needsPartFile) { |
|
166 | - // upload file directly as the final path |
|
167 | - $partFilePath = $this->path; |
|
168 | - |
|
169 | - if ($view && !$this->emitPreHooks($exists)) { |
|
170 | - throw new Exception($this->l10n->t('Could not write to final file, canceled by hook')); |
|
171 | - } |
|
172 | - } |
|
173 | - |
|
174 | - // the part file and target file might be on a different storage in case of a single file storage (e.g. single file share) |
|
175 | - /** @var \OC\Files\Storage\Storage $partStorage */ |
|
176 | - [$partStorage, $internalPartPath] = $this->fileView->resolvePath($partFilePath); |
|
177 | - /** @var \OC\Files\Storage\Storage $storage */ |
|
178 | - [$storage, $internalPath] = $this->fileView->resolvePath($this->path); |
|
179 | - try { |
|
180 | - if (!$needsPartFile) { |
|
181 | - try { |
|
182 | - $this->changeLock(ILockingProvider::LOCK_EXCLUSIVE); |
|
183 | - } catch (LockedException $e) { |
|
184 | - // during very large uploads, the shared lock we got at the start might have been expired |
|
185 | - // meaning that the above lock can fail not just only because somebody else got a shared lock |
|
186 | - // or because there is no existing shared lock to make exclusive |
|
187 | - // |
|
188 | - // Thus we try to get a new exclusive lock, if the original lock failed because of a different shared |
|
189 | - // lock this will still fail, if our original shared lock expired the new lock will be successful and |
|
190 | - // the entire operation will be safe |
|
191 | - |
|
192 | - try { |
|
193 | - $this->acquireLock(ILockingProvider::LOCK_EXCLUSIVE); |
|
194 | - } catch (LockedException $ex) { |
|
195 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
196 | - } |
|
197 | - } |
|
198 | - } |
|
199 | - |
|
200 | - if (!is_resource($data)) { |
|
201 | - $tmpData = fopen('php://temp', 'r+'); |
|
202 | - if ($data !== null) { |
|
203 | - fwrite($tmpData, $data); |
|
204 | - rewind($tmpData); |
|
205 | - } |
|
206 | - $data = $tmpData; |
|
207 | - } |
|
208 | - |
|
209 | - if ($this->request->getHeader('X-HASH') !== '') { |
|
210 | - $hash = $this->request->getHeader('X-HASH'); |
|
211 | - if ($hash === 'all' || $hash === 'md5') { |
|
212 | - $data = HashWrapper::wrap($data, 'md5', function ($hash) { |
|
213 | - $this->header('X-Hash-MD5: ' . $hash); |
|
214 | - }); |
|
215 | - } |
|
216 | - |
|
217 | - if ($hash === 'all' || $hash === 'sha1') { |
|
218 | - $data = HashWrapper::wrap($data, 'sha1', function ($hash) { |
|
219 | - $this->header('X-Hash-SHA1: ' . $hash); |
|
220 | - }); |
|
221 | - } |
|
222 | - |
|
223 | - if ($hash === 'all' || $hash === 'sha256') { |
|
224 | - $data = HashWrapper::wrap($data, 'sha256', function ($hash) { |
|
225 | - $this->header('X-Hash-SHA256: ' . $hash); |
|
226 | - }); |
|
227 | - } |
|
228 | - } |
|
229 | - |
|
230 | - if ($partStorage->instanceOfStorage(Storage\IWriteStreamStorage::class)) { |
|
231 | - $isEOF = false; |
|
232 | - $wrappedData = CallbackWrapper::wrap($data, null, null, null, null, function ($stream) use (&$isEOF) { |
|
233 | - $isEOF = feof($stream); |
|
234 | - }); |
|
235 | - |
|
236 | - $result = true; |
|
237 | - $count = -1; |
|
238 | - try { |
|
239 | - $count = $partStorage->writeStream($internalPartPath, $wrappedData); |
|
240 | - } catch (GenericFileException $e) { |
|
241 | - $result = false; |
|
242 | - } catch (BadGateway $e) { |
|
243 | - throw $e; |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - if ($result === false) { |
|
248 | - $result = $isEOF; |
|
249 | - if (is_resource($wrappedData)) { |
|
250 | - $result = feof($wrappedData); |
|
251 | - } |
|
252 | - } |
|
253 | - } else { |
|
254 | - $target = $partStorage->fopen($internalPartPath, 'wb'); |
|
255 | - if ($target === false) { |
|
256 | - \OC::$server->get(LoggerInterface::class)->error('\OC\Files\Filesystem::fopen() failed', ['app' => 'webdav']); |
|
257 | - // because we have no clue about the cause we can only throw back a 500/Internal Server Error |
|
258 | - throw new Exception($this->l10n->t('Could not write file contents')); |
|
259 | - } |
|
260 | - [$count, $result] = \OC_Helper::streamCopy($data, $target); |
|
261 | - fclose($target); |
|
262 | - } |
|
263 | - |
|
264 | - if ($result === false) { |
|
265 | - $expected = -1; |
|
266 | - if (isset($_SERVER['CONTENT_LENGTH'])) { |
|
267 | - $expected = (int)$_SERVER['CONTENT_LENGTH']; |
|
268 | - } |
|
269 | - if ($expected !== 0) { |
|
270 | - throw new Exception( |
|
271 | - $this->l10n->t( |
|
272 | - 'Error while copying file to target location (copied: %1$s, expected filesize: %2$s)', |
|
273 | - [ |
|
274 | - $this->l10n->n('%n byte', '%n bytes', $count), |
|
275 | - $this->l10n->n('%n byte', '%n bytes', $expected), |
|
276 | - ], |
|
277 | - ) |
|
278 | - ); |
|
279 | - } |
|
280 | - } |
|
281 | - |
|
282 | - // if content length is sent by client: |
|
283 | - // double check if the file was fully received |
|
284 | - // compare expected and actual size |
|
285 | - if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['REQUEST_METHOD'] === 'PUT') { |
|
286 | - $expected = (int)$_SERVER['CONTENT_LENGTH']; |
|
287 | - if ($count !== $expected) { |
|
288 | - throw new BadRequest( |
|
289 | - $this->l10n->t( |
|
290 | - 'Expected filesize of %1$s but read (from Nextcloud client) and wrote (to Nextcloud storage) %2$s. Could either be a network problem on the sending side or a problem writing to the storage on the server side.', |
|
291 | - [ |
|
292 | - $this->l10n->n('%n byte', '%n bytes', $expected), |
|
293 | - $this->l10n->n('%n byte', '%n bytes', $count), |
|
294 | - ], |
|
295 | - ) |
|
296 | - ); |
|
297 | - } |
|
298 | - } |
|
299 | - } catch (\Exception $e) { |
|
300 | - if ($e instanceof LockedException) { |
|
301 | - \OC::$server->get(LoggerInterface::class)->debug($e->getMessage(), ['exception' => $e]); |
|
302 | - } else { |
|
303 | - \OC::$server->get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]); |
|
304 | - } |
|
305 | - |
|
306 | - if ($needsPartFile) { |
|
307 | - $partStorage->unlink($internalPartPath); |
|
308 | - } |
|
309 | - $this->convertToSabreException($e); |
|
310 | - } |
|
311 | - |
|
312 | - try { |
|
313 | - if ($needsPartFile) { |
|
314 | - if ($view && !$this->emitPreHooks($exists)) { |
|
315 | - $partStorage->unlink($internalPartPath); |
|
316 | - throw new Exception($this->l10n->t('Could not rename part file to final file, canceled by hook')); |
|
317 | - } |
|
318 | - try { |
|
319 | - $this->changeLock(ILockingProvider::LOCK_EXCLUSIVE); |
|
320 | - } catch (LockedException $e) { |
|
321 | - // during very large uploads, the shared lock we got at the start might have been expired |
|
322 | - // meaning that the above lock can fail not just only because somebody else got a shared lock |
|
323 | - // or because there is no existing shared lock to make exclusive |
|
324 | - // |
|
325 | - // Thus we try to get a new exclusive lock, if the original lock failed because of a different shared |
|
326 | - // lock this will still fail, if our original shared lock expired the new lock will be successful and |
|
327 | - // the entire operation will be safe |
|
328 | - |
|
329 | - try { |
|
330 | - $this->acquireLock(ILockingProvider::LOCK_EXCLUSIVE); |
|
331 | - } catch (LockedException $ex) { |
|
332 | - if ($needsPartFile) { |
|
333 | - $partStorage->unlink($internalPartPath); |
|
334 | - } |
|
335 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
336 | - } |
|
337 | - } |
|
338 | - |
|
339 | - // rename to correct path |
|
340 | - try { |
|
341 | - $renameOkay = $storage->moveFromStorage($partStorage, $internalPartPath, $internalPath); |
|
342 | - $fileExists = $storage->file_exists($internalPath); |
|
343 | - if ($renameOkay === false || $fileExists === false) { |
|
344 | - \OC::$server->get(LoggerInterface::class)->error('renaming part file to final file failed $renameOkay: ' . ($renameOkay ? 'true' : 'false') . ', $fileExists: ' . ($fileExists ? 'true' : 'false') . ')', ['app' => 'webdav']); |
|
345 | - throw new Exception($this->l10n->t('Could not rename part file to final file')); |
|
346 | - } |
|
347 | - } catch (ForbiddenException $ex) { |
|
348 | - if (!$ex->getRetry()) { |
|
349 | - $partStorage->unlink($internalPartPath); |
|
350 | - } |
|
351 | - throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry()); |
|
352 | - } catch (\Exception $e) { |
|
353 | - $partStorage->unlink($internalPartPath); |
|
354 | - $this->convertToSabreException($e); |
|
355 | - } |
|
356 | - } |
|
357 | - |
|
358 | - // since we skipped the view we need to scan and emit the hooks ourselves |
|
359 | - $storage->getUpdater()->update($internalPath); |
|
360 | - |
|
361 | - try { |
|
362 | - $this->changeLock(ILockingProvider::LOCK_SHARED); |
|
363 | - } catch (LockedException $e) { |
|
364 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
365 | - } |
|
366 | - |
|
367 | - // allow sync clients to send the mtime along in a header |
|
368 | - if (isset($this->request->server['HTTP_X_OC_MTIME'])) { |
|
369 | - $mtime = $this->sanitizeMtime($this->request->server['HTTP_X_OC_MTIME']); |
|
370 | - if ($this->fileView->touch($this->path, $mtime)) { |
|
371 | - $this->header('X-OC-MTime: accepted'); |
|
372 | - } |
|
373 | - } |
|
374 | - |
|
375 | - $fileInfoUpdate = [ |
|
376 | - 'upload_time' => time() |
|
377 | - ]; |
|
378 | - |
|
379 | - // allow sync clients to send the creation time along in a header |
|
380 | - if (isset($this->request->server['HTTP_X_OC_CTIME'])) { |
|
381 | - $ctime = $this->sanitizeMtime($this->request->server['HTTP_X_OC_CTIME']); |
|
382 | - $fileInfoUpdate['creation_time'] = $ctime; |
|
383 | - $this->header('X-OC-CTime: accepted'); |
|
384 | - } |
|
385 | - |
|
386 | - $this->fileView->putFileInfo($this->path, $fileInfoUpdate); |
|
387 | - |
|
388 | - if ($view) { |
|
389 | - $this->emitPostHooks($exists); |
|
390 | - } |
|
391 | - |
|
392 | - $this->refreshInfo(); |
|
393 | - |
|
394 | - if (isset($this->request->server['HTTP_OC_CHECKSUM'])) { |
|
395 | - $checksum = trim($this->request->server['HTTP_OC_CHECKSUM']); |
|
396 | - $this->setChecksum($checksum); |
|
397 | - } elseif ($this->getChecksum() !== null && $this->getChecksum() !== '') { |
|
398 | - $this->setChecksum(''); |
|
399 | - } |
|
400 | - } catch (StorageNotAvailableException $e) { |
|
401 | - throw new ServiceUnavailable($this->l10n->t('Failed to check file size: %1$s', [$e->getMessage()]), 0, $e); |
|
402 | - } |
|
403 | - |
|
404 | - return '"' . $this->info->getEtag() . '"'; |
|
405 | - } |
|
406 | - |
|
407 | - private function getPartFileBasePath($path) { |
|
408 | - $partFileInStorage = \OC::$server->getConfig()->getSystemValue('part_file_in_storage', true); |
|
409 | - if ($partFileInStorage) { |
|
410 | - return $path; |
|
411 | - } else { |
|
412 | - return md5($path); // will place it in the root of the view with a unique name |
|
413 | - } |
|
414 | - } |
|
415 | - |
|
416 | - /** |
|
417 | - * @param string $path |
|
418 | - */ |
|
419 | - private function emitPreHooks($exists, $path = null) { |
|
420 | - if (is_null($path)) { |
|
421 | - $path = $this->path; |
|
422 | - } |
|
423 | - $hookPath = Filesystem::getView()->getRelativePath($this->fileView->getAbsolutePath($path)); |
|
424 | - $run = true; |
|
425 | - |
|
426 | - if (!$exists) { |
|
427 | - \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_create, [ |
|
428 | - \OC\Files\Filesystem::signal_param_path => $hookPath, |
|
429 | - \OC\Files\Filesystem::signal_param_run => &$run, |
|
430 | - ]); |
|
431 | - } else { |
|
432 | - \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_update, [ |
|
433 | - \OC\Files\Filesystem::signal_param_path => $hookPath, |
|
434 | - \OC\Files\Filesystem::signal_param_run => &$run, |
|
435 | - ]); |
|
436 | - } |
|
437 | - \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_write, [ |
|
438 | - \OC\Files\Filesystem::signal_param_path => $hookPath, |
|
439 | - \OC\Files\Filesystem::signal_param_run => &$run, |
|
440 | - ]); |
|
441 | - return $run; |
|
442 | - } |
|
443 | - |
|
444 | - /** |
|
445 | - * @param string $path |
|
446 | - */ |
|
447 | - private function emitPostHooks($exists, $path = null) { |
|
448 | - if (is_null($path)) { |
|
449 | - $path = $this->path; |
|
450 | - } |
|
451 | - $hookPath = Filesystem::getView()->getRelativePath($this->fileView->getAbsolutePath($path)); |
|
452 | - if (!$exists) { |
|
453 | - \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_create, [ |
|
454 | - \OC\Files\Filesystem::signal_param_path => $hookPath |
|
455 | - ]); |
|
456 | - } else { |
|
457 | - \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_update, [ |
|
458 | - \OC\Files\Filesystem::signal_param_path => $hookPath |
|
459 | - ]); |
|
460 | - } |
|
461 | - \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_write, [ |
|
462 | - \OC\Files\Filesystem::signal_param_path => $hookPath |
|
463 | - ]); |
|
464 | - } |
|
465 | - |
|
466 | - /** |
|
467 | - * Returns the data |
|
468 | - * |
|
469 | - * @return resource |
|
470 | - * @throws Forbidden |
|
471 | - * @throws ServiceUnavailable |
|
472 | - */ |
|
473 | - public function get() { |
|
474 | - //throw exception if encryption is disabled but files are still encrypted |
|
475 | - try { |
|
476 | - if (!$this->info->isReadable()) { |
|
477 | - // do a if the file did not exist |
|
478 | - throw new NotFound(); |
|
479 | - } |
|
480 | - try { |
|
481 | - $res = $this->fileView->fopen(ltrim($this->path, '/'), 'rb'); |
|
482 | - } catch (\Exception $e) { |
|
483 | - $this->convertToSabreException($e); |
|
484 | - } |
|
485 | - |
|
486 | - if ($res === false) { |
|
487 | - throw new ServiceUnavailable($this->l10n->t('Could not open file')); |
|
488 | - } |
|
489 | - |
|
490 | - // comparing current file size with the one in DB |
|
491 | - // if different, fix DB and refresh cache. |
|
492 | - if ($this->getSize() !== $this->fileView->filesize($this->getPath())) { |
|
493 | - $logger = \OC::$server->get(LoggerInterface::class); |
|
494 | - $logger->warning('fixing cached size of file id=' . $this->getId()); |
|
495 | - |
|
496 | - $this->getFileInfo()->getStorage()->getUpdater()->update($this->getFileInfo()->getInternalPath()); |
|
497 | - $this->refreshInfo(); |
|
498 | - } |
|
499 | - |
|
500 | - return $res; |
|
501 | - } catch (GenericEncryptionException $e) { |
|
502 | - // returning 503 will allow retry of the operation at a later point in time |
|
503 | - throw new ServiceUnavailable($this->l10n->t('Encryption not ready: %1$s', [$e->getMessage()])); |
|
504 | - } catch (StorageNotAvailableException $e) { |
|
505 | - throw new ServiceUnavailable($this->l10n->t('Failed to open file: %1$s', [$e->getMessage()])); |
|
506 | - } catch (ForbiddenException $ex) { |
|
507 | - throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry()); |
|
508 | - } catch (LockedException $e) { |
|
509 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
510 | - } |
|
511 | - } |
|
512 | - |
|
513 | - /** |
|
514 | - * Delete the current file |
|
515 | - * |
|
516 | - * @throws Forbidden |
|
517 | - * @throws ServiceUnavailable |
|
518 | - */ |
|
519 | - public function delete() { |
|
520 | - if (!$this->info->isDeletable()) { |
|
521 | - throw new Forbidden(); |
|
522 | - } |
|
523 | - |
|
524 | - try { |
|
525 | - if (!$this->fileView->unlink($this->path)) { |
|
526 | - // assume it wasn't possible to delete due to permissions |
|
527 | - throw new Forbidden(); |
|
528 | - } |
|
529 | - } catch (StorageNotAvailableException $e) { |
|
530 | - throw new ServiceUnavailable($this->l10n->t('Failed to unlink: %1$s', [$e->getMessage()])); |
|
531 | - } catch (ForbiddenException $ex) { |
|
532 | - throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry()); |
|
533 | - } catch (LockedException $e) { |
|
534 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
535 | - } |
|
536 | - } |
|
537 | - |
|
538 | - /** |
|
539 | - * Returns the mime-type for a file |
|
540 | - * |
|
541 | - * If null is returned, we'll assume application/octet-stream |
|
542 | - * |
|
543 | - * @return string |
|
544 | - */ |
|
545 | - public function getContentType() { |
|
546 | - $mimeType = $this->info->getMimetype(); |
|
547 | - |
|
548 | - // PROPFIND needs to return the correct mime type, for consistency with the web UI |
|
549 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
550 | - return $mimeType; |
|
551 | - } |
|
552 | - return \OC::$server->getMimeTypeDetector()->getSecureMimeType($mimeType); |
|
553 | - } |
|
554 | - |
|
555 | - /** |
|
556 | - * @return array|bool |
|
557 | - */ |
|
558 | - public function getDirectDownload() { |
|
559 | - if (\OCP\Server::get(\OCP\App\IAppManager::class)->isEnabledForUser('encryption')) { |
|
560 | - return []; |
|
561 | - } |
|
562 | - /** @var \OCP\Files\Storage $storage */ |
|
563 | - [$storage, $internalPath] = $this->fileView->resolvePath($this->path); |
|
564 | - if (is_null($storage)) { |
|
565 | - return []; |
|
566 | - } |
|
567 | - |
|
568 | - return $storage->getDirectDownload($internalPath); |
|
569 | - } |
|
570 | - |
|
571 | - /** |
|
572 | - * Convert the given exception to a SabreException instance |
|
573 | - * |
|
574 | - * @param \Exception $e |
|
575 | - * |
|
576 | - * @throws \Sabre\DAV\Exception |
|
577 | - */ |
|
578 | - private function convertToSabreException(\Exception $e) { |
|
579 | - if ($e instanceof \Sabre\DAV\Exception) { |
|
580 | - throw $e; |
|
581 | - } |
|
582 | - if ($e instanceof NotPermittedException) { |
|
583 | - // a more general case - due to whatever reason the content could not be written |
|
584 | - throw new Forbidden($e->getMessage(), 0, $e); |
|
585 | - } |
|
586 | - if ($e instanceof ForbiddenException) { |
|
587 | - // the path for the file was forbidden |
|
588 | - throw new DAVForbiddenException($e->getMessage(), $e->getRetry(), $e); |
|
589 | - } |
|
590 | - if ($e instanceof EntityTooLargeException) { |
|
591 | - // the file is too big to be stored |
|
592 | - throw new EntityTooLarge($e->getMessage(), 0, $e); |
|
593 | - } |
|
594 | - if ($e instanceof InvalidContentException) { |
|
595 | - // the file content is not permitted |
|
596 | - throw new UnsupportedMediaType($e->getMessage(), 0, $e); |
|
597 | - } |
|
598 | - if ($e instanceof InvalidPathException) { |
|
599 | - // the path for the file was not valid |
|
600 | - // TODO: find proper http status code for this case |
|
601 | - throw new Forbidden($e->getMessage(), 0, $e); |
|
602 | - } |
|
603 | - if ($e instanceof LockedException || $e instanceof LockNotAcquiredException) { |
|
604 | - // the file is currently being written to by another process |
|
605 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
606 | - } |
|
607 | - if ($e instanceof GenericEncryptionException) { |
|
608 | - // returning 503 will allow retry of the operation at a later point in time |
|
609 | - throw new ServiceUnavailable($this->l10n->t('Encryption not ready: %1$s', [$e->getMessage()]), 0, $e); |
|
610 | - } |
|
611 | - if ($e instanceof StorageNotAvailableException) { |
|
612 | - throw new ServiceUnavailable($this->l10n->t('Failed to write file contents: %1$s', [$e->getMessage()]), 0, $e); |
|
613 | - } |
|
614 | - if ($e instanceof NotFoundException) { |
|
615 | - throw new NotFound($this->l10n->t('File not found: %1$s', [$e->getMessage()]), 0, $e); |
|
616 | - } |
|
617 | - |
|
618 | - throw new \Sabre\DAV\Exception($e->getMessage(), 0, $e); |
|
619 | - } |
|
620 | - |
|
621 | - /** |
|
622 | - * Get the checksum for this file |
|
623 | - * |
|
624 | - * @return string|null |
|
625 | - */ |
|
626 | - public function getChecksum() { |
|
627 | - return $this->info->getChecksum(); |
|
628 | - } |
|
629 | - |
|
630 | - public function setChecksum(string $checksum) { |
|
631 | - $this->fileView->putFileInfo($this->path, ['checksum' => $checksum]); |
|
632 | - $this->refreshInfo(); |
|
633 | - } |
|
634 | - |
|
635 | - protected function header($string) { |
|
636 | - if (!\OC::$CLI) { |
|
637 | - \header($string); |
|
638 | - } |
|
639 | - } |
|
640 | - |
|
641 | - public function hash(string $type) { |
|
642 | - return $this->fileView->hash($type, $this->path); |
|
643 | - } |
|
644 | - |
|
645 | - public function getNode(): \OCP\Files\File { |
|
646 | - return $this->node; |
|
647 | - } |
|
648 | - |
|
649 | - public function getMetadata(string $group): FileMetadata { |
|
650 | - return $this->metadata[$group]; |
|
651 | - } |
|
652 | - |
|
653 | - public function setMetadata(string $group, FileMetadata $metadata): void { |
|
654 | - $this->metadata[$group] = $metadata; |
|
655 | - } |
|
656 | - |
|
657 | - public function hasMetadata(string $group) { |
|
658 | - return array_key_exists($group, $this->metadata); |
|
659 | - } |
|
80 | + protected $request; |
|
81 | + |
|
82 | + protected IL10N $l10n; |
|
83 | + |
|
84 | + /** @var array<string, FileMetadata> */ |
|
85 | + private array $metadata = []; |
|
86 | + |
|
87 | + /** |
|
88 | + * Sets up the node, expects a full path name |
|
89 | + * |
|
90 | + * @param \OC\Files\View $view |
|
91 | + * @param \OCP\Files\FileInfo $info |
|
92 | + * @param \OCP\Share\IManager $shareManager |
|
93 | + * @param \OC\AppFramework\Http\Request $request |
|
94 | + */ |
|
95 | + public function __construct(View $view, FileInfo $info, IManager $shareManager = null, Request $request = null) { |
|
96 | + parent::__construct($view, $info, $shareManager); |
|
97 | + |
|
98 | + // Querying IL10N directly results in a dependency loop |
|
99 | + /** @var IL10NFactory $l10nFactory */ |
|
100 | + $l10nFactory = \OC::$server->get(IL10NFactory::class); |
|
101 | + $this->l10n = $l10nFactory->get(Application::APP_ID); |
|
102 | + |
|
103 | + if (isset($request)) { |
|
104 | + $this->request = $request; |
|
105 | + } else { |
|
106 | + $this->request = \OC::$server->getRequest(); |
|
107 | + } |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Updates the data |
|
112 | + * |
|
113 | + * The data argument is a readable stream resource. |
|
114 | + * |
|
115 | + * After a successful put operation, you may choose to return an ETag. The |
|
116 | + * etag must always be surrounded by double-quotes. These quotes must |
|
117 | + * appear in the actual string you're returning. |
|
118 | + * |
|
119 | + * Clients may use the ETag from a PUT request to later on make sure that |
|
120 | + * when they update the file, the contents haven't changed in the mean |
|
121 | + * time. |
|
122 | + * |
|
123 | + * If you don't plan to store the file byte-by-byte, and you return a |
|
124 | + * different object on a subsequent GET you are strongly recommended to not |
|
125 | + * return an ETag, and just return null. |
|
126 | + * |
|
127 | + * @param resource $data |
|
128 | + * |
|
129 | + * @throws Forbidden |
|
130 | + * @throws UnsupportedMediaType |
|
131 | + * @throws BadRequest |
|
132 | + * @throws Exception |
|
133 | + * @throws EntityTooLarge |
|
134 | + * @throws ServiceUnavailable |
|
135 | + * @throws FileLocked |
|
136 | + * @return string|null |
|
137 | + */ |
|
138 | + public function put($data) { |
|
139 | + try { |
|
140 | + $exists = $this->fileView->file_exists($this->path); |
|
141 | + if ($exists && !$this->info->isUpdateable()) { |
|
142 | + throw new Forbidden(); |
|
143 | + } |
|
144 | + } catch (StorageNotAvailableException $e) { |
|
145 | + throw new ServiceUnavailable($this->l10n->t('File is not updatable: %1$s', [$e->getMessage()])); |
|
146 | + } |
|
147 | + |
|
148 | + // verify path of the target |
|
149 | + $this->verifyPath(); |
|
150 | + |
|
151 | + /** @var Storage $partStorage */ |
|
152 | + [$partStorage] = $this->fileView->resolvePath($this->path); |
|
153 | + $needsPartFile = $partStorage->needsPartFile() && (strlen($this->path) > 1); |
|
154 | + |
|
155 | + $view = \OC\Files\Filesystem::getView(); |
|
156 | + |
|
157 | + if ($needsPartFile) { |
|
158 | + // mark file as partial while uploading (ignored by the scanner) |
|
159 | + $partFilePath = $this->getPartFileBasePath($this->path) . '.ocTransferId' . rand() . '.part'; |
|
160 | + |
|
161 | + if (!$view->isCreatable($partFilePath) && $view->isUpdatable($this->path)) { |
|
162 | + $needsPartFile = false; |
|
163 | + } |
|
164 | + } |
|
165 | + if (!$needsPartFile) { |
|
166 | + // upload file directly as the final path |
|
167 | + $partFilePath = $this->path; |
|
168 | + |
|
169 | + if ($view && !$this->emitPreHooks($exists)) { |
|
170 | + throw new Exception($this->l10n->t('Could not write to final file, canceled by hook')); |
|
171 | + } |
|
172 | + } |
|
173 | + |
|
174 | + // the part file and target file might be on a different storage in case of a single file storage (e.g. single file share) |
|
175 | + /** @var \OC\Files\Storage\Storage $partStorage */ |
|
176 | + [$partStorage, $internalPartPath] = $this->fileView->resolvePath($partFilePath); |
|
177 | + /** @var \OC\Files\Storage\Storage $storage */ |
|
178 | + [$storage, $internalPath] = $this->fileView->resolvePath($this->path); |
|
179 | + try { |
|
180 | + if (!$needsPartFile) { |
|
181 | + try { |
|
182 | + $this->changeLock(ILockingProvider::LOCK_EXCLUSIVE); |
|
183 | + } catch (LockedException $e) { |
|
184 | + // during very large uploads, the shared lock we got at the start might have been expired |
|
185 | + // meaning that the above lock can fail not just only because somebody else got a shared lock |
|
186 | + // or because there is no existing shared lock to make exclusive |
|
187 | + // |
|
188 | + // Thus we try to get a new exclusive lock, if the original lock failed because of a different shared |
|
189 | + // lock this will still fail, if our original shared lock expired the new lock will be successful and |
|
190 | + // the entire operation will be safe |
|
191 | + |
|
192 | + try { |
|
193 | + $this->acquireLock(ILockingProvider::LOCK_EXCLUSIVE); |
|
194 | + } catch (LockedException $ex) { |
|
195 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
196 | + } |
|
197 | + } |
|
198 | + } |
|
199 | + |
|
200 | + if (!is_resource($data)) { |
|
201 | + $tmpData = fopen('php://temp', 'r+'); |
|
202 | + if ($data !== null) { |
|
203 | + fwrite($tmpData, $data); |
|
204 | + rewind($tmpData); |
|
205 | + } |
|
206 | + $data = $tmpData; |
|
207 | + } |
|
208 | + |
|
209 | + if ($this->request->getHeader('X-HASH') !== '') { |
|
210 | + $hash = $this->request->getHeader('X-HASH'); |
|
211 | + if ($hash === 'all' || $hash === 'md5') { |
|
212 | + $data = HashWrapper::wrap($data, 'md5', function ($hash) { |
|
213 | + $this->header('X-Hash-MD5: ' . $hash); |
|
214 | + }); |
|
215 | + } |
|
216 | + |
|
217 | + if ($hash === 'all' || $hash === 'sha1') { |
|
218 | + $data = HashWrapper::wrap($data, 'sha1', function ($hash) { |
|
219 | + $this->header('X-Hash-SHA1: ' . $hash); |
|
220 | + }); |
|
221 | + } |
|
222 | + |
|
223 | + if ($hash === 'all' || $hash === 'sha256') { |
|
224 | + $data = HashWrapper::wrap($data, 'sha256', function ($hash) { |
|
225 | + $this->header('X-Hash-SHA256: ' . $hash); |
|
226 | + }); |
|
227 | + } |
|
228 | + } |
|
229 | + |
|
230 | + if ($partStorage->instanceOfStorage(Storage\IWriteStreamStorage::class)) { |
|
231 | + $isEOF = false; |
|
232 | + $wrappedData = CallbackWrapper::wrap($data, null, null, null, null, function ($stream) use (&$isEOF) { |
|
233 | + $isEOF = feof($stream); |
|
234 | + }); |
|
235 | + |
|
236 | + $result = true; |
|
237 | + $count = -1; |
|
238 | + try { |
|
239 | + $count = $partStorage->writeStream($internalPartPath, $wrappedData); |
|
240 | + } catch (GenericFileException $e) { |
|
241 | + $result = false; |
|
242 | + } catch (BadGateway $e) { |
|
243 | + throw $e; |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + if ($result === false) { |
|
248 | + $result = $isEOF; |
|
249 | + if (is_resource($wrappedData)) { |
|
250 | + $result = feof($wrappedData); |
|
251 | + } |
|
252 | + } |
|
253 | + } else { |
|
254 | + $target = $partStorage->fopen($internalPartPath, 'wb'); |
|
255 | + if ($target === false) { |
|
256 | + \OC::$server->get(LoggerInterface::class)->error('\OC\Files\Filesystem::fopen() failed', ['app' => 'webdav']); |
|
257 | + // because we have no clue about the cause we can only throw back a 500/Internal Server Error |
|
258 | + throw new Exception($this->l10n->t('Could not write file contents')); |
|
259 | + } |
|
260 | + [$count, $result] = \OC_Helper::streamCopy($data, $target); |
|
261 | + fclose($target); |
|
262 | + } |
|
263 | + |
|
264 | + if ($result === false) { |
|
265 | + $expected = -1; |
|
266 | + if (isset($_SERVER['CONTENT_LENGTH'])) { |
|
267 | + $expected = (int)$_SERVER['CONTENT_LENGTH']; |
|
268 | + } |
|
269 | + if ($expected !== 0) { |
|
270 | + throw new Exception( |
|
271 | + $this->l10n->t( |
|
272 | + 'Error while copying file to target location (copied: %1$s, expected filesize: %2$s)', |
|
273 | + [ |
|
274 | + $this->l10n->n('%n byte', '%n bytes', $count), |
|
275 | + $this->l10n->n('%n byte', '%n bytes', $expected), |
|
276 | + ], |
|
277 | + ) |
|
278 | + ); |
|
279 | + } |
|
280 | + } |
|
281 | + |
|
282 | + // if content length is sent by client: |
|
283 | + // double check if the file was fully received |
|
284 | + // compare expected and actual size |
|
285 | + if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['REQUEST_METHOD'] === 'PUT') { |
|
286 | + $expected = (int)$_SERVER['CONTENT_LENGTH']; |
|
287 | + if ($count !== $expected) { |
|
288 | + throw new BadRequest( |
|
289 | + $this->l10n->t( |
|
290 | + 'Expected filesize of %1$s but read (from Nextcloud client) and wrote (to Nextcloud storage) %2$s. Could either be a network problem on the sending side or a problem writing to the storage on the server side.', |
|
291 | + [ |
|
292 | + $this->l10n->n('%n byte', '%n bytes', $expected), |
|
293 | + $this->l10n->n('%n byte', '%n bytes', $count), |
|
294 | + ], |
|
295 | + ) |
|
296 | + ); |
|
297 | + } |
|
298 | + } |
|
299 | + } catch (\Exception $e) { |
|
300 | + if ($e instanceof LockedException) { |
|
301 | + \OC::$server->get(LoggerInterface::class)->debug($e->getMessage(), ['exception' => $e]); |
|
302 | + } else { |
|
303 | + \OC::$server->get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]); |
|
304 | + } |
|
305 | + |
|
306 | + if ($needsPartFile) { |
|
307 | + $partStorage->unlink($internalPartPath); |
|
308 | + } |
|
309 | + $this->convertToSabreException($e); |
|
310 | + } |
|
311 | + |
|
312 | + try { |
|
313 | + if ($needsPartFile) { |
|
314 | + if ($view && !$this->emitPreHooks($exists)) { |
|
315 | + $partStorage->unlink($internalPartPath); |
|
316 | + throw new Exception($this->l10n->t('Could not rename part file to final file, canceled by hook')); |
|
317 | + } |
|
318 | + try { |
|
319 | + $this->changeLock(ILockingProvider::LOCK_EXCLUSIVE); |
|
320 | + } catch (LockedException $e) { |
|
321 | + // during very large uploads, the shared lock we got at the start might have been expired |
|
322 | + // meaning that the above lock can fail not just only because somebody else got a shared lock |
|
323 | + // or because there is no existing shared lock to make exclusive |
|
324 | + // |
|
325 | + // Thus we try to get a new exclusive lock, if the original lock failed because of a different shared |
|
326 | + // lock this will still fail, if our original shared lock expired the new lock will be successful and |
|
327 | + // the entire operation will be safe |
|
328 | + |
|
329 | + try { |
|
330 | + $this->acquireLock(ILockingProvider::LOCK_EXCLUSIVE); |
|
331 | + } catch (LockedException $ex) { |
|
332 | + if ($needsPartFile) { |
|
333 | + $partStorage->unlink($internalPartPath); |
|
334 | + } |
|
335 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
336 | + } |
|
337 | + } |
|
338 | + |
|
339 | + // rename to correct path |
|
340 | + try { |
|
341 | + $renameOkay = $storage->moveFromStorage($partStorage, $internalPartPath, $internalPath); |
|
342 | + $fileExists = $storage->file_exists($internalPath); |
|
343 | + if ($renameOkay === false || $fileExists === false) { |
|
344 | + \OC::$server->get(LoggerInterface::class)->error('renaming part file to final file failed $renameOkay: ' . ($renameOkay ? 'true' : 'false') . ', $fileExists: ' . ($fileExists ? 'true' : 'false') . ')', ['app' => 'webdav']); |
|
345 | + throw new Exception($this->l10n->t('Could not rename part file to final file')); |
|
346 | + } |
|
347 | + } catch (ForbiddenException $ex) { |
|
348 | + if (!$ex->getRetry()) { |
|
349 | + $partStorage->unlink($internalPartPath); |
|
350 | + } |
|
351 | + throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry()); |
|
352 | + } catch (\Exception $e) { |
|
353 | + $partStorage->unlink($internalPartPath); |
|
354 | + $this->convertToSabreException($e); |
|
355 | + } |
|
356 | + } |
|
357 | + |
|
358 | + // since we skipped the view we need to scan and emit the hooks ourselves |
|
359 | + $storage->getUpdater()->update($internalPath); |
|
360 | + |
|
361 | + try { |
|
362 | + $this->changeLock(ILockingProvider::LOCK_SHARED); |
|
363 | + } catch (LockedException $e) { |
|
364 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
365 | + } |
|
366 | + |
|
367 | + // allow sync clients to send the mtime along in a header |
|
368 | + if (isset($this->request->server['HTTP_X_OC_MTIME'])) { |
|
369 | + $mtime = $this->sanitizeMtime($this->request->server['HTTP_X_OC_MTIME']); |
|
370 | + if ($this->fileView->touch($this->path, $mtime)) { |
|
371 | + $this->header('X-OC-MTime: accepted'); |
|
372 | + } |
|
373 | + } |
|
374 | + |
|
375 | + $fileInfoUpdate = [ |
|
376 | + 'upload_time' => time() |
|
377 | + ]; |
|
378 | + |
|
379 | + // allow sync clients to send the creation time along in a header |
|
380 | + if (isset($this->request->server['HTTP_X_OC_CTIME'])) { |
|
381 | + $ctime = $this->sanitizeMtime($this->request->server['HTTP_X_OC_CTIME']); |
|
382 | + $fileInfoUpdate['creation_time'] = $ctime; |
|
383 | + $this->header('X-OC-CTime: accepted'); |
|
384 | + } |
|
385 | + |
|
386 | + $this->fileView->putFileInfo($this->path, $fileInfoUpdate); |
|
387 | + |
|
388 | + if ($view) { |
|
389 | + $this->emitPostHooks($exists); |
|
390 | + } |
|
391 | + |
|
392 | + $this->refreshInfo(); |
|
393 | + |
|
394 | + if (isset($this->request->server['HTTP_OC_CHECKSUM'])) { |
|
395 | + $checksum = trim($this->request->server['HTTP_OC_CHECKSUM']); |
|
396 | + $this->setChecksum($checksum); |
|
397 | + } elseif ($this->getChecksum() !== null && $this->getChecksum() !== '') { |
|
398 | + $this->setChecksum(''); |
|
399 | + } |
|
400 | + } catch (StorageNotAvailableException $e) { |
|
401 | + throw new ServiceUnavailable($this->l10n->t('Failed to check file size: %1$s', [$e->getMessage()]), 0, $e); |
|
402 | + } |
|
403 | + |
|
404 | + return '"' . $this->info->getEtag() . '"'; |
|
405 | + } |
|
406 | + |
|
407 | + private function getPartFileBasePath($path) { |
|
408 | + $partFileInStorage = \OC::$server->getConfig()->getSystemValue('part_file_in_storage', true); |
|
409 | + if ($partFileInStorage) { |
|
410 | + return $path; |
|
411 | + } else { |
|
412 | + return md5($path); // will place it in the root of the view with a unique name |
|
413 | + } |
|
414 | + } |
|
415 | + |
|
416 | + /** |
|
417 | + * @param string $path |
|
418 | + */ |
|
419 | + private function emitPreHooks($exists, $path = null) { |
|
420 | + if (is_null($path)) { |
|
421 | + $path = $this->path; |
|
422 | + } |
|
423 | + $hookPath = Filesystem::getView()->getRelativePath($this->fileView->getAbsolutePath($path)); |
|
424 | + $run = true; |
|
425 | + |
|
426 | + if (!$exists) { |
|
427 | + \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_create, [ |
|
428 | + \OC\Files\Filesystem::signal_param_path => $hookPath, |
|
429 | + \OC\Files\Filesystem::signal_param_run => &$run, |
|
430 | + ]); |
|
431 | + } else { |
|
432 | + \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_update, [ |
|
433 | + \OC\Files\Filesystem::signal_param_path => $hookPath, |
|
434 | + \OC\Files\Filesystem::signal_param_run => &$run, |
|
435 | + ]); |
|
436 | + } |
|
437 | + \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_write, [ |
|
438 | + \OC\Files\Filesystem::signal_param_path => $hookPath, |
|
439 | + \OC\Files\Filesystem::signal_param_run => &$run, |
|
440 | + ]); |
|
441 | + return $run; |
|
442 | + } |
|
443 | + |
|
444 | + /** |
|
445 | + * @param string $path |
|
446 | + */ |
|
447 | + private function emitPostHooks($exists, $path = null) { |
|
448 | + if (is_null($path)) { |
|
449 | + $path = $this->path; |
|
450 | + } |
|
451 | + $hookPath = Filesystem::getView()->getRelativePath($this->fileView->getAbsolutePath($path)); |
|
452 | + if (!$exists) { |
|
453 | + \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_create, [ |
|
454 | + \OC\Files\Filesystem::signal_param_path => $hookPath |
|
455 | + ]); |
|
456 | + } else { |
|
457 | + \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_update, [ |
|
458 | + \OC\Files\Filesystem::signal_param_path => $hookPath |
|
459 | + ]); |
|
460 | + } |
|
461 | + \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_write, [ |
|
462 | + \OC\Files\Filesystem::signal_param_path => $hookPath |
|
463 | + ]); |
|
464 | + } |
|
465 | + |
|
466 | + /** |
|
467 | + * Returns the data |
|
468 | + * |
|
469 | + * @return resource |
|
470 | + * @throws Forbidden |
|
471 | + * @throws ServiceUnavailable |
|
472 | + */ |
|
473 | + public function get() { |
|
474 | + //throw exception if encryption is disabled but files are still encrypted |
|
475 | + try { |
|
476 | + if (!$this->info->isReadable()) { |
|
477 | + // do a if the file did not exist |
|
478 | + throw new NotFound(); |
|
479 | + } |
|
480 | + try { |
|
481 | + $res = $this->fileView->fopen(ltrim($this->path, '/'), 'rb'); |
|
482 | + } catch (\Exception $e) { |
|
483 | + $this->convertToSabreException($e); |
|
484 | + } |
|
485 | + |
|
486 | + if ($res === false) { |
|
487 | + throw new ServiceUnavailable($this->l10n->t('Could not open file')); |
|
488 | + } |
|
489 | + |
|
490 | + // comparing current file size with the one in DB |
|
491 | + // if different, fix DB and refresh cache. |
|
492 | + if ($this->getSize() !== $this->fileView->filesize($this->getPath())) { |
|
493 | + $logger = \OC::$server->get(LoggerInterface::class); |
|
494 | + $logger->warning('fixing cached size of file id=' . $this->getId()); |
|
495 | + |
|
496 | + $this->getFileInfo()->getStorage()->getUpdater()->update($this->getFileInfo()->getInternalPath()); |
|
497 | + $this->refreshInfo(); |
|
498 | + } |
|
499 | + |
|
500 | + return $res; |
|
501 | + } catch (GenericEncryptionException $e) { |
|
502 | + // returning 503 will allow retry of the operation at a later point in time |
|
503 | + throw new ServiceUnavailable($this->l10n->t('Encryption not ready: %1$s', [$e->getMessage()])); |
|
504 | + } catch (StorageNotAvailableException $e) { |
|
505 | + throw new ServiceUnavailable($this->l10n->t('Failed to open file: %1$s', [$e->getMessage()])); |
|
506 | + } catch (ForbiddenException $ex) { |
|
507 | + throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry()); |
|
508 | + } catch (LockedException $e) { |
|
509 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
510 | + } |
|
511 | + } |
|
512 | + |
|
513 | + /** |
|
514 | + * Delete the current file |
|
515 | + * |
|
516 | + * @throws Forbidden |
|
517 | + * @throws ServiceUnavailable |
|
518 | + */ |
|
519 | + public function delete() { |
|
520 | + if (!$this->info->isDeletable()) { |
|
521 | + throw new Forbidden(); |
|
522 | + } |
|
523 | + |
|
524 | + try { |
|
525 | + if (!$this->fileView->unlink($this->path)) { |
|
526 | + // assume it wasn't possible to delete due to permissions |
|
527 | + throw new Forbidden(); |
|
528 | + } |
|
529 | + } catch (StorageNotAvailableException $e) { |
|
530 | + throw new ServiceUnavailable($this->l10n->t('Failed to unlink: %1$s', [$e->getMessage()])); |
|
531 | + } catch (ForbiddenException $ex) { |
|
532 | + throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry()); |
|
533 | + } catch (LockedException $e) { |
|
534 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
535 | + } |
|
536 | + } |
|
537 | + |
|
538 | + /** |
|
539 | + * Returns the mime-type for a file |
|
540 | + * |
|
541 | + * If null is returned, we'll assume application/octet-stream |
|
542 | + * |
|
543 | + * @return string |
|
544 | + */ |
|
545 | + public function getContentType() { |
|
546 | + $mimeType = $this->info->getMimetype(); |
|
547 | + |
|
548 | + // PROPFIND needs to return the correct mime type, for consistency with the web UI |
|
549 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
550 | + return $mimeType; |
|
551 | + } |
|
552 | + return \OC::$server->getMimeTypeDetector()->getSecureMimeType($mimeType); |
|
553 | + } |
|
554 | + |
|
555 | + /** |
|
556 | + * @return array|bool |
|
557 | + */ |
|
558 | + public function getDirectDownload() { |
|
559 | + if (\OCP\Server::get(\OCP\App\IAppManager::class)->isEnabledForUser('encryption')) { |
|
560 | + return []; |
|
561 | + } |
|
562 | + /** @var \OCP\Files\Storage $storage */ |
|
563 | + [$storage, $internalPath] = $this->fileView->resolvePath($this->path); |
|
564 | + if (is_null($storage)) { |
|
565 | + return []; |
|
566 | + } |
|
567 | + |
|
568 | + return $storage->getDirectDownload($internalPath); |
|
569 | + } |
|
570 | + |
|
571 | + /** |
|
572 | + * Convert the given exception to a SabreException instance |
|
573 | + * |
|
574 | + * @param \Exception $e |
|
575 | + * |
|
576 | + * @throws \Sabre\DAV\Exception |
|
577 | + */ |
|
578 | + private function convertToSabreException(\Exception $e) { |
|
579 | + if ($e instanceof \Sabre\DAV\Exception) { |
|
580 | + throw $e; |
|
581 | + } |
|
582 | + if ($e instanceof NotPermittedException) { |
|
583 | + // a more general case - due to whatever reason the content could not be written |
|
584 | + throw new Forbidden($e->getMessage(), 0, $e); |
|
585 | + } |
|
586 | + if ($e instanceof ForbiddenException) { |
|
587 | + // the path for the file was forbidden |
|
588 | + throw new DAVForbiddenException($e->getMessage(), $e->getRetry(), $e); |
|
589 | + } |
|
590 | + if ($e instanceof EntityTooLargeException) { |
|
591 | + // the file is too big to be stored |
|
592 | + throw new EntityTooLarge($e->getMessage(), 0, $e); |
|
593 | + } |
|
594 | + if ($e instanceof InvalidContentException) { |
|
595 | + // the file content is not permitted |
|
596 | + throw new UnsupportedMediaType($e->getMessage(), 0, $e); |
|
597 | + } |
|
598 | + if ($e instanceof InvalidPathException) { |
|
599 | + // the path for the file was not valid |
|
600 | + // TODO: find proper http status code for this case |
|
601 | + throw new Forbidden($e->getMessage(), 0, $e); |
|
602 | + } |
|
603 | + if ($e instanceof LockedException || $e instanceof LockNotAcquiredException) { |
|
604 | + // the file is currently being written to by another process |
|
605 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
606 | + } |
|
607 | + if ($e instanceof GenericEncryptionException) { |
|
608 | + // returning 503 will allow retry of the operation at a later point in time |
|
609 | + throw new ServiceUnavailable($this->l10n->t('Encryption not ready: %1$s', [$e->getMessage()]), 0, $e); |
|
610 | + } |
|
611 | + if ($e instanceof StorageNotAvailableException) { |
|
612 | + throw new ServiceUnavailable($this->l10n->t('Failed to write file contents: %1$s', [$e->getMessage()]), 0, $e); |
|
613 | + } |
|
614 | + if ($e instanceof NotFoundException) { |
|
615 | + throw new NotFound($this->l10n->t('File not found: %1$s', [$e->getMessage()]), 0, $e); |
|
616 | + } |
|
617 | + |
|
618 | + throw new \Sabre\DAV\Exception($e->getMessage(), 0, $e); |
|
619 | + } |
|
620 | + |
|
621 | + /** |
|
622 | + * Get the checksum for this file |
|
623 | + * |
|
624 | + * @return string|null |
|
625 | + */ |
|
626 | + public function getChecksum() { |
|
627 | + return $this->info->getChecksum(); |
|
628 | + } |
|
629 | + |
|
630 | + public function setChecksum(string $checksum) { |
|
631 | + $this->fileView->putFileInfo($this->path, ['checksum' => $checksum]); |
|
632 | + $this->refreshInfo(); |
|
633 | + } |
|
634 | + |
|
635 | + protected function header($string) { |
|
636 | + if (!\OC::$CLI) { |
|
637 | + \header($string); |
|
638 | + } |
|
639 | + } |
|
640 | + |
|
641 | + public function hash(string $type) { |
|
642 | + return $this->fileView->hash($type, $this->path); |
|
643 | + } |
|
644 | + |
|
645 | + public function getNode(): \OCP\Files\File { |
|
646 | + return $this->node; |
|
647 | + } |
|
648 | + |
|
649 | + public function getMetadata(string $group): FileMetadata { |
|
650 | + return $this->metadata[$group]; |
|
651 | + } |
|
652 | + |
|
653 | + public function setMetadata(string $group, FileMetadata $metadata): void { |
|
654 | + $this->metadata[$group] = $metadata; |
|
655 | + } |
|
656 | + |
|
657 | + public function hasMetadata(string $group) { |
|
658 | + return array_key_exists($group, $this->metadata); |
|
659 | + } |
|
660 | 660 | } |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | |
157 | 157 | if ($needsPartFile) { |
158 | 158 | // mark file as partial while uploading (ignored by the scanner) |
159 | - $partFilePath = $this->getPartFileBasePath($this->path) . '.ocTransferId' . rand() . '.part'; |
|
159 | + $partFilePath = $this->getPartFileBasePath($this->path).'.ocTransferId'.rand().'.part'; |
|
160 | 160 | |
161 | 161 | if (!$view->isCreatable($partFilePath) && $view->isUpdatable($this->path)) { |
162 | 162 | $needsPartFile = false; |
@@ -209,27 +209,27 @@ discard block |
||
209 | 209 | if ($this->request->getHeader('X-HASH') !== '') { |
210 | 210 | $hash = $this->request->getHeader('X-HASH'); |
211 | 211 | if ($hash === 'all' || $hash === 'md5') { |
212 | - $data = HashWrapper::wrap($data, 'md5', function ($hash) { |
|
213 | - $this->header('X-Hash-MD5: ' . $hash); |
|
212 | + $data = HashWrapper::wrap($data, 'md5', function($hash) { |
|
213 | + $this->header('X-Hash-MD5: '.$hash); |
|
214 | 214 | }); |
215 | 215 | } |
216 | 216 | |
217 | 217 | if ($hash === 'all' || $hash === 'sha1') { |
218 | - $data = HashWrapper::wrap($data, 'sha1', function ($hash) { |
|
219 | - $this->header('X-Hash-SHA1: ' . $hash); |
|
218 | + $data = HashWrapper::wrap($data, 'sha1', function($hash) { |
|
219 | + $this->header('X-Hash-SHA1: '.$hash); |
|
220 | 220 | }); |
221 | 221 | } |
222 | 222 | |
223 | 223 | if ($hash === 'all' || $hash === 'sha256') { |
224 | - $data = HashWrapper::wrap($data, 'sha256', function ($hash) { |
|
225 | - $this->header('X-Hash-SHA256: ' . $hash); |
|
224 | + $data = HashWrapper::wrap($data, 'sha256', function($hash) { |
|
225 | + $this->header('X-Hash-SHA256: '.$hash); |
|
226 | 226 | }); |
227 | 227 | } |
228 | 228 | } |
229 | 229 | |
230 | 230 | if ($partStorage->instanceOfStorage(Storage\IWriteStreamStorage::class)) { |
231 | 231 | $isEOF = false; |
232 | - $wrappedData = CallbackWrapper::wrap($data, null, null, null, null, function ($stream) use (&$isEOF) { |
|
232 | + $wrappedData = CallbackWrapper::wrap($data, null, null, null, null, function($stream) use (&$isEOF) { |
|
233 | 233 | $isEOF = feof($stream); |
234 | 234 | }); |
235 | 235 | |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | if ($result === false) { |
265 | 265 | $expected = -1; |
266 | 266 | if (isset($_SERVER['CONTENT_LENGTH'])) { |
267 | - $expected = (int)$_SERVER['CONTENT_LENGTH']; |
|
267 | + $expected = (int) $_SERVER['CONTENT_LENGTH']; |
|
268 | 268 | } |
269 | 269 | if ($expected !== 0) { |
270 | 270 | throw new Exception( |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | // double check if the file was fully received |
284 | 284 | // compare expected and actual size |
285 | 285 | if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['REQUEST_METHOD'] === 'PUT') { |
286 | - $expected = (int)$_SERVER['CONTENT_LENGTH']; |
|
286 | + $expected = (int) $_SERVER['CONTENT_LENGTH']; |
|
287 | 287 | if ($count !== $expected) { |
288 | 288 | throw new BadRequest( |
289 | 289 | $this->l10n->t( |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | $renameOkay = $storage->moveFromStorage($partStorage, $internalPartPath, $internalPath); |
342 | 342 | $fileExists = $storage->file_exists($internalPath); |
343 | 343 | if ($renameOkay === false || $fileExists === false) { |
344 | - \OC::$server->get(LoggerInterface::class)->error('renaming part file to final file failed $renameOkay: ' . ($renameOkay ? 'true' : 'false') . ', $fileExists: ' . ($fileExists ? 'true' : 'false') . ')', ['app' => 'webdav']); |
|
344 | + \OC::$server->get(LoggerInterface::class)->error('renaming part file to final file failed $renameOkay: '.($renameOkay ? 'true' : 'false').', $fileExists: '.($fileExists ? 'true' : 'false').')', ['app' => 'webdav']); |
|
345 | 345 | throw new Exception($this->l10n->t('Could not rename part file to final file')); |
346 | 346 | } |
347 | 347 | } catch (ForbiddenException $ex) { |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | throw new ServiceUnavailable($this->l10n->t('Failed to check file size: %1$s', [$e->getMessage()]), 0, $e); |
402 | 402 | } |
403 | 403 | |
404 | - return '"' . $this->info->getEtag() . '"'; |
|
404 | + return '"'.$this->info->getEtag().'"'; |
|
405 | 405 | } |
406 | 406 | |
407 | 407 | private function getPartFileBasePath($path) { |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | // if different, fix DB and refresh cache. |
492 | 492 | if ($this->getSize() !== $this->fileView->filesize($this->getPath())) { |
493 | 493 | $logger = \OC::$server->get(LoggerInterface::class); |
494 | - $logger->warning('fixing cached size of file id=' . $this->getId()); |
|
494 | + $logger->warning('fixing cached size of file id='.$this->getId()); |
|
495 | 495 | |
496 | 496 | $this->getFileInfo()->getStorage()->getUpdater()->update($this->getFileInfo()->getInternalPath()); |
497 | 497 | $this->refreshInfo(); |
@@ -55,538 +55,538 @@ |
||
55 | 55 | use Sabre\HTTP\ResponseInterface; |
56 | 56 | |
57 | 57 | class FilesPlugin extends ServerPlugin { |
58 | - // namespace |
|
59 | - public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
60 | - public const NS_NEXTCLOUD = 'http://nextcloud.org/ns'; |
|
61 | - public const FILEID_PROPERTYNAME = '{http://owncloud.org/ns}id'; |
|
62 | - public const INTERNAL_FILEID_PROPERTYNAME = '{http://owncloud.org/ns}fileid'; |
|
63 | - public const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions'; |
|
64 | - public const SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-collaboration-services.org/ns}share-permissions'; |
|
65 | - public const OCM_SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-cloud-mesh.org/ns}share-permissions'; |
|
66 | - public const SHARE_ATTRIBUTES_PROPERTYNAME = '{http://nextcloud.org/ns}share-attributes'; |
|
67 | - public const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL'; |
|
68 | - public const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size'; |
|
69 | - public const GETETAG_PROPERTYNAME = '{DAV:}getetag'; |
|
70 | - public const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified'; |
|
71 | - public const CREATIONDATE_PROPERTYNAME = '{DAV:}creationdate'; |
|
72 | - public const DISPLAYNAME_PROPERTYNAME = '{DAV:}displayname'; |
|
73 | - public const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id'; |
|
74 | - public const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name'; |
|
75 | - public const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums'; |
|
76 | - public const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint'; |
|
77 | - public const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview'; |
|
78 | - public const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type'; |
|
79 | - public const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted'; |
|
80 | - public const METADATA_ETAG_PROPERTYNAME = '{http://nextcloud.org/ns}metadata_etag'; |
|
81 | - public const UPLOAD_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}upload_time'; |
|
82 | - public const CREATION_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}creation_time'; |
|
83 | - public const SHARE_NOTE = '{http://nextcloud.org/ns}note'; |
|
84 | - public const SUBFOLDER_COUNT_PROPERTYNAME = '{http://nextcloud.org/ns}contained-folder-count'; |
|
85 | - public const SUBFILE_COUNT_PROPERTYNAME = '{http://nextcloud.org/ns}contained-file-count'; |
|
86 | - public const FILE_METADATA_SIZE = '{http://nextcloud.org/ns}file-metadata-size'; |
|
87 | - |
|
88 | - /** Reference to main server object */ |
|
89 | - private ?Server $server = null; |
|
90 | - private Tree $tree; |
|
91 | - private IUserSession $userSession; |
|
92 | - |
|
93 | - /** |
|
94 | - * Whether this is public webdav. |
|
95 | - * If true, some returned information will be stripped off. |
|
96 | - */ |
|
97 | - private bool $isPublic; |
|
98 | - private bool $downloadAttachment; |
|
99 | - private IConfig $config; |
|
100 | - private IRequest $request; |
|
101 | - private IPreview $previewManager; |
|
102 | - |
|
103 | - public function __construct(Tree $tree, |
|
104 | - IConfig $config, |
|
105 | - IRequest $request, |
|
106 | - IPreview $previewManager, |
|
107 | - IUserSession $userSession, |
|
108 | - bool $isPublic = false, |
|
109 | - bool $downloadAttachment = true) { |
|
110 | - $this->tree = $tree; |
|
111 | - $this->config = $config; |
|
112 | - $this->request = $request; |
|
113 | - $this->userSession = $userSession; |
|
114 | - $this->isPublic = $isPublic; |
|
115 | - $this->downloadAttachment = $downloadAttachment; |
|
116 | - $this->previewManager = $previewManager; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * This initializes the plugin. |
|
121 | - * |
|
122 | - * This function is called by \Sabre\DAV\Server, after |
|
123 | - * addPlugin is called. |
|
124 | - * |
|
125 | - * This method should set up the required event subscriptions. |
|
126 | - * |
|
127 | - * @return void |
|
128 | - */ |
|
129 | - public function initialize(Server $server) { |
|
130 | - $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
131 | - $server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc'; |
|
132 | - $server->protectedProperties[] = self::FILEID_PROPERTYNAME; |
|
133 | - $server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME; |
|
134 | - $server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME; |
|
135 | - $server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME; |
|
136 | - $server->protectedProperties[] = self::OCM_SHARE_PERMISSIONS_PROPERTYNAME; |
|
137 | - $server->protectedProperties[] = self::SHARE_ATTRIBUTES_PROPERTYNAME; |
|
138 | - $server->protectedProperties[] = self::SIZE_PROPERTYNAME; |
|
139 | - $server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME; |
|
140 | - $server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME; |
|
141 | - $server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME; |
|
142 | - $server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME; |
|
143 | - $server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME; |
|
144 | - $server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME; |
|
145 | - $server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME; |
|
146 | - $server->protectedProperties[] = self::IS_ENCRYPTED_PROPERTYNAME; |
|
147 | - $server->protectedProperties[] = self::SHARE_NOTE; |
|
148 | - |
|
149 | - // normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH |
|
150 | - $allowedProperties = ['{DAV:}getetag']; |
|
151 | - $server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties); |
|
152 | - |
|
153 | - $this->server = $server; |
|
154 | - $this->server->on('propFind', [$this, 'handleGetProperties']); |
|
155 | - $this->server->on('propPatch', [$this, 'handleUpdateProperties']); |
|
156 | - $this->server->on('afterBind', [$this, 'sendFileIdHeader']); |
|
157 | - $this->server->on('afterWriteContent', [$this, 'sendFileIdHeader']); |
|
158 | - $this->server->on('afterMethod:GET', [$this,'httpGet']); |
|
159 | - $this->server->on('afterMethod:GET', [$this, 'handleDownloadToken']); |
|
160 | - $this->server->on('afterResponse', function ($request, ResponseInterface $response) { |
|
161 | - $body = $response->getBody(); |
|
162 | - if (is_resource($body)) { |
|
163 | - fclose($body); |
|
164 | - } |
|
165 | - }); |
|
166 | - $this->server->on('beforeMove', [$this, 'checkMove']); |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Plugin that checks if a move can actually be performed. |
|
171 | - * |
|
172 | - * @param string $source source path |
|
173 | - * @param string $destination destination path |
|
174 | - * @throws Forbidden |
|
175 | - * @throws NotFound |
|
176 | - */ |
|
177 | - public function checkMove($source, $destination) { |
|
178 | - $sourceNode = $this->tree->getNodeForPath($source); |
|
179 | - if (!$sourceNode instanceof Node) { |
|
180 | - return; |
|
181 | - } |
|
182 | - [$sourceDir,] = \Sabre\Uri\split($source); |
|
183 | - [$destinationDir,] = \Sabre\Uri\split($destination); |
|
184 | - |
|
185 | - if ($sourceDir !== $destinationDir) { |
|
186 | - $sourceNodeFileInfo = $sourceNode->getFileInfo(); |
|
187 | - if ($sourceNodeFileInfo === null) { |
|
188 | - throw new NotFound($source . ' does not exist'); |
|
189 | - } |
|
190 | - |
|
191 | - if (!$sourceNodeFileInfo->isDeletable()) { |
|
192 | - throw new Forbidden($source . " cannot be deleted"); |
|
193 | - } |
|
194 | - } |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * This sets a cookie to be able to recognize the start of the download |
|
199 | - * the content must not be longer than 32 characters and must only contain |
|
200 | - * alphanumeric characters |
|
201 | - * |
|
202 | - * @param RequestInterface $request |
|
203 | - * @param ResponseInterface $response |
|
204 | - */ |
|
205 | - public function handleDownloadToken(RequestInterface $request, ResponseInterface $response) { |
|
206 | - $queryParams = $request->getQueryParameters(); |
|
207 | - |
|
208 | - /** |
|
209 | - * this sets a cookie to be able to recognize the start of the download |
|
210 | - * the content must not be longer than 32 characters and must only contain |
|
211 | - * alphanumeric characters |
|
212 | - */ |
|
213 | - if (isset($queryParams['downloadStartSecret'])) { |
|
214 | - $token = $queryParams['downloadStartSecret']; |
|
215 | - if (!isset($token[32]) |
|
216 | - && preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) { |
|
217 | - // FIXME: use $response->setHeader() instead |
|
218 | - setcookie('ocDownloadStarted', $token, time() + 20, '/'); |
|
219 | - } |
|
220 | - } |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Add headers to file download |
|
225 | - * |
|
226 | - * @param RequestInterface $request |
|
227 | - * @param ResponseInterface $response |
|
228 | - */ |
|
229 | - public function httpGet(RequestInterface $request, ResponseInterface $response) { |
|
230 | - // Only handle valid files |
|
231 | - $node = $this->tree->getNodeForPath($request->getPath()); |
|
232 | - if (!($node instanceof IFile)) { |
|
233 | - return; |
|
234 | - } |
|
235 | - |
|
236 | - // adds a 'Content-Disposition: attachment' header in case no disposition |
|
237 | - // header has been set before |
|
238 | - if ($this->downloadAttachment && |
|
239 | - $response->getHeader('Content-Disposition') === null) { |
|
240 | - $filename = $node->getName(); |
|
241 | - if ($this->request->isUserAgent( |
|
242 | - [ |
|
243 | - Request::USER_AGENT_IE, |
|
244 | - Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
|
245 | - Request::USER_AGENT_FREEBOX, |
|
246 | - ])) { |
|
247 | - $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"'); |
|
248 | - } else { |
|
249 | - $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename) |
|
250 | - . '; filename="' . rawurlencode($filename) . '"'); |
|
251 | - } |
|
252 | - } |
|
253 | - |
|
254 | - if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
255 | - //Add OC-Checksum header |
|
256 | - $checksum = $node->getChecksum(); |
|
257 | - if ($checksum !== null && $checksum !== '') { |
|
258 | - $response->addHeader('OC-Checksum', $checksum); |
|
259 | - } |
|
260 | - } |
|
261 | - $response->addHeader('X-Accel-Buffering', 'no'); |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Adds all ownCloud-specific properties |
|
266 | - * |
|
267 | - * @param PropFind $propFind |
|
268 | - * @param \Sabre\DAV\INode $node |
|
269 | - * @return void |
|
270 | - */ |
|
271 | - public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) { |
|
272 | - $httpRequest = $this->server->httpRequest; |
|
273 | - |
|
274 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
275 | - /** |
|
276 | - * This was disabled, because it made dir listing throw an exception, |
|
277 | - * so users were unable to navigate into folders where one subitem |
|
278 | - * is blocked by the files_accesscontrol app, see: |
|
279 | - * https://github.com/nextcloud/files_accesscontrol/issues/65 |
|
280 | - * if (!$node->getFileInfo()->isReadable()) { |
|
281 | - * // avoid detecting files through this means |
|
282 | - * throw new NotFound(); |
|
283 | - * } |
|
284 | - */ |
|
285 | - |
|
286 | - $propFind->handle(self::FILEID_PROPERTYNAME, function () use ($node) { |
|
287 | - return $node->getFileId(); |
|
288 | - }); |
|
289 | - |
|
290 | - $propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function () use ($node) { |
|
291 | - return $node->getInternalFileId(); |
|
292 | - }); |
|
293 | - |
|
294 | - $propFind->handle(self::PERMISSIONS_PROPERTYNAME, function () use ($node) { |
|
295 | - $perms = $node->getDavPermissions(); |
|
296 | - if ($this->isPublic) { |
|
297 | - // remove mount information |
|
298 | - $perms = str_replace(['S', 'M'], '', $perms); |
|
299 | - } |
|
300 | - return $perms; |
|
301 | - }); |
|
302 | - |
|
303 | - $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function () use ($node, $httpRequest) { |
|
304 | - $user = $this->userSession->getUser(); |
|
305 | - if ($user === null) { |
|
306 | - return null; |
|
307 | - } |
|
308 | - return $node->getSharePermissions( |
|
309 | - $user->getUID() |
|
310 | - ); |
|
311 | - }); |
|
312 | - |
|
313 | - $propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function () use ($node, $httpRequest): ?string { |
|
314 | - $user = $this->userSession->getUser(); |
|
315 | - if ($user === null) { |
|
316 | - return null; |
|
317 | - } |
|
318 | - $ncPermissions = $node->getSharePermissions( |
|
319 | - $user->getUID() |
|
320 | - ); |
|
321 | - $ocmPermissions = $this->ncPermissions2ocmPermissions($ncPermissions); |
|
322 | - return json_encode($ocmPermissions, JSON_THROW_ON_ERROR); |
|
323 | - }); |
|
324 | - |
|
325 | - $propFind->handle(self::SHARE_ATTRIBUTES_PROPERTYNAME, function () use ($node, $httpRequest) { |
|
326 | - return json_encode($node->getShareAttributes(), JSON_THROW_ON_ERROR); |
|
327 | - }); |
|
328 | - |
|
329 | - $propFind->handle(self::GETETAG_PROPERTYNAME, function () use ($node): string { |
|
330 | - return $node->getETag(); |
|
331 | - }); |
|
332 | - |
|
333 | - $propFind->handle(self::OWNER_ID_PROPERTYNAME, function () use ($node): ?string { |
|
334 | - $owner = $node->getOwner(); |
|
335 | - if (!$owner) { |
|
336 | - return null; |
|
337 | - } else { |
|
338 | - return $owner->getUID(); |
|
339 | - } |
|
340 | - }); |
|
341 | - $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function () use ($node): ?string { |
|
342 | - $owner = $node->getOwner(); |
|
343 | - if (!$owner) { |
|
344 | - return null; |
|
345 | - } else { |
|
346 | - return $owner->getDisplayName(); |
|
347 | - } |
|
348 | - }); |
|
349 | - |
|
350 | - $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { |
|
351 | - return json_encode($this->previewManager->isAvailable($node->getFileInfo()), JSON_THROW_ON_ERROR); |
|
352 | - }); |
|
353 | - $propFind->handle(self::SIZE_PROPERTYNAME, function () use ($node): int|float { |
|
354 | - return $node->getSize(); |
|
355 | - }); |
|
356 | - $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { |
|
357 | - return $node->getFileInfo()->getMountPoint()->getMountType(); |
|
358 | - }); |
|
359 | - |
|
360 | - $propFind->handle(self::SHARE_NOTE, function () use ($node, $httpRequest): ?string { |
|
361 | - $user = $this->userSession->getUser(); |
|
362 | - if ($user === null) { |
|
363 | - return null; |
|
364 | - } |
|
365 | - return $node->getNoteFromShare( |
|
366 | - $user->getUID() |
|
367 | - ); |
|
368 | - }); |
|
369 | - |
|
370 | - $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function () use ($node) { |
|
371 | - return $this->config->getSystemValue('data-fingerprint', ''); |
|
372 | - }); |
|
373 | - $propFind->handle(self::CREATIONDATE_PROPERTYNAME, function () use ($node) { |
|
374 | - return (new \DateTimeImmutable()) |
|
375 | - ->setTimestamp($node->getFileInfo()->getCreationTime()) |
|
376 | - ->format(\DateTimeInterface::ATOM); |
|
377 | - }); |
|
378 | - $propFind->handle(self::CREATION_TIME_PROPERTYNAME, function () use ($node) { |
|
379 | - return $node->getFileInfo()->getCreationTime(); |
|
380 | - }); |
|
381 | - /** |
|
382 | - * Return file/folder name as displayname. The primary reason to |
|
383 | - * implement it this way is to avoid costly fallback to |
|
384 | - * CustomPropertiesBackend (esp. visible when querying all files |
|
385 | - * in a folder). |
|
386 | - */ |
|
387 | - $propFind->handle(self::DISPLAYNAME_PROPERTYNAME, function () use ($node) { |
|
388 | - return $node->getName(); |
|
389 | - }); |
|
390 | - } |
|
391 | - |
|
392 | - if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
393 | - $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function () use ($node) { |
|
394 | - try { |
|
395 | - $directDownloadUrl = $node->getDirectDownload(); |
|
396 | - if (isset($directDownloadUrl['url'])) { |
|
397 | - return $directDownloadUrl['url']; |
|
398 | - } |
|
399 | - } catch (StorageNotAvailableException $e) { |
|
400 | - return false; |
|
401 | - } catch (ForbiddenException $e) { |
|
402 | - return false; |
|
403 | - } |
|
404 | - return false; |
|
405 | - }); |
|
406 | - |
|
407 | - $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function () use ($node) { |
|
408 | - $checksum = $node->getChecksum(); |
|
409 | - if ($checksum === null || $checksum === '') { |
|
410 | - return null; |
|
411 | - } |
|
412 | - |
|
413 | - return new ChecksumList($checksum); |
|
414 | - }); |
|
415 | - |
|
416 | - $propFind->handle(self::UPLOAD_TIME_PROPERTYNAME, function () use ($node) { |
|
417 | - return $node->getFileInfo()->getUploadTime(); |
|
418 | - }); |
|
419 | - |
|
420 | - if ($this->config->getSystemValueBool('enable_file_metadata', true)) { |
|
421 | - $propFind->handle(self::FILE_METADATA_SIZE, function () use ($node) { |
|
422 | - if (!str_starts_with($node->getFileInfo()->getMimetype(), 'image')) { |
|
423 | - return json_encode((object)[], JSON_THROW_ON_ERROR); |
|
424 | - } |
|
425 | - |
|
426 | - if ($node->hasMetadata('size')) { |
|
427 | - $sizeMetadata = $node->getMetadata('size'); |
|
428 | - } else { |
|
429 | - // This code path should not be called since we try to preload |
|
430 | - // the metadata when loading the folder or the search results |
|
431 | - // in one go |
|
432 | - $metadataManager = \OC::$server->get(IMetadataManager::class); |
|
433 | - $sizeMetadata = $metadataManager->fetchMetadataFor('size', [$node->getId()])[$node->getId()]; |
|
434 | - |
|
435 | - // TODO would be nice to display this in the profiler... |
|
436 | - \OC::$server->get(LoggerInterface::class)->debug('Inefficient fetching of metadata'); |
|
437 | - } |
|
438 | - |
|
439 | - return json_encode((object)$sizeMetadata->getMetadata(), JSON_THROW_ON_ERROR); |
|
440 | - }); |
|
441 | - } |
|
442 | - } |
|
443 | - |
|
444 | - if ($node instanceof Directory) { |
|
445 | - $propFind->handle(self::SIZE_PROPERTYNAME, function () use ($node) { |
|
446 | - return $node->getSize(); |
|
447 | - }); |
|
448 | - |
|
449 | - $propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function () use ($node) { |
|
450 | - return $node->getFileInfo()->isEncrypted() ? '1' : '0'; |
|
451 | - }); |
|
452 | - |
|
453 | - $requestProperties = $propFind->getRequestedProperties(); |
|
454 | - |
|
455 | - // TODO detect dynamically which metadata groups are requested and |
|
456 | - // preload all of them and not just size |
|
457 | - if ($this->config->getSystemValueBool('enable_file_metadata', true) |
|
458 | - && in_array(self::FILE_METADATA_SIZE, $requestProperties, true)) { |
|
459 | - // Preloading of the metadata |
|
460 | - $fileIds = []; |
|
461 | - foreach ($node->getChildren() as $child) { |
|
462 | - /** @var \OCP\Files\Node|Node $child */ |
|
463 | - if (str_starts_with($child->getFileInfo()->getMimeType(), 'image/')) { |
|
464 | - /** @var File $child */ |
|
465 | - $fileIds[] = $child->getFileInfo()->getId(); |
|
466 | - } |
|
467 | - } |
|
468 | - /** @var IMetaDataManager $metadataManager */ |
|
469 | - $metadataManager = \OC::$server->get(IMetadataManager::class); |
|
470 | - $preloadedMetadata = $metadataManager->fetchMetadataFor('size', $fileIds); |
|
471 | - foreach ($node->getChildren() as $child) { |
|
472 | - /** @var \OCP\Files\Node|Node $child */ |
|
473 | - if (str_starts_with($child->getFileInfo()->getMimeType(), 'image')) { |
|
474 | - /** @var File $child */ |
|
475 | - $child->setMetadata('size', $preloadedMetadata[$child->getFileInfo()->getId()]); |
|
476 | - } |
|
477 | - } |
|
478 | - } |
|
479 | - |
|
480 | - if (in_array(self::SUBFILE_COUNT_PROPERTYNAME, $requestProperties, true) |
|
481 | - || in_array(self::SUBFOLDER_COUNT_PROPERTYNAME, $requestProperties, true)) { |
|
482 | - $nbFiles = 0; |
|
483 | - $nbFolders = 0; |
|
484 | - foreach ($node->getChildren() as $child) { |
|
485 | - if ($child instanceof File) { |
|
486 | - $nbFiles++; |
|
487 | - } elseif ($child instanceof Directory) { |
|
488 | - $nbFolders++; |
|
489 | - } |
|
490 | - } |
|
491 | - |
|
492 | - $propFind->handle(self::SUBFILE_COUNT_PROPERTYNAME, $nbFiles); |
|
493 | - $propFind->handle(self::SUBFOLDER_COUNT_PROPERTYNAME, $nbFolders); |
|
494 | - } |
|
495 | - } |
|
496 | - } |
|
497 | - |
|
498 | - /** |
|
499 | - * translate Nextcloud permissions to OCM Permissions |
|
500 | - * |
|
501 | - * @param $ncPermissions |
|
502 | - * @return array |
|
503 | - */ |
|
504 | - protected function ncPermissions2ocmPermissions($ncPermissions) { |
|
505 | - $ocmPermissions = []; |
|
506 | - |
|
507 | - if ($ncPermissions & Constants::PERMISSION_SHARE) { |
|
508 | - $ocmPermissions[] = 'share'; |
|
509 | - } |
|
510 | - |
|
511 | - if ($ncPermissions & Constants::PERMISSION_READ) { |
|
512 | - $ocmPermissions[] = 'read'; |
|
513 | - } |
|
514 | - |
|
515 | - if (($ncPermissions & Constants::PERMISSION_CREATE) || |
|
516 | - ($ncPermissions & Constants::PERMISSION_UPDATE)) { |
|
517 | - $ocmPermissions[] = 'write'; |
|
518 | - } |
|
519 | - |
|
520 | - return $ocmPermissions; |
|
521 | - } |
|
522 | - |
|
523 | - /** |
|
524 | - * Update ownCloud-specific properties |
|
525 | - * |
|
526 | - * @param string $path |
|
527 | - * @param PropPatch $propPatch |
|
528 | - * |
|
529 | - * @return void |
|
530 | - */ |
|
531 | - public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
532 | - $node = $this->tree->getNodeForPath($path); |
|
533 | - if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
534 | - return; |
|
535 | - } |
|
536 | - |
|
537 | - $propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function ($time) use ($node) { |
|
538 | - if (empty($time)) { |
|
539 | - return false; |
|
540 | - } |
|
541 | - $node->touch($time); |
|
542 | - return true; |
|
543 | - }); |
|
544 | - $propPatch->handle(self::GETETAG_PROPERTYNAME, function ($etag) use ($node) { |
|
545 | - if (empty($etag)) { |
|
546 | - return false; |
|
547 | - } |
|
548 | - return $node->setEtag($etag) !== -1; |
|
549 | - }); |
|
550 | - $propPatch->handle(self::CREATIONDATE_PROPERTYNAME, function ($time) use ($node) { |
|
551 | - if (empty($time)) { |
|
552 | - return false; |
|
553 | - } |
|
554 | - $dateTime = new \DateTimeImmutable($time); |
|
555 | - $node->setCreationTime($dateTime->getTimestamp()); |
|
556 | - return true; |
|
557 | - }); |
|
558 | - $propPatch->handle(self::CREATION_TIME_PROPERTYNAME, function ($time) use ($node) { |
|
559 | - if (empty($time)) { |
|
560 | - return false; |
|
561 | - } |
|
562 | - $node->setCreationTime((int) $time); |
|
563 | - return true; |
|
564 | - }); |
|
565 | - /** |
|
566 | - * Disable modification of the displayname property for files and |
|
567 | - * folders via PROPPATCH. See PROPFIND for more information. |
|
568 | - */ |
|
569 | - $propPatch->handle(self::DISPLAYNAME_PROPERTYNAME, function ($displayName) { |
|
570 | - return 403; |
|
571 | - }); |
|
572 | - } |
|
573 | - |
|
574 | - /** |
|
575 | - * @param string $filePath |
|
576 | - * @param \Sabre\DAV\INode $node |
|
577 | - * @throws \Sabre\DAV\Exception\BadRequest |
|
578 | - */ |
|
579 | - public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) { |
|
580 | - // we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder |
|
581 | - if (!$this->server->tree->nodeExists($filePath)) { |
|
582 | - return; |
|
583 | - } |
|
584 | - $node = $this->server->tree->getNodeForPath($filePath); |
|
585 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
586 | - $fileId = $node->getFileId(); |
|
587 | - if (!is_null($fileId)) { |
|
588 | - $this->server->httpResponse->setHeader('OC-FileId', $fileId); |
|
589 | - } |
|
590 | - } |
|
591 | - } |
|
58 | + // namespace |
|
59 | + public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
60 | + public const NS_NEXTCLOUD = 'http://nextcloud.org/ns'; |
|
61 | + public const FILEID_PROPERTYNAME = '{http://owncloud.org/ns}id'; |
|
62 | + public const INTERNAL_FILEID_PROPERTYNAME = '{http://owncloud.org/ns}fileid'; |
|
63 | + public const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions'; |
|
64 | + public const SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-collaboration-services.org/ns}share-permissions'; |
|
65 | + public const OCM_SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-cloud-mesh.org/ns}share-permissions'; |
|
66 | + public const SHARE_ATTRIBUTES_PROPERTYNAME = '{http://nextcloud.org/ns}share-attributes'; |
|
67 | + public const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL'; |
|
68 | + public const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size'; |
|
69 | + public const GETETAG_PROPERTYNAME = '{DAV:}getetag'; |
|
70 | + public const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified'; |
|
71 | + public const CREATIONDATE_PROPERTYNAME = '{DAV:}creationdate'; |
|
72 | + public const DISPLAYNAME_PROPERTYNAME = '{DAV:}displayname'; |
|
73 | + public const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id'; |
|
74 | + public const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name'; |
|
75 | + public const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums'; |
|
76 | + public const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint'; |
|
77 | + public const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview'; |
|
78 | + public const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type'; |
|
79 | + public const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted'; |
|
80 | + public const METADATA_ETAG_PROPERTYNAME = '{http://nextcloud.org/ns}metadata_etag'; |
|
81 | + public const UPLOAD_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}upload_time'; |
|
82 | + public const CREATION_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}creation_time'; |
|
83 | + public const SHARE_NOTE = '{http://nextcloud.org/ns}note'; |
|
84 | + public const SUBFOLDER_COUNT_PROPERTYNAME = '{http://nextcloud.org/ns}contained-folder-count'; |
|
85 | + public const SUBFILE_COUNT_PROPERTYNAME = '{http://nextcloud.org/ns}contained-file-count'; |
|
86 | + public const FILE_METADATA_SIZE = '{http://nextcloud.org/ns}file-metadata-size'; |
|
87 | + |
|
88 | + /** Reference to main server object */ |
|
89 | + private ?Server $server = null; |
|
90 | + private Tree $tree; |
|
91 | + private IUserSession $userSession; |
|
92 | + |
|
93 | + /** |
|
94 | + * Whether this is public webdav. |
|
95 | + * If true, some returned information will be stripped off. |
|
96 | + */ |
|
97 | + private bool $isPublic; |
|
98 | + private bool $downloadAttachment; |
|
99 | + private IConfig $config; |
|
100 | + private IRequest $request; |
|
101 | + private IPreview $previewManager; |
|
102 | + |
|
103 | + public function __construct(Tree $tree, |
|
104 | + IConfig $config, |
|
105 | + IRequest $request, |
|
106 | + IPreview $previewManager, |
|
107 | + IUserSession $userSession, |
|
108 | + bool $isPublic = false, |
|
109 | + bool $downloadAttachment = true) { |
|
110 | + $this->tree = $tree; |
|
111 | + $this->config = $config; |
|
112 | + $this->request = $request; |
|
113 | + $this->userSession = $userSession; |
|
114 | + $this->isPublic = $isPublic; |
|
115 | + $this->downloadAttachment = $downloadAttachment; |
|
116 | + $this->previewManager = $previewManager; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * This initializes the plugin. |
|
121 | + * |
|
122 | + * This function is called by \Sabre\DAV\Server, after |
|
123 | + * addPlugin is called. |
|
124 | + * |
|
125 | + * This method should set up the required event subscriptions. |
|
126 | + * |
|
127 | + * @return void |
|
128 | + */ |
|
129 | + public function initialize(Server $server) { |
|
130 | + $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
131 | + $server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc'; |
|
132 | + $server->protectedProperties[] = self::FILEID_PROPERTYNAME; |
|
133 | + $server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME; |
|
134 | + $server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME; |
|
135 | + $server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME; |
|
136 | + $server->protectedProperties[] = self::OCM_SHARE_PERMISSIONS_PROPERTYNAME; |
|
137 | + $server->protectedProperties[] = self::SHARE_ATTRIBUTES_PROPERTYNAME; |
|
138 | + $server->protectedProperties[] = self::SIZE_PROPERTYNAME; |
|
139 | + $server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME; |
|
140 | + $server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME; |
|
141 | + $server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME; |
|
142 | + $server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME; |
|
143 | + $server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME; |
|
144 | + $server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME; |
|
145 | + $server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME; |
|
146 | + $server->protectedProperties[] = self::IS_ENCRYPTED_PROPERTYNAME; |
|
147 | + $server->protectedProperties[] = self::SHARE_NOTE; |
|
148 | + |
|
149 | + // normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH |
|
150 | + $allowedProperties = ['{DAV:}getetag']; |
|
151 | + $server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties); |
|
152 | + |
|
153 | + $this->server = $server; |
|
154 | + $this->server->on('propFind', [$this, 'handleGetProperties']); |
|
155 | + $this->server->on('propPatch', [$this, 'handleUpdateProperties']); |
|
156 | + $this->server->on('afterBind', [$this, 'sendFileIdHeader']); |
|
157 | + $this->server->on('afterWriteContent', [$this, 'sendFileIdHeader']); |
|
158 | + $this->server->on('afterMethod:GET', [$this,'httpGet']); |
|
159 | + $this->server->on('afterMethod:GET', [$this, 'handleDownloadToken']); |
|
160 | + $this->server->on('afterResponse', function ($request, ResponseInterface $response) { |
|
161 | + $body = $response->getBody(); |
|
162 | + if (is_resource($body)) { |
|
163 | + fclose($body); |
|
164 | + } |
|
165 | + }); |
|
166 | + $this->server->on('beforeMove', [$this, 'checkMove']); |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Plugin that checks if a move can actually be performed. |
|
171 | + * |
|
172 | + * @param string $source source path |
|
173 | + * @param string $destination destination path |
|
174 | + * @throws Forbidden |
|
175 | + * @throws NotFound |
|
176 | + */ |
|
177 | + public function checkMove($source, $destination) { |
|
178 | + $sourceNode = $this->tree->getNodeForPath($source); |
|
179 | + if (!$sourceNode instanceof Node) { |
|
180 | + return; |
|
181 | + } |
|
182 | + [$sourceDir,] = \Sabre\Uri\split($source); |
|
183 | + [$destinationDir,] = \Sabre\Uri\split($destination); |
|
184 | + |
|
185 | + if ($sourceDir !== $destinationDir) { |
|
186 | + $sourceNodeFileInfo = $sourceNode->getFileInfo(); |
|
187 | + if ($sourceNodeFileInfo === null) { |
|
188 | + throw new NotFound($source . ' does not exist'); |
|
189 | + } |
|
190 | + |
|
191 | + if (!$sourceNodeFileInfo->isDeletable()) { |
|
192 | + throw new Forbidden($source . " cannot be deleted"); |
|
193 | + } |
|
194 | + } |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * This sets a cookie to be able to recognize the start of the download |
|
199 | + * the content must not be longer than 32 characters and must only contain |
|
200 | + * alphanumeric characters |
|
201 | + * |
|
202 | + * @param RequestInterface $request |
|
203 | + * @param ResponseInterface $response |
|
204 | + */ |
|
205 | + public function handleDownloadToken(RequestInterface $request, ResponseInterface $response) { |
|
206 | + $queryParams = $request->getQueryParameters(); |
|
207 | + |
|
208 | + /** |
|
209 | + * this sets a cookie to be able to recognize the start of the download |
|
210 | + * the content must not be longer than 32 characters and must only contain |
|
211 | + * alphanumeric characters |
|
212 | + */ |
|
213 | + if (isset($queryParams['downloadStartSecret'])) { |
|
214 | + $token = $queryParams['downloadStartSecret']; |
|
215 | + if (!isset($token[32]) |
|
216 | + && preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) { |
|
217 | + // FIXME: use $response->setHeader() instead |
|
218 | + setcookie('ocDownloadStarted', $token, time() + 20, '/'); |
|
219 | + } |
|
220 | + } |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Add headers to file download |
|
225 | + * |
|
226 | + * @param RequestInterface $request |
|
227 | + * @param ResponseInterface $response |
|
228 | + */ |
|
229 | + public function httpGet(RequestInterface $request, ResponseInterface $response) { |
|
230 | + // Only handle valid files |
|
231 | + $node = $this->tree->getNodeForPath($request->getPath()); |
|
232 | + if (!($node instanceof IFile)) { |
|
233 | + return; |
|
234 | + } |
|
235 | + |
|
236 | + // adds a 'Content-Disposition: attachment' header in case no disposition |
|
237 | + // header has been set before |
|
238 | + if ($this->downloadAttachment && |
|
239 | + $response->getHeader('Content-Disposition') === null) { |
|
240 | + $filename = $node->getName(); |
|
241 | + if ($this->request->isUserAgent( |
|
242 | + [ |
|
243 | + Request::USER_AGENT_IE, |
|
244 | + Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
|
245 | + Request::USER_AGENT_FREEBOX, |
|
246 | + ])) { |
|
247 | + $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"'); |
|
248 | + } else { |
|
249 | + $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename) |
|
250 | + . '; filename="' . rawurlencode($filename) . '"'); |
|
251 | + } |
|
252 | + } |
|
253 | + |
|
254 | + if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
255 | + //Add OC-Checksum header |
|
256 | + $checksum = $node->getChecksum(); |
|
257 | + if ($checksum !== null && $checksum !== '') { |
|
258 | + $response->addHeader('OC-Checksum', $checksum); |
|
259 | + } |
|
260 | + } |
|
261 | + $response->addHeader('X-Accel-Buffering', 'no'); |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Adds all ownCloud-specific properties |
|
266 | + * |
|
267 | + * @param PropFind $propFind |
|
268 | + * @param \Sabre\DAV\INode $node |
|
269 | + * @return void |
|
270 | + */ |
|
271 | + public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) { |
|
272 | + $httpRequest = $this->server->httpRequest; |
|
273 | + |
|
274 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
275 | + /** |
|
276 | + * This was disabled, because it made dir listing throw an exception, |
|
277 | + * so users were unable to navigate into folders where one subitem |
|
278 | + * is blocked by the files_accesscontrol app, see: |
|
279 | + * https://github.com/nextcloud/files_accesscontrol/issues/65 |
|
280 | + * if (!$node->getFileInfo()->isReadable()) { |
|
281 | + * // avoid detecting files through this means |
|
282 | + * throw new NotFound(); |
|
283 | + * } |
|
284 | + */ |
|
285 | + |
|
286 | + $propFind->handle(self::FILEID_PROPERTYNAME, function () use ($node) { |
|
287 | + return $node->getFileId(); |
|
288 | + }); |
|
289 | + |
|
290 | + $propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function () use ($node) { |
|
291 | + return $node->getInternalFileId(); |
|
292 | + }); |
|
293 | + |
|
294 | + $propFind->handle(self::PERMISSIONS_PROPERTYNAME, function () use ($node) { |
|
295 | + $perms = $node->getDavPermissions(); |
|
296 | + if ($this->isPublic) { |
|
297 | + // remove mount information |
|
298 | + $perms = str_replace(['S', 'M'], '', $perms); |
|
299 | + } |
|
300 | + return $perms; |
|
301 | + }); |
|
302 | + |
|
303 | + $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function () use ($node, $httpRequest) { |
|
304 | + $user = $this->userSession->getUser(); |
|
305 | + if ($user === null) { |
|
306 | + return null; |
|
307 | + } |
|
308 | + return $node->getSharePermissions( |
|
309 | + $user->getUID() |
|
310 | + ); |
|
311 | + }); |
|
312 | + |
|
313 | + $propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function () use ($node, $httpRequest): ?string { |
|
314 | + $user = $this->userSession->getUser(); |
|
315 | + if ($user === null) { |
|
316 | + return null; |
|
317 | + } |
|
318 | + $ncPermissions = $node->getSharePermissions( |
|
319 | + $user->getUID() |
|
320 | + ); |
|
321 | + $ocmPermissions = $this->ncPermissions2ocmPermissions($ncPermissions); |
|
322 | + return json_encode($ocmPermissions, JSON_THROW_ON_ERROR); |
|
323 | + }); |
|
324 | + |
|
325 | + $propFind->handle(self::SHARE_ATTRIBUTES_PROPERTYNAME, function () use ($node, $httpRequest) { |
|
326 | + return json_encode($node->getShareAttributes(), JSON_THROW_ON_ERROR); |
|
327 | + }); |
|
328 | + |
|
329 | + $propFind->handle(self::GETETAG_PROPERTYNAME, function () use ($node): string { |
|
330 | + return $node->getETag(); |
|
331 | + }); |
|
332 | + |
|
333 | + $propFind->handle(self::OWNER_ID_PROPERTYNAME, function () use ($node): ?string { |
|
334 | + $owner = $node->getOwner(); |
|
335 | + if (!$owner) { |
|
336 | + return null; |
|
337 | + } else { |
|
338 | + return $owner->getUID(); |
|
339 | + } |
|
340 | + }); |
|
341 | + $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function () use ($node): ?string { |
|
342 | + $owner = $node->getOwner(); |
|
343 | + if (!$owner) { |
|
344 | + return null; |
|
345 | + } else { |
|
346 | + return $owner->getDisplayName(); |
|
347 | + } |
|
348 | + }); |
|
349 | + |
|
350 | + $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { |
|
351 | + return json_encode($this->previewManager->isAvailable($node->getFileInfo()), JSON_THROW_ON_ERROR); |
|
352 | + }); |
|
353 | + $propFind->handle(self::SIZE_PROPERTYNAME, function () use ($node): int|float { |
|
354 | + return $node->getSize(); |
|
355 | + }); |
|
356 | + $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { |
|
357 | + return $node->getFileInfo()->getMountPoint()->getMountType(); |
|
358 | + }); |
|
359 | + |
|
360 | + $propFind->handle(self::SHARE_NOTE, function () use ($node, $httpRequest): ?string { |
|
361 | + $user = $this->userSession->getUser(); |
|
362 | + if ($user === null) { |
|
363 | + return null; |
|
364 | + } |
|
365 | + return $node->getNoteFromShare( |
|
366 | + $user->getUID() |
|
367 | + ); |
|
368 | + }); |
|
369 | + |
|
370 | + $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function () use ($node) { |
|
371 | + return $this->config->getSystemValue('data-fingerprint', ''); |
|
372 | + }); |
|
373 | + $propFind->handle(self::CREATIONDATE_PROPERTYNAME, function () use ($node) { |
|
374 | + return (new \DateTimeImmutable()) |
|
375 | + ->setTimestamp($node->getFileInfo()->getCreationTime()) |
|
376 | + ->format(\DateTimeInterface::ATOM); |
|
377 | + }); |
|
378 | + $propFind->handle(self::CREATION_TIME_PROPERTYNAME, function () use ($node) { |
|
379 | + return $node->getFileInfo()->getCreationTime(); |
|
380 | + }); |
|
381 | + /** |
|
382 | + * Return file/folder name as displayname. The primary reason to |
|
383 | + * implement it this way is to avoid costly fallback to |
|
384 | + * CustomPropertiesBackend (esp. visible when querying all files |
|
385 | + * in a folder). |
|
386 | + */ |
|
387 | + $propFind->handle(self::DISPLAYNAME_PROPERTYNAME, function () use ($node) { |
|
388 | + return $node->getName(); |
|
389 | + }); |
|
390 | + } |
|
391 | + |
|
392 | + if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
393 | + $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function () use ($node) { |
|
394 | + try { |
|
395 | + $directDownloadUrl = $node->getDirectDownload(); |
|
396 | + if (isset($directDownloadUrl['url'])) { |
|
397 | + return $directDownloadUrl['url']; |
|
398 | + } |
|
399 | + } catch (StorageNotAvailableException $e) { |
|
400 | + return false; |
|
401 | + } catch (ForbiddenException $e) { |
|
402 | + return false; |
|
403 | + } |
|
404 | + return false; |
|
405 | + }); |
|
406 | + |
|
407 | + $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function () use ($node) { |
|
408 | + $checksum = $node->getChecksum(); |
|
409 | + if ($checksum === null || $checksum === '') { |
|
410 | + return null; |
|
411 | + } |
|
412 | + |
|
413 | + return new ChecksumList($checksum); |
|
414 | + }); |
|
415 | + |
|
416 | + $propFind->handle(self::UPLOAD_TIME_PROPERTYNAME, function () use ($node) { |
|
417 | + return $node->getFileInfo()->getUploadTime(); |
|
418 | + }); |
|
419 | + |
|
420 | + if ($this->config->getSystemValueBool('enable_file_metadata', true)) { |
|
421 | + $propFind->handle(self::FILE_METADATA_SIZE, function () use ($node) { |
|
422 | + if (!str_starts_with($node->getFileInfo()->getMimetype(), 'image')) { |
|
423 | + return json_encode((object)[], JSON_THROW_ON_ERROR); |
|
424 | + } |
|
425 | + |
|
426 | + if ($node->hasMetadata('size')) { |
|
427 | + $sizeMetadata = $node->getMetadata('size'); |
|
428 | + } else { |
|
429 | + // This code path should not be called since we try to preload |
|
430 | + // the metadata when loading the folder or the search results |
|
431 | + // in one go |
|
432 | + $metadataManager = \OC::$server->get(IMetadataManager::class); |
|
433 | + $sizeMetadata = $metadataManager->fetchMetadataFor('size', [$node->getId()])[$node->getId()]; |
|
434 | + |
|
435 | + // TODO would be nice to display this in the profiler... |
|
436 | + \OC::$server->get(LoggerInterface::class)->debug('Inefficient fetching of metadata'); |
|
437 | + } |
|
438 | + |
|
439 | + return json_encode((object)$sizeMetadata->getMetadata(), JSON_THROW_ON_ERROR); |
|
440 | + }); |
|
441 | + } |
|
442 | + } |
|
443 | + |
|
444 | + if ($node instanceof Directory) { |
|
445 | + $propFind->handle(self::SIZE_PROPERTYNAME, function () use ($node) { |
|
446 | + return $node->getSize(); |
|
447 | + }); |
|
448 | + |
|
449 | + $propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function () use ($node) { |
|
450 | + return $node->getFileInfo()->isEncrypted() ? '1' : '0'; |
|
451 | + }); |
|
452 | + |
|
453 | + $requestProperties = $propFind->getRequestedProperties(); |
|
454 | + |
|
455 | + // TODO detect dynamically which metadata groups are requested and |
|
456 | + // preload all of them and not just size |
|
457 | + if ($this->config->getSystemValueBool('enable_file_metadata', true) |
|
458 | + && in_array(self::FILE_METADATA_SIZE, $requestProperties, true)) { |
|
459 | + // Preloading of the metadata |
|
460 | + $fileIds = []; |
|
461 | + foreach ($node->getChildren() as $child) { |
|
462 | + /** @var \OCP\Files\Node|Node $child */ |
|
463 | + if (str_starts_with($child->getFileInfo()->getMimeType(), 'image/')) { |
|
464 | + /** @var File $child */ |
|
465 | + $fileIds[] = $child->getFileInfo()->getId(); |
|
466 | + } |
|
467 | + } |
|
468 | + /** @var IMetaDataManager $metadataManager */ |
|
469 | + $metadataManager = \OC::$server->get(IMetadataManager::class); |
|
470 | + $preloadedMetadata = $metadataManager->fetchMetadataFor('size', $fileIds); |
|
471 | + foreach ($node->getChildren() as $child) { |
|
472 | + /** @var \OCP\Files\Node|Node $child */ |
|
473 | + if (str_starts_with($child->getFileInfo()->getMimeType(), 'image')) { |
|
474 | + /** @var File $child */ |
|
475 | + $child->setMetadata('size', $preloadedMetadata[$child->getFileInfo()->getId()]); |
|
476 | + } |
|
477 | + } |
|
478 | + } |
|
479 | + |
|
480 | + if (in_array(self::SUBFILE_COUNT_PROPERTYNAME, $requestProperties, true) |
|
481 | + || in_array(self::SUBFOLDER_COUNT_PROPERTYNAME, $requestProperties, true)) { |
|
482 | + $nbFiles = 0; |
|
483 | + $nbFolders = 0; |
|
484 | + foreach ($node->getChildren() as $child) { |
|
485 | + if ($child instanceof File) { |
|
486 | + $nbFiles++; |
|
487 | + } elseif ($child instanceof Directory) { |
|
488 | + $nbFolders++; |
|
489 | + } |
|
490 | + } |
|
491 | + |
|
492 | + $propFind->handle(self::SUBFILE_COUNT_PROPERTYNAME, $nbFiles); |
|
493 | + $propFind->handle(self::SUBFOLDER_COUNT_PROPERTYNAME, $nbFolders); |
|
494 | + } |
|
495 | + } |
|
496 | + } |
|
497 | + |
|
498 | + /** |
|
499 | + * translate Nextcloud permissions to OCM Permissions |
|
500 | + * |
|
501 | + * @param $ncPermissions |
|
502 | + * @return array |
|
503 | + */ |
|
504 | + protected function ncPermissions2ocmPermissions($ncPermissions) { |
|
505 | + $ocmPermissions = []; |
|
506 | + |
|
507 | + if ($ncPermissions & Constants::PERMISSION_SHARE) { |
|
508 | + $ocmPermissions[] = 'share'; |
|
509 | + } |
|
510 | + |
|
511 | + if ($ncPermissions & Constants::PERMISSION_READ) { |
|
512 | + $ocmPermissions[] = 'read'; |
|
513 | + } |
|
514 | + |
|
515 | + if (($ncPermissions & Constants::PERMISSION_CREATE) || |
|
516 | + ($ncPermissions & Constants::PERMISSION_UPDATE)) { |
|
517 | + $ocmPermissions[] = 'write'; |
|
518 | + } |
|
519 | + |
|
520 | + return $ocmPermissions; |
|
521 | + } |
|
522 | + |
|
523 | + /** |
|
524 | + * Update ownCloud-specific properties |
|
525 | + * |
|
526 | + * @param string $path |
|
527 | + * @param PropPatch $propPatch |
|
528 | + * |
|
529 | + * @return void |
|
530 | + */ |
|
531 | + public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
532 | + $node = $this->tree->getNodeForPath($path); |
|
533 | + if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
534 | + return; |
|
535 | + } |
|
536 | + |
|
537 | + $propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function ($time) use ($node) { |
|
538 | + if (empty($time)) { |
|
539 | + return false; |
|
540 | + } |
|
541 | + $node->touch($time); |
|
542 | + return true; |
|
543 | + }); |
|
544 | + $propPatch->handle(self::GETETAG_PROPERTYNAME, function ($etag) use ($node) { |
|
545 | + if (empty($etag)) { |
|
546 | + return false; |
|
547 | + } |
|
548 | + return $node->setEtag($etag) !== -1; |
|
549 | + }); |
|
550 | + $propPatch->handle(self::CREATIONDATE_PROPERTYNAME, function ($time) use ($node) { |
|
551 | + if (empty($time)) { |
|
552 | + return false; |
|
553 | + } |
|
554 | + $dateTime = new \DateTimeImmutable($time); |
|
555 | + $node->setCreationTime($dateTime->getTimestamp()); |
|
556 | + return true; |
|
557 | + }); |
|
558 | + $propPatch->handle(self::CREATION_TIME_PROPERTYNAME, function ($time) use ($node) { |
|
559 | + if (empty($time)) { |
|
560 | + return false; |
|
561 | + } |
|
562 | + $node->setCreationTime((int) $time); |
|
563 | + return true; |
|
564 | + }); |
|
565 | + /** |
|
566 | + * Disable modification of the displayname property for files and |
|
567 | + * folders via PROPPATCH. See PROPFIND for more information. |
|
568 | + */ |
|
569 | + $propPatch->handle(self::DISPLAYNAME_PROPERTYNAME, function ($displayName) { |
|
570 | + return 403; |
|
571 | + }); |
|
572 | + } |
|
573 | + |
|
574 | + /** |
|
575 | + * @param string $filePath |
|
576 | + * @param \Sabre\DAV\INode $node |
|
577 | + * @throws \Sabre\DAV\Exception\BadRequest |
|
578 | + */ |
|
579 | + public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) { |
|
580 | + // we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder |
|
581 | + if (!$this->server->tree->nodeExists($filePath)) { |
|
582 | + return; |
|
583 | + } |
|
584 | + $node = $this->server->tree->getNodeForPath($filePath); |
|
585 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
586 | + $fileId = $node->getFileId(); |
|
587 | + if (!is_null($fileId)) { |
|
588 | + $this->server->httpResponse->setHeader('OC-FileId', $fileId); |
|
589 | + } |
|
590 | + } |
|
591 | + } |
|
592 | 592 | } |
@@ -155,9 +155,9 @@ discard block |
||
155 | 155 | $this->server->on('propPatch', [$this, 'handleUpdateProperties']); |
156 | 156 | $this->server->on('afterBind', [$this, 'sendFileIdHeader']); |
157 | 157 | $this->server->on('afterWriteContent', [$this, 'sendFileIdHeader']); |
158 | - $this->server->on('afterMethod:GET', [$this,'httpGet']); |
|
158 | + $this->server->on('afterMethod:GET', [$this, 'httpGet']); |
|
159 | 159 | $this->server->on('afterMethod:GET', [$this, 'handleDownloadToken']); |
160 | - $this->server->on('afterResponse', function ($request, ResponseInterface $response) { |
|
160 | + $this->server->on('afterResponse', function($request, ResponseInterface $response) { |
|
161 | 161 | $body = $response->getBody(); |
162 | 162 | if (is_resource($body)) { |
163 | 163 | fclose($body); |
@@ -179,17 +179,17 @@ discard block |
||
179 | 179 | if (!$sourceNode instanceof Node) { |
180 | 180 | return; |
181 | 181 | } |
182 | - [$sourceDir,] = \Sabre\Uri\split($source); |
|
183 | - [$destinationDir,] = \Sabre\Uri\split($destination); |
|
182 | + [$sourceDir, ] = \Sabre\Uri\split($source); |
|
183 | + [$destinationDir, ] = \Sabre\Uri\split($destination); |
|
184 | 184 | |
185 | 185 | if ($sourceDir !== $destinationDir) { |
186 | 186 | $sourceNodeFileInfo = $sourceNode->getFileInfo(); |
187 | 187 | if ($sourceNodeFileInfo === null) { |
188 | - throw new NotFound($source . ' does not exist'); |
|
188 | + throw new NotFound($source.' does not exist'); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | if (!$sourceNodeFileInfo->isDeletable()) { |
192 | - throw new Forbidden($source . " cannot be deleted"); |
|
192 | + throw new Forbidden($source." cannot be deleted"); |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | } |
@@ -244,10 +244,10 @@ discard block |
||
244 | 244 | Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
245 | 245 | Request::USER_AGENT_FREEBOX, |
246 | 246 | ])) { |
247 | - $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"'); |
|
247 | + $response->addHeader('Content-Disposition', 'attachment; filename="'.rawurlencode($filename).'"'); |
|
248 | 248 | } else { |
249 | - $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename) |
|
250 | - . '; filename="' . rawurlencode($filename) . '"'); |
|
249 | + $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\''.rawurlencode($filename) |
|
250 | + . '; filename="'.rawurlencode($filename).'"'); |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 | |
@@ -283,15 +283,15 @@ discard block |
||
283 | 283 | * } |
284 | 284 | */ |
285 | 285 | |
286 | - $propFind->handle(self::FILEID_PROPERTYNAME, function () use ($node) { |
|
286 | + $propFind->handle(self::FILEID_PROPERTYNAME, function() use ($node) { |
|
287 | 287 | return $node->getFileId(); |
288 | 288 | }); |
289 | 289 | |
290 | - $propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function () use ($node) { |
|
290 | + $propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function() use ($node) { |
|
291 | 291 | return $node->getInternalFileId(); |
292 | 292 | }); |
293 | 293 | |
294 | - $propFind->handle(self::PERMISSIONS_PROPERTYNAME, function () use ($node) { |
|
294 | + $propFind->handle(self::PERMISSIONS_PROPERTYNAME, function() use ($node) { |
|
295 | 295 | $perms = $node->getDavPermissions(); |
296 | 296 | if ($this->isPublic) { |
297 | 297 | // remove mount information |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | return $perms; |
301 | 301 | }); |
302 | 302 | |
303 | - $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function () use ($node, $httpRequest) { |
|
303 | + $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) { |
|
304 | 304 | $user = $this->userSession->getUser(); |
305 | 305 | if ($user === null) { |
306 | 306 | return null; |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | ); |
311 | 311 | }); |
312 | 312 | |
313 | - $propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function () use ($node, $httpRequest): ?string { |
|
313 | + $propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest): ?string { |
|
314 | 314 | $user = $this->userSession->getUser(); |
315 | 315 | if ($user === null) { |
316 | 316 | return null; |
@@ -322,15 +322,15 @@ discard block |
||
322 | 322 | return json_encode($ocmPermissions, JSON_THROW_ON_ERROR); |
323 | 323 | }); |
324 | 324 | |
325 | - $propFind->handle(self::SHARE_ATTRIBUTES_PROPERTYNAME, function () use ($node, $httpRequest) { |
|
325 | + $propFind->handle(self::SHARE_ATTRIBUTES_PROPERTYNAME, function() use ($node, $httpRequest) { |
|
326 | 326 | return json_encode($node->getShareAttributes(), JSON_THROW_ON_ERROR); |
327 | 327 | }); |
328 | 328 | |
329 | - $propFind->handle(self::GETETAG_PROPERTYNAME, function () use ($node): string { |
|
329 | + $propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node): string { |
|
330 | 330 | return $node->getETag(); |
331 | 331 | }); |
332 | 332 | |
333 | - $propFind->handle(self::OWNER_ID_PROPERTYNAME, function () use ($node): ?string { |
|
333 | + $propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node): ?string { |
|
334 | 334 | $owner = $node->getOwner(); |
335 | 335 | if (!$owner) { |
336 | 336 | return null; |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | return $owner->getUID(); |
339 | 339 | } |
340 | 340 | }); |
341 | - $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function () use ($node): ?string { |
|
341 | + $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node): ?string { |
|
342 | 342 | $owner = $node->getOwner(); |
343 | 343 | if (!$owner) { |
344 | 344 | return null; |
@@ -347,17 +347,17 @@ discard block |
||
347 | 347 | } |
348 | 348 | }); |
349 | 349 | |
350 | - $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { |
|
350 | + $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function() use ($node) { |
|
351 | 351 | return json_encode($this->previewManager->isAvailable($node->getFileInfo()), JSON_THROW_ON_ERROR); |
352 | 352 | }); |
353 | - $propFind->handle(self::SIZE_PROPERTYNAME, function () use ($node): int|float { |
|
353 | + $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node): int | float { |
|
354 | 354 | return $node->getSize(); |
355 | 355 | }); |
356 | - $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { |
|
356 | + $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function() use ($node) { |
|
357 | 357 | return $node->getFileInfo()->getMountPoint()->getMountType(); |
358 | 358 | }); |
359 | 359 | |
360 | - $propFind->handle(self::SHARE_NOTE, function () use ($node, $httpRequest): ?string { |
|
360 | + $propFind->handle(self::SHARE_NOTE, function() use ($node, $httpRequest): ?string { |
|
361 | 361 | $user = $this->userSession->getUser(); |
362 | 362 | if ($user === null) { |
363 | 363 | return null; |
@@ -367,15 +367,15 @@ discard block |
||
367 | 367 | ); |
368 | 368 | }); |
369 | 369 | |
370 | - $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function () use ($node) { |
|
370 | + $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) { |
|
371 | 371 | return $this->config->getSystemValue('data-fingerprint', ''); |
372 | 372 | }); |
373 | - $propFind->handle(self::CREATIONDATE_PROPERTYNAME, function () use ($node) { |
|
373 | + $propFind->handle(self::CREATIONDATE_PROPERTYNAME, function() use ($node) { |
|
374 | 374 | return (new \DateTimeImmutable()) |
375 | 375 | ->setTimestamp($node->getFileInfo()->getCreationTime()) |
376 | 376 | ->format(\DateTimeInterface::ATOM); |
377 | 377 | }); |
378 | - $propFind->handle(self::CREATION_TIME_PROPERTYNAME, function () use ($node) { |
|
378 | + $propFind->handle(self::CREATION_TIME_PROPERTYNAME, function() use ($node) { |
|
379 | 379 | return $node->getFileInfo()->getCreationTime(); |
380 | 380 | }); |
381 | 381 | /** |
@@ -384,13 +384,13 @@ discard block |
||
384 | 384 | * CustomPropertiesBackend (esp. visible when querying all files |
385 | 385 | * in a folder). |
386 | 386 | */ |
387 | - $propFind->handle(self::DISPLAYNAME_PROPERTYNAME, function () use ($node) { |
|
387 | + $propFind->handle(self::DISPLAYNAME_PROPERTYNAME, function() use ($node) { |
|
388 | 388 | return $node->getName(); |
389 | 389 | }); |
390 | 390 | } |
391 | 391 | |
392 | 392 | if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
393 | - $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function () use ($node) { |
|
393 | + $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) { |
|
394 | 394 | try { |
395 | 395 | $directDownloadUrl = $node->getDirectDownload(); |
396 | 396 | if (isset($directDownloadUrl['url'])) { |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | return false; |
405 | 405 | }); |
406 | 406 | |
407 | - $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function () use ($node) { |
|
407 | + $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) { |
|
408 | 408 | $checksum = $node->getChecksum(); |
409 | 409 | if ($checksum === null || $checksum === '') { |
410 | 410 | return null; |
@@ -413,14 +413,14 @@ discard block |
||
413 | 413 | return new ChecksumList($checksum); |
414 | 414 | }); |
415 | 415 | |
416 | - $propFind->handle(self::UPLOAD_TIME_PROPERTYNAME, function () use ($node) { |
|
416 | + $propFind->handle(self::UPLOAD_TIME_PROPERTYNAME, function() use ($node) { |
|
417 | 417 | return $node->getFileInfo()->getUploadTime(); |
418 | 418 | }); |
419 | 419 | |
420 | 420 | if ($this->config->getSystemValueBool('enable_file_metadata', true)) { |
421 | - $propFind->handle(self::FILE_METADATA_SIZE, function () use ($node) { |
|
421 | + $propFind->handle(self::FILE_METADATA_SIZE, function() use ($node) { |
|
422 | 422 | if (!str_starts_with($node->getFileInfo()->getMimetype(), 'image')) { |
423 | - return json_encode((object)[], JSON_THROW_ON_ERROR); |
|
423 | + return json_encode((object) [], JSON_THROW_ON_ERROR); |
|
424 | 424 | } |
425 | 425 | |
426 | 426 | if ($node->hasMetadata('size')) { |
@@ -436,17 +436,17 @@ discard block |
||
436 | 436 | \OC::$server->get(LoggerInterface::class)->debug('Inefficient fetching of metadata'); |
437 | 437 | } |
438 | 438 | |
439 | - return json_encode((object)$sizeMetadata->getMetadata(), JSON_THROW_ON_ERROR); |
|
439 | + return json_encode((object) $sizeMetadata->getMetadata(), JSON_THROW_ON_ERROR); |
|
440 | 440 | }); |
441 | 441 | } |
442 | 442 | } |
443 | 443 | |
444 | 444 | if ($node instanceof Directory) { |
445 | - $propFind->handle(self::SIZE_PROPERTYNAME, function () use ($node) { |
|
445 | + $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
|
446 | 446 | return $node->getSize(); |
447 | 447 | }); |
448 | 448 | |
449 | - $propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function () use ($node) { |
|
449 | + $propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function() use ($node) { |
|
450 | 450 | return $node->getFileInfo()->isEncrypted() ? '1' : '0'; |
451 | 451 | }); |
452 | 452 | |
@@ -534,20 +534,20 @@ discard block |
||
534 | 534 | return; |
535 | 535 | } |
536 | 536 | |
537 | - $propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function ($time) use ($node) { |
|
537 | + $propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function($time) use ($node) { |
|
538 | 538 | if (empty($time)) { |
539 | 539 | return false; |
540 | 540 | } |
541 | 541 | $node->touch($time); |
542 | 542 | return true; |
543 | 543 | }); |
544 | - $propPatch->handle(self::GETETAG_PROPERTYNAME, function ($etag) use ($node) { |
|
544 | + $propPatch->handle(self::GETETAG_PROPERTYNAME, function($etag) use ($node) { |
|
545 | 545 | if (empty($etag)) { |
546 | 546 | return false; |
547 | 547 | } |
548 | 548 | return $node->setEtag($etag) !== -1; |
549 | 549 | }); |
550 | - $propPatch->handle(self::CREATIONDATE_PROPERTYNAME, function ($time) use ($node) { |
|
550 | + $propPatch->handle(self::CREATIONDATE_PROPERTYNAME, function($time) use ($node) { |
|
551 | 551 | if (empty($time)) { |
552 | 552 | return false; |
553 | 553 | } |
@@ -555,7 +555,7 @@ discard block |
||
555 | 555 | $node->setCreationTime($dateTime->getTimestamp()); |
556 | 556 | return true; |
557 | 557 | }); |
558 | - $propPatch->handle(self::CREATION_TIME_PROPERTYNAME, function ($time) use ($node) { |
|
558 | + $propPatch->handle(self::CREATION_TIME_PROPERTYNAME, function($time) use ($node) { |
|
559 | 559 | if (empty($time)) { |
560 | 560 | return false; |
561 | 561 | } |
@@ -566,7 +566,7 @@ discard block |
||
566 | 566 | * Disable modification of the displayname property for files and |
567 | 567 | * folders via PROPPATCH. See PROPFIND for more information. |
568 | 568 | */ |
569 | - $propPatch->handle(self::DISPLAYNAME_PROPERTYNAME, function ($displayName) { |
|
569 | + $propPatch->handle(self::DISPLAYNAME_PROPERTYNAME, function($displayName) { |
|
570 | 570 | return 403; |
571 | 571 | }); |
572 | 572 | } |