home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 29 Fixes_o / 29-Fixes_o.zip / tcpcsd2.zip / BASECSD2.EXE / BIN / SLIPUP.CMD < prev    next >
OS/2 REXX Batch file  |  1993-07-12  |  12KB  |  260 lines

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