home *** CD-ROM | disk | FTP | other *** search
- #slipdial
-
- # Script to automatically dial Demon at 0100 every morning.
-
- ############################################################
- # For this script to work correctly, two modem configuration
- # options are required, and a property of !TCPIP is assumed:
- #
- # * The modem must make DCD follow the actual state of
- # the carrier from the remote modem (i.e. it must NOT
- # hold DCD high while on-line. On my Hayes compatible
- # modem this is option &C1.
- #
- # * The modem must hang up if on-line when DTR goes low.
- # On my Hayes compatible modem this is option &D2.
- #
- # * I assume all future version of !TCPIP will toggle
- # DTR low when they exit.
- #
- # The script works as follows: when !TCPIP quits (either
- # manually or on a 'tcp hangup' timeout), it pulls DTR
- # low. The modem hangs up (&D2). Then, since there is no
- # longer a remote carrier present, DCD goes low (&C1).
- # The script has a DCD alarm, which calls the dcd_drop
- # function and eventually the hangup function.
- #
- # DCD can also go low (the carrier can also be dropped)
- # due to line noise or Demon hanging up.
- #
- # Since the hangup function can also get called on an
- # on-line timeout timer (see later), it kills !TCPIP.
- #
- # So - call termination (dropped carrier, !TCPIP exiting,
- # or on-line timeout) will always result in the modem being
- # placed back on-hook, and !TCPIP being killed.
- ############################################################
-
- # Configure and build user menu.
- call configure
- call makemenus
-
- # Setup serial port
- driver USR
- port %wport %prtnum
- speed %speed
- set protocol slip
-
- # Define the phone number
- set phonenum 01132984848
-
- # Setup an alarm for automatic dialing
- alarm /repeat /time=01:00 /id=everyday "call demon"
-
- # Do absolutely nothing until the alarm triggers
- # or a menu selection is made
- :loop
- message /close
- wait /event
- goto loop
- exit
-
- ############################################################
- # The following 5 functions are called from the user menu
- # or by a timer. Each defines nntp and smtp. These are
- # values substituted into the !TCPIP startup script. Hence
- # the :domail function defines 'nntp' to be '#nntp' since
- # it wishes to comment out all the nntp configuration in
- # the AutoExec script.
- ############################################################
-
- ############################################################
- # Call Demon (this is automatically triggered
- #
- # It sets 'timed' to 'yes' for various timers to be set.
- # Call Demon, and jump to the 'loggedin' routine.
- ############################################################
- :demon
- set timed yes
- set nntp nntp
- set smtp smtp
- call dialup
- goto loggedin
-
- ############################################################
- # A mail download
- #
- # Call Demon, and jump to the 'loggedin' routine.
- ############################################################
- :domail
- set timed yes
- set nntp #nntp
- set smtp smtp
- call dialup
- goto loggedin
-
- ############################################################
- # A news download
- #
- # Call Demon, and jump to the 'loggedin' routine.
- ############################################################
- :donews
- set timed no
- set nntp nntp
- set smtp #smtp
- call dialup
- goto loggedin
-
- ############################################################
- # News and mail
- #
- # Call Demon, and jump to the 'loggedin' routine.
- ############################################################
- :doboth
- set timed no
- set nntp nntp
- set smtp smtp
- call dialup
- goto loggedin
-
- ############################################################
- # Interactive session
- #
- # Call Demon, and jump to the 'loggedin' routine.
- ############################################################
- :interact
- set timed no
- set nntp #nntp
- set smtp #smtp
- call dialup
- goto loggedin
-
- ############################################################
- # Dial Demon.
- #
- # Create an AutoExec file for !TCPIP, claim and initialise
- # the modem. Dial Demon. Login and set protocol. Capture
- # and display MOTD. Wait for Demon to setup their SLIP
- # service.
- ############################################################
- :dialup
-
- # The call hasn't failed (yet!)
- set failed no
-
- # See below...
- set waittime 4
- set starttime 0
- set stoptime 0
-
- # Create a !TCPIP AutoExec file
- make <TCPIP$Dir>.AutoTempl <TCPIP$Dir>.AutoExec
-
- # Claim and initialise the modem
- if (!claim 3) goto call_failed
- message /close
- init ATZ
- sleep 2
- send ATQ0V1M0
- if (!wait /del=5 OK) goto call_failed
-
- # Try to dial Demon
- retry 50 15
- if (!dial /nodial=30 /nocar=10 /busy=5 %phonenum) call call_failed
-
- # Successful connect. Login
- if (!wait /del=20 ogin:) goto call_failed
- send %nodename
-
- # Send password. Also remember current time
- set starttime %$time
- if (!wait /del=20 word:) goto call_failed
- send %password
-
- # Send protocol.
- if (!wait /del=50 ocol:) goto call_failed
- send %protocol
-
- # Get current time. Work out difference between now and when we
- # had just sent our nodename. Halve it. Wait that long after the
- # MOTD. This is intended to give a rough idea of speed the Demon
- # machines are running at - i.e. the longer it takes to log on,
- # the longer we have to wait before the SLIP service is running.
- set stoptime %$time
- set waittime {eval "%stoptime-%starttime"}
- set waittime {eval "%waittime DIV 2"}
- if (?eq %waittime 0) set waittime 1
-
- # Get MOTD, and IP address
- message /capture="IP" /end="HELLO" /maxlines=9 /centre
- ipget 158.
- if (!wait /del=30 HELLO) goto call_failed
- wait /delay=%waittime "a while"
- return 1
-
- ############################################################
- # Call setup failed.
- #
- # * Couldn't claim device
- # * Couldn't initialise modem
- # * Couldn't get an answer
- # * Timed out during login
- # * Timed out waiting for MOTD
- #
- # Mark the call as failed, inform the user and release
- # the device.
- ############################################################
- :call_failed
- set failed yes
- message "Call setup failed" /centre
- release
- return 0
-
- ############################################################
- # Successfully logged in.
- #
- # (Not strictly true -- will arrive here from call_failed
- # too. Therefore check %failed and return).
- ############################################################
- :loggedin
- if (?eq %failed yes) return 1
-
- # Set an alarm if this call is timed. This is so that we don't
- # spend too long on-line unattended. :)
- if (?eq %timed yes) alarm /time=+00:00:20 /id=timeout "goto hangup"
-
- # Fire up !TCPIP
- task /name="TCP/IP" <TCPIP2$dir>.!Run
-
- # Watch for DCD to drop (i.e. the modem has hung up).
- alarm /dcd "goto dcd_drop"
-
- # Wait for a hangup. This loop terminates on the timeout alarm
- # (if set) or the DCD alarm.
- :hupwait
- message /close
- wait /event
- goto hupwait
-
- ############################################################
- # DCD has dropped.
- #
- # Cancel the timeout alarm (if it exists).
- ############################################################
- :dcd_drop
- alarm /cancel=timeout
- goto hangup
-
- ############################################################
- # Hangup the line
- #
- # Arrive here after a DCD drop (or a timeout alarm). Kill
- # !TCPIP (if it's not already dead!). Inform the user of
- # a successful finish. Release the serial device. Wait a
- # couple of seconds for RISC OS to sort its life out.
- # Compute a news transfer rate (if any news arrived).
- # Optionally start TTFN and Newsbase (see later). Trim
- # the DemHist file, and return.
- ############################################################
- :hangup
-
- # Kill !TCPIP
- task /kill="TCP/IP"
-
- # Inform the user
- message "Call finished successfully" /centre
-
- # Release the serial line and let RISC OS sort itself.
- release
- pause 2
-
- # Compute news rate (if any arrived!)
- set newsExists {?file <Mail$Dir>.folder.DemNews}
- case %newsExists
- when 1 2 3; set nrate {newsrate Dem}; message "news rate %nrate cps" /centre
- when 0; message "no news downloaded" /centre
- endcase
- unset newsExists
- unset nrate
-
- # Optionally fire up !TTFN and !Newsbase
- # Neither are started if this was a timed call.
- # Each is only started only if it is not already running.
- if (!?eq %timed yes) if (!?task TTFN) task /name="TTFN" <TTFN$Dir>.!Run
- if (!?eq %timed yes) if (!?task Newsbase) task /name="Newsbase" <NewsBase$Dir>.!Run
-
- # Trim the DemHist file and return
- call trimfile <NNTP$Dir>.DemHist
- return 1
-
- ############################################################
- # Trim a file
- #
- # Time the file in %p1 by checking if it is 5000 bytes or
- # longer. This is achieved by copying the last 200 lines
- # into a temporary file and then moving the temorary file
- # over the original.
- ############################################################
- :trimfile
- if (?lt {?file/size %p1} 5000) return
- copy/tail=200 %p1 %p1-T;delete %p1;move %p1-T %p1
- return 1
-
- ############################################################
- # Configuration
- #
- # Read the system configuration information or call setup
- # if a config file doesn't exist
- ############################################################
- :configure
- set filename {?file/expand slipdial:demonconfg}
- if (!?file %filename) call setup
- open/read/id=conf/error="return" %filename
- read/id=conf/eof="goto closeconf" wport
- read/id=conf/eof="goto closeconf" prtnum
- read/id=conf/eof="goto closeconf" speed
- read/id=conf/eof="goto closeconf" nodename
- read/id=conf/eof="goto closeconf" password
- read/id=conf/eof="goto closeconf" mercury
- :closeconf
- close/id=conf
- return
-
- ############################################################
- # Setup
- #
- # Ask the user for various parameters (note that this
- # script doesn't use the mercury information
- ############################################################
- :setup
- input/prompt="Enter Serial Block Driver Name" wport
- input/prompt="Enter Serial Port Number (if relevant)" prtnum
- input/prompt="Enter Your Modem->Computer Speed (bps):" speed
- input/prompt="Enter Your Demon Nodename:" nodename
- input/prompt="Enter Your Password:" password
- input/prompt="Enter Your Mercury PIN:" mercury
- open/id=conf/write %filename
- write/id=conf %wport
- write/id=conf %prtnum
- write/id=conf %speed
- write/id=conf %nodename
- write/id=conf %password
- write/id=conf %mercury
- close/id=conf
- return 1
-
- ############################################################
- # Make menus
- ############################################################
- :makemenus
- menu "Mail:call domail" "News:call donews" "Both:call doboth" "Interactive:call interact" "Quit:quit"
- return 1
-