#!/bin/bash
#
# by: Brian Butler (20100902)
#
# Grading script for the Morris Worm and Fish Supply Company case study
# this script is to be installed and run on desktopX.example.com
# output is logged to syslog

# Set environment and declare global variables
. /usr/local/lib/labtool.shlib
trap on_exit EXIT
LOG_FACILITY=local0
LOG_PRIORITY=info
LOG_TAG=morriswormGrade
DEBUG=false
ERROR_MESSAGE="FAILED."
PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin
userInput="no"
set -o pipefail
md5hash="d772fabcd82872c9168e166b418cb7a7"

# Check to make sure we are running on the correct host
check_host "desktop"

# Check for required packages
PACKAGES=( wget )
check_packages

# Grab the test file from the web server
echo -n "Checking for http://$(hostname)/ and the site content... "
wget -O /tmp/morris.png http://$(hostname)/img/morris.png || exit 1

[ "$(md5sum /tmp/morris.png)" != "$md5hash" ] && exit 1

echo "PASSED."

#### Moved to lab-cleanup-morrisworm ####
# Restore desktopX's firewall rules and reset vserver to classroom network
#(cp -a /root/iptables /etc/sysconfig/iptables 2>&1 | log)
#(gls-vserver-network --classroom 2>&1 | log)
#########################################

exit 0
