Server.php 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. * @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
  5. *
  6. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  7. * @author Bart Visscher <bartv@thisnet.nl>
  8. * @author Bernhard Posselt <dev@bernhard-posselt.com>
  9. * @author Bernhard Reiter <ockham@raz.or.at>
  10. * @author Bjoern Schiessle <bjoern@schiessle.org>
  11. * @author Björn Schießle <bjoern@schiessle.org>
  12. * @author Christopher Schäpers <kondou@ts.unde.re>
  13. * @author Christoph Wurst <christoph@owncloud.com>
  14. * @author Joas Schilling <coding@schilljs.com>
  15. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  16. * @author Lukas Reschke <lukas@statuscode.ch>
  17. * @author Morris Jobke <hey@morrisjobke.de>
  18. * @author Robin Appelman <robin@icewind.nl>
  19. * @author Robin McCorkell <robin@mccorkell.me.uk>
  20. * @author Roeland Jago Douma <roeland@famdouma.nl>
  21. * @author Sander <brantje@gmail.com>
  22. * @author Thomas Müller <thomas.mueller@tmit.eu>
  23. * @author Thomas Tanghus <thomas@tanghus.net>
  24. * @author Vincent Petry <pvince81@owncloud.com>
  25. * @author Roger Szabo <roger.szabo@web.de>
  26. *
  27. * @license AGPL-3.0
  28. *
  29. * This code is free software: you can redistribute it and/or modify
  30. * it under the terms of the GNU Affero General Public License, version 3,
  31. * as published by the Free Software Foundation.
  32. *
  33. * This program is distributed in the hope that it will be useful,
  34. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  35. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  36. * GNU Affero General Public License for more details.
  37. *
  38. * You should have received a copy of the GNU Affero General Public License, version 3,
  39. * along with this program. If not, see <http://www.gnu.org/licenses/>
  40. *
  41. */
  42. namespace OC;
  43. use bantu\IniGetWrapper\IniGetWrapper;
  44. use OC\App\AppStore\Fetcher\AppFetcher;
  45. use OC\App\AppStore\Fetcher\CategoryFetcher;
  46. use OC\AppFramework\Http\Request;
  47. use OC\AppFramework\Utility\TimeFactory;
  48. use OC\Command\AsyncBus;
  49. use OC\Diagnostics\EventLogger;
  50. use OC\Diagnostics\NullEventLogger;
  51. use OC\Diagnostics\NullQueryLogger;
  52. use OC\Diagnostics\QueryLogger;
  53. use OC\Files\Config\UserMountCache;
  54. use OC\Files\Config\UserMountCacheListener;
  55. use OC\Files\Mount\CacheMountProvider;
  56. use OC\Files\Mount\LocalHomeMountProvider;
  57. use OC\Files\Mount\ObjectHomeMountProvider;
  58. use OC\Files\Node\HookConnector;
  59. use OC\Files\Node\LazyRoot;
  60. use OC\Files\Node\Root;
  61. use OC\Files\View;
  62. use OC\Http\Client\ClientService;
  63. use OC\IntegrityCheck\Checker;
  64. use OC\IntegrityCheck\Helpers\AppLocator;
  65. use OC\IntegrityCheck\Helpers\EnvironmentHelper;
  66. use OC\IntegrityCheck\Helpers\FileAccessHelper;
  67. use OC\Lock\DBLockingProvider;
  68. use OC\Lock\MemcacheLockingProvider;
  69. use OC\Lock\NoopLockingProvider;
  70. use OC\Lockdown\LockdownManager;
  71. use OC\Mail\Mailer;
  72. use OC\Memcache\ArrayCache;
  73. use OC\Notification\Manager;
  74. use OC\Repair\NC11\CleanPreviewsBackgroundJob;
  75. use OC\RichObjectStrings\Validator;
  76. use OC\Security\Bruteforce\Throttler;
  77. use OC\Security\CertificateManager;
  78. use OC\Security\CSP\ContentSecurityPolicyManager;
  79. use OC\Security\Crypto;
  80. use OC\Security\CSP\ContentSecurityPolicyNonceManager;
  81. use OC\Security\CSRF\CsrfTokenGenerator;
  82. use OC\Security\CSRF\CsrfTokenManager;
  83. use OC\Security\CSRF\TokenStorage\SessionStorage;
  84. use OC\Security\Hasher;
  85. use OC\Security\CredentialsManager;
  86. use OC\Security\SecureRandom;
  87. use OC\Security\TrustedDomainHelper;
  88. use OC\Session\CryptoWrapper;
  89. use OC\Tagging\TagMapper;
  90. use OCA\Theming\ThemingDefaults;
  91. use OCP\IL10N;
  92. use OCP\IServerContainer;
  93. use OCP\RichObjectStrings\IValidator;
  94. use OCP\Security\IContentSecurityPolicyManager;
  95. use Symfony\Component\EventDispatcher\EventDispatcher;
  96. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  97. /**
  98. * Class Server
  99. *
  100. * @package OC
  101. *
  102. * TODO: hookup all manager classes
  103. */
  104. class Server extends ServerContainer implements IServerContainer {
  105. /** @var string */
  106. private $webRoot;
  107. /**
  108. * @param string $webRoot
  109. * @param \OC\Config $config
  110. */
  111. public function __construct($webRoot, \OC\Config $config) {
  112. parent::__construct();
  113. $this->webRoot = $webRoot;
  114. $this->registerService('ContactsManager', function ($c) {
  115. return new ContactsManager();
  116. });
  117. $this->registerService('PreviewManager', function (Server $c) {
  118. return new PreviewManager(
  119. $c->getConfig(),
  120. $c->getRootFolder(),
  121. $c->getAppDataDir('preview'),
  122. $c->getEventDispatcher()
  123. );
  124. });
  125. $this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
  126. return new \OC\Preview\Watcher(
  127. $c->getAppDataDir('preview')
  128. );
  129. });
  130. $this->registerService('EncryptionManager', function (Server $c) {
  131. $view = new View();
  132. $util = new Encryption\Util(
  133. $view,
  134. $c->getUserManager(),
  135. $c->getGroupManager(),
  136. $c->getConfig()
  137. );
  138. return new Encryption\Manager(
  139. $c->getConfig(),
  140. $c->getLogger(),
  141. $c->getL10N('core'),
  142. new View(),
  143. $util,
  144. new ArrayCache()
  145. );
  146. });
  147. $this->registerService('EncryptionFileHelper', function (Server $c) {
  148. $util = new Encryption\Util(
  149. new View(),
  150. $c->getUserManager(),
  151. $c->getGroupManager(),
  152. $c->getConfig()
  153. );
  154. return new Encryption\File($util);
  155. });
  156. $this->registerService('EncryptionKeyStorage', function (Server $c) {
  157. $view = new View();
  158. $util = new Encryption\Util(
  159. $view,
  160. $c->getUserManager(),
  161. $c->getGroupManager(),
  162. $c->getConfig()
  163. );
  164. return new Encryption\Keys\Storage($view, $util);
  165. });
  166. $this->registerService('TagMapper', function (Server $c) {
  167. return new TagMapper($c->getDatabaseConnection());
  168. });
  169. $this->registerService('TagManager', function (Server $c) {
  170. $tagMapper = $c->query('TagMapper');
  171. return new TagManager($tagMapper, $c->getUserSession());
  172. });
  173. $this->registerService('SystemTagManagerFactory', function (Server $c) {
  174. $config = $c->getConfig();
  175. $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
  176. /** @var \OC\SystemTag\ManagerFactory $factory */
  177. $factory = new $factoryClass($this);
  178. return $factory;
  179. });
  180. $this->registerService('SystemTagManager', function (Server $c) {
  181. return $c->query('SystemTagManagerFactory')->getManager();
  182. });
  183. $this->registerService('SystemTagObjectMapper', function (Server $c) {
  184. return $c->query('SystemTagManagerFactory')->getObjectMapper();
  185. });
  186. $this->registerService('RootFolder', function (Server $c) {
  187. $manager = \OC\Files\Filesystem::getMountManager(null);
  188. $view = new View();
  189. $root = new Root(
  190. $manager,
  191. $view,
  192. null,
  193. $c->getUserMountCache(),
  194. $this->getLogger(),
  195. $this->getUserManager()
  196. );
  197. $connector = new HookConnector($root, $view);
  198. $connector->viewToNode();
  199. $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
  200. $previewConnector->connectWatcher();
  201. return $root;
  202. });
  203. $this->registerService('LazyRootFolder', function(Server $c) {
  204. return new LazyRoot(function() use ($c) {
  205. return $c->query('RootFolder');
  206. });
  207. });
  208. $this->registerService('UserManager', function (Server $c) {
  209. $config = $c->getConfig();
  210. return new \OC\User\Manager($config);
  211. });
  212. $this->registerService('GroupManager', function (Server $c) {
  213. $groupManager = new \OC\Group\Manager($this->getUserManager());
  214. $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
  215. \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
  216. });
  217. $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
  218. \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
  219. });
  220. $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
  221. \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
  222. });
  223. $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
  224. \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
  225. });
  226. $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
  227. \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
  228. });
  229. $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
  230. \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
  231. //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
  232. \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
  233. });
  234. return $groupManager;
  235. });
  236. $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
  237. $dbConnection = $c->getDatabaseConnection();
  238. return new Authentication\Token\DefaultTokenMapper($dbConnection);
  239. });
  240. $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
  241. $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
  242. $crypto = $c->getCrypto();
  243. $config = $c->getConfig();
  244. $logger = $c->getLogger();
  245. $timeFactory = new TimeFactory();
  246. return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
  247. });
  248. $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
  249. $this->registerService('UserSession', function (Server $c) {
  250. $manager = $c->getUserManager();
  251. $session = new \OC\Session\Memory('');
  252. $timeFactory = new TimeFactory();
  253. // Token providers might require a working database. This code
  254. // might however be called when ownCloud is not yet setup.
  255. if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
  256. $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider');
  257. } else {
  258. $defaultTokenProvider = null;
  259. }
  260. $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom());
  261. $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
  262. \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
  263. });
  264. $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
  265. /** @var $user \OC\User\User */
  266. \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
  267. });
  268. $userSession->listen('\OC\User', 'preDelete', function ($user) {
  269. /** @var $user \OC\User\User */
  270. \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
  271. });
  272. $userSession->listen('\OC\User', 'postDelete', function ($user) {
  273. /** @var $user \OC\User\User */
  274. \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
  275. });
  276. $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
  277. /** @var $user \OC\User\User */
  278. \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
  279. });
  280. $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
  281. /** @var $user \OC\User\User */
  282. \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
  283. });
  284. $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
  285. \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
  286. });
  287. $userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
  288. /** @var $user \OC\User\User */
  289. \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
  290. });
  291. $userSession->listen('\OC\User', 'logout', function () {
  292. \OC_Hook::emit('OC_User', 'logout', array());
  293. });
  294. $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) {
  295. /** @var $user \OC\User\User */
  296. \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value));
  297. });
  298. return $userSession;
  299. });
  300. $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
  301. return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
  302. });
  303. $this->registerService('NavigationManager', function ($c) {
  304. return new \OC\NavigationManager();
  305. });
  306. $this->registerService('AllConfig', function (Server $c) {
  307. return new \OC\AllConfig(
  308. $c->getSystemConfig()
  309. );
  310. });
  311. $this->registerService('SystemConfig', function ($c) use ($config) {
  312. return new \OC\SystemConfig($config);
  313. });
  314. $this->registerService('AppConfig', function (Server $c) {
  315. return new \OC\AppConfig($c->getDatabaseConnection());
  316. });
  317. $this->registerService('L10NFactory', function (Server $c) {
  318. return new \OC\L10N\Factory(
  319. $c->getConfig(),
  320. $c->getRequest(),
  321. $c->getUserSession(),
  322. \OC::$SERVERROOT
  323. );
  324. });
  325. $this->registerService('URLGenerator', function (Server $c) {
  326. $config = $c->getConfig();
  327. $cacheFactory = $c->getMemCacheFactory();
  328. return new \OC\URLGenerator(
  329. $config,
  330. $cacheFactory
  331. );
  332. });
  333. $this->registerService('AppHelper', function ($c) {
  334. return new \OC\AppHelper();
  335. });
  336. $this->registerService('AppFetcher', function ($c) {
  337. return new AppFetcher(
  338. $this->getAppDataDir('appstore'),
  339. $this->getHTTPClientService(),
  340. $this->query(TimeFactory::class),
  341. $this->getConfig()
  342. );
  343. });
  344. $this->registerService('CategoryFetcher', function ($c) {
  345. return new CategoryFetcher(
  346. $this->getAppDataDir('appstore'),
  347. $this->getHTTPClientService(),
  348. $this->query(TimeFactory::class),
  349. $this->getConfig()
  350. );
  351. });
  352. $this->registerService('UserCache', function ($c) {
  353. return new Cache\File();
  354. });
  355. $this->registerService('MemCacheFactory', function (Server $c) {
  356. $config = $c->getConfig();
  357. if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
  358. $v = \OC_App::getAppVersions();
  359. $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
  360. $version = implode(',', $v);
  361. $instanceId = \OC_Util::getInstanceId();
  362. $path = \OC::$SERVERROOT;
  363. $prefix = md5($instanceId . '-' . $version . '-' . $path);
  364. return new \OC\Memcache\Factory($prefix, $c->getLogger(),
  365. $config->getSystemValue('memcache.local', null),
  366. $config->getSystemValue('memcache.distributed', null),
  367. $config->getSystemValue('memcache.locking', null)
  368. );
  369. }
  370. return new \OC\Memcache\Factory('', $c->getLogger(),
  371. '\\OC\\Memcache\\ArrayCache',
  372. '\\OC\\Memcache\\ArrayCache',
  373. '\\OC\\Memcache\\ArrayCache'
  374. );
  375. });
  376. $this->registerService('RedisFactory', function (Server $c) {
  377. $systemConfig = $c->getSystemConfig();
  378. return new RedisFactory($systemConfig);
  379. });
  380. $this->registerService('ActivityManager', function (Server $c) {
  381. return new \OC\Activity\Manager(
  382. $c->getRequest(),
  383. $c->getUserSession(),
  384. $c->getConfig(),
  385. $c->query(IValidator::class)
  386. );
  387. });
  388. $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
  389. return new \OC\Activity\EventMerger(
  390. $c->getL10N('lib')
  391. );
  392. });
  393. $this->registerAlias(IValidator::class, Validator::class);
  394. $this->registerService('AvatarManager', function (Server $c) {
  395. return new AvatarManager(
  396. $c->getUserManager(),
  397. $c->getAppDataDir('avatar'),
  398. $c->getL10N('lib'),
  399. $c->getLogger(),
  400. $c->getConfig()
  401. );
  402. });
  403. $this->registerService('Logger', function (Server $c) {
  404. $logClass = $c->query('AllConfig')->getSystemValue('log_type', 'file');
  405. // TODO: Drop backwards compatibility for config in the future
  406. $logger = 'OC\\Log\\' . ucfirst($logClass=='owncloud' ? 'file' : $logClass);
  407. call_user_func(array($logger, 'init'));
  408. return new Log($logger);
  409. });
  410. $this->registerService('JobList', function (Server $c) {
  411. $config = $c->getConfig();
  412. return new \OC\BackgroundJob\JobList(
  413. $c->getDatabaseConnection(),
  414. $config,
  415. new TimeFactory()
  416. );
  417. });
  418. $this->registerService('Router', function (Server $c) {
  419. $cacheFactory = $c->getMemCacheFactory();
  420. $logger = $c->getLogger();
  421. if ($cacheFactory->isAvailable()) {
  422. $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
  423. } else {
  424. $router = new \OC\Route\Router($logger);
  425. }
  426. return $router;
  427. });
  428. $this->registerService('Search', function ($c) {
  429. return new Search();
  430. });
  431. $this->registerService('SecureRandom', function ($c) {
  432. return new SecureRandom();
  433. });
  434. $this->registerService('Crypto', function (Server $c) {
  435. return new Crypto($c->getConfig(), $c->getSecureRandom());
  436. });
  437. $this->registerService('Hasher', function (Server $c) {
  438. return new Hasher($c->getConfig());
  439. });
  440. $this->registerService('CredentialsManager', function (Server $c) {
  441. return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
  442. });
  443. $this->registerService('DatabaseConnection', function (Server $c) {
  444. $systemConfig = $c->getSystemConfig();
  445. $factory = new \OC\DB\ConnectionFactory($c->getConfig());
  446. $type = $systemConfig->getValue('dbtype', 'sqlite');
  447. if (!$factory->isValidType($type)) {
  448. throw new \OC\DatabaseException('Invalid database type');
  449. }
  450. $connectionParams = $factory->createConnectionParams($systemConfig);
  451. $connection = $factory->getConnection($type, $connectionParams);
  452. $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
  453. return $connection;
  454. });
  455. $this->registerService('HTTPHelper', function (Server $c) {
  456. $config = $c->getConfig();
  457. return new HTTPHelper(
  458. $config,
  459. $c->getHTTPClientService()
  460. );
  461. });
  462. $this->registerService('HttpClientService', function (Server $c) {
  463. $user = \OC_User::getUser();
  464. $uid = $user ? $user : null;
  465. return new ClientService(
  466. $c->getConfig(),
  467. new \OC\Security\CertificateManager($uid, new View(), $c->getConfig())
  468. );
  469. });
  470. $this->registerService('EventLogger', function (Server $c) {
  471. if ($c->getSystemConfig()->getValue('debug', false)) {
  472. return new EventLogger();
  473. } else {
  474. return new NullEventLogger();
  475. }
  476. });
  477. $this->registerService('QueryLogger', function (Server $c) {
  478. if ($c->getSystemConfig()->getValue('debug', false)) {
  479. return new QueryLogger();
  480. } else {
  481. return new NullQueryLogger();
  482. }
  483. });
  484. $this->registerService('TempManager', function (Server $c) {
  485. return new TempManager(
  486. $c->getLogger(),
  487. $c->getConfig()
  488. );
  489. });
  490. $this->registerService('AppManager', function (Server $c) {
  491. return new \OC\App\AppManager(
  492. $c->getUserSession(),
  493. $c->getAppConfig(),
  494. $c->getGroupManager(),
  495. $c->getMemCacheFactory(),
  496. $c->getEventDispatcher()
  497. );
  498. });
  499. $this->registerService('DateTimeZone', function (Server $c) {
  500. return new DateTimeZone(
  501. $c->getConfig(),
  502. $c->getSession()
  503. );
  504. });
  505. $this->registerService('DateTimeFormatter', function (Server $c) {
  506. $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
  507. return new DateTimeFormatter(
  508. $c->getDateTimeZone()->getTimeZone(),
  509. $c->getL10N('lib', $language)
  510. );
  511. });
  512. $this->registerService('UserMountCache', function (Server $c) {
  513. $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
  514. $listener = new UserMountCacheListener($mountCache);
  515. $listener->listen($c->getUserManager());
  516. return $mountCache;
  517. });
  518. $this->registerService('MountConfigManager', function (Server $c) {
  519. $loader = \OC\Files\Filesystem::getLoader();
  520. $mountCache = $c->query('UserMountCache');
  521. $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
  522. // builtin providers
  523. $config = $c->getConfig();
  524. $manager->registerProvider(new CacheMountProvider($config));
  525. $manager->registerHomeProvider(new LocalHomeMountProvider());
  526. $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
  527. return $manager;
  528. });
  529. $this->registerService('IniWrapper', function ($c) {
  530. return new IniGetWrapper();
  531. });
  532. $this->registerService('AsyncCommandBus', function (Server $c) {
  533. $jobList = $c->getJobList();
  534. return new AsyncBus($jobList);
  535. });
  536. $this->registerService('TrustedDomainHelper', function ($c) {
  537. return new TrustedDomainHelper($this->getConfig());
  538. });
  539. $this->registerService('Throttler', function(Server $c) {
  540. return new Throttler(
  541. $c->getDatabaseConnection(),
  542. new TimeFactory(),
  543. $c->getLogger(),
  544. $c->getConfig()
  545. );
  546. });
  547. $this->registerService('IntegrityCodeChecker', function (Server $c) {
  548. // IConfig and IAppManager requires a working database. This code
  549. // might however be called when ownCloud is not yet setup.
  550. if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
  551. $config = $c->getConfig();
  552. $appManager = $c->getAppManager();
  553. } else {
  554. $config = null;
  555. $appManager = null;
  556. }
  557. return new Checker(
  558. new EnvironmentHelper(),
  559. new FileAccessHelper(),
  560. new AppLocator(),
  561. $config,
  562. $c->getMemCacheFactory(),
  563. $appManager,
  564. $c->getTempManager()
  565. );
  566. });
  567. $this->registerService('Request', function ($c) {
  568. if (isset($this['urlParams'])) {
  569. $urlParams = $this['urlParams'];
  570. } else {
  571. $urlParams = [];
  572. }
  573. if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
  574. && in_array('fakeinput', stream_get_wrappers())
  575. ) {
  576. $stream = 'fakeinput://data';
  577. } else {
  578. $stream = 'php://input';
  579. }
  580. return new Request(
  581. [
  582. 'get' => $_GET,
  583. 'post' => $_POST,
  584. 'files' => $_FILES,
  585. 'server' => $_SERVER,
  586. 'env' => $_ENV,
  587. 'cookies' => $_COOKIE,
  588. 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
  589. ? $_SERVER['REQUEST_METHOD']
  590. : null,
  591. 'urlParams' => $urlParams,
  592. ],
  593. $this->getSecureRandom(),
  594. $this->getConfig(),
  595. $this->getCsrfTokenManager(),
  596. $stream
  597. );
  598. });
  599. $this->registerService('Mailer', function (Server $c) {
  600. return new Mailer(
  601. $c->getConfig(),
  602. $c->getLogger(),
  603. $c->getThemingDefaults()
  604. );
  605. });
  606. $this->registerService('LDAPProvider', function(Server $c) {
  607. $config = $c->getConfig();
  608. $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
  609. if(is_null($factoryClass)) {
  610. throw new \Exception('ldapProviderFactory not set');
  611. }
  612. /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
  613. $factory = new $factoryClass($this);
  614. return $factory->getLDAPProvider();
  615. });
  616. $this->registerService('LockingProvider', function (Server $c) {
  617. $ini = $c->getIniWrapper();
  618. $config = $c->getConfig();
  619. $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
  620. if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
  621. /** @var \OC\Memcache\Factory $memcacheFactory */
  622. $memcacheFactory = $c->getMemCacheFactory();
  623. $memcache = $memcacheFactory->createLocking('lock');
  624. if (!($memcache instanceof \OC\Memcache\NullCache)) {
  625. return new MemcacheLockingProvider($memcache, $ttl);
  626. }
  627. return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
  628. }
  629. return new NoopLockingProvider();
  630. });
  631. $this->registerService('MountManager', function () {
  632. return new \OC\Files\Mount\Manager();
  633. });
  634. $this->registerService('MimeTypeDetector', function (Server $c) {
  635. return new \OC\Files\Type\Detection(
  636. $c->getURLGenerator(),
  637. \OC::$configDir,
  638. \OC::$SERVERROOT . '/resources/config/'
  639. );
  640. });
  641. $this->registerService('MimeTypeLoader', function (Server $c) {
  642. return new \OC\Files\Type\Loader(
  643. $c->getDatabaseConnection()
  644. );
  645. });
  646. $this->registerService('NotificationManager', function (Server $c) {
  647. return new Manager(
  648. $c->query(IValidator::class)
  649. );
  650. });
  651. $this->registerService('CapabilitiesManager', function (Server $c) {
  652. $manager = new \OC\CapabilitiesManager($c->getLogger());
  653. $manager->registerCapability(function () use ($c) {
  654. return new \OC\OCS\CoreCapabilities($c->getConfig());
  655. });
  656. return $manager;
  657. });
  658. $this->registerService('CommentsManager', function(Server $c) {
  659. $config = $c->getConfig();
  660. $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
  661. /** @var \OCP\Comments\ICommentsManagerFactory $factory */
  662. $factory = new $factoryClass($this);
  663. return $factory->getManager();
  664. });
  665. $this->registerService('ThemingDefaults', function(Server $c) {
  666. /*
  667. * Dark magic for autoloader.
  668. * If we do a class_exists it will try to load the class which will
  669. * make composer cache the result. Resulting in errors when enabling
  670. * the theming app.
  671. */
  672. $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
  673. if (isset($prefixes['OCA\\Theming\\'])) {
  674. $classExists = true;
  675. } else {
  676. $classExists = false;
  677. }
  678. if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) {
  679. return new ThemingDefaults(
  680. $c->getConfig(),
  681. $c->getL10N('theming'),
  682. $c->getURLGenerator(),
  683. new \OC_Defaults(),
  684. $c->getLazyRootFolder(),
  685. $c->getMemCacheFactory()
  686. );
  687. }
  688. return new \OC_Defaults();
  689. });
  690. $this->registerService('EventDispatcher', function () {
  691. return new EventDispatcher();
  692. });
  693. $this->registerService('CryptoWrapper', function (Server $c) {
  694. // FIXME: Instantiiated here due to cyclic dependency
  695. $request = new Request(
  696. [
  697. 'get' => $_GET,
  698. 'post' => $_POST,
  699. 'files' => $_FILES,
  700. 'server' => $_SERVER,
  701. 'env' => $_ENV,
  702. 'cookies' => $_COOKIE,
  703. 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
  704. ? $_SERVER['REQUEST_METHOD']
  705. : null,
  706. ],
  707. $c->getSecureRandom(),
  708. $c->getConfig()
  709. );
  710. return new CryptoWrapper(
  711. $c->getConfig(),
  712. $c->getCrypto(),
  713. $c->getSecureRandom(),
  714. $request
  715. );
  716. });
  717. $this->registerService('CsrfTokenManager', function (Server $c) {
  718. $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
  719. return new CsrfTokenManager(
  720. $tokenGenerator,
  721. $c->query(SessionStorage::class)
  722. );
  723. });
  724. $this->registerService(SessionStorage::class, function (Server $c) {
  725. return new SessionStorage($c->getSession());
  726. });
  727. $this->registerService('ContentSecurityPolicyManager', function (Server $c) {
  728. return new ContentSecurityPolicyManager();
  729. });
  730. $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) {
  731. return new ContentSecurityPolicyNonceManager(
  732. $c->getCsrfTokenManager(),
  733. $c->getRequest()
  734. );
  735. });
  736. $this->registerService('ShareManager', function(Server $c) {
  737. $config = $c->getConfig();
  738. $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
  739. /** @var \OCP\Share\IProviderFactory $factory */
  740. $factory = new $factoryClass($this);
  741. $manager = new \OC\Share20\Manager(
  742. $c->getLogger(),
  743. $c->getConfig(),
  744. $c->getSecureRandom(),
  745. $c->getHasher(),
  746. $c->getMountManager(),
  747. $c->getGroupManager(),
  748. $c->getL10N('core'),
  749. $factory,
  750. $c->getUserManager(),
  751. $c->getLazyRootFolder(),
  752. $c->getEventDispatcher()
  753. );
  754. return $manager;
  755. });
  756. $this->registerService('SettingsManager', function(Server $c) {
  757. $manager = new \OC\Settings\Manager(
  758. $c->getLogger(),
  759. $c->getDatabaseConnection(),
  760. $c->getL10N('lib'),
  761. $c->getConfig(),
  762. $c->getEncryptionManager(),
  763. $c->getUserManager(),
  764. $c->getLockingProvider(),
  765. new \OC\Settings\Mapper($c->getDatabaseConnection())
  766. );
  767. return $manager;
  768. });
  769. $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
  770. return new \OC\Files\AppData\Factory(
  771. $c->getRootFolder(),
  772. $c->getSystemConfig()
  773. );
  774. });
  775. $this->registerService('LockdownManager', function (Server $c) {
  776. return new LockdownManager();
  777. });
  778. /* To trick DI since we don't extend the DIContainer here */
  779. $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
  780. return new CleanPreviewsBackgroundJob(
  781. $c->getRootFolder(),
  782. $c->getLogger(),
  783. $c->getJobList(),
  784. new TimeFactory()
  785. );
  786. });
  787. }
  788. /**
  789. * @return \OCP\Contacts\IManager
  790. */
  791. public function getContactsManager() {
  792. return $this->query('ContactsManager');
  793. }
  794. /**
  795. * @return \OC\Encryption\Manager
  796. */
  797. public function getEncryptionManager() {
  798. return $this->query('EncryptionManager');
  799. }
  800. /**
  801. * @return \OC\Encryption\File
  802. */
  803. public function getEncryptionFilesHelper() {
  804. return $this->query('EncryptionFileHelper');
  805. }
  806. /**
  807. * @return \OCP\Encryption\Keys\IStorage
  808. */
  809. public function getEncryptionKeyStorage() {
  810. return $this->query('EncryptionKeyStorage');
  811. }
  812. /**
  813. * The current request object holding all information about the request
  814. * currently being processed is returned from this method.
  815. * In case the current execution was not initiated by a web request null is returned
  816. *
  817. * @return \OCP\IRequest
  818. */
  819. public function getRequest() {
  820. return $this->query('Request');
  821. }
  822. /**
  823. * Returns the preview manager which can create preview images for a given file
  824. *
  825. * @return \OCP\IPreview
  826. */
  827. public function getPreviewManager() {
  828. return $this->query('PreviewManager');
  829. }
  830. /**
  831. * Returns the tag manager which can get and set tags for different object types
  832. *
  833. * @see \OCP\ITagManager::load()
  834. * @return \OCP\ITagManager
  835. */
  836. public function getTagManager() {
  837. return $this->query('TagManager');
  838. }
  839. /**
  840. * Returns the system-tag manager
  841. *
  842. * @return \OCP\SystemTag\ISystemTagManager
  843. *
  844. * @since 9.0.0
  845. */
  846. public function getSystemTagManager() {
  847. return $this->query('SystemTagManager');
  848. }
  849. /**
  850. * Returns the system-tag object mapper
  851. *
  852. * @return \OCP\SystemTag\ISystemTagObjectMapper
  853. *
  854. * @since 9.0.0
  855. */
  856. public function getSystemTagObjectMapper() {
  857. return $this->query('SystemTagObjectMapper');
  858. }
  859. /**
  860. * Returns the avatar manager, used for avatar functionality
  861. *
  862. * @return \OCP\IAvatarManager
  863. */
  864. public function getAvatarManager() {
  865. return $this->query('AvatarManager');
  866. }
  867. /**
  868. * Returns the root folder of ownCloud's data directory
  869. *
  870. * @return \OCP\Files\IRootFolder
  871. */
  872. public function getRootFolder() {
  873. return $this->query('LazyRootFolder');
  874. }
  875. /**
  876. * Returns the root folder of ownCloud's data directory
  877. * This is the lazy variant so this gets only initialized once it
  878. * is actually used.
  879. *
  880. * @return \OCP\Files\IRootFolder
  881. */
  882. public function getLazyRootFolder() {
  883. return $this->query('LazyRootFolder');
  884. }
  885. /**
  886. * Returns a view to ownCloud's files folder
  887. *
  888. * @param string $userId user ID
  889. * @return \OCP\Files\Folder|null
  890. */
  891. public function getUserFolder($userId = null) {
  892. if ($userId === null) {
  893. $user = $this->getUserSession()->getUser();
  894. if (!$user) {
  895. return null;
  896. }
  897. $userId = $user->getUID();
  898. }
  899. $root = $this->getRootFolder();
  900. return $root->getUserFolder($userId);
  901. }
  902. /**
  903. * Returns an app-specific view in ownClouds data directory
  904. *
  905. * @return \OCP\Files\Folder
  906. * @deprecated since 9.2.0 use IAppData
  907. */
  908. public function getAppFolder() {
  909. $dir = '/' . \OC_App::getCurrentApp();
  910. $root = $this->getRootFolder();
  911. if (!$root->nodeExists($dir)) {
  912. $folder = $root->newFolder($dir);
  913. } else {
  914. $folder = $root->get($dir);
  915. }
  916. return $folder;
  917. }
  918. /**
  919. * @return \OC\User\Manager
  920. */
  921. public function getUserManager() {
  922. return $this->query('UserManager');
  923. }
  924. /**
  925. * @return \OC\Group\Manager
  926. */
  927. public function getGroupManager() {
  928. return $this->query('GroupManager');
  929. }
  930. /**
  931. * @return \OC\User\Session
  932. */
  933. public function getUserSession() {
  934. return $this->query('UserSession');
  935. }
  936. /**
  937. * @return \OCP\ISession
  938. */
  939. public function getSession() {
  940. return $this->query('UserSession')->getSession();
  941. }
  942. /**
  943. * @param \OCP\ISession $session
  944. */
  945. public function setSession(\OCP\ISession $session) {
  946. $this->query(SessionStorage::class)->setSession($session);
  947. return $this->query('UserSession')->setSession($session);
  948. }
  949. /**
  950. * @return \OC\Authentication\TwoFactorAuth\Manager
  951. */
  952. public function getTwoFactorAuthManager() {
  953. return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
  954. }
  955. /**
  956. * @return \OC\NavigationManager
  957. */
  958. public function getNavigationManager() {
  959. return $this->query('NavigationManager');
  960. }
  961. /**
  962. * @return \OCP\IConfig
  963. */
  964. public function getConfig() {
  965. return $this->query('AllConfig');
  966. }
  967. /**
  968. * @internal For internal use only
  969. * @return \OC\SystemConfig
  970. */
  971. public function getSystemConfig() {
  972. return $this->query('SystemConfig');
  973. }
  974. /**
  975. * Returns the app config manager
  976. *
  977. * @return \OCP\IAppConfig
  978. */
  979. public function getAppConfig() {
  980. return $this->query('AppConfig');
  981. }
  982. /**
  983. * @return \OCP\L10N\IFactory
  984. */
  985. public function getL10NFactory() {
  986. return $this->query('L10NFactory');
  987. }
  988. /**
  989. * get an L10N instance
  990. *
  991. * @param string $app appid
  992. * @param string $lang
  993. * @return IL10N
  994. */
  995. public function getL10N($app, $lang = null) {
  996. return $this->getL10NFactory()->get($app, $lang);
  997. }
  998. /**
  999. * @return \OCP\IURLGenerator
  1000. */
  1001. public function getURLGenerator() {
  1002. return $this->query('URLGenerator');
  1003. }
  1004. /**
  1005. * @return \OCP\IHelper
  1006. */
  1007. public function getHelper() {
  1008. return $this->query('AppHelper');
  1009. }
  1010. /**
  1011. * @return AppFetcher
  1012. */
  1013. public function getAppFetcher() {
  1014. return $this->query('AppFetcher');
  1015. }
  1016. /**
  1017. * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
  1018. * getMemCacheFactory() instead.
  1019. *
  1020. * @return \OCP\ICache
  1021. * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
  1022. */
  1023. public function getCache() {
  1024. return $this->query('UserCache');
  1025. }
  1026. /**
  1027. * Returns an \OCP\CacheFactory instance
  1028. *
  1029. * @return \OCP\ICacheFactory
  1030. */
  1031. public function getMemCacheFactory() {
  1032. return $this->query('MemCacheFactory');
  1033. }
  1034. /**
  1035. * Returns an \OC\RedisFactory instance
  1036. *
  1037. * @return \OC\RedisFactory
  1038. */
  1039. public function getGetRedisFactory() {
  1040. return $this->query('RedisFactory');
  1041. }
  1042. /**
  1043. * Returns the current session
  1044. *
  1045. * @return \OCP\IDBConnection
  1046. */
  1047. public function getDatabaseConnection() {
  1048. return $this->query('DatabaseConnection');
  1049. }
  1050. /**
  1051. * Returns the activity manager
  1052. *
  1053. * @return \OCP\Activity\IManager
  1054. */
  1055. public function getActivityManager() {
  1056. return $this->query('ActivityManager');
  1057. }
  1058. /**
  1059. * Returns an job list for controlling background jobs
  1060. *
  1061. * @return \OCP\BackgroundJob\IJobList
  1062. */
  1063. public function getJobList() {
  1064. return $this->query('JobList');
  1065. }
  1066. /**
  1067. * Returns a logger instance
  1068. *
  1069. * @return \OCP\ILogger
  1070. */
  1071. public function getLogger() {
  1072. return $this->query('Logger');
  1073. }
  1074. /**
  1075. * Returns a router for generating and matching urls
  1076. *
  1077. * @return \OCP\Route\IRouter
  1078. */
  1079. public function getRouter() {
  1080. return $this->query('Router');
  1081. }
  1082. /**
  1083. * Returns a search instance
  1084. *
  1085. * @return \OCP\ISearch
  1086. */
  1087. public function getSearch() {
  1088. return $this->query('Search');
  1089. }
  1090. /**
  1091. * Returns a SecureRandom instance
  1092. *
  1093. * @return \OCP\Security\ISecureRandom
  1094. */
  1095. public function getSecureRandom() {
  1096. return $this->query('SecureRandom');
  1097. }
  1098. /**
  1099. * Returns a Crypto instance
  1100. *
  1101. * @return \OCP\Security\ICrypto
  1102. */
  1103. public function getCrypto() {
  1104. return $this->query('Crypto');
  1105. }
  1106. /**
  1107. * Returns a Hasher instance
  1108. *
  1109. * @return \OCP\Security\IHasher
  1110. */
  1111. public function getHasher() {
  1112. return $this->query('Hasher');
  1113. }
  1114. /**
  1115. * Returns a CredentialsManager instance
  1116. *
  1117. * @return \OCP\Security\ICredentialsManager
  1118. */
  1119. public function getCredentialsManager() {
  1120. return $this->query('CredentialsManager');
  1121. }
  1122. /**
  1123. * Returns an instance of the HTTP helper class
  1124. *
  1125. * @deprecated Use getHTTPClientService()
  1126. * @return \OC\HTTPHelper
  1127. */
  1128. public function getHTTPHelper() {
  1129. return $this->query('HTTPHelper');
  1130. }
  1131. /**
  1132. * Get the certificate manager for the user
  1133. *
  1134. * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
  1135. * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
  1136. */
  1137. public function getCertificateManager($userId = '') {
  1138. if ($userId === '') {
  1139. $userSession = $this->getUserSession();
  1140. $user = $userSession->getUser();
  1141. if (is_null($user)) {
  1142. return null;
  1143. }
  1144. $userId = $user->getUID();
  1145. }
  1146. return new CertificateManager($userId, new View(), $this->getConfig());
  1147. }
  1148. /**
  1149. * Returns an instance of the HTTP client service
  1150. *
  1151. * @return \OCP\Http\Client\IClientService
  1152. */
  1153. public function getHTTPClientService() {
  1154. return $this->query('HttpClientService');
  1155. }
  1156. /**
  1157. * Create a new event source
  1158. *
  1159. * @return \OCP\IEventSource
  1160. */
  1161. public function createEventSource() {
  1162. return new \OC_EventSource();
  1163. }
  1164. /**
  1165. * Get the active event logger
  1166. *
  1167. * The returned logger only logs data when debug mode is enabled
  1168. *
  1169. * @return \OCP\Diagnostics\IEventLogger
  1170. */
  1171. public function getEventLogger() {
  1172. return $this->query('EventLogger');
  1173. }
  1174. /**
  1175. * Get the active query logger
  1176. *
  1177. * The returned logger only logs data when debug mode is enabled
  1178. *
  1179. * @return \OCP\Diagnostics\IQueryLogger
  1180. */
  1181. public function getQueryLogger() {
  1182. return $this->query('QueryLogger');
  1183. }
  1184. /**
  1185. * Get the manager for temporary files and folders
  1186. *
  1187. * @return \OCP\ITempManager
  1188. */
  1189. public function getTempManager() {
  1190. return $this->query('TempManager');
  1191. }
  1192. /**
  1193. * Get the app manager
  1194. *
  1195. * @return \OCP\App\IAppManager
  1196. */
  1197. public function getAppManager() {
  1198. return $this->query('AppManager');
  1199. }
  1200. /**
  1201. * Creates a new mailer
  1202. *
  1203. * @return \OCP\Mail\IMailer
  1204. */
  1205. public function getMailer() {
  1206. return $this->query('Mailer');
  1207. }
  1208. /**
  1209. * Get the webroot
  1210. *
  1211. * @return string
  1212. */
  1213. public function getWebRoot() {
  1214. return $this->webRoot;
  1215. }
  1216. /**
  1217. * @return \OC\OCSClient
  1218. */
  1219. public function getOcsClient() {
  1220. return $this->query('OcsClient');
  1221. }
  1222. /**
  1223. * @return \OCP\IDateTimeZone
  1224. */
  1225. public function getDateTimeZone() {
  1226. return $this->query('DateTimeZone');
  1227. }
  1228. /**
  1229. * @return \OCP\IDateTimeFormatter
  1230. */
  1231. public function getDateTimeFormatter() {
  1232. return $this->query('DateTimeFormatter');
  1233. }
  1234. /**
  1235. * @return \OCP\Files\Config\IMountProviderCollection
  1236. */
  1237. public function getMountProviderCollection() {
  1238. return $this->query('MountConfigManager');
  1239. }
  1240. /**
  1241. * Get the IniWrapper
  1242. *
  1243. * @return IniGetWrapper
  1244. */
  1245. public function getIniWrapper() {
  1246. return $this->query('IniWrapper');
  1247. }
  1248. /**
  1249. * @return \OCP\Command\IBus
  1250. */
  1251. public function getCommandBus() {
  1252. return $this->query('AsyncCommandBus');
  1253. }
  1254. /**
  1255. * Get the trusted domain helper
  1256. *
  1257. * @return TrustedDomainHelper
  1258. */
  1259. public function getTrustedDomainHelper() {
  1260. return $this->query('TrustedDomainHelper');
  1261. }
  1262. /**
  1263. * Get the locking provider
  1264. *
  1265. * @return \OCP\Lock\ILockingProvider
  1266. * @since 8.1.0
  1267. */
  1268. public function getLockingProvider() {
  1269. return $this->query('LockingProvider');
  1270. }
  1271. /**
  1272. * @return \OCP\Files\Mount\IMountManager
  1273. **/
  1274. function getMountManager() {
  1275. return $this->query('MountManager');
  1276. }
  1277. /** @return \OCP\Files\Config\IUserMountCache */
  1278. function getUserMountCache() {
  1279. return $this->query('UserMountCache');
  1280. }
  1281. /**
  1282. * Get the MimeTypeDetector
  1283. *
  1284. * @return \OCP\Files\IMimeTypeDetector
  1285. */
  1286. public function getMimeTypeDetector() {
  1287. return $this->query('MimeTypeDetector');
  1288. }
  1289. /**
  1290. * Get the MimeTypeLoader
  1291. *
  1292. * @return \OCP\Files\IMimeTypeLoader
  1293. */
  1294. public function getMimeTypeLoader() {
  1295. return $this->query('MimeTypeLoader');
  1296. }
  1297. /**
  1298. * Get the manager of all the capabilities
  1299. *
  1300. * @return \OC\CapabilitiesManager
  1301. */
  1302. public function getCapabilitiesManager() {
  1303. return $this->query('CapabilitiesManager');
  1304. }
  1305. /**
  1306. * Get the EventDispatcher
  1307. *
  1308. * @return EventDispatcherInterface
  1309. * @since 8.2.0
  1310. */
  1311. public function getEventDispatcher() {
  1312. return $this->query('EventDispatcher');
  1313. }
  1314. /**
  1315. * Get the Notification Manager
  1316. *
  1317. * @return \OCP\Notification\IManager
  1318. * @since 8.2.0
  1319. */
  1320. public function getNotificationManager() {
  1321. return $this->query('NotificationManager');
  1322. }
  1323. /**
  1324. * @return \OCP\Comments\ICommentsManager
  1325. */
  1326. public function getCommentsManager() {
  1327. return $this->query('CommentsManager');
  1328. }
  1329. /**
  1330. * @return \OC_Defaults
  1331. */
  1332. public function getThemingDefaults() {
  1333. return $this->query('ThemingDefaults');
  1334. }
  1335. /**
  1336. * @return \OC\IntegrityCheck\Checker
  1337. */
  1338. public function getIntegrityCodeChecker() {
  1339. return $this->query('IntegrityCodeChecker');
  1340. }
  1341. /**
  1342. * @return \OC\Session\CryptoWrapper
  1343. */
  1344. public function getSessionCryptoWrapper() {
  1345. return $this->query('CryptoWrapper');
  1346. }
  1347. /**
  1348. * @return CsrfTokenManager
  1349. */
  1350. public function getCsrfTokenManager() {
  1351. return $this->query('CsrfTokenManager');
  1352. }
  1353. /**
  1354. * @return Throttler
  1355. */
  1356. public function getBruteForceThrottler() {
  1357. return $this->query('Throttler');
  1358. }
  1359. /**
  1360. * @return IContentSecurityPolicyManager
  1361. */
  1362. public function getContentSecurityPolicyManager() {
  1363. return $this->query('ContentSecurityPolicyManager');
  1364. }
  1365. /**
  1366. * @return ContentSecurityPolicyNonceManager
  1367. */
  1368. public function getContentSecurityPolicyNonceManager() {
  1369. return $this->query('ContentSecurityPolicyNonceManager');
  1370. }
  1371. /**
  1372. * Not a public API as of 8.2, wait for 9.0
  1373. *
  1374. * @return \OCA\Files_External\Service\BackendService
  1375. */
  1376. public function getStoragesBackendService() {
  1377. return $this->query('OCA\\Files_External\\Service\\BackendService');
  1378. }
  1379. /**
  1380. * Not a public API as of 8.2, wait for 9.0
  1381. *
  1382. * @return \OCA\Files_External\Service\GlobalStoragesService
  1383. */
  1384. public function getGlobalStoragesService() {
  1385. return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
  1386. }
  1387. /**
  1388. * Not a public API as of 8.2, wait for 9.0
  1389. *
  1390. * @return \OCA\Files_External\Service\UserGlobalStoragesService
  1391. */
  1392. public function getUserGlobalStoragesService() {
  1393. return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
  1394. }
  1395. /**
  1396. * Not a public API as of 8.2, wait for 9.0
  1397. *
  1398. * @return \OCA\Files_External\Service\UserStoragesService
  1399. */
  1400. public function getUserStoragesService() {
  1401. return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
  1402. }
  1403. /**
  1404. * @return \OCP\Share\IManager
  1405. */
  1406. public function getShareManager() {
  1407. return $this->query('ShareManager');
  1408. }
  1409. /**
  1410. * Returns the LDAP Provider
  1411. *
  1412. * @return \OCP\LDAP\ILDAPProvider
  1413. */
  1414. public function getLDAPProvider() {
  1415. return $this->query('LDAPProvider');
  1416. }
  1417. /**
  1418. * @return \OCP\Settings\IManager
  1419. */
  1420. public function getSettingsManager() {
  1421. return $this->query('SettingsManager');
  1422. }
  1423. /**
  1424. * @return \OCP\Files\IAppData
  1425. */
  1426. public function getAppDataDir($app) {
  1427. /** @var \OC\Files\AppData\Factory $factory */
  1428. $factory = $this->query(\OC\Files\AppData\Factory::class);
  1429. return $factory->get($app);
  1430. }
  1431. /**
  1432. * @return \OCP\Lockdown\ILockdownManager
  1433. */
  1434. public function getLockdownManager() {
  1435. return $this->query('LockdownManager');
  1436. }
  1437. }