home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / slip-cm.zip / ANSRemote.CMD next >
OS/2 REXX Batch file  |  1994-03-30  |  11KB  |  269 lines

  1. /*--------------------------------------------------------------------------*/
  2. /* Connect to ANSRemote/IP service                                          */
  3. /*                                                                          */
  4. /*     This script provides an automatic login capability for ANS'          */
  5. /*     ANSRemote/IP service.                                                */
  6. /*                                                                          */
  7. /*     This script is essentially SLIPUP.CMD as supplied with TCP/IP V2.    */
  8. /*     One important modification was to change the Annex command prompt    */
  9. /*     to the prompt issued by the ANSRemote terminal servers               */
  10. /*                                                                          */
  11. /*     Dependencies:                                                        */
  12. /*                                                                          */
  13. /*     1. TCP/IP for OS/2 V2 (may work on previous versions but not tested) */
  14. /*                                                                          */
  15. /*     2, David Bolen's SLIP driver as supplied with TCP/IP for OS/2 V2     */
  16. /*                                                                          */
  17. /*     3. Assumes SLIP-only connection environment (no NICs).               */
  18. /*                                                                          */
  19. /*--------------------------------------------------------------------------*/
  20.  
  21. trace OFF
  22.  
  23.   entry = time(reset)
  24.  
  25.   parse arg interface , parameters
  26.  
  27.   signal on HALT name CLEANUP
  28.   signal on SYNTAX name CLEANUP
  29.   signal on FAILURE name CLEANUP
  30.  
  31. /*--------------------------------------------------------------------------*/
  32. /* Set up modem                                                             */
  33. /*--------------------------------------------------------------------------*/
  34.  
  35.  '@MODE COM1:38400,n,8,1,BUFFER=ON,RTS=HS,TO=OFF,IDSR=OFF,OCTS=ON,' ||,
  36.    'XON=OFF,ODSR=OFF,DTR=ON'
  37.  
  38.   cr = '0D'x
  39.   crlf = '0D0A'x
  40.  
  41. /*--------------------------------------------------------------------------*/
  42. /* Prompt the user to enter username, passwords, dial command               */
  43. /*--------------------------------------------------------------------------*/
  44.  
  45.    SLIP_user = Value('SLIP.USERNAME',, 'OS2ENVIRONMENT')
  46.    SLIP_dial = Value('SLIP.DIAL_STRING',, 'OS2ENVIRONMENT')
  47.    SLIP_pw = Value('SLIP.PASSWORD',, 'OS2ENVIRONMENT')
  48.  
  49.    if (SLIP_user == "") | (SLIP_dial == "") | (SLIP_pw == "") then
  50.      signal cleanup
  51.  
  52. /*--------------------------------------------------------------------------*/
  53. /* Get rid of prior activity, then issue dial command                       */
  54. /*--------------------------------------------------------------------------*/
  55.  
  56.   call flush_receive
  57.  
  58.   call send SLIP_dial || cr
  59.   call waitfor 'CONNECT'
  60.   call waitfor crlf
  61.  
  62. /*--------------------------------------------------------------------------*/
  63. /* Send username and password when prompted                                 */
  64. /*--------------------------------------------------------------------------*/
  65.  
  66.   call send cr
  67.  
  68.   call waitfor 'Username:' 
  69.   call flush_receive 'echo'
  70.   call send SLIP_user || cr
  71.  
  72.   call waitfor 'Password:'
  73.   call flush_receive 'echo'
  74.   call send SLIP_pw || cr
  75.  
  76. /*--------------------------------------------------------------------------*/
  77. /* When main prompt received, put us in SLIP mode                           */
  78. /*--------------------------------------------------------------------------*/
  79.  
  80.   call waitfor 'ANSRemote>'
  81.   call flush_receive 'echo'
  82.   call send 'slip' || cr
  83.  
  84. /*--------------------------------------------------------------------------*/
  85. /* Get terminal server and our IP address                                   */
  86. /*--------------------------------------------------------------------------*/
  87.  
  88.   call waitfor 'Your address is'
  89.  
  90.   parse var waitfor_buffer,
  91.     . 'Annex address is' one '.' two '.' three '.' four '.' .
  92.  
  93.   remote = (one || '.' || two || '.' || three || '.' || four)
  94.  
  95.   call waitfor crlf
  96.  
  97.   parse var waitfor_buffer,
  98.     one '.' two '.' three '.' four '.' .
  99.  
  100.   local = (one || '.' || two || '.' || three || '.' || four)
  101.  
  102.   call flush_receive 'echo'
  103.  
  104. /*--------------------------------------------------------------------------*/
  105. /* Tell the user what addresses we found, and configure the interface       */
  106. /*--------------------------------------------------------------------------*/
  107.  
  108.   call display_parameters local, remote
  109.  
  110.  '@ifconfig' interface local remote 'netmask 255.255.0.0'
  111.  '@route -f add default' remote '1'
  112.  
  113. /*--------------------------------------------------------------------------*/
  114. /* Common exit routine                                                      */
  115. /*--------------------------------------------------------------------------*/
  116.  
  117. CLEANUP:
  118.  
  119. exit 0
  120.  
  121.  
  122. /*--------------------------------------------------------------------------*/
  123. /*                            send ( sendstring)                            */
  124. /*..........................................................................*/
  125. /*                                                                          */
  126. /* Routine to send a character string off to the modem.                     */
  127. /*                                                                          */
  128. /*--------------------------------------------------------------------------*/
  129.  
  130. send:
  131.  
  132.    parse arg sendstring
  133.    call slip_com_output interface , sendstring
  134.  
  135.    return
  136.  
  137.  
  138. /*--------------------------------------------------------------------------*/
  139. /*                    waitfor ( waitstring , [timeout] )                    */
  140. /*..........................................................................*/
  141. /*                                                                          */
  142. /* Waits for the supplied string to show up in the COM input.  All input    */
  143. /* from the time this function is called until the string shows up in the   */
  144. /* input is accumulated in the "waitfor_buffer" variable.                   */
  145. /*                                                                          */
  146. /* If timeout is specified, it says how long to wait if data stops showing  */
  147. /* up on the COM port (in seconds).                                                         */
  148. /*                                                                          */
  149. /*--------------------------------------------------------------------------*/
  150.  
  151. waitfor:
  152.  
  153.    parse arg waitstring , timeout
  154.  
  155.    if timeout = '' then
  156.      timeout = 5000    /* L O N G   delay if not specified */
  157.    waitfor_buffer = '' ; done = -1; curpos = 1
  158.    ORI_TIME=TIME('E')
  159.  
  160.    if (remain_buffer = 'REMAIN_BUFFER') then do
  161.       remain_buffer = ''
  162.    end
  163.  
  164.    do while (done = -1)
  165.       if (remain_buffer \= '') then do
  166.          line = remain_buffer
  167.          remain_buffer = ''
  168.        end
  169.        else do
  170.          line = slip_com_input(interface,,10)
  171.       end
  172.       waitfor_buffer = waitfor_buffer || line
  173.       index = pos(waitstring,waitfor_buffer)
  174.       if (index > 0) then do
  175.          remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  176.          waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  177.          done = 0
  178.       end
  179.       call charout , substr(waitfor_buffer,curpos)
  180.       curpos = length(waitfor_buffer)+1
  181.       if ((done \= 0) & (TIME('E')>timeout)) then do
  182.         call lineout , ' WAITFOR: timed out '
  183.         done = 1
  184.        end
  185.    end
  186.    timeout=0
  187.    RC=done
  188.  return RC
  189.  
  190.  
  191.  
  192. /*--------------------------------------------------------------------------*/
  193. /*                               readpass ()                                */
  194. /*..........................................................................*/
  195. /*                                                                          */
  196. /* Routine used to read a password from the user without echoing the        */
  197. /* password to the screen.                                                  */
  198. /*                                                                          */
  199. /*--------------------------------------------------------------------------*/
  200.  
  201. readpass:
  202.  
  203.   answer = ''
  204.   do until key = cr
  205.     key = slip_getch()
  206.     if key \= cr then do
  207.       answer = answer || key
  208.     end
  209.   end
  210.   say ''
  211.   return answer
  212.  
  213.  
  214. /*--------------------------------------------------------------------------*/
  215. /*                             flush_receive ()                             */
  216. /*..........................................................................*/
  217. /*                                                                          */
  218. /* Routine to flush any pending characters to be read from the COM port.    */
  219. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  220. /* point it returns.                                                        */
  221. /*                                                                          */
  222. /* The optional echo argument, if 1, says to echo flushed information.      */
  223. /*                                                                          */
  224. /*--------------------------------------------------------------------------*/
  225.  
  226. flush_receive:
  227.  
  228.    parse arg echo
  229.  
  230.    /* If echoing the flush - take care of waitfor remaining buffer */
  231.    if (echo \= '') & (length(remain_buffer) > 0) then do
  232.       call charout , remain_buffer
  233.       remain_buffer = ''
  234.    end
  235.  
  236.    /* Eat anything left in the modem or COM buffers */
  237.    /* Stop when nothing new appears for 100ms.      */
  238.  
  239.    do until line = ''
  240.      line = slip_com_input(interface,,100)
  241.      if echo \= '' then
  242.         call charout , line
  243.    end
  244.  
  245.    return
  246.  
  247. /*--------------------------------------------------------------------------*/
  248. /*                          display_parameters()                            */
  249. /*--------------------------------------------------------------------------*/
  250.  
  251. display_parameters: procedure
  252.  
  253.   parse arg local, remote
  254.  
  255.   time = format(time(elapsed), 4, 2)
  256.  
  257.   msg.0 = 5
  258.   msg.1 = '   SLIP connection successfully completed'
  259.   msg.2 = '   in' time 'seconds...'
  260.   msg.3 = ' '
  261.   msg.4 = '   Local IP address  =' local
  262.   msg.5 = '   Remote IP address =' remote
  263.  
  264.   do out = 1 to msg.0
  265.     call lineout , msg.out
  266.   end out
  267.  
  268. return 
  269.