2012-06-29 05:18:28 +00:00
|
|
|
# -*- coding: binary -*-
|
2011-06-25 18:51:07 +00:00
|
|
|
require 'rex/ui'
|
|
|
|
|
|
|
|
module Rex
|
|
|
|
module Ui
|
|
|
|
module Text
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# This class implements output against a file and stdout
|
|
|
|
#
|
|
|
|
###
|
|
|
|
class Output::Tee < Rex::Ui::Text::Output
|
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
attr_accessor :fd
|
|
|
|
|
|
|
|
def initialize(path)
|
|
|
|
self.fd = ::File.open(path, "ab")
|
|
|
|
super()
|
|
|
|
end
|
|
|
|
|
|
|
|
def supports_color?
|
|
|
|
case config[:color]
|
|
|
|
when true
|
|
|
|
return true
|
|
|
|
when false
|
|
|
|
return false
|
|
|
|
else # auto
|
|
|
|
term = Rex::Compat.getenv('TERM')
|
|
|
|
return (term and term.match(/(?:vt10[03]|xterm(?:-color)?|linux|screen|rxvt)/i) != nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Prints the supplied message to file output.
|
|
|
|
#
|
|
|
|
def print_raw(msg = '')
|
|
|
|
$stdout.print(msg)
|
|
|
|
$stdout.flush
|
|
|
|
|
|
|
|
return if not self.fd
|
|
|
|
self.fd.write(msg)
|
|
|
|
self.fd.flush
|
|
|
|
msg
|
|
|
|
end
|
|
|
|
|
2014-12-30 00:47:04 +00:00
|
|
|
alias :write :print_raw
|
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
def close
|
|
|
|
self.fd.close if self.fd
|
|
|
|
self.fd = nil
|
|
|
|
end
|
2011-06-25 18:51:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|