diff options
Diffstat (limited to 'whoseip/whoseip.pl')
-rw-r--r-- | whoseip/whoseip.pl | 97 |
1 files changed, 81 insertions, 16 deletions
diff --git a/whoseip/whoseip.pl b/whoseip/whoseip.pl index aa55770..625f441 100644 --- a/whoseip/whoseip.pl +++ b/whoseip/whoseip.pl @@ -468,8 +468,12 @@ sub serve { if ($term =~ /^${ipv4rx}$/) { if (defined($dbf)) { - %res = ipdb_lookup($dbf, $term); - if (defined($res{country})) { + eval { + %res = ipdb_lookup($dbf, $term); + }; + if ($@) { + error("cache lookup failure: $@"); + } elsif (defined($res{country})) { $res{status} = 'OK'; unless (defined($res{cidr})) { $res{cidr} = Net::CIDR::addrandmask2cidr($res{network}, @@ -500,10 +504,15 @@ sub serve { $res{status} = 'OK'; if (defined($dbf)) { foreach my $cidr (split /,/, $res{cidr}) { - ipdb_insert($dbf, $cidr, uc $res{country}, - { cidr => $res{cidr}, - server => $res{server}, - port => $res{port} }); + eval { + ipdb_insert($dbf, $cidr, uc $res{country}, + { cidr => $res{cidr}, + server => $res{server}, + port => $res{port} }); + }; + if ($@) { + error("can't cache $cidr: $@"); + } } } } @@ -608,7 +617,7 @@ sub getsegm { return $res; } -sub output { +sub expandout { my $s = shift; my %esctab = (a => "\a", b => "\b", @@ -624,24 +633,24 @@ sub output { print $s; } -sub format_out { +sub print_result { my $fmt = shift; local %_ = @_; while ($fmt =~ /(.*?)\$\?\{(\w+)\}(.*)/s) { - output($1); + expandout($1); my $v = $2; $fmt = $3; my $t = getsegm(\$fmt); my $f; $f = getsegm(\$fmt) if ($fmt =~ /^\{/); if (defined($_{$v})) { - format_out($t, @_); + print_result($t, @_); } elsif (defined($f)) { - format_out($f, @_); + print_result($f, @_); } } - output($fmt); + expandout($fmt); } sub docgi { @@ -674,7 +683,7 @@ sub docgi { %res = (status => 'BAD', diag => 'search term invalid or missing'); } } - format_out($fmt, %res); + print_result($fmt, %res); } # ####################################################################### @@ -736,7 +745,12 @@ GetOptions("h" => sub { if (defined($dbfile)) { $dbfile .= "whoseip.db" if (-d $dbfile); $dbopt{debug} = $debug; - $dbf = ipdb_open($dbfile, %dbopt); + eval { + $dbf = ipdb_open($dbfile, %dbopt); + }; + if ($@) { + error("can't open cache file $dbfile: $@"); + } } if (defined($dbexport)) { @@ -822,13 +836,13 @@ if ($fastcgi) { my $n = 1; while (<>) { chomp; - format_out($output_format, serve($_), item => $n++); + print_result($output_format, serve($_), item => $n++); last if $single_query; } } else { my $n = 1; foreach my $term (@ARGV) { - format_out($output_format, serve($term), item => $n++); + print_result($output_format, serve($term), item => $n++); } } } @@ -1173,6 +1187,14 @@ Where the information was obtained from. B<QUERY>, if it was retrieved from a remote B<whois> server and B<CACHE>, if it was read from the cache database. +=item B<${timestamp}> + +Time when the record entered the database (if obtained from cache). + +=item B<${ttl}> + +Cache entry time to live (if obtained from cache). + =item B<${server}> Whois server that returned the information. @@ -1181,6 +1203,14 @@ Whois server that returned the information. Port used to query the whois server. +=item B<${package}> + +Name of the package (B<whoseip>). + +=item B<${version}> + +B<Whoseip> version number. + =back If a macro is not defined, the corresponding reference expands to @@ -1203,6 +1233,41 @@ The escape sequences B<\a>, B<\b>, B<\e>, B<\f>, B<\n>, B<\r>, B<\t>, and B<\v> are replaced according to their traditional meaning. +=head1 EXIT CODES + +=over 4 + +=item 0 + +Normal termination. + +=item 64 + +Command line usage error. + +=item 65 + +Input data format error. + +=item 66 + +Input file cannot be opened. + +=item 70 + +Internal software error (please report that!) + +=item 72 + +Critical OS file is missing. Usually that means that B<FastCGI mode> has been +requested, but the B<FCGI> module couldn't be loaded. + +=item 73 + +Can't create output file. + +=back + =head1 BUGS Only IPv4 is supported. |