‪TYPO3CMS  10.4
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 
23 
36 {
40  protected ‪$messageQueue;
41 
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'] === ‪GeneralUtility::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',
74  ));
75  } else {
76  if (GeneralUtility::hostHeaderValueMatchesTrustedHostsPattern($_SERVER['HTTP_HOST'])) {
77  $this->messageQueue->enqueue(new ‪FlashMessage(
78  '',
79  'Trusted hosts pattern is configured to allow current host value.'
80  ));
81  } else {
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:$SERVER_PORT'
84  . ' is "' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . '" while your HTTP_HOST is "'
85  . $_SERVER['HTTP_HOST'] . '". 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 = (string)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 = (string)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  $opcodeCaches = GeneralUtility::makeInstance(OpcodeCacheService::class)->getAllActive();
195  if (empty($opcodeCaches)) {
196  // Set status to notice. It needs to be notice so email won't be triggered.
197  $this->messageQueue->enqueue(new ‪FlashMessage(
198  'PHP opcode caches hold a compiled version of executed PHP scripts in'
199  . ' memory and do not require to recompile a script each time it is accessed.'
200  . ' This can be a massive performance improvement and can reduce the load on a'
201  . ' server in general. A parse time reduction by factor three for fully cached'
202  . ' pages can be achieved easily if using an opcode cache.',
203  'No PHP opcode cache loaded',
205  ));
206  } else {
207  $status = ‪FlashMessage::OK;
208  $message = '';
209  foreach ($opcodeCaches as $opcodeCache => $properties) {
210  $message .= 'Name: ' . $opcodeCache . ' Version: ' . $properties['version'];
211  $message .= LF;
212  if ($properties['warning']) {
213  $status = ‪FlashMessage::WARNING;
214  $message .= ' ' . $properties['warning'];
215  } else {
216  $message .= ' This opcode cache should work correctly and has good performance.';
217  }
218  $message .= LF;
219  }
220  // Set title of status depending on severity
221  switch ($status) {
223  $title = 'A possibly malfunctioning PHP opcode cache is loaded';
224  break;
225  case ‪FlashMessage::OK:
226  default:
227  $title = 'A PHP opcode cache is loaded';
228  break;
229  }
230  $this->messageQueue->enqueue(new ‪FlashMessage(
231  $message,
232  $title,
233  $status
234  ));
235  }
236  }
237 
241  protected function ‪isTrueTypeFontWorking()
242  {
243  if (function_exists('imageftbbox')) {
244  // 20 Pixels at 96 DPI
245  $fontSize = (20 / 96 * 72);
246  $textDimensions = @imageftbbox(
247  $fontSize,
248  0,
249  __DIR__ . '/../../Resources/Private/Font/vera.ttf',
250  'Testing true type support'
251  );
252  $fontBoxWidth = $textDimensions[2] - $textDimensions[0];
253  if ($fontBoxWidth < 300 && $fontBoxWidth > 200) {
254  $this->messageQueue->enqueue(new ‪FlashMessage(
255  'Fonts are rendered by FreeType library. '
256  . 'We need to ensure that the final dimensions are as expected. '
257  . 'This server renderes fonts based on 96 DPI correctly',
258  'FreeType True Type Font DPI'
259  ));
260  } else {
261  $this->messageQueue->enqueue(new ‪FlashMessage(
262  'Fonts are rendered by FreeType library. '
263  . 'This server does not render fonts as expected. '
264  . 'Please check your FreeType 2 module.',
265  'FreeType True Type Font DPI',
267  ));
268  }
269  } else {
270  $this->messageQueue->enqueue(new ‪FlashMessage(
271  'The core relies on GD library compiled into PHP with freetype2'
272  . ' support. This is missing on your system. Please install it.',
273  'PHP GD library freetype2 support missing',
275  ));
276  }
277  }
278 
282  protected function ‪checkLibXmlBug()
283  {
284  $sampleArray = ['Test>><<Data'];
285  $xmlContent = '<numIndex index="0">Test&gt;&gt;&lt;&lt;Data</numIndex>' . LF;
286  $xml = GeneralUtility::array2xml($sampleArray, '', -1);
287  if ($xmlContent !== $xml) {
288  $this->messageQueue->enqueue(new ‪FlashMessage(
289  'Some hosts have problems saving ">><<" in a flexform.'
290  . ' To fix this, enable [BE][flexformForceCDATA] in'
291  . ' All Configuration.',
292  'PHP libxml bug present',
294  ));
295  } else {
296  $this->messageQueue->enqueue(new ‪FlashMessage(
297  '',
298  'PHP libxml bug not present'
299  ));
300  }
301  }
302 }
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck\getStatus
‪FlashMessageQueue getStatus()
Definition: SetupCheck.php:46
‪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:64
‪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:292
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck\checkSystemLocale
‪checkSystemLocale()
Definition: SetupCheck.php:119
‪TYPO3\CMS\Core\Messaging\AbstractMessage\WARNING
‪const WARNING
Definition: AbstractMessage.php:30
‪TYPO3\CMS\Core\Utility\GeneralUtility\ENV_TRUSTED_HOSTS_PATTERN_ALLOW_ALL
‪const ENV_TRUSTED_HOSTS_PATTERN_ALLOW_ALL
Definition: GeneralUtility.php:47
‪TYPO3\CMS\Install\SystemEnvironment
Definition: Check.php:18
‪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:24
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck\isTrueTypeFontWorking
‪isTrueTypeFontWorking()
Definition: SetupCheck.php:240
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck
Definition: SetupCheck.php:36
‪TYPO3\CMS\Core\Messaging\AbstractMessage\NOTICE
‪const NOTICE
Definition: AbstractMessage.php:27
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck\checkLibXmlBug
‪checkLibXmlBug()
Definition: SetupCheck.php:281
‪TYPO3\CMS\Core\Messaging\FlashMessageQueue
Definition: FlashMessageQueue.php:29
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck\$messageQueue
‪FlashMessageQueue $messageQueue
Definition: SetupCheck.php:39
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31