#!/usr/bin/env perl
use strictures;
use CGI qw(:standard);
use Data::Validate::IP "is_ipv4", "is_ipv6";
use Data::Validate::Domain "is_domain";
use JSON;
if ( my $thing = param("ip_or_domain") )
{
print header("application/json"),
to_json({ ipv4 => is_ipv4($thing) ? \1 : \0,
ipv6 => is_ipv6($thing) ? \1 : \0,
domain => is_domain($thing) ? \1 : \0 });
}
else
{
print header("text/html"),
start_html(-title => "OHAI",
-script => { -type => "text/javascript",
-src => "//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" }),
h1("MUCH IP. SO OCTET. WOW."),
start_form(),
p({-style => "width:48%; display:inline-block; text-align:right",
-class => "label"},
"IP or Domain"),
p({-style => "padding-left:1%;width:50%; display:inline-block"},
textfield(-name => "ip_or_domain",
-style => "width:17em",
-placeholder => "Enter an IP or Domain to verify")),
p({-style => "text-align:center", -class => "results"}),
end_form(),
<<' __jQuery', # The leading four spaces have to match at end.
__jQuery
end_html()
;
}
exit 0;
####
plackup -l :8080 -L Shotgun -MPlack::App::WrapCGI \
-e 'Plack::App::WrapCGI->new( script => "1066091.cgi" )'