#!/bin/sh
# Copyright (c) 1997-now, NeoNova BV, The Netherlands. All rights Reserved.
#
# This software is the copyrighted work of NeoNova BV.
# Use of the software is subject to the general business terms and conditions of NeoNova BV
# and its related transaction documents like license sheets or other written notices.#
# Any reproduction or redistribution of the software not in accordance with the license terms
# is expressly prohibited by law, and may result in severe civil and criminally penalties.
# Violators will be prosecuted to the maximum extent possible.

#
# firewall      This shell script brings up the firewall rules
#
# chkconfig: 2345 91 9
# description: Firewall packet filter
# probe: false
#
# Copyright (c) 2001-2004 NeoNova BV"
#
# ASTIUM Home Page: http://www.astium.nl"
#
# ASTIUM: IP Filtering Firewall script for ASTIUM."
#                  

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

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

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

stop() {
	action "Deleting firewall packet filter" \
	/usr/local/astium/sbin/astium-iptables stop
	RETVAL=?$
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/firewall
}

status() {
	COUNT=`/sbin/iptables -n -L | grep ^TO_INTF_EXTERNAL | wc -l`
	if [ $COUNT -gt 0 ]
	then
		echo "firewall is running"
	else
		echo "firewall is stopped"
	fi
}

# 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
