#!/bin/bash
# description: Start/stop Firewall
# chkconfig: 2345 13 90

. /etc/init.d/functions

case "$1" in
'start')
       modprobe ip_conntrack_ftp
       echo -n "Starting firewall ... "
       /usr/sbin/firewall.pl
       RETVAL=$?
       if [[ $RETVAL -eq 0 ]]; then
         echo_success
         echo
       elif [[ $RETVAL -eq 1 ]]; then
         echo_warning
         echo
       else
         echo_failure
         echo
       fi

       /etc/init.d/iptables save
       if [[ -f /opt/hgmods/proxy_cron.pl ]]; then
         /opt/hgmods/proxy_cron.pl
       fi
       if [[ -f /etc/init.d/bandmin ]]; then
         /etc/init.d/bandmin start
       fi
       ;;
'stop')
       iptables -F
       iptables -X
       RETVAL=$?
       ;;
'restart') 
       if [[ -f /etc/init.d/bandmin ]]; then
         /etc/init.d/bandmin stop
       fi
       modprobe ip_conntrack_ftp
       echo -n "Restarting firewall ... "
       /usr/sbin/firewall.pl
       RETVAL=$?
       if [[ $RETVAL -eq 0 ]]; then
         echo_success
         echo
       elif [[ $RETVAL -eq 1 ]]; then
         echo_warning
         echo
       else
         echo_failure
         echo
       fi

       /etc/init.d/iptables save
       if [[ -f /opt/hgmods/proxy_cron.pl ]]; then
         /opt/hgmods/proxy_cron.pl
       fi
       if [[ -f /etc/init.d/bandmin ]]; then
         /etc/init.d/bandmin start
       fi
       ;;
*)
       echo "Usage: $0 { start | stop | restart }"
       RETVAL=1
       ;;
esac
exit $RETVAL

