OC_Util.php 38 KB

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