#!/bin/bash
#
# by: Brian Butler (20100902)
#
# Setup 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=morrisWorm
DEBUG=false
ERROR_MESSAGE="Error running script. Contact your instructor if you continue to see this message."
PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin
userInput="no"
set -o pipefail

# Check to make sure we are running as root
check_root

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

# Prompt the user before we make any changes to the system
cat <<EOL

*** NOTICE ***
This script will reset vserver to setup the excercise.
EOL
confirm
echo
echo -n "Setting up, one moment please... "

# Reset vserver
(/usr/local/sbin/lab-resetvm 2>&1 | log) || exit

# Back up existing iptables rules
([ -f /etc/sysconfig/iptables ] && cp -a /etc/sysconfig/iptables /root/iptables 2>&1 | log)

# Clear iptables rules
(service iptables stop 2>&1 | log) || exit

# Configure vserver to use the private network
(gls-vserver-network --private 2>&1 | log) || exit

echo 'done!'

exit 0
