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 / OnLogon.vt100 < prev    next >
Text File  |  1990-03-02  |  5KB  |  198 lines

  1. /*   This VT100 AREXX macro will try to log you onto a mythical machine at
  2. ** 555-1212.  This machine expects a username (signalled by the appearance of
  3. ** the character "gin:"), 2 passwords (eached signalled by "word:") and a
  4. ** terminal identifier (signalled by "#?").  If any step is unsuccessful this
  5. ** macro will abort and cause VT100 to issue an appropriate message.  If you
  6. ** get logged on via this macro, it will cause VT100 to display a success msg.
  7. **
  8. **   This macro uses the ON, FORWARD and MSG commands of VT100 R2.9.  The ON
  9. ** command is used to step this macro through each of the login steps.  You
  10. ** can probably modify this macro a little and use it yourself.
  11. **
  12. **   Note that this macro uses the AmigaDOS WAIT command (in routine receive:).
  13. ** This WILL cause your disks to be accessed every second or so while awaiting
  14. ** receipt of a character from the serial port.  AREXX 1.10 has a delay()
  15. ** which you can use to replace the AmigaDOS WAIT command.  Simply comment out
  16. ** the WAIT and un-comment the delay.
  17. **
  18. ** Tony Sumrall
  19. **/
  20. trace Off
  21.  
  22. if show("L", "rexxsupport.library") = 0
  23. then call addlib "rexxsupport.library", 0, -30, 0
  24.  
  25. if arg() = 0
  26. then do
  27.     portname = "REXX-VT100"
  28.     port = openport(portname)
  29.  
  30.     if Port = '0000 0000'x
  31.     then do
  32.         say "Couldn't open the port."
  33.         exit 20
  34.     end
  35.  
  36.     "FORWARD" portname
  37.     if rc ~= 0
  38.     then exit
  39.  
  40.     "BAUD 2400"
  41.  
  42.     if dial("DT555-1212") = 0
  43.     then do
  44.         'MSG "Dial failed."'
  45.         call cleanup 20
  46.     end
  47.  
  48.     do i = 1 to 5    /* Try 5 times to get a login prompt */
  49.         'SEND "^M"'
  50.  
  51.         if get_match(2, "gin:") = 2
  52.         then leave
  53.     end
  54.     if i > 5
  55.     then do
  56.         'MSG "No login prompt!"'
  57.         call cleanup 20
  58.     end
  59.  
  60.     call cleanup -1
  61.  
  62.     'ON "word:" rx onlogon pwd1'    /* Setup for 1st password */
  63.     'SEND "acs^M"'
  64. end
  65. else do
  66.     parse upper arg cmd
  67.     if cmd = "PWD1"
  68.     then do
  69.         /*   First password prompt */
  70.         'SEND "your-pwd^M"'
  71.         'ON "word:" rx onlogon pwd2'    /* Setup for 2nd password */
  72.         exit 0
  73.     end
  74.     else if cmd = "PWD2"
  75.     then do
  76.         /*   Second password prompt */
  77.         'SEND "2nd-pwd^M"'
  78.         'ON "#?" rx onlogon termtp'    /* Setup for term type prompt */
  79.         exit 0
  80.     end
  81.     else if cmd = "TERMTP"
  82.     then do
  83.         /*   Send our terminal type.  While we're at it, cancel any
  84.         ** outstanding ON commands. */
  85.         'ON ""'
  86.         'SEND "1^M"'
  87.         'MSG "Logon successful!"'
  88.         exit 0
  89.     end
  90.     else do
  91.         'MSG "Unknown command:' cmd || '"'
  92.         exit 20
  93.     end
  94. end
  95.  
  96. exit 0
  97.  
  98.  
  99. /*   Dial the specified number(s).  If we get no connection we keep going till
  100. ** we get a connection.  If we never get one then we return 0 for failure else
  101. ** we return 1 for success.
  102. **/
  103. dial: procedure expose port portname
  104. numargs = arg()
  105.  
  106. msgdata = ""
  107. do i = 1 to numargs
  108.     'SEND "AT' || arg(i) || '^M"'
  109.     if get_match(40, "CONNECT", "BUSY", "NO") = 2
  110.     then leave
  111. end
  112.  
  113. if i > numargs
  114. then return 0    /* Failure */
  115. else return 1    /* Success */
  116.  
  117. /*   Get a match from the serial port via VT100.  1st arg is the maximum time
  118. ** we'll wait; subsequent args are "acceptable" match strings.  We return the
  119. ** arg() index of the matched string so if we ever time out we'll return 1
  120. ** (since that's the index of the max time arg).
  121. **/
  122. get_match: procedure expose port portname
  123. numargs = arg()
  124. longest = 0
  125. do i = 2 to numargs
  126.     longest = max(longest, length(arg(i)))
  127. end
  128.  
  129. msgdata = ""
  130. maxtime = arg(1)
  131. do forever
  132.     msg = receive(maxtime)
  133.     if msg == ""
  134.     then return 1
  135.  
  136.     msgdata = msgdata || msg
  137.     do i = 2 to numargs
  138.         ndx = index(msgdata, arg(i))
  139.         if ndx > 0
  140.         then leave
  141.     end
  142.     if i <= numargs
  143.     then return i
  144.  
  145.     if length(msgdata) > longest
  146.     then msgdata = right(msgdata, longest - 1)
  147. end
  148.  
  149. /*   Don't use the AREXX waitpkt() function as that locks us up until something
  150. ** arrives at the port.  Instead, use the AmigaDOS WAIT command or, if you have
  151. ** AREXX 1.10 or later, the AREXX delay() function.
  152. **/
  153. receive: procedure expose port portname
  154. arg waittime
  155.  
  156. time = 0
  157. packet = getpkt(portname)
  158. do while packet = '0000 0000'x
  159.     if waittime ~= 0
  160.     then do
  161.         if time > waittime
  162.         then return ""
  163.         address COMMAND "WAIT 1 SEC"    /* AmigaDOS */
  164. /*        call delay 50                    /* AREXX 1.10 or above */ */
  165.         time = time + 1
  166.     end
  167.     else call waitpkt portname
  168.     packet = getpkt(portname)
  169. end
  170. msg = getarg(packet)
  171. call reply packet, 0
  172.  
  173. retval = ""
  174. do while length(msg) > 0
  175.     parse var msg first '00'x msg
  176.     retval = retval || first
  177. end
  178.  
  179. return retval
  180.  
  181. cleanup: procedure expose port portname
  182. arg retc
  183.  
  184. 'FORWARD'
  185.  
  186. packet = getpkt(portname)
  187. do while packet ~= '0000 0000'x
  188.     call reply packet, 0
  189.     packet = getpkt(portname)
  190. end
  191.  
  192. call closeport port
  193.  
  194. if retc = -1
  195. then return
  196.  
  197. exit retc
  198.