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 >
Text File  |  1990-03-02  |  4KB  |  176 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 FORWARD and MSG commands of VT100 R2.9.  The FORWARD
  9. ** command is used to step through the login sequence.  This is a fairly slow
  10. ** process and is just used as an example.  If you would like to use some
  11. ** macro as a model, you would probably prefer to use OnLogon.vt100 as it
  12. ** runs MUCH faster.
  13. **
  14. **   Note that this macro uses the AmigaDOS WAIT command (in routine receive:).
  15. ** This WILL cause your disks to be accessed every second or so while awaiting
  16. ** receipt of a character from the serial port.  AREXX 1.10 has a delay()
  17. ** which you can use to replace the AmigaDOS WAIT command.  Simply comment out
  18. ** the WAIT and un-comment the delay.
  19. **
  20. ** Tony Sumrall
  21. **/
  22. trace Off
  23.  
  24. arg phone
  25.  
  26. portname = "REXX-VT100"
  27. port = openport(portname)
  28.  
  29. if Port = '0000 0000'x
  30. then do
  31.     say "Couldn't open the port."
  32.     exit 20
  33. end
  34.  
  35. "FORWARD" portname
  36. if rc ~= 0
  37. then exit
  38.  
  39. "BAUD 2400"
  40.  
  41. if dial("DT555-1212") = 0
  42. then do
  43.     'MSG "Dial failed."'
  44.     call cleanup 20
  45. end
  46.  
  47. do i = 1 to 5 while get_match(5, "gin:") ~= 2
  48.     'SEND "^M"'
  49. end
  50.  
  51. if login("acs^M", "word:", "1st-pwd^M", "word:", "2nd-pwd^M",,
  52.     "#?", "1^M") = 0
  53. then do
  54.     'MSG "Login failed."'
  55.     call cleanup 20
  56. end
  57.  
  58. 'MSG "Logon successful!"'
  59. call cleanup 0
  60. exit
  61.  
  62. /*   Dial the specified number(s).  If we get no connection we keep going till
  63. ** we get a connection.  If we never get one then we return 0 for failure else
  64. ** we return 1 for success.
  65. **/
  66. dial: procedure expose port portname
  67. numargs = arg()
  68.  
  69. msgdata = ""
  70. do i = 1 to numargs
  71.     'SEND "AT' || arg(i) || '^M"'
  72.     if get_match(40, "CONNECT", "BUSY", "NO") = 2
  73.     then leave
  74. end
  75.  
  76. if i > numargs
  77. then return 0    /* Failure */
  78. else return 1    /* Success */
  79.  
  80. /*   Login to a host.  We get send/expect sequences and we have to match a prior
  81. ** sequence before going on to the next one.  If we ever miss a match we return
  82. ** 0 for failure; if we match on all args we return 1 for success.
  83. **/
  84. login: procedure expose port portname
  85. numargs = arg()
  86.  
  87. msgdata = ""
  88. failures = 0
  89. do i = 1 to numargs
  90.     if i // 2 = 1
  91.     then 'SEND "' || arg(i) || '"'
  92.     else if get_match(5, arg(i)) ~= 2
  93.     then return 0
  94. end
  95.  
  96. return 1
  97.  
  98. /*   Get a match from the serial port via VT100.  1st arg is the maximum time
  99. ** we'll wait; subsequent args are "acceptable" match strings.  We return the
  100. ** arg() index of the matched string so if we ever time out we'll return 1
  101. ** (since that's the index of the max time arg).
  102. **/
  103. get_match: procedure expose port portname
  104. numargs = arg()
  105. longest = 0
  106. do i = 2 to numargs
  107.     longest = max(longest, length(arg(i)))
  108. end
  109.  
  110. msgdata = ""
  111. maxtime = arg(1)
  112. do forever
  113.     msg = receive(maxtime)
  114.     if msg == ""
  115.     then return 1
  116.  
  117.     msgdata = msgdata || msg
  118.     do i = 2 to numargs
  119.         ndx = index(msgdata, arg(i))
  120.         if ndx > 0
  121.         then leave
  122.     end
  123.     if i <= numargs
  124.     then return i
  125.  
  126.     if length(msgdata) > longest
  127.     then msgdata = right(msgdata, longest - 1)
  128. end
  129.  
  130. /*   Don't use the AREXX waitpkt() function as that locks us up until something
  131. ** arrives at the port.  Instead, use the AmigaDOS WAIT command or, if you have
  132. ** AREXX 1.10 or later, the AREXX delay() function.
  133. **/
  134. receive: procedure expose port portname
  135. arg waittime
  136.  
  137. time = 0
  138. packet = getpkt(portname)
  139. do while packet = '0000 0000'x
  140.     if waittime ~= 0
  141.     then do
  142.         if time > waittime
  143.         then return ""
  144.         address COMMAND "WAIT 1 SEC"    /* AmigaDOS */
  145. /*        call delay 50                    /* AREXX 1.10 or above */ */
  146.         time = time + 1
  147.     end
  148.     else call waitpkt portname
  149.     packet = getpkt(portname)
  150. end
  151. msg = getarg(packet)
  152. call reply packet, 0
  153.  
  154. retval = ""
  155. do while length(msg) > 0
  156.     parse var msg first '00'x msg
  157.     retval = retval || first
  158. end
  159.  
  160. return retval
  161.  
  162. cleanup: procedure expose port portname
  163. arg retc
  164.  
  165. 'FORWARD'
  166.  
  167. packet = getpkt(portname)
  168. do while packet ~= '0000 0000'x
  169.     call reply packet, 0
  170.     packet = getpkt(portname)
  171. end
  172.  
  173. call closeport port
  174.  
  175. exit retc
  176.