#! /bin/sh

#set -x

usage="usage: flow-search from|to name logs...\n flow-search between name1 name2 logs..."

if [ $# -lt 3 -o $1 = 'between' -a $# -lt 4 ] ; then
    echo $usage
    exit 1
fi

direction=$1 ; shift
target=$1 ; shift

if [ $direction = 'between' ] ; then 
    target2=$1
    shift
fi

stuff="$direction.$target"

case $direction in
  "from" )
    what="-S $target -D all"
    ;;

  "to" )
    what="-S all -D $target"
    ;;

  "between" )
    what="-S $target -D $target2"
    stuff="$direction.$target.$target2"
    ;;

  '.' )
    echo $usage
    exit 1
    ;;
esac

for n do
    name=`basename $n`
    echo "searching $direction $target on $name"
    /usr/local/security/bin/flow-filter -f Flow.acl $what < $n > $stuff.$name
done


