Server.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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\IRequest;
  34. use OCP\Lock\ILockingProvider;
  35. use OCP\Settings\ISettings;
  36. class Server implements ISettings {
  37. /** @var IDBConnection|Connection */
  38. private $db;
  39. /** @var IRequest */
  40. private $request;
  41. /** @var IConfig */
  42. private $config;
  43. /** @var ILockingProvider */
  44. private $lockingProvider;
  45. /** @var IL10N */
  46. private $l;
  47. /**
  48. * @param IDBConnection $db
  49. * @param IRequest $request
  50. * @param IConfig $config
  51. * @param ILockingProvider $lockingProvider
  52. * @param IL10N $l
  53. */
  54. public function __construct(IDBConnection $db,
  55. IRequest $request,
  56. IConfig $config,
  57. ILockingProvider $lockingProvider,
  58. IL10N $l) {
  59. $this->db = $db;
  60. $this->request = $request;
  61. $this->config = $config;
  62. $this->lockingProvider = $lockingProvider;
  63. $this->l = $l;
  64. }
  65. /**
  66. * @return TemplateResponse
  67. */
  68. public function getForm() {
  69. try {
  70. if ($this->db->getDatabasePlatform() instanceof SqlitePlatform) {
  71. $invalidTransactionIsolationLevel = false;
  72. } else {
  73. $invalidTransactionIsolationLevel = $this->db->getTransactionIsolation() !== Connection::TRANSACTION_READ_COMMITTED;
  74. }
  75. } catch (DBALException $e) {
  76. // ignore
  77. $invalidTransactionIsolationLevel = false;
  78. }
  79. $envPath = getenv('PATH');
  80. // warn if outdated version of a memcache module is used
  81. $caches = [
  82. 'apcu' => ['name' => $this->l->t('APCu'), 'version' => '4.0.6'],
  83. 'redis' => ['name' => $this->l->t('Redis'), 'version' => '2.2.5'],
  84. ];
  85. $outdatedCaches = [];
  86. foreach ($caches as $php_module => $data) {
  87. $isOutdated = extension_loaded($php_module) && version_compare(phpversion($php_module), $data['version'], '<');
  88. if ($isOutdated) {
  89. $outdatedCaches[$php_module] = $data;
  90. }
  91. }
  92. if ($this->lockingProvider instanceof NoopLockingProvider) {
  93. $fileLockingType = 'none';
  94. } else if ($this->lockingProvider instanceof DBLockingProvider) {
  95. $fileLockingType = 'db';
  96. } else {
  97. $fileLockingType = 'cache';
  98. }
  99. $suggestedOverwriteCliUrl = '';
  100. if ($this->config->getSystemValue('overwrite.cli.url', '') === '') {
  101. $suggestedOverwriteCliUrl = $this->request->getServerProtocol() . '://' . $this->request->getInsecureServerHost() . \OC::$WEBROOT;
  102. if (!$this->config->getSystemValue('config_is_read_only', false)) {
  103. // Set the overwrite URL when it was not set yet.
  104. $this->config->setSystemValue('overwrite.cli.url', $suggestedOverwriteCliUrl);
  105. $suggestedOverwriteCliUrl = '';
  106. }
  107. }
  108. $parameters = [
  109. // Diagnosis
  110. 'readOnlyConfigEnabled' => \OC_Helper::isReadOnlyConfigEnabled(),
  111. 'isLocaleWorking' => \OC_Util::isSetLocaleWorking(),
  112. 'isAnnotationsWorking' => \OC_Util::isAnnotationsWorking(),
  113. 'checkForWorkingWellKnownSetup' => $this->config->getSystemValue('check_for_working_wellknown_setup', true),
  114. 'has_fileinfo' => \OC_Util::fileInfoLoaded(),
  115. 'invalidTransactionIsolationLevel' => $invalidTransactionIsolationLevel,
  116. 'getenvServerNotWorking' => empty($envPath),
  117. 'OutdatedCacheWarning' => $outdatedCaches,
  118. 'fileLockingType' => $fileLockingType,
  119. 'suggestedOverwriteCliUrl' => $suggestedOverwriteCliUrl,
  120. // Background jobs
  121. 'backgroundjobs_mode' => $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax'),
  122. 'cron_log' => $this->config->getSystemValue('cron_log', true),
  123. 'lastcron' => $this->config->getAppValue('core', 'lastcron', false),
  124. 'cronErrors' => $this->config->getAppValue('core', 'cronErrors'),
  125. 'cli_based_cron_possible' => function_exists('posix_getpwuid'),
  126. 'cli_based_cron_user' => function_exists('posix_getpwuid') ? posix_getpwuid(fileowner(\OC::$configDir . 'config.php'))['name'] : '',
  127. ];
  128. return new TemplateResponse('settings', 'admin/server', $parameters, '');
  129. }
  130. /**
  131. * @return string the section ID, e.g. 'sharing'
  132. */
  133. public function getSection() {
  134. return 'server';
  135. }
  136. /**
  137. * @return int whether the form should be rather on the top or bottom of
  138. * the admin section. The forms are arranged in ascending order of the
  139. * priority values. It is required to return a value between 0 and 100.
  140. *
  141. * E.g.: 70
  142. */
  143. public function getPriority() {
  144. return 0;
  145. }
  146. }