#!/bin/sh

if [ -z "$1" ]; then
  echo "Please specify file with rules."
  exit 0
fi

echo "   - Loading PORTFW rulesets"

for rule in `cat $1 | $GREP -v "^#"`; do
	rule=`echo $rule | $SED -e 's/,/ /g'`
	set $rule
	PFW_TYPE=$1
	PFW_IP=$3
	PFW_PORT=$2
	PFW_DPORT=$4

	echo "      - $PFW_PORT --> $PFW_IP:$PFW_DPORT"
	
	$IPTABLES -A FORWARD -i $EXTIF -o $INTIF -p $PFW_TYPE -d $PFW_IP --dport $PFW_DPORT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
		 
	$IPTABLES -A PREROUTING -t nat -p $PFW_TYPE -d $EXTIP --dport $PFW_PORT -j DNAT --to $PFW_IP:$PFW_DPORT
done