home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / DATACOM / INTERNET / INTERNNL / NLNET.CMD < prev    next >
OS/2 REXX Batch file  |  1994-11-18  |  13KB  |  327 lines

  1. /*---------------------------------------------------------------------------*/
  2. /*                                                                           */
  3. /*                OS/2 2.0 SLIP Driver for IBM TCP/IP version 2.0            */
  4. /*                                                                           */
  5. /*                               NLNET.CMD                                   */
  6. /*                                                                           */
  7. /*            ..................................................             */
  8. /*                                                                           */
  9. /* Sample attachment script for dialing into the XS4ALL   entry node         */
  10. /* in order to establish a SLIP connection.  This script should be           */
  11. /* specified using the "attachcmd" element in the SLIP                       */
  12. /* configuration file SLIP.CFG in directory \TCPIP\ETC.  A typical slip.cfg  */
  13. /* file for NLnet looks like this:                                           */
  14. /*
  15. interface sl0 {
  16.  device=COM1,
  17.  mtu=1006,
  18.  compression=off,
  19.  attachcmd=nlnet,
  20.  attachparms="userid password atdt020-6947778 atdt020-6685445"
  21. }
  22.                                                                              */
  23. /* The script parameters specify the username/password combination to use    */
  24. /* to login to the terminal server, and the command to send to the modem to  */
  25. /* dial. If there is more than one phone number for this service, you can    */
  26. /* repeat this dial command for each of the available phone numbers.  They   */
  27. /* will be dialed in turn until you get a connection.                        */
  28. /* If any of the parameters are omitted, or are specified as an asterisk (*),*/
  29. /* the script will prompt for them.  This is most useful with the password   */
  30. /* parameter to avoid storing the password in a text file on the disk.       */
  31. /*                                                                           */
  32. /*            - - - - - - - - - - - - - - - - - - - - - - - - -              */
  33. /*                                                                           */
  34. /* When the script runs, it is automatically passed the interface name for   */
  35. /* the interface it is running on as the first argument.                     */
  36. /*                                                                           */
  37. /* The script sends the dial string to the modem and then logs into the      */
  38. /* terminal server using the username/password.  It requests the SLIP        */
  39. /* service to start SLIP, and parses the resulting output to determine the   */
  40. /* appropriate addresses to use.  Lastly, it issues ifconfig and route       */
  41. /* commands to configure the OS/2 system appropriately.  Note that the       */
  42. /* configuration assumes a class C netmask for the SLIP interface.           */
  43. /*                                                                           */
  44. /* The dial command (variable dialcmd) and the responses are modem dependent */
  45. /* and therefore you need to adapt this script to be able to use the         */
  46. /* autodial function of your modem. The dial command you defined in the      */
  47. /* attachparms parameter in your SLIP.CFG file is passed to the modem        */
  48. /* without any change.                                                       */
  49. /*---------------------------------------------------------------------------*/
  50.  
  51. parse arg interface , username password dialcmd
  52. /*---------------------------------------------------------------------------*/
  53. /*                   Initialization and Main Script Code                     */
  54. /*---------------------------------------------------------------------------*/
  55. /* The dialcmd is sent to the modem without any change.                      */
  56. /* if you need a special dialog with your modem adapt the modem part of      */
  57. /* this script.                                                              */
  58. /* The script wait for the string CONNECT, which is sent by Hayes            */
  59. /* compatible modems after the conection has been setup.                     */
  60. /*****************************************************************************/
  61.  
  62. /* Variables used in rest of script. Adapt these if necessary      */
  63. comspeed = 57600                   /* speed to set on our COM port */
  64. waittime = 40                      /* number of seconds to wait for CONNECT */
  65. comport = 'COM1'                   /* serial port you use for modem */
  66.  
  67. /* Set the various prompt strings. They are not case sensitive.       */
  68. login_prompt = 'login:'
  69. password_prompt = 'password:'
  70. unix_prompt = 'inter.NL.net>'
  71. IPaddress_prompt = 'Domain name'
  72.  
  73. /* Set the strings which precede & follow our address. Must be uppercase */
  74. address_prefix = 'IP NUMBER ='
  75. address_suffix = 'DOMAIN NAME'
  76.  
  77. vt_term = 'vt102'
  78. cr='0d'x
  79. lf='0a'x
  80.  
  81. /* Set the COM port.                                                  */
  82. 'MODE' comport || ':' comspeed || ',n,8,1'
  83.  
  84. /* Prompt for missing information                                     */
  85. If dialcmd = '' | dialcmd = '*' Then Do
  86.   Call Charout , 'Dial Command(s): '
  87.   Parse Pull dialcmd
  88. End
  89. If dialcmd = ''  Then Do
  90.   Exit 0
  91. End
  92. maxnum = Words(dialcmd)
  93. curnum = 0
  94. Do i = 1 To maxnum
  95.   number.i = Word(dialcmd, i)
  96. End
  97. If username = '' | username = '*' Then Do
  98.   Call Charout , 'NLnet User Name: '
  99.   Parse Pull username
  100. End
  101. If password = '' | password = '*' Then Do
  102.   Call Charout , 'NLnet Password: '
  103.   password = readpass()
  104. End
  105.  
  106. /* Send dial command until connected.                                 */
  107. rc = 1
  108. Do While (rc = 1)
  109.   curnum = curnum + 1
  110.   If curnum > maxnum Then
  111.     curnum = 1
  112.   Say 'Sending Dial command to modem:'
  113.   Call Send 'ATH' || cr           /* send hangup first                */
  114.   Call Waitfor 'OK'               /* and wait for it to take effect   */
  115.   Call Send number.curnum || cr
  116.   Call Waitfor 'CONNECT',waittime
  117. End
  118.  
  119. /* Make happy sound when connection established                       */
  120. beep(262,100); beep(330,100); beep(392,100)
  121.  
  122. /* Clear buffer with modem output                                     */
  123. Call Flush_receive
  124.  
  125. Say ''
  126. Say 'NLnet - SLIP Script (interface' interface')'
  127.  
  128. /* Flush any stuff left over from previous COM activity               */
  129. Call Flush_receive
  130.  
  131. /* For autobaud detection we have to send a couple of CRs             */
  132. Call Send cr
  133. Call Waitfor login_prompt,2
  134. Do While (rc = 1)
  135.   Call Send cr
  136.   Call Waitfor login_prompt,2
  137. End
  138.  
  139. /* Flush any stuff left over from previous COM activity               */
  140. Call Flush_receive 'echo'
  141.  
  142. Call Charout , 'Now sending user name '
  143. Call Send username || cr
  144.  
  145. Call Waitfor password_prompt
  146. /* Flush any stuff left over from previous COM activity               */
  147. Call Flush_receive 'echo'
  148.  
  149. /* Give password                                                      */
  150. Call Charout , 'Now sending password '
  151.  
  152. Call Send password || cr
  153. Call Send vt_term || cr
  154. Call Waitfor unix_prompt
  155. Call Flush_receive 'echo'
  156.  
  157. /* Request SLIP service, with display of assigned IP address.         */
  158. Call Send "slip -address" || cr
  159.  
  160. /* Parse the results of the SLIP command to determine our address.    */
  161. /* We use the "input_buffer" variable from the waitfor routine        */
  162. /* to parse the stuff we get from the host after waiting for an       */
  163. /* appropriate point in the data stream.                              */
  164. Call Waitfor IPaddress_prompt
  165. Parse Upper Var input_buffer . (address_prefix) a '.' b '.' c '.' d (address_suffix) .
  166.  
  167. /* remove leading zeros and trailing blanks, if any                   */
  168. a = Strip(a,'L',' ')
  169. If a > 0 Then a = Strip(a,'L','0')
  170. If b > 0 Then b = Strip(b,'L','0')
  171. If c > 0 Then c = Strip(c,'L','0')
  172. d = Strip(d,'T',lf)
  173. d = Strip(d,'T',cr)
  174. d = Strip(d,'T',' ')
  175. If d > 0 Then d = Strip(d,'L','0')
  176. os2_address = a||'.'||b||'.'||c||'.'||d
  177.  
  178. /* make a dummy address for the host                                  */
  179. e = d + 1
  180. if e > 254 Then do
  181.    e = 253
  182. end
  183. host_address = a||'.'||b||'.'||c||'.'||e
  184.  
  185. /* Flush anything else                                                */
  186. Call Flush_receive 'echo'
  187.  
  188. /* Now configure this host for the appropriate address,               */
  189. /* and for a default route through the host.                          */
  190.  
  191. Say 'SLIP Connection Established'
  192. Say 'Configuring local address =' os2_address ', Host =' host_address
  193.  
  194. 'ifconfig sl0' os2_address host_address 'netmask 255.255.255.0'
  195. 'route -f add default' host_address '1'
  196.  
  197. /* All done                                                           */
  198. Exit 0
  199.  
  200.  
  201. /*--------------------------------------------------------------------*/
  202. /*                            send ( sendstring)                      */
  203. /*....................................................................*/
  204. /*                                                                    */
  205. /* Routine to send a character string off to the modem.               */
  206. /*                                                                    */
  207. /*--------------------------------------------------------------------*/
  208.  
  209. Send:
  210.  
  211. Parse Arg sendstring
  212. Call Slip_com_output interface , sendstring
  213.  
  214. Return
  215.  
  216.  
  217. /*--------------------------------------------------------------------*/
  218. /*                    waitfor ( waitstring , ìtimeout┘ )              */
  219. /*....................................................................*/
  220. /*                                                                    */
  221. /* Waits for the supplied string to show up in the COM input.  All inp*/
  222. /* from the time this function is called until the string shows up in */
  223. /* input is accumulated in the "input_buffer" variable.               */
  224. /* N.B. The waitfor string is not case sensitive.                     */
  225. /*                                                                    */
  226. /* If timeout is specified, it says how long to wait if data stops sho*/
  227. /* up on the COM port (in seconds).                                   */
  228. /*                                                                    */
  229. /*--------------------------------------------------------------------*/
  230.  
  231. Waitfor:
  232.  
  233. Parse Upper Arg waitstring , timeout
  234.  
  235. If timeout = '' Then
  236.   timeout = 5000                   /* L O N G   delay if not specified*/
  237. input_buffer = ''; waitfor_buffer = '' ; done = -1; curpos = 1
  238. ori_time=Time('E')
  239.  
  240. If (remain_buffer = 'REMAIN_BUFFER') Then Do
  241.   remain_buffer = ''
  242. End
  243.  
  244. Do While (done = -1)
  245.   If (remain_buffer \= '') Then Do
  246.     line = remain_buffer
  247.     remain_buffer = ''
  248.   End
  249.   Else Do
  250.     line = slip_com_input(interface,,10)
  251.   End
  252.   input_buffer = input_buffer || line
  253.   waitfor_buffer = Translate(input_buffer)  /* translate to upper case */
  254.   index = Pos(waitstring,waitfor_buffer)
  255.   If (index > 0) Then Do
  256.     remain_buffer = Substr(input_buffer,index+Length(waitstring))
  257.     input_buffer = Delstr(input_buffer,index+Length(waitstring))
  258.     done = 0
  259.   End
  260.   Call Charout , Substr(input_buffer,curpos)
  261.   curpos = Length(input_buffer)+1
  262.   If ((done \= 0) & (Time('E')>timeout)) Then Do
  263.     Call Lineout , ' WAITFOR: timed out '
  264.     done = 1
  265.   End
  266. End
  267. timeout=0
  268. rc=done
  269. Return rc
  270.  
  271.  
  272.  
  273. /*--------------------------------------------------------------------*/
  274. /*                               readpass ()                          */
  275. /*....................................................................*/
  276. /*                                                                    */
  277. /* Routine used to read a password from the user without echoing the  */
  278. /* password to the screen.                                            */
  279. /*                                                                    */
  280. /*--------------------------------------------------------------------*/
  281.  
  282. Readpass:
  283.  
  284. answer = ''
  285. Do Until key = cr
  286.   key = slip_getch()
  287.   If key \= cr Then Do
  288.     answer = answer || key
  289.   End
  290. End
  291. Say ''
  292. Return answer
  293.  
  294.  
  295. /*--------------------------------------------------------------------*/
  296. /*                             flush_receive ()                       */
  297. /*....................................................................*/
  298. /*                                                                    */
  299. /* Routine to flush any pending characters to be read from the COM por*/
  300. /* Reads everything it can until nothing new shows up for 100ms, at wh*/
  301. /* point it returns.                                                  */
  302. /*                                                                    */
  303. /* The optional echo argument, says to echo flushed information .     */
  304. /*                                                                    */
  305. /*--------------------------------------------------------------------*/
  306.  
  307. Flush_receive:
  308.  
  309. Parse Arg echo
  310.  
  311.        /* If echoing the flush - take care of waitfor remaining buffer*/
  312. If (echo \= '') & (Length(remain_buffer) > 0) Then Do
  313.   Call Charout , remain_buffer
  314.   remain_buffer = ''
  315. End
  316.  
  317.                       /* Eat anything left in the modem or COM buffers*/
  318.                            /* Stop when nothing new appears for 100ms.*/
  319.  
  320. Do Until line = ''
  321.   line = slip_com_input(interface,,100)
  322.   If echo \= '' Then
  323.     Call Charout , line
  324. End
  325.  
  326. Return
  327.