mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-15 10:17:20 +00:00
130 lines
3.4 KiB
Bash
Executable File
130 lines
3.4 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# USAGE: connect-ppp <host>
|
|
#
|
|
# Set up a PPP link to host.
|
|
#
|
|
# This script locks the tty so that faxd and uucp will not
|
|
# interfere. If you are running with faxd as you "getty" then
|
|
# faxd will remove the lock once it notices that pppd is gone.
|
|
# This is the reason for pppd running in with the -detach flag,
|
|
# and you probably would run this script in the background.
|
|
#
|
|
# I had to create the nodropdtr option to pppd in order to be
|
|
# able to do what the script is doing here. Pathces has been
|
|
# sent to the respective people, but I don't know if they like
|
|
# them :-).
|
|
#
|
|
# Look for comments with <LOCAL> in the string. They identify
|
|
# things that you want to set for your system
|
|
|
|
#<LOCAL> define whatever your config file is.
|
|
CON_DB=/etc/ppp-connections
|
|
|
|
#<LOCAL> define whatever your device is.
|
|
DEVICE=tty00
|
|
|
|
#<LOCAL> define whatever your device speed is.
|
|
DEVICESPEED=57600
|
|
|
|
#<LOCAL> define whatever your lock directory is.
|
|
LOCKDIR=/var/spool/lock
|
|
LOCKFILE=$LOCKDIR/LCK..$DEVICE
|
|
|
|
#<LOCAL> define whatever debug level you want.
|
|
DEBUG="-d -d -d -d"
|
|
|
|
# Check that we got a name to connect to. This need not be an actuall hostname
|
|
# just the name you specified in the config file.
|
|
if [ $# -ne 1 ] ; then
|
|
echo "Usage: $0 <host> &"
|
|
exit 1
|
|
fi
|
|
|
|
# Get the configuration that is in effect for <name>
|
|
LINE=`grep "^$1" $CON_DB`
|
|
if [ -z "$LINE" ] ; then
|
|
echo "Unknow host $1"
|
|
exit 1
|
|
fi
|
|
|
|
# parse the CON_DB. The format is:
|
|
#
|
|
# <hostname>:<phone number>:<user id>:<password>:<local ip address>:\
|
|
# <remove_ip_address><netmask>:<pppd options>
|
|
#
|
|
# The last three are optional. But I would recomend specifying a netmask also
|
|
# when you specify a ip address.
|
|
|
|
IP_ADDR=""
|
|
IFS=':'
|
|
set $LINE
|
|
IFS=' '
|
|
HOST=$1
|
|
PHONE=$2
|
|
USER=$3
|
|
PASSWORD=$4
|
|
OUR_IP_ADDR=$5
|
|
THEIR_IP_ADDR=$6
|
|
NETMASK=$7
|
|
shift 7
|
|
OPTIONS=$*
|
|
|
|
if [ -f $LOCKFILE ] ; then
|
|
echo "PPP device is locked"
|
|
exit 1
|
|
else
|
|
|
|
# Lock the device
|
|
# faxd and UUCP wants 10 character lock id.
|
|
echo "$$" | awk '{printf("%10s",$0)}' > $LOCKFILE
|
|
fi
|
|
|
|
|
|
|
|
|
|
#Do we know our local ip address? If so pppd needs a : at the end of it.
|
|
if [ ! -z "$OUR_IP_ADDR" ] ; then
|
|
IP_ADDR=${OUR_IP_ADDR}:${THEIR_IP_ADDR}
|
|
fi
|
|
|
|
#Did we specify a netmask? If so convert to pppd format.
|
|
if [ ! -z "$NETMASK" ] ; then
|
|
NETMASK="netmask ${NETMASK}"
|
|
fi
|
|
|
|
# Do the actual work in a subshell so that we can turn off tostop and set
|
|
# the tty speed before chat dials. The second reason for doing in like
|
|
# is that if you aren't running BIDIR, and you are running faxd, clocal
|
|
# doesn't get turned on from pppd so chat will never work if you exec
|
|
# it from within pppd. I found that I needed to run uucp with the
|
|
# HAVE_CLOCAL_BUG flag set to 1 in order to get it to work in conjunction
|
|
# with faxd. Anyway, this setup seem to work.
|
|
(
|
|
|
|
stty $DEVICESPEED -tostop hupcl 2> /dev/null
|
|
|
|
# <LOCAL> Modify the Modem initialization strings to be whatever works for you
|
|
if chat -v ABORT "NO CARRIER" ABORT BUSY "" ATZ0E1 OK ATS50=255DT$PHONE \
|
|
CONNECT "" ogin: $USER ssword: \\q$PASSWORD
|
|
then
|
|
# We got connected.
|
|
/usr/libexec/pppd $DEBUG $OPTIONS -detach modem defaultroute \
|
|
crtscts $NETMASK $DEVICE $DEVICESPEED $IP_ADDR
|
|
|
|
else
|
|
echo "PPP call failed" 1>&2
|
|
exit 1
|
|
fi
|
|
) < /dev/$DEVICE > /dev/$DEVICE
|
|
# Get the return code from the subshell.
|
|
RC=$?
|
|
|
|
# Clear the lock. Slight window here where someone could detect that
|
|
# pppd is no longer running, remove its lock file and create its own.
|
|
# How to fix??
|
|
rm -f $LOCKFILE
|
|
|
|
#Pass on the exit code.
|
|
exit $RC
|