add the "makerc" command for quick resource script generation, fixes #738

git-svn-id: file:///home/svn/framework3/trunk@10119 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Joshua Drake 2010-08-23 21:19:01 +00:00
parent b6577681c6
commit 49beb83081
3 changed files with 46 additions and 7 deletions

View File

@ -91,6 +91,7 @@ class Core
"loadpath" => "Searches for and loads modules from a path",
"quit" => "Exit the console",
"resource" => "Run the commands stored in a file",
"makerc" => "Save commands entered since start to a file",
"route" => "Route traffic through a session",
"save" => "Saves the active datastores",
"search" => "Searches module names and descriptions",
@ -160,6 +161,18 @@ class Core
end
end
#
# Saves commands executed since the ui started to the specified msfrc file
#
def cmd_makerc(*args)
if args.empty?
print(
"Usage: makerc <output rc file>\n\n" +
"Save the commands executed since startup to the specified file.\n")
return false
end
driver.save_recent_history(args[0])
end
#
# Pop the current dispatcher stack context, assuming it isn't pointed at

View File

@ -263,6 +263,29 @@ class Driver < Msf::Ui::Driver
end
end
#
# Saves the recent history to the specified file
#
def save_recent_history(path)
num = Readline::HISTORY.length - hist_last_saved - 1
tmprc = ""
num.times { |x|
tmprc << Readline::HISTORY[hist_last_saved + x] + "\n"
}
if tmprc.length > 0
print_status("Saving last #{num} commands to #{path} ...")
save_resource(tmprc, path)
else
print_error("No commands to save!")
end
# Always update this, even if we didn't save anything. We do this
# so that we don't end up saving the "makerc" command itself.
self.hist_last_saved = Readline::HISTORY.length
end
#
# Creates the resource script file for the console.
#

View File

@ -47,6 +47,7 @@ module Shell
self.prompt_char = prompt_char
self.histfile = histfile
self.hist_last_saved = 0
end
def init_tab_complete
@ -56,6 +57,7 @@ module Shell
File.readlines(histfile).each { |e|
Readline::HISTORY << e.chomp
}
self.hist_last_saved = Readline::HISTORY.length
end
self.input.output = self.output
update_prompt(input.prompt)
@ -299,6 +301,7 @@ protected
attr_accessor :prompt # :nodoc:
attr_accessor :prompt_char, :tab_complete_proc # :nodoc:
attr_accessor :histfile # :nodoc:
attr_accessor :hist_last_saved # the number of history lines when last saved/loaded
attr_accessor :log_source, :stop_count # :nodoc:
end