#!/bin/sh
#
# scip's firewall
#
# bin/scipfire - the main beast
#
# $Id: scipfire,v 1.3 2001/07/29 21:24:17 scip Exp $
#


#
# this is the only one variable you need to set here!
# it must point to the base dir of your scipfire installation
PREFIX=/etc/scipfire.d





#
# source the configuration
if [ -f "$PREFIX/conf/scipfire.cfg" ]; then
  . $PREFIX/conf/scipfire.cfg
else
  echo "$PREFIX/conf/scipfire.cfg does not exist. Run ./configure to create it."
  exit
fi



#
# define possible modes, we support
RUNLEVELS="start | startlog | print | printlog | stop | reload | restart | status"


#
# get the mode
MODE=$1



#
# see, if the supplied mode is correct
ALLOWED=`echo "$RUNLEVELS" | grep "$MODE"`

if [ "x$ALLOWED" = "x" -o "x$MODE" = "x" ]; then
    echo "usage $0 { $RUNLEVELS }"
else
    echo " scipfire $MODE"
    #
    # execute chain scripts
    case $MODE in
	reload|restart)
	    $iptables -F
	    $iptables -X
	    MODE=start
	    ;;
	status)
	    echo "------[ table filter ]------"
	    $iptables -L -n -v --line-numbers 
	    echo
	    echo "------[ table nat    ]------"
	    $iptables -L -n -v -t nat --line-numbers
	    echo
	    echo "------[ table mangle ]------"
	    $iptables -L -n -v -t mangle --line-numbers
	    exit
	    ;;
    esac
    case $MODE in
	start|print|startlog|printlog)
	    TYPE="S"
	    ;;
	stop)
	    TYPE="K"
	    ;;
    esac
    for chain in `ls $PREFIX/rc.d/$TYPE*`; do
	# echo "/bin/bash $DEBUG $chain $MODE $PREFIX"
	/bin/bash $DEBUG $chain $MODE $PREFIX
    done
    echo " done."
fi



