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

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