Server.php 61 KB

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