@@ -31,22 +31,22 @@ |
||
31 | 31 | */ |
32 | 32 | class Version14000Date20180129121024 extends SimpleMigrationStep { |
33 | 33 | |
34 | - /** |
|
35 | - * @param IOutput $output |
|
36 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
37 | - * @param array $options |
|
38 | - * @return null|ISchemaWrapper |
|
39 | - * @since 13.0.0 |
|
40 | - */ |
|
41 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
42 | - /** @var ISchemaWrapper $schema */ |
|
43 | - $schema = $schemaClosure(); |
|
34 | + /** |
|
35 | + * @param IOutput $output |
|
36 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
37 | + * @param array $options |
|
38 | + * @return null|ISchemaWrapper |
|
39 | + * @since 13.0.0 |
|
40 | + */ |
|
41 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
42 | + /** @var ISchemaWrapper $schema */ |
|
43 | + $schema = $schemaClosure(); |
|
44 | 44 | |
45 | - $schema->dropTable('admin_sections'); |
|
46 | - $schema->dropTable('admin_settings'); |
|
47 | - $schema->dropTable('personal_sections'); |
|
48 | - $schema->dropTable('personal_settings'); |
|
45 | + $schema->dropTable('admin_sections'); |
|
46 | + $schema->dropTable('admin_settings'); |
|
47 | + $schema->dropTable('personal_sections'); |
|
48 | + $schema->dropTable('personal_settings'); |
|
49 | 49 | |
50 | - return $schema; |
|
51 | - } |
|
50 | + return $schema; |
|
51 | + } |
|
52 | 52 | } |
@@ -146,1832 +146,1832 @@ |
||
146 | 146 | * TODO: hookup all manager classes |
147 | 147 | */ |
148 | 148 | class Server extends ServerContainer implements IServerContainer { |
149 | - /** @var string */ |
|
150 | - private $webRoot; |
|
151 | - |
|
152 | - /** |
|
153 | - * @param string $webRoot |
|
154 | - * @param \OC\Config $config |
|
155 | - */ |
|
156 | - public function __construct($webRoot, \OC\Config $config) { |
|
157 | - parent::__construct(); |
|
158 | - $this->webRoot = $webRoot; |
|
159 | - |
|
160 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
161 | - return $c; |
|
162 | - }); |
|
163 | - |
|
164 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
165 | - $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
166 | - |
|
167 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
168 | - $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
169 | - |
|
170 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
171 | - |
|
172 | - |
|
173 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
174 | - return new PreviewManager( |
|
175 | - $c->getConfig(), |
|
176 | - $c->getRootFolder(), |
|
177 | - $c->getAppDataDir('preview'), |
|
178 | - $c->getEventDispatcher(), |
|
179 | - $c->getSession()->get('user_id') |
|
180 | - ); |
|
181 | - }); |
|
182 | - $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
183 | - |
|
184 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
185 | - return new \OC\Preview\Watcher( |
|
186 | - $c->getAppDataDir('preview') |
|
187 | - ); |
|
188 | - }); |
|
189 | - |
|
190 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
191 | - $view = new View(); |
|
192 | - $util = new Encryption\Util( |
|
193 | - $view, |
|
194 | - $c->getUserManager(), |
|
195 | - $c->getGroupManager(), |
|
196 | - $c->getConfig() |
|
197 | - ); |
|
198 | - return new Encryption\Manager( |
|
199 | - $c->getConfig(), |
|
200 | - $c->getLogger(), |
|
201 | - $c->getL10N('core'), |
|
202 | - new View(), |
|
203 | - $util, |
|
204 | - new ArrayCache() |
|
205 | - ); |
|
206 | - }); |
|
207 | - |
|
208 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
209 | - $util = new Encryption\Util( |
|
210 | - new View(), |
|
211 | - $c->getUserManager(), |
|
212 | - $c->getGroupManager(), |
|
213 | - $c->getConfig() |
|
214 | - ); |
|
215 | - return new Encryption\File( |
|
216 | - $util, |
|
217 | - $c->getRootFolder(), |
|
218 | - $c->getShareManager() |
|
219 | - ); |
|
220 | - }); |
|
221 | - |
|
222 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
223 | - $view = new View(); |
|
224 | - $util = new Encryption\Util( |
|
225 | - $view, |
|
226 | - $c->getUserManager(), |
|
227 | - $c->getGroupManager(), |
|
228 | - $c->getConfig() |
|
229 | - ); |
|
230 | - |
|
231 | - return new Encryption\Keys\Storage($view, $util); |
|
232 | - }); |
|
233 | - $this->registerService('TagMapper', function (Server $c) { |
|
234 | - return new TagMapper($c->getDatabaseConnection()); |
|
235 | - }); |
|
236 | - |
|
237 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
238 | - $tagMapper = $c->query('TagMapper'); |
|
239 | - return new TagManager($tagMapper, $c->getUserSession()); |
|
240 | - }); |
|
241 | - $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
242 | - |
|
243 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
244 | - $config = $c->getConfig(); |
|
245 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
|
246 | - return new $factoryClass($this); |
|
247 | - }); |
|
248 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
249 | - return $c->query('SystemTagManagerFactory')->getManager(); |
|
250 | - }); |
|
251 | - $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
252 | - |
|
253 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
254 | - return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
255 | - }); |
|
256 | - $this->registerService('RootFolder', function (Server $c) { |
|
257 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
258 | - $view = new View(); |
|
259 | - $root = new Root( |
|
260 | - $manager, |
|
261 | - $view, |
|
262 | - null, |
|
263 | - $c->getUserMountCache(), |
|
264 | - $this->getLogger(), |
|
265 | - $this->getUserManager() |
|
266 | - ); |
|
267 | - $connector = new HookConnector($root, $view); |
|
268 | - $connector->viewToNode(); |
|
269 | - |
|
270 | - $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
271 | - $previewConnector->connectWatcher(); |
|
272 | - |
|
273 | - return $root; |
|
274 | - }); |
|
275 | - $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
276 | - |
|
277 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
278 | - return new LazyRoot(function () use ($c) { |
|
279 | - return $c->query('RootFolder'); |
|
280 | - }); |
|
281 | - }); |
|
282 | - $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
283 | - |
|
284 | - $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
285 | - $config = $c->getConfig(); |
|
286 | - return new \OC\User\Manager($config); |
|
287 | - }); |
|
288 | - $this->registerAlias('UserManager', \OC\User\Manager::class); |
|
289 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
290 | - |
|
291 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
292 | - $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
293 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
294 | - \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
295 | - }); |
|
296 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
297 | - \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
298 | - }); |
|
299 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
300 | - \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
301 | - }); |
|
302 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
303 | - \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
304 | - }); |
|
305 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
306 | - \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
307 | - }); |
|
308 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
309 | - \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
310 | - //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
311 | - \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
312 | - }); |
|
313 | - return $groupManager; |
|
314 | - }); |
|
315 | - $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
316 | - |
|
317 | - $this->registerService(Store::class, function (Server $c) { |
|
318 | - $session = $c->getSession(); |
|
319 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
320 | - $tokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
321 | - } else { |
|
322 | - $tokenProvider = null; |
|
323 | - } |
|
324 | - $logger = $c->getLogger(); |
|
325 | - return new Store($session, $logger, $tokenProvider); |
|
326 | - }); |
|
327 | - $this->registerAlias(IStore::class, Store::class); |
|
328 | - $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
329 | - $dbConnection = $c->getDatabaseConnection(); |
|
330 | - return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
331 | - }); |
|
332 | - $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
333 | - $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
|
334 | - $crypto = $c->getCrypto(); |
|
335 | - $config = $c->getConfig(); |
|
336 | - $logger = $c->getLogger(); |
|
337 | - $timeFactory = new TimeFactory(); |
|
338 | - return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
339 | - }); |
|
340 | - $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
|
341 | - |
|
342 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
343 | - $manager = $c->getUserManager(); |
|
344 | - $session = new \OC\Session\Memory(''); |
|
345 | - $timeFactory = new TimeFactory(); |
|
346 | - // Token providers might require a working database. This code |
|
347 | - // might however be called when ownCloud is not yet setup. |
|
348 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
349 | - $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
350 | - } else { |
|
351 | - $defaultTokenProvider = null; |
|
352 | - } |
|
353 | - |
|
354 | - $dispatcher = $c->getEventDispatcher(); |
|
355 | - |
|
356 | - $userSession = new \OC\User\Session( |
|
357 | - $manager, |
|
358 | - $session, |
|
359 | - $timeFactory, |
|
360 | - $defaultTokenProvider, |
|
361 | - $c->getConfig(), |
|
362 | - $c->getSecureRandom(), |
|
363 | - $c->getLockdownManager(), |
|
364 | - $c->getLogger() |
|
365 | - ); |
|
366 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
367 | - \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
368 | - }); |
|
369 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
370 | - /** @var $user \OC\User\User */ |
|
371 | - \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
372 | - }); |
|
373 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
374 | - /** @var $user \OC\User\User */ |
|
375 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
376 | - $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
377 | - }); |
|
378 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
379 | - /** @var $user \OC\User\User */ |
|
380 | - \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
381 | - }); |
|
382 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
383 | - /** @var $user \OC\User\User */ |
|
384 | - \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
385 | - }); |
|
386 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
387 | - /** @var $user \OC\User\User */ |
|
388 | - \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
389 | - }); |
|
390 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
391 | - \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
392 | - }); |
|
393 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
394 | - /** @var $user \OC\User\User */ |
|
395 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
396 | - }); |
|
397 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
398 | - /** @var $user \OC\User\User */ |
|
399 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
400 | - }); |
|
401 | - $userSession->listen('\OC\User', 'logout', function () { |
|
402 | - \OC_Hook::emit('OC_User', 'logout', array()); |
|
403 | - }); |
|
404 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
405 | - /** @var $user \OC\User\User */ |
|
406 | - \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
407 | - $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
|
408 | - }); |
|
409 | - return $userSession; |
|
410 | - }); |
|
411 | - $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
412 | - |
|
413 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
414 | - return new \OC\Authentication\TwoFactorAuth\Manager( |
|
415 | - $c->getAppManager(), |
|
416 | - $c->getSession(), |
|
417 | - $c->getConfig(), |
|
418 | - $c->getActivityManager(), |
|
419 | - $c->getLogger(), |
|
420 | - $c->query(\OC\Authentication\Token\IProvider::class), |
|
421 | - $c->query(ITimeFactory::class), |
|
422 | - $c->query(EventDispatcherInterface::class) |
|
423 | - ); |
|
424 | - }); |
|
425 | - |
|
426 | - $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
427 | - $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
428 | - |
|
429 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
430 | - return new \OC\AllConfig( |
|
431 | - $c->getSystemConfig() |
|
432 | - ); |
|
433 | - }); |
|
434 | - $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
435 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
436 | - |
|
437 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
438 | - return new \OC\SystemConfig($config); |
|
439 | - }); |
|
440 | - |
|
441 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
442 | - return new \OC\AppConfig($c->getDatabaseConnection()); |
|
443 | - }); |
|
444 | - $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
445 | - $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
446 | - |
|
447 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
448 | - return new \OC\L10N\Factory( |
|
449 | - $c->getConfig(), |
|
450 | - $c->getRequest(), |
|
451 | - $c->getUserSession(), |
|
452 | - \OC::$SERVERROOT |
|
453 | - ); |
|
454 | - }); |
|
455 | - $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
456 | - |
|
457 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
458 | - $config = $c->getConfig(); |
|
459 | - $cacheFactory = $c->getMemCacheFactory(); |
|
460 | - $request = $c->getRequest(); |
|
461 | - return new \OC\URLGenerator( |
|
462 | - $config, |
|
463 | - $cacheFactory, |
|
464 | - $request |
|
465 | - ); |
|
466 | - }); |
|
467 | - $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
468 | - |
|
469 | - $this->registerService('AppHelper', function ($c) { |
|
470 | - return new \OC\AppHelper(); |
|
471 | - }); |
|
472 | - $this->registerAlias('AppFetcher', AppFetcher::class); |
|
473 | - $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
474 | - |
|
475 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
476 | - return new Cache\File(); |
|
477 | - }); |
|
478 | - $this->registerAlias('UserCache', \OCP\ICache::class); |
|
479 | - |
|
480 | - $this->registerService(Factory::class, function (Server $c) { |
|
481 | - |
|
482 | - $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
483 | - '\\OC\\Memcache\\ArrayCache', |
|
484 | - '\\OC\\Memcache\\ArrayCache', |
|
485 | - '\\OC\\Memcache\\ArrayCache' |
|
486 | - ); |
|
487 | - $config = $c->getConfig(); |
|
488 | - $request = $c->getRequest(); |
|
489 | - $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
|
490 | - |
|
491 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
492 | - $v = \OC_App::getAppVersions(); |
|
493 | - $v['core'] = implode(',', \OC_Util::getVersion()); |
|
494 | - $version = implode(',', $v); |
|
495 | - $instanceId = \OC_Util::getInstanceId(); |
|
496 | - $path = \OC::$SERVERROOT; |
|
497 | - $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl()); |
|
498 | - return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
499 | - $config->getSystemValue('memcache.local', null), |
|
500 | - $config->getSystemValue('memcache.distributed', null), |
|
501 | - $config->getSystemValue('memcache.locking', null) |
|
502 | - ); |
|
503 | - } |
|
504 | - return $arrayCacheFactory; |
|
505 | - |
|
506 | - }); |
|
507 | - $this->registerAlias('MemCacheFactory', Factory::class); |
|
508 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
509 | - |
|
510 | - $this->registerService('RedisFactory', function (Server $c) { |
|
511 | - $systemConfig = $c->getSystemConfig(); |
|
512 | - return new RedisFactory($systemConfig); |
|
513 | - }); |
|
514 | - |
|
515 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
516 | - return new \OC\Activity\Manager( |
|
517 | - $c->getRequest(), |
|
518 | - $c->getUserSession(), |
|
519 | - $c->getConfig(), |
|
520 | - $c->query(IValidator::class) |
|
521 | - ); |
|
522 | - }); |
|
523 | - $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
524 | - |
|
525 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
526 | - return new \OC\Activity\EventMerger( |
|
527 | - $c->getL10N('lib') |
|
528 | - ); |
|
529 | - }); |
|
530 | - $this->registerAlias(IValidator::class, Validator::class); |
|
531 | - |
|
532 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
533 | - return new AvatarManager( |
|
534 | - $c->query(\OC\User\Manager::class), |
|
535 | - $c->getAppDataDir('avatar'), |
|
536 | - $c->getL10N('lib'), |
|
537 | - $c->getLogger(), |
|
538 | - $c->getConfig() |
|
539 | - ); |
|
540 | - }); |
|
541 | - $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
542 | - |
|
543 | - $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
544 | - |
|
545 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
546 | - $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
547 | - $logger = Log::getLogClass($logType); |
|
548 | - call_user_func(array($logger, 'init')); |
|
549 | - $config = $this->getSystemConfig(); |
|
550 | - $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
551 | - |
|
552 | - return new Log($logger, $config, null, $registry); |
|
553 | - }); |
|
554 | - $this->registerAlias('Logger', \OCP\ILogger::class); |
|
555 | - |
|
556 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
557 | - $config = $c->getConfig(); |
|
558 | - return new \OC\BackgroundJob\JobList( |
|
559 | - $c->getDatabaseConnection(), |
|
560 | - $config, |
|
561 | - new TimeFactory() |
|
562 | - ); |
|
563 | - }); |
|
564 | - $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
565 | - |
|
566 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
567 | - $cacheFactory = $c->getMemCacheFactory(); |
|
568 | - $logger = $c->getLogger(); |
|
569 | - if ($cacheFactory->isAvailableLowLatency()) { |
|
570 | - $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
571 | - } else { |
|
572 | - $router = new \OC\Route\Router($logger); |
|
573 | - } |
|
574 | - return $router; |
|
575 | - }); |
|
576 | - $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
577 | - |
|
578 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
579 | - return new Search(); |
|
580 | - }); |
|
581 | - $this->registerAlias('Search', \OCP\ISearch::class); |
|
582 | - |
|
583 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function ($c) { |
|
584 | - return new \OC\Security\RateLimiting\Limiter( |
|
585 | - $this->getUserSession(), |
|
586 | - $this->getRequest(), |
|
587 | - new \OC\AppFramework\Utility\TimeFactory(), |
|
588 | - $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
589 | - ); |
|
590 | - }); |
|
591 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
592 | - return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
593 | - $this->getMemCacheFactory(), |
|
594 | - new \OC\AppFramework\Utility\TimeFactory() |
|
595 | - ); |
|
596 | - }); |
|
597 | - |
|
598 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
599 | - return new SecureRandom(); |
|
600 | - }); |
|
601 | - $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
602 | - |
|
603 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
604 | - return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
605 | - }); |
|
606 | - $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
607 | - |
|
608 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
609 | - return new Hasher($c->getConfig()); |
|
610 | - }); |
|
611 | - $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
612 | - |
|
613 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
614 | - return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
615 | - }); |
|
616 | - $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
617 | - |
|
618 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
619 | - $systemConfig = $c->getSystemConfig(); |
|
620 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
621 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
622 | - if (!$factory->isValidType($type)) { |
|
623 | - throw new \OC\DatabaseException('Invalid database type'); |
|
624 | - } |
|
625 | - $connectionParams = $factory->createConnectionParams(); |
|
626 | - $connection = $factory->getConnection($type, $connectionParams); |
|
627 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
628 | - return $connection; |
|
629 | - }); |
|
630 | - $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
631 | - |
|
632 | - $this->registerService('HTTPHelper', function (Server $c) { |
|
633 | - $config = $c->getConfig(); |
|
634 | - return new HTTPHelper( |
|
635 | - $config, |
|
636 | - $c->getHTTPClientService() |
|
637 | - ); |
|
638 | - }); |
|
639 | - |
|
640 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
641 | - $user = \OC_User::getUser(); |
|
642 | - $uid = $user ? $user : null; |
|
643 | - return new ClientService( |
|
644 | - $c->getConfig(), |
|
645 | - new \OC\Security\CertificateManager( |
|
646 | - $uid, |
|
647 | - new View(), |
|
648 | - $c->getConfig(), |
|
649 | - $c->getLogger(), |
|
650 | - $c->getSecureRandom() |
|
651 | - ) |
|
652 | - ); |
|
653 | - }); |
|
654 | - $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
655 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
656 | - $eventLogger = new EventLogger(); |
|
657 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
658 | - // In debug mode, module is being activated by default |
|
659 | - $eventLogger->activate(); |
|
660 | - } |
|
661 | - return $eventLogger; |
|
662 | - }); |
|
663 | - $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
664 | - |
|
665 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
666 | - $queryLogger = new QueryLogger(); |
|
667 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
668 | - // In debug mode, module is being activated by default |
|
669 | - $queryLogger->activate(); |
|
670 | - } |
|
671 | - return $queryLogger; |
|
672 | - }); |
|
673 | - $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
674 | - |
|
675 | - $this->registerService(TempManager::class, function (Server $c) { |
|
676 | - return new TempManager( |
|
677 | - $c->getLogger(), |
|
678 | - $c->getConfig() |
|
679 | - ); |
|
680 | - }); |
|
681 | - $this->registerAlias('TempManager', TempManager::class); |
|
682 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
683 | - |
|
684 | - $this->registerService(AppManager::class, function (Server $c) { |
|
685 | - return new \OC\App\AppManager( |
|
686 | - $c->getUserSession(), |
|
687 | - $c->query(\OC\AppConfig::class), |
|
688 | - $c->getGroupManager(), |
|
689 | - $c->getMemCacheFactory(), |
|
690 | - $c->getEventDispatcher() |
|
691 | - ); |
|
692 | - }); |
|
693 | - $this->registerAlias('AppManager', AppManager::class); |
|
694 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
695 | - |
|
696 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
697 | - return new DateTimeZone( |
|
698 | - $c->getConfig(), |
|
699 | - $c->getSession() |
|
700 | - ); |
|
701 | - }); |
|
702 | - $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
703 | - |
|
704 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
705 | - $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
706 | - |
|
707 | - return new DateTimeFormatter( |
|
708 | - $c->getDateTimeZone()->getTimeZone(), |
|
709 | - $c->getL10N('lib', $language) |
|
710 | - ); |
|
711 | - }); |
|
712 | - $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
713 | - |
|
714 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
715 | - $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
716 | - $listener = new UserMountCacheListener($mountCache); |
|
717 | - $listener->listen($c->getUserManager()); |
|
718 | - return $mountCache; |
|
719 | - }); |
|
720 | - $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
721 | - |
|
722 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
723 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
724 | - $mountCache = $c->query('UserMountCache'); |
|
725 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
726 | - |
|
727 | - // builtin providers |
|
728 | - |
|
729 | - $config = $c->getConfig(); |
|
730 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
731 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
732 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
733 | - |
|
734 | - return $manager; |
|
735 | - }); |
|
736 | - $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
737 | - |
|
738 | - $this->registerService('IniWrapper', function ($c) { |
|
739 | - return new IniGetWrapper(); |
|
740 | - }); |
|
741 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
742 | - $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
743 | - if ($busClass) { |
|
744 | - list($app, $class) = explode('::', $busClass, 2); |
|
745 | - if ($c->getAppManager()->isInstalled($app)) { |
|
746 | - \OC_App::loadApp($app); |
|
747 | - return $c->query($class); |
|
748 | - } else { |
|
749 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
750 | - } |
|
751 | - } else { |
|
752 | - $jobList = $c->getJobList(); |
|
753 | - return new CronBus($jobList); |
|
754 | - } |
|
755 | - }); |
|
756 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
757 | - return new TrustedDomainHelper($this->getConfig()); |
|
758 | - }); |
|
759 | - $this->registerService('Throttler', function (Server $c) { |
|
760 | - return new Throttler( |
|
761 | - $c->getDatabaseConnection(), |
|
762 | - new TimeFactory(), |
|
763 | - $c->getLogger(), |
|
764 | - $c->getConfig() |
|
765 | - ); |
|
766 | - }); |
|
767 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
768 | - // IConfig and IAppManager requires a working database. This code |
|
769 | - // might however be called when ownCloud is not yet setup. |
|
770 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
771 | - $config = $c->getConfig(); |
|
772 | - $appManager = $c->getAppManager(); |
|
773 | - } else { |
|
774 | - $config = null; |
|
775 | - $appManager = null; |
|
776 | - } |
|
777 | - |
|
778 | - return new Checker( |
|
779 | - new EnvironmentHelper(), |
|
780 | - new FileAccessHelper(), |
|
781 | - new AppLocator(), |
|
782 | - $config, |
|
783 | - $c->getMemCacheFactory(), |
|
784 | - $appManager, |
|
785 | - $c->getTempManager() |
|
786 | - ); |
|
787 | - }); |
|
788 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
789 | - if (isset($this['urlParams'])) { |
|
790 | - $urlParams = $this['urlParams']; |
|
791 | - } else { |
|
792 | - $urlParams = []; |
|
793 | - } |
|
794 | - |
|
795 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
796 | - && in_array('fakeinput', stream_get_wrappers()) |
|
797 | - ) { |
|
798 | - $stream = 'fakeinput://data'; |
|
799 | - } else { |
|
800 | - $stream = 'php://input'; |
|
801 | - } |
|
802 | - |
|
803 | - return new Request( |
|
804 | - [ |
|
805 | - 'get' => $_GET, |
|
806 | - 'post' => $_POST, |
|
807 | - 'files' => $_FILES, |
|
808 | - 'server' => $_SERVER, |
|
809 | - 'env' => $_ENV, |
|
810 | - 'cookies' => $_COOKIE, |
|
811 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
812 | - ? $_SERVER['REQUEST_METHOD'] |
|
813 | - : null, |
|
814 | - 'urlParams' => $urlParams, |
|
815 | - ], |
|
816 | - $this->getSecureRandom(), |
|
817 | - $this->getConfig(), |
|
818 | - $this->getCsrfTokenManager(), |
|
819 | - $stream |
|
820 | - ); |
|
821 | - }); |
|
822 | - $this->registerAlias('Request', \OCP\IRequest::class); |
|
823 | - |
|
824 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
825 | - return new Mailer( |
|
826 | - $c->getConfig(), |
|
827 | - $c->getLogger(), |
|
828 | - $c->query(Defaults::class), |
|
829 | - $c->getURLGenerator(), |
|
830 | - $c->getL10N('lib') |
|
831 | - ); |
|
832 | - }); |
|
833 | - $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
834 | - |
|
835 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
836 | - $config = $c->getConfig(); |
|
837 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
838 | - if (is_null($factoryClass)) { |
|
839 | - throw new \Exception('ldapProviderFactory not set'); |
|
840 | - } |
|
841 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
842 | - $factory = new $factoryClass($this); |
|
843 | - return $factory->getLDAPProvider(); |
|
844 | - }); |
|
845 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
846 | - $ini = $c->getIniWrapper(); |
|
847 | - $config = $c->getConfig(); |
|
848 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
849 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
850 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
851 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
852 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
853 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
854 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
855 | - } |
|
856 | - return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
857 | - } |
|
858 | - return new NoopLockingProvider(); |
|
859 | - }); |
|
860 | - $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
861 | - |
|
862 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
863 | - return new \OC\Files\Mount\Manager(); |
|
864 | - }); |
|
865 | - $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
866 | - |
|
867 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
868 | - return new \OC\Files\Type\Detection( |
|
869 | - $c->getURLGenerator(), |
|
870 | - \OC::$configDir, |
|
871 | - \OC::$SERVERROOT . '/resources/config/' |
|
872 | - ); |
|
873 | - }); |
|
874 | - $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
875 | - |
|
876 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
877 | - return new \OC\Files\Type\Loader( |
|
878 | - $c->getDatabaseConnection() |
|
879 | - ); |
|
880 | - }); |
|
881 | - $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
882 | - $this->registerService(BundleFetcher::class, function () { |
|
883 | - return new BundleFetcher($this->getL10N('lib')); |
|
884 | - }); |
|
885 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
886 | - return new Manager( |
|
887 | - $c->query(IValidator::class) |
|
888 | - ); |
|
889 | - }); |
|
890 | - $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
891 | - |
|
892 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
893 | - $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
894 | - $manager->registerCapability(function () use ($c) { |
|
895 | - return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
896 | - }); |
|
897 | - $manager->registerCapability(function () use ($c) { |
|
898 | - return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
899 | - }); |
|
900 | - return $manager; |
|
901 | - }); |
|
902 | - $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
903 | - |
|
904 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
905 | - $config = $c->getConfig(); |
|
906 | - $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
|
907 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
908 | - $factory = new $factoryClass($this); |
|
909 | - $manager = $factory->getManager(); |
|
910 | - |
|
911 | - $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
912 | - $manager = $c->getUserManager(); |
|
913 | - $user = $manager->get($id); |
|
914 | - if(is_null($user)) { |
|
915 | - $l = $c->getL10N('core'); |
|
916 | - $displayName = $l->t('Unknown user'); |
|
917 | - } else { |
|
918 | - $displayName = $user->getDisplayName(); |
|
919 | - } |
|
920 | - return $displayName; |
|
921 | - }); |
|
922 | - |
|
923 | - return $manager; |
|
924 | - }); |
|
925 | - $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
926 | - |
|
927 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
928 | - /* |
|
149 | + /** @var string */ |
|
150 | + private $webRoot; |
|
151 | + |
|
152 | + /** |
|
153 | + * @param string $webRoot |
|
154 | + * @param \OC\Config $config |
|
155 | + */ |
|
156 | + public function __construct($webRoot, \OC\Config $config) { |
|
157 | + parent::__construct(); |
|
158 | + $this->webRoot = $webRoot; |
|
159 | + |
|
160 | + $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
161 | + return $c; |
|
162 | + }); |
|
163 | + |
|
164 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
165 | + $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
166 | + |
|
167 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
168 | + $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
169 | + |
|
170 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
171 | + |
|
172 | + |
|
173 | + $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
174 | + return new PreviewManager( |
|
175 | + $c->getConfig(), |
|
176 | + $c->getRootFolder(), |
|
177 | + $c->getAppDataDir('preview'), |
|
178 | + $c->getEventDispatcher(), |
|
179 | + $c->getSession()->get('user_id') |
|
180 | + ); |
|
181 | + }); |
|
182 | + $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
183 | + |
|
184 | + $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
185 | + return new \OC\Preview\Watcher( |
|
186 | + $c->getAppDataDir('preview') |
|
187 | + ); |
|
188 | + }); |
|
189 | + |
|
190 | + $this->registerService('EncryptionManager', function (Server $c) { |
|
191 | + $view = new View(); |
|
192 | + $util = new Encryption\Util( |
|
193 | + $view, |
|
194 | + $c->getUserManager(), |
|
195 | + $c->getGroupManager(), |
|
196 | + $c->getConfig() |
|
197 | + ); |
|
198 | + return new Encryption\Manager( |
|
199 | + $c->getConfig(), |
|
200 | + $c->getLogger(), |
|
201 | + $c->getL10N('core'), |
|
202 | + new View(), |
|
203 | + $util, |
|
204 | + new ArrayCache() |
|
205 | + ); |
|
206 | + }); |
|
207 | + |
|
208 | + $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
209 | + $util = new Encryption\Util( |
|
210 | + new View(), |
|
211 | + $c->getUserManager(), |
|
212 | + $c->getGroupManager(), |
|
213 | + $c->getConfig() |
|
214 | + ); |
|
215 | + return new Encryption\File( |
|
216 | + $util, |
|
217 | + $c->getRootFolder(), |
|
218 | + $c->getShareManager() |
|
219 | + ); |
|
220 | + }); |
|
221 | + |
|
222 | + $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
223 | + $view = new View(); |
|
224 | + $util = new Encryption\Util( |
|
225 | + $view, |
|
226 | + $c->getUserManager(), |
|
227 | + $c->getGroupManager(), |
|
228 | + $c->getConfig() |
|
229 | + ); |
|
230 | + |
|
231 | + return new Encryption\Keys\Storage($view, $util); |
|
232 | + }); |
|
233 | + $this->registerService('TagMapper', function (Server $c) { |
|
234 | + return new TagMapper($c->getDatabaseConnection()); |
|
235 | + }); |
|
236 | + |
|
237 | + $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
238 | + $tagMapper = $c->query('TagMapper'); |
|
239 | + return new TagManager($tagMapper, $c->getUserSession()); |
|
240 | + }); |
|
241 | + $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
242 | + |
|
243 | + $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
244 | + $config = $c->getConfig(); |
|
245 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
|
246 | + return new $factoryClass($this); |
|
247 | + }); |
|
248 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
249 | + return $c->query('SystemTagManagerFactory')->getManager(); |
|
250 | + }); |
|
251 | + $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
252 | + |
|
253 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
254 | + return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
255 | + }); |
|
256 | + $this->registerService('RootFolder', function (Server $c) { |
|
257 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
258 | + $view = new View(); |
|
259 | + $root = new Root( |
|
260 | + $manager, |
|
261 | + $view, |
|
262 | + null, |
|
263 | + $c->getUserMountCache(), |
|
264 | + $this->getLogger(), |
|
265 | + $this->getUserManager() |
|
266 | + ); |
|
267 | + $connector = new HookConnector($root, $view); |
|
268 | + $connector->viewToNode(); |
|
269 | + |
|
270 | + $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
271 | + $previewConnector->connectWatcher(); |
|
272 | + |
|
273 | + return $root; |
|
274 | + }); |
|
275 | + $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
276 | + |
|
277 | + $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
278 | + return new LazyRoot(function () use ($c) { |
|
279 | + return $c->query('RootFolder'); |
|
280 | + }); |
|
281 | + }); |
|
282 | + $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
283 | + |
|
284 | + $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
285 | + $config = $c->getConfig(); |
|
286 | + return new \OC\User\Manager($config); |
|
287 | + }); |
|
288 | + $this->registerAlias('UserManager', \OC\User\Manager::class); |
|
289 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
290 | + |
|
291 | + $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
292 | + $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
293 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
294 | + \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
295 | + }); |
|
296 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
297 | + \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
298 | + }); |
|
299 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
300 | + \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
301 | + }); |
|
302 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
303 | + \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
304 | + }); |
|
305 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
306 | + \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
307 | + }); |
|
308 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
309 | + \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
310 | + //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
311 | + \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
312 | + }); |
|
313 | + return $groupManager; |
|
314 | + }); |
|
315 | + $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
316 | + |
|
317 | + $this->registerService(Store::class, function (Server $c) { |
|
318 | + $session = $c->getSession(); |
|
319 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
320 | + $tokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
321 | + } else { |
|
322 | + $tokenProvider = null; |
|
323 | + } |
|
324 | + $logger = $c->getLogger(); |
|
325 | + return new Store($session, $logger, $tokenProvider); |
|
326 | + }); |
|
327 | + $this->registerAlias(IStore::class, Store::class); |
|
328 | + $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
329 | + $dbConnection = $c->getDatabaseConnection(); |
|
330 | + return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
331 | + }); |
|
332 | + $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
333 | + $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
|
334 | + $crypto = $c->getCrypto(); |
|
335 | + $config = $c->getConfig(); |
|
336 | + $logger = $c->getLogger(); |
|
337 | + $timeFactory = new TimeFactory(); |
|
338 | + return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
339 | + }); |
|
340 | + $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
|
341 | + |
|
342 | + $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
343 | + $manager = $c->getUserManager(); |
|
344 | + $session = new \OC\Session\Memory(''); |
|
345 | + $timeFactory = new TimeFactory(); |
|
346 | + // Token providers might require a working database. This code |
|
347 | + // might however be called when ownCloud is not yet setup. |
|
348 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
349 | + $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
350 | + } else { |
|
351 | + $defaultTokenProvider = null; |
|
352 | + } |
|
353 | + |
|
354 | + $dispatcher = $c->getEventDispatcher(); |
|
355 | + |
|
356 | + $userSession = new \OC\User\Session( |
|
357 | + $manager, |
|
358 | + $session, |
|
359 | + $timeFactory, |
|
360 | + $defaultTokenProvider, |
|
361 | + $c->getConfig(), |
|
362 | + $c->getSecureRandom(), |
|
363 | + $c->getLockdownManager(), |
|
364 | + $c->getLogger() |
|
365 | + ); |
|
366 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
367 | + \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
368 | + }); |
|
369 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
370 | + /** @var $user \OC\User\User */ |
|
371 | + \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
372 | + }); |
|
373 | + $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
374 | + /** @var $user \OC\User\User */ |
|
375 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
376 | + $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
377 | + }); |
|
378 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
379 | + /** @var $user \OC\User\User */ |
|
380 | + \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
381 | + }); |
|
382 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
383 | + /** @var $user \OC\User\User */ |
|
384 | + \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
385 | + }); |
|
386 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
387 | + /** @var $user \OC\User\User */ |
|
388 | + \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
389 | + }); |
|
390 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
391 | + \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
392 | + }); |
|
393 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
394 | + /** @var $user \OC\User\User */ |
|
395 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
396 | + }); |
|
397 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
398 | + /** @var $user \OC\User\User */ |
|
399 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
400 | + }); |
|
401 | + $userSession->listen('\OC\User', 'logout', function () { |
|
402 | + \OC_Hook::emit('OC_User', 'logout', array()); |
|
403 | + }); |
|
404 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
405 | + /** @var $user \OC\User\User */ |
|
406 | + \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
407 | + $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
|
408 | + }); |
|
409 | + return $userSession; |
|
410 | + }); |
|
411 | + $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
412 | + |
|
413 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
414 | + return new \OC\Authentication\TwoFactorAuth\Manager( |
|
415 | + $c->getAppManager(), |
|
416 | + $c->getSession(), |
|
417 | + $c->getConfig(), |
|
418 | + $c->getActivityManager(), |
|
419 | + $c->getLogger(), |
|
420 | + $c->query(\OC\Authentication\Token\IProvider::class), |
|
421 | + $c->query(ITimeFactory::class), |
|
422 | + $c->query(EventDispatcherInterface::class) |
|
423 | + ); |
|
424 | + }); |
|
425 | + |
|
426 | + $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
427 | + $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
428 | + |
|
429 | + $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
430 | + return new \OC\AllConfig( |
|
431 | + $c->getSystemConfig() |
|
432 | + ); |
|
433 | + }); |
|
434 | + $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
435 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
436 | + |
|
437 | + $this->registerService('SystemConfig', function ($c) use ($config) { |
|
438 | + return new \OC\SystemConfig($config); |
|
439 | + }); |
|
440 | + |
|
441 | + $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
442 | + return new \OC\AppConfig($c->getDatabaseConnection()); |
|
443 | + }); |
|
444 | + $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
445 | + $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
446 | + |
|
447 | + $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
448 | + return new \OC\L10N\Factory( |
|
449 | + $c->getConfig(), |
|
450 | + $c->getRequest(), |
|
451 | + $c->getUserSession(), |
|
452 | + \OC::$SERVERROOT |
|
453 | + ); |
|
454 | + }); |
|
455 | + $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
456 | + |
|
457 | + $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
458 | + $config = $c->getConfig(); |
|
459 | + $cacheFactory = $c->getMemCacheFactory(); |
|
460 | + $request = $c->getRequest(); |
|
461 | + return new \OC\URLGenerator( |
|
462 | + $config, |
|
463 | + $cacheFactory, |
|
464 | + $request |
|
465 | + ); |
|
466 | + }); |
|
467 | + $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
468 | + |
|
469 | + $this->registerService('AppHelper', function ($c) { |
|
470 | + return new \OC\AppHelper(); |
|
471 | + }); |
|
472 | + $this->registerAlias('AppFetcher', AppFetcher::class); |
|
473 | + $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
474 | + |
|
475 | + $this->registerService(\OCP\ICache::class, function ($c) { |
|
476 | + return new Cache\File(); |
|
477 | + }); |
|
478 | + $this->registerAlias('UserCache', \OCP\ICache::class); |
|
479 | + |
|
480 | + $this->registerService(Factory::class, function (Server $c) { |
|
481 | + |
|
482 | + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
483 | + '\\OC\\Memcache\\ArrayCache', |
|
484 | + '\\OC\\Memcache\\ArrayCache', |
|
485 | + '\\OC\\Memcache\\ArrayCache' |
|
486 | + ); |
|
487 | + $config = $c->getConfig(); |
|
488 | + $request = $c->getRequest(); |
|
489 | + $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
|
490 | + |
|
491 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
492 | + $v = \OC_App::getAppVersions(); |
|
493 | + $v['core'] = implode(',', \OC_Util::getVersion()); |
|
494 | + $version = implode(',', $v); |
|
495 | + $instanceId = \OC_Util::getInstanceId(); |
|
496 | + $path = \OC::$SERVERROOT; |
|
497 | + $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl()); |
|
498 | + return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
499 | + $config->getSystemValue('memcache.local', null), |
|
500 | + $config->getSystemValue('memcache.distributed', null), |
|
501 | + $config->getSystemValue('memcache.locking', null) |
|
502 | + ); |
|
503 | + } |
|
504 | + return $arrayCacheFactory; |
|
505 | + |
|
506 | + }); |
|
507 | + $this->registerAlias('MemCacheFactory', Factory::class); |
|
508 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
509 | + |
|
510 | + $this->registerService('RedisFactory', function (Server $c) { |
|
511 | + $systemConfig = $c->getSystemConfig(); |
|
512 | + return new RedisFactory($systemConfig); |
|
513 | + }); |
|
514 | + |
|
515 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
516 | + return new \OC\Activity\Manager( |
|
517 | + $c->getRequest(), |
|
518 | + $c->getUserSession(), |
|
519 | + $c->getConfig(), |
|
520 | + $c->query(IValidator::class) |
|
521 | + ); |
|
522 | + }); |
|
523 | + $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
524 | + |
|
525 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
526 | + return new \OC\Activity\EventMerger( |
|
527 | + $c->getL10N('lib') |
|
528 | + ); |
|
529 | + }); |
|
530 | + $this->registerAlias(IValidator::class, Validator::class); |
|
531 | + |
|
532 | + $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
533 | + return new AvatarManager( |
|
534 | + $c->query(\OC\User\Manager::class), |
|
535 | + $c->getAppDataDir('avatar'), |
|
536 | + $c->getL10N('lib'), |
|
537 | + $c->getLogger(), |
|
538 | + $c->getConfig() |
|
539 | + ); |
|
540 | + }); |
|
541 | + $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
542 | + |
|
543 | + $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
544 | + |
|
545 | + $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
546 | + $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
547 | + $logger = Log::getLogClass($logType); |
|
548 | + call_user_func(array($logger, 'init')); |
|
549 | + $config = $this->getSystemConfig(); |
|
550 | + $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
551 | + |
|
552 | + return new Log($logger, $config, null, $registry); |
|
553 | + }); |
|
554 | + $this->registerAlias('Logger', \OCP\ILogger::class); |
|
555 | + |
|
556 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
557 | + $config = $c->getConfig(); |
|
558 | + return new \OC\BackgroundJob\JobList( |
|
559 | + $c->getDatabaseConnection(), |
|
560 | + $config, |
|
561 | + new TimeFactory() |
|
562 | + ); |
|
563 | + }); |
|
564 | + $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
565 | + |
|
566 | + $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
567 | + $cacheFactory = $c->getMemCacheFactory(); |
|
568 | + $logger = $c->getLogger(); |
|
569 | + if ($cacheFactory->isAvailableLowLatency()) { |
|
570 | + $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
571 | + } else { |
|
572 | + $router = new \OC\Route\Router($logger); |
|
573 | + } |
|
574 | + return $router; |
|
575 | + }); |
|
576 | + $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
577 | + |
|
578 | + $this->registerService(\OCP\ISearch::class, function ($c) { |
|
579 | + return new Search(); |
|
580 | + }); |
|
581 | + $this->registerAlias('Search', \OCP\ISearch::class); |
|
582 | + |
|
583 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function ($c) { |
|
584 | + return new \OC\Security\RateLimiting\Limiter( |
|
585 | + $this->getUserSession(), |
|
586 | + $this->getRequest(), |
|
587 | + new \OC\AppFramework\Utility\TimeFactory(), |
|
588 | + $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
589 | + ); |
|
590 | + }); |
|
591 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
592 | + return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
593 | + $this->getMemCacheFactory(), |
|
594 | + new \OC\AppFramework\Utility\TimeFactory() |
|
595 | + ); |
|
596 | + }); |
|
597 | + |
|
598 | + $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
599 | + return new SecureRandom(); |
|
600 | + }); |
|
601 | + $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
602 | + |
|
603 | + $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
604 | + return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
605 | + }); |
|
606 | + $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
607 | + |
|
608 | + $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
609 | + return new Hasher($c->getConfig()); |
|
610 | + }); |
|
611 | + $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
612 | + |
|
613 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
614 | + return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
615 | + }); |
|
616 | + $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
617 | + |
|
618 | + $this->registerService(IDBConnection::class, function (Server $c) { |
|
619 | + $systemConfig = $c->getSystemConfig(); |
|
620 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
621 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
622 | + if (!$factory->isValidType($type)) { |
|
623 | + throw new \OC\DatabaseException('Invalid database type'); |
|
624 | + } |
|
625 | + $connectionParams = $factory->createConnectionParams(); |
|
626 | + $connection = $factory->getConnection($type, $connectionParams); |
|
627 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
628 | + return $connection; |
|
629 | + }); |
|
630 | + $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
631 | + |
|
632 | + $this->registerService('HTTPHelper', function (Server $c) { |
|
633 | + $config = $c->getConfig(); |
|
634 | + return new HTTPHelper( |
|
635 | + $config, |
|
636 | + $c->getHTTPClientService() |
|
637 | + ); |
|
638 | + }); |
|
639 | + |
|
640 | + $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
641 | + $user = \OC_User::getUser(); |
|
642 | + $uid = $user ? $user : null; |
|
643 | + return new ClientService( |
|
644 | + $c->getConfig(), |
|
645 | + new \OC\Security\CertificateManager( |
|
646 | + $uid, |
|
647 | + new View(), |
|
648 | + $c->getConfig(), |
|
649 | + $c->getLogger(), |
|
650 | + $c->getSecureRandom() |
|
651 | + ) |
|
652 | + ); |
|
653 | + }); |
|
654 | + $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
655 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
656 | + $eventLogger = new EventLogger(); |
|
657 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
658 | + // In debug mode, module is being activated by default |
|
659 | + $eventLogger->activate(); |
|
660 | + } |
|
661 | + return $eventLogger; |
|
662 | + }); |
|
663 | + $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
664 | + |
|
665 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
666 | + $queryLogger = new QueryLogger(); |
|
667 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
668 | + // In debug mode, module is being activated by default |
|
669 | + $queryLogger->activate(); |
|
670 | + } |
|
671 | + return $queryLogger; |
|
672 | + }); |
|
673 | + $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
674 | + |
|
675 | + $this->registerService(TempManager::class, function (Server $c) { |
|
676 | + return new TempManager( |
|
677 | + $c->getLogger(), |
|
678 | + $c->getConfig() |
|
679 | + ); |
|
680 | + }); |
|
681 | + $this->registerAlias('TempManager', TempManager::class); |
|
682 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
683 | + |
|
684 | + $this->registerService(AppManager::class, function (Server $c) { |
|
685 | + return new \OC\App\AppManager( |
|
686 | + $c->getUserSession(), |
|
687 | + $c->query(\OC\AppConfig::class), |
|
688 | + $c->getGroupManager(), |
|
689 | + $c->getMemCacheFactory(), |
|
690 | + $c->getEventDispatcher() |
|
691 | + ); |
|
692 | + }); |
|
693 | + $this->registerAlias('AppManager', AppManager::class); |
|
694 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
695 | + |
|
696 | + $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
697 | + return new DateTimeZone( |
|
698 | + $c->getConfig(), |
|
699 | + $c->getSession() |
|
700 | + ); |
|
701 | + }); |
|
702 | + $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
703 | + |
|
704 | + $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
705 | + $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
706 | + |
|
707 | + return new DateTimeFormatter( |
|
708 | + $c->getDateTimeZone()->getTimeZone(), |
|
709 | + $c->getL10N('lib', $language) |
|
710 | + ); |
|
711 | + }); |
|
712 | + $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
713 | + |
|
714 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
715 | + $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
716 | + $listener = new UserMountCacheListener($mountCache); |
|
717 | + $listener->listen($c->getUserManager()); |
|
718 | + return $mountCache; |
|
719 | + }); |
|
720 | + $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
721 | + |
|
722 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
723 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
724 | + $mountCache = $c->query('UserMountCache'); |
|
725 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
726 | + |
|
727 | + // builtin providers |
|
728 | + |
|
729 | + $config = $c->getConfig(); |
|
730 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
731 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
732 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
733 | + |
|
734 | + return $manager; |
|
735 | + }); |
|
736 | + $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
737 | + |
|
738 | + $this->registerService('IniWrapper', function ($c) { |
|
739 | + return new IniGetWrapper(); |
|
740 | + }); |
|
741 | + $this->registerService('AsyncCommandBus', function (Server $c) { |
|
742 | + $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
743 | + if ($busClass) { |
|
744 | + list($app, $class) = explode('::', $busClass, 2); |
|
745 | + if ($c->getAppManager()->isInstalled($app)) { |
|
746 | + \OC_App::loadApp($app); |
|
747 | + return $c->query($class); |
|
748 | + } else { |
|
749 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
750 | + } |
|
751 | + } else { |
|
752 | + $jobList = $c->getJobList(); |
|
753 | + return new CronBus($jobList); |
|
754 | + } |
|
755 | + }); |
|
756 | + $this->registerService('TrustedDomainHelper', function ($c) { |
|
757 | + return new TrustedDomainHelper($this->getConfig()); |
|
758 | + }); |
|
759 | + $this->registerService('Throttler', function (Server $c) { |
|
760 | + return new Throttler( |
|
761 | + $c->getDatabaseConnection(), |
|
762 | + new TimeFactory(), |
|
763 | + $c->getLogger(), |
|
764 | + $c->getConfig() |
|
765 | + ); |
|
766 | + }); |
|
767 | + $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
768 | + // IConfig and IAppManager requires a working database. This code |
|
769 | + // might however be called when ownCloud is not yet setup. |
|
770 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
771 | + $config = $c->getConfig(); |
|
772 | + $appManager = $c->getAppManager(); |
|
773 | + } else { |
|
774 | + $config = null; |
|
775 | + $appManager = null; |
|
776 | + } |
|
777 | + |
|
778 | + return new Checker( |
|
779 | + new EnvironmentHelper(), |
|
780 | + new FileAccessHelper(), |
|
781 | + new AppLocator(), |
|
782 | + $config, |
|
783 | + $c->getMemCacheFactory(), |
|
784 | + $appManager, |
|
785 | + $c->getTempManager() |
|
786 | + ); |
|
787 | + }); |
|
788 | + $this->registerService(\OCP\IRequest::class, function ($c) { |
|
789 | + if (isset($this['urlParams'])) { |
|
790 | + $urlParams = $this['urlParams']; |
|
791 | + } else { |
|
792 | + $urlParams = []; |
|
793 | + } |
|
794 | + |
|
795 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
796 | + && in_array('fakeinput', stream_get_wrappers()) |
|
797 | + ) { |
|
798 | + $stream = 'fakeinput://data'; |
|
799 | + } else { |
|
800 | + $stream = 'php://input'; |
|
801 | + } |
|
802 | + |
|
803 | + return new Request( |
|
804 | + [ |
|
805 | + 'get' => $_GET, |
|
806 | + 'post' => $_POST, |
|
807 | + 'files' => $_FILES, |
|
808 | + 'server' => $_SERVER, |
|
809 | + 'env' => $_ENV, |
|
810 | + 'cookies' => $_COOKIE, |
|
811 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
812 | + ? $_SERVER['REQUEST_METHOD'] |
|
813 | + : null, |
|
814 | + 'urlParams' => $urlParams, |
|
815 | + ], |
|
816 | + $this->getSecureRandom(), |
|
817 | + $this->getConfig(), |
|
818 | + $this->getCsrfTokenManager(), |
|
819 | + $stream |
|
820 | + ); |
|
821 | + }); |
|
822 | + $this->registerAlias('Request', \OCP\IRequest::class); |
|
823 | + |
|
824 | + $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
825 | + return new Mailer( |
|
826 | + $c->getConfig(), |
|
827 | + $c->getLogger(), |
|
828 | + $c->query(Defaults::class), |
|
829 | + $c->getURLGenerator(), |
|
830 | + $c->getL10N('lib') |
|
831 | + ); |
|
832 | + }); |
|
833 | + $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
834 | + |
|
835 | + $this->registerService('LDAPProvider', function (Server $c) { |
|
836 | + $config = $c->getConfig(); |
|
837 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
838 | + if (is_null($factoryClass)) { |
|
839 | + throw new \Exception('ldapProviderFactory not set'); |
|
840 | + } |
|
841 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
842 | + $factory = new $factoryClass($this); |
|
843 | + return $factory->getLDAPProvider(); |
|
844 | + }); |
|
845 | + $this->registerService(ILockingProvider::class, function (Server $c) { |
|
846 | + $ini = $c->getIniWrapper(); |
|
847 | + $config = $c->getConfig(); |
|
848 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
849 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
850 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
851 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
852 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
853 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
854 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
855 | + } |
|
856 | + return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
857 | + } |
|
858 | + return new NoopLockingProvider(); |
|
859 | + }); |
|
860 | + $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
861 | + |
|
862 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
863 | + return new \OC\Files\Mount\Manager(); |
|
864 | + }); |
|
865 | + $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
866 | + |
|
867 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
868 | + return new \OC\Files\Type\Detection( |
|
869 | + $c->getURLGenerator(), |
|
870 | + \OC::$configDir, |
|
871 | + \OC::$SERVERROOT . '/resources/config/' |
|
872 | + ); |
|
873 | + }); |
|
874 | + $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
875 | + |
|
876 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
877 | + return new \OC\Files\Type\Loader( |
|
878 | + $c->getDatabaseConnection() |
|
879 | + ); |
|
880 | + }); |
|
881 | + $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
882 | + $this->registerService(BundleFetcher::class, function () { |
|
883 | + return new BundleFetcher($this->getL10N('lib')); |
|
884 | + }); |
|
885 | + $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
886 | + return new Manager( |
|
887 | + $c->query(IValidator::class) |
|
888 | + ); |
|
889 | + }); |
|
890 | + $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
891 | + |
|
892 | + $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
893 | + $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
894 | + $manager->registerCapability(function () use ($c) { |
|
895 | + return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
896 | + }); |
|
897 | + $manager->registerCapability(function () use ($c) { |
|
898 | + return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
899 | + }); |
|
900 | + return $manager; |
|
901 | + }); |
|
902 | + $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
903 | + |
|
904 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
905 | + $config = $c->getConfig(); |
|
906 | + $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
|
907 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
908 | + $factory = new $factoryClass($this); |
|
909 | + $manager = $factory->getManager(); |
|
910 | + |
|
911 | + $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
912 | + $manager = $c->getUserManager(); |
|
913 | + $user = $manager->get($id); |
|
914 | + if(is_null($user)) { |
|
915 | + $l = $c->getL10N('core'); |
|
916 | + $displayName = $l->t('Unknown user'); |
|
917 | + } else { |
|
918 | + $displayName = $user->getDisplayName(); |
|
919 | + } |
|
920 | + return $displayName; |
|
921 | + }); |
|
922 | + |
|
923 | + return $manager; |
|
924 | + }); |
|
925 | + $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
926 | + |
|
927 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
928 | + /* |
|
929 | 929 | * Dark magic for autoloader. |
930 | 930 | * If we do a class_exists it will try to load the class which will |
931 | 931 | * make composer cache the result. Resulting in errors when enabling |
932 | 932 | * the theming app. |
933 | 933 | */ |
934 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
935 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
936 | - $classExists = true; |
|
937 | - } else { |
|
938 | - $classExists = false; |
|
939 | - } |
|
940 | - |
|
941 | - if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
942 | - return new ThemingDefaults( |
|
943 | - $c->getConfig(), |
|
944 | - $c->getL10N('theming'), |
|
945 | - $c->getURLGenerator(), |
|
946 | - $c->getAppDataDir('theming'), |
|
947 | - $c->getMemCacheFactory(), |
|
948 | - new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming')), |
|
949 | - $this->getAppManager() |
|
950 | - ); |
|
951 | - } |
|
952 | - return new \OC_Defaults(); |
|
953 | - }); |
|
954 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
955 | - /** @var Factory $cacheFactory */ |
|
956 | - $cacheFactory = $c->query(Factory::class); |
|
957 | - return new SCSSCacher( |
|
958 | - $c->getLogger(), |
|
959 | - $c->query(\OC\Files\AppData\Factory::class), |
|
960 | - $c->getURLGenerator(), |
|
961 | - $c->getConfig(), |
|
962 | - $c->getThemingDefaults(), |
|
963 | - \OC::$SERVERROOT, |
|
964 | - $cacheFactory->createDistributed('SCSS') |
|
965 | - ); |
|
966 | - }); |
|
967 | - $this->registerService(EventDispatcher::class, function () { |
|
968 | - return new EventDispatcher(); |
|
969 | - }); |
|
970 | - $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
971 | - $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
972 | - |
|
973 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
974 | - // FIXME: Instantiiated here due to cyclic dependency |
|
975 | - $request = new Request( |
|
976 | - [ |
|
977 | - 'get' => $_GET, |
|
978 | - 'post' => $_POST, |
|
979 | - 'files' => $_FILES, |
|
980 | - 'server' => $_SERVER, |
|
981 | - 'env' => $_ENV, |
|
982 | - 'cookies' => $_COOKIE, |
|
983 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
984 | - ? $_SERVER['REQUEST_METHOD'] |
|
985 | - : null, |
|
986 | - ], |
|
987 | - $c->getSecureRandom(), |
|
988 | - $c->getConfig() |
|
989 | - ); |
|
990 | - |
|
991 | - return new CryptoWrapper( |
|
992 | - $c->getConfig(), |
|
993 | - $c->getCrypto(), |
|
994 | - $c->getSecureRandom(), |
|
995 | - $request |
|
996 | - ); |
|
997 | - }); |
|
998 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
999 | - $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
1000 | - |
|
1001 | - return new CsrfTokenManager( |
|
1002 | - $tokenGenerator, |
|
1003 | - $c->query(SessionStorage::class) |
|
1004 | - ); |
|
1005 | - }); |
|
1006 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
1007 | - return new SessionStorage($c->getSession()); |
|
1008 | - }); |
|
1009 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
1010 | - return new ContentSecurityPolicyManager(); |
|
1011 | - }); |
|
1012 | - $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
1013 | - |
|
1014 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1015 | - return new ContentSecurityPolicyNonceManager( |
|
1016 | - $c->getCsrfTokenManager(), |
|
1017 | - $c->getRequest() |
|
1018 | - ); |
|
1019 | - }); |
|
1020 | - |
|
1021 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1022 | - $config = $c->getConfig(); |
|
1023 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
|
1024 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
1025 | - $factory = new $factoryClass($this); |
|
1026 | - |
|
1027 | - $manager = new \OC\Share20\Manager( |
|
1028 | - $c->getLogger(), |
|
1029 | - $c->getConfig(), |
|
1030 | - $c->getSecureRandom(), |
|
1031 | - $c->getHasher(), |
|
1032 | - $c->getMountManager(), |
|
1033 | - $c->getGroupManager(), |
|
1034 | - $c->getL10N('lib'), |
|
1035 | - $c->getL10NFactory(), |
|
1036 | - $factory, |
|
1037 | - $c->getUserManager(), |
|
1038 | - $c->getLazyRootFolder(), |
|
1039 | - $c->getEventDispatcher(), |
|
1040 | - $c->getMailer(), |
|
1041 | - $c->getURLGenerator(), |
|
1042 | - $c->getThemingDefaults() |
|
1043 | - ); |
|
1044 | - |
|
1045 | - return $manager; |
|
1046 | - }); |
|
1047 | - $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
1048 | - |
|
1049 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1050 | - $instance = new Collaboration\Collaborators\Search($c); |
|
1051 | - |
|
1052 | - // register default plugins |
|
1053 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1054 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1055 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1056 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1057 | - |
|
1058 | - return $instance; |
|
1059 | - }); |
|
1060 | - $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1061 | - |
|
1062 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1063 | - |
|
1064 | - $this->registerService('SettingsManager', function (Server $c) { |
|
1065 | - $manager = new \OC\Settings\Manager( |
|
1066 | - $c->getLogger(), |
|
1067 | - $c->getDatabaseConnection(), |
|
1068 | - $c->getL10N('lib'), |
|
1069 | - $c->getConfig(), |
|
1070 | - $c->getEncryptionManager(), |
|
1071 | - $c->getUserManager(), |
|
1072 | - $c->getLockingProvider(), |
|
1073 | - $c->getRequest(), |
|
1074 | - $c->getURLGenerator(), |
|
1075 | - $c->query(AccountManager::class), |
|
1076 | - $c->getGroupManager(), |
|
1077 | - $c->getL10NFactory(), |
|
1078 | - $c->getAppManager() |
|
1079 | - ); |
|
1080 | - return $manager; |
|
1081 | - }); |
|
1082 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1083 | - return new \OC\Files\AppData\Factory( |
|
1084 | - $c->getRootFolder(), |
|
1085 | - $c->getSystemConfig() |
|
1086 | - ); |
|
1087 | - }); |
|
1088 | - |
|
1089 | - $this->registerService('LockdownManager', function (Server $c) { |
|
1090 | - return new LockdownManager(function () use ($c) { |
|
1091 | - return $c->getSession(); |
|
1092 | - }); |
|
1093 | - }); |
|
1094 | - |
|
1095 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1096 | - return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1097 | - }); |
|
1098 | - |
|
1099 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1100 | - return new CloudIdManager(); |
|
1101 | - }); |
|
1102 | - |
|
1103 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1104 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1105 | - |
|
1106 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1107 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1108 | - |
|
1109 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1110 | - return new Defaults( |
|
1111 | - $c->getThemingDefaults() |
|
1112 | - ); |
|
1113 | - }); |
|
1114 | - $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1115 | - |
|
1116 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1117 | - return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1118 | - }); |
|
1119 | - |
|
1120 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
1121 | - return new ShareHelper( |
|
1122 | - $c->query(\OCP\Share\IManager::class) |
|
1123 | - ); |
|
1124 | - }); |
|
1125 | - |
|
1126 | - $this->registerService(Installer::class, function(Server $c) { |
|
1127 | - return new Installer( |
|
1128 | - $c->getAppFetcher(), |
|
1129 | - $c->getHTTPClientService(), |
|
1130 | - $c->getTempManager(), |
|
1131 | - $c->getLogger(), |
|
1132 | - $c->getConfig() |
|
1133 | - ); |
|
1134 | - }); |
|
1135 | - |
|
1136 | - $this->registerService(IApiFactory::class, function(Server $c) { |
|
1137 | - return new ApiFactory($c->getHTTPClientService()); |
|
1138 | - }); |
|
1139 | - |
|
1140 | - $this->registerService(IInstanceFactory::class, function(Server $c) { |
|
1141 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
1142 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
1143 | - }); |
|
1144 | - |
|
1145 | - $this->registerService(IContactsStore::class, function(Server $c) { |
|
1146 | - return new ContactsStore( |
|
1147 | - $c->getContactsManager(), |
|
1148 | - $c->getConfig(), |
|
1149 | - $c->getUserManager(), |
|
1150 | - $c->getGroupManager() |
|
1151 | - ); |
|
1152 | - }); |
|
1153 | - $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1154 | - |
|
1155 | - $this->connectDispatcher(); |
|
1156 | - } |
|
1157 | - |
|
1158 | - /** |
|
1159 | - * @return \OCP\Calendar\IManager |
|
1160 | - */ |
|
1161 | - public function getCalendarManager() { |
|
1162 | - return $this->query('CalendarManager'); |
|
1163 | - } |
|
1164 | - |
|
1165 | - private function connectDispatcher() { |
|
1166 | - $dispatcher = $this->getEventDispatcher(); |
|
1167 | - |
|
1168 | - // Delete avatar on user deletion |
|
1169 | - $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
1170 | - $logger = $this->getLogger(); |
|
1171 | - $manager = $this->getAvatarManager(); |
|
1172 | - /** @var IUser $user */ |
|
1173 | - $user = $e->getSubject(); |
|
1174 | - |
|
1175 | - try { |
|
1176 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1177 | - $avatar->remove(); |
|
1178 | - } catch (NotFoundException $e) { |
|
1179 | - // no avatar to remove |
|
1180 | - } catch (\Exception $e) { |
|
1181 | - // Ignore exceptions |
|
1182 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1183 | - } |
|
1184 | - }); |
|
1185 | - |
|
1186 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1187 | - $manager = $this->getAvatarManager(); |
|
1188 | - /** @var IUser $user */ |
|
1189 | - $user = $e->getSubject(); |
|
1190 | - $feature = $e->getArgument('feature'); |
|
1191 | - $oldValue = $e->getArgument('oldValue'); |
|
1192 | - $value = $e->getArgument('value'); |
|
1193 | - |
|
1194 | - try { |
|
1195 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1196 | - $avatar->userChanged($feature, $oldValue, $value); |
|
1197 | - } catch (NotFoundException $e) { |
|
1198 | - // no avatar to remove |
|
1199 | - } |
|
1200 | - }); |
|
1201 | - } |
|
1202 | - |
|
1203 | - /** |
|
1204 | - * @return \OCP\Contacts\IManager |
|
1205 | - */ |
|
1206 | - public function getContactsManager() { |
|
1207 | - return $this->query('ContactsManager'); |
|
1208 | - } |
|
1209 | - |
|
1210 | - /** |
|
1211 | - * @return \OC\Encryption\Manager |
|
1212 | - */ |
|
1213 | - public function getEncryptionManager() { |
|
1214 | - return $this->query('EncryptionManager'); |
|
1215 | - } |
|
1216 | - |
|
1217 | - /** |
|
1218 | - * @return \OC\Encryption\File |
|
1219 | - */ |
|
1220 | - public function getEncryptionFilesHelper() { |
|
1221 | - return $this->query('EncryptionFileHelper'); |
|
1222 | - } |
|
1223 | - |
|
1224 | - /** |
|
1225 | - * @return \OCP\Encryption\Keys\IStorage |
|
1226 | - */ |
|
1227 | - public function getEncryptionKeyStorage() { |
|
1228 | - return $this->query('EncryptionKeyStorage'); |
|
1229 | - } |
|
1230 | - |
|
1231 | - /** |
|
1232 | - * The current request object holding all information about the request |
|
1233 | - * currently being processed is returned from this method. |
|
1234 | - * In case the current execution was not initiated by a web request null is returned |
|
1235 | - * |
|
1236 | - * @return \OCP\IRequest |
|
1237 | - */ |
|
1238 | - public function getRequest() { |
|
1239 | - return $this->query('Request'); |
|
1240 | - } |
|
1241 | - |
|
1242 | - /** |
|
1243 | - * Returns the preview manager which can create preview images for a given file |
|
1244 | - * |
|
1245 | - * @return \OCP\IPreview |
|
1246 | - */ |
|
1247 | - public function getPreviewManager() { |
|
1248 | - return $this->query('PreviewManager'); |
|
1249 | - } |
|
1250 | - |
|
1251 | - /** |
|
1252 | - * Returns the tag manager which can get and set tags for different object types |
|
1253 | - * |
|
1254 | - * @see \OCP\ITagManager::load() |
|
1255 | - * @return \OCP\ITagManager |
|
1256 | - */ |
|
1257 | - public function getTagManager() { |
|
1258 | - return $this->query('TagManager'); |
|
1259 | - } |
|
1260 | - |
|
1261 | - /** |
|
1262 | - * Returns the system-tag manager |
|
1263 | - * |
|
1264 | - * @return \OCP\SystemTag\ISystemTagManager |
|
1265 | - * |
|
1266 | - * @since 9.0.0 |
|
1267 | - */ |
|
1268 | - public function getSystemTagManager() { |
|
1269 | - return $this->query('SystemTagManager'); |
|
1270 | - } |
|
1271 | - |
|
1272 | - /** |
|
1273 | - * Returns the system-tag object mapper |
|
1274 | - * |
|
1275 | - * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1276 | - * |
|
1277 | - * @since 9.0.0 |
|
1278 | - */ |
|
1279 | - public function getSystemTagObjectMapper() { |
|
1280 | - return $this->query('SystemTagObjectMapper'); |
|
1281 | - } |
|
1282 | - |
|
1283 | - /** |
|
1284 | - * Returns the avatar manager, used for avatar functionality |
|
1285 | - * |
|
1286 | - * @return \OCP\IAvatarManager |
|
1287 | - */ |
|
1288 | - public function getAvatarManager() { |
|
1289 | - return $this->query('AvatarManager'); |
|
1290 | - } |
|
1291 | - |
|
1292 | - /** |
|
1293 | - * Returns the root folder of ownCloud's data directory |
|
1294 | - * |
|
1295 | - * @return \OCP\Files\IRootFolder |
|
1296 | - */ |
|
1297 | - public function getRootFolder() { |
|
1298 | - return $this->query('LazyRootFolder'); |
|
1299 | - } |
|
1300 | - |
|
1301 | - /** |
|
1302 | - * Returns the root folder of ownCloud's data directory |
|
1303 | - * This is the lazy variant so this gets only initialized once it |
|
1304 | - * is actually used. |
|
1305 | - * |
|
1306 | - * @return \OCP\Files\IRootFolder |
|
1307 | - */ |
|
1308 | - public function getLazyRootFolder() { |
|
1309 | - return $this->query('LazyRootFolder'); |
|
1310 | - } |
|
1311 | - |
|
1312 | - /** |
|
1313 | - * Returns a view to ownCloud's files folder |
|
1314 | - * |
|
1315 | - * @param string $userId user ID |
|
1316 | - * @return \OCP\Files\Folder|null |
|
1317 | - */ |
|
1318 | - public function getUserFolder($userId = null) { |
|
1319 | - if ($userId === null) { |
|
1320 | - $user = $this->getUserSession()->getUser(); |
|
1321 | - if (!$user) { |
|
1322 | - return null; |
|
1323 | - } |
|
1324 | - $userId = $user->getUID(); |
|
1325 | - } |
|
1326 | - $root = $this->getRootFolder(); |
|
1327 | - return $root->getUserFolder($userId); |
|
1328 | - } |
|
1329 | - |
|
1330 | - /** |
|
1331 | - * Returns an app-specific view in ownClouds data directory |
|
1332 | - * |
|
1333 | - * @return \OCP\Files\Folder |
|
1334 | - * @deprecated since 9.2.0 use IAppData |
|
1335 | - */ |
|
1336 | - public function getAppFolder() { |
|
1337 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1338 | - $root = $this->getRootFolder(); |
|
1339 | - if (!$root->nodeExists($dir)) { |
|
1340 | - $folder = $root->newFolder($dir); |
|
1341 | - } else { |
|
1342 | - $folder = $root->get($dir); |
|
1343 | - } |
|
1344 | - return $folder; |
|
1345 | - } |
|
1346 | - |
|
1347 | - /** |
|
1348 | - * @return \OC\User\Manager |
|
1349 | - */ |
|
1350 | - public function getUserManager() { |
|
1351 | - return $this->query('UserManager'); |
|
1352 | - } |
|
1353 | - |
|
1354 | - /** |
|
1355 | - * @return \OC\Group\Manager |
|
1356 | - */ |
|
1357 | - public function getGroupManager() { |
|
1358 | - return $this->query('GroupManager'); |
|
1359 | - } |
|
1360 | - |
|
1361 | - /** |
|
1362 | - * @return \OC\User\Session |
|
1363 | - */ |
|
1364 | - public function getUserSession() { |
|
1365 | - return $this->query('UserSession'); |
|
1366 | - } |
|
1367 | - |
|
1368 | - /** |
|
1369 | - * @return \OCP\ISession |
|
1370 | - */ |
|
1371 | - public function getSession() { |
|
1372 | - return $this->query('UserSession')->getSession(); |
|
1373 | - } |
|
1374 | - |
|
1375 | - /** |
|
1376 | - * @param \OCP\ISession $session |
|
1377 | - */ |
|
1378 | - public function setSession(\OCP\ISession $session) { |
|
1379 | - $this->query(SessionStorage::class)->setSession($session); |
|
1380 | - $this->query('UserSession')->setSession($session); |
|
1381 | - $this->query(Store::class)->setSession($session); |
|
1382 | - } |
|
1383 | - |
|
1384 | - /** |
|
1385 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1386 | - */ |
|
1387 | - public function getTwoFactorAuthManager() { |
|
1388 | - return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1389 | - } |
|
1390 | - |
|
1391 | - /** |
|
1392 | - * @return \OC\NavigationManager |
|
1393 | - */ |
|
1394 | - public function getNavigationManager() { |
|
1395 | - return $this->query('NavigationManager'); |
|
1396 | - } |
|
1397 | - |
|
1398 | - /** |
|
1399 | - * @return \OCP\IConfig |
|
1400 | - */ |
|
1401 | - public function getConfig() { |
|
1402 | - return $this->query('AllConfig'); |
|
1403 | - } |
|
1404 | - |
|
1405 | - /** |
|
1406 | - * @return \OC\SystemConfig |
|
1407 | - */ |
|
1408 | - public function getSystemConfig() { |
|
1409 | - return $this->query('SystemConfig'); |
|
1410 | - } |
|
1411 | - |
|
1412 | - /** |
|
1413 | - * Returns the app config manager |
|
1414 | - * |
|
1415 | - * @return \OCP\IAppConfig |
|
1416 | - */ |
|
1417 | - public function getAppConfig() { |
|
1418 | - return $this->query('AppConfig'); |
|
1419 | - } |
|
1420 | - |
|
1421 | - /** |
|
1422 | - * @return \OCP\L10N\IFactory |
|
1423 | - */ |
|
1424 | - public function getL10NFactory() { |
|
1425 | - return $this->query('L10NFactory'); |
|
1426 | - } |
|
1427 | - |
|
1428 | - /** |
|
1429 | - * get an L10N instance |
|
1430 | - * |
|
1431 | - * @param string $app appid |
|
1432 | - * @param string $lang |
|
1433 | - * @return IL10N |
|
1434 | - */ |
|
1435 | - public function getL10N($app, $lang = null) { |
|
1436 | - return $this->getL10NFactory()->get($app, $lang); |
|
1437 | - } |
|
1438 | - |
|
1439 | - /** |
|
1440 | - * @return \OCP\IURLGenerator |
|
1441 | - */ |
|
1442 | - public function getURLGenerator() { |
|
1443 | - return $this->query('URLGenerator'); |
|
1444 | - } |
|
1445 | - |
|
1446 | - /** |
|
1447 | - * @return \OCP\IHelper |
|
1448 | - */ |
|
1449 | - public function getHelper() { |
|
1450 | - return $this->query('AppHelper'); |
|
1451 | - } |
|
1452 | - |
|
1453 | - /** |
|
1454 | - * @return AppFetcher |
|
1455 | - */ |
|
1456 | - public function getAppFetcher() { |
|
1457 | - return $this->query(AppFetcher::class); |
|
1458 | - } |
|
1459 | - |
|
1460 | - /** |
|
1461 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1462 | - * getMemCacheFactory() instead. |
|
1463 | - * |
|
1464 | - * @return \OCP\ICache |
|
1465 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1466 | - */ |
|
1467 | - public function getCache() { |
|
1468 | - return $this->query('UserCache'); |
|
1469 | - } |
|
1470 | - |
|
1471 | - /** |
|
1472 | - * Returns an \OCP\CacheFactory instance |
|
1473 | - * |
|
1474 | - * @return \OCP\ICacheFactory |
|
1475 | - */ |
|
1476 | - public function getMemCacheFactory() { |
|
1477 | - return $this->query('MemCacheFactory'); |
|
1478 | - } |
|
1479 | - |
|
1480 | - /** |
|
1481 | - * Returns an \OC\RedisFactory instance |
|
1482 | - * |
|
1483 | - * @return \OC\RedisFactory |
|
1484 | - */ |
|
1485 | - public function getGetRedisFactory() { |
|
1486 | - return $this->query('RedisFactory'); |
|
1487 | - } |
|
1488 | - |
|
1489 | - |
|
1490 | - /** |
|
1491 | - * Returns the current session |
|
1492 | - * |
|
1493 | - * @return \OCP\IDBConnection |
|
1494 | - */ |
|
1495 | - public function getDatabaseConnection() { |
|
1496 | - return $this->query('DatabaseConnection'); |
|
1497 | - } |
|
1498 | - |
|
1499 | - /** |
|
1500 | - * Returns the activity manager |
|
1501 | - * |
|
1502 | - * @return \OCP\Activity\IManager |
|
1503 | - */ |
|
1504 | - public function getActivityManager() { |
|
1505 | - return $this->query('ActivityManager'); |
|
1506 | - } |
|
1507 | - |
|
1508 | - /** |
|
1509 | - * Returns an job list for controlling background jobs |
|
1510 | - * |
|
1511 | - * @return \OCP\BackgroundJob\IJobList |
|
1512 | - */ |
|
1513 | - public function getJobList() { |
|
1514 | - return $this->query('JobList'); |
|
1515 | - } |
|
1516 | - |
|
1517 | - /** |
|
1518 | - * Returns a logger instance |
|
1519 | - * |
|
1520 | - * @return \OCP\ILogger |
|
1521 | - */ |
|
1522 | - public function getLogger() { |
|
1523 | - return $this->query('Logger'); |
|
1524 | - } |
|
1525 | - |
|
1526 | - /** |
|
1527 | - * Returns a router for generating and matching urls |
|
1528 | - * |
|
1529 | - * @return \OCP\Route\IRouter |
|
1530 | - */ |
|
1531 | - public function getRouter() { |
|
1532 | - return $this->query('Router'); |
|
1533 | - } |
|
1534 | - |
|
1535 | - /** |
|
1536 | - * Returns a search instance |
|
1537 | - * |
|
1538 | - * @return \OCP\ISearch |
|
1539 | - */ |
|
1540 | - public function getSearch() { |
|
1541 | - return $this->query('Search'); |
|
1542 | - } |
|
1543 | - |
|
1544 | - /** |
|
1545 | - * Returns a SecureRandom instance |
|
1546 | - * |
|
1547 | - * @return \OCP\Security\ISecureRandom |
|
1548 | - */ |
|
1549 | - public function getSecureRandom() { |
|
1550 | - return $this->query('SecureRandom'); |
|
1551 | - } |
|
1552 | - |
|
1553 | - /** |
|
1554 | - * Returns a Crypto instance |
|
1555 | - * |
|
1556 | - * @return \OCP\Security\ICrypto |
|
1557 | - */ |
|
1558 | - public function getCrypto() { |
|
1559 | - return $this->query('Crypto'); |
|
1560 | - } |
|
1561 | - |
|
1562 | - /** |
|
1563 | - * Returns a Hasher instance |
|
1564 | - * |
|
1565 | - * @return \OCP\Security\IHasher |
|
1566 | - */ |
|
1567 | - public function getHasher() { |
|
1568 | - return $this->query('Hasher'); |
|
1569 | - } |
|
1570 | - |
|
1571 | - /** |
|
1572 | - * Returns a CredentialsManager instance |
|
1573 | - * |
|
1574 | - * @return \OCP\Security\ICredentialsManager |
|
1575 | - */ |
|
1576 | - public function getCredentialsManager() { |
|
1577 | - return $this->query('CredentialsManager'); |
|
1578 | - } |
|
1579 | - |
|
1580 | - /** |
|
1581 | - * Returns an instance of the HTTP helper class |
|
1582 | - * |
|
1583 | - * @deprecated Use getHTTPClientService() |
|
1584 | - * @return \OC\HTTPHelper |
|
1585 | - */ |
|
1586 | - public function getHTTPHelper() { |
|
1587 | - return $this->query('HTTPHelper'); |
|
1588 | - } |
|
1589 | - |
|
1590 | - /** |
|
1591 | - * Get the certificate manager for the user |
|
1592 | - * |
|
1593 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1594 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1595 | - */ |
|
1596 | - public function getCertificateManager($userId = '') { |
|
1597 | - if ($userId === '') { |
|
1598 | - $userSession = $this->getUserSession(); |
|
1599 | - $user = $userSession->getUser(); |
|
1600 | - if (is_null($user)) { |
|
1601 | - return null; |
|
1602 | - } |
|
1603 | - $userId = $user->getUID(); |
|
1604 | - } |
|
1605 | - return new CertificateManager( |
|
1606 | - $userId, |
|
1607 | - new View(), |
|
1608 | - $this->getConfig(), |
|
1609 | - $this->getLogger(), |
|
1610 | - $this->getSecureRandom() |
|
1611 | - ); |
|
1612 | - } |
|
1613 | - |
|
1614 | - /** |
|
1615 | - * Returns an instance of the HTTP client service |
|
1616 | - * |
|
1617 | - * @return \OCP\Http\Client\IClientService |
|
1618 | - */ |
|
1619 | - public function getHTTPClientService() { |
|
1620 | - return $this->query('HttpClientService'); |
|
1621 | - } |
|
1622 | - |
|
1623 | - /** |
|
1624 | - * Create a new event source |
|
1625 | - * |
|
1626 | - * @return \OCP\IEventSource |
|
1627 | - */ |
|
1628 | - public function createEventSource() { |
|
1629 | - return new \OC_EventSource(); |
|
1630 | - } |
|
1631 | - |
|
1632 | - /** |
|
1633 | - * Get the active event logger |
|
1634 | - * |
|
1635 | - * The returned logger only logs data when debug mode is enabled |
|
1636 | - * |
|
1637 | - * @return \OCP\Diagnostics\IEventLogger |
|
1638 | - */ |
|
1639 | - public function getEventLogger() { |
|
1640 | - return $this->query('EventLogger'); |
|
1641 | - } |
|
1642 | - |
|
1643 | - /** |
|
1644 | - * Get the active query logger |
|
1645 | - * |
|
1646 | - * The returned logger only logs data when debug mode is enabled |
|
1647 | - * |
|
1648 | - * @return \OCP\Diagnostics\IQueryLogger |
|
1649 | - */ |
|
1650 | - public function getQueryLogger() { |
|
1651 | - return $this->query('QueryLogger'); |
|
1652 | - } |
|
1653 | - |
|
1654 | - /** |
|
1655 | - * Get the manager for temporary files and folders |
|
1656 | - * |
|
1657 | - * @return \OCP\ITempManager |
|
1658 | - */ |
|
1659 | - public function getTempManager() { |
|
1660 | - return $this->query('TempManager'); |
|
1661 | - } |
|
1662 | - |
|
1663 | - /** |
|
1664 | - * Get the app manager |
|
1665 | - * |
|
1666 | - * @return \OCP\App\IAppManager |
|
1667 | - */ |
|
1668 | - public function getAppManager() { |
|
1669 | - return $this->query('AppManager'); |
|
1670 | - } |
|
1671 | - |
|
1672 | - /** |
|
1673 | - * Creates a new mailer |
|
1674 | - * |
|
1675 | - * @return \OCP\Mail\IMailer |
|
1676 | - */ |
|
1677 | - public function getMailer() { |
|
1678 | - return $this->query('Mailer'); |
|
1679 | - } |
|
1680 | - |
|
1681 | - /** |
|
1682 | - * Get the webroot |
|
1683 | - * |
|
1684 | - * @return string |
|
1685 | - */ |
|
1686 | - public function getWebRoot() { |
|
1687 | - return $this->webRoot; |
|
1688 | - } |
|
1689 | - |
|
1690 | - /** |
|
1691 | - * @return \OC\OCSClient |
|
1692 | - */ |
|
1693 | - public function getOcsClient() { |
|
1694 | - return $this->query('OcsClient'); |
|
1695 | - } |
|
1696 | - |
|
1697 | - /** |
|
1698 | - * @return \OCP\IDateTimeZone |
|
1699 | - */ |
|
1700 | - public function getDateTimeZone() { |
|
1701 | - return $this->query('DateTimeZone'); |
|
1702 | - } |
|
1703 | - |
|
1704 | - /** |
|
1705 | - * @return \OCP\IDateTimeFormatter |
|
1706 | - */ |
|
1707 | - public function getDateTimeFormatter() { |
|
1708 | - return $this->query('DateTimeFormatter'); |
|
1709 | - } |
|
1710 | - |
|
1711 | - /** |
|
1712 | - * @return \OCP\Files\Config\IMountProviderCollection |
|
1713 | - */ |
|
1714 | - public function getMountProviderCollection() { |
|
1715 | - return $this->query('MountConfigManager'); |
|
1716 | - } |
|
1717 | - |
|
1718 | - /** |
|
1719 | - * Get the IniWrapper |
|
1720 | - * |
|
1721 | - * @return IniGetWrapper |
|
1722 | - */ |
|
1723 | - public function getIniWrapper() { |
|
1724 | - return $this->query('IniWrapper'); |
|
1725 | - } |
|
1726 | - |
|
1727 | - /** |
|
1728 | - * @return \OCP\Command\IBus |
|
1729 | - */ |
|
1730 | - public function getCommandBus() { |
|
1731 | - return $this->query('AsyncCommandBus'); |
|
1732 | - } |
|
1733 | - |
|
1734 | - /** |
|
1735 | - * Get the trusted domain helper |
|
1736 | - * |
|
1737 | - * @return TrustedDomainHelper |
|
1738 | - */ |
|
1739 | - public function getTrustedDomainHelper() { |
|
1740 | - return $this->query('TrustedDomainHelper'); |
|
1741 | - } |
|
1742 | - |
|
1743 | - /** |
|
1744 | - * Get the locking provider |
|
1745 | - * |
|
1746 | - * @return \OCP\Lock\ILockingProvider |
|
1747 | - * @since 8.1.0 |
|
1748 | - */ |
|
1749 | - public function getLockingProvider() { |
|
1750 | - return $this->query('LockingProvider'); |
|
1751 | - } |
|
1752 | - |
|
1753 | - /** |
|
1754 | - * @return \OCP\Files\Mount\IMountManager |
|
1755 | - **/ |
|
1756 | - function getMountManager() { |
|
1757 | - return $this->query('MountManager'); |
|
1758 | - } |
|
1759 | - |
|
1760 | - /** @return \OCP\Files\Config\IUserMountCache */ |
|
1761 | - function getUserMountCache() { |
|
1762 | - return $this->query('UserMountCache'); |
|
1763 | - } |
|
1764 | - |
|
1765 | - /** |
|
1766 | - * Get the MimeTypeDetector |
|
1767 | - * |
|
1768 | - * @return \OCP\Files\IMimeTypeDetector |
|
1769 | - */ |
|
1770 | - public function getMimeTypeDetector() { |
|
1771 | - return $this->query('MimeTypeDetector'); |
|
1772 | - } |
|
1773 | - |
|
1774 | - /** |
|
1775 | - * Get the MimeTypeLoader |
|
1776 | - * |
|
1777 | - * @return \OCP\Files\IMimeTypeLoader |
|
1778 | - */ |
|
1779 | - public function getMimeTypeLoader() { |
|
1780 | - return $this->query('MimeTypeLoader'); |
|
1781 | - } |
|
1782 | - |
|
1783 | - /** |
|
1784 | - * Get the manager of all the capabilities |
|
1785 | - * |
|
1786 | - * @return \OC\CapabilitiesManager |
|
1787 | - */ |
|
1788 | - public function getCapabilitiesManager() { |
|
1789 | - return $this->query('CapabilitiesManager'); |
|
1790 | - } |
|
1791 | - |
|
1792 | - /** |
|
1793 | - * Get the EventDispatcher |
|
1794 | - * |
|
1795 | - * @return EventDispatcherInterface |
|
1796 | - * @since 8.2.0 |
|
1797 | - */ |
|
1798 | - public function getEventDispatcher() { |
|
1799 | - return $this->query('EventDispatcher'); |
|
1800 | - } |
|
1801 | - |
|
1802 | - /** |
|
1803 | - * Get the Notification Manager |
|
1804 | - * |
|
1805 | - * @return \OCP\Notification\IManager |
|
1806 | - * @since 8.2.0 |
|
1807 | - */ |
|
1808 | - public function getNotificationManager() { |
|
1809 | - return $this->query('NotificationManager'); |
|
1810 | - } |
|
1811 | - |
|
1812 | - /** |
|
1813 | - * @return \OCP\Comments\ICommentsManager |
|
1814 | - */ |
|
1815 | - public function getCommentsManager() { |
|
1816 | - return $this->query('CommentsManager'); |
|
1817 | - } |
|
1818 | - |
|
1819 | - /** |
|
1820 | - * @return \OCA\Theming\ThemingDefaults |
|
1821 | - */ |
|
1822 | - public function getThemingDefaults() { |
|
1823 | - return $this->query('ThemingDefaults'); |
|
1824 | - } |
|
1825 | - |
|
1826 | - /** |
|
1827 | - * @return \OC\IntegrityCheck\Checker |
|
1828 | - */ |
|
1829 | - public function getIntegrityCodeChecker() { |
|
1830 | - return $this->query('IntegrityCodeChecker'); |
|
1831 | - } |
|
1832 | - |
|
1833 | - /** |
|
1834 | - * @return \OC\Session\CryptoWrapper |
|
1835 | - */ |
|
1836 | - public function getSessionCryptoWrapper() { |
|
1837 | - return $this->query('CryptoWrapper'); |
|
1838 | - } |
|
1839 | - |
|
1840 | - /** |
|
1841 | - * @return CsrfTokenManager |
|
1842 | - */ |
|
1843 | - public function getCsrfTokenManager() { |
|
1844 | - return $this->query('CsrfTokenManager'); |
|
1845 | - } |
|
1846 | - |
|
1847 | - /** |
|
1848 | - * @return Throttler |
|
1849 | - */ |
|
1850 | - public function getBruteForceThrottler() { |
|
1851 | - return $this->query('Throttler'); |
|
1852 | - } |
|
1853 | - |
|
1854 | - /** |
|
1855 | - * @return IContentSecurityPolicyManager |
|
1856 | - */ |
|
1857 | - public function getContentSecurityPolicyManager() { |
|
1858 | - return $this->query('ContentSecurityPolicyManager'); |
|
1859 | - } |
|
1860 | - |
|
1861 | - /** |
|
1862 | - * @return ContentSecurityPolicyNonceManager |
|
1863 | - */ |
|
1864 | - public function getContentSecurityPolicyNonceManager() { |
|
1865 | - return $this->query('ContentSecurityPolicyNonceManager'); |
|
1866 | - } |
|
1867 | - |
|
1868 | - /** |
|
1869 | - * Not a public API as of 8.2, wait for 9.0 |
|
1870 | - * |
|
1871 | - * @return \OCA\Files_External\Service\BackendService |
|
1872 | - */ |
|
1873 | - public function getStoragesBackendService() { |
|
1874 | - return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1875 | - } |
|
1876 | - |
|
1877 | - /** |
|
1878 | - * Not a public API as of 8.2, wait for 9.0 |
|
1879 | - * |
|
1880 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1881 | - */ |
|
1882 | - public function getGlobalStoragesService() { |
|
1883 | - return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1884 | - } |
|
1885 | - |
|
1886 | - /** |
|
1887 | - * Not a public API as of 8.2, wait for 9.0 |
|
1888 | - * |
|
1889 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1890 | - */ |
|
1891 | - public function getUserGlobalStoragesService() { |
|
1892 | - return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1893 | - } |
|
1894 | - |
|
1895 | - /** |
|
1896 | - * Not a public API as of 8.2, wait for 9.0 |
|
1897 | - * |
|
1898 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
1899 | - */ |
|
1900 | - public function getUserStoragesService() { |
|
1901 | - return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1902 | - } |
|
1903 | - |
|
1904 | - /** |
|
1905 | - * @return \OCP\Share\IManager |
|
1906 | - */ |
|
1907 | - public function getShareManager() { |
|
1908 | - return $this->query('ShareManager'); |
|
1909 | - } |
|
1910 | - |
|
1911 | - /** |
|
1912 | - * @return \OCP\Collaboration\Collaborators\ISearch |
|
1913 | - */ |
|
1914 | - public function getCollaboratorSearch() { |
|
1915 | - return $this->query('CollaboratorSearch'); |
|
1916 | - } |
|
1917 | - |
|
1918 | - /** |
|
1919 | - * @return \OCP\Collaboration\AutoComplete\IManager |
|
1920 | - */ |
|
1921 | - public function getAutoCompleteManager(){ |
|
1922 | - return $this->query(IManager::class); |
|
1923 | - } |
|
1924 | - |
|
1925 | - /** |
|
1926 | - * Returns the LDAP Provider |
|
1927 | - * |
|
1928 | - * @return \OCP\LDAP\ILDAPProvider |
|
1929 | - */ |
|
1930 | - public function getLDAPProvider() { |
|
1931 | - return $this->query('LDAPProvider'); |
|
1932 | - } |
|
1933 | - |
|
1934 | - /** |
|
1935 | - * @return \OCP\Settings\IManager |
|
1936 | - */ |
|
1937 | - public function getSettingsManager() { |
|
1938 | - return $this->query('SettingsManager'); |
|
1939 | - } |
|
1940 | - |
|
1941 | - /** |
|
1942 | - * @return \OCP\Files\IAppData |
|
1943 | - */ |
|
1944 | - public function getAppDataDir($app) { |
|
1945 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
1946 | - $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1947 | - return $factory->get($app); |
|
1948 | - } |
|
1949 | - |
|
1950 | - /** |
|
1951 | - * @return \OCP\Lockdown\ILockdownManager |
|
1952 | - */ |
|
1953 | - public function getLockdownManager() { |
|
1954 | - return $this->query('LockdownManager'); |
|
1955 | - } |
|
1956 | - |
|
1957 | - /** |
|
1958 | - * @return \OCP\Federation\ICloudIdManager |
|
1959 | - */ |
|
1960 | - public function getCloudIdManager() { |
|
1961 | - return $this->query(ICloudIdManager::class); |
|
1962 | - } |
|
1963 | - |
|
1964 | - /** |
|
1965 | - * @return \OCP\Remote\Api\IApiFactory |
|
1966 | - */ |
|
1967 | - public function getRemoteApiFactory() { |
|
1968 | - return $this->query(IApiFactory::class); |
|
1969 | - } |
|
1970 | - |
|
1971 | - /** |
|
1972 | - * @return \OCP\Remote\IInstanceFactory |
|
1973 | - */ |
|
1974 | - public function getRemoteInstanceFactory() { |
|
1975 | - return $this->query(IInstanceFactory::class); |
|
1976 | - } |
|
934 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
935 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
936 | + $classExists = true; |
|
937 | + } else { |
|
938 | + $classExists = false; |
|
939 | + } |
|
940 | + |
|
941 | + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
942 | + return new ThemingDefaults( |
|
943 | + $c->getConfig(), |
|
944 | + $c->getL10N('theming'), |
|
945 | + $c->getURLGenerator(), |
|
946 | + $c->getAppDataDir('theming'), |
|
947 | + $c->getMemCacheFactory(), |
|
948 | + new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming')), |
|
949 | + $this->getAppManager() |
|
950 | + ); |
|
951 | + } |
|
952 | + return new \OC_Defaults(); |
|
953 | + }); |
|
954 | + $this->registerService(SCSSCacher::class, function (Server $c) { |
|
955 | + /** @var Factory $cacheFactory */ |
|
956 | + $cacheFactory = $c->query(Factory::class); |
|
957 | + return new SCSSCacher( |
|
958 | + $c->getLogger(), |
|
959 | + $c->query(\OC\Files\AppData\Factory::class), |
|
960 | + $c->getURLGenerator(), |
|
961 | + $c->getConfig(), |
|
962 | + $c->getThemingDefaults(), |
|
963 | + \OC::$SERVERROOT, |
|
964 | + $cacheFactory->createDistributed('SCSS') |
|
965 | + ); |
|
966 | + }); |
|
967 | + $this->registerService(EventDispatcher::class, function () { |
|
968 | + return new EventDispatcher(); |
|
969 | + }); |
|
970 | + $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
971 | + $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
972 | + |
|
973 | + $this->registerService('CryptoWrapper', function (Server $c) { |
|
974 | + // FIXME: Instantiiated here due to cyclic dependency |
|
975 | + $request = new Request( |
|
976 | + [ |
|
977 | + 'get' => $_GET, |
|
978 | + 'post' => $_POST, |
|
979 | + 'files' => $_FILES, |
|
980 | + 'server' => $_SERVER, |
|
981 | + 'env' => $_ENV, |
|
982 | + 'cookies' => $_COOKIE, |
|
983 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
984 | + ? $_SERVER['REQUEST_METHOD'] |
|
985 | + : null, |
|
986 | + ], |
|
987 | + $c->getSecureRandom(), |
|
988 | + $c->getConfig() |
|
989 | + ); |
|
990 | + |
|
991 | + return new CryptoWrapper( |
|
992 | + $c->getConfig(), |
|
993 | + $c->getCrypto(), |
|
994 | + $c->getSecureRandom(), |
|
995 | + $request |
|
996 | + ); |
|
997 | + }); |
|
998 | + $this->registerService('CsrfTokenManager', function (Server $c) { |
|
999 | + $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
1000 | + |
|
1001 | + return new CsrfTokenManager( |
|
1002 | + $tokenGenerator, |
|
1003 | + $c->query(SessionStorage::class) |
|
1004 | + ); |
|
1005 | + }); |
|
1006 | + $this->registerService(SessionStorage::class, function (Server $c) { |
|
1007 | + return new SessionStorage($c->getSession()); |
|
1008 | + }); |
|
1009 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
1010 | + return new ContentSecurityPolicyManager(); |
|
1011 | + }); |
|
1012 | + $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
1013 | + |
|
1014 | + $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1015 | + return new ContentSecurityPolicyNonceManager( |
|
1016 | + $c->getCsrfTokenManager(), |
|
1017 | + $c->getRequest() |
|
1018 | + ); |
|
1019 | + }); |
|
1020 | + |
|
1021 | + $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1022 | + $config = $c->getConfig(); |
|
1023 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
|
1024 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
1025 | + $factory = new $factoryClass($this); |
|
1026 | + |
|
1027 | + $manager = new \OC\Share20\Manager( |
|
1028 | + $c->getLogger(), |
|
1029 | + $c->getConfig(), |
|
1030 | + $c->getSecureRandom(), |
|
1031 | + $c->getHasher(), |
|
1032 | + $c->getMountManager(), |
|
1033 | + $c->getGroupManager(), |
|
1034 | + $c->getL10N('lib'), |
|
1035 | + $c->getL10NFactory(), |
|
1036 | + $factory, |
|
1037 | + $c->getUserManager(), |
|
1038 | + $c->getLazyRootFolder(), |
|
1039 | + $c->getEventDispatcher(), |
|
1040 | + $c->getMailer(), |
|
1041 | + $c->getURLGenerator(), |
|
1042 | + $c->getThemingDefaults() |
|
1043 | + ); |
|
1044 | + |
|
1045 | + return $manager; |
|
1046 | + }); |
|
1047 | + $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
1048 | + |
|
1049 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1050 | + $instance = new Collaboration\Collaborators\Search($c); |
|
1051 | + |
|
1052 | + // register default plugins |
|
1053 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1054 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1055 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1056 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1057 | + |
|
1058 | + return $instance; |
|
1059 | + }); |
|
1060 | + $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1061 | + |
|
1062 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1063 | + |
|
1064 | + $this->registerService('SettingsManager', function (Server $c) { |
|
1065 | + $manager = new \OC\Settings\Manager( |
|
1066 | + $c->getLogger(), |
|
1067 | + $c->getDatabaseConnection(), |
|
1068 | + $c->getL10N('lib'), |
|
1069 | + $c->getConfig(), |
|
1070 | + $c->getEncryptionManager(), |
|
1071 | + $c->getUserManager(), |
|
1072 | + $c->getLockingProvider(), |
|
1073 | + $c->getRequest(), |
|
1074 | + $c->getURLGenerator(), |
|
1075 | + $c->query(AccountManager::class), |
|
1076 | + $c->getGroupManager(), |
|
1077 | + $c->getL10NFactory(), |
|
1078 | + $c->getAppManager() |
|
1079 | + ); |
|
1080 | + return $manager; |
|
1081 | + }); |
|
1082 | + $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1083 | + return new \OC\Files\AppData\Factory( |
|
1084 | + $c->getRootFolder(), |
|
1085 | + $c->getSystemConfig() |
|
1086 | + ); |
|
1087 | + }); |
|
1088 | + |
|
1089 | + $this->registerService('LockdownManager', function (Server $c) { |
|
1090 | + return new LockdownManager(function () use ($c) { |
|
1091 | + return $c->getSession(); |
|
1092 | + }); |
|
1093 | + }); |
|
1094 | + |
|
1095 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1096 | + return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1097 | + }); |
|
1098 | + |
|
1099 | + $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1100 | + return new CloudIdManager(); |
|
1101 | + }); |
|
1102 | + |
|
1103 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1104 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1105 | + |
|
1106 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1107 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1108 | + |
|
1109 | + $this->registerService(Defaults::class, function (Server $c) { |
|
1110 | + return new Defaults( |
|
1111 | + $c->getThemingDefaults() |
|
1112 | + ); |
|
1113 | + }); |
|
1114 | + $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1115 | + |
|
1116 | + $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1117 | + return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1118 | + }); |
|
1119 | + |
|
1120 | + $this->registerService(IShareHelper::class, function (Server $c) { |
|
1121 | + return new ShareHelper( |
|
1122 | + $c->query(\OCP\Share\IManager::class) |
|
1123 | + ); |
|
1124 | + }); |
|
1125 | + |
|
1126 | + $this->registerService(Installer::class, function(Server $c) { |
|
1127 | + return new Installer( |
|
1128 | + $c->getAppFetcher(), |
|
1129 | + $c->getHTTPClientService(), |
|
1130 | + $c->getTempManager(), |
|
1131 | + $c->getLogger(), |
|
1132 | + $c->getConfig() |
|
1133 | + ); |
|
1134 | + }); |
|
1135 | + |
|
1136 | + $this->registerService(IApiFactory::class, function(Server $c) { |
|
1137 | + return new ApiFactory($c->getHTTPClientService()); |
|
1138 | + }); |
|
1139 | + |
|
1140 | + $this->registerService(IInstanceFactory::class, function(Server $c) { |
|
1141 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
1142 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
1143 | + }); |
|
1144 | + |
|
1145 | + $this->registerService(IContactsStore::class, function(Server $c) { |
|
1146 | + return new ContactsStore( |
|
1147 | + $c->getContactsManager(), |
|
1148 | + $c->getConfig(), |
|
1149 | + $c->getUserManager(), |
|
1150 | + $c->getGroupManager() |
|
1151 | + ); |
|
1152 | + }); |
|
1153 | + $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1154 | + |
|
1155 | + $this->connectDispatcher(); |
|
1156 | + } |
|
1157 | + |
|
1158 | + /** |
|
1159 | + * @return \OCP\Calendar\IManager |
|
1160 | + */ |
|
1161 | + public function getCalendarManager() { |
|
1162 | + return $this->query('CalendarManager'); |
|
1163 | + } |
|
1164 | + |
|
1165 | + private function connectDispatcher() { |
|
1166 | + $dispatcher = $this->getEventDispatcher(); |
|
1167 | + |
|
1168 | + // Delete avatar on user deletion |
|
1169 | + $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
1170 | + $logger = $this->getLogger(); |
|
1171 | + $manager = $this->getAvatarManager(); |
|
1172 | + /** @var IUser $user */ |
|
1173 | + $user = $e->getSubject(); |
|
1174 | + |
|
1175 | + try { |
|
1176 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1177 | + $avatar->remove(); |
|
1178 | + } catch (NotFoundException $e) { |
|
1179 | + // no avatar to remove |
|
1180 | + } catch (\Exception $e) { |
|
1181 | + // Ignore exceptions |
|
1182 | + $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1183 | + } |
|
1184 | + }); |
|
1185 | + |
|
1186 | + $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1187 | + $manager = $this->getAvatarManager(); |
|
1188 | + /** @var IUser $user */ |
|
1189 | + $user = $e->getSubject(); |
|
1190 | + $feature = $e->getArgument('feature'); |
|
1191 | + $oldValue = $e->getArgument('oldValue'); |
|
1192 | + $value = $e->getArgument('value'); |
|
1193 | + |
|
1194 | + try { |
|
1195 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1196 | + $avatar->userChanged($feature, $oldValue, $value); |
|
1197 | + } catch (NotFoundException $e) { |
|
1198 | + // no avatar to remove |
|
1199 | + } |
|
1200 | + }); |
|
1201 | + } |
|
1202 | + |
|
1203 | + /** |
|
1204 | + * @return \OCP\Contacts\IManager |
|
1205 | + */ |
|
1206 | + public function getContactsManager() { |
|
1207 | + return $this->query('ContactsManager'); |
|
1208 | + } |
|
1209 | + |
|
1210 | + /** |
|
1211 | + * @return \OC\Encryption\Manager |
|
1212 | + */ |
|
1213 | + public function getEncryptionManager() { |
|
1214 | + return $this->query('EncryptionManager'); |
|
1215 | + } |
|
1216 | + |
|
1217 | + /** |
|
1218 | + * @return \OC\Encryption\File |
|
1219 | + */ |
|
1220 | + public function getEncryptionFilesHelper() { |
|
1221 | + return $this->query('EncryptionFileHelper'); |
|
1222 | + } |
|
1223 | + |
|
1224 | + /** |
|
1225 | + * @return \OCP\Encryption\Keys\IStorage |
|
1226 | + */ |
|
1227 | + public function getEncryptionKeyStorage() { |
|
1228 | + return $this->query('EncryptionKeyStorage'); |
|
1229 | + } |
|
1230 | + |
|
1231 | + /** |
|
1232 | + * The current request object holding all information about the request |
|
1233 | + * currently being processed is returned from this method. |
|
1234 | + * In case the current execution was not initiated by a web request null is returned |
|
1235 | + * |
|
1236 | + * @return \OCP\IRequest |
|
1237 | + */ |
|
1238 | + public function getRequest() { |
|
1239 | + return $this->query('Request'); |
|
1240 | + } |
|
1241 | + |
|
1242 | + /** |
|
1243 | + * Returns the preview manager which can create preview images for a given file |
|
1244 | + * |
|
1245 | + * @return \OCP\IPreview |
|
1246 | + */ |
|
1247 | + public function getPreviewManager() { |
|
1248 | + return $this->query('PreviewManager'); |
|
1249 | + } |
|
1250 | + |
|
1251 | + /** |
|
1252 | + * Returns the tag manager which can get and set tags for different object types |
|
1253 | + * |
|
1254 | + * @see \OCP\ITagManager::load() |
|
1255 | + * @return \OCP\ITagManager |
|
1256 | + */ |
|
1257 | + public function getTagManager() { |
|
1258 | + return $this->query('TagManager'); |
|
1259 | + } |
|
1260 | + |
|
1261 | + /** |
|
1262 | + * Returns the system-tag manager |
|
1263 | + * |
|
1264 | + * @return \OCP\SystemTag\ISystemTagManager |
|
1265 | + * |
|
1266 | + * @since 9.0.0 |
|
1267 | + */ |
|
1268 | + public function getSystemTagManager() { |
|
1269 | + return $this->query('SystemTagManager'); |
|
1270 | + } |
|
1271 | + |
|
1272 | + /** |
|
1273 | + * Returns the system-tag object mapper |
|
1274 | + * |
|
1275 | + * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1276 | + * |
|
1277 | + * @since 9.0.0 |
|
1278 | + */ |
|
1279 | + public function getSystemTagObjectMapper() { |
|
1280 | + return $this->query('SystemTagObjectMapper'); |
|
1281 | + } |
|
1282 | + |
|
1283 | + /** |
|
1284 | + * Returns the avatar manager, used for avatar functionality |
|
1285 | + * |
|
1286 | + * @return \OCP\IAvatarManager |
|
1287 | + */ |
|
1288 | + public function getAvatarManager() { |
|
1289 | + return $this->query('AvatarManager'); |
|
1290 | + } |
|
1291 | + |
|
1292 | + /** |
|
1293 | + * Returns the root folder of ownCloud's data directory |
|
1294 | + * |
|
1295 | + * @return \OCP\Files\IRootFolder |
|
1296 | + */ |
|
1297 | + public function getRootFolder() { |
|
1298 | + return $this->query('LazyRootFolder'); |
|
1299 | + } |
|
1300 | + |
|
1301 | + /** |
|
1302 | + * Returns the root folder of ownCloud's data directory |
|
1303 | + * This is the lazy variant so this gets only initialized once it |
|
1304 | + * is actually used. |
|
1305 | + * |
|
1306 | + * @return \OCP\Files\IRootFolder |
|
1307 | + */ |
|
1308 | + public function getLazyRootFolder() { |
|
1309 | + return $this->query('LazyRootFolder'); |
|
1310 | + } |
|
1311 | + |
|
1312 | + /** |
|
1313 | + * Returns a view to ownCloud's files folder |
|
1314 | + * |
|
1315 | + * @param string $userId user ID |
|
1316 | + * @return \OCP\Files\Folder|null |
|
1317 | + */ |
|
1318 | + public function getUserFolder($userId = null) { |
|
1319 | + if ($userId === null) { |
|
1320 | + $user = $this->getUserSession()->getUser(); |
|
1321 | + if (!$user) { |
|
1322 | + return null; |
|
1323 | + } |
|
1324 | + $userId = $user->getUID(); |
|
1325 | + } |
|
1326 | + $root = $this->getRootFolder(); |
|
1327 | + return $root->getUserFolder($userId); |
|
1328 | + } |
|
1329 | + |
|
1330 | + /** |
|
1331 | + * Returns an app-specific view in ownClouds data directory |
|
1332 | + * |
|
1333 | + * @return \OCP\Files\Folder |
|
1334 | + * @deprecated since 9.2.0 use IAppData |
|
1335 | + */ |
|
1336 | + public function getAppFolder() { |
|
1337 | + $dir = '/' . \OC_App::getCurrentApp(); |
|
1338 | + $root = $this->getRootFolder(); |
|
1339 | + if (!$root->nodeExists($dir)) { |
|
1340 | + $folder = $root->newFolder($dir); |
|
1341 | + } else { |
|
1342 | + $folder = $root->get($dir); |
|
1343 | + } |
|
1344 | + return $folder; |
|
1345 | + } |
|
1346 | + |
|
1347 | + /** |
|
1348 | + * @return \OC\User\Manager |
|
1349 | + */ |
|
1350 | + public function getUserManager() { |
|
1351 | + return $this->query('UserManager'); |
|
1352 | + } |
|
1353 | + |
|
1354 | + /** |
|
1355 | + * @return \OC\Group\Manager |
|
1356 | + */ |
|
1357 | + public function getGroupManager() { |
|
1358 | + return $this->query('GroupManager'); |
|
1359 | + } |
|
1360 | + |
|
1361 | + /** |
|
1362 | + * @return \OC\User\Session |
|
1363 | + */ |
|
1364 | + public function getUserSession() { |
|
1365 | + return $this->query('UserSession'); |
|
1366 | + } |
|
1367 | + |
|
1368 | + /** |
|
1369 | + * @return \OCP\ISession |
|
1370 | + */ |
|
1371 | + public function getSession() { |
|
1372 | + return $this->query('UserSession')->getSession(); |
|
1373 | + } |
|
1374 | + |
|
1375 | + /** |
|
1376 | + * @param \OCP\ISession $session |
|
1377 | + */ |
|
1378 | + public function setSession(\OCP\ISession $session) { |
|
1379 | + $this->query(SessionStorage::class)->setSession($session); |
|
1380 | + $this->query('UserSession')->setSession($session); |
|
1381 | + $this->query(Store::class)->setSession($session); |
|
1382 | + } |
|
1383 | + |
|
1384 | + /** |
|
1385 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1386 | + */ |
|
1387 | + public function getTwoFactorAuthManager() { |
|
1388 | + return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1389 | + } |
|
1390 | + |
|
1391 | + /** |
|
1392 | + * @return \OC\NavigationManager |
|
1393 | + */ |
|
1394 | + public function getNavigationManager() { |
|
1395 | + return $this->query('NavigationManager'); |
|
1396 | + } |
|
1397 | + |
|
1398 | + /** |
|
1399 | + * @return \OCP\IConfig |
|
1400 | + */ |
|
1401 | + public function getConfig() { |
|
1402 | + return $this->query('AllConfig'); |
|
1403 | + } |
|
1404 | + |
|
1405 | + /** |
|
1406 | + * @return \OC\SystemConfig |
|
1407 | + */ |
|
1408 | + public function getSystemConfig() { |
|
1409 | + return $this->query('SystemConfig'); |
|
1410 | + } |
|
1411 | + |
|
1412 | + /** |
|
1413 | + * Returns the app config manager |
|
1414 | + * |
|
1415 | + * @return \OCP\IAppConfig |
|
1416 | + */ |
|
1417 | + public function getAppConfig() { |
|
1418 | + return $this->query('AppConfig'); |
|
1419 | + } |
|
1420 | + |
|
1421 | + /** |
|
1422 | + * @return \OCP\L10N\IFactory |
|
1423 | + */ |
|
1424 | + public function getL10NFactory() { |
|
1425 | + return $this->query('L10NFactory'); |
|
1426 | + } |
|
1427 | + |
|
1428 | + /** |
|
1429 | + * get an L10N instance |
|
1430 | + * |
|
1431 | + * @param string $app appid |
|
1432 | + * @param string $lang |
|
1433 | + * @return IL10N |
|
1434 | + */ |
|
1435 | + public function getL10N($app, $lang = null) { |
|
1436 | + return $this->getL10NFactory()->get($app, $lang); |
|
1437 | + } |
|
1438 | + |
|
1439 | + /** |
|
1440 | + * @return \OCP\IURLGenerator |
|
1441 | + */ |
|
1442 | + public function getURLGenerator() { |
|
1443 | + return $this->query('URLGenerator'); |
|
1444 | + } |
|
1445 | + |
|
1446 | + /** |
|
1447 | + * @return \OCP\IHelper |
|
1448 | + */ |
|
1449 | + public function getHelper() { |
|
1450 | + return $this->query('AppHelper'); |
|
1451 | + } |
|
1452 | + |
|
1453 | + /** |
|
1454 | + * @return AppFetcher |
|
1455 | + */ |
|
1456 | + public function getAppFetcher() { |
|
1457 | + return $this->query(AppFetcher::class); |
|
1458 | + } |
|
1459 | + |
|
1460 | + /** |
|
1461 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1462 | + * getMemCacheFactory() instead. |
|
1463 | + * |
|
1464 | + * @return \OCP\ICache |
|
1465 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1466 | + */ |
|
1467 | + public function getCache() { |
|
1468 | + return $this->query('UserCache'); |
|
1469 | + } |
|
1470 | + |
|
1471 | + /** |
|
1472 | + * Returns an \OCP\CacheFactory instance |
|
1473 | + * |
|
1474 | + * @return \OCP\ICacheFactory |
|
1475 | + */ |
|
1476 | + public function getMemCacheFactory() { |
|
1477 | + return $this->query('MemCacheFactory'); |
|
1478 | + } |
|
1479 | + |
|
1480 | + /** |
|
1481 | + * Returns an \OC\RedisFactory instance |
|
1482 | + * |
|
1483 | + * @return \OC\RedisFactory |
|
1484 | + */ |
|
1485 | + public function getGetRedisFactory() { |
|
1486 | + return $this->query('RedisFactory'); |
|
1487 | + } |
|
1488 | + |
|
1489 | + |
|
1490 | + /** |
|
1491 | + * Returns the current session |
|
1492 | + * |
|
1493 | + * @return \OCP\IDBConnection |
|
1494 | + */ |
|
1495 | + public function getDatabaseConnection() { |
|
1496 | + return $this->query('DatabaseConnection'); |
|
1497 | + } |
|
1498 | + |
|
1499 | + /** |
|
1500 | + * Returns the activity manager |
|
1501 | + * |
|
1502 | + * @return \OCP\Activity\IManager |
|
1503 | + */ |
|
1504 | + public function getActivityManager() { |
|
1505 | + return $this->query('ActivityManager'); |
|
1506 | + } |
|
1507 | + |
|
1508 | + /** |
|
1509 | + * Returns an job list for controlling background jobs |
|
1510 | + * |
|
1511 | + * @return \OCP\BackgroundJob\IJobList |
|
1512 | + */ |
|
1513 | + public function getJobList() { |
|
1514 | + return $this->query('JobList'); |
|
1515 | + } |
|
1516 | + |
|
1517 | + /** |
|
1518 | + * Returns a logger instance |
|
1519 | + * |
|
1520 | + * @return \OCP\ILogger |
|
1521 | + */ |
|
1522 | + public function getLogger() { |
|
1523 | + return $this->query('Logger'); |
|
1524 | + } |
|
1525 | + |
|
1526 | + /** |
|
1527 | + * Returns a router for generating and matching urls |
|
1528 | + * |
|
1529 | + * @return \OCP\Route\IRouter |
|
1530 | + */ |
|
1531 | + public function getRouter() { |
|
1532 | + return $this->query('Router'); |
|
1533 | + } |
|
1534 | + |
|
1535 | + /** |
|
1536 | + * Returns a search instance |
|
1537 | + * |
|
1538 | + * @return \OCP\ISearch |
|
1539 | + */ |
|
1540 | + public function getSearch() { |
|
1541 | + return $this->query('Search'); |
|
1542 | + } |
|
1543 | + |
|
1544 | + /** |
|
1545 | + * Returns a SecureRandom instance |
|
1546 | + * |
|
1547 | + * @return \OCP\Security\ISecureRandom |
|
1548 | + */ |
|
1549 | + public function getSecureRandom() { |
|
1550 | + return $this->query('SecureRandom'); |
|
1551 | + } |
|
1552 | + |
|
1553 | + /** |
|
1554 | + * Returns a Crypto instance |
|
1555 | + * |
|
1556 | + * @return \OCP\Security\ICrypto |
|
1557 | + */ |
|
1558 | + public function getCrypto() { |
|
1559 | + return $this->query('Crypto'); |
|
1560 | + } |
|
1561 | + |
|
1562 | + /** |
|
1563 | + * Returns a Hasher instance |
|
1564 | + * |
|
1565 | + * @return \OCP\Security\IHasher |
|
1566 | + */ |
|
1567 | + public function getHasher() { |
|
1568 | + return $this->query('Hasher'); |
|
1569 | + } |
|
1570 | + |
|
1571 | + /** |
|
1572 | + * Returns a CredentialsManager instance |
|
1573 | + * |
|
1574 | + * @return \OCP\Security\ICredentialsManager |
|
1575 | + */ |
|
1576 | + public function getCredentialsManager() { |
|
1577 | + return $this->query('CredentialsManager'); |
|
1578 | + } |
|
1579 | + |
|
1580 | + /** |
|
1581 | + * Returns an instance of the HTTP helper class |
|
1582 | + * |
|
1583 | + * @deprecated Use getHTTPClientService() |
|
1584 | + * @return \OC\HTTPHelper |
|
1585 | + */ |
|
1586 | + public function getHTTPHelper() { |
|
1587 | + return $this->query('HTTPHelper'); |
|
1588 | + } |
|
1589 | + |
|
1590 | + /** |
|
1591 | + * Get the certificate manager for the user |
|
1592 | + * |
|
1593 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1594 | + * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1595 | + */ |
|
1596 | + public function getCertificateManager($userId = '') { |
|
1597 | + if ($userId === '') { |
|
1598 | + $userSession = $this->getUserSession(); |
|
1599 | + $user = $userSession->getUser(); |
|
1600 | + if (is_null($user)) { |
|
1601 | + return null; |
|
1602 | + } |
|
1603 | + $userId = $user->getUID(); |
|
1604 | + } |
|
1605 | + return new CertificateManager( |
|
1606 | + $userId, |
|
1607 | + new View(), |
|
1608 | + $this->getConfig(), |
|
1609 | + $this->getLogger(), |
|
1610 | + $this->getSecureRandom() |
|
1611 | + ); |
|
1612 | + } |
|
1613 | + |
|
1614 | + /** |
|
1615 | + * Returns an instance of the HTTP client service |
|
1616 | + * |
|
1617 | + * @return \OCP\Http\Client\IClientService |
|
1618 | + */ |
|
1619 | + public function getHTTPClientService() { |
|
1620 | + return $this->query('HttpClientService'); |
|
1621 | + } |
|
1622 | + |
|
1623 | + /** |
|
1624 | + * Create a new event source |
|
1625 | + * |
|
1626 | + * @return \OCP\IEventSource |
|
1627 | + */ |
|
1628 | + public function createEventSource() { |
|
1629 | + return new \OC_EventSource(); |
|
1630 | + } |
|
1631 | + |
|
1632 | + /** |
|
1633 | + * Get the active event logger |
|
1634 | + * |
|
1635 | + * The returned logger only logs data when debug mode is enabled |
|
1636 | + * |
|
1637 | + * @return \OCP\Diagnostics\IEventLogger |
|
1638 | + */ |
|
1639 | + public function getEventLogger() { |
|
1640 | + return $this->query('EventLogger'); |
|
1641 | + } |
|
1642 | + |
|
1643 | + /** |
|
1644 | + * Get the active query logger |
|
1645 | + * |
|
1646 | + * The returned logger only logs data when debug mode is enabled |
|
1647 | + * |
|
1648 | + * @return \OCP\Diagnostics\IQueryLogger |
|
1649 | + */ |
|
1650 | + public function getQueryLogger() { |
|
1651 | + return $this->query('QueryLogger'); |
|
1652 | + } |
|
1653 | + |
|
1654 | + /** |
|
1655 | + * Get the manager for temporary files and folders |
|
1656 | + * |
|
1657 | + * @return \OCP\ITempManager |
|
1658 | + */ |
|
1659 | + public function getTempManager() { |
|
1660 | + return $this->query('TempManager'); |
|
1661 | + } |
|
1662 | + |
|
1663 | + /** |
|
1664 | + * Get the app manager |
|
1665 | + * |
|
1666 | + * @return \OCP\App\IAppManager |
|
1667 | + */ |
|
1668 | + public function getAppManager() { |
|
1669 | + return $this->query('AppManager'); |
|
1670 | + } |
|
1671 | + |
|
1672 | + /** |
|
1673 | + * Creates a new mailer |
|
1674 | + * |
|
1675 | + * @return \OCP\Mail\IMailer |
|
1676 | + */ |
|
1677 | + public function getMailer() { |
|
1678 | + return $this->query('Mailer'); |
|
1679 | + } |
|
1680 | + |
|
1681 | + /** |
|
1682 | + * Get the webroot |
|
1683 | + * |
|
1684 | + * @return string |
|
1685 | + */ |
|
1686 | + public function getWebRoot() { |
|
1687 | + return $this->webRoot; |
|
1688 | + } |
|
1689 | + |
|
1690 | + /** |
|
1691 | + * @return \OC\OCSClient |
|
1692 | + */ |
|
1693 | + public function getOcsClient() { |
|
1694 | + return $this->query('OcsClient'); |
|
1695 | + } |
|
1696 | + |
|
1697 | + /** |
|
1698 | + * @return \OCP\IDateTimeZone |
|
1699 | + */ |
|
1700 | + public function getDateTimeZone() { |
|
1701 | + return $this->query('DateTimeZone'); |
|
1702 | + } |
|
1703 | + |
|
1704 | + /** |
|
1705 | + * @return \OCP\IDateTimeFormatter |
|
1706 | + */ |
|
1707 | + public function getDateTimeFormatter() { |
|
1708 | + return $this->query('DateTimeFormatter'); |
|
1709 | + } |
|
1710 | + |
|
1711 | + /** |
|
1712 | + * @return \OCP\Files\Config\IMountProviderCollection |
|
1713 | + */ |
|
1714 | + public function getMountProviderCollection() { |
|
1715 | + return $this->query('MountConfigManager'); |
|
1716 | + } |
|
1717 | + |
|
1718 | + /** |
|
1719 | + * Get the IniWrapper |
|
1720 | + * |
|
1721 | + * @return IniGetWrapper |
|
1722 | + */ |
|
1723 | + public function getIniWrapper() { |
|
1724 | + return $this->query('IniWrapper'); |
|
1725 | + } |
|
1726 | + |
|
1727 | + /** |
|
1728 | + * @return \OCP\Command\IBus |
|
1729 | + */ |
|
1730 | + public function getCommandBus() { |
|
1731 | + return $this->query('AsyncCommandBus'); |
|
1732 | + } |
|
1733 | + |
|
1734 | + /** |
|
1735 | + * Get the trusted domain helper |
|
1736 | + * |
|
1737 | + * @return TrustedDomainHelper |
|
1738 | + */ |
|
1739 | + public function getTrustedDomainHelper() { |
|
1740 | + return $this->query('TrustedDomainHelper'); |
|
1741 | + } |
|
1742 | + |
|
1743 | + /** |
|
1744 | + * Get the locking provider |
|
1745 | + * |
|
1746 | + * @return \OCP\Lock\ILockingProvider |
|
1747 | + * @since 8.1.0 |
|
1748 | + */ |
|
1749 | + public function getLockingProvider() { |
|
1750 | + return $this->query('LockingProvider'); |
|
1751 | + } |
|
1752 | + |
|
1753 | + /** |
|
1754 | + * @return \OCP\Files\Mount\IMountManager |
|
1755 | + **/ |
|
1756 | + function getMountManager() { |
|
1757 | + return $this->query('MountManager'); |
|
1758 | + } |
|
1759 | + |
|
1760 | + /** @return \OCP\Files\Config\IUserMountCache */ |
|
1761 | + function getUserMountCache() { |
|
1762 | + return $this->query('UserMountCache'); |
|
1763 | + } |
|
1764 | + |
|
1765 | + /** |
|
1766 | + * Get the MimeTypeDetector |
|
1767 | + * |
|
1768 | + * @return \OCP\Files\IMimeTypeDetector |
|
1769 | + */ |
|
1770 | + public function getMimeTypeDetector() { |
|
1771 | + return $this->query('MimeTypeDetector'); |
|
1772 | + } |
|
1773 | + |
|
1774 | + /** |
|
1775 | + * Get the MimeTypeLoader |
|
1776 | + * |
|
1777 | + * @return \OCP\Files\IMimeTypeLoader |
|
1778 | + */ |
|
1779 | + public function getMimeTypeLoader() { |
|
1780 | + return $this->query('MimeTypeLoader'); |
|
1781 | + } |
|
1782 | + |
|
1783 | + /** |
|
1784 | + * Get the manager of all the capabilities |
|
1785 | + * |
|
1786 | + * @return \OC\CapabilitiesManager |
|
1787 | + */ |
|
1788 | + public function getCapabilitiesManager() { |
|
1789 | + return $this->query('CapabilitiesManager'); |
|
1790 | + } |
|
1791 | + |
|
1792 | + /** |
|
1793 | + * Get the EventDispatcher |
|
1794 | + * |
|
1795 | + * @return EventDispatcherInterface |
|
1796 | + * @since 8.2.0 |
|
1797 | + */ |
|
1798 | + public function getEventDispatcher() { |
|
1799 | + return $this->query('EventDispatcher'); |
|
1800 | + } |
|
1801 | + |
|
1802 | + /** |
|
1803 | + * Get the Notification Manager |
|
1804 | + * |
|
1805 | + * @return \OCP\Notification\IManager |
|
1806 | + * @since 8.2.0 |
|
1807 | + */ |
|
1808 | + public function getNotificationManager() { |
|
1809 | + return $this->query('NotificationManager'); |
|
1810 | + } |
|
1811 | + |
|
1812 | + /** |
|
1813 | + * @return \OCP\Comments\ICommentsManager |
|
1814 | + */ |
|
1815 | + public function getCommentsManager() { |
|
1816 | + return $this->query('CommentsManager'); |
|
1817 | + } |
|
1818 | + |
|
1819 | + /** |
|
1820 | + * @return \OCA\Theming\ThemingDefaults |
|
1821 | + */ |
|
1822 | + public function getThemingDefaults() { |
|
1823 | + return $this->query('ThemingDefaults'); |
|
1824 | + } |
|
1825 | + |
|
1826 | + /** |
|
1827 | + * @return \OC\IntegrityCheck\Checker |
|
1828 | + */ |
|
1829 | + public function getIntegrityCodeChecker() { |
|
1830 | + return $this->query('IntegrityCodeChecker'); |
|
1831 | + } |
|
1832 | + |
|
1833 | + /** |
|
1834 | + * @return \OC\Session\CryptoWrapper |
|
1835 | + */ |
|
1836 | + public function getSessionCryptoWrapper() { |
|
1837 | + return $this->query('CryptoWrapper'); |
|
1838 | + } |
|
1839 | + |
|
1840 | + /** |
|
1841 | + * @return CsrfTokenManager |
|
1842 | + */ |
|
1843 | + public function getCsrfTokenManager() { |
|
1844 | + return $this->query('CsrfTokenManager'); |
|
1845 | + } |
|
1846 | + |
|
1847 | + /** |
|
1848 | + * @return Throttler |
|
1849 | + */ |
|
1850 | + public function getBruteForceThrottler() { |
|
1851 | + return $this->query('Throttler'); |
|
1852 | + } |
|
1853 | + |
|
1854 | + /** |
|
1855 | + * @return IContentSecurityPolicyManager |
|
1856 | + */ |
|
1857 | + public function getContentSecurityPolicyManager() { |
|
1858 | + return $this->query('ContentSecurityPolicyManager'); |
|
1859 | + } |
|
1860 | + |
|
1861 | + /** |
|
1862 | + * @return ContentSecurityPolicyNonceManager |
|
1863 | + */ |
|
1864 | + public function getContentSecurityPolicyNonceManager() { |
|
1865 | + return $this->query('ContentSecurityPolicyNonceManager'); |
|
1866 | + } |
|
1867 | + |
|
1868 | + /** |
|
1869 | + * Not a public API as of 8.2, wait for 9.0 |
|
1870 | + * |
|
1871 | + * @return \OCA\Files_External\Service\BackendService |
|
1872 | + */ |
|
1873 | + public function getStoragesBackendService() { |
|
1874 | + return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1875 | + } |
|
1876 | + |
|
1877 | + /** |
|
1878 | + * Not a public API as of 8.2, wait for 9.0 |
|
1879 | + * |
|
1880 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1881 | + */ |
|
1882 | + public function getGlobalStoragesService() { |
|
1883 | + return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1884 | + } |
|
1885 | + |
|
1886 | + /** |
|
1887 | + * Not a public API as of 8.2, wait for 9.0 |
|
1888 | + * |
|
1889 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1890 | + */ |
|
1891 | + public function getUserGlobalStoragesService() { |
|
1892 | + return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1893 | + } |
|
1894 | + |
|
1895 | + /** |
|
1896 | + * Not a public API as of 8.2, wait for 9.0 |
|
1897 | + * |
|
1898 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
1899 | + */ |
|
1900 | + public function getUserStoragesService() { |
|
1901 | + return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1902 | + } |
|
1903 | + |
|
1904 | + /** |
|
1905 | + * @return \OCP\Share\IManager |
|
1906 | + */ |
|
1907 | + public function getShareManager() { |
|
1908 | + return $this->query('ShareManager'); |
|
1909 | + } |
|
1910 | + |
|
1911 | + /** |
|
1912 | + * @return \OCP\Collaboration\Collaborators\ISearch |
|
1913 | + */ |
|
1914 | + public function getCollaboratorSearch() { |
|
1915 | + return $this->query('CollaboratorSearch'); |
|
1916 | + } |
|
1917 | + |
|
1918 | + /** |
|
1919 | + * @return \OCP\Collaboration\AutoComplete\IManager |
|
1920 | + */ |
|
1921 | + public function getAutoCompleteManager(){ |
|
1922 | + return $this->query(IManager::class); |
|
1923 | + } |
|
1924 | + |
|
1925 | + /** |
|
1926 | + * Returns the LDAP Provider |
|
1927 | + * |
|
1928 | + * @return \OCP\LDAP\ILDAPProvider |
|
1929 | + */ |
|
1930 | + public function getLDAPProvider() { |
|
1931 | + return $this->query('LDAPProvider'); |
|
1932 | + } |
|
1933 | + |
|
1934 | + /** |
|
1935 | + * @return \OCP\Settings\IManager |
|
1936 | + */ |
|
1937 | + public function getSettingsManager() { |
|
1938 | + return $this->query('SettingsManager'); |
|
1939 | + } |
|
1940 | + |
|
1941 | + /** |
|
1942 | + * @return \OCP\Files\IAppData |
|
1943 | + */ |
|
1944 | + public function getAppDataDir($app) { |
|
1945 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
1946 | + $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1947 | + return $factory->get($app); |
|
1948 | + } |
|
1949 | + |
|
1950 | + /** |
|
1951 | + * @return \OCP\Lockdown\ILockdownManager |
|
1952 | + */ |
|
1953 | + public function getLockdownManager() { |
|
1954 | + return $this->query('LockdownManager'); |
|
1955 | + } |
|
1956 | + |
|
1957 | + /** |
|
1958 | + * @return \OCP\Federation\ICloudIdManager |
|
1959 | + */ |
|
1960 | + public function getCloudIdManager() { |
|
1961 | + return $this->query(ICloudIdManager::class); |
|
1962 | + } |
|
1963 | + |
|
1964 | + /** |
|
1965 | + * @return \OCP\Remote\Api\IApiFactory |
|
1966 | + */ |
|
1967 | + public function getRemoteApiFactory() { |
|
1968 | + return $this->query(IApiFactory::class); |
|
1969 | + } |
|
1970 | + |
|
1971 | + /** |
|
1972 | + * @return \OCP\Remote\IInstanceFactory |
|
1973 | + */ |
|
1974 | + public function getRemoteInstanceFactory() { |
|
1975 | + return $this->query(IInstanceFactory::class); |
|
1976 | + } |
|
1977 | 1977 | } |
@@ -49,356 +49,356 @@ |
||
49 | 49 | use OCP\Util; |
50 | 50 | |
51 | 51 | class Manager implements IManager { |
52 | - /** @var ILogger */ |
|
53 | - private $log; |
|
54 | - /** @var IDBConnection */ |
|
55 | - private $dbc; |
|
56 | - /** @var IL10N */ |
|
57 | - private $l; |
|
58 | - /** @var IConfig */ |
|
59 | - private $config; |
|
60 | - /** @var EncryptionManager */ |
|
61 | - private $encryptionManager; |
|
62 | - /** @var IUserManager */ |
|
63 | - private $userManager; |
|
64 | - /** @var ILockingProvider */ |
|
65 | - private $lockingProvider; |
|
66 | - /** @var IRequest */ |
|
67 | - private $request; |
|
68 | - /** @var IURLGenerator */ |
|
69 | - private $url; |
|
70 | - /** @var AccountManager */ |
|
71 | - private $accountManager; |
|
72 | - /** @var IGroupManager */ |
|
73 | - private $groupManager; |
|
74 | - /** @var IFactory */ |
|
75 | - private $l10nFactory; |
|
76 | - /** @var IAppManager */ |
|
77 | - private $appManager; |
|
78 | - |
|
79 | - /** |
|
80 | - * @param ILogger $log |
|
81 | - * @param IDBConnection $dbc |
|
82 | - * @param IL10N $l |
|
83 | - * @param IConfig $config |
|
84 | - * @param EncryptionManager $encryptionManager |
|
85 | - * @param IUserManager $userManager |
|
86 | - * @param ILockingProvider $lockingProvider |
|
87 | - * @param IRequest $request |
|
88 | - * @param IURLGenerator $url |
|
89 | - * @param AccountManager $accountManager |
|
90 | - * @param IGroupManager $groupManager |
|
91 | - * @param IFactory $l10nFactory |
|
92 | - * @param IAppManager $appManager |
|
93 | - */ |
|
94 | - public function __construct( |
|
95 | - ILogger $log, |
|
96 | - IDBConnection $dbc, |
|
97 | - IL10N $l, |
|
98 | - IConfig $config, |
|
99 | - EncryptionManager $encryptionManager, |
|
100 | - IUserManager $userManager, |
|
101 | - ILockingProvider $lockingProvider, |
|
102 | - IRequest $request, |
|
103 | - IURLGenerator $url, |
|
104 | - AccountManager $accountManager, |
|
105 | - IGroupManager $groupManager, |
|
106 | - IFactory $l10nFactory, |
|
107 | - IAppManager $appManager |
|
108 | - ) { |
|
109 | - $this->log = $log; |
|
110 | - $this->dbc = $dbc; |
|
111 | - $this->l = $l; |
|
112 | - $this->config = $config; |
|
113 | - $this->encryptionManager = $encryptionManager; |
|
114 | - $this->userManager = $userManager; |
|
115 | - $this->lockingProvider = $lockingProvider; |
|
116 | - $this->request = $request; |
|
117 | - $this->url = $url; |
|
118 | - $this->accountManager = $accountManager; |
|
119 | - $this->groupManager = $groupManager; |
|
120 | - $this->l10nFactory = $l10nFactory; |
|
121 | - $this->appManager = $appManager; |
|
122 | - } |
|
123 | - |
|
124 | - /** @var array */ |
|
125 | - protected $sectionClasses = []; |
|
126 | - |
|
127 | - /** @var array */ |
|
128 | - protected $sections = []; |
|
129 | - |
|
130 | - /** |
|
131 | - * @param string $type 'admin' or 'personal' |
|
132 | - * @param string $section Class must implement OCP\Settings\ISection |
|
133 | - * @return void |
|
134 | - */ |
|
135 | - public function registerSection(string $type, string $section) { |
|
136 | - $this->sectionClasses[$section] = $type; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @param string $type 'admin' or 'personal' |
|
141 | - * @return ISection[] |
|
142 | - */ |
|
143 | - protected function getSections(string $type): array { |
|
144 | - if (!isset($this->sections[$type])) { |
|
145 | - $this->sections[$type] = []; |
|
146 | - } |
|
147 | - |
|
148 | - foreach ($this->sectionClasses as $class => $sectionType) { |
|
149 | - try { |
|
150 | - /** @var ISection $section */ |
|
151 | - $section = \OC::$server->query($class); |
|
152 | - } catch (QueryException $e) { |
|
153 | - $this->log->logException($e, ['level' => Util::INFO]); |
|
154 | - continue; |
|
155 | - } |
|
156 | - |
|
157 | - if (!$section instanceof ISection) { |
|
158 | - $this->log->logException(new \InvalidArgumentException('Invalid settings section registered'), ['level' => Util::INFO]); |
|
159 | - continue; |
|
160 | - } |
|
161 | - |
|
162 | - $this->sections[$sectionType][$section->getID()] = $section; |
|
163 | - |
|
164 | - unset($this->sectionClasses[$class]); |
|
165 | - } |
|
166 | - |
|
167 | - return $this->sections[$type]; |
|
168 | - } |
|
169 | - |
|
170 | - /** @var array */ |
|
171 | - protected $settingClasses = []; |
|
172 | - |
|
173 | - /** @var array */ |
|
174 | - protected $settings = []; |
|
175 | - |
|
176 | - /** |
|
177 | - * @param string $type 'admin' or 'personal' |
|
178 | - * @param string $setting Class must implement OCP\Settings\ISetting |
|
179 | - * @return void |
|
180 | - */ |
|
181 | - public function registerSetting(string $type, string $setting) { |
|
182 | - $this->settingClasses[$setting] = $type; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * @param string $type 'admin' or 'personal' |
|
187 | - * @param string $section |
|
188 | - * @return ISettings[] |
|
189 | - */ |
|
190 | - protected function getSettings(string $type, string $section): array { |
|
191 | - if (!isset($this->settings[$type])) { |
|
192 | - $this->settings[$type] = []; |
|
193 | - } |
|
194 | - if (!isset($this->settings[$type][$section])) { |
|
195 | - $this->settings[$type][$section] = []; |
|
196 | - } |
|
197 | - |
|
198 | - foreach ($this->settingClasses as $class => $settingsType) { |
|
199 | - try { |
|
200 | - /** @var ISettings $setting */ |
|
201 | - $setting = \OC::$server->query($class); |
|
202 | - } catch (QueryException $e) { |
|
203 | - $this->log->logException($e, ['level' => Util::INFO]); |
|
204 | - continue; |
|
205 | - } |
|
206 | - |
|
207 | - if (!$setting instanceof ISettings) { |
|
208 | - $this->log->logException(new \InvalidArgumentException('Invalid settings setting registered'), ['level' => Util::INFO]); |
|
209 | - continue; |
|
210 | - } |
|
211 | - |
|
212 | - if (!isset($this->settings[$settingsType][$setting->getSection()])) { |
|
213 | - $this->settings[$settingsType][$setting->getSection()] = []; |
|
214 | - } |
|
215 | - $this->settings[$settingsType][$setting->getSection()][] = $setting; |
|
216 | - |
|
217 | - unset($this->settingClasses[$class]); |
|
218 | - } |
|
219 | - |
|
220 | - return $this->settings[$type][$section]; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * @inheritdoc |
|
225 | - */ |
|
226 | - public function getAdminSections(): array { |
|
227 | - // built-in sections |
|
228 | - $sections = [ |
|
229 | - 0 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('settings', 'admin.svg'))], |
|
230 | - 5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))], |
|
231 | - 10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
232 | - 45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
233 | - 98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
234 | - 99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0, $this->url->imagePath('settings', 'help.svg'))], |
|
235 | - ]; |
|
236 | - |
|
237 | - $appSections = $this->getSections('admin'); |
|
238 | - |
|
239 | - foreach ($appSections as $section) { |
|
240 | - /** @var ISection $section */ |
|
241 | - if (!isset($sections[$section->getPriority()])) { |
|
242 | - $sections[$section->getPriority()] = []; |
|
243 | - } |
|
244 | - |
|
245 | - $sections[$section->getPriority()][] = $section; |
|
246 | - } |
|
247 | - |
|
248 | - ksort($sections); |
|
249 | - |
|
250 | - return $sections; |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * @param string $section |
|
255 | - * @return ISection[] |
|
256 | - */ |
|
257 | - private function getBuiltInAdminSettings($section): array { |
|
258 | - $forms = []; |
|
259 | - |
|
260 | - if ($section === 'server') { |
|
261 | - /** @var ISettings $form */ |
|
262 | - $form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l); |
|
263 | - $forms[$form->getPriority()] = [$form]; |
|
264 | - $form = new Admin\ServerDevNotice(); |
|
265 | - $forms[$form->getPriority()] = [$form]; |
|
266 | - } |
|
267 | - if ($section === 'encryption') { |
|
268 | - /** @var ISettings $form */ |
|
269 | - $form = new Admin\Encryption($this->encryptionManager, $this->userManager); |
|
270 | - $forms[$form->getPriority()] = [$form]; |
|
271 | - } |
|
272 | - if ($section === 'sharing') { |
|
273 | - /** @var ISettings $form */ |
|
274 | - $form = new Admin\Sharing($this->config); |
|
275 | - $forms[$form->getPriority()] = [$form]; |
|
276 | - } |
|
277 | - if ($section === 'additional') { |
|
278 | - /** @var ISettings $form */ |
|
279 | - $form = new Admin\Additional($this->config); |
|
280 | - $forms[$form->getPriority()] = [$form]; |
|
281 | - } |
|
282 | - if ($section === 'tips-tricks') { |
|
283 | - /** @var ISettings $form */ |
|
284 | - $form = new Admin\TipsTricks($this->config); |
|
285 | - $forms[$form->getPriority()] = [$form]; |
|
286 | - } |
|
287 | - |
|
288 | - return $forms; |
|
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * @param string $section |
|
293 | - * @return ISection[] |
|
294 | - */ |
|
295 | - private function getBuiltInPersonalSettings($section): array { |
|
296 | - $forms = []; |
|
297 | - |
|
298 | - if ($section === 'personal-info') { |
|
299 | - /** @var ISettings $form */ |
|
300 | - $form = new Personal\PersonalInfo( |
|
301 | - $this->config, |
|
302 | - $this->userManager, |
|
303 | - $this->groupManager, |
|
304 | - $this->accountManager, |
|
305 | - $this->appManager, |
|
306 | - $this->l10nFactory, |
|
307 | - $this->l |
|
308 | - ); |
|
309 | - $forms[$form->getPriority()] = [$form]; |
|
310 | - } |
|
311 | - if($section === 'security') { |
|
312 | - /** @var ISettings $form */ |
|
313 | - $form = new Personal\Security(); |
|
314 | - $forms[$form->getPriority()] = [$form]; |
|
315 | - } |
|
316 | - if ($section === 'additional') { |
|
317 | - /** @var ISettings $form */ |
|
318 | - $form = new Personal\Additional(); |
|
319 | - $forms[$form->getPriority()] = [$form]; |
|
320 | - } |
|
321 | - |
|
322 | - return $forms; |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * @inheritdoc |
|
327 | - */ |
|
328 | - public function getAdminSettings($section): array { |
|
329 | - $settings = $this->getBuiltInAdminSettings($section); |
|
330 | - $appSettings = $this->getSettings('admin', $section); |
|
331 | - |
|
332 | - foreach ($appSettings as $setting) { |
|
333 | - if (!isset($settings[$setting->getPriority()])) { |
|
334 | - $settings[$setting->getPriority()] = []; |
|
335 | - } |
|
336 | - $settings[$setting->getPriority()][] = $setting; |
|
337 | - } |
|
338 | - |
|
339 | - ksort($settings); |
|
340 | - return $settings; |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * @inheritdoc |
|
345 | - */ |
|
346 | - public function getPersonalSections(): array { |
|
347 | - $sections = [ |
|
348 | - 0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))], |
|
349 | - 5 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('settings', 'password.svg'))], |
|
350 | - 15 => [new Section('sync-clients', $this->l->t('Sync clients'), 0, $this->url->imagePath('settings', 'change.svg'))], |
|
351 | - ]; |
|
352 | - |
|
353 | - $legacyForms = \OC_App::getForms('personal'); |
|
354 | - if(!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms)) { |
|
355 | - $sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))]; |
|
356 | - } |
|
357 | - |
|
358 | - $appSections = $this->getSections('personal'); |
|
359 | - |
|
360 | - foreach ($appSections as $section) { |
|
361 | - /** @var ISection $section */ |
|
362 | - if (!isset($sections[$section->getPriority()])) { |
|
363 | - $sections[$section->getPriority()] = []; |
|
364 | - } |
|
365 | - |
|
366 | - $sections[$section->getPriority()][] = $section; |
|
367 | - } |
|
368 | - |
|
369 | - ksort($sections); |
|
370 | - |
|
371 | - return $sections; |
|
372 | - } |
|
373 | - |
|
374 | - /** |
|
375 | - * @param string[] $forms |
|
376 | - * @return bool |
|
377 | - */ |
|
378 | - private function hasLegacyPersonalSettingsToRender(array $forms): bool { |
|
379 | - foreach ($forms as $form) { |
|
380 | - if(trim($form) !== '') { |
|
381 | - return true; |
|
382 | - } |
|
383 | - } |
|
384 | - return false; |
|
385 | - } |
|
386 | - |
|
387 | - /** |
|
388 | - * @inheritdoc |
|
389 | - */ |
|
390 | - public function getPersonalSettings($section): array { |
|
391 | - $settings = $this->getBuiltInPersonalSettings($section); |
|
392 | - $appSettings = $this->getSettings('personal', $section); |
|
393 | - |
|
394 | - foreach ($appSettings as $setting) { |
|
395 | - if (!isset($settings[$setting->getPriority()])) { |
|
396 | - $settings[$setting->getPriority()] = []; |
|
397 | - } |
|
398 | - $settings[$setting->getPriority()][] = $setting; |
|
399 | - } |
|
400 | - |
|
401 | - ksort($settings); |
|
402 | - return $settings; |
|
403 | - } |
|
52 | + /** @var ILogger */ |
|
53 | + private $log; |
|
54 | + /** @var IDBConnection */ |
|
55 | + private $dbc; |
|
56 | + /** @var IL10N */ |
|
57 | + private $l; |
|
58 | + /** @var IConfig */ |
|
59 | + private $config; |
|
60 | + /** @var EncryptionManager */ |
|
61 | + private $encryptionManager; |
|
62 | + /** @var IUserManager */ |
|
63 | + private $userManager; |
|
64 | + /** @var ILockingProvider */ |
|
65 | + private $lockingProvider; |
|
66 | + /** @var IRequest */ |
|
67 | + private $request; |
|
68 | + /** @var IURLGenerator */ |
|
69 | + private $url; |
|
70 | + /** @var AccountManager */ |
|
71 | + private $accountManager; |
|
72 | + /** @var IGroupManager */ |
|
73 | + private $groupManager; |
|
74 | + /** @var IFactory */ |
|
75 | + private $l10nFactory; |
|
76 | + /** @var IAppManager */ |
|
77 | + private $appManager; |
|
78 | + |
|
79 | + /** |
|
80 | + * @param ILogger $log |
|
81 | + * @param IDBConnection $dbc |
|
82 | + * @param IL10N $l |
|
83 | + * @param IConfig $config |
|
84 | + * @param EncryptionManager $encryptionManager |
|
85 | + * @param IUserManager $userManager |
|
86 | + * @param ILockingProvider $lockingProvider |
|
87 | + * @param IRequest $request |
|
88 | + * @param IURLGenerator $url |
|
89 | + * @param AccountManager $accountManager |
|
90 | + * @param IGroupManager $groupManager |
|
91 | + * @param IFactory $l10nFactory |
|
92 | + * @param IAppManager $appManager |
|
93 | + */ |
|
94 | + public function __construct( |
|
95 | + ILogger $log, |
|
96 | + IDBConnection $dbc, |
|
97 | + IL10N $l, |
|
98 | + IConfig $config, |
|
99 | + EncryptionManager $encryptionManager, |
|
100 | + IUserManager $userManager, |
|
101 | + ILockingProvider $lockingProvider, |
|
102 | + IRequest $request, |
|
103 | + IURLGenerator $url, |
|
104 | + AccountManager $accountManager, |
|
105 | + IGroupManager $groupManager, |
|
106 | + IFactory $l10nFactory, |
|
107 | + IAppManager $appManager |
|
108 | + ) { |
|
109 | + $this->log = $log; |
|
110 | + $this->dbc = $dbc; |
|
111 | + $this->l = $l; |
|
112 | + $this->config = $config; |
|
113 | + $this->encryptionManager = $encryptionManager; |
|
114 | + $this->userManager = $userManager; |
|
115 | + $this->lockingProvider = $lockingProvider; |
|
116 | + $this->request = $request; |
|
117 | + $this->url = $url; |
|
118 | + $this->accountManager = $accountManager; |
|
119 | + $this->groupManager = $groupManager; |
|
120 | + $this->l10nFactory = $l10nFactory; |
|
121 | + $this->appManager = $appManager; |
|
122 | + } |
|
123 | + |
|
124 | + /** @var array */ |
|
125 | + protected $sectionClasses = []; |
|
126 | + |
|
127 | + /** @var array */ |
|
128 | + protected $sections = []; |
|
129 | + |
|
130 | + /** |
|
131 | + * @param string $type 'admin' or 'personal' |
|
132 | + * @param string $section Class must implement OCP\Settings\ISection |
|
133 | + * @return void |
|
134 | + */ |
|
135 | + public function registerSection(string $type, string $section) { |
|
136 | + $this->sectionClasses[$section] = $type; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @param string $type 'admin' or 'personal' |
|
141 | + * @return ISection[] |
|
142 | + */ |
|
143 | + protected function getSections(string $type): array { |
|
144 | + if (!isset($this->sections[$type])) { |
|
145 | + $this->sections[$type] = []; |
|
146 | + } |
|
147 | + |
|
148 | + foreach ($this->sectionClasses as $class => $sectionType) { |
|
149 | + try { |
|
150 | + /** @var ISection $section */ |
|
151 | + $section = \OC::$server->query($class); |
|
152 | + } catch (QueryException $e) { |
|
153 | + $this->log->logException($e, ['level' => Util::INFO]); |
|
154 | + continue; |
|
155 | + } |
|
156 | + |
|
157 | + if (!$section instanceof ISection) { |
|
158 | + $this->log->logException(new \InvalidArgumentException('Invalid settings section registered'), ['level' => Util::INFO]); |
|
159 | + continue; |
|
160 | + } |
|
161 | + |
|
162 | + $this->sections[$sectionType][$section->getID()] = $section; |
|
163 | + |
|
164 | + unset($this->sectionClasses[$class]); |
|
165 | + } |
|
166 | + |
|
167 | + return $this->sections[$type]; |
|
168 | + } |
|
169 | + |
|
170 | + /** @var array */ |
|
171 | + protected $settingClasses = []; |
|
172 | + |
|
173 | + /** @var array */ |
|
174 | + protected $settings = []; |
|
175 | + |
|
176 | + /** |
|
177 | + * @param string $type 'admin' or 'personal' |
|
178 | + * @param string $setting Class must implement OCP\Settings\ISetting |
|
179 | + * @return void |
|
180 | + */ |
|
181 | + public function registerSetting(string $type, string $setting) { |
|
182 | + $this->settingClasses[$setting] = $type; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * @param string $type 'admin' or 'personal' |
|
187 | + * @param string $section |
|
188 | + * @return ISettings[] |
|
189 | + */ |
|
190 | + protected function getSettings(string $type, string $section): array { |
|
191 | + if (!isset($this->settings[$type])) { |
|
192 | + $this->settings[$type] = []; |
|
193 | + } |
|
194 | + if (!isset($this->settings[$type][$section])) { |
|
195 | + $this->settings[$type][$section] = []; |
|
196 | + } |
|
197 | + |
|
198 | + foreach ($this->settingClasses as $class => $settingsType) { |
|
199 | + try { |
|
200 | + /** @var ISettings $setting */ |
|
201 | + $setting = \OC::$server->query($class); |
|
202 | + } catch (QueryException $e) { |
|
203 | + $this->log->logException($e, ['level' => Util::INFO]); |
|
204 | + continue; |
|
205 | + } |
|
206 | + |
|
207 | + if (!$setting instanceof ISettings) { |
|
208 | + $this->log->logException(new \InvalidArgumentException('Invalid settings setting registered'), ['level' => Util::INFO]); |
|
209 | + continue; |
|
210 | + } |
|
211 | + |
|
212 | + if (!isset($this->settings[$settingsType][$setting->getSection()])) { |
|
213 | + $this->settings[$settingsType][$setting->getSection()] = []; |
|
214 | + } |
|
215 | + $this->settings[$settingsType][$setting->getSection()][] = $setting; |
|
216 | + |
|
217 | + unset($this->settingClasses[$class]); |
|
218 | + } |
|
219 | + |
|
220 | + return $this->settings[$type][$section]; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * @inheritdoc |
|
225 | + */ |
|
226 | + public function getAdminSections(): array { |
|
227 | + // built-in sections |
|
228 | + $sections = [ |
|
229 | + 0 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('settings', 'admin.svg'))], |
|
230 | + 5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))], |
|
231 | + 10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
232 | + 45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
233 | + 98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
234 | + 99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0, $this->url->imagePath('settings', 'help.svg'))], |
|
235 | + ]; |
|
236 | + |
|
237 | + $appSections = $this->getSections('admin'); |
|
238 | + |
|
239 | + foreach ($appSections as $section) { |
|
240 | + /** @var ISection $section */ |
|
241 | + if (!isset($sections[$section->getPriority()])) { |
|
242 | + $sections[$section->getPriority()] = []; |
|
243 | + } |
|
244 | + |
|
245 | + $sections[$section->getPriority()][] = $section; |
|
246 | + } |
|
247 | + |
|
248 | + ksort($sections); |
|
249 | + |
|
250 | + return $sections; |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * @param string $section |
|
255 | + * @return ISection[] |
|
256 | + */ |
|
257 | + private function getBuiltInAdminSettings($section): array { |
|
258 | + $forms = []; |
|
259 | + |
|
260 | + if ($section === 'server') { |
|
261 | + /** @var ISettings $form */ |
|
262 | + $form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l); |
|
263 | + $forms[$form->getPriority()] = [$form]; |
|
264 | + $form = new Admin\ServerDevNotice(); |
|
265 | + $forms[$form->getPriority()] = [$form]; |
|
266 | + } |
|
267 | + if ($section === 'encryption') { |
|
268 | + /** @var ISettings $form */ |
|
269 | + $form = new Admin\Encryption($this->encryptionManager, $this->userManager); |
|
270 | + $forms[$form->getPriority()] = [$form]; |
|
271 | + } |
|
272 | + if ($section === 'sharing') { |
|
273 | + /** @var ISettings $form */ |
|
274 | + $form = new Admin\Sharing($this->config); |
|
275 | + $forms[$form->getPriority()] = [$form]; |
|
276 | + } |
|
277 | + if ($section === 'additional') { |
|
278 | + /** @var ISettings $form */ |
|
279 | + $form = new Admin\Additional($this->config); |
|
280 | + $forms[$form->getPriority()] = [$form]; |
|
281 | + } |
|
282 | + if ($section === 'tips-tricks') { |
|
283 | + /** @var ISettings $form */ |
|
284 | + $form = new Admin\TipsTricks($this->config); |
|
285 | + $forms[$form->getPriority()] = [$form]; |
|
286 | + } |
|
287 | + |
|
288 | + return $forms; |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * @param string $section |
|
293 | + * @return ISection[] |
|
294 | + */ |
|
295 | + private function getBuiltInPersonalSettings($section): array { |
|
296 | + $forms = []; |
|
297 | + |
|
298 | + if ($section === 'personal-info') { |
|
299 | + /** @var ISettings $form */ |
|
300 | + $form = new Personal\PersonalInfo( |
|
301 | + $this->config, |
|
302 | + $this->userManager, |
|
303 | + $this->groupManager, |
|
304 | + $this->accountManager, |
|
305 | + $this->appManager, |
|
306 | + $this->l10nFactory, |
|
307 | + $this->l |
|
308 | + ); |
|
309 | + $forms[$form->getPriority()] = [$form]; |
|
310 | + } |
|
311 | + if($section === 'security') { |
|
312 | + /** @var ISettings $form */ |
|
313 | + $form = new Personal\Security(); |
|
314 | + $forms[$form->getPriority()] = [$form]; |
|
315 | + } |
|
316 | + if ($section === 'additional') { |
|
317 | + /** @var ISettings $form */ |
|
318 | + $form = new Personal\Additional(); |
|
319 | + $forms[$form->getPriority()] = [$form]; |
|
320 | + } |
|
321 | + |
|
322 | + return $forms; |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * @inheritdoc |
|
327 | + */ |
|
328 | + public function getAdminSettings($section): array { |
|
329 | + $settings = $this->getBuiltInAdminSettings($section); |
|
330 | + $appSettings = $this->getSettings('admin', $section); |
|
331 | + |
|
332 | + foreach ($appSettings as $setting) { |
|
333 | + if (!isset($settings[$setting->getPriority()])) { |
|
334 | + $settings[$setting->getPriority()] = []; |
|
335 | + } |
|
336 | + $settings[$setting->getPriority()][] = $setting; |
|
337 | + } |
|
338 | + |
|
339 | + ksort($settings); |
|
340 | + return $settings; |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * @inheritdoc |
|
345 | + */ |
|
346 | + public function getPersonalSections(): array { |
|
347 | + $sections = [ |
|
348 | + 0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))], |
|
349 | + 5 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('settings', 'password.svg'))], |
|
350 | + 15 => [new Section('sync-clients', $this->l->t('Sync clients'), 0, $this->url->imagePath('settings', 'change.svg'))], |
|
351 | + ]; |
|
352 | + |
|
353 | + $legacyForms = \OC_App::getForms('personal'); |
|
354 | + if(!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms)) { |
|
355 | + $sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))]; |
|
356 | + } |
|
357 | + |
|
358 | + $appSections = $this->getSections('personal'); |
|
359 | + |
|
360 | + foreach ($appSections as $section) { |
|
361 | + /** @var ISection $section */ |
|
362 | + if (!isset($sections[$section->getPriority()])) { |
|
363 | + $sections[$section->getPriority()] = []; |
|
364 | + } |
|
365 | + |
|
366 | + $sections[$section->getPriority()][] = $section; |
|
367 | + } |
|
368 | + |
|
369 | + ksort($sections); |
|
370 | + |
|
371 | + return $sections; |
|
372 | + } |
|
373 | + |
|
374 | + /** |
|
375 | + * @param string[] $forms |
|
376 | + * @return bool |
|
377 | + */ |
|
378 | + private function hasLegacyPersonalSettingsToRender(array $forms): bool { |
|
379 | + foreach ($forms as $form) { |
|
380 | + if(trim($form) !== '') { |
|
381 | + return true; |
|
382 | + } |
|
383 | + } |
|
384 | + return false; |
|
385 | + } |
|
386 | + |
|
387 | + /** |
|
388 | + * @inheritdoc |
|
389 | + */ |
|
390 | + public function getPersonalSettings($section): array { |
|
391 | + $settings = $this->getBuiltInPersonalSettings($section); |
|
392 | + $appSettings = $this->getSettings('personal', $section); |
|
393 | + |
|
394 | + foreach ($appSettings as $setting) { |
|
395 | + if (!isset($settings[$setting->getPriority()])) { |
|
396 | + $settings[$setting->getPriority()] = []; |
|
397 | + } |
|
398 | + $settings[$setting->getPriority()][] = $setting; |
|
399 | + } |
|
400 | + |
|
401 | + ksort($settings); |
|
402 | + return $settings; |
|
403 | + } |
|
404 | 404 | } |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | ); |
309 | 309 | $forms[$form->getPriority()] = [$form]; |
310 | 310 | } |
311 | - if($section === 'security') { |
|
311 | + if ($section === 'security') { |
|
312 | 312 | /** @var ISettings $form */ |
313 | 313 | $form = new Personal\Security(); |
314 | 314 | $forms[$form->getPriority()] = [$form]; |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | ]; |
352 | 352 | |
353 | 353 | $legacyForms = \OC_App::getForms('personal'); |
354 | - if(!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms)) { |
|
354 | + if (!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms)) { |
|
355 | 355 | $sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))]; |
356 | 356 | } |
357 | 357 | |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | */ |
378 | 378 | private function hasLegacyPersonalSettingsToRender(array $forms): bool { |
379 | 379 | foreach ($forms as $form) { |
380 | - if(trim($form) !== '') { |
|
380 | + if (trim($form) !== '') { |
|
381 | 381 | return true; |
382 | 382 | } |
383 | 383 | } |
@@ -28,71 +28,71 @@ |
||
28 | 28 | * @since 9.1 |
29 | 29 | */ |
30 | 30 | interface IManager { |
31 | - /** |
|
32 | - * @since 9.1.0 |
|
33 | - */ |
|
34 | - const KEY_ADMIN_SETTINGS = 'admin'; |
|
31 | + /** |
|
32 | + * @since 9.1.0 |
|
33 | + */ |
|
34 | + const KEY_ADMIN_SETTINGS = 'admin'; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @since 9.1.0 |
|
38 | - */ |
|
39 | - const KEY_ADMIN_SECTION = 'admin-section'; |
|
36 | + /** |
|
37 | + * @since 9.1.0 |
|
38 | + */ |
|
39 | + const KEY_ADMIN_SECTION = 'admin-section'; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @since 13.0.0 |
|
43 | - */ |
|
44 | - const KEY_PERSONAL_SETTINGS = 'personal'; |
|
41 | + /** |
|
42 | + * @since 13.0.0 |
|
43 | + */ |
|
44 | + const KEY_PERSONAL_SETTINGS = 'personal'; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @since 13.0.0 |
|
48 | - */ |
|
49 | - const KEY_PERSONAL_SECTION = 'personal-section'; |
|
46 | + /** |
|
47 | + * @since 13.0.0 |
|
48 | + */ |
|
49 | + const KEY_PERSONAL_SECTION = 'personal-section'; |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param string $type 'admin' or 'personal' |
|
53 | - * @param string $section Class must implement OCP\Settings\ISection |
|
54 | - * @since 14.0.0 |
|
55 | - */ |
|
56 | - public function registerSection(string $type, string $section); |
|
51 | + /** |
|
52 | + * @param string $type 'admin' or 'personal' |
|
53 | + * @param string $section Class must implement OCP\Settings\ISection |
|
54 | + * @since 14.0.0 |
|
55 | + */ |
|
56 | + public function registerSection(string $type, string $section); |
|
57 | 57 | |
58 | - /** |
|
59 | - * @param string $type 'admin' or 'personal' |
|
60 | - * @param string $setting Class must implement OCP\Settings\ISetting |
|
61 | - * @since 14.0.0 |
|
62 | - */ |
|
63 | - public function registerSetting(string $type, string $setting); |
|
58 | + /** |
|
59 | + * @param string $type 'admin' or 'personal' |
|
60 | + * @param string $setting Class must implement OCP\Settings\ISetting |
|
61 | + * @since 14.0.0 |
|
62 | + */ |
|
63 | + public function registerSetting(string $type, string $setting); |
|
64 | 64 | |
65 | - /** |
|
66 | - * returns a list of the admin sections |
|
67 | - * |
|
68 | - * @return array array of ISection[] where key is the priority |
|
69 | - * @since 9.1.0 |
|
70 | - */ |
|
71 | - public function getAdminSections(): array; |
|
65 | + /** |
|
66 | + * returns a list of the admin sections |
|
67 | + * |
|
68 | + * @return array array of ISection[] where key is the priority |
|
69 | + * @since 9.1.0 |
|
70 | + */ |
|
71 | + public function getAdminSections(): array; |
|
72 | 72 | |
73 | - /** |
|
74 | - * returns a list of the personal sections |
|
75 | - * |
|
76 | - * @return array array of ISection[] where key is the priority |
|
77 | - * @since 13.0.0 |
|
78 | - */ |
|
79 | - public function getPersonalSections(): array; |
|
73 | + /** |
|
74 | + * returns a list of the personal sections |
|
75 | + * |
|
76 | + * @return array array of ISection[] where key is the priority |
|
77 | + * @since 13.0.0 |
|
78 | + */ |
|
79 | + public function getPersonalSections(): array; |
|
80 | 80 | |
81 | - /** |
|
82 | - * returns a list of the admin settings |
|
83 | - * |
|
84 | - * @param string $section the section id for which to load the settings |
|
85 | - * @return array array of IAdmin[] where key is the priority |
|
86 | - * @since 9.1.0 |
|
87 | - */ |
|
88 | - public function getAdminSettings($section): array; |
|
81 | + /** |
|
82 | + * returns a list of the admin settings |
|
83 | + * |
|
84 | + * @param string $section the section id for which to load the settings |
|
85 | + * @return array array of IAdmin[] where key is the priority |
|
86 | + * @since 9.1.0 |
|
87 | + */ |
|
88 | + public function getAdminSettings($section): array; |
|
89 | 89 | |
90 | - /** |
|
91 | - * returns a list of the personal settings |
|
92 | - * |
|
93 | - * @param string $section the section id for which to load the settings |
|
94 | - * @return array array of IPersonal[] where key is the priority |
|
95 | - * @since 13.0.0 |
|
96 | - */ |
|
97 | - public function getPersonalSettings($section): array; |
|
90 | + /** |
|
91 | + * returns a list of the personal settings |
|
92 | + * |
|
93 | + * @param string $section the section id for which to load the settings |
|
94 | + * @return array array of IPersonal[] where key is the priority |
|
95 | + * @since 13.0.0 |
|
96 | + */ |
|
97 | + public function getPersonalSettings($section): array; |
|
98 | 98 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | /** |
37 | 37 | * @since 9.1.0 |
38 | 38 | */ |
39 | - const KEY_ADMIN_SECTION = 'admin-section'; |
|
39 | + const KEY_ADMIN_SECTION = 'admin-section'; |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * @since 13.0.0 |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | /** |
47 | 47 | * @since 13.0.0 |
48 | 48 | */ |
49 | - const KEY_PERSONAL_SECTION = 'personal-section'; |
|
49 | + const KEY_PERSONAL_SECTION = 'personal-section'; |
|
50 | 50 | |
51 | 51 | /** |
52 | 52 | * @param string $type 'admin' or 'personal' |
@@ -62,993 +62,993 @@ |
||
62 | 62 | * OC_autoload! |
63 | 63 | */ |
64 | 64 | class OC { |
65 | - /** |
|
66 | - * Associative array for autoloading. classname => filename |
|
67 | - */ |
|
68 | - public static $CLASSPATH = array(); |
|
69 | - /** |
|
70 | - * The installation path for Nextcloud on the server (e.g. /srv/http/nextcloud) |
|
71 | - */ |
|
72 | - public static $SERVERROOT = ''; |
|
73 | - /** |
|
74 | - * the current request path relative to the Nextcloud root (e.g. files/index.php) |
|
75 | - */ |
|
76 | - private static $SUBURI = ''; |
|
77 | - /** |
|
78 | - * the Nextcloud root path for http requests (e.g. nextcloud/) |
|
79 | - */ |
|
80 | - public static $WEBROOT = ''; |
|
81 | - /** |
|
82 | - * The installation path array of the apps folder on the server (e.g. /srv/http/nextcloud) 'path' and |
|
83 | - * web path in 'url' |
|
84 | - */ |
|
85 | - public static $APPSROOTS = array(); |
|
86 | - |
|
87 | - /** |
|
88 | - * @var string |
|
89 | - */ |
|
90 | - public static $configDir; |
|
91 | - |
|
92 | - /** |
|
93 | - * requested app |
|
94 | - */ |
|
95 | - public static $REQUESTEDAPP = ''; |
|
96 | - |
|
97 | - /** |
|
98 | - * check if Nextcloud runs in cli mode |
|
99 | - */ |
|
100 | - public static $CLI = false; |
|
101 | - |
|
102 | - /** |
|
103 | - * @var \OC\Autoloader $loader |
|
104 | - */ |
|
105 | - public static $loader = null; |
|
106 | - |
|
107 | - /** @var \Composer\Autoload\ClassLoader $composerAutoloader */ |
|
108 | - public static $composerAutoloader = null; |
|
109 | - |
|
110 | - /** |
|
111 | - * @var \OC\Server |
|
112 | - */ |
|
113 | - public static $server = null; |
|
114 | - |
|
115 | - /** |
|
116 | - * @var \OC\Config |
|
117 | - */ |
|
118 | - private static $config = null; |
|
119 | - |
|
120 | - /** |
|
121 | - * @throws \RuntimeException when the 3rdparty directory is missing or |
|
122 | - * the app path list is empty or contains an invalid path |
|
123 | - */ |
|
124 | - public static function initPaths() { |
|
125 | - if(defined('PHPUNIT_CONFIG_DIR')) { |
|
126 | - self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
127 | - } elseif(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
128 | - self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
129 | - } elseif($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
130 | - self::$configDir = rtrim($dir, '/') . '/'; |
|
131 | - } else { |
|
132 | - self::$configDir = OC::$SERVERROOT . '/config/'; |
|
133 | - } |
|
134 | - self::$config = new \OC\Config(self::$configDir); |
|
135 | - |
|
136 | - OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); |
|
137 | - /** |
|
138 | - * FIXME: The following lines are required because we can't yet instantiate |
|
139 | - * \OC::$server->getRequest() since \OC::$server does not yet exist. |
|
140 | - */ |
|
141 | - $params = [ |
|
142 | - 'server' => [ |
|
143 | - 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], |
|
144 | - 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'], |
|
145 | - ], |
|
146 | - ]; |
|
147 | - $fakeRequest = new \OC\AppFramework\Http\Request($params, null, new \OC\AllConfig(new \OC\SystemConfig(self::$config))); |
|
148 | - $scriptName = $fakeRequest->getScriptName(); |
|
149 | - if (substr($scriptName, -1) == '/') { |
|
150 | - $scriptName .= 'index.php'; |
|
151 | - //make sure suburi follows the same rules as scriptName |
|
152 | - if (substr(OC::$SUBURI, -9) != 'index.php') { |
|
153 | - if (substr(OC::$SUBURI, -1) != '/') { |
|
154 | - OC::$SUBURI = OC::$SUBURI . '/'; |
|
155 | - } |
|
156 | - OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
157 | - } |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - if (OC::$CLI) { |
|
162 | - OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
163 | - } else { |
|
164 | - if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { |
|
165 | - OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
|
166 | - |
|
167 | - if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
|
168 | - OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
169 | - } |
|
170 | - } else { |
|
171 | - // The scriptName is not ending with OC::$SUBURI |
|
172 | - // This most likely means that we are calling from CLI. |
|
173 | - // However some cron jobs still need to generate |
|
174 | - // a web URL, so we use overwritewebroot as a fallback. |
|
175 | - OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
176 | - } |
|
177 | - |
|
178 | - // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
|
179 | - // slash which is required by URL generation. |
|
180 | - if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
181 | - substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
|
182 | - header('Location: '.\OC::$WEBROOT.'/'); |
|
183 | - exit(); |
|
184 | - } |
|
185 | - } |
|
186 | - |
|
187 | - // search the apps folder |
|
188 | - $config_paths = self::$config->getValue('apps_paths', array()); |
|
189 | - if (!empty($config_paths)) { |
|
190 | - foreach ($config_paths as $paths) { |
|
191 | - if (isset($paths['url']) && isset($paths['path'])) { |
|
192 | - $paths['url'] = rtrim($paths['url'], '/'); |
|
193 | - $paths['path'] = rtrim($paths['path'], '/'); |
|
194 | - OC::$APPSROOTS[] = $paths; |
|
195 | - } |
|
196 | - } |
|
197 | - } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
198 | - OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); |
|
199 | - } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
200 | - OC::$APPSROOTS[] = array( |
|
201 | - 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
202 | - 'url' => '/apps', |
|
203 | - 'writable' => true |
|
204 | - ); |
|
205 | - } |
|
206 | - |
|
207 | - if (empty(OC::$APPSROOTS)) { |
|
208 | - throw new \RuntimeException('apps directory not found! Please put the Nextcloud apps folder in the Nextcloud folder' |
|
209 | - . ' or the folder above. You can also configure the location in the config.php file.'); |
|
210 | - } |
|
211 | - $paths = array(); |
|
212 | - foreach (OC::$APPSROOTS as $path) { |
|
213 | - $paths[] = $path['path']; |
|
214 | - if (!is_dir($path['path'])) { |
|
215 | - throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the Nextcloud apps folder in the' |
|
216 | - . ' Nextcloud folder or the folder above. You can also configure the location in the' |
|
217 | - . ' config.php file.', $path['path'])); |
|
218 | - } |
|
219 | - } |
|
220 | - |
|
221 | - // set the right include path |
|
222 | - set_include_path( |
|
223 | - implode(PATH_SEPARATOR, $paths) |
|
224 | - ); |
|
225 | - } |
|
226 | - |
|
227 | - public static function checkConfig() { |
|
228 | - $l = \OC::$server->getL10N('lib'); |
|
229 | - |
|
230 | - // Create config if it does not already exist |
|
231 | - $configFilePath = self::$configDir .'/config.php'; |
|
232 | - if(!file_exists($configFilePath)) { |
|
233 | - @touch($configFilePath); |
|
234 | - } |
|
235 | - |
|
236 | - // Check if config is writable |
|
237 | - $configFileWritable = is_writable($configFilePath); |
|
238 | - if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled() |
|
239 | - || !$configFileWritable && \OCP\Util::needUpgrade()) { |
|
240 | - |
|
241 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
242 | - |
|
243 | - if (self::$CLI) { |
|
244 | - echo $l->t('Cannot write into "config" directory!')."\n"; |
|
245 | - echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
|
246 | - echo "\n"; |
|
247 | - echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; |
|
248 | - exit; |
|
249 | - } else { |
|
250 | - OC_Template::printErrorPage( |
|
251 | - $l->t('Cannot write into "config" directory!'), |
|
252 | - $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
|
253 | - [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) |
|
254 | - ); |
|
255 | - } |
|
256 | - } |
|
257 | - } |
|
258 | - |
|
259 | - public static function checkInstalled() { |
|
260 | - if (defined('OC_CONSOLE')) { |
|
261 | - return; |
|
262 | - } |
|
263 | - // Redirect to installer if not installed |
|
264 | - if (!\OC::$server->getSystemConfig()->getValue('installed', false) && OC::$SUBURI !== '/index.php' && OC::$SUBURI !== '/status.php') { |
|
265 | - if (OC::$CLI) { |
|
266 | - throw new Exception('Not installed'); |
|
267 | - } else { |
|
268 | - $url = OC::$WEBROOT . '/index.php'; |
|
269 | - header('Location: ' . $url); |
|
270 | - } |
|
271 | - exit(); |
|
272 | - } |
|
273 | - } |
|
274 | - |
|
275 | - public static function checkMaintenanceMode() { |
|
276 | - // Allow ajax update script to execute without being stopped |
|
277 | - if (\OC::$server->getSystemConfig()->getValue('maintenance', false) && OC::$SUBURI != '/core/ajax/update.php') { |
|
278 | - // send http status 503 |
|
279 | - header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
280 | - header('Status: 503 Service Temporarily Unavailable'); |
|
281 | - header('Retry-After: 120'); |
|
282 | - |
|
283 | - // render error page |
|
284 | - $template = new OC_Template('', 'update.user', 'guest'); |
|
285 | - OC_Util::addScript('maintenance-check'); |
|
286 | - OC_Util::addStyle('core', 'guest'); |
|
287 | - $template->printPage(); |
|
288 | - die(); |
|
289 | - } |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * Prints the upgrade page |
|
294 | - * |
|
295 | - * @param \OC\SystemConfig $systemConfig |
|
296 | - */ |
|
297 | - private static function printUpgradePage(\OC\SystemConfig $systemConfig) { |
|
298 | - $disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false); |
|
299 | - $tooBig = false; |
|
300 | - if (!$disableWebUpdater) { |
|
301 | - $apps = \OC::$server->getAppManager(); |
|
302 | - if ($apps->isInstalled('user_ldap')) { |
|
303 | - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
304 | - |
|
305 | - $result = $qb->selectAlias($qb->createFunction('COUNT(*)'), 'user_count') |
|
306 | - ->from('ldap_user_mapping') |
|
307 | - ->execute(); |
|
308 | - $row = $result->fetch(); |
|
309 | - $result->closeCursor(); |
|
310 | - |
|
311 | - $tooBig = ($row['user_count'] > 50); |
|
312 | - } |
|
313 | - if (!$tooBig && $apps->isInstalled('user_saml')) { |
|
314 | - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
315 | - |
|
316 | - $result = $qb->selectAlias($qb->createFunction('COUNT(*)'), 'user_count') |
|
317 | - ->from('user_saml_users') |
|
318 | - ->execute(); |
|
319 | - $row = $result->fetch(); |
|
320 | - $result->closeCursor(); |
|
321 | - |
|
322 | - $tooBig = ($row['user_count'] > 50); |
|
323 | - } |
|
324 | - if (!$tooBig) { |
|
325 | - // count users |
|
326 | - $stats = \OC::$server->getUserManager()->countUsers(); |
|
327 | - $totalUsers = array_sum($stats); |
|
328 | - $tooBig = ($totalUsers > 50); |
|
329 | - } |
|
330 | - } |
|
331 | - $ignoreTooBigWarning = isset($_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup']) && |
|
332 | - $_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup'] === 'IAmSuperSureToDoThis'; |
|
333 | - |
|
334 | - if ($disableWebUpdater || ($tooBig && !$ignoreTooBigWarning)) { |
|
335 | - // send http status 503 |
|
336 | - header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
337 | - header('Status: 503 Service Temporarily Unavailable'); |
|
338 | - header('Retry-After: 120'); |
|
339 | - |
|
340 | - // render error page |
|
341 | - $template = new OC_Template('', 'update.use-cli', 'guest'); |
|
342 | - $template->assign('productName', 'nextcloud'); // for now |
|
343 | - $template->assign('version', OC_Util::getVersionString()); |
|
344 | - $template->assign('tooBig', $tooBig); |
|
345 | - |
|
346 | - $template->printPage(); |
|
347 | - die(); |
|
348 | - } |
|
349 | - |
|
350 | - // check whether this is a core update or apps update |
|
351 | - $installedVersion = $systemConfig->getValue('version', '0.0.0'); |
|
352 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
353 | - |
|
354 | - // if not a core upgrade, then it's apps upgrade |
|
355 | - $isAppsOnlyUpgrade = version_compare($currentVersion, $installedVersion, '='); |
|
356 | - |
|
357 | - $oldTheme = $systemConfig->getValue('theme'); |
|
358 | - $systemConfig->setValue('theme', ''); |
|
359 | - OC_Util::addScript('config'); // needed for web root |
|
360 | - OC_Util::addScript('update'); |
|
361 | - |
|
362 | - /** @var \OC\App\AppManager $appManager */ |
|
363 | - $appManager = \OC::$server->getAppManager(); |
|
364 | - |
|
365 | - $tmpl = new OC_Template('', 'update.admin', 'guest'); |
|
366 | - $tmpl->assign('version', OC_Util::getVersionString()); |
|
367 | - $tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade); |
|
368 | - |
|
369 | - // get third party apps |
|
370 | - $ocVersion = \OCP\Util::getVersion(); |
|
371 | - $incompatibleApps = $appManager->getIncompatibleApps($ocVersion); |
|
372 | - $incompatibleShippedApps = []; |
|
373 | - foreach ($incompatibleApps as $appInfo) { |
|
374 | - if ($appManager->isShipped($appInfo['id'])) { |
|
375 | - $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
376 | - } |
|
377 | - } |
|
378 | - |
|
379 | - if (!empty($incompatibleShippedApps)) { |
|
380 | - $l = \OC::$server->getL10N('core'); |
|
381 | - $hint = $l->t('The files of the app %$1s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
|
382 | - throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
383 | - } |
|
384 | - |
|
385 | - $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
|
386 | - $tmpl->assign('incompatibleAppsList', $incompatibleApps); |
|
387 | - $tmpl->assign('productName', 'Nextcloud'); // for now |
|
388 | - $tmpl->assign('oldTheme', $oldTheme); |
|
389 | - $tmpl->printPage(); |
|
390 | - } |
|
391 | - |
|
392 | - public static function initSession() { |
|
393 | - if(self::$server->getRequest()->getServerProtocol() === 'https') { |
|
394 | - ini_set('session.cookie_secure', true); |
|
395 | - } |
|
396 | - |
|
397 | - // prevents javascript from accessing php session cookies |
|
398 | - ini_set('session.cookie_httponly', 'true'); |
|
399 | - |
|
400 | - // set the cookie path to the Nextcloud directory |
|
401 | - $cookie_path = OC::$WEBROOT ? : '/'; |
|
402 | - ini_set('session.cookie_path', $cookie_path); |
|
403 | - |
|
404 | - // Let the session name be changed in the initSession Hook |
|
405 | - $sessionName = OC_Util::getInstanceId(); |
|
406 | - |
|
407 | - try { |
|
408 | - // Allow session apps to create a custom session object |
|
409 | - $useCustomSession = false; |
|
410 | - $session = self::$server->getSession(); |
|
411 | - OC_Hook::emit('OC', 'initSession', array('session' => &$session, 'sessionName' => &$sessionName, 'useCustomSession' => &$useCustomSession)); |
|
412 | - if (!$useCustomSession) { |
|
413 | - // set the session name to the instance id - which is unique |
|
414 | - $session = new \OC\Session\Internal($sessionName); |
|
415 | - } |
|
416 | - |
|
417 | - $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
418 | - $session = $cryptoWrapper->wrapSession($session); |
|
419 | - self::$server->setSession($session); |
|
420 | - |
|
421 | - // if session can't be started break with http 500 error |
|
422 | - } catch (Exception $e) { |
|
423 | - \OCP\Util::logException('base', $e); |
|
424 | - //show the user a detailed error page |
|
425 | - OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
426 | - OC_Template::printExceptionErrorPage($e); |
|
427 | - die(); |
|
428 | - } |
|
429 | - |
|
430 | - $sessionLifeTime = self::getSessionLifeTime(); |
|
431 | - |
|
432 | - // session timeout |
|
433 | - if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
|
434 | - if (isset($_COOKIE[session_name()])) { |
|
435 | - setcookie(session_name(), null, -1, self::$WEBROOT ? : '/'); |
|
436 | - } |
|
437 | - \OC::$server->getUserSession()->logout(); |
|
438 | - } |
|
439 | - |
|
440 | - $session->set('LAST_ACTIVITY', time()); |
|
441 | - } |
|
442 | - |
|
443 | - /** |
|
444 | - * @return string |
|
445 | - */ |
|
446 | - private static function getSessionLifeTime() { |
|
447 | - return \OC::$server->getConfig()->getSystemValue('session_lifetime', 60 * 60 * 24); |
|
448 | - } |
|
449 | - |
|
450 | - public static function loadAppClassPaths() { |
|
451 | - foreach (OC_App::getEnabledApps() as $app) { |
|
452 | - $appPath = OC_App::getAppPath($app); |
|
453 | - if ($appPath === false) { |
|
454 | - continue; |
|
455 | - } |
|
456 | - |
|
457 | - $file = $appPath . '/appinfo/classpath.php'; |
|
458 | - if (file_exists($file)) { |
|
459 | - require_once $file; |
|
460 | - } |
|
461 | - } |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
465 | - * Try to set some values to the required Nextcloud default |
|
466 | - */ |
|
467 | - public static function setRequiredIniValues() { |
|
468 | - @ini_set('default_charset', 'UTF-8'); |
|
469 | - @ini_set('gd.jpeg_ignore_warning', '1'); |
|
470 | - } |
|
471 | - |
|
472 | - /** |
|
473 | - * Send the same site cookies |
|
474 | - */ |
|
475 | - private static function sendSameSiteCookies() { |
|
476 | - $cookieParams = session_get_cookie_params(); |
|
477 | - $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
478 | - $policies = [ |
|
479 | - 'lax', |
|
480 | - 'strict', |
|
481 | - ]; |
|
482 | - |
|
483 | - // Append __Host to the cookie if it meets the requirements |
|
484 | - $cookiePrefix = ''; |
|
485 | - if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
486 | - $cookiePrefix = '__Host-'; |
|
487 | - } |
|
488 | - |
|
489 | - foreach($policies as $policy) { |
|
490 | - header( |
|
491 | - sprintf( |
|
492 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
493 | - $cookiePrefix, |
|
494 | - $policy, |
|
495 | - $cookieParams['path'], |
|
496 | - $policy |
|
497 | - ), |
|
498 | - false |
|
499 | - ); |
|
500 | - } |
|
501 | - } |
|
502 | - |
|
503 | - /** |
|
504 | - * Same Site cookie to further mitigate CSRF attacks. This cookie has to |
|
505 | - * be set in every request if cookies are sent to add a second level of |
|
506 | - * defense against CSRF. |
|
507 | - * |
|
508 | - * If the cookie is not sent this will set the cookie and reload the page. |
|
509 | - * We use an additional cookie since we want to protect logout CSRF and |
|
510 | - * also we can't directly interfere with PHP's session mechanism. |
|
511 | - */ |
|
512 | - private static function performSameSiteCookieProtection() { |
|
513 | - $request = \OC::$server->getRequest(); |
|
514 | - |
|
515 | - // Some user agents are notorious and don't really properly follow HTTP |
|
516 | - // specifications. For those, have an automated opt-out. Since the protection |
|
517 | - // for remote.php is applied in base.php as starting point we need to opt out |
|
518 | - // here. |
|
519 | - $incompatibleUserAgents = [ |
|
520 | - // OS X Finder |
|
521 | - '/^WebDAVFS/', |
|
522 | - ]; |
|
523 | - if($request->isUserAgent($incompatibleUserAgents)) { |
|
524 | - return; |
|
525 | - } |
|
526 | - |
|
527 | - if(count($_COOKIE) > 0) { |
|
528 | - $requestUri = $request->getScriptName(); |
|
529 | - $processingScript = explode('/', $requestUri); |
|
530 | - $processingScript = $processingScript[count($processingScript)-1]; |
|
531 | - |
|
532 | - // index.php routes are handled in the middleware |
|
533 | - if($processingScript === 'index.php') { |
|
534 | - return; |
|
535 | - } |
|
536 | - |
|
537 | - // All other endpoints require the lax and the strict cookie |
|
538 | - if(!$request->passesStrictCookieCheck()) { |
|
539 | - self::sendSameSiteCookies(); |
|
540 | - // Debug mode gets access to the resources without strict cookie |
|
541 | - // due to the fact that the SabreDAV browser also lives there. |
|
542 | - if(!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
543 | - http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
|
544 | - exit(); |
|
545 | - } |
|
546 | - } |
|
547 | - } elseif(!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
548 | - self::sendSameSiteCookies(); |
|
549 | - } |
|
550 | - } |
|
551 | - |
|
552 | - public static function init() { |
|
553 | - // calculate the root directories |
|
554 | - OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); |
|
555 | - |
|
556 | - // register autoloader |
|
557 | - $loaderStart = microtime(true); |
|
558 | - require_once __DIR__ . '/autoloader.php'; |
|
559 | - self::$loader = new \OC\Autoloader([ |
|
560 | - OC::$SERVERROOT . '/lib/private/legacy', |
|
561 | - ]); |
|
562 | - if (defined('PHPUNIT_RUN')) { |
|
563 | - self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
564 | - } |
|
565 | - spl_autoload_register(array(self::$loader, 'load')); |
|
566 | - $loaderEnd = microtime(true); |
|
567 | - |
|
568 | - self::$CLI = (php_sapi_name() == 'cli'); |
|
569 | - |
|
570 | - // Add default composer PSR-4 autoloader |
|
571 | - self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
572 | - |
|
573 | - try { |
|
574 | - self::initPaths(); |
|
575 | - // setup 3rdparty autoloader |
|
576 | - $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
577 | - if (!file_exists($vendorAutoLoad)) { |
|
578 | - 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".'); |
|
579 | - } |
|
580 | - require_once $vendorAutoLoad; |
|
581 | - |
|
582 | - } catch (\RuntimeException $e) { |
|
583 | - if (!self::$CLI) { |
|
584 | - $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
|
585 | - $protocol = in_array($claimedProtocol, ['HTTP/1.0', 'HTTP/1.1', 'HTTP/2']) ? $claimedProtocol : 'HTTP/1.1'; |
|
586 | - header($protocol . ' ' . OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
587 | - } |
|
588 | - // we can't use the template error page here, because this needs the |
|
589 | - // DI container which isn't available yet |
|
590 | - print($e->getMessage()); |
|
591 | - exit(); |
|
592 | - } |
|
593 | - |
|
594 | - // setup the basic server |
|
595 | - self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); |
|
596 | - \OC::$server->getEventLogger()->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); |
|
597 | - \OC::$server->getEventLogger()->start('boot', 'Initialize'); |
|
598 | - |
|
599 | - // Don't display errors and log them |
|
600 | - error_reporting(E_ALL | E_STRICT); |
|
601 | - @ini_set('display_errors', '0'); |
|
602 | - @ini_set('log_errors', '1'); |
|
603 | - |
|
604 | - if(!date_default_timezone_set('UTC')) { |
|
605 | - throw new \RuntimeException('Could not set timezone to UTC'); |
|
606 | - } |
|
607 | - |
|
608 | - //try to configure php to enable big file uploads. |
|
609 | - //this doesn´t work always depending on the webserver and php configuration. |
|
610 | - //Let´s try to overwrite some defaults anyway |
|
611 | - |
|
612 | - //try to set the maximum execution time to 60min |
|
613 | - if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
614 | - @set_time_limit(3600); |
|
615 | - } |
|
616 | - @ini_set('max_execution_time', '3600'); |
|
617 | - @ini_set('max_input_time', '3600'); |
|
618 | - |
|
619 | - //try to set the maximum filesize to 10G |
|
620 | - @ini_set('upload_max_filesize', '10G'); |
|
621 | - @ini_set('post_max_size', '10G'); |
|
622 | - @ini_set('file_uploads', '50'); |
|
623 | - |
|
624 | - self::setRequiredIniValues(); |
|
625 | - self::handleAuthHeaders(); |
|
626 | - self::registerAutoloaderCache(); |
|
627 | - |
|
628 | - // initialize intl fallback is necessary |
|
629 | - \Patchwork\Utf8\Bootup::initIntl(); |
|
630 | - OC_Util::isSetLocaleWorking(); |
|
631 | - |
|
632 | - if (!defined('PHPUNIT_RUN')) { |
|
633 | - OC\Log\ErrorHandler::setLogger(\OC::$server->getLogger()); |
|
634 | - $debug = \OC::$server->getConfig()->getSystemValue('debug', false); |
|
635 | - OC\Log\ErrorHandler::register($debug); |
|
636 | - } |
|
637 | - |
|
638 | - \OC::$server->getEventLogger()->start('init_session', 'Initialize session'); |
|
639 | - OC_App::loadApps(array('session')); |
|
640 | - if (!self::$CLI) { |
|
641 | - self::initSession(); |
|
642 | - } |
|
643 | - \OC::$server->getEventLogger()->end('init_session'); |
|
644 | - self::checkConfig(); |
|
645 | - self::checkInstalled(); |
|
646 | - |
|
647 | - OC_Response::addSecurityHeaders(); |
|
648 | - |
|
649 | - self::performSameSiteCookieProtection(); |
|
650 | - |
|
651 | - if (!defined('OC_CONSOLE')) { |
|
652 | - $errors = OC_Util::checkServer(\OC::$server->getSystemConfig()); |
|
653 | - if (count($errors) > 0) { |
|
654 | - if (self::$CLI) { |
|
655 | - // Convert l10n string into regular string for usage in database |
|
656 | - $staticErrors = []; |
|
657 | - foreach ($errors as $error) { |
|
658 | - echo $error['error'] . "\n"; |
|
659 | - echo $error['hint'] . "\n\n"; |
|
660 | - $staticErrors[] = [ |
|
661 | - 'error' => (string)$error['error'], |
|
662 | - 'hint' => (string)$error['hint'], |
|
663 | - ]; |
|
664 | - } |
|
665 | - |
|
666 | - try { |
|
667 | - \OC::$server->getConfig()->setAppValue('core', 'cronErrors', json_encode($staticErrors)); |
|
668 | - } catch (\Exception $e) { |
|
669 | - echo('Writing to database failed'); |
|
670 | - } |
|
671 | - exit(1); |
|
672 | - } else { |
|
673 | - OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
674 | - OC_Util::addStyle('guest'); |
|
675 | - OC_Template::printGuestPage('', 'error', array('errors' => $errors)); |
|
676 | - exit; |
|
677 | - } |
|
678 | - } elseif (self::$CLI && \OC::$server->getConfig()->getSystemValue('installed', false)) { |
|
679 | - \OC::$server->getConfig()->deleteAppValue('core', 'cronErrors'); |
|
680 | - } |
|
681 | - } |
|
682 | - //try to set the session lifetime |
|
683 | - $sessionLifeTime = self::getSessionLifeTime(); |
|
684 | - @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
685 | - |
|
686 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
687 | - |
|
688 | - // User and Groups |
|
689 | - if (!$systemConfig->getValue("installed", false)) { |
|
690 | - self::$server->getSession()->set('user_id', ''); |
|
691 | - } |
|
692 | - |
|
693 | - OC_User::useBackend(new \OC\User\Database()); |
|
694 | - \OC::$server->getGroupManager()->addBackend(new \OC\Group\Database()); |
|
695 | - |
|
696 | - // Subscribe to the hook |
|
697 | - \OCP\Util::connectHook( |
|
698 | - '\OCA\Files_Sharing\API\Server2Server', |
|
699 | - 'preLoginNameUsedAsUserName', |
|
700 | - '\OC\User\Database', |
|
701 | - 'preLoginNameUsedAsUserName' |
|
702 | - ); |
|
703 | - |
|
704 | - //setup extra user backends |
|
705 | - if (!\OCP\Util::needUpgrade()) { |
|
706 | - OC_User::setupBackends(); |
|
707 | - } else { |
|
708 | - // Run upgrades in incognito mode |
|
709 | - OC_User::setIncognitoMode(true); |
|
710 | - } |
|
711 | - |
|
712 | - self::registerCleanupHooks(); |
|
713 | - self::registerFilesystemHooks(); |
|
714 | - self::registerShareHooks(); |
|
715 | - self::registerEncryptionWrapper(); |
|
716 | - self::registerEncryptionHooks(); |
|
717 | - self::registerAccountHooks(); |
|
718 | - |
|
719 | - $settings = new \OC\Settings\Application(); |
|
720 | - $settings->register(); |
|
721 | - |
|
722 | - //make sure temporary files are cleaned up |
|
723 | - $tmpManager = \OC::$server->getTempManager(); |
|
724 | - register_shutdown_function(array($tmpManager, 'clean')); |
|
725 | - $lockProvider = \OC::$server->getLockingProvider(); |
|
726 | - register_shutdown_function(array($lockProvider, 'releaseAll')); |
|
727 | - |
|
728 | - // Check whether the sample configuration has been copied |
|
729 | - if($systemConfig->getValue('copied_sample_config', false)) { |
|
730 | - $l = \OC::$server->getL10N('lib'); |
|
731 | - header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
732 | - header('Status: 503 Service Temporarily Unavailable'); |
|
733 | - OC_Template::printErrorPage( |
|
734 | - $l->t('Sample configuration detected'), |
|
735 | - $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') |
|
736 | - ); |
|
737 | - return; |
|
738 | - } |
|
739 | - |
|
740 | - $request = \OC::$server->getRequest(); |
|
741 | - $host = $request->getInsecureServerHost(); |
|
742 | - /** |
|
743 | - * if the host passed in headers isn't trusted |
|
744 | - * FIXME: Should not be in here at all :see_no_evil: |
|
745 | - */ |
|
746 | - if (!OC::$CLI |
|
747 | - // overwritehost is always trusted, workaround to not have to make |
|
748 | - // \OC\AppFramework\Http\Request::getOverwriteHost public |
|
749 | - && self::$server->getConfig()->getSystemValue('overwritehost') === '' |
|
750 | - && !\OC::$server->getTrustedDomainHelper()->isTrustedDomain($host) |
|
751 | - && self::$server->getConfig()->getSystemValue('installed', false) |
|
752 | - ) { |
|
753 | - // Allow access to CSS resources |
|
754 | - $isScssRequest = false; |
|
755 | - if(strpos($request->getPathInfo(), '/css/') === 0) { |
|
756 | - $isScssRequest = true; |
|
757 | - } |
|
758 | - |
|
759 | - if(substr($request->getRequestUri(), -11) === '/status.php') { |
|
760 | - OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST); |
|
761 | - header('Status: 400 Bad Request'); |
|
762 | - header('Content-Type: application/json'); |
|
763 | - echo '{"error": "Trusted domain error.", "code": 15}'; |
|
764 | - exit(); |
|
765 | - } |
|
766 | - |
|
767 | - if (!$isScssRequest) { |
|
768 | - OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST); |
|
769 | - header('Status: 400 Bad Request'); |
|
770 | - |
|
771 | - \OC::$server->getLogger()->warning( |
|
772 | - 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', |
|
773 | - [ |
|
774 | - 'app' => 'core', |
|
775 | - 'remoteAddress' => $request->getRemoteAddress(), |
|
776 | - 'host' => $host, |
|
777 | - ] |
|
778 | - ); |
|
779 | - |
|
780 | - $tmpl = new OCP\Template('core', 'untrustedDomain', 'guest'); |
|
781 | - $tmpl->assign('domain', $host); |
|
782 | - $tmpl->printPage(); |
|
783 | - |
|
784 | - exit(); |
|
785 | - } |
|
786 | - } |
|
787 | - \OC::$server->getEventLogger()->end('boot'); |
|
788 | - } |
|
789 | - |
|
790 | - /** |
|
791 | - * register hooks for the cleanup of cache and bruteforce protection |
|
792 | - */ |
|
793 | - public static function registerCleanupHooks() { |
|
794 | - //don't try to do this before we are properly setup |
|
795 | - if (\OC::$server->getSystemConfig()->getValue('installed', false) && !\OCP\Util::needUpgrade()) { |
|
796 | - |
|
797 | - // NOTE: This will be replaced to use OCP |
|
798 | - $userSession = self::$server->getUserSession(); |
|
799 | - $userSession->listen('\OC\User', 'postLogin', function () use ($userSession) { |
|
800 | - if (!defined('PHPUNIT_RUN')) { |
|
801 | - // reset brute force delay for this IP address and username |
|
802 | - $uid = \OC::$server->getUserSession()->getUser()->getUID(); |
|
803 | - $request = \OC::$server->getRequest(); |
|
804 | - $throttler = \OC::$server->getBruteForceThrottler(); |
|
805 | - $throttler->resetDelay($request->getRemoteAddress(), 'login', ['user' => $uid]); |
|
806 | - } |
|
807 | - |
|
808 | - try { |
|
809 | - $cache = new \OC\Cache\File(); |
|
810 | - $cache->gc(); |
|
811 | - } catch (\OC\ServerNotAvailableException $e) { |
|
812 | - // not a GC exception, pass it on |
|
813 | - throw $e; |
|
814 | - } catch (\OC\ForbiddenException $e) { |
|
815 | - // filesystem blocked for this request, ignore |
|
816 | - } catch (\Exception $e) { |
|
817 | - // a GC exception should not prevent users from using OC, |
|
818 | - // so log the exception |
|
819 | - \OC::$server->getLogger()->logException($e, [ |
|
820 | - 'message' => 'Exception when running cache gc.', |
|
821 | - 'level' => \OCP\Util::WARN, |
|
822 | - 'app' => 'core', |
|
823 | - ]); |
|
824 | - } |
|
825 | - }); |
|
826 | - } |
|
827 | - } |
|
828 | - |
|
829 | - private static function registerEncryptionWrapper() { |
|
830 | - $manager = self::$server->getEncryptionManager(); |
|
831 | - \OCP\Util::connectHook('OC_Filesystem', 'preSetup', $manager, 'setupStorage'); |
|
832 | - } |
|
833 | - |
|
834 | - private static function registerEncryptionHooks() { |
|
835 | - $enabled = self::$server->getEncryptionManager()->isEnabled(); |
|
836 | - if ($enabled) { |
|
837 | - \OCP\Util::connectHook('OCP\Share', 'post_shared', 'OC\Encryption\HookManager', 'postShared'); |
|
838 | - \OCP\Util::connectHook('OCP\Share', 'post_unshare', 'OC\Encryption\HookManager', 'postUnshared'); |
|
839 | - \OCP\Util::connectHook('OC_Filesystem', 'post_rename', 'OC\Encryption\HookManager', 'postRename'); |
|
840 | - \OCP\Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', 'OC\Encryption\HookManager', 'postRestore'); |
|
841 | - } |
|
842 | - } |
|
843 | - |
|
844 | - private static function registerAccountHooks() { |
|
845 | - $hookHandler = new \OC\Accounts\Hooks(\OC::$server->getLogger()); |
|
846 | - \OCP\Util::connectHook('OC_User', 'changeUser', $hookHandler, 'changeUserHook'); |
|
847 | - } |
|
848 | - |
|
849 | - /** |
|
850 | - * register hooks for the filesystem |
|
851 | - */ |
|
852 | - public static function registerFilesystemHooks() { |
|
853 | - // Check for blacklisted files |
|
854 | - OC_Hook::connect('OC_Filesystem', 'write', 'OC\Files\Filesystem', 'isBlacklisted'); |
|
855 | - OC_Hook::connect('OC_Filesystem', 'rename', 'OC\Files\Filesystem', 'isBlacklisted'); |
|
856 | - } |
|
857 | - |
|
858 | - /** |
|
859 | - * register hooks for sharing |
|
860 | - */ |
|
861 | - public static function registerShareHooks() { |
|
862 | - if (\OC::$server->getSystemConfig()->getValue('installed')) { |
|
863 | - OC_Hook::connect('OC_User', 'post_deleteUser', 'OC\Share20\Hooks', 'post_deleteUser'); |
|
864 | - OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OC\Share20\Hooks', 'post_removeFromGroup'); |
|
865 | - OC_Hook::connect('OC_User', 'post_deleteGroup', 'OC\Share20\Hooks', 'post_deleteGroup'); |
|
866 | - } |
|
867 | - } |
|
868 | - |
|
869 | - protected static function registerAutoloaderCache() { |
|
870 | - // The class loader takes an optional low-latency cache, which MUST be |
|
871 | - // namespaced. The instanceid is used for namespacing, but might be |
|
872 | - // unavailable at this point. Furthermore, it might not be possible to |
|
873 | - // generate an instanceid via \OC_Util::getInstanceId() because the |
|
874 | - // config file may not be writable. As such, we only register a class |
|
875 | - // loader cache if instanceid is available without trying to create one. |
|
876 | - $instanceId = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
877 | - if ($instanceId) { |
|
878 | - try { |
|
879 | - $memcacheFactory = \OC::$server->getMemCacheFactory(); |
|
880 | - self::$loader->setMemoryCache($memcacheFactory->createLocal('Autoloader')); |
|
881 | - } catch (\Exception $ex) { |
|
882 | - } |
|
883 | - } |
|
884 | - } |
|
885 | - |
|
886 | - /** |
|
887 | - * Handle the request |
|
888 | - */ |
|
889 | - public static function handleRequest() { |
|
890 | - |
|
891 | - \OC::$server->getEventLogger()->start('handle_request', 'Handle request'); |
|
892 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
893 | - // load all the classpaths from the enabled apps so they are available |
|
894 | - // in the routing files of each app |
|
895 | - OC::loadAppClassPaths(); |
|
896 | - |
|
897 | - // Check if Nextcloud is installed or in maintenance (update) mode |
|
898 | - if (!$systemConfig->getValue('installed', false)) { |
|
899 | - \OC::$server->getSession()->clear(); |
|
900 | - $setupHelper = new OC\Setup( |
|
901 | - $systemConfig, |
|
902 | - \OC::$server->getIniWrapper(), |
|
903 | - \OC::$server->getL10N('lib'), |
|
904 | - \OC::$server->query(\OCP\Defaults::class), |
|
905 | - \OC::$server->getLogger(), |
|
906 | - \OC::$server->getSecureRandom(), |
|
907 | - \OC::$server->query(\OC\Installer::class) |
|
908 | - ); |
|
909 | - $controller = new OC\Core\Controller\SetupController($setupHelper); |
|
910 | - $controller->run($_POST); |
|
911 | - exit(); |
|
912 | - } |
|
913 | - |
|
914 | - $request = \OC::$server->getRequest(); |
|
915 | - $requestPath = $request->getRawPathInfo(); |
|
916 | - if ($requestPath === '/heartbeat') { |
|
917 | - return; |
|
918 | - } |
|
919 | - if (substr($requestPath, -3) !== '.js') { // we need these files during the upgrade |
|
920 | - self::checkMaintenanceMode(); |
|
921 | - |
|
922 | - if (\OCP\Util::needUpgrade()) { |
|
923 | - if (function_exists('opcache_reset')) { |
|
924 | - opcache_reset(); |
|
925 | - } |
|
926 | - if (!$systemConfig->getValue('maintenance', false)) { |
|
927 | - self::printUpgradePage($systemConfig); |
|
928 | - exit(); |
|
929 | - } |
|
930 | - } |
|
931 | - } |
|
932 | - |
|
933 | - // emergency app disabling |
|
934 | - if ($requestPath === '/disableapp' |
|
935 | - && $request->getMethod() === 'POST' |
|
936 | - && ((array)$request->getParam('appid')) !== '' |
|
937 | - ) { |
|
938 | - \OCP\JSON::callCheck(); |
|
939 | - \OCP\JSON::checkAdminUser(); |
|
940 | - $appIds = (array)$request->getParam('appid'); |
|
941 | - foreach($appIds as $appId) { |
|
942 | - $appId = \OC_App::cleanAppId($appId); |
|
943 | - \OC_App::disable($appId); |
|
944 | - } |
|
945 | - \OC_JSON::success(); |
|
946 | - exit(); |
|
947 | - } |
|
948 | - |
|
949 | - // Always load authentication apps |
|
950 | - OC_App::loadApps(['authentication']); |
|
951 | - |
|
952 | - // Load minimum set of apps |
|
953 | - if (!\OCP\Util::needUpgrade() |
|
954 | - && !$systemConfig->getValue('maintenance', false)) { |
|
955 | - // For logged-in users: Load everything |
|
956 | - if(\OC::$server->getUserSession()->isLoggedIn()) { |
|
957 | - OC_App::loadApps(); |
|
958 | - } else { |
|
959 | - // For guests: Load only filesystem and logging |
|
960 | - OC_App::loadApps(array('filesystem', 'logging')); |
|
961 | - self::handleLogin($request); |
|
962 | - } |
|
963 | - } |
|
964 | - |
|
965 | - if (!self::$CLI) { |
|
966 | - try { |
|
967 | - if (!$systemConfig->getValue('maintenance', false) && !\OCP\Util::needUpgrade()) { |
|
968 | - OC_App::loadApps(array('filesystem', 'logging')); |
|
969 | - OC_App::loadApps(); |
|
970 | - } |
|
971 | - OC_Util::setupFS(); |
|
972 | - OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo()); |
|
973 | - return; |
|
974 | - } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { |
|
975 | - //header('HTTP/1.0 404 Not Found'); |
|
976 | - } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { |
|
977 | - OC_Response::setStatus(405); |
|
978 | - return; |
|
979 | - } |
|
980 | - } |
|
981 | - |
|
982 | - // Handle WebDAV |
|
983 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
984 | - // not allowed any more to prevent people |
|
985 | - // mounting this root directly. |
|
986 | - // Users need to mount remote.php/webdav instead. |
|
987 | - header('HTTP/1.1 405 Method Not Allowed'); |
|
988 | - header('Status: 405 Method Not Allowed'); |
|
989 | - return; |
|
990 | - } |
|
991 | - |
|
992 | - // Someone is logged in |
|
993 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
994 | - OC_App::loadApps(); |
|
995 | - OC_User::setupBackends(); |
|
996 | - OC_Util::setupFS(); |
|
997 | - // FIXME |
|
998 | - // Redirect to default application |
|
999 | - OC_Util::redirectToDefaultPage(); |
|
1000 | - } else { |
|
1001 | - // Not handled and not logged in |
|
1002 | - header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm')); |
|
1003 | - } |
|
1004 | - } |
|
1005 | - |
|
1006 | - /** |
|
1007 | - * Check login: apache auth, auth token, basic auth |
|
1008 | - * |
|
1009 | - * @param OCP\IRequest $request |
|
1010 | - * @return boolean |
|
1011 | - */ |
|
1012 | - static function handleLogin(OCP\IRequest $request) { |
|
1013 | - $userSession = self::$server->getUserSession(); |
|
1014 | - if (OC_User::handleApacheAuth()) { |
|
1015 | - return true; |
|
1016 | - } |
|
1017 | - if ($userSession->tryTokenLogin($request)) { |
|
1018 | - return true; |
|
1019 | - } |
|
1020 | - if (isset($_COOKIE['nc_username']) |
|
1021 | - && isset($_COOKIE['nc_token']) |
|
1022 | - && isset($_COOKIE['nc_session_id']) |
|
1023 | - && $userSession->loginWithCookie($_COOKIE['nc_username'], $_COOKIE['nc_token'], $_COOKIE['nc_session_id'])) { |
|
1024 | - return true; |
|
1025 | - } |
|
1026 | - if ($userSession->tryBasicAuthLogin($request, \OC::$server->getBruteForceThrottler())) { |
|
1027 | - return true; |
|
1028 | - } |
|
1029 | - return false; |
|
1030 | - } |
|
1031 | - |
|
1032 | - protected static function handleAuthHeaders() { |
|
1033 | - //copy http auth headers for apache+php-fcgid work around |
|
1034 | - if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { |
|
1035 | - $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; |
|
1036 | - } |
|
1037 | - |
|
1038 | - // Extract PHP_AUTH_USER/PHP_AUTH_PW from other headers if necessary. |
|
1039 | - $vars = array( |
|
1040 | - 'HTTP_AUTHORIZATION', // apache+php-cgi work around |
|
1041 | - 'REDIRECT_HTTP_AUTHORIZATION', // apache+php-cgi alternative |
|
1042 | - ); |
|
1043 | - foreach ($vars as $var) { |
|
1044 | - if (isset($_SERVER[$var]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$var], $matches)) { |
|
1045 | - list($name, $password) = explode(':', base64_decode($matches[1]), 2); |
|
1046 | - $_SERVER['PHP_AUTH_USER'] = $name; |
|
1047 | - $_SERVER['PHP_AUTH_PW'] = $password; |
|
1048 | - break; |
|
1049 | - } |
|
1050 | - } |
|
1051 | - } |
|
65 | + /** |
|
66 | + * Associative array for autoloading. classname => filename |
|
67 | + */ |
|
68 | + public static $CLASSPATH = array(); |
|
69 | + /** |
|
70 | + * The installation path for Nextcloud on the server (e.g. /srv/http/nextcloud) |
|
71 | + */ |
|
72 | + public static $SERVERROOT = ''; |
|
73 | + /** |
|
74 | + * the current request path relative to the Nextcloud root (e.g. files/index.php) |
|
75 | + */ |
|
76 | + private static $SUBURI = ''; |
|
77 | + /** |
|
78 | + * the Nextcloud root path for http requests (e.g. nextcloud/) |
|
79 | + */ |
|
80 | + public static $WEBROOT = ''; |
|
81 | + /** |
|
82 | + * The installation path array of the apps folder on the server (e.g. /srv/http/nextcloud) 'path' and |
|
83 | + * web path in 'url' |
|
84 | + */ |
|
85 | + public static $APPSROOTS = array(); |
|
86 | + |
|
87 | + /** |
|
88 | + * @var string |
|
89 | + */ |
|
90 | + public static $configDir; |
|
91 | + |
|
92 | + /** |
|
93 | + * requested app |
|
94 | + */ |
|
95 | + public static $REQUESTEDAPP = ''; |
|
96 | + |
|
97 | + /** |
|
98 | + * check if Nextcloud runs in cli mode |
|
99 | + */ |
|
100 | + public static $CLI = false; |
|
101 | + |
|
102 | + /** |
|
103 | + * @var \OC\Autoloader $loader |
|
104 | + */ |
|
105 | + public static $loader = null; |
|
106 | + |
|
107 | + /** @var \Composer\Autoload\ClassLoader $composerAutoloader */ |
|
108 | + public static $composerAutoloader = null; |
|
109 | + |
|
110 | + /** |
|
111 | + * @var \OC\Server |
|
112 | + */ |
|
113 | + public static $server = null; |
|
114 | + |
|
115 | + /** |
|
116 | + * @var \OC\Config |
|
117 | + */ |
|
118 | + private static $config = null; |
|
119 | + |
|
120 | + /** |
|
121 | + * @throws \RuntimeException when the 3rdparty directory is missing or |
|
122 | + * the app path list is empty or contains an invalid path |
|
123 | + */ |
|
124 | + public static function initPaths() { |
|
125 | + if(defined('PHPUNIT_CONFIG_DIR')) { |
|
126 | + self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
127 | + } elseif(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
128 | + self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
129 | + } elseif($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
130 | + self::$configDir = rtrim($dir, '/') . '/'; |
|
131 | + } else { |
|
132 | + self::$configDir = OC::$SERVERROOT . '/config/'; |
|
133 | + } |
|
134 | + self::$config = new \OC\Config(self::$configDir); |
|
135 | + |
|
136 | + OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); |
|
137 | + /** |
|
138 | + * FIXME: The following lines are required because we can't yet instantiate |
|
139 | + * \OC::$server->getRequest() since \OC::$server does not yet exist. |
|
140 | + */ |
|
141 | + $params = [ |
|
142 | + 'server' => [ |
|
143 | + 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], |
|
144 | + 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'], |
|
145 | + ], |
|
146 | + ]; |
|
147 | + $fakeRequest = new \OC\AppFramework\Http\Request($params, null, new \OC\AllConfig(new \OC\SystemConfig(self::$config))); |
|
148 | + $scriptName = $fakeRequest->getScriptName(); |
|
149 | + if (substr($scriptName, -1) == '/') { |
|
150 | + $scriptName .= 'index.php'; |
|
151 | + //make sure suburi follows the same rules as scriptName |
|
152 | + if (substr(OC::$SUBURI, -9) != 'index.php') { |
|
153 | + if (substr(OC::$SUBURI, -1) != '/') { |
|
154 | + OC::$SUBURI = OC::$SUBURI . '/'; |
|
155 | + } |
|
156 | + OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
157 | + } |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + if (OC::$CLI) { |
|
162 | + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
163 | + } else { |
|
164 | + if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { |
|
165 | + OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
|
166 | + |
|
167 | + if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
|
168 | + OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
169 | + } |
|
170 | + } else { |
|
171 | + // The scriptName is not ending with OC::$SUBURI |
|
172 | + // This most likely means that we are calling from CLI. |
|
173 | + // However some cron jobs still need to generate |
|
174 | + // a web URL, so we use overwritewebroot as a fallback. |
|
175 | + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
176 | + } |
|
177 | + |
|
178 | + // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
|
179 | + // slash which is required by URL generation. |
|
180 | + if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
181 | + substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
|
182 | + header('Location: '.\OC::$WEBROOT.'/'); |
|
183 | + exit(); |
|
184 | + } |
|
185 | + } |
|
186 | + |
|
187 | + // search the apps folder |
|
188 | + $config_paths = self::$config->getValue('apps_paths', array()); |
|
189 | + if (!empty($config_paths)) { |
|
190 | + foreach ($config_paths as $paths) { |
|
191 | + if (isset($paths['url']) && isset($paths['path'])) { |
|
192 | + $paths['url'] = rtrim($paths['url'], '/'); |
|
193 | + $paths['path'] = rtrim($paths['path'], '/'); |
|
194 | + OC::$APPSROOTS[] = $paths; |
|
195 | + } |
|
196 | + } |
|
197 | + } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
198 | + OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); |
|
199 | + } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
200 | + OC::$APPSROOTS[] = array( |
|
201 | + 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
202 | + 'url' => '/apps', |
|
203 | + 'writable' => true |
|
204 | + ); |
|
205 | + } |
|
206 | + |
|
207 | + if (empty(OC::$APPSROOTS)) { |
|
208 | + throw new \RuntimeException('apps directory not found! Please put the Nextcloud apps folder in the Nextcloud folder' |
|
209 | + . ' or the folder above. You can also configure the location in the config.php file.'); |
|
210 | + } |
|
211 | + $paths = array(); |
|
212 | + foreach (OC::$APPSROOTS as $path) { |
|
213 | + $paths[] = $path['path']; |
|
214 | + if (!is_dir($path['path'])) { |
|
215 | + throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the Nextcloud apps folder in the' |
|
216 | + . ' Nextcloud folder or the folder above. You can also configure the location in the' |
|
217 | + . ' config.php file.', $path['path'])); |
|
218 | + } |
|
219 | + } |
|
220 | + |
|
221 | + // set the right include path |
|
222 | + set_include_path( |
|
223 | + implode(PATH_SEPARATOR, $paths) |
|
224 | + ); |
|
225 | + } |
|
226 | + |
|
227 | + public static function checkConfig() { |
|
228 | + $l = \OC::$server->getL10N('lib'); |
|
229 | + |
|
230 | + // Create config if it does not already exist |
|
231 | + $configFilePath = self::$configDir .'/config.php'; |
|
232 | + if(!file_exists($configFilePath)) { |
|
233 | + @touch($configFilePath); |
|
234 | + } |
|
235 | + |
|
236 | + // Check if config is writable |
|
237 | + $configFileWritable = is_writable($configFilePath); |
|
238 | + if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled() |
|
239 | + || !$configFileWritable && \OCP\Util::needUpgrade()) { |
|
240 | + |
|
241 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
242 | + |
|
243 | + if (self::$CLI) { |
|
244 | + echo $l->t('Cannot write into "config" directory!')."\n"; |
|
245 | + echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
|
246 | + echo "\n"; |
|
247 | + echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; |
|
248 | + exit; |
|
249 | + } else { |
|
250 | + OC_Template::printErrorPage( |
|
251 | + $l->t('Cannot write into "config" directory!'), |
|
252 | + $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
|
253 | + [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) |
|
254 | + ); |
|
255 | + } |
|
256 | + } |
|
257 | + } |
|
258 | + |
|
259 | + public static function checkInstalled() { |
|
260 | + if (defined('OC_CONSOLE')) { |
|
261 | + return; |
|
262 | + } |
|
263 | + // Redirect to installer if not installed |
|
264 | + if (!\OC::$server->getSystemConfig()->getValue('installed', false) && OC::$SUBURI !== '/index.php' && OC::$SUBURI !== '/status.php') { |
|
265 | + if (OC::$CLI) { |
|
266 | + throw new Exception('Not installed'); |
|
267 | + } else { |
|
268 | + $url = OC::$WEBROOT . '/index.php'; |
|
269 | + header('Location: ' . $url); |
|
270 | + } |
|
271 | + exit(); |
|
272 | + } |
|
273 | + } |
|
274 | + |
|
275 | + public static function checkMaintenanceMode() { |
|
276 | + // Allow ajax update script to execute without being stopped |
|
277 | + if (\OC::$server->getSystemConfig()->getValue('maintenance', false) && OC::$SUBURI != '/core/ajax/update.php') { |
|
278 | + // send http status 503 |
|
279 | + header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
280 | + header('Status: 503 Service Temporarily Unavailable'); |
|
281 | + header('Retry-After: 120'); |
|
282 | + |
|
283 | + // render error page |
|
284 | + $template = new OC_Template('', 'update.user', 'guest'); |
|
285 | + OC_Util::addScript('maintenance-check'); |
|
286 | + OC_Util::addStyle('core', 'guest'); |
|
287 | + $template->printPage(); |
|
288 | + die(); |
|
289 | + } |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * Prints the upgrade page |
|
294 | + * |
|
295 | + * @param \OC\SystemConfig $systemConfig |
|
296 | + */ |
|
297 | + private static function printUpgradePage(\OC\SystemConfig $systemConfig) { |
|
298 | + $disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false); |
|
299 | + $tooBig = false; |
|
300 | + if (!$disableWebUpdater) { |
|
301 | + $apps = \OC::$server->getAppManager(); |
|
302 | + if ($apps->isInstalled('user_ldap')) { |
|
303 | + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
304 | + |
|
305 | + $result = $qb->selectAlias($qb->createFunction('COUNT(*)'), 'user_count') |
|
306 | + ->from('ldap_user_mapping') |
|
307 | + ->execute(); |
|
308 | + $row = $result->fetch(); |
|
309 | + $result->closeCursor(); |
|
310 | + |
|
311 | + $tooBig = ($row['user_count'] > 50); |
|
312 | + } |
|
313 | + if (!$tooBig && $apps->isInstalled('user_saml')) { |
|
314 | + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
315 | + |
|
316 | + $result = $qb->selectAlias($qb->createFunction('COUNT(*)'), 'user_count') |
|
317 | + ->from('user_saml_users') |
|
318 | + ->execute(); |
|
319 | + $row = $result->fetch(); |
|
320 | + $result->closeCursor(); |
|
321 | + |
|
322 | + $tooBig = ($row['user_count'] > 50); |
|
323 | + } |
|
324 | + if (!$tooBig) { |
|
325 | + // count users |
|
326 | + $stats = \OC::$server->getUserManager()->countUsers(); |
|
327 | + $totalUsers = array_sum($stats); |
|
328 | + $tooBig = ($totalUsers > 50); |
|
329 | + } |
|
330 | + } |
|
331 | + $ignoreTooBigWarning = isset($_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup']) && |
|
332 | + $_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup'] === 'IAmSuperSureToDoThis'; |
|
333 | + |
|
334 | + if ($disableWebUpdater || ($tooBig && !$ignoreTooBigWarning)) { |
|
335 | + // send http status 503 |
|
336 | + header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
337 | + header('Status: 503 Service Temporarily Unavailable'); |
|
338 | + header('Retry-After: 120'); |
|
339 | + |
|
340 | + // render error page |
|
341 | + $template = new OC_Template('', 'update.use-cli', 'guest'); |
|
342 | + $template->assign('productName', 'nextcloud'); // for now |
|
343 | + $template->assign('version', OC_Util::getVersionString()); |
|
344 | + $template->assign('tooBig', $tooBig); |
|
345 | + |
|
346 | + $template->printPage(); |
|
347 | + die(); |
|
348 | + } |
|
349 | + |
|
350 | + // check whether this is a core update or apps update |
|
351 | + $installedVersion = $systemConfig->getValue('version', '0.0.0'); |
|
352 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
353 | + |
|
354 | + // if not a core upgrade, then it's apps upgrade |
|
355 | + $isAppsOnlyUpgrade = version_compare($currentVersion, $installedVersion, '='); |
|
356 | + |
|
357 | + $oldTheme = $systemConfig->getValue('theme'); |
|
358 | + $systemConfig->setValue('theme', ''); |
|
359 | + OC_Util::addScript('config'); // needed for web root |
|
360 | + OC_Util::addScript('update'); |
|
361 | + |
|
362 | + /** @var \OC\App\AppManager $appManager */ |
|
363 | + $appManager = \OC::$server->getAppManager(); |
|
364 | + |
|
365 | + $tmpl = new OC_Template('', 'update.admin', 'guest'); |
|
366 | + $tmpl->assign('version', OC_Util::getVersionString()); |
|
367 | + $tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade); |
|
368 | + |
|
369 | + // get third party apps |
|
370 | + $ocVersion = \OCP\Util::getVersion(); |
|
371 | + $incompatibleApps = $appManager->getIncompatibleApps($ocVersion); |
|
372 | + $incompatibleShippedApps = []; |
|
373 | + foreach ($incompatibleApps as $appInfo) { |
|
374 | + if ($appManager->isShipped($appInfo['id'])) { |
|
375 | + $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
376 | + } |
|
377 | + } |
|
378 | + |
|
379 | + if (!empty($incompatibleShippedApps)) { |
|
380 | + $l = \OC::$server->getL10N('core'); |
|
381 | + $hint = $l->t('The files of the app %$1s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
|
382 | + throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
383 | + } |
|
384 | + |
|
385 | + $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
|
386 | + $tmpl->assign('incompatibleAppsList', $incompatibleApps); |
|
387 | + $tmpl->assign('productName', 'Nextcloud'); // for now |
|
388 | + $tmpl->assign('oldTheme', $oldTheme); |
|
389 | + $tmpl->printPage(); |
|
390 | + } |
|
391 | + |
|
392 | + public static function initSession() { |
|
393 | + if(self::$server->getRequest()->getServerProtocol() === 'https') { |
|
394 | + ini_set('session.cookie_secure', true); |
|
395 | + } |
|
396 | + |
|
397 | + // prevents javascript from accessing php session cookies |
|
398 | + ini_set('session.cookie_httponly', 'true'); |
|
399 | + |
|
400 | + // set the cookie path to the Nextcloud directory |
|
401 | + $cookie_path = OC::$WEBROOT ? : '/'; |
|
402 | + ini_set('session.cookie_path', $cookie_path); |
|
403 | + |
|
404 | + // Let the session name be changed in the initSession Hook |
|
405 | + $sessionName = OC_Util::getInstanceId(); |
|
406 | + |
|
407 | + try { |
|
408 | + // Allow session apps to create a custom session object |
|
409 | + $useCustomSession = false; |
|
410 | + $session = self::$server->getSession(); |
|
411 | + OC_Hook::emit('OC', 'initSession', array('session' => &$session, 'sessionName' => &$sessionName, 'useCustomSession' => &$useCustomSession)); |
|
412 | + if (!$useCustomSession) { |
|
413 | + // set the session name to the instance id - which is unique |
|
414 | + $session = new \OC\Session\Internal($sessionName); |
|
415 | + } |
|
416 | + |
|
417 | + $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
418 | + $session = $cryptoWrapper->wrapSession($session); |
|
419 | + self::$server->setSession($session); |
|
420 | + |
|
421 | + // if session can't be started break with http 500 error |
|
422 | + } catch (Exception $e) { |
|
423 | + \OCP\Util::logException('base', $e); |
|
424 | + //show the user a detailed error page |
|
425 | + OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
426 | + OC_Template::printExceptionErrorPage($e); |
|
427 | + die(); |
|
428 | + } |
|
429 | + |
|
430 | + $sessionLifeTime = self::getSessionLifeTime(); |
|
431 | + |
|
432 | + // session timeout |
|
433 | + if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
|
434 | + if (isset($_COOKIE[session_name()])) { |
|
435 | + setcookie(session_name(), null, -1, self::$WEBROOT ? : '/'); |
|
436 | + } |
|
437 | + \OC::$server->getUserSession()->logout(); |
|
438 | + } |
|
439 | + |
|
440 | + $session->set('LAST_ACTIVITY', time()); |
|
441 | + } |
|
442 | + |
|
443 | + /** |
|
444 | + * @return string |
|
445 | + */ |
|
446 | + private static function getSessionLifeTime() { |
|
447 | + return \OC::$server->getConfig()->getSystemValue('session_lifetime', 60 * 60 * 24); |
|
448 | + } |
|
449 | + |
|
450 | + public static function loadAppClassPaths() { |
|
451 | + foreach (OC_App::getEnabledApps() as $app) { |
|
452 | + $appPath = OC_App::getAppPath($app); |
|
453 | + if ($appPath === false) { |
|
454 | + continue; |
|
455 | + } |
|
456 | + |
|
457 | + $file = $appPath . '/appinfo/classpath.php'; |
|
458 | + if (file_exists($file)) { |
|
459 | + require_once $file; |
|
460 | + } |
|
461 | + } |
|
462 | + } |
|
463 | + |
|
464 | + /** |
|
465 | + * Try to set some values to the required Nextcloud default |
|
466 | + */ |
|
467 | + public static function setRequiredIniValues() { |
|
468 | + @ini_set('default_charset', 'UTF-8'); |
|
469 | + @ini_set('gd.jpeg_ignore_warning', '1'); |
|
470 | + } |
|
471 | + |
|
472 | + /** |
|
473 | + * Send the same site cookies |
|
474 | + */ |
|
475 | + private static function sendSameSiteCookies() { |
|
476 | + $cookieParams = session_get_cookie_params(); |
|
477 | + $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
478 | + $policies = [ |
|
479 | + 'lax', |
|
480 | + 'strict', |
|
481 | + ]; |
|
482 | + |
|
483 | + // Append __Host to the cookie if it meets the requirements |
|
484 | + $cookiePrefix = ''; |
|
485 | + if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
486 | + $cookiePrefix = '__Host-'; |
|
487 | + } |
|
488 | + |
|
489 | + foreach($policies as $policy) { |
|
490 | + header( |
|
491 | + sprintf( |
|
492 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
493 | + $cookiePrefix, |
|
494 | + $policy, |
|
495 | + $cookieParams['path'], |
|
496 | + $policy |
|
497 | + ), |
|
498 | + false |
|
499 | + ); |
|
500 | + } |
|
501 | + } |
|
502 | + |
|
503 | + /** |
|
504 | + * Same Site cookie to further mitigate CSRF attacks. This cookie has to |
|
505 | + * be set in every request if cookies are sent to add a second level of |
|
506 | + * defense against CSRF. |
|
507 | + * |
|
508 | + * If the cookie is not sent this will set the cookie and reload the page. |
|
509 | + * We use an additional cookie since we want to protect logout CSRF and |
|
510 | + * also we can't directly interfere with PHP's session mechanism. |
|
511 | + */ |
|
512 | + private static function performSameSiteCookieProtection() { |
|
513 | + $request = \OC::$server->getRequest(); |
|
514 | + |
|
515 | + // Some user agents are notorious and don't really properly follow HTTP |
|
516 | + // specifications. For those, have an automated opt-out. Since the protection |
|
517 | + // for remote.php is applied in base.php as starting point we need to opt out |
|
518 | + // here. |
|
519 | + $incompatibleUserAgents = [ |
|
520 | + // OS X Finder |
|
521 | + '/^WebDAVFS/', |
|
522 | + ]; |
|
523 | + if($request->isUserAgent($incompatibleUserAgents)) { |
|
524 | + return; |
|
525 | + } |
|
526 | + |
|
527 | + if(count($_COOKIE) > 0) { |
|
528 | + $requestUri = $request->getScriptName(); |
|
529 | + $processingScript = explode('/', $requestUri); |
|
530 | + $processingScript = $processingScript[count($processingScript)-1]; |
|
531 | + |
|
532 | + // index.php routes are handled in the middleware |
|
533 | + if($processingScript === 'index.php') { |
|
534 | + return; |
|
535 | + } |
|
536 | + |
|
537 | + // All other endpoints require the lax and the strict cookie |
|
538 | + if(!$request->passesStrictCookieCheck()) { |
|
539 | + self::sendSameSiteCookies(); |
|
540 | + // Debug mode gets access to the resources without strict cookie |
|
541 | + // due to the fact that the SabreDAV browser also lives there. |
|
542 | + if(!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
543 | + http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
|
544 | + exit(); |
|
545 | + } |
|
546 | + } |
|
547 | + } elseif(!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
548 | + self::sendSameSiteCookies(); |
|
549 | + } |
|
550 | + } |
|
551 | + |
|
552 | + public static function init() { |
|
553 | + // calculate the root directories |
|
554 | + OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); |
|
555 | + |
|
556 | + // register autoloader |
|
557 | + $loaderStart = microtime(true); |
|
558 | + require_once __DIR__ . '/autoloader.php'; |
|
559 | + self::$loader = new \OC\Autoloader([ |
|
560 | + OC::$SERVERROOT . '/lib/private/legacy', |
|
561 | + ]); |
|
562 | + if (defined('PHPUNIT_RUN')) { |
|
563 | + self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
564 | + } |
|
565 | + spl_autoload_register(array(self::$loader, 'load')); |
|
566 | + $loaderEnd = microtime(true); |
|
567 | + |
|
568 | + self::$CLI = (php_sapi_name() == 'cli'); |
|
569 | + |
|
570 | + // Add default composer PSR-4 autoloader |
|
571 | + self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
572 | + |
|
573 | + try { |
|
574 | + self::initPaths(); |
|
575 | + // setup 3rdparty autoloader |
|
576 | + $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
577 | + if (!file_exists($vendorAutoLoad)) { |
|
578 | + 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".'); |
|
579 | + } |
|
580 | + require_once $vendorAutoLoad; |
|
581 | + |
|
582 | + } catch (\RuntimeException $e) { |
|
583 | + if (!self::$CLI) { |
|
584 | + $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
|
585 | + $protocol = in_array($claimedProtocol, ['HTTP/1.0', 'HTTP/1.1', 'HTTP/2']) ? $claimedProtocol : 'HTTP/1.1'; |
|
586 | + header($protocol . ' ' . OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
587 | + } |
|
588 | + // we can't use the template error page here, because this needs the |
|
589 | + // DI container which isn't available yet |
|
590 | + print($e->getMessage()); |
|
591 | + exit(); |
|
592 | + } |
|
593 | + |
|
594 | + // setup the basic server |
|
595 | + self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); |
|
596 | + \OC::$server->getEventLogger()->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); |
|
597 | + \OC::$server->getEventLogger()->start('boot', 'Initialize'); |
|
598 | + |
|
599 | + // Don't display errors and log them |
|
600 | + error_reporting(E_ALL | E_STRICT); |
|
601 | + @ini_set('display_errors', '0'); |
|
602 | + @ini_set('log_errors', '1'); |
|
603 | + |
|
604 | + if(!date_default_timezone_set('UTC')) { |
|
605 | + throw new \RuntimeException('Could not set timezone to UTC'); |
|
606 | + } |
|
607 | + |
|
608 | + //try to configure php to enable big file uploads. |
|
609 | + //this doesn´t work always depending on the webserver and php configuration. |
|
610 | + //Let´s try to overwrite some defaults anyway |
|
611 | + |
|
612 | + //try to set the maximum execution time to 60min |
|
613 | + if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
614 | + @set_time_limit(3600); |
|
615 | + } |
|
616 | + @ini_set('max_execution_time', '3600'); |
|
617 | + @ini_set('max_input_time', '3600'); |
|
618 | + |
|
619 | + //try to set the maximum filesize to 10G |
|
620 | + @ini_set('upload_max_filesize', '10G'); |
|
621 | + @ini_set('post_max_size', '10G'); |
|
622 | + @ini_set('file_uploads', '50'); |
|
623 | + |
|
624 | + self::setRequiredIniValues(); |
|
625 | + self::handleAuthHeaders(); |
|
626 | + self::registerAutoloaderCache(); |
|
627 | + |
|
628 | + // initialize intl fallback is necessary |
|
629 | + \Patchwork\Utf8\Bootup::initIntl(); |
|
630 | + OC_Util::isSetLocaleWorking(); |
|
631 | + |
|
632 | + if (!defined('PHPUNIT_RUN')) { |
|
633 | + OC\Log\ErrorHandler::setLogger(\OC::$server->getLogger()); |
|
634 | + $debug = \OC::$server->getConfig()->getSystemValue('debug', false); |
|
635 | + OC\Log\ErrorHandler::register($debug); |
|
636 | + } |
|
637 | + |
|
638 | + \OC::$server->getEventLogger()->start('init_session', 'Initialize session'); |
|
639 | + OC_App::loadApps(array('session')); |
|
640 | + if (!self::$CLI) { |
|
641 | + self::initSession(); |
|
642 | + } |
|
643 | + \OC::$server->getEventLogger()->end('init_session'); |
|
644 | + self::checkConfig(); |
|
645 | + self::checkInstalled(); |
|
646 | + |
|
647 | + OC_Response::addSecurityHeaders(); |
|
648 | + |
|
649 | + self::performSameSiteCookieProtection(); |
|
650 | + |
|
651 | + if (!defined('OC_CONSOLE')) { |
|
652 | + $errors = OC_Util::checkServer(\OC::$server->getSystemConfig()); |
|
653 | + if (count($errors) > 0) { |
|
654 | + if (self::$CLI) { |
|
655 | + // Convert l10n string into regular string for usage in database |
|
656 | + $staticErrors = []; |
|
657 | + foreach ($errors as $error) { |
|
658 | + echo $error['error'] . "\n"; |
|
659 | + echo $error['hint'] . "\n\n"; |
|
660 | + $staticErrors[] = [ |
|
661 | + 'error' => (string)$error['error'], |
|
662 | + 'hint' => (string)$error['hint'], |
|
663 | + ]; |
|
664 | + } |
|
665 | + |
|
666 | + try { |
|
667 | + \OC::$server->getConfig()->setAppValue('core', 'cronErrors', json_encode($staticErrors)); |
|
668 | + } catch (\Exception $e) { |
|
669 | + echo('Writing to database failed'); |
|
670 | + } |
|
671 | + exit(1); |
|
672 | + } else { |
|
673 | + OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
674 | + OC_Util::addStyle('guest'); |
|
675 | + OC_Template::printGuestPage('', 'error', array('errors' => $errors)); |
|
676 | + exit; |
|
677 | + } |
|
678 | + } elseif (self::$CLI && \OC::$server->getConfig()->getSystemValue('installed', false)) { |
|
679 | + \OC::$server->getConfig()->deleteAppValue('core', 'cronErrors'); |
|
680 | + } |
|
681 | + } |
|
682 | + //try to set the session lifetime |
|
683 | + $sessionLifeTime = self::getSessionLifeTime(); |
|
684 | + @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
685 | + |
|
686 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
687 | + |
|
688 | + // User and Groups |
|
689 | + if (!$systemConfig->getValue("installed", false)) { |
|
690 | + self::$server->getSession()->set('user_id', ''); |
|
691 | + } |
|
692 | + |
|
693 | + OC_User::useBackend(new \OC\User\Database()); |
|
694 | + \OC::$server->getGroupManager()->addBackend(new \OC\Group\Database()); |
|
695 | + |
|
696 | + // Subscribe to the hook |
|
697 | + \OCP\Util::connectHook( |
|
698 | + '\OCA\Files_Sharing\API\Server2Server', |
|
699 | + 'preLoginNameUsedAsUserName', |
|
700 | + '\OC\User\Database', |
|
701 | + 'preLoginNameUsedAsUserName' |
|
702 | + ); |
|
703 | + |
|
704 | + //setup extra user backends |
|
705 | + if (!\OCP\Util::needUpgrade()) { |
|
706 | + OC_User::setupBackends(); |
|
707 | + } else { |
|
708 | + // Run upgrades in incognito mode |
|
709 | + OC_User::setIncognitoMode(true); |
|
710 | + } |
|
711 | + |
|
712 | + self::registerCleanupHooks(); |
|
713 | + self::registerFilesystemHooks(); |
|
714 | + self::registerShareHooks(); |
|
715 | + self::registerEncryptionWrapper(); |
|
716 | + self::registerEncryptionHooks(); |
|
717 | + self::registerAccountHooks(); |
|
718 | + |
|
719 | + $settings = new \OC\Settings\Application(); |
|
720 | + $settings->register(); |
|
721 | + |
|
722 | + //make sure temporary files are cleaned up |
|
723 | + $tmpManager = \OC::$server->getTempManager(); |
|
724 | + register_shutdown_function(array($tmpManager, 'clean')); |
|
725 | + $lockProvider = \OC::$server->getLockingProvider(); |
|
726 | + register_shutdown_function(array($lockProvider, 'releaseAll')); |
|
727 | + |
|
728 | + // Check whether the sample configuration has been copied |
|
729 | + if($systemConfig->getValue('copied_sample_config', false)) { |
|
730 | + $l = \OC::$server->getL10N('lib'); |
|
731 | + header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
732 | + header('Status: 503 Service Temporarily Unavailable'); |
|
733 | + OC_Template::printErrorPage( |
|
734 | + $l->t('Sample configuration detected'), |
|
735 | + $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') |
|
736 | + ); |
|
737 | + return; |
|
738 | + } |
|
739 | + |
|
740 | + $request = \OC::$server->getRequest(); |
|
741 | + $host = $request->getInsecureServerHost(); |
|
742 | + /** |
|
743 | + * if the host passed in headers isn't trusted |
|
744 | + * FIXME: Should not be in here at all :see_no_evil: |
|
745 | + */ |
|
746 | + if (!OC::$CLI |
|
747 | + // overwritehost is always trusted, workaround to not have to make |
|
748 | + // \OC\AppFramework\Http\Request::getOverwriteHost public |
|
749 | + && self::$server->getConfig()->getSystemValue('overwritehost') === '' |
|
750 | + && !\OC::$server->getTrustedDomainHelper()->isTrustedDomain($host) |
|
751 | + && self::$server->getConfig()->getSystemValue('installed', false) |
|
752 | + ) { |
|
753 | + // Allow access to CSS resources |
|
754 | + $isScssRequest = false; |
|
755 | + if(strpos($request->getPathInfo(), '/css/') === 0) { |
|
756 | + $isScssRequest = true; |
|
757 | + } |
|
758 | + |
|
759 | + if(substr($request->getRequestUri(), -11) === '/status.php') { |
|
760 | + OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST); |
|
761 | + header('Status: 400 Bad Request'); |
|
762 | + header('Content-Type: application/json'); |
|
763 | + echo '{"error": "Trusted domain error.", "code": 15}'; |
|
764 | + exit(); |
|
765 | + } |
|
766 | + |
|
767 | + if (!$isScssRequest) { |
|
768 | + OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST); |
|
769 | + header('Status: 400 Bad Request'); |
|
770 | + |
|
771 | + \OC::$server->getLogger()->warning( |
|
772 | + 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', |
|
773 | + [ |
|
774 | + 'app' => 'core', |
|
775 | + 'remoteAddress' => $request->getRemoteAddress(), |
|
776 | + 'host' => $host, |
|
777 | + ] |
|
778 | + ); |
|
779 | + |
|
780 | + $tmpl = new OCP\Template('core', 'untrustedDomain', 'guest'); |
|
781 | + $tmpl->assign('domain', $host); |
|
782 | + $tmpl->printPage(); |
|
783 | + |
|
784 | + exit(); |
|
785 | + } |
|
786 | + } |
|
787 | + \OC::$server->getEventLogger()->end('boot'); |
|
788 | + } |
|
789 | + |
|
790 | + /** |
|
791 | + * register hooks for the cleanup of cache and bruteforce protection |
|
792 | + */ |
|
793 | + public static function registerCleanupHooks() { |
|
794 | + //don't try to do this before we are properly setup |
|
795 | + if (\OC::$server->getSystemConfig()->getValue('installed', false) && !\OCP\Util::needUpgrade()) { |
|
796 | + |
|
797 | + // NOTE: This will be replaced to use OCP |
|
798 | + $userSession = self::$server->getUserSession(); |
|
799 | + $userSession->listen('\OC\User', 'postLogin', function () use ($userSession) { |
|
800 | + if (!defined('PHPUNIT_RUN')) { |
|
801 | + // reset brute force delay for this IP address and username |
|
802 | + $uid = \OC::$server->getUserSession()->getUser()->getUID(); |
|
803 | + $request = \OC::$server->getRequest(); |
|
804 | + $throttler = \OC::$server->getBruteForceThrottler(); |
|
805 | + $throttler->resetDelay($request->getRemoteAddress(), 'login', ['user' => $uid]); |
|
806 | + } |
|
807 | + |
|
808 | + try { |
|
809 | + $cache = new \OC\Cache\File(); |
|
810 | + $cache->gc(); |
|
811 | + } catch (\OC\ServerNotAvailableException $e) { |
|
812 | + // not a GC exception, pass it on |
|
813 | + throw $e; |
|
814 | + } catch (\OC\ForbiddenException $e) { |
|
815 | + // filesystem blocked for this request, ignore |
|
816 | + } catch (\Exception $e) { |
|
817 | + // a GC exception should not prevent users from using OC, |
|
818 | + // so log the exception |
|
819 | + \OC::$server->getLogger()->logException($e, [ |
|
820 | + 'message' => 'Exception when running cache gc.', |
|
821 | + 'level' => \OCP\Util::WARN, |
|
822 | + 'app' => 'core', |
|
823 | + ]); |
|
824 | + } |
|
825 | + }); |
|
826 | + } |
|
827 | + } |
|
828 | + |
|
829 | + private static function registerEncryptionWrapper() { |
|
830 | + $manager = self::$server->getEncryptionManager(); |
|
831 | + \OCP\Util::connectHook('OC_Filesystem', 'preSetup', $manager, 'setupStorage'); |
|
832 | + } |
|
833 | + |
|
834 | + private static function registerEncryptionHooks() { |
|
835 | + $enabled = self::$server->getEncryptionManager()->isEnabled(); |
|
836 | + if ($enabled) { |
|
837 | + \OCP\Util::connectHook('OCP\Share', 'post_shared', 'OC\Encryption\HookManager', 'postShared'); |
|
838 | + \OCP\Util::connectHook('OCP\Share', 'post_unshare', 'OC\Encryption\HookManager', 'postUnshared'); |
|
839 | + \OCP\Util::connectHook('OC_Filesystem', 'post_rename', 'OC\Encryption\HookManager', 'postRename'); |
|
840 | + \OCP\Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', 'OC\Encryption\HookManager', 'postRestore'); |
|
841 | + } |
|
842 | + } |
|
843 | + |
|
844 | + private static function registerAccountHooks() { |
|
845 | + $hookHandler = new \OC\Accounts\Hooks(\OC::$server->getLogger()); |
|
846 | + \OCP\Util::connectHook('OC_User', 'changeUser', $hookHandler, 'changeUserHook'); |
|
847 | + } |
|
848 | + |
|
849 | + /** |
|
850 | + * register hooks for the filesystem |
|
851 | + */ |
|
852 | + public static function registerFilesystemHooks() { |
|
853 | + // Check for blacklisted files |
|
854 | + OC_Hook::connect('OC_Filesystem', 'write', 'OC\Files\Filesystem', 'isBlacklisted'); |
|
855 | + OC_Hook::connect('OC_Filesystem', 'rename', 'OC\Files\Filesystem', 'isBlacklisted'); |
|
856 | + } |
|
857 | + |
|
858 | + /** |
|
859 | + * register hooks for sharing |
|
860 | + */ |
|
861 | + public static function registerShareHooks() { |
|
862 | + if (\OC::$server->getSystemConfig()->getValue('installed')) { |
|
863 | + OC_Hook::connect('OC_User', 'post_deleteUser', 'OC\Share20\Hooks', 'post_deleteUser'); |
|
864 | + OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OC\Share20\Hooks', 'post_removeFromGroup'); |
|
865 | + OC_Hook::connect('OC_User', 'post_deleteGroup', 'OC\Share20\Hooks', 'post_deleteGroup'); |
|
866 | + } |
|
867 | + } |
|
868 | + |
|
869 | + protected static function registerAutoloaderCache() { |
|
870 | + // The class loader takes an optional low-latency cache, which MUST be |
|
871 | + // namespaced. The instanceid is used for namespacing, but might be |
|
872 | + // unavailable at this point. Furthermore, it might not be possible to |
|
873 | + // generate an instanceid via \OC_Util::getInstanceId() because the |
|
874 | + // config file may not be writable. As such, we only register a class |
|
875 | + // loader cache if instanceid is available without trying to create one. |
|
876 | + $instanceId = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
877 | + if ($instanceId) { |
|
878 | + try { |
|
879 | + $memcacheFactory = \OC::$server->getMemCacheFactory(); |
|
880 | + self::$loader->setMemoryCache($memcacheFactory->createLocal('Autoloader')); |
|
881 | + } catch (\Exception $ex) { |
|
882 | + } |
|
883 | + } |
|
884 | + } |
|
885 | + |
|
886 | + /** |
|
887 | + * Handle the request |
|
888 | + */ |
|
889 | + public static function handleRequest() { |
|
890 | + |
|
891 | + \OC::$server->getEventLogger()->start('handle_request', 'Handle request'); |
|
892 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
893 | + // load all the classpaths from the enabled apps so they are available |
|
894 | + // in the routing files of each app |
|
895 | + OC::loadAppClassPaths(); |
|
896 | + |
|
897 | + // Check if Nextcloud is installed or in maintenance (update) mode |
|
898 | + if (!$systemConfig->getValue('installed', false)) { |
|
899 | + \OC::$server->getSession()->clear(); |
|
900 | + $setupHelper = new OC\Setup( |
|
901 | + $systemConfig, |
|
902 | + \OC::$server->getIniWrapper(), |
|
903 | + \OC::$server->getL10N('lib'), |
|
904 | + \OC::$server->query(\OCP\Defaults::class), |
|
905 | + \OC::$server->getLogger(), |
|
906 | + \OC::$server->getSecureRandom(), |
|
907 | + \OC::$server->query(\OC\Installer::class) |
|
908 | + ); |
|
909 | + $controller = new OC\Core\Controller\SetupController($setupHelper); |
|
910 | + $controller->run($_POST); |
|
911 | + exit(); |
|
912 | + } |
|
913 | + |
|
914 | + $request = \OC::$server->getRequest(); |
|
915 | + $requestPath = $request->getRawPathInfo(); |
|
916 | + if ($requestPath === '/heartbeat') { |
|
917 | + return; |
|
918 | + } |
|
919 | + if (substr($requestPath, -3) !== '.js') { // we need these files during the upgrade |
|
920 | + self::checkMaintenanceMode(); |
|
921 | + |
|
922 | + if (\OCP\Util::needUpgrade()) { |
|
923 | + if (function_exists('opcache_reset')) { |
|
924 | + opcache_reset(); |
|
925 | + } |
|
926 | + if (!$systemConfig->getValue('maintenance', false)) { |
|
927 | + self::printUpgradePage($systemConfig); |
|
928 | + exit(); |
|
929 | + } |
|
930 | + } |
|
931 | + } |
|
932 | + |
|
933 | + // emergency app disabling |
|
934 | + if ($requestPath === '/disableapp' |
|
935 | + && $request->getMethod() === 'POST' |
|
936 | + && ((array)$request->getParam('appid')) !== '' |
|
937 | + ) { |
|
938 | + \OCP\JSON::callCheck(); |
|
939 | + \OCP\JSON::checkAdminUser(); |
|
940 | + $appIds = (array)$request->getParam('appid'); |
|
941 | + foreach($appIds as $appId) { |
|
942 | + $appId = \OC_App::cleanAppId($appId); |
|
943 | + \OC_App::disable($appId); |
|
944 | + } |
|
945 | + \OC_JSON::success(); |
|
946 | + exit(); |
|
947 | + } |
|
948 | + |
|
949 | + // Always load authentication apps |
|
950 | + OC_App::loadApps(['authentication']); |
|
951 | + |
|
952 | + // Load minimum set of apps |
|
953 | + if (!\OCP\Util::needUpgrade() |
|
954 | + && !$systemConfig->getValue('maintenance', false)) { |
|
955 | + // For logged-in users: Load everything |
|
956 | + if(\OC::$server->getUserSession()->isLoggedIn()) { |
|
957 | + OC_App::loadApps(); |
|
958 | + } else { |
|
959 | + // For guests: Load only filesystem and logging |
|
960 | + OC_App::loadApps(array('filesystem', 'logging')); |
|
961 | + self::handleLogin($request); |
|
962 | + } |
|
963 | + } |
|
964 | + |
|
965 | + if (!self::$CLI) { |
|
966 | + try { |
|
967 | + if (!$systemConfig->getValue('maintenance', false) && !\OCP\Util::needUpgrade()) { |
|
968 | + OC_App::loadApps(array('filesystem', 'logging')); |
|
969 | + OC_App::loadApps(); |
|
970 | + } |
|
971 | + OC_Util::setupFS(); |
|
972 | + OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo()); |
|
973 | + return; |
|
974 | + } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { |
|
975 | + //header('HTTP/1.0 404 Not Found'); |
|
976 | + } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { |
|
977 | + OC_Response::setStatus(405); |
|
978 | + return; |
|
979 | + } |
|
980 | + } |
|
981 | + |
|
982 | + // Handle WebDAV |
|
983 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
984 | + // not allowed any more to prevent people |
|
985 | + // mounting this root directly. |
|
986 | + // Users need to mount remote.php/webdav instead. |
|
987 | + header('HTTP/1.1 405 Method Not Allowed'); |
|
988 | + header('Status: 405 Method Not Allowed'); |
|
989 | + return; |
|
990 | + } |
|
991 | + |
|
992 | + // Someone is logged in |
|
993 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
994 | + OC_App::loadApps(); |
|
995 | + OC_User::setupBackends(); |
|
996 | + OC_Util::setupFS(); |
|
997 | + // FIXME |
|
998 | + // Redirect to default application |
|
999 | + OC_Util::redirectToDefaultPage(); |
|
1000 | + } else { |
|
1001 | + // Not handled and not logged in |
|
1002 | + header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm')); |
|
1003 | + } |
|
1004 | + } |
|
1005 | + |
|
1006 | + /** |
|
1007 | + * Check login: apache auth, auth token, basic auth |
|
1008 | + * |
|
1009 | + * @param OCP\IRequest $request |
|
1010 | + * @return boolean |
|
1011 | + */ |
|
1012 | + static function handleLogin(OCP\IRequest $request) { |
|
1013 | + $userSession = self::$server->getUserSession(); |
|
1014 | + if (OC_User::handleApacheAuth()) { |
|
1015 | + return true; |
|
1016 | + } |
|
1017 | + if ($userSession->tryTokenLogin($request)) { |
|
1018 | + return true; |
|
1019 | + } |
|
1020 | + if (isset($_COOKIE['nc_username']) |
|
1021 | + && isset($_COOKIE['nc_token']) |
|
1022 | + && isset($_COOKIE['nc_session_id']) |
|
1023 | + && $userSession->loginWithCookie($_COOKIE['nc_username'], $_COOKIE['nc_token'], $_COOKIE['nc_session_id'])) { |
|
1024 | + return true; |
|
1025 | + } |
|
1026 | + if ($userSession->tryBasicAuthLogin($request, \OC::$server->getBruteForceThrottler())) { |
|
1027 | + return true; |
|
1028 | + } |
|
1029 | + return false; |
|
1030 | + } |
|
1031 | + |
|
1032 | + protected static function handleAuthHeaders() { |
|
1033 | + //copy http auth headers for apache+php-fcgid work around |
|
1034 | + if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { |
|
1035 | + $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; |
|
1036 | + } |
|
1037 | + |
|
1038 | + // Extract PHP_AUTH_USER/PHP_AUTH_PW from other headers if necessary. |
|
1039 | + $vars = array( |
|
1040 | + 'HTTP_AUTHORIZATION', // apache+php-cgi work around |
|
1041 | + 'REDIRECT_HTTP_AUTHORIZATION', // apache+php-cgi alternative |
|
1042 | + ); |
|
1043 | + foreach ($vars as $var) { |
|
1044 | + if (isset($_SERVER[$var]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$var], $matches)) { |
|
1045 | + list($name, $password) = explode(':', base64_decode($matches[1]), 2); |
|
1046 | + $_SERVER['PHP_AUTH_USER'] = $name; |
|
1047 | + $_SERVER['PHP_AUTH_PW'] = $password; |
|
1048 | + break; |
|
1049 | + } |
|
1050 | + } |
|
1051 | + } |
|
1052 | 1052 | } |
1053 | 1053 | |
1054 | 1054 | OC::init(); |
@@ -122,14 +122,14 @@ discard block |
||
122 | 122 | * the app path list is empty or contains an invalid path |
123 | 123 | */ |
124 | 124 | public static function initPaths() { |
125 | - if(defined('PHPUNIT_CONFIG_DIR')) { |
|
126 | - self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
127 | - } elseif(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
128 | - self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
129 | - } elseif($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
130 | - self::$configDir = rtrim($dir, '/') . '/'; |
|
125 | + if (defined('PHPUNIT_CONFIG_DIR')) { |
|
126 | + self::$configDir = OC::$SERVERROOT.'/'.PHPUNIT_CONFIG_DIR.'/'; |
|
127 | + } elseif (defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT.'/tests/config/')) { |
|
128 | + self::$configDir = OC::$SERVERROOT.'/tests/config/'; |
|
129 | + } elseif ($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
130 | + self::$configDir = rtrim($dir, '/').'/'; |
|
131 | 131 | } else { |
132 | - self::$configDir = OC::$SERVERROOT . '/config/'; |
|
132 | + self::$configDir = OC::$SERVERROOT.'/config/'; |
|
133 | 133 | } |
134 | 134 | self::$config = new \OC\Config(self::$configDir); |
135 | 135 | |
@@ -151,9 +151,9 @@ discard block |
||
151 | 151 | //make sure suburi follows the same rules as scriptName |
152 | 152 | if (substr(OC::$SUBURI, -9) != 'index.php') { |
153 | 153 | if (substr(OC::$SUBURI, -1) != '/') { |
154 | - OC::$SUBURI = OC::$SUBURI . '/'; |
|
154 | + OC::$SUBURI = OC::$SUBURI.'/'; |
|
155 | 155 | } |
156 | - OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
156 | + OC::$SUBURI = OC::$SUBURI.'index.php'; |
|
157 | 157 | } |
158 | 158 | } |
159 | 159 | |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
166 | 166 | |
167 | 167 | if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
168 | - OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
168 | + OC::$WEBROOT = '/'.OC::$WEBROOT; |
|
169 | 169 | } |
170 | 170 | } else { |
171 | 171 | // The scriptName is not ending with OC::$SUBURI |
@@ -194,11 +194,11 @@ discard block |
||
194 | 194 | OC::$APPSROOTS[] = $paths; |
195 | 195 | } |
196 | 196 | } |
197 | - } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
198 | - OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); |
|
199 | - } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
197 | + } elseif (file_exists(OC::$SERVERROOT.'/apps')) { |
|
198 | + OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT.'/apps', 'url' => '/apps', 'writable' => true); |
|
199 | + } elseif (file_exists(OC::$SERVERROOT.'/../apps')) { |
|
200 | 200 | OC::$APPSROOTS[] = array( |
201 | - 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
201 | + 'path' => rtrim(dirname(OC::$SERVERROOT), '/').'/apps', |
|
202 | 202 | 'url' => '/apps', |
203 | 203 | 'writable' => true |
204 | 204 | ); |
@@ -228,8 +228,8 @@ discard block |
||
228 | 228 | $l = \OC::$server->getL10N('lib'); |
229 | 229 | |
230 | 230 | // Create config if it does not already exist |
231 | - $configFilePath = self::$configDir .'/config.php'; |
|
232 | - if(!file_exists($configFilePath)) { |
|
231 | + $configFilePath = self::$configDir.'/config.php'; |
|
232 | + if (!file_exists($configFilePath)) { |
|
233 | 233 | @touch($configFilePath); |
234 | 234 | } |
235 | 235 | |
@@ -244,13 +244,13 @@ discard block |
||
244 | 244 | echo $l->t('Cannot write into "config" directory!')."\n"; |
245 | 245 | echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
246 | 246 | echo "\n"; |
247 | - echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; |
|
247 | + echo $l->t('See %s', [$urlGenerator->linkToDocs('admin-dir_permissions')])."\n"; |
|
248 | 248 | exit; |
249 | 249 | } else { |
250 | 250 | OC_Template::printErrorPage( |
251 | 251 | $l->t('Cannot write into "config" directory!'), |
252 | 252 | $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
253 | - [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) |
|
253 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
254 | 254 | ); |
255 | 255 | } |
256 | 256 | } |
@@ -265,8 +265,8 @@ discard block |
||
265 | 265 | if (OC::$CLI) { |
266 | 266 | throw new Exception('Not installed'); |
267 | 267 | } else { |
268 | - $url = OC::$WEBROOT . '/index.php'; |
|
269 | - header('Location: ' . $url); |
|
268 | + $url = OC::$WEBROOT.'/index.php'; |
|
269 | + header('Location: '.$url); |
|
270 | 270 | } |
271 | 271 | exit(); |
272 | 272 | } |
@@ -372,14 +372,14 @@ discard block |
||
372 | 372 | $incompatibleShippedApps = []; |
373 | 373 | foreach ($incompatibleApps as $appInfo) { |
374 | 374 | if ($appManager->isShipped($appInfo['id'])) { |
375 | - $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
375 | + $incompatibleShippedApps[] = $appInfo['name'].' ('.$appInfo['id'].')'; |
|
376 | 376 | } |
377 | 377 | } |
378 | 378 | |
379 | 379 | if (!empty($incompatibleShippedApps)) { |
380 | 380 | $l = \OC::$server->getL10N('core'); |
381 | 381 | $hint = $l->t('The files of the app %$1s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
382 | - throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
382 | + throw new \OC\HintException('The files of the app '.implode(', ', $incompatibleShippedApps).' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | } |
391 | 391 | |
392 | 392 | public static function initSession() { |
393 | - if(self::$server->getRequest()->getServerProtocol() === 'https') { |
|
393 | + if (self::$server->getRequest()->getServerProtocol() === 'https') { |
|
394 | 394 | ini_set('session.cookie_secure', true); |
395 | 395 | } |
396 | 396 | |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | ini_set('session.cookie_httponly', 'true'); |
399 | 399 | |
400 | 400 | // set the cookie path to the Nextcloud directory |
401 | - $cookie_path = OC::$WEBROOT ? : '/'; |
|
401 | + $cookie_path = OC::$WEBROOT ?: '/'; |
|
402 | 402 | ini_set('session.cookie_path', $cookie_path); |
403 | 403 | |
404 | 404 | // Let the session name be changed in the initSession Hook |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | // session timeout |
433 | 433 | if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
434 | 434 | if (isset($_COOKIE[session_name()])) { |
435 | - setcookie(session_name(), null, -1, self::$WEBROOT ? : '/'); |
|
435 | + setcookie(session_name(), null, -1, self::$WEBROOT ?: '/'); |
|
436 | 436 | } |
437 | 437 | \OC::$server->getUserSession()->logout(); |
438 | 438 | } |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | continue; |
455 | 455 | } |
456 | 456 | |
457 | - $file = $appPath . '/appinfo/classpath.php'; |
|
457 | + $file = $appPath.'/appinfo/classpath.php'; |
|
458 | 458 | if (file_exists($file)) { |
459 | 459 | require_once $file; |
460 | 460 | } |
@@ -482,14 +482,14 @@ discard block |
||
482 | 482 | |
483 | 483 | // Append __Host to the cookie if it meets the requirements |
484 | 484 | $cookiePrefix = ''; |
485 | - if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
485 | + if ($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
486 | 486 | $cookiePrefix = '__Host-'; |
487 | 487 | } |
488 | 488 | |
489 | - foreach($policies as $policy) { |
|
489 | + foreach ($policies as $policy) { |
|
490 | 490 | header( |
491 | 491 | sprintf( |
492 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
492 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;'.$secureCookie.'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
493 | 493 | $cookiePrefix, |
494 | 494 | $policy, |
495 | 495 | $cookieParams['path'], |
@@ -520,31 +520,31 @@ discard block |
||
520 | 520 | // OS X Finder |
521 | 521 | '/^WebDAVFS/', |
522 | 522 | ]; |
523 | - if($request->isUserAgent($incompatibleUserAgents)) { |
|
523 | + if ($request->isUserAgent($incompatibleUserAgents)) { |
|
524 | 524 | return; |
525 | 525 | } |
526 | 526 | |
527 | - if(count($_COOKIE) > 0) { |
|
527 | + if (count($_COOKIE) > 0) { |
|
528 | 528 | $requestUri = $request->getScriptName(); |
529 | 529 | $processingScript = explode('/', $requestUri); |
530 | - $processingScript = $processingScript[count($processingScript)-1]; |
|
530 | + $processingScript = $processingScript[count($processingScript) - 1]; |
|
531 | 531 | |
532 | 532 | // index.php routes are handled in the middleware |
533 | - if($processingScript === 'index.php') { |
|
533 | + if ($processingScript === 'index.php') { |
|
534 | 534 | return; |
535 | 535 | } |
536 | 536 | |
537 | 537 | // All other endpoints require the lax and the strict cookie |
538 | - if(!$request->passesStrictCookieCheck()) { |
|
538 | + if (!$request->passesStrictCookieCheck()) { |
|
539 | 539 | self::sendSameSiteCookies(); |
540 | 540 | // Debug mode gets access to the resources without strict cookie |
541 | 541 | // due to the fact that the SabreDAV browser also lives there. |
542 | - if(!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
542 | + if (!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
543 | 543 | http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
544 | 544 | exit(); |
545 | 545 | } |
546 | 546 | } |
547 | - } elseif(!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
547 | + } elseif (!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
548 | 548 | self::sendSameSiteCookies(); |
549 | 549 | } |
550 | 550 | } |
@@ -555,12 +555,12 @@ discard block |
||
555 | 555 | |
556 | 556 | // register autoloader |
557 | 557 | $loaderStart = microtime(true); |
558 | - require_once __DIR__ . '/autoloader.php'; |
|
558 | + require_once __DIR__.'/autoloader.php'; |
|
559 | 559 | self::$loader = new \OC\Autoloader([ |
560 | - OC::$SERVERROOT . '/lib/private/legacy', |
|
560 | + OC::$SERVERROOT.'/lib/private/legacy', |
|
561 | 561 | ]); |
562 | 562 | if (defined('PHPUNIT_RUN')) { |
563 | - self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
563 | + self::$loader->addValidRoot(OC::$SERVERROOT.'/tests'); |
|
564 | 564 | } |
565 | 565 | spl_autoload_register(array(self::$loader, 'load')); |
566 | 566 | $loaderEnd = microtime(true); |
@@ -568,12 +568,12 @@ discard block |
||
568 | 568 | self::$CLI = (php_sapi_name() == 'cli'); |
569 | 569 | |
570 | 570 | // Add default composer PSR-4 autoloader |
571 | - self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
571 | + self::$composerAutoloader = require_once OC::$SERVERROOT.'/lib/composer/autoload.php'; |
|
572 | 572 | |
573 | 573 | try { |
574 | 574 | self::initPaths(); |
575 | 575 | // setup 3rdparty autoloader |
576 | - $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
576 | + $vendorAutoLoad = OC::$SERVERROOT.'/3rdparty/autoload.php'; |
|
577 | 577 | if (!file_exists($vendorAutoLoad)) { |
578 | 578 | 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".'); |
579 | 579 | } |
@@ -583,7 +583,7 @@ discard block |
||
583 | 583 | if (!self::$CLI) { |
584 | 584 | $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
585 | 585 | $protocol = in_array($claimedProtocol, ['HTTP/1.0', 'HTTP/1.1', 'HTTP/2']) ? $claimedProtocol : 'HTTP/1.1'; |
586 | - header($protocol . ' ' . OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
586 | + header($protocol.' '.OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
587 | 587 | } |
588 | 588 | // we can't use the template error page here, because this needs the |
589 | 589 | // DI container which isn't available yet |
@@ -601,7 +601,7 @@ discard block |
||
601 | 601 | @ini_set('display_errors', '0'); |
602 | 602 | @ini_set('log_errors', '1'); |
603 | 603 | |
604 | - if(!date_default_timezone_set('UTC')) { |
|
604 | + if (!date_default_timezone_set('UTC')) { |
|
605 | 605 | throw new \RuntimeException('Could not set timezone to UTC'); |
606 | 606 | } |
607 | 607 | |
@@ -655,11 +655,11 @@ discard block |
||
655 | 655 | // Convert l10n string into regular string for usage in database |
656 | 656 | $staticErrors = []; |
657 | 657 | foreach ($errors as $error) { |
658 | - echo $error['error'] . "\n"; |
|
659 | - echo $error['hint'] . "\n\n"; |
|
658 | + echo $error['error']."\n"; |
|
659 | + echo $error['hint']."\n\n"; |
|
660 | 660 | $staticErrors[] = [ |
661 | - 'error' => (string)$error['error'], |
|
662 | - 'hint' => (string)$error['hint'], |
|
661 | + 'error' => (string) $error['error'], |
|
662 | + 'hint' => (string) $error['hint'], |
|
663 | 663 | ]; |
664 | 664 | } |
665 | 665 | |
@@ -681,7 +681,7 @@ discard block |
||
681 | 681 | } |
682 | 682 | //try to set the session lifetime |
683 | 683 | $sessionLifeTime = self::getSessionLifeTime(); |
684 | - @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
684 | + @ini_set('gc_maxlifetime', (string) $sessionLifeTime); |
|
685 | 685 | |
686 | 686 | $systemConfig = \OC::$server->getSystemConfig(); |
687 | 687 | |
@@ -726,7 +726,7 @@ discard block |
||
726 | 726 | register_shutdown_function(array($lockProvider, 'releaseAll')); |
727 | 727 | |
728 | 728 | // Check whether the sample configuration has been copied |
729 | - if($systemConfig->getValue('copied_sample_config', false)) { |
|
729 | + if ($systemConfig->getValue('copied_sample_config', false)) { |
|
730 | 730 | $l = \OC::$server->getL10N('lib'); |
731 | 731 | header('HTTP/1.1 503 Service Temporarily Unavailable'); |
732 | 732 | header('Status: 503 Service Temporarily Unavailable'); |
@@ -752,11 +752,11 @@ discard block |
||
752 | 752 | ) { |
753 | 753 | // Allow access to CSS resources |
754 | 754 | $isScssRequest = false; |
755 | - if(strpos($request->getPathInfo(), '/css/') === 0) { |
|
755 | + if (strpos($request->getPathInfo(), '/css/') === 0) { |
|
756 | 756 | $isScssRequest = true; |
757 | 757 | } |
758 | 758 | |
759 | - if(substr($request->getRequestUri(), -11) === '/status.php') { |
|
759 | + if (substr($request->getRequestUri(), -11) === '/status.php') { |
|
760 | 760 | OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST); |
761 | 761 | header('Status: 400 Bad Request'); |
762 | 762 | header('Content-Type: application/json'); |
@@ -796,7 +796,7 @@ discard block |
||
796 | 796 | |
797 | 797 | // NOTE: This will be replaced to use OCP |
798 | 798 | $userSession = self::$server->getUserSession(); |
799 | - $userSession->listen('\OC\User', 'postLogin', function () use ($userSession) { |
|
799 | + $userSession->listen('\OC\User', 'postLogin', function() use ($userSession) { |
|
800 | 800 | if (!defined('PHPUNIT_RUN')) { |
801 | 801 | // reset brute force delay for this IP address and username |
802 | 802 | $uid = \OC::$server->getUserSession()->getUser()->getUID(); |
@@ -933,12 +933,12 @@ discard block |
||
933 | 933 | // emergency app disabling |
934 | 934 | if ($requestPath === '/disableapp' |
935 | 935 | && $request->getMethod() === 'POST' |
936 | - && ((array)$request->getParam('appid')) !== '' |
|
936 | + && ((array) $request->getParam('appid')) !== '' |
|
937 | 937 | ) { |
938 | 938 | \OCP\JSON::callCheck(); |
939 | 939 | \OCP\JSON::checkAdminUser(); |
940 | - $appIds = (array)$request->getParam('appid'); |
|
941 | - foreach($appIds as $appId) { |
|
940 | + $appIds = (array) $request->getParam('appid'); |
|
941 | + foreach ($appIds as $appId) { |
|
942 | 942 | $appId = \OC_App::cleanAppId($appId); |
943 | 943 | \OC_App::disable($appId); |
944 | 944 | } |
@@ -953,7 +953,7 @@ discard block |
||
953 | 953 | if (!\OCP\Util::needUpgrade() |
954 | 954 | && !$systemConfig->getValue('maintenance', false)) { |
955 | 955 | // For logged-in users: Load everything |
956 | - if(\OC::$server->getUserSession()->isLoggedIn()) { |
|
956 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
957 | 957 | OC_App::loadApps(); |
958 | 958 | } else { |
959 | 959 | // For guests: Load only filesystem and logging |
@@ -63,1202 +63,1202 @@ |
||
63 | 63 | * upgrading and removing apps. |
64 | 64 | */ |
65 | 65 | class OC_App { |
66 | - static private $appVersion = []; |
|
67 | - static private $adminForms = array(); |
|
68 | - static private $personalForms = array(); |
|
69 | - static private $appInfo = array(); |
|
70 | - static private $appTypes = array(); |
|
71 | - static private $loadedApps = array(); |
|
72 | - static private $altLogin = array(); |
|
73 | - static private $alreadyRegistered = []; |
|
74 | - const officialApp = 200; |
|
75 | - |
|
76 | - /** |
|
77 | - * clean the appId |
|
78 | - * |
|
79 | - * @param string|boolean $app AppId that needs to be cleaned |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - public static function cleanAppId($app) { |
|
83 | - return str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Check if an app is loaded |
|
88 | - * |
|
89 | - * @param string $app |
|
90 | - * @return bool |
|
91 | - */ |
|
92 | - public static function isAppLoaded($app) { |
|
93 | - return in_array($app, self::$loadedApps, true); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * loads all apps |
|
98 | - * |
|
99 | - * @param string[] | string | null $types |
|
100 | - * @return bool |
|
101 | - * |
|
102 | - * This function walks through the ownCloud directory and loads all apps |
|
103 | - * it can find. A directory contains an app if the file /appinfo/info.xml |
|
104 | - * exists. |
|
105 | - * |
|
106 | - * if $types is set, only apps of those types will be loaded |
|
107 | - */ |
|
108 | - public static function loadApps($types = null) { |
|
109 | - if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
110 | - return false; |
|
111 | - } |
|
112 | - // Load the enabled apps here |
|
113 | - $apps = self::getEnabledApps(); |
|
114 | - |
|
115 | - // Add each apps' folder as allowed class path |
|
116 | - foreach($apps as $app) { |
|
117 | - $path = self::getAppPath($app); |
|
118 | - if($path !== false) { |
|
119 | - self::registerAutoloading($app, $path); |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - // prevent app.php from printing output |
|
124 | - ob_start(); |
|
125 | - foreach ($apps as $app) { |
|
126 | - if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) { |
|
127 | - self::loadApp($app); |
|
128 | - } |
|
129 | - } |
|
130 | - ob_end_clean(); |
|
131 | - |
|
132 | - return true; |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * load a single app |
|
137 | - * |
|
138 | - * @param string $app |
|
139 | - */ |
|
140 | - public static function loadApp($app) { |
|
141 | - self::$loadedApps[] = $app; |
|
142 | - $appPath = self::getAppPath($app); |
|
143 | - if($appPath === false) { |
|
144 | - return; |
|
145 | - } |
|
146 | - |
|
147 | - // in case someone calls loadApp() directly |
|
148 | - self::registerAutoloading($app, $appPath); |
|
149 | - |
|
150 | - if (is_file($appPath . '/appinfo/app.php')) { |
|
151 | - \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
152 | - self::requireAppFile($app); |
|
153 | - if (self::isType($app, array('authentication'))) { |
|
154 | - // since authentication apps affect the "is app enabled for group" check, |
|
155 | - // the enabled apps cache needs to be cleared to make sure that the |
|
156 | - // next time getEnableApps() is called it will also include apps that were |
|
157 | - // enabled for groups |
|
158 | - self::$enabledAppsCache = array(); |
|
159 | - } |
|
160 | - \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
161 | - } |
|
162 | - |
|
163 | - $info = self::getAppInfo($app); |
|
164 | - if (!empty($info['activity']['filters'])) { |
|
165 | - foreach ($info['activity']['filters'] as $filter) { |
|
166 | - \OC::$server->getActivityManager()->registerFilter($filter); |
|
167 | - } |
|
168 | - } |
|
169 | - if (!empty($info['activity']['settings'])) { |
|
170 | - foreach ($info['activity']['settings'] as $setting) { |
|
171 | - \OC::$server->getActivityManager()->registerSetting($setting); |
|
172 | - } |
|
173 | - } |
|
174 | - if (!empty($info['activity']['providers'])) { |
|
175 | - foreach ($info['activity']['providers'] as $provider) { |
|
176 | - \OC::$server->getActivityManager()->registerProvider($provider); |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - if (!empty($info['settings']['admin'])) { |
|
181 | - foreach ($info['settings']['admin'] as $setting) { |
|
182 | - \OC::$server->getSettingsManager()->registerSetting('admin', $setting); |
|
183 | - } |
|
184 | - } |
|
185 | - if (!empty($info['settings']['admin-section'])) { |
|
186 | - foreach ($info['settings']['admin-section'] as $section) { |
|
187 | - \OC::$server->getSettingsManager()->registerSection('admin', $section); |
|
188 | - } |
|
189 | - } |
|
190 | - if (!empty($info['settings']['personal'])) { |
|
191 | - foreach ($info['settings']['personal'] as $setting) { |
|
192 | - \OC::$server->getSettingsManager()->registerSetting('personal', $setting); |
|
193 | - } |
|
194 | - } |
|
195 | - if (!empty($info['settings']['personal-section'])) { |
|
196 | - foreach ($info['settings']['personal-section'] as $section) { |
|
197 | - \OC::$server->getSettingsManager()->registerSection('personal', $section); |
|
198 | - } |
|
199 | - } |
|
200 | - |
|
201 | - if (!empty($info['collaboration']['plugins'])) { |
|
202 | - // deal with one or many plugin entries |
|
203 | - $plugins = isset($info['collaboration']['plugins']['plugin']['@value']) ? |
|
204 | - [$info['collaboration']['plugins']['plugin']] : $info['collaboration']['plugins']['plugin']; |
|
205 | - foreach ($plugins as $plugin) { |
|
206 | - if($plugin['@attributes']['type'] === 'collaborator-search') { |
|
207 | - $pluginInfo = [ |
|
208 | - 'shareType' => $plugin['@attributes']['share-type'], |
|
209 | - 'class' => $plugin['@value'], |
|
210 | - ]; |
|
211 | - \OC::$server->getCollaboratorSearch()->registerPlugin($pluginInfo); |
|
212 | - } else if ($plugin['@attributes']['type'] === 'autocomplete-sort') { |
|
213 | - \OC::$server->getAutoCompleteManager()->registerSorter($plugin['@value']); |
|
214 | - } |
|
215 | - } |
|
216 | - } |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * @internal |
|
221 | - * @param string $app |
|
222 | - * @param string $path |
|
223 | - */ |
|
224 | - public static function registerAutoloading($app, $path) { |
|
225 | - $key = $app . '-' . $path; |
|
226 | - if(isset(self::$alreadyRegistered[$key])) { |
|
227 | - return; |
|
228 | - } |
|
229 | - |
|
230 | - self::$alreadyRegistered[$key] = true; |
|
231 | - |
|
232 | - // Register on PSR-4 composer autoloader |
|
233 | - $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
|
234 | - \OC::$server->registerNamespace($app, $appNamespace); |
|
235 | - |
|
236 | - if (file_exists($path . '/composer/autoload.php')) { |
|
237 | - require_once $path . '/composer/autoload.php'; |
|
238 | - } else { |
|
239 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
240 | - // Register on legacy autoloader |
|
241 | - \OC::$loader->addValidRoot($path); |
|
242 | - } |
|
243 | - |
|
244 | - // Register Test namespace only when testing |
|
245 | - if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
|
246 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
247 | - } |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Load app.php from the given app |
|
252 | - * |
|
253 | - * @param string $app app name |
|
254 | - */ |
|
255 | - private static function requireAppFile($app) { |
|
256 | - try { |
|
257 | - // encapsulated here to avoid variable scope conflicts |
|
258 | - require_once $app . '/appinfo/app.php'; |
|
259 | - } catch (Error $ex) { |
|
260 | - \OC::$server->getLogger()->logException($ex); |
|
261 | - if (!\OC::$server->getAppManager()->isShipped($app)) { |
|
262 | - // Only disable apps which are not shipped |
|
263 | - self::disable($app); |
|
264 | - } |
|
265 | - } |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * check if an app is of a specific type |
|
270 | - * |
|
271 | - * @param string $app |
|
272 | - * @param string|array $types |
|
273 | - * @return bool |
|
274 | - */ |
|
275 | - public static function isType($app, $types) { |
|
276 | - if (is_string($types)) { |
|
277 | - $types = array($types); |
|
278 | - } |
|
279 | - $appTypes = self::getAppTypes($app); |
|
280 | - foreach ($types as $type) { |
|
281 | - if (array_search($type, $appTypes) !== false) { |
|
282 | - return true; |
|
283 | - } |
|
284 | - } |
|
285 | - return false; |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * get the types of an app |
|
290 | - * |
|
291 | - * @param string $app |
|
292 | - * @return array |
|
293 | - */ |
|
294 | - private static function getAppTypes($app) { |
|
295 | - //load the cache |
|
296 | - if (count(self::$appTypes) == 0) { |
|
297 | - self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types'); |
|
298 | - } |
|
299 | - |
|
300 | - if (isset(self::$appTypes[$app])) { |
|
301 | - return explode(',', self::$appTypes[$app]); |
|
302 | - } else { |
|
303 | - return array(); |
|
304 | - } |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * read app types from info.xml and cache them in the database |
|
309 | - */ |
|
310 | - public static function setAppTypes($app) { |
|
311 | - $appData = self::getAppInfo($app); |
|
312 | - if(!is_array($appData)) { |
|
313 | - return; |
|
314 | - } |
|
315 | - |
|
316 | - if (isset($appData['types'])) { |
|
317 | - $appTypes = implode(',', $appData['types']); |
|
318 | - } else { |
|
319 | - $appTypes = ''; |
|
320 | - $appData['types'] = []; |
|
321 | - } |
|
322 | - |
|
323 | - \OC::$server->getConfig()->setAppValue($app, 'types', $appTypes); |
|
324 | - |
|
325 | - if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) { |
|
326 | - $enabled = \OC::$server->getConfig()->getAppValue($app, 'enabled', 'yes'); |
|
327 | - if ($enabled !== 'yes' && $enabled !== 'no') { |
|
328 | - \OC::$server->getConfig()->setAppValue($app, 'enabled', 'yes'); |
|
329 | - } |
|
330 | - } |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * get all enabled apps |
|
335 | - */ |
|
336 | - protected static $enabledAppsCache = array(); |
|
337 | - |
|
338 | - /** |
|
339 | - * Returns apps enabled for the current user. |
|
340 | - * |
|
341 | - * @param bool $forceRefresh whether to refresh the cache |
|
342 | - * @param bool $all whether to return apps for all users, not only the |
|
343 | - * currently logged in one |
|
344 | - * @return string[] |
|
345 | - */ |
|
346 | - public static function getEnabledApps($forceRefresh = false, $all = false) { |
|
347 | - if (!\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
348 | - return array(); |
|
349 | - } |
|
350 | - // in incognito mode or when logged out, $user will be false, |
|
351 | - // which is also the case during an upgrade |
|
352 | - $appManager = \OC::$server->getAppManager(); |
|
353 | - if ($all) { |
|
354 | - $user = null; |
|
355 | - } else { |
|
356 | - $user = \OC::$server->getUserSession()->getUser(); |
|
357 | - } |
|
358 | - |
|
359 | - if (is_null($user)) { |
|
360 | - $apps = $appManager->getInstalledApps(); |
|
361 | - } else { |
|
362 | - $apps = $appManager->getEnabledAppsForUser($user); |
|
363 | - } |
|
364 | - $apps = array_filter($apps, function ($app) { |
|
365 | - return $app !== 'files';//we add this manually |
|
366 | - }); |
|
367 | - sort($apps); |
|
368 | - array_unshift($apps, 'files'); |
|
369 | - return $apps; |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * checks whether or not an app is enabled |
|
374 | - * |
|
375 | - * @param string $app app |
|
376 | - * @return bool |
|
377 | - * @deprecated 13.0.0 use \OC::$server->getAppManager()->isEnabledForUser($appId) |
|
378 | - * |
|
379 | - * This function checks whether or not an app is enabled. |
|
380 | - */ |
|
381 | - public static function isEnabled($app) { |
|
382 | - return \OC::$server->getAppManager()->isEnabledForUser($app); |
|
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * enables an app |
|
387 | - * |
|
388 | - * @param string $appId |
|
389 | - * @param array $groups (optional) when set, only these groups will have access to the app |
|
390 | - * @throws \Exception |
|
391 | - * @return void |
|
392 | - * |
|
393 | - * This function set an app as enabled in appconfig. |
|
394 | - */ |
|
395 | - public function enable($appId, |
|
396 | - $groups = null) { |
|
397 | - self::$enabledAppsCache = []; // flush |
|
398 | - |
|
399 | - // Check if app is already downloaded |
|
400 | - $installer = \OC::$server->query(Installer::class); |
|
401 | - $isDownloaded = $installer->isDownloaded($appId); |
|
402 | - |
|
403 | - if(!$isDownloaded) { |
|
404 | - $installer->downloadApp($appId); |
|
405 | - } |
|
406 | - |
|
407 | - $installer->installApp($appId); |
|
408 | - |
|
409 | - $appManager = \OC::$server->getAppManager(); |
|
410 | - if (!is_null($groups)) { |
|
411 | - $groupManager = \OC::$server->getGroupManager(); |
|
412 | - $groupsList = []; |
|
413 | - foreach ($groups as $group) { |
|
414 | - $groupItem = $groupManager->get($group); |
|
415 | - if ($groupItem instanceof \OCP\IGroup) { |
|
416 | - $groupsList[] = $groupManager->get($group); |
|
417 | - } |
|
418 | - } |
|
419 | - $appManager->enableAppForGroups($appId, $groupsList); |
|
420 | - } else { |
|
421 | - $appManager->enableApp($appId); |
|
422 | - } |
|
423 | - } |
|
424 | - |
|
425 | - /** |
|
426 | - * @param string $app |
|
427 | - * @return bool |
|
428 | - */ |
|
429 | - public static function removeApp($app) { |
|
430 | - if (\OC::$server->getAppManager()->isShipped($app)) { |
|
431 | - return false; |
|
432 | - } |
|
433 | - |
|
434 | - $installer = \OC::$server->query(Installer::class); |
|
435 | - return $installer->removeApp($app); |
|
436 | - } |
|
437 | - |
|
438 | - /** |
|
439 | - * This function set an app as disabled in appconfig. |
|
440 | - * |
|
441 | - * @param string $app app |
|
442 | - * @throws Exception |
|
443 | - */ |
|
444 | - public static function disable($app) { |
|
445 | - // flush |
|
446 | - self::$enabledAppsCache = array(); |
|
447 | - |
|
448 | - // run uninstall steps |
|
449 | - $appData = OC_App::getAppInfo($app); |
|
450 | - if (!is_null($appData)) { |
|
451 | - OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']); |
|
452 | - } |
|
453 | - |
|
454 | - // emit disable hook - needed anymore ? |
|
455 | - \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app)); |
|
456 | - |
|
457 | - // finally disable it |
|
458 | - $appManager = \OC::$server->getAppManager(); |
|
459 | - $appManager->disableApp($app); |
|
460 | - } |
|
461 | - |
|
462 | - // This is private as well. It simply works, so don't ask for more details |
|
463 | - private static function proceedNavigation($list) { |
|
464 | - usort($list, function($a, $b) { |
|
465 | - if (isset($a['order']) && isset($b['order'])) { |
|
466 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
467 | - } else if (isset($a['order']) || isset($b['order'])) { |
|
468 | - return isset($a['order']) ? -1 : 1; |
|
469 | - } else { |
|
470 | - return ($a['name'] < $b['name']) ? -1 : 1; |
|
471 | - } |
|
472 | - }); |
|
473 | - |
|
474 | - $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); |
|
475 | - foreach ($list as $index => &$navEntry) { |
|
476 | - if ($navEntry['id'] == $activeApp) { |
|
477 | - $navEntry['active'] = true; |
|
478 | - } else { |
|
479 | - $navEntry['active'] = false; |
|
480 | - } |
|
481 | - } |
|
482 | - unset($navEntry); |
|
483 | - |
|
484 | - return $list; |
|
485 | - } |
|
486 | - |
|
487 | - /** |
|
488 | - * Get the path where to install apps |
|
489 | - * |
|
490 | - * @return string|false |
|
491 | - */ |
|
492 | - public static function getInstallPath() { |
|
493 | - if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) { |
|
494 | - return false; |
|
495 | - } |
|
496 | - |
|
497 | - foreach (OC::$APPSROOTS as $dir) { |
|
498 | - if (isset($dir['writable']) && $dir['writable'] === true) { |
|
499 | - return $dir['path']; |
|
500 | - } |
|
501 | - } |
|
502 | - |
|
503 | - \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR); |
|
504 | - return null; |
|
505 | - } |
|
506 | - |
|
507 | - |
|
508 | - /** |
|
509 | - * search for an app in all app-directories |
|
510 | - * |
|
511 | - * @param string $appId |
|
512 | - * @return false|string |
|
513 | - */ |
|
514 | - public static function findAppInDirectories($appId) { |
|
515 | - $sanitizedAppId = self::cleanAppId($appId); |
|
516 | - if($sanitizedAppId !== $appId) { |
|
517 | - return false; |
|
518 | - } |
|
519 | - static $app_dir = array(); |
|
520 | - |
|
521 | - if (isset($app_dir[$appId])) { |
|
522 | - return $app_dir[$appId]; |
|
523 | - } |
|
524 | - |
|
525 | - $possibleApps = array(); |
|
526 | - foreach (OC::$APPSROOTS as $dir) { |
|
527 | - if (file_exists($dir['path'] . '/' . $appId)) { |
|
528 | - $possibleApps[] = $dir; |
|
529 | - } |
|
530 | - } |
|
531 | - |
|
532 | - if (empty($possibleApps)) { |
|
533 | - return false; |
|
534 | - } elseif (count($possibleApps) === 1) { |
|
535 | - $dir = array_shift($possibleApps); |
|
536 | - $app_dir[$appId] = $dir; |
|
537 | - return $dir; |
|
538 | - } else { |
|
539 | - $versionToLoad = array(); |
|
540 | - foreach ($possibleApps as $possibleApp) { |
|
541 | - $version = self::getAppVersionByPath($possibleApp['path']); |
|
542 | - if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) { |
|
543 | - $versionToLoad = array( |
|
544 | - 'dir' => $possibleApp, |
|
545 | - 'version' => $version, |
|
546 | - ); |
|
547 | - } |
|
548 | - } |
|
549 | - $app_dir[$appId] = $versionToLoad['dir']; |
|
550 | - return $versionToLoad['dir']; |
|
551 | - //TODO - write test |
|
552 | - } |
|
553 | - } |
|
554 | - |
|
555 | - /** |
|
556 | - * Get the directory for the given app. |
|
557 | - * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
558 | - * |
|
559 | - * @param string $appId |
|
560 | - * @return string|false |
|
561 | - */ |
|
562 | - public static function getAppPath($appId) { |
|
563 | - if ($appId === null || trim($appId) === '') { |
|
564 | - return false; |
|
565 | - } |
|
566 | - |
|
567 | - if (($dir = self::findAppInDirectories($appId)) != false) { |
|
568 | - return $dir['path'] . '/' . $appId; |
|
569 | - } |
|
570 | - return false; |
|
571 | - } |
|
572 | - |
|
573 | - /** |
|
574 | - * Get the path for the given app on the access |
|
575 | - * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
576 | - * |
|
577 | - * @param string $appId |
|
578 | - * @return string|false |
|
579 | - */ |
|
580 | - public static function getAppWebPath($appId) { |
|
581 | - if (($dir = self::findAppInDirectories($appId)) != false) { |
|
582 | - return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
583 | - } |
|
584 | - return false; |
|
585 | - } |
|
586 | - |
|
587 | - /** |
|
588 | - * get the last version of the app from appinfo/info.xml |
|
589 | - * |
|
590 | - * @param string $appId |
|
591 | - * @param bool $useCache |
|
592 | - * @return string |
|
593 | - */ |
|
594 | - public static function getAppVersion($appId, $useCache = true) { |
|
595 | - if($useCache && isset(self::$appVersion[$appId])) { |
|
596 | - return self::$appVersion[$appId]; |
|
597 | - } |
|
598 | - |
|
599 | - $file = self::getAppPath($appId); |
|
600 | - self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0'; |
|
601 | - return self::$appVersion[$appId]; |
|
602 | - } |
|
603 | - |
|
604 | - /** |
|
605 | - * get app's version based on it's path |
|
606 | - * |
|
607 | - * @param string $path |
|
608 | - * @return string |
|
609 | - */ |
|
610 | - public static function getAppVersionByPath($path) { |
|
611 | - $infoFile = $path . '/appinfo/info.xml'; |
|
612 | - $appData = self::getAppInfo($infoFile, true); |
|
613 | - return isset($appData['version']) ? $appData['version'] : ''; |
|
614 | - } |
|
615 | - |
|
616 | - |
|
617 | - /** |
|
618 | - * Read all app metadata from the info.xml file |
|
619 | - * |
|
620 | - * @param string $appId id of the app or the path of the info.xml file |
|
621 | - * @param bool $path |
|
622 | - * @param string $lang |
|
623 | - * @return array|null |
|
624 | - * @note all data is read from info.xml, not just pre-defined fields |
|
625 | - */ |
|
626 | - public static function getAppInfo($appId, $path = false, $lang = null) { |
|
627 | - if ($path) { |
|
628 | - $file = $appId; |
|
629 | - } else { |
|
630 | - if ($lang === null && isset(self::$appInfo[$appId])) { |
|
631 | - return self::$appInfo[$appId]; |
|
632 | - } |
|
633 | - $appPath = self::getAppPath($appId); |
|
634 | - if($appPath === false) { |
|
635 | - return null; |
|
636 | - } |
|
637 | - $file = $appPath . '/appinfo/info.xml'; |
|
638 | - } |
|
639 | - |
|
640 | - $parser = new InfoParser(\OC::$server->getMemCacheFactory()->createLocal('core.appinfo')); |
|
641 | - $data = $parser->parse($file); |
|
642 | - |
|
643 | - if (is_array($data)) { |
|
644 | - $data = OC_App::parseAppInfo($data, $lang); |
|
645 | - } |
|
646 | - if(isset($data['ocsid'])) { |
|
647 | - $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
|
648 | - if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
649 | - $data['ocsid'] = $storedId; |
|
650 | - } |
|
651 | - } |
|
652 | - |
|
653 | - if ($lang === null) { |
|
654 | - self::$appInfo[$appId] = $data; |
|
655 | - } |
|
656 | - |
|
657 | - return $data; |
|
658 | - } |
|
659 | - |
|
660 | - /** |
|
661 | - * Returns the navigation |
|
662 | - * |
|
663 | - * @return array |
|
664 | - * |
|
665 | - * This function returns an array containing all entries added. The |
|
666 | - * entries are sorted by the key 'order' ascending. Additional to the keys |
|
667 | - * given for each app the following keys exist: |
|
668 | - * - active: boolean, signals if the user is on this navigation entry |
|
669 | - */ |
|
670 | - public static function getNavigation() { |
|
671 | - $entries = OC::$server->getNavigationManager()->getAll(); |
|
672 | - return self::proceedNavigation($entries); |
|
673 | - } |
|
674 | - |
|
675 | - /** |
|
676 | - * Returns the Settings Navigation |
|
677 | - * |
|
678 | - * @return string[] |
|
679 | - * |
|
680 | - * This function returns an array containing all settings pages added. The |
|
681 | - * entries are sorted by the key 'order' ascending. |
|
682 | - */ |
|
683 | - public static function getSettingsNavigation() { |
|
684 | - $entries = OC::$server->getNavigationManager()->getAll('settings'); |
|
685 | - return self::proceedNavigation($entries); |
|
686 | - } |
|
687 | - |
|
688 | - /** |
|
689 | - * get the id of loaded app |
|
690 | - * |
|
691 | - * @return string |
|
692 | - */ |
|
693 | - public static function getCurrentApp() { |
|
694 | - $request = \OC::$server->getRequest(); |
|
695 | - $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); |
|
696 | - $topFolder = substr($script, 0, strpos($script, '/') ?: 0); |
|
697 | - if (empty($topFolder)) { |
|
698 | - $path_info = $request->getPathInfo(); |
|
699 | - if ($path_info) { |
|
700 | - $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); |
|
701 | - } |
|
702 | - } |
|
703 | - if ($topFolder == 'apps') { |
|
704 | - $length = strlen($topFolder); |
|
705 | - return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1); |
|
706 | - } else { |
|
707 | - return $topFolder; |
|
708 | - } |
|
709 | - } |
|
710 | - |
|
711 | - /** |
|
712 | - * @param string $type |
|
713 | - * @return array |
|
714 | - */ |
|
715 | - public static function getForms($type) { |
|
716 | - $forms = array(); |
|
717 | - switch ($type) { |
|
718 | - case 'admin': |
|
719 | - $source = self::$adminForms; |
|
720 | - break; |
|
721 | - case 'personal': |
|
722 | - $source = self::$personalForms; |
|
723 | - break; |
|
724 | - default: |
|
725 | - return array(); |
|
726 | - } |
|
727 | - foreach ($source as $form) { |
|
728 | - $forms[] = include $form; |
|
729 | - } |
|
730 | - return $forms; |
|
731 | - } |
|
732 | - |
|
733 | - /** |
|
734 | - * register an admin form to be shown |
|
735 | - * |
|
736 | - * @param string $app |
|
737 | - * @param string $page |
|
738 | - */ |
|
739 | - public static function registerAdmin($app, $page) { |
|
740 | - self::$adminForms[] = $app . '/' . $page . '.php'; |
|
741 | - } |
|
742 | - |
|
743 | - /** |
|
744 | - * register a personal form to be shown |
|
745 | - * @param string $app |
|
746 | - * @param string $page |
|
747 | - */ |
|
748 | - public static function registerPersonal($app, $page) { |
|
749 | - self::$personalForms[] = $app . '/' . $page . '.php'; |
|
750 | - } |
|
751 | - |
|
752 | - /** |
|
753 | - * @param array $entry |
|
754 | - */ |
|
755 | - public static function registerLogIn(array $entry) { |
|
756 | - self::$altLogin[] = $entry; |
|
757 | - } |
|
758 | - |
|
759 | - /** |
|
760 | - * @return array |
|
761 | - */ |
|
762 | - public static function getAlternativeLogIns() { |
|
763 | - return self::$altLogin; |
|
764 | - } |
|
765 | - |
|
766 | - /** |
|
767 | - * get a list of all apps in the apps folder |
|
768 | - * |
|
769 | - * @return array an array of app names (string IDs) |
|
770 | - * @todo: change the name of this method to getInstalledApps, which is more accurate |
|
771 | - */ |
|
772 | - public static function getAllApps() { |
|
773 | - |
|
774 | - $apps = array(); |
|
775 | - |
|
776 | - foreach (OC::$APPSROOTS as $apps_dir) { |
|
777 | - if (!is_readable($apps_dir['path'])) { |
|
778 | - \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
779 | - continue; |
|
780 | - } |
|
781 | - $dh = opendir($apps_dir['path']); |
|
782 | - |
|
783 | - if (is_resource($dh)) { |
|
784 | - while (($file = readdir($dh)) !== false) { |
|
785 | - |
|
786 | - if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
787 | - |
|
788 | - $apps[] = $file; |
|
789 | - } |
|
790 | - } |
|
791 | - } |
|
792 | - } |
|
793 | - |
|
794 | - $apps = array_unique($apps); |
|
795 | - |
|
796 | - return $apps; |
|
797 | - } |
|
798 | - |
|
799 | - /** |
|
800 | - * List all apps, this is used in apps.php |
|
801 | - * |
|
802 | - * @return array |
|
803 | - */ |
|
804 | - public function listAllApps() { |
|
805 | - $installedApps = OC_App::getAllApps(); |
|
806 | - |
|
807 | - $appManager = \OC::$server->getAppManager(); |
|
808 | - //we don't want to show configuration for these |
|
809 | - $blacklist = $appManager->getAlwaysEnabledApps(); |
|
810 | - $appList = array(); |
|
811 | - $langCode = \OC::$server->getL10N('core')->getLanguageCode(); |
|
812 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
813 | - |
|
814 | - foreach ($installedApps as $app) { |
|
815 | - if (array_search($app, $blacklist) === false) { |
|
816 | - |
|
817 | - $info = OC_App::getAppInfo($app, false, $langCode); |
|
818 | - if (!is_array($info)) { |
|
819 | - \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
820 | - continue; |
|
821 | - } |
|
822 | - |
|
823 | - if (!isset($info['name'])) { |
|
824 | - \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
825 | - continue; |
|
826 | - } |
|
827 | - |
|
828 | - $enabled = \OC::$server->getConfig()->getAppValue($app, 'enabled', 'no'); |
|
829 | - $info['groups'] = null; |
|
830 | - if ($enabled === 'yes') { |
|
831 | - $active = true; |
|
832 | - } else if ($enabled === 'no') { |
|
833 | - $active = false; |
|
834 | - } else { |
|
835 | - $active = true; |
|
836 | - $info['groups'] = $enabled; |
|
837 | - } |
|
838 | - |
|
839 | - $info['active'] = $active; |
|
840 | - |
|
841 | - if ($appManager->isShipped($app)) { |
|
842 | - $info['internal'] = true; |
|
843 | - $info['level'] = self::officialApp; |
|
844 | - $info['removable'] = false; |
|
845 | - } else { |
|
846 | - $info['internal'] = false; |
|
847 | - $info['removable'] = true; |
|
848 | - } |
|
849 | - |
|
850 | - $appPath = self::getAppPath($app); |
|
851 | - if($appPath !== false) { |
|
852 | - $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
853 | - if (file_exists($appIcon)) { |
|
854 | - $info['preview'] = $urlGenerator->imagePath($app, $app . '.svg'); |
|
855 | - $info['previewAsIcon'] = true; |
|
856 | - } else { |
|
857 | - $appIcon = $appPath . '/img/app.svg'; |
|
858 | - if (file_exists($appIcon)) { |
|
859 | - $info['preview'] = $urlGenerator->imagePath($app, 'app.svg'); |
|
860 | - $info['previewAsIcon'] = true; |
|
861 | - } |
|
862 | - } |
|
863 | - } |
|
864 | - // fix documentation |
|
865 | - if (isset($info['documentation']) && is_array($info['documentation'])) { |
|
866 | - foreach ($info['documentation'] as $key => $url) { |
|
867 | - // If it is not an absolute URL we assume it is a key |
|
868 | - // i.e. admin-ldap will get converted to go.php?to=admin-ldap |
|
869 | - if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) { |
|
870 | - $url = $urlGenerator->linkToDocs($url); |
|
871 | - } |
|
872 | - |
|
873 | - $info['documentation'][$key] = $url; |
|
874 | - } |
|
875 | - } |
|
876 | - |
|
877 | - $info['version'] = OC_App::getAppVersion($app); |
|
878 | - $appList[] = $info; |
|
879 | - } |
|
880 | - } |
|
881 | - |
|
882 | - return $appList; |
|
883 | - } |
|
884 | - |
|
885 | - public static function shouldUpgrade($app) { |
|
886 | - $versions = self::getAppVersions(); |
|
887 | - $currentVersion = OC_App::getAppVersion($app); |
|
888 | - if ($currentVersion && isset($versions[$app])) { |
|
889 | - $installedVersion = $versions[$app]; |
|
890 | - if (!version_compare($currentVersion, $installedVersion, '=')) { |
|
891 | - return true; |
|
892 | - } |
|
893 | - } |
|
894 | - return false; |
|
895 | - } |
|
896 | - |
|
897 | - /** |
|
898 | - * Adjust the number of version parts of $version1 to match |
|
899 | - * the number of version parts of $version2. |
|
900 | - * |
|
901 | - * @param string $version1 version to adjust |
|
902 | - * @param string $version2 version to take the number of parts from |
|
903 | - * @return string shortened $version1 |
|
904 | - */ |
|
905 | - private static function adjustVersionParts($version1, $version2) { |
|
906 | - $version1 = explode('.', $version1); |
|
907 | - $version2 = explode('.', $version2); |
|
908 | - // reduce $version1 to match the number of parts in $version2 |
|
909 | - while (count($version1) > count($version2)) { |
|
910 | - array_pop($version1); |
|
911 | - } |
|
912 | - // if $version1 does not have enough parts, add some |
|
913 | - while (count($version1) < count($version2)) { |
|
914 | - $version1[] = '0'; |
|
915 | - } |
|
916 | - return implode('.', $version1); |
|
917 | - } |
|
918 | - |
|
919 | - /** |
|
920 | - * Check whether the current ownCloud version matches the given |
|
921 | - * application's version requirements. |
|
922 | - * |
|
923 | - * The comparison is made based on the number of parts that the |
|
924 | - * app info version has. For example for ownCloud 6.0.3 if the |
|
925 | - * app info version is expecting version 6.0, the comparison is |
|
926 | - * made on the first two parts of the ownCloud version. |
|
927 | - * This means that it's possible to specify "requiremin" => 6 |
|
928 | - * and "requiremax" => 6 and it will still match ownCloud 6.0.3. |
|
929 | - * |
|
930 | - * @param string $ocVersion ownCloud version to check against |
|
931 | - * @param array $appInfo app info (from xml) |
|
932 | - * |
|
933 | - * @return boolean true if compatible, otherwise false |
|
934 | - */ |
|
935 | - public static function isAppCompatible($ocVersion, $appInfo) { |
|
936 | - $requireMin = ''; |
|
937 | - $requireMax = ''; |
|
938 | - if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) { |
|
939 | - $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version']; |
|
940 | - } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
941 | - $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version']; |
|
942 | - } else if (isset($appInfo['requiremin'])) { |
|
943 | - $requireMin = $appInfo['requiremin']; |
|
944 | - } else if (isset($appInfo['require'])) { |
|
945 | - $requireMin = $appInfo['require']; |
|
946 | - } |
|
947 | - |
|
948 | - if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) { |
|
949 | - $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version']; |
|
950 | - } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
951 | - $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version']; |
|
952 | - } else if (isset($appInfo['requiremax'])) { |
|
953 | - $requireMax = $appInfo['requiremax']; |
|
954 | - } |
|
955 | - |
|
956 | - if (is_array($ocVersion)) { |
|
957 | - $ocVersion = implode('.', $ocVersion); |
|
958 | - } |
|
959 | - |
|
960 | - if (!empty($requireMin) |
|
961 | - && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<') |
|
962 | - ) { |
|
963 | - |
|
964 | - return false; |
|
965 | - } |
|
966 | - |
|
967 | - if (!empty($requireMax) |
|
968 | - && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>') |
|
969 | - ) { |
|
970 | - return false; |
|
971 | - } |
|
972 | - |
|
973 | - return true; |
|
974 | - } |
|
975 | - |
|
976 | - /** |
|
977 | - * get the installed version of all apps |
|
978 | - */ |
|
979 | - public static function getAppVersions() { |
|
980 | - static $versions; |
|
981 | - |
|
982 | - if(!$versions) { |
|
983 | - $appConfig = \OC::$server->getAppConfig(); |
|
984 | - $versions = $appConfig->getValues(false, 'installed_version'); |
|
985 | - } |
|
986 | - return $versions; |
|
987 | - } |
|
988 | - |
|
989 | - /** |
|
990 | - * @param string $app |
|
991 | - * @param \OCP\IConfig $config |
|
992 | - * @param \OCP\IL10N $l |
|
993 | - * @return bool |
|
994 | - * |
|
995 | - * @throws Exception if app is not compatible with this version of ownCloud |
|
996 | - * @throws Exception if no app-name was specified |
|
997 | - */ |
|
998 | - public function installApp($app, |
|
999 | - \OCP\IConfig $config, |
|
1000 | - \OCP\IL10N $l) { |
|
1001 | - if ($app !== false) { |
|
1002 | - // check if the app is compatible with this version of ownCloud |
|
1003 | - $info = self::getAppInfo($app); |
|
1004 | - if(!is_array($info)) { |
|
1005 | - throw new \Exception( |
|
1006 | - $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
1007 | - [$info['name']] |
|
1008 | - ) |
|
1009 | - ); |
|
1010 | - } |
|
1011 | - |
|
1012 | - $version = \OCP\Util::getVersion(); |
|
1013 | - if (!self::isAppCompatible($version, $info)) { |
|
1014 | - throw new \Exception( |
|
1015 | - $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
1016 | - array($info['name']) |
|
1017 | - ) |
|
1018 | - ); |
|
1019 | - } |
|
1020 | - |
|
1021 | - // check for required dependencies |
|
1022 | - self::checkAppDependencies($config, $l, $info); |
|
1023 | - |
|
1024 | - $config->setAppValue($app, 'enabled', 'yes'); |
|
1025 | - if (isset($appData['id'])) { |
|
1026 | - $config->setAppValue($app, 'ocsid', $appData['id']); |
|
1027 | - } |
|
1028 | - |
|
1029 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
1030 | - $appPath = self::getAppPath($app); |
|
1031 | - self::registerAutoloading($app, $appPath); |
|
1032 | - } |
|
1033 | - |
|
1034 | - \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
|
1035 | - } else { |
|
1036 | - if(empty($appName) ) { |
|
1037 | - throw new \Exception($l->t("No app name specified")); |
|
1038 | - } else { |
|
1039 | - throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
|
1040 | - } |
|
1041 | - } |
|
1042 | - |
|
1043 | - return $app; |
|
1044 | - } |
|
1045 | - |
|
1046 | - /** |
|
1047 | - * update the database for the app and call the update script |
|
1048 | - * |
|
1049 | - * @param string $appId |
|
1050 | - * @return bool |
|
1051 | - */ |
|
1052 | - public static function updateApp($appId) { |
|
1053 | - $appPath = self::getAppPath($appId); |
|
1054 | - if($appPath === false) { |
|
1055 | - return false; |
|
1056 | - } |
|
1057 | - self::registerAutoloading($appId, $appPath); |
|
1058 | - |
|
1059 | - $appData = self::getAppInfo($appId); |
|
1060 | - self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
|
1061 | - |
|
1062 | - if (file_exists($appPath . '/appinfo/database.xml')) { |
|
1063 | - OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
1064 | - } else { |
|
1065 | - $ms = new MigrationService($appId, \OC::$server->getDatabaseConnection()); |
|
1066 | - $ms->migrate(); |
|
1067 | - } |
|
1068 | - |
|
1069 | - self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
|
1070 | - self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
|
1071 | - unset(self::$appVersion[$appId]); |
|
1072 | - |
|
1073 | - // run upgrade code |
|
1074 | - if (file_exists($appPath . '/appinfo/update.php')) { |
|
1075 | - self::loadApp($appId); |
|
1076 | - include $appPath . '/appinfo/update.php'; |
|
1077 | - } |
|
1078 | - self::setupBackgroundJobs($appData['background-jobs']); |
|
1079 | - |
|
1080 | - //set remote/public handlers |
|
1081 | - if (array_key_exists('ocsid', $appData)) { |
|
1082 | - \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
|
1083 | - } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
1084 | - \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
|
1085 | - } |
|
1086 | - foreach ($appData['remote'] as $name => $path) { |
|
1087 | - \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
1088 | - } |
|
1089 | - foreach ($appData['public'] as $name => $path) { |
|
1090 | - \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
1091 | - } |
|
1092 | - |
|
1093 | - self::setAppTypes($appId); |
|
1094 | - |
|
1095 | - $version = \OC_App::getAppVersion($appId); |
|
1096 | - \OC::$server->getConfig()->setAppValue($appId, 'installed_version', $version); |
|
1097 | - |
|
1098 | - \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( |
|
1099 | - ManagerEvent::EVENT_APP_UPDATE, $appId |
|
1100 | - )); |
|
1101 | - |
|
1102 | - return true; |
|
1103 | - } |
|
1104 | - |
|
1105 | - /** |
|
1106 | - * @param string $appId |
|
1107 | - * @param string[] $steps |
|
1108 | - * @throws \OC\NeedsUpdateException |
|
1109 | - */ |
|
1110 | - public static function executeRepairSteps($appId, array $steps) { |
|
1111 | - if (empty($steps)) { |
|
1112 | - return; |
|
1113 | - } |
|
1114 | - // load the app |
|
1115 | - self::loadApp($appId); |
|
1116 | - |
|
1117 | - $dispatcher = OC::$server->getEventDispatcher(); |
|
1118 | - |
|
1119 | - // load the steps |
|
1120 | - $r = new Repair([], $dispatcher); |
|
1121 | - foreach ($steps as $step) { |
|
1122 | - try { |
|
1123 | - $r->addStep($step); |
|
1124 | - } catch (Exception $ex) { |
|
1125 | - $r->emit('\OC\Repair', 'error', [$ex->getMessage()]); |
|
1126 | - \OC::$server->getLogger()->logException($ex); |
|
1127 | - } |
|
1128 | - } |
|
1129 | - // run the steps |
|
1130 | - $r->run(); |
|
1131 | - } |
|
1132 | - |
|
1133 | - public static function setupBackgroundJobs(array $jobs) { |
|
1134 | - $queue = \OC::$server->getJobList(); |
|
1135 | - foreach ($jobs as $job) { |
|
1136 | - $queue->add($job); |
|
1137 | - } |
|
1138 | - } |
|
1139 | - |
|
1140 | - /** |
|
1141 | - * @param string $appId |
|
1142 | - * @param string[] $steps |
|
1143 | - */ |
|
1144 | - private static function setupLiveMigrations($appId, array $steps) { |
|
1145 | - $queue = \OC::$server->getJobList(); |
|
1146 | - foreach ($steps as $step) { |
|
1147 | - $queue->add('OC\Migration\BackgroundRepair', [ |
|
1148 | - 'app' => $appId, |
|
1149 | - 'step' => $step]); |
|
1150 | - } |
|
1151 | - } |
|
1152 | - |
|
1153 | - /** |
|
1154 | - * @param string $appId |
|
1155 | - * @return \OC\Files\View|false |
|
1156 | - */ |
|
1157 | - public static function getStorage($appId) { |
|
1158 | - if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check |
|
1159 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
1160 | - $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
1161 | - if (!$view->file_exists($appId)) { |
|
1162 | - $view->mkdir($appId); |
|
1163 | - } |
|
1164 | - return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
1165 | - } else { |
|
1166 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
1167 | - return false; |
|
1168 | - } |
|
1169 | - } else { |
|
1170 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
1171 | - return false; |
|
1172 | - } |
|
1173 | - } |
|
1174 | - |
|
1175 | - protected static function findBestL10NOption($options, $lang) { |
|
1176 | - $fallback = $similarLangFallback = $englishFallback = false; |
|
1177 | - |
|
1178 | - $lang = strtolower($lang); |
|
1179 | - $similarLang = $lang; |
|
1180 | - if (strpos($similarLang, '_')) { |
|
1181 | - // For "de_DE" we want to find "de" and the other way around |
|
1182 | - $similarLang = substr($lang, 0, strpos($lang, '_')); |
|
1183 | - } |
|
1184 | - |
|
1185 | - foreach ($options as $option) { |
|
1186 | - if (is_array($option)) { |
|
1187 | - if ($fallback === false) { |
|
1188 | - $fallback = $option['@value']; |
|
1189 | - } |
|
1190 | - |
|
1191 | - if (!isset($option['@attributes']['lang'])) { |
|
1192 | - continue; |
|
1193 | - } |
|
1194 | - |
|
1195 | - $attributeLang = strtolower($option['@attributes']['lang']); |
|
1196 | - if ($attributeLang === $lang) { |
|
1197 | - return $option['@value']; |
|
1198 | - } |
|
1199 | - |
|
1200 | - if ($attributeLang === $similarLang) { |
|
1201 | - $similarLangFallback = $option['@value']; |
|
1202 | - } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
1203 | - if ($similarLangFallback === false) { |
|
1204 | - $similarLangFallback = $option['@value']; |
|
1205 | - } |
|
1206 | - } |
|
1207 | - } else { |
|
1208 | - $englishFallback = $option; |
|
1209 | - } |
|
1210 | - } |
|
1211 | - |
|
1212 | - if ($similarLangFallback !== false) { |
|
1213 | - return $similarLangFallback; |
|
1214 | - } else if ($englishFallback !== false) { |
|
1215 | - return $englishFallback; |
|
1216 | - } |
|
1217 | - return (string) $fallback; |
|
1218 | - } |
|
1219 | - |
|
1220 | - /** |
|
1221 | - * parses the app data array and enhanced the 'description' value |
|
1222 | - * |
|
1223 | - * @param array $data the app data |
|
1224 | - * @param string $lang |
|
1225 | - * @return array improved app data |
|
1226 | - */ |
|
1227 | - public static function parseAppInfo(array $data, $lang = null) { |
|
1228 | - |
|
1229 | - if ($lang && isset($data['name']) && is_array($data['name'])) { |
|
1230 | - $data['name'] = self::findBestL10NOption($data['name'], $lang); |
|
1231 | - } |
|
1232 | - if ($lang && isset($data['summary']) && is_array($data['summary'])) { |
|
1233 | - $data['summary'] = self::findBestL10NOption($data['summary'], $lang); |
|
1234 | - } |
|
1235 | - if ($lang && isset($data['description']) && is_array($data['description'])) { |
|
1236 | - $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
|
1237 | - } else if (isset($data['description']) && is_string($data['description'])) { |
|
1238 | - $data['description'] = trim($data['description']); |
|
1239 | - } else { |
|
1240 | - $data['description'] = ''; |
|
1241 | - } |
|
1242 | - |
|
1243 | - return $data; |
|
1244 | - } |
|
1245 | - |
|
1246 | - /** |
|
1247 | - * @param \OCP\IConfig $config |
|
1248 | - * @param \OCP\IL10N $l |
|
1249 | - * @param array $info |
|
1250 | - * @throws \Exception |
|
1251 | - */ |
|
1252 | - public static function checkAppDependencies($config, $l, $info) { |
|
1253 | - $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); |
|
1254 | - $missing = $dependencyAnalyzer->analyze($info); |
|
1255 | - if (!empty($missing)) { |
|
1256 | - $missingMsg = implode(PHP_EOL, $missing); |
|
1257 | - throw new \Exception( |
|
1258 | - $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s', |
|
1259 | - [$info['name'], $missingMsg] |
|
1260 | - ) |
|
1261 | - ); |
|
1262 | - } |
|
1263 | - } |
|
66 | + static private $appVersion = []; |
|
67 | + static private $adminForms = array(); |
|
68 | + static private $personalForms = array(); |
|
69 | + static private $appInfo = array(); |
|
70 | + static private $appTypes = array(); |
|
71 | + static private $loadedApps = array(); |
|
72 | + static private $altLogin = array(); |
|
73 | + static private $alreadyRegistered = []; |
|
74 | + const officialApp = 200; |
|
75 | + |
|
76 | + /** |
|
77 | + * clean the appId |
|
78 | + * |
|
79 | + * @param string|boolean $app AppId that needs to be cleaned |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + public static function cleanAppId($app) { |
|
83 | + return str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Check if an app is loaded |
|
88 | + * |
|
89 | + * @param string $app |
|
90 | + * @return bool |
|
91 | + */ |
|
92 | + public static function isAppLoaded($app) { |
|
93 | + return in_array($app, self::$loadedApps, true); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * loads all apps |
|
98 | + * |
|
99 | + * @param string[] | string | null $types |
|
100 | + * @return bool |
|
101 | + * |
|
102 | + * This function walks through the ownCloud directory and loads all apps |
|
103 | + * it can find. A directory contains an app if the file /appinfo/info.xml |
|
104 | + * exists. |
|
105 | + * |
|
106 | + * if $types is set, only apps of those types will be loaded |
|
107 | + */ |
|
108 | + public static function loadApps($types = null) { |
|
109 | + if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
110 | + return false; |
|
111 | + } |
|
112 | + // Load the enabled apps here |
|
113 | + $apps = self::getEnabledApps(); |
|
114 | + |
|
115 | + // Add each apps' folder as allowed class path |
|
116 | + foreach($apps as $app) { |
|
117 | + $path = self::getAppPath($app); |
|
118 | + if($path !== false) { |
|
119 | + self::registerAutoloading($app, $path); |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + // prevent app.php from printing output |
|
124 | + ob_start(); |
|
125 | + foreach ($apps as $app) { |
|
126 | + if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) { |
|
127 | + self::loadApp($app); |
|
128 | + } |
|
129 | + } |
|
130 | + ob_end_clean(); |
|
131 | + |
|
132 | + return true; |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * load a single app |
|
137 | + * |
|
138 | + * @param string $app |
|
139 | + */ |
|
140 | + public static function loadApp($app) { |
|
141 | + self::$loadedApps[] = $app; |
|
142 | + $appPath = self::getAppPath($app); |
|
143 | + if($appPath === false) { |
|
144 | + return; |
|
145 | + } |
|
146 | + |
|
147 | + // in case someone calls loadApp() directly |
|
148 | + self::registerAutoloading($app, $appPath); |
|
149 | + |
|
150 | + if (is_file($appPath . '/appinfo/app.php')) { |
|
151 | + \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
152 | + self::requireAppFile($app); |
|
153 | + if (self::isType($app, array('authentication'))) { |
|
154 | + // since authentication apps affect the "is app enabled for group" check, |
|
155 | + // the enabled apps cache needs to be cleared to make sure that the |
|
156 | + // next time getEnableApps() is called it will also include apps that were |
|
157 | + // enabled for groups |
|
158 | + self::$enabledAppsCache = array(); |
|
159 | + } |
|
160 | + \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
161 | + } |
|
162 | + |
|
163 | + $info = self::getAppInfo($app); |
|
164 | + if (!empty($info['activity']['filters'])) { |
|
165 | + foreach ($info['activity']['filters'] as $filter) { |
|
166 | + \OC::$server->getActivityManager()->registerFilter($filter); |
|
167 | + } |
|
168 | + } |
|
169 | + if (!empty($info['activity']['settings'])) { |
|
170 | + foreach ($info['activity']['settings'] as $setting) { |
|
171 | + \OC::$server->getActivityManager()->registerSetting($setting); |
|
172 | + } |
|
173 | + } |
|
174 | + if (!empty($info['activity']['providers'])) { |
|
175 | + foreach ($info['activity']['providers'] as $provider) { |
|
176 | + \OC::$server->getActivityManager()->registerProvider($provider); |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + if (!empty($info['settings']['admin'])) { |
|
181 | + foreach ($info['settings']['admin'] as $setting) { |
|
182 | + \OC::$server->getSettingsManager()->registerSetting('admin', $setting); |
|
183 | + } |
|
184 | + } |
|
185 | + if (!empty($info['settings']['admin-section'])) { |
|
186 | + foreach ($info['settings']['admin-section'] as $section) { |
|
187 | + \OC::$server->getSettingsManager()->registerSection('admin', $section); |
|
188 | + } |
|
189 | + } |
|
190 | + if (!empty($info['settings']['personal'])) { |
|
191 | + foreach ($info['settings']['personal'] as $setting) { |
|
192 | + \OC::$server->getSettingsManager()->registerSetting('personal', $setting); |
|
193 | + } |
|
194 | + } |
|
195 | + if (!empty($info['settings']['personal-section'])) { |
|
196 | + foreach ($info['settings']['personal-section'] as $section) { |
|
197 | + \OC::$server->getSettingsManager()->registerSection('personal', $section); |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + if (!empty($info['collaboration']['plugins'])) { |
|
202 | + // deal with one or many plugin entries |
|
203 | + $plugins = isset($info['collaboration']['plugins']['plugin']['@value']) ? |
|
204 | + [$info['collaboration']['plugins']['plugin']] : $info['collaboration']['plugins']['plugin']; |
|
205 | + foreach ($plugins as $plugin) { |
|
206 | + if($plugin['@attributes']['type'] === 'collaborator-search') { |
|
207 | + $pluginInfo = [ |
|
208 | + 'shareType' => $plugin['@attributes']['share-type'], |
|
209 | + 'class' => $plugin['@value'], |
|
210 | + ]; |
|
211 | + \OC::$server->getCollaboratorSearch()->registerPlugin($pluginInfo); |
|
212 | + } else if ($plugin['@attributes']['type'] === 'autocomplete-sort') { |
|
213 | + \OC::$server->getAutoCompleteManager()->registerSorter($plugin['@value']); |
|
214 | + } |
|
215 | + } |
|
216 | + } |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * @internal |
|
221 | + * @param string $app |
|
222 | + * @param string $path |
|
223 | + */ |
|
224 | + public static function registerAutoloading($app, $path) { |
|
225 | + $key = $app . '-' . $path; |
|
226 | + if(isset(self::$alreadyRegistered[$key])) { |
|
227 | + return; |
|
228 | + } |
|
229 | + |
|
230 | + self::$alreadyRegistered[$key] = true; |
|
231 | + |
|
232 | + // Register on PSR-4 composer autoloader |
|
233 | + $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
|
234 | + \OC::$server->registerNamespace($app, $appNamespace); |
|
235 | + |
|
236 | + if (file_exists($path . '/composer/autoload.php')) { |
|
237 | + require_once $path . '/composer/autoload.php'; |
|
238 | + } else { |
|
239 | + \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
240 | + // Register on legacy autoloader |
|
241 | + \OC::$loader->addValidRoot($path); |
|
242 | + } |
|
243 | + |
|
244 | + // Register Test namespace only when testing |
|
245 | + if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
|
246 | + \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
247 | + } |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Load app.php from the given app |
|
252 | + * |
|
253 | + * @param string $app app name |
|
254 | + */ |
|
255 | + private static function requireAppFile($app) { |
|
256 | + try { |
|
257 | + // encapsulated here to avoid variable scope conflicts |
|
258 | + require_once $app . '/appinfo/app.php'; |
|
259 | + } catch (Error $ex) { |
|
260 | + \OC::$server->getLogger()->logException($ex); |
|
261 | + if (!\OC::$server->getAppManager()->isShipped($app)) { |
|
262 | + // Only disable apps which are not shipped |
|
263 | + self::disable($app); |
|
264 | + } |
|
265 | + } |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * check if an app is of a specific type |
|
270 | + * |
|
271 | + * @param string $app |
|
272 | + * @param string|array $types |
|
273 | + * @return bool |
|
274 | + */ |
|
275 | + public static function isType($app, $types) { |
|
276 | + if (is_string($types)) { |
|
277 | + $types = array($types); |
|
278 | + } |
|
279 | + $appTypes = self::getAppTypes($app); |
|
280 | + foreach ($types as $type) { |
|
281 | + if (array_search($type, $appTypes) !== false) { |
|
282 | + return true; |
|
283 | + } |
|
284 | + } |
|
285 | + return false; |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * get the types of an app |
|
290 | + * |
|
291 | + * @param string $app |
|
292 | + * @return array |
|
293 | + */ |
|
294 | + private static function getAppTypes($app) { |
|
295 | + //load the cache |
|
296 | + if (count(self::$appTypes) == 0) { |
|
297 | + self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types'); |
|
298 | + } |
|
299 | + |
|
300 | + if (isset(self::$appTypes[$app])) { |
|
301 | + return explode(',', self::$appTypes[$app]); |
|
302 | + } else { |
|
303 | + return array(); |
|
304 | + } |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * read app types from info.xml and cache them in the database |
|
309 | + */ |
|
310 | + public static function setAppTypes($app) { |
|
311 | + $appData = self::getAppInfo($app); |
|
312 | + if(!is_array($appData)) { |
|
313 | + return; |
|
314 | + } |
|
315 | + |
|
316 | + if (isset($appData['types'])) { |
|
317 | + $appTypes = implode(',', $appData['types']); |
|
318 | + } else { |
|
319 | + $appTypes = ''; |
|
320 | + $appData['types'] = []; |
|
321 | + } |
|
322 | + |
|
323 | + \OC::$server->getConfig()->setAppValue($app, 'types', $appTypes); |
|
324 | + |
|
325 | + if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) { |
|
326 | + $enabled = \OC::$server->getConfig()->getAppValue($app, 'enabled', 'yes'); |
|
327 | + if ($enabled !== 'yes' && $enabled !== 'no') { |
|
328 | + \OC::$server->getConfig()->setAppValue($app, 'enabled', 'yes'); |
|
329 | + } |
|
330 | + } |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * get all enabled apps |
|
335 | + */ |
|
336 | + protected static $enabledAppsCache = array(); |
|
337 | + |
|
338 | + /** |
|
339 | + * Returns apps enabled for the current user. |
|
340 | + * |
|
341 | + * @param bool $forceRefresh whether to refresh the cache |
|
342 | + * @param bool $all whether to return apps for all users, not only the |
|
343 | + * currently logged in one |
|
344 | + * @return string[] |
|
345 | + */ |
|
346 | + public static function getEnabledApps($forceRefresh = false, $all = false) { |
|
347 | + if (!\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
348 | + return array(); |
|
349 | + } |
|
350 | + // in incognito mode or when logged out, $user will be false, |
|
351 | + // which is also the case during an upgrade |
|
352 | + $appManager = \OC::$server->getAppManager(); |
|
353 | + if ($all) { |
|
354 | + $user = null; |
|
355 | + } else { |
|
356 | + $user = \OC::$server->getUserSession()->getUser(); |
|
357 | + } |
|
358 | + |
|
359 | + if (is_null($user)) { |
|
360 | + $apps = $appManager->getInstalledApps(); |
|
361 | + } else { |
|
362 | + $apps = $appManager->getEnabledAppsForUser($user); |
|
363 | + } |
|
364 | + $apps = array_filter($apps, function ($app) { |
|
365 | + return $app !== 'files';//we add this manually |
|
366 | + }); |
|
367 | + sort($apps); |
|
368 | + array_unshift($apps, 'files'); |
|
369 | + return $apps; |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * checks whether or not an app is enabled |
|
374 | + * |
|
375 | + * @param string $app app |
|
376 | + * @return bool |
|
377 | + * @deprecated 13.0.0 use \OC::$server->getAppManager()->isEnabledForUser($appId) |
|
378 | + * |
|
379 | + * This function checks whether or not an app is enabled. |
|
380 | + */ |
|
381 | + public static function isEnabled($app) { |
|
382 | + return \OC::$server->getAppManager()->isEnabledForUser($app); |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * enables an app |
|
387 | + * |
|
388 | + * @param string $appId |
|
389 | + * @param array $groups (optional) when set, only these groups will have access to the app |
|
390 | + * @throws \Exception |
|
391 | + * @return void |
|
392 | + * |
|
393 | + * This function set an app as enabled in appconfig. |
|
394 | + */ |
|
395 | + public function enable($appId, |
|
396 | + $groups = null) { |
|
397 | + self::$enabledAppsCache = []; // flush |
|
398 | + |
|
399 | + // Check if app is already downloaded |
|
400 | + $installer = \OC::$server->query(Installer::class); |
|
401 | + $isDownloaded = $installer->isDownloaded($appId); |
|
402 | + |
|
403 | + if(!$isDownloaded) { |
|
404 | + $installer->downloadApp($appId); |
|
405 | + } |
|
406 | + |
|
407 | + $installer->installApp($appId); |
|
408 | + |
|
409 | + $appManager = \OC::$server->getAppManager(); |
|
410 | + if (!is_null($groups)) { |
|
411 | + $groupManager = \OC::$server->getGroupManager(); |
|
412 | + $groupsList = []; |
|
413 | + foreach ($groups as $group) { |
|
414 | + $groupItem = $groupManager->get($group); |
|
415 | + if ($groupItem instanceof \OCP\IGroup) { |
|
416 | + $groupsList[] = $groupManager->get($group); |
|
417 | + } |
|
418 | + } |
|
419 | + $appManager->enableAppForGroups($appId, $groupsList); |
|
420 | + } else { |
|
421 | + $appManager->enableApp($appId); |
|
422 | + } |
|
423 | + } |
|
424 | + |
|
425 | + /** |
|
426 | + * @param string $app |
|
427 | + * @return bool |
|
428 | + */ |
|
429 | + public static function removeApp($app) { |
|
430 | + if (\OC::$server->getAppManager()->isShipped($app)) { |
|
431 | + return false; |
|
432 | + } |
|
433 | + |
|
434 | + $installer = \OC::$server->query(Installer::class); |
|
435 | + return $installer->removeApp($app); |
|
436 | + } |
|
437 | + |
|
438 | + /** |
|
439 | + * This function set an app as disabled in appconfig. |
|
440 | + * |
|
441 | + * @param string $app app |
|
442 | + * @throws Exception |
|
443 | + */ |
|
444 | + public static function disable($app) { |
|
445 | + // flush |
|
446 | + self::$enabledAppsCache = array(); |
|
447 | + |
|
448 | + // run uninstall steps |
|
449 | + $appData = OC_App::getAppInfo($app); |
|
450 | + if (!is_null($appData)) { |
|
451 | + OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']); |
|
452 | + } |
|
453 | + |
|
454 | + // emit disable hook - needed anymore ? |
|
455 | + \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app)); |
|
456 | + |
|
457 | + // finally disable it |
|
458 | + $appManager = \OC::$server->getAppManager(); |
|
459 | + $appManager->disableApp($app); |
|
460 | + } |
|
461 | + |
|
462 | + // This is private as well. It simply works, so don't ask for more details |
|
463 | + private static function proceedNavigation($list) { |
|
464 | + usort($list, function($a, $b) { |
|
465 | + if (isset($a['order']) && isset($b['order'])) { |
|
466 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
467 | + } else if (isset($a['order']) || isset($b['order'])) { |
|
468 | + return isset($a['order']) ? -1 : 1; |
|
469 | + } else { |
|
470 | + return ($a['name'] < $b['name']) ? -1 : 1; |
|
471 | + } |
|
472 | + }); |
|
473 | + |
|
474 | + $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); |
|
475 | + foreach ($list as $index => &$navEntry) { |
|
476 | + if ($navEntry['id'] == $activeApp) { |
|
477 | + $navEntry['active'] = true; |
|
478 | + } else { |
|
479 | + $navEntry['active'] = false; |
|
480 | + } |
|
481 | + } |
|
482 | + unset($navEntry); |
|
483 | + |
|
484 | + return $list; |
|
485 | + } |
|
486 | + |
|
487 | + /** |
|
488 | + * Get the path where to install apps |
|
489 | + * |
|
490 | + * @return string|false |
|
491 | + */ |
|
492 | + public static function getInstallPath() { |
|
493 | + if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) { |
|
494 | + return false; |
|
495 | + } |
|
496 | + |
|
497 | + foreach (OC::$APPSROOTS as $dir) { |
|
498 | + if (isset($dir['writable']) && $dir['writable'] === true) { |
|
499 | + return $dir['path']; |
|
500 | + } |
|
501 | + } |
|
502 | + |
|
503 | + \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR); |
|
504 | + return null; |
|
505 | + } |
|
506 | + |
|
507 | + |
|
508 | + /** |
|
509 | + * search for an app in all app-directories |
|
510 | + * |
|
511 | + * @param string $appId |
|
512 | + * @return false|string |
|
513 | + */ |
|
514 | + public static function findAppInDirectories($appId) { |
|
515 | + $sanitizedAppId = self::cleanAppId($appId); |
|
516 | + if($sanitizedAppId !== $appId) { |
|
517 | + return false; |
|
518 | + } |
|
519 | + static $app_dir = array(); |
|
520 | + |
|
521 | + if (isset($app_dir[$appId])) { |
|
522 | + return $app_dir[$appId]; |
|
523 | + } |
|
524 | + |
|
525 | + $possibleApps = array(); |
|
526 | + foreach (OC::$APPSROOTS as $dir) { |
|
527 | + if (file_exists($dir['path'] . '/' . $appId)) { |
|
528 | + $possibleApps[] = $dir; |
|
529 | + } |
|
530 | + } |
|
531 | + |
|
532 | + if (empty($possibleApps)) { |
|
533 | + return false; |
|
534 | + } elseif (count($possibleApps) === 1) { |
|
535 | + $dir = array_shift($possibleApps); |
|
536 | + $app_dir[$appId] = $dir; |
|
537 | + return $dir; |
|
538 | + } else { |
|
539 | + $versionToLoad = array(); |
|
540 | + foreach ($possibleApps as $possibleApp) { |
|
541 | + $version = self::getAppVersionByPath($possibleApp['path']); |
|
542 | + if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) { |
|
543 | + $versionToLoad = array( |
|
544 | + 'dir' => $possibleApp, |
|
545 | + 'version' => $version, |
|
546 | + ); |
|
547 | + } |
|
548 | + } |
|
549 | + $app_dir[$appId] = $versionToLoad['dir']; |
|
550 | + return $versionToLoad['dir']; |
|
551 | + //TODO - write test |
|
552 | + } |
|
553 | + } |
|
554 | + |
|
555 | + /** |
|
556 | + * Get the directory for the given app. |
|
557 | + * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
558 | + * |
|
559 | + * @param string $appId |
|
560 | + * @return string|false |
|
561 | + */ |
|
562 | + public static function getAppPath($appId) { |
|
563 | + if ($appId === null || trim($appId) === '') { |
|
564 | + return false; |
|
565 | + } |
|
566 | + |
|
567 | + if (($dir = self::findAppInDirectories($appId)) != false) { |
|
568 | + return $dir['path'] . '/' . $appId; |
|
569 | + } |
|
570 | + return false; |
|
571 | + } |
|
572 | + |
|
573 | + /** |
|
574 | + * Get the path for the given app on the access |
|
575 | + * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
576 | + * |
|
577 | + * @param string $appId |
|
578 | + * @return string|false |
|
579 | + */ |
|
580 | + public static function getAppWebPath($appId) { |
|
581 | + if (($dir = self::findAppInDirectories($appId)) != false) { |
|
582 | + return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
583 | + } |
|
584 | + return false; |
|
585 | + } |
|
586 | + |
|
587 | + /** |
|
588 | + * get the last version of the app from appinfo/info.xml |
|
589 | + * |
|
590 | + * @param string $appId |
|
591 | + * @param bool $useCache |
|
592 | + * @return string |
|
593 | + */ |
|
594 | + public static function getAppVersion($appId, $useCache = true) { |
|
595 | + if($useCache && isset(self::$appVersion[$appId])) { |
|
596 | + return self::$appVersion[$appId]; |
|
597 | + } |
|
598 | + |
|
599 | + $file = self::getAppPath($appId); |
|
600 | + self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0'; |
|
601 | + return self::$appVersion[$appId]; |
|
602 | + } |
|
603 | + |
|
604 | + /** |
|
605 | + * get app's version based on it's path |
|
606 | + * |
|
607 | + * @param string $path |
|
608 | + * @return string |
|
609 | + */ |
|
610 | + public static function getAppVersionByPath($path) { |
|
611 | + $infoFile = $path . '/appinfo/info.xml'; |
|
612 | + $appData = self::getAppInfo($infoFile, true); |
|
613 | + return isset($appData['version']) ? $appData['version'] : ''; |
|
614 | + } |
|
615 | + |
|
616 | + |
|
617 | + /** |
|
618 | + * Read all app metadata from the info.xml file |
|
619 | + * |
|
620 | + * @param string $appId id of the app or the path of the info.xml file |
|
621 | + * @param bool $path |
|
622 | + * @param string $lang |
|
623 | + * @return array|null |
|
624 | + * @note all data is read from info.xml, not just pre-defined fields |
|
625 | + */ |
|
626 | + public static function getAppInfo($appId, $path = false, $lang = null) { |
|
627 | + if ($path) { |
|
628 | + $file = $appId; |
|
629 | + } else { |
|
630 | + if ($lang === null && isset(self::$appInfo[$appId])) { |
|
631 | + return self::$appInfo[$appId]; |
|
632 | + } |
|
633 | + $appPath = self::getAppPath($appId); |
|
634 | + if($appPath === false) { |
|
635 | + return null; |
|
636 | + } |
|
637 | + $file = $appPath . '/appinfo/info.xml'; |
|
638 | + } |
|
639 | + |
|
640 | + $parser = new InfoParser(\OC::$server->getMemCacheFactory()->createLocal('core.appinfo')); |
|
641 | + $data = $parser->parse($file); |
|
642 | + |
|
643 | + if (is_array($data)) { |
|
644 | + $data = OC_App::parseAppInfo($data, $lang); |
|
645 | + } |
|
646 | + if(isset($data['ocsid'])) { |
|
647 | + $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
|
648 | + if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
649 | + $data['ocsid'] = $storedId; |
|
650 | + } |
|
651 | + } |
|
652 | + |
|
653 | + if ($lang === null) { |
|
654 | + self::$appInfo[$appId] = $data; |
|
655 | + } |
|
656 | + |
|
657 | + return $data; |
|
658 | + } |
|
659 | + |
|
660 | + /** |
|
661 | + * Returns the navigation |
|
662 | + * |
|
663 | + * @return array |
|
664 | + * |
|
665 | + * This function returns an array containing all entries added. The |
|
666 | + * entries are sorted by the key 'order' ascending. Additional to the keys |
|
667 | + * given for each app the following keys exist: |
|
668 | + * - active: boolean, signals if the user is on this navigation entry |
|
669 | + */ |
|
670 | + public static function getNavigation() { |
|
671 | + $entries = OC::$server->getNavigationManager()->getAll(); |
|
672 | + return self::proceedNavigation($entries); |
|
673 | + } |
|
674 | + |
|
675 | + /** |
|
676 | + * Returns the Settings Navigation |
|
677 | + * |
|
678 | + * @return string[] |
|
679 | + * |
|
680 | + * This function returns an array containing all settings pages added. The |
|
681 | + * entries are sorted by the key 'order' ascending. |
|
682 | + */ |
|
683 | + public static function getSettingsNavigation() { |
|
684 | + $entries = OC::$server->getNavigationManager()->getAll('settings'); |
|
685 | + return self::proceedNavigation($entries); |
|
686 | + } |
|
687 | + |
|
688 | + /** |
|
689 | + * get the id of loaded app |
|
690 | + * |
|
691 | + * @return string |
|
692 | + */ |
|
693 | + public static function getCurrentApp() { |
|
694 | + $request = \OC::$server->getRequest(); |
|
695 | + $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); |
|
696 | + $topFolder = substr($script, 0, strpos($script, '/') ?: 0); |
|
697 | + if (empty($topFolder)) { |
|
698 | + $path_info = $request->getPathInfo(); |
|
699 | + if ($path_info) { |
|
700 | + $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); |
|
701 | + } |
|
702 | + } |
|
703 | + if ($topFolder == 'apps') { |
|
704 | + $length = strlen($topFolder); |
|
705 | + return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1); |
|
706 | + } else { |
|
707 | + return $topFolder; |
|
708 | + } |
|
709 | + } |
|
710 | + |
|
711 | + /** |
|
712 | + * @param string $type |
|
713 | + * @return array |
|
714 | + */ |
|
715 | + public static function getForms($type) { |
|
716 | + $forms = array(); |
|
717 | + switch ($type) { |
|
718 | + case 'admin': |
|
719 | + $source = self::$adminForms; |
|
720 | + break; |
|
721 | + case 'personal': |
|
722 | + $source = self::$personalForms; |
|
723 | + break; |
|
724 | + default: |
|
725 | + return array(); |
|
726 | + } |
|
727 | + foreach ($source as $form) { |
|
728 | + $forms[] = include $form; |
|
729 | + } |
|
730 | + return $forms; |
|
731 | + } |
|
732 | + |
|
733 | + /** |
|
734 | + * register an admin form to be shown |
|
735 | + * |
|
736 | + * @param string $app |
|
737 | + * @param string $page |
|
738 | + */ |
|
739 | + public static function registerAdmin($app, $page) { |
|
740 | + self::$adminForms[] = $app . '/' . $page . '.php'; |
|
741 | + } |
|
742 | + |
|
743 | + /** |
|
744 | + * register a personal form to be shown |
|
745 | + * @param string $app |
|
746 | + * @param string $page |
|
747 | + */ |
|
748 | + public static function registerPersonal($app, $page) { |
|
749 | + self::$personalForms[] = $app . '/' . $page . '.php'; |
|
750 | + } |
|
751 | + |
|
752 | + /** |
|
753 | + * @param array $entry |
|
754 | + */ |
|
755 | + public static function registerLogIn(array $entry) { |
|
756 | + self::$altLogin[] = $entry; |
|
757 | + } |
|
758 | + |
|
759 | + /** |
|
760 | + * @return array |
|
761 | + */ |
|
762 | + public static function getAlternativeLogIns() { |
|
763 | + return self::$altLogin; |
|
764 | + } |
|
765 | + |
|
766 | + /** |
|
767 | + * get a list of all apps in the apps folder |
|
768 | + * |
|
769 | + * @return array an array of app names (string IDs) |
|
770 | + * @todo: change the name of this method to getInstalledApps, which is more accurate |
|
771 | + */ |
|
772 | + public static function getAllApps() { |
|
773 | + |
|
774 | + $apps = array(); |
|
775 | + |
|
776 | + foreach (OC::$APPSROOTS as $apps_dir) { |
|
777 | + if (!is_readable($apps_dir['path'])) { |
|
778 | + \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
779 | + continue; |
|
780 | + } |
|
781 | + $dh = opendir($apps_dir['path']); |
|
782 | + |
|
783 | + if (is_resource($dh)) { |
|
784 | + while (($file = readdir($dh)) !== false) { |
|
785 | + |
|
786 | + if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
787 | + |
|
788 | + $apps[] = $file; |
|
789 | + } |
|
790 | + } |
|
791 | + } |
|
792 | + } |
|
793 | + |
|
794 | + $apps = array_unique($apps); |
|
795 | + |
|
796 | + return $apps; |
|
797 | + } |
|
798 | + |
|
799 | + /** |
|
800 | + * List all apps, this is used in apps.php |
|
801 | + * |
|
802 | + * @return array |
|
803 | + */ |
|
804 | + public function listAllApps() { |
|
805 | + $installedApps = OC_App::getAllApps(); |
|
806 | + |
|
807 | + $appManager = \OC::$server->getAppManager(); |
|
808 | + //we don't want to show configuration for these |
|
809 | + $blacklist = $appManager->getAlwaysEnabledApps(); |
|
810 | + $appList = array(); |
|
811 | + $langCode = \OC::$server->getL10N('core')->getLanguageCode(); |
|
812 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
813 | + |
|
814 | + foreach ($installedApps as $app) { |
|
815 | + if (array_search($app, $blacklist) === false) { |
|
816 | + |
|
817 | + $info = OC_App::getAppInfo($app, false, $langCode); |
|
818 | + if (!is_array($info)) { |
|
819 | + \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
820 | + continue; |
|
821 | + } |
|
822 | + |
|
823 | + if (!isset($info['name'])) { |
|
824 | + \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
825 | + continue; |
|
826 | + } |
|
827 | + |
|
828 | + $enabled = \OC::$server->getConfig()->getAppValue($app, 'enabled', 'no'); |
|
829 | + $info['groups'] = null; |
|
830 | + if ($enabled === 'yes') { |
|
831 | + $active = true; |
|
832 | + } else if ($enabled === 'no') { |
|
833 | + $active = false; |
|
834 | + } else { |
|
835 | + $active = true; |
|
836 | + $info['groups'] = $enabled; |
|
837 | + } |
|
838 | + |
|
839 | + $info['active'] = $active; |
|
840 | + |
|
841 | + if ($appManager->isShipped($app)) { |
|
842 | + $info['internal'] = true; |
|
843 | + $info['level'] = self::officialApp; |
|
844 | + $info['removable'] = false; |
|
845 | + } else { |
|
846 | + $info['internal'] = false; |
|
847 | + $info['removable'] = true; |
|
848 | + } |
|
849 | + |
|
850 | + $appPath = self::getAppPath($app); |
|
851 | + if($appPath !== false) { |
|
852 | + $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
853 | + if (file_exists($appIcon)) { |
|
854 | + $info['preview'] = $urlGenerator->imagePath($app, $app . '.svg'); |
|
855 | + $info['previewAsIcon'] = true; |
|
856 | + } else { |
|
857 | + $appIcon = $appPath . '/img/app.svg'; |
|
858 | + if (file_exists($appIcon)) { |
|
859 | + $info['preview'] = $urlGenerator->imagePath($app, 'app.svg'); |
|
860 | + $info['previewAsIcon'] = true; |
|
861 | + } |
|
862 | + } |
|
863 | + } |
|
864 | + // fix documentation |
|
865 | + if (isset($info['documentation']) && is_array($info['documentation'])) { |
|
866 | + foreach ($info['documentation'] as $key => $url) { |
|
867 | + // If it is not an absolute URL we assume it is a key |
|
868 | + // i.e. admin-ldap will get converted to go.php?to=admin-ldap |
|
869 | + if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) { |
|
870 | + $url = $urlGenerator->linkToDocs($url); |
|
871 | + } |
|
872 | + |
|
873 | + $info['documentation'][$key] = $url; |
|
874 | + } |
|
875 | + } |
|
876 | + |
|
877 | + $info['version'] = OC_App::getAppVersion($app); |
|
878 | + $appList[] = $info; |
|
879 | + } |
|
880 | + } |
|
881 | + |
|
882 | + return $appList; |
|
883 | + } |
|
884 | + |
|
885 | + public static function shouldUpgrade($app) { |
|
886 | + $versions = self::getAppVersions(); |
|
887 | + $currentVersion = OC_App::getAppVersion($app); |
|
888 | + if ($currentVersion && isset($versions[$app])) { |
|
889 | + $installedVersion = $versions[$app]; |
|
890 | + if (!version_compare($currentVersion, $installedVersion, '=')) { |
|
891 | + return true; |
|
892 | + } |
|
893 | + } |
|
894 | + return false; |
|
895 | + } |
|
896 | + |
|
897 | + /** |
|
898 | + * Adjust the number of version parts of $version1 to match |
|
899 | + * the number of version parts of $version2. |
|
900 | + * |
|
901 | + * @param string $version1 version to adjust |
|
902 | + * @param string $version2 version to take the number of parts from |
|
903 | + * @return string shortened $version1 |
|
904 | + */ |
|
905 | + private static function adjustVersionParts($version1, $version2) { |
|
906 | + $version1 = explode('.', $version1); |
|
907 | + $version2 = explode('.', $version2); |
|
908 | + // reduce $version1 to match the number of parts in $version2 |
|
909 | + while (count($version1) > count($version2)) { |
|
910 | + array_pop($version1); |
|
911 | + } |
|
912 | + // if $version1 does not have enough parts, add some |
|
913 | + while (count($version1) < count($version2)) { |
|
914 | + $version1[] = '0'; |
|
915 | + } |
|
916 | + return implode('.', $version1); |
|
917 | + } |
|
918 | + |
|
919 | + /** |
|
920 | + * Check whether the current ownCloud version matches the given |
|
921 | + * application's version requirements. |
|
922 | + * |
|
923 | + * The comparison is made based on the number of parts that the |
|
924 | + * app info version has. For example for ownCloud 6.0.3 if the |
|
925 | + * app info version is expecting version 6.0, the comparison is |
|
926 | + * made on the first two parts of the ownCloud version. |
|
927 | + * This means that it's possible to specify "requiremin" => 6 |
|
928 | + * and "requiremax" => 6 and it will still match ownCloud 6.0.3. |
|
929 | + * |
|
930 | + * @param string $ocVersion ownCloud version to check against |
|
931 | + * @param array $appInfo app info (from xml) |
|
932 | + * |
|
933 | + * @return boolean true if compatible, otherwise false |
|
934 | + */ |
|
935 | + public static function isAppCompatible($ocVersion, $appInfo) { |
|
936 | + $requireMin = ''; |
|
937 | + $requireMax = ''; |
|
938 | + if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) { |
|
939 | + $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version']; |
|
940 | + } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
941 | + $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version']; |
|
942 | + } else if (isset($appInfo['requiremin'])) { |
|
943 | + $requireMin = $appInfo['requiremin']; |
|
944 | + } else if (isset($appInfo['require'])) { |
|
945 | + $requireMin = $appInfo['require']; |
|
946 | + } |
|
947 | + |
|
948 | + if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) { |
|
949 | + $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version']; |
|
950 | + } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
951 | + $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version']; |
|
952 | + } else if (isset($appInfo['requiremax'])) { |
|
953 | + $requireMax = $appInfo['requiremax']; |
|
954 | + } |
|
955 | + |
|
956 | + if (is_array($ocVersion)) { |
|
957 | + $ocVersion = implode('.', $ocVersion); |
|
958 | + } |
|
959 | + |
|
960 | + if (!empty($requireMin) |
|
961 | + && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<') |
|
962 | + ) { |
|
963 | + |
|
964 | + return false; |
|
965 | + } |
|
966 | + |
|
967 | + if (!empty($requireMax) |
|
968 | + && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>') |
|
969 | + ) { |
|
970 | + return false; |
|
971 | + } |
|
972 | + |
|
973 | + return true; |
|
974 | + } |
|
975 | + |
|
976 | + /** |
|
977 | + * get the installed version of all apps |
|
978 | + */ |
|
979 | + public static function getAppVersions() { |
|
980 | + static $versions; |
|
981 | + |
|
982 | + if(!$versions) { |
|
983 | + $appConfig = \OC::$server->getAppConfig(); |
|
984 | + $versions = $appConfig->getValues(false, 'installed_version'); |
|
985 | + } |
|
986 | + return $versions; |
|
987 | + } |
|
988 | + |
|
989 | + /** |
|
990 | + * @param string $app |
|
991 | + * @param \OCP\IConfig $config |
|
992 | + * @param \OCP\IL10N $l |
|
993 | + * @return bool |
|
994 | + * |
|
995 | + * @throws Exception if app is not compatible with this version of ownCloud |
|
996 | + * @throws Exception if no app-name was specified |
|
997 | + */ |
|
998 | + public function installApp($app, |
|
999 | + \OCP\IConfig $config, |
|
1000 | + \OCP\IL10N $l) { |
|
1001 | + if ($app !== false) { |
|
1002 | + // check if the app is compatible with this version of ownCloud |
|
1003 | + $info = self::getAppInfo($app); |
|
1004 | + if(!is_array($info)) { |
|
1005 | + throw new \Exception( |
|
1006 | + $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
1007 | + [$info['name']] |
|
1008 | + ) |
|
1009 | + ); |
|
1010 | + } |
|
1011 | + |
|
1012 | + $version = \OCP\Util::getVersion(); |
|
1013 | + if (!self::isAppCompatible($version, $info)) { |
|
1014 | + throw new \Exception( |
|
1015 | + $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
1016 | + array($info['name']) |
|
1017 | + ) |
|
1018 | + ); |
|
1019 | + } |
|
1020 | + |
|
1021 | + // check for required dependencies |
|
1022 | + self::checkAppDependencies($config, $l, $info); |
|
1023 | + |
|
1024 | + $config->setAppValue($app, 'enabled', 'yes'); |
|
1025 | + if (isset($appData['id'])) { |
|
1026 | + $config->setAppValue($app, 'ocsid', $appData['id']); |
|
1027 | + } |
|
1028 | + |
|
1029 | + if(isset($info['settings']) && is_array($info['settings'])) { |
|
1030 | + $appPath = self::getAppPath($app); |
|
1031 | + self::registerAutoloading($app, $appPath); |
|
1032 | + } |
|
1033 | + |
|
1034 | + \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
|
1035 | + } else { |
|
1036 | + if(empty($appName) ) { |
|
1037 | + throw new \Exception($l->t("No app name specified")); |
|
1038 | + } else { |
|
1039 | + throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
|
1040 | + } |
|
1041 | + } |
|
1042 | + |
|
1043 | + return $app; |
|
1044 | + } |
|
1045 | + |
|
1046 | + /** |
|
1047 | + * update the database for the app and call the update script |
|
1048 | + * |
|
1049 | + * @param string $appId |
|
1050 | + * @return bool |
|
1051 | + */ |
|
1052 | + public static function updateApp($appId) { |
|
1053 | + $appPath = self::getAppPath($appId); |
|
1054 | + if($appPath === false) { |
|
1055 | + return false; |
|
1056 | + } |
|
1057 | + self::registerAutoloading($appId, $appPath); |
|
1058 | + |
|
1059 | + $appData = self::getAppInfo($appId); |
|
1060 | + self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
|
1061 | + |
|
1062 | + if (file_exists($appPath . '/appinfo/database.xml')) { |
|
1063 | + OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
1064 | + } else { |
|
1065 | + $ms = new MigrationService($appId, \OC::$server->getDatabaseConnection()); |
|
1066 | + $ms->migrate(); |
|
1067 | + } |
|
1068 | + |
|
1069 | + self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
|
1070 | + self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
|
1071 | + unset(self::$appVersion[$appId]); |
|
1072 | + |
|
1073 | + // run upgrade code |
|
1074 | + if (file_exists($appPath . '/appinfo/update.php')) { |
|
1075 | + self::loadApp($appId); |
|
1076 | + include $appPath . '/appinfo/update.php'; |
|
1077 | + } |
|
1078 | + self::setupBackgroundJobs($appData['background-jobs']); |
|
1079 | + |
|
1080 | + //set remote/public handlers |
|
1081 | + if (array_key_exists('ocsid', $appData)) { |
|
1082 | + \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
|
1083 | + } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
1084 | + \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
|
1085 | + } |
|
1086 | + foreach ($appData['remote'] as $name => $path) { |
|
1087 | + \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
1088 | + } |
|
1089 | + foreach ($appData['public'] as $name => $path) { |
|
1090 | + \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
1091 | + } |
|
1092 | + |
|
1093 | + self::setAppTypes($appId); |
|
1094 | + |
|
1095 | + $version = \OC_App::getAppVersion($appId); |
|
1096 | + \OC::$server->getConfig()->setAppValue($appId, 'installed_version', $version); |
|
1097 | + |
|
1098 | + \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( |
|
1099 | + ManagerEvent::EVENT_APP_UPDATE, $appId |
|
1100 | + )); |
|
1101 | + |
|
1102 | + return true; |
|
1103 | + } |
|
1104 | + |
|
1105 | + /** |
|
1106 | + * @param string $appId |
|
1107 | + * @param string[] $steps |
|
1108 | + * @throws \OC\NeedsUpdateException |
|
1109 | + */ |
|
1110 | + public static function executeRepairSteps($appId, array $steps) { |
|
1111 | + if (empty($steps)) { |
|
1112 | + return; |
|
1113 | + } |
|
1114 | + // load the app |
|
1115 | + self::loadApp($appId); |
|
1116 | + |
|
1117 | + $dispatcher = OC::$server->getEventDispatcher(); |
|
1118 | + |
|
1119 | + // load the steps |
|
1120 | + $r = new Repair([], $dispatcher); |
|
1121 | + foreach ($steps as $step) { |
|
1122 | + try { |
|
1123 | + $r->addStep($step); |
|
1124 | + } catch (Exception $ex) { |
|
1125 | + $r->emit('\OC\Repair', 'error', [$ex->getMessage()]); |
|
1126 | + \OC::$server->getLogger()->logException($ex); |
|
1127 | + } |
|
1128 | + } |
|
1129 | + // run the steps |
|
1130 | + $r->run(); |
|
1131 | + } |
|
1132 | + |
|
1133 | + public static function setupBackgroundJobs(array $jobs) { |
|
1134 | + $queue = \OC::$server->getJobList(); |
|
1135 | + foreach ($jobs as $job) { |
|
1136 | + $queue->add($job); |
|
1137 | + } |
|
1138 | + } |
|
1139 | + |
|
1140 | + /** |
|
1141 | + * @param string $appId |
|
1142 | + * @param string[] $steps |
|
1143 | + */ |
|
1144 | + private static function setupLiveMigrations($appId, array $steps) { |
|
1145 | + $queue = \OC::$server->getJobList(); |
|
1146 | + foreach ($steps as $step) { |
|
1147 | + $queue->add('OC\Migration\BackgroundRepair', [ |
|
1148 | + 'app' => $appId, |
|
1149 | + 'step' => $step]); |
|
1150 | + } |
|
1151 | + } |
|
1152 | + |
|
1153 | + /** |
|
1154 | + * @param string $appId |
|
1155 | + * @return \OC\Files\View|false |
|
1156 | + */ |
|
1157 | + public static function getStorage($appId) { |
|
1158 | + if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check |
|
1159 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
1160 | + $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
1161 | + if (!$view->file_exists($appId)) { |
|
1162 | + $view->mkdir($appId); |
|
1163 | + } |
|
1164 | + return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
1165 | + } else { |
|
1166 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
1167 | + return false; |
|
1168 | + } |
|
1169 | + } else { |
|
1170 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
1171 | + return false; |
|
1172 | + } |
|
1173 | + } |
|
1174 | + |
|
1175 | + protected static function findBestL10NOption($options, $lang) { |
|
1176 | + $fallback = $similarLangFallback = $englishFallback = false; |
|
1177 | + |
|
1178 | + $lang = strtolower($lang); |
|
1179 | + $similarLang = $lang; |
|
1180 | + if (strpos($similarLang, '_')) { |
|
1181 | + // For "de_DE" we want to find "de" and the other way around |
|
1182 | + $similarLang = substr($lang, 0, strpos($lang, '_')); |
|
1183 | + } |
|
1184 | + |
|
1185 | + foreach ($options as $option) { |
|
1186 | + if (is_array($option)) { |
|
1187 | + if ($fallback === false) { |
|
1188 | + $fallback = $option['@value']; |
|
1189 | + } |
|
1190 | + |
|
1191 | + if (!isset($option['@attributes']['lang'])) { |
|
1192 | + continue; |
|
1193 | + } |
|
1194 | + |
|
1195 | + $attributeLang = strtolower($option['@attributes']['lang']); |
|
1196 | + if ($attributeLang === $lang) { |
|
1197 | + return $option['@value']; |
|
1198 | + } |
|
1199 | + |
|
1200 | + if ($attributeLang === $similarLang) { |
|
1201 | + $similarLangFallback = $option['@value']; |
|
1202 | + } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
1203 | + if ($similarLangFallback === false) { |
|
1204 | + $similarLangFallback = $option['@value']; |
|
1205 | + } |
|
1206 | + } |
|
1207 | + } else { |
|
1208 | + $englishFallback = $option; |
|
1209 | + } |
|
1210 | + } |
|
1211 | + |
|
1212 | + if ($similarLangFallback !== false) { |
|
1213 | + return $similarLangFallback; |
|
1214 | + } else if ($englishFallback !== false) { |
|
1215 | + return $englishFallback; |
|
1216 | + } |
|
1217 | + return (string) $fallback; |
|
1218 | + } |
|
1219 | + |
|
1220 | + /** |
|
1221 | + * parses the app data array and enhanced the 'description' value |
|
1222 | + * |
|
1223 | + * @param array $data the app data |
|
1224 | + * @param string $lang |
|
1225 | + * @return array improved app data |
|
1226 | + */ |
|
1227 | + public static function parseAppInfo(array $data, $lang = null) { |
|
1228 | + |
|
1229 | + if ($lang && isset($data['name']) && is_array($data['name'])) { |
|
1230 | + $data['name'] = self::findBestL10NOption($data['name'], $lang); |
|
1231 | + } |
|
1232 | + if ($lang && isset($data['summary']) && is_array($data['summary'])) { |
|
1233 | + $data['summary'] = self::findBestL10NOption($data['summary'], $lang); |
|
1234 | + } |
|
1235 | + if ($lang && isset($data['description']) && is_array($data['description'])) { |
|
1236 | + $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
|
1237 | + } else if (isset($data['description']) && is_string($data['description'])) { |
|
1238 | + $data['description'] = trim($data['description']); |
|
1239 | + } else { |
|
1240 | + $data['description'] = ''; |
|
1241 | + } |
|
1242 | + |
|
1243 | + return $data; |
|
1244 | + } |
|
1245 | + |
|
1246 | + /** |
|
1247 | + * @param \OCP\IConfig $config |
|
1248 | + * @param \OCP\IL10N $l |
|
1249 | + * @param array $info |
|
1250 | + * @throws \Exception |
|
1251 | + */ |
|
1252 | + public static function checkAppDependencies($config, $l, $info) { |
|
1253 | + $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); |
|
1254 | + $missing = $dependencyAnalyzer->analyze($info); |
|
1255 | + if (!empty($missing)) { |
|
1256 | + $missingMsg = implode(PHP_EOL, $missing); |
|
1257 | + throw new \Exception( |
|
1258 | + $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s', |
|
1259 | + [$info['name'], $missingMsg] |
|
1260 | + ) |
|
1261 | + ); |
|
1262 | + } |
|
1263 | + } |
|
1264 | 1264 | } |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | $apps = self::getEnabledApps(); |
114 | 114 | |
115 | 115 | // Add each apps' folder as allowed class path |
116 | - foreach($apps as $app) { |
|
116 | + foreach ($apps as $app) { |
|
117 | 117 | $path = self::getAppPath($app); |
118 | - if($path !== false) { |
|
118 | + if ($path !== false) { |
|
119 | 119 | self::registerAutoloading($app, $path); |
120 | 120 | } |
121 | 121 | } |
@@ -140,15 +140,15 @@ discard block |
||
140 | 140 | public static function loadApp($app) { |
141 | 141 | self::$loadedApps[] = $app; |
142 | 142 | $appPath = self::getAppPath($app); |
143 | - if($appPath === false) { |
|
143 | + if ($appPath === false) { |
|
144 | 144 | return; |
145 | 145 | } |
146 | 146 | |
147 | 147 | // in case someone calls loadApp() directly |
148 | 148 | self::registerAutoloading($app, $appPath); |
149 | 149 | |
150 | - if (is_file($appPath . '/appinfo/app.php')) { |
|
151 | - \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
150 | + if (is_file($appPath.'/appinfo/app.php')) { |
|
151 | + \OC::$server->getEventLogger()->start('load_app_'.$app, 'Load app: '.$app); |
|
152 | 152 | self::requireAppFile($app); |
153 | 153 | if (self::isType($app, array('authentication'))) { |
154 | 154 | // since authentication apps affect the "is app enabled for group" check, |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | // enabled for groups |
158 | 158 | self::$enabledAppsCache = array(); |
159 | 159 | } |
160 | - \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
160 | + \OC::$server->getEventLogger()->end('load_app_'.$app); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | $info = self::getAppInfo($app); |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | $plugins = isset($info['collaboration']['plugins']['plugin']['@value']) ? |
204 | 204 | [$info['collaboration']['plugins']['plugin']] : $info['collaboration']['plugins']['plugin']; |
205 | 205 | foreach ($plugins as $plugin) { |
206 | - if($plugin['@attributes']['type'] === 'collaborator-search') { |
|
206 | + if ($plugin['@attributes']['type'] === 'collaborator-search') { |
|
207 | 207 | $pluginInfo = [ |
208 | 208 | 'shareType' => $plugin['@attributes']['share-type'], |
209 | 209 | 'class' => $plugin['@value'], |
@@ -222,8 +222,8 @@ discard block |
||
222 | 222 | * @param string $path |
223 | 223 | */ |
224 | 224 | public static function registerAutoloading($app, $path) { |
225 | - $key = $app . '-' . $path; |
|
226 | - if(isset(self::$alreadyRegistered[$key])) { |
|
225 | + $key = $app.'-'.$path; |
|
226 | + if (isset(self::$alreadyRegistered[$key])) { |
|
227 | 227 | return; |
228 | 228 | } |
229 | 229 | |
@@ -233,17 +233,17 @@ discard block |
||
233 | 233 | $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
234 | 234 | \OC::$server->registerNamespace($app, $appNamespace); |
235 | 235 | |
236 | - if (file_exists($path . '/composer/autoload.php')) { |
|
237 | - require_once $path . '/composer/autoload.php'; |
|
236 | + if (file_exists($path.'/composer/autoload.php')) { |
|
237 | + require_once $path.'/composer/autoload.php'; |
|
238 | 238 | } else { |
239 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
239 | + \OC::$composerAutoloader->addPsr4($appNamespace.'\\', $path.'/lib/', true); |
|
240 | 240 | // Register on legacy autoloader |
241 | 241 | \OC::$loader->addValidRoot($path); |
242 | 242 | } |
243 | 243 | |
244 | 244 | // Register Test namespace only when testing |
245 | 245 | if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
246 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
246 | + \OC::$composerAutoloader->addPsr4($appNamespace.'\\Tests\\', $path.'/tests/', true); |
|
247 | 247 | } |
248 | 248 | } |
249 | 249 | |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | private static function requireAppFile($app) { |
256 | 256 | try { |
257 | 257 | // encapsulated here to avoid variable scope conflicts |
258 | - require_once $app . '/appinfo/app.php'; |
|
258 | + require_once $app.'/appinfo/app.php'; |
|
259 | 259 | } catch (Error $ex) { |
260 | 260 | \OC::$server->getLogger()->logException($ex); |
261 | 261 | if (!\OC::$server->getAppManager()->isShipped($app)) { |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | */ |
310 | 310 | public static function setAppTypes($app) { |
311 | 311 | $appData = self::getAppInfo($app); |
312 | - if(!is_array($appData)) { |
|
312 | + if (!is_array($appData)) { |
|
313 | 313 | return; |
314 | 314 | } |
315 | 315 | |
@@ -361,8 +361,8 @@ discard block |
||
361 | 361 | } else { |
362 | 362 | $apps = $appManager->getEnabledAppsForUser($user); |
363 | 363 | } |
364 | - $apps = array_filter($apps, function ($app) { |
|
365 | - return $app !== 'files';//we add this manually |
|
364 | + $apps = array_filter($apps, function($app) { |
|
365 | + return $app !== 'files'; //we add this manually |
|
366 | 366 | }); |
367 | 367 | sort($apps); |
368 | 368 | array_unshift($apps, 'files'); |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | $installer = \OC::$server->query(Installer::class); |
401 | 401 | $isDownloaded = $installer->isDownloaded($appId); |
402 | 402 | |
403 | - if(!$isDownloaded) { |
|
403 | + if (!$isDownloaded) { |
|
404 | 404 | $installer->downloadApp($appId); |
405 | 405 | } |
406 | 406 | |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | */ |
514 | 514 | public static function findAppInDirectories($appId) { |
515 | 515 | $sanitizedAppId = self::cleanAppId($appId); |
516 | - if($sanitizedAppId !== $appId) { |
|
516 | + if ($sanitizedAppId !== $appId) { |
|
517 | 517 | return false; |
518 | 518 | } |
519 | 519 | static $app_dir = array(); |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | |
525 | 525 | $possibleApps = array(); |
526 | 526 | foreach (OC::$APPSROOTS as $dir) { |
527 | - if (file_exists($dir['path'] . '/' . $appId)) { |
|
527 | + if (file_exists($dir['path'].'/'.$appId)) { |
|
528 | 528 | $possibleApps[] = $dir; |
529 | 529 | } |
530 | 530 | } |
@@ -565,7 +565,7 @@ discard block |
||
565 | 565 | } |
566 | 566 | |
567 | 567 | if (($dir = self::findAppInDirectories($appId)) != false) { |
568 | - return $dir['path'] . '/' . $appId; |
|
568 | + return $dir['path'].'/'.$appId; |
|
569 | 569 | } |
570 | 570 | return false; |
571 | 571 | } |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | */ |
580 | 580 | public static function getAppWebPath($appId) { |
581 | 581 | if (($dir = self::findAppInDirectories($appId)) != false) { |
582 | - return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
582 | + return OC::$WEBROOT.$dir['url'].'/'.$appId; |
|
583 | 583 | } |
584 | 584 | return false; |
585 | 585 | } |
@@ -592,7 +592,7 @@ discard block |
||
592 | 592 | * @return string |
593 | 593 | */ |
594 | 594 | public static function getAppVersion($appId, $useCache = true) { |
595 | - if($useCache && isset(self::$appVersion[$appId])) { |
|
595 | + if ($useCache && isset(self::$appVersion[$appId])) { |
|
596 | 596 | return self::$appVersion[$appId]; |
597 | 597 | } |
598 | 598 | |
@@ -608,7 +608,7 @@ discard block |
||
608 | 608 | * @return string |
609 | 609 | */ |
610 | 610 | public static function getAppVersionByPath($path) { |
611 | - $infoFile = $path . '/appinfo/info.xml'; |
|
611 | + $infoFile = $path.'/appinfo/info.xml'; |
|
612 | 612 | $appData = self::getAppInfo($infoFile, true); |
613 | 613 | return isset($appData['version']) ? $appData['version'] : ''; |
614 | 614 | } |
@@ -631,10 +631,10 @@ discard block |
||
631 | 631 | return self::$appInfo[$appId]; |
632 | 632 | } |
633 | 633 | $appPath = self::getAppPath($appId); |
634 | - if($appPath === false) { |
|
634 | + if ($appPath === false) { |
|
635 | 635 | return null; |
636 | 636 | } |
637 | - $file = $appPath . '/appinfo/info.xml'; |
|
637 | + $file = $appPath.'/appinfo/info.xml'; |
|
638 | 638 | } |
639 | 639 | |
640 | 640 | $parser = new InfoParser(\OC::$server->getMemCacheFactory()->createLocal('core.appinfo')); |
@@ -643,9 +643,9 @@ discard block |
||
643 | 643 | if (is_array($data)) { |
644 | 644 | $data = OC_App::parseAppInfo($data, $lang); |
645 | 645 | } |
646 | - if(isset($data['ocsid'])) { |
|
646 | + if (isset($data['ocsid'])) { |
|
647 | 647 | $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
648 | - if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
648 | + if ($storedId !== '' && $storedId !== $data['ocsid']) { |
|
649 | 649 | $data['ocsid'] = $storedId; |
650 | 650 | } |
651 | 651 | } |
@@ -737,7 +737,7 @@ discard block |
||
737 | 737 | * @param string $page |
738 | 738 | */ |
739 | 739 | public static function registerAdmin($app, $page) { |
740 | - self::$adminForms[] = $app . '/' . $page . '.php'; |
|
740 | + self::$adminForms[] = $app.'/'.$page.'.php'; |
|
741 | 741 | } |
742 | 742 | |
743 | 743 | /** |
@@ -746,7 +746,7 @@ discard block |
||
746 | 746 | * @param string $page |
747 | 747 | */ |
748 | 748 | public static function registerPersonal($app, $page) { |
749 | - self::$personalForms[] = $app . '/' . $page . '.php'; |
|
749 | + self::$personalForms[] = $app.'/'.$page.'.php'; |
|
750 | 750 | } |
751 | 751 | |
752 | 752 | /** |
@@ -775,7 +775,7 @@ discard block |
||
775 | 775 | |
776 | 776 | foreach (OC::$APPSROOTS as $apps_dir) { |
777 | 777 | if (!is_readable($apps_dir['path'])) { |
778 | - \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
778 | + \OCP\Util::writeLog('core', 'unable to read app folder : '.$apps_dir['path'], \OCP\Util::WARN); |
|
779 | 779 | continue; |
780 | 780 | } |
781 | 781 | $dh = opendir($apps_dir['path']); |
@@ -783,7 +783,7 @@ discard block |
||
783 | 783 | if (is_resource($dh)) { |
784 | 784 | while (($file = readdir($dh)) !== false) { |
785 | 785 | |
786 | - if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
786 | + if ($file[0] != '.' and is_dir($apps_dir['path'].'/'.$file) and is_file($apps_dir['path'].'/'.$file.'/appinfo/info.xml')) { |
|
787 | 787 | |
788 | 788 | $apps[] = $file; |
789 | 789 | } |
@@ -816,12 +816,12 @@ discard block |
||
816 | 816 | |
817 | 817 | $info = OC_App::getAppInfo($app, false, $langCode); |
818 | 818 | if (!is_array($info)) { |
819 | - \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
819 | + \OCP\Util::writeLog('core', 'Could not read app info file for app "'.$app.'"', \OCP\Util::ERROR); |
|
820 | 820 | continue; |
821 | 821 | } |
822 | 822 | |
823 | 823 | if (!isset($info['name'])) { |
824 | - \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
824 | + \OCP\Util::writeLog('core', 'App id "'.$app.'" has no name in appinfo', \OCP\Util::ERROR); |
|
825 | 825 | continue; |
826 | 826 | } |
827 | 827 | |
@@ -848,13 +848,13 @@ discard block |
||
848 | 848 | } |
849 | 849 | |
850 | 850 | $appPath = self::getAppPath($app); |
851 | - if($appPath !== false) { |
|
852 | - $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
851 | + if ($appPath !== false) { |
|
852 | + $appIcon = $appPath.'/img/'.$app.'.svg'; |
|
853 | 853 | if (file_exists($appIcon)) { |
854 | - $info['preview'] = $urlGenerator->imagePath($app, $app . '.svg'); |
|
854 | + $info['preview'] = $urlGenerator->imagePath($app, $app.'.svg'); |
|
855 | 855 | $info['previewAsIcon'] = true; |
856 | 856 | } else { |
857 | - $appIcon = $appPath . '/img/app.svg'; |
|
857 | + $appIcon = $appPath.'/img/app.svg'; |
|
858 | 858 | if (file_exists($appIcon)) { |
859 | 859 | $info['preview'] = $urlGenerator->imagePath($app, 'app.svg'); |
860 | 860 | $info['previewAsIcon'] = true; |
@@ -979,7 +979,7 @@ discard block |
||
979 | 979 | public static function getAppVersions() { |
980 | 980 | static $versions; |
981 | 981 | |
982 | - if(!$versions) { |
|
982 | + if (!$versions) { |
|
983 | 983 | $appConfig = \OC::$server->getAppConfig(); |
984 | 984 | $versions = $appConfig->getValues(false, 'installed_version'); |
985 | 985 | } |
@@ -1001,7 +1001,7 @@ discard block |
||
1001 | 1001 | if ($app !== false) { |
1002 | 1002 | // check if the app is compatible with this version of ownCloud |
1003 | 1003 | $info = self::getAppInfo($app); |
1004 | - if(!is_array($info)) { |
|
1004 | + if (!is_array($info)) { |
|
1005 | 1005 | throw new \Exception( |
1006 | 1006 | $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
1007 | 1007 | [$info['name']] |
@@ -1026,14 +1026,14 @@ discard block |
||
1026 | 1026 | $config->setAppValue($app, 'ocsid', $appData['id']); |
1027 | 1027 | } |
1028 | 1028 | |
1029 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
1029 | + if (isset($info['settings']) && is_array($info['settings'])) { |
|
1030 | 1030 | $appPath = self::getAppPath($app); |
1031 | 1031 | self::registerAutoloading($app, $appPath); |
1032 | 1032 | } |
1033 | 1033 | |
1034 | 1034 | \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
1035 | 1035 | } else { |
1036 | - if(empty($appName) ) { |
|
1036 | + if (empty($appName)) { |
|
1037 | 1037 | throw new \Exception($l->t("No app name specified")); |
1038 | 1038 | } else { |
1039 | 1039 | throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
@@ -1051,7 +1051,7 @@ discard block |
||
1051 | 1051 | */ |
1052 | 1052 | public static function updateApp($appId) { |
1053 | 1053 | $appPath = self::getAppPath($appId); |
1054 | - if($appPath === false) { |
|
1054 | + if ($appPath === false) { |
|
1055 | 1055 | return false; |
1056 | 1056 | } |
1057 | 1057 | self::registerAutoloading($appId, $appPath); |
@@ -1059,8 +1059,8 @@ discard block |
||
1059 | 1059 | $appData = self::getAppInfo($appId); |
1060 | 1060 | self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
1061 | 1061 | |
1062 | - if (file_exists($appPath . '/appinfo/database.xml')) { |
|
1063 | - OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
1062 | + if (file_exists($appPath.'/appinfo/database.xml')) { |
|
1063 | + OC_DB::updateDbFromStructure($appPath.'/appinfo/database.xml'); |
|
1064 | 1064 | } else { |
1065 | 1065 | $ms = new MigrationService($appId, \OC::$server->getDatabaseConnection()); |
1066 | 1066 | $ms->migrate(); |
@@ -1071,23 +1071,23 @@ discard block |
||
1071 | 1071 | unset(self::$appVersion[$appId]); |
1072 | 1072 | |
1073 | 1073 | // run upgrade code |
1074 | - if (file_exists($appPath . '/appinfo/update.php')) { |
|
1074 | + if (file_exists($appPath.'/appinfo/update.php')) { |
|
1075 | 1075 | self::loadApp($appId); |
1076 | - include $appPath . '/appinfo/update.php'; |
|
1076 | + include $appPath.'/appinfo/update.php'; |
|
1077 | 1077 | } |
1078 | 1078 | self::setupBackgroundJobs($appData['background-jobs']); |
1079 | 1079 | |
1080 | 1080 | //set remote/public handlers |
1081 | 1081 | if (array_key_exists('ocsid', $appData)) { |
1082 | 1082 | \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
1083 | - } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
1083 | + } elseif (\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
1084 | 1084 | \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
1085 | 1085 | } |
1086 | 1086 | foreach ($appData['remote'] as $name => $path) { |
1087 | - \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
1087 | + \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $appId.'/'.$path); |
|
1088 | 1088 | } |
1089 | 1089 | foreach ($appData['public'] as $name => $path) { |
1090 | - \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
1090 | + \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $appId.'/'.$path); |
|
1091 | 1091 | } |
1092 | 1092 | |
1093 | 1093 | self::setAppTypes($appId); |
@@ -1157,17 +1157,17 @@ discard block |
||
1157 | 1157 | public static function getStorage($appId) { |
1158 | 1158 | if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check |
1159 | 1159 | if (\OC::$server->getUserSession()->isLoggedIn()) { |
1160 | - $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
1160 | + $view = new \OC\Files\View('/'.OC_User::getUser()); |
|
1161 | 1161 | if (!$view->file_exists($appId)) { |
1162 | 1162 | $view->mkdir($appId); |
1163 | 1163 | } |
1164 | - return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
1164 | + return new \OC\Files\View('/'.OC_User::getUser().'/'.$appId); |
|
1165 | 1165 | } else { |
1166 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
1166 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.', user not logged in', \OCP\Util::ERROR); |
|
1167 | 1167 | return false; |
1168 | 1168 | } |
1169 | 1169 | } else { |
1170 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
1170 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.' not enabled', \OCP\Util::ERROR); |
|
1171 | 1171 | return false; |
1172 | 1172 | } |
1173 | 1173 | } |
@@ -1199,9 +1199,9 @@ discard block |
||
1199 | 1199 | |
1200 | 1200 | if ($attributeLang === $similarLang) { |
1201 | 1201 | $similarLangFallback = $option['@value']; |
1202 | - } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
1202 | + } else if (strpos($attributeLang, $similarLang.'_') === 0) { |
|
1203 | 1203 | if ($similarLangFallback === false) { |
1204 | - $similarLangFallback = $option['@value']; |
|
1204 | + $similarLangFallback = $option['@value']; |
|
1205 | 1205 | } |
1206 | 1206 | } |
1207 | 1207 | } else { |
@@ -1236,7 +1236,7 @@ discard block |
||
1236 | 1236 | $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
1237 | 1237 | } else if (isset($data['description']) && is_string($data['description'])) { |
1238 | 1238 | $data['description'] = trim($data['description']); |
1239 | - } else { |
|
1239 | + } else { |
|
1240 | 1240 | $data['description'] = ''; |
1241 | 1241 | } |
1242 | 1242 |
@@ -57,560 +57,560 @@ |
||
57 | 57 | * This class provides the functionality needed to install, update and remove apps |
58 | 58 | */ |
59 | 59 | class Installer { |
60 | - /** @var AppFetcher */ |
|
61 | - private $appFetcher; |
|
62 | - /** @var IClientService */ |
|
63 | - private $clientService; |
|
64 | - /** @var ITempManager */ |
|
65 | - private $tempManager; |
|
66 | - /** @var ILogger */ |
|
67 | - private $logger; |
|
68 | - /** @var IConfig */ |
|
69 | - private $config; |
|
70 | - /** @var array - for caching the result of app fetcher */ |
|
71 | - private $apps = null; |
|
72 | - /** @var bool|null - for caching the result of the ready status */ |
|
73 | - private $isInstanceReadyForUpdates = null; |
|
74 | - |
|
75 | - /** |
|
76 | - * @param AppFetcher $appFetcher |
|
77 | - * @param IClientService $clientService |
|
78 | - * @param ITempManager $tempManager |
|
79 | - * @param ILogger $logger |
|
80 | - * @param IConfig $config |
|
81 | - */ |
|
82 | - public function __construct(AppFetcher $appFetcher, |
|
83 | - IClientService $clientService, |
|
84 | - ITempManager $tempManager, |
|
85 | - ILogger $logger, |
|
86 | - IConfig $config) { |
|
87 | - $this->appFetcher = $appFetcher; |
|
88 | - $this->clientService = $clientService; |
|
89 | - $this->tempManager = $tempManager; |
|
90 | - $this->logger = $logger; |
|
91 | - $this->config = $config; |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Installs an app that is located in one of the app folders already |
|
96 | - * |
|
97 | - * @param string $appId App to install |
|
98 | - * @throws \Exception |
|
99 | - * @return string app ID |
|
100 | - */ |
|
101 | - public function installApp($appId) { |
|
102 | - $app = \OC_App::findAppInDirectories($appId); |
|
103 | - if($app === false) { |
|
104 | - throw new \Exception('App not found in any app directory'); |
|
105 | - } |
|
106 | - |
|
107 | - $basedir = $app['path'].'/'.$appId; |
|
108 | - $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true); |
|
109 | - |
|
110 | - $l = \OC::$server->getL10N('core'); |
|
111 | - |
|
112 | - if(!is_array($info)) { |
|
113 | - throw new \Exception( |
|
114 | - $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
115 | - [$info['name']] |
|
116 | - ) |
|
117 | - ); |
|
118 | - } |
|
119 | - |
|
120 | - $version = \OCP\Util::getVersion(); |
|
121 | - if (!\OC_App::isAppCompatible($version, $info)) { |
|
122 | - throw new \Exception( |
|
123 | - // TODO $l |
|
124 | - $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
125 | - [$info['name']] |
|
126 | - ) |
|
127 | - ); |
|
128 | - } |
|
129 | - |
|
130 | - // check for required dependencies |
|
131 | - \OC_App::checkAppDependencies($this->config, $l, $info); |
|
132 | - \OC_App::registerAutoloading($appId, $basedir); |
|
133 | - |
|
134 | - //install the database |
|
135 | - if(is_file($basedir.'/appinfo/database.xml')) { |
|
136 | - if (\OC::$server->getConfig()->getAppValue($info['id'], 'installed_version') === null) { |
|
137 | - OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
|
138 | - } else { |
|
139 | - OC_DB::updateDbFromStructure($basedir.'/appinfo/database.xml'); |
|
140 | - } |
|
141 | - } else { |
|
142 | - $ms = new \OC\DB\MigrationService($info['id'], \OC::$server->getDatabaseConnection()); |
|
143 | - $ms->migrate(); |
|
144 | - } |
|
145 | - |
|
146 | - \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
147 | - |
|
148 | - //run appinfo/install.php |
|
149 | - if(!isset($data['noinstall']) or $data['noinstall']==false) { |
|
150 | - self::includeAppScript($basedir . '/appinfo/install.php'); |
|
151 | - } |
|
152 | - |
|
153 | - $appData = OC_App::getAppInfo($appId); |
|
154 | - OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']); |
|
155 | - |
|
156 | - //set the installed version |
|
157 | - \OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'], false)); |
|
158 | - \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
|
159 | - |
|
160 | - //set remote/public handlers |
|
161 | - foreach($info['remote'] as $name=>$path) { |
|
162 | - \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
|
163 | - } |
|
164 | - foreach($info['public'] as $name=>$path) { |
|
165 | - \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
|
166 | - } |
|
167 | - |
|
168 | - OC_App::setAppTypes($info['id']); |
|
169 | - |
|
170 | - return $info['id']; |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * @brief checks whether or not an app is installed |
|
175 | - * @param string $app app |
|
176 | - * @returns bool |
|
177 | - * |
|
178 | - * Checks whether or not an app is installed, i.e. registered in apps table. |
|
179 | - */ |
|
180 | - public static function isInstalled( $app ) { |
|
181 | - return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Updates the specified app from the appstore |
|
186 | - * |
|
187 | - * @param string $appId |
|
188 | - * @return bool |
|
189 | - */ |
|
190 | - public function updateAppstoreApp($appId) { |
|
191 | - if($this->isUpdateAvailable($appId)) { |
|
192 | - try { |
|
193 | - $this->downloadApp($appId); |
|
194 | - } catch (\Exception $e) { |
|
195 | - $this->logger->logException($e, [ |
|
196 | - 'level' => \OCP\Util::ERROR, |
|
197 | - 'app' => 'core', |
|
198 | - ]); |
|
199 | - return false; |
|
200 | - } |
|
201 | - return OC_App::updateApp($appId); |
|
202 | - } |
|
203 | - |
|
204 | - return false; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Downloads an app and puts it into the app directory |
|
209 | - * |
|
210 | - * @param string $appId |
|
211 | - * |
|
212 | - * @throws \Exception If the installation was not successful |
|
213 | - */ |
|
214 | - public function downloadApp($appId) { |
|
215 | - $appId = strtolower($appId); |
|
216 | - |
|
217 | - $apps = $this->appFetcher->get(); |
|
218 | - foreach($apps as $app) { |
|
219 | - if($app['id'] === $appId) { |
|
220 | - // Load the certificate |
|
221 | - $certificate = new X509(); |
|
222 | - $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
223 | - $loadedCertificate = $certificate->loadX509($app['certificate']); |
|
224 | - |
|
225 | - // Verify if the certificate has been revoked |
|
226 | - $crl = new X509(); |
|
227 | - $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
228 | - $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
229 | - if($crl->validateSignature() !== true) { |
|
230 | - throw new \Exception('Could not validate CRL signature'); |
|
231 | - } |
|
232 | - $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
|
233 | - $revoked = $crl->getRevoked($csn); |
|
234 | - if ($revoked !== false) { |
|
235 | - throw new \Exception( |
|
236 | - sprintf( |
|
237 | - 'Certificate "%s" has been revoked', |
|
238 | - $csn |
|
239 | - ) |
|
240 | - ); |
|
241 | - } |
|
242 | - |
|
243 | - // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
|
244 | - if($certificate->validateSignature() !== true) { |
|
245 | - throw new \Exception( |
|
246 | - sprintf( |
|
247 | - 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
|
248 | - $appId |
|
249 | - ) |
|
250 | - ); |
|
251 | - } |
|
252 | - |
|
253 | - // Verify if the certificate is issued for the requested app id |
|
254 | - $certInfo = openssl_x509_parse($app['certificate']); |
|
255 | - if(!isset($certInfo['subject']['CN'])) { |
|
256 | - throw new \Exception( |
|
257 | - sprintf( |
|
258 | - 'App with id %s has a cert with no CN', |
|
259 | - $appId |
|
260 | - ) |
|
261 | - ); |
|
262 | - } |
|
263 | - if($certInfo['subject']['CN'] !== $appId) { |
|
264 | - throw new \Exception( |
|
265 | - sprintf( |
|
266 | - 'App with id %s has a cert issued to %s', |
|
267 | - $appId, |
|
268 | - $certInfo['subject']['CN'] |
|
269 | - ) |
|
270 | - ); |
|
271 | - } |
|
272 | - |
|
273 | - // Download the release |
|
274 | - $tempFile = $this->tempManager->getTemporaryFile('.tar.gz'); |
|
275 | - $client = $this->clientService->newClient(); |
|
276 | - $client->get($app['releases'][0]['download'], ['save_to' => $tempFile]); |
|
277 | - |
|
278 | - // Check if the signature actually matches the downloaded content |
|
279 | - $certificate = openssl_get_publickey($app['certificate']); |
|
280 | - $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
281 | - openssl_free_key($certificate); |
|
282 | - |
|
283 | - if($verified === true) { |
|
284 | - // Seems to match, let's proceed |
|
285 | - $extractDir = $this->tempManager->getTemporaryFolder(); |
|
286 | - $archive = new TAR($tempFile); |
|
287 | - |
|
288 | - if($archive) { |
|
289 | - if (!$archive->extract($extractDir)) { |
|
290 | - throw new \Exception( |
|
291 | - sprintf( |
|
292 | - 'Could not extract app %s', |
|
293 | - $appId |
|
294 | - ) |
|
295 | - ); |
|
296 | - } |
|
297 | - $allFiles = scandir($extractDir); |
|
298 | - $folders = array_diff($allFiles, ['.', '..']); |
|
299 | - $folders = array_values($folders); |
|
300 | - |
|
301 | - if(count($folders) > 1) { |
|
302 | - throw new \Exception( |
|
303 | - sprintf( |
|
304 | - 'Extracted app %s has more than 1 folder', |
|
305 | - $appId |
|
306 | - ) |
|
307 | - ); |
|
308 | - } |
|
309 | - |
|
310 | - // Check if appinfo/info.xml has the same app ID as well |
|
311 | - $loadEntities = libxml_disable_entity_loader(false); |
|
312 | - $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
313 | - libxml_disable_entity_loader($loadEntities); |
|
314 | - if((string)$xml->id !== $appId) { |
|
315 | - throw new \Exception( |
|
316 | - sprintf( |
|
317 | - 'App for id %s has a wrong app ID in info.xml: %s', |
|
318 | - $appId, |
|
319 | - (string)$xml->id |
|
320 | - ) |
|
321 | - ); |
|
322 | - } |
|
323 | - |
|
324 | - // Check if the version is lower than before |
|
325 | - $currentVersion = OC_App::getAppVersion($appId); |
|
326 | - $newVersion = (string)$xml->version; |
|
327 | - if(version_compare($currentVersion, $newVersion) === 1) { |
|
328 | - throw new \Exception( |
|
329 | - sprintf( |
|
330 | - 'App for id %s has version %s and tried to update to lower version %s', |
|
331 | - $appId, |
|
332 | - $currentVersion, |
|
333 | - $newVersion |
|
334 | - ) |
|
335 | - ); |
|
336 | - } |
|
337 | - |
|
338 | - $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
339 | - // Remove old app with the ID if existent |
|
340 | - OC_Helper::rmdirr($baseDir); |
|
341 | - // Move to app folder |
|
342 | - if(@mkdir($baseDir)) { |
|
343 | - $extractDir .= '/' . $folders[0]; |
|
344 | - OC_Helper::copyr($extractDir, $baseDir); |
|
345 | - } |
|
346 | - OC_Helper::copyr($extractDir, $baseDir); |
|
347 | - OC_Helper::rmdirr($extractDir); |
|
348 | - return; |
|
349 | - } else { |
|
350 | - throw new \Exception( |
|
351 | - sprintf( |
|
352 | - 'Could not extract app with ID %s to %s', |
|
353 | - $appId, |
|
354 | - $extractDir |
|
355 | - ) |
|
356 | - ); |
|
357 | - } |
|
358 | - } else { |
|
359 | - // Signature does not match |
|
360 | - throw new \Exception( |
|
361 | - sprintf( |
|
362 | - 'App with id %s has invalid signature', |
|
363 | - $appId |
|
364 | - ) |
|
365 | - ); |
|
366 | - } |
|
367 | - } |
|
368 | - } |
|
369 | - |
|
370 | - throw new \Exception( |
|
371 | - sprintf( |
|
372 | - 'Could not download app %s', |
|
373 | - $appId |
|
374 | - ) |
|
375 | - ); |
|
376 | - } |
|
377 | - |
|
378 | - /** |
|
379 | - * Check if an update for the app is available |
|
380 | - * |
|
381 | - * @param string $appId |
|
382 | - * @return string|false false or the version number of the update |
|
383 | - */ |
|
384 | - public function isUpdateAvailable($appId) { |
|
385 | - if ($this->isInstanceReadyForUpdates === null) { |
|
386 | - $installPath = OC_App::getInstallPath(); |
|
387 | - if ($installPath === false || $installPath === null) { |
|
388 | - $this->isInstanceReadyForUpdates = false; |
|
389 | - } else { |
|
390 | - $this->isInstanceReadyForUpdates = true; |
|
391 | - } |
|
392 | - } |
|
393 | - |
|
394 | - if ($this->isInstanceReadyForUpdates === false) { |
|
395 | - return false; |
|
396 | - } |
|
397 | - |
|
398 | - if ($this->isInstalledFromGit($appId) === true) { |
|
399 | - return false; |
|
400 | - } |
|
401 | - |
|
402 | - if ($this->apps === null) { |
|
403 | - $this->apps = $this->appFetcher->get(); |
|
404 | - } |
|
405 | - |
|
406 | - foreach($this->apps as $app) { |
|
407 | - if($app['id'] === $appId) { |
|
408 | - $currentVersion = OC_App::getAppVersion($appId); |
|
409 | - $newestVersion = $app['releases'][0]['version']; |
|
410 | - if (version_compare($newestVersion, $currentVersion, '>')) { |
|
411 | - return $newestVersion; |
|
412 | - } else { |
|
413 | - return false; |
|
414 | - } |
|
415 | - } |
|
416 | - } |
|
417 | - |
|
418 | - return false; |
|
419 | - } |
|
420 | - |
|
421 | - /** |
|
422 | - * Check if app has been installed from git |
|
423 | - * @param string $name name of the application to remove |
|
424 | - * @return boolean |
|
425 | - * |
|
426 | - * The function will check if the path contains a .git folder |
|
427 | - */ |
|
428 | - private function isInstalledFromGit($appId) { |
|
429 | - $app = \OC_App::findAppInDirectories($appId); |
|
430 | - if($app === false) { |
|
431 | - return false; |
|
432 | - } |
|
433 | - $basedir = $app['path'].'/'.$appId; |
|
434 | - return file_exists($basedir.'/.git/'); |
|
435 | - } |
|
436 | - |
|
437 | - /** |
|
438 | - * Check if app is already downloaded |
|
439 | - * @param string $name name of the application to remove |
|
440 | - * @return boolean |
|
441 | - * |
|
442 | - * The function will check if the app is already downloaded in the apps repository |
|
443 | - */ |
|
444 | - public function isDownloaded($name) { |
|
445 | - foreach(\OC::$APPSROOTS as $dir) { |
|
446 | - $dirToTest = $dir['path']; |
|
447 | - $dirToTest .= '/'; |
|
448 | - $dirToTest .= $name; |
|
449 | - $dirToTest .= '/'; |
|
450 | - |
|
451 | - if (is_dir($dirToTest)) { |
|
452 | - return true; |
|
453 | - } |
|
454 | - } |
|
455 | - |
|
456 | - return false; |
|
457 | - } |
|
458 | - |
|
459 | - /** |
|
460 | - * Removes an app |
|
461 | - * @param string $appId ID of the application to remove |
|
462 | - * @return boolean |
|
463 | - * |
|
464 | - * |
|
465 | - * This function works as follows |
|
466 | - * -# call uninstall repair steps |
|
467 | - * -# removing the files |
|
468 | - * |
|
469 | - * The function will not delete preferences, tables and the configuration, |
|
470 | - * this has to be done by the function oc_app_uninstall(). |
|
471 | - */ |
|
472 | - public function removeApp($appId) { |
|
473 | - if($this->isDownloaded( $appId )) { |
|
474 | - $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
475 | - OC_Helper::rmdirr($appDir); |
|
476 | - return true; |
|
477 | - }else{ |
|
478 | - \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
|
479 | - |
|
480 | - return false; |
|
481 | - } |
|
482 | - |
|
483 | - } |
|
484 | - |
|
485 | - /** |
|
486 | - * Installs the app within the bundle and marks the bundle as installed |
|
487 | - * |
|
488 | - * @param Bundle $bundle |
|
489 | - * @throws \Exception If app could not get installed |
|
490 | - */ |
|
491 | - public function installAppBundle(Bundle $bundle) { |
|
492 | - $appIds = $bundle->getAppIdentifiers(); |
|
493 | - foreach($appIds as $appId) { |
|
494 | - if(!$this->isDownloaded($appId)) { |
|
495 | - $this->downloadApp($appId); |
|
496 | - } |
|
497 | - $this->installApp($appId); |
|
498 | - $app = new OC_App(); |
|
499 | - $app->enable($appId); |
|
500 | - } |
|
501 | - $bundles = json_decode($this->config->getAppValue('core', 'installed.bundles', json_encode([])), true); |
|
502 | - $bundles[] = $bundle->getIdentifier(); |
|
503 | - $this->config->setAppValue('core', 'installed.bundles', json_encode($bundles)); |
|
504 | - } |
|
505 | - |
|
506 | - /** |
|
507 | - * Installs shipped apps |
|
508 | - * |
|
509 | - * This function installs all apps found in the 'apps' directory that should be enabled by default; |
|
510 | - * @param bool $softErrors When updating we ignore errors and simply log them, better to have a |
|
511 | - * working ownCloud at the end instead of an aborted update. |
|
512 | - * @return array Array of error messages (appid => Exception) |
|
513 | - */ |
|
514 | - public static function installShippedApps($softErrors = false) { |
|
515 | - $errors = []; |
|
516 | - foreach(\OC::$APPSROOTS as $app_dir) { |
|
517 | - if($dir = opendir( $app_dir['path'] )) { |
|
518 | - while( false !== ( $filename = readdir( $dir ))) { |
|
519 | - if( $filename[0] !== '.' and is_dir($app_dir['path']."/$filename") ) { |
|
520 | - if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
521 | - if(!Installer::isInstalled($filename)) { |
|
522 | - $info=OC_App::getAppInfo($filename); |
|
523 | - $enabled = isset($info['default_enable']); |
|
524 | - if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps())) |
|
525 | - && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') { |
|
526 | - if ($softErrors) { |
|
527 | - try { |
|
528 | - Installer::installShippedApp($filename); |
|
529 | - } catch (HintException $e) { |
|
530 | - if ($e->getPrevious() instanceof TableExistsException) { |
|
531 | - $errors[$filename] = $e; |
|
532 | - continue; |
|
533 | - } |
|
534 | - throw $e; |
|
535 | - } |
|
536 | - } else { |
|
537 | - Installer::installShippedApp($filename); |
|
538 | - } |
|
539 | - \OC::$server->getConfig()->setAppValue($filename, 'enabled', 'yes'); |
|
540 | - } |
|
541 | - } |
|
542 | - } |
|
543 | - } |
|
544 | - } |
|
545 | - closedir( $dir ); |
|
546 | - } |
|
547 | - } |
|
548 | - |
|
549 | - return $errors; |
|
550 | - } |
|
551 | - |
|
552 | - /** |
|
553 | - * install an app already placed in the app folder |
|
554 | - * @param string $app id of the app to install |
|
555 | - * @return integer |
|
556 | - */ |
|
557 | - public static function installShippedApp($app) { |
|
558 | - //install the database |
|
559 | - $appPath = OC_App::getAppPath($app); |
|
560 | - \OC_App::registerAutoloading($app, $appPath); |
|
561 | - |
|
562 | - if(is_file("$appPath/appinfo/database.xml")) { |
|
563 | - try { |
|
564 | - OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
|
565 | - } catch (TableExistsException $e) { |
|
566 | - throw new HintException( |
|
567 | - 'Failed to enable app ' . $app, |
|
568 | - 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer noopener">support channels</a>.', |
|
569 | - 0, $e |
|
570 | - ); |
|
571 | - } |
|
572 | - } else { |
|
573 | - $ms = new \OC\DB\MigrationService($app, \OC::$server->getDatabaseConnection()); |
|
574 | - $ms->migrate(); |
|
575 | - } |
|
576 | - |
|
577 | - //run appinfo/install.php |
|
578 | - self::includeAppScript("$appPath/appinfo/install.php"); |
|
579 | - |
|
580 | - $info = OC_App::getAppInfo($app); |
|
581 | - if (is_null($info)) { |
|
582 | - return false; |
|
583 | - } |
|
584 | - \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
585 | - |
|
586 | - OC_App::executeRepairSteps($app, $info['repair-steps']['install']); |
|
587 | - |
|
588 | - $config = \OC::$server->getConfig(); |
|
589 | - |
|
590 | - $config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app)); |
|
591 | - if (array_key_exists('ocsid', $info)) { |
|
592 | - $config->setAppValue($app, 'ocsid', $info['ocsid']); |
|
593 | - } |
|
594 | - |
|
595 | - //set remote/public handlers |
|
596 | - foreach($info['remote'] as $name=>$path) { |
|
597 | - $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
|
598 | - } |
|
599 | - foreach($info['public'] as $name=>$path) { |
|
600 | - $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
|
601 | - } |
|
602 | - |
|
603 | - OC_App::setAppTypes($info['id']); |
|
604 | - |
|
605 | - return $info['id']; |
|
606 | - } |
|
607 | - |
|
608 | - /** |
|
609 | - * @param string $script |
|
610 | - */ |
|
611 | - private static function includeAppScript($script) { |
|
612 | - if ( file_exists($script) ){ |
|
613 | - include $script; |
|
614 | - } |
|
615 | - } |
|
60 | + /** @var AppFetcher */ |
|
61 | + private $appFetcher; |
|
62 | + /** @var IClientService */ |
|
63 | + private $clientService; |
|
64 | + /** @var ITempManager */ |
|
65 | + private $tempManager; |
|
66 | + /** @var ILogger */ |
|
67 | + private $logger; |
|
68 | + /** @var IConfig */ |
|
69 | + private $config; |
|
70 | + /** @var array - for caching the result of app fetcher */ |
|
71 | + private $apps = null; |
|
72 | + /** @var bool|null - for caching the result of the ready status */ |
|
73 | + private $isInstanceReadyForUpdates = null; |
|
74 | + |
|
75 | + /** |
|
76 | + * @param AppFetcher $appFetcher |
|
77 | + * @param IClientService $clientService |
|
78 | + * @param ITempManager $tempManager |
|
79 | + * @param ILogger $logger |
|
80 | + * @param IConfig $config |
|
81 | + */ |
|
82 | + public function __construct(AppFetcher $appFetcher, |
|
83 | + IClientService $clientService, |
|
84 | + ITempManager $tempManager, |
|
85 | + ILogger $logger, |
|
86 | + IConfig $config) { |
|
87 | + $this->appFetcher = $appFetcher; |
|
88 | + $this->clientService = $clientService; |
|
89 | + $this->tempManager = $tempManager; |
|
90 | + $this->logger = $logger; |
|
91 | + $this->config = $config; |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Installs an app that is located in one of the app folders already |
|
96 | + * |
|
97 | + * @param string $appId App to install |
|
98 | + * @throws \Exception |
|
99 | + * @return string app ID |
|
100 | + */ |
|
101 | + public function installApp($appId) { |
|
102 | + $app = \OC_App::findAppInDirectories($appId); |
|
103 | + if($app === false) { |
|
104 | + throw new \Exception('App not found in any app directory'); |
|
105 | + } |
|
106 | + |
|
107 | + $basedir = $app['path'].'/'.$appId; |
|
108 | + $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true); |
|
109 | + |
|
110 | + $l = \OC::$server->getL10N('core'); |
|
111 | + |
|
112 | + if(!is_array($info)) { |
|
113 | + throw new \Exception( |
|
114 | + $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
115 | + [$info['name']] |
|
116 | + ) |
|
117 | + ); |
|
118 | + } |
|
119 | + |
|
120 | + $version = \OCP\Util::getVersion(); |
|
121 | + if (!\OC_App::isAppCompatible($version, $info)) { |
|
122 | + throw new \Exception( |
|
123 | + // TODO $l |
|
124 | + $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
125 | + [$info['name']] |
|
126 | + ) |
|
127 | + ); |
|
128 | + } |
|
129 | + |
|
130 | + // check for required dependencies |
|
131 | + \OC_App::checkAppDependencies($this->config, $l, $info); |
|
132 | + \OC_App::registerAutoloading($appId, $basedir); |
|
133 | + |
|
134 | + //install the database |
|
135 | + if(is_file($basedir.'/appinfo/database.xml')) { |
|
136 | + if (\OC::$server->getConfig()->getAppValue($info['id'], 'installed_version') === null) { |
|
137 | + OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
|
138 | + } else { |
|
139 | + OC_DB::updateDbFromStructure($basedir.'/appinfo/database.xml'); |
|
140 | + } |
|
141 | + } else { |
|
142 | + $ms = new \OC\DB\MigrationService($info['id'], \OC::$server->getDatabaseConnection()); |
|
143 | + $ms->migrate(); |
|
144 | + } |
|
145 | + |
|
146 | + \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
147 | + |
|
148 | + //run appinfo/install.php |
|
149 | + if(!isset($data['noinstall']) or $data['noinstall']==false) { |
|
150 | + self::includeAppScript($basedir . '/appinfo/install.php'); |
|
151 | + } |
|
152 | + |
|
153 | + $appData = OC_App::getAppInfo($appId); |
|
154 | + OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']); |
|
155 | + |
|
156 | + //set the installed version |
|
157 | + \OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'], false)); |
|
158 | + \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
|
159 | + |
|
160 | + //set remote/public handlers |
|
161 | + foreach($info['remote'] as $name=>$path) { |
|
162 | + \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
|
163 | + } |
|
164 | + foreach($info['public'] as $name=>$path) { |
|
165 | + \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
|
166 | + } |
|
167 | + |
|
168 | + OC_App::setAppTypes($info['id']); |
|
169 | + |
|
170 | + return $info['id']; |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * @brief checks whether or not an app is installed |
|
175 | + * @param string $app app |
|
176 | + * @returns bool |
|
177 | + * |
|
178 | + * Checks whether or not an app is installed, i.e. registered in apps table. |
|
179 | + */ |
|
180 | + public static function isInstalled( $app ) { |
|
181 | + return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Updates the specified app from the appstore |
|
186 | + * |
|
187 | + * @param string $appId |
|
188 | + * @return bool |
|
189 | + */ |
|
190 | + public function updateAppstoreApp($appId) { |
|
191 | + if($this->isUpdateAvailable($appId)) { |
|
192 | + try { |
|
193 | + $this->downloadApp($appId); |
|
194 | + } catch (\Exception $e) { |
|
195 | + $this->logger->logException($e, [ |
|
196 | + 'level' => \OCP\Util::ERROR, |
|
197 | + 'app' => 'core', |
|
198 | + ]); |
|
199 | + return false; |
|
200 | + } |
|
201 | + return OC_App::updateApp($appId); |
|
202 | + } |
|
203 | + |
|
204 | + return false; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Downloads an app and puts it into the app directory |
|
209 | + * |
|
210 | + * @param string $appId |
|
211 | + * |
|
212 | + * @throws \Exception If the installation was not successful |
|
213 | + */ |
|
214 | + public function downloadApp($appId) { |
|
215 | + $appId = strtolower($appId); |
|
216 | + |
|
217 | + $apps = $this->appFetcher->get(); |
|
218 | + foreach($apps as $app) { |
|
219 | + if($app['id'] === $appId) { |
|
220 | + // Load the certificate |
|
221 | + $certificate = new X509(); |
|
222 | + $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
223 | + $loadedCertificate = $certificate->loadX509($app['certificate']); |
|
224 | + |
|
225 | + // Verify if the certificate has been revoked |
|
226 | + $crl = new X509(); |
|
227 | + $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
228 | + $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
229 | + if($crl->validateSignature() !== true) { |
|
230 | + throw new \Exception('Could not validate CRL signature'); |
|
231 | + } |
|
232 | + $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
|
233 | + $revoked = $crl->getRevoked($csn); |
|
234 | + if ($revoked !== false) { |
|
235 | + throw new \Exception( |
|
236 | + sprintf( |
|
237 | + 'Certificate "%s" has been revoked', |
|
238 | + $csn |
|
239 | + ) |
|
240 | + ); |
|
241 | + } |
|
242 | + |
|
243 | + // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
|
244 | + if($certificate->validateSignature() !== true) { |
|
245 | + throw new \Exception( |
|
246 | + sprintf( |
|
247 | + 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
|
248 | + $appId |
|
249 | + ) |
|
250 | + ); |
|
251 | + } |
|
252 | + |
|
253 | + // Verify if the certificate is issued for the requested app id |
|
254 | + $certInfo = openssl_x509_parse($app['certificate']); |
|
255 | + if(!isset($certInfo['subject']['CN'])) { |
|
256 | + throw new \Exception( |
|
257 | + sprintf( |
|
258 | + 'App with id %s has a cert with no CN', |
|
259 | + $appId |
|
260 | + ) |
|
261 | + ); |
|
262 | + } |
|
263 | + if($certInfo['subject']['CN'] !== $appId) { |
|
264 | + throw new \Exception( |
|
265 | + sprintf( |
|
266 | + 'App with id %s has a cert issued to %s', |
|
267 | + $appId, |
|
268 | + $certInfo['subject']['CN'] |
|
269 | + ) |
|
270 | + ); |
|
271 | + } |
|
272 | + |
|
273 | + // Download the release |
|
274 | + $tempFile = $this->tempManager->getTemporaryFile('.tar.gz'); |
|
275 | + $client = $this->clientService->newClient(); |
|
276 | + $client->get($app['releases'][0]['download'], ['save_to' => $tempFile]); |
|
277 | + |
|
278 | + // Check if the signature actually matches the downloaded content |
|
279 | + $certificate = openssl_get_publickey($app['certificate']); |
|
280 | + $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
281 | + openssl_free_key($certificate); |
|
282 | + |
|
283 | + if($verified === true) { |
|
284 | + // Seems to match, let's proceed |
|
285 | + $extractDir = $this->tempManager->getTemporaryFolder(); |
|
286 | + $archive = new TAR($tempFile); |
|
287 | + |
|
288 | + if($archive) { |
|
289 | + if (!$archive->extract($extractDir)) { |
|
290 | + throw new \Exception( |
|
291 | + sprintf( |
|
292 | + 'Could not extract app %s', |
|
293 | + $appId |
|
294 | + ) |
|
295 | + ); |
|
296 | + } |
|
297 | + $allFiles = scandir($extractDir); |
|
298 | + $folders = array_diff($allFiles, ['.', '..']); |
|
299 | + $folders = array_values($folders); |
|
300 | + |
|
301 | + if(count($folders) > 1) { |
|
302 | + throw new \Exception( |
|
303 | + sprintf( |
|
304 | + 'Extracted app %s has more than 1 folder', |
|
305 | + $appId |
|
306 | + ) |
|
307 | + ); |
|
308 | + } |
|
309 | + |
|
310 | + // Check if appinfo/info.xml has the same app ID as well |
|
311 | + $loadEntities = libxml_disable_entity_loader(false); |
|
312 | + $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
313 | + libxml_disable_entity_loader($loadEntities); |
|
314 | + if((string)$xml->id !== $appId) { |
|
315 | + throw new \Exception( |
|
316 | + sprintf( |
|
317 | + 'App for id %s has a wrong app ID in info.xml: %s', |
|
318 | + $appId, |
|
319 | + (string)$xml->id |
|
320 | + ) |
|
321 | + ); |
|
322 | + } |
|
323 | + |
|
324 | + // Check if the version is lower than before |
|
325 | + $currentVersion = OC_App::getAppVersion($appId); |
|
326 | + $newVersion = (string)$xml->version; |
|
327 | + if(version_compare($currentVersion, $newVersion) === 1) { |
|
328 | + throw new \Exception( |
|
329 | + sprintf( |
|
330 | + 'App for id %s has version %s and tried to update to lower version %s', |
|
331 | + $appId, |
|
332 | + $currentVersion, |
|
333 | + $newVersion |
|
334 | + ) |
|
335 | + ); |
|
336 | + } |
|
337 | + |
|
338 | + $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
339 | + // Remove old app with the ID if existent |
|
340 | + OC_Helper::rmdirr($baseDir); |
|
341 | + // Move to app folder |
|
342 | + if(@mkdir($baseDir)) { |
|
343 | + $extractDir .= '/' . $folders[0]; |
|
344 | + OC_Helper::copyr($extractDir, $baseDir); |
|
345 | + } |
|
346 | + OC_Helper::copyr($extractDir, $baseDir); |
|
347 | + OC_Helper::rmdirr($extractDir); |
|
348 | + return; |
|
349 | + } else { |
|
350 | + throw new \Exception( |
|
351 | + sprintf( |
|
352 | + 'Could not extract app with ID %s to %s', |
|
353 | + $appId, |
|
354 | + $extractDir |
|
355 | + ) |
|
356 | + ); |
|
357 | + } |
|
358 | + } else { |
|
359 | + // Signature does not match |
|
360 | + throw new \Exception( |
|
361 | + sprintf( |
|
362 | + 'App with id %s has invalid signature', |
|
363 | + $appId |
|
364 | + ) |
|
365 | + ); |
|
366 | + } |
|
367 | + } |
|
368 | + } |
|
369 | + |
|
370 | + throw new \Exception( |
|
371 | + sprintf( |
|
372 | + 'Could not download app %s', |
|
373 | + $appId |
|
374 | + ) |
|
375 | + ); |
|
376 | + } |
|
377 | + |
|
378 | + /** |
|
379 | + * Check if an update for the app is available |
|
380 | + * |
|
381 | + * @param string $appId |
|
382 | + * @return string|false false or the version number of the update |
|
383 | + */ |
|
384 | + public function isUpdateAvailable($appId) { |
|
385 | + if ($this->isInstanceReadyForUpdates === null) { |
|
386 | + $installPath = OC_App::getInstallPath(); |
|
387 | + if ($installPath === false || $installPath === null) { |
|
388 | + $this->isInstanceReadyForUpdates = false; |
|
389 | + } else { |
|
390 | + $this->isInstanceReadyForUpdates = true; |
|
391 | + } |
|
392 | + } |
|
393 | + |
|
394 | + if ($this->isInstanceReadyForUpdates === false) { |
|
395 | + return false; |
|
396 | + } |
|
397 | + |
|
398 | + if ($this->isInstalledFromGit($appId) === true) { |
|
399 | + return false; |
|
400 | + } |
|
401 | + |
|
402 | + if ($this->apps === null) { |
|
403 | + $this->apps = $this->appFetcher->get(); |
|
404 | + } |
|
405 | + |
|
406 | + foreach($this->apps as $app) { |
|
407 | + if($app['id'] === $appId) { |
|
408 | + $currentVersion = OC_App::getAppVersion($appId); |
|
409 | + $newestVersion = $app['releases'][0]['version']; |
|
410 | + if (version_compare($newestVersion, $currentVersion, '>')) { |
|
411 | + return $newestVersion; |
|
412 | + } else { |
|
413 | + return false; |
|
414 | + } |
|
415 | + } |
|
416 | + } |
|
417 | + |
|
418 | + return false; |
|
419 | + } |
|
420 | + |
|
421 | + /** |
|
422 | + * Check if app has been installed from git |
|
423 | + * @param string $name name of the application to remove |
|
424 | + * @return boolean |
|
425 | + * |
|
426 | + * The function will check if the path contains a .git folder |
|
427 | + */ |
|
428 | + private function isInstalledFromGit($appId) { |
|
429 | + $app = \OC_App::findAppInDirectories($appId); |
|
430 | + if($app === false) { |
|
431 | + return false; |
|
432 | + } |
|
433 | + $basedir = $app['path'].'/'.$appId; |
|
434 | + return file_exists($basedir.'/.git/'); |
|
435 | + } |
|
436 | + |
|
437 | + /** |
|
438 | + * Check if app is already downloaded |
|
439 | + * @param string $name name of the application to remove |
|
440 | + * @return boolean |
|
441 | + * |
|
442 | + * The function will check if the app is already downloaded in the apps repository |
|
443 | + */ |
|
444 | + public function isDownloaded($name) { |
|
445 | + foreach(\OC::$APPSROOTS as $dir) { |
|
446 | + $dirToTest = $dir['path']; |
|
447 | + $dirToTest .= '/'; |
|
448 | + $dirToTest .= $name; |
|
449 | + $dirToTest .= '/'; |
|
450 | + |
|
451 | + if (is_dir($dirToTest)) { |
|
452 | + return true; |
|
453 | + } |
|
454 | + } |
|
455 | + |
|
456 | + return false; |
|
457 | + } |
|
458 | + |
|
459 | + /** |
|
460 | + * Removes an app |
|
461 | + * @param string $appId ID of the application to remove |
|
462 | + * @return boolean |
|
463 | + * |
|
464 | + * |
|
465 | + * This function works as follows |
|
466 | + * -# call uninstall repair steps |
|
467 | + * -# removing the files |
|
468 | + * |
|
469 | + * The function will not delete preferences, tables and the configuration, |
|
470 | + * this has to be done by the function oc_app_uninstall(). |
|
471 | + */ |
|
472 | + public function removeApp($appId) { |
|
473 | + if($this->isDownloaded( $appId )) { |
|
474 | + $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
475 | + OC_Helper::rmdirr($appDir); |
|
476 | + return true; |
|
477 | + }else{ |
|
478 | + \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
|
479 | + |
|
480 | + return false; |
|
481 | + } |
|
482 | + |
|
483 | + } |
|
484 | + |
|
485 | + /** |
|
486 | + * Installs the app within the bundle and marks the bundle as installed |
|
487 | + * |
|
488 | + * @param Bundle $bundle |
|
489 | + * @throws \Exception If app could not get installed |
|
490 | + */ |
|
491 | + public function installAppBundle(Bundle $bundle) { |
|
492 | + $appIds = $bundle->getAppIdentifiers(); |
|
493 | + foreach($appIds as $appId) { |
|
494 | + if(!$this->isDownloaded($appId)) { |
|
495 | + $this->downloadApp($appId); |
|
496 | + } |
|
497 | + $this->installApp($appId); |
|
498 | + $app = new OC_App(); |
|
499 | + $app->enable($appId); |
|
500 | + } |
|
501 | + $bundles = json_decode($this->config->getAppValue('core', 'installed.bundles', json_encode([])), true); |
|
502 | + $bundles[] = $bundle->getIdentifier(); |
|
503 | + $this->config->setAppValue('core', 'installed.bundles', json_encode($bundles)); |
|
504 | + } |
|
505 | + |
|
506 | + /** |
|
507 | + * Installs shipped apps |
|
508 | + * |
|
509 | + * This function installs all apps found in the 'apps' directory that should be enabled by default; |
|
510 | + * @param bool $softErrors When updating we ignore errors and simply log them, better to have a |
|
511 | + * working ownCloud at the end instead of an aborted update. |
|
512 | + * @return array Array of error messages (appid => Exception) |
|
513 | + */ |
|
514 | + public static function installShippedApps($softErrors = false) { |
|
515 | + $errors = []; |
|
516 | + foreach(\OC::$APPSROOTS as $app_dir) { |
|
517 | + if($dir = opendir( $app_dir['path'] )) { |
|
518 | + while( false !== ( $filename = readdir( $dir ))) { |
|
519 | + if( $filename[0] !== '.' and is_dir($app_dir['path']."/$filename") ) { |
|
520 | + if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
521 | + if(!Installer::isInstalled($filename)) { |
|
522 | + $info=OC_App::getAppInfo($filename); |
|
523 | + $enabled = isset($info['default_enable']); |
|
524 | + if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps())) |
|
525 | + && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') { |
|
526 | + if ($softErrors) { |
|
527 | + try { |
|
528 | + Installer::installShippedApp($filename); |
|
529 | + } catch (HintException $e) { |
|
530 | + if ($e->getPrevious() instanceof TableExistsException) { |
|
531 | + $errors[$filename] = $e; |
|
532 | + continue; |
|
533 | + } |
|
534 | + throw $e; |
|
535 | + } |
|
536 | + } else { |
|
537 | + Installer::installShippedApp($filename); |
|
538 | + } |
|
539 | + \OC::$server->getConfig()->setAppValue($filename, 'enabled', 'yes'); |
|
540 | + } |
|
541 | + } |
|
542 | + } |
|
543 | + } |
|
544 | + } |
|
545 | + closedir( $dir ); |
|
546 | + } |
|
547 | + } |
|
548 | + |
|
549 | + return $errors; |
|
550 | + } |
|
551 | + |
|
552 | + /** |
|
553 | + * install an app already placed in the app folder |
|
554 | + * @param string $app id of the app to install |
|
555 | + * @return integer |
|
556 | + */ |
|
557 | + public static function installShippedApp($app) { |
|
558 | + //install the database |
|
559 | + $appPath = OC_App::getAppPath($app); |
|
560 | + \OC_App::registerAutoloading($app, $appPath); |
|
561 | + |
|
562 | + if(is_file("$appPath/appinfo/database.xml")) { |
|
563 | + try { |
|
564 | + OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
|
565 | + } catch (TableExistsException $e) { |
|
566 | + throw new HintException( |
|
567 | + 'Failed to enable app ' . $app, |
|
568 | + 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer noopener">support channels</a>.', |
|
569 | + 0, $e |
|
570 | + ); |
|
571 | + } |
|
572 | + } else { |
|
573 | + $ms = new \OC\DB\MigrationService($app, \OC::$server->getDatabaseConnection()); |
|
574 | + $ms->migrate(); |
|
575 | + } |
|
576 | + |
|
577 | + //run appinfo/install.php |
|
578 | + self::includeAppScript("$appPath/appinfo/install.php"); |
|
579 | + |
|
580 | + $info = OC_App::getAppInfo($app); |
|
581 | + if (is_null($info)) { |
|
582 | + return false; |
|
583 | + } |
|
584 | + \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
585 | + |
|
586 | + OC_App::executeRepairSteps($app, $info['repair-steps']['install']); |
|
587 | + |
|
588 | + $config = \OC::$server->getConfig(); |
|
589 | + |
|
590 | + $config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app)); |
|
591 | + if (array_key_exists('ocsid', $info)) { |
|
592 | + $config->setAppValue($app, 'ocsid', $info['ocsid']); |
|
593 | + } |
|
594 | + |
|
595 | + //set remote/public handlers |
|
596 | + foreach($info['remote'] as $name=>$path) { |
|
597 | + $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
|
598 | + } |
|
599 | + foreach($info['public'] as $name=>$path) { |
|
600 | + $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
|
601 | + } |
|
602 | + |
|
603 | + OC_App::setAppTypes($info['id']); |
|
604 | + |
|
605 | + return $info['id']; |
|
606 | + } |
|
607 | + |
|
608 | + /** |
|
609 | + * @param string $script |
|
610 | + */ |
|
611 | + private static function includeAppScript($script) { |
|
612 | + if ( file_exists($script) ){ |
|
613 | + include $script; |
|
614 | + } |
|
615 | + } |
|
616 | 616 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public function installApp($appId) { |
102 | 102 | $app = \OC_App::findAppInDirectories($appId); |
103 | - if($app === false) { |
|
103 | + if ($app === false) { |
|
104 | 104 | throw new \Exception('App not found in any app directory'); |
105 | 105 | } |
106 | 106 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | |
110 | 110 | $l = \OC::$server->getL10N('core'); |
111 | 111 | |
112 | - if(!is_array($info)) { |
|
112 | + if (!is_array($info)) { |
|
113 | 113 | throw new \Exception( |
114 | 114 | $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
115 | 115 | [$info['name']] |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | \OC_App::registerAutoloading($appId, $basedir); |
133 | 133 | |
134 | 134 | //install the database |
135 | - if(is_file($basedir.'/appinfo/database.xml')) { |
|
135 | + if (is_file($basedir.'/appinfo/database.xml')) { |
|
136 | 136 | if (\OC::$server->getConfig()->getAppValue($info['id'], 'installed_version') === null) { |
137 | 137 | OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
138 | 138 | } else { |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | \OC_App::setupBackgroundJobs($info['background-jobs']); |
147 | 147 | |
148 | 148 | //run appinfo/install.php |
149 | - if(!isset($data['noinstall']) or $data['noinstall']==false) { |
|
150 | - self::includeAppScript($basedir . '/appinfo/install.php'); |
|
149 | + if (!isset($data['noinstall']) or $data['noinstall'] == false) { |
|
150 | + self::includeAppScript($basedir.'/appinfo/install.php'); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | $appData = OC_App::getAppInfo($appId); |
@@ -158,10 +158,10 @@ discard block |
||
158 | 158 | \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
159 | 159 | |
160 | 160 | //set remote/public handlers |
161 | - foreach($info['remote'] as $name=>$path) { |
|
161 | + foreach ($info['remote'] as $name=>$path) { |
|
162 | 162 | \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
163 | 163 | } |
164 | - foreach($info['public'] as $name=>$path) { |
|
164 | + foreach ($info['public'] as $name=>$path) { |
|
165 | 165 | \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
166 | 166 | } |
167 | 167 | |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | * |
178 | 178 | * Checks whether or not an app is installed, i.e. registered in apps table. |
179 | 179 | */ |
180 | - public static function isInstalled( $app ) { |
|
180 | + public static function isInstalled($app) { |
|
181 | 181 | return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null); |
182 | 182 | } |
183 | 183 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @return bool |
189 | 189 | */ |
190 | 190 | public function updateAppstoreApp($appId) { |
191 | - if($this->isUpdateAvailable($appId)) { |
|
191 | + if ($this->isUpdateAvailable($appId)) { |
|
192 | 192 | try { |
193 | 193 | $this->downloadApp($appId); |
194 | 194 | } catch (\Exception $e) { |
@@ -215,18 +215,18 @@ discard block |
||
215 | 215 | $appId = strtolower($appId); |
216 | 216 | |
217 | 217 | $apps = $this->appFetcher->get(); |
218 | - foreach($apps as $app) { |
|
219 | - if($app['id'] === $appId) { |
|
218 | + foreach ($apps as $app) { |
|
219 | + if ($app['id'] === $appId) { |
|
220 | 220 | // Load the certificate |
221 | 221 | $certificate = new X509(); |
222 | - $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
222 | + $certificate->loadCA(file_get_contents(__DIR__.'/../../resources/codesigning/root.crt')); |
|
223 | 223 | $loadedCertificate = $certificate->loadX509($app['certificate']); |
224 | 224 | |
225 | 225 | // Verify if the certificate has been revoked |
226 | 226 | $crl = new X509(); |
227 | - $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
228 | - $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
229 | - if($crl->validateSignature() !== true) { |
|
227 | + $crl->loadCA(file_get_contents(__DIR__.'/../../resources/codesigning/root.crt')); |
|
228 | + $crl->loadCRL(file_get_contents(__DIR__.'/../../resources/codesigning/root.crl')); |
|
229 | + if ($crl->validateSignature() !== true) { |
|
230 | 230 | throw new \Exception('Could not validate CRL signature'); |
231 | 231 | } |
232 | 232 | $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | } |
242 | 242 | |
243 | 243 | // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
244 | - if($certificate->validateSignature() !== true) { |
|
244 | + if ($certificate->validateSignature() !== true) { |
|
245 | 245 | throw new \Exception( |
246 | 246 | sprintf( |
247 | 247 | 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | |
253 | 253 | // Verify if the certificate is issued for the requested app id |
254 | 254 | $certInfo = openssl_x509_parse($app['certificate']); |
255 | - if(!isset($certInfo['subject']['CN'])) { |
|
255 | + if (!isset($certInfo['subject']['CN'])) { |
|
256 | 256 | throw new \Exception( |
257 | 257 | sprintf( |
258 | 258 | 'App with id %s has a cert with no CN', |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | ) |
261 | 261 | ); |
262 | 262 | } |
263 | - if($certInfo['subject']['CN'] !== $appId) { |
|
263 | + if ($certInfo['subject']['CN'] !== $appId) { |
|
264 | 264 | throw new \Exception( |
265 | 265 | sprintf( |
266 | 266 | 'App with id %s has a cert issued to %s', |
@@ -277,15 +277,15 @@ discard block |
||
277 | 277 | |
278 | 278 | // Check if the signature actually matches the downloaded content |
279 | 279 | $certificate = openssl_get_publickey($app['certificate']); |
280 | - $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
280 | + $verified = (bool) openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
281 | 281 | openssl_free_key($certificate); |
282 | 282 | |
283 | - if($verified === true) { |
|
283 | + if ($verified === true) { |
|
284 | 284 | // Seems to match, let's proceed |
285 | 285 | $extractDir = $this->tempManager->getTemporaryFolder(); |
286 | 286 | $archive = new TAR($tempFile); |
287 | 287 | |
288 | - if($archive) { |
|
288 | + if ($archive) { |
|
289 | 289 | if (!$archive->extract($extractDir)) { |
290 | 290 | throw new \Exception( |
291 | 291 | sprintf( |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | $folders = array_diff($allFiles, ['.', '..']); |
299 | 299 | $folders = array_values($folders); |
300 | 300 | |
301 | - if(count($folders) > 1) { |
|
301 | + if (count($folders) > 1) { |
|
302 | 302 | throw new \Exception( |
303 | 303 | sprintf( |
304 | 304 | 'Extracted app %s has more than 1 folder', |
@@ -309,22 +309,22 @@ discard block |
||
309 | 309 | |
310 | 310 | // Check if appinfo/info.xml has the same app ID as well |
311 | 311 | $loadEntities = libxml_disable_entity_loader(false); |
312 | - $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
312 | + $xml = simplexml_load_file($extractDir.'/'.$folders[0].'/appinfo/info.xml'); |
|
313 | 313 | libxml_disable_entity_loader($loadEntities); |
314 | - if((string)$xml->id !== $appId) { |
|
314 | + if ((string) $xml->id !== $appId) { |
|
315 | 315 | throw new \Exception( |
316 | 316 | sprintf( |
317 | 317 | 'App for id %s has a wrong app ID in info.xml: %s', |
318 | 318 | $appId, |
319 | - (string)$xml->id |
|
319 | + (string) $xml->id |
|
320 | 320 | ) |
321 | 321 | ); |
322 | 322 | } |
323 | 323 | |
324 | 324 | // Check if the version is lower than before |
325 | 325 | $currentVersion = OC_App::getAppVersion($appId); |
326 | - $newVersion = (string)$xml->version; |
|
327 | - if(version_compare($currentVersion, $newVersion) === 1) { |
|
326 | + $newVersion = (string) $xml->version; |
|
327 | + if (version_compare($currentVersion, $newVersion) === 1) { |
|
328 | 328 | throw new \Exception( |
329 | 329 | sprintf( |
330 | 330 | 'App for id %s has version %s and tried to update to lower version %s', |
@@ -335,12 +335,12 @@ discard block |
||
335 | 335 | ); |
336 | 336 | } |
337 | 337 | |
338 | - $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
338 | + $baseDir = OC_App::getInstallPath().'/'.$appId; |
|
339 | 339 | // Remove old app with the ID if existent |
340 | 340 | OC_Helper::rmdirr($baseDir); |
341 | 341 | // Move to app folder |
342 | - if(@mkdir($baseDir)) { |
|
343 | - $extractDir .= '/' . $folders[0]; |
|
342 | + if (@mkdir($baseDir)) { |
|
343 | + $extractDir .= '/'.$folders[0]; |
|
344 | 344 | OC_Helper::copyr($extractDir, $baseDir); |
345 | 345 | } |
346 | 346 | OC_Helper::copyr($extractDir, $baseDir); |
@@ -403,8 +403,8 @@ discard block |
||
403 | 403 | $this->apps = $this->appFetcher->get(); |
404 | 404 | } |
405 | 405 | |
406 | - foreach($this->apps as $app) { |
|
407 | - if($app['id'] === $appId) { |
|
406 | + foreach ($this->apps as $app) { |
|
407 | + if ($app['id'] === $appId) { |
|
408 | 408 | $currentVersion = OC_App::getAppVersion($appId); |
409 | 409 | $newestVersion = $app['releases'][0]['version']; |
410 | 410 | if (version_compare($newestVersion, $currentVersion, '>')) { |
@@ -427,7 +427,7 @@ discard block |
||
427 | 427 | */ |
428 | 428 | private function isInstalledFromGit($appId) { |
429 | 429 | $app = \OC_App::findAppInDirectories($appId); |
430 | - if($app === false) { |
|
430 | + if ($app === false) { |
|
431 | 431 | return false; |
432 | 432 | } |
433 | 433 | $basedir = $app['path'].'/'.$appId; |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | * The function will check if the app is already downloaded in the apps repository |
443 | 443 | */ |
444 | 444 | public function isDownloaded($name) { |
445 | - foreach(\OC::$APPSROOTS as $dir) { |
|
445 | + foreach (\OC::$APPSROOTS as $dir) { |
|
446 | 446 | $dirToTest = $dir['path']; |
447 | 447 | $dirToTest .= '/'; |
448 | 448 | $dirToTest .= $name; |
@@ -470,11 +470,11 @@ discard block |
||
470 | 470 | * this has to be done by the function oc_app_uninstall(). |
471 | 471 | */ |
472 | 472 | public function removeApp($appId) { |
473 | - if($this->isDownloaded( $appId )) { |
|
474 | - $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
473 | + if ($this->isDownloaded($appId)) { |
|
474 | + $appDir = OC_App::getInstallPath().'/'.$appId; |
|
475 | 475 | OC_Helper::rmdirr($appDir); |
476 | 476 | return true; |
477 | - }else{ |
|
477 | + } else { |
|
478 | 478 | \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
479 | 479 | |
480 | 480 | return false; |
@@ -490,8 +490,8 @@ discard block |
||
490 | 490 | */ |
491 | 491 | public function installAppBundle(Bundle $bundle) { |
492 | 492 | $appIds = $bundle->getAppIdentifiers(); |
493 | - foreach($appIds as $appId) { |
|
494 | - if(!$this->isDownloaded($appId)) { |
|
493 | + foreach ($appIds as $appId) { |
|
494 | + if (!$this->isDownloaded($appId)) { |
|
495 | 495 | $this->downloadApp($appId); |
496 | 496 | } |
497 | 497 | $this->installApp($appId); |
@@ -513,13 +513,13 @@ discard block |
||
513 | 513 | */ |
514 | 514 | public static function installShippedApps($softErrors = false) { |
515 | 515 | $errors = []; |
516 | - foreach(\OC::$APPSROOTS as $app_dir) { |
|
517 | - if($dir = opendir( $app_dir['path'] )) { |
|
518 | - while( false !== ( $filename = readdir( $dir ))) { |
|
519 | - if( $filename[0] !== '.' and is_dir($app_dir['path']."/$filename") ) { |
|
520 | - if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
521 | - if(!Installer::isInstalled($filename)) { |
|
522 | - $info=OC_App::getAppInfo($filename); |
|
516 | + foreach (\OC::$APPSROOTS as $app_dir) { |
|
517 | + if ($dir = opendir($app_dir['path'])) { |
|
518 | + while (false !== ($filename = readdir($dir))) { |
|
519 | + if ($filename[0] !== '.' and is_dir($app_dir['path']."/$filename")) { |
|
520 | + if (file_exists($app_dir['path']."/$filename/appinfo/info.xml")) { |
|
521 | + if (!Installer::isInstalled($filename)) { |
|
522 | + $info = OC_App::getAppInfo($filename); |
|
523 | 523 | $enabled = isset($info['default_enable']); |
524 | 524 | if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps())) |
525 | 525 | && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') { |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | } |
543 | 543 | } |
544 | 544 | } |
545 | - closedir( $dir ); |
|
545 | + closedir($dir); |
|
546 | 546 | } |
547 | 547 | } |
548 | 548 | |
@@ -559,12 +559,12 @@ discard block |
||
559 | 559 | $appPath = OC_App::getAppPath($app); |
560 | 560 | \OC_App::registerAutoloading($app, $appPath); |
561 | 561 | |
562 | - if(is_file("$appPath/appinfo/database.xml")) { |
|
562 | + if (is_file("$appPath/appinfo/database.xml")) { |
|
563 | 563 | try { |
564 | 564 | OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
565 | 565 | } catch (TableExistsException $e) { |
566 | 566 | throw new HintException( |
567 | - 'Failed to enable app ' . $app, |
|
567 | + 'Failed to enable app '.$app, |
|
568 | 568 | 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer noopener">support channels</a>.', |
569 | 569 | 0, $e |
570 | 570 | ); |
@@ -593,10 +593,10 @@ discard block |
||
593 | 593 | } |
594 | 594 | |
595 | 595 | //set remote/public handlers |
596 | - foreach($info['remote'] as $name=>$path) { |
|
596 | + foreach ($info['remote'] as $name=>$path) { |
|
597 | 597 | $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
598 | 598 | } |
599 | - foreach($info['public'] as $name=>$path) { |
|
599 | + foreach ($info['public'] as $name=>$path) { |
|
600 | 600 | $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
601 | 601 | } |
602 | 602 | |
@@ -609,7 +609,7 @@ discard block |
||
609 | 609 | * @param string $script |
610 | 610 | */ |
611 | 611 | private static function includeAppScript($script) { |
612 | - if ( file_exists($script) ){ |
|
612 | + if (file_exists($script)) { |
|
613 | 613 | include $script; |
614 | 614 | } |
615 | 615 | } |