Server.php 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067
  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 Christoph Wurst <christoph@owncloud.com>
  13. * @author Christopher Schäpers <kondou@ts.unde.re>
  14. * @author Damjan Georgievski <gdamjan@gmail.com>
  15. * @author Joas Schilling <coding@schilljs.com>
  16. * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  17. * @author Julius Haertl <jus@bitgrid.net>
  18. * @author Julius Härtl <jus@bitgrid.net>
  19. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  20. * @author Lukas Reschke <lukas@statuscode.ch>
  21. * @author Morris Jobke <hey@morrisjobke.de>
  22. * @author Piotr Mrówczyński <mrow4a@yahoo.com>
  23. * @author Robin Appelman <robin@icewind.nl>
  24. * @author Robin McCorkell <robin@mccorkell.me.uk>
  25. * @author Roeland Jago Douma <roeland@famdouma.nl>
  26. * @author root <root@localhost.localdomain>
  27. * @author Sander <brantje@gmail.com>
  28. * @author Thomas Müller <thomas.mueller@tmit.eu>
  29. * @author Thomas Tanghus <thomas@tanghus.net>
  30. * @author Vincent Petry <pvince81@owncloud.com>
  31. *
  32. * @license AGPL-3.0
  33. *
  34. * This code is free software: you can redistribute it and/or modify
  35. * it under the terms of the GNU Affero General Public License, version 3,
  36. * as published by the Free Software Foundation.
  37. *
  38. * This program is distributed in the hope that it will be useful,
  39. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  40. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  41. * GNU Affero General Public License for more details.
  42. *
  43. * You should have received a copy of the GNU Affero General Public License, version 3,
  44. * along with this program. If not, see <http://www.gnu.org/licenses/>
  45. *
  46. */
  47. namespace OC;
  48. use bantu\IniGetWrapper\IniGetWrapper;
  49. use OC\Accounts\AccountManager;
  50. use OC\App\AppManager;
  51. use OC\App\AppStore\Bundles\BundleFetcher;
  52. use OC\App\AppStore\Fetcher\AppFetcher;
  53. use OC\App\AppStore\Fetcher\CategoryFetcher;
  54. use OC\AppFramework\Http\Request;
  55. use OC\AppFramework\Utility\SimpleContainer;
  56. use OC\AppFramework\Utility\TimeFactory;
  57. use OC\Authentication\LoginCredentials\Store;
  58. use OC\Authentication\Token\IProvider;
  59. use OC\Avatar\AvatarManager;
  60. use OC\Collaboration\Collaborators\GroupPlugin;
  61. use OC\Collaboration\Collaborators\MailPlugin;
  62. use OC\Collaboration\Collaborators\RemoteGroupPlugin;
  63. use OC\Collaboration\Collaborators\RemotePlugin;
  64. use OC\Collaboration\Collaborators\UserPlugin;
  65. use OC\Command\CronBus;
  66. use OC\Comments\ManagerFactory as CommentsManagerFactory;
  67. use OC\Contacts\ContactsMenu\ActionFactory;
  68. use OC\Contacts\ContactsMenu\ContactsStore;
  69. use OC\Diagnostics\EventLogger;
  70. use OC\Diagnostics\QueryLogger;
  71. use OC\Federation\CloudFederationFactory;
  72. use OC\Federation\CloudFederationProviderManager;
  73. use OC\Federation\CloudIdManager;
  74. use OC\Files\Config\UserMountCache;
  75. use OC\Files\Config\UserMountCacheListener;
  76. use OC\Files\Mount\CacheMountProvider;
  77. use OC\Files\Mount\LocalHomeMountProvider;
  78. use OC\Files\Mount\ObjectHomeMountProvider;
  79. use OC\Files\Node\HookConnector;
  80. use OC\Files\Node\LazyRoot;
  81. use OC\Files\Node\Root;
  82. use OC\Files\Storage\StorageFactory;
  83. use OC\Files\View;
  84. use OC\FullTextSearch\FullTextSearchManager;
  85. use OC\Http\Client\ClientService;
  86. use OC\IntegrityCheck\Checker;
  87. use OC\IntegrityCheck\Helpers\AppLocator;
  88. use OC\IntegrityCheck\Helpers\EnvironmentHelper;
  89. use OC\IntegrityCheck\Helpers\FileAccessHelper;
  90. use OC\Lock\DBLockingProvider;
  91. use OC\Lock\MemcacheLockingProvider;
  92. use OC\Lock\NoopLockingProvider;
  93. use OC\Lockdown\LockdownManager;
  94. use OC\Log\LogFactory;
  95. use OC\Mail\Mailer;
  96. use OC\Memcache\ArrayCache;
  97. use OC\Memcache\Factory;
  98. use OC\Notification\Manager;
  99. use OC\OCS\DiscoveryService;
  100. use OC\Remote\Api\ApiFactory;
  101. use OC\Remote\InstanceFactory;
  102. use OC\RichObjectStrings\Validator;
  103. use OC\Security\Bruteforce\Throttler;
  104. use OC\Security\CertificateManager;
  105. use OC\Security\CSP\ContentSecurityPolicyManager;
  106. use OC\Security\Crypto;
  107. use OC\Security\CSP\ContentSecurityPolicyNonceManager;
  108. use OC\Security\CSRF\CsrfTokenGenerator;
  109. use OC\Security\CSRF\CsrfTokenManager;
  110. use OC\Security\CSRF\TokenStorage\SessionStorage;
  111. use OC\Security\Hasher;
  112. use OC\Security\CredentialsManager;
  113. use OC\Security\SecureRandom;
  114. use OC\Security\TrustedDomainHelper;
  115. use OC\Session\CryptoWrapper;
  116. use OC\Share20\ProviderFactory;
  117. use OC\Share20\ShareHelper;
  118. use OC\SystemTag\ManagerFactory as SystemTagManagerFactory;
  119. use OC\Tagging\TagMapper;
  120. use OC\Template\IconsCacher;
  121. use OC\Template\JSCombiner;
  122. use OC\Template\SCSSCacher;
  123. use OC\Dashboard\DashboardManager;
  124. use OCA\Theming\ImageManager;
  125. use OCA\Theming\ThemingDefaults;
  126. use OCP\Accounts\IAccountManager;
  127. use OCP\App\IAppManager;
  128. use OCP\AppFramework\Utility\ITimeFactory;
  129. use OCP\Collaboration\AutoComplete\IManager;
  130. use OCP\Contacts\ContactsMenu\IContactsStore;
  131. use OCP\Dashboard\IDashboardManager;
  132. use OCP\Defaults;
  133. use OCA\Theming\Util;
  134. use OCP\Federation\ICloudFederationFactory;
  135. use OCP\Federation\ICloudFederationProviderManager;
  136. use OCP\Federation\ICloudIdManager;
  137. use OCP\Authentication\LoginCredentials\IStore;
  138. use OCP\Files\NotFoundException;
  139. use OCP\Files\Storage\IStorageFactory;
  140. use OCP\FullTextSearch\IFullTextSearchManager;
  141. use OCP\GlobalScale\IConfig;
  142. use OCP\Group\ISubAdmin;
  143. use OCP\ICacheFactory;
  144. use OCP\IDBConnection;
  145. use OCP\IInitialStateService;
  146. use OCP\IL10N;
  147. use OCP\IServerContainer;
  148. use OCP\ITempManager;
  149. use OCP\Contacts\ContactsMenu\IActionFactory;
  150. use OCP\IUser;
  151. use OCP\Lock\ILockingProvider;
  152. use OCP\Log\ILogFactory;
  153. use OCP\Remote\Api\IApiFactory;
  154. use OCP\Remote\IInstanceFactory;
  155. use OCP\RichObjectStrings\IValidator;
  156. use OCP\Security\IContentSecurityPolicyManager;
  157. use OCP\Share\IShareHelper;
  158. use Symfony\Component\EventDispatcher\EventDispatcher;
  159. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  160. use Symfony\Component\EventDispatcher\GenericEvent;
  161. /**
  162. * Class Server
  163. *
  164. * @package OC
  165. *
  166. * TODO: hookup all manager classes
  167. */
  168. class Server extends ServerContainer implements IServerContainer {
  169. /** @var string */
  170. private $webRoot;
  171. /**
  172. * @param string $webRoot
  173. * @param \OC\Config $config
  174. */
  175. public function __construct($webRoot, \OC\Config $config) {
  176. parent::__construct();
  177. $this->webRoot = $webRoot;
  178. // To find out if we are running from CLI or not
  179. $this->registerParameter('isCLI', \OC::$CLI);
  180. $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) {
  181. return $c;
  182. });
  183. $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
  184. $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class);
  185. $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class);
  186. $this->registerAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class);
  187. $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class);
  188. $this->registerAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class);
  189. $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
  190. $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
  191. $this->registerAlias(IActionFactory::class, ActionFactory::class);
  192. $this->registerService(\OCP\IPreview::class, function (Server $c) {
  193. return new PreviewManager(
  194. $c->getConfig(),
  195. $c->getRootFolder(),
  196. $c->getAppDataDir('preview'),
  197. $c->getEventDispatcher(),
  198. $c->getSession()->get('user_id')
  199. );
  200. });
  201. $this->registerAlias('PreviewManager', \OCP\IPreview::class);
  202. $this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
  203. return new \OC\Preview\Watcher(
  204. $c->getAppDataDir('preview')
  205. );
  206. });
  207. $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) {
  208. $view = new View();
  209. $util = new Encryption\Util(
  210. $view,
  211. $c->getUserManager(),
  212. $c->getGroupManager(),
  213. $c->getConfig()
  214. );
  215. return new Encryption\Manager(
  216. $c->getConfig(),
  217. $c->getLogger(),
  218. $c->getL10N('core'),
  219. new View(),
  220. $util,
  221. new ArrayCache()
  222. );
  223. });
  224. $this->registerAlias('EncryptionManager', \OCP\Encryption\IManager::class);
  225. $this->registerService('EncryptionFileHelper', function (Server $c) {
  226. $util = new Encryption\Util(
  227. new View(),
  228. $c->getUserManager(),
  229. $c->getGroupManager(),
  230. $c->getConfig()
  231. );
  232. return new Encryption\File(
  233. $util,
  234. $c->getRootFolder(),
  235. $c->getShareManager()
  236. );
  237. });
  238. $this->registerService('EncryptionKeyStorage', function (Server $c) {
  239. $view = new View();
  240. $util = new Encryption\Util(
  241. $view,
  242. $c->getUserManager(),
  243. $c->getGroupManager(),
  244. $c->getConfig()
  245. );
  246. return new Encryption\Keys\Storage($view, $util);
  247. });
  248. $this->registerService('TagMapper', function (Server $c) {
  249. return new TagMapper($c->getDatabaseConnection());
  250. });
  251. $this->registerService(\OCP\ITagManager::class, function (Server $c) {
  252. $tagMapper = $c->query('TagMapper');
  253. return new TagManager($tagMapper, $c->getUserSession());
  254. });
  255. $this->registerAlias('TagManager', \OCP\ITagManager::class);
  256. $this->registerService('SystemTagManagerFactory', function (Server $c) {
  257. $config = $c->getConfig();
  258. $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
  259. return new $factoryClass($this);
  260. });
  261. $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
  262. return $c->query('SystemTagManagerFactory')->getManager();
  263. });
  264. $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
  265. $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
  266. return $c->query('SystemTagManagerFactory')->getObjectMapper();
  267. });
  268. $this->registerService('RootFolder', function (Server $c) {
  269. $manager = \OC\Files\Filesystem::getMountManager(null);
  270. $view = new View();
  271. $root = new Root(
  272. $manager,
  273. $view,
  274. null,
  275. $c->getUserMountCache(),
  276. $this->getLogger(),
  277. $this->getUserManager()
  278. );
  279. $connector = new HookConnector($root, $view);
  280. $connector->viewToNode();
  281. $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
  282. $previewConnector->connectWatcher();
  283. return $root;
  284. });
  285. $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
  286. $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) {
  287. return new LazyRoot(function () use ($c) {
  288. return $c->query('RootFolder');
  289. });
  290. });
  291. $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
  292. $this->registerService(\OC\User\Manager::class, function (Server $c) {
  293. $config = $c->getConfig();
  294. return new \OC\User\Manager($config);
  295. });
  296. $this->registerAlias('UserManager', \OC\User\Manager::class);
  297. $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
  298. $this->registerService(\OCP\IGroupManager::class, function (Server $c) {
  299. $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
  300. $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
  301. \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
  302. });
  303. $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
  304. \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
  305. });
  306. $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
  307. \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
  308. });
  309. $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
  310. \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
  311. });
  312. $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
  313. \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
  314. });
  315. $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
  316. \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
  317. //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
  318. \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
  319. });
  320. return $groupManager;
  321. });
  322. $this->registerAlias('GroupManager', \OCP\IGroupManager::class);
  323. $this->registerService(Store::class, function (Server $c) {
  324. $session = $c->getSession();
  325. if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
  326. $tokenProvider = $c->query(IProvider::class);
  327. } else {
  328. $tokenProvider = null;
  329. }
  330. $logger = $c->getLogger();
  331. return new Store($session, $logger, $tokenProvider);
  332. });
  333. $this->registerAlias(IStore::class, Store::class);
  334. $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) {
  335. $dbConnection = $c->getDatabaseConnection();
  336. return new Authentication\Token\DefaultTokenMapper($dbConnection);
  337. });
  338. $this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
  339. $this->registerService(\OC\User\Session::class, function (Server $c) {
  340. $manager = $c->getUserManager();
  341. $session = new \OC\Session\Memory('');
  342. $timeFactory = new TimeFactory();
  343. // Token providers might require a working database. This code
  344. // might however be called when ownCloud is not yet setup.
  345. if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
  346. $defaultTokenProvider = $c->query(IProvider::class);
  347. } else {
  348. $defaultTokenProvider = null;
  349. }
  350. $dispatcher = $c->getEventDispatcher();
  351. $userSession = new \OC\User\Session(
  352. $manager,
  353. $session,
  354. $timeFactory,
  355. $defaultTokenProvider,
  356. $c->getConfig(),
  357. $c->getSecureRandom(),
  358. $c->getLockdownManager(),
  359. $c->getLogger()
  360. );
  361. $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
  362. \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
  363. });
  364. $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
  365. /** @var $user \OC\User\User */
  366. \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
  367. });
  368. $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) {
  369. /** @var $user \OC\User\User */
  370. \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
  371. $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
  372. });
  373. $userSession->listen('\OC\User', 'postDelete', function ($user) {
  374. /** @var $user \OC\User\User */
  375. \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
  376. });
  377. $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
  378. /** @var $user \OC\User\User */
  379. \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
  380. });
  381. $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
  382. /** @var $user \OC\User\User */
  383. \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
  384. });
  385. $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
  386. \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
  387. });
  388. $userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) {
  389. /** @var $user \OC\User\User */
  390. \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin));
  391. });
  392. $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
  393. /** @var $user \OC\User\User */
  394. \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
  395. });
  396. $userSession->listen('\OC\User', 'logout', function () {
  397. \OC_Hook::emit('OC_User', 'logout', array());
  398. });
  399. $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) {
  400. /** @var $user \OC\User\User */
  401. \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
  402. $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value]));
  403. });
  404. return $userSession;
  405. });
  406. $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class);
  407. $this->registerAlias('UserSession', \OC\User\Session::class);
  408. $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class);
  409. $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
  410. $this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
  411. $this->registerService(\OC\AllConfig::class, function (Server $c) {
  412. return new \OC\AllConfig(
  413. $c->getSystemConfig()
  414. );
  415. });
  416. $this->registerAlias('AllConfig', \OC\AllConfig::class);
  417. $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
  418. $this->registerService('SystemConfig', function ($c) use ($config) {
  419. return new \OC\SystemConfig($config);
  420. });
  421. $this->registerService(\OC\AppConfig::class, function (Server $c) {
  422. return new \OC\AppConfig($c->getDatabaseConnection());
  423. });
  424. $this->registerAlias('AppConfig', \OC\AppConfig::class);
  425. $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
  426. $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
  427. return new \OC\L10N\Factory(
  428. $c->getConfig(),
  429. $c->getRequest(),
  430. $c->getUserSession(),
  431. \OC::$SERVERROOT
  432. );
  433. });
  434. $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
  435. $this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
  436. $config = $c->getConfig();
  437. $cacheFactory = $c->getMemCacheFactory();
  438. $request = $c->getRequest();
  439. return new \OC\URLGenerator(
  440. $config,
  441. $cacheFactory,
  442. $request
  443. );
  444. });
  445. $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
  446. $this->registerAlias('AppFetcher', AppFetcher::class);
  447. $this->registerAlias('CategoryFetcher', CategoryFetcher::class);
  448. $this->registerService(\OCP\ICache::class, function ($c) {
  449. return new Cache\File();
  450. });
  451. $this->registerAlias('UserCache', \OCP\ICache::class);
  452. $this->registerService(Factory::class, function (Server $c) {
  453. $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
  454. ArrayCache::class,
  455. ArrayCache::class,
  456. ArrayCache::class
  457. );
  458. $config = $c->getConfig();
  459. $request = $c->getRequest();
  460. $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request);
  461. if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
  462. $v = \OC_App::getAppVersions();
  463. $v['core'] = implode(',', \OC_Util::getVersion());
  464. $version = implode(',', $v);
  465. $instanceId = \OC_Util::getInstanceId();
  466. $path = \OC::$SERVERROOT;
  467. $prefix = md5($instanceId . '-' . $version . '-' . $path);
  468. return new \OC\Memcache\Factory($prefix, $c->getLogger(),
  469. $config->getSystemValue('memcache.local', null),
  470. $config->getSystemValue('memcache.distributed', null),
  471. $config->getSystemValue('memcache.locking', null)
  472. );
  473. }
  474. return $arrayCacheFactory;
  475. });
  476. $this->registerAlias('MemCacheFactory', Factory::class);
  477. $this->registerAlias(ICacheFactory::class, Factory::class);
  478. $this->registerService('RedisFactory', function (Server $c) {
  479. $systemConfig = $c->getSystemConfig();
  480. return new RedisFactory($systemConfig);
  481. });
  482. $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
  483. return new \OC\Activity\Manager(
  484. $c->getRequest(),
  485. $c->getUserSession(),
  486. $c->getConfig(),
  487. $c->query(IValidator::class)
  488. );
  489. });
  490. $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
  491. $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
  492. return new \OC\Activity\EventMerger(
  493. $c->getL10N('lib')
  494. );
  495. });
  496. $this->registerAlias(IValidator::class, Validator::class);
  497. $this->registerService(AvatarManager::class, function(Server $c) {
  498. return new AvatarManager(
  499. $c->query(\OC\User\Manager::class),
  500. $c->getAppDataDir('avatar'),
  501. $c->getL10N('lib'),
  502. $c->getLogger(),
  503. $c->getConfig()
  504. );
  505. });
  506. $this->registerAlias(\OCP\IAvatarManager::class, AvatarManager::class);
  507. $this->registerAlias('AvatarManager', AvatarManager::class);
  508. $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
  509. $this->registerService(\OC\Log::class, function (Server $c) {
  510. $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
  511. $factory = new LogFactory($c, $this->getSystemConfig());
  512. $logger = $factory->get($logType);
  513. $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class);
  514. return new Log($logger, $this->getSystemConfig(), null, $registry);
  515. });
  516. $this->registerAlias(\OCP\ILogger::class, \OC\Log::class);
  517. $this->registerAlias('Logger', \OC\Log::class);
  518. $this->registerService(ILogFactory::class, function (Server $c) {
  519. return new LogFactory($c, $this->getSystemConfig());
  520. });
  521. $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
  522. $config = $c->getConfig();
  523. return new \OC\BackgroundJob\JobList(
  524. $c->getDatabaseConnection(),
  525. $config,
  526. new TimeFactory()
  527. );
  528. });
  529. $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
  530. $this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
  531. $cacheFactory = $c->getMemCacheFactory();
  532. $logger = $c->getLogger();
  533. if ($cacheFactory->isLocalCacheAvailable()) {
  534. $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
  535. } else {
  536. $router = new \OC\Route\Router($logger);
  537. }
  538. return $router;
  539. });
  540. $this->registerAlias('Router', \OCP\Route\IRouter::class);
  541. $this->registerService(\OCP\ISearch::class, function ($c) {
  542. return new Search();
  543. });
  544. $this->registerAlias('Search', \OCP\ISearch::class);
  545. $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) {
  546. return new \OC\Security\RateLimiting\Limiter(
  547. $this->getUserSession(),
  548. $this->getRequest(),
  549. new \OC\AppFramework\Utility\TimeFactory(),
  550. $c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
  551. );
  552. });
  553. $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
  554. return new \OC\Security\RateLimiting\Backend\MemoryCache(
  555. $this->getMemCacheFactory(),
  556. new \OC\AppFramework\Utility\TimeFactory()
  557. );
  558. });
  559. $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
  560. return new SecureRandom();
  561. });
  562. $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
  563. $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
  564. return new Crypto($c->getConfig(), $c->getSecureRandom());
  565. });
  566. $this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
  567. $this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
  568. return new Hasher($c->getConfig());
  569. });
  570. $this->registerAlias('Hasher', \OCP\Security\IHasher::class);
  571. $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
  572. return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
  573. });
  574. $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
  575. $this->registerService(IDBConnection::class, function (Server $c) {
  576. $systemConfig = $c->getSystemConfig();
  577. $factory = new \OC\DB\ConnectionFactory($systemConfig);
  578. $type = $systemConfig->getValue('dbtype', 'sqlite');
  579. if (!$factory->isValidType($type)) {
  580. throw new \OC\DatabaseException('Invalid database type');
  581. }
  582. $connectionParams = $factory->createConnectionParams();
  583. $connection = $factory->getConnection($type, $connectionParams);
  584. $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
  585. return $connection;
  586. });
  587. $this->registerAlias('DatabaseConnection', IDBConnection::class);
  588. $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
  589. $user = \OC_User::getUser();
  590. $uid = $user ? $user : null;
  591. return new ClientService(
  592. $c->getConfig(),
  593. new \OC\Security\CertificateManager(
  594. $uid,
  595. new View(),
  596. $c->getConfig(),
  597. $c->getLogger(),
  598. $c->getSecureRandom()
  599. )
  600. );
  601. });
  602. $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
  603. $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
  604. $eventLogger = new EventLogger();
  605. if ($c->getSystemConfig()->getValue('debug', false)) {
  606. // In debug mode, module is being activated by default
  607. $eventLogger->activate();
  608. }
  609. return $eventLogger;
  610. });
  611. $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
  612. $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
  613. $queryLogger = new QueryLogger();
  614. if ($c->getSystemConfig()->getValue('debug', false)) {
  615. // In debug mode, module is being activated by default
  616. $queryLogger->activate();
  617. }
  618. return $queryLogger;
  619. });
  620. $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
  621. $this->registerService(TempManager::class, function (Server $c) {
  622. return new TempManager(
  623. $c->getLogger(),
  624. $c->getConfig()
  625. );
  626. });
  627. $this->registerAlias('TempManager', TempManager::class);
  628. $this->registerAlias(ITempManager::class, TempManager::class);
  629. $this->registerService(AppManager::class, function (Server $c) {
  630. return new \OC\App\AppManager(
  631. $c->getUserSession(),
  632. $c->query(\OC\AppConfig::class),
  633. $c->getGroupManager(),
  634. $c->getMemCacheFactory(),
  635. $c->getEventDispatcher()
  636. );
  637. });
  638. $this->registerAlias('AppManager', AppManager::class);
  639. $this->registerAlias(IAppManager::class, AppManager::class);
  640. $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
  641. return new DateTimeZone(
  642. $c->getConfig(),
  643. $c->getSession()
  644. );
  645. });
  646. $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
  647. $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
  648. $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
  649. return new DateTimeFormatter(
  650. $c->getDateTimeZone()->getTimeZone(),
  651. $c->getL10N('lib', $language)
  652. );
  653. });
  654. $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
  655. $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
  656. $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
  657. $listener = new UserMountCacheListener($mountCache);
  658. $listener->listen($c->getUserManager());
  659. return $mountCache;
  660. });
  661. $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
  662. $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
  663. $loader = \OC\Files\Filesystem::getLoader();
  664. $mountCache = $c->query('UserMountCache');
  665. $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
  666. // builtin providers
  667. $config = $c->getConfig();
  668. $manager->registerProvider(new CacheMountProvider($config));
  669. $manager->registerHomeProvider(new LocalHomeMountProvider());
  670. $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
  671. return $manager;
  672. });
  673. $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
  674. $this->registerService('IniWrapper', function ($c) {
  675. return new IniGetWrapper();
  676. });
  677. $this->registerService('AsyncCommandBus', function (Server $c) {
  678. $busClass = $c->getConfig()->getSystemValue('commandbus');
  679. if ($busClass) {
  680. list($app, $class) = explode('::', $busClass, 2);
  681. if ($c->getAppManager()->isInstalled($app)) {
  682. \OC_App::loadApp($app);
  683. return $c->query($class);
  684. } else {
  685. throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
  686. }
  687. } else {
  688. $jobList = $c->getJobList();
  689. return new CronBus($jobList);
  690. }
  691. });
  692. $this->registerService('TrustedDomainHelper', function ($c) {
  693. return new TrustedDomainHelper($this->getConfig());
  694. });
  695. $this->registerService(Throttler::class, function (Server $c) {
  696. return new Throttler(
  697. $c->getDatabaseConnection(),
  698. new TimeFactory(),
  699. $c->getLogger(),
  700. $c->getConfig()
  701. );
  702. });
  703. $this->registerAlias('Throttler', Throttler::class);
  704. $this->registerService('IntegrityCodeChecker', function (Server $c) {
  705. // IConfig and IAppManager requires a working database. This code
  706. // might however be called when ownCloud is not yet setup.
  707. if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
  708. $config = $c->getConfig();
  709. $appManager = $c->getAppManager();
  710. } else {
  711. $config = null;
  712. $appManager = null;
  713. }
  714. return new Checker(
  715. new EnvironmentHelper(),
  716. new FileAccessHelper(),
  717. new AppLocator(),
  718. $config,
  719. $c->getMemCacheFactory(),
  720. $appManager,
  721. $c->getTempManager()
  722. );
  723. });
  724. $this->registerService(\OCP\IRequest::class, function ($c) {
  725. if (isset($this['urlParams'])) {
  726. $urlParams = $this['urlParams'];
  727. } else {
  728. $urlParams = [];
  729. }
  730. if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
  731. && in_array('fakeinput', stream_get_wrappers())
  732. ) {
  733. $stream = 'fakeinput://data';
  734. } else {
  735. $stream = 'php://input';
  736. }
  737. return new Request(
  738. [
  739. 'get' => $_GET,
  740. 'post' => $_POST,
  741. 'files' => $_FILES,
  742. 'server' => $_SERVER,
  743. 'env' => $_ENV,
  744. 'cookies' => $_COOKIE,
  745. 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
  746. ? $_SERVER['REQUEST_METHOD']
  747. : '',
  748. 'urlParams' => $urlParams,
  749. ],
  750. $this->getSecureRandom(),
  751. $this->getConfig(),
  752. $this->getCsrfTokenManager(),
  753. $stream
  754. );
  755. });
  756. $this->registerAlias('Request', \OCP\IRequest::class);
  757. $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
  758. return new Mailer(
  759. $c->getConfig(),
  760. $c->getLogger(),
  761. $c->query(Defaults::class),
  762. $c->getURLGenerator(),
  763. $c->getL10N('lib')
  764. );
  765. });
  766. $this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
  767. $this->registerService('LDAPProvider', function (Server $c) {
  768. $config = $c->getConfig();
  769. $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
  770. if (is_null($factoryClass)) {
  771. throw new \Exception('ldapProviderFactory not set');
  772. }
  773. /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
  774. $factory = new $factoryClass($this);
  775. return $factory->getLDAPProvider();
  776. });
  777. $this->registerService(ILockingProvider::class, function (Server $c) {
  778. $ini = $c->getIniWrapper();
  779. $config = $c->getConfig();
  780. $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
  781. if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
  782. /** @var \OC\Memcache\Factory $memcacheFactory */
  783. $memcacheFactory = $c->getMemCacheFactory();
  784. $memcache = $memcacheFactory->createLocking('lock');
  785. if (!($memcache instanceof \OC\Memcache\NullCache)) {
  786. return new MemcacheLockingProvider($memcache, $ttl);
  787. }
  788. return new DBLockingProvider(
  789. $c->getDatabaseConnection(),
  790. $c->getLogger(),
  791. new TimeFactory(),
  792. $ttl,
  793. !\OC::$CLI
  794. );
  795. }
  796. return new NoopLockingProvider();
  797. });
  798. $this->registerAlias('LockingProvider', ILockingProvider::class);
  799. $this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
  800. return new \OC\Files\Mount\Manager();
  801. });
  802. $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
  803. $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
  804. return new \OC\Files\Type\Detection(
  805. $c->getURLGenerator(),
  806. \OC::$configDir,
  807. \OC::$SERVERROOT . '/resources/config/'
  808. );
  809. });
  810. $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
  811. $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
  812. return new \OC\Files\Type\Loader(
  813. $c->getDatabaseConnection()
  814. );
  815. });
  816. $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
  817. $this->registerService(BundleFetcher::class, function () {
  818. return new BundleFetcher($this->getL10N('lib'));
  819. });
  820. $this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
  821. return new Manager(
  822. $c->query(IValidator::class)
  823. );
  824. });
  825. $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
  826. $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
  827. $manager = new \OC\CapabilitiesManager($c->getLogger());
  828. $manager->registerCapability(function () use ($c) {
  829. return new \OC\OCS\CoreCapabilities($c->getConfig());
  830. });
  831. $manager->registerCapability(function () use ($c) {
  832. return $c->query(\OC\Security\Bruteforce\Capabilities::class);
  833. });
  834. return $manager;
  835. });
  836. $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
  837. $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) {
  838. $config = $c->getConfig();
  839. $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
  840. /** @var \OCP\Comments\ICommentsManagerFactory $factory */
  841. $factory = new $factoryClass($this);
  842. $manager = $factory->getManager();
  843. $manager->registerDisplayNameResolver('user', function($id) use ($c) {
  844. $manager = $c->getUserManager();
  845. $user = $manager->get($id);
  846. if(is_null($user)) {
  847. $l = $c->getL10N('core');
  848. $displayName = $l->t('Unknown user');
  849. } else {
  850. $displayName = $user->getDisplayName();
  851. }
  852. return $displayName;
  853. });
  854. return $manager;
  855. });
  856. $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
  857. $this->registerService('ThemingDefaults', function (Server $c) {
  858. /*
  859. * Dark magic for autoloader.
  860. * If we do a class_exists it will try to load the class which will
  861. * make composer cache the result. Resulting in errors when enabling
  862. * the theming app.
  863. */
  864. $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
  865. if (isset($prefixes['OCA\\Theming\\'])) {
  866. $classExists = true;
  867. } else {
  868. $classExists = false;
  869. }
  870. if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
  871. return new ThemingDefaults(
  872. $c->getConfig(),
  873. $c->getL10N('theming'),
  874. $c->getURLGenerator(),
  875. $c->getMemCacheFactory(),
  876. new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')),
  877. new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()),
  878. $c->getAppManager(),
  879. $c->getNavigationManager()
  880. );
  881. }
  882. return new \OC_Defaults();
  883. });
  884. $this->registerService(SCSSCacher::class, function (Server $c) {
  885. /** @var Factory $cacheFactory */
  886. $cacheFactory = $c->query(Factory::class);
  887. return new SCSSCacher(
  888. $c->getLogger(),
  889. $c->query(\OC\Files\AppData\Factory::class),
  890. $c->getURLGenerator(),
  891. $c->getConfig(),
  892. $c->getThemingDefaults(),
  893. \OC::$SERVERROOT,
  894. $this->getMemCacheFactory(),
  895. $c->query(IconsCacher::class),
  896. new TimeFactory()
  897. );
  898. });
  899. $this->registerService(JSCombiner::class, function (Server $c) {
  900. /** @var Factory $cacheFactory */
  901. $cacheFactory = $c->query(Factory::class);
  902. return new JSCombiner(
  903. $c->getAppDataDir('js'),
  904. $c->getURLGenerator(),
  905. $this->getMemCacheFactory(),
  906. $c->getSystemConfig(),
  907. $c->getLogger()
  908. );
  909. });
  910. $this->registerService(EventDispatcher::class, function () {
  911. return new EventDispatcher();
  912. });
  913. $this->registerAlias('EventDispatcher', EventDispatcher::class);
  914. $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
  915. $this->registerService('CryptoWrapper', function (Server $c) {
  916. // FIXME: Instantiiated here due to cyclic dependency
  917. $request = new Request(
  918. [
  919. 'get' => $_GET,
  920. 'post' => $_POST,
  921. 'files' => $_FILES,
  922. 'server' => $_SERVER,
  923. 'env' => $_ENV,
  924. 'cookies' => $_COOKIE,
  925. 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
  926. ? $_SERVER['REQUEST_METHOD']
  927. : null,
  928. ],
  929. $c->getSecureRandom(),
  930. $c->getConfig()
  931. );
  932. return new CryptoWrapper(
  933. $c->getConfig(),
  934. $c->getCrypto(),
  935. $c->getSecureRandom(),
  936. $request
  937. );
  938. });
  939. $this->registerService('CsrfTokenManager', function (Server $c) {
  940. $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
  941. return new CsrfTokenManager(
  942. $tokenGenerator,
  943. $c->query(SessionStorage::class)
  944. );
  945. });
  946. $this->registerService(SessionStorage::class, function (Server $c) {
  947. return new SessionStorage($c->getSession());
  948. });
  949. $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
  950. return new ContentSecurityPolicyManager();
  951. });
  952. $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
  953. $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) {
  954. return new ContentSecurityPolicyNonceManager(
  955. $c->getCsrfTokenManager(),
  956. $c->getRequest()
  957. );
  958. });
  959. $this->registerService(\OCP\Share\IManager::class, function (Server $c) {
  960. $config = $c->getConfig();
  961. $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
  962. /** @var \OCP\Share\IProviderFactory $factory */
  963. $factory = new $factoryClass($this);
  964. $manager = new \OC\Share20\Manager(
  965. $c->getLogger(),
  966. $c->getConfig(),
  967. $c->getSecureRandom(),
  968. $c->getHasher(),
  969. $c->getMountManager(),
  970. $c->getGroupManager(),
  971. $c->getL10N('lib'),
  972. $c->getL10NFactory(),
  973. $factory,
  974. $c->getUserManager(),
  975. $c->getLazyRootFolder(),
  976. $c->getEventDispatcher(),
  977. $c->getMailer(),
  978. $c->getURLGenerator(),
  979. $c->getThemingDefaults()
  980. );
  981. return $manager;
  982. });
  983. $this->registerAlias('ShareManager', \OCP\Share\IManager::class);
  984. $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) {
  985. $instance = new Collaboration\Collaborators\Search($c);
  986. // register default plugins
  987. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
  988. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
  989. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
  990. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
  991. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]);
  992. return $instance;
  993. });
  994. $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
  995. $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class);
  996. $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
  997. $this->registerService('SettingsManager', function (Server $c) {
  998. $manager = new \OC\Settings\Manager(
  999. $c->getLogger(),
  1000. $c->getL10N('lib'),
  1001. $c->getURLGenerator(),
  1002. $c
  1003. );
  1004. return $manager;
  1005. });
  1006. $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
  1007. return new \OC\Files\AppData\Factory(
  1008. $c->getRootFolder(),
  1009. $c->getSystemConfig()
  1010. );
  1011. });
  1012. $this->registerService('LockdownManager', function (Server $c) {
  1013. return new LockdownManager(function () use ($c) {
  1014. return $c->getSession();
  1015. });
  1016. });
  1017. $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
  1018. return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
  1019. });
  1020. $this->registerService(ICloudIdManager::class, function (Server $c) {
  1021. return new CloudIdManager();
  1022. });
  1023. $this->registerService(IConfig::class, function (Server $c) {
  1024. return new GlobalScale\Config($c->getConfig());
  1025. });
  1026. $this->registerService(ICloudFederationProviderManager::class, function (Server $c) {
  1027. return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger());
  1028. });
  1029. $this->registerService(ICloudFederationFactory::class, function (Server $c) {
  1030. return new CloudFederationFactory();
  1031. });
  1032. $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
  1033. $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
  1034. $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
  1035. $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
  1036. $this->registerService(Defaults::class, function (Server $c) {
  1037. return new Defaults(
  1038. $c->getThemingDefaults()
  1039. );
  1040. });
  1041. $this->registerAlias('Defaults', \OCP\Defaults::class);
  1042. $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) {
  1043. return $c->query(\OCP\IUserSession::class)->getSession();
  1044. });
  1045. $this->registerService(IShareHelper::class, function (Server $c) {
  1046. return new ShareHelper(
  1047. $c->query(\OCP\Share\IManager::class)
  1048. );
  1049. });
  1050. $this->registerService(Installer::class, function(Server $c) {
  1051. return new Installer(
  1052. $c->getAppFetcher(),
  1053. $c->getHTTPClientService(),
  1054. $c->getTempManager(),
  1055. $c->getLogger(),
  1056. $c->getConfig()
  1057. );
  1058. });
  1059. $this->registerService(IApiFactory::class, function(Server $c) {
  1060. return new ApiFactory($c->getHTTPClientService());
  1061. });
  1062. $this->registerService(IInstanceFactory::class, function(Server $c) {
  1063. $memcacheFactory = $c->getMemCacheFactory();
  1064. return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService());
  1065. });
  1066. $this->registerService(IContactsStore::class, function(Server $c) {
  1067. return new ContactsStore(
  1068. $c->getContactsManager(),
  1069. $c->getConfig(),
  1070. $c->getUserManager(),
  1071. $c->getGroupManager()
  1072. );
  1073. });
  1074. $this->registerAlias(IContactsStore::class, ContactsStore::class);
  1075. $this->registerAlias(IAccountManager::class, AccountManager::class);
  1076. $this->registerService(IStorageFactory::class, function() {
  1077. return new StorageFactory();
  1078. });
  1079. $this->registerAlias(IDashboardManager::class, DashboardManager::class);
  1080. $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class);
  1081. $this->registerService(\OC\Security\IdentityProof\Manager::class, function (Server $c) {
  1082. return new \OC\Security\IdentityProof\Manager(
  1083. $c->query(\OC\Files\AppData\Factory::class),
  1084. $c->getCrypto(),
  1085. $c->getConfig()
  1086. );
  1087. });
  1088. $this->registerAlias(ISubAdmin::class, SubAdmin::class);
  1089. $this->registerAlias(IInitialStateService::class, InitialStateService::class);
  1090. $this->connectDispatcher();
  1091. }
  1092. /**
  1093. * @return \OCP\Calendar\IManager
  1094. */
  1095. public function getCalendarManager() {
  1096. return $this->query('CalendarManager');
  1097. }
  1098. /**
  1099. * @return \OCP\Calendar\Resource\IManager
  1100. */
  1101. public function getCalendarResourceBackendManager() {
  1102. return $this->query('CalendarResourceBackendManager');
  1103. }
  1104. /**
  1105. * @return \OCP\Calendar\Room\IManager
  1106. */
  1107. public function getCalendarRoomBackendManager() {
  1108. return $this->query('CalendarRoomBackendManager');
  1109. }
  1110. private function connectDispatcher() {
  1111. $dispatcher = $this->getEventDispatcher();
  1112. // Delete avatar on user deletion
  1113. $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) {
  1114. $logger = $this->getLogger();
  1115. $manager = $this->getAvatarManager();
  1116. /** @var IUser $user */
  1117. $user = $e->getSubject();
  1118. try {
  1119. $avatar = $manager->getAvatar($user->getUID());
  1120. $avatar->remove();
  1121. } catch (NotFoundException $e) {
  1122. // no avatar to remove
  1123. } catch (\Exception $e) {
  1124. // Ignore exceptions
  1125. $logger->info('Could not cleanup avatar of ' . $user->getUID());
  1126. }
  1127. });
  1128. $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
  1129. $manager = $this->getAvatarManager();
  1130. /** @var IUser $user */
  1131. $user = $e->getSubject();
  1132. $feature = $e->getArgument('feature');
  1133. $oldValue = $e->getArgument('oldValue');
  1134. $value = $e->getArgument('value');
  1135. try {
  1136. $avatar = $manager->getAvatar($user->getUID());
  1137. $avatar->userChanged($feature, $oldValue, $value);
  1138. } catch (NotFoundException $e) {
  1139. // no avatar to remove
  1140. }
  1141. });
  1142. }
  1143. /**
  1144. * @return \OCP\Contacts\IManager
  1145. */
  1146. public function getContactsManager() {
  1147. return $this->query('ContactsManager');
  1148. }
  1149. /**
  1150. * @return \OC\Encryption\Manager
  1151. */
  1152. public function getEncryptionManager() {
  1153. return $this->query('EncryptionManager');
  1154. }
  1155. /**
  1156. * @return \OC\Encryption\File
  1157. */
  1158. public function getEncryptionFilesHelper() {
  1159. return $this->query('EncryptionFileHelper');
  1160. }
  1161. /**
  1162. * @return \OCP\Encryption\Keys\IStorage
  1163. */
  1164. public function getEncryptionKeyStorage() {
  1165. return $this->query('EncryptionKeyStorage');
  1166. }
  1167. /**
  1168. * The current request object holding all information about the request
  1169. * currently being processed is returned from this method.
  1170. * In case the current execution was not initiated by a web request null is returned
  1171. *
  1172. * @return \OCP\IRequest
  1173. */
  1174. public function getRequest() {
  1175. return $this->query('Request');
  1176. }
  1177. /**
  1178. * Returns the preview manager which can create preview images for a given file
  1179. *
  1180. * @return \OCP\IPreview
  1181. */
  1182. public function getPreviewManager() {
  1183. return $this->query('PreviewManager');
  1184. }
  1185. /**
  1186. * Returns the tag manager which can get and set tags for different object types
  1187. *
  1188. * @see \OCP\ITagManager::load()
  1189. * @return \OCP\ITagManager
  1190. */
  1191. public function getTagManager() {
  1192. return $this->query('TagManager');
  1193. }
  1194. /**
  1195. * Returns the system-tag manager
  1196. *
  1197. * @return \OCP\SystemTag\ISystemTagManager
  1198. *
  1199. * @since 9.0.0
  1200. */
  1201. public function getSystemTagManager() {
  1202. return $this->query('SystemTagManager');
  1203. }
  1204. /**
  1205. * Returns the system-tag object mapper
  1206. *
  1207. * @return \OCP\SystemTag\ISystemTagObjectMapper
  1208. *
  1209. * @since 9.0.0
  1210. */
  1211. public function getSystemTagObjectMapper() {
  1212. return $this->query('SystemTagObjectMapper');
  1213. }
  1214. /**
  1215. * Returns the avatar manager, used for avatar functionality
  1216. *
  1217. * @return \OCP\IAvatarManager
  1218. */
  1219. public function getAvatarManager() {
  1220. return $this->query('AvatarManager');
  1221. }
  1222. /**
  1223. * Returns the root folder of ownCloud's data directory
  1224. *
  1225. * @return \OCP\Files\IRootFolder
  1226. */
  1227. public function getRootFolder() {
  1228. return $this->query('LazyRootFolder');
  1229. }
  1230. /**
  1231. * Returns the root folder of ownCloud's data directory
  1232. * This is the lazy variant so this gets only initialized once it
  1233. * is actually used.
  1234. *
  1235. * @return \OCP\Files\IRootFolder
  1236. */
  1237. public function getLazyRootFolder() {
  1238. return $this->query('LazyRootFolder');
  1239. }
  1240. /**
  1241. * Returns a view to ownCloud's files folder
  1242. *
  1243. * @param string $userId user ID
  1244. * @return \OCP\Files\Folder|null
  1245. */
  1246. public function getUserFolder($userId = null) {
  1247. if ($userId === null) {
  1248. $user = $this->getUserSession()->getUser();
  1249. if (!$user) {
  1250. return null;
  1251. }
  1252. $userId = $user->getUID();
  1253. }
  1254. $root = $this->getRootFolder();
  1255. return $root->getUserFolder($userId);
  1256. }
  1257. /**
  1258. * Returns an app-specific view in ownClouds data directory
  1259. *
  1260. * @return \OCP\Files\Folder
  1261. * @deprecated since 9.2.0 use IAppData
  1262. */
  1263. public function getAppFolder() {
  1264. $dir = '/' . \OC_App::getCurrentApp();
  1265. $root = $this->getRootFolder();
  1266. if (!$root->nodeExists($dir)) {
  1267. $folder = $root->newFolder($dir);
  1268. } else {
  1269. $folder = $root->get($dir);
  1270. }
  1271. return $folder;
  1272. }
  1273. /**
  1274. * @return \OC\User\Manager
  1275. */
  1276. public function getUserManager() {
  1277. return $this->query('UserManager');
  1278. }
  1279. /**
  1280. * @return \OC\Group\Manager
  1281. */
  1282. public function getGroupManager() {
  1283. return $this->query('GroupManager');
  1284. }
  1285. /**
  1286. * @return \OC\User\Session
  1287. */
  1288. public function getUserSession() {
  1289. return $this->query('UserSession');
  1290. }
  1291. /**
  1292. * @return \OCP\ISession
  1293. */
  1294. public function getSession() {
  1295. return $this->query('UserSession')->getSession();
  1296. }
  1297. /**
  1298. * @param \OCP\ISession $session
  1299. */
  1300. public function setSession(\OCP\ISession $session) {
  1301. $this->query(SessionStorage::class)->setSession($session);
  1302. $this->query('UserSession')->setSession($session);
  1303. $this->query(Store::class)->setSession($session);
  1304. }
  1305. /**
  1306. * @return \OC\Authentication\TwoFactorAuth\Manager
  1307. */
  1308. public function getTwoFactorAuthManager() {
  1309. return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
  1310. }
  1311. /**
  1312. * @return \OC\NavigationManager
  1313. */
  1314. public function getNavigationManager() {
  1315. return $this->query('NavigationManager');
  1316. }
  1317. /**
  1318. * @return \OCP\IConfig
  1319. */
  1320. public function getConfig() {
  1321. return $this->query('AllConfig');
  1322. }
  1323. /**
  1324. * @return \OC\SystemConfig
  1325. */
  1326. public function getSystemConfig() {
  1327. return $this->query('SystemConfig');
  1328. }
  1329. /**
  1330. * Returns the app config manager
  1331. *
  1332. * @return \OCP\IAppConfig
  1333. */
  1334. public function getAppConfig() {
  1335. return $this->query('AppConfig');
  1336. }
  1337. /**
  1338. * @return \OCP\L10N\IFactory
  1339. */
  1340. public function getL10NFactory() {
  1341. return $this->query('L10NFactory');
  1342. }
  1343. /**
  1344. * get an L10N instance
  1345. *
  1346. * @param string $app appid
  1347. * @param string $lang
  1348. * @return IL10N
  1349. */
  1350. public function getL10N($app, $lang = null) {
  1351. return $this->getL10NFactory()->get($app, $lang);
  1352. }
  1353. /**
  1354. * @return \OCP\IURLGenerator
  1355. */
  1356. public function getURLGenerator() {
  1357. return $this->query('URLGenerator');
  1358. }
  1359. /**
  1360. * @return AppFetcher
  1361. */
  1362. public function getAppFetcher() {
  1363. return $this->query(AppFetcher::class);
  1364. }
  1365. /**
  1366. * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
  1367. * getMemCacheFactory() instead.
  1368. *
  1369. * @return \OCP\ICache
  1370. * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
  1371. */
  1372. public function getCache() {
  1373. return $this->query('UserCache');
  1374. }
  1375. /**
  1376. * Returns an \OCP\CacheFactory instance
  1377. *
  1378. * @return \OCP\ICacheFactory
  1379. */
  1380. public function getMemCacheFactory() {
  1381. return $this->query('MemCacheFactory');
  1382. }
  1383. /**
  1384. * Returns an \OC\RedisFactory instance
  1385. *
  1386. * @return \OC\RedisFactory
  1387. */
  1388. public function getGetRedisFactory() {
  1389. return $this->query('RedisFactory');
  1390. }
  1391. /**
  1392. * Returns the current session
  1393. *
  1394. * @return \OCP\IDBConnection
  1395. */
  1396. public function getDatabaseConnection() {
  1397. return $this->query('DatabaseConnection');
  1398. }
  1399. /**
  1400. * Returns the activity manager
  1401. *
  1402. * @return \OCP\Activity\IManager
  1403. */
  1404. public function getActivityManager() {
  1405. return $this->query('ActivityManager');
  1406. }
  1407. /**
  1408. * Returns an job list for controlling background jobs
  1409. *
  1410. * @return \OCP\BackgroundJob\IJobList
  1411. */
  1412. public function getJobList() {
  1413. return $this->query('JobList');
  1414. }
  1415. /**
  1416. * Returns a logger instance
  1417. *
  1418. * @return \OCP\ILogger
  1419. */
  1420. public function getLogger() {
  1421. return $this->query('Logger');
  1422. }
  1423. /**
  1424. * @return ILogFactory
  1425. * @throws \OCP\AppFramework\QueryException
  1426. */
  1427. public function getLogFactory() {
  1428. return $this->query(ILogFactory::class);
  1429. }
  1430. /**
  1431. * Returns a router for generating and matching urls
  1432. *
  1433. * @return \OCP\Route\IRouter
  1434. */
  1435. public function getRouter() {
  1436. return $this->query('Router');
  1437. }
  1438. /**
  1439. * Returns a search instance
  1440. *
  1441. * @return \OCP\ISearch
  1442. */
  1443. public function getSearch() {
  1444. return $this->query('Search');
  1445. }
  1446. /**
  1447. * Returns a SecureRandom instance
  1448. *
  1449. * @return \OCP\Security\ISecureRandom
  1450. */
  1451. public function getSecureRandom() {
  1452. return $this->query('SecureRandom');
  1453. }
  1454. /**
  1455. * Returns a Crypto instance
  1456. *
  1457. * @return \OCP\Security\ICrypto
  1458. */
  1459. public function getCrypto() {
  1460. return $this->query('Crypto');
  1461. }
  1462. /**
  1463. * Returns a Hasher instance
  1464. *
  1465. * @return \OCP\Security\IHasher
  1466. */
  1467. public function getHasher() {
  1468. return $this->query('Hasher');
  1469. }
  1470. /**
  1471. * Returns a CredentialsManager instance
  1472. *
  1473. * @return \OCP\Security\ICredentialsManager
  1474. */
  1475. public function getCredentialsManager() {
  1476. return $this->query('CredentialsManager');
  1477. }
  1478. /**
  1479. * Get the certificate manager for the user
  1480. *
  1481. * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
  1482. * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
  1483. */
  1484. public function getCertificateManager($userId = '') {
  1485. if ($userId === '') {
  1486. $userSession = $this->getUserSession();
  1487. $user = $userSession->getUser();
  1488. if (is_null($user)) {
  1489. return null;
  1490. }
  1491. $userId = $user->getUID();
  1492. }
  1493. return new CertificateManager(
  1494. $userId,
  1495. new View(),
  1496. $this->getConfig(),
  1497. $this->getLogger(),
  1498. $this->getSecureRandom()
  1499. );
  1500. }
  1501. /**
  1502. * Returns an instance of the HTTP client service
  1503. *
  1504. * @return \OCP\Http\Client\IClientService
  1505. */
  1506. public function getHTTPClientService() {
  1507. return $this->query('HttpClientService');
  1508. }
  1509. /**
  1510. * Create a new event source
  1511. *
  1512. * @return \OCP\IEventSource
  1513. */
  1514. public function createEventSource() {
  1515. return new \OC_EventSource();
  1516. }
  1517. /**
  1518. * Get the active event logger
  1519. *
  1520. * The returned logger only logs data when debug mode is enabled
  1521. *
  1522. * @return \OCP\Diagnostics\IEventLogger
  1523. */
  1524. public function getEventLogger() {
  1525. return $this->query('EventLogger');
  1526. }
  1527. /**
  1528. * Get the active query logger
  1529. *
  1530. * The returned logger only logs data when debug mode is enabled
  1531. *
  1532. * @return \OCP\Diagnostics\IQueryLogger
  1533. */
  1534. public function getQueryLogger() {
  1535. return $this->query('QueryLogger');
  1536. }
  1537. /**
  1538. * Get the manager for temporary files and folders
  1539. *
  1540. * @return \OCP\ITempManager
  1541. */
  1542. public function getTempManager() {
  1543. return $this->query('TempManager');
  1544. }
  1545. /**
  1546. * Get the app manager
  1547. *
  1548. * @return \OCP\App\IAppManager
  1549. */
  1550. public function getAppManager() {
  1551. return $this->query('AppManager');
  1552. }
  1553. /**
  1554. * Creates a new mailer
  1555. *
  1556. * @return \OCP\Mail\IMailer
  1557. */
  1558. public function getMailer() {
  1559. return $this->query('Mailer');
  1560. }
  1561. /**
  1562. * Get the webroot
  1563. *
  1564. * @return string
  1565. */
  1566. public function getWebRoot() {
  1567. return $this->webRoot;
  1568. }
  1569. /**
  1570. * @return \OC\OCSClient
  1571. */
  1572. public function getOcsClient() {
  1573. return $this->query('OcsClient');
  1574. }
  1575. /**
  1576. * @return \OCP\IDateTimeZone
  1577. */
  1578. public function getDateTimeZone() {
  1579. return $this->query('DateTimeZone');
  1580. }
  1581. /**
  1582. * @return \OCP\IDateTimeFormatter
  1583. */
  1584. public function getDateTimeFormatter() {
  1585. return $this->query('DateTimeFormatter');
  1586. }
  1587. /**
  1588. * @return \OCP\Files\Config\IMountProviderCollection
  1589. */
  1590. public function getMountProviderCollection() {
  1591. return $this->query('MountConfigManager');
  1592. }
  1593. /**
  1594. * Get the IniWrapper
  1595. *
  1596. * @return IniGetWrapper
  1597. */
  1598. public function getIniWrapper() {
  1599. return $this->query('IniWrapper');
  1600. }
  1601. /**
  1602. * @return \OCP\Command\IBus
  1603. */
  1604. public function getCommandBus() {
  1605. return $this->query('AsyncCommandBus');
  1606. }
  1607. /**
  1608. * Get the trusted domain helper
  1609. *
  1610. * @return TrustedDomainHelper
  1611. */
  1612. public function getTrustedDomainHelper() {
  1613. return $this->query('TrustedDomainHelper');
  1614. }
  1615. /**
  1616. * Get the locking provider
  1617. *
  1618. * @return \OCP\Lock\ILockingProvider
  1619. * @since 8.1.0
  1620. */
  1621. public function getLockingProvider() {
  1622. return $this->query('LockingProvider');
  1623. }
  1624. /**
  1625. * @return \OCP\Files\Mount\IMountManager
  1626. **/
  1627. function getMountManager() {
  1628. return $this->query('MountManager');
  1629. }
  1630. /** @return \OCP\Files\Config\IUserMountCache */
  1631. function getUserMountCache() {
  1632. return $this->query('UserMountCache');
  1633. }
  1634. /**
  1635. * Get the MimeTypeDetector
  1636. *
  1637. * @return \OCP\Files\IMimeTypeDetector
  1638. */
  1639. public function getMimeTypeDetector() {
  1640. return $this->query('MimeTypeDetector');
  1641. }
  1642. /**
  1643. * Get the MimeTypeLoader
  1644. *
  1645. * @return \OCP\Files\IMimeTypeLoader
  1646. */
  1647. public function getMimeTypeLoader() {
  1648. return $this->query('MimeTypeLoader');
  1649. }
  1650. /**
  1651. * Get the manager of all the capabilities
  1652. *
  1653. * @return \OC\CapabilitiesManager
  1654. */
  1655. public function getCapabilitiesManager() {
  1656. return $this->query('CapabilitiesManager');
  1657. }
  1658. /**
  1659. * Get the EventDispatcher
  1660. *
  1661. * @return EventDispatcherInterface
  1662. * @since 8.2.0
  1663. */
  1664. public function getEventDispatcher() {
  1665. return $this->query('EventDispatcher');
  1666. }
  1667. /**
  1668. * Get the Notification Manager
  1669. *
  1670. * @return \OCP\Notification\IManager
  1671. * @since 8.2.0
  1672. */
  1673. public function getNotificationManager() {
  1674. return $this->query('NotificationManager');
  1675. }
  1676. /**
  1677. * @return \OCP\Comments\ICommentsManager
  1678. */
  1679. public function getCommentsManager() {
  1680. return $this->query('CommentsManager');
  1681. }
  1682. /**
  1683. * @return \OCA\Theming\ThemingDefaults
  1684. */
  1685. public function getThemingDefaults() {
  1686. return $this->query('ThemingDefaults');
  1687. }
  1688. /**
  1689. * @return \OC\IntegrityCheck\Checker
  1690. */
  1691. public function getIntegrityCodeChecker() {
  1692. return $this->query('IntegrityCodeChecker');
  1693. }
  1694. /**
  1695. * @return \OC\Session\CryptoWrapper
  1696. */
  1697. public function getSessionCryptoWrapper() {
  1698. return $this->query('CryptoWrapper');
  1699. }
  1700. /**
  1701. * @return CsrfTokenManager
  1702. */
  1703. public function getCsrfTokenManager() {
  1704. return $this->query('CsrfTokenManager');
  1705. }
  1706. /**
  1707. * @return Throttler
  1708. */
  1709. public function getBruteForceThrottler() {
  1710. return $this->query('Throttler');
  1711. }
  1712. /**
  1713. * @return IContentSecurityPolicyManager
  1714. */
  1715. public function getContentSecurityPolicyManager() {
  1716. return $this->query('ContentSecurityPolicyManager');
  1717. }
  1718. /**
  1719. * @return ContentSecurityPolicyNonceManager
  1720. */
  1721. public function getContentSecurityPolicyNonceManager() {
  1722. return $this->query('ContentSecurityPolicyNonceManager');
  1723. }
  1724. /**
  1725. * Not a public API as of 8.2, wait for 9.0
  1726. *
  1727. * @return \OCA\Files_External\Service\BackendService
  1728. */
  1729. public function getStoragesBackendService() {
  1730. return $this->query('OCA\\Files_External\\Service\\BackendService');
  1731. }
  1732. /**
  1733. * Not a public API as of 8.2, wait for 9.0
  1734. *
  1735. * @return \OCA\Files_External\Service\GlobalStoragesService
  1736. */
  1737. public function getGlobalStoragesService() {
  1738. return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
  1739. }
  1740. /**
  1741. * Not a public API as of 8.2, wait for 9.0
  1742. *
  1743. * @return \OCA\Files_External\Service\UserGlobalStoragesService
  1744. */
  1745. public function getUserGlobalStoragesService() {
  1746. return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
  1747. }
  1748. /**
  1749. * Not a public API as of 8.2, wait for 9.0
  1750. *
  1751. * @return \OCA\Files_External\Service\UserStoragesService
  1752. */
  1753. public function getUserStoragesService() {
  1754. return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
  1755. }
  1756. /**
  1757. * @return \OCP\Share\IManager
  1758. */
  1759. public function getShareManager() {
  1760. return $this->query('ShareManager');
  1761. }
  1762. /**
  1763. * @return \OCP\Collaboration\Collaborators\ISearch
  1764. */
  1765. public function getCollaboratorSearch() {
  1766. return $this->query('CollaboratorSearch');
  1767. }
  1768. /**
  1769. * @return \OCP\Collaboration\AutoComplete\IManager
  1770. */
  1771. public function getAutoCompleteManager(){
  1772. return $this->query(IManager::class);
  1773. }
  1774. /**
  1775. * Returns the LDAP Provider
  1776. *
  1777. * @return \OCP\LDAP\ILDAPProvider
  1778. */
  1779. public function getLDAPProvider() {
  1780. return $this->query('LDAPProvider');
  1781. }
  1782. /**
  1783. * @return \OCP\Settings\IManager
  1784. */
  1785. public function getSettingsManager() {
  1786. return $this->query('SettingsManager');
  1787. }
  1788. /**
  1789. * @return \OCP\Files\IAppData
  1790. */
  1791. public function getAppDataDir($app) {
  1792. /** @var \OC\Files\AppData\Factory $factory */
  1793. $factory = $this->query(\OC\Files\AppData\Factory::class);
  1794. return $factory->get($app);
  1795. }
  1796. /**
  1797. * @return \OCP\Lockdown\ILockdownManager
  1798. */
  1799. public function getLockdownManager() {
  1800. return $this->query('LockdownManager');
  1801. }
  1802. /**
  1803. * @return \OCP\Federation\ICloudIdManager
  1804. */
  1805. public function getCloudIdManager() {
  1806. return $this->query(ICloudIdManager::class);
  1807. }
  1808. /**
  1809. * @return \OCP\GlobalScale\IConfig
  1810. */
  1811. public function getGlobalScaleConfig() {
  1812. return $this->query(IConfig::class);
  1813. }
  1814. /**
  1815. * @return \OCP\Federation\ICloudFederationProviderManager
  1816. */
  1817. public function getCloudFederationProviderManager() {
  1818. return $this->query(ICloudFederationProviderManager::class);
  1819. }
  1820. /**
  1821. * @return \OCP\Remote\Api\IApiFactory
  1822. */
  1823. public function getRemoteApiFactory() {
  1824. return $this->query(IApiFactory::class);
  1825. }
  1826. /**
  1827. * @return \OCP\Federation\ICloudFederationFactory
  1828. */
  1829. public function getCloudFederationFactory() {
  1830. return $this->query(ICloudFederationFactory::class);
  1831. }
  1832. /**
  1833. * @return \OCP\Remote\IInstanceFactory
  1834. */
  1835. public function getRemoteInstanceFactory() {
  1836. return $this->query(IInstanceFactory::class);
  1837. }
  1838. /**
  1839. * @return IStorageFactory
  1840. */
  1841. public function getStorageFactory() {
  1842. return $this->query(IStorageFactory::class);
  1843. }
  1844. }