home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / xpress.zip / XPRESS.CMD next >
OS/2 REXX Batch file  |  1994-12-05  |  12KB  |  275 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*        OS/2 2.1 / WARP REX Driver for IBM TCP/IP version 2.0 / IAK       */
  4. /*                                                                          */
  5. /*                               EXPRESS.CMD                                */
  6. /*                                                                          */
  7. /*            ..................................................            */
  8. /*                                                                          */
  9. /*                                                                          */
  10. /* Sample script for connecting to Internet Express                         */
  11. /*                                                                          */
  12. /* Note:        This script may be modified to suit the needs of the user   */
  13. /*              and is written to process dialogs similar to those          */
  14. /*              used by many Annex type service providers.                  */
  15. /*                                                                          */
  16. /* The script parameters specify the command to send to the modem to dial   */
  17. /* the remote site and the username/password combination to use to log into */
  18. /* the terminal server.  If any of the parameters are omitted, or are       */
  19. /* specified as an asterix (*), the script will prompt for them (Refer      */
  20. /* to caveate below).  This is most useful with the password parameter to   */
  21. /* avoid storing the password in a text file on the disk.                   */
  22. /*                                                                          */
  23. /* For example, the following might be used in SlipPM:                      */
  24. /*              Login Script: express.cmd atdt999-9999 loginid password     */
  25. /*                                                                          */
  26. /* which would then feed the "atdt999-9999" command to the modem, followed  */
  27. /* by the login id and password once the connection is established.         */
  28. /*                                                                          */
  29. /* From slip directly the express script supports:                          */
  30. /*              -connect "express.cmd atdt999-9999 loginid *"               */
  31. /*                                                                          */
  32. /* which would cause express.cmd to initially prompt for the password. It   */
  33. /* would then feed the "atdt999-9999" command to the modem, and when the    */
  34. /* Annex answered, it would use "loginid" as a username and the password    */
  35. /* specified.                                                               */
  36. /*                                                                          */
  37. /* NOTE: You must pass the phone number, and both login id and password     */
  38. /*       to express.cmd from the Dialer.  The Dialer will NOT allow the     */
  39. /*       input of a phone number, login or password from the keyboard.      */
  40. /*            - - - - - - - - - - - - - - - - - - - - - - - - -             */
  41. /*                                                                          */
  42. /* When the script runs, it is automatically passed the interface name for  */
  43. /* the interface it is running on as the first argument, followed by the    */
  44. /* user arguments.                                                          */
  45. /*                                                                          */
  46. /* The script sends the dial string to the modem and then logs into the     */
  47. /* terminal server using the username/password.  It then issues the SLIP    */
  48. /* command to start SLIP, and parses the resulting output to determine the  */
  49. /* appropriate addresses to use.  Lastly, it issues ifconfig and route      */
  50. /* commands to configure the OS/2 system appropriately.  Note that the      */
  51. /* configuration assumes a class C netmask for the SLIP interface.          */
  52. /*                                                                          */
  53. /*--------------------------------------------------------------------------*/
  54.  
  55. parse arg interface , dialcmd username password
  56.  
  57. /*--------------------------------------------------------------------------*/
  58. /*                   Initialization and Main Script Code                    */
  59. /*--------------------------------------------------------------------------*/
  60.  
  61. /* Set some definitions for easier COM strings */
  62. cr='0d'x
  63. crlf='0d0a'x
  64. reset1 = 'AT&F'      /* Change to suit YOUR modem */
  65. reset2 = 'ATHZ'      /* Change to suit YOUR modem */
  66.  
  67. say ''
  68. say 'Internet Express SLIP Annex Connection Script ',
  69.     '(interface' interface')'
  70.  
  71. /* Prompt for missing information */
  72. if dialcmd = '' then do
  73.    call charout , 'Dial Command: '
  74.    parse pull dialcmd
  75. end
  76. if username = '' | username = '*' then do
  77.    call charout , 'User Name: '
  78.    parse pull username
  79. end
  80. else do
  81.    say 'User:' username
  82. end
  83. if password = '' | password = '*' then do
  84.    call charout , 'Password: '
  85.    password = readpass()
  86. end
  87.  
  88. /* Flush any stuff left over from previous COM activity */
  89. call flush_receive
  90.  
  91. /* Reset the modem here */
  92. /* You may need to customize this for your modem make and model */
  93. call lineout , 'Reset modem...'
  94. call send reset1 || cr
  95. call waitfor 'OK', 5 ; call flush_receive 'echo'
  96.  if RC = 1 then do
  97.     call lineout , 'Modem not resetting... Trying again'
  98.     call send '+++'
  99.     call waitfor 'OK'
  100.     call send reset2 || cr
  101.     call waitfor 'OK', 3
  102.   end
  103.  
  104. /* Dial the remote server */
  105. call charout , 'Now Dialing...'
  106.  
  107. /* Wait for connection */
  108. call send dialcmd || cr
  109. call waitfor 'CONNECT' ; call waitfor crlf
  110.  
  111. /* Handle login.  We wait for standard strings, and then flush anything */
  112. /* else to take care of trailing spaces, etc..                          */
  113. /* call send cr */
  114.  
  115. call waitfor 'Username:' ; call flush_receive 'echo'
  116. call send username || cr
  117. call waitfor 'Password:' ; call flush_receive 'echo'
  118. call send password || cr
  119. call waitfor 'continue';   call flush_receive 'echo'
  120. call send 'SLIP' || cr
  121.  
  122. /* Parse the results of the SLIP command to determine our address. */
  123. /* We use the "waitfor_buffer" variable from the waitfor routine   */
  124. /* to parse the stuff we get from the Annex after waiting for an   */
  125. /* appropriate point in the data stream.                           */
  126.  
  127. call waitfor 'Your address is'
  128. parse var waitfor_buffer . 'Annex address is' a '.' b '.' c '.' d '.' .
  129. annex_address = a||'.'||b||'.'||c||'.'||d
  130.  
  131. call waitfor crlf
  132. parse var waitfor_buffer  a '.' b '.' c '.' d '.' .
  133. os2_address = a||'.'||b||'.'||c||'.'||d
  134.  
  135. /* Flush anything else */
  136. call flush_receive 'echo'
  137.  
  138. /* Now configure this host for the appropriate address, */
  139. /* and for a default route through the Annex.           */
  140.  
  141. say 'SLIP Connection Established'
  142. say 'Configuring local address =' os2_address ', Annex =' annex_address
  143.  
  144. 'ifconfig sl0' os2_address annex_address 'netmask 255.255.255.0'
  145. 'route add default' annex_address '1'
  146.  
  147. /* All done */
  148. exit 0
  149.  
  150.  
  151. /*--------------------------------------------------------------------------*/
  152. /*                            send ( sendstring)                            */
  153. /*..........................................................................*/
  154. /*                                                                          */
  155. /* Routine to send a character string off to the modem.                     */
  156. /*                                                                          */
  157. /*--------------------------------------------------------------------------*/
  158.  
  159. send:
  160.  
  161.    parse arg sendstring
  162.    call slip_com_output interface , sendstring
  163.  
  164.    return
  165.  
  166.  
  167. /*--------------------------------------------------------------------------*/
  168. /*                    waitfor ( waitstring , [timeout] )                    */
  169. /*..........................................................................*/
  170. /*                                                                          */
  171. /* Waits for the supplied string to show up in the COM input.  All input    */
  172. /* from the time this function is called until the string shows up in the   */
  173. /* input is accumulated in the "waitfor_buffer" variable.                   */
  174. /*                                                                          */
  175. /* If timeout is specified, it says how long to wait if data stops showing  */
  176. /* up on the COM port (in seconds).                                                         */
  177. /*                                                                          */
  178. /*--------------------------------------------------------------------------*/
  179.  
  180. waitfor:
  181.  
  182.    parse arg waitstring , timeout
  183.  
  184.    if timeout = '' then
  185.      timeout = 5000    /* L O N G   delay if not specified */
  186.    waitfor_buffer = '' ; done = -1; curpos = 1
  187.    ORI_TIME=TIME('E')
  188.  
  189.    if (remain_buffer = 'REMAIN_BUFFER') then do
  190.       remain_buffer = ''
  191.    end
  192.  
  193.    do while (done = -1)
  194.       if (remain_buffer \= '') then do
  195.          line = remain_buffer
  196.          remain_buffer = ''
  197.        end
  198.        else do
  199.          line = slip_com_input(interface,,10)
  200.       end
  201.       waitfor_buffer = waitfor_buffer || line
  202.       index = pos(waitstring,waitfor_buffer)
  203.       if (index > 0) then do
  204.          remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  205.          waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  206.          done = 0
  207.       end
  208.       call charout , substr(waitfor_buffer,curpos)
  209.       curpos = length(waitfor_buffer)+1
  210.       if ((done \= 0) & (TIME('E')>timeout)) then do
  211.         call lineout , ' WAITFOR: timed out '
  212.         done = 1
  213.        end
  214.    end
  215.    timeout=0
  216.    RC=done
  217.  return RC
  218.  
  219.  
  220.  
  221. /*--------------------------------------------------------------------------*/
  222. /*                               readpass ()                                */
  223. /*..........................................................................*/
  224. /*                                                                          */
  225. /* Routine used to read a password from the user without echoing the        */
  226. /* password to the screen.                                                  */
  227. /*                                                                          */
  228. /*--------------------------------------------------------------------------*/
  229.  
  230. readpass:
  231.  
  232.   answer = ''
  233.   do until key = cr
  234.     key = slip_getch()
  235.     if key \= cr then do
  236.       answer = answer || key
  237.     end
  238.   end
  239.   say ''
  240.   return answer
  241.  
  242.  
  243. /*--------------------------------------------------------------------------*/
  244. /*                             flush_receive ()                             */
  245. /*..........................................................................*/
  246. /*                                                                          */
  247. /* Routine to flush any pending characters to be read from the COM port.    */
  248. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  249. /* point it returns.                                                        */
  250. /*                                                                          */
  251. /* The optional echo argument, if 1, says to echo flushed information.      */
  252. /*                                                                          */
  253. /*--------------------------------------------------------------------------*/
  254.  
  255. flush_receive:
  256.  
  257.    parse arg echo
  258.  
  259.    /* If echoing the flush - take care of waitfor remaining buffer */
  260.    if (echo \= '') & (length(remain_buffer) > 0) then do
  261.       call charout , remain_buffer
  262.       remain_buffer = ''
  263.    end
  264.  
  265.    /* Eat anything left in the modem or COM buffers */
  266.    /* Stop when nothing new appears for 100ms.      */
  267.  
  268.    do until line = ''
  269.      line = slip_com_input(interface,,100)
  270.      if echo \= '' then
  271.         call charout , line
  272.    end
  273.  
  274.    return
  275.