1
0

Server.php 44 KB

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