#!/bin/bash


if [ "$DOIT" = "" ]; then
  DOIT=0
fi

if [ "$DIR" = "" ]; then
  DIR=/ips
fi
if [ "$OURDEV" = "" ]; then
  OURDEV=eth0
fi
  
if [ "$IPTABLES" = "" ]; then
  IPTABLES=$DIR/iptables
fi


LIST=`echo $DIR/udp/*`
for i in $LIST; do 


   if [ ! -f "$i" ]; then
       continue
   fi    

   PTS=`cat $i 2> /dev/null`

   i=`basename $i`
   
   echo -n "$i" 
   #continue

   PLUS=
   
   for p in $PTS; do 
  
     if [ "$p" = "" ]; then
        continue
     fi    

     if [ "$p" = "+" ]; then
        PLUS=1
	echo " ACCEPT"
        continue
     fi    
     if [ "$p" = "-" ]; then
	echo " REJECT"
        PLUS=0
        continue
     fi    

     if [ "$PLUS" = "" ]; then
        continue
     fi    
 
     echo -n " $p : "
 
     if [ $PLUS = 0 ]; then
        COM="$IPTABLES -A FORWARD -i $OURDEV -s $i -p udp --destination-port $p -j REJECT"
     elif [ $PLUS = 1 ]; then
        COM="$IPTABLES -A FORWARD -i $OURDEV -s $i -p udp --destination-port $p -j ACCEPT"
     else
        continue
     fi 

     echo $COM
     if [ $DOIT = 1 ]; then
       $COM
     fi  

   done

     if [ $PLUS = 1 ]; then
        COM="$IPTABLES -A FORWARD -i $OURDEV -s $i -p udp -j REJECT"
	echo $COM
        if [ $DOIT = 1 ]; then
          $COM
        fi  
     fi

   echo

done
