From 2776669a517d2bbd624157bf4ef616a7bdfd6c8d Mon Sep 17 00:00:00 2001 From: David Rude Date: Thu, 21 Jul 2011 18:19:43 +0000 Subject: [PATCH] reworked how the custom prompts work with different input streams git-svn-id: file:///home/svn/framework3/trunk@13279 4d416f70-5f16-0410-b530-b9f4589650da --- lib/rex/ui/text/input/readline.rb | 51 --------------------------- lib/rex/ui/text/shell.rb | 57 +++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 53 deletions(-) diff --git a/lib/rex/ui/text/input/readline.rb b/lib/rex/ui/text/input/readline.rb index 1ed383cad0..a18a797010 100644 --- a/lib/rex/ui/text/input/readline.rb +++ b/lib/rex/ui/text/input/readline.rb @@ -86,57 +86,6 @@ begin Thread.current.priority = -20 output.prompting - if framework - if prompt.include?("%T") - t = Time.now - if framework.datastore['PromptTimeFormat'] - t = t.strftime(framework.datastore['PromptTimeFormat']) - end - prompt.gsub!(/%T/, t.to_s) - end - - if prompt.include?("%H") - hostname = ENV['HOSTNAME'] - if hostname.nil? - hostname = `hostname`.split('.')[0] - end - - # check if hostname is still nil - if hostname.nil? - hostname = ENV['COMPUTERNAME'] - end - - if hostname.nil? - hostname = 'unknown' - end - - prompt.gsub!(/%H/, hostname.chomp) - end - - if prompt.include?("%U") - user = ENV['USER'] - if user.nil? - user = `whoami` - end - - # check if username is still nil - if user.nil? - user = ENV['USERNAME'] - end - - if user.nil? - user = 'unknown' - end - - prompt.gsub!(/%U/, user.chomp) - end - - prompt.gsub!(/%S/, framework.sessions.count.to_s) - prompt.gsub!(/%J/, framework.jobs.count.to_s) - prompt.gsub!(/%L/, Rex::Socket.source_address("50.50.50.50")) - prompt.gsub!(/%D/, ::Dir.getwd) - end - line = ::Readline.readline(prompt, true) ::Readline::HISTORY.pop if (line and line.empty?) ensure diff --git a/lib/rex/ui/text/shell.rb b/lib/rex/ui/text/shell.rb index acfb79d097..d9a5d66bb4 100644 --- a/lib/rex/ui/text/shell.rb +++ b/lib/rex/ui/text/shell.rb @@ -21,7 +21,8 @@ module Shell module InputShell attr_accessor :prompt, :output - def pgets + def pgets() + output.print(prompt) output.flush @@ -126,7 +127,59 @@ module Shell break if (self.stop_flag or self.stop_count > 1) init_tab_complete - line = input.pgets(self.framework) + + if framework + if input.prompt.include?("%T") + t = Time.now + if framework.datastore['PromptTimeFormat'] + t = t.strftime(framework.datastore['PromptTimeFormat']) + end + input.prompt.gsub!(/%T/, t.to_s) + end + + if input.prompt.include?("%H") + hostname = ENV['HOSTNAME'] + if hostname.nil? + hostname = `hostname`.split('.')[0] + end + + # check if hostname is still nil + if hostname.nil? + hostname = ENV['COMPUTERNAME'] + end + + if hostname.nil? + hostname = 'unknown' + end + + input.prompt.gsub!(/%H/, hostname.chomp) + end + + if input.prompt.include?("%U") + user = ENV['USER'] + if user.nil? + user = `whoami` + end + + # check if username is still nil + if user.nil? + user = ENV['USERNAME'] + end + + if user.nil? + user = 'unknown' + end + + input.prompt.gsub!(/%U/, user.chomp) + end + + input.prompt.gsub!(/%S/, framework.sessions.count.to_s) + input.prompt.gsub!(/%J/, framework.jobs.count.to_s) + input.prompt.gsub!(/%L/, Rex::Socket.source_address("50.50.50.50")) + input.prompt.gsub!(/%D/, ::Dir.getwd) + end + + line = input.pgets() log_output(input.prompt) # If a block was passed in, pass the line to it. If it returns true,