Fixed bug #12025: Make statuses in the status report sorted and grouped
[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 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 * Determines the Install Tool's status, mainly concerning its protection.
37 *
38 * @see typo3/sysext/reports/interfaces/tx_reports_StatusProvider::getStatus()
39 */
40 public function getStatus() {
41 $statuses = array(
42 'Php' => $this->getPhpStatus(),
43 'PhpMemoryLimit' => $this->getPhpMemoryLimitStatus(),
44 'PhpRegisterGlobals' => $this->getPhpRegisterGlobalsStatus(),
45 'Webserver' => $this->getWebserverStatus(),
46 );
47
48 return $statuses;
49 }
50
51
52 /**
53 * Checks the current PHP version against a minimum required version.
54 *
55 * @return tx_reports_reports_status_Status A status of whether a minimum PHP version requirment is met
56 */
57 protected function getPhpStatus() {
58 $message = '';
59 $severity = tx_reports_reports_status_Status::OK;
60
61 if (version_compare(phpversion(), TYPO3_REQUIREMENTS_MINIMUM_PHP) < 0) {
62 $message = 'Your PHP installation is too old.';
63 $severity = tx_reports_reports_status_Status::ERROR;
64 }
65
66 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
67 'PHP',
68 phpversion(),
69 $message,
70 $severity
71 );
72 }
73
74 /**
75 * Checks the current memory limit against a minimum required version.
76 *
77 * @return tx_reports_reports_status_Status A status of whether a minimum memory limit requirment is met
78 */
79 protected function getPhpMemoryLimitStatus() {
80 $memoryLimit = ini_get('memory_limit');
81 $message = '';
82 $severity = tx_reports_reports_status_Status::OK;
83
84 if ($memoryLimit && t3lib_div::getBytesFromSizeMeasurement($memoryLimit) < t3lib_div::getBytesFromSizeMeasurement(TYPO3_REQUIREMENTS_RECOMMENDED_PHP_MEMORY_LIMIT)) {
85 $message = 'Depending on your configuration, TYPO3 can run with a ' . $memoryLimit . ' PHP memory limit. However, a ' . TYPO3_REQUIREMENTS_RECOMMENDED_PHP_MEMORY_LIMIT . ' PHP memory limit or above is recommended, especially if your site uses additional extensions.';
86 $severity = tx_reports_reports_status_Status::WARNING;
87 }
88
89 if ($memoryLimit && t3lib_div::getBytesFromSizeMeasurement($memoryLimit) < t3lib_div::getBytesFromSizeMeasurement(TYPO3_REQUIREMENTS_MINIMUM_PHP_MEMORY_LIMIT)) {
90 $message = 'Depending on your configuration, TYPO3 can run with a ' . $memoryLimit . ' PHP memory limit. However, a ' . TYPO3_REQUIREMENTS_MINIMUM_PHP_MEMORY_LIMIT . ' PHP memory limit or above is required, especially if your site uses additional extensions.';
91 $severity = tx_reports_reports_status_Status::ERROR;
92 }
93
94 if ($severity > tx_reports_reports_status_Status::OK) {
95 if ($php_ini_path = get_cfg_var('cfg_file_path')) {
96 $message .= ' Increase the memory limit by editing the memory_limit parameter in the file ' . $php_ini_path . ' and then restart your web server (or contact your system administrator or hosting provider for assistance).';
97 } else {
98 $message .= ' Contact your system administrator or hosting provider for assistance with increasing your PHP memory limit.';
99 }
100 }
101
102 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
103 'PHP Memory Limit', $memoryLimit, $message, $severity
104 );
105 }
106
107 /**
108 * checks whether register globals is on or off.
109 *
110 * @return tx_reports_reports_status_Status A status of whether register globals is on or off
111 */
112 protected function getPhpRegisterGlobalsStatus() {
113 $value = $GLOBALS['LANG']->getLL('status_disabled');
114 $message = '';
115 $severity = tx_reports_reports_status_Status::OK;
116
117 $registerGlobals = trim(ini_get('register_globals'));
118
119 // can't reliably check for 'on', therefore checking for the oposite 'off', '', or 0
120 if (!empty($registerGlobals) && strtolower($registerGlobals) != 'off') {
121 $message = '<em>register_globals</em> is enabled. TYPO3 requires this configuration directive to be disabled. Your site may not be secure when <em>register_globals</em> is enabled. The PHP manual has instructions for <a href="http://php.net/configuration.changes">how to change configuration settings</a>.';
122 $severity = tx_reports_reports_status_Status::ERROR;
123 $value = $GLOBALS['LANG']->getLL('status_enabled')
124 . ' (\'' . $registerGlobals . '\')';
125 }
126
127 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
128 'PHP Register Globals', $value, $message, $severity
129 );
130 }
131
132 /**
133 * Reports the webserver TYPO3 is running on.
134 *
135 * @return tx_reports_reports_status_Status The server software as a status
136 */
137 protected function getWebserverStatus() {
138 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
139 'Web Server',
140 $_SERVER['SERVER_SOFTWARE']
141 );
142 }
143 }
144
145
146 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/reports/reports/status/class.tx_reports_reports_status_systemstatus.php']) {
147 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/reports/reports/status/class.tx_reports_reports_status_systemstatus.php']);
148 }
149
150 ?>