#!/bin/sh
#
# firewall      This shell script brings up the firewall rules
#
# chkconfig: 2345 11 91
# description: Firewall packet filter
# probe: false
#
# Copyright (c) 2011 - now Ipconnectivity BV"
#

# Source function library.
. /etc/init.d/functions

[ -f /etc/sysconfig/firewall ] && . /etc/sysconfig/firewall

start() {
        action "Installing Firewall packet filter" \
	/usr/local/ipcs/sbin/ipcs-firewall.sh $FIREWALL_OPTS start
        RETVAL=$?
	[ $RETVAL = 0 ] && touch /var/lock/subsys/firewall
        return $RETVAL
}

stop() {
	action "Deleting firewall packet filter" \

	iptables -F
	iptables -X
	iptables -t nat -F
	iptables -t nat -X
	iptables -t mangle -F
	iptables -t mangle -X

	RETVAL=?$
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/firewall
}

status() {
        echo "Display firewall status:"
	iptables -L 
	echo ""
	echo ""
	iptables -L -t nat
}


# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        stop
        start
        ;;
  condrestart)
        if [ -f /var/lock/subsys/firewall ]; then
            stop
            start
        fi
        ;;
  status)
        status
        ;;

  probe)
	if [ -f /var/lock/subsys/firewall -a \
	    /etc/sysconfig/firewall -nt /var/lock/subsys/firewall ];then
	    echo reload
	fi
	if [ ! -f /etc/sysconfig/firewall ]; then
	    if [ -f /var/lock/subsys/firewall ]; then
		echo stop
	    fi
	fi
	exit 0
	;;
  *)
	echo "Usage: firewall {start|stop|restart|status}"
	exit 1
esac

exit 0
