This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | if (!defined('PSI_CONFIG_FILE')) { |
||
3 | /** |
||
4 | * phpSysInfo version |
||
5 | */ |
||
6 | define('PSI_VERSION', '3.2.5'); |
||
7 | /** |
||
8 | * phpSysInfo configuration |
||
9 | */ |
||
10 | define('PSI_CONFIG_FILE', APP_ROOT.'/phpsysinfo.ini'); |
||
11 | |||
12 | define('ARRAY_EXP', '/^return array \([^;]*\);$/'); //array expression search |
||
13 | |||
14 | if (!is_readable(PSI_CONFIG_FILE) || !($config = @parse_ini_file(PSI_CONFIG_FILE, true))) { |
||
15 | if (defined('PSI_INTERNAL_XML') && PSI_INTERNAL_XML === true) { |
||
16 | echo "ERROR: phpsysinfo.ini does not exist or is not readable by the webserver in the phpsysinfo directory"; |
||
17 | die(); |
||
18 | } |
||
19 | } else { |
||
20 | foreach ($config as $name=>$group) { |
||
21 | if (strtoupper($name)=="MAIN") { |
||
22 | $name_prefix='PSI_'; |
||
23 | } elseif (strtoupper(substr($name, 0, 7))=="SENSOR_") { |
||
24 | $name_prefix='PSI_'.strtoupper($name).'_'; |
||
25 | } else { |
||
26 | $name_prefix='PSI_PLUGIN_'.strtoupper($name).'_'; |
||
27 | } |
||
28 | foreach ($group as $param=>$value) { |
||
29 | if ((trim($value)==="") || (trim($value)==="0")) { |
||
30 | define($name_prefix.strtoupper($param), false); |
||
31 | } elseif (trim($value)==="1") { |
||
32 | define($name_prefix.strtoupper($param), true); |
||
33 | } else { |
||
34 | if (strstr($value, ',')) { |
||
35 | define($name_prefix.strtoupper($param), 'return '.var_export(preg_split('/\s*,\s*/', trim($value), -1, PREG_SPLIT_NO_EMPTY), 1).';'); |
||
36 | } else { |
||
37 | define($name_prefix.strtoupper($param), trim($value)); |
||
38 | } |
||
39 | } |
||
40 | } |
||
41 | } |
||
42 | } |
||
43 | |||
44 | if (defined('PSI_ALLOWED') && is_string(PSI_ALLOWED)) { |
||
45 | if (preg_match(ARRAY_EXP, PSI_ALLOWED)) { |
||
46 | $allowed = eval(strtolower(PSI_ALLOWED)); |
||
47 | } else { |
||
48 | $allowed = array(strtolower(PSI_ALLOWED)); |
||
49 | } |
||
50 | |||
51 | if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) { |
||
52 | $ip = $_SERVER["HTTP_X_FORWARDED_FOR"]; |
||
53 | } else { |
||
54 | if (isset($_SERVER["HTTP_CLIENT_IP"])) { |
||
55 | $ip = $_SERVER["HTTP_CLIENT_IP"]; |
||
56 | } else { |
||
57 | $ip = $_SERVER["REMOTE_ADDR"]; |
||
58 | } |
||
59 | } |
||
60 | $ip = preg_replace("/^::ffff:/", "", strtolower($ip)); |
||
61 | |||
62 | if (!in_array($ip, $allowed, true)) { |
||
63 | echo "Client IP address not allowed"; |
||
64 | die(); |
||
65 | } |
||
66 | } |
||
67 | |||
68 | /* default error handler */ |
||
69 | if (function_exists('errorHandlerPsi')) { |
||
70 | restore_error_handler(); |
||
71 | } |
||
72 | |||
73 | /* fatal errors only */ |
||
74 | $old_err_rep = error_reporting(); |
||
75 | error_reporting(E_ERROR); |
||
76 | |||
77 | /* get git revision */ |
||
78 | if (file_exists(APP_ROOT.'/.git/HEAD')) { |
||
79 | $contents = @file_get_contents(APP_ROOT.'/.git/HEAD'); |
||
80 | if ($contents && preg_match("/^ref:\s+(.*)\/([^\/\s]*)/m", $contents, $matches)) { |
||
81 | $contents = @file_get_contents(APP_ROOT.'/.git/'.$matches[1]."/".$matches[2]); |
||
82 | if ($contents && preg_match("/^([^\s]*)/m", $contents, $revision)) { |
||
83 | define('PSI_VERSION_STRING', PSI_VERSION ."-".$matches[2]."-".substr($revision[1], 0, 7)); |
||
84 | } else { |
||
85 | define('PSI_VERSION_STRING', PSI_VERSION ."-".$matches[2]); |
||
86 | } |
||
87 | } |
||
88 | } |
||
89 | /* get svn revision */ |
||
90 | if (!defined('PSI_VERSION_STRING') && file_exists(APP_ROOT.'/.svn/entries')) { |
||
91 | $contents = @file_get_contents(APP_ROOT.'/.svn/entries'); |
||
92 | if ($contents && preg_match("/dir\n(.+)/", $contents, $matches)) { |
||
93 | define('PSI_VERSION_STRING', PSI_VERSION."-r".$matches[1]); |
||
94 | } else { |
||
95 | define('PSI_VERSION_STRING', PSI_VERSION); |
||
96 | } |
||
97 | } |
||
98 | if (!defined('PSI_VERSION_STRING')) { |
||
99 | define('PSI_VERSION_STRING', PSI_VERSION); |
||
100 | } |
||
101 | |||
102 | if (!defined('PSI_OS')) { //if not overloaded in phpsysinfo.ini |
||
103 | /* get Linux code page */ |
||
104 | if (PHP_OS == 'Linux') { |
||
105 | if (file_exists('/etc/sysconfig/i18n')) { |
||
106 | $contents = @file_get_contents('/etc/sysconfig/i18n'); |
||
107 | } elseif (file_exists('/etc/default/locale')) { |
||
108 | $contents = @file_get_contents('/etc/default/locale'); |
||
109 | } elseif (file_exists('/etc/locale.conf')) { |
||
110 | $contents = @file_get_contents('/etc/locale.conf'); |
||
111 | } elseif (file_exists('/etc/sysconfig/language')) { |
||
112 | $contents = @file_get_contents('/etc/sysconfig/language'); |
||
113 | } elseif (file_exists('/etc/profile.d/lang.sh')) { |
||
114 | $contents = @file_get_contents('/etc/profile.d/lang.sh'); |
||
115 | } elseif (file_exists('/etc/profile')) { |
||
116 | $contents = @file_get_contents('/etc/profile'); |
||
117 | } else { |
||
118 | $contents = false; |
||
119 | if (file_exists('/system/build.prop')) { //Android |
||
120 | define('PSI_OS', 'Android'); |
||
121 | if (!defined('PSI_MODE_POPEN')) { //if not overloaded in phpsysinfo.ini |
||
122 | if (!function_exists("proc_open")) { //proc_open function test by executing 'pwd' command |
||
123 | define('PSI_MODE_POPEN', true); //use popen() function - no stderr error handling |
||
124 | } else { |
||
125 | $out = ''; |
||
126 | $err = ''; |
||
127 | $pipes = array(); |
||
128 | $descriptorspec = array(0=>array("pipe", "r"), 1=>array("pipe", "w"), 2=>array("pipe", "w")); |
||
129 | $process = proc_open("pwd 2>/dev/null ", $descriptorspec, $pipes); |
||
130 | if (!is_resource($process)) { |
||
131 | define('PSI_MODE_POPEN', true); |
||
132 | } else { |
||
133 | $w = null; |
||
134 | $e = null; |
||
135 | |||
136 | while (!(feof($pipes[1]) || feof($pipes[2]))) { |
||
137 | $read = array($pipes[1], $pipes[2]); |
||
138 | |||
139 | $n = stream_select($read, $w, $e, 5); |
||
140 | |||
141 | if (($n === false) || ($n === 0)) { |
||
142 | break; |
||
143 | } |
||
144 | |||
145 | foreach ($read as $r) { |
||
146 | if ($r == $pipes[1]) { |
||
147 | $out .= fread($r, 4096); |
||
148 | } |
||
149 | if ($r == $pipes[2]) { |
||
150 | $err .= fread($r, 4096); |
||
151 | } |
||
152 | } |
||
153 | } |
||
154 | |||
155 | if (is_null($out) || (trim($out) == "") || (substr(trim($out), 0, 1) != "/")) { |
||
156 | define('PSI_MODE_POPEN', true); |
||
157 | } |
||
158 | fclose($pipes[0]); |
||
159 | fclose($pipes[1]); |
||
160 | fclose($pipes[2]); |
||
161 | // It is important that you close any pipes before calling |
||
162 | // proc_close in order to avoid a deadlock |
||
163 | proc_close($process); |
||
164 | } |
||
165 | } |
||
166 | } |
||
167 | } |
||
168 | } |
||
169 | if (!(defined('PSI_SYSTEM_CODEPAGE') && defined('PSI_SYSTEM_LANG')) //also if both not overloaded in phpsysinfo.ini |
||
170 | && $contents && (preg_match('/^(LANG="?[^"\n]*"?)/m', $contents, $matches) |
||
171 | || preg_match('/^RC_(LANG="?[^"\n]*"?)/m', $contents, $matches) |
||
172 | || preg_match('/^\s*export (LANG="?[^"\n]*"?)/m', $contents, $matches))) { |
||
173 | if (!defined('PSI_SYSTEM_CODEPAGE') && @exec($matches[1].' locale -k LC_CTYPE 2>/dev/null', $lines)) { //if not overloaded in phpsysinfo.ini |
||
174 | foreach ($lines as $line) { |
||
0 ignored issues
–
show
The expression
$lines of type null|array is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
![]() |
|||
175 | if (preg_match('/^charmap="?([^"]*)/', $line, $matches2)) { |
||
176 | define('PSI_SYSTEM_CODEPAGE', $matches2[1]); |
||
177 | break; |
||
178 | } |
||
179 | } |
||
180 | } |
||
181 | if (!defined('PSI_SYSTEM_LANG') && @exec($matches[1].' locale 2>/dev/null', $lines)) { //also if not overloaded in phpsysinfo.ini |
||
182 | foreach ($lines as $line) { |
||
0 ignored issues
–
show
The expression
$lines of type null|array is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
![]() |
|||
183 | View Code Duplication | if (preg_match('/^LC_MESSAGES="?([^\."@]*)/', $line, $matches2)) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
184 | $lang = ""; |
||
185 | if (is_readable(APP_ROOT.'/data/languages.ini') && ($langdata = @parse_ini_file(APP_ROOT.'/data/languages.ini', true))) { |
||
186 | if (isset($langdata['Linux']['_'.$matches2[1]])) { |
||
187 | $lang = $langdata['Linux']['_'.$matches2[1]]; |
||
188 | } |
||
189 | } |
||
190 | if ($lang == "") { |
||
191 | $lang = 'Unknown'; |
||
192 | } |
||
193 | define('PSI_SYSTEM_LANG', $lang.' ('.$matches2[1].')'); |
||
194 | break; |
||
195 | } |
||
196 | } |
||
197 | } |
||
198 | } |
||
199 | } elseif (PHP_OS == 'Haiku') { |
||
200 | if (!(defined('PSI_SYSTEM_CODEPAGE') && defined('PSI_SYSTEM_LANG')) //also if both not overloaded in phpsysinfo.ini |
||
201 | && @exec('locale -m 2>/dev/null', $lines)) { |
||
202 | foreach ($lines as $line) { |
||
0 ignored issues
–
show
The expression
$lines of type null|array is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
![]() |
|||
203 | if (preg_match('/^"?([^\."]*)\.?([^"]*)/', $line, $matches2)) { |
||
204 | |||
205 | if (!defined('PSI_SYSTEM_CODEPAGE') && isset($matches2[2]) && !is_null($matches2[2]) && (trim($matches2[2]) != "")) { //also if not overloaded in phpsysinfo.ini |
||
206 | define('PSI_SYSTEM_CODEPAGE', $matches2[2]); |
||
207 | } |
||
208 | |||
209 | View Code Duplication | if (!defined('PSI_SYSTEM_LANG')) { //if not overloaded in phpsysinfo.ini |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
210 | $lang = ""; |
||
211 | if (is_readable(APP_ROOT.'/data/languages.ini') && ($langdata = @parse_ini_file(APP_ROOT.'/data/languages.ini', true))) { |
||
212 | if (isset($langdata['Linux']['_'.$matches2[1]])) { |
||
213 | $lang = $langdata['Linux']['_'.$matches2[1]]; |
||
214 | } |
||
215 | } |
||
216 | if ($lang == "") { |
||
217 | $lang = 'Unknown'; |
||
218 | } |
||
219 | define('PSI_SYSTEM_LANG', $lang.' ('.$matches2[1].')'); |
||
220 | } |
||
221 | break; |
||
222 | } |
||
223 | } |
||
224 | } |
||
225 | } elseif (PHP_OS == 'Darwin') { |
||
226 | View Code Duplication | if (!defined('PSI_SYSTEM_LANG') //if not overloaded in phpsysinfo.ini |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
227 | && @exec('defaults read /Library/Preferences/.GlobalPreferences AppleLocale 2>/dev/null', $lines)) { |
||
228 | $lang = ""; |
||
229 | if (is_readable(APP_ROOT.'/data/languages.ini') && ($langdata = @parse_ini_file(APP_ROOT.'/data/languages.ini', true))) { |
||
230 | if (isset($langdata['Linux']['_'.$lines[0]])) { |
||
231 | $lang = $langdata['Linux']['_'.$lines[0]]; |
||
232 | } |
||
233 | } |
||
234 | if ($lang == "") { |
||
235 | $lang = 'Unknown'; |
||
236 | } |
||
237 | define('PSI_SYSTEM_LANG', $lang.' ('.$lines[0].')'); |
||
238 | } |
||
239 | } |
||
240 | } |
||
241 | |||
242 | if (!defined('PSI_OS')) { |
||
243 | define('PSI_OS', PHP_OS); |
||
244 | } |
||
245 | |||
246 | if (!defined('PSI_SYSTEM_LANG')) { |
||
247 | define('PSI_SYSTEM_LANG', null); |
||
248 | } |
||
249 | if (!defined('PSI_SYSTEM_CODEPAGE')) { //if not overloaded in phpsysinfo.ini |
||
250 | if ((PSI_OS=='Android') || (PSI_OS=='Darwin')) { |
||
251 | define('PSI_SYSTEM_CODEPAGE', 'UTF-8'); |
||
252 | } elseif (PSI_OS=='Minix') { |
||
253 | define('PSI_SYSTEM_CODEPAGE', 'CP437'); |
||
254 | } else { |
||
255 | define('PSI_SYSTEM_CODEPAGE', null); |
||
256 | } |
||
257 | } |
||
258 | |||
259 | if (!defined('PSI_JSON_ISSUE')) { //if not overloaded in phpsysinfo.ini |
||
260 | if (simplexml_load_string("<A><B><C/></B>\n</A>") !== simplexml_load_string("<A><B><C/></B></A>")) { // json_encode issue test |
||
261 | define('PSI_JSON_ISSUE', true); // Problem must be solved |
||
262 | } |
||
263 | } |
||
264 | |||
265 | /* restore error level */ |
||
266 | error_reporting($old_err_rep); |
||
267 | |||
268 | /* restore error handler */ |
||
269 | if (function_exists('errorHandlerPsi')) { |
||
270 | set_error_handler('errorHandlerPsi'); |
||
271 | } |
||
272 | } |
||
273 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.