home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 29 Fixes_o / 29-Fixes_o.zip / tcpcsd2.zip / BASECSD2.EXE / BIN / FONUSER.CMD < prev    next >
OS/2 REXX Batch file  |  1993-07-16  |  8KB  |  207 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                OS/2 2.0 SLIP Driver for IBM TCP/IP version 2.0           */
  4. /*                                                                          */
  5. /*                               FONUSER.CMD                                */
  6. /*                                                                          */
  7. /*            ..................................................            */
  8. /*                                                                          */
  9. /* Sample attachment script for dialing into a system w/o password          */
  10. /* protection.  This script should be specified using the "attachcmd" and   */
  11. /* "attachparm" elements in SLIP.CFG file.                                  */
  12. /*                                                                          */
  13. /*              interface sl0 {                                             */
  14. /*                 attachcmd  = fonuser.cmd                                 */
  15. /*                 attachparm = "dialcmd"                                   */
  16. /*              }                                                           */
  17. /*                                                                          */
  18. /*            - - - - - - - - - - - - - - - - - - - - - - - - -             */
  19. /*                                                                          */
  20. /* When the script runs, it is automatically passed the interface name for  */
  21. /* the interface it is running on as the first argument, and the user       */
  22. /* arguments (from SLIP.CFG) as the second argument.                        */
  23. /*                                                                          */
  24. /*                                                                          */
  25. /*--------------------------------------------------------------------------*/
  26.  
  27. parse arg interface , dialcmd
  28.  
  29. /*--------------------------------------------------------------------------*/
  30. /*                   Initialization and Main Script Code                    */
  31. /*--------------------------------------------------------------------------*/
  32.  
  33. /* Set some definitions for easier COM strings */
  34. cr='0d'x
  35. crlf='0d0a'x
  36. timeout = 0
  37.  
  38. say ''
  39. say 'FONUSER - SLIP Script ',
  40.     '(interface' interface')'
  41.  
  42. 'mode com1 38400,n,8,1,buffer=on'
  43. /* Prompt for missing information */
  44. if dialcmd = '' then do
  45.    call charout , 'Dial Command: '
  46.    parse pull dialcmd
  47. end
  48.  
  49. /* Flush any stuff left over from previous COM activity */
  50. call flush_receive
  51.  
  52. /* Dial the remote server */
  53. call lineout , 'Reset modem...'
  54. call send 'ATZ' || cr
  55. call waitfor 'OK', 5 ; call flush_receive 'echo'
  56.  if RC = 1 then do
  57.     call lineout , 'Modem not resetting... Trying again'
  58.     call send '+++'
  59.     call waitfor 'OK'
  60.     call send 'ATHZ' || cr
  61.     call waitfor 'OK', 3
  62.   end
  63.  
  64. /* Wait for connection */
  65. call lineout , 'Now Dialing...'
  66. call send dialcmd || cr
  67. call waitfor 'CONNECT', 40 ; call waitfor crlf , 2
  68.  if RC = 1 then do
  69.     call lineout , ' Unable to connect exit from FONUSER '
  70.     exit(2)
  71.   end
  72.   else do
  73.     /* Flush anything else */
  74.     call flush_receive 'echo'
  75.     /* Now configure this host for the appropriate address, */
  76.     'ifconfig sl0 222.222.222.10 222.222.222.20 netmask 255.255.255.0'
  77.     'route -f add default' 222.222.222.20 '1'
  78.     /* All done */
  79.     exit 0
  80.   end
  81.  
  82.  
  83.  
  84.  
  85. /*--------------------------------------------------------------------------*/
  86. /*                            send ( sendstring)                            */
  87. /*..........................................................................*/
  88. /*                                                                          */
  89. /* Routine to send a character string off to the modem.                     */
  90. /*                                                                          */
  91. /*--------------------------------------------------------------------------*/
  92.  
  93. send:
  94.  
  95.    parse arg sendstring
  96.    call slip_com_output interface , sendstring
  97.  
  98.    return
  99.  
  100. /*--------------------------------------------------------------------------*/
  101. /*                    waitfor ( waitstring , [timeout] )                    */
  102. /*..........................................................................*/
  103. /*                                                                          */
  104. /* Waits for the supplied string to show up in the COM input.  All input    */
  105. /* from the time this function is called until the string shows up in the   */
  106. /* input is accumulated in the "waitfor_buffer" variable.                   */
  107. /*                                                                          */
  108. /* If timeout is specified, it says how long to wait if data stops showing  */
  109. /* up on the COM port (in seconds).                                                         */
  110. /*                                                                          */
  111. /*--------------------------------------------------------------------------*/
  112.  
  113. waitfor:
  114.  
  115.    parse arg waitstring , timeout
  116.  
  117.    if timeout = '' then
  118.      timeout = 5000    /* L O N G   delay if not specified */
  119.    waitfor_buffer = '' ; done = -1; curpos = 1
  120.    ORI_TIME=TIME('E')
  121.  
  122.    if (remain_buffer = 'REMAIN_BUFFER') then do
  123.       remain_buffer = ''
  124.    end
  125.  
  126.    do while (done = -1)
  127.       if (remain_buffer \= '') then do
  128.          line = remain_buffer
  129.          remain_buffer = ''
  130.        end
  131.        else do
  132.          line = slip_com_input(interface,,10)
  133.       end
  134.       waitfor_buffer = waitfor_buffer || line
  135.       index = pos(waitstring,waitfor_buffer)
  136.       if (index > 0) then do
  137.          remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  138.          waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  139.          done = 0
  140.       end
  141.       call charout , substr(waitfor_buffer,curpos)
  142.       curpos = length(waitfor_buffer)+1
  143.       if ((done \= 0) & (TIME('E')>timeout)) then do
  144.         call lineout , ' WAITFOR: timed out '
  145.         done = 1
  146.        end
  147.    end
  148.    timeout=0
  149.    RC=done
  150.  return RC
  151.  
  152.  
  153. /*--------------------------------------------------------------------------*/
  154. /*                               readpass ()                                */
  155. /*..........................................................................*/
  156. /*                                                                          */
  157. /* Routine used to read a password from the user without echoing the        */
  158. /* password to the screen.                                                  */
  159. /*                                                                          */
  160. /*--------------------------------------------------------------------------*/
  161.  
  162. readpass:
  163.  
  164.   answer = ''
  165.   do until key = cr
  166.     key = slip_getch()
  167.     if key \= cr then do
  168.       answer = answer || key
  169.     end
  170.   end
  171.   say ''
  172.   return answer
  173.  
  174.  
  175. /*--------------------------------------------------------------------------*/
  176. /*                             flush_receive ()                             */
  177. /*..........................................................................*/
  178. /*                                                                          */
  179. /* Routine to flush any pending characters to be read from the COM port.    */
  180. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  181. /* point it returns.                                                        */
  182. /*                                                                          */
  183. /* The optional echo argument, if 1, says to echo flushed information.      */
  184. /*                                                                          */
  185. /*--------------------------------------------------------------------------*/
  186.  
  187. flush_receive:
  188.  
  189.    parse arg echo
  190.  
  191.    /* If echoing the flush - take care of waitfor remaining buffer */
  192.    if (echo \= '') & (length(remain_buffer) > 0) then do
  193.       call charout , remain_buffer
  194.       remain_buffer = ''
  195.    end
  196.  
  197.    /* Eat anything left in the modem or COM buffers */
  198.    /* Stop when nothing new appears for 100ms.      */
  199.  
  200.    do until line = ''
  201.      line = slip_com_input(interface,,100)
  202.      if echo \= '' then
  203.         call charout , line
  204.    end
  205.  
  206.    return
  207.