[BUGFIX] Unlimited memory limit handling in system status report
[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 * Determines the Install Tool's status, mainly concerning its protection.
37 *
38 * @return array List of statuses
39 * @see typo3/sysext/reports/interfaces/tx_reports_StatusProvider::getStatus()
40 */
41 public function getStatus() {
42 $statuses = array(
43 'Php' => $this->getPhpStatus(),
44 'PhpMemoryLimit' => $this->getPhpMemoryLimitStatus(),
45 'PhpRegisterGlobals' => $this->getPhpRegisterGlobalsStatus(),
46 'Webserver' => $this->getWebserverStatus(),
47 );
48
49 return $statuses;
50 }
51
52
53 /**
54 * Checks the current PHP version against a minimum required version.
55 *
56 * @return tx_reports_reports_status_Status A status of whether a minimum PHP version requirment is met
57 */
58 protected function getPhpStatus() {
59 $message = '';
60 $severity = tx_reports_reports_status_Status::OK;
61
62 if (version_compare(phpversion(), TYPO3_REQUIREMENTS_MINIMUM_PHP) < 0) {
63 $message = $GLOBALS['LANG']->getLL('status_phpTooOld');
64 $severity = tx_reports_reports_status_Status::ERROR;
65 }
66
67 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
68 $GLOBALS['LANG']->getLL('status_phpVersion'),
69 phpversion(),
70 $message,
71 $severity
72 );
73 }
74
75 /**
76 * Checks the current memory limit against a minimum required version.
77 *
78 * @return tx_reports_reports_status_Status A status of whether a minimum memory limit requirment is met
79 */
80 protected function getPhpMemoryLimitStatus() {
81 $memoryLimit = ini_get('memory_limit');
82 $memoryLimitBytes = t3lib_div::getBytesFromSizeMeasurement($memoryLimit);
83 $message = '';
84 $severity = tx_reports_reports_status_Status::OK;
85
86 if ($memoryLimitBytes > 0) {
87 if ($memoryLimitBytes < t3lib_div::getBytesFromSizeMeasurement(TYPO3_REQUIREMENTS_RECOMMENDED_PHP_MEMORY_LIMIT)) {
88 $message = sprintf($GLOBALS['LANG']->getLL('status_phpMemoryRecommendation'), $memoryLimit, TYPO3_REQUIREMENTS_RECOMMENDED_PHP_MEMORY_LIMIT);
89 $severity = tx_reports_reports_status_Status::WARNING;
90 }
91
92 if ($memoryLimitBytes < t3lib_div::getBytesFromSizeMeasurement(TYPO3_REQUIREMENTS_MINIMUM_PHP_MEMORY_LIMIT)) {
93 $message = sprintf($GLOBALS['LANG']->getLL('status_phpMemoryRequirement'), $memoryLimit, TYPO3_REQUIREMENTS_MINIMUM_PHP_MEMORY_LIMIT);
94 $severity = tx_reports_reports_status_Status::ERROR;
95 }
96
97 if ($severity > tx_reports_reports_status_Status::OK) {
98 if ($php_ini_path = get_cfg_var('cfg_file_path')) {
99 $message .= ' ' . sprintf($GLOBALS['LANG']->getLL('status_phpMemoryEditLimit'), $php_ini_path);
100 } else {
101 $message .= ' ' . $GLOBALS['LANG']->getLL('status_phpMemoryContactAdmin');
102 }
103 }
104 }
105
106 return t3lib_div::makeInstance(
107 'tx_reports_reports_status_Status',
108 $GLOBALS['LANG']->getLL('status_phpMemory'),
109 ($memoryLimitBytes > 0 ? $memoryLimit : $GLOBALS['LANG']->getLL('status_phpMemoryUnlimited')),
110 $message,
111 $severity
112 );
113 }
114
115 /**
116 * checks whether register globals is on or off.
117 *
118 * @return tx_reports_reports_status_Status A status of whether register globals is on or off
119 */
120 protected function getPhpRegisterGlobalsStatus() {
121 $value = $GLOBALS['LANG']->getLL('status_disabled');
122 $message = '';
123 $severity = tx_reports_reports_status_Status::OK;
124
125 $registerGlobals = trim(ini_get('register_globals'));
126
127 // can't reliably check for 'on', therefore checking for the oposite 'off', '', or 0
128 if (!empty($registerGlobals) && strtolower($registerGlobals) != 'off') {
129 $registerGlobalsHighlight = '<em>register_globals</em>';
130 $phpManualLink .= '<a href="http://php.net/configuration.changes">' . $GLOBALS['LANG']->getLL('status_phpRegisterGlobalsHowToChange') . '</a>';
131 $message = sprintf($GLOBALS['LANG']->getLL('status_phpRegisterGlobalsEnabled'), $registerGlobalsHighlight);
132 $message .= ' ' . sprintf($GLOBALS['LANG']->getLL('status_phpRegisterGlobalsSecurity'), $registerGlobalsHighlight);
133 $message .= ' ' . sprintf($GLOBALS['LANG']->getLL('status_phpRegisterGlobalsPHPManual'), $phpManualLink);
134 $severity = tx_reports_reports_status_Status::ERROR;
135 $value = $GLOBALS['LANG']->getLL('status_enabled')
136 . ' (\'' . $registerGlobals . '\')';
137 }
138
139 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
140 $GLOBALS['LANG']->getLL('status_phpRegisterGlobals'), $value, $message, $severity
141 );
142 }
143
144 /**
145 * Reports the webserver TYPO3 is running on.
146 *
147 * @return tx_reports_reports_status_Status The server software as a status
148 */
149 protected function getWebserverStatus() {
150 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
151 $GLOBALS['LANG']->getLL('status_webServer'),
152 $_SERVER['SERVER_SOFTWARE']
153 );
154 }
155 }
156
157
158 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/reports/status/class.tx_reports_reports_status_systemstatus.php'])) {
159 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/reports/status/class.tx_reports_reports_status_systemstatus.php']);
160 }
161
162 ?>