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-2015 Daniel Marschall, ViaThinkSoft [www.viathinksoft.de] |
||
8 | # |
||
9 | # Distribution, usage etc. pp. regulated by the current version of GPL. |
||
10 | # |
||
11 | # |
||
12 | # Version 2015-04-17 |
||
13 | # |
||
14 | |||
15 | #mb_internal_encoding('utf-8'); |
||
16 | |||
4 | daniel-mar | 17 | require_once __DIR__ . '/../../../shared/php_includes/common_functions.inc.php'; |
18 | require_once __DIR__ . '/../../../shared/php_includes/idna_convert.class.php'; |
||
2 | daniel-mar | 19 | |
20 | $punycoder = new idna_convert(); |
||
21 | |||
22 | $in = ''; |
||
23 | while($f = fgets(STDIN)) { |
||
24 | $in .= $f; |
||
25 | } |
||
26 | |||
27 | $pre = generateRandomToken($in); |
||
28 | $post = generateRandomToken($in); |
||
29 | $plc1 = generateRandomToken($in); |
||
30 | |||
31 | // to avoid that "domain......ati.tn" will be highlighted completely. |
||
32 | $in = preg_replace('@\\.{2,}+@u', '<<<'.$plc1.':${0}>>>', $in); |
||
33 | |||
34 | if ($argc == 1) { |
||
35 | $out = array(); |
||
36 | exec(__DIR__ . '/allpatterns', $out, $code); |
||
37 | if ($code != 0) { |
||
38 | echo __DIR__ . "/allpatterns failed with code $code\n"; # TODO: STDERR |
||
39 | exit(1); |
||
40 | } |
||
41 | foreach ($out as $o) { |
||
42 | $o = trim($o); |
||
43 | if ($o == '') continue; |
||
44 | $argv[] = $o; |
||
45 | } |
||
46 | } |
||
47 | |||
48 | array_shift($argv); |
||
49 | # $i = 0; |
||
50 | foreach ($argv as $x) { |
||
51 | # TODO: problem: $x darf nicht quoted werden, darf aber auch nicht @ enthalten -> dynamisch rausfinden welcher delimiter nicht vorkommt |
||
52 | # TODO: there are several problems using this mechanism. It is very hard to highlight everything which is queryable through gwhois. |
||
53 | # for example: (1) it is not possible to use \S+ in the pattern files, because it would match everything in the gwhois output, even though it was only meant to match everything in the query |
||
54 | # (2) if the rule .com.xx is applied after .xx , the .com.xx will not match, since .xx is already wrapped with $pre and $post |
||
55 | |||
56 | # $i++; |
||
57 | # $pre = "[start$i]"; |
||
58 | # $post = "[end$i]"; |
||
59 | |||
60 | $in = preg_replace($x, $pre.'${0}'.$post, $in); |
||
61 | |||
62 | $c = 0; |
||
63 | |||
64 | $x = preg_replace_callback("@(xn\-\-[0-9a-z\-]+)@ui", "punycodeCB", $x, -1, $c); |
||
65 | if ($c > 0) { |
||
66 | $in = preg_replace($x, $pre.'${0}'.$post, $in); |
||
67 | } |
||
68 | } |
||
69 | |||
70 | # Remove nesting (( x (( y )) a )) -> (( x a )) |
||
71 | do { |
||
72 | $ok = true; |
||
73 | $in = preg_replace_callback("@$pre(.*$post)@Uu", "verschachtelungCB", $in); |
||
74 | } while (!$ok); |
||
75 | |||
76 | # colorize |
||
77 | $in = str_replace($pre, "\033[41m\033[37m", $in); |
||
78 | $in = str_replace($post, "\033[0m", $in); |
||
79 | |||
80 | # undo it again (see above) |
||
81 | $in = preg_replace('@<<<'.$plc1.':([^>]+)>>>@u', '${1}', $in); |
||
82 | |||
83 | echo $in; |
||
84 | |||
85 | # --- |
||
86 | |||
87 | function verschachtelungCB($treffer) { |
||
88 | global $pre, $post, $ok; |
||
89 | |||
90 | if (strpos($treffer[1], $pre) === false) { |
||
91 | return $pre.$treffer[1]; |
||
92 | } else { |
||
93 | $ok = false; |
||
94 | return $pre.str_replace(array($pre,$post), '', $treffer[1]); |
||
95 | } |
||
96 | } |
||
97 | |||
98 | function punycodeCB($treffer) { |
||
99 | global $punycoder; |
||
100 | |||
101 | $out = ""; |
||
102 | $x = $punycoder->decode(strtolower($treffer[0])); |
||
103 | preg_match_all('/./u', $x, $results); |
||
104 | foreach ($results[0] as $m) { |
||
105 | $out .= '\\x{'.dechex(_uniord($m)).'}'; |
||
106 | } |
||
107 | |||
108 | return $out; |
||
109 | } |
||
110 |