Server.php 52 KB

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