db69ac5d58be12fa998913e62c31f6d3b2f0dda7
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / SystemEnvironment / Check.php
1 <?php
2 namespace TYPO3\CMS\Install\SystemEnvironment;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Install\Status;
18
19 /**
20 * Check system environment status
21 *
22 * This class is a hardcoded requirement check of the underlying
23 * server and PHP system.
24 *
25 * The class *must not* check for any TYPO3 specific things like
26 * specific configuration values or directories. It should not fail
27 * if there is no TYPO3 at all.
28 *
29 * The only core code used is the class loader
30 *
31 * This class is instantiated as the *very first* class during
32 * installation. It is meant to be *standalone* und must not have
33 * any requirements, except the status classes. It must be possible
34 * to run this script separated from the rest of the core, without
35 * dependencies.
36 *
37 * This means especially:
38 * * No hooks or anything like that
39 * * No usage of *any* TYPO3 code like GeneralUtility
40 * * No require of anything but the status classes
41 * * No localization
42 *
43 * The status messages and title *must not* include HTML, use plain
44 * text only. The return values of this class are not bound to HTML
45 * and can be used in different scopes (eg. as json array).
46 *
47 * @author Christian Kuhn <lolli@schwarzbu.ch>
48 */
49 class Check {
50
51 /**
52 * @var array List of required PHP extensions
53 */
54 protected $requiredPhpExtensions = array(
55 'fileinfo',
56 'filter',
57 'gd',
58 'hash',
59 'json',
60 'mysqli',
61 'openssl',
62 'pcre',
63 'session',
64 'soap',
65 'SPL',
66 'standard',
67 'xml',
68 'zip',
69 'zlib',
70 );
71
72 /**
73 * Get all status information as array with status objects
74 *
75 * @return array<\TYPO3\CMS\Install\Status\StatusInterface>
76 */
77 public function getStatus() {
78 $statusArray = array();
79 $statusArray[] = $this->checkCurrentDirectoryIsInIncludePath();
80 $statusArray[] = $this->checkFileUploadEnabled();
81 $statusArray[] = $this->checkMaximumFileUploadSize();
82 $statusArray[] = $this->checkPostUploadSizeIsHigherOrEqualMaximumFileUploadSize();
83 $statusArray[] = $this->checkMemorySettings();
84 $statusArray[] = $this->checkPhpVersion();
85 $statusArray[] = $this->checkMaxExecutionTime();
86 $statusArray[] = $this->checkDisableFunctions();
87 $statusArray[] = $this->checkDownloadsPossible();
88 $statusArray[] = $this->checkDocRoot();
89 $statusArray[] = $this->checkOpenBaseDir();
90 $statusArray[] = $this->checkXdebugMaxNestingLevel();
91 $statusArray[] = $this->checkOpenSslInstalled();
92 if ($this->isSuhosinLoadedAndActive()) {
93 $statusArray[] = $this->getSuhosinLoadedStatus();
94 $statusArray[] = $this->checkSuhosinRequestMaxVars();
95 $statusArray[] = $this->checkSuhosinRequestMaxVarnameLength();
96 $statusArray[] = $this->checkSuhosinPostMaxNameLength();
97 $statusArray[] = $this->checkSuhosinPostMaxVars();
98 $statusArray[] = $this->checkSuhosinGetMaxNameLength();
99 $statusArray[] = $this->checkSuhosinGetMaxValueLength();
100 $statusArray[] = $this->checkSuhosinExecutorIncludeWhitelistContainsPhar();
101 $statusArray[] = $this->checkSuhosinExecutorIncludeWhitelistContainsVfs();
102 }
103 $statusArray[] = $this->checkSomePhpOpcodeCacheIsLoaded();
104 $statusArray[] = $this->checkReflectionDocComment();
105 $statusArray[] = $this->checkSystemLocale();
106 $statusArray[] = $this->checkLocaleWithUTF8filesystem();
107 $statusArray[] = $this->checkWindowsApacheThreadStackSize();
108 foreach ($this->requiredPhpExtensions as $extension) {
109 $statusArray[] = $this->checkRequiredPhpExtension($extension);
110 }
111 $statusArray[] = $this->checkGdLibTrueColorSupport();
112 $statusArray[] = $this->checkGdLibGifSupport();
113 $statusArray[] = $this->checkGdLibJpgSupport();
114 $statusArray[] = $this->checkGdLibPngSupport();
115 $statusArray[] = $this->checkGdLibFreeTypeSupport();
116 $statusArray[] = $this->checkRegisterGlobals();
117 $statusArray[] = $this->checkLibXmlBug();
118 $statusArray[] = $this->isTrueTypeFontWorking();
119 return $statusArray;
120 }
121
122 /**
123 * Checks if current directory (.) is in PHP include path
124 *
125 * @return Status\StatusInterface
126 */
127 protected function checkCurrentDirectoryIsInIncludePath() {
128 $includePath = ini_get('include_path');
129 $delimiter = $this->isWindowsOs() ? ';' : ':';
130 $pathArray = $this->trimExplode($delimiter, $includePath);
131 if (!in_array('.', $pathArray)) {
132 $status = new Status\WarningStatus();
133 $status->setTitle('Current directory (./) is not within PHP include path');
134 $status->setMessage(
135 'include_path = ' . implode(' ', $pathArray) . LF .
136 'Normally the current path \'.\' is included in the' .
137 ' include_path of PHP. Although TYPO3 does not rely on this,' .
138 ' it is an unusual setting that may introduce problems for' .
139 ' some extensions.'
140 );
141 } else {
142 $status = new Status\OkStatus();
143 $status->setTitle('Current directory (./) is within PHP include path.');
144 }
145 return $status;
146 }
147
148 /**
149 * Check if file uploads are enabled in PHP
150 *
151 * @return Status\StatusInterface
152 */
153 protected function checkFileUploadEnabled() {
154 if (!ini_get('file_uploads')) {
155 $status = new Status\ErrorStatus();
156 $status->setTitle('File uploads not allowed in PHP');
157 $status->setMessage(
158 'file_uploads=' . ini_get('file_uploads') . LF .
159 'TYPO3 uses the ability to upload files from the browser in various cases.' .
160 ' If this flag is disabled in PHP, you won\'t be able to upload files.' .
161 ' But it doesn\'t end here, because not only are files not accepted by' .
162 ' the server - ALL content in the forms are discarded and therefore' .
163 ' nothing at all will be editable if you don\'t set this flag!' .
164 ' However if you cannot enable fileupload for some reason in PHP, alternatively' .
165 ' change the default form encoding value with \\$TYPO3_CONF_VARS[SYS][form_enctype].'
166 );
167 } else {
168 $status = new Status\OkStatus();
169 $status->setTitle('File uploads allowed in PHP');
170 }
171 return $status;
172 }
173
174 /**
175 * Check maximum file upload size against default value of 10MB
176 *
177 * @return Status\StatusInterface
178 */
179 protected function checkMaximumFileUploadSize() {
180 $maximumUploadFilesize = $this->getBytesFromSizeMeasurement(ini_get('upload_max_filesize'));
181 $configuredMaximumUploadFilesize = 1024 * (int)$GLOBALS['TYPO3_CONF_VARS']['BE']['maxFileSize'];
182 if ($maximumUploadFilesize < $configuredMaximumUploadFilesize) {
183 $status = new Status\ErrorStatus();
184 $status->setTitle('PHP Maximum upload filesize too small');
185 $status->setMessage(
186 'PHP upload_max_filesize = ' . (int)($maximumUploadFilesize / 1024) . ' KB' . LF .
187 'TYPO3_CONF_VARS[BE][maxFileSize] = ' . (int)($configuredMaximumUploadFilesize / 1024) . ' KB' . LF . LF .
188 'Currently PHP determines the limits for uploaded file\'s sizes and not TYPO3.' .
189 ' It is recommended that the value of upload_max_filesize is at least equal to the value' .
190 ' of TYPO3_CONF_VARS[BE][maxFileSize].'
191 );
192 } else {
193 $status = new Status\OkStatus();
194 $status->setTitle('PHP Maximum file upload size is higher than or equal to [BE][maxFileSize]');
195 }
196 return $status;
197 }
198
199 /**
200 * Check maximum post upload size correlates with maximum file upload
201 *
202 * @return Status\StatusInterface
203 */
204 protected function checkPostUploadSizeIsHigherOrEqualMaximumFileUploadSize() {
205 $maximumUploadFilesize = $this->getBytesFromSizeMeasurement(ini_get('upload_max_filesize'));
206 $maximumPostSize = $this->getBytesFromSizeMeasurement(ini_get('post_max_size'));
207 if ($maximumPostSize < $maximumUploadFilesize) {
208 $status = new Status\ErrorStatus();
209 $status->setTitle('Maximum size for POST requests is smaller than maximum upload filesize in PHP');
210 $status->setMessage(
211 'upload_max_filesize=' . ini_get('upload_max_filesize') . LF .
212 'post_max_size=' . ini_get('post_max_size') . LF .
213 'You have defined a maximum size for file uploads in PHP which' .
214 ' exceeds the allowed size for POST requests. Therefore the' .
215 ' file uploads can also not be larger than ' . ini_get('post_max_size') . '.'
216 );
217 } else {
218 $status = new Status\OkStatus();
219 $status->setTitle('Maximum post upload size correlates with maximum upload file size in PHP');
220 }
221 return $status;
222 }
223
224 /**
225 * Check memory settings
226 *
227 * @return Status\StatusInterface
228 */
229 protected function checkMemorySettings() {
230 $minimumMemoryLimit = 32;
231 $recommendedMemoryLimit = 64;
232 $memoryLimit = $this->getBytesFromSizeMeasurement(ini_get('memory_limit'));
233 if ($memoryLimit <= 0) {
234 $status = new Status\WarningStatus();
235 $status->setTitle('Unlimited memory limit for PHP');
236 $status->setMessage(
237 'PHP is configured not to limit memory usage at all. This is a risk' .
238 ' and should be avoided in production setup. In general it\'s best practice to limit this.' .
239 ' To be safe, set a limit in PHP, but with a minimum of ' . $recommendedMemoryLimit . 'MB:' . LF .
240 'memory_limit=' . $recommendedMemoryLimit . 'M'
241 );
242 } elseif ($memoryLimit < 1024 * 1024 * $minimumMemoryLimit) {
243 $status = new Status\ErrorStatus();
244 $status->setTitle('PHP Memory limit below ' . $minimumMemoryLimit . 'MB');
245 $status->setMessage(
246 'memory_limit=' . ini_get('memory_limit') . LF .
247 'Your system is configured to enforce a memory limit for PHP scripts lower than ' .
248 $minimumMemoryLimit . 'MB. It is required to raise the limit.' .
249 ' We recommend a minimum PHP memory limit of ' . $recommendedMemoryLimit . 'MB:' . LF .
250 'memory_limit=' . $recommendedMemoryLimit . 'M'
251 );
252 } elseif ($memoryLimit < 1024 * 1024 * $recommendedMemoryLimit) {
253 $status = new Status\WarningStatus();
254 $status->setTitle('PHP Memory limit below ' . $recommendedMemoryLimit . 'MB');
255 $status->setMessage(
256 'memory_limit=' . ini_get('memory_limit') . LF .
257 'Your system is configured to enforce a memory limit for PHP scripts lower than ' .
258 $recommendedMemoryLimit . 'MB.' .
259 ' A slim TYPO3 instance without many extensions will probably work, but you should monitor your' .
260 ' system for "allowed memory size of X bytes exhausted" messages, especially if using the backend.' .
261 ' To be on the safe side,' . ' we recommend a minimum PHP memory limit of ' .
262 $recommendedMemoryLimit . 'MB:' . LF .
263 'memory_limit=' . $recommendedMemoryLimit . 'M'
264 );
265 } else {
266 $status = new Status\OkStatus();
267 $status->setTitle('PHP Memory limit is equal to or more than ' . $recommendedMemoryLimit . 'MB');
268 }
269 return $status;
270 }
271
272 /**
273 * Check minimum PHP version
274 *
275 * @return Status\StatusInterface
276 */
277 protected function checkPhpVersion() {
278 $minimumPhpVersion = '5.5.0';
279 $currentPhpVersion = phpversion();
280 if (version_compare($currentPhpVersion, $minimumPhpVersion) < 0) {
281 $status = new Status\ErrorStatus();
282 $status->setTitle('PHP version too low');
283 $status->setMessage(
284 'Your PHP version ' . $currentPhpVersion . ' is too old. TYPO3 CMS does not run' .
285 ' with this version. Update to at least PHP ' . $minimumPhpVersion
286 );
287 } else {
288 $status = new Status\OkStatus();
289 $status->setTitle('PHP version is fine');
290 }
291 return $status;
292 }
293
294 /**
295 * Check maximum execution time
296 *
297 * @return Status\StatusInterface
298 */
299 protected function checkMaxExecutionTime() {
300 $minimumMaximumExecutionTime = 30;
301 $recommendedMaximumExecutionTime = 240;
302 $currentMaximumExecutionTime = ini_get('max_execution_time');
303 if ($currentMaximumExecutionTime == 0) {
304 if (PHP_SAPI === 'cli') {
305 $status = new Status\OkStatus();
306 $status->setTitle('Infinite PHP script execution time');
307 $status->setMessage(
308 'Maximum PHP script execution time is always set to infinite (0) in cli mode.' .
309 ' The setting used for web requests cannot be checked from command line.'
310 );
311 } else {
312 $status = new Status\WarningStatus();
313 $status->setTitle('Infinite PHP script execution time');
314 $status->setMessage(
315 'max_execution_time=' . $currentMaximumExecutionTime . LF .
316 'While TYPO3 is fine with this, you risk a denial-of-service for your system if for whatever' .
317 ' reason some script hangs in an infinite loop. You are usually on the safe side ' .
318 ' if it is reduced to ' . $recommendedMaximumExecutionTime . ' seconds:' . LF .
319 'max_execution_time=' . $recommendedMaximumExecutionTime
320 );
321 }
322 } elseif ($currentMaximumExecutionTime < $minimumMaximumExecutionTime) {
323 $status = new Status\ErrorStatus();
324 $status->setTitle('Low PHP script execution time');
325 $status->setMessage(
326 'max_execution_time=' . $currentMaximumExecutionTime . LF .
327 'Your max_execution_time is too low. Some expensive operations in TYPO3 can take longer than that.' .
328 ' It is recommended to raise the limit to ' . $recommendedMaximumExecutionTime . ' seconds:' . LF .
329 'max_execution_time=' . $recommendedMaximumExecutionTime
330 );
331 } elseif ($currentMaximumExecutionTime < $recommendedMaximumExecutionTime) {
332 $status = new Status\WarningStatus();
333 $status->setTitle('Low PHP script execution time');
334 $status->setMessage(
335 'max_execution_time=' . $currentMaximumExecutionTime . LF .
336 'Your max_execution_time is low. While TYPO3 often runs without problems' .
337 ' with ' . $minimumMaximumExecutionTime . ' seconds,' .
338 ' it may still happen that script execution is stopped before finishing' .
339 ' calculations. You should monitor the system for messages in this area' .
340 ' and maybe raise the limit to ' . $recommendedMaximumExecutionTime . ' seconds:' . LF .
341 'max_execution_time=' . $recommendedMaximumExecutionTime
342 );
343 } else {
344 $status = new Status\OkStatus();
345 $status->setTitle('Maximum PHP script execution time is equal to or more than '
346 . $recommendedMaximumExecutionTime);
347 }
348 return $status;
349 }
350
351 /**
352 * Check for disabled functions
353 *
354 * @return Status\StatusInterface
355 */
356 protected function checkDisableFunctions() {
357 $disabledFunctions = trim(ini_get('disable_functions'));
358
359 // Filter "disable_functions"
360 $disabledFunctionsArray = $this->trimExplode(',', $disabledFunctions);
361
362 // Array with strings to find
363 $findStrings = array(
364 // Disabled by default on Ubuntu OS but this is okay since the Core does not use them
365 'pcntl_',
366 );
367 foreach ($disabledFunctionsArray as $key => $disabledFunction) {
368 foreach ($findStrings as $findString) {
369 if (strpos($disabledFunction, $findString) !== FALSE) {
370 unset($disabledFunctionsArray[$key]);
371 }
372 }
373 }
374
375 if ($disabledFunctions !== '') {
376 if (count($disabledFunctionsArray) > 0) {
377 $status = new Status\ErrorStatus();
378 $status->setTitle('Some PHP functions disabled');
379 $status->setMessage(
380 'disable_functions=' . implode(' ', explode(',', $disabledFunctions)) . LF .
381 'These function(s) are disabled. TYPO3 uses some of those, so there might be trouble.' .
382 ' TYPO3 is designed to use the default set of PHP functions plus some common extensions.' .
383 ' Possibly these functions are disabled' .
384 ' due to security considerations and most likely the list would include a function like' .
385 ' exec() which is used by TYPO3 at various places. Depending on which exact functions' .
386 ' are disabled, some parts of the system may just break without further notice.'
387 );
388 } else {
389 $status = new Status\NoticeStatus();
390 $status->setTitle('Some PHP functions currently disabled but OK');
391 $status->setMessage(
392 'disable_functions=' . implode(' ', explode(',', $disabledFunctions)) . LF .
393 'These function(s) are disabled. TYPO3 uses currently none of those, so you are good to go.'
394 );
395 }
396 } else {
397 $status = new Status\OkStatus();
398 $status->setTitle('No disabled PHP functions');
399 }
400 return $status;
401 }
402
403 /**
404 * Check if it is possible to download external data (e.g. TER)
405 * Either allow_url_fopen must be enabled or curl must be used
406 *
407 * @return Status\OkStatus|Status\WarningStatus
408 */
409 protected function checkDownloadsPossible() {
410 $allowUrlFopen = (bool)ini_get('allow_url_fopen');
411 $curlEnabled = !empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlUse']);
412 if ($allowUrlFopen || $curlEnabled) {
413 $status = new Status\OkStatus();
414 $status->setTitle('Fetching external URLs is allowed');
415 } else {
416 $status = new Status\WarningStatus();
417 $status->setTitle('Fetching external URLs is not allowed');
418 $status->setMessage(
419 'Either enable PHP runtime setting "allow_url_fopen"' . LF . 'or enable curl by setting [SYS][curlUse] accordingly.'
420 );
421 }
422 return $status;
423 }
424
425 /**
426 * Check for doc_root ini setting
427 *
428 * @return Status\StatusInterface
429 */
430 protected function checkDocRoot() {
431 $docRootSetting = trim(ini_get('doc_root'));
432 if ($docRootSetting !== '') {
433 $status = new Status\NoticeStatus();
434 $status->setTitle('doc_root is set');
435 $status->setMessage(
436 'doc_root=' . $docRootSetting . LF .
437 'PHP cannot execute scripts' .
438 ' outside this directory. This setting is seldom used and must correlate' .
439 ' with your actual document root. You might be in trouble if your' .
440 ' TYPO3 CMS core code is linked to some different location.' .
441 ' If that is a problem, the setting must be changed.'
442 );
443 } else {
444 $status = new Status\OkStatus();
445 $status->setTitle('PHP doc_root is not set');
446 }
447 return $status;
448 }
449
450 /**
451 * Check open_basedir
452 *
453 * @return Status\StatusInterface
454 */
455 protected function checkOpenBaseDir() {
456 $openBaseDirSetting = trim(ini_get('open_basedir'));
457 if ($openBaseDirSetting !== '') {
458 $status = new Status\NoticeStatus();
459 $status->setTitle('PHP open_basedir is set');
460 $status->setMessage(
461 'open_basedir = ' . ini_get('open_basedir') . LF .
462 'This restricts TYPO3 to open and include files only in this' .
463 ' path. Please make sure that this does not prevent TYPO3 from running,' .
464 ' if for example your TYPO3 CMS core is linked to a different directory' .
465 ' not included in this path.'
466 );
467 } else {
468 $status = new Status\OkStatus();
469 $status->setTitle('PHP open_basedir is off');
470 }
471 return $status;
472 }
473
474 /**
475 * If xdebug is loaded, the default max_nesting_level of 100 must be raised
476 *
477 * @return Status\StatusInterface
478 */
479 protected function checkXdebugMaxNestingLevel() {
480 if (extension_loaded('xdebug')) {
481 $recommendedMaxNestingLevel = 400;
482 $errorThreshold = 250;
483 $currentMaxNestingLevel = ini_get('xdebug.max_nesting_level');
484 if ($currentMaxNestingLevel < $errorThreshold) {
485 $status = new Status\ErrorStatus();
486 $status->setTitle('PHP xdebug.max_nesting_level is critically low');
487 $status->setMessage(
488 'xdebug.max_nesting_level=' . $currentMaxNestingLevel . LF .
489 'This setting controls the maximum number of nested function calls to protect against' .
490 ' infinite recursion. The current value is too low for TYPO3 CMS and must' .
491 ' be either raised or xdebug has to be unloaded. A value of ' . $recommendedMaxNestingLevel .
492 ' is recommended. Warning: Expect fatal PHP errors in central parts of the CMS' .
493 ' if the value is not raised significantly to:' . LF .
494 'xdebug.max_nesting_level=' . $recommendedMaxNestingLevel
495 );
496 } elseif ($currentMaxNestingLevel < $recommendedMaxNestingLevel) {
497 $status = new Status\WarningStatus();
498 $status->setTitle('PHP xdebug.max_nesting_level is low');
499 $status->setMessage(
500 'xdebug.max_nesting_level=' . $currentMaxNestingLevel . LF .
501 'This setting controls the maximum number of nested function calls to protect against' .
502 ' infinite recursion. The current value is high enough for the TYPO3 CMS core to work' .
503 ' fine, but still some extensions could raise fatal PHP errors if the setting is not' .
504 ' raised further. A value of ' . $recommendedMaxNestingLevel . ' is recommended.' . LF .
505 'xdebug.max_nesting_level=' . $recommendedMaxNestingLevel
506 );
507 } else {
508 $status = new Status\OkStatus();
509 $status->setTitle('PHP xdebug.max_nesting_level ok');
510 }
511 } else {
512 $status = new Status\OkStatus();
513 $status->setTitle('PHP xdebug extension not loaded');
514 }
515 return $status;
516 }
517
518 /**
519 * Check accessibility and functionality of OpenSSL
520 *
521 * @return Status\StatusInterface
522 */
523 protected function checkOpenSslInstalled() {
524 if (extension_loaded('openssl')) {
525 $testKey = @openssl_pkey_new();
526 if (is_resource($testKey)) {
527 openssl_free_key($testKey);
528 $status = new Status\OkStatus();
529 $status->setTitle('PHP OpenSSL extension installed properly');
530 } else {
531 $status = new Status\ErrorStatus();
532 $status->setTitle('PHP OpenSSL extension not working');
533 $status->setMessage(
534 'Something went wrong while trying to create a new private key for testing.' .
535 ' Please check the integration of the PHP OpenSSL extension and if it is installed correctly.'
536 );
537 }
538 } else {
539 $status = new Status\ErrorStatus();
540 $status->setTitle('PHP OpenSSL extension not loaded');
541 $status->setMessage(
542 'OpenSSL is a PHP extension to encrypt/decrypt data between requests.' .
543 ' TYPO3 CMS requires it to be able to encrypt stored passwords to improve the security in the' .
544 ' database layer.'
545 );
546 }
547
548 return $status;
549 }
550
551 /**
552 * Get suhosin loaded status
553 * Should be called only if suhosin extension is loaded
554 *
555 * @return Status\StatusInterface
556 * @throws \BadMethodCallException
557 */
558 protected function getSuhosinLoadedStatus() {
559 if ($this->isSuhosinLoadedAndActive()) {
560 $status = new Status\OkStatus();
561 $status->setTitle('PHP suhosin extension loaded and active');
562 return $status;
563 } else {
564 throw new \BadMethodCallException('Should be called only if suhosin extension is loaded', 1422634778);
565 }
566 }
567
568 /**
569 * Check suhosin.request.max_vars
570 *
571 * @return Status\StatusInterface
572 */
573 protected function checkSuhosinRequestMaxVars() {
574 $recommendedRequestMaxVars = 400;
575 if ($this->isSuhosinLoadedAndActive()) {
576 $currentRequestMaxVars = ini_get('suhosin.request.max_vars');
577 if ($currentRequestMaxVars < $recommendedRequestMaxVars) {
578 $status = new Status\ErrorStatus();
579 $status->setTitle('PHP suhosin.request.max_vars too low');
580 $status->setMessage(
581 'suhosin.request.max_vars=' . $currentRequestMaxVars . LF .
582 'This setting can lead to lost information if submitting forms with lots of data in TYPO3 CMS' .
583 ' (as the install tool does). It is highly recommended to raise this' .
584 ' to at least ' . $recommendedRequestMaxVars . ':' . LF .
585 'suhosin.request.max_vars=' . $recommendedRequestMaxVars
586 );
587 } else {
588 $status = new Status\OkStatus();
589 $status->setTitle('PHP suhosin.request.max_vars ok');
590 }
591 } else {
592 $status = new Status\InfoStatus();
593 $status->setTitle('Suhosin not loaded');
594 $status->setMessage(
595 'If enabling suhosin, suhosin.request.max_vars' .
596 ' should be set to at least ' . $recommendedRequestMaxVars . ':' . LF .
597 'suhosin.request.max_vars=' . $recommendedRequestMaxVars
598 );
599 }
600 return $status;
601 }
602
603 /**
604 * Check suhosin.request.max_varname_length
605 *
606 * @return Status\StatusInterface
607 */
608 protected function checkSuhosinRequestMaxVarnameLength() {
609 $recommendedRequestMaxVarnameLength = 200;
610 if ($this->isSuhosinLoadedAndActive()) {
611 $currentRequestMaxVarnameLength = ini_get('suhosin.request.max_varname_length');
612 if ($currentRequestMaxVarnameLength < $recommendedRequestMaxVarnameLength) {
613 $status = new Status\ErrorStatus();
614 $status->setTitle('PHP suhosin.request.max_varname_length too low');
615 $status->setMessage(
616 'suhosin.request.max_varname_length=' . $currentRequestMaxVarnameLength . LF .
617 'This setting can lead to lost information if submitting forms with lots of data in TYPO3 CMS' .
618 ' (as the install tool does). It is highly recommended to raise this' .
619 ' to at least ' . $recommendedRequestMaxVarnameLength . ':' . LF .
620 'suhosin.request.max_varname_length=' . $recommendedRequestMaxVarnameLength
621 );
622 } else {
623 $status = new Status\OkStatus();
624 $status->setTitle('PHP suhosin.request.max_varname_length ok');
625 }
626 } else {
627 $status = new Status\InfoStatus();
628 $status->setTitle('Suhosin not loaded');
629 $status->setMessage(
630 'If enabling suhosin, suhosin.request.max_varname_length' .
631 ' should be set to at least ' . $recommendedRequestMaxVarnameLength . ':' . LF .
632 'suhosin.request.max_varname_length=' . $recommendedRequestMaxVarnameLength
633 );
634 }
635 return $status;
636 }
637
638 /**
639 * Check suhosin.post.max_name_length
640 *
641 * @return Status\StatusInterface
642 */
643 protected function checkSuhosinPostMaxNameLength() {
644 $recommendedPostMaxNameLength = 200;
645 if ($this->isSuhosinLoadedAndActive()) {
646 $currentPostMaxNameLength = ini_get('suhosin.post.max_name_length');
647 if ($currentPostMaxNameLength < $recommendedPostMaxNameLength) {
648 $status = new Status\ErrorStatus();
649 $status->setTitle('PHP suhosin.post.max_name_length too low');
650 $status->setMessage(
651 'suhosin.post.max_name_length=' . $currentPostMaxNameLength . LF .
652 'This setting can lead to lost information if submitting forms with lots of data in TYPO3 CMS' .
653 ' (as the install tool does). It is highly recommended to raise this' .
654 ' to at least ' . $recommendedPostMaxNameLength . ':' . LF .
655 'suhosin.post.max_name_length=' . $recommendedPostMaxNameLength
656 );
657 } else {
658 $status = new Status\OkStatus();
659 $status->setTitle('PHP suhosin.post.max_name_length ok');
660 }
661 } else {
662 $status = new Status\InfoStatus();
663 $status->setTitle('Suhosin not loaded');
664 $status->setMessage(
665 'If enabling suhosin, suhosin.post.max_name_length' .
666 ' should be set to at least ' . $recommendedPostMaxNameLength . ':' . LF .
667 'suhosin.post.max_name_length=' . $recommendedPostMaxNameLength
668 );
669 }
670 return $status;
671 }
672
673 /**
674 * Check suhosin.post.max_vars
675 *
676 * @return Status\StatusInterface
677 */
678 protected function checkSuhosinPostMaxVars() {
679 $recommendedPostMaxVars = 400;
680 if ($this->isSuhosinLoadedAndActive()) {
681 $currentPostMaxVars = ini_get('suhosin.post.max_vars');
682 if ($currentPostMaxVars < $recommendedPostMaxVars) {
683 $status = new Status\ErrorStatus();
684 $status->setTitle('PHP suhosin.post.max_vars too low');
685 $status->setMessage(
686 'suhosin.post.max_vars=' . $currentPostMaxVars . LF .
687 'This setting can lead to lost information if submitting forms with lots of data in TYPO3 CMS' .
688 ' (as the install tool does). It is highly recommended to raise this' .
689 ' to at least ' . $recommendedPostMaxVars . ':' . LF .
690 'suhosin.post.max_vars=' . $recommendedPostMaxVars
691 );
692 } else {
693 $status = new Status\OkStatus();
694 $status->setTitle('PHP suhosin.post.max_vars ok');
695 }
696 } else {
697 $status = new Status\InfoStatus();
698 $status->setTitle('Suhosin not loaded');
699 $status->setMessage(
700 'If enabling suhosin, suhosin.post.max_vars' .
701 ' should be set to at least ' . $recommendedPostMaxVars . ':' . LF .
702 'suhosin.post.max_vars=' . $recommendedPostMaxVars
703 );
704 }
705 return $status;
706 }
707
708 /**
709 * Check suhosin.get.max_value_length
710 *
711 * @return Status\StatusInterface
712 */
713 protected function checkSuhosinGetMaxValueLength() {
714 $recommendedGetMaxValueLength = 2000;
715 if ($this->isSuhosinLoadedAndActive()) {
716 $currentGetMaxValueLength = ini_get('suhosin.get.max_value_length');
717 if ($currentGetMaxValueLength < $recommendedGetMaxValueLength) {
718 $status = new Status\ErrorStatus();
719 $status->setTitle('PHP suhosin.get.max_value_length too low');
720 $status->setMessage(
721 'suhosin.get.max_value_length=' . $currentGetMaxValueLength . LF .
722 'This setting can lead to lost information if submitting forms with lots of data in TYPO3 CMS' .
723 ' (as the install tool does). It is highly recommended to raise this' .
724 ' to at least ' . $recommendedGetMaxValueLength . ':' . LF .
725 'suhosin.get.max_value_length=' . $recommendedGetMaxValueLength
726 );
727 } else {
728 $status = new Status\OkStatus();
729 $status->setTitle('PHP suhosin.get.max_value_length ok');
730 }
731 } else {
732 $status = new Status\InfoStatus();
733 $status->setTitle('Suhosin not loaded');
734 $status->setMessage(
735 'If enabling suhosin, suhosin.get.max_value_length' .
736 ' should be set to at least ' . $recommendedGetMaxValueLength . ':' . LF .
737 'suhosin.get.max_value_length=' . $recommendedGetMaxValueLength
738 );
739 }
740 return $status;
741 }
742
743 /**
744 * Check suhosin.get.max_name_length
745 *
746 * @return Status\StatusInterface
747 */
748 protected function checkSuhosinGetMaxNameLength() {
749 $recommendedGetMaxNameLength = 200;
750 if ($this->isSuhosinLoadedAndActive()) {
751 $currentGetMaxNameLength = ini_get('suhosin.get.max_name_length');
752 if ($currentGetMaxNameLength < $recommendedGetMaxNameLength) {
753 $status = new Status\ErrorStatus();
754 $status->setTitle('PHP suhosin.get.max_name_length too low');
755 $status->setMessage(
756 'suhosin.get.max_name_length=' . $currentGetMaxNameLength . LF .
757 'This setting can lead to lost information if submitting forms with lots of data in TYPO3 CMS' .
758 ' (as the install tool does). It is highly recommended to raise this' .
759 ' to at least ' . $recommendedGetMaxNameLength . ':' . LF .
760 'suhosin.get.max_name_length=' . $recommendedGetMaxNameLength
761 );
762 } else {
763 $status = new Status\OkStatus();
764 $status->setTitle('PHP suhosin.get.max_name_length ok');
765 }
766 } else {
767 $status = new Status\InfoStatus();
768 $status->setTitle('Suhosin not loaded');
769 $status->setMessage(
770 'If enabling suhosin, suhosin.get.max_name_length' .
771 ' should be set to at least ' . $recommendedGetMaxNameLength . ':' . LF .
772 'suhosin.get.max_name_length=' . $recommendedGetMaxNameLength
773 );
774 }
775 return $status;
776 }
777
778 /**
779 * Check suhosin.executor.include.whitelist contains phar
780 *
781 * @return Status\StatusInterface
782 */
783 protected function checkSuhosinExecutorIncludeWhiteListContainsPhar() {
784 if ($this->isSuhosinLoadedAndActive()) {
785 $whitelist = (string)ini_get('suhosin.executor.include.whitelist');
786 if (strpos($whitelist, 'phar') === FALSE) {
787 $status = new Status\NoticeStatus();
788 $status->setTitle('PHP suhosin.executor.include.whitelist does not contain phar');
789 $status->setMessage(
790 'suhosin.executor.include.whitelist= ' . $whitelist . LF .
791 '"phar" is currently not a hard requirement of TYPO3 CMS but is nice to have and a possible' .
792 ' requirement in future versions. A useful setting is:' . LF .
793 'suhosin.executor.include.whitelist=phar,vfs'
794 );
795 } else {
796 $status = new Status\OkStatus();
797 $status->setTitle('PHP suhosin.executor.include.whitelist contains phar');
798 }
799 } else {
800 $status = new Status\InfoStatus();
801 $status->setTitle('Suhosin not loaded');
802 $status->setMessage(
803 'If enabling suhosin, a useful setting is:' . LF .
804 'suhosin.executor.include.whitelist=phar,vfs'
805 );
806 }
807 return $status;
808 }
809
810 /**
811 * Check suhosin.executor.include.whitelist contains vfs
812 *
813 * @return Status\StatusInterface
814 */
815 protected function checkSuhosinExecutorIncludeWhiteListContainsVfs() {
816 if ($this->isSuhosinLoadedAndActive()) {
817 $whitelist = (string)ini_get('suhosin.executor.include.whitelist');
818 if (strpos($whitelist, 'vfs') === FALSE) {
819 $status = new Status\WarningStatus();
820 $status->setTitle('PHP suhosin.executor.include.whitelist does not contain vfs');
821 $status->setMessage(
822 'suhosin.executor.include.whitelist= ' . $whitelist . LF .
823 '"vfs" is currently not a hard requirement of TYPO3 CMS but tons of unit tests rely on it.' .
824 ' Furthermore, vfs will likely be a base for an additional compatibility layer in the future.' .
825 ' A useful setting is:' . LF .
826 'suhosin.executor.include.whitelist=phar,vfs'
827 );
828 } else {
829 $status = new Status\OkStatus();
830 $status->setTitle('PHP suhosin.executor.include.whitelist contains vfs');
831 }
832 } else {
833 $status = new Status\InfoStatus();
834 $status->setTitle('Suhosin not loaded');
835 $status->setMessage(
836 'If enabling suhosin, a useful setting is:' . LF .
837 'suhosin.executor.include.whitelist=phar,vfs'
838 );
839 }
840 return $status;
841 }
842
843 /**
844 * Check if some opcode cache is loaded
845 *
846 * @return Status\StatusInterface
847 */
848 protected function checkSomePhpOpcodeCacheIsLoaded() {
849 // Link to our wiki page, so we can update opcode cache issue information independent of TYPO3 CMS releases.
850 $wikiLink = 'For more information take a look in our wiki ' . TYPO3_URL_WIKI_OPCODECACHE . '.';
851 $opcodeCaches = \TYPO3\CMS\Core\Utility\OpcodeCacheUtility::getAllActive();
852 if (count($opcodeCaches) === 0) {
853 // Set status to notice. It needs to be notice so email won't be triggered.
854 $status = new Status\NoticeStatus();
855 $status->setTitle('No PHP opcode cache loaded');
856 $status->setMessage(
857 'PHP opcode caches hold a compiled version of executed PHP scripts in' .
858 ' memory and do not require to recompile a script each time it is accessed.' .
859 ' This can be a massive performance improvement and can reduce the load on a' .
860 ' server in general. A parse time reduction by factor three for fully cached' .
861 ' pages can be achieved easily if using an opcode cache.' .
862 LF . $wikiLink
863 );
864 } else {
865 $status = new Status\OkStatus();
866 $message = '';
867
868 foreach ($opcodeCaches as $opcodeCache => $properties) {
869 $message .= 'Name: ' . $opcodeCache . ' Version: ' . $properties['version'];
870 $message .= LF;
871
872 if ($properties['error']) {
873 // Set status to error if not already set
874 if ($status->getSeverity() !== 'error') {
875 $status = new Status\ErrorStatus();
876 }
877 $message .= ' This opcode cache is marked as malfunctioning by the TYPO3 CMS Team.';
878 } elseif ($properties['canInvalidate']) {
879 $message .= ' This opcode cache should work correctly and has good performance.';
880 } else {
881 // Set status to notice if not already error set. It needs to be notice so email won't be triggered.
882 if ($status->getSeverity() !== 'error' || $status->getSeverity() !== 'warning') {
883 $status = new Status\NoticeStatus();
884 }
885 $message .= ' This opcode cache may work correctly but has medium performance.';
886 }
887 $message .= LF;
888 }
889
890 $message .= $wikiLink;
891
892 // Set title of status depending on serverity
893 switch ($status->getSeverity()) {
894 case 'error':
895 $status->setTitle('A possibly malfunctioning PHP opcode cache is loaded');
896 break;
897 case 'warning':
898 $status->setTitle('A PHP opcode cache is loaded which may cause problems');
899 break;
900 case 'ok':
901 default:
902 $status->setTitle('A PHP opcode cache is loaded');
903 break;
904 }
905 $status->setMessage($message);
906 }
907 return $status;
908 }
909
910 /**
911 * Check doc comments can be fetched by reflection
912 *
913 * @return Status\StatusInterface
914 */
915 protected function checkReflectionDocComment() {
916 $testReflection = new \ReflectionMethod(get_class($this), __FUNCTION__);
917 if ($testReflection->getDocComment() === FALSE) {
918 $status = new Status\AlertStatus();
919 $status->setTitle('PHP Doc comment reflection broken');
920 $status->setMessage(
921 'TYPO3 CMS core extensions like extbase and fluid heavily rely on method'
922 . ' comment parsing to fetch annotations and add magic belonging to them.'
923 . ' This does not work in the current environment and so we cannot install'
924 . ' TYPO3 CMS.' . LF
925 . ' Here are some possibilities: ' . LF
926 . '* In Zend OPcache you can disable saving/loading comments. If you are using'
927 . ' Zend OPcache (included since PHP 5.5) then check your php.ini settings for'
928 . ' opcache.save_comments and opcache.load_comments and enable them.' . LF
929 . '* In Zend Optimizer+ you can disable saving comments. If you are using'
930 . ' Zend Optimizer+ then check your php.ini settings for'
931 . ' zend_optimizerplus.save_comments and enable it.' . LF
932 . '* The PHP extension eaccelerator is known to break this if'
933 . ' it is compiled without --with-eaccelerator-doc-comment-inclusion flag.'
934 . ' This compile flag must be specified, otherwise TYPO3 CMS will not work.' . LF
935 . 'For more information take a look in our wiki ' . TYPO3_URL_WIKI_OPCODECACHE . '.'
936 );
937 } else {
938 $status = new Status\OkStatus();
939 $status->setTitle('PHP Doc comment reflection works');
940 }
941 return $status;
942 }
943
944 /**
945 * Check if systemLocale setting is correct (locale exists in the OS)
946 *
947 * @return Status\StatusInterface
948 */
949 protected function checkSystemLocale() {
950
951 $currentLocale = setlocale(LC_CTYPE, 0);
952
953 // On Windows an empty locale value uses the regional settings from the Control Panel
954 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale'] === '' && TYPO3_OS !== 'WIN') {
955 $status = new Status\InfoStatus();
956 $status->setTitle('Empty systemLocale setting');
957 $status->setMessage(
958 '$GLOBALS[TYPO3_CONF_VARS][SYS][systemLocale] is not set. This is fine as long as no UTF-8' .
959 ' file system is used.'
960 );
961 } elseif (setlocale(LC_CTYPE, $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale']) === FALSE) {
962 $status = new Status\ErrorStatus();
963 $status->setTitle('Incorrect systemLocale setting');
964 $status->setMessage(
965 'Current value of the $GLOBALS[TYPO3_CONF_VARS][SYS][systemLocale] is incorrect. A locale with' .
966 ' this name doesn\'t exist in the operating system.'
967 );
968 setlocale(LC_CTYPE, $currentLocale);
969 } else {
970 $status = new Status\OkStatus();
971 $status->setTitle('System locale is correct');
972 }
973
974 return $status;
975 }
976
977 /**
978 * Checks whether we can use file names with UTF-8 characters.
979 * Configured system locale must support UTF-8 when UTF8filesystem is set
980 *
981 * @return Status\StatusInterface
982 */
983 protected function checkLocaleWithUTF8filesystem() {
984
985 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']) {
986
987 // On Windows an empty local value uses the regional settings from the Control Panel
988 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale'] === '' && TYPO3_OS !== 'WIN') {
989 $status = new Status\ErrorStatus();
990 $status->setTitle('System locale not set on UTF-8 file system');
991 $status->setMessage(
992 '$GLOBALS[TYPO3_CONF_VARS][SYS][UTF8filesystem] is set, but $GLOBALS[TYPO3_CONF_VARS][SYS][systemLocale]' .
993 ' is empty. Make sure a valid locale which supports UTF-8 is set.'
994 );
995 } else {
996 $testString = 'ÖöĄĆŻĘĆćążąęó.jpg';
997 $currentLocale = setlocale(LC_CTYPE, 0);
998 $quote = TYPO3_OS === 'WIN' ? '"' : '\'';
999
1000 setlocale(LC_CTYPE, $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale']);
1001
1002 if (escapeshellarg($testString) === $quote . $testString . $quote) {
1003 $status = new Status\OkStatus();
1004 $status->setTitle('File names with UTF-8 characters can be used.');
1005 } else {
1006 $status = new Status\ErrorStatus();
1007 $status->setTitle('System locale setting doesn\'t support UTF-8 file names.');
1008 $status->setMessage(
1009 'Please check your $GLOBALS[TYPO3_CONF_VARS][SYS][systemLocale] setting.'
1010 );
1011 }
1012
1013 setlocale(LC_CTYPE, $currentLocale);
1014 }
1015
1016
1017 } else {
1018 $status = new Status\OkStatus();
1019 $status->setTitle('Skipping test, as UTF8filesystem is not enabled.');
1020 }
1021
1022 return $status;
1023 }
1024
1025 /**
1026 * Checks thread stack size if on windows with apache
1027 *
1028 * @return Status\StatusInterface
1029 */
1030 protected function checkWindowsApacheThreadStackSize() {
1031 if (
1032 $this->isWindowsOs()
1033 && substr($_SERVER['SERVER_SOFTWARE'], 0, 6) === 'Apache'
1034 ) {
1035 $status = new Status\WarningStatus();
1036 $status->setTitle('Windows apache thread stack size');
1037 $status->setMessage(
1038 'This current value cannot be checked by the system, so please ignore this warning if it' .
1039 ' is already taken care of: Fluid uses complex regular expressions which require a lot' .
1040 ' of stack space during the first processing.' .
1041 ' On Windows the default stack size for Apache is a lot smaller than on UNIX.' .
1042 ' You can increase the size to 8MB (default on UNIX) by adding the following configuration' .
1043 ' to httpd.conf and restarting Apache afterwards:' . LF .
1044 '<IfModule mpm_winnt_module>' . LF .
1045 'ThreadStackSize 8388608' . LF .
1046 '</IfModule>'
1047 );
1048 } else {
1049 $status = new Status\OkStatus();
1050 $status->setTitle('Apache ThreadStackSize is not an issue on UNIX systems');
1051 }
1052 return $status;
1053 }
1054
1055 /**
1056 * Check if a specific required PHP extension is loaded
1057 *
1058 * @param string $extension
1059 * @return Status\StatusInterface
1060 */
1061 protected function checkRequiredPhpExtension($extension) {
1062 if (!extension_loaded($extension)) {
1063 $status = new Status\ErrorStatus();
1064 $status->setTitle('PHP extension ' . $extension . ' not loaded');
1065 $status->setMessage(
1066 'TYPO3 CMS uses PHP extension ' . $extension . ' but it is not loaded' .
1067 ' in your environment. Change your environment to provide this extension.'
1068 );
1069 } else {
1070 $status = new Status\OkStatus();
1071 $status->setTitle('PHP extension ' . $extension . ' loaded');
1072 }
1073 return $status;
1074 }
1075
1076 /**
1077 * Check imagecreatetruecolor to verify gdlib works as expected
1078 *
1079 * @return Status\StatusInterface
1080 */
1081 protected function checkGdLibTrueColorSupport() {
1082 if (function_exists('imagecreatetruecolor')) {
1083 $imageResource = @imagecreatetruecolor(50, 100);
1084 if (is_resource($imageResource)) {
1085 imagedestroy($imageResource);
1086 $status = new Status\OkStatus();
1087 $status->setTitle('PHP GD library true color works');
1088 } else {
1089 $status = new Status\ErrorStatus();
1090 $status->setTitle('PHP GD library true color support broken');
1091 $status->setMessage(
1092 'GD is loaded, but calling imagecreatetruecolor() fails.' .
1093 ' This must be fixed, TYPO3 CMS won\'t work well otherwise.'
1094 );
1095 }
1096 } else {
1097 $status = new Status\ErrorStatus();
1098 $status->setTitle('PHP GD library true color support missing');
1099 $status->setMessage(
1100 'Gdlib is essential for TYPO3 CMS to work properly.'
1101 );
1102 }
1103 return $status;
1104 }
1105
1106 /**
1107 * Check gif support of GD library
1108 *
1109 * @return Status\StatusInterface
1110 */
1111 protected function checkGdLibGifSupport() {
1112 if (
1113 function_exists('imagecreatefromgif')
1114 && function_exists('imagegif')
1115 && (imagetypes() & IMG_GIF)
1116 ) {
1117 $imageResource = @imagecreatefromgif(__DIR__ . '/../../Resources/Public/Images/TestInput/Test.gif');
1118 if (is_resource($imageResource)) {
1119 imagedestroy($imageResource);
1120 $status = new Status\OkStatus();
1121 $status->setTitle('PHP GD library has gif support');
1122 } else {
1123 $status = new Status\ErrorStatus();
1124 $status->setTitle('PHP GD library gif support broken');
1125 $status->setMessage(
1126 'GD is loaded, but calling imagecreatefromgif() fails.' .
1127 ' This must be fixed, TYPO3 CMS won\'t work well otherwise.'
1128 );
1129 }
1130 } else {
1131 $status = new Status\ErrorStatus();
1132 $status->setTitle('PHP GD library gif support missing');
1133 $status->setMessage(
1134 'GD must be compiled with gif support. This is essential for' .
1135 ' TYPO3 CMS to work properly.'
1136 );
1137 }
1138 return $status;
1139 }
1140
1141 /**
1142 * Check jgp support of GD library
1143 *
1144 * @return Status\StatusInterface
1145 */
1146 protected function checkGdLibJpgSupport() {
1147 if (
1148 function_exists('imagecreatefromjpeg')
1149 && function_exists('imagejpeg')
1150 && (imagetypes() & IMG_JPG)
1151 ) {
1152 $status = new Status\OkStatus();
1153 $status->setTitle('PHP GD library has jpg support');
1154 } else {
1155 $status = new Status\ErrorStatus();
1156 $status->setTitle('PHP GD library jpg support missing');
1157 $status->setMessage(
1158 'GD must be compiled with jpg support. This is essential for' .
1159 ' TYPO3 CMS to work properly.'
1160 );
1161 }
1162 return $status;
1163 }
1164
1165 /**
1166 * Check png support of GD library
1167 *
1168 * @return Status\StatusInterface
1169 */
1170 protected function checkGdLibPngSupport() {
1171 if (
1172 function_exists('imagecreatefrompng')
1173 && function_exists('imagepng')
1174 && (imagetypes() & IMG_PNG)
1175 ) {
1176 $imageResource = @imagecreatefrompng(__DIR__ . '/../../Resources/Public/Images/TestInput/Test.png');
1177 if (is_resource($imageResource)) {
1178 imagedestroy($imageResource);
1179 $status = new Status\OkStatus();
1180 $status->setTitle('PHP GD library has png support');
1181 } else {
1182 $status = new Status\ErrorStatus();
1183 $status->setTitle('PHP GD library png support broken');
1184 $status->setMessage(
1185 'GD is compiled with png support, but calling imagecreatefrompng() fails.' .
1186 ' Check your environment and fix it, png in GD lib is important' .
1187 ' for TYPO3 CMS to work properly.'
1188 );
1189 }
1190 } else {
1191 $status = new Status\ErrorStatus();
1192 $status->setTitle('PHP GD library png support missing');
1193 $status->setMessage(
1194 'GD must be compiled with png support. This is essential for' .
1195 ' TYPO3 CMS to work properly'
1196 );
1197 }
1198 return $status;
1199 }
1200
1201 /**
1202 * Check gdlib supports freetype
1203 *
1204 * @return Status\StatusInterface
1205 */
1206 protected function checkGdLibFreeTypeSupport() {
1207 if (function_exists('imagettftext')) {
1208 $status = new Status\OkStatus();
1209 $status->setTitle('PHP GD library has freetype font support');
1210 $status->setMessage(
1211 'There is a difference between the font size setting which the GD' .
1212 ' library should be supplied with. If installation is completed' .
1213 ' a test in the install tool helps to find out the value you need.'
1214 );
1215 } else {
1216 $status = new Status\ErrorStatus();
1217 $status->setTitle('PHP GD library freetype support missing');
1218 $status->setMessage(
1219 'Some core functionality and extension rely on the GD' .
1220 ' to render fonts on images. This support is missing' .
1221 ' in your environment. Install it.'
1222 );
1223 }
1224 return $status;
1225 }
1226
1227 /**
1228 * Create true type font test image
1229 *
1230 * @return Status\StatusInterface
1231 */
1232 protected function isTrueTypeFontWorking() {
1233 if (function_exists('imageftbbox')) {
1234 // 20 Pixels at 96 DPI
1235 $fontSize = (20 / 96 * 72);
1236 $textDimensions = @imageftbbox(
1237 $fontSize,
1238 0,
1239 __DIR__ . '/../../Resources/Private/Font/vera.ttf',
1240 'Testing true type support'
1241 );
1242 $fontBoxWidth = $textDimensions[2] - $textDimensions[0];
1243 if ($fontBoxWidth < 300 && $fontBoxWidth > 200) {
1244 $status = new Status\OkStatus();
1245 $status->setTitle('FreeType True Type Font DPI');
1246 $status->setMessage('Fonts are rendered by FreeType library. ' .
1247 'We need to ensure that the final dimensions are as expected. ' .
1248 'This server renderes fonts based on 96 DPI correctly'
1249 );
1250 } else {
1251 $status = new Status\NoticeStatus();
1252 $status->setTitle('FreeType True Type Font DPI');
1253 $status->setMessage('Fonts are rendered by FreeType library. ' .
1254 'This server does not render fonts as expected. ' .
1255 'Please check your FreeType 2 module.'
1256 );
1257 }
1258 } else {
1259 $status = new Status\ErrorStatus();
1260 $status->setTitle('PHP GD library freetype2 support missing');
1261 $status->setMessage(
1262 'The core relies on GD library compiled into PHP with freetype2' .
1263 ' support. This is missing on your system. Please install it.'
1264 );
1265 }
1266
1267 return $status;
1268 }
1269
1270 /**
1271 * Check register globals
1272 *
1273 * @return Status\StatusInterface
1274 */
1275 protected function checkRegisterGlobals() {
1276 $registerGlobalsEnabled = filter_var(
1277 ini_get('register_globals'),
1278 FILTER_VALIDATE_BOOLEAN,
1279 array(FILTER_REQUIRE_SCALAR, FILTER_NULL_ON_FAILURE)
1280 );
1281 if ($registerGlobalsEnabled === TRUE) {
1282 $status = new Status\ErrorStatus();
1283 $status->setTitle('PHP register globals on');
1284 $status->setMessage(
1285 'register_globals=' . ini_get('register_globals') . LF .
1286 'TYPO3 requires PHP setting "register_globals" set to off.' .
1287 ' This ancient PHP setting is a big security problem and should' .
1288 ' never be enabled:' . LF .
1289 'register_globals=Off'
1290 );
1291 } else {
1292 $status = new Status\OkStatus();
1293 $status->setTitle('PHP register globals off');
1294 }
1295 return $status;
1296 }
1297
1298 /**
1299 * Check for bug in libxml
1300 *
1301 * @return Status\StatusInterface
1302 */
1303 protected function checkLibXmlBug() {
1304 $sampleArray = array('Test>><<Data');
1305
1306 $xmlContent = '<numIndex index="0">Test&gt;&gt;&lt;&lt;Data</numIndex>' . LF;
1307
1308 $xml = \TYPO3\CMS\Core\Utility\GeneralUtility::array2xml($sampleArray, '', -1);
1309
1310 if ($xmlContent !== $xml) {
1311 $status = new Status\ErrorStatus();
1312 $status->setTitle('PHP libxml bug present');
1313 $status->setMessage(
1314 'Some hosts have problems saving ">><<" in a flexform.' .
1315 ' To fix this, enable [BE][flexformForceCDATA] in' .
1316 ' All Configuration.'
1317 );
1318 } else {
1319 $status = new Status\OkStatus();
1320 $status->setTitle('PHP libxml bug not present');
1321 }
1322 return $status;
1323 }
1324
1325 /**
1326 * Helper methods
1327 */
1328
1329 /**
1330 * Validate a given IP address.
1331 *
1332 * @param string $ip IP address to be tested
1333 * @return bool
1334 */
1335 protected function isValidIp($ip) {
1336 return filter_var($ip, FILTER_VALIDATE_IP) !== FALSE;
1337 }
1338
1339 /**
1340 * Test if this instance runs on windows OS
1341 *
1342 * @return bool TRUE if operating system is windows
1343 */
1344 protected function isWindowsOs() {
1345 $windowsOs = FALSE;
1346 if (!stristr(PHP_OS, 'darwin') && stristr(PHP_OS, 'win')) {
1347 $windowsOs = TRUE;
1348 }
1349 return $windowsOs;
1350 }
1351
1352 /**
1353 * Helper method to find out if suhosin extension is loaded
1354 *
1355 * @return bool TRUE if suhosin PHP extension is loaded
1356 */
1357 protected function isSuhosinLoadedAndActive() {
1358 $suhosinLoaded = FALSE;
1359 if (extension_loaded('suhosin')) {
1360 $suhosinInSimulationMode = filter_var(
1361 ini_get('suhosin.simulation'),
1362 FILTER_VALIDATE_BOOLEAN,
1363 array(FILTER_REQUIRE_SCALAR, FILTER_NULL_ON_FAILURE)
1364 );
1365 if (!$suhosinInSimulationMode) {
1366 $suhosinLoaded = TRUE;
1367 }
1368 }
1369 return $suhosinLoaded;
1370 }
1371
1372 /**
1373 * Helper method to explode a string by delimiter and throw away empty values.
1374 * Removes empty values from result array.
1375 *
1376 * @param string $delimiter Delimiter string to explode with
1377 * @param string $string The string to explode
1378 * @return array Exploded values
1379 */
1380 protected function trimExplode($delimiter, $string) {
1381 $explodedValues = explode($delimiter, $string);
1382 $resultWithPossibleEmptyValues = array_map('trim', $explodedValues);
1383 $result = array();
1384 foreach ($resultWithPossibleEmptyValues as $value) {
1385 if ($value !== '') {
1386 $result[] = $value;
1387 }
1388 }
1389 return $result;
1390 }
1391
1392 /**
1393 * Helper method to get the bytes value from a measurement string like "100k".
1394 *
1395 * @param string $measurement The measurement (e.g. "100k")
1396 * @return int The bytes value (e.g. 102400)
1397 */
1398 protected function getBytesFromSizeMeasurement($measurement) {
1399 $bytes = doubleval($measurement);
1400 if (stripos($measurement, 'G')) {
1401 $bytes *= 1024 * 1024 * 1024;
1402 } elseif (stripos($measurement, 'M')) {
1403 $bytes *= 1024 * 1024;
1404 } elseif (stripos($measurement, 'K')) {
1405 $bytes *= 1024;
1406 }
1407 return (int)$bytes;
1408 }
1409
1410 }