Skip to content

Instantly share code, notes, and snippets.

@keiya
Created December 18, 2012 11:50
Show Gist options
  • Save keiya/4327348 to your computer and use it in GitHub Desktop.
Save keiya/4327348 to your computer and use it in GitHub Desktop.
dig web interface for minimalist
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
$| = 1;
if ($ENV{'QUERY_STRING'} ne '') {
print "Content-type:text/plain\n\n";
my %_GET = map { split('=',$_,2) } split('&',$ENV{'QUERY_STRING'});
if ($_GET{'addr'} !~ m/[^a-zA-Z0-9\.\-]/
and $_GET{'server'} !~ m/[^a-zA-Z0-9\.\-]/
and $_GET{'opt'} =~ m/(?:\-\w|)/) {
my $str = "dig $_GET{'opt'} $_GET{'addr'}";
$str .= " \@$_GET{'server'}" if $_GET{'server'} ne '';
print `$str`;
}
else {
print 'wrong address format';
}
}
else {
print "Content-type:text/html\n\n";
print <<__END__;
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, minimum-scale=1" />
<style>
body {
margin: 20px;
}
input,select {
font-size:1.2em;
}
</style>
</head>
<body onload='document.dig.addr.focus();'>
<form method='GET' action='dig.pl' name='dig'>
\$ dig
<select name='opt'>
<option value='' />(default)</option>
<option value='-x' />-x</option>
</select>
<input type='text' name='addr' />
\@<input type='text' name='server' placeholder='optional' />
<input type='submit' value='dig' />
</form>
</body>
</html>
__END__
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment