Rev 2 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 5 | ||
---|---|---|---|
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | # |
3 | # |
4 | # generic Whois - Automatic Pattern Generator configuration |
4 | # VWhois (ViaThinkSoft WHOIS, a fork of generic Whois / gwhois) |
- | 5 | # Common functions in PHP |
|
5 | # |
6 | # |
6 | # (c) 2012-2018 Daniel Marschall, ViaThinkSoft [www.viathinksoft.de] |
7 | # (c) 2012-2018 by Daniel Marschall, ViaThinkSoft <info@daniel-marschall.de> |
7 | # |
8 | # |
8 | # Distribution, usage etc. pp. regulated by the current version of GPL. |
9 | # License: https://www.gnu.org/licenses/gpl-2.0.html (GPL version 2) |
9 | # |
- | |
10 | # |
- | |
11 | # Version 2018-10-26 |
- | |
12 | # |
10 | # |
13 | 11 | ||
14 | function parse_config($file) { |
12 | function parse_config($file) { |
15 | if (!file_exists($file)) return false; |
13 | if (!file_exists($file)) return false; |
16 | 14 | ||
17 | $count = 0; |
15 | $count = 0; |
18 | 16 | ||
19 | $cont = file($file); |
17 | $cont = file($file); |
20 | foreach ($cont as $c) { |
18 | foreach ($cont as $c) { |
21 | $c = trim($c); |
19 | $c = trim($c); |
22 | 20 | ||
23 | if ($c == '') continue; |
21 | if ($c == '') continue; |
24 | if ($c[0] == '#') continue; |
22 | if ($c[0] == '#') continue; |
25 | 23 | ||
26 | $c = preg_replace('@(.+)\\s#.+$@U', '\\1', $c); |
24 | $c = preg_replace('@(.+)\\s#.+$@U', '\\1', $c); |
27 | 25 | ||
28 | $ary = explode('=', $c, 2); |
26 | $ary = explode('=', $c, 2); |
29 | $name = trim($ary[0]); |
27 | $name = trim($ary[0]); |
30 | $val = trim($ary[1]); |
28 | $val = trim($ary[1]); |
31 | 29 | ||
32 | // 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 |
33 | /* |
31 | /* |
34 | if (strtolower($val) === 'no') $val = false; |
32 | if (strtolower($val) === 'no') $val = false; |
35 | if (strtolower($val) === 'false') $val = false; |
33 | if (strtolower($val) === 'false') $val = false; |
36 | if (strtolower($val) === 'yes') $val = true; |
34 | if (strtolower($val) === 'yes') $val = true; |
37 | if (strtolower($val) === 'true') $val = true; |
35 | if (strtolower($val) === 'true') $val = true; |
38 | */ |
36 | */ |
39 | 37 | ||
40 | $val = str_strip_quotes($val); |
38 | $val = str_strip_quotes($val); |
41 | 39 | ||
42 | define($name, $val); |
40 | define($name, $val); |
43 | $count++; |
41 | $count++; |
44 | } |
42 | } |
45 | 43 | ||
46 | return $count; |
44 | return $count; |
47 | } |
45 | } |
48 | 46 | ||
49 | function str_strip_quotes($x) { |
47 | function str_strip_quotes($x) { |
50 | if (((substr($x,0,1) == '"') && (substr($x,-1,1) == '"')) || |
48 | if (((substr($x,0,1) == '"') && (substr($x,-1,1) == '"')) || |
51 | ((substr($x,0,1) == "'") && (substr($x,-1,1) == "'"))) { |
49 | ((substr($x,0,1) == "'") && (substr($x,-1,1) == "'"))) { |
52 | return substr($x,1,strlen($x)-2); |
50 | return substr($x,1,strlen($x)-2); |
53 | } else { |
51 | } else { |
54 | return $x; |
52 | return $x; |
55 | } |
53 | } |
56 | } |
54 | } |
57 | 55 | ||
58 | 56 |