‪TYPO3CMS  9.5
SetupCheck.php
Go to the documentation of this file.
1 <?php
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 
22 
35 {
39  protected ‪$messageQueue;
40 
46  public function ‪getStatus(): ‪FlashMessageQueue
47  {
48  $this->messageQueue = new ‪FlashMessageQueue('install');
49 
52  $this->‪checkSystemLocale();
55  $this->‪isTrueTypeFontWorking();
56  $this->‪checkLibXmlBug();
57 
59  }
60 
64  protected function ‪checkTrustedHostPattern()
65  {
66  if (‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['trustedHostsPattern'] === ‪GeneralUtility::ENV_TRUSTED_HOSTS_PATTERN_ALLOW_ALL) {
67  $this->messageQueue->enqueue(new ‪FlashMessage(
68  'Trusted hosts pattern is configured to allow all header values. Check the pattern defined in Admin'
69  . ' Tools -> Settings -> Configure Installation-Wide Options -> System -> trustedHostsPattern'
70  . ' and adapt it to expected host value(s).',
71  'Trusted hosts pattern is insecure',
73  ));
74  } else {
75  if (GeneralUtility::hostHeaderValueMatchesTrustedHostsPattern($_SERVER['HTTP_HOST'])) {
76  $this->messageQueue->enqueue(new ‪FlashMessage(
77  '',
78  'Trusted hosts pattern is configured to allow current host value.'
79  ));
80  } else {
81  $defaultPort = GeneralUtility::getIndpEnv('TYPO3_SSL') ? '443' : '80';
82  $this->messageQueue->enqueue(new ‪FlashMessage(
83  'The trusted hosts pattern will be configured to allow all header values. This is because your $SERVER_NAME:[defaultPort]'
84  . ' is "' . $_SERVER['SERVER_NAME'] . ':' . $defaultPort . '" while your HTTP_HOST:SERVER_PORT is "'
85  . $_SERVER['HTTP_HOST'] . ':' . $_SERVER['SERVER_PORT'] . '". Check the pattern defined in Admin'
86  . ' Tools -> Settings -> Configure Installation-Wide Options -> System -> trustedHostsPattern'
87  . ' and adapt it to expected host value(s).',
88  'Trusted hosts pattern mismatch',
90  ));
91  }
92  }
93  }
94 
99  protected function ‪checkDownloadsPossible()
100  {
101  $allowUrlFopen = (bool)ini_get('allow_url_fopen');
102  $curlEnabled = function_exists('curl_version');
103  if ($allowUrlFopen || $curlEnabled) {
104  $this->messageQueue->enqueue(new ‪FlashMessage(
105  '',
106  'Fetching external URLs is allowed'
107  ));
108  } else {
109  $this->messageQueue->enqueue(new ‪FlashMessage(
110  'Either enable PHP runtime setting "allow_url_fopen"' . LF . 'or compile curl into your PHP with --with-curl.',
111  'Fetching external URLs is not allowed',
113  ));
114  }
115  }
116 
120  protected function ‪checkSystemLocale()
121  {
122  $currentLocale = setlocale(LC_CTYPE, 0);
123 
124  // On Windows an empty locale value uses the regional settings from the Control Panel
125  if (‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale'] === '' && !‪Environment::isWindows()) {
126  $this->messageQueue->enqueue(new ‪FlashMessage(
127  '$GLOBALS[TYPO3_CONF_VARS][SYS][systemLocale] is not set. This is fine as long as no UTF-8 file system is used.',
128  'Empty systemLocale setting',
130  ));
131  } elseif (setlocale(LC_CTYPE, ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale']) === false) {
132  $this->messageQueue->enqueue(new ‪FlashMessage(
133  'Current value of the $GLOBALS[TYPO3_CONF_VARS][SYS][systemLocale] is incorrect. A locale with'
134  . ' this name doesn\'t exist in the operating system.',
135  'Incorrect systemLocale setting',
137  ));
138  setlocale(LC_CTYPE, $currentLocale);
139  } else {
140  $this->messageQueue->enqueue(new ‪FlashMessage(
141  '',
142  'System locale is correct'
143  ));
144  }
145  }
146 
151  protected function ‪checkLocaleWithUTF8filesystem()
152  {
153  if (‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']) {
154  // On Windows an empty local value uses the regional settings from the Control Panel
155  if (‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale'] === '' && !‪Environment::isWindows()) {
156  $this->messageQueue->enqueue(new ‪FlashMessage(
157  '$GLOBALS[TYPO3_CONF_VARS][SYS][UTF8filesystem] is set, but $GLOBALS[TYPO3_CONF_VARS][SYS][systemLocale]'
158  . ' is empty. Make sure a valid locale which supports UTF-8 is set.',
159  'System locale not set on UTF-8 file system',
161  ));
162  } else {
163  $testString = 'ÖöĄĆŻĘĆćążąęó.jpg';
164  $currentLocale = setlocale(LC_CTYPE, 0);
165  $quote = ‪Environment::isWindows() ? '"' : '\'';
166  setlocale(LC_CTYPE, ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale']);
167  if (escapeshellarg($testString) === $quote . $testString . $quote) {
168  $this->messageQueue->enqueue(new ‪FlashMessage(
169  '',
170  'File names with UTF-8 characters can be used.'
171  ));
172  } else {
173  $this->messageQueue->enqueue(new ‪FlashMessage(
174  'Please check your $GLOBALS[TYPO3_CONF_VARS][SYS][systemLocale] setting.',
175  'System locale setting doesn\'t support UTF-8 file names.',
177  ));
178  }
179  setlocale(LC_CTYPE, $currentLocale);
180  }
181  } else {
182  $this->messageQueue->enqueue(new ‪FlashMessage(
183  '',
184  'Skipping test, as UTF8filesystem is not enabled.'
185  ));
186  }
187  }
188 
192  protected function ‪checkSomePhpOpcodeCacheIsLoaded()
193  {
194  // Link to our documentation page, so we can update opcode cache issue information independent of TYPO3 CMS releases.
195  $documentationLink = 'For more information take a look in our documentation ' . TYPO3_URL_WIKI_OPCODECACHE . '.';
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  . LF . $documentationLink,
206  'No PHP opcode cache loaded',
208  ));
209  } else {
210  $status = ‪FlashMessage::OK;
211  $message = '';
212  foreach ($opcodeCaches as $opcodeCache => $properties) {
213  $message .= 'Name: ' . $opcodeCache . ' Version: ' . $properties['version'];
214  $message .= LF;
215  if ($properties['error']) {
216  $status = ‪FlashMessage::ERROR;
217  $message .= ' This opcode cache is marked as malfunctioning by the TYPO3 CMS Team.';
218  } elseif ($properties['canInvalidate']) {
219  $message .= ' This opcode cache should work correctly and has good performance.';
220  } else {
221  // Set status to notice if not already error set. It needs to be notice so email won't be triggered.
222  if ($status !== ‪FlashMessage::ERROR) {
223  $status = ‪FlashMessage::NOTICE;
224  }
225  $message .= ' This opcode cache may work correctly but has medium performance.';
226  }
227  $message .= LF;
228  }
229  $message .= $documentationLink;
230  // Set title of status depending on serverity
231  switch ($status) {
233  $title = 'A possibly malfunctioning PHP opcode cache is loaded';
234  break;
235  case ‪FlashMessage::OK:
236  default:
237  $title = 'A PHP opcode cache is loaded';
238  break;
239  }
240  $this->messageQueue->enqueue(new ‪FlashMessage(
241  $message,
242  $title,
243  $status
244  ));
245  }
246  }
247 
251  protected function ‪isTrueTypeFontWorking()
252  {
253  if (function_exists('imageftbbox')) {
254  // 20 Pixels at 96 DPI
255  $fontSize = (20 / 96 * 72);
256  $textDimensions = @imageftbbox(
257  $fontSize,
258  0,
259  __DIR__ . '/../../Resources/Private/Font/vera.ttf',
260  'Testing true type support'
261  );
262  $fontBoxWidth = $textDimensions[2] - $textDimensions[0];
263  if ($fontBoxWidth < 300 && $fontBoxWidth > 200) {
264  $this->messageQueue->enqueue(new ‪FlashMessage(
265  'Fonts are rendered by FreeType library. '
266  . 'We need to ensure that the final dimensions are as expected. '
267  . 'This server renderes fonts based on 96 DPI correctly',
268  'FreeType True Type Font DPI'
269  ));
270  } else {
271  $this->messageQueue->enqueue(new ‪FlashMessage(
272  'Fonts are rendered by FreeType library. '
273  . 'This server does not render fonts as expected. '
274  . 'Please check your FreeType 2 module.',
275  'FreeType True Type Font DPI',
277  ));
278  }
279  } else {
280  $this->messageQueue->enqueue(new ‪FlashMessage(
281  'The core relies on GD library compiled into PHP with freetype2'
282  . ' support. This is missing on your system. Please install it.',
283  'PHP GD library freetype2 support missing',
285  ));
286  }
287  }
288 
292  protected function ‪checkLibXmlBug()
293  {
294  $sampleArray = ['Test>><<Data'];
295  $xmlContent = '<numIndex index="0">Test&gt;&gt;&lt;&lt;Data</numIndex>' . LF;
296  $xml = GeneralUtility::array2xml($sampleArray, '', -1);
297  if ($xmlContent !== $xml) {
298  $this->messageQueue->enqueue(new ‪FlashMessage(
299  'Some hosts have problems saving ">><<" in a flexform.'
300  . ' To fix this, enable [BE][flexformForceCDATA] in'
301  . ' All Configuration.',
302  'PHP libxml bug present',
304  ));
305  } else {
306  $this->messageQueue->enqueue(new ‪FlashMessage(
307  '',
308  'PHP libxml bug not present'
309  ));
310  }
311  }
312 }
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck\getStatus
‪FlashMessageQueue getStatus()
Definition: SetupCheck.php:45
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck\checkLocaleWithUTF8filesystem
‪checkLocaleWithUTF8filesystem()
Definition: SetupCheck.php:150
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck\checkDownloadsPossible
‪checkDownloadsPossible()
Definition: SetupCheck.php:98
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck\checkTrustedHostPattern
‪checkTrustedHostPattern()
Definition: SetupCheck.php:63
‪TYPO3\CMS\Install\SystemEnvironment\CheckInterface
Definition: CheckInterface.php:31
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck\checkSomePhpOpcodeCacheIsLoaded
‪checkSomePhpOpcodeCacheIsLoaded()
Definition: SetupCheck.php:191
‪TYPO3\CMS\Core\Core\Environment\isWindows
‪static bool isWindows()
Definition: Environment.php:266
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck\checkSystemLocale
‪checkSystemLocale()
Definition: SetupCheck.php:119
‪TYPO3\CMS\Core\Messaging\AbstractMessage\WARNING
‪const WARNING
Definition: AbstractMessage.php:28
‪TYPO3\CMS\Core\Utility\GeneralUtility\ENV_TRUSTED_HOSTS_PATTERN_ALLOW_ALL
‪const ENV_TRUSTED_HOSTS_PATTERN_ALLOW_ALL
Definition: GeneralUtility.php:54
‪TYPO3\CMS\Install\SystemEnvironment
Definition: Check.php:2
‪TYPO3\CMS\Core\Service\OpcodeCacheService
Definition: OpcodeCacheService.php:24
‪TYPO3\CMS\Core\Messaging\AbstractMessage\OK
‪const OK
Definition: AbstractMessage.php:27
‪TYPO3\CMS\Core\Messaging\AbstractMessage\INFO
‪const INFO
Definition: AbstractMessage.php:26
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:22
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck\isTrueTypeFontWorking
‪isTrueTypeFontWorking()
Definition: SetupCheck.php:250
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck
Definition: SetupCheck.php:35
‪TYPO3\CMS\Core\Messaging\AbstractMessage\NOTICE
‪const NOTICE
Definition: AbstractMessage.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck\checkLibXmlBug
‪checkLibXmlBug()
Definition: SetupCheck.php:291
‪TYPO3\CMS\Core\Messaging\FlashMessageQueue
Definition: FlashMessageQueue.php:25
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck\$messageQueue
‪FlashMessageQueue $messageQueue
Definition: SetupCheck.php:38
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:29