Subversion Repositories ALCASAR

Rev

Rev 3100 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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