37360c13bce9abe2404b0f48b90b43b33de4dcba
[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-2010 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 * $Id$
34 */
35 class tx_reports_reports_status_ConfigurationStatus implements tx_reports_StatusProvider {
36
37 // 10 MB
38 protected $deprecationLogFileSizeWarningThreshold = 10485760;
39 // 100 MB
40 protected $deprecationLogFileSizeErrorThreshold = 104857600;
41
42 /**
43 * Backpath to the typo3 main directory
44 *
45 * @var string
46 */
47 protected $backPath = '../';
48
49 /**
50 * Determines the Install Tool's status, mainly concerning its protection.
51 *
52 * @return array List of statuses
53 * @see typo3/sysext/reports/interfaces/tx_reports_StatusProvider::getStatus()
54 */
55 public function getStatus() {
56 $statuses = array(
57 'emptyReferenceIndex' => $this->getReferenceIndexStatus(),
58 'deprecationLog' => $this->getDeprecationLogStatus()
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 whether memcached is configured, if that's the case we asume it's also used.
101 *
102 * @return boolean True if memcached is used, false otherwise.
103 */
104 protected function isMemcachedUsed() {
105 $memcachedUsed = FALSE;
106
107 $memcachedServers = $this->getConfiguredMemcachedServers();
108 if (count($memcachedServers)) {
109 $memcachedUsed = TRUE;
110 }
111
112 return $memcachedUsed;
113 }
114
115 /**
116 * Gets the configured memcached server connections.
117 *
118 * @return array An array of configured memcached server connections.
119 */
120 protected function getConfiguredMemcachedServers() {
121 $memcachedServers = array();
122
123 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'])) {
124 foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] as $table => $conf) {
125 if (is_array($conf)) {
126 foreach ($conf as $key => $value) {
127 if (!is_array($value) && $value === 't3lib_cache_backend_MemcachedBackend') {
128 $memcachedServers = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$table]['options']['servers'];
129 break;
130 }
131 }
132 }
133 }
134 }
135
136 return $memcachedServers;
137 }
138
139 /**
140 * Checks whether TYPO3 can connect to the configured memcached servers.
141 *
142 * @return tx_reports_reports_status_Status An tx_reports_reports_status_Status object representing whether TYPO3 can connect to the configured memcached servers
143 */
144 protected function getMemcachedConnectionStatus() {
145 $value = $GLOBALS['LANG']->getLL('status_ok');
146 $message = '';
147 $severity = tx_reports_reports_status_Status::OK;
148
149 $failedConnections = array();
150 $defaultMemcachedPort = ini_get('memcache.default_port');
151 $memcachedServers = $this->getConfiguredMemcachedServers();
152
153 if (function_exists('memcache_connect') && is_array($memcachedServers)) {
154 foreach ($memcachedServers as $testServer) {
155 $configuredServer = $testServer;
156 if (substr($testServer, 0, 7) == 'unix://') {
157 $host = $testServer;
158 $port = 0;
159 } else {
160 if (substr($testServer, 0, 6) === 'tcp://') {
161 $testServer = substr($testServer, 6);
162 }
163 if (strstr($testServer, ':') !== FALSE) {
164 list($host, $port) = explode(':', $testServer, 2);
165 } else {
166 $host = $testServer;
167 $port = $defaultMemcachedPort;
168 }
169 }
170 $memcachedConnection = @memcache_connect($host, $port);
171 if ($memcachedConnection != null) {
172 memcache_close($memcachedConnection);
173 } else {
174 $failedConnections[] = $configuredServer;
175 }
176 }
177 }
178
179 if (count($failedConnections)) {
180 $value = $GLOBALS['LANG']->getLL('status_connectionFailed');
181 $severity = tx_reports_reports_status_Status::WARNING;
182
183 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.memcache_not_usable')
184 . '<br /><br />'
185 . '<ul><li>'
186 . implode('</li><li>', $failedConnections)
187 . '</li></ul>';
188 }
189
190 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
191 $GLOBALS['LANG']->getLL('status_memcachedConfiguration'), $value, $message, $severity
192 );
193 }
194
195 /**
196 * Provides status information on the deprecation log, whether it's enabled
197 * and if so whether certain limits in file size are reached.
198 *
199 * @return tx_reports_reports_status_Status The deprecation log status.
200 */
201 protected function getDeprecationLogStatus() {
202 $title = $GLOBALS['LANG']->getLL('status_configuration_DeprecationLog');
203 $value = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:disabled');
204 $message = '';
205 $severity = tx_reports_reports_status_Status::OK;
206
207 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog']) {
208 $value = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:enabled');
209 $message = '<p>' . $GLOBALS['LANG']->getLL('status_configuration_DeprecationLogEnabled') . '</p>';
210 $severity = tx_reports_reports_status_Status::NOTICE;
211
212 $logFile = t3lib_div::getDeprecationLogFileName();
213 $logFileSize = 0;
214
215 if (file_exists($logFile)) {
216 $logFileSize = filesize($logFile);
217
218 $message .= '<p> ' . sprintf(
219 $GLOBALS['LANG']->getLL('status_configuration_DeprecationLogFile'),
220 $this->getDeprecationLogFileLink()
221 ) . '</p>';
222 }
223
224 if ($logFileSize > $this->deprecationLogFileSizeWarningThreshold) {
225 $severity = tx_reports_reports_status_Status::WARNING;
226 }
227
228 if ($logFileSize > $this->deprecationLogFileSizeErrorThreshold) {
229 $severity = tx_reports_reports_status_Status::ERROR;
230 }
231
232 if ($severity > tx_reports_reports_status_Status::OK) {
233 $message .= '<p> ' . sprintf(
234 $GLOBALS['LANG']->getLL('status_configuration_DeprecationLogSize'),
235 t3lib_div::formatSize($logFileSize)
236 ) . '</p>';
237 }
238 }
239
240 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
241 $title, $value, $message, $severity
242 );
243 }
244
245 /**
246 * Creates a link to the deprecation log file with the absolute path as the
247 * link text.
248 *
249 * @return string Link to the deprecation log file
250 */
251 protected function getDeprecationLogFileLink() {
252 $logFile = t3lib_div::getDeprecationLogFileName();
253 $relativePath = t3lib_div::resolveBackPath(
254 $this->backPath . substr($logFile, strlen(PATH_site))
255 );
256 $link = '<a href="' . $relativePath . '">' . $logFile . '</a>';
257
258 return $link;
259 }
260 }
261
262
263 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/reports/status/class.tx_reports_reports_status_configurationstatus.php'])) {
264 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/reports/status/class.tx_reports_reports_status_configurationstatus.php']);
265 }
266
267 ?>