Passed
Push — master ( 68d364...bd2e63 )
by Roeland
14:14 queued 11s
created
apps/settings/lib/Controller/CheckSetupController.php 1 patch
Indentation   +680 added lines, -680 removed lines patch added patch discarded remove patch
@@ -82,304 +82,304 @@  discard block
 block discarded – undo
82 82
 use Symfony\Component\EventDispatcher\GenericEvent;
83 83
 
84 84
 class CheckSetupController extends Controller {
85
-	/** @var IConfig */
86
-	private $config;
87
-	/** @var IClientService */
88
-	private $clientService;
89
-	/** @var IURLGenerator */
90
-	private $urlGenerator;
91
-	/** @var IL10N */
92
-	private $l10n;
93
-	/** @var Checker */
94
-	private $checker;
95
-	/** @var LoggerInterface */
96
-	private $logger;
97
-	/** @var EventDispatcherInterface */
98
-	private $dispatcher;
99
-	/** @var Connection */
100
-	private $db;
101
-	/** @var ILockingProvider */
102
-	private $lockingProvider;
103
-	/** @var IDateTimeFormatter */
104
-	private $dateTimeFormatter;
105
-	/** @var MemoryInfo */
106
-	private $memoryInfo;
107
-	/** @var ISecureRandom */
108
-	private $secureRandom;
109
-	/** @var IniGetWrapper */
110
-	private $iniGetWrapper;
111
-	/** @var IDBConnection */
112
-	private $connection;
113
-
114
-	public function __construct($AppName,
115
-								IRequest $request,
116
-								IConfig $config,
117
-								IClientService $clientService,
118
-								IURLGenerator $urlGenerator,
119
-								IL10N $l10n,
120
-								Checker $checker,
121
-								LoggerInterface $logger,
122
-								EventDispatcherInterface $dispatcher,
123
-								Connection $db,
124
-								ILockingProvider $lockingProvider,
125
-								IDateTimeFormatter $dateTimeFormatter,
126
-								MemoryInfo $memoryInfo,
127
-								ISecureRandom $secureRandom,
128
-								IniGetWrapper $iniGetWrapper,
129
-								IDBConnection $connection) {
130
-		parent::__construct($AppName, $request);
131
-		$this->config = $config;
132
-		$this->clientService = $clientService;
133
-		$this->urlGenerator = $urlGenerator;
134
-		$this->l10n = $l10n;
135
-		$this->checker = $checker;
136
-		$this->logger = $logger;
137
-		$this->dispatcher = $dispatcher;
138
-		$this->db = $db;
139
-		$this->lockingProvider = $lockingProvider;
140
-		$this->dateTimeFormatter = $dateTimeFormatter;
141
-		$this->memoryInfo = $memoryInfo;
142
-		$this->secureRandom = $secureRandom;
143
-		$this->iniGetWrapper = $iniGetWrapper;
144
-		$this->connection = $connection;
145
-	}
146
-
147
-	/**
148
-	 * Checks if the server can connect to the internet using HTTPS and HTTP
149
-	 * @return bool
150
-	 */
151
-	private function hasInternetConnectivityProblems(): bool {
152
-		if ($this->config->getSystemValue('has_internet_connection', true) === false) {
153
-			return false;
154
-		}
155
-
156
-		$siteArray = $this->config->getSystemValue('connectivity_check_domains', [
157
-			'www.nextcloud.com', 'www.startpage.com', 'www.eff.org', 'www.edri.org'
158
-		]);
159
-
160
-		foreach ($siteArray as $site) {
161
-			if ($this->isSiteReachable($site)) {
162
-				return false;
163
-			}
164
-		}
165
-		return true;
166
-	}
167
-
168
-	/**
169
-	 * Checks if the Nextcloud server can connect to a specific URL using both HTTPS and HTTP
170
-	 * @return bool
171
-	 */
172
-	private function isSiteReachable($sitename) {
173
-		$httpSiteName = 'http://' . $sitename . '/';
174
-		$httpsSiteName = 'https://' . $sitename . '/';
175
-
176
-		try {
177
-			$client = $this->clientService->newClient();
178
-			$client->get($httpSiteName);
179
-			$client->get($httpsSiteName);
180
-		} catch (\Exception $e) {
181
-			$this->logger->error('Cannot connect to: ' . $sitename, [
182
-				'app' => 'internet_connection_check',
183
-				'exception' => $e,
184
-			]);
185
-			return false;
186
-		}
187
-		return true;
188
-	}
189
-
190
-	/**
191
-	 * Checks whether a local memcache is installed or not
192
-	 * @return bool
193
-	 */
194
-	private function isMemcacheConfigured() {
195
-		return $this->config->getSystemValue('memcache.local', null) !== null;
196
-	}
197
-
198
-	/**
199
-	 * Whether PHP can generate "secure" pseudorandom integers
200
-	 *
201
-	 * @return bool
202
-	 */
203
-	private function isRandomnessSecure() {
204
-		try {
205
-			$this->secureRandom->generate(1);
206
-		} catch (\Exception $ex) {
207
-			return false;
208
-		}
209
-		return true;
210
-	}
211
-
212
-	/**
213
-	 * Public for the sake of unit-testing
214
-	 *
215
-	 * @return array
216
-	 */
217
-	protected function getCurlVersion() {
218
-		return curl_version();
219
-	}
220
-
221
-	/**
222
-	 * Check if the used  SSL lib is outdated. Older OpenSSL and NSS versions do
223
-	 * have multiple bugs which likely lead to problems in combination with
224
-	 * functionality required by ownCloud such as SNI.
225
-	 *
226
-	 * @link https://github.com/owncloud/core/issues/17446#issuecomment-122877546
227
-	 * @link https://bugzilla.redhat.com/show_bug.cgi?id=1241172
228
-	 * @return string
229
-	 */
230
-	private function isUsedTlsLibOutdated() {
231
-		// Don't run check when:
232
-		// 1. Server has `has_internet_connection` set to false
233
-		// 2. AppStore AND S2S is disabled
234
-		if (!$this->config->getSystemValue('has_internet_connection', true)) {
235
-			return '';
236
-		}
237
-		if (!$this->config->getSystemValue('appstoreenabled', true)
238
-			&& $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'no'
239
-			&& $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'no') {
240
-			return '';
241
-		}
242
-
243
-		$versionString = $this->getCurlVersion();
244
-		if (isset($versionString['ssl_version'])) {
245
-			$versionString = $versionString['ssl_version'];
246
-		} else {
247
-			return '';
248
-		}
249
-
250
-		$features = $this->l10n->t('installing and updating apps via the app store or Federated Cloud Sharing');
251
-		if (!$this->config->getSystemValue('appstoreenabled', true)) {
252
-			$features = $this->l10n->t('Federated Cloud Sharing');
253
-		}
254
-
255
-		// Check if at least OpenSSL after 1.01d or 1.0.2b
256
-		if (strpos($versionString, 'OpenSSL/') === 0) {
257
-			$majorVersion = substr($versionString, 8, 5);
258
-			$patchRelease = substr($versionString, 13, 6);
259
-
260
-			if (($majorVersion === '1.0.1' && ord($patchRelease) < ord('d')) ||
261
-				($majorVersion === '1.0.2' && ord($patchRelease) < ord('b'))) {
262
-				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]);
263
-			}
264
-		}
265
-
266
-		// Check if NSS and perform heuristic check
267
-		if (strpos($versionString, 'NSS/') === 0) {
268
-			try {
269
-				$firstClient = $this->clientService->newClient();
270
-				$firstClient->get('https://nextcloud.com/');
271
-
272
-				$secondClient = $this->clientService->newClient();
273
-				$secondClient->get('https://nextcloud.com/');
274
-			} catch (ClientException $e) {
275
-				if ($e->getResponse()->getStatusCode() === 400) {
276
-					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]);
277
-				}
278
-			} catch (\Exception $e) {
279
-				$this->logger->warning('error checking curl', [
280
-					'app' => 'settings',
281
-					'exception' => $e,
282
-				]);
283
-				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.');
284
-			}
285
-		}
286
-
287
-		return '';
288
-	}
289
-
290
-	/**
291
-	 * Whether the version is outdated
292
-	 *
293
-	 * @return bool
294
-	 */
295
-	protected function isPhpOutdated(): bool {
296
-		return PHP_VERSION_ID < 70300;
297
-	}
298
-
299
-	/**
300
-	 * Whether the php version is still supported (at time of release)
301
-	 * according to: https://www.php.net/supported-versions.php
302
-	 *
303
-	 * @return array
304
-	 */
305
-	private function isPhpSupported(): array {
306
-		return ['eol' => $this->isPhpOutdated(), 'version' => PHP_VERSION];
307
-	}
308
-
309
-	/**
310
-	 * Check if the reverse proxy configuration is working as expected
311
-	 *
312
-	 * @return bool
313
-	 */
314
-	private function forwardedForHeadersWorking() {
315
-		$trustedProxies = $this->config->getSystemValue('trusted_proxies', []);
316
-		$remoteAddress = $this->request->getHeader('REMOTE_ADDR');
317
-
318
-		if (empty($trustedProxies) && $this->request->getHeader('X-Forwarded-Host') !== '') {
319
-			return false;
320
-		}
321
-
322
-		if (\is_array($trustedProxies) && \in_array($remoteAddress, $trustedProxies, true) && $remoteAddress !== '127.0.0.1') {
323
-			return $remoteAddress !== $this->request->getRemoteAddress();
324
-		}
325
-
326
-		// either not enabled or working correctly
327
-		return true;
328
-	}
329
-
330
-	/**
331
-	 * Checks if the correct memcache module for PHP is installed. Only
332
-	 * fails if memcached is configured and the working module is not installed.
333
-	 *
334
-	 * @return bool
335
-	 */
336
-	private function isCorrectMemcachedPHPModuleInstalled() {
337
-		if ($this->config->getSystemValue('memcache.distributed', null) !== '\OC\Memcache\Memcached') {
338
-			return true;
339
-		}
340
-
341
-		// there are two different memcached modules for PHP
342
-		// we only support memcached and not memcache
343
-		// https://code.google.com/p/memcached/wiki/PHPClientComparison
344
-		return !(!extension_loaded('memcached') && extension_loaded('memcache'));
345
-	}
346
-
347
-	/**
348
-	 * Checks if set_time_limit is not disabled.
349
-	 *
350
-	 * @return bool
351
-	 */
352
-	private function isSettimelimitAvailable() {
353
-		if (function_exists('set_time_limit')
354
-			&& strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
355
-			return true;
356
-		}
357
-
358
-		return false;
359
-	}
360
-
361
-	/**
362
-	 * @return RedirectResponse
363
-	 */
364
-	public function rescanFailedIntegrityCheck() {
365
-		$this->checker->runInstanceVerification();
366
-		return new RedirectResponse(
367
-			$this->urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => 'overview'])
368
-		);
369
-	}
370
-
371
-	/**
372
-	 * @NoCSRFRequired
373
-	 */
374
-	public function getFailedIntegrityCheckFiles(): DataDisplayResponse {
375
-		if (!$this->checker->isCodeCheckEnforced()) {
376
-			return new DataDisplayResponse('Integrity checker has been disabled. Integrity cannot be verified.');
377
-		}
378
-
379
-		$completeResults = $this->checker->getResults();
380
-
381
-		if (!empty($completeResults)) {
382
-			$formattedTextResponse = 'Technical information
85
+    /** @var IConfig */
86
+    private $config;
87
+    /** @var IClientService */
88
+    private $clientService;
89
+    /** @var IURLGenerator */
90
+    private $urlGenerator;
91
+    /** @var IL10N */
92
+    private $l10n;
93
+    /** @var Checker */
94
+    private $checker;
95
+    /** @var LoggerInterface */
96
+    private $logger;
97
+    /** @var EventDispatcherInterface */
98
+    private $dispatcher;
99
+    /** @var Connection */
100
+    private $db;
101
+    /** @var ILockingProvider */
102
+    private $lockingProvider;
103
+    /** @var IDateTimeFormatter */
104
+    private $dateTimeFormatter;
105
+    /** @var MemoryInfo */
106
+    private $memoryInfo;
107
+    /** @var ISecureRandom */
108
+    private $secureRandom;
109
+    /** @var IniGetWrapper */
110
+    private $iniGetWrapper;
111
+    /** @var IDBConnection */
112
+    private $connection;
113
+
114
+    public function __construct($AppName,
115
+                                IRequest $request,
116
+                                IConfig $config,
117
+                                IClientService $clientService,
118
+                                IURLGenerator $urlGenerator,
119
+                                IL10N $l10n,
120
+                                Checker $checker,
121
+                                LoggerInterface $logger,
122
+                                EventDispatcherInterface $dispatcher,
123
+                                Connection $db,
124
+                                ILockingProvider $lockingProvider,
125
+                                IDateTimeFormatter $dateTimeFormatter,
126
+                                MemoryInfo $memoryInfo,
127
+                                ISecureRandom $secureRandom,
128
+                                IniGetWrapper $iniGetWrapper,
129
+                                IDBConnection $connection) {
130
+        parent::__construct($AppName, $request);
131
+        $this->config = $config;
132
+        $this->clientService = $clientService;
133
+        $this->urlGenerator = $urlGenerator;
134
+        $this->l10n = $l10n;
135
+        $this->checker = $checker;
136
+        $this->logger = $logger;
137
+        $this->dispatcher = $dispatcher;
138
+        $this->db = $db;
139
+        $this->lockingProvider = $lockingProvider;
140
+        $this->dateTimeFormatter = $dateTimeFormatter;
141
+        $this->memoryInfo = $memoryInfo;
142
+        $this->secureRandom = $secureRandom;
143
+        $this->iniGetWrapper = $iniGetWrapper;
144
+        $this->connection = $connection;
145
+    }
146
+
147
+    /**
148
+     * Checks if the server can connect to the internet using HTTPS and HTTP
149
+     * @return bool
150
+     */
151
+    private function hasInternetConnectivityProblems(): bool {
152
+        if ($this->config->getSystemValue('has_internet_connection', true) === false) {
153
+            return false;
154
+        }
155
+
156
+        $siteArray = $this->config->getSystemValue('connectivity_check_domains', [
157
+            'www.nextcloud.com', 'www.startpage.com', 'www.eff.org', 'www.edri.org'
158
+        ]);
159
+
160
+        foreach ($siteArray as $site) {
161
+            if ($this->isSiteReachable($site)) {
162
+                return false;
163
+            }
164
+        }
165
+        return true;
166
+    }
167
+
168
+    /**
169
+     * Checks if the Nextcloud server can connect to a specific URL using both HTTPS and HTTP
170
+     * @return bool
171
+     */
172
+    private function isSiteReachable($sitename) {
173
+        $httpSiteName = 'http://' . $sitename . '/';
174
+        $httpsSiteName = 'https://' . $sitename . '/';
175
+
176
+        try {
177
+            $client = $this->clientService->newClient();
178
+            $client->get($httpSiteName);
179
+            $client->get($httpsSiteName);
180
+        } catch (\Exception $e) {
181
+            $this->logger->error('Cannot connect to: ' . $sitename, [
182
+                'app' => 'internet_connection_check',
183
+                'exception' => $e,
184
+            ]);
185
+            return false;
186
+        }
187
+        return true;
188
+    }
189
+
190
+    /**
191
+     * Checks whether a local memcache is installed or not
192
+     * @return bool
193
+     */
194
+    private function isMemcacheConfigured() {
195
+        return $this->config->getSystemValue('memcache.local', null) !== null;
196
+    }
197
+
198
+    /**
199
+     * Whether PHP can generate "secure" pseudorandom integers
200
+     *
201
+     * @return bool
202
+     */
203
+    private function isRandomnessSecure() {
204
+        try {
205
+            $this->secureRandom->generate(1);
206
+        } catch (\Exception $ex) {
207
+            return false;
208
+        }
209
+        return true;
210
+    }
211
+
212
+    /**
213
+     * Public for the sake of unit-testing
214
+     *
215
+     * @return array
216
+     */
217
+    protected function getCurlVersion() {
218
+        return curl_version();
219
+    }
220
+
221
+    /**
222
+     * Check if the used  SSL lib is outdated. Older OpenSSL and NSS versions do
223
+     * have multiple bugs which likely lead to problems in combination with
224
+     * functionality required by ownCloud such as SNI.
225
+     *
226
+     * @link https://github.com/owncloud/core/issues/17446#issuecomment-122877546
227
+     * @link https://bugzilla.redhat.com/show_bug.cgi?id=1241172
228
+     * @return string
229
+     */
230
+    private function isUsedTlsLibOutdated() {
231
+        // Don't run check when:
232
+        // 1. Server has `has_internet_connection` set to false
233
+        // 2. AppStore AND S2S is disabled
234
+        if (!$this->config->getSystemValue('has_internet_connection', true)) {
235
+            return '';
236
+        }
237
+        if (!$this->config->getSystemValue('appstoreenabled', true)
238
+            && $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'no'
239
+            && $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'no') {
240
+            return '';
241
+        }
242
+
243
+        $versionString = $this->getCurlVersion();
244
+        if (isset($versionString['ssl_version'])) {
245
+            $versionString = $versionString['ssl_version'];
246
+        } else {
247
+            return '';
248
+        }
249
+
250
+        $features = $this->l10n->t('installing and updating apps via the app store or Federated Cloud Sharing');
251
+        if (!$this->config->getSystemValue('appstoreenabled', true)) {
252
+            $features = $this->l10n->t('Federated Cloud Sharing');
253
+        }
254
+
255
+        // Check if at least OpenSSL after 1.01d or 1.0.2b
256
+        if (strpos($versionString, 'OpenSSL/') === 0) {
257
+            $majorVersion = substr($versionString, 8, 5);
258
+            $patchRelease = substr($versionString, 13, 6);
259
+
260
+            if (($majorVersion === '1.0.1' && ord($patchRelease) < ord('d')) ||
261
+                ($majorVersion === '1.0.2' && ord($patchRelease) < ord('b'))) {
262
+                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]);
263
+            }
264
+        }
265
+
266
+        // Check if NSS and perform heuristic check
267
+        if (strpos($versionString, 'NSS/') === 0) {
268
+            try {
269
+                $firstClient = $this->clientService->newClient();
270
+                $firstClient->get('https://nextcloud.com/');
271
+
272
+                $secondClient = $this->clientService->newClient();
273
+                $secondClient->get('https://nextcloud.com/');
274
+            } catch (ClientException $e) {
275
+                if ($e->getResponse()->getStatusCode() === 400) {
276
+                    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]);
277
+                }
278
+            } catch (\Exception $e) {
279
+                $this->logger->warning('error checking curl', [
280
+                    'app' => 'settings',
281
+                    'exception' => $e,
282
+                ]);
283
+                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.');
284
+            }
285
+        }
286
+
287
+        return '';
288
+    }
289
+
290
+    /**
291
+     * Whether the version is outdated
292
+     *
293
+     * @return bool
294
+     */
295
+    protected function isPhpOutdated(): bool {
296
+        return PHP_VERSION_ID < 70300;
297
+    }
298
+
299
+    /**
300
+     * Whether the php version is still supported (at time of release)
301
+     * according to: https://www.php.net/supported-versions.php
302
+     *
303
+     * @return array
304
+     */
305
+    private function isPhpSupported(): array {
306
+        return ['eol' => $this->isPhpOutdated(), 'version' => PHP_VERSION];
307
+    }
308
+
309
+    /**
310
+     * Check if the reverse proxy configuration is working as expected
311
+     *
312
+     * @return bool
313
+     */
314
+    private function forwardedForHeadersWorking() {
315
+        $trustedProxies = $this->config->getSystemValue('trusted_proxies', []);
316
+        $remoteAddress = $this->request->getHeader('REMOTE_ADDR');
317
+
318
+        if (empty($trustedProxies) && $this->request->getHeader('X-Forwarded-Host') !== '') {
319
+            return false;
320
+        }
321
+
322
+        if (\is_array($trustedProxies) && \in_array($remoteAddress, $trustedProxies, true) && $remoteAddress !== '127.0.0.1') {
323
+            return $remoteAddress !== $this->request->getRemoteAddress();
324
+        }
325
+
326
+        // either not enabled or working correctly
327
+        return true;
328
+    }
329
+
330
+    /**
331
+     * Checks if the correct memcache module for PHP is installed. Only
332
+     * fails if memcached is configured and the working module is not installed.
333
+     *
334
+     * @return bool
335
+     */
336
+    private function isCorrectMemcachedPHPModuleInstalled() {
337
+        if ($this->config->getSystemValue('memcache.distributed', null) !== '\OC\Memcache\Memcached') {
338
+            return true;
339
+        }
340
+
341
+        // there are two different memcached modules for PHP
342
+        // we only support memcached and not memcache
343
+        // https://code.google.com/p/memcached/wiki/PHPClientComparison
344
+        return !(!extension_loaded('memcached') && extension_loaded('memcache'));
345
+    }
346
+
347
+    /**
348
+     * Checks if set_time_limit is not disabled.
349
+     *
350
+     * @return bool
351
+     */
352
+    private function isSettimelimitAvailable() {
353
+        if (function_exists('set_time_limit')
354
+            && strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
355
+            return true;
356
+        }
357
+
358
+        return false;
359
+    }
360
+
361
+    /**
362
+     * @return RedirectResponse
363
+     */
364
+    public function rescanFailedIntegrityCheck() {
365
+        $this->checker->runInstanceVerification();
366
+        return new RedirectResponse(
367
+            $this->urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => 'overview'])
368
+        );
369
+    }
370
+
371
+    /**
372
+     * @NoCSRFRequired
373
+     */
374
+    public function getFailedIntegrityCheckFiles(): DataDisplayResponse {
375
+        if (!$this->checker->isCodeCheckEnforced()) {
376
+            return new DataDisplayResponse('Integrity checker has been disabled. Integrity cannot be verified.');
377
+        }
378
+
379
+        $completeResults = $this->checker->getResults();
380
+
381
+        if (!empty($completeResults)) {
382
+            $formattedTextResponse = 'Technical information
383 383
 =====================
384 384
 The following list covers which files have failed the integrity check. Please read
385 385
 the previous linked documentation to learn more about the errors and how to fix
@@ -388,389 +388,389 @@  discard block
 block discarded – undo
388 388
 Results
389 389
 =======
390 390
 ';
391
-			foreach ($completeResults as $context => $contextResult) {
392
-				$formattedTextResponse .= "- $context\n";
393
-
394
-				foreach ($contextResult as $category => $result) {
395
-					$formattedTextResponse .= "\t- $category\n";
396
-					if ($category !== 'EXCEPTION') {
397
-						foreach ($result as $key => $results) {
398
-							$formattedTextResponse .= "\t\t- $key\n";
399
-						}
400
-					} else {
401
-						foreach ($result as $key => $results) {
402
-							$formattedTextResponse .= "\t\t- $results\n";
403
-						}
404
-					}
405
-				}
406
-			}
407
-
408
-			$formattedTextResponse .= '
391
+            foreach ($completeResults as $context => $contextResult) {
392
+                $formattedTextResponse .= "- $context\n";
393
+
394
+                foreach ($contextResult as $category => $result) {
395
+                    $formattedTextResponse .= "\t- $category\n";
396
+                    if ($category !== 'EXCEPTION') {
397
+                        foreach ($result as $key => $results) {
398
+                            $formattedTextResponse .= "\t\t- $key\n";
399
+                        }
400
+                    } else {
401
+                        foreach ($result as $key => $results) {
402
+                            $formattedTextResponse .= "\t\t- $results\n";
403
+                        }
404
+                    }
405
+                }
406
+            }
407
+
408
+            $formattedTextResponse .= '
409 409
 Raw output
410 410
 ==========
411 411
 ';
412
-			$formattedTextResponse .= print_r($completeResults, true);
413
-		} else {
414
-			$formattedTextResponse = 'No errors have been found.';
415
-		}
416
-
417
-
418
-		return new DataDisplayResponse(
419
-			$formattedTextResponse,
420
-			Http::STATUS_OK,
421
-			[
422
-				'Content-Type' => 'text/plain',
423
-			]
424
-		);
425
-	}
426
-
427
-	/**
428
-	 * Checks whether a PHP opcache is properly set up
429
-	 * @return bool
430
-	 */
431
-	protected function isOpcacheProperlySetup() {
432
-		if (!$this->iniGetWrapper->getBool('opcache.enable')) {
433
-			return false;
434
-		}
435
-
436
-		if (!$this->iniGetWrapper->getBool('opcache.save_comments')) {
437
-			return false;
438
-		}
439
-
440
-		if ($this->iniGetWrapper->getNumeric('opcache.max_accelerated_files') < 10000) {
441
-			return false;
442
-		}
443
-
444
-		if ($this->iniGetWrapper->getNumeric('opcache.memory_consumption') < 128) {
445
-			return false;
446
-		}
447
-
448
-		if ($this->iniGetWrapper->getNumeric('opcache.interned_strings_buffer') < 8) {
449
-			return false;
450
-		}
451
-
452
-		return true;
453
-	}
454
-
455
-	/**
456
-	 * Check if the required FreeType functions are present
457
-	 * @return bool
458
-	 */
459
-	protected function hasFreeTypeSupport() {
460
-		return function_exists('imagettfbbox') && function_exists('imagettftext');
461
-	}
462
-
463
-	protected function hasMissingIndexes(): array {
464
-		$indexInfo = new MissingIndexInformation();
465
-		// Dispatch event so apps can also hint for pending index updates if needed
466
-		$event = new GenericEvent($indexInfo);
467
-		$this->dispatcher->dispatch(IDBConnection::CHECK_MISSING_INDEXES_EVENT, $event);
468
-
469
-		return $indexInfo->getListOfMissingIndexes();
470
-	}
471
-
472
-	protected function hasMissingPrimaryKeys(): array {
473
-		$info = new MissingPrimaryKeyInformation();
474
-		// Dispatch event so apps can also hint for pending index updates if needed
475
-		$event = new GenericEvent($info);
476
-		$this->dispatcher->dispatch(IDBConnection::CHECK_MISSING_PRIMARY_KEYS_EVENT, $event);
477
-
478
-		return $info->getListOfMissingPrimaryKeys();
479
-	}
480
-
481
-	protected function hasMissingColumns(): array {
482
-		$indexInfo = new MissingColumnInformation();
483
-		// Dispatch event so apps can also hint for pending index updates if needed
484
-		$event = new GenericEvent($indexInfo);
485
-		$this->dispatcher->dispatch(IDBConnection::CHECK_MISSING_COLUMNS_EVENT, $event);
486
-
487
-		return $indexInfo->getListOfMissingColumns();
488
-	}
489
-
490
-	protected function isSqliteUsed() {
491
-		return strpos($this->config->getSystemValue('dbtype'), 'sqlite') !== false;
492
-	}
493
-
494
-	protected function isReadOnlyConfig(): bool {
495
-		return \OC_Helper::isReadOnlyConfigEnabled();
496
-	}
497
-
498
-	protected function hasValidTransactionIsolationLevel(): bool {
499
-		try {
500
-			if ($this->db->getDatabasePlatform() instanceof SqlitePlatform) {
501
-				return true;
502
-			}
503
-
504
-			return $this->db->getTransactionIsolation() === TransactionIsolationLevel::READ_COMMITTED;
505
-		} catch (Exception $e) {
506
-			// ignore
507
-		}
508
-
509
-		return true;
510
-	}
511
-
512
-	protected function hasFileinfoInstalled(): bool {
513
-		return \OC_Util::fileInfoLoaded();
514
-	}
515
-
516
-	protected function hasWorkingFileLocking(): bool {
517
-		return !($this->lockingProvider instanceof NoopLockingProvider);
518
-	}
519
-
520
-	protected function getSuggestedOverwriteCliURL(): string {
521
-		$suggestedOverwriteCliUrl = '';
522
-		if ($this->config->getSystemValue('overwrite.cli.url', '') === '') {
523
-			$suggestedOverwriteCliUrl = $this->request->getServerProtocol() . '://' . $this->request->getInsecureServerHost() . \OC::$WEBROOT;
524
-			if (!$this->config->getSystemValue('config_is_read_only', false)) {
525
-				// Set the overwrite URL when it was not set yet.
526
-				$this->config->setSystemValue('overwrite.cli.url', $suggestedOverwriteCliUrl);
527
-				$suggestedOverwriteCliUrl = '';
528
-			}
529
-		}
530
-		return $suggestedOverwriteCliUrl;
531
-	}
532
-
533
-	protected function getLastCronInfo(): array {
534
-		$lastCronRun = $this->config->getAppValue('core', 'lastcron', 0);
535
-		return [
536
-			'diffInSeconds' => time() - $lastCronRun,
537
-			'relativeTime' => $this->dateTimeFormatter->formatTimeSpan($lastCronRun),
538
-			'backgroundJobsUrl' => $this->urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => 'server']) . '#backgroundjobs',
539
-		];
540
-	}
541
-
542
-	protected function getCronErrors() {
543
-		$errors = json_decode($this->config->getAppValue('core', 'cronErrors', ''), true);
544
-
545
-		if (is_array($errors)) {
546
-			return $errors;
547
-		}
548
-
549
-		return [];
550
-	}
551
-
552
-	protected function hasOpcacheLoaded(): bool {
553
-		return extension_loaded('Zend OPcache');
554
-	}
555
-
556
-	/**
557
-	 * Iterates through the configured app roots and
558
-	 * tests if the subdirectories are owned by the same user than the current user.
559
-	 *
560
-	 * @return array
561
-	 */
562
-	protected function getAppDirsWithDifferentOwner(): array {
563
-		$currentUser = posix_getuid();
564
-		$appDirsWithDifferentOwner = [[]];
565
-
566
-		foreach (OC::$APPSROOTS as $appRoot) {
567
-			if ($appRoot['writable'] === true) {
568
-				$appDirsWithDifferentOwner[] = $this->getAppDirsWithDifferentOwnerForAppRoot($currentUser, $appRoot);
569
-			}
570
-		}
571
-
572
-		$appDirsWithDifferentOwner = array_merge(...$appDirsWithDifferentOwner);
573
-		sort($appDirsWithDifferentOwner);
574
-
575
-		return $appDirsWithDifferentOwner;
576
-	}
577
-
578
-	/**
579
-	 * Tests if the directories for one apps directory are writable by the current user.
580
-	 *
581
-	 * @param int $currentUser The current user
582
-	 * @param array $appRoot The app root config
583
-	 * @return string[] The none writable directory paths inside the app root
584
-	 */
585
-	private function getAppDirsWithDifferentOwnerForAppRoot(int $currentUser, array $appRoot): array {
586
-		$appDirsWithDifferentOwner = [];
587
-		$appsPath = $appRoot['path'];
588
-		$appsDir = new DirectoryIterator($appRoot['path']);
589
-
590
-		foreach ($appsDir as $fileInfo) {
591
-			if ($fileInfo->isDir() && !$fileInfo->isDot()) {
592
-				$absAppPath = $appsPath . DIRECTORY_SEPARATOR . $fileInfo->getFilename();
593
-				$appDirUser = fileowner($absAppPath);
594
-				if ($appDirUser !== $currentUser) {
595
-					$appDirsWithDifferentOwner[] = $absAppPath;
596
-				}
597
-			}
598
-		}
599
-
600
-		return $appDirsWithDifferentOwner;
601
-	}
602
-
603
-	/**
604
-	 * Checks for potential PHP modules that would improve the instance
605
-	 *
606
-	 * @return string[] A list of PHP modules that is recommended
607
-	 */
608
-	protected function hasRecommendedPHPModules(): array {
609
-		$recommendedPHPModules = [];
610
-
611
-		if (!extension_loaded('intl')) {
612
-			$recommendedPHPModules[] = 'intl';
613
-		}
614
-
615
-		if (!extension_loaded('bcmath')) {
616
-			$recommendedPHPModules[] = 'bcmath';
617
-		}
618
-
619
-		if (!extension_loaded('gmp')) {
620
-			$recommendedPHPModules[] = 'gmp';
621
-		}
622
-
623
-		if ($this->config->getAppValue('theming', 'enabled', 'no') === 'yes') {
624
-			if (!extension_loaded('imagick')) {
625
-				$recommendedPHPModules[] = 'imagick';
626
-			}
627
-		}
628
-
629
-		return $recommendedPHPModules;
630
-	}
631
-
632
-	protected function isMysqlUsedWithoutUTF8MB4(): bool {
633
-		return ($this->config->getSystemValue('dbtype', 'sqlite') === 'mysql') && ($this->config->getSystemValue('mysql.utf8mb4', false) === false);
634
-	}
635
-
636
-	protected function hasBigIntConversionPendingColumns(): array {
637
-		// copy of ConvertFilecacheBigInt::getColumnsByTable()
638
-		$tables = [
639
-			'activity' => ['activity_id', 'object_id'],
640
-			'activity_mq' => ['mail_id'],
641
-			'authtoken' => ['id'],
642
-			'bruteforce_attempts' => ['id'],
643
-			'federated_reshares' => ['share_id'],
644
-			'filecache' => ['fileid', 'storage', 'parent', 'mimetype', 'mimepart', 'mtime', 'storage_mtime'],
645
-			'filecache_extended' => ['fileid'],
646
-			'file_locks' => ['id'],
647
-			'jobs' => ['id'],
648
-			'mimetypes' => ['id'],
649
-			'mounts' => ['id', 'storage_id', 'root_id', 'mount_id'],
650
-			'share_external' => ['id', 'parent'],
651
-			'storages' => ['numeric_id'],
652
-		];
653
-
654
-		$schema = new SchemaWrapper($this->db);
655
-		$isSqlite = $this->db->getDatabasePlatform() instanceof SqlitePlatform;
656
-		$pendingColumns = [];
657
-
658
-		foreach ($tables as $tableName => $columns) {
659
-			if (!$schema->hasTable($tableName)) {
660
-				continue;
661
-			}
662
-
663
-			$table = $schema->getTable($tableName);
664
-			foreach ($columns as $columnName) {
665
-				$column = $table->getColumn($columnName);
666
-				$isAutoIncrement = $column->getAutoincrement();
667
-				$isAutoIncrementOnSqlite = $isSqlite && $isAutoIncrement;
668
-				if ($column->getType()->getName() !== Types::BIGINT && !$isAutoIncrementOnSqlite) {
669
-					$pendingColumns[] = $tableName . '.' . $columnName;
670
-				}
671
-			}
672
-		}
673
-
674
-		return $pendingColumns;
675
-	}
676
-
677
-	protected function isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed(): bool {
678
-		$objectStore = $this->config->getSystemValue('objectstore', null);
679
-		$objectStoreMultibucket = $this->config->getSystemValue('objectstore_multibucket', null);
680
-
681
-		if (!isset($objectStoreMultibucket) && !isset($objectStore)) {
682
-			return true;
683
-		}
684
-
685
-		if (isset($objectStoreMultibucket['class']) && $objectStoreMultibucket['class'] !== 'OC\\Files\\ObjectStore\\S3') {
686
-			return true;
687
-		}
688
-
689
-		if (isset($objectStore['class']) && $objectStore['class'] !== 'OC\\Files\\ObjectStore\\S3') {
690
-			return true;
691
-		}
692
-
693
-		$tempPath = sys_get_temp_dir();
694
-		if (!is_dir($tempPath)) {
695
-			$this->logger->error('Error while checking the temporary PHP path - it was not properly set to a directory. value: ' . $tempPath);
696
-			return false;
697
-		}
698
-		$freeSpaceInTemp = disk_free_space($tempPath);
699
-		if ($freeSpaceInTemp === false) {
700
-			$this->logger->error('Error while checking the available disk space of temporary PHP path - no free disk space returned. temporary path: ' . $tempPath);
701
-			return false;
702
-		}
703
-
704
-		$freeSpaceInTempInGB = $freeSpaceInTemp / 1024 / 1024 / 1024;
705
-		if ($freeSpaceInTempInGB > 50) {
706
-			return true;
707
-		}
708
-
709
-		$this->logger->warning('Checking the available space in the temporary path resulted in ' . round($freeSpaceInTempInGB, 1) . ' GB instead of the recommended 50GB. Path: ' . $tempPath);
710
-		return false;
711
-	}
712
-
713
-	protected function imageMagickLacksSVGSupport(): bool {
714
-		return extension_loaded('imagick') && count(\Imagick::queryFormats('SVG')) === 0;
715
-	}
716
-
717
-	/**
718
-	 * @return DataResponse
719
-	 */
720
-	public function check() {
721
-		$phpDefaultCharset = new PhpDefaultCharset();
722
-		$phpOutputBuffering = new PhpOutputBuffering();
723
-		$legacySSEKeyFormat = new LegacySSEKeyFormat($this->l10n, $this->config, $this->urlGenerator);
724
-		$checkUserCertificates = new CheckUserCertificates($this->l10n, $this->config, $this->urlGenerator);
725
-		$supportedDatabases = new SupportedDatabase($this->l10n, $this->connection);
726
-
727
-		return new DataResponse(
728
-			[
729
-				'isGetenvServerWorking' => !empty(getenv('PATH')),
730
-				'isReadOnlyConfig' => $this->isReadOnlyConfig(),
731
-				'hasValidTransactionIsolationLevel' => $this->hasValidTransactionIsolationLevel(),
732
-				'hasFileinfoInstalled' => $this->hasFileinfoInstalled(),
733
-				'hasWorkingFileLocking' => $this->hasWorkingFileLocking(),
734
-				'suggestedOverwriteCliURL' => $this->getSuggestedOverwriteCliURL(),
735
-				'cronInfo' => $this->getLastCronInfo(),
736
-				'cronErrors' => $this->getCronErrors(),
737
-				'serverHasInternetConnectionProblems' => $this->hasInternetConnectivityProblems(),
738
-				'isMemcacheConfigured' => $this->isMemcacheConfigured(),
739
-				'memcacheDocs' => $this->urlGenerator->linkToDocs('admin-performance'),
740
-				'isRandomnessSecure' => $this->isRandomnessSecure(),
741
-				'securityDocs' => $this->urlGenerator->linkToDocs('admin-security'),
742
-				'isUsedTlsLibOutdated' => $this->isUsedTlsLibOutdated(),
743
-				'phpSupported' => $this->isPhpSupported(),
744
-				'forwardedForHeadersWorking' => $this->forwardedForHeadersWorking(),
745
-				'reverseProxyDocs' => $this->urlGenerator->linkToDocs('admin-reverse-proxy'),
746
-				'isCorrectMemcachedPHPModuleInstalled' => $this->isCorrectMemcachedPHPModuleInstalled(),
747
-				'hasPassedCodeIntegrityCheck' => $this->checker->hasPassedCheck(),
748
-				'codeIntegrityCheckerDocumentation' => $this->urlGenerator->linkToDocs('admin-code-integrity'),
749
-				'isOpcacheProperlySetup' => $this->isOpcacheProperlySetup(),
750
-				'hasOpcacheLoaded' => $this->hasOpcacheLoaded(),
751
-				'phpOpcacheDocumentation' => $this->urlGenerator->linkToDocs('admin-php-opcache'),
752
-				'isSettimelimitAvailable' => $this->isSettimelimitAvailable(),
753
-				'hasFreeTypeSupport' => $this->hasFreeTypeSupport(),
754
-				'missingPrimaryKeys' => $this->hasMissingPrimaryKeys(),
755
-				'missingIndexes' => $this->hasMissingIndexes(),
756
-				'missingColumns' => $this->hasMissingColumns(),
757
-				'isSqliteUsed' => $this->isSqliteUsed(),
758
-				'databaseConversionDocumentation' => $this->urlGenerator->linkToDocs('admin-db-conversion'),
759
-				'isMemoryLimitSufficient' => $this->memoryInfo->isMemoryLimitSufficient(),
760
-				'appDirsWithDifferentOwner' => $this->getAppDirsWithDifferentOwner(),
761
-				'recommendedPHPModules' => $this->hasRecommendedPHPModules(),
762
-				'pendingBigIntConversionColumns' => $this->hasBigIntConversionPendingColumns(),
763
-				'isMysqlUsedWithoutUTF8MB4' => $this->isMysqlUsedWithoutUTF8MB4(),
764
-				'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' => $this->isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed(),
765
-				'reverseProxyGeneratedURL' => $this->urlGenerator->getAbsoluteURL('index.php'),
766
-				'imageMagickLacksSVGSupport' => $this->imageMagickLacksSVGSupport(),
767
-				PhpDefaultCharset::class => ['pass' => $phpDefaultCharset->run(), 'description' => $phpDefaultCharset->description(), 'severity' => $phpDefaultCharset->severity()],
768
-				PhpOutputBuffering::class => ['pass' => $phpOutputBuffering->run(), 'description' => $phpOutputBuffering->description(), 'severity' => $phpOutputBuffering->severity()],
769
-				LegacySSEKeyFormat::class => ['pass' => $legacySSEKeyFormat->run(), 'description' => $legacySSEKeyFormat->description(), 'severity' => $legacySSEKeyFormat->severity(), 'linkToDocumentation' => $legacySSEKeyFormat->linkToDocumentation()],
770
-				CheckUserCertificates::class => ['pass' => $checkUserCertificates->run(), 'description' => $checkUserCertificates->description(), 'severity' => $checkUserCertificates->severity(), 'elements' => $checkUserCertificates->elements()],
771
-				'isDefaultPhoneRegionSet' => $this->config->getSystemValueString('default_phone_region', '') !== '',
772
-				SupportedDatabase::class => ['pass' => $supportedDatabases->run(), 'description' => $supportedDatabases->description(), 'severity' => $supportedDatabases->severity()],
773
-			]
774
-		);
775
-	}
412
+            $formattedTextResponse .= print_r($completeResults, true);
413
+        } else {
414
+            $formattedTextResponse = 'No errors have been found.';
415
+        }
416
+
417
+
418
+        return new DataDisplayResponse(
419
+            $formattedTextResponse,
420
+            Http::STATUS_OK,
421
+            [
422
+                'Content-Type' => 'text/plain',
423
+            ]
424
+        );
425
+    }
426
+
427
+    /**
428
+     * Checks whether a PHP opcache is properly set up
429
+     * @return bool
430
+     */
431
+    protected function isOpcacheProperlySetup() {
432
+        if (!$this->iniGetWrapper->getBool('opcache.enable')) {
433
+            return false;
434
+        }
435
+
436
+        if (!$this->iniGetWrapper->getBool('opcache.save_comments')) {
437
+            return false;
438
+        }
439
+
440
+        if ($this->iniGetWrapper->getNumeric('opcache.max_accelerated_files') < 10000) {
441
+            return false;
442
+        }
443
+
444
+        if ($this->iniGetWrapper->getNumeric('opcache.memory_consumption') < 128) {
445
+            return false;
446
+        }
447
+
448
+        if ($this->iniGetWrapper->getNumeric('opcache.interned_strings_buffer') < 8) {
449
+            return false;
450
+        }
451
+
452
+        return true;
453
+    }
454
+
455
+    /**
456
+     * Check if the required FreeType functions are present
457
+     * @return bool
458
+     */
459
+    protected function hasFreeTypeSupport() {
460
+        return function_exists('imagettfbbox') && function_exists('imagettftext');
461
+    }
462
+
463
+    protected function hasMissingIndexes(): array {
464
+        $indexInfo = new MissingIndexInformation();
465
+        // Dispatch event so apps can also hint for pending index updates if needed
466
+        $event = new GenericEvent($indexInfo);
467
+        $this->dispatcher->dispatch(IDBConnection::CHECK_MISSING_INDEXES_EVENT, $event);
468
+
469
+        return $indexInfo->getListOfMissingIndexes();
470
+    }
471
+
472
+    protected function hasMissingPrimaryKeys(): array {
473
+        $info = new MissingPrimaryKeyInformation();
474
+        // Dispatch event so apps can also hint for pending index updates if needed
475
+        $event = new GenericEvent($info);
476
+        $this->dispatcher->dispatch(IDBConnection::CHECK_MISSING_PRIMARY_KEYS_EVENT, $event);
477
+
478
+        return $info->getListOfMissingPrimaryKeys();
479
+    }
480
+
481
+    protected function hasMissingColumns(): array {
482
+        $indexInfo = new MissingColumnInformation();
483
+        // Dispatch event so apps can also hint for pending index updates if needed
484
+        $event = new GenericEvent($indexInfo);
485
+        $this->dispatcher->dispatch(IDBConnection::CHECK_MISSING_COLUMNS_EVENT, $event);
486
+
487
+        return $indexInfo->getListOfMissingColumns();
488
+    }
489
+
490
+    protected function isSqliteUsed() {
491
+        return strpos($this->config->getSystemValue('dbtype'), 'sqlite') !== false;
492
+    }
493
+
494
+    protected function isReadOnlyConfig(): bool {
495
+        return \OC_Helper::isReadOnlyConfigEnabled();
496
+    }
497
+
498
+    protected function hasValidTransactionIsolationLevel(): bool {
499
+        try {
500
+            if ($this->db->getDatabasePlatform() instanceof SqlitePlatform) {
501
+                return true;
502
+            }
503
+
504
+            return $this->db->getTransactionIsolation() === TransactionIsolationLevel::READ_COMMITTED;
505
+        } catch (Exception $e) {
506
+            // ignore
507
+        }
508
+
509
+        return true;
510
+    }
511
+
512
+    protected function hasFileinfoInstalled(): bool {
513
+        return \OC_Util::fileInfoLoaded();
514
+    }
515
+
516
+    protected function hasWorkingFileLocking(): bool {
517
+        return !($this->lockingProvider instanceof NoopLockingProvider);
518
+    }
519
+
520
+    protected function getSuggestedOverwriteCliURL(): string {
521
+        $suggestedOverwriteCliUrl = '';
522
+        if ($this->config->getSystemValue('overwrite.cli.url', '') === '') {
523
+            $suggestedOverwriteCliUrl = $this->request->getServerProtocol() . '://' . $this->request->getInsecureServerHost() . \OC::$WEBROOT;
524
+            if (!$this->config->getSystemValue('config_is_read_only', false)) {
525
+                // Set the overwrite URL when it was not set yet.
526
+                $this->config->setSystemValue('overwrite.cli.url', $suggestedOverwriteCliUrl);
527
+                $suggestedOverwriteCliUrl = '';
528
+            }
529
+        }
530
+        return $suggestedOverwriteCliUrl;
531
+    }
532
+
533
+    protected function getLastCronInfo(): array {
534
+        $lastCronRun = $this->config->getAppValue('core', 'lastcron', 0);
535
+        return [
536
+            'diffInSeconds' => time() - $lastCronRun,
537
+            'relativeTime' => $this->dateTimeFormatter->formatTimeSpan($lastCronRun),
538
+            'backgroundJobsUrl' => $this->urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => 'server']) . '#backgroundjobs',
539
+        ];
540
+    }
541
+
542
+    protected function getCronErrors() {
543
+        $errors = json_decode($this->config->getAppValue('core', 'cronErrors', ''), true);
544
+
545
+        if (is_array($errors)) {
546
+            return $errors;
547
+        }
548
+
549
+        return [];
550
+    }
551
+
552
+    protected function hasOpcacheLoaded(): bool {
553
+        return extension_loaded('Zend OPcache');
554
+    }
555
+
556
+    /**
557
+     * Iterates through the configured app roots and
558
+     * tests if the subdirectories are owned by the same user than the current user.
559
+     *
560
+     * @return array
561
+     */
562
+    protected function getAppDirsWithDifferentOwner(): array {
563
+        $currentUser = posix_getuid();
564
+        $appDirsWithDifferentOwner = [[]];
565
+
566
+        foreach (OC::$APPSROOTS as $appRoot) {
567
+            if ($appRoot['writable'] === true) {
568
+                $appDirsWithDifferentOwner[] = $this->getAppDirsWithDifferentOwnerForAppRoot($currentUser, $appRoot);
569
+            }
570
+        }
571
+
572
+        $appDirsWithDifferentOwner = array_merge(...$appDirsWithDifferentOwner);
573
+        sort($appDirsWithDifferentOwner);
574
+
575
+        return $appDirsWithDifferentOwner;
576
+    }
577
+
578
+    /**
579
+     * Tests if the directories for one apps directory are writable by the current user.
580
+     *
581
+     * @param int $currentUser The current user
582
+     * @param array $appRoot The app root config
583
+     * @return string[] The none writable directory paths inside the app root
584
+     */
585
+    private function getAppDirsWithDifferentOwnerForAppRoot(int $currentUser, array $appRoot): array {
586
+        $appDirsWithDifferentOwner = [];
587
+        $appsPath = $appRoot['path'];
588
+        $appsDir = new DirectoryIterator($appRoot['path']);
589
+
590
+        foreach ($appsDir as $fileInfo) {
591
+            if ($fileInfo->isDir() && !$fileInfo->isDot()) {
592
+                $absAppPath = $appsPath . DIRECTORY_SEPARATOR . $fileInfo->getFilename();
593
+                $appDirUser = fileowner($absAppPath);
594
+                if ($appDirUser !== $currentUser) {
595
+                    $appDirsWithDifferentOwner[] = $absAppPath;
596
+                }
597
+            }
598
+        }
599
+
600
+        return $appDirsWithDifferentOwner;
601
+    }
602
+
603
+    /**
604
+     * Checks for potential PHP modules that would improve the instance
605
+     *
606
+     * @return string[] A list of PHP modules that is recommended
607
+     */
608
+    protected function hasRecommendedPHPModules(): array {
609
+        $recommendedPHPModules = [];
610
+
611
+        if (!extension_loaded('intl')) {
612
+            $recommendedPHPModules[] = 'intl';
613
+        }
614
+
615
+        if (!extension_loaded('bcmath')) {
616
+            $recommendedPHPModules[] = 'bcmath';
617
+        }
618
+
619
+        if (!extension_loaded('gmp')) {
620
+            $recommendedPHPModules[] = 'gmp';
621
+        }
622
+
623
+        if ($this->config->getAppValue('theming', 'enabled', 'no') === 'yes') {
624
+            if (!extension_loaded('imagick')) {
625
+                $recommendedPHPModules[] = 'imagick';
626
+            }
627
+        }
628
+
629
+        return $recommendedPHPModules;
630
+    }
631
+
632
+    protected function isMysqlUsedWithoutUTF8MB4(): bool {
633
+        return ($this->config->getSystemValue('dbtype', 'sqlite') === 'mysql') && ($this->config->getSystemValue('mysql.utf8mb4', false) === false);
634
+    }
635
+
636
+    protected function hasBigIntConversionPendingColumns(): array {
637
+        // copy of ConvertFilecacheBigInt::getColumnsByTable()
638
+        $tables = [
639
+            'activity' => ['activity_id', 'object_id'],
640
+            'activity_mq' => ['mail_id'],
641
+            'authtoken' => ['id'],
642
+            'bruteforce_attempts' => ['id'],
643
+            'federated_reshares' => ['share_id'],
644
+            'filecache' => ['fileid', 'storage', 'parent', 'mimetype', 'mimepart', 'mtime', 'storage_mtime'],
645
+            'filecache_extended' => ['fileid'],
646
+            'file_locks' => ['id'],
647
+            'jobs' => ['id'],
648
+            'mimetypes' => ['id'],
649
+            'mounts' => ['id', 'storage_id', 'root_id', 'mount_id'],
650
+            'share_external' => ['id', 'parent'],
651
+            'storages' => ['numeric_id'],
652
+        ];
653
+
654
+        $schema = new SchemaWrapper($this->db);
655
+        $isSqlite = $this->db->getDatabasePlatform() instanceof SqlitePlatform;
656
+        $pendingColumns = [];
657
+
658
+        foreach ($tables as $tableName => $columns) {
659
+            if (!$schema->hasTable($tableName)) {
660
+                continue;
661
+            }
662
+
663
+            $table = $schema->getTable($tableName);
664
+            foreach ($columns as $columnName) {
665
+                $column = $table->getColumn($columnName);
666
+                $isAutoIncrement = $column->getAutoincrement();
667
+                $isAutoIncrementOnSqlite = $isSqlite && $isAutoIncrement;
668
+                if ($column->getType()->getName() !== Types::BIGINT && !$isAutoIncrementOnSqlite) {
669
+                    $pendingColumns[] = $tableName . '.' . $columnName;
670
+                }
671
+            }
672
+        }
673
+
674
+        return $pendingColumns;
675
+    }
676
+
677
+    protected function isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed(): bool {
678
+        $objectStore = $this->config->getSystemValue('objectstore', null);
679
+        $objectStoreMultibucket = $this->config->getSystemValue('objectstore_multibucket', null);
680
+
681
+        if (!isset($objectStoreMultibucket) && !isset($objectStore)) {
682
+            return true;
683
+        }
684
+
685
+        if (isset($objectStoreMultibucket['class']) && $objectStoreMultibucket['class'] !== 'OC\\Files\\ObjectStore\\S3') {
686
+            return true;
687
+        }
688
+
689
+        if (isset($objectStore['class']) && $objectStore['class'] !== 'OC\\Files\\ObjectStore\\S3') {
690
+            return true;
691
+        }
692
+
693
+        $tempPath = sys_get_temp_dir();
694
+        if (!is_dir($tempPath)) {
695
+            $this->logger->error('Error while checking the temporary PHP path - it was not properly set to a directory. value: ' . $tempPath);
696
+            return false;
697
+        }
698
+        $freeSpaceInTemp = disk_free_space($tempPath);
699
+        if ($freeSpaceInTemp === false) {
700
+            $this->logger->error('Error while checking the available disk space of temporary PHP path - no free disk space returned. temporary path: ' . $tempPath);
701
+            return false;
702
+        }
703
+
704
+        $freeSpaceInTempInGB = $freeSpaceInTemp / 1024 / 1024 / 1024;
705
+        if ($freeSpaceInTempInGB > 50) {
706
+            return true;
707
+        }
708
+
709
+        $this->logger->warning('Checking the available space in the temporary path resulted in ' . round($freeSpaceInTempInGB, 1) . ' GB instead of the recommended 50GB. Path: ' . $tempPath);
710
+        return false;
711
+    }
712
+
713
+    protected function imageMagickLacksSVGSupport(): bool {
714
+        return extension_loaded('imagick') && count(\Imagick::queryFormats('SVG')) === 0;
715
+    }
716
+
717
+    /**
718
+     * @return DataResponse
719
+     */
720
+    public function check() {
721
+        $phpDefaultCharset = new PhpDefaultCharset();
722
+        $phpOutputBuffering = new PhpOutputBuffering();
723
+        $legacySSEKeyFormat = new LegacySSEKeyFormat($this->l10n, $this->config, $this->urlGenerator);
724
+        $checkUserCertificates = new CheckUserCertificates($this->l10n, $this->config, $this->urlGenerator);
725
+        $supportedDatabases = new SupportedDatabase($this->l10n, $this->connection);
726
+
727
+        return new DataResponse(
728
+            [
729
+                'isGetenvServerWorking' => !empty(getenv('PATH')),
730
+                'isReadOnlyConfig' => $this->isReadOnlyConfig(),
731
+                'hasValidTransactionIsolationLevel' => $this->hasValidTransactionIsolationLevel(),
732
+                'hasFileinfoInstalled' => $this->hasFileinfoInstalled(),
733
+                'hasWorkingFileLocking' => $this->hasWorkingFileLocking(),
734
+                'suggestedOverwriteCliURL' => $this->getSuggestedOverwriteCliURL(),
735
+                'cronInfo' => $this->getLastCronInfo(),
736
+                'cronErrors' => $this->getCronErrors(),
737
+                'serverHasInternetConnectionProblems' => $this->hasInternetConnectivityProblems(),
738
+                'isMemcacheConfigured' => $this->isMemcacheConfigured(),
739
+                'memcacheDocs' => $this->urlGenerator->linkToDocs('admin-performance'),
740
+                'isRandomnessSecure' => $this->isRandomnessSecure(),
741
+                'securityDocs' => $this->urlGenerator->linkToDocs('admin-security'),
742
+                'isUsedTlsLibOutdated' => $this->isUsedTlsLibOutdated(),
743
+                'phpSupported' => $this->isPhpSupported(),
744
+                'forwardedForHeadersWorking' => $this->forwardedForHeadersWorking(),
745
+                'reverseProxyDocs' => $this->urlGenerator->linkToDocs('admin-reverse-proxy'),
746
+                'isCorrectMemcachedPHPModuleInstalled' => $this->isCorrectMemcachedPHPModuleInstalled(),
747
+                'hasPassedCodeIntegrityCheck' => $this->checker->hasPassedCheck(),
748
+                'codeIntegrityCheckerDocumentation' => $this->urlGenerator->linkToDocs('admin-code-integrity'),
749
+                'isOpcacheProperlySetup' => $this->isOpcacheProperlySetup(),
750
+                'hasOpcacheLoaded' => $this->hasOpcacheLoaded(),
751
+                'phpOpcacheDocumentation' => $this->urlGenerator->linkToDocs('admin-php-opcache'),
752
+                'isSettimelimitAvailable' => $this->isSettimelimitAvailable(),
753
+                'hasFreeTypeSupport' => $this->hasFreeTypeSupport(),
754
+                'missingPrimaryKeys' => $this->hasMissingPrimaryKeys(),
755
+                'missingIndexes' => $this->hasMissingIndexes(),
756
+                'missingColumns' => $this->hasMissingColumns(),
757
+                'isSqliteUsed' => $this->isSqliteUsed(),
758
+                'databaseConversionDocumentation' => $this->urlGenerator->linkToDocs('admin-db-conversion'),
759
+                'isMemoryLimitSufficient' => $this->memoryInfo->isMemoryLimitSufficient(),
760
+                'appDirsWithDifferentOwner' => $this->getAppDirsWithDifferentOwner(),
761
+                'recommendedPHPModules' => $this->hasRecommendedPHPModules(),
762
+                'pendingBigIntConversionColumns' => $this->hasBigIntConversionPendingColumns(),
763
+                'isMysqlUsedWithoutUTF8MB4' => $this->isMysqlUsedWithoutUTF8MB4(),
764
+                'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' => $this->isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed(),
765
+                'reverseProxyGeneratedURL' => $this->urlGenerator->getAbsoluteURL('index.php'),
766
+                'imageMagickLacksSVGSupport' => $this->imageMagickLacksSVGSupport(),
767
+                PhpDefaultCharset::class => ['pass' => $phpDefaultCharset->run(), 'description' => $phpDefaultCharset->description(), 'severity' => $phpDefaultCharset->severity()],
768
+                PhpOutputBuffering::class => ['pass' => $phpOutputBuffering->run(), 'description' => $phpOutputBuffering->description(), 'severity' => $phpOutputBuffering->severity()],
769
+                LegacySSEKeyFormat::class => ['pass' => $legacySSEKeyFormat->run(), 'description' => $legacySSEKeyFormat->description(), 'severity' => $legacySSEKeyFormat->severity(), 'linkToDocumentation' => $legacySSEKeyFormat->linkToDocumentation()],
770
+                CheckUserCertificates::class => ['pass' => $checkUserCertificates->run(), 'description' => $checkUserCertificates->description(), 'severity' => $checkUserCertificates->severity(), 'elements' => $checkUserCertificates->elements()],
771
+                'isDefaultPhoneRegionSet' => $this->config->getSystemValueString('default_phone_region', '') !== '',
772
+                SupportedDatabase::class => ['pass' => $supportedDatabases->run(), 'description' => $supportedDatabases->description(), 'severity' => $supportedDatabases->severity()],
773
+            ]
774
+        );
775
+    }
776 776
 }
Please login to merge, or discard this patch.