Created
September 8, 2016 15:09
-
-
Save wttw/3ea332fa59ed394f091b2c6fcf0db3df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /dns/<qtype>/<host> | |
sub resolve { | |
my $self = shift; | |
my $qtype = $self->param('qtype'); | |
my $query = $self->param('query'); | |
$query =~ s/^\s*//; | |
$query =~ s/\s*$//; | |
if($qtype eq 'reverse') { | |
$qtype = 'ptr'; | |
if($query =~ /^[0-9a-f:.]+$/) { | |
my $ip = new Net::IP($query); | |
if($ip) { | |
$query = $ip->reverse_ip(); | |
} | |
} | |
if($query =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) { | |
$query = "$4.$3.$2.$1.in-addr.arpa"; | |
} | |
} | |
my $qdesc = exists $QUERY_DESCRIPTION->{$qtype} ? $QUERY_DESCRIPTION->{$qtype} : uc($qtype); | |
$self->app->log->debug("About to render"); | |
my $cv = AnyEvent->condvar; | |
$cv->begin; | |
AnyEvent::DNS::resolver->request({ | |
rd => 1, | |
qd => [[$query, $qtype, 'in']] | |
}, sub { | |
my $res = shift; | |
$self->app->log->debug("In callback"); | |
$self->stash(res => $res, qtype => uc($qtype), qname => $query, qdesc => $qdesc); | |
$cv->end; | |
}); | |
$cv->recv; | |
$self->render(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment