[TASK] Require PHP setting register_globals set to Off
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / reports / status / class.tx_reports_reports_status_systemstatus.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 several checks about the system's health
28 *
29 * @author Ingo Renner <ingo@typo3.org>
30 * @package TYPO3
31 * @subpackage reports
32 */
33 class tx_reports_reports_status_SystemStatus implements tx_reports_StatusProvider {
34
35 /**
36 * PHP modules which are required. Can be changed by hook in getMissingPhpModules()
37 *
38 * @var array
39 */
40 protected $requiredPhpModules = array(
41 'fileinfo', 'filter', 'gd', 'json', 'mysql', 'pcre', 'session', 'SPL', 'standard', 'openssl', 'xml', 'zlib', 'soap'
42 );
43
44 /**
45 * Determines the Install Tool's status, mainly concerning its protection.
46 *
47 * @return array List of statuses
48 * @see typo3/sysext/reports/interfaces/tx_reports_StatusProvider::getStatus()
49 */
50 public function getStatus() {
51 $this->executeAdminCommand();
52
53 $statuses = array(
54 'Php' => $this->getPhpStatus(),
55 'PhpMemoryLimit' => $this->getPhpMemoryLimitStatus(),
56 'PhpPeakMemory' => $this->getPhpPeakMemoryStatus(),
57 'Webserver' => $this->getWebserverStatus(),
58 'PhpModules' => $this->getMissingPhpModules(),
59 );
60
61 return $statuses;
62 }
63
64 /**
65 * Checks the current PHP version against a minimum required version.
66 *
67 * @return tx_reports_reports_status_Status A status of whether a minimum PHP version requirement is met
68 */
69 protected function getPhpStatus() {
70 $message = '';
71 $severity = tx_reports_reports_status_Status::OK;
72
73 if (version_compare(phpversion(), TYPO3_REQUIREMENTS_MINIMUM_PHP) < 0) {
74 $message = $GLOBALS['LANG']->getLL('status_phpTooOld');
75 $severity = tx_reports_reports_status_Status::ERROR;
76 }
77
78 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
79 $GLOBALS['LANG']->getLL('status_phpVersion'),
80 phpversion(),
81 $message,
82 $severity
83 );
84 }
85
86 /**
87 * Checks the current memory limit against a minimum required version.
88 *
89 * @return tx_reports_reports_status_Status A status of whether a minimum memory limit requirement is met
90 */
91 protected function getPhpMemoryLimitStatus() {
92 $memoryLimit = ini_get('memory_limit');
93 $memoryLimitBytes = t3lib_div::getBytesFromSizeMeasurement($memoryLimit);
94 $message = '';
95 $severity = tx_reports_reports_status_Status::OK;
96
97 if ($memoryLimitBytes > 0) {
98 if ($memoryLimitBytes < t3lib_div::getBytesFromSizeMeasurement(TYPO3_REQUIREMENTS_RECOMMENDED_PHP_MEMORY_LIMIT)) {
99 $message = sprintf($GLOBALS['LANG']->getLL('status_phpMemoryRecommendation'), $memoryLimit, TYPO3_REQUIREMENTS_RECOMMENDED_PHP_MEMORY_LIMIT);
100 $severity = tx_reports_reports_status_Status::WARNING;
101 }
102
103 if ($memoryLimitBytes < t3lib_div::getBytesFromSizeMeasurement(TYPO3_REQUIREMENTS_MINIMUM_PHP_MEMORY_LIMIT)) {
104 $message = sprintf($GLOBALS['LANG']->getLL('status_phpMemoryRequirement'), $memoryLimit, TYPO3_REQUIREMENTS_MINIMUM_PHP_MEMORY_LIMIT);
105 $severity = tx_reports_reports_status_Status::ERROR;
106 }
107
108 if ($severity > tx_reports_reports_status_Status::OK) {
109 if ($php_ini_path = get_cfg_var('cfg_file_path')) {
110 $message .= ' ' . sprintf($GLOBALS['LANG']->getLL('status_phpMemoryEditLimit'), $php_ini_path);
111 } else {
112 $message .= ' ' . $GLOBALS['LANG']->getLL('status_phpMemoryContactAdmin');
113 }
114 }
115 }
116
117 return t3lib_div::makeInstance(
118 'tx_reports_reports_status_Status',
119 $GLOBALS['LANG']->getLL('status_phpMemory'),
120 ($memoryLimitBytes > 0 ? $memoryLimit : $GLOBALS['LANG']->getLL('status_phpMemoryUnlimited')),
121 $message,
122 $severity
123 );
124 }
125
126 /**
127 * Executes commands like clearing the memory status flag
128 *
129 * @return void
130 */
131 protected function executeAdminCommand() {
132 $command = t3lib_div::_GET('adminCmd');
133
134 switch ($command) {
135 case 'clear_peak_memory_usage_flag':
136 /** @var $registry t3lib_Registry */
137 $registry = t3lib_div::makeInstance('t3lib_Registry');
138 $registry->remove('core', 'reports-peakMemoryUsage');
139 break;
140 }
141 }
142
143 /**
144 * Checks if there was a request in the past which approached the memory limit
145 *
146 * @return tx_reports_reports_status_Status A status of whether the memory limit was approached by one of the requests
147 */
148 protected function getPhpPeakMemoryStatus() {
149 /** @var $registry t3lib_Registry */
150 $registry = t3lib_div::makeInstance('t3lib_Registry');
151 $peakMemoryUsage = $registry->get('core', 'reports-peakMemoryUsage');
152 $memoryLimit = t3lib_div::getBytesFromSizeMeasurement(ini_get('memory_limit'));
153 $value = $GLOBALS['LANG']->getLL('status_ok');
154
155 $message = '';
156 $severity = tx_reports_reports_status_Status::OK;
157 $bytesUsed = $peakMemoryUsage['used'];
158 $percentageUsed = $memoryLimit ? number_format($bytesUsed / $memoryLimit * 100, 1) . '%' : '?';
159 $dateOfPeak = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $peakMemoryUsage['tstamp']);
160 $urlOfPeak = '<a href="' . htmlspecialchars($peakMemoryUsage['url']) . '">' . htmlspecialchars($peakMemoryUsage['url']) . '</a>';
161 $clearFlagUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_URL') . '&amp;adminCmd=clear_peak_memory_usage_flag';
162
163 if ($peakMemoryUsage['used']) {
164 $message = sprintf(
165 $GLOBALS['LANG']->getLL('status_phpPeakMemoryTooHigh'),
166 t3lib_div::formatSize($peakMemoryUsage['used']),
167 $percentageUsed,
168 t3lib_div::formatSize($memoryLimit),
169 $dateOfPeak,
170 $urlOfPeak
171 );
172 $message .= ' <a href="' . $clearFlagUrl . '">' . $GLOBALS['LANG']->getLL('status_phpPeakMemoryClearFlag') . '</a>.';
173 $severity = tx_reports_reports_status_Status::WARNING;
174 $value = $percentageUsed;
175 }
176
177 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
178 $GLOBALS['LANG']->getLL('status_phpPeakMemory'), $value, $message, $severity
179 );
180 }
181
182 /**
183 * Reports the webserver TYPO3 is running on.
184 *
185 * @return tx_reports_reports_status_Status The server software as a status
186 */
187 protected function getWebserverStatus() {
188 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
189 $GLOBALS['LANG']->getLL('status_webServer'),
190 $_SERVER['SERVER_SOFTWARE']
191 );
192 }
193
194 /**
195 * Reports whether any of the required PHP modules are missing
196 *
197 * @return tx_reports_reports_status_Status A status of missing PHP modules
198 */
199 protected function getMissingPhpModules() {
200 // Hook to adjust the required PHP modules
201 $modules = $this->requiredPhpModules;
202 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install/mod/class.tx_install.php']['requiredPhpModules'])) {
203 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install/mod/class.tx_install.php']['requiredPhpModules'] as $classData) {
204 $hookObject = t3lib_div::getUserObj($classData);
205 $modules = $hookObject->setRequiredPhpModules($modules, $this);
206 }
207 }
208 $missingPhpModules = array();
209 foreach ($modules as $module) {
210 if (is_array($module)) {
211 $detectedSubmodules = FALSE;
212 foreach ($module as $submodule) {
213 if (extension_loaded($submodule)) {
214 $detectedSubmodules = TRUE;
215 }
216 }
217 if ($detectedSubmodules === FALSE) {
218 $missingPhpModules[] = sprintf($GLOBALS['LANG']->getLL('status_phpModulesGroup'), '(' . implode(', ', $module) . ')');
219 }
220 } elseif (!extension_loaded($module)) {
221 $missingPhpModules[] = $module;
222 }
223 }
224 if (count($missingPhpModules) > 0) {
225 $value = $GLOBALS['LANG']->getLL('status_phpModulesMissing');
226 $message = sprintf($GLOBALS['LANG']->getLL('status_phpModulesList'), implode(', ', $missingPhpModules));
227 $message .= ' ' . $GLOBALS['LANG']->getLL('status_phpModulesInfo');
228 $severity = tx_reports_reports_status_Status::ERROR;
229 } else {
230 $value = $GLOBALS['LANG']->getLL('status_phpModulesPresent');
231 $message = '';
232 $severity = tx_reports_reports_status_Status::OK;
233 }
234 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
235 $GLOBALS['LANG']->getLL('status_phpModules'), $value, $message, $severity
236 );
237 }
238 }
239 ?>