#!/bin/sh
# General PAP login script to use with mgetty
# Edit /etc/mgetty+sendfax/login.config and change the /AutoPPP/ line
# line this
# /AutoPPP/ - a_ppp /etc/ppp/paplogin

PPPPARMS=/usr/lib/linuxconf/lib/pppparms
if [ -x $PPPPARMS ] ; then
	# We do not know the user yet, so we can only configure few things
	eval `$PPPPARMS pppdopt defppp defppp`
fi
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



# 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

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 auth -chap +pap login \
		crtscts modem lock \
		$IDLETIMEOPT $PROXYARP $DNSOPT
else
	# Allocate the IP from the tty name, using DNS lookup
	# this is the nicest solution. No /etc/ppp/options.tty needed
	exec /usr/sbin/pppd -detach auth -chap +pap login \
		crtscts modem lock \
		loghost:$PPP_REMOTEIP \
		$IDLETIMEOPT $PROXYARP $DNSOPT
fi
