Server.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace OC\Settings\Admin;
  24. use Doctrine\DBAL\Connection;
  25. use Doctrine\DBAL\DBALException;
  26. use Doctrine\DBAL\Platforms\SqlitePlatform;
  27. use OC\Lock\DBLockingProvider;
  28. use OC\Lock\NoopLockingProvider;
  29. use OCP\AppFramework\Http\TemplateResponse;
  30. use OCP\IConfig;
  31. use OCP\IDBConnection;
  32. use OCP\IL10N;
  33. use OCP\Lock\ILockingProvider;
  34. use OCP\Settings\ISettings;
  35. class Server implements ISettings {
  36. /** @var IDBConnection|Connection */
  37. private $db;
  38. /** @var IConfig */
  39. private $config;
  40. /** @var ILockingProvider */
  41. private $lockingProvider;
  42. /** @var IL10N */
  43. private $l;
  44. /**
  45. * @param IDBConnection $db
  46. * @param IConfig $config
  47. * @param ILockingProvider $lockingProvider
  48. * @param IL10N $l
  49. */
  50. public function __construct(IDBConnection $db,
  51. IConfig $config,
  52. ILockingProvider $lockingProvider,
  53. IL10N $l) {
  54. $this->db = $db;
  55. $this->config = $config;
  56. $this->lockingProvider = $lockingProvider;
  57. $this->l = $l;
  58. }
  59. /**
  60. * @return TemplateResponse
  61. */
  62. public function getForm() {
  63. try {
  64. if ($this->db->getDatabasePlatform() instanceof SqlitePlatform) {
  65. $invalidTransactionIsolationLevel = false;
  66. } else {
  67. $invalidTransactionIsolationLevel = $this->db->getTransactionIsolation() !== Connection::TRANSACTION_READ_COMMITTED;
  68. }
  69. } catch (DBALException $e) {
  70. // ignore
  71. $invalidTransactionIsolationLevel = false;
  72. }
  73. $envPath = getenv('PATH');
  74. // warn if outdated version of a memcache module is used
  75. $caches = [
  76. 'apcu' => ['name' => $this->l->t('APCu'), 'version' => '4.0.6'],
  77. 'redis' => ['name' => $this->l->t('Redis'), 'version' => '2.2.5'],
  78. ];
  79. $outdatedCaches = [];
  80. foreach ($caches as $php_module => $data) {
  81. $isOutdated = extension_loaded($php_module) && version_compare(phpversion($php_module), $data['version'], '<');
  82. if ($isOutdated) {
  83. $outdatedCaches[$php_module] = $data;
  84. }
  85. }
  86. if ($this->lockingProvider instanceof NoopLockingProvider) {
  87. $fileLockingType = 'none';
  88. } else if ($this->lockingProvider instanceof DBLockingProvider) {
  89. $fileLockingType = 'db';
  90. } else {
  91. $fileLockingType = 'cache';
  92. }
  93. // If the current web root is non-empty but the web root from the config is,
  94. // and system cron is used, the URL generator fails to build valid URLs.
  95. $shouldSuggestOverwriteCliUrl = $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'cron'
  96. && \OC::$WEBROOT && \OC::$WEBROOT !== '/'
  97. && !$this->config->getSystemValue('overwrite.cli.url', '');
  98. $suggestedOverwriteCliUrl = ($shouldSuggestOverwriteCliUrl) ? \OC::$WEBROOT : '';
  99. $parameters = [
  100. // Diagnosis
  101. 'readOnlyConfigEnabled' => \OC_Helper::isReadOnlyConfigEnabled(),
  102. 'isLocaleWorking' => \OC_Util::isSetLocaleWorking(),
  103. 'isAnnotationsWorking' => \OC_Util::isAnnotationsWorking(),
  104. 'checkForWorkingWellKnownSetup' => $this->config->getSystemValue('check_for_working_wellknown_setup', true),
  105. 'has_fileinfo' => \OC_Util::fileInfoLoaded(),
  106. 'invalidTransactionIsolationLevel' => $invalidTransactionIsolationLevel,
  107. 'getenvServerNotWorking' => empty($envPath),
  108. 'OutdatedCacheWarning' => $outdatedCaches,
  109. 'fileLockingType' => $fileLockingType,
  110. 'suggestedOverwriteCliUrl' => $suggestedOverwriteCliUrl,
  111. // Background jobs
  112. 'backgroundjobs_mode' => $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax'),
  113. 'cron_log' => $this->config->getSystemValue('cron_log', true),
  114. 'lastcron' => $this->config->getAppValue('core', 'lastcron', false),
  115. 'cronErrors' => $this->config->getAppValue('core', 'cronErrors'),
  116. 'cli_based_cron_possible' => function_exists('posix_getpwuid'),
  117. 'cli_based_cron_user' => function_exists('posix_getpwuid') ? posix_getpwuid(fileowner(\OC::$configDir . 'config.php'))['name'] : '',
  118. ];
  119. return new TemplateResponse('settings', 'admin/server', $parameters, '');
  120. }
  121. /**
  122. * @return string the section ID, e.g. 'sharing'
  123. */
  124. public function getSection() {
  125. return 'server';
  126. }
  127. /**
  128. * @return int whether the form should be rather on the top or bottom of
  129. * the admin section. The forms are arranged in ascending order of the
  130. * priority values. It is required to return a value between 0 and 100.
  131. *
  132. * E.g.: 70
  133. */
  134. public function getPriority() {
  135. return 0;
  136. }
  137. }