home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / mr_net.cmd < prev    next >
OS/2 REXX Batch file  |  1994-12-13  |  12KB  |  271 lines

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