home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / nuslip.zip / NUSLIPUP.CMD
OS/2 REXX Batch file  |  1994-08-02  |  22KB  |  334 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*      Minimized OS/2 2.0 SLIP Driver for IBM TCP/IP version 2.0           */
  4. /*                                                                          */
  5. /*                             NUSLIPUP.CMD                                 */
  6. /*                                                                          */
  7. /*            ..................................................            */
  8. /*                                                                          */
  9. /*       August 1, 1994                                                     */
  10. /*                                                                          */
  11. /* NOTE: This file has evolved from the SLIPUP.CMD file supplied with       */
  12. /*       IBM's TCP/IP package.  Some people who are new to TCPIP and/or     */
  13. /*       Rexx have had difficulty getting their SLIP connection working     */
  14. /*       and it is hoped that this file may be easier to understand.        */
  15. /*                                                                          */
  16. /*       These modifications by John Pedersen, CompuServe 76547,357         */
  17. /*       Any suggestions or comments are welcome.                           */
  18. /*                                                                          */
  19. /*--------------------------------------------------------------------------*/
  20. /*                                                                          */
  21. /* This is an attachment script for dialing into a SLIP service provider.   */
  22. /* Notes on usage:                                                          */
  23. /*                                                                          */
  24. /* 1. The default installation procedure for TCP/IP puts TCPSTART.CMD into  */
  25. /*    your STARTUP folder.  This file invokes another .CMD file called      */
  26. /*    SETUP.CMD.  To get yourself going, remove TCPSTART.CMD from your      */
  27. /*    STARTUP folder so these programs never get called.                    */
  28. /*                                                                          */
  29. /* 2. This script file should be specified using the "attachcmd" in the     */
  30. /*    SLIP.CFG file; however no "attachparm" elements are used so that we   */
  31. /*    can move a lot of the tweaking into one place (ie. the front part of  */
  32. /*    this file.  For example, SLIP.CFG might look like this:               */
  33. /*                                                                          */
  34. /*             interface sl0 { device=COM1,                                 */
  35. /*                             mtu=1006,                                    */
  36. /*                             compression=auto,                            */
  37. /*                             attachcmd=nuslipup.cmd }                     */
  38. /*                                                                          */
  39. /* 3. This method REQUIRES that your password be inserted permanently into  */
  40. /*    the file below.  If security is a problem, DON'T use this method, or  */
  41. /*    take appropriate measures.  Also, if you wish to pass this file along */
  42. /*    to help somebody else, REMOVE your password first.                    */
  43. /*                                                                          */
  44. /* 4. The basic idea here is:                                               */
  45. /*                                                                          */
  46. /*    a) First the script sends the dial string to the modem.  If           */
  47. /*       connection is not made, it will redial (10 times).                 */
  48. /*                                                                          */
  49. /*    b) Next, we log into the service provider using the                   */
  50. /*       username and password.                                             */
  51. /*                                                                          */
  52. /*    c) At this point, the service provider may offer a menu, and we  have */
  53. /*       to respond appropriately.                                          */
  54. /*                                                                          */
  55. /*    d) If IP Addresses are to be assigned at login time, we have to grab  */
  56. /*       that output and parse it to determine the appropriate addresses    */
  57. /*       to use.                                                            */
  58. /*                                                                          */
  59. /*    e) Lastly, it issues ifconfig and route commands to configure our     */
  60. /*       system appropriately.  Note that the configuration assumes a       */
  61. /*       class C netmask for the SLIP interface.                            */
  62. /*                                                                          */
  63. /* NOTE(!), if you're studying the Rexx below, that there are calls to two  */
  64. /* Rexx functions provided by TCPIP:                                        */
  65. /*   slip_com_input ( interface(sl0) , [max_characters] , [timeout(ms.)] )  */
  66. /*        As implied, this gets characters from the COM port.               */
  67. /*   slip_com_output ( interface , string )                                 */
  68. /*        And, also obvious, this sends a string to the COM port.  Note     */
  69. /*        that the chararacters may not all have been sent when this        */
  70. /*        routine returns.                                                  */
  71.  
  72.  
  73.  
  74. /*==========================================================================*/
  75. /* THIS AREA IS FOR SETTING UP YOUR UNIQUE VARIABLES.  EDIT AS APPROPRIATE. */
  76. /* For LoginPrompt and PwPrompt, enter the end of the text string which is  */
  77. /* sent by your service provider to prompt you for your user name and your  */
  78. /* password.  Match upper and lower case exactly!!!                         */
  79.  
  80. /* Except for my password, I've got my own login details inserted below,    */
  81. /* to give you a better idea of how it ends up.                             */
  82. /* When you're trying to get things going, look at the actual text that     */
  83. /* your service provider is sending.  LoginPrompt, PwPrompt, ThirdPrompt    */
  84. /* below should be changed so YOU are looking for the text that YOUR        */
  85. /* service provider is sending.  AddrMarker1 and AddrMarker2 are also       */
  86. /* prompt strings, for those cases where IP Addresses are assigned at login.*/
  87.  
  88. DialType    = 'T'               /* T for tone; P for pulse.                 */
  89. DialNumber  = '1-905-847-8866'  /* Phone number of service provider.        */
  90. LoginName   = 'pedersen'        /* Your login name.                         */
  91. Password    = ''                /* Change this to your password.            */
  92. ComNumber   = 1                 /* 1 for COM1, 2 for COM2.                  */
  93. LoginStart  = 'CR'              /* 'CR' to start login with cr; else '*'.   */
  94. LoginPrompt = 'login:'          /* Text prompting for login name.           */
  95. PwPrompt    = 'Password:'       /* Text prompting for password.             */
  96. ThirdPrompt = 'choice:'         /* Text prompting for connection type.      */
  97. ThirdAnswer = '2'               /* My reply to the third prompt.            */
  98. MyIPAddress = '199.0.20.53'     /* Set to '*' if IP Addr assigned at login. */
  99. Gateway     = '165.154.1.1'     /* Srvce provider; '*' if assigned at login.*/
  100. AddrMarker1 = 'Your address is' /* Line with this text has your IP Address. */
  101. AddrMarker2 = 'Your gateway is' /* Line with this text has Gateway Address. */
  102.  
  103.  
  104. /*==========================================================================*/
  105. /* THIS SECTION MAKES SURE THAT YOUR COM PORT IS SET UP CORRECTLY.  The     */
  106. /* settings below will be correct for most circumstances; most modems will  */
  107. /* negotiate a lower rate if required.                                      */
  108. /*--------------------------------------------------------------------------*/
  109. 'mode com'ComNumber': 19200,',      /* Baud rate                            */
  110.                          'n,',      /* No parity                            */
  111.                          '8,',      /* 8 data bits                          */
  112.                          '1,',      /* 1 stop bit                           */
  113.                    'xon=off,',      /* software (XON/XOFF) handshake off    */
  114.                   'idsr=off,',      /* input "DataSet Ready" handshake off  */
  115.                   'odsr=off,',      /* output "DataSet Ready" handshake off */
  116.                    'octs=on,',      /* output "Clear To Send" handshake on  */
  117.                     'rts=hs,',      /* "Request To Send" handshake on       */
  118.                     'dtr=on,',      /* Data Terminal Ready                  */
  119.                  'buffer=on'        /* use buffer if applicable             */
  120.  
  121.  
  122. /*==========================================================================*/
  123. /**************** MAIN SCRIPT CODE STARTS HERE ******************************/
  124. /*--------------------------------------------------------------------------*/
  125. cr='0d'x                           /* define the carriage return character  */
  126. crlf='0d0a'x                       /* and carriage return-line feed pair.   */
  127.  
  128.  
  129. /*==========================================================================*/
  130. /* THIS SECTION DIALS THE PHONE; IT INCLUDES A LOOP FOR REDIALING IF BUSY.  */
  131. /*--------------------------------------------------------------------------*/
  132. Dialcmd = 'ATD'DialType||DialNumber  /* Put together the dial command.      */
  133. DialCnt = 0                          /* Initialize a retry counter.         */
  134. call DoDial                          /* Call the dial routine.              */
  135. do while waitfor('CONNECT', '35')=1  /* Wait for CONNECT signal from modem. */
  136.    call send 'ATH'                   /* if you time out, send "hangup" cmd  */
  137.    call flush_receive                /* to modem,                           */
  138.    say 'Hanging up....'              /* and inform user.                    */
  139.    call DoDial                       /* Send the dial command again.        */
  140. end                                  /* End of redial loop.                 */
  141. call waitfor crlf                    /* Wait for characters from provider.  */
  142.  
  143.  
  144. /*==========================================================================*/
  145. /* THIS SECTION IS THE LOGIN SEQUENCE.                                      */
  146. /* Wait for standard strings, and then flush anything else to take care of  */
  147. /* trailing spaces, etc..                                                   */
  148. /*--------------------------------------------------------------------------*/
  149. if LoginStart = 'CR' then call send cr  /* Start with CR if required.       */
  150. call waitfor LoginPrompt                /* Wait for the prompt for          */
  151. call flush_receive 'echo'               /* username and reply               */
  152. call send LoginName || cr               /* with your login name.            */
  153. call waitfor PwPrompt                   /* Wait for the prompt for          */
  154. call flush_receive 'echo'               /* password and reply               */
  155. call send Password || cr                /* with your password.              */
  156. call waitfor ThirdPrompt                /* Wait for the menu prompt and     */
  157. call flush_receive 'echo'               /* respond with "SLIP" or "2" or    */
  158. call send ThirdAnswer || cr             /* whatever is required.            */
  159. call flush_receive 'echo'               /* Show it, and                     */
  160.  
  161.  
  162. /*==========================================================================*/
  163. /* WE NEED TO DO THIS SECTION IF OUR IP ADDRESS IS ASSIGNED AT LOGIN.       */
  164. /* Parse the results of the SLIP command to determine our address.          */
  165. /* We use the "waitfor_buff" variable from the waitfor routine to parse     */
  166. /* the stuff we get from the service provider after waiting for an          */
  167. /* appropriate point in the data stream.                                    */
  168. /* There's a section for extracting the Gateway address, and there's a      */
  169. /* section for extracting your address; switch them around according to     */
  170. /* your needs.                                                              */
  171. /*--------------------------------------------------------------------------*/
  172.  
  173. If Gateway = '*' then                    /* If we need to get IP's then     */
  174. DO                                       /* do this block.  First wait      */
  175.    call waitfor AddrMarker2              /* for text that tells you that    */
  176.    Gateway = GetIPAddr(waitfor_buff)     /* the line is in buffer; then     */
  177.    call flush_receive 'echo'             /* Do the flush.                   */
  178. END                                      /* extract it.                     */
  179.  
  180.  
  181. If MyIPAddress = '*' then                /* Next get your                   */
  182. DO                                       /* own IP address; first           */
  183.    call waitfor AddrMarker1              /* wait for next line.             */
  184.    MyIPAddress = GetIPAddr(waitfor_buff) /* Call extraction routine.        */
  185.    call flush_receive 'echo'             /* Flush anything else             */
  186. END                                      /* End of IP address collection.   */
  187.  
  188.  
  189. /*==========================================================================*/
  190. /* CONFIGURE THIS HOST                                                      */
  191. /* for appropriate address, and for default route through service provider. */
  192. /*--------------------------------------------------------------------------*/
  193. say 'SLIP Connection Established'
  194. say 'Configuring local address =' MyIPAddress Gateway
  195. 'ifconfig sl0' MyIPAddress Gateway 'netmask 255.255.255.0'
  196. 'route -f add default' Gateway '1'
  197.  
  198. exit 0
  199. /*--------------------------------------------------------------------------*/
  200. /* All done; end of main routine. (callable routines follow...)             */
  201. /*==========================================================================*/
  202.  
  203.  
  204. /*==========================================================================*/
  205. /* ONLY CALLABLE ROUTINES BELOW THIS POINT                                  */
  206. /*==========================================================================*/
  207.  
  208.  
  209. /*==========================================================================*/
  210. /*                            send ( sendstring)                            */
  211. /*..........................................................................*/
  212. /*                                                                          */
  213. /* Routine to send a character string off to the modem.                     */
  214. /*                                                                          */
  215. /*--------------------------------------------------------------------------*/
  216.  
  217. send:
  218.  
  219.    parse arg sendstring
  220.    call slip_com_output 'sl0' , sendstring
  221.  
  222.    return
  223.  
  224.  
  225. /*==========================================================================*/
  226. /*                    waitfor ( waitstring , [timeout] )                    */
  227. /*..........................................................................*/
  228. /*                                                                          */
  229. /* Waits for the supplied string to show up in the COM input.  All input    */
  230. /* from the time this function is called until the string shows up in the   */
  231. /* input is accumulated in the "waitfor_buff" variable.                     */
  232. /*                                                                          */
  233. /* If timeout is specified, it says how long to wait if data stops showing  */
  234. /* up on the COM port (in seconds).                                         */
  235. /*                                                                          */
  236. /*--------------------------------------------------------------------------*/
  237.  
  238. waitfor:
  239.  
  240.    parse arg waitstring , timeout              /* get text string and       */
  241.                                                /* timeout value in seconds. */
  242.    if timeout = '' then timeout = 5000         /* LONG delay if unspecified */
  243.    waitfor_buff = ''                           /* Clear waitfor_buff.       */
  244.    done = -1                                   /* Initialize a "done" flag. */
  245.    TimerVal = TIME('R')                        /* Reset the timer.          */
  246.  
  247.    do while (done = -1)                        /* Do below until a flag set.*/
  248.       line = slip_com_input('sl0',,10)         /* Get any input from COM,   */
  249.       if timeout>50 then                       /* don't need feedback       */
  250.          call charout , line                   /* while dialing.            */
  251.       waitfor_buff = waitfor_buff||line        /* append to waitfor_buff.   */
  252.       if pos(waitstring,waitfor_buff)>0 then   /* search the buffer for our */
  253.       DO                                       /* text string; if found,    */
  254.          done = 0                              /* Set done flag to indicate */
  255.          DO UNTIL line = ''                    /* 'til null (100ms. timeout)*/
  256.            line = slip_com_input('sl0',,100)   /* left in COM or modem buffs*/
  257.            waitfor_buff=waitfor_buff||line     /* Stick into buffer.        */
  258.          END
  259.       END
  260.       TimerVal = TRUNC( TIME('E') )            /* Get elapsed seconds.      */
  261.       If TimerVal<>LastTime & Timeout<50 then
  262.           call charout , CR||"Elapsed time:" TimerVal "  "
  263.       LastTime = TimerVal
  264.  
  265.       if TimerVal>timeout then do
  266.         call lineout , ' WAITFOR: timed out '
  267.         done = 1
  268.        end
  269.    end
  270.    return done
  271.  
  272.  
  273. /*--------------------------------------------------------------------------*/
  274. /*                             flush_receive ()                             */
  275. /*..........................................................................*/
  276. /*                                                                          */
  277. /* Routine to flush any pending characters to be read from the COM port.    */
  278. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  279. /* point it returns.                                                        */
  280. /*                                                                          */
  281. /* The optional echo argument, if present, says to echo flushed information.*/
  282. /*                                                                          */
  283. /*--------------------------------------------------------------------------*/
  284.  
  285. flush_receive:
  286.    parse arg echo                           /* this says if echo wanted.    */
  287.    if (echo \= '') then                     /* If echo wanted, and there    */
  288.       call charout , remain_buff            /* do the echo.                 */
  289.    remain_buff = ''                         /* Clear the remain_buff.       */
  290.    do until line = ''                       /* Until null (100ms. timeout)  */
  291.      line = slip_com_input('sl0',,100)      /* left in COM or modem buffers */
  292.      if echo \= '' then call charout , line /* just echo or throw away.     */
  293.    end
  294.  
  295.    return
  296.  
  297.  
  298. /*==========================================================================*/
  299. /*                             GetIPAddr ()                                 */
  300. /*--------------------------------------------------------------------------*/
  301. /* This routine takes a string of text with an IP (Internet Protocol)       */
  302. /* address buried somewhere in it, and returns the IP address only.         */
  303. /*..........................................................................*/
  304. GetIPAddr: Procedure                 /* Use procedure to isolate variables. */
  305. parse arg  a '.' b '.' c '.' d       /* Initial parsing; a & d may contain  */
  306. a = WORD(a, WORDS(a) )               /* excess: in a we only want last word */
  307. d = WORD(d, 1)                       /* and in d we only want first word.   */
  308. IPAddr = a||'.'||b||'.'||c||'.'||d   /* Put address components              */
  309. Say "IP Address extracted:" IPAddr   /* together, and report to             */
  310. return IPAddr                        /* user.                               */
  311.  
  312.  
  313. /*==========================================================================*/
  314. /*                            DoDial                                        */
  315. /*--------------------------------------------------------------------------*/
  316. /* This routine flushes the buffer; sends the dialcommand to the modem,     */
  317. /* and keeps a count of the number of tries.                                */
  318. /*..........................................................................*/
  319. DoDial:
  320. call flush_receive                   /* Flush stuff from prev. COM activity */
  321. DialCnt = DialCnt + 1                /* Count the dial attempt.             */
  322. If DialCnt>10 then                   /* Test to see if the maximum number   */
  323. DO                                   /* of retries will be exceeded.        */
  324.    say "...aborting after 10 tries." /* Bail out if                         */
  325.    exit                              /* no more retries are permitted.      */
  326. END
  327. call slip_com_output 'sl0' , dialcmd||cr  /* Dial remote server.            */
  328. OutString = 'Now Dialing (#'DialCnt')...' /* Give user some                 */
  329. call charout , crlf||Outstring||crlf      /* feedback.                      */
  330. return
  331.  
  332.  
  333.  
  334.