#!/com/sh
# Script to automate dialing and logging in procedures

#    Copyright 1995 Sentinet Ltd
#    All rights reserved.
#
#    Lyndon David and Tom Brock
#
#    Redistribution and use in any form are permitted provided that the
#    following restrictions are are met:
#	1.  Source distributions must retain this entire copyright notice
#	    and comment.
#	2.  Binary distributions must include the acknowledgement "This
#	    product includes software developed by Lyndon David" in the
#	    documentation or other materials provided with the
#	    distribution.  This must not be represented as an endorsement
#	    or promotion without specific prior written permission.
#	3.  The origin of this software must not be misrepresented, either
#	    by explicit claim or by omission.  Credits must appear in the
#	    source and documentation.
#	4.  Altered versions must be plainly marked as such in the source
#	    and documentation and must not be misrepresented as being the
#	    original software.
#    This software is provided "as is" and without any express or implied
#    warranties, including, without limitation, the implied warranties of
#    merchantability and fitness for a particular purpose.
#
#
#SCCS revision @(#)dial_script	2.1 5/20/95


args " " >> logfile
args

date>>logfile
date

send_waitfor /dev/sio1 3 ats30=6 OK | readln argument
if eqs ((^argument)) "No match" then
    hangup
    args "Error initial modem comms" >> logfile
    args "Error initial modem comms"
    return -f
else
    args "Comms with modem OK" >> logfile
    args "Comms with modem OK"
endif


send_waitfor /dev/sio1 60 "atdt<phone number>" login: BUSY "NO CARRIER" "ERROR" "NO ANSWER" "BLACKLISTED" "NO DIALTONE" | readln argument
if eqs ((^argument)) "login:" then
    args "Connected, Received login:" >> logfile
    args "Connected, Received login:"
else
    hangup
    args (("Error during connection: " + ^argument)) >> logfile
    args (("Error during connection: " + ^argument))
    return -f
endif

send_waitfor /dev/sio1 20 "sendstring" Password: "NO CARRIER" | readln argument
if eqs ((^argument)) "Password:" then
    args "           Received Password:" >> logfile
    args "           Received Password:"
else
    hangup
    args (("Error during connection: " + ^argument)) >> logfile
    args (("Error during connection: " + ^argument))
    return -f
endif


send_waitfor /dev/sio1 30 "password" Protocol: "NO CARRIER" | readln argument
if eqs ((^argument)) "Protocol:" then
    args "           Received Protocol:" >> logfile
    args "           Received Protocol:"
else
    hangup
    args (("Error during connection: " + ^argument)) >> logfile
    args (("Error during connection: " + ^argument))
    return -f
endif


send_waitfor /dev/sio1 30 "slip" HELLO "NO CARRIER" | readln argument
if eqs ((^argument)) "HELLO" then
    args (("           Received " + ^argument)) >> logfile
    args (("           Received " + ^argument))
else
    hangup
    args (("Error during connection: " + ^argument)) >> logfile
    args (("Error during connection: " + ^argument))
    return -f
endif

/etc/ifconfig sl0  my_ipaddr your_ipaddr
/etc/route add default default_gateway_ipaddr 1
        
#set the date and report

ntpdate -s -t 10 local_time_server_ipaddr &

# now sit and wait for the carrier to drop

#punt any waiting mail out to the net

/usr/lib/sendmail -q &

while dcd
    do
    /usr/bin/sleep 10
    enddo

/etc/route delete default gateway_ipaddr 1
/etc/ifconfig sl0 down


date>>logfile
date

