Class: ScripTTY::Apps::CaptureApp
- Inherits:
-
Object
- Object
- ScripTTY::Apps::CaptureApp
- Defined in:
- lib/scriptty/apps/capture_app.rb
Instance Attribute Summary collapse
-
#term ⇒ Object
readonly
Returns the value of attribute term.
Instance Method Summary collapse
- #detach_console(console) ⇒ Object
-
#exit ⇒ Object
Instruct the event loop to exit.
- #handle_console_command_entered(cmd) ⇒ Object
-
#initialize(argv) ⇒ CaptureApp
constructor
A new instance of CaptureApp.
- #log_messages ⇒ Object
- #main ⇒ Object
Constructor Details
#initialize(argv) ⇒ CaptureApp
Returns a new instance of CaptureApp.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/scriptty/apps/capture_app.rb', line 34 def initialize(argv) @client_connection = nil @server_connection = nil @output_file = nil @options = (argv) @console_password = "" # TODO SECURITY FIXME @attached_consoles = [] @net = ScripTTY::Net::EventLoop.new @log_stringio = StringIO.new @log = Logger.new(@log_stringio) @dump_counter = 1 end |
Instance Attribute Details
#term ⇒ Object (readonly)
Returns the value of attribute term.
32 33 34 |
# File 'lib/scriptty/apps/capture_app.rb', line 32 def term @term end |
Instance Method Details
#detach_console(console) ⇒ Object
47 48 49 |
# File 'lib/scriptty/apps/capture_app.rb', line 47 def detach_console(console) @attached_consoles.delete(console) end |
#exit ⇒ Object
Instruct the event loop to exit.
Can be invoked by another thread.
85 86 87 |
# File 'lib/scriptty/apps/capture_app.rb', line 85 def exit @net.exit end |
#handle_console_command_entered(cmd) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/scriptty/apps/capture_app.rb', line 89 def handle_console_command_entered(cmd) case cmd when /^'(.*)$/i # comment comment = $1.strip @output_file.info("Comment: #{comment}") if @output_file log.info("Comment: #{comment}") when /^d(ump)?$/i # Generate ScreenPattern based on a screen dump and write it to a file. cmd_dump else log.warn("Unknown console command: #{cmd}") end @last_command = cmd end |
#log_messages ⇒ Object
51 52 53 |
# File 'lib/scriptty/apps/capture_app.rb', line 51 def ([""]*10 + @log_stringio.string.split("\n"))[-10..-1].map{|line| line.sub(/^.*?\]/, '')} end |
#main ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/scriptty/apps/capture_app.rb', line 55 def main @output_file = Util::Transcript::Writer.new(File.open(@options[:output], @options[:append] ? "a" : "w")) if @options[:output] @output_file.info("--- Capture started #{Time.now} ---") if @output_file @net.on_accept(@options[:console_addrs] || [], :multiple => true) do |conn| p = ScripTTY::Net::PasswordPrompt.new(conn, "Console password: ") p.authenticate { |password| password == @console_password } p.on_fail { conn.write("Authentiation failed.\r\n") { conn.close } } p.on_success { @attached_consoles << ScripTTY::Net::Console.new(conn, self) @attached_consoles.each { |c| c.refresh! } } end @net.on_accept(@options[:listen_addrs], :multiple => true) do |conn| @output_file.client_open(*conn.remote_address) if @output_file @client_connection = conn @client_connection.on_receive_bytes { |bytes| handle_client_receive_bytes(bytes) } @client_connection.on_close { handle_client_close ; @client_connection = nil } handle_client_connected end @net.main ensure if @output_file @output_file.close @output_file = nil end end |