server.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  1. <?php
  2. /**
  3. * @author Bart Visscher <bartv@thisnet.nl>
  4. * @author Bernhard Posselt <dev@bernhard-posselt.com>
  5. * @author Bernhard Reiter <ockham@raz.or.at>
  6. * @author Björn Schießle <schiessle@owncloud.com>
  7. * @author Christopher Schäpers <kondou@ts.unde.re>
  8. * @author Joas Schilling <nickvergessen@owncloud.com>
  9. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  10. * @author Lukas Reschke <lukas@owncloud.com>
  11. * @author Morris Jobke <hey@morrisjobke.de>
  12. * @author Robin Appelman <icewind@owncloud.com>
  13. * @author Robin McCorkell <rmccorkell@karoshi.org.uk>
  14. * @author Sander <brantje@gmail.com>
  15. * @author Thomas Müller <thomas.mueller@tmit.eu>
  16. * @author Thomas Tanghus <thomas@tanghus.net>
  17. * @author Vincent Petry <pvince81@owncloud.com>
  18. *
  19. * @copyright Copyright (c) 2015, ownCloud, Inc.
  20. * @license AGPL-3.0
  21. *
  22. * This code is free software: you can redistribute it and/or modify
  23. * it under the terms of the GNU Affero General Public License, version 3,
  24. * as published by the Free Software Foundation.
  25. *
  26. * This program is distributed in the hope that it will be useful,
  27. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  29. * GNU Affero General Public License for more details.
  30. *
  31. * You should have received a copy of the GNU Affero General Public License, version 3,
  32. * along with this program. If not, see <http://www.gnu.org/licenses/>
  33. *
  34. */
  35. namespace OC;
  36. use bantu\IniGetWrapper\IniGetWrapper;
  37. use OC\AppFramework\Http\Request;
  38. use OC\AppFramework\Db\Db;
  39. use OC\AppFramework\Utility\SimpleContainer;
  40. use OC\Cache\UserCache;
  41. use OC\Command\AsyncBus;
  42. use OC\Diagnostics\NullQueryLogger;
  43. use OC\Diagnostics\EventLogger;
  44. use OC\Diagnostics\QueryLogger;
  45. use OC\Mail\Mailer;
  46. use OC\Memcache\ArrayCache;
  47. use OC\Http\Client\ClientService;
  48. use OC\Security\CertificateManager;
  49. use OC\Files\Node\Root;
  50. use OC\Files\View;
  51. use OC\Security\Crypto;
  52. use OC\Security\Hasher;
  53. use OC\Security\SecureRandom;
  54. use OC\Diagnostics\NullEventLogger;
  55. use OC\Security\TrustedDomainHelper;
  56. use OCP\IServerContainer;
  57. use OCP\ISession;
  58. use OC\Tagging\TagMapper;
  59. /**
  60. * Class Server
  61. *
  62. * @package OC
  63. *
  64. * TODO: hookup all manager classes
  65. */
  66. class Server extends SimpleContainer implements IServerContainer {
  67. /** @var string */
  68. private $webRoot;
  69. /**
  70. * @param string $webRoot
  71. */
  72. public function __construct($webRoot) {
  73. $this->webRoot = $webRoot;
  74. $this->registerService('ContactsManager', function ($c) {
  75. return new ContactsManager();
  76. });
  77. $this->registerService('PreviewManager', function (Server $c) {
  78. return new PreviewManager($c->getConfig());
  79. });
  80. $this->registerService('EncryptionManager', function (Server $c) {
  81. return new Encryption\Manager($c->getConfig(), $c->getLogger());
  82. });
  83. $this->registerService('EncryptionFileHelper', function (Server $c) {
  84. $util = new \OC\Encryption\Util(
  85. new \OC\Files\View(),
  86. $c->getUserManager(),
  87. $c->getGroupManager(),
  88. $c->getConfig()
  89. );
  90. return new Encryption\File($util);
  91. });
  92. $this->registerService('EncryptionKeyStorage', function (Server $c) {
  93. $view = new \OC\Files\View();
  94. $util = new \OC\Encryption\Util(
  95. $view,
  96. $c->getUserManager(),
  97. $c->getGroupManager(),
  98. $c->getConfig()
  99. );
  100. return new Encryption\Keys\Storage($view, $util);
  101. });
  102. $this->registerService('TagMapper', function(Server $c) {
  103. return new TagMapper($c->getDatabaseConnection());
  104. });
  105. $this->registerService('TagManager', function (Server $c) {
  106. $tagMapper = $c->query('TagMapper');
  107. return new TagManager($tagMapper, $c->getUserSession());
  108. });
  109. $this->registerService('RootFolder', function (Server $c) {
  110. // TODO: get user and user manager from container as well
  111. $user = \OC_User::getUser();
  112. /** @var $c SimpleContainer */
  113. $userManager = $c->query('UserManager');
  114. $user = $userManager->get($user);
  115. $manager = \OC\Files\Filesystem::getMountManager();
  116. $view = new View();
  117. return new Root($manager, $view, $user);
  118. });
  119. $this->registerService('UserManager', function (Server $c) {
  120. $config = $c->getConfig();
  121. return new \OC\User\Manager($config);
  122. });
  123. $this->registerService('GroupManager', function (Server $c) {
  124. $groupManager = new \OC\Group\Manager($this->getUserManager());
  125. $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
  126. \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
  127. });
  128. $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
  129. \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
  130. });
  131. $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
  132. \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
  133. });
  134. $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
  135. \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
  136. });
  137. $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
  138. \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
  139. });
  140. $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
  141. \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
  142. });
  143. return $groupManager;
  144. });
  145. $this->registerService('UserSession', function (Server $c) {
  146. $manager = $c->getUserManager();
  147. $userSession = new \OC\User\Session($manager, new \OC\Session\Memory(''));
  148. $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
  149. \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
  150. });
  151. $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
  152. /** @var $user \OC\User\User */
  153. \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
  154. });
  155. $userSession->listen('\OC\User', 'preDelete', function ($user) {
  156. /** @var $user \OC\User\User */
  157. \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
  158. });
  159. $userSession->listen('\OC\User', 'postDelete', function ($user) {
  160. /** @var $user \OC\User\User */
  161. \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
  162. });
  163. $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
  164. /** @var $user \OC\User\User */
  165. \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
  166. });
  167. $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
  168. /** @var $user \OC\User\User */
  169. \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
  170. });
  171. $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
  172. \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
  173. });
  174. $userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
  175. /** @var $user \OC\User\User */
  176. \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
  177. });
  178. $userSession->listen('\OC\User', 'logout', function () {
  179. \OC_Hook::emit('OC_User', 'logout', array());
  180. });
  181. return $userSession;
  182. });
  183. $this->registerService('NavigationManager', function ($c) {
  184. return new \OC\NavigationManager();
  185. });
  186. $this->registerService('AllConfig', function (Server $c) {
  187. return new \OC\AllConfig(
  188. $c->getSystemConfig()
  189. );
  190. });
  191. $this->registerService('SystemConfig', function ($c) {
  192. return new \OC\SystemConfig();
  193. });
  194. $this->registerService('AppConfig', function ($c) {
  195. return new \OC\AppConfig(\OC_DB::getConnection());
  196. });
  197. $this->registerService('L10NFactory', function ($c) {
  198. return new \OC\L10N\Factory();
  199. });
  200. $this->registerService('URLGenerator', function (Server $c) {
  201. $config = $c->getConfig();
  202. $cacheFactory = $c->getMemCacheFactory();
  203. return new \OC\URLGenerator(
  204. $config,
  205. $cacheFactory
  206. );
  207. });
  208. $this->registerService('AppHelper', function ($c) {
  209. return new \OC\AppHelper();
  210. });
  211. $this->registerService('UserCache', function ($c) {
  212. return new UserCache();
  213. });
  214. $this->registerService('MemCacheFactory', function (Server $c) {
  215. $config = $c->getConfig();
  216. if($config->getSystemValue('installed', false)) {
  217. $v = \OC_App::getAppVersions();
  218. $v['core'] = implode('.', \OC_Util::getVersion());
  219. $version = implode(',', $v);
  220. $instanceId = \OC_Util::getInstanceId();
  221. $path = \OC::$SERVERROOT;
  222. $prefix = md5($instanceId.'-'.$version.'-'.$path);
  223. return new \OC\Memcache\Factory($prefix,
  224. $config->getSystemValue('memcache.local', null),
  225. $config->getSystemValue('memcache.distributed', null)
  226. );
  227. }
  228. return new \OC\Memcache\Factory('',
  229. new ArrayCache(),
  230. new ArrayCache()
  231. );
  232. });
  233. $this->registerService('ActivityManager', function (Server $c) {
  234. return new ActivityManager(
  235. $c->getRequest(),
  236. $c->getUserSession(),
  237. $c->getConfig()
  238. );
  239. });
  240. $this->registerService('AvatarManager', function ($c) {
  241. return new AvatarManager();
  242. });
  243. $this->registerService('Logger', function (Server $c) {
  244. $logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud');
  245. $logger = 'OC_Log_' . ucfirst($logClass);
  246. call_user_func(array($logger, 'init'));
  247. return new Log($logger);
  248. });
  249. $this->registerService('JobList', function (Server $c) {
  250. $config = $c->getConfig();
  251. return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config);
  252. });
  253. $this->registerService('Router', function (Server $c) {
  254. $cacheFactory = $c->getMemCacheFactory();
  255. if ($cacheFactory->isAvailable()) {
  256. $router = new \OC\Route\CachingRouter($cacheFactory->create('route'));
  257. } else {
  258. $router = new \OC\Route\Router();
  259. }
  260. return $router;
  261. });
  262. $this->registerService('Search', function ($c) {
  263. return new Search();
  264. });
  265. $this->registerService('SecureRandom', function ($c) {
  266. return new SecureRandom();
  267. });
  268. $this->registerService('Crypto', function (Server $c) {
  269. return new Crypto($c->getConfig(), $c->getSecureRandom());
  270. });
  271. $this->registerService('Hasher', function (Server $c) {
  272. return new Hasher($c->getConfig());
  273. });
  274. $this->registerService('DatabaseConnection', function (Server $c) {
  275. $factory = new \OC\DB\ConnectionFactory();
  276. $systemConfig = $c->getSystemConfig();
  277. $type = $systemConfig->getValue('dbtype', 'sqlite');
  278. if (!$factory->isValidType($type)) {
  279. throw new \OC\DatabaseException('Invalid database type');
  280. }
  281. $connectionParams = $factory->createConnectionParams($systemConfig);
  282. $connection = $factory->getConnection($type, $connectionParams);
  283. $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
  284. return $connection;
  285. });
  286. $this->registerService('Db', function (Server $c) {
  287. return new Db($c->getDatabaseConnection());
  288. });
  289. $this->registerService('HTTPHelper', function (Server $c) {
  290. $config = $c->getConfig();
  291. return new HTTPHelper(
  292. $config,
  293. $c->getHTTPClientService()
  294. );
  295. });
  296. $this->registerService('HttpClientService', function (Server $c) {
  297. $user = \OC_User::getUser();
  298. $uid = $user ? $user : null;
  299. return new ClientService(
  300. $c->getConfig(),
  301. new \OC\Security\CertificateManager($uid, new \OC\Files\View())
  302. );
  303. });
  304. $this->registerService('EventLogger', function (Server $c) {
  305. if (defined('DEBUG') and DEBUG) {
  306. return new EventLogger();
  307. } else {
  308. return new NullEventLogger();
  309. }
  310. });
  311. $this->registerService('QueryLogger', function ($c) {
  312. if (defined('DEBUG') and DEBUG) {
  313. return new QueryLogger();
  314. } else {
  315. return new NullQueryLogger();
  316. }
  317. });
  318. $this->registerService('TempManager', function (Server $c) {
  319. return new TempManager(get_temp_dir(), $c->getLogger());
  320. });
  321. $this->registerService('AppManager', function(Server $c) {
  322. return new \OC\App\AppManager(
  323. $c->getUserSession(),
  324. $c->getAppConfig(),
  325. $c->getGroupManager(),
  326. $c->getMemCacheFactory()
  327. );
  328. });
  329. $this->registerService('DateTimeZone', function(Server $c) {
  330. return new DateTimeZone(
  331. $c->getConfig(),
  332. $c->getSession()
  333. );
  334. });
  335. $this->registerService('DateTimeFormatter', function(Server $c) {
  336. $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
  337. return new DateTimeFormatter(
  338. $c->getDateTimeZone()->getTimeZone(),
  339. $c->getL10N('lib', $language)
  340. );
  341. });
  342. $this->registerService('MountConfigManager', function () {
  343. $loader = \OC\Files\Filesystem::getLoader();
  344. return new \OC\Files\Config\MountProviderCollection($loader);
  345. });
  346. $this->registerService('IniWrapper', function ($c) {
  347. return new IniGetWrapper();
  348. });
  349. $this->registerService('AsyncCommandBus', function (Server $c) {
  350. $jobList = $c->getJobList();
  351. return new AsyncBus($jobList);
  352. });
  353. $this->registerService('TrustedDomainHelper', function ($c) {
  354. return new TrustedDomainHelper($this->getConfig());
  355. });
  356. $this->registerService('Request', function ($c) {
  357. if (isset($this['urlParams'])) {
  358. $urlParams = $this['urlParams'];
  359. } else {
  360. $urlParams = [];
  361. }
  362. if ($this->getSession()->exists('requesttoken')) {
  363. $requestToken = $this->getSession()->get('requesttoken');
  364. } else {
  365. $requestToken = false;
  366. }
  367. if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
  368. && in_array('fakeinput', stream_get_wrappers())
  369. ) {
  370. $stream = 'fakeinput://data';
  371. } else {
  372. $stream = 'php://input';
  373. }
  374. return new Request(
  375. [
  376. 'get' => $_GET,
  377. 'post' => $_POST,
  378. 'files' => $_FILES,
  379. 'server' => $_SERVER,
  380. 'env' => $_ENV,
  381. 'cookies' => $_COOKIE,
  382. 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
  383. ? $_SERVER['REQUEST_METHOD']
  384. : null,
  385. 'urlParams' => $urlParams,
  386. 'requesttoken' => $requestToken,
  387. ],
  388. $this->getSecureRandom(),
  389. $this->getConfig(),
  390. $stream
  391. );
  392. });
  393. $this->registerService('Mailer', function(Server $c) {
  394. return new Mailer(
  395. $c->getConfig(),
  396. $c->getLogger(),
  397. new \OC_Defaults()
  398. );
  399. });
  400. $this->registerService('OcsClient', function(Server $c) {
  401. return new OCSClient(
  402. $this->getHTTPClientService(),
  403. $this->getConfig(),
  404. $this->getLogger()
  405. );
  406. });
  407. }
  408. /**
  409. * @return \OCP\Contacts\IManager
  410. */
  411. public function getContactsManager() {
  412. return $this->query('ContactsManager');
  413. }
  414. /**
  415. * @return \OC\Encryption\Manager
  416. */
  417. public function getEncryptionManager() {
  418. return $this->query('EncryptionManager');
  419. }
  420. /**
  421. * @return \OC\Encryption\File
  422. */
  423. public function getEncryptionFilesHelper() {
  424. return $this->query('EncryptionFileHelper');
  425. }
  426. /**
  427. * @return \OCP\Encryption\Keys\IStorage
  428. */
  429. public function getEncryptionKeyStorage() {
  430. return $this->query('EncryptionKeyStorage');
  431. }
  432. /**
  433. * The current request object holding all information about the request
  434. * currently being processed is returned from this method.
  435. * In case the current execution was not initiated by a web request null is returned
  436. *
  437. * @return \OCP\IRequest
  438. */
  439. public function getRequest() {
  440. return $this->query('Request');
  441. }
  442. /**
  443. * Returns the preview manager which can create preview images for a given file
  444. *
  445. * @return \OCP\IPreview
  446. */
  447. public function getPreviewManager() {
  448. return $this->query('PreviewManager');
  449. }
  450. /**
  451. * Returns the tag manager which can get and set tags for different object types
  452. *
  453. * @see \OCP\ITagManager::load()
  454. * @return \OCP\ITagManager
  455. */
  456. public function getTagManager() {
  457. return $this->query('TagManager');
  458. }
  459. /**
  460. * Returns the avatar manager, used for avatar functionality
  461. *
  462. * @return \OCP\IAvatarManager
  463. */
  464. public function getAvatarManager() {
  465. return $this->query('AvatarManager');
  466. }
  467. /**
  468. * Returns the root folder of ownCloud's data directory
  469. *
  470. * @return \OCP\Files\IRootFolder
  471. */
  472. public function getRootFolder() {
  473. return $this->query('RootFolder');
  474. }
  475. /**
  476. * Returns a view to ownCloud's files folder
  477. *
  478. * @param string $userId user ID
  479. * @return \OCP\Files\Folder
  480. */
  481. public function getUserFolder($userId = null) {
  482. if ($userId === null) {
  483. $user = $this->getUserSession()->getUser();
  484. if (!$user) {
  485. return null;
  486. }
  487. $userId = $user->getUID();
  488. } else {
  489. $user = $this->getUserManager()->get($userId);
  490. }
  491. \OC\Files\Filesystem::initMountPoints($userId);
  492. $dir = '/' . $userId;
  493. $root = $this->getRootFolder();
  494. $folder = null;
  495. if (!$root->nodeExists($dir)) {
  496. $folder = $root->newFolder($dir);
  497. } else {
  498. $folder = $root->get($dir);
  499. }
  500. $dir = '/files';
  501. if (!$folder->nodeExists($dir)) {
  502. $folder = $folder->newFolder($dir);
  503. \OC_Util::copySkeleton($user, $folder);
  504. } else {
  505. $folder = $folder->get($dir);
  506. }
  507. return $folder;
  508. }
  509. /**
  510. * Returns an app-specific view in ownClouds data directory
  511. *
  512. * @return \OCP\Files\Folder
  513. */
  514. public function getAppFolder() {
  515. $dir = '/' . \OC_App::getCurrentApp();
  516. $root = $this->getRootFolder();
  517. $folder = null;
  518. if (!$root->nodeExists($dir)) {
  519. $folder = $root->newFolder($dir);
  520. } else {
  521. $folder = $root->get($dir);
  522. }
  523. return $folder;
  524. }
  525. /**
  526. * @return \OC\User\Manager
  527. */
  528. public function getUserManager() {
  529. return $this->query('UserManager');
  530. }
  531. /**
  532. * @return \OC\Group\Manager
  533. */
  534. public function getGroupManager() {
  535. return $this->query('GroupManager');
  536. }
  537. /**
  538. * @return \OC\User\Session
  539. */
  540. public function getUserSession() {
  541. return $this->query('UserSession');
  542. }
  543. /**
  544. * @return \OCP\ISession
  545. */
  546. public function getSession() {
  547. return $this->query('UserSession')->getSession();
  548. }
  549. /**
  550. * @param \OCP\ISession $session
  551. */
  552. public function setSession(\OCP\ISession $session) {
  553. return $this->query('UserSession')->setSession($session);
  554. }
  555. /**
  556. * @return \OC\NavigationManager
  557. */
  558. public function getNavigationManager() {
  559. return $this->query('NavigationManager');
  560. }
  561. /**
  562. * @return \OCP\IConfig
  563. */
  564. public function getConfig() {
  565. return $this->query('AllConfig');
  566. }
  567. /**
  568. * For internal use only
  569. *
  570. * @return \OC\SystemConfig
  571. */
  572. public function getSystemConfig() {
  573. return $this->query('SystemConfig');
  574. }
  575. /**
  576. * Returns the app config manager
  577. *
  578. * @return \OCP\IAppConfig
  579. */
  580. public function getAppConfig() {
  581. return $this->query('AppConfig');
  582. }
  583. /**
  584. * get an L10N instance
  585. *
  586. * @param string $app appid
  587. * @param string $lang
  588. * @return \OC_L10N
  589. */
  590. public function getL10N($app, $lang = null) {
  591. return $this->query('L10NFactory')->get($app, $lang);
  592. }
  593. /**
  594. * @return \OCP\IURLGenerator
  595. */
  596. public function getURLGenerator() {
  597. return $this->query('URLGenerator');
  598. }
  599. /**
  600. * @return \OCP\IHelper
  601. */
  602. public function getHelper() {
  603. return $this->query('AppHelper');
  604. }
  605. /**
  606. * Returns an ICache instance
  607. *
  608. * @return \OCP\ICache
  609. */
  610. public function getCache() {
  611. return $this->query('UserCache');
  612. }
  613. /**
  614. * Returns an \OCP\CacheFactory instance
  615. *
  616. * @return \OCP\ICacheFactory
  617. */
  618. public function getMemCacheFactory() {
  619. return $this->query('MemCacheFactory');
  620. }
  621. /**
  622. * Returns the current session
  623. *
  624. * @return \OCP\IDBConnection
  625. */
  626. public function getDatabaseConnection() {
  627. return $this->query('DatabaseConnection');
  628. }
  629. /**
  630. * Returns the activity manager
  631. *
  632. * @return \OCP\Activity\IManager
  633. */
  634. public function getActivityManager() {
  635. return $this->query('ActivityManager');
  636. }
  637. /**
  638. * Returns an job list for controlling background jobs
  639. *
  640. * @return \OCP\BackgroundJob\IJobList
  641. */
  642. public function getJobList() {
  643. return $this->query('JobList');
  644. }
  645. /**
  646. * Returns a logger instance
  647. *
  648. * @return \OCP\ILogger
  649. */
  650. public function getLogger() {
  651. return $this->query('Logger');
  652. }
  653. /**
  654. * Returns a router for generating and matching urls
  655. *
  656. * @return \OCP\Route\IRouter
  657. */
  658. public function getRouter() {
  659. return $this->query('Router');
  660. }
  661. /**
  662. * Returns a search instance
  663. *
  664. * @return \OCP\ISearch
  665. */
  666. public function getSearch() {
  667. return $this->query('Search');
  668. }
  669. /**
  670. * Returns a SecureRandom instance
  671. *
  672. * @return \OCP\Security\ISecureRandom
  673. */
  674. public function getSecureRandom() {
  675. return $this->query('SecureRandom');
  676. }
  677. /**
  678. * Returns a Crypto instance
  679. *
  680. * @return \OCP\Security\ICrypto
  681. */
  682. public function getCrypto() {
  683. return $this->query('Crypto');
  684. }
  685. /**
  686. * Returns a Hasher instance
  687. *
  688. * @return \OCP\Security\IHasher
  689. */
  690. public function getHasher() {
  691. return $this->query('Hasher');
  692. }
  693. /**
  694. * Returns an instance of the db facade
  695. * @deprecated use getDatabaseConnection, will be removed in ownCloud 10
  696. * @return \OCP\IDb
  697. */
  698. public function getDb() {
  699. return $this->query('Db');
  700. }
  701. /**
  702. * Returns an instance of the HTTP helper class
  703. * @deprecated Use getHTTPClientService()
  704. * @return \OC\HTTPHelper
  705. */
  706. public function getHTTPHelper() {
  707. return $this->query('HTTPHelper');
  708. }
  709. /**
  710. * Get the certificate manager for the user
  711. *
  712. * @param string $uid (optional) if not specified the current loggedin user is used
  713. * @return \OCP\ICertificateManager
  714. */
  715. public function getCertificateManager($uid = null) {
  716. if (is_null($uid)) {
  717. $userSession = $this->getUserSession();
  718. $user = $userSession->getUser();
  719. if (is_null($user)) {
  720. return null;
  721. }
  722. $uid = $user->getUID();
  723. }
  724. return new CertificateManager($uid, new \OC\Files\View());
  725. }
  726. /**
  727. * Returns an instance of the HTTP client service
  728. *
  729. * @return \OCP\Http\Client\IClientService
  730. */
  731. public function getHTTPClientService() {
  732. return $this->query('HttpClientService');
  733. }
  734. /**
  735. * Create a new event source
  736. *
  737. * @return \OCP\IEventSource
  738. */
  739. public function createEventSource() {
  740. return new \OC_EventSource();
  741. }
  742. /**
  743. * Get the active event logger
  744. *
  745. * The returned logger only logs data when debug mode is enabled
  746. *
  747. * @return \OCP\Diagnostics\IEventLogger
  748. */
  749. public function getEventLogger() {
  750. return $this->query('EventLogger');
  751. }
  752. /**
  753. * Get the active query logger
  754. *
  755. * The returned logger only logs data when debug mode is enabled
  756. *
  757. * @return \OCP\Diagnostics\IQueryLogger
  758. */
  759. public function getQueryLogger() {
  760. return $this->query('QueryLogger');
  761. }
  762. /**
  763. * Get the manager for temporary files and folders
  764. *
  765. * @return \OCP\ITempManager
  766. */
  767. public function getTempManager() {
  768. return $this->query('TempManager');
  769. }
  770. /**
  771. * Get the app manager
  772. *
  773. * @return \OCP\App\IAppManager
  774. */
  775. public function getAppManager() {
  776. return $this->query('AppManager');
  777. }
  778. /**
  779. * Creates a new mailer
  780. *
  781. * @return \OCP\Mail\IMailer
  782. */
  783. public function getMailer() {
  784. return $this->query('Mailer');
  785. }
  786. /**
  787. * Get the webroot
  788. *
  789. * @return string
  790. */
  791. public function getWebRoot() {
  792. return $this->webRoot;
  793. }
  794. /**
  795. * @return \OC\OCSClient
  796. */
  797. public function getOcsClient() {
  798. return $this->query('OcsClient');
  799. }
  800. /**
  801. * @return \OCP\IDateTimeZone
  802. */
  803. public function getDateTimeZone() {
  804. return $this->query('DateTimeZone');
  805. }
  806. /**
  807. * @return \OCP\IDateTimeFormatter
  808. */
  809. public function getDateTimeFormatter() {
  810. return $this->query('DateTimeFormatter');
  811. }
  812. /**
  813. * @return \OCP\Files\Config\IMountProviderCollection
  814. */
  815. public function getMountProviderCollection(){
  816. return $this->query('MountConfigManager');
  817. }
  818. /**
  819. * Get the IniWrapper
  820. *
  821. * @return IniGetWrapper
  822. */
  823. public function getIniWrapper() {
  824. return $this->query('IniWrapper');
  825. }
  826. /**
  827. * @return \OCP\Command\IBus
  828. */
  829. public function getCommandBus(){
  830. return $this->query('AsyncCommandBus');
  831. }
  832. /**
  833. * Get the trusted domain helper
  834. *
  835. * @return TrustedDomainHelper
  836. */
  837. public function getTrustedDomainHelper() {
  838. return $this->query('TrustedDomainHelper');
  839. }
  840. }