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