home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / slip20b1.zip / slipup.cmd < prev    next >
OS/2 REXX Batch file  |  1993-04-09  |  10KB  |  264 lines

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