2 /***************************************************************
5 * (c) 2009-2011 Ingo Renner <ingo@typo3.org>
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.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
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.
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
27 * Performs some checks about the install tool protection status
29 * @author Ingo Renner <ingo@typo3.org>
33 class tx_reports_reports_status_ConfigurationStatus
implements tx_reports_StatusProvider
{
36 protected $deprecationLogFileSizeWarningThreshold = 10485760;
38 protected $deprecationLogFileSizeErrorThreshold = 104857600;
41 * Backpath to the typo3 main directory
45 protected $backPath = '../';
48 * Determines the Install Tool's status, mainly concerning its protection.
50 * @return array List of statuses
51 * @see typo3/sysext/reports/interfaces/tx_reports_StatusProvider::getStatus()
53 public function getStatus() {
55 'emptyReferenceIndex' => $this->getReferenceIndexStatus(),
56 'deprecationLog' => $this->getDeprecationLogStatus(),
57 'safeModeEnabled' => $this->getPhpSafeModeStatus(),
58 'magicQuotesGpcEnabled' => $this->getPhpMagicQuotesGpcStatus(),
61 if ($this->isMemcachedUsed()) {
62 $statuses['memcachedConnection'] = $this->getMemcachedConnectionStatus();
69 * Checks if sys_refindex is empty.
71 * @return tx_reports_reports_status_Status An tx_reports_reports_status_Status object representing whether the reference index is empty or not
73 protected function getReferenceIndexStatus() {
74 $value = $GLOBALS['LANG']->getLL('status_ok');
76 $severity = tx_reports_reports_status_Status
::OK
;
78 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'sys_refindex');
79 $registry = t3lib_div
::makeInstance('t3lib_Registry');
80 $lastRefIndexUpdate = $registry->get('core', 'sys_refindex_lastUpdate');
82 if (!$count && $lastRefIndexUpdate) {
83 $value = $GLOBALS['LANG']->getLL('status_empty');
84 $severity = tx_reports_reports_status_Status
::WARNING
;
86 $url = 'sysext/lowlevel/dbint/index.php?&id=0&SET[function]=refindex';
88 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.backend_reference_index'),
89 '<a href="' . $url . '">',
91 t3lib_BeFunc
::dateTime($lastRefIndexUpdate)
94 return t3lib_div
::makeInstance('tx_reports_reports_status_Status',
95 $GLOBALS['LANG']->getLL('status_referenceIndex'), $value, $message, $severity
100 * Checks if PHP safe_mode is enabled.
102 * @return tx_reports_reports_status_Status A tx_reports_reports_status_Status object representing whether the safe_mode is enabled or not
104 protected function getPhpSafeModeStatus() {
105 $value = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:disabled');
107 $severity = tx_reports_reports_status_Status
::OK
;
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');
115 return t3lib_div
::makeInstance('tx_reports_reports_status_Status',
116 $GLOBALS['LANG']->getLL('status_PhpSafeMode'), $value, $message, $severity
121 * Checks if PHP magic_quotes_gpc is enabled.
123 * @return tx_reports_reports_status_Status A tx_reports_reports_status_Status object representing whether the magic_quote_gpc is enabled or not
125 protected function getPhpMagicQuotesGpcStatus() {
126 $value = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:disabled');
128 $severity = tx_reports_reports_status_Status
::OK
;
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');
136 return t3lib_div
::makeInstance('tx_reports_reports_status_Status',
137 $GLOBALS['LANG']->getLL('status_PhpMagicQuotesGpc'), $value, $message, $severity
142 * Checks whether memcached is configured, if that's the case we asume it's also used.
144 * @return boolean TRUE if memcached is used, FALSE otherwise.
146 protected function isMemcachedUsed() {
147 $memcachedUsed = FALSE;
149 $memcachedServers = $this->getConfiguredMemcachedServers();
150 if (count($memcachedServers)) {
151 $memcachedUsed = TRUE;
154 return $memcachedUsed;
158 * Gets the configured memcached server connections.
160 * @return array An array of configured memcached server connections.
162 protected function getConfiguredMemcachedServers() {
163 $memcachedServers = array();
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'];
178 return $memcachedServers;
182 * Checks whether TYPO3 can connect to the configured memcached servers.
184 * @return tx_reports_reports_status_Status An tx_reports_reports_status_Status object representing whether TYPO3 can connect to the configured memcached servers
186 protected function getMemcachedConnectionStatus() {
187 $value = $GLOBALS['LANG']->getLL('status_ok');
189 $severity = tx_reports_reports_status_Status
::OK
;
191 $failedConnections = array();
192 $defaultMemcachedPort = ini_get('memcache.default_port');
193 $memcachedServers = $this->getConfiguredMemcachedServers();
195 if (function_exists('memcache_connect') && is_array($memcachedServers)) {
196 foreach ($memcachedServers as $testServer) {
197 $configuredServer = $testServer;
198 if (substr($testServer, 0, 7) == 'unix://') {
202 if (substr($testServer, 0, 6) === 'tcp://') {
203 $testServer = substr($testServer, 6);
205 if (strstr($testServer, ':') !== FALSE) {
206 list($host, $port) = explode(':', $testServer, 2);
209 $port = $defaultMemcachedPort;
212 $memcachedConnection = @memcache_connect
($host, $port);
213 if ($memcachedConnection != NULL) {
214 memcache_close($memcachedConnection);
216 $failedConnections[] = $configuredServer;
221 if (count($failedConnections)) {
222 $value = $GLOBALS['LANG']->getLL('status_connectionFailed');
223 $severity = tx_reports_reports_status_Status
::WARNING
;
225 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.memcache_not_usable')
228 . implode('</li><li>', $failedConnections)
232 return t3lib_div
::makeInstance('tx_reports_reports_status_Status',
233 $GLOBALS['LANG']->getLL('status_memcachedConfiguration'), $value, $message, $severity
238 * Provides status information on the deprecation log, whether it's enabled
239 * and if so whether certain limits in file size are reached.
241 * @return tx_reports_reports_status_Status The deprecation log status.
243 protected function getDeprecationLogStatus() {
244 $title = $GLOBALS['LANG']->getLL('status_configuration_DeprecationLog');
245 $value = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:disabled');
247 $severity = tx_reports_reports_status_Status
::OK
;
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
;
254 $logFile = t3lib_div
::getDeprecationLogFileName();
257 if (file_exists($logFile)) {
258 $logFileSize = filesize($logFile);
260 $message .= '<p> ' . sprintf(
261 $GLOBALS['LANG']->getLL('status_configuration_DeprecationLogFile'),
262 $this->getDeprecationLogFileLink()
266 if ($logFileSize > $this->deprecationLogFileSizeWarningThreshold
) {
267 $severity = tx_reports_reports_status_Status
::WARNING
;
270 if ($logFileSize > $this->deprecationLogFileSizeErrorThreshold
) {
271 $severity = tx_reports_reports_status_Status
::ERROR
;
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)
282 return t3lib_div
::makeInstance('tx_reports_reports_status_Status',
283 $title, $value, $message, $severity
288 * Creates a link to the deprecation log file with the absolute path as the
291 * @return string Link to the deprecation log file
293 protected function getDeprecationLogFileLink() {
294 $logFile = t3lib_div
::getDeprecationLogFileName();
295 $relativePath = t3lib_div
::resolveBackPath(
296 $this->backPath
. substr($logFile, strlen(PATH_site
))
298 $link = '<a href="' . $relativePath . '">' . $logFile . '</a>';
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']);