#!/bin/sh
# by M. Andreoli

interface=$1; tty=$2; speed=$3; loc=$4; rem=$5

. /etc/utils
. /setup/lib/basic


restart_services()
{
for s in named httpd smbd
do
conf=$(. /setup/cnf/$s.cnf; echo $ACTION)
[ "$conf" = configure ] && setup $s restart
done
}

# acousting log

wave -c 440 2
wave -c 880 4


#----------------------------------------------
# put an entry in /var/run, useful to identificate
# the pppd pid and its tty device
#----------------------------------------------

echo $tty > /var/run/$interface.tty

#-----------------------------
# check if we are on Internet
#----------------------------

case "`setup isp status`" in
*up*)
	> /var/run/connected
	;
esac

#-------------------------
# network routing and NAT
#-------------------------

if [ "$rem" ] ; then
	mask=`get_mask $interface` 	# get netmask for the interface
	NETWORK=$(ip_network $rem $mask) 	# create NETWORK
	route add -net $NETWORK $interface	# add routing
	[ "$loc" ] && setup network # change my IP (?)
	ipfwadm -F -i m -S $rem -D 0/0 		# set NAT	
	restart_services
fi

# End
