You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Server.php 43KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554
  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());
  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. );
  766. return $manager;
  767. });
  768. $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
  769. return new \OC\Files\AppData\Factory(
  770. $c->getRootFolder(),
  771. $c->getSystemConfig()
  772. );
  773. });
  774. $this->registerService('LockdownManager', function (Server $c) {
  775. return new LockdownManager();
  776. });
  777. /* To trick DI since we don't extend the DIContainer here */
  778. $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
  779. return new CleanPreviewsBackgroundJob(
  780. $c->getRootFolder(),
  781. $c->getLogger(),
  782. $c->getJobList(),
  783. new TimeFactory()
  784. );
  785. });
  786. }
  787. /**
  788. * @return \OCP\Contacts\IManager
  789. */
  790. public function getContactsManager() {
  791. return $this->query('ContactsManager');
  792. }
  793. /**
  794. * @return \OC\Encryption\Manager
  795. */
  796. public function getEncryptionManager() {
  797. return $this->query('EncryptionManager');
  798. }
  799. /**
  800. * @return \OC\Encryption\File
  801. */
  802. public function getEncryptionFilesHelper() {
  803. return $this->query('EncryptionFileHelper');
  804. }
  805. /**
  806. * @return \OCP\Encryption\Keys\IStorage
  807. */
  808. public function getEncryptionKeyStorage() {
  809. return $this->query('EncryptionKeyStorage');
  810. }
  811. /**
  812. * The current request object holding all information about the request
  813. * currently being processed is returned from this method.
  814. * In case the current execution was not initiated by a web request null is returned
  815. *
  816. * @return \OCP\IRequest
  817. */
  818. public function getRequest() {
  819. return $this->query('Request');
  820. }
  821. /**
  822. * Returns the preview manager which can create preview images for a given file
  823. *
  824. * @return \OCP\IPreview
  825. */
  826. public function getPreviewManager() {
  827. return $this->query('PreviewManager');
  828. }
  829. /**
  830. * Returns the tag manager which can get and set tags for different object types
  831. *
  832. * @see \OCP\ITagManager::load()
  833. * @return \OCP\ITagManager
  834. */
  835. public function getTagManager() {
  836. return $this->query('TagManager');
  837. }
  838. /**
  839. * Returns the system-tag manager
  840. *
  841. * @return \OCP\SystemTag\ISystemTagManager
  842. *
  843. * @since 9.0.0
  844. */
  845. public function getSystemTagManager() {
  846. return $this->query('SystemTagManager');
  847. }
  848. /**
  849. * Returns the system-tag object mapper
  850. *
  851. * @return \OCP\SystemTag\ISystemTagObjectMapper
  852. *
  853. * @since 9.0.0
  854. */
  855. public function getSystemTagObjectMapper() {
  856. return $this->query('SystemTagObjectMapper');
  857. }
  858. /**
  859. * Returns the avatar manager, used for avatar functionality
  860. *
  861. * @return \OCP\IAvatarManager
  862. */
  863. public function getAvatarManager() {
  864. return $this->query('AvatarManager');
  865. }
  866. /**
  867. * Returns the root folder of ownCloud's data directory
  868. *
  869. * @return \OCP\Files\IRootFolder
  870. */
  871. public function getRootFolder() {
  872. return $this->query('LazyRootFolder');
  873. }
  874. /**
  875. * Returns the root folder of ownCloud's data directory
  876. * This is the lazy variant so this gets only initialized once it
  877. * is actually used.
  878. *
  879. * @return \OCP\Files\IRootFolder
  880. */
  881. public function getLazyRootFolder() {
  882. return $this->query('LazyRootFolder');
  883. }
  884. /**
  885. * Returns a view to ownCloud's files folder
  886. *
  887. * @param string $userId user ID
  888. * @return \OCP\Files\Folder|null
  889. */
  890. public function getUserFolder($userId = null) {
  891. if ($userId === null) {
  892. $user = $this->getUserSession()->getUser();
  893. if (!$user) {
  894. return null;
  895. }
  896. $userId = $user->getUID();
  897. }
  898. $root = $this->getRootFolder();
  899. return $root->getUserFolder($userId);
  900. }
  901. /**
  902. * Returns an app-specific view in ownClouds data directory
  903. *
  904. * @return \OCP\Files\Folder
  905. * @deprecated since 9.2.0 use IAppData
  906. */
  907. public function getAppFolder() {
  908. $dir = '/' . \OC_App::getCurrentApp();
  909. $root = $this->getRootFolder();
  910. if (!$root->nodeExists($dir)) {
  911. $folder = $root->newFolder($dir);
  912. } else {
  913. $folder = $root->get($dir);
  914. }
  915. return $folder;
  916. }
  917. /**
  918. * @return \OC\User\Manager
  919. */
  920. public function getUserManager() {
  921. return $this->query('UserManager');
  922. }
  923. /**
  924. * @return \OC\Group\Manager
  925. */
  926. public function getGroupManager() {
  927. return $this->query('GroupManager');
  928. }
  929. /**
  930. * @return \OC\User\Session
  931. */
  932. public function getUserSession() {
  933. return $this->query('UserSession');
  934. }
  935. /**
  936. * @return \OCP\ISession
  937. */
  938. public function getSession() {
  939. return $this->query('UserSession')->getSession();
  940. }
  941. /**
  942. * @param \OCP\ISession $session
  943. */
  944. public function setSession(\OCP\ISession $session) {
  945. $this->query(SessionStorage::class)->setSession($session);
  946. return $this->query('UserSession')->setSession($session);
  947. }
  948. /**
  949. * @return \OC\Authentication\TwoFactorAuth\Manager
  950. */
  951. public function getTwoFactorAuthManager() {
  952. return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
  953. }
  954. /**
  955. * @return \OC\NavigationManager
  956. */
  957. public function getNavigationManager() {
  958. return $this->query('NavigationManager');
  959. }
  960. /**
  961. * @return \OCP\IConfig
  962. */
  963. public function getConfig() {
  964. return $this->query('AllConfig');
  965. }
  966. /**
  967. * @internal For internal use only
  968. * @return \OC\SystemConfig
  969. */
  970. public function getSystemConfig() {
  971. return $this->query('SystemConfig');
  972. }
  973. /**
  974. * Returns the app config manager
  975. *
  976. * @return \OCP\IAppConfig
  977. */
  978. public function getAppConfig() {
  979. return $this->query('AppConfig');
  980. }
  981. /**
  982. * @return \OCP\L10N\IFactory
  983. */
  984. public function getL10NFactory() {
  985. return $this->query('L10NFactory');
  986. }
  987. /**
  988. * get an L10N instance
  989. *
  990. * @param string $app appid
  991. * @param string $lang
  992. * @return IL10N
  993. */
  994. public function getL10N($app, $lang = null) {
  995. return $this->getL10NFactory()->get($app, $lang);
  996. }
  997. /**
  998. * @return \OCP\IURLGenerator
  999. */
  1000. public function getURLGenerator() {
  1001. return $this->query('URLGenerator');
  1002. }
  1003. /**
  1004. * @return \OCP\IHelper
  1005. */
  1006. public function getHelper() {
  1007. return $this->query('AppHelper');
  1008. }
  1009. /**
  1010. * @return AppFetcher
  1011. */
  1012. public function getAppFetcher() {
  1013. return $this->query('AppFetcher');
  1014. }
  1015. /**
  1016. * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
  1017. * getMemCacheFactory() instead.
  1018. *
  1019. * @return \OCP\ICache
  1020. * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
  1021. */
  1022. public function getCache() {
  1023. return $this->query('UserCache');
  1024. }
  1025. /**
  1026. * Returns an \OCP\CacheFactory instance
  1027. *
  1028. * @return \OCP\ICacheFactory
  1029. */
  1030. public function getMemCacheFactory() {
  1031. return $this->query('MemCacheFactory');
  1032. }
  1033. /**
  1034. * Returns an \OC\RedisFactory instance
  1035. *
  1036. * @return \OC\RedisFactory
  1037. */
  1038. public function getGetRedisFactory() {
  1039. return $this->query('RedisFactory');
  1040. }
  1041. /**
  1042. * Returns the current session
  1043. *
  1044. * @return \OCP\IDBConnection
  1045. */
  1046. public function getDatabaseConnection() {
  1047. return $this->query('DatabaseConnection');
  1048. }
  1049. /**
  1050. * Returns the activity manager
  1051. *
  1052. * @return \OCP\Activity\IManager
  1053. */
  1054. public function getActivityManager() {
  1055. return $this->query('ActivityManager');
  1056. }
  1057. /**
  1058. * Returns an job list for controlling background jobs
  1059. *
  1060. * @return \OCP\BackgroundJob\IJobList
  1061. */
  1062. public function getJobList() {
  1063. return $this->query('JobList');
  1064. }
  1065. /**
  1066. * Returns a logger instance
  1067. *
  1068. * @return \OCP\ILogger
  1069. */
  1070. public function getLogger() {
  1071. return $this->query('Logger');
  1072. }
  1073. /**
  1074. * Returns a router for generating and matching urls
  1075. *
  1076. * @return \OCP\Route\IRouter
  1077. */
  1078. public function getRouter() {
  1079. return $this->query('Router');
  1080. }
  1081. /**
  1082. * Returns a search instance
  1083. *
  1084. * @return \OCP\ISearch
  1085. */
  1086. public function getSearch() {
  1087. return $this->query('Search');
  1088. }
  1089. /**
  1090. * Returns a SecureRandom instance
  1091. *
  1092. * @return \OCP\Security\ISecureRandom
  1093. */
  1094. public function getSecureRandom() {
  1095. return $this->query('SecureRandom');
  1096. }
  1097. /**
  1098. * Returns a Crypto instance
  1099. *
  1100. * @return \OCP\Security\ICrypto
  1101. */
  1102. public function getCrypto() {
  1103. return $this->query('Crypto');
  1104. }
  1105. /**
  1106. * Returns a Hasher instance
  1107. *
  1108. * @return \OCP\Security\IHasher
  1109. */
  1110. public function getHasher() {
  1111. return $this->query('Hasher');
  1112. }
  1113. /**
  1114. * Returns a CredentialsManager instance
  1115. *
  1116. * @return \OCP\Security\ICredentialsManager
  1117. */
  1118. public function getCredentialsManager() {
  1119. return $this->query('CredentialsManager');
  1120. }
  1121. /**
  1122. * Returns an instance of the HTTP helper class
  1123. *
  1124. * @deprecated Use getHTTPClientService()
  1125. * @return \OC\HTTPHelper
  1126. */
  1127. public function getHTTPHelper() {
  1128. return $this->query('HTTPHelper');
  1129. }
  1130. /**
  1131. * Get the certificate manager for the user
  1132. *
  1133. * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
  1134. * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
  1135. */
  1136. public function getCertificateManager($userId = '') {
  1137. if ($userId === '') {
  1138. $userSession = $this->getUserSession();
  1139. $user = $userSession->getUser();
  1140. if (is_null($user)) {
  1141. return null;
  1142. }
  1143. $userId = $user->getUID();
  1144. }
  1145. return new CertificateManager($userId, new View(), $this->getConfig());
  1146. }
  1147. /**
  1148. * Returns an instance of the HTTP client service
  1149. *
  1150. * @return \OCP\Http\Client\IClientService
  1151. */
  1152. public function getHTTPClientService() {
  1153. return $this->query('HttpClientService');
  1154. }
  1155. /**
  1156. * Create a new event source
  1157. *
  1158. * @return \OCP\IEventSource
  1159. */
  1160. public function createEventSource() {
  1161. return new \OC_EventSource();
  1162. }
  1163. /**
  1164. * Get the active event logger
  1165. *
  1166. * The returned logger only logs data when debug mode is enabled
  1167. *
  1168. * @return \OCP\Diagnostics\IEventLogger
  1169. */
  1170. public function getEventLogger() {
  1171. return $this->query('EventLogger');
  1172. }
  1173. /**
  1174. * Get the active query logger
  1175. *
  1176. * The returned logger only logs data when debug mode is enabled
  1177. *
  1178. * @return \OCP\Diagnostics\IQueryLogger
  1179. */
  1180. public function getQueryLogger() {
  1181. return $this->query('QueryLogger');
  1182. }
  1183. /**
  1184. * Get the manager for temporary files and folders
  1185. *
  1186. * @return \OCP\ITempManager
  1187. */
  1188. public function getTempManager() {
  1189. return $this->query('TempManager');
  1190. }
  1191. /**
  1192. * Get the app manager
  1193. *
  1194. * @return \OCP\App\IAppManager
  1195. */
  1196. public function getAppManager() {
  1197. return $this->query('AppManager');
  1198. }
  1199. /**
  1200. * Creates a new mailer
  1201. *
  1202. * @return \OCP\Mail\IMailer
  1203. */
  1204. public function getMailer() {
  1205. return $this->query('Mailer');
  1206. }
  1207. /**
  1208. * Get the webroot
  1209. *
  1210. * @return string
  1211. */
  1212. public function getWebRoot() {
  1213. return $this->webRoot;
  1214. }
  1215. /**
  1216. * @return \OC\OCSClient
  1217. */
  1218. public function getOcsClient() {
  1219. return $this->query('OcsClient');
  1220. }
  1221. /**
  1222. * @return \OCP\IDateTimeZone
  1223. */
  1224. public function getDateTimeZone() {
  1225. return $this->query('DateTimeZone');
  1226. }
  1227. /**
  1228. * @return \OCP\IDateTimeFormatter
  1229. */
  1230. public function getDateTimeFormatter() {
  1231. return $this->query('DateTimeFormatter');
  1232. }
  1233. /**
  1234. * @return \OCP\Files\Config\IMountProviderCollection
  1235. */
  1236. public function getMountProviderCollection() {
  1237. return $this->query('MountConfigManager');
  1238. }
  1239. /**
  1240. * Get the IniWrapper
  1241. *
  1242. * @return IniGetWrapper
  1243. */
  1244. public function getIniWrapper() {
  1245. return $this->query('IniWrapper');
  1246. }
  1247. /**
  1248. * @return \OCP\Command\IBus
  1249. */
  1250. public function getCommandBus() {
  1251. return $this->query('AsyncCommandBus');
  1252. }
  1253. /**
  1254. * Get the trusted domain helper
  1255. *
  1256. * @return TrustedDomainHelper
  1257. */
  1258. public function getTrustedDomainHelper() {
  1259. return $this->query('TrustedDomainHelper');
  1260. }
  1261. /**
  1262. * Get the locking provider
  1263. *
  1264. * @return \OCP\Lock\ILockingProvider
  1265. * @since 8.1.0
  1266. */
  1267. public function getLockingProvider() {
  1268. return $this->query('LockingProvider');
  1269. }
  1270. /**
  1271. * @return \OCP\Files\Mount\IMountManager
  1272. **/
  1273. function getMountManager() {
  1274. return $this->query('MountManager');
  1275. }
  1276. /** @return \OCP\Files\Config\IUserMountCache */
  1277. function getUserMountCache() {
  1278. return $this->query('UserMountCache');
  1279. }
  1280. /**
  1281. * Get the MimeTypeDetector
  1282. *
  1283. * @return \OCP\Files\IMimeTypeDetector
  1284. */
  1285. public function getMimeTypeDetector() {
  1286. return $this->query('MimeTypeDetector');
  1287. }
  1288. /**
  1289. * Get the MimeTypeLoader
  1290. *
  1291. * @return \OCP\Files\IMimeTypeLoader
  1292. */
  1293. public function getMimeTypeLoader() {
  1294. return $this->query('MimeTypeLoader');
  1295. }
  1296. /**
  1297. * Get the manager of all the capabilities
  1298. *
  1299. * @return \OC\CapabilitiesManager
  1300. */
  1301. public function getCapabilitiesManager() {
  1302. return $this->query('CapabilitiesManager');
  1303. }
  1304. /**
  1305. * Get the EventDispatcher
  1306. *
  1307. * @return EventDispatcherInterface
  1308. * @since 8.2.0
  1309. */
  1310. public function getEventDispatcher() {
  1311. return $this->query('EventDispatcher');
  1312. }
  1313. /**
  1314. * Get the Notification Manager
  1315. *
  1316. * @return \OCP\Notification\IManager
  1317. * @since 8.2.0
  1318. */
  1319. public function getNotificationManager() {
  1320. return $this->query('NotificationManager');
  1321. }
  1322. /**
  1323. * @return \OCP\Comments\ICommentsManager
  1324. */
  1325. public function getCommentsManager() {
  1326. return $this->query('CommentsManager');
  1327. }
  1328. /**
  1329. * @return \OC_Defaults
  1330. */
  1331. public function getThemingDefaults() {
  1332. return $this->query('ThemingDefaults');
  1333. }
  1334. /**
  1335. * @return \OC\IntegrityCheck\Checker
  1336. */
  1337. public function getIntegrityCodeChecker() {
  1338. return $this->query('IntegrityCodeChecker');
  1339. }
  1340. /**
  1341. * @return \OC\Session\CryptoWrapper
  1342. */
  1343. public function getSessionCryptoWrapper() {
  1344. return $this->query('CryptoWrapper');
  1345. }
  1346. /**
  1347. * @return CsrfTokenManager
  1348. */
  1349. public function getCsrfTokenManager() {
  1350. return $this->query('CsrfTokenManager');
  1351. }
  1352. /**
  1353. * @return Throttler
  1354. */
  1355. public function getBruteForceThrottler() {
  1356. return $this->query('Throttler');
  1357. }
  1358. /**
  1359. * @return IContentSecurityPolicyManager
  1360. */
  1361. public function getContentSecurityPolicyManager() {
  1362. return $this->query('ContentSecurityPolicyManager');
  1363. }
  1364. /**
  1365. * @return ContentSecurityPolicyNonceManager
  1366. */
  1367. public function getContentSecurityPolicyNonceManager() {
  1368. return $this->query('ContentSecurityPolicyNonceManager');
  1369. }
  1370. /**
  1371. * Not a public API as of 8.2, wait for 9.0
  1372. *
  1373. * @return \OCA\Files_External\Service\BackendService
  1374. */
  1375. public function getStoragesBackendService() {
  1376. return $this->query('OCA\\Files_External\\Service\\BackendService');
  1377. }
  1378. /**
  1379. * Not a public API as of 8.2, wait for 9.0
  1380. *
  1381. * @return \OCA\Files_External\Service\GlobalStoragesService
  1382. */
  1383. public function getGlobalStoragesService() {
  1384. return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
  1385. }
  1386. /**
  1387. * Not a public API as of 8.2, wait for 9.0
  1388. *
  1389. * @return \OCA\Files_External\Service\UserGlobalStoragesService
  1390. */
  1391. public function getUserGlobalStoragesService() {
  1392. return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
  1393. }
  1394. /**
  1395. * Not a public API as of 8.2, wait for 9.0
  1396. *
  1397. * @return \OCA\Files_External\Service\UserStoragesService
  1398. */
  1399. public function getUserStoragesService() {
  1400. return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
  1401. }
  1402. /**
  1403. * @return \OCP\Share\IManager
  1404. */
  1405. public function getShareManager() {
  1406. return $this->query('ShareManager');
  1407. }
  1408. /**
  1409. * Returns the LDAP Provider
  1410. *
  1411. * @return \OCP\LDAP\ILDAPProvider
  1412. */
  1413. public function getLDAPProvider() {
  1414. return $this->query('LDAPProvider');
  1415. }
  1416. /**
  1417. * @return \OCP\Settings\IManager
  1418. */
  1419. public function getSettingsManager() {
  1420. return $this->query('SettingsManager');
  1421. }
  1422. /**
  1423. * @return \OCP\Files\IAppData
  1424. */
  1425. public function getAppDataDir($app) {
  1426. /** @var \OC\Files\AppData\Factory $factory */
  1427. $factory = $this->query(\OC\Files\AppData\Factory::class);
  1428. return $factory->get($app);
  1429. }
  1430. /**
  1431. * @return \OCP\Lockdown\ILockdownManager
  1432. */
  1433. public function getLockdownManager() {
  1434. return $this->query('LockdownManager');
  1435. }
  1436. }