home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / ppprexx.zip / cis.cmd next >
OS/2 REXX Batch file  |  1995-04-21  |  9KB  |  235 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                OS/2 2.0 REX Driver for  IBM TCP/IP version 2.0           */
  4. /*                                                                          */
  5. /*                                CIS.CMD                                   */
  6. /*                                                                          */
  7. /*            ..................................................            */
  8. /*                                                                          */
  9. /* Sample attachment script for dialing into CIS                            */
  10. /*                                                                          */
  11. /* The script sends the dial string to the modem and then logs into the     */
  12. /* terminal server using the userid/password.                               */
  13. /*                                                                          */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /* Author: Klaus-Dieter Trog    100013,1542@compuserve.com (Freeware)       */
  17. /*--------------------------------------------------------------------------*/
  18.  
  19. parse arg interface, ppp_com, ppp_cmd, dialcmd, userid, password
  20.  
  21. /*--------------------------------------------------------------------------*/
  22. /*                   Initialization and Main Script Code                    */
  23. /*--------------------------------------------------------------------------*/
  24.  
  25. If RxFuncQuery('SysLoadFuncs') <> 0 Then
  26.    rcy = RxFuncAdd('SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs')
  27. Call Sysloadfuncs
  28. debug = 0
  29.  
  30. /* Set some definitions for easier COM strings */
  31. cr='0d'x
  32. crlf='0d0a'x
  33. cis_hostname = 'f374a04ee1ed653a'x
  34. cis_userid =   '55f36572a0c9443a'x
  35. cis_password = 'e1f3f3776f72e43a'x
  36.  
  37. /* Set fixed Values */
  38. mdm_str1 = 'AT&F'
  39. mdm_str2 = 'ATZ1'
  40. dialcmd = 'ATDT069-20976'
  41. userid = '100013,1542'
  42. password = '*'
  43.  
  44. say ''
  45. say 'COMPUSERVE - PPP Server Connection Script by kdt',
  46.     '(interface' interface')'
  47.  
  48. /* Prompt for missing information */
  49. if dialcmd = '' then do
  50.    call charout , 'Dial Command: '
  51.    parse pull dialcmd
  52. end
  53. if userid = '' | userid = '*' then do
  54.    call charout , 'User Name: '
  55.    parse pull userid
  56. end
  57. else do
  58.    say 'User:' userid
  59. end
  60. if password = '' | password = '*' then do
  61.    call charout , 'Password: '
  62.    password = readpass()
  63. end
  64.  
  65. /* Flush any stuff left over from previous COM activity */
  66. call flush_receive
  67.  
  68. /* Init modem strings */
  69. call charout , 'Initializing Modem...' || crlf
  70. call send mdm_str1 || cr
  71. call waitfor 'OK' ; call flush_receive 'echo'
  72. call send mdm_str2 || cr
  73. call waitfor 'OK' ; call flush_receive 'echo'
  74.  
  75. /* Dial the remote server */
  76. call charout , 'Now Dialing...' || crlf
  77.  
  78. /* Wait for connection */
  79. call send dialcmd || cr
  80. call waitfor 'CONNECT' ; call waitfor crlf
  81.  
  82. /* Handle login.  We wait for standard strings, and then flush anything */
  83. /* else to take care of trailing spaces, etc..                          */
  84. call send  cr
  85. call waitfor cis_hostname ; call flush_receive 'echo'
  86. call send 'CIS' || cr
  87. call waitfor cis_userid ; call flush_receive 'echo'
  88. call send userid || '/GO:PPPCONNECT' || cr
  89. call waitfor cis_password ; call flush_receive 'echo'
  90. call send password || cr
  91.  
  92. /* Wait for the main prompt and then send the "ppp" command */
  93. call waitfor 'PPP' ; call flush_receive 'echo'
  94. call send 'PPP' || cr
  95.  
  96. /* Parse the results of the PPP  command to determine our address. */
  97. /* We use the "waitfor_buffer" variable from the waitfor routine   */
  98. /* to parse the stuff we get from the line  after waiting for an   */
  99. /* appropriate point in the data stream.                           */
  100. /* Flush anything else */
  101. call flush_receive 'echo'
  102.  
  103.  
  104. say 'PPP Connection Established'
  105.  
  106. /* All done */
  107. exit 0
  108.  
  109.  
  110. /*--------------------------------------------------------------------------*/
  111. /*                            send ( sendstring)                            */
  112. /*..........................................................................*/
  113. /*                                                                          */
  114. /* Routine to send a character string off to the modem.                     */
  115. /*                                                                          */
  116. /*--------------------------------------------------------------------------*/
  117.  
  118. send:
  119.  
  120.    parse arg sendstring
  121.    call ppp_com_output interface , sendstring
  122.  
  123.    return
  124.  
  125.  
  126. /*--------------------------------------------------------------------------*/
  127. /*                    waitfor ( waitstring , [timeout] )                    */
  128. /*..........................................................................*/
  129. /*                                                                          */
  130. /* Waits for the supplied string to show up in the COM input.  All input    */
  131. /* from the time this function is called until the string shows up in the   */
  132. /* input is accumulated in the "waitfor_buffer" variable.                   */
  133. /*                                                                          */
  134. /* If timeout is specified, it says how long to wait if data stops showing  */
  135. /* up on the COM port (in seconds).                                                         */
  136. /*                                                                          */
  137. /*--------------------------------------------------------------------------*/
  138.  
  139. waitfor:
  140.  
  141.    parse arg waitstring , timeout
  142.    if timeout = '' then
  143.      timeout = 5000    /* L O N G   delay if not specified */
  144.    waitfor_buffer = '' ; done = -1; curpos = 1
  145.    ORI_TIME=TIME('E')
  146.  
  147.    if (remain_buffer = 'REMAIN_BUFFER') then do
  148.       remain_buffer = ''
  149.    end
  150.  
  151.    do while (done = -1)
  152.       if (remain_buffer \= '') then do
  153.          line = remain_buffer
  154.          remain_buffer = ''
  155.        end
  156.        else do
  157.          line = ppp_com_input(interface,,10)
  158.       end
  159.       waitfor_buffer = waitfor_buffer || line
  160.       index = pos(waitstring,waitfor_buffer)
  161.       if (index > 0) then do
  162.          remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  163.          waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  164.          done = 0
  165.       end
  166.       call charout , substr(waitfor_buffer,curpos)
  167.       x_val = '[' || C2X(substr(waitfor_buffer,curpos)) || ']'
  168.       if X_val <> '[]' & debug then call charout , crlf || x_val
  169.       curpos = length(waitfor_buffer)+1
  170.       if ((done \= 0) & (TIME('E')>timeout)) then do
  171.         call lineout , ' WAITFOR: timed out '
  172.         done = 1
  173.        end
  174.    end
  175.    timeout=0
  176.    RC=done
  177.  return RC
  178.  
  179.  
  180.  
  181. /*--------------------------------------------------------------------------*/
  182. /*                               readpass ()                                */
  183. /*..........................................................................*/
  184. /*                                                                          */
  185. /* Routine used to read a password from the user without echoing the        */
  186. /* password to the screen.                                                  */
  187. /*                                                                          */
  188. /*--------------------------------------------------------------------------*/
  189.  
  190. readpass:
  191.  
  192.   answer = ''
  193.   do until key = cr
  194.     key = SysGetKey('NOECHO')
  195.     if key \= cr then do
  196.       answer = answer || key
  197.     end
  198.   end
  199.   say ''
  200.   return answer
  201.  
  202.  
  203. /*--------------------------------------------------------------------------*/
  204. /*                             flush_receive ()                             */
  205. /*..........................................................................*/
  206. /*                                                                          */
  207. /* Routine to flush any pending characters to be read from the COM port.    */
  208. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  209. /* point it returns.                                                        */
  210. /*                                                                          */
  211. /* The optional echo argument, if 1, says to echo flushed information.      */
  212. /*                                                                          */
  213. /*--------------------------------------------------------------------------*/
  214.  
  215. flush_receive:
  216.  
  217.    parse arg echo
  218.  
  219.    /* If echoing the flush - take care of waitfor remaining buffer */
  220.    if (echo \= '') & (length(remain_buffer) > 0) then do
  221.       call charout , remain_buffer
  222.       remain_buffer = ''
  223.    end
  224.  
  225.    /* Eat anything left in the modem or COM buffers */
  226.    /* Stop when nothing new appears for 100ms.      */
  227.  
  228.    do until line = ''
  229.      line = ppp_com_input(interface,,100)
  230.      if echo \= '' then
  231.         call charout , line
  232.    end
  233.  
  234.    return
  235.