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