And because reasons… and because <readmore/> is so hard to spell…
#!/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/li +bs/jquery/1.10.2/jquery.min.js" }), h1("MUCH IP. SO OCTET. WOW."), start_form(), p({-style => "width:48%; display:inline-block; text-align:righ +t", -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 e +nd. <script type="text/javascript">jQuery(function($){ var $in = $("input[name=ip_or_domain]"); var $form = $in.closest("form"); $form.submit(function(e){ e.preventDefault() }); $in.keyup(function(e){ $(".results").children().remove(); $.ajax({ dataType: "json" ,url: "/" ,data: { ip_or_domain:$in.val() } ,success: function(data){ for ( var key in data ) { if ( data.hasOwnProperty(key) && data[key] ) { var $i = $("<div style='color:#900'></div +>"); $i.hide(); $(".results").append($i); $i.text("Looks like " + key).fadeIn(); } } if ( ! $(".results").children().length ) $(".results").hide().append("<i>nothing</i>") +.fadeIn(); } }); }); })</script> __jQuery end_html() ; } exit 0;
Update: moved the end_html().
plackup -l :8080 -L Shotgun -MPlack::App::WrapCGI \ -e 'Plack::App::WrapCGI->new( script => "1066091.cgi" )'
Don’t write code like this so close to Christmas. You will make the baby Jesus cry.
In reply to Re: All attempts to match data from input fail. Please help.
by Your Mother
in thread All attempts to match data from input fail. Please help.
by taint
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |