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

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*        OS/2 3.0 / WARP REX Driver for IBM TCP/IP version 2.0 / IAK       */
  4. /*                                                                          */
  5. /* FILE:     teleport.cmd                                                   */
  6. /* PURPOSE:  Slip connect script for Teleport                               */
  7. /*                                                                          */
  8. /* This script is used by the 'other Provider' connection program to dial   */
  9. /* and connect to TELEPORT.COM, a provider in the Portland, OR area.        */
  10. /* Teleport has multiple routers you may connect to and they are assigned   */
  11. /* based on next unused connection in the telephone switch 'hunt' group.    */
  12. /* Each router is a NetBlazer with a different IP address.  The routers     */
  13. /* assign the remote IP address (user's) from a pool of addresses.  This    */
  14. /* script handles the prompts and responses unique to Teleport.  It is a    */
  15. /* starting place for a script that handles dynamic router and remote IP    */
  16. /* addresses.  Before you modify this, I recommend connecting with your     */
  17. /* provider using Hyperaccess or some other terminal program to capture     */
  18. /* the connection prompts and responses.  Look for things like carraige     */
  19. /* returns you may have to strip off.                                       */
  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.  This parm passing doesn.t seem to work.  If any knows   */
  24. /* why, please post.  Additionally, this script contains a routine to       */
  25. /* take in the password if modified and used standalone with a slip.cfg     */
  26. /* file.                                                                    */
  27. /*                                                                          */
  28. /* This script was pieced together from several examples.  Since it works   */
  29. /* I haven't messed with it.                                                */
  30. /*                                                                          */
  31. /*                                                                          */
  32. /* TO SETUP: (Teleport config used as an example)                           */
  33. /* You will need the information from your provider.                        */
  34. /*                                                                          */
  35. /* 1. Start Dial Other 'Provider Internet Provider' app.                    */
  36. /* 2. Select 'Add Provider'                                                 */
  37. /* 3. On page 1 enter the following:                                        */
  38. /*       Provider Name: teleport                                            */
  39. /*       Login ID:           XXXXXX  (your id)                              */
  40. /*       Password:           XXXXXX                                         */
  41. /*       Nickname:           teleport                                       */
  42. /*       Phone Number:       220-2276                                       */
  43. /*       Login Script:       teleport.cmd                                   */
  44. /*                                                                          */
  45. /* 4. On page 2 enter the following:                                        */
  46. /*       MTU Size:           1006                                           */
  47. /*          select VJ compression                                           */
  48. /*       Domain Nameserver:  192.108.254.11                                 */
  49. /*       Your Domain Name:   teleport.com                                   */
  50. /*                                                                          */
  51. /* 5. Select 'OK'                                                           */
  52. /* 6. Copy this scrip to your \tcpip\bin dir                                */
  53. /* 7. Rock and Roll!                                                        */
  54. /*                                                                          */
  55. /* Teleport connects with the following prompts and responses.  This script */
  56. /* identifies the router by parsing the login script and using a REXX       */
  57. /* select statement to assign address.  The remote IP address is parsed     */
  58. /* from the response from the teleport router.  This address has a CRLF     */
  59. /* that needs to be stripped off.                                           */
  60. /*                                                                          */
  61. /* TELEPORT PROMPTS:                                                        */
  62. /* nb-xxxx login:  (where xxxx can be: pdx1, pdx2, pdx3, pdx4, vanc, salem) */
  63. /* Password:                                                                */
  64. /*                                                                          */
  65. /* TELEPORT RESPONSES:                                                      */
  66. /* Set IP address of interface 'username-slip'                              */
  67. /* Packet mode enabled for IP address: xxx.xxx.xxx.xxx                      */
  68. /*                                                                          */
  69. /*                                                                          */
  70. /*--------------------------------------------------------------------------*/
  71. /* CHANGES                                                                  */
  72. /* 11/22/94 bhh Added correct logic for all nb routers                      */
  73. /*--------------------------------------------------------------------------*/
  74.  
  75. parse arg interface , dialcmd username password gateway
  76.  
  77. /*--------------------------------------------------------------------------*/
  78. /*                   Initialization and Main Script Code                    */
  79. /*--------------------------------------------------------------------------*/
  80.  
  81. /* Set some definitions for easier COM strings */
  82. cr='0d'x
  83. crlf='0d0a'x
  84. blazer=''
  85. router_addr=''
  86. local_addr=''
  87.  
  88. say ''
  89. say 'Teleport Connection Script '
  90. say ''
  91.  
  92. /* Since the parm passing mechanism from the program doesn't seem to work   */
  93. /* for me, I am hard coding the dial code, username and password.           */
  94. dialcmd='atm0dt220-2276'
  95.  
  96. /* Put user id here. */
  97. username='xxxxxxx'
  98. /* Put user password here. */
  99. password='xxxxxxx'
  100.  
  101.  
  102. /* Flush any stuff left over from previous COM activity */
  103. call flush_receive
  104.  
  105. /* Reset the modem here */
  106. /* You may need to customize this for your modem make and model */
  107. /* The following is used with a Supra v32bis modem              */
  108. all lineout , 'Reset modem...'
  109. call send 'AT&F2' || cr
  110. call waitfor 'OK', 5 ; call flush_receive 'echo'
  111.  if RC = 1 then do
  112.     call lineout , 'Modem not resetting... Trying again'
  113.     call send '+++'
  114.     call waitfor 'OK'
  115.     call send 'ATHZ' || cr
  116.     call waitfor 'OK', 3
  117.   end
  118.  
  119. /* Wait for connection */
  120. maxtries=20
  121. tries=0
  122. pause=30
  123. busy=1
  124. do while (busy=1)
  125.     index=0
  126.     call charout , 'Now Dialing...  '
  127.     call send dialcmd || cr
  128.     call waitfor 'CONNECT', 30 ; call flush_receive 'echo'
  129.     index=pos('BUSY', waitfor_buffer)
  130.     if (index > 0) then
  131.     do
  132.        tries=tries+1
  133.        if (tries>maxtries) then
  134.        do
  135.           exit 0
  136.        end
  137.        say ''
  138.        call charout , 'retrying '|| tries || ' of ' || maxtries||'... '
  139.     end
  140.     index=pos('CONNECT', waitfor_buffer)
  141.     if (index > 0) then
  142.     do
  143.         busy=0
  144.     end
  145. end
  146.  
  147. /* Handle login.  We wait for standard strings, and then flush anything */
  148. /* else to take care of trailing spaces, etc..                          */
  149. call send cr 
  150.  
  151. /* call waitfor 'login:' ; call flush_receive 'echo'          */
  152. /* Teleport has multiple routers.  Need to check login prompt */
  153.  
  154. call waitfor 'nb-'
  155. blazer=substr(remain_buffer,1,4)
  156. call flush_receive 'echo'
  157.  
  158. select
  159. when blazer = 'pdx1' then
  160.     router_addr='192.108.254.66'
  161. when blazer = 'pdx2' then
  162.     router_addr='192.108.254.67'
  163. when blazer = 'pdx3' then
  164.     router_addr='192.108.254.69'
  165. when blazer = 'pdx4'
  166.     router_addr='192.108.254.70'
  167. when blazer = 'sale'                /*  Salem */
  168.     router_addr='192.108.254.68'
  169. when blazer = 'vanc'
  170.     router_addr='192.108.254.65'
  171. end
  172.  
  173. call send username || cr
  174. call waitfor 'Password:' ; call flush_receive 'echo'
  175. call send password || cr
  176.  
  177. /* Teleport Replies with string 'Packet mode enabled for IP address XXX.XXX.XXX.XXX' */
  178. /* Use get_rest to handle selays flush_receive will not.                             */
  179. /* Need to strip crlf from address so ifconfig and route works.                      */
  180.  
  181. call waitfor 'enabled for IP address: ' ; call get_rest
  182. str_addr = remain_buffer
  183. length_addr=length(str_addr)
  184.  
  185. local_addr=substr(str_addr,1,length_addr-2)
  186.  
  187. call flush_receive
  188.  
  189. /* Now configure this host for the appropriate address, */
  190. /* and for a default route through teleport.            */
  191.  
  192. say str_addr
  193. 'ifconfig sl0' local_addr router_addr
  194. 'route -fh add host' router_addr local_addr '0'
  195. 'route add default' router_addr '1'
  196.  
  197. say '*** SLIP Connection Established ***'
  198.  
  199. /* All done */
  200. exit 0
  201.  
  202.  
  203. /*--------------------------------------------------------------------------*/
  204. /*                            send ( sendstring)                            */
  205. /*..........................................................................*/
  206. /*                                                                          */
  207. /* Routine to send a character string off to the modem.                     */
  208. /*                                                                          */
  209. /*--------------------------------------------------------------------------*/
  210.  
  211. send:
  212.  
  213.    parse arg sendstring
  214.    call slip_com_output interface , sendstring
  215.  
  216.    return
  217.  
  218.  
  219. /*--------------------------------------------------------------------------*/
  220. /*                    waitfor ( waitstring , [timeout] )                    */
  221. /*..........................................................................*/
  222. /*                                                                          */
  223. /* Waits for the supplied string to show up in the COM input.  All input    */
  224. /* from the time this function is called until the string shows up in the   */
  225. /* input is accumulated in the "waitfor_buffer" variable.                   */
  226. /*                                                                          */
  227. /* If timeout is specified, it says how long to wait if data stops showing  */
  228. /* up on the COM port (in seconds).                                                         */
  229. /*                                                                          */
  230. /*--------------------------------------------------------------------------*/
  231.  
  232. waitfor:
  233.  
  234.    parse arg waitstring , timeout
  235.  
  236.    if timeout = '' then
  237.      timeout = 5000    /* L O N G   delay if not specified */
  238.    waitfor_buffer = '' ; done = -1; curpos = 1
  239.    ORI_TIME=TIME('E')
  240.  
  241.    if (remain_buffer = 'REMAIN_BUFFER') then do
  242.       remain_buffer = ''
  243.    end
  244.  
  245.    do while (done = -1)
  246.       if (remain_buffer \= '') then do
  247.          line = remain_buffer
  248.          remain_buffer = ''
  249.        end
  250.        else do
  251.          line = slip_com_input(interface,,10)
  252.       end
  253.       waitfor_buffer = waitfor_buffer || line
  254.       index = pos(waitstring,waitfor_buffer)
  255.       if (index > 0) then do
  256.          remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  257.          waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  258.          done = 0
  259.       end
  260.       call charout , substr(waitfor_buffer,curpos)
  261.       curpos = length(waitfor_buffer)+1
  262.       if ((done \= 0) & (TIME('E')>timeout)) then do
  263.         call lineout , ' WAITFOR: timed out '
  264.         done = 1
  265.        end
  266.    end
  267.    timeout=0
  268.    RC=done
  269.  return RC
  270.  
  271.  
  272.  
  273. /*--------------------------------------------------------------------------*/
  274. /*                               readpass ()                                */
  275. /*..........................................................................*/
  276. /*                                                                          */
  277. /* Routine used to read a password from the user without echoing the        */
  278. /* password to the screen. (For use as a standalone REXX script)            */
  279. /*                                                                          */
  280. /*--------------------------------------------------------------------------*/
  281.  
  282. readpass:
  283.  
  284.   answer = ''
  285.   do until key = cr
  286.     key = slip_getch()
  287.     if key \= cr then do
  288.       call charout '*'
  289.       answer = answer || key
  290.     end
  291.   end
  292.   say ''
  293.   return answer
  294.  
  295.  
  296. /*--------------------------------------------------------------------------*/
  297. /*                             flush_receive ()                             */
  298. /*..........................................................................*/
  299. /*                                                                          */
  300. /* Routine to flush any pending characters to be read from the COM port.    */
  301. /* Reads everything it can until nothing new shows up for 250ms, at which   */
  302. /* point it returns.                                                        */
  303. /*                                                                          */
  304. /* The optional echo argument, if 1, says to echo flushed information.      */
  305. /*                                                                          */
  306. /*--------------------------------------------------------------------------*/
  307.  
  308. flush_receive:
  309.  
  310.    parse arg echo
  311.  
  312.    /* If echoing the flush - take care of waitfor remaining buffer */
  313.    if (echo \= '') & (length(remain_buffer) > 0) then do
  314.       call charout , remain_buffer
  315.       remain_buffer = ''
  316.    end
  317.  
  318.    /* Eat anything left in the modem or COM buffers */
  319.    /* Stop when nothing new appears for 100ms.      */
  320.  
  321.    do until line = ''
  322.      line = slip_com_input(interface,,100)
  323.      if echo \= '' then
  324.         call charout , line
  325.    end
  326.  
  327.    return
  328.  
  329.  
  330. /*--------------------------------------------------------------------------*/
  331. /*                             get_rest ()                                  */
  332. /*..........................................................................*/
  333. /*                                                                          */
  334. /* Use get_rest to handle selays flush_receive will not.                    */
  335. /*                                                                          */
  336. /*--------------------------------------------------------------------------*/
  337.  
  338. get_rest:
  339.    restline='XXX'
  340.    do until restline = ''
  341.      restline = slip_com_input(interface,,500)
  342.      remain_buffer = remain_buffer||restline
  343.    end
  344.    return
  345.  
  346.