checksetupcontroller.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php
  2. /**
  3. * @author Joas Schilling <nickvergessen@owncloud.com>
  4. * @author Lukas Reschke <lukas@owncloud.com>
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. *
  7. * @copyright Copyright (c) 2015, ownCloud, Inc.
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  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, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OC\Settings\Controller;
  24. use GuzzleHttp\Exception\ClientException;
  25. use OCP\AppFramework\Controller;
  26. use OCP\AppFramework\Http\DataResponse;
  27. use OCP\Http\Client\IClientService;
  28. use OCP\IConfig;
  29. use OCP\IL10N;
  30. use OCP\IRequest;
  31. use OC_Util;
  32. use OCP\IURLGenerator;
  33. /**
  34. * @package OC\Settings\Controller
  35. */
  36. class CheckSetupController extends Controller {
  37. /** @var IConfig */
  38. private $config;
  39. /** @var IClientService */
  40. private $clientService;
  41. /** @var \OC_Util */
  42. private $util;
  43. /** @var IURLGenerator */
  44. private $urlGenerator;
  45. /** @var IL10N */
  46. private $l10n;
  47. /**
  48. * @param string $AppName
  49. * @param IRequest $request
  50. * @param IConfig $config
  51. * @param IClientService $clientService
  52. * @param IURLGenerator $urlGenerator
  53. * @param \OC_Util $util
  54. * @param IL10N $l10n
  55. */
  56. public function __construct($AppName,
  57. IRequest $request,
  58. IConfig $config,
  59. IClientService $clientService,
  60. IURLGenerator $urlGenerator,
  61. \OC_Util $util,
  62. IL10N $l10n) {
  63. parent::__construct($AppName, $request);
  64. $this->config = $config;
  65. $this->clientService = $clientService;
  66. $this->util = $util;
  67. $this->urlGenerator = $urlGenerator;
  68. $this->l10n = $l10n;
  69. }
  70. /**
  71. * Checks if the ownCloud server can connect to the internet using HTTPS and HTTP
  72. * @return bool
  73. */
  74. private function isInternetConnectionWorking() {
  75. if ($this->config->getSystemValue('has_internet_connection', true) === false) {
  76. return false;
  77. }
  78. try {
  79. $client = $this->clientService->newClient();
  80. $client->get('https://www.owncloud.org/');
  81. $client->get('http://www.owncloud.org/');
  82. return true;
  83. } catch (\Exception $e) {
  84. return false;
  85. }
  86. }
  87. /**
  88. * Checks whether a local memcache is installed or not
  89. * @return bool
  90. */
  91. private function isMemcacheConfigured() {
  92. return $this->config->getSystemValue('memcache.local', null) !== null;
  93. }
  94. /**
  95. * Whether /dev/urandom is available to the PHP controller
  96. *
  97. * @return bool
  98. */
  99. private function isUrandomAvailable() {
  100. if(@file_exists('/dev/urandom')) {
  101. $file = fopen('/dev/urandom', 'rb');
  102. if($file) {
  103. fclose($file);
  104. return true;
  105. }
  106. }
  107. return false;
  108. }
  109. /**
  110. * Public for the sake of unit-testing
  111. *
  112. * @return array
  113. */
  114. public function getCurlVersion() {
  115. return curl_version();
  116. }
  117. /**
  118. * Check if the used SSL lib is outdated. Older OpenSSL and NSS versions do
  119. * have multiple bugs which likely lead to problems in combination with
  120. * functionality required by ownCloud such as SNI.
  121. *
  122. * @link https://github.com/owncloud/core/issues/17446#issuecomment-122877546
  123. * @link https://bugzilla.redhat.com/show_bug.cgi?id=1241172
  124. * @return string
  125. */
  126. private function isUsedTlsLibOutdated() {
  127. $versionString = $this->getCurlVersion();
  128. if(isset($versionString['ssl_version'])) {
  129. $versionString = $versionString['ssl_version'];
  130. } else {
  131. return '';
  132. }
  133. $features = (string)$this->l10n->t('installing and updating apps via the app store or Federated Cloud Sharing');
  134. if(OC_Util::getEditionString() !== '') {
  135. $features = (string)$this->l10n->t('Federated Cloud Sharing');
  136. }
  137. // Check if at least OpenSSL after 1.01d or 1.0.2b
  138. if(strpos($versionString, 'OpenSSL/') === 0) {
  139. $majorVersion = substr($versionString, 8, 5);
  140. $patchRelease = substr($versionString, 13, 6);
  141. if(($majorVersion === '1.0.1' && ord($patchRelease) < ord('d')) ||
  142. ($majorVersion === '1.0.2' && ord($patchRelease) < ord('b'))) {
  143. return (string) $this->l10n->t('cURL is using an outdated %s version (%s). Please update your operating system or features such as %s will not work reliably.', ['OpenSSL', $versionString, $features]);
  144. }
  145. }
  146. // Check if NSS and perform heuristic check
  147. if(strpos($versionString, 'NSS/') === 0) {
  148. try {
  149. $firstClient = $this->clientService->newClient();
  150. $firstClient->get('https://www.owncloud.org/');
  151. $secondClient = $this->clientService->newClient();
  152. $secondClient->get('https://owncloud.org/');
  153. } catch (ClientException $e) {
  154. if($e->getResponse()->getStatusCode() === 400) {
  155. return (string) $this->l10n->t('cURL is using an outdated %s version (%s). Please update your operating system or features such as %s will not work reliably.', ['NSS', $versionString, $features]);
  156. }
  157. }
  158. }
  159. return '';
  160. }
  161. /*
  162. * Whether the php version is still supported (at time of release)
  163. * according to: https://secure.php.net/supported-versions.php
  164. *
  165. * @return array
  166. */
  167. private function isPhpSupported() {
  168. $eol = false;
  169. //PHP 5.4 is EOL on 14 Sep 2015
  170. if (version_compare(PHP_VERSION, '5.5.0') === -1) {
  171. $eol = true;
  172. }
  173. return ['eol' => $eol, 'version' => PHP_VERSION];
  174. }
  175. /*
  176. * Check if the reverse proxy configuration is working as expected
  177. *
  178. * @return bool
  179. */
  180. private function forwardedForHeadersWorking() {
  181. $trustedProxies = $this->config->getSystemValue('trusted_proxies', []);
  182. $remoteAddress = $this->request->getRemoteAddress();
  183. if (is_array($trustedProxies) && in_array($remoteAddress, $trustedProxies)) {
  184. return false;
  185. }
  186. // either not enabled or working correctly
  187. return true;
  188. }
  189. /**
  190. * @return DataResponse
  191. */
  192. public function check() {
  193. return new DataResponse(
  194. [
  195. 'serverHasInternetConnection' => $this->isInternetConnectionWorking(),
  196. 'dataDirectoryProtected' => $this->util->isHtaccessWorking($this->config),
  197. 'isMemcacheConfigured' => $this->isMemcacheConfigured(),
  198. 'memcacheDocs' => $this->urlGenerator->linkToDocs('admin-performance'),
  199. 'isUrandomAvailable' => $this->isUrandomAvailable(),
  200. 'securityDocs' => $this->urlGenerator->linkToDocs('admin-security'),
  201. 'isUsedTlsLibOutdated' => $this->isUsedTlsLibOutdated(),
  202. 'phpSupported' => $this->isPhpSupported(),
  203. 'forwardedForHeadersWorking' => $this->forwardedForHeadersWorking(),
  204. 'reverseProxyDocs' => $this->urlGenerator->linkToDocs('admin-reverse-proxy'),
  205. ]
  206. );
  207. }
  208. }