e21dc5378e638b90e8ea3a2921ff54a302da595c
[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 $message = '';
83 $severity = tx_reports_reports_status_Status::OK;
84
85 if ($memoryLimit && t3lib_div::getBytesFromSizeMeasurement($memoryLimit) < t3lib_div::getBytesFromSizeMeasurement(TYPO3_REQUIREMENTS_RECOMMENDED_PHP_MEMORY_LIMIT)) {
86 $message = sprintf($GLOBALS['LANG']->getLL('status_phpMemoryRecommendation'), $memoryLimit, TYPO3_REQUIREMENTS_RECOMMENDED_PHP_MEMORY_LIMIT);
87 $severity = tx_reports_reports_status_Status::WARNING;
88 }
89
90 if ($memoryLimit && t3lib_div::getBytesFromSizeMeasurement($memoryLimit) < t3lib_div::getBytesFromSizeMeasurement(TYPO3_REQUIREMENTS_MINIMUM_PHP_MEMORY_LIMIT)) {
91 $message = sprintf($GLOBALS['LANG']->getLL('status_phpMemoryRequirement'), $memoryLimit, TYPO3_REQUIREMENTS_MINIMUM_PHP_MEMORY_LIMIT);
92 $severity = tx_reports_reports_status_Status::ERROR;
93 }
94
95 if ($severity > tx_reports_reports_status_Status::OK) {
96 if ($php_ini_path = get_cfg_var('cfg_file_path')) {
97 $message .= ' ' . sprintf($GLOBALS['LANG']->getLL('status_phpMemoryEditLimit'), $php_ini_path);
98 } else {
99 $message .= ' ' . $GLOBALS['LANG']->getLL('status_phpMemoryContactAdmin');
100 }
101 }
102
103 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
104 $GLOBALS['LANG']->getLL('status_phpMemory'), $memoryLimit, $message, $severity
105 );
106 }
107
108 /**
109 * checks whether register globals is on or off.
110 *
111 * @return tx_reports_reports_status_Status A status of whether register globals is on or off
112 */
113 protected function getPhpRegisterGlobalsStatus() {
114 $value = $GLOBALS['LANG']->getLL('status_disabled');
115 $message = '';
116 $severity = tx_reports_reports_status_Status::OK;
117
118 $registerGlobals = trim(ini_get('register_globals'));
119
120 // can't reliably check for 'on', therefore checking for the oposite 'off', '', or 0
121 if (!empty($registerGlobals) && strtolower($registerGlobals) != 'off') {
122 $registerGlobalsHighlight = '<em>register_globals</em>';
123 $phpManualLink .= '<a href="http://php.net/configuration.changes">' . $GLOBALS['LANG']->getLL('status_phpRegisterGlobalsHowToChange') . '</a>';
124 $message = sprintf($GLOBALS['LANG']->getLL('status_phpRegisterGlobalsEnabled'), $registerGlobalsHighlight);
125 $message .= ' ' . sprintf($GLOBALS['LANG']->getLL('status_phpRegisterGlobalsSecurity'), $registerGlobalsHighlight);
126 $message .= ' ' . sprintf($GLOBALS['LANG']->getLL('status_phpRegisterGlobalsPHPManual'), $phpManualLink);
127 $severity = tx_reports_reports_status_Status::ERROR;
128 $value = $GLOBALS['LANG']->getLL('status_enabled')
129 . ' (\'' . $registerGlobals . '\')';
130 }
131
132 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
133 $GLOBALS['LANG']->getLL('status_phpRegisterGlobals'), $value, $message, $severity
134 );
135 }
136
137 /**
138 * Reports the webserver TYPO3 is running on.
139 *
140 * @return tx_reports_reports_status_Status The server software as a status
141 */
142 protected function getWebserverStatus() {
143 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
144 $GLOBALS['LANG']->getLL('status_webServer'),
145 $_SERVER['SERVER_SOFTWARE']
146 );
147 }
148 }
149
150
151 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/reports/status/class.tx_reports_reports_status_systemstatus.php'])) {
152 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/reports/status/class.tx_reports_reports_status_systemstatus.php']);
153 }
154
155 ?>