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()
60 if ($this->isMemcachedUsed()) {
61 $statuses['memcachedConnection'] = $this->getMemcachedConnectionStatus();
68 * Checks if sys_refindex is empty.
70 * @return tx_reports_reports_status_Status An tx_reports_reports_status_Status object representing whether the reference index is empty or not
72 protected function getReferenceIndexStatus() {
73 $value = $GLOBALS['LANG']->getLL('status_ok');
75 $severity = tx_reports_reports_status_Status
::OK
;
77 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'sys_refindex');
78 $registry = t3lib_div
::makeInstance('t3lib_Registry');
79 $lastRefIndexUpdate = $registry->get('core', 'sys_refindex_lastUpdate');
81 if (!$count && $lastRefIndexUpdate) {
82 $value = $GLOBALS['LANG']->getLL('status_empty');
83 $severity = tx_reports_reports_status_Status
::WARNING
;
85 $url = 'sysext/lowlevel/dbint/index.php?&id=0&SET[function]=refindex';
87 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.backend_reference_index'),
88 '<a href="' . $url . '">',
90 t3lib_BeFunc
::dateTime($lastRefIndexUpdate)
93 return t3lib_div
::makeInstance('tx_reports_reports_status_Status',
94 $GLOBALS['LANG']->getLL('status_referenceIndex'), $value, $message, $severity
99 * Checks if PHP safe_mode is enabled.
101 * @return tx_reports_reports_status_Status A tx_reports_reports_status_Status object representing whether the safe_mode is enabled or not
103 protected function getPhpSafeModeStatus() {
104 $value = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:disabled');
106 $severity = tx_reports_reports_status_Status
::OK
;
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');
114 return t3lib_div
::makeInstance('tx_reports_reports_status_Status',
115 $GLOBALS['LANG']->getLL('status_PhpSafeMode'), $value, $message, $severity
120 * Checks whether memcached is configured, if that's the case we asume it's also used.
122 * @return boolean True if memcached is used, false otherwise.
124 protected function isMemcachedUsed() {
125 $memcachedUsed = FALSE;
127 $memcachedServers = $this->getConfiguredMemcachedServers();
128 if (count($memcachedServers)) {
129 $memcachedUsed = TRUE;
132 return $memcachedUsed;
136 * Gets the configured memcached server connections.
138 * @return array An array of configured memcached server connections.
140 protected function getConfiguredMemcachedServers() {
141 $memcachedServers = array();
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'];
156 return $memcachedServers;
160 * Checks whether TYPO3 can connect to the configured memcached servers.
162 * @return tx_reports_reports_status_Status An tx_reports_reports_status_Status object representing whether TYPO3 can connect to the configured memcached servers
164 protected function getMemcachedConnectionStatus() {
165 $value = $GLOBALS['LANG']->getLL('status_ok');
167 $severity = tx_reports_reports_status_Status
::OK
;
169 $failedConnections = array();
170 $defaultMemcachedPort = ini_get('memcache.default_port');
171 $memcachedServers = $this->getConfiguredMemcachedServers();
173 if (function_exists('memcache_connect') && is_array($memcachedServers)) {
174 foreach ($memcachedServers as $testServer) {
175 $configuredServer = $testServer;
176 if (substr($testServer, 0, 7) == 'unix://') {
180 if (substr($testServer, 0, 6) === 'tcp://') {
181 $testServer = substr($testServer, 6);
183 if (strstr($testServer, ':') !== FALSE) {
184 list($host, $port) = explode(':', $testServer, 2);
187 $port = $defaultMemcachedPort;
190 $memcachedConnection = @memcache_connect
($host, $port);
191 if ($memcachedConnection != null) {
192 memcache_close($memcachedConnection);
194 $failedConnections[] = $configuredServer;
199 if (count($failedConnections)) {
200 $value = $GLOBALS['LANG']->getLL('status_connectionFailed');
201 $severity = tx_reports_reports_status_Status
::WARNING
;
203 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.memcache_not_usable')
206 . implode('</li><li>', $failedConnections)
210 return t3lib_div
::makeInstance('tx_reports_reports_status_Status',
211 $GLOBALS['LANG']->getLL('status_memcachedConfiguration'), $value, $message, $severity
216 * Provides status information on the deprecation log, whether it's enabled
217 * and if so whether certain limits in file size are reached.
219 * @return tx_reports_reports_status_Status The deprecation log status.
221 protected function getDeprecationLogStatus() {
222 $title = $GLOBALS['LANG']->getLL('status_configuration_DeprecationLog');
223 $value = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:disabled');
225 $severity = tx_reports_reports_status_Status
::OK
;
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
;
232 $logFile = t3lib_div
::getDeprecationLogFileName();
235 if (file_exists($logFile)) {
236 $logFileSize = filesize($logFile);
238 $message .= '<p> ' . sprintf(
239 $GLOBALS['LANG']->getLL('status_configuration_DeprecationLogFile'),
240 $this->getDeprecationLogFileLink()
244 if ($logFileSize > $this->deprecationLogFileSizeWarningThreshold
) {
245 $severity = tx_reports_reports_status_Status
::WARNING
;
248 if ($logFileSize > $this->deprecationLogFileSizeErrorThreshold
) {
249 $severity = tx_reports_reports_status_Status
::ERROR
;
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)
260 return t3lib_div
::makeInstance('tx_reports_reports_status_Status',
261 $title, $value, $message, $severity
266 * Creates a link to the deprecation log file with the absolute path as the
269 * @return string Link to the deprecation log file
271 protected function getDeprecationLogFileLink() {
272 $logFile = t3lib_div
::getDeprecationLogFileName();
273 $relativePath = t3lib_div
::resolveBackPath(
274 $this->backPath
. substr($logFile, strlen(PATH_site
))
276 $link = '<a href="' . $relativePath . '">' . $logFile . '</a>';
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']);