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

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