Subversion Repositories ALCASAR

Rev

Rev 3037 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 3037 Rev 3100
1
<?php
1
<?php
2
if (!defined('PSI_CONFIG_FILE')) {
2
if (!defined('PSI_CONFIG_FILE')) {
3
    /**
3
    /**
4
     * phpSysInfo version
4
     * phpSysInfo version
5
     */
5
     */
6
    define('PSI_VERSION', '3.4.1');
6
    define('PSI_VERSION', '3.4.2');
7
    /**
7
    /**
8
     * phpSysInfo configuration
8
     * phpSysInfo configuration
9
     */
9
     */
10
    define('PSI_CONFIG_FILE', PSI_APP_ROOT.'/phpsysinfo.ini');
10
    define('PSI_CONFIG_FILE', PSI_APP_ROOT.'/phpsysinfo.ini');
11
 
11
 
12
    define('ARRAY_EXP', '/^return array \([^;]*\);$/'); //array expression search
12
    define('ARRAY_EXP', '/^return array \([^;]*\);$/'); //array expression search
13
 
13
 
14
    if (!is_readable(PSI_CONFIG_FILE)) {
14
    if (!is_readable(PSI_CONFIG_FILE)) {
15
        echo "ERROR: phpsysinfo.ini does not exist or is not readable by the webserver in the phpsysinfo directory";
15
        echo "ERROR: phpsysinfo.ini does not exist or is not readable by the webserver in the phpsysinfo directory";
16
        die();
16
        die();
17
    } elseif (!($config = @parse_ini_file(PSI_CONFIG_FILE, true))) {
17
    } elseif (!($config = @parse_ini_file(PSI_CONFIG_FILE, true))) {
18
        echo "ERROR: phpsysinfo.ini file is not parsable";
18
        echo "ERROR: phpsysinfo.ini file is not parsable";
19
        die();
19
        die();
20
    } else {
20
    } else {
21
        foreach ($config as $name=>$group) {
21
        foreach ($config as $name=>$group) {
22
            if (strtoupper($name)=="MAIN") {
22
            if (strtoupper($name)=="MAIN") {
23
                $name_prefix='PSI_';
23
                $name_prefix='PSI_';
24
            } elseif (strtoupper(substr($name, 0, 7))=="SENSOR_") {
24
            } elseif (strtoupper(substr($name, 0, 7))=="SENSOR_") {
25
                $name_prefix='PSI_'.strtoupper($name).'_';
25
                $name_prefix='PSI_'.strtoupper($name).'_';
26
            } else {
26
            } else {
27
                $name_prefix='PSI_PLUGIN_'.strtoupper($name).'_';
27
                $name_prefix='PSI_PLUGIN_'.strtoupper($name).'_';
28
            }
28
            }
29
            foreach ($group as $param=>$value) {
29
            foreach ($group as $param=>$value) {
30
                if ((trim($value)==="") || (trim($value)==="0")) {
30
                if ((trim($value)==="") || (trim($value)==="0")) {
31
                    define($name_prefix.strtoupper($param), false);
31
                    define($name_prefix.strtoupper($param), false);
32
                } elseif (trim($value)==="1") {
32
                } elseif (trim($value)==="1") {
33
                    define($name_prefix.strtoupper($param), true);
33
                    define($name_prefix.strtoupper($param), true);
34
                } else {
34
                } else {
35
                    if (strstr($value, ',')) {
35
                    if ((($paramup = strtoupper($param)) !== 'WMI_PASSWORD') && ($paramup !== 'SSH_PASSWORD') && strstr($value, ',')) {
36
                        define($name_prefix.strtoupper($param), 'return '.var_export(preg_split('/\s*,\s*/', trim($value), -1, PREG_SPLIT_NO_EMPTY), 1).';');
36
                        define($name_prefix.$paramup, 'return '.var_export(preg_split('/\s*,\s*/', trim($value), -1, PREG_SPLIT_NO_EMPTY), 1).';');
37
                    } else {
37
                    } else {
38
                        define($name_prefix.strtoupper($param), trim($value));
38
                        define($name_prefix.$paramup, trim($value));
39
                    }
39
                    }
40
                }
40
                }
41
            }
41
            }
42
        }
42
        }
43
    }
43
    }
44
 
44
 
45
    if (defined('PSI_ALLOWED') && is_string(PSI_ALLOWED)) {
45
    if (defined('PSI_ALLOWED') && is_string(PSI_ALLOWED)) {
46
        if (preg_match(ARRAY_EXP, PSI_ALLOWED)) {
46
        if (preg_match(ARRAY_EXP, PSI_ALLOWED)) {
47
            $allowed = eval(strtolower(PSI_ALLOWED));
47
            $allowed = eval(strtolower(PSI_ALLOWED));
48
        } else {
48
        } else {
49
            $allowed = array(strtolower(PSI_ALLOWED));
49
            $allowed = array(strtolower(PSI_ALLOWED));
50
        }
50
        }
51
 
51
 
52
        if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
52
        if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
53
            $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
53
            $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
54
        } else {
54
        } else {
55
            if (isset($_SERVER["HTTP_CLIENT_IP"])) {
55
            if (isset($_SERVER["HTTP_CLIENT_IP"])) {
56
                $ip = $_SERVER["HTTP_CLIENT_IP"];
56
                $ip = $_SERVER["HTTP_CLIENT_IP"];
57
            } else {
57
            } else {
58
                $ip = $_SERVER["REMOTE_ADDR"];
58
                $ip = $_SERVER["REMOTE_ADDR"];
59
            }
59
            }
60
        }
60
        }
61
        $ip = preg_replace("/^::ffff:/", "", strtolower($ip));
61
        $ip = preg_replace("/^::ffff:/", "", strtolower($ip));
62
 
62
 
-
 
63
        $ip_decimal = ip2long($ip);
63
        if (!in_array($ip, $allowed, true)) {
64
        if ($ip_decimal === false) {
-
 
65
            echo "Client IP wrong address (".$ip."). Client not allowed.";
-
 
66
            die();
-
 
67
        }
-
 
68
 
-
 
69
        // code based on https://gist.github.com/tott/7684443
-
 
70
        $was = false;
-
 
71
        foreach ($allowed as $allow) {
-
 
72
            if (strpos($allow, '/') === false) {
-
 
73
                    $was = ($allow === $ip);
-
 
74
            } else {
-
 
75
                  list($allow, $netmask) = explode('/', $allow, 2);
-
 
76
                  $allow_decimal = ip2long($allow);
-
 
77
                  $wildcard_decimal = pow(2, (32 - $netmask)) - 1;
-
 
78
                  $netmask_decimal = ~$wildcard_decimal;
-
 
79
                $was = (($ip_decimal & $netmask_decimal) === ($allow_decimal & $netmask_decimal));
-
 
80
            }
-
 
81
            if ($was) {
-
 
82
               break;
-
 
83
            }
-
 
84
        }
-
 
85
 
-
 
86
        if (!$was) {
64
            echo "Client IP address not allowed";
87
            echo "Client IP address (".$ip.") not allowed.";
65
            die();
88
            die();
66
        }
89
        }
67
    }
90
    }
68
 
91
 
69
    /* default error handler */
92
    /* default error handler */
70
    if (function_exists('errorHandlerPsi')) {
93
    if (function_exists('errorHandlerPsi')) {
71
        restore_error_handler();
94
        restore_error_handler();
72
    }
95
    }
73
 
96
 
74
    /* fatal errors only */
97
    /* fatal errors only */
75
    $old_err_rep = error_reporting();
98
    $old_err_rep = error_reporting();
76
    error_reporting(E_ERROR);
99
    error_reporting(E_ERROR);
77
 
100
 
78
    /* get git revision */
101
    /* get git revision */
79
    if (file_exists(PSI_APP_ROOT.'/.git/HEAD')) {
102
    if (file_exists(PSI_APP_ROOT.'/.git/HEAD')) {
80
        $contents = @file_get_contents(PSI_APP_ROOT.'/.git/HEAD');
103
        $contents = @file_get_contents(PSI_APP_ROOT.'/.git/HEAD');
81
        if ($contents && preg_match("/^ref:\s+(.*)\/([^\/\s]*)/m", $contents, $matches)) {
104
        if ($contents && preg_match("/^ref:\s+(.*)\/([^\/\s]*)/m", $contents, $matches)) {
82
            $contents = @file_get_contents(PSI_APP_ROOT.'/.git/'.$matches[1]."/".$matches[2]);
105
            $contents = @file_get_contents(PSI_APP_ROOT.'/.git/'.$matches[1]."/".$matches[2]);
83
            if ($contents && preg_match("/^([^\s]*)/m", $contents, $revision)) {
106
            if ($contents && preg_match("/^([^\s]*)/m", $contents, $revision)) {
84
                define('PSI_VERSION_STRING', PSI_VERSION ."-".$matches[2]."-".substr($revision[1], 0, 7));
107
                define('PSI_VERSION_STRING', PSI_VERSION ."-".$matches[2]."-".substr($revision[1], 0, 7));
85
            } else {
108
            } else {
86
                define('PSI_VERSION_STRING', PSI_VERSION ."-".$matches[2]);
109
                define('PSI_VERSION_STRING', PSI_VERSION ."-".$matches[2]);
87
            }
110
            }
88
        }
111
        }
89
    }
112
    }
90
    /* get svn revision */
113
    /* get svn revision */
91
    if (!defined('PSI_VERSION_STRING') && file_exists(PSI_APP_ROOT.'/.svn/entries')) {
114
    if (!defined('PSI_VERSION_STRING') && file_exists(PSI_APP_ROOT.'/.svn/entries')) {
92
        $contents = @file_get_contents(PSI_APP_ROOT.'/.svn/entries');
115
        $contents = @file_get_contents(PSI_APP_ROOT.'/.svn/entries');
93
        if ($contents && preg_match("/dir\n(.+)/", $contents, $matches)) {
116
        if ($contents && preg_match("/dir\n(.+)/", $contents, $matches)) {
94
            define('PSI_VERSION_STRING', PSI_VERSION."-r".$matches[1]);
117
            define('PSI_VERSION_STRING', PSI_VERSION."-r".$matches[1]);
95
        } else {
118
        } else {
96
            define('PSI_VERSION_STRING', PSI_VERSION);
119
            define('PSI_VERSION_STRING', PSI_VERSION);
97
        }
120
        }
98
    }
121
    }
99
    if (!defined('PSI_VERSION_STRING')) {
122
    if (!defined('PSI_VERSION_STRING')) {
100
        define('PSI_VERSION_STRING', PSI_VERSION);
123
        define('PSI_VERSION_STRING', PSI_VERSION);
101
    }
124
    }
102
 
125
 
103
    if (defined('PSI_ROOTFS') && is_string(PSI_ROOTFS) && (PSI_ROOTFS !== '') && (PSI_ROOTFS !== '/')) {
126
    if (defined('PSI_ROOTFS') && is_string(PSI_ROOTFS) && (PSI_ROOTFS !== '') && (PSI_ROOTFS !== '/')) {
104
        $rootfs = PSI_ROOTFS;
127
        $rootfs = PSI_ROOTFS;
105
        if ($rootfs[0] === '/') {
128
        if ($rootfs[0] === '/') {
106
            define('PSI_ROOT_FILESYSTEM', $rootfs);
129
            define('PSI_ROOT_FILESYSTEM', $rootfs);
107
        } else {
130
        } else {
108
            define('PSI_ROOT_FILESYSTEM', '');
131
            define('PSI_ROOT_FILESYSTEM', '');
109
        }
132
        }
110
    } else {
133
    } else {
111
        define('PSI_ROOT_FILESYSTEM', '');
134
        define('PSI_ROOT_FILESYSTEM', '');
112
    }
135
    }
113
 
136
 
114
    if (!defined('PSI_OS')) { //if not overloaded in phpsysinfo.ini
137
    if (!defined('PSI_OS')) { //if not overloaded in phpsysinfo.ini
115
        /* get Linux code page */
138
        /* get Linux code page */
116
        if (PHP_OS == 'Linux') {
139
        if ((PHP_OS == 'Linux') || (PHP_OS == 'GNU')) {
117
            if (file_exists($fname = PSI_ROOT_FILESYSTEM.'/etc/sysconfig/i18n')
140
            if (file_exists($fname = PSI_ROOT_FILESYSTEM.'/etc/sysconfig/i18n')
118
               || file_exists($fname = PSI_ROOT_FILESYSTEM.'/etc/default/locale')
141
               || file_exists($fname = PSI_ROOT_FILESYSTEM.'/etc/default/locale')
119
               || file_exists($fname = PSI_ROOT_FILESYSTEM.'/etc/locale.conf')
142
               || file_exists($fname = PSI_ROOT_FILESYSTEM.'/etc/locale.conf')
120
               || file_exists($fname = PSI_ROOT_FILESYSTEM.'/etc/sysconfig/language')
143
               || file_exists($fname = PSI_ROOT_FILESYSTEM.'/etc/sysconfig/language')
121
               || file_exists($fname = PSI_ROOT_FILESYSTEM.'/etc/profile.d/lang.sh')
144
               || file_exists($fname = PSI_ROOT_FILESYSTEM.'/etc/profile.d/lang.sh')
122
               || file_exists($fname = PSI_ROOT_FILESYSTEM.'/etc/profile.d/i18n.sh')
145
               || file_exists($fname = PSI_ROOT_FILESYSTEM.'/etc/profile.d/i18n.sh')
123
               || file_exists($fname = PSI_ROOT_FILESYSTEM.'/etc/profile')) {
146
               || file_exists($fname = PSI_ROOT_FILESYSTEM.'/etc/profile')) {
124
                $contents = @file_get_contents($fname);
147
                $contents = @file_get_contents($fname);
125
            } else {
148
            } else {
126
                $contents = false;
149
                $contents = false;
-
 
150
                if (PHP_OS == 'Linux') {
127
                if (file_exists(PSI_ROOT_FILESYSTEM.'/system/build.prop')) { //Android
151
                    if (file_exists(PSI_ROOT_FILESYSTEM.'/system/build.prop')) { //Android
128
                    define('PSI_OS', 'Android');
152
                        define('PSI_OS', 'Android');
129
                    if ((PSI_ROOT_FILESYSTEM === '') && function_exists('exec') && @exec('uname -o 2>/dev/null', $unameo) && (sizeof($unameo)>0) && (($unameo0 = trim($unameo[0])) != "")) {
153
                        if ((PSI_ROOT_FILESYSTEM === '') && function_exists('exec') && @exec('uname -o 2>/dev/null', $unameo) && (sizeof($unameo)>0) && (($unameo0 = trim($unameo[0])) != "")) {
130
                        define('PSI_UNAMEO', $unameo0); // is Android on Termux
154
                            define('PSI_UNAMEO', $unameo0); // is Android on Termux
131
                    }
155
                        }
132
                    if ((PSI_ROOT_FILESYSTEM === '') && !defined('PSI_MODE_POPEN')) { //if not overloaded in phpsysinfo.ini
156
                        if ((PSI_ROOT_FILESYSTEM === '') && !defined('PSI_MODE_POPEN')) { //if not overloaded in phpsysinfo.ini
133
                        if (!function_exists("proc_open")) { //proc_open function test by executing 'pwd' bbbmand
157
                            if (!function_exists("proc_open")) { //proc_open function test by executing 'pwd' bbbmand
134
                            define('PSI_MODE_POPEN', true); //use popen() function - no stderr error handling (but with problems with timeout)
158
                                define('PSI_MODE_POPEN', true); //use popen() function - no stderr error handling (but with problems with timeout)
135
                        } else {
-
 
136
                            $out = '';
-
 
137
                            $err = '';
-
 
138
                            $pipes = array();
-
 
139
                            $descriptorspec = array(0=>array("pipe", "r"), 1=>array("pipe", "w"), 2=>array("pipe", "w"));
-
 
140
                            $process = proc_open("pwd 2>/dev/null ", $descriptorspec, $pipes);
-
 
141
                            if (!is_resource($process)) {
-
 
142
                                define('PSI_MODE_POPEN', true);
-
 
143
                            } else {
159
                            } else {
-
 
160
                                $out = '';
-
 
161
                                $err = '';
-
 
162
                                $pipes = array();
-
 
163
                                $descriptorspec = array(0=>array("pipe", "r"), 1=>array("pipe", "w"), 2=>array("pipe", "w"));
-
 
164
                                $process = proc_open("pwd 2>/dev/null ", $descriptorspec, $pipes);
-
 
165
                                if (!is_resource($process)) {
-
 
166
                                    define('PSI_MODE_POPEN', true);
-
 
167
                                } else {
144
                                $w = null;
168
                                    $w = null;
145
                                $e = null;
169
                                    $e = null;
146
 
170
 
147
                                while (!(feof($pipes[1]) && feof($pipes[2]))) {
171
                                    while (!(feof($pipes[1]) && feof($pipes[2]))) {
148
                                    $read = array($pipes[1], $pipes[2]);
172
                                        $read = array($pipes[1], $pipes[2]);
149
 
173
 
150
                                    $n = stream_select($read, $w, $e, 5);
174
                                        $n = stream_select($read, $w, $e, 5);
151
 
175
 
152
                                    if (($n === false) || ($n === 0)) {
176
                                        if (($n === false) || ($n === 0)) {
153
                                        break;
177
                                            break;
154
                                    }
178
                                        }
155
 
179
 
156
                                    foreach ($read as $r) {
180
                                        foreach ($read as $r) {
157
                                        if ($r == $pipes[1]) {
181
                                            if ($r == $pipes[1]) {
158
                                            $out .= fread($r, 4096);
182
                                                $out .= fread($r, 4096);
159
                                        } elseif (feof($pipes[1]) && ($r == $pipes[2])) {//read STDERR after STDOUT
183
                                            } elseif (feof($pipes[1]) && ($r == $pipes[2])) {//read STDERR after STDOUT
160
                                            $err .= fread($r, 4096);
184
                                                $err .= fread($r, 4096);
-
 
185
                                            }
161
                                        }
186
                                        }
162
                                    }
187
                                    }
163
                                }
-
 
164
 
188
 
165
                                if (($out === null) || (trim($out) == "") || (substr(trim($out), 0, 1) != "/")) {
189
                                    if (($out === null) || (trim($out) == "") || (substr(trim($out), 0, 1) != "/")) {
166
                                    define('PSI_MODE_POPEN', true);
190
                                        define('PSI_MODE_POPEN', true);
-
 
191
                                    }
-
 
192
                                    fclose($pipes[0]);
-
 
193
                                    fclose($pipes[1]);
-
 
194
                                    fclose($pipes[2]);
-
 
195
                                    // It is important that you close any pipes before calling
-
 
196
                                    // proc_close in order to avoid a deadlock
-
 
197
                                    proc_close($process);
167
                                }
198
                                }
168
                                fclose($pipes[0]);
-
 
169
                                fclose($pipes[1]);
-
 
170
                                fclose($pipes[2]);
-
 
171
                                // It is important that you close any pipes before calling
-
 
172
                                // proc_close in order to avoid a deadlock
-
 
173
                                proc_close($process);
-
 
174
                            }
199
                            }
175
                        }
200
                        }
-
 
201
                    } elseif (file_exists(PSI_ROOT_FILESYSTEM.'/var/mobile/Library/Cydia/metadata.cb0')) { //jailbroken iOS with Cydia
-
 
202
                        define('PSI_OS', 'Darwin');
176
                    }
203
                    }
177
                }
204
                }
178
            }
205
            }
179
            if (!(defined('PSI_SYSTEM_CODEPAGE') && defined('PSI_SYSTEM_LANG')) //also if both not overloaded in phpsysinfo.ini
206
            if (!(defined('PSI_SYSTEM_CODEPAGE') && defined('PSI_SYSTEM_LANG')) //also if both not overloaded in phpsysinfo.ini
180
               && $contents && (preg_match('/^(LANG="?[^"\n]*"?)/m', $contents, $matches)
207
               && $contents && (preg_match('/^(LANG="?[^"\n]*"?)/m', $contents, $matches)
181
               || preg_match('/^RC_(LANG="?[^"\n]*"?)/m', $contents, $matches)
208
               || preg_match('/^RC_(LANG="?[^"\n]*"?)/m', $contents, $matches)
182
               || preg_match('/^\s*export (LANG="?[^"\n]*"?)/m', $contents, $matches))) {
209
               || preg_match('/^\s*export (LANG="?[^"\n]*"?)/m', $contents, $matches))) {
183
                if (!defined('PSI_SYSTEM_CODEPAGE')) {
210
                if (!defined('PSI_SYSTEM_CODEPAGE')) {
184
                    if (file_exists($vtfname = PSI_ROOT_FILESYSTEM.'/sys/module/vt/parameters/default_utf8')
211
                    if (file_exists($vtfname = PSI_ROOT_FILESYSTEM.'/sys/module/vt/parameters/default_utf8')
185
                       && (trim(@file_get_contents($vtfname)) === "1")) {
212
                       && (trim(@file_get_contents($vtfname)) === "1")) {
186
                            define('PSI_SYSTEM_CODEPAGE', 'UTF-8');
213
                        define('PSI_SYSTEM_CODEPAGE', 'UTF-8');
187
                    } elseif ((PSI_ROOT_FILESYSTEM === '') && function_exists('exec') && @exec($matches[1].' locale -k LC_CTYPE 2>/dev/null', $lines)) { //if not overloaded in phpsysinfo.ini
214
                    } elseif ((PSI_ROOT_FILESYSTEM === '') && function_exists('exec') && @exec($matches[1].' locale -k LC_CTYPE 2>/dev/null', $lines)) { //if not overloaded in phpsysinfo.ini
188
                        foreach ($lines as $line) {
215
                        foreach ($lines as $line) {
189
                            if (preg_match('/^charmap="?([^"]*)/', $line, $matches2)) {
216
                            if (preg_match('/^charmap="?([^"]*)/', $line, $matches2)) {
190
                                define('PSI_SYSTEM_CODEPAGE', $matches2[1]);
217
                                define('PSI_SYSTEM_CODEPAGE', $matches2[1]);
191
                                break;
218
                                break;
192
                            }
219
                            }
193
                        }
220
                        }
194
                    }
221
                    }
195
                }
222
                }
196
                if ((PSI_ROOT_FILESYSTEM === '') && !defined('PSI_SYSTEM_LANG') && function_exists('exec') && @exec($matches[1].' locale 2>/dev/null', $lines2)) { //also if not overloaded in phpsysinfo.ini
223
                if ((PSI_ROOT_FILESYSTEM === '') && !defined('PSI_SYSTEM_LANG') && function_exists('exec') && @exec($matches[1].' locale 2>/dev/null', $lines2)) { //also if not overloaded in phpsysinfo.ini
197
                    foreach ($lines2 as $line) {
224
                    foreach ($lines2 as $line) {
198
                        if (preg_match('/^LC_MESSAGES="?([^\."@]*)/', $line, $matches2)) {
225
                        if (preg_match('/^LC_MESSAGES="?([^\."@]*)/', $line, $matches2)) {
199
                            $lang = "";
226
                            $lang = "";
200
                            if (is_readable(PSI_APP_ROOT.'/data/languages.ini') && ($langdata = @parse_ini_file(PSI_APP_ROOT.'/data/languages.ini', true))) {
227
                            if (is_readable(PSI_APP_ROOT.'/data/languages.ini') && ($langdata = @parse_ini_file(PSI_APP_ROOT.'/data/languages.ini', true))) {
201
                                if (isset($langdata['Linux']['_'.$matches2[1]])) {
228
                                if (isset($langdata['Linux']['_'.$matches2[1]])) {
202
                                    $lang = $langdata['Linux']['_'.$matches2[1]];
229
                                    $lang = $langdata['Linux']['_'.$matches2[1]];
203
                                }
230
                                }
204
                            }
231
                            }
205
                            if ($lang == "") {
232
                            if ($lang == "") {
206
                                $lang = 'Unknown';
233
                                $lang = 'Unknown';
207
                            }
234
                            }
208
                            define('PSI_SYSTEM_LANG', $lang.' ('.$matches2[1].')');
235
                            define('PSI_SYSTEM_LANG', $lang.' ('.$matches2[1].')');
209
                            break;
236
                            break;
210
                        }
237
                        }
211
                    }
238
                    }
212
                }
239
                }
213
            }
240
            }
214
        } elseif (PHP_OS == 'Haiku') {
241
        } elseif (PHP_OS == 'Haiku') {
215
            if (!(defined('PSI_SYSTEM_CODEPAGE') && defined('PSI_SYSTEM_LANG')) //also if both not overloaded in phpsysinfo.ini
242
            if (!(defined('PSI_SYSTEM_CODEPAGE') && defined('PSI_SYSTEM_LANG')) //also if both not overloaded in phpsysinfo.ini
216
                && (PSI_ROOT_FILESYSTEM === '') && function_exists('exec') && @exec('locale --message 2>/dev/null', $lines)) {
243
                && (PSI_ROOT_FILESYSTEM === '') && function_exists('exec') && @exec('locale --message 2>/dev/null', $lines)) {
217
                foreach ($lines as $line) {
244
                foreach ($lines as $line) {
218
                    if (preg_match('/^"?([^\."]*)\.?([^"]*)/', $line, $matches2)) {
245
                    if (preg_match('/^"?([^\."]*)\.?([^"]*)/', $line, $matches2)) {
219
 
246
 
220
                        if (!defined('PSI_SYSTEM_CODEPAGE') && isset($matches2[2]) && ($matches2[2] !== null) && (trim($matches2[2]) != "")) { //also if not overloaded in phpsysinfo.ini
247
                        if (!defined('PSI_SYSTEM_CODEPAGE') && isset($matches2[2]) && ($matches2[2] !== null) && (trim($matches2[2]) != "")) { //also if not overloaded in phpsysinfo.ini
221
                            define('PSI_SYSTEM_CODEPAGE', $matches2[2]);
248
                            define('PSI_SYSTEM_CODEPAGE', $matches2[2]);
222
                        }
249
                        }
223
 
250
 
224
                        if (!defined('PSI_SYSTEM_LANG')) { //if not overloaded in phpsysinfo.ini
251
                        if (!defined('PSI_SYSTEM_LANG')) { //if not overloaded in phpsysinfo.ini
225
                            $lang = "";
252
                            $lang = "";
226
                            if (is_readable(PSI_APP_ROOT.'/data/languages.ini') && ($langdata = @parse_ini_file(PSI_APP_ROOT.'/data/languages.ini', true))) {
253
                            if (is_readable(PSI_APP_ROOT.'/data/languages.ini') && ($langdata = @parse_ini_file(PSI_APP_ROOT.'/data/languages.ini', true))) {
227
                                if (isset($langdata['Linux']['_'.$matches2[1]])) {
254
                                if (isset($langdata['Linux']['_'.$matches2[1]])) {
228
                                    $lang = $langdata['Linux']['_'.$matches2[1]];
255
                                    $lang = $langdata['Linux']['_'.$matches2[1]];
229
                                }
256
                                }
230
                            }
257
                            }
231
                            if ($lang == "") {
258
                            if ($lang == "") {
232
                                $lang = 'Unknown';
259
                                $lang = 'Unknown';
233
                            }
260
                            }
234
                            define('PSI_SYSTEM_LANG', $lang.' ('.$matches2[1].')');
261
                            define('PSI_SYSTEM_LANG', $lang.' ('.$matches2[1].')');
235
                        }
262
                        }
236
                        break;
263
                        break;
237
                    }
264
                    }
238
                }
265
                }
239
            }
266
            }
240
        } elseif (PHP_OS == 'Darwin') {
267
        } elseif ((PHP_OS == 'Darwin') || (defined('PSI_OS') && (PSI_OS == 'Darwin'))){
241
            if (!defined('PSI_SYSTEM_LANG') //if not overloaded in phpsysinfo.ini
268
            if (!defined('PSI_SYSTEM_LANG') //if not overloaded in phpsysinfo.ini
242
                && (PSI_ROOT_FILESYSTEM === '') && function_exists('exec') && @exec('defaults read /Library/Preferences/.GlobalPreferences AppleLocale 2>/dev/null', $lines)) {
269
                && (PSI_ROOT_FILESYSTEM === '') && function_exists('exec') && @exec('defaults read /Library/Preferences/.GlobalPreferences AppleLocale 2>/dev/null', $lines)) {
243
                $lang = "";
270
                $lang = "";
244
                if (is_readable(PSI_APP_ROOT.'/data/languages.ini') && ($langdata = @parse_ini_file(PSI_APP_ROOT.'/data/languages.ini', true))) {
271
                if (is_readable(PSI_APP_ROOT.'/data/languages.ini') && ($langdata = @parse_ini_file(PSI_APP_ROOT.'/data/languages.ini', true))) {
245
                    if (isset($langdata['Linux']['_'.$lines[0]])) {
272
                    if (isset($langdata['Linux']['_'.$lines[0]])) {
246
                        $lang = $langdata['Linux']['_'.$lines[0]];
273
                        $lang = $langdata['Linux']['_'.$lines[0]];
247
                    }
274
                    }
248
                }
275
                }
249
                if ($lang == "") {
276
                if ($lang == "") {
250
                    $lang = 'Unknown';
277
                    $lang = 'Unknown';
251
                }
278
                }
252
                define('PSI_SYSTEM_LANG', $lang.' ('.$lines[0].')');
279
                define('PSI_SYSTEM_LANG', $lang.' ('.$lines[0].')');
253
            }
280
            }
254
        }
281
        }
255
    }
282
    }
256
 
283
 
257
    /* maximum time in seconds a script is allowed to run before it is terminated by the parser */
284
    /* maximum time in seconds a script is allowed to run before it is terminated by the parser */
258
    if (defined('PSI_MAX_TIMEOUT')) {
285
    if (defined('PSI_MAX_TIMEOUT')) {
259
        ini_set('max_execution_time', max(intval(PSI_MAX_TIMEOUT), 0));
286
        ini_set('max_execution_time', max(intval(PSI_MAX_TIMEOUT), 0));
260
    } else {
287
    } else {
261
        ini_set('max_execution_time', 30);
288
        ini_set('max_execution_time', 30);
262
    }
289
    }
263
 
290
 
264
    /* executeProgram() timeout value in seconds */
291
    /* executeProgram() timeout value in seconds */
265
    if (defined('PSI_EXEC_TIMEOUT')) {
292
    if (defined('PSI_EXEC_TIMEOUT')) {
266
        define('PSI_EXEC_TIMEOUT_INT', max(intval(PSI_EXEC_TIMEOUT), 1));
293
        define('PSI_EXEC_TIMEOUT_INT', max(intval(PSI_EXEC_TIMEOUT), 1));
267
    } else {
294
    } else {
268
        define('PSI_EXEC_TIMEOUT_INT', 30);
295
        define('PSI_EXEC_TIMEOUT_INT', 30);
269
    }
296
    }
270
 
297
 
271
    /* snmprealwalk() and executeProgram("snmpwalk") number of seconds until the first timeout */
298
    /* snmprealwalk() and executeProgram("snmpwalk") number of seconds until the first timeout */
272
    if (defined('PSI_SNMP_TIMEOUT')) {
299
    if (defined('PSI_SNMP_TIMEOUT')) {
273
        define('PSI_SNMP_TIMEOUT_INT', max(intval(PSI_SNMP_TIMEOUT), 1));
300
        define('PSI_SNMP_TIMEOUT_INT', max(intval(PSI_SNMP_TIMEOUT), 1));
274
    } else {
301
    } else {
275
        define('PSI_SNMP_TIMEOUT_INT', 3);
302
        define('PSI_SNMP_TIMEOUT_INT', 3);
276
    }
303
    }
277
 
304
 
278
    /* snmprealwalk() and executeProgram("snmpwalk") number of times to retry if timeouts occur */
305
    /* snmprealwalk() and executeProgram("snmpwalk") number of times to retry if timeouts occur */
279
    if (defined('PSI_SNMP_RETRY')) {
306
    if (defined('PSI_SNMP_RETRY')) {
280
        define('PSI_SNMP_RETRY_INT', max(intval(PSI_SNMP_RETRY), 0));
307
        define('PSI_SNMP_RETRY_INT', max(intval(PSI_SNMP_RETRY), 0));
281
    } else {
308
    } else {
282
        define('PSI_SNMP_RETRY_INT', 0);
309
        define('PSI_SNMP_RETRY_INT', 0);
283
    }
310
    }
284
 
311
 
285
    if (!defined('PSI_OS')) {
312
    if (!defined('PSI_OS')) {
286
        define('PSI_OS', PHP_OS);
313
        define('PSI_OS', PHP_OS);
287
    }
314
    }
288
 
315
 
289
    if (!defined('PSI_SYSTEM_LANG')) {
316
    if (!defined('PSI_SYSTEM_LANG')) {
290
        define('PSI_SYSTEM_LANG', null);
317
        define('PSI_SYSTEM_LANG', null);
291
    }
318
    }
292
    if (!defined('PSI_SYSTEM_CODEPAGE')) { //if not overloaded in phpsysinfo.ini
319
    if (!defined('PSI_SYSTEM_CODEPAGE')) { //if not overloaded in phpsysinfo.ini
293
        if ((PSI_OS=='Android') || (PSI_OS=='Darwin')) {
320
        if ((PSI_OS=='Android') || (PSI_OS=='Darwin')) {
294
            define('PSI_SYSTEM_CODEPAGE', 'UTF-8');
321
            define('PSI_SYSTEM_CODEPAGE', 'UTF-8');
295
        } elseif (PSI_OS=='Minix') {
322
        } elseif (PSI_OS=='Minix') {
296
            define('PSI_SYSTEM_CODEPAGE', 'CP437');
323
            define('PSI_SYSTEM_CODEPAGE', 'CP437');
297
        } elseif (PSI_OS!='WINNT') {
324
        } elseif (PSI_OS!='WINNT') {
298
            define('PSI_SYSTEM_CODEPAGE', null);
325
            define('PSI_SYSTEM_CODEPAGE', null);
299
        }
326
        }
300
    }
327
    }
301
 
328
 
302
    if (!defined('PSI_JSON_ISSUE')) { //if not overloaded in phpsysinfo.ini
329
    if (!defined('PSI_JSON_ISSUE')) { //if not overloaded in phpsysinfo.ini
303
        if (!extension_loaded("xml")) {
330
        if (!extension_loaded("xml")) {
304
            die("phpSysInfo requires the xml extension to php in order to work properly.");
331
            die("phpSysInfo requires the xml extension to php in order to work properly.");
305
        }
332
        }
306
        if (simplexml_load_string("<A><B><C/></B>\n</A>") !== simplexml_load_string("<A><B><C/></B></A>")) { // json_encode issue test
333
        if (simplexml_load_string("<A><B><C/></B>\n</A>") !== simplexml_load_string("<A><B><C/></B></A>")) { // json_encode issue test
307
            define('PSI_JSON_ISSUE', true); // Problem must be solved
334
            define('PSI_JSON_ISSUE', true); // Problem must be solved
308
        }
335
        }
309
    }
336
    }
310
 
337
 
311
    /* restore error level */
338
    /* restore error level */
312
    error_reporting($old_err_rep);
339
    error_reporting($old_err_rep);
313
 
340
 
314
    /* restore error handler */
341
    /* restore error handler */
315
    if (function_exists('errorHandlerPsi')) {
342
    if (function_exists('errorHandlerPsi')) {
316
        set_error_handler('errorHandlerPsi');
343
        set_error_handler('errorHandlerPsi');
317
    }
344
    }
318
}
345
}
319
 
346