Rev 5 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | daniel-mar | 1 | <?php |
2 | |||
3 | # |
||
4 | # generic Whois - Automatic Pattern Generator configuration |
||
5 | # |
||
6 | # (c) 2012-2018 Daniel Marschall, ViaThinkSoft [www.viathinksoft.de] |
||
7 | # |
||
8 | # Distribution, usage etc. pp. regulated by the current version of GPL. |
||
9 | # |
||
10 | # |
||
11 | # Version 2018-10-26 |
||
12 | # |
||
13 | |||
14 | function parse_config($file) { |
||
15 | if (!file_exists($file)) return false; |
||
16 | |||
17 | $count = 0; |
||
18 | |||
19 | $cont = file($file); |
||
20 | foreach ($cont as $c) { |
||
21 | $c = trim($c); |
||
22 | |||
23 | if ($c == '') continue; |
||
24 | if ($c[0] == '#') continue; |
||
25 | |||
26 | $c = preg_replace('@(.+)\\s#.+$@U', '\\1', $c); |
||
27 | |||
28 | $ary = explode('=', $c, 2); |
||
29 | $name = trim($ary[0]); |
||
30 | $val = trim($ary[1]); |
||
31 | |||
32 | // true/false does not work for bash, so we do not accept it here either |
||
33 | /* |
||
34 | if (strtolower($val) === 'no') $val = false; |
||
35 | if (strtolower($val) === 'false') $val = false; |
||
36 | if (strtolower($val) === 'yes') $val = true; |
||
37 | if (strtolower($val) === 'true') $val = true; |
||
38 | */ |
||
39 | |||
40 | $val = str_strip_quotes($val); |
||
41 | |||
42 | define($name, $val); |
||
43 | $count++; |
||
44 | } |
||
45 | |||
46 | return $count; |
||
47 | } |
||
48 | |||
49 | function str_strip_quotes($x) { |
||
50 | if (((substr($x,0,1) == '"') && (substr($x,-1,1) == '"')) || |
||
51 | ((substr($x,0,1) == "'") && (substr($x,-1,1) == "'"))) { |
||
52 | return substr($x,1,strlen($x)-2); |
||
53 | } else { |
||
54 | return $x; |
||
55 | } |
||
56 | } |
||
57 |