home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / transpac.cmd < prev    next >
OS/2 REXX Batch file  |  1996-04-10  |  10KB  |  247 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*       OS/2 2.1 / WARP REXX Driver for IBM TCP/IP version 2.0 / IAK       */
  4. /*                                                                          */
  5. /*                              TRANSPAC.CMD                                */
  6. /*                                                                          */
  7. /*            ..................................................            */
  8. /*                                                                          */
  9. /* Attachment script for dialing into CIS via PPP, through the local        */
  10. /* FT-Connect nodes provided by CIS in many European countries.             */
  11. /*                                                                          */
  12. /* The script sends the dial string to the modem and then logs into the     */
  13. /* terminal server using the userid/password. It solves the problem         */
  14. /* of dialling at 7-bit even parity, and connecting at 8-bit no parity      */
  15. /*                                                                          */
  16. /* Note: this script sets up hardware flow control on the COM port.         */
  17. /* Ensure your modem setup also sets up hardware flow control.              */
  18. /* (Ignore all recommendations for XON/XOFF flow control - it won't work).  */
  19. /*                                                                          */
  20. /* Usage: Copy this command file (TRANSPAC.CMD) to \TCPIP\BIN.              */
  21. /* Customize the string assigned to mdm_str for your modem.                 */
  22. /* You may have to modify the NUA.  This one is ok for the Netherlands      */
  23. /* Enter TRANSPAC.CMD ATDT<phonenumber> <userid> <password> as your Login   */
  24. /* Sequence on page 1 of the dialer and ensure that there are no blank      */
  25. /* lines following that line!!!                                             */
  26. /*                                                                          */
  27. /* adapted from a script by Mark Yudkin  (YCCIS.CMD)                        */
  28. /* by Jos Verbeeck  100332.254@compuserve.com                               */
  29. /*                                                                          */
  30.  
  31. /* first 3 parameters are from dialler (ignore 3rd), next 3 from user: */
  32. parse arg interface, comport, , dialcmd, userid, password
  33.  
  34. /*--------------------------------------------------------------------------*/
  35. /*                   Initialization and Main Script Code                    */
  36. /*--------------------------------------------------------------------------*/
  37.  
  38. /* Set fixed values - customize as necessary (use hardware flow control) */
  39. mdm_str = 'ATZ'
  40. NUA = '196282595'
  41.  
  42. /* the rest of the script does not need any customization */
  43. /* Set some definitions for easier COM strings */
  44. cr='0d'x
  45. crlf='0d0a'x
  46.  
  47. say ''
  48. say 'COMPUSERVE - PPP Server Connection Script (C) Mark Yudkin, 1995',
  49.     '(interface' interface') on' comport
  50.  
  51. /* Prompt for missing information */
  52. if dialcmd = '' then do
  53.    call charout , 'Dial Command: '
  54.    parse pull dialcmd
  55. end
  56. if userid = '' | userid = '*' then do
  57.    call charout , 'User Name: '
  58.    parse pull userid
  59. end
  60. else do
  61.    say 'User:' userid
  62. end
  63. if password = '' | password = '*' then do
  64.    call charout , 'Password: '
  65.    password = readpass()
  66. end
  67.  
  68. /* Flush any stuff left over from previous COM activity */
  69. call flush_receive
  70.  
  71. /* Reset and initialize the modem here */
  72. call lineout, 'Initializing' comport 'for login...'
  73. /* "MODE" comport "57600,E,7,1,IDSR=OFF,OCTS=ON,RTS=ON,ODSR=OFF,DTR=ON,XON=OFF,BUFFER=AUTO" */
  74. "MODE" comport "57600,E,7,1,IDSR=OFF,OCTS=ON,RTS=HS,ODSR=OFF,DTR=ON,XON=OFF,BUFFER=AUTO"
  75. call lineout, 'Resetting and initializing modem...'
  76. call send 'AT&F' || cr
  77. call waitfor 'OK'; call flush_receive 'echo'
  78.  if RC = 1 then do
  79.     call lineout , 'Modem not resetting... Trying again'
  80.     call send '+++'
  81.     call waitfor 'OK'
  82.     call send 'ATHZ' || cr
  83.     call waitfor 'OK'
  84.  end
  85. call send mdm_str || cr
  86. call waitfor 'OK'; call flush_receive 'echo'
  87.  
  88. /* Dial the remote server */
  89. call charout , 'Dialing...' || crlf
  90.  
  91. /* Wait for connection */
  92. call send dialcmd || cr
  93. call waitfor 'CONNECT' ; call waitfor crlf
  94.  
  95. /* Handle login.  We wait for standard strings, and then flush anything */
  96. /* else to take care of trailing spaces, etc..                          */
  97. call send cr
  98. call waitfor 'TRANSPAC' ; call flush_receive 'echo'
  99. call send NUA || cr
  100. call waitfor 'ame:' ; call flush_receive 'echo'
  101. call send 'CIS' || cr
  102. call waitfor 'ID:' ; call flush_receive 'echo'
  103. call send userid || '/GO:PPPCONNECT' || cr
  104. call waitfor 'ord:' ; call flush_receive 'echo'
  105. call send password || cr
  106.  
  107. /* Wait for the main prompt and then send the "ppp" command */
  108. call waitfor 'PPP' ; call flush_receive 'echo'
  109. call send 'PPP' || cr
  110.  
  111. /* Flush anything else */
  112. call flush_receive 'echo'
  113.  
  114. /* reset the serial port for PPP */
  115. call lineout , 'Resetting' comport 'for PPP...'
  116. "MODE" comport "57600,N,8,1,BUFFER=AUTO"
  117.  
  118. say 'PPP Connection Established'
  119.  
  120. /* All done */
  121. exit 0
  122.  
  123. /*--------------------------------------------------------------------------*/
  124. /*                            send ( sendstring)                            */
  125. /*..........................................................................*/
  126. /*                                                                          */
  127. /* Routine to send a character string off to the modem.                     */
  128. /*                                                                          */
  129. /*--------------------------------------------------------------------------*/
  130.  
  131. send:
  132.  
  133.    parse arg sendstring
  134.    call ppp_com_output interface , sendstring
  135.  
  136.    return
  137.  
  138.  
  139. /*--------------------------------------------------------------------------*/
  140. /*                    waitfor ( waitstring , [timeout] )                    */
  141. /*..........................................................................*/
  142. /*                                                                          */
  143. /* Waits for the supplied string to show up in the COM input.  All input    */
  144. /* from the time this function is called until the string shows up in the   */
  145. /* input is accumulated in the "waitfor_buffer" variable.                   */
  146. /*                                                                          */
  147. /* If timeout is specified, it says how long to wait if data stops showing  */
  148. /* up on the COM port (in seconds).                                                         */
  149. /*                                                                          */
  150. /*--------------------------------------------------------------------------*/
  151.  
  152. waitfor:
  153.  
  154.    parse arg waitstring , timeout
  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 = ppp_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 = SysGetKey('NOECHO')
  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 = ppp_com_input(interface,,100)
  241.      if echo \= '' then
  242.         call charout , line
  243.    end
  244.  
  245.    return
  246.  
  247.