‪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 
59  }
60 
64  protected function ‪checkTrustedHostPattern()
65  {
66  if (‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['trustedHostsPattern'] === ‪VerifyHostHeader::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',
72  ContextualFeedbackSeverity::WARNING
73  ));
74  } else {
75  $verifyHostHeader = new ‪VerifyHostHeader(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['trustedHostsPattern'] ?? '');
76  if ($verifyHostHeader->isAllowedHostHeaderValue(‪$_SERVER['HTTP_HOST'], ‪$_SERVER)) {
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',
89  ContextualFeedbackSeverity::ERROR
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',
112  ContextualFeedbackSeverity::WARNING
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',
129  ContextualFeedbackSeverity::INFO
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',
136  ContextualFeedbackSeverity::ERROR
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',
160  ContextualFeedbackSeverity::ERROR
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.',
176  ContextualFeedbackSeverity::ERROR
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',
204  ContextualFeedbackSeverity::NOTICE
205  ));
206  } else {
207  $status = ContextualFeedbackSeverity::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 = ContextualFeedbackSeverity::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) {
222  case ContextualFeedbackSeverity::WARNING:
223  $title = 'A possibly malfunctioning PHP opcode cache is loaded';
224  break;
225  case ContextualFeedbackSeverity::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',
266  ContextualFeedbackSeverity::NOTICE
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',
274  ContextualFeedbackSeverity::ERROR
275  ));
276  }
277  }
278 }
‪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\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:119
‪TYPO3\CMS\Install\SystemEnvironment
Definition: Check.php:18
‪$_SERVER
‪$_SERVER['TYPO3_DEPRECATED_ENTRYPOINT']
Definition: legacy-backend.php:20
‪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:240
‪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:52
‪TYPO3\CMS\Core\Messaging\FlashMessageQueue
Definition: FlashMessageQueue.php:29
‪TYPO3\CMS\Install\SystemEnvironment\SetupCheck\$messageQueue
‪FlashMessageQueue $messageQueue
Definition: SetupCheck.php:41
‪TYPO3\CMS\Core\Core\Environment\isWindows
‪static isWindows()
Definition: Environment.php:276