home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / ccsoslip.zip / CCSOSLIP.CMD next >
OS/2 REXX Batch file  |  1995-09-06  |  9KB  |  241 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*    OS/2 2.1 / WARP REXX SL/IP Dialup Script for Dynamic IP Addresses     */
  4. /*    (modified from original IBM script for UIUC CCSO Terminal Server)     */
  5. /*                       m-woo@uiuc.edu, 6 September 1995                   */
  6. /*                member of Champaign-Urbana OS/2 Users Group               */
  7. /*                    in no way affiliated with UIUC CCSO                   */
  8. /*--------------------------------------------------------------------------*/
  9.  
  10. /* Loading the REXXUtils DLLs -- okay, they hog resources, but...           */
  11. call RxFuncAdd "SysSleep", "RexxUtil", "SysSleep" 
  12.  
  13. /* If you are having trouble with your modem not hanging up, try            */
  14. /* uncommenting or adding the appropriate MODE command below                */
  15.  
  16. /* 'mode com1,,,,,dtr=on' */
  17. /* 'mode com2,,,,,dtr=on' */
  18.  
  19. /* Okay, I shouldn't have hardcoded the terminal server's phone number here */
  20. /* -- feel free to change it to an argument                                 */
  21.  
  22. /* Normal CCSO terminal server phone number */
  23. dialcmd = 'atdt333-3700' 
  24.  
  25. /* CCSO 28.8 kbps dialup phone number */
  26. /* dialcmd = 'atdt244-5109' */
  27.  
  28. /* CCSO Faculty and Staff phone number */
  29. /* dialcmd = 'atdt333-7999' */
  30.  
  31. parse arg interface , username password
  32.  
  33. /*--------------------------------------------------------------------------*/
  34. /*                   Initialization and Main Script Code                    */
  35. /*--------------------------------------------------------------------------*/
  36.  
  37. cr='0d'x
  38. crlf='0d0a'x
  39.  
  40. say ''
  41. say 'CCSO Terminal Server SLIP Connection Script ',
  42.     '(interface' interface')'
  43.  
  44. if username = '' | username = '*' then do
  45.    call charout , 'User Name: '
  46.    parse pull username
  47. end
  48. else do
  49.    say 'User:' username
  50. end
  51. if password = '' | password = '*' then do
  52.    call charout , 'Password: '
  53.    password = readpass()
  54. end
  55.  
  56. call flush_receive
  57.  
  58. call lineout , 'Reset modem...'
  59. call send 'ATZ' || cr
  60. call waitfor 'OK', 5 ; call flush_receive 'echo'
  61. call SysSleep 5
  62.  if RC = 1 then do
  63.     call lineout , 'Modem not resetting... Trying again'
  64.     call send '+++'
  65.     call waitfor 'OK'
  66.     call send 'ATHZ' || cr
  67.     call waitfor 'OK', 3
  68.   end
  69.  
  70. call charout , 'Now Dialing...'
  71.  
  72. /* Wait for connection - will redial if not online                     */
  73. /* Note: redial doesn't seem to work with the new IAK dialer :-(       */
  74.  
  75. call lineout , '  ...Dialing CCSO Terminal Server...'
  76. connected = '0'
  77. do forever until connected
  78.    call send dialcmd || cr
  79.    call waitfor 'CONNECT', 30
  80.    if pos('CONNECT',waitfor_buffer) \=0 then do
  81.       call lineout , ' ...Connected to CCSO Terminal Server'
  82.       connected = '1'
  83.       call waitfor crlf
  84.    end
  85.    call SysSleep 5
  86. end
  87.  
  88. /* Handle login.  We wait for standard strings, and then flush anything */
  89. /* else to take care of trailing spaces, etc..                          */
  90. call waitfor 'Username:' ; call flush_receive 'echo'
  91. call send username || cr
  92. call waitfor 'Password:' ; call flush_receive 'echo'
  93. call send password || cr
  94. call waitfor '>' ; call flush_receive 'echo'
  95. call send 'SLIP default' || cr
  96.  
  97. call waitfor 'Your IP address is '
  98. call waitfor '. MTU'
  99.  
  100. /* Flush anything else */
  101. call flush_receive 'echo'
  102.  
  103. 'detach bootp sl0'
  104.  
  105. /* The next line is a strange kludge that shouldn't be needed, */
  106. /* but for some reason my system won't work without it         */
  107. /* Depending on what CCSO does, the address may have to be     */
  108. /* changed in the future                                       */
  109. /* If you are having trouble, you might try using it           */
  110.  
  111. /* 'route add default 128.174.22.9 1' */
  112.  
  113. /* All done */
  114. exit 0
  115.  
  116.  
  117. /*--------------------------------------------------------------------------*/
  118. /*                            send ( sendstring)                            */
  119. /*..........................................................................*/
  120. /*                                                                          */
  121. /* Routine to send a character string off to the modem.                     */
  122. /*                                                                          */
  123. /*--------------------------------------------------------------------------*/
  124.  
  125. send:
  126.  
  127.    parse arg sendstring
  128.    call slip_com_output interface , sendstring
  129.  
  130.    return
  131.  
  132.  
  133. /*--------------------------------------------------------------------------*/
  134. /*                    waitfor ( waitstring , [timeout] )                    */
  135. /*..........................................................................*/
  136. /*                                                                          */
  137. /* Waits for the supplied string to show up in the COM input.  All input    */
  138. /* from the time this function is called until the string shows up in the   */
  139. /* input is accumulated in the "waitfor_buffer" variable.                   */
  140. /*                                                                          */
  141. /* If timeout is specified, it says how long to wait if data stops showing  */
  142. /* up on the COM port (in seconds).                                                         */
  143. /*                                                                          */
  144. /*--------------------------------------------------------------------------*/
  145.  
  146. waitfor:
  147.  
  148.    parse arg waitstring , timeout
  149.  
  150.    if timeout = '' then
  151.      timeout = 5000    /* L O N G   delay if not specified */
  152.    waitfor_buffer = '' ; done = -1; curpos = 1
  153.    ORI_TIME=TIME('E')
  154.  
  155.    if (remain_buffer = 'REMAIN_BUFFER') then do
  156.       remain_buffer = ''
  157.    end
  158.  
  159.    do while (done = -1)
  160.       if (remain_buffer \= '') then do
  161.          line = remain_buffer
  162.          remain_buffer = ''
  163.        end
  164.        else do
  165.          line = slip_com_input(interface,,10)
  166.       end
  167.       waitfor_buffer = waitfor_buffer || line
  168.       index = pos(waitstring,waitfor_buffer)
  169.       if (index > 0) then do
  170.          remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  171.          waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  172.          done = 0
  173.       end
  174.       call charout , substr(waitfor_buffer,curpos)
  175.       curpos = length(waitfor_buffer)+1
  176.       if ((done \= 0) & (TIME('E')>timeout)) then do
  177.         call lineout , ' WAITFOR: timed out '
  178.         done = 1
  179.        end
  180.    end
  181.    timeout=0
  182.    RC=done
  183.  return RC
  184.  
  185.  
  186.  
  187. /*--------------------------------------------------------------------------*/
  188. /*                               readpass ()                                */
  189. /*..........................................................................*/
  190. /*                                                                          */
  191. /* Routine used to read a password from the user without echoing the        */
  192. /* password to the screen.                                                  */
  193. /*                                                                          */
  194. /*--------------------------------------------------------------------------*/
  195.  
  196. readpass:
  197.  
  198.   answer = ''
  199.   do until key = cr
  200.     key = slip_getch()
  201.     if key \= cr then do
  202.       answer = answer || key
  203.     end
  204.   end
  205.   say ''
  206.   return answer
  207.  
  208.  
  209. /*--------------------------------------------------------------------------*/
  210. /*                             flush_receive ()                             */
  211. /*..........................................................................*/
  212. /*                                                                          */
  213. /* Routine to flush any pending characters to be read from the COM port.    */
  214. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  215. /* point it returns.                                                        */
  216. /*                                                                          */
  217. /* The optional echo argument, if 1, says to echo flushed information.      */
  218. /*                                                                          */
  219. /*--------------------------------------------------------------------------*/
  220.  
  221. flush_receive:
  222.  
  223.    parse arg echo
  224.  
  225.    /* If echoing the flush - take care of waitfor remaining buffer */
  226.    if (echo \= '') & (length(remain_buffer) > 0) then do
  227.       call charout , remain_buffer
  228.       remain_buffer = ''
  229.    end
  230.  
  231.    /* Eat anything left in the modem or COM buffers */
  232.    /* Stop when nothing new appears for 100ms.      */
  233.  
  234.    do until line = ''
  235.      line = slip_com_input(interface,,100)
  236.      if echo \= '' then
  237.         call charout , line
  238.    end
  239.  
  240.    return
  241.