#
# APF 0.9.6 [apf@r-fx.org]
###
# Copyright (C) 1999-2004, R-fx Networks <proj@r-fx.org>
# Copyright (C) 2004, Ryan MacDonald <ryan@r-fx.org>
#
#    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 of the License, 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.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
###
#
CNF="/etc/apf/conf.apf"
if [ -f $CNF ]; then
   source $CNF
else
   echo "$CNF not found, aborting."
   exit 1
fi

if [ "$SET_VNET" == "0" ]; then
	exit 1
fi

if [ ! -f "$INSTALL_PATH/vnet/vnetgen.def" ]; then
        echo "vnetgen.def not found, aborting."
        exit 1
fi

if [ ! -f "$ip" ] && [ ! -f "$ifconfig" ]; then
        eout "{glob} $ip and $ifconfig not found; aborting"
	echo "$ip and $ifconfig not found; aborting"
        exit 1
elif [ -f "$ip" ]; then
 for addr in `/sbin/ip addr list | tr '/' ' ' | grep -w inet | grep -w $IF | grep -v 127.0.0.1 | grep -vw $NET | awk '{print$2}'`; do
  if [ ! -f "$INSTALL_PATH/vnet/$addr.rules" ]; then
        touch $INSTALL_PATH/vnet/$addr.rules
        chmod 600 $INSTALL_PATH/vnet/$addr.rules
        . $INSTALL_PATH/vnet/vnetgen.def
  fi
 done
elif [ -f "$ifconfig" ]; then
for iface in `ifconfig | grep -w $IF | awk '{print$1}'`; do
  for addr in `ifconfig $iface | grep -w inet | tr ':' ' ' | grep -vw $NET | awk '{print$3}'`; do
    if [ ! -f "$INSTALL_PATH/vnet/$addr.rules" ]; then
        touch $INSTALL_PATH/vnet/$addr.rules
        chmod 600 $INSTALL_PATH/vnet/$addr.rules
        . $INSTALL_PATH/vnet/vnetgen.def
    fi
  done
done
fi
