#!/bin/sh
#
# firewall      This shell script takes care of starting and stopping
#               the firewall.
#
# chkconfig: 2345 11 90
# description: rc.firewall is an ipchains-based firewall script with \
#   extensive support for network services, masquerading, port \
#   forwarding, and IP accounting. 
# processname:
# config: /etc/firewall.conf
 
# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -x /etc/rc.d/rc.firewall ] || exit 0

[ -f /etc/firewall.conf ] || exit 0

RETVAL=0

# See how we were called.
case "$1" in
	start|restart|reload)
		/etc/rc.d/rc.firewall
		RETVAL=$?
		if [ $RETVAL -eq 0 ]
		then
			touch /var/lock/subsys/firewall
			echo "Firewall Started."
		else
			rm -f /var/lock/subsys/firewall
			echo "Error Starting Firewall!"
		fi
		;;
	stop)
		/etc/rc.d/rc.firewall --accept-all
		RETVAL=$?
		[ $RETVAL -eq 0 ] \
			&& rm -f /var/lock/subsys/firewall
        ;;
	status)
		TOTAL_RULES="`ipchains -L -n|egrep -c '^(MASQ|ACCEPT|DENY|REJECT|-)  *'`"
		echo "$TOTAL_RULES IPchains Firewall Rules (includes IP Accounting)"
        ;;
	*)
		echo "Usage: `basename $0` {start|stop|restart|reload|status}"
		RETVAL=1
		;;
esac

exit $RETVAL
