[TASK] EXT:reports Minor typo in HTML
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / Classes / Report / Status / ConfigurationStatus.php
1 <?php
2 namespace TYPO3\CMS\Reports\Report\Status;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009-2011 Ingo Renner <ingo@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * Performs some checks about the install tool protection status
28 *
29 * @author Ingo Renner <ingo@typo3.org>
30 */
31 class ConfigurationStatus implements \TYPO3\CMS\Reports\StatusProviderInterface {
32
33 /**
34 * 10MB
35 *
36 * @var integer
37 */
38 protected $deprecationLogFileSizeWarningThreshold = 10485760;
39
40 /**
41 * 100MB
42 *
43 * @var integer
44 */
45 protected $deprecationLogFileSizeErrorThreshold = 104857600;
46
47 /**
48 * Backpath to the typo3 main directory
49 *
50 * @var string
51 */
52 protected $backPath = '../';
53
54 /**
55 * Determines the Install Tool's status, mainly concerning its protection.
56 *
57 * @return array List of statuses
58 * @see typo3/sysext/reports/interfaces/tx_reports_StatusProvider::getStatus()
59 */
60 public function getStatus() {
61 $this->executeAdminCommand();
62 $statuses = array(
63 'emptyReferenceIndex' => $this->getReferenceIndexStatus(),
64 'deprecationLog' => $this->getDeprecationLogStatus()
65 );
66 // Do not show status about non-existent features
67 if (version_compare(phpversion(), '5.4', '<')) {
68 $statuses['safeModeEnabled'] = $this->getPhpSafeModeStatus();
69 $statuses['magicQuotesGpcEnabled'] = $this->getPhpMagicQuotesGpcStatus();
70 }
71 if ($this->isMemcachedUsed()) {
72 $statuses['memcachedConnection'] = $this->getMemcachedConnectionStatus();
73 }
74 if (TYPO3_OS !== 'WIN') {
75 $statuses['createdFilesWorldWritable'] = $this->getCreatedFilesWorldWritableStatus();
76 $statuses['createdDirectoriesWorldWritable'] = $this->getCreatedDirectoriesWorldWritableStatus();
77 }
78 return $statuses;
79 }
80
81 /**
82 * Checks if sys_refindex is empty.
83 *
84 * @return \TYPO3\CMS\Reports\Status An tx_reports_reports_status_Status object representing whether the reference index is empty or not
85 */
86 protected function getReferenceIndexStatus() {
87 $value = $GLOBALS['LANG']->getLL('status_ok');
88 $message = '';
89 $severity = \TYPO3\CMS\Reports\Status::OK;
90 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'sys_refindex');
91 $registry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Registry');
92 $lastRefIndexUpdate = $registry->get('core', 'sys_refindex_lastUpdate');
93 if (!$count && $lastRefIndexUpdate) {
94 $value = $GLOBALS['LANG']->getLL('status_empty');
95 $severity = \TYPO3\CMS\Reports\Status::WARNING;
96 $url = 'sysext/lowlevel/dbint/index.php?&id=0&SET[function]=refindex';
97 $message = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.backend_reference_index'), '<a href="' . $url . '">', '</a>', \TYPO3\CMS\Backend\Utility\BackendUtility::dateTime($lastRefIndexUpdate));
98 }
99 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Reports\\Status', $GLOBALS['LANG']->getLL('status_referenceIndex'), $value, $message, $severity);
100 }
101
102 /**
103 * Checks if PHP safe_mode is enabled.
104 *
105 * @return \TYPO3\CMS\Reports\Status A tx_reports_reports_status_Status object representing whether the safe_mode is enabled or not
106 */
107 protected function getPhpSafeModeStatus() {
108 $value = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:disabled');
109 $message = '';
110 $severity = \TYPO3\CMS\Reports\Status::OK;
111 if (\TYPO3\CMS\Core\Utility\PhpOptionsUtility::isSafeModeEnabled()) {
112 $value = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:enabled');
113 $severity = \TYPO3\CMS\Reports\Status::WARNING;
114 $message = $GLOBALS['LANG']->getLL('status_configuration_PhpSafeModeEnabled');
115 }
116 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Reports\\Status', $GLOBALS['LANG']->getLL('status_PhpSafeMode'), $value, $message, $severity);
117 }
118
119 /**
120 * Checks if PHP magic_quotes_gpc is enabled.
121 *
122 * @return \TYPO3\CMS\Reports\Status A tx_reports_reports_status_Status object representing whether the magic_quote_gpc is enabled or not
123 */
124 protected function getPhpMagicQuotesGpcStatus() {
125 $value = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:disabled');
126 $message = '';
127 $severity = \TYPO3\CMS\Reports\Status::OK;
128 if (\TYPO3\CMS\Core\Utility\PhpOptionsUtility::isMagicQuotesGpcEnabled()) {
129 $value = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:enabled');
130 $severity = \TYPO3\CMS\Reports\Status::WARNING;
131 $message = $GLOBALS['LANG']->getLL('status_configuration_PhpMagicQuotesGpcEnabled');
132 }
133 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Reports\\Status', $GLOBALS['LANG']->getLL('status_PhpMagicQuotesGpc'), $value, $message, $severity);
134 }
135
136 /**
137 * Checks whether memcached is configured, if that's the case we asume it's also used.
138 *
139 * @return boolean TRUE if memcached is used, FALSE otherwise.
140 */
141 protected function isMemcachedUsed() {
142 $memcachedUsed = FALSE;
143 $memcachedServers = $this->getConfiguredMemcachedServers();
144 if (count($memcachedServers)) {
145 $memcachedUsed = TRUE;
146 }
147 return $memcachedUsed;
148 }
149
150 /**
151 * Gets the configured memcached server connections.
152 *
153 * @return array An array of configured memcached server connections.
154 */
155 protected function getConfiguredMemcachedServers() {
156 $memcachedServers = array();
157 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'])) {
158 foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] as $table => $conf) {
159 if (is_array($conf)) {
160 foreach ($conf as $key => $value) {
161 if (!is_array($value) && $value === 'TYPO3\\CMS\\Core\\Cache\\Backend\\MemcachedBackend') {
162 $memcachedServers = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$table]['options']['servers'];
163 break;
164 }
165 }
166 }
167 }
168 }
169 return $memcachedServers;
170 }
171
172 /**
173 * Checks whether TYPO3 can connect to the configured memcached servers.
174 *
175 * @return \TYPO3\CMS\Reports\Status An tx_reports_reports_status_Status object representing whether TYPO3 can connect to the configured memcached servers
176 */
177 protected function getMemcachedConnectionStatus() {
178 $value = $GLOBALS['LANG']->getLL('status_ok');
179 $message = '';
180 $severity = \TYPO3\CMS\Reports\Status::OK;
181 $failedConnections = array();
182 $defaultMemcachedPort = ini_get('memcache.default_port');
183 $memcachedServers = $this->getConfiguredMemcachedServers();
184 if (function_exists('memcache_connect') && is_array($memcachedServers)) {
185 foreach ($memcachedServers as $testServer) {
186 $configuredServer = $testServer;
187 if (substr($testServer, 0, 7) == 'unix://') {
188 $host = $testServer;
189 $port = 0;
190 } else {
191 if (substr($testServer, 0, 6) === 'tcp://') {
192 $testServer = substr($testServer, 6);
193 }
194 if (strstr($testServer, ':') !== FALSE) {
195 list($host, $port) = explode(':', $testServer, 2);
196 } else {
197 $host = $testServer;
198 $port = $defaultMemcachedPort;
199 }
200 }
201 $memcachedConnection = @memcache_connect($host, $port);
202 if ($memcachedConnection != NULL) {
203 memcache_close($memcachedConnection);
204 } else {
205 $failedConnections[] = $configuredServer;
206 }
207 }
208 }
209 if (count($failedConnections)) {
210 $value = $GLOBALS['LANG']->getLL('status_connectionFailed');
211 $severity = \TYPO3\CMS\Reports\Status::WARNING;
212 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.memcache_not_usable') . '<br /><br />' . '<ul><li>' . implode('</li><li>', $failedConnections) . '</li></ul>';
213 }
214 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Reports\\Status', $GLOBALS['LANG']->getLL('status_memcachedConfiguration'), $value, $message, $severity);
215 }
216
217 /**
218 * Provides status information on the deprecation log, whether it's enabled
219 * and if so whether certain limits in file size are reached.
220 *
221 * @return \TYPO3\CMS\Reports\Status The deprecation log status.
222 */
223 protected function getDeprecationLogStatus() {
224 $title = $GLOBALS['LANG']->getLL('status_configuration_DeprecationLog');
225 $value = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:disabled');
226 $message = '';
227 $severity = \TYPO3\CMS\Reports\Status::OK;
228 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog']) {
229 $value = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:enabled');
230 $message = '<p>' . $GLOBALS['LANG']->getLL('status_configuration_DeprecationLogEnabled') . '</p>';
231 $severity = \TYPO3\CMS\Reports\Status::NOTICE;
232 $logFile = \TYPO3\CMS\Core\Utility\GeneralUtility::getDeprecationLogFileName();
233 $logFileSize = 0;
234 if (@file_exists($logFile)) {
235 $logFileSize = filesize($logFile);
236 $message .= '<p>' . sprintf($GLOBALS['LANG']->getLL('status_configuration_DeprecationLogFile'), $this->getDeprecationLogFileLink()) . '</p>';
237 $removeDeprecationLogFileUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL') . '&amp;adminCmd=removeDeprecationLogFile';
238 $message .= '<p>' . sprintf($GLOBALS['LANG']->getLL('status_configuration_DeprecationLogSize'), \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($logFileSize)) . ' <a href="' . $removeDeprecationLogFileUrl . '">' . $GLOBALS['LANG']->getLL('status_configuration_DeprecationLogDeleteLink') . '</a></p>';
239 }
240 if ($logFileSize > $this->deprecationLogFileSizeWarningThreshold) {
241 $severity = \TYPO3\CMS\Reports\Status::WARNING;
242 }
243 if ($logFileSize > $this->deprecationLogFileSizeErrorThreshold) {
244 $severity = \TYPO3\CMS\Reports\Status::ERROR;
245 }
246 }
247 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Reports\\Status', $title, $value, $message, $severity);
248 }
249
250 /**
251 * Warning, if fileCreateMask has write bit for 'others' set.
252 *
253 * @return \TYPO3\CMS\Reports\Status The writable status for 'others'
254 */
255 protected function getCreatedFilesWorldWritableStatus() {
256 $value = $GLOBALS['LANG']->getLL('status_ok');
257 $message = '';
258 $severity = \TYPO3\CMS\Reports\Status::OK;
259 if ((int) $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] % 10 & 2) {
260 $value = $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'];
261 $severity = \TYPO3\CMS\Reports\Status::WARNING;
262 $message = $GLOBALS['LANG']->getLL('status_CreatedFilePermissions.writable');
263 }
264 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Reports\\Status', $GLOBALS['LANG']->getLL('status_CreatedFilePermissions'), $value, $message, $severity);
265 }
266
267 /**
268 * Warning, if folderCreateMask has write bit for 'others' set.
269 *
270 * @return \TYPO3\CMS\Reports\Status The writable status for 'others'
271 */
272 protected function getCreatedDirectoriesWorldWritableStatus() {
273 $value = $GLOBALS['LANG']->getLL('status_ok');
274 $message = '';
275 $severity = \TYPO3\CMS\Reports\Status::OK;
276 if ((int) $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] % 10 & 2) {
277 $value = $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'];
278 $severity = \TYPO3\CMS\Reports\Status::WARNING;
279 $message = $GLOBALS['LANG']->getLL('status_CreatedDirectoryPermissions.writable');
280 }
281 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Reports\\Status', $GLOBALS['LANG']->getLL('status_CreatedDirectoryPermissions'), $value, $message, $severity);
282 }
283
284 /**
285 * Creates a link to the deprecation log file with the absolute path as the
286 * link text.
287 *
288 * @return string Link to the deprecation log file
289 */
290 protected function getDeprecationLogFileLink() {
291 $logFile = \TYPO3\CMS\Core\Utility\GeneralUtility::getDeprecationLogFileName();
292 $relativePath = \TYPO3\CMS\Core\Utility\GeneralUtility::resolveBackPath($this->backPath . substr($logFile, strlen(PATH_site)));
293 $link = '<a href="' . $relativePath . '">' . $logFile . '</a>';
294 return $link;
295 }
296
297 /**
298 * Executes admin commands.
299 *
300 * Currently implemented commands are:
301 * - Remove deprecation log file
302 *
303 * @return void
304 */
305 protected function executeAdminCommand() {
306 $command = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('adminCmd');
307 switch ($command) {
308 case 'removeDeprecationLogFile':
309 self::removeDeprecationLogFile();
310 break;
311 default:
312 // intentionally left blank
313 break;
314 }
315 }
316
317 /**
318 * Remove deprecation log file.
319 *
320 * @return void
321 */
322 static protected function removeDeprecationLogFile() {
323 if (@unlink(\TYPO3\CMS\Core\Utility\GeneralUtility::getDeprecationLogFileName())) {
324 $message = $GLOBALS['LANG']->getLL('status_configuration_DeprecationLogDeletedSuccessful');
325 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::OK;
326 } else {
327 $message = $GLOBALS['LANG']->getLL('status_configuration_DeprecationLogDeletionFailed');
328 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR;
329 }
330 \TYPO3\CMS\Core\Messaging\FlashMessageQueue::addMessage(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $message, '', $severity, TRUE));
331 }
332
333 }
334
335
336 ?>