home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / internet / slipdail / !SLIPdial / Scripts / automagic next >
Encoding:
Text File  |  1995-02-16  |  10.0 KB  |  352 lines

  1. #slipdial
  2.  
  3. # Script to automatically dial Demon at 0100 every morning.
  4.  
  5. ############################################################
  6. # For this script to work correctly, two modem configuration
  7. # options are required, and a property of !TCPIP is assumed:
  8. #
  9. #  * The modem must make DCD follow the actual state of
  10. #    the carrier from the remote modem (i.e. it must NOT
  11. #    hold DCD high while on-line. On my Hayes compatible
  12. #    modem this is option &C1.
  13. #
  14. #  * The modem must hang up if on-line when DTR goes low.
  15. #    On my Hayes compatible modem this is option &D2.
  16. #
  17. #  * I assume all future version of !TCPIP will toggle
  18. #    DTR low when they exit.
  19. #
  20. # The script works as follows: when !TCPIP quits (either
  21. # manually or on a 'tcp hangup' timeout), it pulls DTR
  22. # low. The modem hangs up (&D2). Then, since there is no
  23. # longer a remote carrier present, DCD goes low (&C1).
  24. # The script has a DCD alarm, which calls the dcd_drop
  25. # function and eventually the hangup function.
  26. #
  27. # DCD can also go low (the carrier can also be dropped)
  28. # due to line noise or Demon hanging up.
  29. #
  30. # Since the hangup function can also get called on an
  31. # on-line timeout timer (see later), it kills !TCPIP.
  32. #
  33. # So - call termination (dropped carrier, !TCPIP exiting,
  34. # or on-line timeout) will always result in the modem being
  35. # placed back on-hook, and !TCPIP being killed.
  36. ############################################################
  37.  
  38. # Configure and build user menu.
  39. call configure
  40. call makemenus
  41.  
  42. # Setup serial port
  43. driver USR
  44. port %wport %prtnum
  45. speed %speed
  46. set protocol slip
  47.  
  48. # Define the phone number
  49. set phonenum 01132984848
  50.  
  51. # Setup an alarm for automatic dialing
  52. alarm /repeat /time=01:00 /id=everyday "call demon"
  53.  
  54. # Do absolutely nothing until the alarm triggers
  55. # or a menu selection is made
  56. :loop
  57. message /close
  58. wait /event
  59. goto loop
  60. exit
  61.  
  62. ############################################################
  63. # The following 5 functions are called from the user menu
  64. # or by a timer. Each defines nntp and smtp. These are
  65. # values substituted into the !TCPIP startup script. Hence
  66. # the :domail function defines 'nntp' to be '#nntp' since
  67. # it wishes to comment out all the nntp configuration in
  68. # the AutoExec script.
  69. ############################################################
  70.  
  71. ############################################################
  72. # Call Demon (this is automatically triggered
  73. #
  74. # It sets 'timed' to 'yes' for various timers to be set.
  75. # Call Demon, and jump to the 'loggedin' routine.
  76. ############################################################
  77. :demon
  78. set timed yes
  79. set nntp nntp
  80. set smtp smtp
  81. call dialup
  82. goto loggedin
  83.  
  84. ############################################################
  85. # A mail download
  86. #
  87. # Call Demon, and jump to the 'loggedin' routine.
  88. ############################################################
  89. :domail
  90. set timed yes
  91. set nntp #nntp
  92. set smtp smtp
  93. call dialup
  94. goto loggedin
  95.  
  96. ############################################################
  97. # A news download
  98. #
  99. # Call Demon, and jump to the 'loggedin' routine.
  100. ############################################################
  101. :donews
  102. set timed no
  103. set nntp nntp
  104. set smtp #smtp
  105. call dialup
  106. goto loggedin
  107.  
  108. ############################################################
  109. # News and mail
  110. #
  111. # Call Demon, and jump to the 'loggedin' routine.
  112. ############################################################
  113. :doboth
  114. set timed no
  115. set nntp nntp
  116. set smtp smtp
  117. call dialup
  118. goto loggedin
  119.  
  120. ############################################################
  121. # Interactive session
  122. #
  123. # Call Demon, and jump to the 'loggedin' routine.
  124. ############################################################
  125. :interact
  126. set timed no
  127. set nntp #nntp
  128. set smtp #smtp
  129. call dialup
  130. goto loggedin
  131.  
  132. ############################################################
  133. # Dial Demon.
  134. #
  135. # Create an AutoExec file for !TCPIP, claim and initialise
  136. # the modem. Dial Demon. Login and set protocol. Capture
  137. # and display MOTD. Wait for Demon to setup their SLIP
  138. # service.
  139. ############################################################
  140. :dialup
  141.  
  142. # The call hasn't failed (yet!)
  143. set failed no
  144.  
  145. # See below...
  146. set waittime 4
  147. set starttime 0
  148. set stoptime 0
  149.  
  150. # Create a !TCPIP AutoExec file
  151. make <TCPIP$Dir>.AutoTempl <TCPIP$Dir>.AutoExec
  152.  
  153. # Claim and initialise the modem
  154. if (!claim 3) goto call_failed
  155. message /close
  156. init ATZ
  157. sleep 2
  158. send ATQ0V1M0
  159. if (!wait /del=5 OK) goto call_failed
  160.  
  161. # Try to dial Demon
  162. retry 50 15
  163. if (!dial /nodial=30 /nocar=10 /busy=5 %phonenum) call call_failed
  164.  
  165. # Successful connect. Login
  166. if (!wait /del=20 ogin:) goto call_failed
  167. send %nodename
  168.  
  169. # Send password. Also remember current time
  170. set starttime %$time
  171. if (!wait /del=20 word:) goto call_failed
  172. send %password
  173.  
  174. # Send protocol.
  175. if (!wait /del=50 ocol:) goto call_failed
  176. send %protocol
  177.  
  178. # Get current time. Work out difference between now and when we
  179. # had just sent our nodename. Halve it. Wait that long after the
  180. # MOTD. This is intended to give a rough idea of speed the Demon
  181. # machines are running at - i.e. the longer it takes to log on,
  182. # the longer we have to wait before the SLIP service is running.
  183. set stoptime %$time
  184. set waittime {eval "%stoptime-%starttime"}
  185. set waittime {eval "%waittime DIV 2"}
  186. if (?eq %waittime 0) set waittime 1
  187.  
  188. # Get MOTD, and IP address
  189. message /capture="IP" /end="HELLO" /maxlines=9 /centre
  190. ipget 158.
  191. if (!wait /del=30 HELLO) goto call_failed
  192. wait /delay=%waittime "a while"
  193. return 1
  194.  
  195. ############################################################
  196. # Call setup failed.
  197. #
  198. #  * Couldn't claim device
  199. #  * Couldn't initialise modem
  200. #  * Couldn't get an answer
  201. #  * Timed out during login
  202. #  * Timed out waiting for MOTD
  203. #
  204. # Mark the call as failed, inform the user and release
  205. # the device.
  206. ############################################################
  207. :call_failed
  208. set failed yes
  209. message "Call setup failed" /centre
  210. release
  211. return 0
  212.  
  213. ############################################################
  214. # Successfully logged in.
  215. # (Not strictly true -- will arrive here from call_failed
  216. # too. Therefore check %failed and return).
  217. ############################################################
  218. :loggedin
  219. if (?eq %failed yes) return 1
  220.  
  221. # Set an alarm if this call is timed. This is so that we don't
  222. # spend too long on-line unattended. :)
  223. if (?eq %timed yes) alarm /time=+00:00:20 /id=timeout "goto hangup"
  224.  
  225. # Fire up !TCPIP
  226. task /name="TCP/IP" <TCPIP2$dir>.!Run
  227.  
  228. # Watch for DCD to drop (i.e. the modem has hung up).
  229. alarm /dcd "goto dcd_drop"
  230.  
  231. # Wait for a hangup. This loop terminates on the timeout alarm
  232. # (if set) or the DCD alarm.
  233. :hupwait
  234. message /close
  235. wait /event
  236. goto hupwait
  237.  
  238. ############################################################
  239. # DCD has dropped.
  240. #
  241. # Cancel the timeout alarm (if it exists).
  242. ############################################################
  243. :dcd_drop
  244. alarm /cancel=timeout
  245. goto hangup
  246.  
  247. ############################################################
  248. # Hangup the line
  249. #
  250. # Arrive here after a DCD drop (or a timeout alarm). Kill
  251. # !TCPIP (if it's not already dead!). Inform the user of
  252. # a successful finish. Release the serial device. Wait a
  253. # couple of seconds for RISC OS to sort its life out.
  254. # Compute a news transfer rate (if any news arrived).
  255. # Optionally start TTFN and Newsbase (see later). Trim
  256. # the DemHist file, and return.
  257. ############################################################
  258. :hangup
  259.  
  260. # Kill !TCPIP
  261. task /kill="TCP/IP"
  262.  
  263. # Inform the user
  264. message "Call finished successfully" /centre
  265.  
  266. # Release the serial line and let RISC OS sort itself.
  267. release
  268. pause 2
  269.  
  270. # Compute news rate (if any arrived!)
  271. set newsExists {?file <Mail$Dir>.folder.DemNews}
  272. case %newsExists
  273. when 1 2 3; set nrate {newsrate Dem}; message "news rate %nrate cps" /centre
  274. when 0; message "no news downloaded" /centre
  275. endcase
  276. unset newsExists
  277. unset nrate
  278.  
  279. # Optionally fire up !TTFN and !Newsbase
  280. # Neither are started if this was a timed call.
  281. # Each is only started only if it is not already running.
  282. if (!?eq %timed yes) if (!?task TTFN) task /name="TTFN" <TTFN$Dir>.!Run
  283. if (!?eq %timed yes) if (!?task Newsbase) task /name="Newsbase" <NewsBase$Dir>.!Run
  284.  
  285. # Trim the DemHist file and return
  286. call trimfile <NNTP$Dir>.DemHist
  287. return 1
  288.  
  289. ############################################################
  290. # Trim a file
  291. #
  292. # Time the file in %p1 by checking if it is 5000 bytes or
  293. # longer. This is achieved by copying the last 200 lines
  294. # into a temporary file and then moving the temorary file
  295. # over the original.
  296. ############################################################
  297. :trimfile
  298. if (?lt {?file/size %p1} 5000) return
  299. copy/tail=200 %p1 %p1-T;delete %p1;move %p1-T %p1
  300. return 1
  301.  
  302. ############################################################
  303. # Configuration
  304. #
  305. # Read the system configuration information or call setup
  306. # if a config file doesn't exist
  307. ############################################################
  308. :configure
  309. set filename {?file/expand slipdial:demonconfg}
  310. if (!?file %filename) call setup
  311. open/read/id=conf/error="return" %filename
  312. read/id=conf/eof="goto closeconf" wport
  313. read/id=conf/eof="goto closeconf" prtnum
  314. read/id=conf/eof="goto closeconf" speed
  315. read/id=conf/eof="goto closeconf" nodename
  316. read/id=conf/eof="goto closeconf" password
  317. read/id=conf/eof="goto closeconf" mercury
  318. :closeconf
  319. close/id=conf
  320. return
  321.  
  322. ############################################################
  323. # Setup
  324. #
  325. # Ask the user for various parameters (note that this
  326. # script doesn't use the mercury information
  327. ############################################################
  328. :setup
  329. input/prompt="Enter Serial Block Driver Name" wport
  330. input/prompt="Enter Serial Port Number (if relevant)" prtnum
  331. input/prompt="Enter Your Modem->Computer Speed (bps):" speed
  332. input/prompt="Enter Your Demon Nodename:" nodename
  333. input/prompt="Enter Your Password:" password
  334. input/prompt="Enter Your Mercury PIN:" mercury
  335. open/id=conf/write %filename
  336. write/id=conf %wport
  337. write/id=conf %prtnum
  338. write/id=conf %speed
  339. write/id=conf %nodename
  340. write/id=conf %password
  341. write/id=conf %mercury
  342. close/id=conf
  343. return 1
  344.  
  345. ############################################################
  346. # Make menus
  347. ############################################################
  348. :makemenus
  349. menu "Mail:call domail" "News:call donews" "Both:call doboth" "Interactive:call interact" "Quit:quit"
  350. return 1
  351.