Rev 5 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5 | Rev 11 | ||
---|---|---|---|
1 | #!/usr/bin/php |
1 | #!/usr/bin/php |
2 | <?php |
2 | <?php |
3 | 3 | ||
4 | # |
4 | # |
5 | # VWhois (ViaThinkSoft WHOIS, a fork of generic Whois / gwhois) |
5 | # VGWhoIs (ViaThinkSoft Global WhoIs, a fork of generic Whois / gwhois) |
6 | # Maintenance / Developer utilities |
6 | # Maintenance / Developer utilities |
7 | # |
7 | # |
8 | # (c) 2012-2019 by Daniel Marschall, ViaThinkSoft <info@daniel-marschall.de> |
8 | # (c) 2012-2019 by Daniel Marschall, ViaThinkSoft <info@daniel-marschall.de> |
9 | # |
9 | # |
10 | # License: https://www.gnu.org/licenses/gpl-2.0.html (GPL version 2) |
10 | # License: https://www.gnu.org/licenses/gpl-2.0.html (GPL version 2) |
11 | # |
11 | # |
12 | 12 | ||
13 | require_once __DIR__ . '/../../../shared/php_includes/common_functions.inc.php'; |
13 | require_once __DIR__ . '/../../../shared/php_includes/common_functions.inc.php'; |
14 | 14 | ||
15 | $patterns = glob(__DIR__ . '/../../../main/pattern/*'); |
15 | $patterns = glob(__DIR__ . '/../../../main/pattern/*'); |
16 | 16 | ||
17 | #$bs = '\\b'; |
17 | #$bs = '\\b'; |
18 | #$be = '\\b'; |
18 | #$be = '\\b'; |
19 | 19 | ||
20 | $vc = '[\p{L}a-zA-Z0-9_\\-\\+\\*\\.]'; |
20 | $vc = '[\p{L}a-zA-Z0-9_\\-\\+\\*\\.]'; |
21 | $bs = '(?<!'.$vc.')'; |
21 | $bs = '(?<!'.$vc.')'; |
22 | $be = '(?!'.$vc.')'; |
22 | $be = '(?!'.$vc.')'; |
23 | 23 | ||
24 | foreach ($patterns as $pattern_file) { |
24 | foreach ($patterns as $pattern_file) { |
25 | $pattern = file($pattern_file); |
25 | $pattern = file($pattern_file); |
26 | 26 | ||
27 | $pattern[] = ':end'; |
27 | $pattern[] = ':end'; |
28 | 28 | ||
29 | $content = ''; |
29 | $content = ''; |
30 | foreach ($pattern as $p) { |
30 | foreach ($pattern as $p) { |
31 | $p = trim($p); |
31 | $p = trim($p); |
32 | if ($p == '') continue; |
32 | if ($p == '') continue; |
33 | if ($p[0] == '#') continue; // comment |
33 | if ($p[0] == '#') continue; // comment |
34 | 34 | ||
35 | if (preg_match('@^\\^redirect:@ismU', $p, $m)) continue; |
35 | if (preg_match('@^\\^redirect:@ismU', $p, $m)) continue; |
36 | 36 | ||
37 | $p = str_replace(array('(.*)', '(.+)'), '', $p); |
37 | $p = str_replace(array('(.*)', '(.+)'), '', $p); |
38 | 38 | ||
39 | if ($p[0] == ':') { |
39 | if ($p[0] == ':') { |
40 | $content = ''; |
40 | $content = ''; |
41 | } else { |
41 | } else { |
42 | if ($p[0] == '=') { |
42 | if ($p[0] == '=') { |
43 | // IP |
43 | // IP |
44 | $p_ = substr($p, 1); |
44 | $p_ = substr($p, 1); |
45 | 45 | ||
46 | // ignore for now |
46 | // ignore for now |
47 | continue; |
47 | continue; |
48 | } else if ($p[0] == '*') { |
48 | } else if ($p[0] == '*') { |
49 | // ASN |
49 | // ASN |
50 | 50 | ||
51 | preg_match('#\*(.*):(\d+)(-(\d+)){0,1}#isU', $p, $m); |
51 | preg_match('#\*(.*):(\d+)(-(\d+)){0,1}#isU', $p, $m); |
52 | $prefix = $m[1]; |
52 | $prefix = $m[1]; |
53 | $min = $m[2]; |
53 | $min = $m[2]; |
54 | $max = (isset($m[4])) ? $m[4] : $min; |
54 | $max = (isset($m[4])) ? $m[4] : $min; |
55 | 55 | ||
56 | // ignore for now |
56 | // ignore for now |
57 | continue; |
57 | continue; |
58 | } else if (preg_match('@^(urn:){0,1}oid:(.*)@i', $p, $m)) { |
58 | } else if (preg_match('@^(urn:){0,1}oid:(.*)@i', $p, $m)) { |
59 | // OIDs |
59 | // OIDs |
60 | 60 | ||
61 | $regex = normalize_oid($m[2]); |
61 | $regex = normalize_oid($m[2]); |
62 | $regex = str_replace('.', '\\.0*', $regex); |
62 | $regex = str_replace('.', '\\.0*', $regex); |
63 | $regex = '@('.$bs.$regex.'(\\.\\d+)*'.$be.')@iU'; |
63 | $regex = '@('.$bs.$regex.'(\\.\\d+)*'.$be.')@iU'; |
64 | 64 | ||
65 | echo "$regex\n"; |
65 | echo "$regex\n"; |
66 | } else { |
66 | } else { |
67 | // REGEX |
67 | // REGEX |
68 | 68 | ||
69 | $regex = $p; |
69 | $regex = $p; |
70 | 70 | ||
71 | if ($regex == '.') continue; // last resort |
71 | if ($regex == '.') continue; // last resort |
72 | 72 | ||
73 | $regex = preg_replace('@(?<!(?<!\\\\)\\$)$@', $vc.'*', $regex); |
73 | $regex = preg_replace('@(?<!(?<!\\\\)\\$)$@', $vc.'*', $regex); |
74 | $regex = preg_replace('@(?<!\\\\)\\$$@', '', $regex); |
74 | $regex = preg_replace('@(?<!\\\\)\\$$@', '', $regex); |
75 | 75 | ||
76 | $regex = preg_replace('@^(?!\\^)@', $vc.'*', $regex); |
76 | $regex = preg_replace('@^(?!\\^)@', $vc.'*', $regex); |
77 | $regex = preg_replace('@^\\^@', '', $regex); |
77 | $regex = preg_replace('@^\\^@', '', $regex); |
78 | 78 | ||
79 | $regex = preg_replace('@(?>!\\$)$@', $vc.'*', $regex); |
79 | $regex = preg_replace('@(?>!\\$)$@', $vc.'*', $regex); |
80 | $regex = preg_replace('@\\$$@', '', $regex); |
80 | $regex = preg_replace('@\\$$@', '', $regex); |
81 | 81 | ||
82 | $regex = '@('.$bs.$regex.$be.')@iUu'; |
82 | $regex = '@('.$bs.$regex.$be.')@iUu'; |
83 | 83 | ||
84 | echo "$regex\n"; |
84 | echo "$regex\n"; |
85 | } |
85 | } |
86 | } |
86 | } |
87 | } |
87 | } |
88 | } |
88 | } |