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

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