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

  1. /*---------------------------------------------------------------------------*/
  2. /*                                                                           */
  3. /*                OS/2 2.0 SLIP Driver for IBM TCP/IP version 2.0            */
  4. /*                                                                           */
  5. /*                               XS4ALL.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 XS4ALL looks like this:                                          */
  14. /*
  15. interface sl0 {
  16.  device=COM1,
  17.  mtu=1006,
  18.  compression=on,
  19.  attachcmd=xs4all,
  20.  attachparms="userid password atdt020-6222175 atdt020-6265060"
  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 = '/'
  71. IPaddress_prompt = 'for user '
  72.  
  73. /* Set the strings which precede & follow our address. Must be uppercase */
  74. address_prefix = 'IP NUMBER'
  75. address_suffix = 'FOR USER'
  76.  
  77. cr='0d'x
  78.  
  79. /* Set the COM port.                                                  */
  80. 'MODE' comport || ':' comspeed || ',n,8,1'
  81.  
  82. /* Prompt for missing information                                     */
  83. If dialcmd = '' | dialcmd = '*' Then Do
  84.   Call Charout , 'Dial Command: '
  85.   Parse Pull dialcmd
  86. End
  87. If dialcmd = ''  Then Do
  88.   Exit 0
  89. End
  90. maxnum = Words(dialcmd)
  91. curnum = 0
  92. Do i = 1 To maxnum
  93.   number.i = Word(dialcmd, i)
  94. End
  95. If username = '' | username = '*' Then Do
  96.   Call Charout , 'XS4ALL User Name: '
  97.   Parse Pull username
  98. End
  99. If password = '' | password = '*' Then Do
  100.   Call Charout , 'XS4ALL Password: '
  101.   password = readpass()
  102. End
  103. unix_prompt = unix_prompt || username
  104. IPaddress_prompt = IPaddress_prompt || username
  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 'XS4ALL - 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 Waitfor unix_prompt
  154. Call Flush_receive 'echo'
  155.  
  156. /* Request SLIP service, without prompting for IP address             */
  157. Call Send "slip -y" || cr
  158.  
  159. /* Parse the results of the SLIP command to determine our address.    */
  160. /* We use the "input_buffer" variable from the waitfor routine        */
  161. /* to parse the stuff we get from the host after waiting for an       */
  162. /* appropriate point in the data stream.                              */
  163. Call Waitfor IPaddress_prompt
  164. Parse Upper Var input_buffer . (address_prefix) a '.' b '.' c '.' d (address_suffix) .
  165.  
  166. /* remove leading zeros and trailing blanks, if any                   */
  167. If a > 0 Then a = Strip(a,'L','0')
  168. If b > 0 Then b = Strip(b,'L','0')
  169. If c > 0 Then c = Strip(c,'L','0')
  170. d = Strip(d,'T',' ')
  171. If d > 0 Then d = Strip(d,'L','0')
  172. os2_address = a||'.'||b||'.'||c||'.'||d
  173.  
  174. /* make a dummy address for the host                                  */
  175. e = d + 1
  176. if e > 254 Then do
  177.    e = 253
  178. end
  179. host_address = a||'.'||b||'.'||c||'.'||e
  180.  
  181. /* Flush anything else                                                */
  182. Call Flush_receive 'echo'
  183.  
  184. /* Now configure this host for the appropriate address,               */
  185. /* and for a default route through the host.                          */
  186.  
  187. Say 'SLIP Connection Established'
  188. Say 'Configuring local address =' os2_address ', Host =' host_address
  189.  
  190. 'ifconfig sl0' os2_address host_address 'netmask 255.255.255.0'
  191. 'route -f add default' host_address '1'
  192.  
  193. /* All done                                                           */
  194. Exit 0
  195.  
  196.  
  197. /*--------------------------------------------------------------------*/
  198. /*                            send ( sendstring)                      */
  199. /*....................................................................*/
  200. /*                                                                    */
  201. /* Routine to send a character string off to the modem.               */
  202. /*                                                                    */
  203. /*--------------------------------------------------------------------*/
  204.  
  205. Send:
  206.  
  207. Parse Arg sendstring
  208. Call Slip_com_output interface , sendstring
  209.  
  210. Return
  211.  
  212.  
  213. /*--------------------------------------------------------------------*/
  214. /*                    waitfor ( waitstring , [timeout] )              */
  215. /*....................................................................*/
  216. /*                                                                    */
  217. /* Waits for the supplied string to show up in the COM input.  All inp*/
  218. /* from the time this function is called until the string shows up in */
  219. /* input is accumulated in the "input_buffer" variable.               */
  220. /* N.B. The waitfor string is not case sensitive.                     */
  221. /*                                                                    */
  222. /* If timeout is specified, it says how long to wait if data stops sho*/
  223. /* up on the COM port (in seconds).                                   */
  224. /*                                                                    */
  225. /*--------------------------------------------------------------------*/
  226.  
  227. Waitfor:
  228.  
  229. Parse Upper Arg waitstring , timeout
  230.  
  231. If timeout = '' Then
  232.   timeout = 5000                   /* L O N G   delay if not specified*/
  233. input_buffer = ''; waitfor_buffer = '' ; done = -1; curpos = 1
  234. ori_time=Time('E')
  235.  
  236. If (remain_buffer = 'REMAIN_BUFFER') Then Do
  237.   remain_buffer = ''
  238. End
  239.  
  240. Do While (done = -1)
  241.   If (remain_buffer \= '') Then Do
  242.     line = remain_buffer
  243.     remain_buffer = ''
  244.   End
  245.   Else Do
  246.     line = slip_com_input(interface,,10)
  247.   End
  248.   input_buffer = input_buffer || line
  249.   waitfor_buffer = Translate(input_buffer)  /* translate to upper case */
  250.   index = Pos(waitstring,waitfor_buffer)
  251.   If (index > 0) Then Do
  252.     remain_buffer = Substr(input_buffer,index+Length(waitstring))
  253.     input_buffer = Delstr(input_buffer,index+Length(waitstring))
  254.     done = 0
  255.   End
  256.   Call Charout , Substr(input_buffer,curpos)
  257.   curpos = Length(input_buffer)+1
  258.   If ((done \= 0) & (Time('E')>timeout)) Then Do
  259.     Call Lineout , ' WAITFOR: timed out '
  260.     done = 1
  261.   End
  262. End
  263. timeout=0
  264. rc=done
  265. Return rc
  266.  
  267.  
  268.  
  269. /*--------------------------------------------------------------------*/
  270. /*                               readpass ()                          */
  271. /*....................................................................*/
  272. /*                                                                    */
  273. /* Routine used to read a password from the user without echoing the  */
  274. /* password to the screen.                                            */
  275. /*                                                                    */
  276. /*--------------------------------------------------------------------*/
  277.  
  278. Readpass:
  279.  
  280. answer = ''
  281. Do Until key = cr
  282.   key = slip_getch()
  283.   If key \= cr Then Do
  284.     answer = answer || key
  285.   End
  286. End
  287. Say ''
  288. Return answer
  289.  
  290.  
  291. /*--------------------------------------------------------------------*/
  292. /*                             flush_receive ()                       */
  293. /*....................................................................*/
  294. /*                                                                    */
  295. /* Routine to flush any pending characters to be read from the COM por*/
  296. /* Reads everything it can until nothing new shows up for 100ms, at wh*/
  297. /* point it returns.                                                  */
  298. /*                                                                    */
  299. /* The optional echo argument, says to echo flushed information .     */
  300. /*                                                                    */
  301. /*--------------------------------------------------------------------*/
  302.  
  303. Flush_receive:
  304.  
  305. Parse Arg echo
  306.  
  307.        /* If echoing the flush - take care of waitfor remaining buffer*/
  308. If (echo \= '') & (Length(remain_buffer) > 0) Then Do
  309.   Call Charout , remain_buffer
  310.   remain_buffer = ''
  311. End
  312.  
  313.                       /* Eat anything left in the modem or COM buffers*/
  314.                            /* Stop when nothing new appears for 100ms.*/
  315.  
  316. Do Until line = ''
  317.   line = slip_com_input(interface,,100)
  318.   If echo \= '' Then
  319.     Call Charout , line
  320. End
  321.  
  322. Return
  323.