#! /bin/sh

PATH=/sbin:/bin:/usr/sbin:/usr/bin
NAME=guarddog

#test -x /etc/rc.firewall || exit 0

if [ ! -f /etc/rc.firewall ]; then
  echo "Unable to start guarddog firewall - /etc/rc.firewall does not exist"
  exit 0
fi

set -e

case "$1" in
  start|restart|reload|force-reload)
	echo -n "Setting up guarddog firewall..."
	/bin/bash /etc/rc.firewall
	echo "done."
	;;
  stop)
        if [ -x /sbin/iptables ]; then
            echo -n "Stopping iptables firewall..."
            iptables -P OUTPUT ACCEPT
            iptables -P INPUT ACCEPT
            iptables -P FORWARD ACCEPT
            iptables -F
            iptables -X
            echo "done."
            exit 0;
        fi
        if [ -x /sbin/ipchains ]; then
            echo -n "Stopping ipchains firewall..."
            ipchains -P output ACCEPT
            ipchains -P input ACCEPT
            ipchains -P forward ACCEPT
            ipchains -F
            ipchains -X
            echo "done."
            exit 0;
        fi
        echo "Cannot find /sbin/ipchains or /sbin/iptables"
        exit 1
        ;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|restart|reload|force-reload}" >&2
	exit 1
	;;
esac

exit 0
