Server.php 49 KB

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