You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CheckSetupController.php 25KB

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