#!/bin/sh
# $Id: accounting,v 1.1.5.1 2000/07/16 12:00:01 root Exp root $
# $Date: 2000/07/16 12:00:01 $
#
# File: accounting
# Desc: setup accounting on a linux-host
#
# Author : Jens Friedrich
# 
#   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: accounting,v $
# Revision 1.1.5.1  2000/07/16 12:00:01  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:54  jens
# .
#
# Revision 1.1  1999/08/01 21:44:54  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:18  jens
# initial ci -r 1.0.9
#
# Revision 1.0  1998/06/01 19:32:54  jens
# initial ci -r 1.0
#
#

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

. $FWDIR/etc/net.cfg
. $FWDIR/etc/gateway.sh

# is accounting available ?
ACCNT=/proc/net/ip_acct

while [ $# -gt 0 ]; do

 case "$1" in

  start)
    if test -x $IPFW ; then

      ##### Accounting rules ####
      if [ -e $ACCNT -a x"$ACCOUNT" != x ]; then
        echo -n "Starting IP accounting: "
        for I in $ACCOUNT; do
          IPADDR=$I
          if [ -n "$IPADDR" ]; then 
            echo -n "$IPADDR "
            $IPFW -A -a -P all -S $IPADDR -D $ANY
            $IPFW -A -a -P all -S $ANY    -D $IPADDR
          fi
        done; echo ""
      fi
    fi
    ;;

  stop)
    if test -x $IPFW ; then
      if [ -e $ACCNT -a x"$ACCOUNT" != x ]; then
        echo "Stopping IP accounting."
        for I in $ACCOUNT; do
          IPADDR=$I
          if [ -n "$IPADDR" ]; then
            $IPFW -A -d -P all -S $IPADDR -D $ANY
            $IPFW -A -d -P all -S $ANY    -D $IPADDR
          fi
        done
      fi
    fi
    ;;

  *)
    echo "Usage: $0 {start|stop}"
    exit 1
    ;;

 esac
 shift
done
