home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / crsos2.zip / CRIS.CMD < prev    next >
OS/2 REXX Batch file  |  1994-11-26  |  9KB  |  232 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*        OS/2 2.1 / WARP REX Driver for IBM TCP/IP version 2.0 / IAK       */
  3. /*                                                                          */
  4. /*                                CRIS.CMD                                  */
  5. /*                                                                          */
  6. /*            ..................................................            */
  7. /*                                                                          */
  8. /* Sample attachment script for dialing into a CRIS Point of Presence       */
  9. /* server in order to establish a SLIP connection.  This script should be   */
  10. /* specified on page 1 in the Login Script field for connections via SlipPM */
  11. /* or using the -connect option if executing slip directly.                 */
  12. /*                                                                          */
  13. /*       YOU WILL NEED THE FOLLOWING FOR YOUR ADD PROVIDER CHANGES          */
  14. /* For example, the following might be used in SlipPM:                      */
  15. /*              Login Script: cris.cmd atdt999-9999 loginid password        */
  16. /*                                                                          */
  17. /* which would then feed the "atdt999-9999" command to the modem, followed  */
  18. /* by the login id and password once the connection is established.         */
  19. /*--------------------------------------------------------------------------*/
  20.  
  21. parse arg interface , dialcmd username password
  22.  
  23. /*--------------------------------------------------------------------------*/
  24. /*                   Initialization and Main Script Code                    */
  25. /*--------------------------------------------------------------------------*/
  26.  
  27. /* Set some definitions for easier COM strings */
  28. cr='0d'x
  29. crlf='0d0a'x
  30.  
  31. say ''
  32. say 'CRIS SLIP Connection Script ',
  33.     '(interface' interface')'
  34.  
  35. /* Prompt for missing information */
  36. if dialcmd = '' then do
  37.    call charout , 'Dial Command: '
  38.    parse pull dialcmd
  39. end
  40. if username = '' | username = '*' then do
  41.    call charout , 'User Name: '
  42.    parse pull username
  43. end
  44. else do
  45.    say 'User:' username
  46. end
  47. if password = '' | password = '*' then do
  48.    call charout , 'Password: '
  49.    password = readpass()
  50. end
  51.  
  52. /* Flush any stuff left over from previous COM activity */
  53. call flush_receive
  54.  
  55. /* Reset the modem here */
  56. /* You may need to customize this for your modem make and model */
  57. call lineout , 'Reset modem...'
  58. call send 'AT&F' || cr
  59. call waitfor 'OK', 5 ; call flush_receive 'echo'
  60. call send 'ATHZ0' || cr
  61. call waitfor 'OK', 5 ; call flush_receive 'echo'
  62.  if RC = 1 then do
  63.     call lineout , 'Modem not resetting... Trying again'
  64.     call send '+++'
  65.     call waitfor 'OK'
  66.     call send 'ATHZ' || cr
  67.     call waitfor 'OK', 3
  68.   end
  69.  
  70. /* Dial the remote server */
  71. call charout , 'Now Dialing...'
  72.  
  73. /* Wait for connection */
  74. call send dialcmd || cr
  75. call waitfor 'CONNECT' ; call waitfor crlf
  76.  
  77. /* Handle login.  We wait for standard strings, and then flush anything */
  78. /* else to take care of trailing spaces, etc..                          */
  79. /* call send cr */
  80. call waitfor 'user:' ; call flush_receive 'echo'
  81. call send username || cr
  82. call waitfor 'Password:' ; call flush_receive 'echo'
  83. call send password || cr
  84.  
  85. /* Flush anything else */
  86. call flush_receive 'echo'
  87.  
  88. /* Now configure this host for the appropriate address, */
  89. /* and for a default route through CRIS                 */
  90.  
  91. say 'SLIP Connection Established'
  92.  
  93. /* These addresses are for the Tulsa Oklahoma node and  */
  94. /* Will need updated for any other city.                */
  95. /* Contact CRIS Customer Support for your IP Addresses  */
  96.  
  97. cris_address = 192.0.2.1
  98. os2_address = 199.3.12.9
  99.  
  100. say 'Configuring local address =' os2_address ', Cris =' cris_address
  101. 'ifconfig sl0' os2_address cris_address 'netmask 255.255.255.0'
  102. 'route add default' cris_address '1'
  103.  
  104. /* All done */
  105. exit 0
  106.  
  107.  
  108. /*--------------------------------------------------------------------------*/
  109. /*                            send ( sendstring)                            */
  110. /*..........................................................................*/
  111. /*                                                                          */
  112. /* Routine to send a character string off to the modem.                     */
  113. /*                                                                          */
  114. /*--------------------------------------------------------------------------*/
  115.  
  116. send:
  117.  
  118.    parse arg sendstring
  119.    call slip_com_output interface , sendstring
  120.  
  121.    return
  122.  
  123.  
  124. /*--------------------------------------------------------------------------*/
  125. /*                    waitfor ( waitstring , [timeout] )                    */
  126. /*..........................................................................*/
  127. /*                                                                          */
  128. /* Waits for the supplied string to show up in the COM input.  All input    */
  129. /* from the time this function is called until the string shows up in the   */
  130. /* input is accumulated in the "waitfor_buffer" variable.                   */
  131. /*                                                                          */
  132. /* If timeout is specified, it says how long to wait if data stops showing  */
  133. /* up on the COM port (in seconds).                                                         */
  134. /*                                                                          */
  135. /*--------------------------------------------------------------------------*/
  136.  
  137. waitfor:
  138.  
  139.    parse arg waitstring , timeout
  140.  
  141.    if timeout = '' then
  142.      timeout = 5000    /* L O N G   delay if not specified */
  143.    waitfor_buffer = '' ; done = -1; curpos = 1
  144.    ORI_TIME=TIME('E')
  145.  
  146.    if (remain_buffer = 'REMAIN_BUFFER') then do
  147.       remain_buffer = ''
  148.    end
  149.  
  150.    do while (done = -1)
  151.       if (remain_buffer \= '') then do
  152.          line = remain_buffer
  153.          remain_buffer = ''
  154.        end
  155.        else do
  156.          line = slip_com_input(interface,,10)
  157.       end
  158.       waitfor_buffer = waitfor_buffer || line
  159.       index = pos(waitstring,waitfor_buffer)
  160.       if (index > 0) then do
  161.          remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  162.          waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  163.          done = 0
  164.       end
  165.       call charout , substr(waitfor_buffer,curpos)
  166.       curpos = length(waitfor_buffer)+1
  167.       if ((done \= 0) & (TIME('E')>timeout)) then do
  168.         call lineout , ' WAITFOR: timed out '
  169.         done = 1
  170.        end
  171.    end
  172.    timeout=0
  173.    RC=done
  174.  return RC
  175.  
  176.  
  177.  
  178. /*--------------------------------------------------------------------------*/
  179. /*                               readpass ()                                */
  180. /*..........................................................................*/
  181. /*                                                                          */
  182. /* Routine used to read a password from the user without echoing the        */
  183. /* password to the screen.                                                  */
  184. /*                                                                          */
  185. /*--------------------------------------------------------------------------*/
  186.  
  187. readpass:
  188.  
  189.   answer = ''
  190.   do until key = cr
  191.     key = slip_getch()
  192.     if key \= cr then do
  193.       answer = answer || key
  194.     end
  195.   end
  196.   say ''
  197.   return answer
  198.  
  199.  
  200. /*--------------------------------------------------------------------------*/
  201. /*                             flush_receive ()                             */
  202. /*..........................................................................*/
  203. /*                                                                          */
  204. /* Routine to flush any pending characters to be read from the COM port.    */
  205. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  206. /* point it returns.                                                        */
  207. /*                                                                          */
  208. /* The optional echo argument, if 1, says to echo flushed information.      */
  209. /*                                                                          */
  210. /*--------------------------------------------------------------------------*/
  211.  
  212. flush_receive:
  213.  
  214.    parse arg echo
  215.  
  216.    /* If echoing the flush - take care of waitfor remaining buffer */
  217.    if (echo \= '') & (length(remain_buffer) > 0) then do
  218.       call charout , remain_buffer
  219.       remain_buffer = ''
  220.    end
  221.  
  222.    /* Eat anything left in the modem or COM buffers */
  223.    /* Stop when nothing new appears for 100ms.      */
  224.  
  225.    do until line = ''
  226.      line = slip_com_input(interface,,100)
  227.      if echo \= '' then
  228.         call charout , line
  229.    end
  230.  
  231.    return
  232.