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