#!/bin/sh
#
# firewall      This shell script takes care of starting and stopping
#               the firewall.
#
# chkconfig: 2345 11 90
# description: RCF (aka rc.firewall) is an ipchains-based firewall with an extensive list of network services (including IPSec, VTUN, NFS, SMB, Napster, Proxies, etc.), masquerading, port forwarding (including network games), IP accounting. All services are self-contained modules which can be prioritized and modified easily. Protections include spoofing, stuffed routing/masquerading, DoS, smurf attacks, outgoing port scans, and much more. RCF also supports multiple private, public, and DMZ interfaces with unique rules for each interface/service. RCF is distributed under the General Public License (GPL) terms.
# processname:
# config: /etc/firewall.conf
 
# Source function library 
[ -f /etc/rc.d/init.d/functions ] && . /etc/rc.d/init.d/functions	# Red Hat

# Source networking configuration.
if [ -f /etc/sysconfig/network ]	# Red Hat
then
	. /etc/sysconfig/network
elif [ -f /etc/network/options ]	# Debian
then
	. /etc/network/options
fi

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

[ -x /etc/firewall/sbin/rcf ] || exit 0

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

RETVAL=0

# See how we were called.
case "$1" in
	start|restart|reload|force-reload)
		/etc/firewall/sbin/rcf
		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/firewall/sbin/rcf --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|force-reload|status}"
		RETVAL=1
		;;
esac

exit $RETVAL
