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

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*       OS/2 2.1 / WARP REXX Driver for IBM TCP/IP version 2.0 / IAK       */
  4. /*                                                                          */
  5. /*                               INTERNEX.CMD                               */
  6. /*                                    1.0                                   */
  7. /*            Multi-number redialing connection script for SlipPm           */
  8. /*                          written by Tim Charron                          */
  9. /*                              tcharron@io.org                             */
  10. /*                                                                          */
  11. /*                              December 3 1994                             */
  12. /*                                                                          */
  13. /*            ..................................................            */
  14. /*                                                                          */
  15. /* This script is an extension of the ANNEX.CMD script supplied with        */
  16. /* OS/2 WARP.  It has redial capability built in.  It will attempt redials  */
  17. /* until a connection is completed.                                         */
  18. /*                                                                          */
  19. /* This script should be specified on page 1 in the Login Script field for  */
  20. /* connections via SlipPm, or using the -connect option if executing slip   */
  21. /* directly.                                                                */
  22. /*                                                                          */
  23. /* As well, the specific phone numbers to dial should be identified in the  */
  24. /* script below, if you should have multiple numbers to dial.               */
  25. /*                                                                          */
  26. /* You may want to change the modem initialization string.  See the file    */
  27. /* MODEM.LST in the TCPIP\ETC directory.                                    */
  28. /*                                                                          */
  29. /* The script parameters specify the username/password combination to use   */
  30. /* to log into the terminal server.                                         */
  31. /*                                                                          */
  32. /* The following should be used in SlipPM:                                  */
  33. /*              Login Script: internex.cmd loginid password                 */
  34. /*                                                                          */
  35. /*            - - - - - - - - - - - - - - - - - - - - - - - - -             */
  36. /*                                                                          */
  37. /* When the script runs, it is automatically passed the interface name for  */
  38. /* the interface it is running on as the first argument, followed by the    */
  39. /* user arguments.                                                          */
  40. /*                                                                          */
  41. /* The script sends the dial string to the modem and then logs into the     */
  42. /* terminal server using the username/password.  It then issues the SLIP    */
  43. /* command to start SLIP, and parses the resulting output to determine the  */
  44. /* appropriate addresses to use.  Lastly, it issues ifconfig and route      */
  45. /* commands to configure the OS/2 system appropriately.  Note that the      */
  46. /* configuration assumes a class C netmask for the SLIP interface.          */
  47. /*                                                                          */
  48. /*--------------------------------------------------------------------------*/
  49.  
  50. parse arg interface , username password
  51.  
  52. /*--------------------------------------------------------------*/
  53. /* Enter the addresses of your machine and host here            */
  54. /*--------------------------------------------------------------*/
  55. os2_address=199.###.###.###
  56. remote_address=198.133.36.254
  57. netmask=255.255.255.0
  58.  
  59. /*--------------------------------------------------------------*/
  60. /* Enter the PHONE NUMBERS here, and the total number of phone  */
  61. /* numbers in dialcmd.0.  waittime is how many seconds to wait  */
  62. /* for a connection.                                            */
  63. /*--------------------------------------------------------------*/
  64. dialcmd.0=2
  65. dialcmd.1="ATDT 7W 416-363-4621"
  66. dialcmd.2="ATDT 7W 416-363-4151"
  67. waittime=50
  68.  
  69. /* ------------------------------------------------------------ */
  70. /* Customize this for for your modem make and model             */
  71. /* ------------------------------------------------------------ */
  72. /* PPI modem */
  73. modemreset1="ATI2"
  74. modemreset2="ATE1L0M0N1Q0V1W2X4Y0&C1&D2&K3&Q5&R0&S1S7=60"
  75.  
  76. /*--------------------------------------------------------------------------*/
  77. /*                   Initialization and Main Script Code                    */
  78. /*--------------------------------------------------------------------------*/
  79.  
  80. /* Set some definitions for easier COM strings */
  81. cr='0d'x
  82. crlf='0d0a'x
  83.  
  84. say ''
  85. say 'INTERNEX - autodialing Script ',
  86.     '(interface' interface')'
  87.  
  88. /* Prompt for missing information */
  89. if dialcmd.1 = '' then do
  90.    call charout , 'Dial Command: '
  91.    parse pull dialcmd
  92. end
  93. if username = '' | username = '*' then do
  94.    call charout , 'User Name: '
  95.    parse pull username
  96. end
  97. else do
  98.    say 'User:' username
  99. end
  100. if password = '' | password = '*' then do
  101.    call charout , 'Password: '
  102.    password = readpass()
  103. end
  104.  
  105. dialcount=0
  106. redialit:
  107. /* Flush any stuff left over from previous COM activity */
  108. /* Each flush_receive will give a .1 second pause. Some modems may require */
  109. /* a longer break between redials */
  110. call flush_receive 'echo'
  111. call flush_receive 'echo'
  112.  
  113. /* Reset the modem here */
  114. call lineout , 'Reset modem...'
  115. call send modemreset1 || cr
  116. call waitfor 'OK', 5 ; call flush_receive 'echo'
  117.  if RC = 1 then do
  118.     call lineout , 'Modem not resetting... Trying again'
  119.     call send '+++'
  120.     call waitfor 'OK', 3
  121.     call send 'ATHZ' || cr
  122.     call waitfor 'OK', 3
  123.     call send modemreset1 || cr
  124.     call waitfor 'OK', 5 ; call flush_receive 'echo'
  125.   end
  126. call send modemreset2 || cr
  127. call waitfor 'OK', 5 ; call flush_receive 'echo'
  128.  if RC = 1 then do
  129.     call lineout , 'Modem not resetting... Trying again'
  130.     call send '+++'
  131.     call waitfor 'OK', 3
  132.     call send 'ATHZ' || cr
  133.     call waitfor 'OK', 3
  134.     call send modemreset2 || cr
  135.     call waitfor 'OK', 5 ; call flush_receive 'echo'
  136.   end
  137.  
  138. /* Dial the remote server */
  139.  
  140. /* Determine which phone number to dial */
  141. dialcount=dialcount+1
  142. if dialcount > dialcmd.0 then
  143. do
  144.    dialcount=1
  145. end
  146. dialwhat=dialcmd.dialcount
  147. call charout , 'Now Dialing...'dialwhat
  148.  
  149. /* Wait for connection */
  150. call send dialwhat || cr
  151. call waitfor2 'CONNECT','BUSY',waittime
  152.  if RC = 1 then do
  153.     call lineout , 'No answer... Trying again'
  154.     signal redialit
  155.  end
  156. call waitfor crlf , 4
  157.  
  158. /* Handle login.  We wait for standard strings, and then flush anything */
  159. /* else to take care of trailing spaces, etc..                          */
  160. /* call send cr */
  161. call waitfor 'ogin:' ; call flush_receive 'echo'
  162. call send username || cr
  163. call waitfor 'assword:' ; call flush_receive 'echo'
  164. call send password || cr
  165.  
  166. /* Flush anything else */
  167. call flush_receive 'echo'
  168.  
  169. /* Now configure this host for the appropriate address, */
  170. /* and for a default route */
  171.  
  172. say 'SLIP Connection Established'
  173. say 'Configuring local address =' os2_address ', Remote =' remote_address
  174.  
  175. 'ifconfig sl0' os2_address remote_address 'netmask ' netmask
  176. 'route add default' remote_address '1'
  177.  
  178. /* All done */
  179. exit 0
  180.  
  181.  
  182. /*--------------------------------------------------------------------------*/
  183. /*                            send ( sendstring)                            */
  184. /*..........................................................................*/
  185. /*                                                                          */
  186. /* Routine to send a character string off to the modem.                     */
  187. /*                                                                          */
  188. /*--------------------------------------------------------------------------*/
  189.  
  190. send:
  191.  
  192.    parse arg sendstring
  193.    call slip_com_output interface , sendstring
  194.  
  195.    return
  196.  
  197.  
  198. /*--------------------------------------------------------------------------*/
  199. /*                    waitfor ( waitstring , [timeout] )                    */
  200. /*..........................................................................*/
  201. /*                                                                          */
  202. /* Waits for the supplied string to show up in the COM input.  All input    */
  203. /* from the time this function is called until the string shows up in the   */
  204. /* input is accumulated in the "waitfor_buffer" variable.                   */
  205. /*                                                                          */
  206. /* If timeout is specified, it says how long to wait if data stops showing  */
  207. /* up on the COM port (in seconds).                                         */
  208. /*                                                                          */
  209. /*--------------------------------------------------------------------------*/
  210.  
  211. waitfor:
  212.  
  213.    parse arg waitstring , timeout
  214.  
  215.    if timeout = '' then
  216.      timeout = 5000    /* L O N G   delay if not specified */
  217.    waitfor_buffer = '' ; done = -1; curpos = 1
  218.    ORI_TIME=TIME('E')
  219.  
  220.    if (remain_buffer = 'REMAIN_BUFFER') then do
  221.       remain_buffer = ''
  222.    end
  223.  
  224.    do while (done = -1)
  225.       if (remain_buffer \= '') then do
  226.          line = remain_buffer
  227.          remain_buffer = ''
  228.        end
  229.        else do
  230.          line = slip_com_input(interface,,10)
  231.       end
  232.       waitfor_buffer = waitfor_buffer || line
  233.       index = pos(waitstring,waitfor_buffer)
  234.       if (index > 0) then do
  235.          remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  236.          waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  237.          done = 0
  238.       end
  239.       call charout , substr(waitfor_buffer,curpos)
  240.       curpos = length(waitfor_buffer)+1
  241.       if ((done \= 0) & (TIME('E')>timeout)) then do
  242.         call lineout , ' WAITFOR: timed out '
  243.         done = 1
  244.        end
  245.    end
  246.    timeout=0
  247.    RC=done
  248.  return RC
  249.  
  250. /*--------------------------------------------------------------------------*/
  251. /*                waitfor2 ( waitstring , killstring, [timeout] )           */
  252. /*                modified copy of waitfor by Tim Charron 12/01/94          */
  253. /*..........................................................................*/
  254. /*                                                                          */
  255. /* Waits for the supplied string to show up in the COM input.  All input    */
  256. /* from the time this function is called until the string shows up in the   */
  257. /* input is accumulated in the "waitfor_buffer" variable.                   */
  258. /*                                                                          */
  259. /* If timeout is specified, it says how long to wait if data stops showing  */
  260. /* up on the COM port (in seconds).                                         */
  261. /*                                                                          */
  262. /* If killstring shows up, exits with error */
  263. /*--------------------------------------------------------------------------*/
  264.  
  265. waitfor2:
  266.  
  267.    parse arg waitstring , killstring, timeout
  268.  
  269.    if timeout = '' then
  270.      timeout = 5000    /* L O N G   delay if not specified */
  271.    waitfor_buffer = '' ; done = -1; curpos = 1
  272.    ORI_TIME=TIME('E')
  273.  
  274.    if (remain_buffer = 'REMAIN_BUFFER') then do
  275.       remain_buffer = ''
  276.    end
  277.  
  278.    do while (done = -1)
  279.       if (remain_buffer \= '') then do
  280.          line = remain_buffer
  281.          remain_buffer = ''
  282.        end
  283.        else do
  284.          line = slip_com_input(interface,,10)
  285.       end
  286.       waitfor_buffer = waitfor_buffer || line
  287.       index = pos(waitstring,waitfor_buffer)
  288.       if (index > 0) then do
  289.          remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  290.          waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  291.          done = 0
  292.       end
  293.       index = pos(killstring,waitfor_buffer)
  294.       call charout , substr(waitfor_buffer,curpos)
  295.       curpos = length(waitfor_buffer)+1
  296.        if ((done \= 0) & (TIME('E')>timeout)) then do
  297.         call lineout , ' WAITFOR2: timed out ' 
  298.         done = 1
  299.        end
  300.        if ((done \= 0) & (index > 0)) then do
  301. /*        call lineout , ' WAITFOR2: kill string detected' */
  302.         done = 1
  303.        end
  304.    end
  305.    timeout=0
  306.    RC=done
  307.  return RC
  308.  
  309.  
  310.  
  311. /*--------------------------------------------------------------------------*/
  312. /*                               readpass ()                                */
  313. /*..........................................................................*/
  314. /*                                                                          */
  315. /* Routine used to read a password from the user without echoing the        */
  316. /* password to the screen.                                                  */
  317. /*                                                                          */
  318. /*--------------------------------------------------------------------------*/
  319.  
  320. readpass:
  321.  
  322.   answer = ''
  323.   do until key = cr
  324.     key = slip_getch()
  325.     if key \= cr then do
  326.       answer = answer || key
  327.     end
  328.   end
  329.   say ''
  330.   return answer
  331.  
  332.  
  333. /*--------------------------------------------------------------------------*/
  334. /*                             flush_receive ()                             */
  335. /*..........................................................................*/
  336. /*                                                                          */
  337. /* Routine to flush any pending characters to be read from the COM port.    */
  338. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  339. /* point it returns.                                                        */
  340. /*                                                                          */
  341. /* The optional echo argument, if 1, says to echo flushed information.      */
  342. /*                                                                          */
  343. /*--------------------------------------------------------------------------*/
  344.  
  345. flush_receive:
  346.  
  347.    parse arg echo
  348.  
  349.    /* If echoing the flush - take care of waitfor remaining buffer */
  350.    if (echo \= '') & (length(remain_buffer) > 0) then do
  351.       call charout , remain_buffer
  352.       remain_buffer = ''
  353.    end
  354.  
  355.    /* Eat anything left in the modem or COM buffers */
  356.    /* Stop when nothing new appears for 100ms.      */
  357.  
  358.    do until line = ''
  359.      line = slip_com_input(interface,,100)
  360.      if echo \= '' then
  361.         call charout , line
  362.    end
  363. return
  364.  
  365.