2012-06-29 05:18:28 +00:00
|
|
|
# -*- coding: binary -*-
|
2005-07-14 22:45:10 +00:00
|
|
|
require 'rex/ui'
|
|
|
|
|
|
|
|
module Rex
|
|
|
|
module Ui
|
|
|
|
module Text
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# This class acts as a base for all input mediums. It defines
|
2009-11-10 15:59:49 +00:00
|
|
|
# the interface that will be used by anything that wants to
|
2005-07-14 22:45:10 +00:00
|
|
|
# interact with a derived class.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
class Input
|
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
require 'rex/ui/text/input/stdio'
|
|
|
|
require 'rex/ui/text/input/readline'
|
|
|
|
require 'rex/ui/text/input/socket'
|
|
|
|
require 'rex/ui/text/input/buffer'
|
|
|
|
require 'rex/ui/text/color'
|
|
|
|
|
|
|
|
include Rex::Ui::Text::Color
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
self.eof = false
|
|
|
|
@config = {
|
|
|
|
:color => :auto, # true, false, :auto
|
|
|
|
}
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Whether or not the input medium supports readline.
|
|
|
|
#
|
|
|
|
def supports_readline
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Stub for tab completion reset
|
|
|
|
#
|
|
|
|
def reset_tab_completion
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Calls the underlying system read.
|
|
|
|
#
|
|
|
|
def sysread(len)
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Gets a line of input
|
|
|
|
#
|
|
|
|
def gets
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Has the input medium reached end-of-file?
|
|
|
|
#
|
|
|
|
def eof?
|
|
|
|
return eof
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns a pollable file descriptor that is associated with this
|
|
|
|
# input medium.
|
|
|
|
#
|
|
|
|
def fd
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Indicates whether or not this input medium is intrinsicly a
|
|
|
|
# shell provider. This would indicate whether or not it
|
|
|
|
# already expects to have a prompt.
|
|
|
|
#
|
|
|
|
def intrinsic_shell?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_prompt(new_prompt = '', new_prompt_char = '')
|
|
|
|
self.prompt = new_prompt + new_prompt_char
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_reader :config
|
|
|
|
|
|
|
|
def disable_color
|
|
|
|
return if not @config
|
|
|
|
@config[:color] = false
|
|
|
|
end
|
|
|
|
|
|
|
|
def enable_color
|
|
|
|
return if not @config
|
|
|
|
@config[:color] = true
|
|
|
|
end
|
|
|
|
|
|
|
|
def auto_color
|
|
|
|
return if not @config
|
|
|
|
@config[:color] = :auto
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_prompt(prompt)
|
|
|
|
substitute_colors(prompt, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
def reset_color
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_accessor :eof, :prompt, :prompt_char, :config
|
2005-07-14 22:45:10 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
2008-11-12 22:47:21 +00:00
|
|
|
end
|
2009-11-10 15:59:49 +00:00
|
|
|
|