Mercurial > hg > anonet-resdb
comparison contrib/whoisd/whoisd.pl @ 1141:58130f5eecf2 draft
found a bug when sending just '.'... wasn't good.
author | epoch <epoch@hacking.allowed.org> |
---|---|
date | Sun, 06 Oct 2013 11:45:06 +0000 |
parents | eec8e319f5bd |
children | ca4d35064aa2 |
comparison
equal
deleted
inserted
replaced
1140:eec8e319f5bd | 1141:58130f5eecf2 |
---|---|
20 if($QUERY eq "!!\n") { | 20 if($QUERY eq "!!\n") { |
21 $QUERY=<stdin>; | 21 $QUERY=<stdin>; |
22 $QUERY =~ s/^!r(.+?)[\/,].*$/\1/; | 22 $QUERY =~ s/^!r(.+?)[\/,].*$/\1/; |
23 printf "A500\n"; #fake this I guess. Does it even use that number for anything? | 23 printf "A500\n"; #fake this I guess. Does it even use that number for anything? |
24 printf "%% Looks like you're trying -A on a BSDian traceroute with this server.\n"; | 24 printf "%% Looks like you're trying -A on a BSDian traceroute with this server.\n"; |
25 printf "%% support will come soon for that.\n"; | |
26 $HACK=1; | 25 $HACK=1; |
27 } | 26 } |
28 | 27 |
29 # ASNs | 28 # ASNs |
30 if($QUERY =~ m/^AS(.+?)$/) { | 29 if($QUERY =~ m/^AS(.+?)$/) { |
31 printf "%% AS section for %s\n", $QUERY; | 30 printf "%% AS section for %s\n", $QUERY; |
32 my $AS=$1; | 31 my $AS=$1; |
33 chdir("$RESDB/db/as"); | 32 chdir("$RESDB/db/as") || die "%% error"; |
34 if(chdir($AS)) { | 33 if(chdir($AS) || die "%% error") { |
35 foreach(split(/\n/,`grep '' -r .`)) { | 34 foreach(split(/\n/,`grep '' -r .`)) { |
36 $out = $_; | 35 $out = $_; |
37 $out =~ s/^\.\///g; | 36 $out =~ s/^\.\///g; |
38 $out =~ m/^(.+?):(.+?)$/; | 37 $out =~ m/^(.+?):(.+?)$/; |
39 ($title, $value) = ($1, $2); | 38 ($title, $value) = ($1, $2); |
48 } | 47 } |
49 | 48 |
50 # IPv4 addresses | 49 # IPv4 addresses |
51 if($QUERY =~ m/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/) { | 50 if($QUERY =~ m/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/) { |
52 printf "%% IP section for %s\n", $QUERY unless $HACK; | 51 printf "%% IP section for %s\n", $QUERY unless $HACK; |
53 chdir("$RESDB/db/ip"); | 52 chdir("$RESDB/db/ip") || die "%% error"; |
54 @parts=split(/\./,$QUERY); | 53 @parts=split(/\./,$QUERY); |
55 for($i=0;$i<scalar(@parts)-1;$i++) { | 54 for($i=0;$i<scalar(@parts)-1;$i++) { |
56 if(!chdir(sprintf("%02X",$parts[$i]))) { | 55 if(!chdir(sprintf("%02X",$parts[$i]))) { |
57 printf "%-20s %s\n", "error" . ":", "IP not found." unless $HACK; | 56 printf "%-20s %s\n", "error" . ":", "IP not found." unless $HACK; |
58 exit; | 57 exit; |
72 | 71 |
73 # if we get here and there's still a . in the query it is probably a domain. | 72 # if we get here and there's still a . in the query it is probably a domain. |
74 if($QUERY =~ m/\./) { | 73 if($QUERY =~ m/\./) { |
75 printf "%% domain section for %s\n", $QUERY; | 74 printf "%% domain section for %s\n", $QUERY; |
76 @parts=split(/\./,$QUERY); | 75 @parts=split(/\./,$QUERY); |
77 chdir("$RESDB/db/dom"); | 76 chdir("$RESDB/db/dom") || die "%% error"; |
78 for($i=scalar(@parts)-1;$i>scalar(@parts)-3;$i--) { | 77 for($i=scalar(@parts)-1;$i>scalar(@parts)-3;$i--) { |
78 if(!$parts[$i]) { | |
79 printf "%% error"; | |
80 exit | |
81 } | |
79 if(!chdir($parts[$i])) { | 82 if(!chdir($parts[$i])) { |
80 printf "%-20s %s", "warning" . ":", "domain not found."; | 83 printf "%-20s %s", "warning" . ":", "domain not found."; |
81 exit; | 84 exit; |
82 } | 85 } |
83 } | 86 } |
94 } | 97 } |
95 | 98 |
96 # default to assuming it is a name. | 99 # default to assuming it is a name. |
97 printf "%% user section for %s\n", $QUERY unless $HACK; | 100 printf "%% user section for %s\n", $QUERY unless $HACK; |
98 | 101 |
99 chdir("$RESDB/db/usr"); | 102 chdir("$RESDB/db/usr") || die "%% error"; |
100 if(chdir($QUERY)) { | 103 if(chdir($QUERY)) { |
101 foreach(split(/\n/,`grep '' -r .`)) { | 104 foreach(split(/\n/,`grep '' -r .`)) { |
102 $out = $_; | 105 $out = $_; |
103 $out =~ s/^\.\///g; | 106 $out =~ s/^\.\///g; |
104 $out =~ m/^(.+?):(.+?)$/; | 107 $out =~ m/^(.+?):(.+?)$/; |
106 printf "%-20s %s\n", $title . ":", $value unless $HACK; | 109 printf "%-20s %s\n", $title . ":", $value unless $HACK; |
107 } | 110 } |
108 } else { | 111 } else { |
109 printf "%-20s missing db/usr file.\n", "warning" . ":" unless $HACK; | 112 printf "%-20s missing db/usr file.\n", "warning" . ":" unless $HACK; |
110 } | 113 } |
111 chdir("$RESDB/db/as"); | 114 chdir("$RESDB/db/as") || die "%% error"; |
112 foreach(split(/\n/,`grep '^$QUERY\$' */owner | cut -d/ -f1`)) { | 115 foreach(split(/\n/,`grep '^$QUERY\$' */owner | cut -d/ -f1`)) { |
113 $out = $_; | 116 $out = $_; |
114 $out =~ s/\n//g; | 117 $out =~ s/\n//g; |
115 printf "%-20s AS%s\n", "origin" . ":", $out if $HACK; | 118 printf "%-20s AS%s\n", "origin" . ":", $out if $HACK; |
116 printf "%-20s AS%s\n", "origin" . ":", $out unless $HACK; | 119 printf "%-20s AS%s\n", "origin" . ":", $out unless $HACK; |