home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / pcnet.cmd < prev    next >
OS/2 REXX Batch file  |  1995-01-07  |  14KB  |  304 lines

  1. /*--------------------------------------------------------------------------*/
  2. /* modified by prs on 05/19/94                                              */
  3. /* modified by emr on 12/1/94                                               */
  4. /*                                                                          */
  5. /*                                                                          */
  6. /*                OS/2 2.0 SLIP Driver for IBM TCP/IP version 2.0           */
  7. /*                modified to fit the Warp TCP/IP implementation            */
  8. /*                                                                          */
  9. /*                                SLIPUP.CMD                                */
  10. /*                                                                          */
  11. /*            ..................................................            */
  12. /*                                                                          */
  13. /* Sample attachment script for dialing into the PCNet terminal             */
  14. /* server in order to establish a SLIP connection.  This script should be   */
  15. /* specified using the "attachcmd" and "attachparm" elements in the SLIP    */
  16. /* configuration file SLIP.CFG.  For example:                               */
  17. /*                                                                          */
  18. /*              interface sl0 {                                             */
  19. /*                 attachcmd  = slipup                                      */
  20. /*                 attachparm = "dialcmd username password"                 */
  21. /*              }                                                           */
  22. /*                                                                          */
  23. /*  Instead of linking into the SLIP.CFG file in Warp, this links into      */
  24. /*  the Provider dialog in SLIPPM.EXE.  Specify the script in the  Login    */
  25. /*  scriptbox in screen 1 of 4 of Modify Provider/Provider Information      */
  26. /*  in the Dial Other Internet Providers Screen:                            */
  27. /*                                                                          */
  28. /*  paradigm.com <dial command> <userid> <password>                         */
  29. /*                                                                          */
  30. /*   For example:  paradigm.cmd atdt2501205 Puserid MyPassWd                */
  31. /*                                                                          */
  32. /* The script parameters specify the command to send to the modem to dial   */
  33. /* the remote site and the username/password combination to use to log into */
  34. /* the terminal server.  If any of the parameters are omitted, or are       */
  35. /* specified as an asterix (*), the script will prompt for them.  This is   */
  36. /* most useful with the password parameter to avoid storing the password    */
  37. /* in a text file on the disk.                                              */
  38. /*                                                                          */
  39. /* For example, the following might be how I would set it up:               */
  40. /*                                                                          */
  41. /*              interface sl0 {                                             */
  42. /*                 attachcmd  = slipup                                      */
  43. /*                 attachparm = "atdt###-#### db3l *"                       */
  44. /*              }                                                           */
  45. /*                                                                          */
  46. /* which would cause slipup to initially prompt me for the password.  It    */
  47. /* would then feed the "atdt###-####" command to the modem, and when the    */
  48. /* pcnet answered, it would use "db3l" as a username and the password I     */
  49. /* initially entered as the password.                                       */
  50. /*                                                                          */
  51. /*            - - - - - - - - - - - - - - - - - - - - - - - - -             */
  52. /* --emr 12/1/94                                                                         */
  53. /* When the script runs, it is automatically passed the interface name for  */
  54. /* the interface it is running on as the first argument, and the user       */
  55. /* arguments.  The interface info is taken from page 4 of 4 of the SLIPPM   */
  56. /* Modify Provider dialog                                                   */
  57. /*                                                                          */
  58. /* The script sends the dial string to the modem and then logs into the     */
  59. /* terminal server using the username/password.  It then issues the SLIP    */
  60. /* command to start SLIP, and parses the resulting output to determine the  */
  61. /* appropriate addresses to use.  Lastly, it issues ifconfig and route      */
  62. /* commands to configure the OS/2 system appropriately.  Note that the      */
  63. /* configuration assumes a class C netmask for the SLIP interface.          */
  64. /*                                                                          */
  65. /* -- emr 12/7/94                                                           */
  66. /* Actually, rpinz has the SLIP or PPP command set up to run automagically  */
  67. /* on my account, so no SLIP command is issued by the script.  It would be  */
  68. /* given at the noted location in this script                               */
  69. /*--------------------------------------------------------------------------*/
  70.  
  71. parse arg interface , dialcmd username password
  72.  
  73. /*--------------------------------------------------------------------------*/
  74. /*                   Initialization and Main Script Code                    */
  75. /*--------------------------------------------------------------------------*/
  76.  
  77. /* Set some definitions for easier COM strings */
  78. cr='0d'x
  79. crlf='0d0a'x
  80. ctrlc='03'x
  81.  
  82. say ''
  83. say 'SLIPUP - SLIP Script ',
  84.     '(interface' interface')'
  85.  
  86. /* Prompt for missing information */
  87. if dialcmd = '' then do
  88.    call charout , 'Dial Command: '
  89.    parse pull dialcmd
  90. end
  91. if username = '' | username = '*' then do
  92.    call charout , 'User Name: '
  93.    parse pull username
  94. end
  95. else do
  96.    say 'User:' username
  97. end
  98. if password = '' | password = '*' then do
  99.    call charout , 'Password: '
  100.    password = readpass()
  101. end
  102.  
  103. /* Reset comport settings */
  104. /*  emr - commented out in the Warp version                             */
  105. /* MODE "COM2: 19200,n,8,1,buffer=on,rts=hs"                            */
  106.  
  107. /* Initialize modem                                                     */
  108. /* Reset the modem here                                                 */
  109. /* You may need to customize this for your modem make and model         */
  110. /*  emr - This is set up for a USR Sportster v.34 connecting at 14.4K   */
  111. call lineout , 'Reset modem...'
  112. call send 'AT&F1&A3&K3' || cr
  113. call waitfor 'OK', 5 ; call flush_receive 'echo'
  114.  if RC = 1 then do
  115.     call lineout , 'Modem not resetting... Trying again'
  116.     call send '+++'
  117.     call waitfor 'OK'
  118.     call send 'ATHZ' || cr
  119.     call waitfor 'OK', 3
  120.   end
  121.  
  122. /* Flush any stuff left over from previous COM activity */
  123. call flush_receive
  124.  
  125. /* Dial the remote server */
  126. call charout , 'Now Dialing...'
  127.  
  128. /* Wait for connection */
  129. call send dialcmd || cr
  130.  
  131. call waitfor 'CONNECT' ; call waitfor crlf
  132.  
  133. /* Handle login.  We wait for standard strings, and then flush anything */
  134. /* else to take care of trailing spaces, etc..                          */
  135. call send cr
  136. call waitfor 'login:' ; call flush_receive 'echo'
  137. call send username || cr
  138. call waitfor 'Password:' ; call flush_receive 'echo'
  139. call send password || cr
  140.  
  141. /*  --emr 12/7/94                                            */
  142. /*  Add the necessary call to waitfor and send as noted here */
  143. /*  Uncomment if necessary                                   */
  144. /* call waitfor 'Net%' ; call flush_receive 'echo'           */
  145. /* call send 'slip' || cr                                    */
  146.  
  147. /* Parse the results of the SLIP command to determine our address.      */
  148. /* We use the "waitfor_buffer" variable from the waitfor routine        */
  149. /* to parse the stuff we get from PCNET after waiting for an            */
  150. /* appropriate point in the data stream.                                */
  151. call waitfor 'beginning....'
  152.  
  153. /*   --emr 12/1/94                                                                   */
  154. /*   The following picks up the necessary detail for my account, but    */
  155. /*   since PPP isn't supported, the connection breaks quickly.  I       */
  156. /*   assume that Ron can set up SL/IP, and that the prompt string       */
  157. /*   would change to "SL/IP" rather than "PPP" below                    */
  158. /*                                                                      */
  159. parse var waitfor_buffer . 'SL/IP session from (' a '.' b '.' c '.' d ') to ' e '.' f '.' g '.' h .
  160. pcnet_address = a||'.'||b||'.'||c||'.'||d
  161. os2_address = e||'.'||f||'.'||g||'.'||h
  162.  
  163. /* Flush anything else */
  164. call flush_receive 'echo'
  165.  
  166. /* Now configure this host for the appropriate address, */
  167. /* and for a default route through the pcnet.           */
  168. say ' '
  169. say 'SLIP Connection Established'
  170. say 'Configuring local address =' os2_address ', PCNet =' pcnet_address
  171.  
  172. 'ifconfig sl0' os2_address pcnet_address 'netmask 255.255.255.0'
  173. 'route add default' pcnet_address '1'
  174.  
  175.  
  176. /* All done */
  177. exit 0
  178.  
  179.  
  180. /*--------------------------------------------------------------------------*/
  181. /*                            send ( sendstring)                            */
  182. /*..........................................................................*/
  183. /*                                                                          */
  184. /* Routine to send a character string off to the modem.                     */
  185. /*                                                                          */
  186. /*--------------------------------------------------------------------------*/
  187.  
  188. send:
  189.  
  190.    parse arg sendstring
  191.    call slip_com_output interface , sendstring
  192.  
  193.    return
  194.  
  195.  
  196. /*--------------------------------------------------------------------------*/
  197. /*                    waitfor ( waitstring , [timeout] )                    */
  198. /*..........................................................................*/
  199. /*                                                                          */
  200. /* Waits for the supplied string to show up in the COM input.  All input    */
  201. /* from the time this function is called until the string shows up in the   */
  202. /* input is accumulated in the "waitfor_buffer" variable.                   */
  203. /*                                                                          */
  204. /* If timeout is specified, it says how long to wait if data stops showing  */
  205. /* up on the COM port (in seconds).                                                         */
  206. /*                                                                          */
  207. /*--------------------------------------------------------------------------*/
  208.  
  209. waitfor:
  210.  
  211.    parse arg waitstring , timeout
  212.  
  213.    if timeout = '' then
  214.      timeout = 5000    /* L O N G   delay if not specified */
  215.    waitfor_buffer = '' ; done = -1; curpos = 1
  216.    ORI_TIME=TIME('E')
  217.  
  218.    if (remain_buffer = 'REMAIN_BUFFER') then do
  219.       remain_buffer = ''
  220.    end
  221.  
  222.    do while (done = -1)
  223.       if (remain_buffer \= '') then do
  224.          line = remain_buffer
  225.          remain_buffer = ''
  226.        end
  227.        else do
  228.          line = slip_com_input(interface,,10)
  229.       end
  230.       waitfor_buffer = waitfor_buffer || line
  231.       index = pos(waitstring,waitfor_buffer)
  232.       if (index > 0) then do
  233.          remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  234.          waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  235.          done = 0
  236.       end
  237.       call charout , substr(waitfor_buffer,curpos)
  238.       curpos = length(waitfor_buffer)+1
  239.       if ((done \= 0) & (TIME('E')>timeout)) then do
  240.         call lineout , ' WAITFOR: timed out '
  241.         done = 1
  242.        end
  243.    end
  244.    timeout=0
  245.    RC=done
  246.  return RC
  247.  
  248.  
  249.  
  250. /*--------------------------------------------------------------------------*/
  251. /*                               readpass ()                                */
  252. /*..........................................................................*/
  253. /*                                                                          */
  254. /* Routine used to read a password from the user without echoing the        */
  255. /* password to the screen.                                                  */
  256. /*                                                                          */
  257. /*--------------------------------------------------------------------------*/
  258.  
  259. readpass:
  260.  
  261.   answer = ''
  262.   do until key = cr
  263.     key = slip_getch()
  264.     if key \= cr then do
  265.       answer = answer || key
  266.     end
  267.   end
  268.   say ''
  269.   return answer
  270.  
  271.  
  272. /*--------------------------------------------------------------------------*/
  273. /*                             flush_receive ()                             */
  274. /*..........................................................................*/
  275. /*                                                                          */
  276. /* Routine to flush any pending characters to be read from the COM port.    */
  277. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  278. /* point it returns.                                                        */
  279. /*                                                                          */
  280. /* The optional echo argument, if 1, says to echo flushed information.      */
  281. /*                                                                          */
  282. /*--------------------------------------------------------------------------*/
  283.  
  284. flush_receive:
  285.  
  286.    parse arg echo
  287.  
  288.    /* If echoing the flush - take care of waitfor remaining buffer */
  289.    if (echo \= '') & (length(remain_buffer) > 0) then do
  290.       call charout , remain_buffer
  291.       remain_buffer = ''
  292.    end
  293.  
  294.    /* Eat anything left in the modem or COM buffers */
  295.    /* Stop when nothing new appears for 100ms.      */
  296.  
  297.    do until line = ''
  298.      line = slip_com_input(interface,,100)
  299.      if echo \= '' then
  300.         call charout , line
  301.    end
  302.  
  303.    return
  304.