home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / infine.cmd < prev    next >
OS/2 REXX Batch file  |  1995-04-04  |  14KB  |  307 lines

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