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