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

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*        OS/2 REXX Driver for OS/2 Warp (Connect or IAK+PPP update)        */
  4. /*                                                                          */
  5. /*                  YCCIS.CMD dialstr userid password                       */
  6. /*                                                                          */
  7. /*            ..................................................            */
  8. /*                                                                          */
  9. /* Attachment script for dialing into CIS via PPP.                          */
  10. /*                                                                          */
  11. /* The script sends the dial string to the modem and then logs into the     */
  12. /* terminal server using the userid/password. It solves the problem         */
  13. /* of dialling at 7-bit even parity, and connecting at 8-bit no parity      */
  14. /*                                                                          */
  15. /* Note: this script sets up hardware flow control on the COM port.         */
  16. /* Ensure your modem setup also sets up hardware flow control.              */
  17. /* (Ignore all recommendations for XON/XOFF flow control - it won't work).  */
  18. /*                                                                          */
  19. /* Usage: Copy this command file (YCCIS.CMD) to \TCPIP\BIN.                 */
  20. /* Customize the string assigned to mdm_str for your modem.                 */ 
  21. /* Enter <YCCIS.CMD ATDTnnn userid password> as your login sequence         */
  22. /* and ensure that there are no blank lines following that line!!!          */
  23. /*                                                                          */
  24. /* Author: Mark Yudkin          76251.3362@compuserve.com                   */
  25. /* (C) Mark Yudkin, 1995                                                    */
  26. /*                                                                          */
  27. /* Email me for information on Cogent/SQLfor OS/2 and Cogent/SQL for MVS    */
  28. /* the leading code generator authoring tool for OS/2 and/or MVS.           */
  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 = 'ATE0Q0S0=0V1X1&C1&D2&N17&S1&G2&K3'       /* for Zyxel U-1496E */
  40.  
  41. /* the rest of the script does not need any customization */
  42. /* Set some definitions for easier COM strings */
  43. cr='0d'x
  44. crlf='0d0a'x
  45.  
  46. say ''
  47. say 'COMPUSERVE - PPP Server Connection Script (C) Mark Yudkin, 1995',
  48.     '(interface' interface') on' comport
  49.  
  50. /* Prompt for missing information */
  51. if dialcmd = '' then do
  52.    call charout , 'Dial Command: '
  53.    parse pull dialcmd
  54. end
  55. if userid = '' | userid = '*' then do
  56.    call charout , 'User Name: '
  57.    parse pull userid
  58. end
  59. else do
  60.    say 'User:' userid
  61. end
  62. if password = '' | password = '*' then do
  63.    call charout , 'Password: '
  64.    password = readpass()
  65. end
  66.  
  67. /* Flush any stuff left over from previous COM activity */
  68. call flush_receive
  69.  
  70. /* Reset and initialize the modem here */
  71. call lineout, 'Initializing' comport 'for login...'
  72. /* "MODE" comport "57600,E,7,1,IDSR=OFF,OCTS=ON,RTS=ON,ODSR=OFF,DTR=ON,XON=OFF,BUFFER=AUTO" */
  73. "MODE" comport "57600,E,7,1,IDSR=OFF,OCTS=ON,RTS=HS,ODSR=OFF,DTR=ON,XON=OFF,BUFFER=AUTO"
  74. call lineout, 'Resetting and initializing modem...'
  75. call send 'AT&F' || cr
  76. call waitfor 'OK'; call flush_receive 'echo'
  77.  if RC = 1 then do
  78.     call lineout , 'Modem not resetting... Trying again'
  79.     call send '+++'
  80.     call waitfor 'OK'
  81.     call send 'ATHZ' || cr
  82.     call waitfor 'OK'
  83.  end
  84. call send mdm_str || cr
  85. call waitfor 'OK'; call flush_receive 'echo'
  86.  
  87. /* Dial the remote server */
  88. call charout , 'Dialing...' || crlf
  89.  
  90. /* Wait for connection */
  91. call send dialcmd || cr
  92. call waitfor 'CONNECT' ; call waitfor crlf
  93.  
  94. /* Handle login.  We wait for standard strings, and then flush anything */
  95. /* else to take care of trailing spaces, etc..                          */
  96. call send cr
  97. call waitfor 'ame:' ; call flush_receive 'echo'
  98. call send 'CIS' || cr
  99. call waitfor 'ID:' ; call flush_receive 'echo'
  100. call send userid || '/GO:PPPCONNECT' || cr
  101. call waitfor 'ord:' ; call flush_receive 'echo'
  102. call send password || cr
  103.  
  104. /* Wait for the main prompt and then send the "ppp" command */
  105. call waitfor 'PPP' ; call flush_receive 'echo'
  106. call send 'PPP' || cr
  107.  
  108. /* Flush anything else */
  109. call flush_receive 'echo'
  110.  
  111. /* reset the serial port for PPP */
  112. call lineout , 'Resetting' comport 'for PPP...'
  113. "MODE" comport "57600,N,8,1,BUFFER=AUTO"
  114.  
  115. say 'PPP Connection Established'
  116.  
  117. /* All done */
  118. exit 0
  119.  
  120.  
  121. /*--------------------------------------------------------------------------*/
  122. /*                            send ( sendstring)                            */
  123. /*..........................................................................*/
  124. /*                                                                          */
  125. /* Routine to send a character string off to the modem.                     */
  126. /*                                                                          */
  127. /*--------------------------------------------------------------------------*/
  128.  
  129. send:
  130.  
  131.    parse arg sendstring
  132.    call ppp_com_output interface , sendstring
  133.  
  134.    return
  135.  
  136.  
  137. /*--------------------------------------------------------------------------*/
  138. /*                    waitfor ( waitstring , [timeout] )                    */
  139. /*..........................................................................*/
  140. /*                                                                          */
  141. /* Waits for the supplied string to show up in the COM input.  All input    */
  142. /* from the time this function is called until the string shows up in the   */
  143. /* input is accumulated in the "waitfor_buffer" variable.                   */
  144. /*                                                                          */
  145. /* If timeout is specified, it says how long to wait if data stops showing  */
  146. /* up on the COM port (in seconds).                                                         */
  147. /*                                                                          */
  148. /*--------------------------------------------------------------------------*/
  149.  
  150. waitfor:
  151.  
  152.    parse arg waitstring , timeout
  153.    if timeout = '' then
  154.      timeout = 5000    /* L O N G   delay if not specified */
  155.    waitfor_buffer = '' ; done = -1; curpos = 1
  156.    ORI_TIME=TIME('E')
  157.  
  158.    if (remain_buffer = 'REMAIN_BUFFER') then do
  159.       remain_buffer = ''
  160.    end
  161.  
  162.    do while (done = -1)
  163.       if (remain_buffer \= '') then do
  164.          line = remain_buffer
  165.          remain_buffer = ''
  166.        end
  167.        else do
  168.          line = ppp_com_input(interface,,10)
  169.       end
  170.       waitfor_buffer = waitfor_buffer || line
  171.       index = pos(waitstring,waitfor_buffer)
  172.       if (index > 0) then do
  173.          remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  174.          waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  175.          done = 0
  176.       end
  177.       call charout , substr(waitfor_buffer,curpos)
  178.       curpos = length(waitfor_buffer)+1
  179.       if ((done \= 0) & (TIME('E')>timeout)) then do
  180.         call lineout , ' WAITFOR: timed out '
  181.         done = 1
  182.       end
  183.    end
  184.    timeout=0
  185.    RC=done
  186.  return RC
  187.  
  188.  
  189.  
  190. /*--------------------------------------------------------------------------*/
  191. /*                               readpass ()                                */
  192. /*..........................................................................*/
  193. /*                                                                          */
  194. /* Routine used to read a password from the user without echoing the        */
  195. /* password to the screen.                                                  */
  196. /*                                                                          */
  197. /*--------------------------------------------------------------------------*/
  198.  
  199. readpass:
  200.  
  201.   answer = ''
  202.   do until key = cr
  203.     key = SysGetKey('NOECHO')
  204.     if key \= cr then do
  205.       answer = answer || key
  206.     end
  207.   end
  208.   say ''
  209.   return answer
  210.  
  211.  
  212. /*--------------------------------------------------------------------------*/
  213. /*                             flush_receive ()                             */
  214. /*..........................................................................*/
  215. /*                                                                          */
  216. /* Routine to flush any pending characters to be read from the COM port.    */
  217. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  218. /* point it returns.                                                        */
  219. /*                                                                          */
  220. /* The optional echo argument, if 1, says to echo flushed information.      */
  221. /*                                                                          */
  222. /*--------------------------------------------------------------------------*/
  223.  
  224. flush_receive:
  225.  
  226.    parse arg echo
  227.  
  228.    /* If echoing the flush - take care of waitfor remaining buffer */
  229.    if (echo \= '') & (length(remain_buffer) > 0) then do
  230.       call charout , remain_buffer
  231.       remain_buffer = ''
  232.    end
  233.  
  234.    /* Eat anything left in the modem or COM buffers */
  235.    /* Stop when nothing new appears for 100ms.      */
  236.  
  237.    do until line = ''
  238.      line = ppp_com_input(interface,,100)
  239.      if echo \= '' then
  240.         call charout , line
  241.    end
  242.  
  243.    return
  244.