Subversion Repositories ALCASAR

Rev

Rev 3037 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 3037 Rev 3100
Line 1... Line 1...
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
 
Line 30... Line 30...
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
    }
Line 58... Line 58...
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 */
Line 111... Line 134...
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;
Line 235... Line 262...
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]])) {