add full support for persistent history, works in msfweb as well. fixes #523
git-svn-id: file:///home/svn/framework3/trunk@7621 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
1b4aa0380b
commit
fd61df4e9e
|
@ -49,6 +49,10 @@ class Driver < Msf::Ui::Driver
|
|||
# RealReadline
|
||||
#
|
||||
# Whether or to use the system Readline or the RBReadline (default)
|
||||
#
|
||||
# HistFile
|
||||
#
|
||||
# Name of a file to store command history
|
||||
#
|
||||
def initialize(prompt = DefaultPrompt, prompt_char = DefaultPromptChar, opts = {})
|
||||
|
||||
|
@ -65,11 +69,16 @@ class Driver < Msf::Ui::Driver
|
|||
# Default to the RbReadline wrapper
|
||||
require 'readline_compatible' if(not rl)
|
||||
|
||||
hist = Msf::Config.history_file
|
||||
File.readlines(hist).each {|e| Readline::HISTORY << e.chomp } if File.exists?(hist)
|
||||
histfile = opts['HistFile'] || Msf::Config.history_file
|
||||
|
||||
if histfile and File.exists?(histfile)
|
||||
File.readlines(histfile).each { |e|
|
||||
Readline::HISTORY << e.chomp
|
||||
}
|
||||
end
|
||||
|
||||
# Call the parent
|
||||
super(prompt, prompt_char)
|
||||
super(prompt, prompt_char, histfile)
|
||||
|
||||
# Temporarily disable output
|
||||
self.disable_output = true
|
||||
|
|
|
@ -87,7 +87,7 @@ module DispatcherShell
|
|||
#
|
||||
# Initialize the dispatcher shell.
|
||||
#
|
||||
def initialize(prompt, prompt_char = '>')
|
||||
def initialize(prompt, prompt_char = '>', histfile = nil)
|
||||
super
|
||||
|
||||
# Initialze the dispatcher array
|
||||
|
|
|
@ -36,7 +36,7 @@ module Shell
|
|||
#
|
||||
# Initializes a shell that has a prompt and can be interacted with.
|
||||
#
|
||||
def initialize(prompt, prompt_char = '>')
|
||||
def initialize(prompt, prompt_char = '>', histfile = nil)
|
||||
# Set the stop flag to false
|
||||
self.stop_flag = false
|
||||
self.disable_output = false
|
||||
|
@ -46,6 +46,8 @@ module Shell
|
|||
self.init_prompt = prompt
|
||||
self.prompt_char = prompt_char
|
||||
|
||||
self.histfile = histfile || ''
|
||||
|
||||
# Initialize the user interface handles
|
||||
init_ui(Input::Stdio.new, Output::Stdio.new)
|
||||
end
|
||||
|
@ -134,7 +136,14 @@ module Shell
|
|||
else
|
||||
# Otherwise, call what should be an overriden instance method to
|
||||
# process the line.
|
||||
run_single(line)
|
||||
ret = run_single(line)
|
||||
# don't bother saving lines that couldn't be found as a
|
||||
# command
|
||||
if ret and File.exists?(self.histfile)
|
||||
File.open(self.histfile, "a") { |f|
|
||||
f.puts(line)
|
||||
}
|
||||
end
|
||||
self.stop_count = 0
|
||||
end
|
||||
|
||||
|
@ -278,6 +287,7 @@ protected
|
|||
attr_accessor :stop_flag, :init_prompt # :nodoc:
|
||||
attr_accessor :prompt # :nodoc:
|
||||
attr_accessor :prompt_char, :tab_complete_proc # :nodoc:
|
||||
attr_accessor :histfile # :nodoc:
|
||||
attr_accessor :log_source, :stop_count # :nodoc:
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue