home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / DATACOM / INTERNET / WARPIAK / PPP.ZIP / BIN / CYBERNET.CMD < prev    next >
OS/2 REXX Batch file  |  1994-09-14  |  10KB  |  233 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*        OS/2 2.11 / WARP REX Driver for IBM TCP/IP version 2.0 / IAK      */
  4. /*                                                                          */
  5. /* Sample attachment script for dialing into an Internet access provider.   */
  6. /* This script should be specified on page 1 in the Login Script field for  */
  7. /* connections via SlipPM or using the -connect option if executing slip    */
  8. /* directly.                                                                */
  9. /*                                                                          */
  10. /*        NOTE: This file is supplied as a sample connection script, and    */
  11. /*              does not constitute the endorsement of a particular         */
  12. /*              Internet provider on the part of IBM.                       */
  13. /*              Internet providers periodically change their connection     */
  14. /*              procedures; please refer to the latest information provided */
  15. /*              by the service provider.                                    */
  16. /*                                                                          */
  17. /*              This script may be modified to suit the needs of the user   */
  18. /*              and is written to process dialogs similar to those          */
  19. /*              required by many Annex type service providers.              */
  20. /*                                                                          */
  21. /* When the script runs, it is automatically passed the interface name for  */
  22. /* the interface it is running on as the first argument, followed by the    */
  23. /* user arguments.                                                          */
  24. /*                                                                          */
  25. /* The script sends the dial string to the modem and then logs into the     */
  26. /* terminal server using the username/password.  It then issues the SLIP    */
  27. /* command to start SLIP, and parses the resulting output to determine the  */
  28. /* appropriate addresses to use.  Lastly, it issues ifconfig and route      */
  29. /* commands to configure the OS/2 system appropriately.  Note that the      */
  30. /* configuration assumes a class C netmask for the SLIP interface.          */
  31. /*                                                                          */
  32. /*--------------------------------------------------------------------------*/
  33.  
  34. parse arg interface , dialcmd username password
  35.  
  36. /*--------------------------------------------------------------------------*/
  37. /*                   Initialization and Main Script Code                    */
  38. /*--------------------------------------------------------------------------*/
  39.  
  40. /* Set some definitions for easier COM strings */
  41. cr='0d'x
  42. crlf='0d0a'x
  43.  
  44. say ''
  45. say 'ANNEX - SLIP ANNEX Cybernet Server Connection Script ',
  46.     '(interface' interface')'
  47.  
  48. /* Flush any stuff left over from previous COM activity */
  49. call flush_receive
  50.  
  51. /* Reset the modem here */
  52. /* You may need to customize this for your modem make and model */
  53. call lineout , 'Reset modem...'
  54. call send 'AT&F' || cr
  55. call waitfor 'OK', 5 ; call flush_receive 'echo'
  56.  if RC = 1 then do
  57.     call lineout , 'Modem not resetting... Trying again'
  58.     call send '+++'
  59.     call waitfor 'OK'
  60.     call send 'ATHZ' || cr
  61.     call waitfor 'OK', 3
  62.   end
  63.  
  64. /* Dial the remote server */
  65. call charout , 'Now Dialing...'
  66.  
  67. /* Wait for connection */
  68. call send dialcmd || cr
  69. call waitfor 'CONNECT' ; call waitfor crlf
  70.  
  71. /* Handle login.  We wait for standard strings, and then flush anything */
  72. /* else to take care of trailing spaces, etc..                          */
  73. /* call send cr */
  74. call waitfor 'CyberGate>' ; call flush_receive 'echo'
  75. call send 'SLIP' || cr
  76. call waitfor 'Username:' ; call flush_receive 'echo'
  77. call send username || cr
  78. call waitfor 'Password:' ; call flush_receive 'echo'
  79. call send password || cr
  80.  
  81. /* Parse the results of the SLIP command to determine our address. */
  82. /* We use the "waitfor_buffer" variable from the waitfor routine   */
  83. /* to parse the stuff we get from the Annex after waiting for an   */
  84. /* appropriate point in the data stream.                           */
  85. call waitfor 'Your address is' 
  86. parse var waitfor_buffer . 'Annex address is' a '.' b '.' c '.' d '.' .
  87. annex_address = a||'.'||b||'.'||c||'.'||d
  88.  
  89. call waitfor crlf 
  90. parse var waitfor_buffer  a '.' b '.' c '.' d '.' .
  91. os2_address = a||'.'||b||'.'||c||'.'||d
  92.  
  93. /* Flush anything else */
  94. call flush_receive 'echo'
  95.  
  96. /* Now configure this host for the appropriate address, */
  97. /* and for a default route through the Annex.           */
  98.  
  99. say 'SLIP Connection Established'
  100. say 'Configuring local address =' os2_address ', Annex =' annex_address
  101.  
  102. 'ifconfig sl0' os2_address annex_address 'netmask 255.255.255.0'
  103. 'route add default' annex_address '1'
  104.  
  105. /* All done */
  106. exit 0
  107.  
  108.  
  109. /*--------------------------------------------------------------------------*/
  110. /*                            send ( sendstring)                            */
  111. /*..........................................................................*/
  112. /*                                                                          */
  113. /* Routine to send a character string off to the modem.                     */
  114. /*                                                                          */
  115. /*--------------------------------------------------------------------------*/
  116.  
  117. send:
  118.  
  119.    parse arg sendstring
  120.    call slip_com_output interface , sendstring
  121.  
  122.    return
  123.  
  124.  
  125. /*--------------------------------------------------------------------------*/
  126. /*                    waitfor ( waitstring , [timeout] )                    */
  127. /*..........................................................................*/
  128. /*                                                                          */
  129. /* Waits for the supplied string to show up in the COM input.  All input    */
  130. /* from the time this function is called until the string shows up in the   */
  131. /* input is accumulated in the "waitfor_buffer" variable.                   */
  132. /*                                                                          */
  133. /* If timeout is specified, it says how long to wait if data stops showing  */
  134. /* up on the COM port (in seconds).                                                         */
  135. /*                                                                          */
  136. /*--------------------------------------------------------------------------*/
  137.  
  138. waitfor:
  139.  
  140.    parse arg waitstring , timeout
  141.  
  142.    if timeout = '' then
  143.      timeout = 5000    /* L O N G   delay if not specified */
  144.    waitfor_buffer = '' ; done = -1; curpos = 1
  145.    ORI_TIME=TIME('E')
  146.  
  147.    if (remain_buffer = 'REMAIN_BUFFER') then do
  148.       remain_buffer = ''
  149.    end
  150.  
  151.    do while (done = -1)
  152.       if (remain_buffer \= '') then do
  153.          line = remain_buffer
  154.          remain_buffer = ''
  155.        end
  156.        else do
  157.          line = slip_com_input(interface,,10)
  158.       end
  159.       waitfor_buffer = waitfor_buffer || line
  160.       index = pos(waitstring,waitfor_buffer)
  161.       if (index > 0) then do
  162.          remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  163.          waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  164.          done = 0
  165.       end
  166.       call charout , substr(waitfor_buffer,curpos)
  167.       curpos = length(waitfor_buffer)+1
  168.       if ((done \= 0) & (TIME('E')>timeout)) then do
  169.         call lineout , ' WAITFOR: timed out '
  170.         done = 1
  171.        end
  172.    end
  173.    timeout=0
  174.    RC=done
  175.  return RC
  176.  
  177.  
  178.  
  179. /*--------------------------------------------------------------------------*/
  180. /*                               readpass ()                                */
  181. /*..........................................................................*/
  182. /*                                                                          */
  183. /* Routine used to read a password from the user without echoing the        */
  184. /* password to the screen.                                                  */
  185. /*                                                                          */
  186. /*--------------------------------------------------------------------------*/
  187.  
  188. readpass:
  189.  
  190.   answer = ''
  191.   do until key = cr
  192.     key = slip_getch()
  193.     if key \= cr then do
  194.       answer = answer || key
  195.     end
  196.   end
  197.   say ''
  198.   return answer
  199.  
  200.  
  201. /*--------------------------------------------------------------------------*/
  202. /*                             flush_receive ()                             */
  203. /*..........................................................................*/
  204. /*                                                                          */
  205. /* Routine to flush any pending characters to be read from the COM port.    */
  206. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  207. /* point it returns.                                                        */
  208. /*                                                                          */
  209. /* The optional echo argument, if 1, says to echo flushed information.      */
  210. /*                                                                          */
  211. /*--------------------------------------------------------------------------*/
  212.  
  213. flush_receive:
  214.  
  215.    parse arg echo
  216.  
  217.    /* If echoing the flush - take care of waitfor remaining buffer */
  218.    if (echo \= '') & (length(remain_buffer) > 0) then do
  219.       call charout , remain_buffer
  220.       remain_buffer = ''
  221.    end
  222.  
  223.    /* Eat anything left in the modem or COM buffers */
  224.    /* Stop when nothing new appears for 100ms.      */
  225.  
  226.    do until line = ''
  227.      line = slip_com_input(interface,,100)
  228.      if echo \= '' then
  229.         call charout , line
  230.    end
  231.  
  232.    return
  233.