1
0

OC_Util.php 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Bart Visscher <bartv@thisnet.nl>
  7. * @author Bernhard Posselt <dev@bernhard-posselt.com>
  8. * @author Birk Borkason <daniel.niccoli@gmail.com>
  9. * @author Bjoern Schiessle <bjoern@schiessle.org>
  10. * @author Björn Schießle <bjoern@schiessle.org>
  11. * @author Brice Maron <brice@bmaron.net>
  12. * @author Christopher Schäpers <kondou@ts.unde.re>
  13. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  14. * @author Clark Tomlinson <fallen013@gmail.com>
  15. * @author cmeh <cmeh@users.noreply.github.com>
  16. * @author Eric Masseran <rico.masseran@gmail.com>
  17. * @author Felix Epp <work@felixepp.de>
  18. * @author Florin Peter <github@florin-peter.de>
  19. * @author Frank Karlitschek <frank@karlitschek.de>
  20. * @author Georg Ehrke <oc.list@georgehrke.com>
  21. * @author helix84 <helix84@centrum.sk>
  22. * @author Ilja Neumann <ineumann@owncloud.com>
  23. * @author Individual IT Services <info@individual-it.net>
  24. * @author Jakob Sack <mail@jakobsack.de>
  25. * @author Joas Schilling <coding@schilljs.com>
  26. * @author John Molakvoæ <skjnldsv@protonmail.com>
  27. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  28. * @author Julius Härtl <jus@bitgrid.net>
  29. * @author Kawohl <john@owncloud.com>
  30. * @author Lukas Reschke <lukas@statuscode.ch>
  31. * @author Markus Goetz <markus@woboq.com>
  32. * @author Martin Mattel <martin.mattel@diemattels.at>
  33. * @author Marvin Thomas Rabe <mrabe@marvinrabe.de>
  34. * @author Michael Gapczynski <GapczynskiM@gmail.com>
  35. * @author Morris Jobke <hey@morrisjobke.de>
  36. * @author rakekniven <mark.ziegler@rakekniven.de>
  37. * @author Robert Dailey <rcdailey@gmail.com>
  38. * @author Robin Appelman <robin@icewind.nl>
  39. * @author Robin McCorkell <robin@mccorkell.me.uk>
  40. * @author Roeland Jago Douma <roeland@famdouma.nl>
  41. * @author Sebastian Wessalowski <sebastian@wessalowski.org>
  42. * @author Stefan Rado <owncloud@sradonia.net>
  43. * @author Stefan Weil <sw@weilnetz.de>
  44. * @author Thomas Müller <thomas.mueller@tmit.eu>
  45. * @author Thomas Tanghus <thomas@tanghus.net>
  46. * @author Valdnet <47037905+Valdnet@users.noreply.github.com>
  47. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  48. * @author Vincent Petry <vincent@nextcloud.com>
  49. * @author Volkan Gezer <volkangezer@gmail.com>
  50. *
  51. * @license AGPL-3.0
  52. *
  53. * This code is free software: you can redistribute it and/or modify
  54. * it under the terms of the GNU Affero General Public License, version 3,
  55. * as published by the Free Software Foundation.
  56. *
  57. * This program is distributed in the hope that it will be useful,
  58. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  59. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  60. * GNU Affero General Public License for more details.
  61. *
  62. * You should have received a copy of the GNU Affero General Public License, version 3,
  63. * along with this program. If not, see <http://www.gnu.org/licenses/>
  64. *
  65. */
  66. use bantu\IniGetWrapper\IniGetWrapper;
  67. use OC\AppFramework\Http\Request;
  68. use OC\Files\SetupManager;
  69. use OCP\Files\Template\ITemplateManager;
  70. use OCP\IConfig;
  71. use OCP\IDBConnection;
  72. use OCP\IGroupManager;
  73. use OCP\IURLGenerator;
  74. use OCP\IUser;
  75. use OCP\Share\IManager;
  76. use Psr\Log\LoggerInterface;
  77. class OC_Util {
  78. public static $scripts = [];
  79. public static $styles = [];
  80. public static $headers = [];
  81. /** @var array Local cache of version.php */
  82. private static $versionCache = null;
  83. protected static function getAppManager() {
  84. return \OC::$server->getAppManager();
  85. }
  86. /**
  87. * Setup the file system
  88. *
  89. * @param string|null $user
  90. * @return boolean
  91. * @description configure the initial filesystem based on the configuration
  92. * @suppress PhanDeprecatedFunction
  93. * @suppress PhanAccessMethodInternal
  94. */
  95. public static function setupFS(?string $user = '') {
  96. // If we are not forced to load a specific user we load the one that is logged in
  97. if ($user === '') {
  98. $userObject = \OC::$server->get(\OCP\IUserSession::class)->getUser();
  99. } else {
  100. $userObject = \OC::$server->get(\OCP\IUserManager::class)->get($user);
  101. }
  102. /** @var SetupManager $setupManager */
  103. $setupManager = \OC::$server->get(SetupManager::class);
  104. if ($userObject) {
  105. $setupManager->setupForUser($userObject);
  106. } else {
  107. $setupManager->setupRoot();
  108. }
  109. return true;
  110. }
  111. /**
  112. * Check if a password is required for each public link
  113. *
  114. * @param bool $checkGroupMembership Check group membership exclusion
  115. * @return boolean
  116. * @suppress PhanDeprecatedFunction
  117. */
  118. public static function isPublicLinkPasswordRequired(bool $checkGroupMembership = true) {
  119. /** @var IManager $shareManager */
  120. $shareManager = \OC::$server->get(IManager::class);
  121. return $shareManager->shareApiLinkEnforcePassword($checkGroupMembership);
  122. }
  123. /**
  124. * check if sharing is disabled for the current user
  125. * @param IConfig $config
  126. * @param IGroupManager $groupManager
  127. * @param IUser|null $user
  128. * @return bool
  129. */
  130. public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) {
  131. /** @var IManager $shareManager */
  132. $shareManager = \OC::$server->get(IManager::class);
  133. $userId = $user ? $user->getUID() : null;
  134. return $shareManager->sharingDisabledForUser($userId);
  135. }
  136. /**
  137. * check if share API enforces a default expire date
  138. *
  139. * @return boolean
  140. * @suppress PhanDeprecatedFunction
  141. */
  142. public static function isDefaultExpireDateEnforced() {
  143. /** @var IManager $shareManager */
  144. $shareManager = \OC::$server->get(IManager::class);
  145. return $shareManager->shareApiLinkDefaultExpireDateEnforced();
  146. }
  147. /**
  148. * Get the quota of a user
  149. *
  150. * @param IUser|null $user
  151. * @return int|\OCP\Files\FileInfo::SPACE_UNLIMITED|false Quota bytes
  152. */
  153. public static function getUserQuota(?IUser $user) {
  154. if (is_null($user)) {
  155. return \OCP\Files\FileInfo::SPACE_UNLIMITED;
  156. }
  157. $userQuota = $user->getQuota();
  158. if ($userQuota === 'none') {
  159. return \OCP\Files\FileInfo::SPACE_UNLIMITED;
  160. }
  161. return OC_Helper::computerFileSize($userQuota);
  162. }
  163. /**
  164. * copies the skeleton to the users /files
  165. *
  166. * @param string $userId
  167. * @param \OCP\Files\Folder $userDirectory
  168. * @throws \OCP\Files\NotFoundException
  169. * @throws \OCP\Files\NotPermittedException
  170. * @suppress PhanDeprecatedFunction
  171. */
  172. public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) {
  173. /** @var LoggerInterface $logger */
  174. $logger = \OC::$server->get(LoggerInterface::class);
  175. $plainSkeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton');
  176. $userLang = \OC::$server->getL10NFactory()->findLanguage();
  177. $skeletonDirectory = str_replace('{lang}', $userLang, $plainSkeletonDirectory);
  178. if (!file_exists($skeletonDirectory)) {
  179. $dialectStart = strpos($userLang, '_');
  180. if ($dialectStart !== false) {
  181. $skeletonDirectory = str_replace('{lang}', substr($userLang, 0, $dialectStart), $plainSkeletonDirectory);
  182. }
  183. if ($dialectStart === false || !file_exists($skeletonDirectory)) {
  184. $skeletonDirectory = str_replace('{lang}', 'default', $plainSkeletonDirectory);
  185. }
  186. if (!file_exists($skeletonDirectory)) {
  187. $skeletonDirectory = '';
  188. }
  189. }
  190. $instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', '');
  191. if ($instanceId === null) {
  192. throw new \RuntimeException('no instance id!');
  193. }
  194. $appdata = 'appdata_' . $instanceId;
  195. if ($userId === $appdata) {
  196. throw new \RuntimeException('username is reserved name: ' . $appdata);
  197. }
  198. if (!empty($skeletonDirectory)) {
  199. $logger->debug('copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'), ['app' => 'files_skeleton']);
  200. self::copyr($skeletonDirectory, $userDirectory);
  201. // update the file cache
  202. $userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE);
  203. /** @var ITemplateManager $templateManager */
  204. $templateManager = \OC::$server->get(ITemplateManager::class);
  205. $templateManager->initializeTemplateDirectory(null, $userId);
  206. }
  207. }
  208. /**
  209. * copies a directory recursively by using streams
  210. *
  211. * @param string $source
  212. * @param \OCP\Files\Folder $target
  213. * @return void
  214. */
  215. public static function copyr($source, \OCP\Files\Folder $target) {
  216. $logger = \OC::$server->getLogger();
  217. // Verify if folder exists
  218. $dir = opendir($source);
  219. if ($dir === false) {
  220. $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']);
  221. return;
  222. }
  223. // Copy the files
  224. while (false !== ($file = readdir($dir))) {
  225. if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
  226. if (is_dir($source . '/' . $file)) {
  227. $child = $target->newFolder($file);
  228. self::copyr($source . '/' . $file, $child);
  229. } else {
  230. $child = $target->newFile($file);
  231. $sourceStream = fopen($source . '/' . $file, 'r');
  232. if ($sourceStream === false) {
  233. $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']);
  234. closedir($dir);
  235. return;
  236. }
  237. $child->putContent($sourceStream);
  238. }
  239. }
  240. }
  241. closedir($dir);
  242. }
  243. /**
  244. * @return void
  245. * @suppress PhanUndeclaredMethod
  246. */
  247. public static function tearDownFS() {
  248. /** @var SetupManager $setupManager */
  249. $setupManager = \OC::$server->get(SetupManager::class);
  250. $setupManager->tearDown();
  251. }
  252. /**
  253. * get the current installed version of ownCloud
  254. *
  255. * @return array
  256. */
  257. public static function getVersion() {
  258. OC_Util::loadVersion();
  259. return self::$versionCache['OC_Version'];
  260. }
  261. /**
  262. * get the current installed version string of ownCloud
  263. *
  264. * @return string
  265. */
  266. public static function getVersionString() {
  267. OC_Util::loadVersion();
  268. return self::$versionCache['OC_VersionString'];
  269. }
  270. /**
  271. * @deprecated the value is of no use anymore
  272. * @return string
  273. */
  274. public static function getEditionString() {
  275. return '';
  276. }
  277. /**
  278. * @description get the update channel of the current installed of ownCloud.
  279. * @return string
  280. */
  281. public static function getChannel() {
  282. OC_Util::loadVersion();
  283. return \OC::$server->getConfig()->getSystemValue('updater.release.channel', self::$versionCache['OC_Channel']);
  284. }
  285. /**
  286. * @description get the build number of the current installed of ownCloud.
  287. * @return string
  288. */
  289. public static function getBuild() {
  290. OC_Util::loadVersion();
  291. return self::$versionCache['OC_Build'];
  292. }
  293. /**
  294. * @description load the version.php into the session as cache
  295. * @suppress PhanUndeclaredVariable
  296. */
  297. private static function loadVersion() {
  298. if (self::$versionCache !== null) {
  299. return;
  300. }
  301. $timestamp = filemtime(OC::$SERVERROOT . '/version.php');
  302. require OC::$SERVERROOT . '/version.php';
  303. /** @var int $timestamp */
  304. self::$versionCache['OC_Version_Timestamp'] = $timestamp;
  305. /** @var string $OC_Version */
  306. self::$versionCache['OC_Version'] = $OC_Version;
  307. /** @var string $OC_VersionString */
  308. self::$versionCache['OC_VersionString'] = $OC_VersionString;
  309. /** @var string $OC_Build */
  310. self::$versionCache['OC_Build'] = $OC_Build;
  311. /** @var string $OC_Channel */
  312. self::$versionCache['OC_Channel'] = $OC_Channel;
  313. }
  314. /**
  315. * generates a path for JS/CSS files. If no application is provided it will create the path for core.
  316. *
  317. * @param string $application application to get the files from
  318. * @param string $directory directory within this application (css, js, vendor, etc)
  319. * @param string $file the file inside of the above folder
  320. * @return string the path
  321. */
  322. private static function generatePath($application, $directory, $file) {
  323. if (is_null($file)) {
  324. $file = $application;
  325. $application = "";
  326. }
  327. if (!empty($application)) {
  328. return "$application/$directory/$file";
  329. } else {
  330. return "$directory/$file";
  331. }
  332. }
  333. /**
  334. * add a javascript file
  335. *
  336. * @deprecated 24.0.0 - Use \OCP\Util::addScript
  337. *
  338. * @param string $application application id
  339. * @param string|null $file filename
  340. * @param bool $prepend prepend the Script to the beginning of the list
  341. * @return void
  342. */
  343. public static function addScript($application, $file = null, $prepend = false) {
  344. $path = OC_Util::generatePath($application, 'js', $file);
  345. // core js files need separate handling
  346. if ($application !== 'core' && $file !== null) {
  347. self::addTranslations($application);
  348. }
  349. self::addExternalResource($application, $prepend, $path, "script");
  350. }
  351. /**
  352. * add a javascript file from the vendor sub folder
  353. *
  354. * @param string $application application id
  355. * @param string|null $file filename
  356. * @param bool $prepend prepend the Script to the beginning of the list
  357. * @return void
  358. */
  359. public static function addVendorScript($application, $file = null, $prepend = false) {
  360. $path = OC_Util::generatePath($application, 'vendor', $file);
  361. self::addExternalResource($application, $prepend, $path, "script");
  362. }
  363. /**
  364. * add a translation JS file
  365. *
  366. * @deprecated 24.0.0
  367. *
  368. * @param string $application application id
  369. * @param string|null $languageCode language code, defaults to the current language
  370. * @param bool|null $prepend prepend the Script to the beginning of the list
  371. */
  372. public static function addTranslations($application, $languageCode = null, $prepend = false) {
  373. if (is_null($languageCode)) {
  374. $languageCode = \OC::$server->getL10NFactory()->findLanguage($application);
  375. }
  376. if (!empty($application)) {
  377. $path = "$application/l10n/$languageCode";
  378. } else {
  379. $path = "l10n/$languageCode";
  380. }
  381. self::addExternalResource($application, $prepend, $path, "script");
  382. }
  383. /**
  384. * add a css file
  385. *
  386. * @param string $application application id
  387. * @param string|null $file filename
  388. * @param bool $prepend prepend the Style to the beginning of the list
  389. * @return void
  390. */
  391. public static function addStyle($application, $file = null, $prepend = false) {
  392. $path = OC_Util::generatePath($application, 'css', $file);
  393. self::addExternalResource($application, $prepend, $path, "style");
  394. }
  395. /**
  396. * add a css file from the vendor sub folder
  397. *
  398. * @param string $application application id
  399. * @param string|null $file filename
  400. * @param bool $prepend prepend the Style to the beginning of the list
  401. * @return void
  402. */
  403. public static function addVendorStyle($application, $file = null, $prepend = false) {
  404. $path = OC_Util::generatePath($application, 'vendor', $file);
  405. self::addExternalResource($application, $prepend, $path, "style");
  406. }
  407. /**
  408. * add an external resource css/js file
  409. *
  410. * @param string $application application id
  411. * @param bool $prepend prepend the file to the beginning of the list
  412. * @param string $path
  413. * @param string $type (script or style)
  414. * @return void
  415. */
  416. private static function addExternalResource($application, $prepend, $path, $type = "script") {
  417. if ($type === "style") {
  418. if (!in_array($path, self::$styles)) {
  419. if ($prepend === true) {
  420. array_unshift(self::$styles, $path);
  421. } else {
  422. self::$styles[] = $path;
  423. }
  424. }
  425. } elseif ($type === "script") {
  426. if (!in_array($path, self::$scripts)) {
  427. if ($prepend === true) {
  428. array_unshift(self::$scripts, $path);
  429. } else {
  430. self::$scripts [] = $path;
  431. }
  432. }
  433. }
  434. }
  435. /**
  436. * Add a custom element to the header
  437. * If $text is null then the element will be written as empty element.
  438. * So use "" to get a closing tag.
  439. * @param string $tag tag name of the element
  440. * @param array $attributes array of attributes for the element
  441. * @param string $text the text content for the element
  442. * @param bool $prepend prepend the header to the beginning of the list
  443. */
  444. public static function addHeader($tag, $attributes, $text = null, $prepend = false) {
  445. $header = [
  446. 'tag' => $tag,
  447. 'attributes' => $attributes,
  448. 'text' => $text
  449. ];
  450. if ($prepend === true) {
  451. array_unshift(self::$headers, $header);
  452. } else {
  453. self::$headers[] = $header;
  454. }
  455. }
  456. /**
  457. * check if the current server configuration is suitable for ownCloud
  458. *
  459. * @param \OC\SystemConfig $config
  460. * @return array arrays with error messages and hints
  461. */
  462. public static function checkServer(\OC\SystemConfig $config) {
  463. $l = \OC::$server->getL10N('lib');
  464. $errors = [];
  465. $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data');
  466. if (!self::needUpgrade($config) && $config->getValue('installed', false)) {
  467. // this check needs to be done every time
  468. $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY);
  469. }
  470. // Assume that if checkServer() succeeded before in this session, then all is fine.
  471. if (\OC::$server->getSession()->exists('checkServer_succeeded') && \OC::$server->getSession()->get('checkServer_succeeded')) {
  472. return $errors;
  473. }
  474. $webServerRestart = false;
  475. $setup = new \OC\Setup(
  476. $config,
  477. \OC::$server->get(IniGetWrapper::class),
  478. \OC::$server->getL10N('lib'),
  479. \OC::$server->get(\OCP\Defaults::class),
  480. \OC::$server->get(LoggerInterface::class),
  481. \OC::$server->getSecureRandom(),
  482. \OC::$server->get(\OC\Installer::class)
  483. );
  484. $urlGenerator = \OC::$server->getURLGenerator();
  485. $availableDatabases = $setup->getSupportedDatabases();
  486. if (empty($availableDatabases)) {
  487. $errors[] = [
  488. 'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'),
  489. 'hint' => '' //TODO: sane hint
  490. ];
  491. $webServerRestart = true;
  492. }
  493. // Check if config folder is writable.
  494. if (!OC_Helper::isReadOnlyConfigEnabled()) {
  495. if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) {
  496. $errors[] = [
  497. 'error' => $l->t('Cannot write into "config" directory.'),
  498. 'hint' => $l->t('This can usually be fixed by giving the web server write access to the config directory. See %s',
  499. [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) . '. '
  500. . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s',
  501. [ $urlGenerator->linkToDocs('admin-config') ])
  502. ];
  503. }
  504. }
  505. // Check if there is a writable install folder.
  506. if ($config->getValue('appstoreenabled', true)) {
  507. if (OC_App::getInstallPath() === null
  508. || !is_writable(OC_App::getInstallPath())
  509. || !is_readable(OC_App::getInstallPath())
  510. ) {
  511. $errors[] = [
  512. 'error' => $l->t('Cannot write into "apps" directory.'),
  513. 'hint' => $l->t('This can usually be fixed by giving the web server write access to the apps directory'
  514. . ' or disabling the App Store in the config file.')
  515. ];
  516. }
  517. }
  518. // Create root dir.
  519. if ($config->getValue('installed', false)) {
  520. if (!is_dir($CONFIG_DATADIRECTORY)) {
  521. $success = @mkdir($CONFIG_DATADIRECTORY);
  522. if ($success) {
  523. $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY));
  524. } else {
  525. $errors[] = [
  526. 'error' => $l->t('Cannot create "data" directory.'),
  527. 'hint' => $l->t('This can usually be fixed by giving the web server write access to the root directory. See %s',
  528. [$urlGenerator->linkToDocs('admin-dir_permissions')])
  529. ];
  530. }
  531. } elseif (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) {
  532. // is_writable doesn't work for NFS mounts, so try to write a file and check if it exists.
  533. $testFile = sprintf('%s/%s.tmp', $CONFIG_DATADIRECTORY, uniqid('data_dir_writability_test_'));
  534. $handle = fopen($testFile, 'w');
  535. if (!$handle || fwrite($handle, 'Test write operation') === false) {
  536. $permissionsHint = $l->t('Permissions can usually be fixed by giving the web server write access to the root directory. See %s.',
  537. [$urlGenerator->linkToDocs('admin-dir_permissions')]);
  538. $errors[] = [
  539. 'error' => $l->t('Your data directory is not writable.'),
  540. 'hint' => $permissionsHint
  541. ];
  542. } else {
  543. fclose($handle);
  544. unlink($testFile);
  545. }
  546. } else {
  547. $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY));
  548. }
  549. }
  550. if (!OC_Util::isSetLocaleWorking()) {
  551. $errors[] = [
  552. 'error' => $l->t('Setting locale to %s failed.',
  553. ['en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/'
  554. . 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8']),
  555. 'hint' => $l->t('Please install one of these locales on your system and restart your web server.')
  556. ];
  557. }
  558. // Contains the dependencies that should be checked against
  559. // classes = class_exists
  560. // functions = function_exists
  561. // defined = defined
  562. // ini = ini_get
  563. // If the dependency is not found the missing module name is shown to the EndUser
  564. // When adding new checks always verify that they pass on Travis as well
  565. // for ini settings, see https://github.com/owncloud/administration/blob/master/travis-ci/custom.ini
  566. $dependencies = [
  567. 'classes' => [
  568. 'ZipArchive' => 'zip',
  569. 'DOMDocument' => 'dom',
  570. 'XMLWriter' => 'XMLWriter',
  571. 'XMLReader' => 'XMLReader',
  572. ],
  573. 'functions' => [
  574. 'xml_parser_create' => 'libxml',
  575. 'mb_strcut' => 'mbstring',
  576. 'ctype_digit' => 'ctype',
  577. 'json_encode' => 'JSON',
  578. 'gd_info' => 'GD',
  579. 'gzencode' => 'zlib',
  580. 'simplexml_load_string' => 'SimpleXML',
  581. 'hash' => 'HASH Message Digest Framework',
  582. 'curl_init' => 'cURL',
  583. 'openssl_verify' => 'OpenSSL',
  584. ],
  585. 'defined' => [
  586. 'PDO::ATTR_DRIVER_NAME' => 'PDO'
  587. ],
  588. 'ini' => [
  589. 'default_charset' => 'UTF-8',
  590. ],
  591. ];
  592. $missingDependencies = [];
  593. $invalidIniSettings = [];
  594. $iniWrapper = \OC::$server->get(IniGetWrapper::class);
  595. foreach ($dependencies['classes'] as $class => $module) {
  596. if (!class_exists($class)) {
  597. $missingDependencies[] = $module;
  598. }
  599. }
  600. foreach ($dependencies['functions'] as $function => $module) {
  601. if (!function_exists($function)) {
  602. $missingDependencies[] = $module;
  603. }
  604. }
  605. foreach ($dependencies['defined'] as $defined => $module) {
  606. if (!defined($defined)) {
  607. $missingDependencies[] = $module;
  608. }
  609. }
  610. foreach ($dependencies['ini'] as $setting => $expected) {
  611. if (strtolower($iniWrapper->getString($setting)) !== strtolower($expected)) {
  612. $invalidIniSettings[] = [$setting, $expected];
  613. }
  614. }
  615. foreach ($missingDependencies as $missingDependency) {
  616. $errors[] = [
  617. 'error' => $l->t('PHP module %s not installed.', [$missingDependency]),
  618. 'hint' => $l->t('Please ask your server administrator to install the module.'),
  619. ];
  620. $webServerRestart = true;
  621. }
  622. foreach ($invalidIniSettings as $setting) {
  623. $errors[] = [
  624. 'error' => $l->t('PHP setting "%s" is not set to "%s".', [$setting[0], var_export($setting[1], true)]),
  625. 'hint' => $l->t('Adjusting this setting in php.ini will make Nextcloud run again')
  626. ];
  627. $webServerRestart = true;
  628. }
  629. /**
  630. * The mbstring.func_overload check can only be performed if the mbstring
  631. * module is installed as it will return null if the checking setting is
  632. * not available and thus a check on the boolean value fails.
  633. *
  634. * TODO: Should probably be implemented in the above generic dependency
  635. * check somehow in the long-term.
  636. */
  637. if ($iniWrapper->getBool('mbstring.func_overload') !== null &&
  638. $iniWrapper->getBool('mbstring.func_overload') === true) {
  639. $errors[] = [
  640. 'error' => $l->t('<code>mbstring.func_overload</code> is set to <code>%s</code> instead of the expected value <code>0</code>.', [$iniWrapper->getString('mbstring.func_overload')]),
  641. 'hint' => $l->t('To fix this issue set <code>mbstring.func_overload</code> to <code>0</code> in your php.ini.')
  642. ];
  643. }
  644. if (function_exists('xml_parser_create') &&
  645. LIBXML_LOADED_VERSION < 20700) {
  646. $version = LIBXML_LOADED_VERSION;
  647. $major = floor($version / 10000);
  648. $version -= ($major * 10000);
  649. $minor = floor($version / 100);
  650. $version -= ($minor * 100);
  651. $patch = $version;
  652. $errors[] = [
  653. 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]),
  654. 'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.')
  655. ];
  656. }
  657. if (!self::isAnnotationsWorking()) {
  658. $errors[] = [
  659. 'error' => $l->t('PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.'),
  660. 'hint' => $l->t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.')
  661. ];
  662. }
  663. if (!\OC::$CLI && $webServerRestart) {
  664. $errors[] = [
  665. 'error' => $l->t('PHP modules have been installed, but they are still listed as missing?'),
  666. 'hint' => $l->t('Please ask your server administrator to restart the web server.')
  667. ];
  668. }
  669. foreach (['secret', 'instanceid', 'passwordsalt'] as $requiredConfig) {
  670. if ($config->getValue($requiredConfig, '') === '' && !\OC::$CLI && $config->getValue('installed', false)) {
  671. $errors[] = [
  672. 'error' => $l->t('The required %s config variable is not configured in the config.php file.', [$requiredConfig]),
  673. 'hint' => $l->t('Please ask your server administrator to check the Nextcloud configuration.')
  674. ];
  675. }
  676. }
  677. $errors = array_merge($errors, self::checkDatabaseVersion());
  678. // Cache the result of this function
  679. \OC::$server->getSession()->set('checkServer_succeeded', count($errors) == 0);
  680. return $errors;
  681. }
  682. /**
  683. * Check the database version
  684. *
  685. * @return array errors array
  686. */
  687. public static function checkDatabaseVersion() {
  688. $l = \OC::$server->getL10N('lib');
  689. $errors = [];
  690. $dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite');
  691. if ($dbType === 'pgsql') {
  692. // check PostgreSQL version
  693. // TODO latest postgresql 8 released was 8 years ago, maybe remove the
  694. // check completely?
  695. try {
  696. /** @var IDBConnection $connection */
  697. $connection = \OC::$server->get(IDBConnection::class);
  698. $result = $connection->executeQuery('SHOW SERVER_VERSION');
  699. $data = $result->fetch();
  700. $result->closeCursor();
  701. if (isset($data['server_version'])) {
  702. $version = $data['server_version'];
  703. if (version_compare($version, '9.0.0', '<')) {
  704. $errors[] = [
  705. 'error' => $l->t('PostgreSQL >= 9 required.'),
  706. 'hint' => $l->t('Please upgrade your database version.')
  707. ];
  708. }
  709. }
  710. } catch (\Doctrine\DBAL\Exception $e) {
  711. $logger = \OC::$server->getLogger();
  712. $logger->warning('Error occurred while checking PostgreSQL version, assuming >= 9');
  713. $logger->logException($e);
  714. }
  715. }
  716. return $errors;
  717. }
  718. /**
  719. * Check for correct file permissions of data directory
  720. *
  721. * @param string $dataDirectory
  722. * @return array arrays with error messages and hints
  723. */
  724. public static function checkDataDirectoryPermissions($dataDirectory) {
  725. if (\OC::$server->getConfig()->getSystemValue('check_data_directory_permissions', true) === false) {
  726. return [];
  727. }
  728. $perms = substr(decoct(@fileperms($dataDirectory)), -3);
  729. if (substr($perms, -1) !== '0') {
  730. chmod($dataDirectory, 0770);
  731. clearstatcache();
  732. $perms = substr(decoct(@fileperms($dataDirectory)), -3);
  733. if ($perms[2] !== '0') {
  734. $l = \OC::$server->getL10N('lib');
  735. return [[
  736. 'error' => $l->t('Your data directory is readable by other users.'),
  737. 'hint' => $l->t('Please change the permissions to 0770 so that the directory cannot be listed by other users.'),
  738. ]];
  739. }
  740. }
  741. return [];
  742. }
  743. /**
  744. * Check that the data directory exists and is valid by
  745. * checking the existence of the ".ocdata" file.
  746. *
  747. * @param string $dataDirectory data directory path
  748. * @return array errors found
  749. */
  750. public static function checkDataDirectoryValidity($dataDirectory) {
  751. $l = \OC::$server->getL10N('lib');
  752. $errors = [];
  753. if ($dataDirectory[0] !== '/') {
  754. $errors[] = [
  755. 'error' => $l->t('Your data directory must be an absolute path.'),
  756. 'hint' => $l->t('Check the value of "datadirectory" in your configuration.')
  757. ];
  758. }
  759. if (!file_exists($dataDirectory . '/.ocdata')) {
  760. $errors[] = [
  761. 'error' => $l->t('Your data directory is invalid.'),
  762. 'hint' => $l->t('Ensure there is a file called ".ocdata"' .
  763. ' in the root of the data directory.')
  764. ];
  765. }
  766. return $errors;
  767. }
  768. /**
  769. * Check if the user is logged in, redirects to home if not. With
  770. * redirect URL parameter to the request URI.
  771. *
  772. * @return void
  773. */
  774. public static function checkLoggedIn() {
  775. // Check if we are a user
  776. if (!\OC::$server->getUserSession()->isLoggedIn()) {
  777. header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute(
  778. 'core.login.showLoginForm',
  779. [
  780. 'redirect_url' => \OC::$server->getRequest()->getRequestUri(),
  781. ]
  782. )
  783. );
  784. exit();
  785. }
  786. // Redirect to 2FA challenge selection if 2FA challenge was not solved yet
  787. if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) {
  788. header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge'));
  789. exit();
  790. }
  791. }
  792. /**
  793. * Check if the user is a admin, redirects to home if not
  794. *
  795. * @return void
  796. */
  797. public static function checkAdminUser() {
  798. OC_Util::checkLoggedIn();
  799. if (!OC_User::isAdminUser(OC_User::getUser())) {
  800. header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php'));
  801. exit();
  802. }
  803. }
  804. /**
  805. * Returns the URL of the default page
  806. * based on the system configuration and
  807. * the apps visible for the current user
  808. *
  809. * @return string URL
  810. * @suppress PhanDeprecatedFunction
  811. */
  812. public static function getDefaultPageUrl() {
  813. /** @var IURLGenerator $urlGenerator */
  814. $urlGenerator = \OC::$server->get(IURLGenerator::class);
  815. return $urlGenerator->linkToDefaultPageUrl();
  816. }
  817. /**
  818. * Redirect to the user default page
  819. *
  820. * @return void
  821. */
  822. public static function redirectToDefaultPage() {
  823. $location = self::getDefaultPageUrl();
  824. header('Location: ' . $location);
  825. exit();
  826. }
  827. /**
  828. * get an id unique for this instance
  829. *
  830. * @return string
  831. */
  832. public static function getInstanceId() {
  833. $id = \OC::$server->getSystemConfig()->getValue('instanceid', null);
  834. if (is_null($id)) {
  835. // We need to guarantee at least one letter in instanceid so it can be used as the session_name
  836. $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS);
  837. \OC::$server->getSystemConfig()->setValue('instanceid', $id);
  838. }
  839. return $id;
  840. }
  841. /**
  842. * Public function to sanitize HTML
  843. *
  844. * This function is used to sanitize HTML and should be applied on any
  845. * string or array of strings before displaying it on a web page.
  846. *
  847. * @param string|string[] $value
  848. * @return string|string[] an array of sanitized strings or a single sanitized string, depends on the input parameter.
  849. */
  850. public static function sanitizeHTML($value) {
  851. if (is_array($value)) {
  852. /** @var string[] $value */
  853. $value = array_map(function ($value) {
  854. return self::sanitizeHTML($value);
  855. }, $value);
  856. } else {
  857. // Specify encoding for PHP<5.4
  858. $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
  859. }
  860. return $value;
  861. }
  862. /**
  863. * Public function to encode url parameters
  864. *
  865. * This function is used to encode path to file before output.
  866. * Encoding is done according to RFC 3986 with one exception:
  867. * Character '/' is preserved as is.
  868. *
  869. * @param string $component part of URI to encode
  870. * @return string
  871. */
  872. public static function encodePath($component) {
  873. $encoded = rawurlencode($component);
  874. $encoded = str_replace('%2F', '/', $encoded);
  875. return $encoded;
  876. }
  877. public function createHtaccessTestFile(\OCP\IConfig $config) {
  878. // php dev server does not support htaccess
  879. if (php_sapi_name() === 'cli-server') {
  880. return false;
  881. }
  882. // testdata
  883. $fileName = '/htaccesstest.txt';
  884. $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.';
  885. // creating a test file
  886. $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName;
  887. if (file_exists($testFile)) {// already running this test, possible recursive call
  888. return false;
  889. }
  890. $fp = @fopen($testFile, 'w');
  891. if (!$fp) {
  892. throw new \OCP\HintException('Can\'t create test file to check for working .htaccess file.',
  893. 'Make sure it is possible for the web server to write to ' . $testFile);
  894. }
  895. fwrite($fp, $testContent);
  896. fclose($fp);
  897. return $testContent;
  898. }
  899. /**
  900. * Check if the .htaccess file is working
  901. *
  902. * @param \OCP\IConfig $config
  903. * @return bool
  904. * @throws Exception
  905. * @throws \OCP\HintException If the test file can't get written.
  906. */
  907. public function isHtaccessWorking(\OCP\IConfig $config) {
  908. if (\OC::$CLI || !$config->getSystemValue('check_for_working_htaccess', true)) {
  909. return true;
  910. }
  911. $testContent = $this->createHtaccessTestFile($config);
  912. if ($testContent === false) {
  913. return false;
  914. }
  915. $fileName = '/htaccesstest.txt';
  916. $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName;
  917. // accessing the file via http
  918. $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName);
  919. try {
  920. $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody();
  921. } catch (\Exception $e) {
  922. $content = false;
  923. }
  924. if (strpos($url, 'https:') === 0) {
  925. $url = 'http:' . substr($url, 6);
  926. } else {
  927. $url = 'https:' . substr($url, 5);
  928. }
  929. try {
  930. $fallbackContent = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody();
  931. } catch (\Exception $e) {
  932. $fallbackContent = false;
  933. }
  934. // cleanup
  935. @unlink($testFile);
  936. /*
  937. * If the content is not equal to test content our .htaccess
  938. * is working as required
  939. */
  940. return $content !== $testContent && $fallbackContent !== $testContent;
  941. }
  942. /**
  943. * Check if current locale is non-UTF8
  944. *
  945. * @return bool
  946. */
  947. private static function isNonUTF8Locale() {
  948. if (function_exists('escapeshellcmd')) {
  949. return '' === escapeshellcmd('§');
  950. } elseif (function_exists('escapeshellarg')) {
  951. return '\'\'' === escapeshellarg('§');
  952. } else {
  953. return 0 === preg_match('/utf-?8/i', setlocale(LC_CTYPE, 0));
  954. }
  955. }
  956. /**
  957. * Check if the setlocale call does not work. This can happen if the right
  958. * local packages are not available on the server.
  959. *
  960. * @return bool
  961. */
  962. public static function isSetLocaleWorking() {
  963. if (self::isNonUTF8Locale()) {
  964. // Borrowed from \Patchwork\Utf8\Bootup::initLocale
  965. setlocale(LC_ALL, 'C.UTF-8', 'C');
  966. setlocale(LC_CTYPE, 'en_US.UTF-8', 'fr_FR.UTF-8', 'es_ES.UTF-8', 'de_DE.UTF-8', 'ru_RU.UTF-8', 'pt_BR.UTF-8', 'it_IT.UTF-8', 'ja_JP.UTF-8', 'zh_CN.UTF-8', '0');
  967. // Check again
  968. if (self::isNonUTF8Locale()) {
  969. return false;
  970. }
  971. }
  972. return true;
  973. }
  974. /**
  975. * Check if it's possible to get the inline annotations
  976. *
  977. * @return bool
  978. */
  979. public static function isAnnotationsWorking() {
  980. $reflection = new \ReflectionMethod(__METHOD__);
  981. $docs = $reflection->getDocComment();
  982. return (is_string($docs) && strlen($docs) > 50);
  983. }
  984. /**
  985. * Check if the PHP module fileinfo is loaded.
  986. *
  987. * @return bool
  988. */
  989. public static function fileInfoLoaded() {
  990. return function_exists('finfo_open');
  991. }
  992. /**
  993. * clear all levels of output buffering
  994. *
  995. * @return void
  996. */
  997. public static function obEnd() {
  998. while (ob_get_level()) {
  999. ob_end_clean();
  1000. }
  1001. }
  1002. /**
  1003. * Checks whether the server is running on Mac OS X
  1004. *
  1005. * @return bool true if running on Mac OS X, false otherwise
  1006. */
  1007. public static function runningOnMac() {
  1008. return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN');
  1009. }
  1010. /**
  1011. * Handles the case that there may not be a theme, then check if a "default"
  1012. * theme exists and take that one
  1013. *
  1014. * @return string the theme
  1015. */
  1016. public static function getTheme() {
  1017. $theme = \OC::$server->getSystemConfig()->getValue("theme", '');
  1018. if ($theme === '') {
  1019. if (is_dir(OC::$SERVERROOT . '/themes/default')) {
  1020. $theme = 'default';
  1021. }
  1022. }
  1023. return $theme;
  1024. }
  1025. /**
  1026. * Normalize a unicode string
  1027. *
  1028. * @param string $value a not normalized string
  1029. * @return bool|string
  1030. */
  1031. public static function normalizeUnicode($value) {
  1032. if (Normalizer::isNormalized($value)) {
  1033. return $value;
  1034. }
  1035. $normalizedValue = Normalizer::normalize($value);
  1036. if ($normalizedValue === null || $normalizedValue === false) {
  1037. \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']);
  1038. return $value;
  1039. }
  1040. return $normalizedValue;
  1041. }
  1042. /**
  1043. * A human readable string is generated based on version and build number
  1044. *
  1045. * @return string
  1046. */
  1047. public static function getHumanVersion() {
  1048. $version = OC_Util::getVersionString();
  1049. $build = OC_Util::getBuild();
  1050. if (!empty($build) and OC_Util::getChannel() === 'daily') {
  1051. $version .= ' Build:' . $build;
  1052. }
  1053. return $version;
  1054. }
  1055. /**
  1056. * Returns whether the given file name is valid
  1057. *
  1058. * @param string $file file name to check
  1059. * @return bool true if the file name is valid, false otherwise
  1060. * @deprecated use \OC\Files\View::verifyPath()
  1061. */
  1062. public static function isValidFileName($file) {
  1063. $trimmed = trim($file);
  1064. if ($trimmed === '') {
  1065. return false;
  1066. }
  1067. if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) {
  1068. return false;
  1069. }
  1070. // detect part files
  1071. if (preg_match('/' . \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX . '/', $trimmed) !== 0) {
  1072. return false;
  1073. }
  1074. foreach (str_split($trimmed) as $char) {
  1075. if (strpos(\OCP\Constants::FILENAME_INVALID_CHARS, $char) !== false) {
  1076. return false;
  1077. }
  1078. }
  1079. return true;
  1080. }
  1081. /**
  1082. * Check whether the instance needs to perform an upgrade,
  1083. * either when the core version is higher or any app requires
  1084. * an upgrade.
  1085. *
  1086. * @param \OC\SystemConfig $config
  1087. * @return bool whether the core or any app needs an upgrade
  1088. * @throws \OCP\HintException When the upgrade from the given version is not allowed
  1089. */
  1090. public static function needUpgrade(\OC\SystemConfig $config) {
  1091. if ($config->getValue('installed', false)) {
  1092. $installedVersion = $config->getValue('version', '0.0.0');
  1093. $currentVersion = implode('.', \OCP\Util::getVersion());
  1094. $versionDiff = version_compare($currentVersion, $installedVersion);
  1095. if ($versionDiff > 0) {
  1096. return true;
  1097. } elseif ($config->getValue('debug', false) && $versionDiff < 0) {
  1098. // downgrade with debug
  1099. $installedMajor = explode('.', $installedVersion);
  1100. $installedMajor = $installedMajor[0] . '.' . $installedMajor[1];
  1101. $currentMajor = explode('.', $currentVersion);
  1102. $currentMajor = $currentMajor[0] . '.' . $currentMajor[1];
  1103. if ($installedMajor === $currentMajor) {
  1104. // Same major, allow downgrade for developers
  1105. return true;
  1106. } else {
  1107. // downgrade attempt, throw exception
  1108. throw new \OCP\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')');
  1109. }
  1110. } elseif ($versionDiff < 0) {
  1111. // downgrade attempt, throw exception
  1112. throw new \OCP\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')');
  1113. }
  1114. // also check for upgrades for apps (independently from the user)
  1115. $apps = \OC_App::getEnabledApps(false, true);
  1116. $shouldUpgrade = false;
  1117. foreach ($apps as $app) {
  1118. if (\OC_App::shouldUpgrade($app)) {
  1119. $shouldUpgrade = true;
  1120. break;
  1121. }
  1122. }
  1123. return $shouldUpgrade;
  1124. } else {
  1125. return false;
  1126. }
  1127. }
  1128. }