#!/bin/sh
#----------------------------------------------------------------------------
# /etc/rc.d/rc130.portfw - configure portforwarding
# was file /etc/rc.d/rc600.portfw
#
# Creation:        05.11.2000  fm
# Last Update:     $Id: rc130.portfw 9564 2005-08-12 21:13:37Z hh $
#----------------------------------------------------------------------------

case x$PORTFW_N in
x|x0) ;;
*)
    begin_script PORTFW "configuring portforwarding ..."

    > /etc/portfw.conf

    for idx in `seq 1 $PORTFW_N`
    do
        eval target='$PORTFW_'$idx'_TARGET'
        eval new_target='$PORTFW_'$idx'_NEW_TARGET'
        eval proto='$PORTFW_'$idx'_PROTOCOL'

        oldIFS="$IFS"

        IFS=":"
        set -- $target
        if [ "$2" = "" ]
        then
            target_host="default"
            target_ports="$1"
        else
            target_host="$1"
            target_ports="$2"
        fi

        set -- $new_target
        new_target_host="$1"
        if [ "$2" = "" ]
        then
            new_target_ports="$target_ports"
        else
            new_target_ports="$2"
        fi

        IFS="$oldIFS"

	translate_ip_net $target_host
	if is_error
	then
	    log_error "can't extract ip address from PORTFW_${idx}_TARGET='$target'"
	    continue
	fi
	target_host=$res

	translate_ip_net $new_target_host
	if is_error
	then
	    log_error "can't extract ip address from PORTFW_${idx}_NEW_TARGET='$new_target'"
	    continue
	fi
	new_target_host=$res

	echo "$target_host $target_ports $new_target_host $new_target_ports $proto" >> /etc/portfw.conf
    done

    end_script
;;
esac
