home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / umr.cmd < prev    next >
OS/2 REXX Batch file  |  1994-12-19  |  7KB  |  190 lines

  1.  
  2. parse arg interface , dialcmd username password
  3.  
  4. /*--------------------------------------------------------------------------*/
  5. /*                   Initialization and Main Script Code                    */
  6. /*--------------------------------------------------------------------------*/
  7.  
  8. /* Set some definitions for easier COM strings */
  9. cr='0d'x
  10. crlf='0d0a'x
  11. 'mode com1 19200,n,8,1,buffer=on,dtr=on,rts=hs'
  12. dialcmd='ATDT341-6188'
  13. username='place your email address within the quotes'
  14. password='and your password within the quotes'
  15. say ''
  16. say 'ANNEX - SLIP ANNEX Rolla Example Connection Script ',
  17.     '(interface' interface')'
  18.  
  19. /* Flush any stuff left over from previous COM activity */
  20. call flush_receive
  21.  
  22. /* Reset the modem here */
  23. /* You may need to customize this for your modem make and model */
  24. call lineout , 'Reset modem...'
  25. call send 'ATZ' || cr
  26. call send 'ATZ' || cr
  27. call send 'ATZ' || cr
  28. call send 'ATZ' || cr
  29.  
  30. call waitfor 'OK', 5 ; call flush_receive 'echo'
  31.  if RC = 1 then do
  32.     call lineout , 'Modem not resetting... Trying again'
  33.     call send '+++'
  34.     call waitfor 'OK'
  35.     call send 'ATHZ' || cr
  36.     call waitfor 'OK', 3
  37.   end
  38.  
  39. /* Dial the remote server */
  40. call charout , 'Now Dialing...'
  41. call send 'ATDT341-6188'|| cr
  42. /* Wait for connection */
  43. /*call send dialcmd || cr*/
  44. call waitfor 'CONNECT' ; call waitfor crlf
  45.  
  46. /* Handle login.  We wait for standard strings, and then flush anything */
  47. /* else to take care of trailing spaces, etc..                          */
  48. /* call send cr */
  49.  
  50. call waitfor 'Username:' ; call flush_receive 'echo'
  51. call send username || cr
  52. call waitfor 'Password:' ; call flush_receive 'echo'
  53. call send password || cr
  54. call waitfor '>' ; call flush_receive 'echo'
  55. call send 'SLIP' || cr
  56.  
  57.  
  58. /* Parse the results of the SLIP command to determine our address. */
  59. /* We use the "waitfor_buffer" variable from the waitfor routine   */
  60. /* to parse the stuff we get from the Annex after waiting for an   */
  61. /* appropriate point in the data stream.                           */
  62.  
  63. call waitfor 'Your IP address is' 
  64. parse var waitfor_buffer . 'Annex address is' a '.' b '.' c '.' d '.' .
  65. annex_address = a||'.'||b||'.'||c||'.'||d
  66.  
  67.  
  68. call waitfor crlf 
  69. parse var waitfor_buffer  a '.' b '.' c '.' d '.' .
  70. os2_address = a||'.'||b||'.'||c||'.'||d
  71.  
  72. /* Flush anything else */
  73. call flush_receive 'echo'
  74.  
  75. /* Now configure this host for the appropriate address, */
  76. /* and for a default route through the Annex.           */
  77.  
  78. say 'SLIP Connection Established'
  79. say 'Configuring local address =' os2_address ', Annex =' annex_address
  80.  
  81. 'ifconfig sl0' os2_address annex_address 'netmask 255.255.255.0'
  82. 'route add default' annex_address '1'
  83.  
  84. /* All done */
  85. exit 0
  86.  
  87.  
  88. /*--------------------------------------------------------------------------*/
  89. /*                            send ( sendstring)                            */
  90. /*..........................................................................*/
  91. /*                                                                          */
  92. /* Routine to send a character string off to the modem.                     */
  93. /*                                                                          */
  94. /*--------------------------------------------------------------------------*/
  95.  
  96. send:
  97.  
  98.    parse arg sendstring
  99.    call slip_com_output interface , sendstring
  100.  
  101.    return
  102.  
  103.  
  104. /*--------------------------------------------------------------------------*/
  105. /*                    waitfor ( waitstring , [timeout] )                    */
  106. /*..........................................................................*/
  107. /*                                                                          */
  108. /* Waits for the supplied string to show up in the COM input.  All input    */
  109. /* from the time this function is called until the string shows up in the   */
  110. /* input is accumulated in the "waitfor_buffer" variable.                   */
  111. /*                                                                          */
  112. /* If timeout is specified, it says how long to wait if data stops showing  */
  113. /* up on the COM port (in seconds).                                                         */
  114. /*                                                                          */
  115. /*--------------------------------------------------------------------------*/
  116.  
  117. waitfor:
  118.  
  119.    parse arg waitstring , timeout
  120.  
  121.    if timeout = '' then
  122.      timeout = 5000    /* L O N G   delay if not specified */
  123.    waitfor_buffer = '' ; done = -1; curpos = 1
  124.    ORI_TIME=TIME('E')
  125.  
  126.    if (remain_buffer = 'REMAIN_BUFFER') then do
  127.       remain_buffer = ''
  128.    end
  129.  
  130.    do while (done = -1)
  131.       if (remain_buffer \= '') then do
  132.          line = remain_buffer
  133.          remain_buffer = ''
  134.        end
  135.        else do
  136.          line = slip_com_input(interface,,10)
  137.       end
  138.       waitfor_buffer = waitfor_buffer || line
  139.       index = pos(waitstring,waitfor_buffer)
  140.       if (index > 0) then do
  141.          remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  142.          waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  143.          done = 0
  144.       end
  145.       call charout , substr(waitfor_buffer,curpos)
  146.       curpos = length(waitfor_buffer)+1
  147.       if ((done \= 0) & (TIME('E')>timeout)) then do
  148.         call lineout , ' WAITFOR: timed out '
  149.         done = 1
  150.        end
  151.    end
  152.    timeout=0
  153.    RC=done
  154.  return RC
  155.  
  156.  
  157.  
  158. /*--------------------------------------------------------------------------*/
  159. /*                             flush_receive ()                             */
  160. /*..........................................................................*/
  161. /*                                                                          */
  162. /* Routine to flush any pending characters to be read from the COM port.    */
  163. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  164. /* point it returns.                                                        */
  165. /*                                                                          */
  166. /* The optional echo argument, if 1, says to echo flushed information.      */
  167. /*                                                                          */
  168. /*--------------------------------------------------------------------------*/
  169.  
  170. flush_receive:
  171.  
  172.    parse arg echo
  173.  
  174.    /* If echoing the flush - take care of waitfor remaining buffer */
  175.    if (echo \= '') & (length(remain_buffer) > 0) then do
  176.       call charout , remain_buffer
  177.       remain_buffer = ''
  178.    end
  179.  
  180.    /* Eat anything left in the modem or COM buffers */
  181.    /* Stop when nothing new appears for 100ms.      */
  182.  
  183.    do until line = ''
  184.      line = slip_com_input(interface,,100)
  185.      if echo \= '' then
  186.         call charout , line
  187.    end
  188.  
  189.    return
  190.