‪TYPO3CMS  ‪main
SetupCheck.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
25 
38 {
42  protected ‪$messageQueue;
43 
47  public function ‪getStatus(): ‪FlashMessageQueue
48  {
49  $this->messageQueue = new ‪FlashMessageQueue('install');
50 
53  $this->‪checkSystemLocale();
56  $this->‪isTrueTypeFontWorking();
57  $this->‪checkLibXmlBug();
58 
60  }
61 
65  protected function ‪checkTrustedHostPattern()
66  {
67  if (‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['trustedHostsPattern'] === ‪VerifyHostHeader::ENV_TRUSTED_HOSTS_PATTERN_ALLOW_ALL) {
68  $this->messageQueue->enqueue(new ‪FlashMessage(
69  'Trusted hosts pattern is configured to allow all header values. Check the pattern defined in Admin'
70  . ' Tools -> Settings -> Configure Installation-Wide Options -> System -> trustedHostsPattern'
71  . ' and adapt it to expected host value(s).',
72  'Trusted hosts pattern is insecure',
73  ContextualFeedbackSeverity::WARNING
74  ));
75  } else {
76  $verifyHostHeader = new ‪VerifyHostHeader(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['trustedHostsPattern'] ?? '');
77  if ($verifyHostHeader->isAllowedHostHeaderValue($_SERVER['HTTP_HOST'], $_SERVER)) {
78  $this->messageQueue->enqueue(new ‪FlashMessage(
79  '',
80  'Trusted hosts pattern is configured to allow current host value.'
81  ));
82  } else {
83  $this->messageQueue->enqueue(new ‪FlashMessage(
84  'The trusted hosts pattern will be configured to allow all header values. This is because your $SERVER_NAME:$SERVER_PORT'
85  . ' is "' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . '" while your HTTP_HOST is "'
86  . $_SERVER['HTTP_HOST'] . '". Check the pattern defined in Admin'
87  . ' Tools -> Settings -> Configure Installation-Wide Options -> System -> trustedHostsPattern'
88  . ' and adapt it to expected host value(s).',
89  'Trusted hosts pattern mismatch',
90  ContextualFeedbackSeverity::ERROR
91  ));
92  }
93  }
94  }
95 
100  protected function ‪checkDownloadsPossible()
101  {
102  $allowUrlFopen = (bool)ini_get('allow_url_fopen');
103  $curlEnabled = function_exists('curl_version');
104  if ($allowUrlFopen || $curlEnabled) {
105  $this->messageQueue->enqueue(new ‪FlashMessage(
106  '',
107  'Fetching external URLs is allowed'
108  ));
109  } else {
110  $this->messageQueue->enqueue(new ‪FlashMessage(
111  'Either enable PHP runtime setting "allow_url_fopen"' . LF . 'or compile curl into your PHP with --with-curl.',
112  'Fetching external URLs is not allowed',
113  ContextualFeedbackSeverity::WARNING
114  ));
115  }
116  }
117 
121  protected function ‪checkSystemLocale()
122  {
123  $currentLocale = (string)setlocale(LC_CTYPE, '0');
124 
125  // On Windows an empty locale value uses the regional settings from the Control Panel
126  if (‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale'] === '' && !‪Environment::isWindows()) {
127  $this->messageQueue->enqueue(new ‪FlashMessage(
128  '$GLOBALS[TYPO3_CONF_VARS][SYS][systemLocale] is not set. This is fine as long as no UTF-8 file system is used.',
129  'Empty systemLocale setting',
130  ContextualFeedbackSeverity::INFO
131  ));
132  } elseif (setlocale(LC_CTYPE, ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale']) === false) {
133  $this->messageQueue->enqueue(new ‪FlashMessage(
134  'Current value of the $GLOBALS[TYPO3_CONF_VARS][SYS][systemLocale] is incorrect. A locale with'
135  . ' this name doesn\'t exist in the operating system.',
136  'Incorrect systemLocale setting',
137  ContextualFeedbackSeverity::ERROR
138  ));
139  setlocale(LC_CTYPE, $currentLocale);
140  } else {
141  $this->messageQueue->enqueue(new ‪FlashMessage(
142  '',
143  'System locale is correct'
144  ));
145  }
146  }
147 
152  protected function ‪checkLocaleWithUTF8filesystem()
153  {
154  if (‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']) {
155  // On Windows an empty local value uses the regional settings from the Control Panel
156  if (‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale'] === '' && !‪Environment::isWindows()) {
157  $this->messageQueue->enqueue(new ‪FlashMessage(
158  '$GLOBALS[TYPO3_CONF_VARS][SYS][UTF8filesystem] is set, but $GLOBALS[TYPO3_CONF_VARS][SYS][systemLocale]'
159  . ' is empty. Make sure a valid locale which supports UTF-8 is set.',
160  'System locale not set on UTF-8 file system',
161  ContextualFeedbackSeverity::ERROR
162  ));
163  } else {
164  $testString = 'ÖöĄĆŻĘĆćążąęó.jpg';
165  $currentLocale = (string)setlocale(LC_CTYPE, '0');
166  $quote = ‪Environment::isWindows() ? '"' : '\'';
167  setlocale(LC_CTYPE, ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale']);
168  if (escapeshellarg($testString) === $quote . $testString . $quote) {
169  $this->messageQueue->enqueue(new ‪FlashMessage(
170  '',
171  'File names with UTF-8 characters can be used.'
172  ));
173  } else {
174  $this->messageQueue->enqueue(new ‪FlashMessage(
175  'Please check your $GLOBALS[TYPO3_CONF_VARS][SYS][systemLocale] setting.',
176  'System locale setting doesn\'t support UTF-8 file names.',
177  ContextualFeedbackSeverity::ERROR
178  ));
179  }
180  setlocale(LC_CTYPE, $currentLocale);
181  }
182  } else {
183  $this->messageQueue->enqueue(new ‪FlashMessage(
184  '',
185  'Skipping test, as UTF8filesystem is not enabled.'
186  ));
187  }
188  }
189 
193  protected function ‪checkSomePhpOpcodeCacheIsLoaded()
194  {
195  $opcodeCaches = GeneralUtility::makeInstance(OpcodeCacheService::class)->getAllActive();
196  if (empty($opcodeCaches)) {
197  // Set status to notice. It needs to be notice so email won't be triggered.
198  $this->messageQueue->enqueue(new ‪FlashMessage(
199  'PHP opcode caches hold a compiled version of executed PHP scripts in'
200  . ' memory and do not require to recompile a script each time it is accessed.'
201  . ' This can be a massive performance improvement and can reduce the load on a'
202  . ' server in general. A parse time reduction by factor three for fully cached'
203  . ' pages can be achieved easily if using an opcode cache.',
204  'No PHP opcode cache loaded',
205  ContextualFeedbackSeverity::NOTICE
206  ));
207  } else {
208  $status = ContextualFeedbackSeverity::OK;
209  $message = '';
210  foreach ($opcodeCaches as $opcodeCache => $properties) {
211  $message .= 'Name: ' . $opcodeCache . ' Version: ' . $properties['version'];
212  $message .= LF;
213  if ($properties['warning']) {
214  $status = ContextualFeedbackSeverity::WARNING;
215  $message .= ' ' . $properties['warning'];
216  } else {
217  $message .= ' This opcode cache should work correctly and has good performance.';
218  }
219  $message .= LF;
220  }
221  // Set title of status depending on severity
222  switch ($status) {
223  case ContextualFeedbackSeverity::WARNING:
224  $title = 'A possibly malfunctioning PHP opcode cache is loaded';
225  break;
226  case ContextualFeedbackSeverity::OK:
227  default:
228  $title = 'A PHP opcode cache is loaded';
229  break;
230  }
231  $this->messageQueue->enqueue(new ‪FlashMessage(
232  $message,
233  $title,
234  $status
235  ));
236  }
237  }
238 
242  protected function ‪isTrueTypeFontWorking()
243  {
244  if (function_exists('imageftbbox')) {
245  // 20 Pixels at 96 DPI
246  $fontSize = (20 / 96 * 72);
247  $textDimensions = @imageftbbox(
248  $fontSize,
249  0,
250  __DIR__ . '/../../Resources/Private/Font/vera.ttf',
251  'Testing true type support'
252  );
253  $fontBoxWidth = $textDimensions[2] - $textDimensions[0];
254  if ($fontBoxWidth < 300 && $fontBoxWidth > 200) {
255  $this->messageQueue->enqueue(new ‪FlashMessage(
256  'Fonts are rendered by FreeType library. '
257  . 'We need to ensure that the final dimensions are as expected. '
258  . 'This server renderes fonts based on 96 DPI correctly',
259  'FreeType True Type Font DPI'
260  ));
261  } else {
262  $this->messageQueue->enqueue(new ‪FlashMessage(
263  'Fonts are rendered by FreeType library. '
264  . 'This server does not render fonts as expected. '
265  . 'Please check your FreeType 2 module.',
266  'FreeType True Type Font DPI',
267  ContextualFeedbackSeverity::NOTICE
268  ));
269  }
270  } else {
271  $this->messageQueue->enqueue(new ‪FlashMessage(
272  'The core relies on GD library compiled into PHP with freetype2'
273  . ' support. This is missing on your system. Please install it.',
274  'PHP GD library freetype2 support missing',
275  ContextualFeedbackSeverity::ERROR
276  ));
277  }
278  }
279 
283  protected function ‪checkLibXmlBug()
284  {
285  $sampleArray = ['Test>><<Data'];
286  $xmlContent = '<numIndex index="0">Test&gt;&gt;&lt;&lt;Data</numIndex>' . LF;
287  $xml = GeneralUtility::array2xml($sampleArray, '', -1);
288  if ($xmlContent !== $xml) {
289  $this->messageQueue->enqueue(new ‪FlashMessage(
290  'Some hosts have problems saving ">><<" in a flexform.'
291  . ' To fix this, enable [BE][flexformForceCDATA] in'
292  . ' All Configuration.',
293  'PHP libxml bug present',
294  ContextualFeedbackSeverity::ERROR
295  ));
296  } else {
297  $this->messageQueue->enqueue(new ‪FlashMessage(
298  '',
299  'PHP libxml bug not present'
300  ));
301  }
302  }
303 }
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck\checkLocaleWithUTF8filesystem
‪checkLocaleWithUTF8filesystem()
Definition: SetupCheck.php:151
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck\checkDownloadsPossible
‪checkDownloadsPossible()
Definition: SetupCheck.php:99
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck\checkTrustedHostPattern
‪checkTrustedHostPattern()
Definition: SetupCheck.php:64
‪TYPO3\CMS\Install\SystemEnvironment\CheckInterface
Definition: CheckInterface.php:31
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck\checkSomePhpOpcodeCacheIsLoaded
‪checkSomePhpOpcodeCacheIsLoaded()
Definition: SetupCheck.php:192
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck\getStatus
‪getStatus()
Definition: SetupCheck.php:46
‪TYPO3\CMS\Core\Type\ContextualFeedbackSeverity
‪ContextualFeedbackSeverity
Definition: ContextualFeedbackSeverity.php:25
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck\checkSystemLocale
‪checkSystemLocale()
Definition: SetupCheck.php:120
‪TYPO3\CMS\Install\SystemEnvironment
Definition: Check.php:18
‪TYPO3\CMS\Core\Middleware\VerifyHostHeader\ENV_TRUSTED_HOSTS_PATTERN_ALLOW_ALL
‪const ENV_TRUSTED_HOSTS_PATTERN_ALLOW_ALL
Definition: VerifyHostHeader.php:32
‪TYPO3\CMS\Core\Service\OpcodeCacheService
Definition: OpcodeCacheService.php:27
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:27
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck\isTrueTypeFontWorking
‪isTrueTypeFontWorking()
Definition: SetupCheck.php:241
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck
Definition: SetupCheck.php:38
‪TYPO3\CMS\Core\Middleware\VerifyHostHeader
Definition: VerifyHostHeader.php:31
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck\checkLibXmlBug
‪checkLibXmlBug()
Definition: SetupCheck.php:282
‪TYPO3\CMS\Core\Messaging\FlashMessageQueue
Definition: FlashMessageQueue.php:30
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck\$messageQueue
‪FlashMessageQueue $messageQueue
Definition: SetupCheck.php:41
‪TYPO3\CMS\Core\Core\Environment\isWindows
‪static isWindows()
Definition: Environment.php:276