home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / mindlink.zip / mindlink.cmd next >
OS/2 REXX Batch file  |  1994-12-05  |  8KB  |  234 lines

  1. /* Mindlink Logon Script for OS/2 Warp Version 3 */
  2. /* Created: October 27, 1994                            */
  3. /* Tested: December 5, 1994                            */
  4.  
  5. /* ****************************************** */
  6. /* IMPORTANT: This script was tested using the dialer */
  7. /* settings outlined in MINDLINK.TXT. You should read that */
  8. /* file (should be in this zip) before attempting to */
  9. /* connect. */
  10. /* ****************************************** */
  11.  
  12.  
  13. parse arg interface , dialcmd username password modeminit
  14.  
  15. /*--------------------------------------------------------------------------*/
  16. /*                   Initialization and Main Script Code                    */
  17. /*--------------------------------------------------------------------------*/
  18.  
  19. /* Set some definitions for easier COM strings */
  20.  
  21. reset_modem='ATZ'
  22. init_modem='AT&F1'    /* This init string works with 99% of modems...only change if neccessary */
  23. hangup_modem='ATH'
  24.  
  25.  
  26. cr='0d'x
  27. crlf='0d0a'x
  28.  
  29.  
  30. 'route -fh'
  31.  
  32.  
  33. say ''
  34. say 'Mindlink Information Services - OS/2 Warp SLIP Script ',
  35.     '(interface' interface')'
  36.  
  37.  
  38. /* Flush any stuff left over from previous COM activity */
  39. call flush_receive
  40.  
  41. /* Reset the modem here */
  42. call lineout , 'Reset modem...'
  43. call send init_modem || cr
  44. call waitfor 'OK', 10 ; call flush_receive 'echo'
  45.  if RC = 1 then do
  46.     call lineout , 'Modem not resetting... Trying again'
  47.     call send '+++'
  48.     call waitfor 'OK'
  49.     call send hangup_modem || cr
  50.     call waitfor 'OK', 3
  51.   end
  52.  
  53. /* Dial the remote server */
  54. call charout , 'Now Dialing...'
  55.  
  56. /* Wait for connection */
  57. call send dialcmd || cr
  58. call waitfor 'CONNECT' ; call waitfor crlf
  59.  
  60. /* Handle login.  We wait for standard strings, and then flush anything */
  61. /* else to take care of trailing spaces, etc..                          */
  62. /* call send cr */
  63.  
  64. call waitfor 'key:' ; call flush_receive 'echo'
  65. call send cr
  66. call send cr
  67.  
  68. call waitfor 'service:' ; call flush_receive 'echo'
  69. call send 'slip' || cr
  70.  
  71. call waitfor 'login:' ; call flush_receive 'echo'
  72. call send username || cr
  73.  
  74. call waitfor 'password:'; call flush_receive 'echo'
  75. call send password || cr
  76.  
  77.  
  78. /* Parse the results of the SLIP command to determine our address. */
  79. /* We use the "waitfor_buffer" variable from the waitfor routine   */
  80. /* to parse the stuff we get from the Mindlink after waiting for an   */
  81. /* appropriate point in the data stream.                           */
  82. call waitfor '(deep' 
  83. parse var waitfor_buffer . 'You are connected to ' a '.' b '.' c '.' d .
  84. annex_address = a||'.'||b||'.'||c||'.'||d
  85.  
  86.  
  87. call waitfor 'Your address is'
  88.  
  89. call waitfor crlf 
  90. parse var waitfor_buffer  a '.' b '.' c '.' d . . .
  91. parse var d dd +2
  92. os2_address = a||'.'||b||'.'||c||'.'||dd
  93.  
  94. /* Flush anything else */
  95. call flush_receive 'echo'
  96.  
  97. /* Now configure this host for the appropriate address, */
  98. /* and for a default route through the Annex.           */
  99.  
  100. say 'SLIP Connection Established'
  101. say 'Configuring local address =' os2_address ', Annex =' annex_address
  102.  
  103. 'ifconfig sl0' os2_address annex_address 'netmask 255.255.255.0'
  104. 'route add default 'annex_address' 1'
  105.  
  106. /* All done */
  107. exit 0
  108.  
  109.  
  110. /*--------------------------------------------------------------------------*/
  111. /*                            send ( sendstring)                            */
  112. /*..........................................................................*/
  113. /*                                                                          */
  114. /* Routine to send a character string off to the modem.                     */
  115. /*                                                                          */
  116. /*--------------------------------------------------------------------------*/
  117.  
  118. send:
  119.  
  120.    parse arg sendstring
  121.    call slip_com_output interface , sendstring
  122.  
  123.    return
  124.  
  125.  
  126. /*--------------------------------------------------------------------------*/
  127. /*                    waitfor ( waitstring , [timeout] )                    */
  128. /*..........................................................................*/
  129. /*                                                                          */
  130. /* Waits for the supplied string to show up in the COM input.  All input    */
  131. /* from the time this function is called until the string shows up in the   */
  132. /* input is accumulated in the "waitfor_buffer" variable.                   */
  133. /*                                                                          */
  134. /* If timeout is specified, it says how long to wait if data stops showing  */
  135. /* up on the COM port (in seconds).                                                         */
  136. /*                                                                          */
  137. /*--------------------------------------------------------------------------*/
  138.  
  139. waitfor:
  140.  
  141.    parse arg waitstring , timeout
  142.  
  143.    if timeout = '' then
  144.      timeout = 5000    /* L O N G   delay if not specified */
  145.    waitfor_buffer = '' ; done = -1; curpos = 1
  146.    ORI_TIME=TIME('E')
  147.  
  148.    if (remain_buffer = 'REMAIN_BUFFER') then do
  149.       remain_buffer = ''
  150.    end
  151.  
  152.    do while (done = -1)
  153.       if (remain_buffer \= '') then do
  154.          line = remain_buffer
  155.          remain_buffer = ''
  156.        end
  157.        else do
  158.          line = slip_com_input(interface,,10)
  159.       end
  160.       waitfor_buffer = waitfor_buffer || line
  161.       index = pos(waitstring,waitfor_buffer)
  162.       if (index > 0) then do
  163.          remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  164.          waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  165.          done = 0
  166.       end
  167.       call charout , substr(waitfor_buffer,curpos)
  168.       curpos = length(waitfor_buffer)+1
  169.       if ((done \= 0) & (TIME('E')>timeout)) then do
  170.         call lineout , ' WAITFOR: timed out '
  171.         done = 1
  172.        end
  173.    end
  174.    timeout=0
  175.    RC=done
  176.  return RC
  177.  
  178.  
  179.  
  180. /*--------------------------------------------------------------------------*/
  181. /*                               readpass ()                                */
  182. /*..........................................................................*/
  183. /*                                                                          */
  184. /* Routine used to read a password from the user without echoing the        */
  185. /* password to the screen.                                                  */
  186. /*                                                                          */
  187. /*--------------------------------------------------------------------------*/
  188.  
  189. readpass:
  190.  
  191.   answer = ''
  192.   do until key = cr
  193.     key = slip_getch()
  194.     if key \= cr then do
  195.       answer = answer || key
  196.     end
  197.   end
  198.   say ''
  199.   return answer
  200.  
  201.  
  202. /*--------------------------------------------------------------------------*/
  203. /*                             flush_receive ()                             */
  204. /*..........................................................................*/
  205. /*                                                                          */
  206. /* Routine to flush any pending characters to be read from the COM port.    */
  207. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  208. /* point it returns.                                                        */
  209. /*                                                                          */
  210. /* The optional echo argument, if 1, says to echo flushed information.      */
  211. /*                                                                          */
  212. /*--------------------------------------------------------------------------*/
  213.  
  214. flush_receive:
  215.  
  216.    parse arg echo
  217.  
  218.    /* If echoing the flush - take care of waitfor remaining buffer */
  219.    if (echo \= '') & (length(remain_buffer) > 0) then do
  220.       call charout , remain_buffer
  221.       remain_buffer = ''
  222.    end
  223.  
  224.    /* Eat anything left in the modem or COM buffers */
  225.    /* Stop when nothing new appears for 100ms.      */
  226.  
  227.    do until line = ''
  228.      line = slip_com_input(interface,,100)
  229.      if echo \= '' then
  230.         call charout , line
  231.    end
  232.  
  233.    return
  234.