home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / michnet.zip / michnet.cmd next >
OS/2 REXX Batch file  |  1995-01-13  |  12KB  |  275 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*        OS/2 2.x / WARP REXX Driver for IBM TCP/IP version 2.0 / IAK      */
  4. /*                                                                          */
  5. /*                                MICHNET.CMD                               */
  6. /*                                                                          */
  7. /*            ..................................................            */
  8. /*                                                                          */
  9. /* Sample attachment script for dialing into MichNet server in order to     */
  10. /* establish a SLIP connection.  This script should be specified on page 1  */
  11. /* in the Login Script field for connections via SlipPM or using the        */
  12. /* -connect option if executing slip directly.                              */
  13. /*                                                                          */
  14. /* For example, the following might be used in SlipPM:                      */
  15. /* Login Script: michnet.cmd atdt998-1300 uniqname@umich.edu kerberospwd    */
  16. /*                                                                          */
  17. /* which would then feed the "atdt998-1300" command to the modem, followed  */
  18. /* by the login id and password once the connection is established.         */
  19. /*                                                                          */
  20. /* From slip directly the script supports:                                  */
  21. /*              -connect "michnet.cmd atdt998-1300 loginid *"               */
  22. /*                                                                          */
  23. /* which would cause michnet.trm to initially prompt for the password. It   */
  24. /* would then feed the "atdt998-1300" command to the modem, and when        */
  25. /* MichNet answers, it would use "loginid" as a username and the password   */
  26. /* specified.                                                               */
  27. /*                                                                          */
  28. /* Make sure you have these settings in your Dialup dialog box              */
  29. /* for University of Michigan NAS info.  Your University mileage            */
  30. /* may vary:                                                                */
  31. /*                                                                          */
  32. /*  *Phone Number: <blank>                                                  */
  33. /*  Login Script: michnet.cmd atdt9981300 uniqname@umich.edu kerberos       */
  34. /*  *MTU Size: 1006                                                         */
  35. /*  *Domain Nameserver: 141.211.144.15                                      */
  36. /*  *Your Domain Name: umich.edu                                            */
  37. /*  News Server: news.itd.umich.edu                                         */
  38. /*  Gopher Server: gopher.itd.umich.edu                                     */
  39. /*  WWW Server: www.umich.edu                                               */
  40. /*  POP Mail Server: pop.itd.umich.edu (questionable)                       */
  41. /*  Replay Domain: umich.edu                                                */
  42. /*  Reply (Mail) ID: <uniqname>@umich.edu                                   */
  43. /*  POP Login ID: <uniqname>                                                */
  44. /*  POP Password: <kerberos>                                                */
  45. /*                                                                          */
  46. /* This has been tested to work only with SLIP as of 10-JAN-95.  The Gamma  */
  47. /* PPP driver is out but not yet tested.  (I'm working on it.)              */
  48. /*                                                                          */
  49. /* Enjoy!  (Brian Shensky, shensky@umich.edu, 14 January 1995)              */
  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 'MICHNET - SLIP Connection Script for MichNet',
  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. /* Reset the modem here */
  88. /* You may need to customize this for your modem make and model */
  89. call lineout , 'Reset modem...'
  90. call send 'AT&F"H3\N3' || cr
  91. call waitfor 'OK', 5 ; call flush_receive 'echo'
  92.  if RC = 1 then do
  93.     call lineout , 'Modem not resetting... Trying again'
  94.     call send '+++'
  95.     call waitfor 'OK'
  96.     call send 'ATHZ' || cr
  97.     call waitfor 'OK', 3
  98.   end
  99.  
  100. /* Dial the remote server */
  101. call charout , 'Now Dialing...'
  102.  
  103. /* Wait for connection */
  104. call send dialcmd || cr
  105. call waitfor 'CONNECT' ; call waitfor crlf
  106.  
  107. /* Handle login.  We wait for standard strings, and then flush anything */
  108. /* else to take care of trailing spaces, etc..                          */
  109. /* call send cr */
  110. call waitfor 'host:' ; call flush_receive 'echo'
  111. call send 'slip' || cr
  112. call waitfor 'login:' ; call flush_receive 'echo'
  113. call send username || cr
  114. call waitfor 'Password:' ; call flush_receive 'echo'
  115. call send password || cr
  116.  
  117. /* Parse the results of the SLIP command to determine our address. */
  118. /* We use the "waitfor_buffer" variable from the waitfor routine   */
  119. /* to parse the stuff we get from the MichNet after waiting for an */
  120. /* appropriate point in the data stream.                           */
  121.  
  122. /* SL/IP session from (141.211.7.10) to 141.211.7.11 beginning.... */
  123.  
  124. call waitfor ')'
  125. say '!!!' waitfor_buffer '!!!'
  126. parse var waitfor_buffer 'SL/IP session from (' a '.' b '.' c '.' d ')' .
  127. call waitfor 'beginning....'
  128. parse var waitfor_buffer . e '.' f '.' g '.' h .
  129. annex_address = a||'.'||b||'.'||c||'.'||d
  130.  
  131. /* parse var waitfor_buffer  a '.' b '.' c '.' d '.' . */
  132. os2_address = e||'.'||f||'.'||g||'.'||h
  133.  
  134. /* Flush anything else */
  135. call flush_receive 'echo'
  136.  
  137. /* Now configure this host for the appropriate address, */
  138. /* and for a default route through the Annex.           */
  139.  
  140. say crlf crlf 'HEY!! SLIP Connection Established'
  141. say 'Configuring local address =' os2_address
  142. say 'MichNet =' annex_address
  143.  
  144. 'ifconfig sl0' os2_address annex_address 'netmask 255.255.255.0'
  145. 'route add default' annex_address '1'
  146.  
  147. /* All done */
  148. exit 0
  149.  
  150.  
  151. /*--------------------------------------------------------------------------*/
  152. /*                            send ( sendstring)                            */
  153. /*..........................................................................*/
  154. /*                                                                          */
  155. /* Routine to send a character string off to the modem.                     */
  156. /*                                                                          */
  157. /*--------------------------------------------------------------------------*/
  158.  
  159. send:
  160.  
  161.    parse arg sendstring
  162.    call slip_com_output interface , sendstring
  163.  
  164.    return
  165.  
  166.  
  167. /*--------------------------------------------------------------------------*/
  168. /*                    waitfor ( waitstring , [timeout] )                    */
  169. /*..........................................................................*/
  170. /*                                                                          */
  171. /* Waits for the supplied string to show up in the COM input.  All input    */
  172. /* from the time this function is called until the string shows up in the   */
  173. /* input is accumulated in the "waitfor_buffer" variable.                   */
  174. /*                                                                          */
  175. /* If timeout is specified, it says how long to wait if data stops showing  */
  176. /* up on the COM port (in seconds).                                                         */
  177. /*                                                                          */
  178. /*--------------------------------------------------------------------------*/
  179.  
  180. waitfor:
  181.  
  182.    parse arg waitstring , timeout
  183.  
  184.    if timeout = '' then
  185.      timeout = 5000    /* L O N G   delay if not specified */
  186.    waitfor_buffer = '' ; done = -1; curpos = 1
  187.    ORI_TIME=TIME('E')
  188.  
  189.    if (remain_buffer = 'REMAIN_BUFFER') then do
  190.       remain_buffer = ''
  191.    end
  192.  
  193.    do while (done = -1)
  194.       if (remain_buffer \= '') then do
  195.          line = remain_buffer
  196.          remain_buffer = ''
  197.        end
  198.        else do
  199.          line = slip_com_input(interface,,10)
  200.       end
  201.       waitfor_buffer = waitfor_buffer || line
  202.       index = pos(waitstring,waitfor_buffer)
  203.       if (index > 0) then do
  204.          remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  205.          waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  206.          done = 0
  207.       end
  208.       call charout , substr(waitfor_buffer,curpos)
  209.       curpos = length(waitfor_buffer)+1
  210.       if ((done \= 0) & (TIME('E')>timeout)) then do
  211.         call lineout , ' WAITFOR: timed out '
  212.         done = 1
  213.        end
  214.    end
  215.    timeout=0
  216.    RC=done
  217.  return RC
  218.  
  219.  
  220.  
  221. /*--------------------------------------------------------------------------*/
  222. /*                               readpass ()                                */
  223. /*..........................................................................*/
  224. /*                                                                          */
  225. /* Routine used to read a password from the user without echoing the        */
  226. /* password to the screen.                                                  */
  227. /*                                                                          */
  228. /*--------------------------------------------------------------------------*/
  229.  
  230. readpass:
  231.  
  232.   answer = ''
  233.   do until key = cr
  234.     key = slip_getch()
  235.     if key \= cr then do
  236.       answer = answer || key
  237.     end
  238.   end
  239.   say ''
  240.   return answer
  241.  
  242.  
  243. /*--------------------------------------------------------------------------*/
  244. /*                             flush_receive ()                             */
  245. /*..........................................................................*/
  246. /*                                                                          */
  247. /* Routine to flush any pending characters to be read from the COM port.    */
  248. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  249. /* point it returns.                                                        */
  250. /*                                                                          */
  251. /* The optional echo argument, if 1, says to echo flushed information.      */
  252. /*                                                                          */
  253. /*--------------------------------------------------------------------------*/
  254.  
  255. flush_receive:
  256.  
  257.    parse arg echo
  258.  
  259.    /* If echoing the flush - take care of waitfor remaining buffer */
  260.    if (echo \= '') & (length(remain_buffer) > 0) then do
  261.       call charout , remain_buffer
  262.       remain_buffer = ''
  263.    end
  264.  
  265.    /* Eat anything left in the modem or COM buffers */
  266.    /* Stop when nothing new appears for 100ms.      */
  267.  
  268.    do until line = ''
  269.      line = slip_com_input(interface,,100)
  270.      if echo \= '' then
  271.         call charout , line
  272.    end
  273.  
  274.    return
  275.