#!/bin/sh
set -x
# $Id: fw_rules,v 1.1.5.1 2000/07/16 12:00:02 root Exp root $
# $Date: 2000/07/16 12:00:02 $
#
# File: fw-rules
# Desc: add/delete the firewalling-rules for a service
#       means: execute scripts in the rules directory
#       with the add or delete parameter.
# 
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2, or (at your option)
#   any later version.
# 
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
# (c) Copyright 1998 Jens Friedrich
#
# $Log: fw_rules,v $
# Revision 1.1.5.1  2000/07/16 12:00:02  root
# FCT
#
# Revision 1.1.4.2  2000/07/15 19:01:24  jens
# Rev.
#
# Revision 1.1.4.1  1999/08/01 21:44:55  jens
# .
#
# Revision 1.1  1999/08/01 21:44:55  jens
# Initial revision
#
# Revision 1.1.0.1  1998/11/02 09:36:30  jens
# .
#
# Revision 1.1  1998/11/02 09:35:49  jens
# Initial revision
#
# Revision 1.1  1998/11/02 09:33:28  jens
# Initial revision
#
# Revision 1.0.9.1  1998/06/01 19:35:24  jens
# initial ci -r 1.0.9
#
# Revision 1.0  1998/06/01 19:32:58  jens
# initial ci -r 1.0
#
#

# where is the firewall-package located ?
[ -z "$FWDIR" ] && FWDIR=`echo $0 | sed -e 's/[\/][A-Za-z0-9_\.-]*$//'`

usage ()
{
    echo "Usage: $0 [-t] [-v] <service> | Firewall/<service> [del]"
    echo "<service>             execute rules file $FWDIR/rules/<service>.rules"
    echo "Firewall/<service>    execute rules file $FWDIR/rules/Firewall/<service>.rules"
    echo "-t                    run in test mode, only create the config files"
    echo "-v                    run in verbose mode, print each IP-filter line"
    echo "del                   delete rules for the specified service"
    exit 1
}
        
if [ $# -eq 0 ]; then
  usage
fi

# read the configuration files
. $FWDIR/etc/net.cfg
. $FWDIR/etc/fw.cfg
. $FWDIR/etc/services.cfg
. $FWDIR/etc/trusted.cfg
. $FWDIR/etc/aliases.cfg
. $FWDIR/etc/gateway.sh

testing=false
verbose=false
setup=false

while [ $# -gt 0 ]; do
  case "$1" in

      -s) setup=true
          echo ""
          ;;

      -h) usage
          ;;

      -t) testing=true
          echo ""
          ;;

      -v) verbose=true
          ;;

      *)
          fw_svc="./"
          [ `echo "$1" | grep -i -c Firewall` -gt 0 ] && fw_svc="Firewall"
          rule=`echo $1 | sed 's/^.*\///'`
          rule=`echo $rule | sed 's/\.rules$//'`
          . $FWDIR/rules/$fw_svc/$rule.rules $2
          ;;

  esac
  shift
done
