/* 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 ON, FORWARD and MSG commands of VT100 R2.9. The ON ** command is used to step this macro through each of the login steps. You ** can probably modify this macro a little and use it yourself. ** ** 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 if show("L", "rexxsupport.library") = 0 then call addlib "rexxsupport.library", 0, -30, 0 if arg() = 0 then do 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 /* Try 5 times to get a login prompt */ 'SEND "^M"' if get_match(2, "gin:") = 2 then leave end if i > 5 then do 'MSG "No login prompt!"' call cleanup 20 end call cleanup -1 'ON "word:" rx onlogon pwd1' /* Setup for 1st password */ 'SEND "acs^M"' end else do parse upper arg cmd if cmd = "PWD1" then do /* First password prompt */ 'SEND "your-pwd^M"' 'ON "word:" rx onlogon pwd2' /* Setup for 2nd password */ exit 0 end else if cmd = "PWD2" then do /* Second password prompt */ 'SEND "2nd-pwd^M"' 'ON "#?" rx onlogon termtp' /* Setup for term type prompt */ exit 0 end else if cmd = "TERMTP" then do /* Send our terminal type. While we're at it, cancel any ** outstanding ON commands. */ 'ON ""' 'SEND "1^M"' 'MSG "Logon successful!"' exit 0 end else do 'MSG "Unknown command:' cmd || '"' exit 20 end end exit 0 /* 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 */ /* 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 if retc = -1 then return exit retc