From 9c4aecb53956df33ef16c51f6a195320b1032d58 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Wed, 13 Jun 2018 11:45:49 +0200 Subject: Merge all setup checks into one controller * renamed hasMissingIndexes to missingIndexes Signed-off-by: Morris Jobke --- settings/Controller/CheckSetupController.php | 98 +++++++++++++++++++- settings/css/settings.scss | 4 - settings/templates/settings/admin/overview.php | 122 +------------------------ 3 files changed, 97 insertions(+), 127 deletions(-) (limited to 'settings') diff --git a/settings/Controller/CheckSetupController.php b/settings/Controller/CheckSetupController.php index b4619ee4bb0..f83d0966eda 100644 --- a/settings/Controller/CheckSetupController.php +++ b/settings/Controller/CheckSetupController.php @@ -31,21 +31,27 @@ namespace OC\Settings\Controller; use bantu\IniGetWrapper\IniGetWrapper; +use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Platforms\SqlitePlatform; use GuzzleHttp\Exception\ClientException; use OC\AppFramework\Http; +use OC\DB\Connection; use OC\DB\MissingIndexInformation; use OC\IntegrityCheck\Checker; +use OC\Lock\NoopLockingProvider; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\DataDisplayResponse; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\RedirectResponse; use OCP\Http\Client\IClientService; use OCP\IConfig; +use OCP\IDateTimeFormatter; use OCP\IDBConnection; use OCP\IL10N; use OCP\ILogger; use OCP\IRequest; use OCP\IURLGenerator; +use OCP\Lock\ILockingProvider; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\GenericEvent; @@ -69,6 +75,12 @@ class CheckSetupController extends Controller { private $logger; /** @var EventDispatcherInterface */ private $dispatcher; + /** @var IDBConnection|Connection */ + private $db; + /** @var ILockingProvider */ + private $lockingProvider; + /** @var IDateTimeFormatter */ + private $dateTimeFormatter; public function __construct($AppName, IRequest $request, @@ -79,7 +91,10 @@ class CheckSetupController extends Controller { IL10N $l10n, Checker $checker, ILogger $logger, - EventDispatcherInterface $dispatcher) { + EventDispatcherInterface $dispatcher, + IDBConnection $db, + ILockingProvider $lockingProvider, + IDateTimeFormatter $dateTimeFormatter) { parent::__construct($AppName, $request); $this->config = $config; $this->clientService = $clientService; @@ -89,6 +104,9 @@ class CheckSetupController extends Controller { $this->checker = $checker; $this->logger = $logger; $this->dispatcher = $dispatcher; + $this->db = $db; + $this->lockingProvider = $lockingProvider; + $this->dateTimeFormatter = $dateTimeFormatter; } /** @@ -424,16 +442,92 @@ Raw output return $indexInfo->getListOfMissingIndexes(); } + /** + * warn if outdated version of a memcache module is used + */ + protected function getOutdatedCaches(): array { + $caches = [ + 'apcu' => ['name' => 'APCu', 'version' => '4.0.6'], + 'redis' => ['name' => 'Redis', 'version' => '2.2.5'], + ]; + $outdatedCaches = []; + foreach ($caches as $php_module => $data) { + $isOutdated = extension_loaded($php_module) && version_compare(phpversion($php_module), $data['version'], '<'); + if ($isOutdated) { + $outdatedCaches[] = $data; + } + } + + return $outdatedCaches; + } + protected function isSqliteUsed() { return strpos($this->config->getSystemValue('dbtype'), 'sqlite') !== false; } + protected function isReadOnlyConfig(): bool { + return \OC_Helper::isReadOnlyConfigEnabled(); + } + + protected function hasValidTransactionIsolationLevel(): bool { + try { + if ($this->db->getDatabasePlatform() instanceof SqlitePlatform) { + return true; + } + + return $this->db->getTransactionIsolation() === Connection::TRANSACTION_READ_COMMITTED; + } catch (DBALException $e) { + // ignore + } + + return true; + } + + protected function hasFileinfoInstalled(): bool { + return \OC_Util::fileInfoLoaded(); + } + + protected function hasWorkingFileLocking(): bool { + return !($this->lockingProvider instanceof NoopLockingProvider); + } + + protected function getSuggestedOverwriteCliURL(): string { + $suggestedOverwriteCliUrl = ''; + if ($this->config->getSystemValue('overwrite.cli.url', '') === '') { + $suggestedOverwriteCliUrl = $this->request->getServerProtocol() . '://' . $this->request->getInsecureServerHost() . \OC::$WEBROOT; + if (!$this->config->getSystemValue('config_is_read_only', false)) { + // Set the overwrite URL when it was not set yet. + $this->config->setSystemValue('overwrite.cli.url', $suggestedOverwriteCliUrl); + $suggestedOverwriteCliUrl = ''; + } + } + return $suggestedOverwriteCliUrl; + } + + protected function getLastCronInfo(): array { + $lastCronRun = $this->config->getAppValue('core', 'lastcron', 0); + return [ + 'diffInSeconds' => time() - $lastCronRun, + 'relativeTime' => $this->dateTimeFormatter->formatTimeSpan($lastCronRun), + 'backgroundJobsUrl' => $this->urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => 'server']) . '#backgroundjobs', + ]; + } + /** * @return DataResponse */ public function check() { return new DataResponse( [ + 'isGetenvServerWorking' => !empty(getenv('PATH')), + 'isReadOnlyConfig' => $this->isReadOnlyConfig(), + 'hasValidTransactionIsolationLevel' => $this->hasValidTransactionIsolationLevel(), + 'outdatedCaches' => $this->getOutdatedCaches(), + 'hasFileinfoInstalled' => $this->hasFileinfoInstalled(), + 'hasWorkingFileLocking' => $this->hasWorkingFileLocking(), + 'suggestedOverwriteCliURL' => $this->getSuggestedOverwriteCliURL(), + 'cronInfo' => $this->getLastCronInfo(), + 'cronErrors' => json_decode($this->config->getAppValue('core', 'cronErrors', ''), true), 'serverHasInternetConnection' => $this->isInternetConnectionWorking(), 'isMemcacheConfigured' => $this->isMemcacheConfigured(), 'memcacheDocs' => $this->urlGenerator->linkToDocs('admin-performance'), @@ -450,7 +544,7 @@ Raw output 'phpOpcacheDocumentation' => $this->urlGenerator->linkToDocs('admin-php-opcache'), 'isSettimelimitAvailable' => $this->isSettimelimitAvailable(), 'hasFreeTypeSupport' => $this->hasFreeTypeSupport(), - 'hasMissingIndexes' => $this->hasMissingIndexes(), + 'missingIndexes' => $this->hasMissingIndexes(), 'isSqliteUsed' => $this->isSqliteUsed(), 'databaseConversionDocumentation' => $this->urlGenerator->linkToDocs('admin-db-conversion'), ] diff --git a/settings/css/settings.scss b/settings/css/settings.scss index 5c1714021fb..a6f93a3e95d 100644 --- a/settings/css/settings.scss +++ b/settings/css/settings.scss @@ -1319,10 +1319,6 @@ doesnotexist:-o-prefocus, .strengthify-wrapper { text-decoration: underline; } - & > ul { - color: $color-error; - } - .extra-top-margin { margin-top: 12px; } diff --git a/settings/templates/settings/admin/overview.php b/settings/templates/settings/admin/overview.php index 5fb5e110eb1..cf725d3101e 100644 --- a/settings/templates/settings/admin/overview.php +++ b/settings/templates/settings/admin/overview.php @@ -23,133 +23,13 @@ /** @var \OCP\IL10N $l */ /** @var array $_ */ +/** @var \OCP\Defaults $theme */ ?>

t('Security & setup warnings'));?>

t('It\'s important for the security and performance of your instance that everything is configured correctly. To help you with that we are doing some automatic checks. Please see the linked documentation for more information.'));?>

-
    - -
  • - t('PHP does not seem to be setup properly to query system environment variables. The test with getenv("PATH") only returns an empty response.')); ?>
    - t('Please check the installation documentation ↗ for PHP configuration notes and the PHP configuration of your server, especially when using php-fpm.', link_to_docs('admin-php-fpm'))); ?> -
  • - -
  • - t('The Read-Only config has been enabled. This prevents setting some configurations via the web-interface. Furthermore, the file needs to be made writable manually for every update.')); ?> -
  • - -
  • - t('PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.')); ?>
    - t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.')); ?> -
  • - -
  • - t('Your database does not run with "READ COMMITTED" transaction isolation level. This can cause problems when multiple actions are executed in parallel.')); ?> -
  • - $data) { - ?> -
  • - t('%1$s below version %2$s is installed, for stability and performance reasons it is recommended to update to a newer %1$s version.', $data)); ?> -
  • - -
  • - t('The PHP module \'fileinfo\' is missing. It is strongly recommended to enable this module to get the best results with MIME type detection.')); ?> -
  • - -
  • - t('Transactional file locking is disabled, this might lead to issues with race conditions. Enable \'filelocking.enabled\' in config.php to avoid these problems. See the documentation ↗ for more information.', link_to_docs('admin-transactional-locking'))); ?> -
  • - -
  • - t('System locale can not be set to a one which supports UTF-8.')); - ?> -
    - t('This means that there might be problems with certain characters in filenames.')); - ?> -
    - t('It is strongly proposed to install the required packages on your system to support one of the following locales: %s.', [$locales])); - ?> -
  • - -
  • - t('If your installation is not installed at the root of the domain and uses system Cron, there can be issues with the URL generation. To avoid these problems, please set the "overwrite.cli.url" option in your config.php file to the webroot path of your installation (Suggested: "%s")', $_['suggestedOverwriteCliUrl'])); ?> -
  • - -
  • - t('It was not possible to execute the cron job via CLI. The following technical errors have appeared:')); ?> -
    -
      - error)) {?> -
    1. error) ?> hint) ?>
    2. - -
    -
  • - - getDateTimeFormatter(); - $absolute_time = $formatter->formatDateTime($_['lastcron'], 'long', 'long'); - if (time() - $_['lastcron'] > 3600): ?> -
  • - t("Last background job execution ran %s. Something seems wrong.", [$relative_time]));?> - t('Check the background job settings')); ?> -
  • - - -