#!/usr/bin/perl
#
# A Simple WWW interface for Sleuth domain checker
# (c) 1999--2006 Martin Mares <mj@ucw.cz>
#
# Load configuration file and all modules we need
BEGIN { require "check.conf"; }
use CGI;
use IO::Handle;
$query = new CGI;
print $query->header;
$domain = $query->param('domain');
$server = $query->param('server');
$serverip = $query->param('serverip');
$verbose = $query->param('verbose');
$secondary = $query->param('secondary');
$submitter = $query->param('submitter');
$submit = "Submit";
$stylesheet = <<EOF
#headbar {
background-color: #4c3bff; color: #fffa45; margin: 0 15%; padding: 1ex;
text-align: center;
border: solid white;
border-width: 1px;
}
#headbox1 {
position: absolute;
width: 15%;
top: 0; bottom: auto; left: 0; right: auto;
text-align: center;
}
#headbox2 {
position: absolute;
width: 15%;
top: 0; bottom: auto; left: auto; right: 0;
text-align: center;
}
#querybox {
background-color: #ffffb0;
color: black;
margins: 0 15%;
padding: 1ex 2ex;
border: solid black;
border-width: 1px;
}
#querybox TD {
padding: 0.5ex 1ex;
}
TD#qbhead {
font-size: 150%;
font-weight: bold;
text-align: center;
padding-bottom: 1ex;
}
.singline { display: block }
.collapse { margin: 0 0 }
.msgW { color: #9e6500; font-style: normal; }
.msgE, .msgF { color: #d73a05; font-style: normal; }
EOF
;
print $query->start_html( -title=>"DNS Sleuth",
-author=>"$admin_email",
-dtd=>'-//W3C//DTD HTML 4.01//EN',
-style=>{-code=>$stylesheet}
);
print <<EOF
<div id=headbar align=center>
<h2 class=collapse>The DNS Sleuth</h2>
<p class=collapse style="margin-top: 1ex">An online tool for checking of DNS zones
</div>
<div id=headbox1 align=center>
<p><A HREF="ftp://atrey.karlin.mff.cuni.cz/pub/local/mj/net/sleuth-$version.tar.gz">Sleuth</A> version $version ($rev_date)
</div>
<div id=headbox2 align=center>
<p>
<span class=singline>Written by</span>
<span class=singline>$author_ref</span>
<span class=singline><a href="mailto:$author_email"><$author_email></a></span>
</div>
EOF
;
if ($secondary_ns eq "") {
$secondary = '';
}
$msg = "New query";
if ($domain eq "") {
print <<EOF
<P>This is an online version of Sleuth -- a detector
of common errors in DNS zones.
<P>To check a zone, just enter its name in the form below. You can explictly
specify a name server to be asked for zone data and if its name isn't available
from the public DNS, then also its IP address. If you select the verbose mode,
you will also get a full dump of the zone at no extra cost.
EOF
;
if ($secondary_ns ne "") {
print <<EOF
<P>If you want to submit a request for secondary DNS service, fill in all
form fields and check the "request secondary" box. The secondary server will
run on <CODE>$secondary_ns</CODE>, so don't forget to list it as an
authoritative server in your zone file.
EOF
;
}
print <<EOF
<P>If you want to run Sleuth on your own machine, just <a href="ftp://atrey.karlin.mff.cuni.cz/pub/local/mj/net/">download</a>
the latest version from our FTP server. Sleuth is free software, you can freely use and distribute it according
to the <a href="http://www.gnu.org/copyleft/">GNU General Public License</a>.
<P>If this page looks a bit fruitless, but otherwise displayed correctly,
it's probably because your browser doesn't support the <a href="http://www.w3.org/Style/CSS/">Cascading
Style Sheets</a> which are The Right Way to define presentation of HTML documents.
In case this page looks a bit weird, your browser probably tries
to support the style sheets, but does it wrongly (hello, Netscape 4).
EOF
;
} elsif ($secondary ne "" && $serverip eq "") {
$msg = "Missing server name";
} elsif ($secondary ne "" && $submitter eq "" && $need_submitter) {
$msg = "Please fill in who is submitting the zone";
} elsif ($server !~ /^[0-9A-Za-z.-]*$/ ||
$serverip !~ /^(\d+\.\d+\.\d+\.\d+)?$/ ||
$domain !~ /^[0-9A-Za-z.\/-]*$/ ||
$submitter !~ /^[0-9A-Za-z.\240-\376 -]*$/) {
$msg = "Incorrect parameter syntax";
} elsif ($secondary ne "" && defined $sec_ns_addr_space &&
unpack("H8",pack("c4",split(/\./,$serverip))) !~ $sec_ns_addr_space) {
$msg = "Name server address out of permitted range";
} else {
print "<H2>Check results for $domain</H2>\n";
@c = "./sleuth";
if ($verbose ne "") { push @c, "-v"; }
push @c, "-h", $domain, $server;
if ($serverip ne "") { push @c, $serverip; }
if ($secondary ne "") { push @c, $secondary_ns, $secondary_ns_ip; }
STDOUT->flush();
$rc = system @c;
if ($secondary ne "") {
if ($rc / 256) {
print "<P>Request for secondary DNS service rejected because of errors in the zone.\n";
print "<P>If you have any questions, please ask $admin_ref.\n";
} else {
print "<P>Forwarding your secondary DNS service request to $admin_ref\n";
print "who will notify you by e-mail sent to the hostmaster address given in the\n";
print "SOA record when the secondary server will be configured.\n";
shift @c;
while ($c[0] =~ /^-[vh]$/) { shift @c; }
$ru = $query->remote_user;
($rh = $query->remote_host) =~ s/[^A-Za-z0-9. \240-\376-]/?/g;
# This might look insecure, but we know all the names have been correctly
# validated by the first sleuth run.
`( echo "Domain: $domain" ;
echo "Server: $server [$serverip]" ;
echo "User: $ru" ;
echo "From: $submitter ($rh)" ;
echo ;
./sleuth @c
) | mail -s \"New zone\" $secondaries_to`;
$? && print "<P><EM>Forwarding failed (rc=$?)</EM>\n";
}
}
print "<hr>\n";
}
print $query->startform(-method=>'GET');
print "\
<p><table align=center border=0 id=querybox>\n\
<tr><td colspan=4 align=center id=qbhead>$msg</td></tr>\n";
print "<tr><td><em>Domain:</em></td><td>", $query->textfield('domain'), "</td>\n";
print "<td><em>Verbose output:</em></td><td>", $query->checkbox(-name=>'verbose',value=>'ON',-label=>''), "</td></tr>\n";
print "<tr><td><em>Server name:</em></td><td>", $query->textfield('server'), "</td>\n";
print "<td><em>Server IP:</em></td><td>", $query->textfield('serverip'), "</td></tr>\n";
if ($secondary_ns ne "") {
print "<tr><td><em>Request secondary:</em></td><td>", $query->checkbox(-name=>'secondary',value=>'ON',-label=>''), "</td>\n";
print "<td><em>Your name:</em></td><td>", $query->textfield('submitter'), "</td></tr>\n";
}
print "<tr><td colspan=4 align=center>", $query->submit('action', 'Submit'), "</td></tr>\n";
print "</table>\n";
print $query->endform;
print "<div align=center><p>Please <a href=\"mailto:$author_email\">send</a> your bug reports and suggestions to $author_ref.</div>\n";
print $query->end_html;
print "\n";
syntax highlighted by Code2HTML, v. 0.9.1