[TASK] EXT:reports Minor typo in HTML
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / Classes / Report / Status / SystemStatus.php
1 <?php
2 namespace TYPO3\CMS\Reports\Report\Status;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009-2011 Ingo Renner <ingo@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * Performs several checks about the system's health
28 *
29 * @author Ingo Renner <ingo@typo3.org>
30 */
31 class SystemStatus implements \TYPO3\CMS\Reports\StatusProviderInterface {
32
33 /**
34 * PHP modules which are required. Can be changed by hook in getMissingPhpModules()
35 *
36 * @var array
37 */
38 protected $requiredPhpModules = array(
39 'fileinfo',
40 'filter',
41 'gd',
42 'json',
43 'mysql',
44 'pcre',
45 'session',
46 'SPL',
47 'standard',
48 'openssl',
49 'xml',
50 'zlib',
51 'soap',
52 'zip'
53 );
54
55 /**
56 * Determines the Install Tool's status, mainly concerning its protection.
57 *
58 * @return array List of statuses
59 * @see typo3/sysext/reports/interfaces/tx_reports_StatusProvider::getStatus()
60 */
61 public function getStatus() {
62 $this->executeAdminCommand();
63 $statuses = array(
64 'Php' => $this->getPhpStatus(),
65 'PhpMemoryLimit' => $this->getPhpMemoryLimitStatus(),
66 'PhpPeakMemory' => $this->getPhpPeakMemoryStatus(),
67 'Webserver' => $this->getWebserverStatus(),
68 'PhpModules' => $this->getMissingPhpModules()
69 );
70 return $statuses;
71 }
72
73 /**
74 * Checks the current PHP version against a minimum required version.
75 *
76 * @return \TYPO3\CMS\Reports\Status A status of whether a minimum PHP version requirement is met
77 */
78 protected function getPhpStatus() {
79 $message = '';
80 $severity = \TYPO3\CMS\Reports\Status::OK;
81 if (version_compare(phpversion(), TYPO3_REQUIREMENTS_MINIMUM_PHP) < 0) {
82 $message = $GLOBALS['LANG']->getLL('status_phpTooOld');
83 $severity = \TYPO3\CMS\Reports\Status::ERROR;
84 }
85 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Reports\\Status', $GLOBALS['LANG']->getLL('status_phpVersion'), phpversion(), $message, $severity);
86 }
87
88 /**
89 * Checks the current memory limit against a minimum required version.
90 *
91 * @return \TYPO3\CMS\Reports\Status A status of whether a minimum memory limit requirement is met
92 */
93 protected function getPhpMemoryLimitStatus() {
94 $memoryLimit = ini_get('memory_limit');
95 $memoryLimitBytes = \TYPO3\CMS\Core\Utility\GeneralUtility::getBytesFromSizeMeasurement($memoryLimit);
96 $message = '';
97 $severity = \TYPO3\CMS\Reports\Status::OK;
98 if ($memoryLimitBytes > 0) {
99 if ($memoryLimitBytes < \TYPO3\CMS\Core\Utility\GeneralUtility::getBytesFromSizeMeasurement(TYPO3_REQUIREMENTS_RECOMMENDED_PHP_MEMORY_LIMIT)) {
100 $message = sprintf($GLOBALS['LANG']->getLL('status_phpMemoryRecommendation'), $memoryLimit, TYPO3_REQUIREMENTS_RECOMMENDED_PHP_MEMORY_LIMIT);
101 $severity = \TYPO3\CMS\Reports\Status::WARNING;
102 }
103 if ($memoryLimitBytes < \TYPO3\CMS\Core\Utility\GeneralUtility::getBytesFromSizeMeasurement(TYPO3_REQUIREMENTS_MINIMUM_PHP_MEMORY_LIMIT)) {
104 $message = sprintf($GLOBALS['LANG']->getLL('status_phpMemoryRequirement'), $memoryLimit, TYPO3_REQUIREMENTS_MINIMUM_PHP_MEMORY_LIMIT);
105 $severity = \TYPO3\CMS\Reports\Status::ERROR;
106 }
107 if ($severity > \TYPO3\CMS\Reports\Status::OK) {
108 if ($php_ini_path = get_cfg_var('cfg_file_path')) {
109 $message .= ' ' . sprintf($GLOBALS['LANG']->getLL('status_phpMemoryEditLimit'), $php_ini_path);
110 } else {
111 $message .= ' ' . $GLOBALS['LANG']->getLL('status_phpMemoryContactAdmin');
112 }
113 }
114 }
115 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Reports\\Status', $GLOBALS['LANG']->getLL('status_phpMemory'), $memoryLimitBytes > 0 ? $memoryLimit : $GLOBALS['LANG']->getLL('status_phpMemoryUnlimited'), $message, $severity);
116 }
117
118 /**
119 * Executes commands like clearing the memory status flag
120 *
121 * @return void
122 */
123 protected function executeAdminCommand() {
124 $command = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('adminCmd');
125 switch ($command) {
126 case 'clear_peak_memory_usage_flag':
127 /** @var $registry \TYPO3\CMS\Core\Registry */
128 $registry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Registry');
129 $registry->remove('core', 'reports-peakMemoryUsage');
130 break;
131 }
132 }
133
134 /**
135 * Checks if there was a request in the past which approached the memory limit
136 *
137 * @return tx_reports_reports_status_Status A status of whether the memory limit was approached by one of the requests
138 */
139 protected function getPhpPeakMemoryStatus() {
140 /** @var $registry \TYPO3\CMS\Core\Registry */
141 $registry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Registry');
142 $peakMemoryUsage = $registry->get('core', 'reports-peakMemoryUsage');
143 $memoryLimit = \TYPO3\CMS\Core\Utility\GeneralUtility::getBytesFromSizeMeasurement(ini_get('memory_limit'));
144 $value = $GLOBALS['LANG']->getLL('status_ok');
145 $message = '';
146 $severity = \TYPO3\CMS\Reports\Status::OK;
147 $bytesUsed = $peakMemoryUsage['used'];
148 $percentageUsed = $memoryLimit ? number_format($bytesUsed / $memoryLimit * 100, 1) . '%' : '?';
149 $dateOfPeak = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $peakMemoryUsage['tstamp']);
150 $urlOfPeak = '<a href="' . htmlspecialchars($peakMemoryUsage['url']) . '">' . htmlspecialchars($peakMemoryUsage['url']) . '</a>';
151 $clearFlagUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL') . '&amp;adminCmd=clear_peak_memory_usage_flag';
152 if ($peakMemoryUsage['used']) {
153 $message = sprintf($GLOBALS['LANG']->getLL('status_phpPeakMemoryTooHigh'), \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($peakMemoryUsage['used']), $percentageUsed, \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($memoryLimit), $dateOfPeak, $urlOfPeak);
154 $message .= ' <a href="' . $clearFlagUrl . '">' . $GLOBALS['LANG']->getLL('status_phpPeakMemoryClearFlag') . '</a>.';
155 $severity = \TYPO3\CMS\Reports\Status::WARNING;
156 $value = $percentageUsed;
157 }
158 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Reports\\Status', $GLOBALS['LANG']->getLL('status_phpPeakMemory'), $value, $message, $severity);
159 }
160
161 /**
162 * Reports the webserver TYPO3 is running on.
163 *
164 * @return \TYPO3\CMS\Reports\Status The server software as a status
165 */
166 protected function getWebserverStatus() {
167 $value = $_SERVER['SERVER_SOFTWARE'];
168 $message = '';
169 // The additional information are only important on a Windows system with Apache running.
170 // Even with lowest Apache ServerTokens (Prod[uctOnly]) the name is returned.
171 if (TYPO3_OS === 'WIN' && substr($value, 0, 6) === 'Apache') {
172 $message .= '<p>' . $GLOBALS['LANG']->getLL('status_webServer_infoText') . '</p>';
173 $message .= '<div class="typo3-message message-warning">' . $GLOBALS['LANG']->getLL('status_webServer_threadStackSize') . '</div>';
174 }
175 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Reports\\Status', $GLOBALS['LANG']->getLL('status_webServer'), $value, $message);
176 }
177
178 /**
179 * Reports whether any of the required PHP modules are missing
180 *
181 * @return \TYPO3\CMS\Reports\Status A status of missing PHP modules
182 */
183 protected function getMissingPhpModules() {
184 // Hook to adjust the required PHP modules
185 $modules = $this->requiredPhpModules;
186 if (is_array(${$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install/mod/class.tx_install.php']['requiredPhpModules']})) {
187 foreach (${$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install/mod/class.tx_install.php']['requiredPhpModules']} as $classData) {
188 $hookObject = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classData);
189 $modules = $hookObject->setRequiredPhpModules($modules, $this);
190 }
191 }
192 $missingPhpModules = array();
193 foreach ($modules as $module) {
194 if (is_array($module)) {
195 $detectedSubmodules = FALSE;
196 foreach ($module as $submodule) {
197 if (extension_loaded($submodule)) {
198 $detectedSubmodules = TRUE;
199 }
200 }
201 if ($detectedSubmodules === FALSE) {
202 $missingPhpModules[] = sprintf($GLOBALS['LANG']->getLL('status_phpModulesGroup'), '(' . implode(', ', $module) . ')');
203 }
204 } elseif (!extension_loaded($module)) {
205 $missingPhpModules[] = $module;
206 }
207 }
208 if (count($missingPhpModules) > 0) {
209 $value = $GLOBALS['LANG']->getLL('status_phpModulesMissing');
210 $message = sprintf($GLOBALS['LANG']->getLL('status_phpModulesList'), implode(', ', $missingPhpModules));
211 $message .= ' ' . $GLOBALS['LANG']->getLL('status_phpModulesInfo');
212 $severity = \TYPO3\CMS\Reports\Status::ERROR;
213 } else {
214 $value = $GLOBALS['LANG']->getLL('status_phpModulesPresent');
215 $message = '';
216 $severity = \TYPO3\CMS\Reports\Status::OK;
217 }
218 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Reports\\Status', $GLOBALS['LANG']->getLL('status_phpModules'), $value, $message, $severity);
219 }
220
221 }
222
223
224 ?>