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

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