9886a27dbb185cbdfaf457e228529e79b97e8dd3
[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 );
59
60 if ($this->isMemcachedUsed()) {
61 $statuses['memcachedConnection'] = $this->getMemcachedConnectionStatus();
62 }
63
64 return $statuses;
65 }
66
67 /**
68 * Checks if sys_refindex is empty.
69 *
70 * @return tx_reports_reports_status_Status An tx_reports_reports_status_Status object representing whether the reference index is empty or not
71 */
72 protected function getReferenceIndexStatus() {
73 $value = $GLOBALS['LANG']->getLL('status_ok');
74 $message = '';
75 $severity = tx_reports_reports_status_Status::OK;
76
77 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'sys_refindex');
78 $registry = t3lib_div::makeInstance('t3lib_Registry');
79 $lastRefIndexUpdate = $registry->get('core', 'sys_refindex_lastUpdate');
80
81 if (!$count && $lastRefIndexUpdate) {
82 $value = $GLOBALS['LANG']->getLL('status_empty');
83 $severity = tx_reports_reports_status_Status::WARNING;
84
85 $url = 'sysext/lowlevel/dbint/index.php?&id=0&SET[function]=refindex';
86 $message = sprintf(
87 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.backend_reference_index'),
88 '<a href="' . $url . '">',
89 '</a>',
90 t3lib_BeFunc::dateTime($lastRefIndexUpdate)
91 );
92 }
93 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
94 $GLOBALS['LANG']->getLL('status_referenceIndex'), $value, $message, $severity
95 );
96 }
97
98 /**
99 * Checks if PHP safe_mode is enabled.
100 *
101 * @return tx_reports_reports_status_Status A tx_reports_reports_status_Status object representing whether the safe_mode is enabled or not
102 */
103 protected function getPhpSafeModeStatus() {
104 $value = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:disabled');
105 $message = '';
106 $severity = tx_reports_reports_status_Status::OK;
107
108 if (t3lib_utility_PhpOptions::isSafeModeEnabled()) {
109 $value = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:enabled');
110 $severity = tx_reports_reports_status_Status::WARNING;
111 $message = $GLOBALS['LANG']->sL('status_configuration_PhpSafeModeEnabled');
112 }
113
114 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
115 $GLOBALS['LANG']->getLL('status_PhpSafeMode'), $value, $message, $severity
116 );
117 }
118
119 /**
120 * Checks whether memcached is configured, if that's the case we asume it's also used.
121 *
122 * @return boolean TRUE if memcached is used, FALSE otherwise.
123 */
124 protected function isMemcachedUsed() {
125 $memcachedUsed = FALSE;
126
127 $memcachedServers = $this->getConfiguredMemcachedServers();
128 if (count($memcachedServers)) {
129 $memcachedUsed = TRUE;
130 }
131
132 return $memcachedUsed;
133 }
134
135 /**
136 * Gets the configured memcached server connections.
137 *
138 * @return array An array of configured memcached server connections.
139 */
140 protected function getConfiguredMemcachedServers() {
141 $memcachedServers = array();
142
143 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'])) {
144 foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] as $table => $conf) {
145 if (is_array($conf)) {
146 foreach ($conf as $key => $value) {
147 if (!is_array($value) && $value === 't3lib_cache_backend_MemcachedBackend') {
148 $memcachedServers = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$table]['options']['servers'];
149 break;
150 }
151 }
152 }
153 }
154 }
155
156 return $memcachedServers;
157 }
158
159 /**
160 * Checks whether TYPO3 can connect to the configured memcached servers.
161 *
162 * @return tx_reports_reports_status_Status An tx_reports_reports_status_Status object representing whether TYPO3 can connect to the configured memcached servers
163 */
164 protected function getMemcachedConnectionStatus() {
165 $value = $GLOBALS['LANG']->getLL('status_ok');
166 $message = '';
167 $severity = tx_reports_reports_status_Status::OK;
168
169 $failedConnections = array();
170 $defaultMemcachedPort = ini_get('memcache.default_port');
171 $memcachedServers = $this->getConfiguredMemcachedServers();
172
173 if (function_exists('memcache_connect') && is_array($memcachedServers)) {
174 foreach ($memcachedServers as $testServer) {
175 $configuredServer = $testServer;
176 if (substr($testServer, 0, 7) == 'unix://') {
177 $host = $testServer;
178 $port = 0;
179 } else {
180 if (substr($testServer, 0, 6) === 'tcp://') {
181 $testServer = substr($testServer, 6);
182 }
183 if (strstr($testServer, ':') !== FALSE) {
184 list($host, $port) = explode(':', $testServer, 2);
185 } else {
186 $host = $testServer;
187 $port = $defaultMemcachedPort;
188 }
189 }
190 $memcachedConnection = @memcache_connect($host, $port);
191 if ($memcachedConnection != NULL) {
192 memcache_close($memcachedConnection);
193 } else {
194 $failedConnections[] = $configuredServer;
195 }
196 }
197 }
198
199 if (count($failedConnections)) {
200 $value = $GLOBALS['LANG']->getLL('status_connectionFailed');
201 $severity = tx_reports_reports_status_Status::WARNING;
202
203 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.memcache_not_usable')
204 . '<br /><br />'
205 . '<ul><li>'
206 . implode('</li><li>', $failedConnections)
207 . '</li></ul>';
208 }
209
210 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
211 $GLOBALS['LANG']->getLL('status_memcachedConfiguration'), $value, $message, $severity
212 );
213 }
214
215 /**
216 * Provides status information on the deprecation log, whether it's enabled
217 * and if so whether certain limits in file size are reached.
218 *
219 * @return tx_reports_reports_status_Status The deprecation log status.
220 */
221 protected function getDeprecationLogStatus() {
222 $title = $GLOBALS['LANG']->getLL('status_configuration_DeprecationLog');
223 $value = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:disabled');
224 $message = '';
225 $severity = tx_reports_reports_status_Status::OK;
226
227 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog']) {
228 $value = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:enabled');
229 $message = '<p>' . $GLOBALS['LANG']->getLL('status_configuration_DeprecationLogEnabled') . '</p>';
230 $severity = tx_reports_reports_status_Status::NOTICE;
231
232 $logFile = t3lib_div::getDeprecationLogFileName();
233 $logFileSize = 0;
234
235 if (file_exists($logFile)) {
236 $logFileSize = filesize($logFile);
237
238 $message .= '<p> ' . sprintf(
239 $GLOBALS['LANG']->getLL('status_configuration_DeprecationLogFile'),
240 $this->getDeprecationLogFileLink()
241 ) . '</p>';
242 }
243
244 if ($logFileSize > $this->deprecationLogFileSizeWarningThreshold) {
245 $severity = tx_reports_reports_status_Status::WARNING;
246 }
247
248 if ($logFileSize > $this->deprecationLogFileSizeErrorThreshold) {
249 $severity = tx_reports_reports_status_Status::ERROR;
250 }
251
252 if ($severity > tx_reports_reports_status_Status::OK) {
253 $message .= '<p> ' . sprintf(
254 $GLOBALS['LANG']->getLL('status_configuration_DeprecationLogSize'),
255 t3lib_div::formatSize($logFileSize)
256 ) . '</p>';
257 }
258 }
259
260 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
261 $title, $value, $message, $severity
262 );
263 }
264
265 /**
266 * Creates a link to the deprecation log file with the absolute path as the
267 * link text.
268 *
269 * @return string Link to the deprecation log file
270 */
271 protected function getDeprecationLogFileLink() {
272 $logFile = t3lib_div::getDeprecationLogFileName();
273 $relativePath = t3lib_div::resolveBackPath(
274 $this->backPath . substr($logFile, strlen(PATH_site))
275 );
276 $link = '<a href="' . $relativePath . '">' . $logFile . '</a>';
277
278 return $link;
279 }
280 }
281
282
283 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/reports/status/class.tx_reports_reports_status_configurationstatus.php'])) {
284 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/reports/status/class.tx_reports_reports_status_configurationstatus.php']);
285 }
286
287 ?>