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