|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2009-2011 Ingo Renner <ingo@typo3.org> 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * 00017 * This script is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * This copyright notice MUST APPEAR in all copies of the script! 00023 ***************************************************************/ 00024 00025 00026 /** 00027 * Performs some checks about the install tool protection status 00028 * 00029 * @author Ingo Renner <ingo@typo3.org> 00030 * @package TYPO3 00031 * @subpackage reports 00032 * 00033 * $Id: class.tx_reports_reports_status_configurationstatus.php 10120 2011-01-18 20:03:36Z ohader $ 00034 */ 00035 class tx_reports_reports_status_ConfigurationStatus implements tx_reports_StatusProvider { 00036 00037 // 10 MB 00038 protected $deprecationLogFileSizeWarningThreshold = 10485760; 00039 // 100 MB 00040 protected $deprecationLogFileSizeErrorThreshold = 104857600; 00041 00042 /** 00043 * Backpath to the typo3 main directory 00044 * 00045 * @var string 00046 */ 00047 protected $backPath = '../'; 00048 00049 /** 00050 * Determines the Install Tool's status, mainly concerning its protection. 00051 * 00052 * @return array List of statuses 00053 * @see typo3/sysext/reports/interfaces/tx_reports_StatusProvider::getStatus() 00054 */ 00055 public function getStatus() { 00056 $statuses = array( 00057 'emptyReferenceIndex' => $this->getReferenceIndexStatus(), 00058 'deprecationLog' => $this->getDeprecationLogStatus(), 00059 'safeModeEnabled' => $this->getPhpSafeModeStatus() 00060 ); 00061 00062 if ($this->isMemcachedUsed()) { 00063 $statuses['memcachedConnection'] = $this->getMemcachedConnectionStatus(); 00064 } 00065 00066 return $statuses; 00067 } 00068 00069 /** 00070 * Checks if sys_refindex is empty. 00071 * 00072 * @return tx_reports_reports_status_Status An tx_reports_reports_status_Status object representing whether the reference index is empty or not 00073 */ 00074 protected function getReferenceIndexStatus() { 00075 $value = $GLOBALS['LANG']->getLL('status_ok'); 00076 $message = ''; 00077 $severity = tx_reports_reports_status_Status::OK; 00078 00079 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'sys_refindex'); 00080 $registry = t3lib_div::makeInstance('t3lib_Registry'); 00081 $lastRefIndexUpdate = $registry->get('core', 'sys_refindex_lastUpdate'); 00082 00083 if (!$count && $lastRefIndexUpdate) { 00084 $value = $GLOBALS['LANG']->getLL('status_empty'); 00085 $severity = tx_reports_reports_status_Status::WARNING; 00086 00087 $url = 'sysext/lowlevel/dbint/index.php?&id=0&SET[function]=refindex'; 00088 $message = sprintf( 00089 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.backend_reference_index'), 00090 '<a href="' . $url . '">', 00091 '</a>', 00092 t3lib_BeFunc::dateTime($lastRefIndexUpdate) 00093 ); 00094 } 00095 return t3lib_div::makeInstance('tx_reports_reports_status_Status', 00096 $GLOBALS['LANG']->getLL('status_referenceIndex'), $value, $message, $severity 00097 ); 00098 } 00099 00100 /** 00101 * Checks if PHP safe_mode is enabled. 00102 * 00103 * @return tx_reports_reports_status_Status A tx_reports_reports_status_Status object representing whether the safe_mode is enabled or not 00104 */ 00105 protected function getPhpSafeModeStatus() { 00106 $value = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:disabled'); 00107 $message = ''; 00108 $severity = tx_reports_reports_status_Status::OK; 00109 00110 if (t3lib_utility_PhpOptions::isSafeModeEnabled()) { 00111 $value = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:enabled'); 00112 $severity = tx_reports_reports_status_Status::WARNING; 00113 $message = $GLOBALS['LANG']->sL('status_configuration_PhpSafeModeEnabled'); 00114 } 00115 00116 return t3lib_div::makeInstance('tx_reports_reports_status_Status', 00117 $GLOBALS['LANG']->getLL('status_PhpSafeMode'), $value, $message, $severity 00118 ); 00119 } 00120 00121 /** 00122 * Checks whether memcached is configured, if that's the case we asume it's also used. 00123 * 00124 * @return boolean True if memcached is used, false otherwise. 00125 */ 00126 protected function isMemcachedUsed() { 00127 $memcachedUsed = FALSE; 00128 00129 $memcachedServers = $this->getConfiguredMemcachedServers(); 00130 if (count($memcachedServers)) { 00131 $memcachedUsed = TRUE; 00132 } 00133 00134 return $memcachedUsed; 00135 } 00136 00137 /** 00138 * Gets the configured memcached server connections. 00139 * 00140 * @return array An array of configured memcached server connections. 00141 */ 00142 protected function getConfiguredMemcachedServers() { 00143 $memcachedServers = array(); 00144 00145 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'])) { 00146 foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] as $table => $conf) { 00147 if (is_array($conf)) { 00148 foreach ($conf as $key => $value) { 00149 if (!is_array($value) && $value === 't3lib_cache_backend_MemcachedBackend') { 00150 $memcachedServers = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$table]['options']['servers']; 00151 break; 00152 } 00153 } 00154 } 00155 } 00156 } 00157 00158 return $memcachedServers; 00159 } 00160 00161 /** 00162 * Checks whether TYPO3 can connect to the configured memcached servers. 00163 * 00164 * @return tx_reports_reports_status_Status An tx_reports_reports_status_Status object representing whether TYPO3 can connect to the configured memcached servers 00165 */ 00166 protected function getMemcachedConnectionStatus() { 00167 $value = $GLOBALS['LANG']->getLL('status_ok'); 00168 $message = ''; 00169 $severity = tx_reports_reports_status_Status::OK; 00170 00171 $failedConnections = array(); 00172 $defaultMemcachedPort = ini_get('memcache.default_port'); 00173 $memcachedServers = $this->getConfiguredMemcachedServers(); 00174 00175 if (function_exists('memcache_connect') && is_array($memcachedServers)) { 00176 foreach ($memcachedServers as $testServer) { 00177 $configuredServer = $testServer; 00178 if (substr($testServer, 0, 7) == 'unix://') { 00179 $host = $testServer; 00180 $port = 0; 00181 } else { 00182 if (substr($testServer, 0, 6) === 'tcp://') { 00183 $testServer = substr($testServer, 6); 00184 } 00185 if (strstr($testServer, ':') !== FALSE) { 00186 list($host, $port) = explode(':', $testServer, 2); 00187 } else { 00188 $host = $testServer; 00189 $port = $defaultMemcachedPort; 00190 } 00191 } 00192 $memcachedConnection = @memcache_connect($host, $port); 00193 if ($memcachedConnection != null) { 00194 memcache_close($memcachedConnection); 00195 } else { 00196 $failedConnections[] = $configuredServer; 00197 } 00198 } 00199 } 00200 00201 if (count($failedConnections)) { 00202 $value = $GLOBALS['LANG']->getLL('status_connectionFailed'); 00203 $severity = tx_reports_reports_status_Status::WARNING; 00204 00205 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.memcache_not_usable') 00206 . '<br /><br />' 00207 . '<ul><li>' 00208 . implode('</li><li>', $failedConnections) 00209 . '</li></ul>'; 00210 } 00211 00212 return t3lib_div::makeInstance('tx_reports_reports_status_Status', 00213 $GLOBALS['LANG']->getLL('status_memcachedConfiguration'), $value, $message, $severity 00214 ); 00215 } 00216 00217 /** 00218 * Provides status information on the deprecation log, whether it's enabled 00219 * and if so whether certain limits in file size are reached. 00220 * 00221 * @return tx_reports_reports_status_Status The deprecation log status. 00222 */ 00223 protected function getDeprecationLogStatus() { 00224 $title = $GLOBALS['LANG']->getLL('status_configuration_DeprecationLog'); 00225 $value = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:disabled'); 00226 $message = ''; 00227 $severity = tx_reports_reports_status_Status::OK; 00228 00229 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog']) { 00230 $value = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:enabled'); 00231 $message = '<p>' . $GLOBALS['LANG']->getLL('status_configuration_DeprecationLogEnabled') . '</p>'; 00232 $severity = tx_reports_reports_status_Status::NOTICE; 00233 00234 $logFile = t3lib_div::getDeprecationLogFileName(); 00235 $logFileSize = 0; 00236 00237 if (file_exists($logFile)) { 00238 $logFileSize = filesize($logFile); 00239 00240 $message .= '<p> ' . sprintf( 00241 $GLOBALS['LANG']->getLL('status_configuration_DeprecationLogFile'), 00242 $this->getDeprecationLogFileLink() 00243 ) . '</p>'; 00244 } 00245 00246 if ($logFileSize > $this->deprecationLogFileSizeWarningThreshold) { 00247 $severity = tx_reports_reports_status_Status::WARNING; 00248 } 00249 00250 if ($logFileSize > $this->deprecationLogFileSizeErrorThreshold) { 00251 $severity = tx_reports_reports_status_Status::ERROR; 00252 } 00253 00254 if ($severity > tx_reports_reports_status_Status::OK) { 00255 $message .= '<p> ' . sprintf( 00256 $GLOBALS['LANG']->getLL('status_configuration_DeprecationLogSize'), 00257 t3lib_div::formatSize($logFileSize) 00258 ) . '</p>'; 00259 } 00260 } 00261 00262 return t3lib_div::makeInstance('tx_reports_reports_status_Status', 00263 $title, $value, $message, $severity 00264 ); 00265 } 00266 00267 /** 00268 * Creates a link to the deprecation log file with the absolute path as the 00269 * link text. 00270 * 00271 * @return string Link to the deprecation log file 00272 */ 00273 protected function getDeprecationLogFileLink() { 00274 $logFile = t3lib_div::getDeprecationLogFileName(); 00275 $relativePath = t3lib_div::resolveBackPath( 00276 $this->backPath . substr($logFile, strlen(PATH_site)) 00277 ); 00278 $link = '<a href="' . $relativePath . '">' . $logFile . '</a>'; 00279 00280 return $link; 00281 } 00282 } 00283 00284 00285 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/reports/status/class.tx_reports_reports_status_configurationstatus.php'])) { 00286 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/reports/status/class.tx_reports_reports_status_configurationstatus.php']); 00287 } 00288 00289 ?>
1.8.0