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

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