#!/bin/sh
#
# firewall        Starts firewall.
#
#
# chkconfig: 2345 12 88
# description: Firewall setup

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

[ -d /etc/sysconfig/firewall ] || exit 0
[ -f /etc/sysconfig/firewall/firewall ] || exit 0

#MMODULES="ip_masq_ftp ip_masq_irc ip_masq_raudio ip_masq_quake"


# See how we were called.
case "$1" in
  start)
        echo -n "Starting firewall: "

        for i in $MMODULES; do
           modprobe $i
        done

        /sbin/ipchains -F
        /sbin/ipchains -Z
        /sbin/ipchains-restore < /etc/sysconfig/firewall/firewall 2>/dev/null

        success
        echo
        touch /var/lock/subsys/firewall
        ;;
  stop)
        echo -n "Shutting down firewall: "
        cp /etc/sysconfig/firewall/firewall /etc/sysconfig/firewall/firewall.bak
        /sbin/ipchains-save > /etc/sysconfig/firewall/firewall.work 2>/dev/null
        date >> /var/log/ipacct
        /sbin/ipchains -L -vn >> /var/log/ipacct

        /sbin/ipchains -P forward ACCEPT
        /sbin/ipchains -P input   ACCEPT
        /sbin/ipchains -P output  ACCEPT
        /sbin/ipchains -F
	/sbin/ipchains -X
        /sbin/ipchains -Z
        success
        echo
        rm -f /var/lock/subsys/firewall
        ;;
  status)
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  *)
        echo "Usage: firewall {start|stop|status|restart}"
        exit 1
esac

exit 0
