home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / elron.cmd < prev    next >
OS/2 REXX Batch file  |  1995-02-03  |  13KB  |  286 lines

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