home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mega Top 1
/
os2_top1.zip
/
os2_top1
/
APPS
/
DATACOM
/
INTERNET
/
INTERNNL
/
NLNET.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1994-11-18
|
13KB
|
327 lines
/*---------------------------------------------------------------------------*/
/* */
/* OS/2 2.0 SLIP Driver for IBM TCP/IP version 2.0 */
/* */
/* NLNET.CMD */
/* */
/* .................................................. */
/* */
/* Sample attachment script for dialing into the XS4ALL entry node */
/* in order to establish a SLIP connection. This script should be */
/* specified using the "attachcmd" element in the SLIP */
/* configuration file SLIP.CFG in directory \TCPIP\ETC. A typical slip.cfg */
/* file for NLnet looks like this: */
/*
interface sl0 {
device=COM1,
mtu=1006,
compression=off,
attachcmd=nlnet,
attachparms="userid password atdt020-6947778 atdt020-6685445"
}
*/
/* The script parameters specify the username/password combination to use */
/* to login to the terminal server, and the command to send to the modem to */
/* dial. If there is more than one phone number for this service, you can */
/* repeat this dial command for each of the available phone numbers. They */
/* will be dialed in turn until you get a connection. */
/* If any of the parameters are omitted, or are specified as an asterisk (*),*/
/* the script will prompt for them. This is most useful with the password */
/* parameter to avoid storing the password in a text file on the disk. */
/* */
/* - - - - - - - - - - - - - - - - - - - - - - - - - */
/* */
/* When the script runs, it is automatically passed the interface name for */
/* the interface it is running on as the first argument. */
/* */
/* The script sends the dial string to the modem and then logs into the */
/* terminal server using the username/password. It requests the SLIP */
/* service to start SLIP, and parses the resulting output to determine the */
/* appropriate addresses to use. Lastly, it issues ifconfig and route */
/* commands to configure the OS/2 system appropriately. Note that the */
/* configuration assumes a class C netmask for the SLIP interface. */
/* */
/* The dial command (variable dialcmd) and the responses are modem dependent */
/* and therefore you need to adapt this script to be able to use the */
/* autodial function of your modem. The dial command you defined in the */
/* attachparms parameter in your SLIP.CFG file is passed to the modem */
/* without any change. */
/*---------------------------------------------------------------------------*/
parse arg interface , username password dialcmd
/*---------------------------------------------------------------------------*/
/* Initialization and Main Script Code */
/*---------------------------------------------------------------------------*/
/* The dialcmd is sent to the modem without any change. */
/* if you need a special dialog with your modem adapt the modem part of */
/* this script. */
/* The script wait for the string CONNECT, which is sent by Hayes */
/* compatible modems after the conection has been setup. */
/*****************************************************************************/
/* Variables used in rest of script. Adapt these if necessary */
comspeed = 57600 /* speed to set on our COM port */
waittime = 40 /* number of seconds to wait for CONNECT */
comport = 'COM1' /* serial port you use for modem */
/* Set the various prompt strings. They are not case sensitive. */
login_prompt = 'login:'
password_prompt = 'password:'
unix_prompt = 'inter.NL.net>'
IPaddress_prompt = 'Domain name'
/* Set the strings which precede & follow our address. Must be uppercase */
address_prefix = 'IP NUMBER ='
address_suffix = 'DOMAIN NAME'
vt_term = 'vt102'
cr='0d'x
lf='0a'x
/* Set the COM port. */
'MODE' comport || ':' comspeed || ',n,8,1'
/* Prompt for missing information */
If dialcmd = '' | dialcmd = '*' Then Do
Call Charout , 'Dial Command(s): '
Parse Pull dialcmd
End
If dialcmd = '' Then Do
Exit 0
End
maxnum = Words(dialcmd)
curnum = 0
Do i = 1 To maxnum
number.i = Word(dialcmd, i)
End
If username = '' | username = '*' Then Do
Call Charout , 'NLnet User Name: '
Parse Pull username
End
If password = '' | password = '*' Then Do
Call Charout , 'NLnet Password: '
password = readpass()
End
/* Send dial command until connected. */
rc = 1
Do While (rc = 1)
curnum = curnum + 1
If curnum > maxnum Then
curnum = 1
Say 'Sending Dial command to modem:'
Call Send 'ATH' || cr /* send hangup first */
Call Waitfor 'OK' /* and wait for it to take effect */
Call Send number.curnum || cr
Call Waitfor 'CONNECT',waittime
End
/* Make happy sound when connection established */
beep(262,100); beep(330,100); beep(392,100)
/* Clear buffer with modem output */
Call Flush_receive
Say ''
Say 'NLnet - SLIP Script (interface' interface')'
/* Flush any stuff left over from previous COM activity */
Call Flush_receive
/* For autobaud detection we have to send a couple of CRs */
Call Send cr
Call Waitfor login_prompt,2
Do While (rc = 1)
Call Send cr
Call Waitfor login_prompt,2
End
/* Flush any stuff left over from previous COM activity */
Call Flush_receive 'echo'
Call Charout , 'Now sending user name '
Call Send username || cr
Call Waitfor password_prompt
/* Flush any stuff left over from previous COM activity */
Call Flush_receive 'echo'
/* Give password */
Call Charout , 'Now sending password '
Call Send password || cr
Call Send vt_term || cr
Call Waitfor unix_prompt
Call Flush_receive 'echo'
/* Request SLIP service, with display of assigned IP address. */
Call Send "slip -address" || cr
/* Parse the results of the SLIP command to determine our address. */
/* We use the "input_buffer" variable from the waitfor routine */
/* to parse the stuff we get from the host after waiting for an */
/* appropriate point in the data stream. */
Call Waitfor IPaddress_prompt
Parse Upper Var input_buffer . (address_prefix) a '.' b '.' c '.' d (address_suffix) .
/* remove leading zeros and trailing blanks, if any */
a = Strip(a,'L',' ')
If a > 0 Then a = Strip(a,'L','0')
If b > 0 Then b = Strip(b,'L','0')
If c > 0 Then c = Strip(c,'L','0')
d = Strip(d,'T',lf)
d = Strip(d,'T',cr)
d = Strip(d,'T',' ')
If d > 0 Then d = Strip(d,'L','0')
os2_address = a||'.'||b||'.'||c||'.'||d
/* make a dummy address for the host */
e = d + 1
if e > 254 Then do
e = 253
end
host_address = a||'.'||b||'.'||c||'.'||e
/* Flush anything else */
Call Flush_receive 'echo'
/* Now configure this host for the appropriate address, */
/* and for a default route through the host. */
Say 'SLIP Connection Established'
Say 'Configuring local address =' os2_address ', Host =' host_address
'ifconfig sl0' os2_address host_address 'netmask 255.255.255.0'
'route -f add default' host_address '1'
/* All done */
Exit 0
/*--------------------------------------------------------------------*/
/* send ( sendstring) */
/*....................................................................*/
/* */
/* Routine to send a character string off to the modem. */
/* */
/*--------------------------------------------------------------------*/
Send:
Parse Arg sendstring
Call Slip_com_output interface , sendstring
Return
/*--------------------------------------------------------------------*/
/* waitfor ( waitstring , ìtimeout┘ ) */
/*....................................................................*/
/* */
/* Waits for the supplied string to show up in the COM input. All inp*/
/* from the time this function is called until the string shows up in */
/* input is accumulated in the "input_buffer" variable. */
/* N.B. The waitfor string is not case sensitive. */
/* */
/* If timeout is specified, it says how long to wait if data stops sho*/
/* up on the COM port (in seconds). */
/* */
/*--------------------------------------------------------------------*/
Waitfor:
Parse Upper Arg waitstring , timeout
If timeout = '' Then
timeout = 5000 /* L O N G delay if not specified*/
input_buffer = ''; waitfor_buffer = '' ; done = -1; curpos = 1
ori_time=Time('E')
If (remain_buffer = 'REMAIN_BUFFER') Then Do
remain_buffer = ''
End
Do While (done = -1)
If (remain_buffer \= '') Then Do
line = remain_buffer
remain_buffer = ''
End
Else Do
line = slip_com_input(interface,,10)
End
input_buffer = input_buffer || line
waitfor_buffer = Translate(input_buffer) /* translate to upper case */
index = Pos(waitstring,waitfor_buffer)
If (index > 0) Then Do
remain_buffer = Substr(input_buffer,index+Length(waitstring))
input_buffer = Delstr(input_buffer,index+Length(waitstring))
done = 0
End
Call Charout , Substr(input_buffer,curpos)
curpos = Length(input_buffer)+1
If ((done \= 0) & (Time('E')>timeout)) Then Do
Call Lineout , ' WAITFOR: timed out '
done = 1
End
End
timeout=0
rc=done
Return rc
/*--------------------------------------------------------------------*/
/* readpass () */
/*....................................................................*/
/* */
/* Routine used to read a password from the user without echoing the */
/* password to the screen. */
/* */
/*--------------------------------------------------------------------*/
Readpass:
answer = ''
Do Until key = cr
key = slip_getch()
If key \= cr Then Do
answer = answer || key
End
End
Say ''
Return answer
/*--------------------------------------------------------------------*/
/* flush_receive () */
/*....................................................................*/
/* */
/* Routine to flush any pending characters to be read from the COM por*/
/* Reads everything it can until nothing new shows up for 100ms, at wh*/
/* point it returns. */
/* */
/* The optional echo argument, says to echo flushed information . */
/* */
/*--------------------------------------------------------------------*/
Flush_receive:
Parse Arg echo
/* If echoing the flush - take care of waitfor remaining buffer*/
If (echo \= '') & (Length(remain_buffer) > 0) Then Do
Call Charout , remain_buffer
remain_buffer = ''
End
/* Eat anything left in the modem or COM buffers*/
/* Stop when nothing new appears for 100ms.*/
Do Until line = ''
line = slip_com_input(interface,,100)
If echo \= '' Then
Call Charout , line
End
Return