#!/bin/bash
# Name: authcheck
# Author: Brendan Hide (http://swiftspirit.co.za/)
# Copyright: (c) Brendan Hide, released under the GPLv3 license
#            See http://www.gnu.org/licenses/gpl-3.0.html for the License details
# Release Version: 0.3 (2009-04-09)
# TODO: nil

#If you have admin rights to the server, input the secret text into a comment of the default page
#SECRETTEXT=`echo "tricky secret text" | md5sum | awk {'print $1'}`
SECRETTEXT="tricky secret text"

RANDSET="$RANDOM.$$"
HUH="/tmp/.authcheck.$RANDSET.huh.htm"
DEF="/tmp/.authcheck.$RANDSET.def.htm"

trap "rm -f $HUH" INT TERM EXIT

if [ $# -eq 1 ]
 then
  wget --no-cache -T 2 -t 3 -O - $1/huh.htm 2>&1 | cat > $HUH
  wget --no-cache -T 2 -t 3 -O - $1 2>&1 | cat > $DEF
  grep "$SECRETTEXT" < $HUH > /dev/null && echo "Domain $1 is being served by the default site on the server"
  grep "Giving up" < $DEF > /dev/null && echo "Domain $1 is not responding - \"Giving up\""
  grep "No route to host" < $DEF > /dev/null && echo "Domain $1 is not reachable - \"No route to host\""
  grep "401 Unauthorized" < $DEF > /dev/null && echo "Domain $1 has ACL issues - 401 Unauthorized"
  grep "403 Forbidden" < $DEF > /dev/null && echo "Domain $1 has no default content and directory browsing is forbidden - 403 Forbidden"
 else echo "Usage: authcheck domainname"
fi

rm -f $HUH
rm -f $DEF

trap - INT TERM EXIT
