Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

CheckSetupController.php 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bjoern Schiessle <bjoern@schiessle.org>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Cthulhux <git@tuxproject.de>
  8. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  9. * @author Derek <derek.kelly27@gmail.com>
  10. * @author Georg Ehrke <oc.list@georgehrke.com>
  11. * @author Joas Schilling <coding@schilljs.com>
  12. * @author Ko- <k.stoffelen@cs.ru.nl>
  13. * @author Lauris Binde <laurisb@users.noreply.github.com>
  14. * @author Lukas Reschke <lukas@statuscode.ch>
  15. * @author Michael Weimann <mail@michael-weimann.eu>
  16. * @author Morris Jobke <hey@morrisjobke.de>
  17. * @author Robin McCorkell <robin@mccorkell.me.uk>
  18. * @author Roeland Jago Douma <roeland@famdouma.nl>
  19. * @author Sven Strickroth <email@cs-ware.de>
  20. * @author Sylvia van Os <sylvia@hackerchick.me>
  21. * @author Timo Förster <tfoerster@webfoersterei.de>
  22. *
  23. * @license AGPL-3.0
  24. *
  25. * This code is free software: you can redistribute it and/or modify
  26. * it under the terms of the GNU Affero General Public License, version 3,
  27. * as published by the Free Software Foundation.
  28. *
  29. * This program is distributed in the hope that it will be useful,
  30. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  32. * GNU Affero General Public License for more details.
  33. *
  34. * You should have received a copy of the GNU Affero General Public License, version 3,
  35. * along with this program. If not, see <http://www.gnu.org/licenses/>
  36. *
  37. */
  38. namespace OCA\Settings\Controller;
  39. use bantu\IniGetWrapper\IniGetWrapper;
  40. use DirectoryIterator;
  41. use Doctrine\DBAL\DBALException;
  42. use Doctrine\DBAL\Platforms\SqlitePlatform;
  43. use Doctrine\DBAL\Types\Types;
  44. use GuzzleHttp\Exception\ClientException;
  45. use OC;
  46. use OC\AppFramework\Http;
  47. use OC\DB\Connection;
  48. use OC\DB\MissingColumnInformation;
  49. use OC\DB\MissingIndexInformation;
  50. use OC\DB\SchemaWrapper;
  51. use OC\IntegrityCheck\Checker;
  52. use OC\Lock\NoopLockingProvider;
  53. use OC\MemoryInfo;
  54. use OCA\Settings\SetupChecks\LegacySSEKeyFormat;
  55. use OCA\Settings\SetupChecks\PhpDefaultCharset;
  56. use OCA\Settings\SetupChecks\PhpOutputBuffering;
  57. use OCP\AppFramework\Controller;
  58. use OCP\AppFramework\Http\DataDisplayResponse;
  59. use OCP\AppFramework\Http\DataResponse;
  60. use OCP\AppFramework\Http\RedirectResponse;
  61. use OCP\Http\Client\IClientService;
  62. use OCP\IConfig;
  63. use OCP\IDateTimeFormatter;
  64. use OCP\IDBConnection;
  65. use OCP\IL10N;
  66. use OCP\ILogger;
  67. use OCP\IRequest;
  68. use OCP\IURLGenerator;
  69. use OCP\Lock\ILockingProvider;
  70. use OCP\Security\ISecureRandom;
  71. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  72. use Symfony\Component\EventDispatcher\GenericEvent;
  73. class CheckSetupController extends Controller {
  74. /** @var IConfig */
  75. private $config;
  76. /** @var IClientService */
  77. private $clientService;
  78. /** @var IURLGenerator */
  79. private $urlGenerator;
  80. /** @var IL10N */
  81. private $l10n;
  82. /** @var Checker */
  83. private $checker;
  84. /** @var ILogger */
  85. private $logger;
  86. /** @var EventDispatcherInterface */
  87. private $dispatcher;
  88. /** @var IDBConnection|Connection */
  89. private $db;
  90. /** @var ILockingProvider */
  91. private $lockingProvider;
  92. /** @var IDateTimeFormatter */
  93. private $dateTimeFormatter;
  94. /** @var MemoryInfo */
  95. private $memoryInfo;
  96. /** @var ISecureRandom */
  97. private $secureRandom;
  98. /** @var IniGetWrapper */
  99. private $iniGetWrapper;
  100. public function __construct($AppName,
  101. IRequest $request,
  102. IConfig $config,
  103. IClientService $clientService,
  104. IURLGenerator $urlGenerator,
  105. IL10N $l10n,
  106. Checker $checker,
  107. ILogger $logger,
  108. EventDispatcherInterface $dispatcher,
  109. IDBConnection $db,
  110. ILockingProvider $lockingProvider,
  111. IDateTimeFormatter $dateTimeFormatter,
  112. MemoryInfo $memoryInfo,
  113. ISecureRandom $secureRandom,
  114. IniGetWrapper $iniGetWrapper) {
  115. parent::__construct($AppName, $request);
  116. $this->config = $config;
  117. $this->clientService = $clientService;
  118. $this->urlGenerator = $urlGenerator;
  119. $this->l10n = $l10n;
  120. $this->checker = $checker;
  121. $this->logger = $logger;
  122. $this->dispatcher = $dispatcher;
  123. $this->db = $db;
  124. $this->lockingProvider = $lockingProvider;
  125. $this->dateTimeFormatter = $dateTimeFormatter;
  126. $this->memoryInfo = $memoryInfo;
  127. $this->secureRandom = $secureRandom;
  128. $this->iniGetWrapper = $iniGetWrapper;
  129. }
  130. /**
  131. * Checks if the server can connect to the internet using HTTPS and HTTP
  132. * @return bool
  133. */
  134. private function hasInternetConnectivityProblems(): bool {
  135. if ($this->config->getSystemValue('has_internet_connection', true) === false) {
  136. return false;
  137. }
  138. $siteArray = $this->config->getSystemValue('connectivity_check_domains', [
  139. 'www.nextcloud.com', 'www.startpage.com', 'www.eff.org', 'www.edri.org'
  140. ]);
  141. foreach ($siteArray as $site) {
  142. if ($this->isSiteReachable($site)) {
  143. return false;
  144. }
  145. }
  146. return true;
  147. }
  148. /**
  149. * Checks if the Nextcloud server can connect to a specific URL using both HTTPS and HTTP
  150. * @return bool
  151. */
  152. private function isSiteReachable($sitename) {
  153. $httpSiteName = 'http://' . $sitename . '/';
  154. $httpsSiteName = 'https://' . $sitename . '/';
  155. try {
  156. $client = $this->clientService->newClient();
  157. $client->get($httpSiteName);
  158. $client->get($httpsSiteName);
  159. } catch (\Exception $e) {
  160. $this->logger->logException($e, ['app' => 'internet_connection_check']);
  161. return false;
  162. }
  163. return true;
  164. }
  165. /**
  166. * Checks whether a local memcache is installed or not
  167. * @return bool
  168. */
  169. private function isMemcacheConfigured() {
  170. return $this->config->getSystemValue('memcache.local', null) !== null;
  171. }
  172. /**
  173. * Whether PHP can generate "secure" pseudorandom integers
  174. *
  175. * @return bool
  176. */
  177. private function isRandomnessSecure() {
  178. try {
  179. $this->secureRandom->generate(1);
  180. } catch (\Exception $ex) {
  181. return false;
  182. }
  183. return true;
  184. }
  185. /**
  186. * Public for the sake of unit-testing
  187. *
  188. * @return array
  189. */
  190. protected function getCurlVersion() {
  191. return curl_version();
  192. }
  193. /**
  194. * Check if the used SSL lib is outdated. Older OpenSSL and NSS versions do
  195. * have multiple bugs which likely lead to problems in combination with
  196. * functionality required by ownCloud such as SNI.
  197. *
  198. * @link https://github.com/owncloud/core/issues/17446#issuecomment-122877546
  199. * @link https://bugzilla.redhat.com/show_bug.cgi?id=1241172
  200. * @return string
  201. */
  202. private function isUsedTlsLibOutdated() {
  203. // Don't run check when:
  204. // 1. Server has `has_internet_connection` set to false
  205. // 2. AppStore AND S2S is disabled
  206. if (!$this->config->getSystemValue('has_internet_connection', true)) {
  207. return '';
  208. }
  209. if (!$this->config->getSystemValue('appstoreenabled', true)
  210. && $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'no'
  211. && $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'no') {
  212. return '';
  213. }
  214. $versionString = $this->getCurlVersion();
  215. if (isset($versionString['ssl_version'])) {
  216. $versionString = $versionString['ssl_version'];
  217. } else {
  218. return '';
  219. }
  220. $features = (string)$this->l10n->t('installing and updating apps via the app store or Federated Cloud Sharing');
  221. if (!$this->config->getSystemValue('appstoreenabled', true)) {
  222. $features = (string)$this->l10n->t('Federated Cloud Sharing');
  223. }
  224. // Check if at least OpenSSL after 1.01d or 1.0.2b
  225. if (strpos($versionString, 'OpenSSL/') === 0) {
  226. $majorVersion = substr($versionString, 8, 5);
  227. $patchRelease = substr($versionString, 13, 6);
  228. if (($majorVersion === '1.0.1' && ord($patchRelease) < ord('d')) ||
  229. ($majorVersion === '1.0.2' && ord($patchRelease) < ord('b'))) {
  230. return $this->l10n->t('cURL is using an outdated %1$s version (%2$s). Please update your operating system or features such as %3$s will not work reliably.', ['OpenSSL', $versionString, $features]);
  231. }
  232. }
  233. // Check if NSS and perform heuristic check
  234. if (strpos($versionString, 'NSS/') === 0) {
  235. try {
  236. $firstClient = $this->clientService->newClient();
  237. $firstClient->get('https://nextcloud.com/');
  238. $secondClient = $this->clientService->newClient();
  239. $secondClient->get('https://nextcloud.com/');
  240. } catch (ClientException $e) {
  241. if ($e->getResponse()->getStatusCode() === 400) {
  242. return $this->l10n->t('cURL is using an outdated %1$s version (%2$s). Please update your operating system or features such as %3$s will not work reliably.', ['NSS', $versionString, $features]);
  243. }
  244. }
  245. }
  246. return '';
  247. }
  248. /**
  249. * Whether the version is outdated
  250. *
  251. * @return bool
  252. */
  253. protected function isPhpOutdated(): bool {
  254. return PHP_VERSION_ID < 70300;
  255. }
  256. /**
  257. * Whether the php version is still supported (at time of release)
  258. * according to: https://www.php.net/supported-versions.php
  259. *
  260. * @return array
  261. */
  262. private function isPhpSupported(): array {
  263. return ['eol' => $this->isPhpOutdated(), 'version' => PHP_VERSION];
  264. }
  265. /**
  266. * Check if the reverse proxy configuration is working as expected
  267. *
  268. * @return bool
  269. */
  270. private function forwardedForHeadersWorking() {
  271. $trustedProxies = $this->config->getSystemValue('trusted_proxies', []);
  272. $remoteAddress = $this->request->getHeader('REMOTE_ADDR');
  273. if (empty($trustedProxies) && $this->request->getHeader('X-Forwarded-Host') !== '') {
  274. return false;
  275. }
  276. if (\is_array($trustedProxies) && \in_array($remoteAddress, $trustedProxies, true)) {
  277. return $remoteAddress !== $this->request->getRemoteAddress();
  278. }
  279. // either not enabled or working correctly
  280. return true;
  281. }
  282. /**
  283. * Checks if the correct memcache module for PHP is installed. Only
  284. * fails if memcached is configured and the working module is not installed.
  285. *
  286. * @return bool
  287. */
  288. private function isCorrectMemcachedPHPModuleInstalled() {
  289. if ($this->config->getSystemValue('memcache.distributed', null) !== '\OC\Memcache\Memcached') {
  290. return true;
  291. }
  292. // there are two different memcached modules for PHP
  293. // we only support memcached and not memcache
  294. // https://code.google.com/p/memcached/wiki/PHPClientComparison
  295. return !(!extension_loaded('memcached') && extension_loaded('memcache'));
  296. }
  297. /**
  298. * Checks if set_time_limit is not disabled.
  299. *
  300. * @return bool
  301. */
  302. private function isSettimelimitAvailable() {
  303. if (function_exists('set_time_limit')
  304. && strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
  305. return true;
  306. }
  307. return false;
  308. }
  309. /**
  310. * @return RedirectResponse
  311. */
  312. public function rescanFailedIntegrityCheck() {
  313. $this->checker->runInstanceVerification();
  314. return new RedirectResponse(
  315. $this->urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => 'overview'])
  316. );
  317. }
  318. /**
  319. * @NoCSRFRequired
  320. * @return DataResponse
  321. */
  322. public function getFailedIntegrityCheckFiles() {
  323. if (!$this->checker->isCodeCheckEnforced()) {
  324. return new DataDisplayResponse('Integrity checker has been disabled. Integrity cannot be verified.');
  325. }
  326. $completeResults = $this->checker->getResults();
  327. if (!empty($completeResults)) {
  328. $formattedTextResponse = 'Technical information
  329. =====================
  330. The following list covers which files have failed the integrity check. Please read
  331. the previous linked documentation to learn more about the errors and how to fix
  332. them.
  333. Results
  334. =======
  335. ';
  336. foreach ($completeResults as $context => $contextResult) {
  337. $formattedTextResponse .= "- $context\n";
  338. foreach ($contextResult as $category => $result) {
  339. $formattedTextResponse .= "\t- $category\n";
  340. if ($category !== 'EXCEPTION') {
  341. foreach ($result as $key => $results) {
  342. $formattedTextResponse .= "\t\t- $key\n";
  343. }
  344. } else {
  345. foreach ($result as $key => $results) {
  346. $formattedTextResponse .= "\t\t- $results\n";
  347. }
  348. }
  349. }
  350. }
  351. $formattedTextResponse .= '
  352. Raw output
  353. ==========
  354. ';
  355. $formattedTextResponse .= print_r($completeResults, true);
  356. } else {
  357. $formattedTextResponse = 'No errors have been found.';
  358. }
  359. $response = new DataDisplayResponse(
  360. $formattedTextResponse,
  361. Http::STATUS_OK,
  362. [
  363. 'Content-Type' => 'text/plain',
  364. ]
  365. );
  366. return $response;
  367. }
  368. /**
  369. * Checks whether a PHP opcache is properly set up
  370. * @return bool
  371. */
  372. protected function isOpcacheProperlySetup() {
  373. if (!$this->iniGetWrapper->getBool('opcache.enable')) {
  374. return false;
  375. }
  376. if (!$this->iniGetWrapper->getBool('opcache.save_comments')) {
  377. return false;
  378. }
  379. if ($this->iniGetWrapper->getNumeric('opcache.max_accelerated_files') < 10000) {
  380. return false;
  381. }
  382. if ($this->iniGetWrapper->getNumeric('opcache.memory_consumption') < 128) {
  383. return false;
  384. }
  385. if ($this->iniGetWrapper->getNumeric('opcache.interned_strings_buffer') < 8) {
  386. return false;
  387. }
  388. return true;
  389. }
  390. /**
  391. * Check if the required FreeType functions are present
  392. * @return bool
  393. */
  394. protected function hasFreeTypeSupport() {
  395. return function_exists('imagettfbbox') && function_exists('imagettftext');
  396. }
  397. protected function hasMissingIndexes(): array {
  398. $indexInfo = new MissingIndexInformation();
  399. // Dispatch event so apps can also hint for pending index updates if needed
  400. $event = new GenericEvent($indexInfo);
  401. $this->dispatcher->dispatch(IDBConnection::CHECK_MISSING_INDEXES_EVENT, $event);
  402. return $indexInfo->getListOfMissingIndexes();
  403. }
  404. protected function hasMissingColumns(): array {
  405. $indexInfo = new MissingColumnInformation();
  406. // Dispatch event so apps can also hint for pending index updates if needed
  407. $event = new GenericEvent($indexInfo);
  408. $this->dispatcher->dispatch(IDBConnection::CHECK_MISSING_COLUMNS_EVENT, $event);
  409. return $indexInfo->getListOfMissingColumns();
  410. }
  411. protected function isSqliteUsed() {
  412. return strpos($this->config->getSystemValue('dbtype'), 'sqlite') !== false;
  413. }
  414. protected function isReadOnlyConfig(): bool {
  415. return \OC_Helper::isReadOnlyConfigEnabled();
  416. }
  417. protected function hasValidTransactionIsolationLevel(): bool {
  418. try {
  419. if ($this->db->getDatabasePlatform() instanceof SqlitePlatform) {
  420. return true;
  421. }
  422. return $this->db->getTransactionIsolation() === Connection::TRANSACTION_READ_COMMITTED;
  423. } catch (DBALException $e) {
  424. // ignore
  425. }
  426. return true;
  427. }
  428. protected function hasFileinfoInstalled(): bool {
  429. return \OC_Util::fileInfoLoaded();
  430. }
  431. protected function hasWorkingFileLocking(): bool {
  432. return !($this->lockingProvider instanceof NoopLockingProvider);
  433. }
  434. protected function getSuggestedOverwriteCliURL(): string {
  435. $suggestedOverwriteCliUrl = '';
  436. if ($this->config->getSystemValue('overwrite.cli.url', '') === '') {
  437. $suggestedOverwriteCliUrl = $this->request->getServerProtocol() . '://' . $this->request->getInsecureServerHost() . \OC::$WEBROOT;
  438. if (!$this->config->getSystemValue('config_is_read_only', false)) {
  439. // Set the overwrite URL when it was not set yet.
  440. $this->config->setSystemValue('overwrite.cli.url', $suggestedOverwriteCliUrl);
  441. $suggestedOverwriteCliUrl = '';
  442. }
  443. }
  444. return $suggestedOverwriteCliUrl;
  445. }
  446. protected function getLastCronInfo(): array {
  447. $lastCronRun = $this->config->getAppValue('core', 'lastcron', 0);
  448. return [
  449. 'diffInSeconds' => time() - $lastCronRun,
  450. 'relativeTime' => $this->dateTimeFormatter->formatTimeSpan($lastCronRun),
  451. 'backgroundJobsUrl' => $this->urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => 'server']) . '#backgroundjobs',
  452. ];
  453. }
  454. protected function getCronErrors() {
  455. $errors = json_decode($this->config->getAppValue('core', 'cronErrors', ''), true);
  456. if (is_array($errors)) {
  457. return $errors;
  458. }
  459. return [];
  460. }
  461. protected function isPHPMailerUsed(): bool {
  462. return $this->config->getSystemValue('mail_smtpmode', 'smtp') === 'php';
  463. }
  464. protected function hasOpcacheLoaded(): bool {
  465. return extension_loaded('Zend OPcache');
  466. }
  467. /**
  468. * Iterates through the configured app roots and
  469. * tests if the subdirectories are owned by the same user than the current user.
  470. *
  471. * @return array
  472. */
  473. protected function getAppDirsWithDifferentOwner(): array {
  474. $currentUser = posix_getuid();
  475. $appDirsWithDifferentOwner = [[]];
  476. foreach (OC::$APPSROOTS as $appRoot) {
  477. if ($appRoot['writable'] === true) {
  478. $appDirsWithDifferentOwner[] = $this->getAppDirsWithDifferentOwnerForAppRoot($currentUser, $appRoot);
  479. }
  480. }
  481. $appDirsWithDifferentOwner = array_merge(...$appDirsWithDifferentOwner);
  482. sort($appDirsWithDifferentOwner);
  483. return $appDirsWithDifferentOwner;
  484. }
  485. /**
  486. * Tests if the directories for one apps directory are writable by the current user.
  487. *
  488. * @param int $currentUser The current user
  489. * @param array $appRoot The app root config
  490. * @return string[] The none writable directory paths inside the app root
  491. */
  492. private function getAppDirsWithDifferentOwnerForAppRoot(int $currentUser, array $appRoot): array {
  493. $appDirsWithDifferentOwner = [];
  494. $appsPath = $appRoot['path'];
  495. $appsDir = new DirectoryIterator($appRoot['path']);
  496. foreach ($appsDir as $fileInfo) {
  497. if ($fileInfo->isDir() && !$fileInfo->isDot()) {
  498. $absAppPath = $appsPath . DIRECTORY_SEPARATOR . $fileInfo->getFilename();
  499. $appDirUser = fileowner($absAppPath);
  500. if ($appDirUser !== $currentUser) {
  501. $appDirsWithDifferentOwner[] = $absAppPath;
  502. }
  503. }
  504. }
  505. return $appDirsWithDifferentOwner;
  506. }
  507. /**
  508. * Checks for potential PHP modules that would improve the instance
  509. *
  510. * @return string[] A list of PHP modules that is recommended
  511. */
  512. protected function hasRecommendedPHPModules(): array {
  513. $recommendedPHPModules = [];
  514. if (!extension_loaded('intl')) {
  515. $recommendedPHPModules[] = 'intl';
  516. }
  517. if (!extension_loaded('bcmath')) {
  518. $recommendedPHPModules[] = 'bcmath';
  519. }
  520. if (!extension_loaded('gmp')) {
  521. $recommendedPHPModules[] = 'gmp';
  522. }
  523. if ($this->config->getAppValue('theming', 'enabled', 'no') === 'yes') {
  524. if (!extension_loaded('imagick')) {
  525. $recommendedPHPModules[] = 'imagick';
  526. }
  527. }
  528. return $recommendedPHPModules;
  529. }
  530. protected function isMysqlUsedWithoutUTF8MB4(): bool {
  531. return ($this->config->getSystemValue('dbtype', 'sqlite') === 'mysql') && ($this->config->getSystemValue('mysql.utf8mb4', false) === false);
  532. }
  533. protected function hasBigIntConversionPendingColumns(): array {
  534. // copy of ConvertFilecacheBigInt::getColumnsByTable()
  535. $tables = [
  536. 'activity' => ['activity_id', 'object_id'],
  537. 'activity_mq' => ['mail_id'],
  538. 'authtoken' => ['id'],
  539. 'bruteforce_attempts' => ['id'],
  540. 'filecache' => ['fileid', 'storage', 'parent', 'mimetype', 'mimepart', 'mtime', 'storage_mtime'],
  541. 'file_locks' => ['id'],
  542. 'jobs' => ['id'],
  543. 'mimetypes' => ['id'],
  544. 'mounts' => ['id', 'storage_id', 'root_id', 'mount_id'],
  545. 'storages' => ['numeric_id'],
  546. ];
  547. $schema = new SchemaWrapper($this->db);
  548. $isSqlite = $this->db->getDatabasePlatform() instanceof SqlitePlatform;
  549. $pendingColumns = [];
  550. foreach ($tables as $tableName => $columns) {
  551. if (!$schema->hasTable($tableName)) {
  552. continue;
  553. }
  554. $table = $schema->getTable($tableName);
  555. foreach ($columns as $columnName) {
  556. $column = $table->getColumn($columnName);
  557. $isAutoIncrement = $column->getAutoincrement();
  558. $isAutoIncrementOnSqlite = $isSqlite && $isAutoIncrement;
  559. if ($column->getType()->getName() !== Types::BIGINT && !$isAutoIncrementOnSqlite) {
  560. $pendingColumns[] = $tableName . '.' . $columnName;
  561. }
  562. }
  563. }
  564. return $pendingColumns;
  565. }
  566. protected function isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed(): bool {
  567. $objectStore = $this->config->getSystemValue('objectstore', null);
  568. $objectStoreMultibucket = $this->config->getSystemValue('objectstore_multibucket', null);
  569. if (!isset($objectStoreMultibucket) && !isset($objectStore)) {
  570. return true;
  571. }
  572. if (isset($objectStoreMultibucket['class']) && $objectStoreMultibucket['class'] !== 'OC\\Files\\ObjectStore\\S3') {
  573. return true;
  574. }
  575. if (isset($objectStore['class']) && $objectStore['class'] !== 'OC\\Files\\ObjectStore\\S3') {
  576. return true;
  577. }
  578. $tempPath = sys_get_temp_dir();
  579. if (!is_dir($tempPath)) {
  580. $this->logger->error('Error while checking the temporary PHP path - it was not properly set to a directory. value: ' . $tempPath);
  581. return false;
  582. }
  583. $freeSpaceInTemp = disk_free_space($tempPath);
  584. if ($freeSpaceInTemp === false) {
  585. $this->logger->error('Error while checking the available disk space of temporary PHP path - no free disk space returned. temporary path: ' . $tempPath);
  586. return false;
  587. }
  588. $freeSpaceInTempInGB = $freeSpaceInTemp / 1024 / 1024 / 1024;
  589. if ($freeSpaceInTempInGB > 50) {
  590. return true;
  591. }
  592. $this->logger->warning('Checking the available space in the temporary path resulted in ' . round($freeSpaceInTempInGB, 1) . ' GB instead of the recommended 50GB. Path: ' . $tempPath);
  593. return false;
  594. }
  595. /**
  596. * @return DataResponse
  597. */
  598. public function check() {
  599. $phpDefaultCharset = new PhpDefaultCharset();
  600. $phpOutputBuffering = new PhpOutputBuffering();
  601. $legacySSEKeyFormat = new LegacySSEKeyFormat($this->l10n, $this->config, $this->urlGenerator);
  602. return new DataResponse(
  603. [
  604. 'isGetenvServerWorking' => !empty(getenv('PATH')),
  605. 'isReadOnlyConfig' => $this->isReadOnlyConfig(),
  606. 'hasValidTransactionIsolationLevel' => $this->hasValidTransactionIsolationLevel(),
  607. 'hasFileinfoInstalled' => $this->hasFileinfoInstalled(),
  608. 'hasWorkingFileLocking' => $this->hasWorkingFileLocking(),
  609. 'suggestedOverwriteCliURL' => $this->getSuggestedOverwriteCliURL(),
  610. 'cronInfo' => $this->getLastCronInfo(),
  611. 'cronErrors' => $this->getCronErrors(),
  612. 'serverHasInternetConnectionProblems' => $this->hasInternetConnectivityProblems(),
  613. 'isMemcacheConfigured' => $this->isMemcacheConfigured(),
  614. 'memcacheDocs' => $this->urlGenerator->linkToDocs('admin-performance'),
  615. 'isRandomnessSecure' => $this->isRandomnessSecure(),
  616. 'securityDocs' => $this->urlGenerator->linkToDocs('admin-security'),
  617. 'isUsedTlsLibOutdated' => $this->isUsedTlsLibOutdated(),
  618. 'phpSupported' => $this->isPhpSupported(),
  619. 'forwardedForHeadersWorking' => $this->forwardedForHeadersWorking(),
  620. 'reverseProxyDocs' => $this->urlGenerator->linkToDocs('admin-reverse-proxy'),
  621. 'isCorrectMemcachedPHPModuleInstalled' => $this->isCorrectMemcachedPHPModuleInstalled(),
  622. 'hasPassedCodeIntegrityCheck' => $this->checker->hasPassedCheck(),
  623. 'codeIntegrityCheckerDocumentation' => $this->urlGenerator->linkToDocs('admin-code-integrity'),
  624. 'isOpcacheProperlySetup' => $this->isOpcacheProperlySetup(),
  625. 'hasOpcacheLoaded' => $this->hasOpcacheLoaded(),
  626. 'phpOpcacheDocumentation' => $this->urlGenerator->linkToDocs('admin-php-opcache'),
  627. 'isSettimelimitAvailable' => $this->isSettimelimitAvailable(),
  628. 'hasFreeTypeSupport' => $this->hasFreeTypeSupport(),
  629. 'missingIndexes' => $this->hasMissingIndexes(),
  630. 'missingColumns' => $this->hasMissingColumns(),
  631. 'isSqliteUsed' => $this->isSqliteUsed(),
  632. 'databaseConversionDocumentation' => $this->urlGenerator->linkToDocs('admin-db-conversion'),
  633. 'isPHPMailerUsed' => $this->isPHPMailerUsed(),
  634. 'mailSettingsDocumentation' => $this->urlGenerator->getAbsoluteURL('index.php/settings/admin'),
  635. 'isMemoryLimitSufficient' => $this->memoryInfo->isMemoryLimitSufficient(),
  636. 'appDirsWithDifferentOwner' => $this->getAppDirsWithDifferentOwner(),
  637. 'recommendedPHPModules' => $this->hasRecommendedPHPModules(),
  638. 'pendingBigIntConversionColumns' => $this->hasBigIntConversionPendingColumns(),
  639. 'isMysqlUsedWithoutUTF8MB4' => $this->isMysqlUsedWithoutUTF8MB4(),
  640. 'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' => $this->isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed(),
  641. 'reverseProxyGeneratedURL' => $this->urlGenerator->getAbsoluteURL('index.php'),
  642. PhpDefaultCharset::class => ['pass' => $phpDefaultCharset->run(), 'description' => $phpDefaultCharset->description(), 'severity' => $phpDefaultCharset->severity()],
  643. PhpOutputBuffering::class => ['pass' => $phpOutputBuffering->run(), 'description' => $phpOutputBuffering->description(), 'severity' => $phpOutputBuffering->severity()],
  644. LegacySSEKeyFormat::class => ['pass' => $legacySSEKeyFormat->run(), 'description' => $legacySSEKeyFormat->description(), 'severity' => $legacySSEKeyFormat->severity(), 'linkToDocumentation' => $legacySSEKeyFormat->linkToDocumentation()],
  645. ]
  646. );
  647. }
  648. }