1<?php
2/* Copyright (C) 2001-2002	Rodolphe Quiedeville	<rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2012	Laurent Destailleur		<eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012	Regis Houssin			<regis.houssin@inodbox.com>
5 * Copyright (C) 2016       Juanjo Menent			<jmenent@2byte.es>
6 * Copyright (C) 2020       Tobias Sekan			<tobias.sekan@startmail.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22/**
23 *      \file       htdocs/admin/system/phpinfo.php
24 *		\brief      Page des infos systeme de php
25 */
26
27require '../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
30
31$langs->loadLangs(array("admin", "install", "errors"));
32
33if (!$user->admin) {
34	accessforbidden();
35}
36
37
38
39/*
40 * View
41 */
42
43llxHeader();
44
45$title = 'InfoPHP';
46
47if (isset($title)) {
48	print load_fiche_titre($langs->trans($title), '', 'title_setup');
49}
50
51
52// Check PHP setup is OK
53$maxphp = @ini_get('upload_max_filesize'); // In unknown
54if (preg_match('/k$/i', $maxphp)) {
55	$maxphp = preg_replace('/k$/i', '', $maxphp);
56	$maxphp = $maxphp * 1;
57}
58if (preg_match('/m$/i', $maxphp)) {
59	$maxphp = preg_replace('/m$/i', '', $maxphp);
60	$maxphp = $maxphp * 1024;
61}
62if (preg_match('/g$/i', $maxphp)) {
63	$maxphp = preg_replace('/g$/i', '', $maxphp);
64	$maxphp = $maxphp * 1024 * 1024;
65}
66if (preg_match('/t$/i', $maxphp)) {
67	$maxphp = preg_replace('/t$/i', '', $maxphp);
68	$maxphp = $maxphp * 1024 * 1024 * 1024;
69}
70$maxphp2 = @ini_get('post_max_size'); // In unknown
71if (preg_match('/k$/i', $maxphp2)) {
72	$maxphp2 = preg_replace('/k$/i', '', $maxphp2);
73	$maxphp2 = $maxphp2 * 1;
74}
75if (preg_match('/m$/i', $maxphp2)) {
76	$maxphp2 = preg_replace('/m$/i', '', $maxphp2);
77	$maxphp2 = $maxphp2 * 1024;
78}
79if (preg_match('/g$/i', $maxphp2)) {
80	$maxphp2 = preg_replace('/g$/i', '', $maxphp2);
81	$maxphp2 = $maxphp2 * 1024 * 1024;
82}
83if (preg_match('/t$/i', $maxphp2)) {
84	$maxphp2 = preg_replace('/t$/i', '', $maxphp2);
85	$maxphp2 = $maxphp2 * 1024 * 1024 * 1024;
86}
87if ($maxphp > 0 && $maxphp2 > 0 && $maxphp > $maxphp2) {
88	$langs->load("errors");
89	print info_admin($langs->trans("WarningParamUploadMaxFileSizeHigherThanPostMaxSize", @ini_get('upload_max_filesize'), @ini_get('post_max_size')), 0, 0, 0, 'warning');
90	print '<br>';
91}
92
93
94print '<table class="noborder centpercent">';
95print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
96
97$ErrorPicturePath = "../../theme/eldy/img/error.png";
98$WarningPicturePath = "../../theme/eldy/img/warning.png";
99$OkayPicturePath = "../../theme/eldy/img/tick.png";
100
101print '<tr><td>'.$langs->trans("Version").'</td><td>';
102
103$arrayphpminversionerror = array(5, 5, 0);
104$arrayphpminversionwarning = array(5, 6, 0);
105
106if (versioncompare(versionphparray(), $arrayphpminversionerror) < 0) {
107	print '<img src="'.$ErrorPicturePath.'" alt="Error"> '.$langs->trans("ErrorPHPVersionTooLow", versiontostring($arrayphpminversionerror));
108} elseif (versioncompare(versionphparray(), $arrayphpminversionwarning) < 0) {
109	print '<img src="'.$WarningPicturePath.'" alt="Warning"> '.$langs->trans("ErrorPHPVersionTooLow", versiontostring($arrayphpminversionwarning));
110} else {
111	print '<img src="'.$OkayPicturePath.'" alt="Ok"> '.versiontostring(versionphparray());
112}
113
114print '</td></tr>';
115print '<tr><td>GET and POST support</td><td>';
116
117if (!isset($_GET["testget"]) && !isset($_POST["testpost"]) && !isset($_GET["mainmenu"])) {	// We must keep $_GET and $_POST here
118	print '<img src="'.$WarningPicturePath.'" alt="Warning"> '.$langs->trans("PHPSupportPOSTGETKo");
119	print ' (<a href="'.$_SERVER["PHP_SELF"].'?testget=ok">'.$langs->trans("Recheck").'</a>)';
120} else {
121	print '<img src="'.$OkayPicturePath.'" alt="Ok"> '.$langs->trans("PHPSupportPOSTGETOk");
122}
123
124print '</td></tr>';
125print '<tr><td>Sessions support</td><td>';
126if (!function_exists("session_id")) {
127	print '<img src="'.$ErrorPicturePath.'" alt="Error"> '.$langs->trans("ErrorPHPDoesNotSupportSessions");
128} else {
129	print '<img src="'.$OkayPicturePath.'" alt="Ok"> '.$langs->trans("PHPSupportSessions");
130}
131print '</td></tr>';
132
133print '<tr><td>UTF-8 support</td><td>';
134if (!function_exists("utf8_encode")) {
135	print '<img src="'.$WarningPicturePath.'" alt="Warning"> '.$langs->trans("ErrorPHPDoesNotSupport", "UTF8");
136} else {
137	print '<img src="'.$OkayPicturePath.'" alt="Ok"> '.$langs->trans("PHPSupport", "UTF8");
138}
139print '</td></tr>';
140
141print '</table>';
142
143print '<br>';
144
145$activatedExtensions = array();
146$loadedExtensions    = array_map('strtolower', get_loaded_extensions(false));
147
148print '<table class="noborder centpercent">';
149print '<tr class="liste_titre">';
150print '<td class="titlefield">'.$langs->trans("Extension").'</td>';
151print '<td>'.$langs->trans("Test").'</td>';
152print '</tr>';
153
154$functions = ["mb_check_encoding"];
155$name      = "MBString";
156
157print "<tr>";
158print "<td>".$name."</td>";
159print getResultColumn($name, $activatedExtensions, $loadedExtensions, $functions);
160print "</tr>";
161
162$functions = ["json_decode"];
163$name      = "JSON";
164
165print "<tr>";
166print "<td>".$name."</td>";
167print getResultColumn($name, $activatedExtensions, $loadedExtensions, $functions);
168print "</tr>";
169
170$functions = ["imagecreate"];
171$name      = "GD";
172
173print "<tr>";
174print "<td>".$name."</td>";
175print getResultColumn($name, $activatedExtensions, $loadedExtensions, $functions);
176print "</tr>";
177
178$functions = ["curl_init"];
179$name      = "Curl";
180
181print "<tr>";
182print "<td>".$name."</td>";
183print getResultColumn($name, $activatedExtensions, $loadedExtensions, $functions);
184print "</tr>";
185
186if (empty($_SERVER["SERVER_ADMIN"]) || $_SERVER["SERVER_ADMIN"] != 'doliwamp@localhost') {
187	$functions = ["locale_get_primary_language", "locale_get_region"];
188	$name      = "Intl";
189
190	print "<tr>";
191	print "<td>".$name."</td>";
192	print getResultColumn($name, $activatedExtensions, $loadedExtensions, $functions);
193	print "</tr>";
194}
195
196$functions = ["imap_open"];
197$name      = "IMAP";
198
199print "<tr>";
200print "<td>".$name."</td>";
201print getResultColumn($name, $activatedExtensions, $loadedExtensions, $functions);
202print "</tr>";
203
204$functions = array();
205$name      = "xDebug";
206
207print "<tr>";
208print "<td>".$name."</td>";
209print getResultColumn($name, $activatedExtensions, $loadedExtensions, $functions);
210print "</tr>";
211
212print '</table>';
213
214print '<br>';
215
216// Get php_info array
217$phparray = phpinfo_array();
218foreach ($phparray as $key => $value) {
219	print '<div class="div-table-responsive-no-min">';
220	print '<table class="noborder">';
221	print '<tr class="liste_titre">';
222	print '<td class="titlefield">'.$key.'</td>';
223	print '<td colspan="2">'.$langs->trans("Value").'</td>';
224	print "</tr>\n";
225
226	//var_dump($value);
227	foreach ($value as $keyparam => $keyvalue) {
228		if (!is_array($keyvalue)) {
229			print '<tr class="oddeven">';
230			print '<td>'.$keyparam.'</td>';
231			$valtoshow = $keyvalue;
232			if ($keyparam == 'X-ChromePhp-Data') {
233				$valtoshow = dol_trunc($keyvalue, 80);
234			}
235			print '<td colspan="2" class="wordbreak">';
236			if ($keyparam == 'Path') {
237				$valtoshow = implode('; ', explode(';', trim($valtoshow)));
238			}
239			if ($keyparam == 'PATH') {
240				$valtoshow = implode('; ', explode(';', trim($valtoshow)));
241			}
242			if ($keyparam == '_SERVER["PATH"]') {
243				$valtoshow = implode('; ', explode(';', trim($valtoshow)));
244			}
245			print $valtoshow;
246			print '</td>';
247			print '</tr>';
248		} else {
249			print '<tr class="oddeven">';
250			print '<td class="wordbreak">'.$keyparam.'</td>';
251			$i = 0;
252			foreach ($keyvalue as $keyparam2 => $keyvalue2) {
253				print '<td>';
254				$valtoshow = $keyvalue2;
255				if ($keyparam == 'disable_functions') {
256					$valtoshow = implode(', ', explode(',', trim($valtoshow)));
257				}
258				//print $keyparam;
259				print $valtoshow;
260				$i++;
261				print '</td>';
262			}
263			print '</tr>';
264		}
265	}
266	print '</table>';
267	print '</div>';
268	print '<br>';
269}
270
271// End of page
272llxFooter();
273$db->close();
274
275
276/**
277 * Return a result column with a translated result text
278 *
279 * @param string $name			The name of the PHP extension
280 * @param array $activated		A list with all activated PHP extensions. Deprecated.
281 * @param array $loaded			A list with all loaded PHP extensions
282 * @param array $functions		A list with all PHP functions to check
283 * @return string
284 */
285function getResultColumn($name, array $activated, array $loaded, array $functions)
286{
287	global $langs;
288
289	$result = true;
290
291	//$result = $result && in_array(strtolower($name), $activated);
292	$result = $result && in_array(strtolower($name), $loaded);
293
294	foreach ($functions as $function) {
295		$result = $result && function_exists($function);
296	}
297
298	$html = "<td>";
299	if ($result) {
300		if (strtolower($name) == 'xdebug') {
301			$html .= img_warning($langs->trans("ModuleActivated", "xdebug"));
302		} else {
303			$html .= img_picto($langs->trans("Ok"), 'tick');
304		}
305		if (in_array(strtolower($name), $loaded)) {
306			$html .= ' '.$langs->trans("Loaded").' - ';
307		} else {
308			//$html .= ' '.$langs->trans("NotLoaded").' - ';
309		}
310		if (strtolower($name) == 'xdebug') {
311			$html .= ' '.$langs->trans("ModuleActivated", "xdebug");
312			$html .= ' - '.$langs->trans("ModuleActivatedMayExposeInformation");
313		} else {
314			$html .= ' <span class="opacitymedium">'.$langs->trans("PHPSupport", $name).'</span>';
315		}
316	} else {
317		if (strtolower($name) == 'xdebug') {
318			$html .= yn(0).' - ';
319		} else {
320			$html .= img_warning($langs->trans("ModuleActivated", "xdebug"));
321		}
322		if (in_array(strtolower($name), $loaded)) {
323			$html .= ' '.$langs->trans("Loaded").' - ';
324		} else {
325			//$html .= ' '.$langs->trans("NotLoaded").' - ';
326		}
327		$html .= ' '.$langs->trans("ErrorPHPDoesNotSupport", $name);
328	}
329	$html .= "</td>";
330
331	return $html;
332}
333