Subversion Repositories vgwhois

Rev

Rev 5 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 11
1
<?php
1
<?php
2
 
2
 
3
#
3
#
4
#  VWhois (ViaThinkSoft WHOIS, a fork of generic Whois / gwhois)
4
#  VGWhoIs (ViaThinkSoft Global WhoIs, a fork of generic Whois / gwhois)
5
#  Common functions in PHP
5
#  Common functions in PHP
6
#
6
#
7
#  (c) 2012-2018 by Daniel Marschall, ViaThinkSoft <info@daniel-marschall.de>
7
#  (c) 2012-2018 by Daniel Marschall, ViaThinkSoft <info@daniel-marschall.de>
8
#
8
#
9
#  License: https://www.gnu.org/licenses/gpl-2.0.html (GPL version 2)
9
#  License: https://www.gnu.org/licenses/gpl-2.0.html (GPL version 2)
10
#
10
#
11
 
11
 
12
function parse_config($file) {
12
function parse_config($file) {
13
        if (!file_exists($file)) return false;
13
        if (!file_exists($file)) return false;
14
 
14
 
15
        $count = 0;
15
        $count = 0;
16
 
16
 
17
        $cont = file($file);
17
        $cont = file($file);
18
        foreach ($cont as $c) {
18
        foreach ($cont as $c) {
19
                $c = trim($c);
19
                $c = trim($c);
20
 
20
 
21
                if ($c == '') continue;
21
                if ($c == '') continue;
22
                if ($c[0] == '#') continue;
22
                if ($c[0] == '#') continue;
23
 
23
 
24
                $c = preg_replace('@(.+)\\s#.+$@U', '\\1', $c);
24
                $c = preg_replace('@(.+)\\s#.+$@U', '\\1', $c);
25
 
25
 
26
                $ary = explode('=', $c, 2);
26
                $ary = explode('=', $c, 2);
27
                $name = trim($ary[0]);
27
                $name = trim($ary[0]);
28
                $val = trim($ary[1]);
28
                $val = trim($ary[1]);
29
 
29
 
30
                // true/false does not work for bash, so we do not accept it here either
30
                // true/false does not work for bash, so we do not accept it here either
31
                /*
31
                /*
32
                if (strtolower($val) === 'no') $val = false;
32
                if (strtolower($val) === 'no') $val = false;
33
                if (strtolower($val) === 'false') $val = false;
33
                if (strtolower($val) === 'false') $val = false;
34
                if (strtolower($val) === 'yes') $val = true;
34
                if (strtolower($val) === 'yes') $val = true;
35
                if (strtolower($val) === 'true') $val = true;
35
                if (strtolower($val) === 'true') $val = true;
36
                */
36
                */
37
 
37
 
38
                $val = str_strip_quotes($val);
38
                $val = str_strip_quotes($val);
39
 
39
 
40
                define($name, $val);
40
                define($name, $val);
41
                $count++;
41
                $count++;
42
        }
42
        }
43
 
43
 
44
        return $count;
44
        return $count;
45
}
45
}
46
 
46
 
47
function str_strip_quotes($x) {
47
function str_strip_quotes($x) {
48
        if (((substr($x,0,1) == '"') && (substr($x,-1,1) == '"')) ||
48
        if (((substr($x,0,1) == '"') && (substr($x,-1,1) == '"')) ||
49
            ((substr($x,0,1) == "'") && (substr($x,-1,1) == "'"))) {
49
            ((substr($x,0,1) == "'") && (substr($x,-1,1) == "'"))) {
50
                return substr($x,1,strlen($x)-2);
50
                return substr($x,1,strlen($x)-2);
51
        } else {
51
        } else {
52
                return $x;
52
                return $x;
53
        }
53
        }
54
}
54
}
55
 
55
 
56
 
56