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