Rev 2 | 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 | # |
||
5 | # generic Whois - Maintenance Framework: Testcases |
||
6 | # |
||
7 | # (c) 2012-2014 Daniel Marschall, ViaThinkSoft [www.viathinksoft.de] |
||
8 | # |
||
9 | # Distribution, usage etc. pp. regulated by the current version of GPL. |
||
10 | # |
||
11 | # |
||
12 | # Version 2014-11-25 |
||
13 | # |
||
14 | |||
4 | daniel-mar | 15 | require_once __DIR__ . '/../../../shared/php_includes/common_functions.inc.php'; |
2 | daniel-mar | 16 | |
4 | daniel-mar | 17 | $patterns = glob(__DIR__ . '/../../../main/pattern/*'); |
2 | daniel-mar | 18 | |
19 | #$bs = '\\b'; |
||
20 | #$be = '\\b'; |
||
21 | |||
22 | $vc = '[\p{L}a-zA-Z0-9_\\-\\+\\*\\.]'; |
||
23 | $bs = '(?<!'.$vc.')'; |
||
24 | $be = '(?!'.$vc.')'; |
||
25 | |||
26 | foreach ($patterns as $pattern_file) { |
||
27 | $pattern = file($pattern_file); |
||
28 | |||
29 | $pattern[] = ':end'; |
||
30 | |||
31 | $content = ''; |
||
32 | foreach ($pattern as $p) { |
||
33 | $p = trim($p); |
||
34 | if ($p == '') continue; |
||
35 | if ($p[0] == '#') continue; // comment |
||
36 | |||
37 | if (preg_match('@^\\^redirect:@ismU', $p, $m)) continue; |
||
38 | |||
39 | $p = str_replace(array('(.*)', '(.+)'), '', $p); |
||
40 | |||
41 | if ($p[0] == ':') { |
||
42 | $content = ''; |
||
43 | } else { |
||
44 | if ($p[0] == '=') { |
||
45 | // IP |
||
46 | $p_ = substr($p, 1); |
||
47 | |||
48 | // ignore for now |
||
49 | continue; |
||
50 | } else if ($p[0] == '*') { |
||
51 | // ASN |
||
52 | |||
53 | preg_match('#\*(.*):(\d+)(-(\d+)){0,1}#isU', $p, $m); |
||
54 | $prefix = $m[1]; |
||
55 | $min = $m[2]; |
||
56 | $max = (isset($m[4])) ? $m[4] : $min; |
||
57 | |||
58 | // ignore for now |
||
59 | continue; |
||
60 | } else if (preg_match('@^(urn:){0,1}oid:(.*)@i', $p, $m)) { |
||
61 | // OIDs |
||
62 | |||
63 | $regex = normalize_oid($m[2]); |
||
64 | $regex = str_replace('.', '\\.0*', $regex); |
||
65 | $regex = '@('.$bs.$regex.'(\\.\\d+)*'.$be.')@iU'; |
||
66 | |||
67 | echo "$regex\n"; |
||
68 | } else { |
||
69 | // REGEX |
||
70 | |||
71 | $regex = $p; |
||
72 | |||
73 | if ($regex == '.') continue; // last resort |
||
74 | |||
75 | $regex = preg_replace('@(?<!(?<!\\\\)\\$)$@', $vc.'*', $regex); |
||
76 | $regex = preg_replace('@(?<!\\\\)\\$$@', '', $regex); |
||
77 | |||
78 | $regex = preg_replace('@^(?!\\^)@', $vc.'*', $regex); |
||
79 | $regex = preg_replace('@^\\^@', '', $regex); |
||
80 | |||
81 | $regex = preg_replace('@(?>!\\$)$@', $vc.'*', $regex); |
||
82 | $regex = preg_replace('@\\$$@', '', $regex); |
||
83 | |||
84 | $regex = '@('.$bs.$regex.$be.')@iUu'; |
||
85 | |||
86 | echo "$regex\n"; |
||
87 | } |
||
88 | } |
||
89 | } |
||
90 | } |