home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fred Fish Collection 1.5
/
ffcollection-1-5-1992-11.iso
/
ff_disks
/
300-399
/
ff330.lzh
/
Vt100
/
RexxSamples
/
FwdLogon.vt100
< prev
next >
Wrap
Text File
|
1990-03-02
|
4KB
|
176 lines
/* This VT100 AREXX macro will try to log you onto a mythical machine at
** 555-1212. This machine expects a username (signalled by the appearance of
** the character "gin:"), 2 passwords (eached signalled by "word:") and a
** terminal identifier (signalled by "#?"). If any step is unsuccessful this
** macro will abort and cause VT100 to issue an appropriate message. If you
** get logged on via this macro, it will cause VT100 to display a success msg.
**
** This macro uses the FORWARD and MSG commands of VT100 R2.9. The FORWARD
** command is used to step through the login sequence. This is a fairly slow
** process and is just used as an example. If you would like to use some
** macro as a model, you would probably prefer to use OnLogon.vt100 as it
** runs MUCH faster.
**
** Note that this macro uses the AmigaDOS WAIT command (in routine receive:).
** This WILL cause your disks to be accessed every second or so while awaiting
** receipt of a character from the serial port. AREXX 1.10 has a delay()
** which you can use to replace the AmigaDOS WAIT command. Simply comment out
** the WAIT and un-comment the delay.
**
** Tony Sumrall
**/
trace Off
arg phone
portname = "REXX-VT100"
port = openport(portname)
if Port = '0000 0000'x
then do
say "Couldn't open the port."
exit 20
end
"FORWARD" portname
if rc ~= 0
then exit
"BAUD 2400"
if dial("DT555-1212") = 0
then do
'MSG "Dial failed."'
call cleanup 20
end
do i = 1 to 5 while get_match(5, "gin:") ~= 2
'SEND "^M"'
end
if login("acs^M", "word:", "1st-pwd^M", "word:", "2nd-pwd^M",,
"#?", "1^M") = 0
then do
'MSG "Login failed."'
call cleanup 20
end
'MSG "Logon successful!"'
call cleanup 0
exit
/* Dial the specified number(s). If we get no connection we keep going till
** we get a connection. If we never get one then we return 0 for failure else
** we return 1 for success.
**/
dial: procedure expose port portname
numargs = arg()
msgdata = ""
do i = 1 to numargs
'SEND "AT' || arg(i) || '^M"'
if get_match(40, "CONNECT", "BUSY", "NO") = 2
then leave
end
if i > numargs
then return 0 /* Failure */
else return 1 /* Success */
/* Login to a host. We get send/expect sequences and we have to match a prior
** sequence before going on to the next one. If we ever miss a match we return
** 0 for failure; if we match on all args we return 1 for success.
**/
login: procedure expose port portname
numargs = arg()
msgdata = ""
failures = 0
do i = 1 to numargs
if i // 2 = 1
then 'SEND "' || arg(i) || '"'
else if get_match(5, arg(i)) ~= 2
then return 0
end
return 1
/* Get a match from the serial port via VT100. 1st arg is the maximum time
** we'll wait; subsequent args are "acceptable" match strings. We return the
** arg() index of the matched string so if we ever time out we'll return 1
** (since that's the index of the max time arg).
**/
get_match: procedure expose port portname
numargs = arg()
longest = 0
do i = 2 to numargs
longest = max(longest, length(arg(i)))
end
msgdata = ""
maxtime = arg(1)
do forever
msg = receive(maxtime)
if msg == ""
then return 1
msgdata = msgdata || msg
do i = 2 to numargs
ndx = index(msgdata, arg(i))
if ndx > 0
then leave
end
if i <= numargs
then return i
if length(msgdata) > longest
then msgdata = right(msgdata, longest - 1)
end
/* Don't use the AREXX waitpkt() function as that locks us up until something
** arrives at the port. Instead, use the AmigaDOS WAIT command or, if you have
** AREXX 1.10 or later, the AREXX delay() function.
**/
receive: procedure expose port portname
arg waittime
time = 0
packet = getpkt(portname)
do while packet = '0000 0000'x
if waittime ~= 0
then do
if time > waittime
then return ""
address COMMAND "WAIT 1 SEC" /* AmigaDOS */
/* call delay 50 /* AREXX 1.10 or above */ */
time = time + 1
end
else call waitpkt portname
packet = getpkt(portname)
end
msg = getarg(packet)
call reply packet, 0
retval = ""
do while length(msg) > 0
parse var msg first '00'x msg
retval = retval || first
end
return retval
cleanup: procedure expose port portname
arg retc
'FORWARD'
packet = getpkt(portname)
do while packet ~= '0000 0000'x
call reply packet, 0
packet = getpkt(portname)
end
call closeport port
exit retc