home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / ccniak2.zip / HOOKED2.CMD < prev   
OS/2 REXX Batch file  |  1994-12-19  |  13KB  |  311 lines

  1. /*--------------------------------------------------------------------------*/
  2. /* HOOKED2.CMD                                                              */
  3. /* 11-15-94                                                                 */
  4. /* Customized by Chacko Neroth  (address: cheroth@hooked.net)               */
  5. /*                                                                          */
  6. /* OS/2 2.1 / WARP REX Driver for IBM TCP/IP version 2.0 / IAK              */
  7. /*                                                                          */
  8. /*                                                                          */
  9. /* Sample attachment script for dialing to hooked.net (TIA)internet provider*/
  10. /* in order to establish a SLIP connection via TIA. This script should be   */
  11. /* specified on page 1 in the Login Script field for connections via SlipPM */
  12. /* or using the -connect option if executing slip directly.                 */
  13. /*                                                                          */
  14. /* NOTE: This file is supplied as a sample connection script, and           */
  15. /*       does not constitute the endorsement of a particular                */
  16. /*       Internet provider on the part of IBM.                              */
  17. /*       Internet providers periodically change their connection            */
  18. /*       procedures; please refer to the latest information provided        */
  19. /*       by the service provider.                                           */
  20. /*                                                                          */
  21. /*       This script may be modified to suit the needs of the user          */
  22. /*       and is written to process dialogs similar to those                 */
  23. /*       used by TIA SLIP  type service providers.                          */
  24. /*                                                                          */
  25. /* The script parameters specify the command to send to the modem to dial   */
  26. /* the remote site and the username/password combination to use to log into */
  27. /* the terminal server.  If any of the parameters are omitted, or are       */
  28. /* specified as an asterix (*), the script will prompt for them (Refer      */
  29. /* to caveate below).  This is most useful with the password parameter to   */
  30. /* avoid storing the password in a text file on the disk.                   */
  31. /*                                                                          */
  32. /* For example, the following might be used in SlipPM:                      */
  33. /*              Login Script: hooked.cmd atdt999-9999 loginid password      */
  34. /*                                                                          */
  35. /* which would then feed the "atdt999-9999" command to the modem, followed  */
  36. /* by the login id and password once the connection is established.         */
  37. /*                                                                          */
  38. /* From slip directly the hooked script supports:                           */
  39. /*              -connect "hooked.cmd atdt999-9999 loginid *"                */
  40. /*                                                                          */
  41. /* which would cause hooked.cmd to initially prompt for the password. It    */
  42. /* would then feed the "atdt999-9999" command to the modem, and when        */
  43. /* Hooked answered, it would use "loginid" as a username and the password   */
  44. /* specified.                                                               */
  45. /*                                                                          */
  46. /* NOTE: You must pass the phone number, and both login id and password     */
  47. /*       to hooked.cmd from the Dialer.  The Dialer will NOT allow for the  */
  48. /*       input of a phone number, login or password from the keyboard.      */
  49. /*            - - - - - - - - - - - - - - - - - - - - - - - - -             */
  50. /*                                                                          */
  51. /* When the script runs, it is automatically passed the interface name for  */
  52. /* the interface it is running on as the first argument, followed by the    */
  53. /* user arguments.                                                          */
  54. /*                                                                          */
  55. /* The script sends the dial string to the modem and then logs into the     */
  56. /* terminal server using the username/password.  It then issues the SLIP    */
  57. /* command to start SLIP.  Lastly, it issues ifconfig and route             */
  58. /* commands to configure the OS/2 system appropriately.  Note that the      */
  59. /* configuration uses the hooked  netmask for the SLIP interface.           */
  60. /*                                                                          */
  61. /*--------------------------------------------------------------------------*/
  62.  
  63. parse arg interface , dialcmd username password
  64.  
  65. /*--------------------------------------------------------------------------*/
  66. /*                   Initialization and Main Script Code                    */
  67. /*--------------------------------------------------------------------------*/
  68.  
  69. call RxFuncAdd 'SysSleep', 'RexxUtil', 'SysSleep'
  70.  
  71. /* Set some definitions for easier COM strings */
  72. cr='0d'x
  73. crlf='0d0a'x
  74.  
  75. /*say 'HOOKED  -- Script for SLIP Dialer via TIA ('interface')'*/
  76. dialcmd = 'ATL0DT534-0841' /* MODIFY FOR YOUR TEL ACCESS NUMBER */
  77.                                     /* change L0 to M0 to turn speaker off */
  78. hostprompt= '>'                  /* MODIFY FOR YOUR HOST'S PROMT */
  79. username= 'loginname'       /* MODIFY FOR YOUR LOGIN_NAME */
  80. password= 'password'           /* MODIFY FOR YOUR PASSWORD */
  81.  
  82.  
  83. 'mode com2:dtr=on'         /* needed with some com drivers */
  84. /* Flush any stuff left over from previous COM activity */
  85. call flush_receive
  86.  
  87. /* Reset the modem here */
  88. /* You may need to customize this for your modem make and model */
  89. /*call lineout , 'Reset modem...'*/
  90.  
  91. call send 'AT&F' || cr        /* MODIFY IF NEEDED */
  92.  
  93. retry:
  94. call waitfor 'OK', 5 ; call flush_receive 'echo'
  95.  if RC = 1 then do
  96.     call lineout , 'Modem not resetting... Trying again'
  97.     call send '+++'
  98.     call waitfor 'OK'
  99.     call send 'ATHZ' || cr
  100.     call waitfor 'OK', 3
  101.   end
  102.  
  103. /* Dial the remote server */
  104. call SysSleep(1)
  105. call charout , 'Now Dialing...'
  106. call send dialcmd || cr
  107.  
  108. /* Wait for connection */
  109. RC = waitfor('CONNECT', 65); /*call flush_receive 'echo'*/
  110.  
  111. if (RC > 1) then /*busy*/
  112.     do
  113.     say 'BUSY, Retrying'
  114.     call send 'ATZ' || cr
  115.     call SysSleep(3)
  116.     signal retry
  117.     end
  118.  
  119. if (RC > 0) then /*timedout*/
  120.     do
  121.     say 'Connect: TIMED OUT'
  122.     exit 1
  123.     end
  124.  
  125. /*call waitfor crlf*/
  126. relogc = 0
  127.  
  128. call waitfor 'login: ',20 ; call flush_receive 'echo'
  129. relog:
  130. call SysSleep(3)
  131. call send username || cr
  132. call waitfor 'sword:',10 ; call flush_receive 'echo'
  133. if (RC>0) then
  134.     do
  135.     relogc = relogc+1
  136.     if (relogc < 6) then
  137.         do
  138.         say 'Login/Password waiting timed out. Trying to relogin'
  139.         signal relog
  140.         end
  141.     else
  142.         do
  143.        say 'Login failed. Try again.'
  144.         exit 1
  145.         end
  146.  
  147.     end
  148.  
  149. call SysSleep(1)
  150. call send password || cr
  151.  
  152. call waitfor hostprompt ; call flush_receive 'echo'
  153. call send '/usr/local/bin/tia' || cr    /* MODIFY THE PATH FOR YOUR PROVIDER*/
  154. call waitfor 'software.' ; call flush_receive 'echo'
  155.  
  156. say 'SLIP Connection Established'
  157.  
  158.  
  159. /* slip configuration with the hooked specific fixed ip */
  160.    
  161. ip = '199.2.134.2'    /* MODIFY FOR YOUR PROVIDER's IP ADDRESS if not Hooked */
  162. os2_address = ip
  163. hooked_address = ip
  164. netmask = '0.0.0.0'    /* MODIFY FOR YOUR PROVIDER's MASK ADDRESS if not Hooked */
  165.  
  166.  
  167. say 'Configuring local address =' os2_address ', Hooked =' hooked_address
  168. say 'DO NOT TERMINATE THIS SESSION, UNTIL YOU WANT TO DISCONNECT !'
  169. say 'This window may be minimized.'
  170.  
  171. 'ifconfig sl0' ip ip 'netmask' netmask
  172. 'route add default' hooked_address '1'
  173.  
  174. /* All done */
  175. exit 0
  176.  
  177.  
  178. /*--------------------------------------------------------------------------*/
  179. /*                            send ( sendstring)                            */
  180. /*..........................................................................*/
  181. /*                                                                          */
  182. /* Routine to send a character string off to the modem.                     */
  183. /*                                                                          */
  184. /*--------------------------------------------------------------------------*/
  185.  
  186. send:
  187.  
  188.    parse arg sendstring
  189.    call slip_com_output interface , sendstring
  190.  
  191.    return
  192.  
  193.  
  194. /*--------------------------------------------------------------------------*/
  195. /*                    waitfor ( waitstring , [timeout] )                    */
  196. /*..........................................................................*/
  197. /*                                                                          */
  198. /* Waits for the supplied string to show up in the COM input.  All input    */
  199. /* from the time this function is called until the string shows up in the   */
  200. /* input is accumulated in the "waitfor_buffer" variable.                   */
  201. /*                                                                          */
  202. /* If timeout is specified, it says how long to wait if data stops showing  */
  203. /* up on the COM port (in seconds).                                         */
  204. /*                                                                          */
  205. /*--------------------------------------------------------------------------*/
  206.  
  207. waitfor:
  208.  
  209.    parse arg waitstring , timeout
  210.  
  211.    if timeout = '' then
  212.      timeout = 5000    /* L O N G   delay if not specified */
  213.    waitfor_buffer = '' ; done = -1; curpos = 1
  214.    ORI_TIME=TIME('E')
  215.  
  216.    if (remain_buffer = 'REMAIN_BUFFER') then do
  217.       remain_buffer = ''
  218.    end
  219.  
  220.     done = -1
  221.    do while (done == -1)
  222.       if (remain_buffer \= '') then do
  223.          line = remain_buffer
  224.          remain_buffer = ''
  225.        end
  226.        else do
  227.          line = slip_com_input(interface,,10)
  228.       end
  229.  
  230.       waitfor_buffer = waitfor_buffer || line
  231.  
  232.       index = pos('BUSY',waitfor_buffer)
  233.       if (index > 0) then do
  234.          RC = 2
  235.             return RC
  236.       end
  237.  
  238.       index = pos(waitstring,waitfor_buffer)
  239.       if (index > 0) then do
  240.          remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  241.          waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  242.          done = 0
  243.       end
  244.       call charout , substr(waitfor_buffer,curpos)
  245.       curpos = length(waitfor_buffer)+1
  246.       if ((done \= 0) & (TIME('E')>timeout)) then do
  247.         call lineout , ' WAITFOR: timed out '
  248.         done = 1
  249.        end
  250.    end
  251.    timeout=0
  252.    RC=done
  253.  return RC
  254.  
  255.  
  256.  
  257. /*--------------------------------------------------------------------------*/
  258. /*                               readpass ()                                */
  259. /*..........................................................................*/
  260. /*                                                                          */
  261. /* Routine used to read a password from the user without echoing the        */
  262. /* password to the screen.                                                  */
  263. /*                                                                          */
  264. /*--------------------------------------------------------------------------*/
  265.  
  266. readpass:
  267.  
  268.   answer = ''
  269.   do until key = cr
  270.     key = slip_getch()
  271.     if key \= cr then do
  272.       answer = answer || key
  273.     end
  274.   end
  275.   say ''
  276.   return answer
  277.  
  278.  
  279. /*--------------------------------------------------------------------------*/
  280. /*                             flush_receive ()                             */
  281. /*..........................................................................*/
  282. /*                                                                          */
  283. /* Routine to flush any pending characters to be read from the COM port.    */
  284. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  285. /* point it returns.                                                        */
  286. /*                                                                          */
  287. /* The optional echo argument, if 1, says to echo flushed information.      */
  288. /*                                                                          */
  289. /*--------------------------------------------------------------------------*/
  290.  
  291. flush_receive:
  292.  
  293.    parse arg echo
  294.  
  295.    /* If echoing the flush - take care of waitfor remaining buffer */
  296.    if (echo \= '') & (length(remain_buffer) > 0) then do
  297.       call charout , remain_buffer
  298.       remain_buffer = ''
  299.    end
  300.  
  301.    /* Eat anything left in the modem or COM buffers */
  302.    /* Stop when nothing new appears for 100ms.      */
  303.  
  304.    do until line = ''
  305.      line = slip_com_input(interface,,100)
  306.      if echo \= '' then
  307.         call charout , line
  308.    end
  309.  
  310.    return
  311.