home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / DATACOM / INTERNET / WARPIAK / PPP.ZIP / BIN / ANNEX.CMD next >
OS/2 REXX Batch file  |  1994-08-25  |  11KB  |  254 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                OS/2 2.0 REX Driver for IBM TCP/IP version 2.0           */
  4. /*                                                                          */
  5. /*                                ANNEX.CMD                                 */
  6. /*                                                                          */
  7. /*            ..................................................            */
  8. /*                                                                          */
  9. /* Sample attachment script for dialing into a Xylogics Annex terminal      */
  10. /* server in order to establish a SLIP connection.  This script should be   */
  11. /* specified on page 1 in the Login Script field for connections via SlipPM */
  12. /* or using the -connect option if executing slip directly.                 */
  13. /*                                                                          */
  14. /* The script parameters specify the command to send to the modem to dial   */
  15. /* the remote site and the username/password combination to use to log into */
  16. /* the terminal server.  If any of the parameters are omitted, or are       */
  17. /* specified as an asterix (*), the script will prompt for them.  This is   */
  18. /* most useful with the password parameter to avoid storing the password    */
  19. /* in a text file on the disk.                                              */
  20. /*                                                                          */
  21. /* For example, the following might be used in SlipPM:                      */
  22. /*              Login Script: annex.cmd atdt999-9999 loginid  *             */
  23. /*                                                                          */
  24. /* or from slip directly:                                                   */
  25. /*              -connect "annex.cmd atdt999-9999 loginid *"                 */
  26. /*                                                                          */
  27. /* which would cause annex.cmd to initially prompt for the password. It     */
  28. /* would then feed the "atdt999-9999" command to the modem, and when the    */
  29. /* Annex answered, it would use "loginid" as a username and the password    */
  30. /* specified.                                                               */
  31. /*                                                                          */
  32. /*            - - - - - - - - - - - - - - - - - - - - - - - - -             */
  33. /*                                                                          */
  34. /* When the script runs, it is automatically passed the interface name for  */
  35. /* the interface it is running on as the first argument, followed by the    */
  36. /* user arguments.                                                          */
  37. /*                                                                          */
  38. /* The script sends the dial string to the modem and then logs into the     */
  39. /* terminal server using the username/password.  It then issues the SLIP    */
  40. /* command to start SLIP, and parses the resulting output to determine the  */
  41. /* appropriate addresses to use.  Lastly, it issues ifconfig and route      */
  42. /* commands to configure the OS/2 system appropriately.  Note that the      */
  43. /* configuration assumes a class C netmask for the SLIP interface.          */
  44. /*                                                                          */
  45. /*--------------------------------------------------------------------------*/
  46.  
  47. parse arg interface , dialcmd username password
  48.  
  49. /*--------------------------------------------------------------------------*/
  50. /*                   Initialization and Main Script Code                    */
  51. /*--------------------------------------------------------------------------*/
  52.  
  53. /* Set some definitions for easier COM strings */
  54. cr='0d'x
  55. crlf='0d0a'x
  56.  
  57. say ''
  58. say 'ANNEX - SLIP ANNEX Server Connection Script ',
  59.     '(interface' interface')'
  60.  
  61. /* Prompt for missing information */
  62. if dialcmd = '' then do
  63.    call charout , 'Dial Command: '
  64.    parse pull dialcmd
  65. end
  66. if username = '' | username = '*' then do
  67.    call charout , 'User Name: '
  68.    parse pull username
  69. end
  70. else do
  71.    say 'User:' username
  72. end
  73. if password = '' | password = '*' then do
  74.    call charout , 'Password: '
  75.    password = readpass()
  76. end
  77.  
  78. /* Flush any stuff left over from previous COM activity */
  79. call flush_receive
  80.  
  81. /* Dial the remote server */
  82. call charout , 'Now Dialing...'
  83.  
  84. /* Wait for connection */
  85. call send dialcmd || cr
  86. call waitfor 'CONNECT' ; call waitfor crlf
  87.  
  88. /* Handle login.  We wait for standard strings, and then flush anything */
  89. /* else to take care of trailing spaces, etc..                          */
  90. call send cr
  91. call waitfor 'Username:' ; call flush_receive 'echo'
  92. call send username || cr
  93. call waitfor 'Password:' ; call flush_receive 'echo'
  94. call send password || cr
  95.  
  96. /* Wait for the main prompt and then send the "slip" command */
  97. call waitfor 'Annex:' ; call flush_receive 'echo'
  98. call send 'slip' || cr
  99.  
  100. /* Parse the results of the SLIP command to determine our address. */
  101. /* We use the "waitfor_buffer" variable from the waitfor routine   */
  102. /* to parse the stuff we get from the Annex after waiting for an   */
  103. /* appropriate point in the data stream.                           */
  104. call waitfor 'Your address is'
  105. parse var waitfor_buffer . 'Annex address is' a '.' b '.' c '.' d '.' .
  106. annex_address = a||'.'||b||'.'||c||'.'||d
  107.  
  108. /* Now parse the remainder for our address */
  109.  
  110. call waitfor crlf
  111. parse var waitfor_buffer a '.' b '.' c '.' d '.' .
  112. os2_address = a||'.'||b||'.'||c||'.'||d
  113.  
  114. /* Flush anything else */
  115. call flush_receive 'echo'
  116.  
  117. /* Now configure this host for the appropriate address, */
  118. /* and for a default route through the Annex.           */
  119.  
  120. say 'SLIP Connection Established'
  121. say 'Configuring local address =' os2_address ', Annex =' annex_address
  122.  
  123. 'ifconfig sl0' os2_address annex_address 'netmask 255.255.255.0'
  124. 'route add default' annex_address '1'
  125.  
  126. /* All done */
  127. exit 0
  128.  
  129.  
  130. /*--------------------------------------------------------------------------*/
  131. /*                            send ( sendstring)                            */
  132. /*..........................................................................*/
  133. /*                                                                          */
  134. /* Routine to send a character string off to the modem.                     */
  135. /*                                                                          */
  136. /*--------------------------------------------------------------------------*/
  137.  
  138. send:
  139.  
  140.    parse arg sendstring
  141.    call slip_com_output interface , sendstring
  142.  
  143.    return
  144.  
  145.  
  146. /*--------------------------------------------------------------------------*/
  147. /*                    waitfor ( waitstring , [timeout] )                    */
  148. /*..........................................................................*/
  149. /*                                                                          */
  150. /* Waits for the supplied string to show up in the COM input.  All input    */
  151. /* from the time this function is called until the string shows up in the   */
  152. /* input is accumulated in the "waitfor_buffer" variable.                   */
  153. /*                                                                          */
  154. /* If timeout is specified, it says how long to wait if data stops showing  */
  155. /* up on the COM port (in seconds).                                                         */
  156. /*                                                                          */
  157. /*--------------------------------------------------------------------------*/
  158.  
  159. waitfor:
  160.  
  161.    parse arg waitstring , timeout
  162.  
  163.    if timeout = '' then
  164.      timeout = 5000    /* L O N G   delay if not specified */
  165.    waitfor_buffer = '' ; done = -1; curpos = 1
  166.    ORI_TIME=TIME('E')
  167.  
  168.    if (remain_buffer = 'REMAIN_BUFFER') then do
  169.       remain_buffer = ''
  170.    end
  171.  
  172.    do while (done = -1)
  173.       if (remain_buffer \= '') then do
  174.          line = remain_buffer
  175.          remain_buffer = ''
  176.        end
  177.        else do
  178.          line = slip_com_input(interface,,10)
  179.       end
  180.       waitfor_buffer = waitfor_buffer || line
  181.       index = pos(waitstring,waitfor_buffer)
  182.       if (index > 0) then do
  183.          remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  184.          waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  185.          done = 0
  186.       end
  187.       call charout , substr(waitfor_buffer,curpos)
  188.       curpos = length(waitfor_buffer)+1
  189.       if ((done \= 0) & (TIME('E')>timeout)) then do
  190.         call lineout , ' WAITFOR: timed out '
  191.         done = 1
  192.        end
  193.    end
  194.    timeout=0
  195.    RC=done
  196.  return RC
  197.  
  198.  
  199.  
  200. /*--------------------------------------------------------------------------*/
  201. /*                               readpass ()                                */
  202. /*..........................................................................*/
  203. /*                                                                          */
  204. /* Routine used to read a password from the user without echoing the        */
  205. /* password to the screen.                                                  */
  206. /*                                                                          */
  207. /*--------------------------------------------------------------------------*/
  208.  
  209. readpass:
  210.  
  211.   answer = ''
  212.   do until key = cr
  213.     key = slip_getch()
  214.     if key \= cr then do
  215.       answer = answer || key
  216.     end
  217.   end
  218.   say ''
  219.   return answer
  220.  
  221.  
  222. /*--------------------------------------------------------------------------*/
  223. /*                             flush_receive ()                             */
  224. /*..........................................................................*/
  225. /*                                                                          */
  226. /* Routine to flush any pending characters to be read from the COM port.    */
  227. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  228. /* point it returns.                                                        */
  229. /*                                                                          */
  230. /* The optional echo argument, if 1, says to echo flushed information.      */
  231. /*                                                                          */
  232. /*--------------------------------------------------------------------------*/
  233.  
  234. flush_receive:
  235.  
  236.    parse arg echo
  237.  
  238.    /* If echoing the flush - take care of waitfor remaining buffer */
  239.    if (echo \= '') & (length(remain_buffer) > 0) then do
  240.       call charout , remain_buffer
  241.       remain_buffer = ''
  242.    end
  243.  
  244.    /* Eat anything left in the modem or COM buffers */
  245.    /* Stop when nothing new appears for 100ms.      */
  246.  
  247.    do until line = ''
  248.      line = slip_com_input(interface,,100)
  249.      if echo \= '' then
  250.         call charout , line
  251.    end
  252.  
  253.    return
  254.