#!/bin/sh
# General PPP login script 
# Work with the linuxconf's pppdialin module

PPPPARMS=/usr/lib/linuxconf/lib/pppparms
USER=`id -un`
if [ -x $PPPPARMS ] ; then
	#echo $PPPPARMS pppdopt $USER defppp >>/tmp/pppd.log
	#$PPPPARMS pppdopt $USER defppp >>/tmp/pppd.log
	eval `$PPPPARMS pppdopt $USER defppp`
fi
# How to allocate the remote IP address
if [ "$PPP_ALLOCFROMTTY" = "yes" -a "$PPP_REMOTEIP" = "" ] ; then
	# Check out the quotes on the next two lines.
	# They are back quote, not normal quote. Very important!!!
	TTY=`tty`
	PPP_REMOTEIP=`basename $TTY`
fi

# DNS sent to the client
DNSKEYW=ms-dns
IDLEKEYW=idle
if [ "$PPP_233" = "no" ] ; then
	DNSKEYW=dns-addr
	IDLEKEYW=idle-disconnect
fi

PROXYARP=
if [ "$PPP_PROXYARP" = "yes" ] ; then
	PROXYARP=proxyarp
fi

if [ "$PPP_DNS1" != "" ] ; then
	DNSOPT="$DNSOPT $DNSKEYW $PPP_DNS1"
fi

if [ "$PPP_DNS2" != "" ] ; then
	DNSOPT="$DNSOPT $DNSKEYW $PPP_DNS2"
fi

IDLETIMEOPT=
if [ "$PPP_IDLETIME" != "" -a "$PPP_IDLETIME" != "0" ] ; then
	IDLETIMEOPT="$IDLEKEYW $PPP_IDLETIME"
fi
if [ "$PPP_MAXTIME" != "" -a "$PPP_MAXTIME" != "0" ] ; then
	IDLETIMEOPT="$IDLETIMEOPT maxconnect $PPP_MAXTIME"
fi

if [ "$PPP_IPXENABLE" = "yes" ] ; then
	IPXOPTS="ipx $PPP_IPXOPTIONS"
	if [ "$PPP_IPXROUTINGRIP" = "yes" ] ; then
		IPXOPTS="$IPXOPTS ipx-routing 2"
	fi
	if [ "$PPP_IPXROUTINGNLSP" = "yes" ] ; then
		IPXOPTS="$IPXOPTS ipx-routing 4"
	fi
	if [ "$PPP_IPXNETNUM" != "" ] ; then
		IPXOPTS="$IPXOPTS ipx-network $PPP_IPXNETNUM"
	fi
	if [ "$PPP_IPXLOCALNUM" != "" -o "$PPP_IPXREMOTENUM" != "" ] ; then
		IPXOPTS="$IPXOPTS ipx-node $PPP_IPXLOCALNUM:$PPP_IPX_REMOTENUM"
	fi
	
fi

if [ "$PPP_OURIP" = "none" ] ; then
	PPP_OURIP=
fi


if [ -f /etc/ppp/options.$TTY ] ; then
	# Assume that the IP configuration for the PPP session is stored
	# in /etc/ppp/options.tty
	exec /usr/sbin/pppd -detach \
		crtscts modem lock $PROXYARP \
		$DNSOPT noauth $PPP_OPTIONS $IDLETIMEOPT $IPXOPTS ipparam "pppdialin $USER"
else
	exec /usr/sbin/pppd -detach \
		crtscts modem lock \
		$PPP_OURIP:$PPP_REMOTEIP $PROXYARP \
		$DNSOPT noauth $PPP_OPTIONS $IDLETIMEOPT $IPXOPTS ipparam "pppdialin $USER"
fi

