Sunday, October 30, 2011

CGI's in BASH, Part 2: Conclusion of Domain report

This is the conclusion to
Checking Status of Domains hosted on a server. Advanced Bash

This CGI in bash take the data we harvested in check2 from the out directory and prints this output to the web in a clean format. 

It take the list of domains from "masterlist" and searches the output files to see if that domain is in the good or bad bucket. 

It then add the results to an HTML table being constructed. 


domainreport
#!/bin/bash

echo "Content-type: text/html"
echo
echo "<html><body>"


cd /data/namedb/checkdomains

echo "<table border=2 cellpadding=2 cellspacing=2>"

for h in $( cat masterlist ); do

out="<tr><td>$h </td> "

for i in "extern" "local" "sokol" "whois" ; do

out="$out <td>`grep -l "^$h" $i.*`</td>"

done

out="$out <td>`grep -l "^$h" domains-from-httpd`</td>"
out="$out <td>`grep -l "^$h" domains-from-mail`</td>"
out="$out <td>`grep -l "^$h" available`</td>"
out="$out </tr>"

echo $out |\
sed -e 's/domains-from-httpd/Httpd/' |\
sed -e 's/domains-from-mail/E-Mail/' |\
sed -e 's/\.bad/<font color="red">\0<\/font>/g' |\
sed -e 's/\.good/<font color="green">\0<\/font>/g'
done

echo "</table>"
echo "</body></html>"


This second version save the first pass output to a file, then takes a second pass to sort the report before removing the index used to sort, and then displays it.


domainreport2
#!/bin/bash

echo "Content-type: text/html"
echo
echo "<html><body>"

echo "" > /tmp/domainreportout

cd /data/namedb/checkdomains

echo "<table border=1 cellpadding=2 cellspacing=2>"

for h in $( cat masterlist ); do

out="<td><a target="blank" href="http://$h">$h</a></td>"

for i in "extern" "local" "sokol" "whois" ; do

out="$out <td>`grep -l "^$h" $i.*`</td>"

done

out="$out <td>`grep -l "^$h" domains-from-httpd`</td>"
out="$out <td>`grep -l "^$h" domains-from-mail`</td>"
out="$out <td>`grep -l "^$h" available`</td>"
tally=`echo $out | tr '<' '\n' | grep -c "\.good"`
#out="<td>$tally</td>$out"
out="$tally ::$out"
out="<tr>$out</tr>"

echo $out |\
sed -e 's/domains-from-httpd/Httpd/' |\
sed -e 's/domains-from-mail/E-Mail/' |\
sed -e 's/\.bad/<font color="red">\0<\/font>/g' |\
sed -e 's/\.good/<font color="green">\0<\/font>/g' >> /tmp/domainreportout
done

sort -n -r /tmp/domainreportout | sed 's/.*:://'


echo "</table>"
echo "</body></html>"


Below is an example of the output.


6ghz.comextern.goodlocal.goodsokol.goodwhois.goodHttpdE-Mail
8vsb.comextern.goodlocal.goodsokol.goodwhois.goodHttpdE-Mail
9bnog.comextern.badlocal.badsokol.goodwhois.bad
9bnog.netextern.badlocal.badsokol.goodwhois.bad
9bnog.orgextern.badlocal.badsokol.goodwhois.bad
a2znetworks.netsokol.badwhois.badE-Mailavailable

No comments: