home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / ccniak.zip / HOOKED2.CMD < prev   
OS/2 REXX Batch file  |  1994-11-23  |  13KB  |  310 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. /* Set some definitions for easier COM strings */
  70. cr='0d'x
  71. crlf='0d0a'x
  72.  
  73. /*say 'HOOKED  -- Script for SLIP Dialer via TIA ('interface')'*/
  74. dialcmd = 'ATL0DT534-0841' /* MODIFY FOR YOUR TEL ACCESS NUMBER */
  75.                                     /* change L0 to M0 to turn speaker off */
  76. hostprompt= '>'                  /* MODIFY FOR YOUR HOST'S PROMT */
  77. username= 'loginname'       /* MODIFY FOR YOUR LOGIN_NAME */
  78. password= 'password'           /* MODIFY FOR YOUR PASSWORD */
  79.  
  80.  
  81. 'mode com2:dtr=on'         /* needed with some com drivers */
  82. /* Flush any stuff left over from previous COM activity */
  83. call flush_receive
  84.  
  85. /* Reset the modem here */
  86. /* You may need to customize this for your modem make and model */
  87. /*call lineout , 'Reset modem...'*/
  88.  
  89. call send 'AT&F' || cr        /* MODIFY IF NEEDED */
  90.  
  91. retry:
  92. call waitfor 'OK', 5 ; call flush_receive 'echo'
  93.  if RC = 1 then do
  94.     call lineout , 'Modem not resetting... Trying again'
  95.     call send '+++'
  96.     call waitfor 'OK'
  97.     call send 'ATHZ' || cr
  98.     call waitfor 'OK', 3
  99.   end
  100.  
  101. /* Dial the remote server */
  102. call SysSleep(1)
  103. call charout , 'Now Dialing...'
  104. call send dialcmd || cr
  105.  
  106. /* Wait for connection */
  107. RC = waitfor('CONNECT', 65); /*call flush_receive 'echo'*/
  108.  
  109. if (RC > 1) then /*busy*/
  110.     do
  111.     say 'BUSY, Retrying'
  112.     call send 'ATZ' || cr
  113.     call SysSleep(3)
  114.     signal retry
  115.     end
  116.  
  117. if (RC > 0) then /*timedout*/
  118.     do
  119.     say 'Connect: TIMED OUT'
  120.     exit 1
  121.     end
  122.  
  123. /*call waitfor crlf*/
  124. relogc = 0
  125.  
  126. call waitfor 'login:',20 ; call flush_receive 'echo'
  127. relog:
  128. call SysSleep(1)
  129. call send username || cr
  130. call waitfor 'sword:',10 ; call flush_receive 'echo'
  131. if (RC>0) then
  132.     do
  133.     relogc = relogc+1
  134.     if (relogc < 6) then
  135.         do
  136.         say 'Login/Password waiting timed out. Trying to relogin'
  137.         signal relog
  138.         end
  139.     else
  140.         do
  141.        say 'Login failed. Try again.'
  142.         exit 1
  143.         end
  144.  
  145.     end
  146.  
  147. call SysSleep(1)
  148. call send password || cr
  149. call waitfor 'TERM=',5 ; call flush_receive 'echo'
  150. call SysSleep(1)
  151. call send cr
  152.  
  153. call waitfor hostprompt ; call flush_receive 'echo'
  154. call send '/usr/local/bin/tia' || cr    /* MODIFY THE PATH FOR YOUR PROVIDER*/
  155. call waitfor 'software.' ; call flush_receive 'echo'
  156.  
  157. say 'SLIP Connection Established'
  158.  
  159.  
  160. /* slip configuration with the hooked specific fixed ip */
  161.    
  162. ip = '199.2.134.2'    /* MODIFY FOR YOUR PROVIDER's IP ADDRESS if not Hooked */
  163. os2_address = ip
  164. hooked_address = ip
  165. netmask = '0.0.0.0'    /* MODIFY FOR YOUR PROVIDER's MASK ADDRESS if not Hooked */
  166.  
  167.  
  168. say 'Configuring local address =' os2_address ', Hooked =' hooked_address
  169.  
  170. 'ifconfig sl0' ip ip 'netmask' netmask
  171. 'route add default' hooked_address '1'
  172.  
  173. /* All done */
  174. exit 0
  175.  
  176.  
  177. /*--------------------------------------------------------------------------*/
  178. /*                            send ( sendstring)                            */
  179. /*..........................................................................*/
  180. /*                                                                          */
  181. /* Routine to send a character string off to the modem.                     */
  182. /*                                                                          */
  183. /*--------------------------------------------------------------------------*/
  184.  
  185. send:
  186.  
  187.    parse arg sendstring
  188.    call slip_com_output interface , sendstring
  189.  
  190.    return
  191.  
  192.  
  193. /*--------------------------------------------------------------------------*/
  194. /*                    waitfor ( waitstring , [timeout] )                    */
  195. /*..........................................................................*/
  196. /*                                                                          */
  197. /* Waits for the supplied string to show up in the COM input.  All input    */
  198. /* from the time this function is called until the string shows up in the   */
  199. /* input is accumulated in the "waitfor_buffer" variable.                   */
  200. /*                                                                          */
  201. /* If timeout is specified, it says how long to wait if data stops showing  */
  202. /* up on the COM port (in seconds).                                         */
  203. /*                                                                          */
  204. /*--------------------------------------------------------------------------*/
  205.  
  206. waitfor:
  207.  
  208.    parse arg waitstring , timeout
  209.  
  210.    if timeout = '' then
  211.      timeout = 5000    /* L O N G   delay if not specified */
  212.    waitfor_buffer = '' ; done = -1; curpos = 1
  213.    ORI_TIME=TIME('E')
  214.  
  215.    if (remain_buffer = 'REMAIN_BUFFER') then do
  216.       remain_buffer = ''
  217.    end
  218.  
  219.     done = -1
  220.    do while (done == -1)
  221.       if (remain_buffer \= '') then do
  222.          line = remain_buffer
  223.          remain_buffer = ''
  224.        end
  225.        else do
  226.          line = slip_com_input(interface,,10)
  227.       end
  228.  
  229.       waitfor_buffer = waitfor_buffer || line
  230.  
  231.       index = pos('BUSY',waitfor_buffer)
  232.       if (index > 0) then do
  233.          RC = 2
  234.             return RC
  235.       end
  236.  
  237.       index = pos(waitstring,waitfor_buffer)
  238.       if (index > 0) then do
  239.          remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  240.          waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  241.          done = 0
  242.       end
  243.       call charout , substr(waitfor_buffer,curpos)
  244.       curpos = length(waitfor_buffer)+1
  245.       if ((done \= 0) & (TIME('E')>timeout)) then do
  246.         call lineout , ' WAITFOR: timed out '
  247.         done = 1
  248.        end
  249.    end
  250.    timeout=0
  251.    RC=done
  252.  return RC
  253.  
  254.  
  255.  
  256. /*--------------------------------------------------------------------------*/
  257. /*                               readpass ()                                */
  258. /*..........................................................................*/
  259. /*                                                                          */
  260. /* Routine used to read a password from the user without echoing the        */
  261. /* password to the screen.                                                  */
  262. /*                                                                          */
  263. /*--------------------------------------------------------------------------*/
  264.  
  265. readpass:
  266.  
  267.   answer = ''
  268.   do until key = cr
  269.     key = slip_getch()
  270.     if key \= cr then do
  271.       answer = answer || key
  272.     end
  273.   end
  274.   say ''
  275.   return answer
  276.  
  277.  
  278. /*--------------------------------------------------------------------------*/
  279. /*                             flush_receive ()                             */
  280. /*..........................................................................*/
  281. /*                                                                          */
  282. /* Routine to flush any pending characters to be read from the COM port.    */
  283. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  284. /* point it returns.                                                        */
  285. /*                                                                          */
  286. /* The optional echo argument, if 1, says to echo flushed information.      */
  287. /*                                                                          */
  288. /*--------------------------------------------------------------------------*/
  289.  
  290. flush_receive:
  291.  
  292.    parse arg echo
  293.  
  294.    /* If echoing the flush - take care of waitfor remaining buffer */
  295.    if (echo \= '') & (length(remain_buffer) > 0) then do
  296.       call charout , remain_buffer
  297.       remain_buffer = ''
  298.    end
  299.  
  300.    /* Eat anything left in the modem or COM buffers */
  301.    /* Stop when nothing new appears for 100ms.      */
  302.  
  303.    do until line = ''
  304.      line = slip_com_input(interface,,100)
  305.      if echo \= '' then
  306.         call charout , line
  307.    end
  308.  
  309.    return
  310.