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 44KB

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