[BUGFIX] Re-enable environment status report in Backend
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / SystemEnvironment / SetupCheck.php
1 <?php
2 namespace TYPO3\CMS\Install\SystemEnvironment;
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
17 use TYPO3\CMS\Core\Service\OpcodeCacheService;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Install\Status;
20
21 /**
22 * Check TYPO3 setup status
23 *
24 * This class is a hardcoded requirement check for the TYPO3 setup.
25 *
26 * The status messages and title *must not* include HTML, use plain
27 * text only. The return values of this class are not bound to HTML
28 * and can be used in different scopes (eg. as json array).
29 */
30 class SetupCheck
31 {
32 /**
33 * Get all status information as array with status objects
34 *
35 * @return array<\TYPO3\CMS\Install\Status\StatusInterface>
36 */
37 public function getStatus()
38 {
39 $status = [];
40
41 $status[] = $this->checkTrustedHostPattern();
42 $status[] = $this->checkDownloadsPossible();
43 $status[] = $this->checkSystemLocale();
44 $status[] = $this->checkLocaleWithUTF8filesystem();
45 $status[] = $this->checkSomePhpOpcodeCacheIsLoaded();
46 $status[] = $this->isTrueTypeFontWorking();
47 $status[] = $this->checkLibXmlBug();
48
49 return $status;
50 }
51
52 /**
53 * Checks the status of the trusted hosts pattern check
54 *
55 * @return Status\StatusInterface
56 */
57 protected function checkTrustedHostPattern()
58 {
59 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['trustedHostsPattern'] === GeneralUtility::ENV_TRUSTED_HOSTS_PATTERN_ALLOW_ALL) {
60 $status = new Status\WarningStatus();
61 $status->setTitle('Trusted hosts pattern is insecure');
62 $status->setMessage('Trusted hosts pattern is configured to allow all header values. Check the pattern defined in Install Tool -> All configuration -> System -> trustedHostsPattern and adapt it to expected host value(s).');
63 } else {
64 if (GeneralUtility::hostHeaderValueMatchesTrustedHostsPattern($_SERVER['HTTP_HOST'])) {
65 $status = new Status\OkStatus();
66 $status->setTitle('Trusted hosts pattern is configured to allow current host value.');
67 } else {
68 $status = new Status\ErrorStatus();
69 $status->setTitle('Trusted hosts pattern mismatch');
70 $status->setMessage('The trusted hosts pattern will be configured to allow all header values. This is because your $SERVER_NAME is "' . htmlspecialchars($_SERVER['SERVER_NAME']) . '" while your HTTP_HOST is "' . htmlspecialchars($_SERVER['HTTP_HOST']) . '". Check the pattern defined in Install Tool -> All configuration -> System -> trustedHostsPattern and adapt it to expected host value(s).');
71 }
72 }
73
74 return $status;
75 }
76
77 /**
78 * Check if it is possible to download external data (e.g. TER)
79 * Either allow_url_fopen must be enabled or curl must be used
80 *
81 * @return Status\OkStatus|Status\WarningStatus
82 */
83 protected function checkDownloadsPossible()
84 {
85 $allowUrlFopen = (bool)ini_get('allow_url_fopen');
86 $curlEnabled = function_exists('curl_version');
87 if ($allowUrlFopen || $curlEnabled) {
88 $status = new Status\OkStatus();
89 $status->setTitle('Fetching external URLs is allowed');
90 } else {
91 $status = new Status\WarningStatus();
92 $status->setTitle('Fetching external URLs is not allowed');
93 $status->setMessage(
94 'Either enable PHP runtime setting "allow_url_fopen"' . LF . 'or compile curl into your PHP with --with-curl.'
95 );
96 }
97
98 return $status;
99 }
100
101 /**
102 * Check if systemLocale setting is correct (locale exists in the OS)
103 *
104 * @return Status\StatusInterface
105 */
106 protected function checkSystemLocale()
107 {
108 $currentLocale = setlocale(LC_CTYPE, 0);
109
110 // On Windows an empty locale value uses the regional settings from the Control Panel
111 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale'] === '' && TYPO3_OS !== 'WIN') {
112 $status = new Status\InfoStatus();
113 $status->setTitle('Empty systemLocale setting');
114 $status->setMessage(
115 '$GLOBALS[TYPO3_CONF_VARS][SYS][systemLocale] is not set. This is fine as long as no UTF-8' .
116 ' file system is used.'
117 );
118 } elseif (setlocale(LC_CTYPE, $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale']) === false) {
119 $status = new Status\ErrorStatus();
120 $status->setTitle('Incorrect systemLocale setting');
121 $status->setMessage(
122 'Current value of the $GLOBALS[TYPO3_CONF_VARS][SYS][systemLocale] is incorrect. A locale with' .
123 ' this name doesn\'t exist in the operating system.'
124 );
125 setlocale(LC_CTYPE, $currentLocale);
126 } else {
127 $status = new Status\OkStatus();
128 $status->setTitle('System locale is correct');
129 }
130
131 return $status;
132 }
133
134 /**
135 * Checks whether we can use file names with UTF-8 characters.
136 * Configured system locale must support UTF-8 when UTF8filesystem is set
137 *
138 * @return Status\StatusInterface
139 */
140 protected function checkLocaleWithUTF8filesystem()
141 {
142 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']) {
143 // On Windows an empty local value uses the regional settings from the Control Panel
144 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale'] === '' && TYPO3_OS !== 'WIN') {
145 $status = new Status\ErrorStatus();
146 $status->setTitle('System locale not set on UTF-8 file system');
147 $status->setMessage(
148 '$GLOBALS[TYPO3_CONF_VARS][SYS][UTF8filesystem] is set, but $GLOBALS[TYPO3_CONF_VARS][SYS][systemLocale]' .
149 ' is empty. Make sure a valid locale which supports UTF-8 is set.'
150 );
151 } else {
152 $testString = 'ÖöĄĆŻĘĆćążąęó.jpg';
153 $currentLocale = setlocale(LC_CTYPE, 0);
154 $quote = TYPO3_OS === 'WIN' ? '"' : '\'';
155 setlocale(LC_CTYPE, $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale']);
156 if (escapeshellarg($testString) === $quote . $testString . $quote) {
157 $status = new Status\OkStatus();
158 $status->setTitle('File names with UTF-8 characters can be used.');
159 } else {
160 $status = new Status\ErrorStatus();
161 $status->setTitle('System locale setting doesn\'t support UTF-8 file names.');
162 $status->setMessage(
163 'Please check your $GLOBALS[TYPO3_CONF_VARS][SYS][systemLocale] setting.'
164 );
165 }
166 setlocale(LC_CTYPE, $currentLocale);
167 }
168 } else {
169 $status = new Status\OkStatus();
170 $status->setTitle('Skipping test, as UTF8filesystem is not enabled.');
171 }
172
173 return $status;
174 }
175
176 /**
177 * Check if some opcode cache is loaded
178 *
179 * @return Status\StatusInterface
180 */
181 protected function checkSomePhpOpcodeCacheIsLoaded()
182 {
183 // Link to our wiki page, so we can update opcode cache issue information independent of TYPO3 CMS releases.
184 $wikiLink = 'For more information take a look in our wiki ' . TYPO3_URL_WIKI_OPCODECACHE . '.';
185 $opcodeCaches = GeneralUtility::makeInstance(OpcodeCacheService::class)->getAllActive();
186 if (empty($opcodeCaches)) {
187 // Set status to notice. It needs to be notice so email won't be triggered.
188 $status = new Status\NoticeStatus();
189 $status->setTitle('No PHP opcode cache loaded');
190 $status->setMessage(
191 'PHP opcode caches hold a compiled version of executed PHP scripts in' .
192 ' memory and do not require to recompile a script each time it is accessed.' .
193 ' This can be a massive performance improvement and can reduce the load on a' .
194 ' server in general. A parse time reduction by factor three for fully cached' .
195 ' pages can be achieved easily if using an opcode cache.' .
196 LF . $wikiLink
197 );
198 } else {
199 $status = new Status\OkStatus();
200 $message = '';
201 foreach ($opcodeCaches as $opcodeCache => $properties) {
202 $message .= 'Name: ' . $opcodeCache . ' Version: ' . $properties['version'];
203 $message .= LF;
204 if ($properties['error']) {
205 // Set status to error if not already set
206 if ($status->getSeverity() !== 'error') {
207 $status = new Status\ErrorStatus();
208 }
209 $message .= ' This opcode cache is marked as malfunctioning by the TYPO3 CMS Team.';
210 } elseif ($properties['canInvalidate']) {
211 $message .= ' This opcode cache should work correctly and has good performance.';
212 } else {
213 // Set status to notice if not already error set. It needs to be notice so email won't be triggered.
214 if ($status->getSeverity() !== 'error' || $status->getSeverity() !== 'warning') {
215 $status = new Status\NoticeStatus();
216 }
217 $message .= ' This opcode cache may work correctly but has medium performance.';
218 }
219 $message .= LF;
220 }
221 $message .= $wikiLink;
222 // Set title of status depending on serverity
223 switch ($status->getSeverity()) {
224 case 'error':
225 $status->setTitle('A possibly malfunctioning PHP opcode cache is loaded');
226 break;
227 case 'warning':
228 $status->setTitle('A PHP opcode cache is loaded which may cause problems');
229 break;
230 case 'ok':
231 default:
232 $status->setTitle('A PHP opcode cache is loaded');
233 break;
234 }
235 $status->setMessage($message);
236 }
237
238 return $status;
239 }
240
241 /**
242 * Create true type font test image
243 *
244 * @return Status\StatusInterface
245 */
246 protected function isTrueTypeFontWorking()
247 {
248 if (function_exists('imageftbbox')) {
249 // 20 Pixels at 96 DPI
250 $fontSize = (20 / 96 * 72);
251 $textDimensions = @imageftbbox(
252 $fontSize,
253 0,
254 __DIR__ . '/../../Resources/Private/Font/vera.ttf',
255 'Testing true type support'
256 );
257 $fontBoxWidth = $textDimensions[2] - $textDimensions[0];
258 if ($fontBoxWidth < 300 && $fontBoxWidth > 200) {
259 $status = new Status\OkStatus();
260 $status->setTitle('FreeType True Type Font DPI');
261 $status->setMessage('Fonts are rendered by FreeType library. ' .
262 'We need to ensure that the final dimensions are as expected. ' .
263 'This server renderes fonts based on 96 DPI correctly');
264 } else {
265 $status = new Status\NoticeStatus();
266 $status->setTitle('FreeType True Type Font DPI');
267 $status->setMessage('Fonts are rendered by FreeType library. ' .
268 'This server does not render fonts as expected. ' .
269 'Please check your FreeType 2 module.');
270 }
271 } else {
272 $status = new Status\ErrorStatus();
273 $status->setTitle('PHP GD library freetype2 support missing');
274 $status->setMessage(
275 'The core relies on GD library compiled into PHP with freetype2' .
276 ' support. This is missing on your system. Please install it.'
277 );
278 }
279
280 return $status;
281 }
282
283 /**
284 * Check for bug in libxml
285 *
286 * @return Status\StatusInterface
287 */
288 protected function checkLibXmlBug()
289 {
290 $sampleArray = ['Test>><<Data'];
291 $xmlContent = '<numIndex index="0">Test&gt;&gt;&lt;&lt;Data</numIndex>' . LF;
292 $xml = GeneralUtility::array2xml($sampleArray, '', -1);
293
294 if ($xmlContent !== $xml) {
295 $status = new Status\ErrorStatus();
296 $status->setTitle('PHP libxml bug present');
297 $status->setMessage(
298 'Some hosts have problems saving ">><<" in a flexform.' .
299 ' To fix this, enable [BE][flexformForceCDATA] in' .
300 ' All Configuration.'
301 );
302 } else {
303 $status = new Status\OkStatus();
304 $status->setTitle('PHP libxml bug not present');
305 }
306
307 return $status;
308 }
309 }