metasploit-framework/lib/msf/util/document_generator.rb

75 lines
2.0 KiB
Ruby
Raw Normal View History

###
#
# This provides methods to generate documentation for a module.
#
###
require 'msf/util/document_generator/pull_request_finder'
require 'msf/util/document_generator/normalizer'
module Msf
module Util
module DocumentGenerator
2016-02-18 17:44:14 +00:00
# Spawns a module document with a browser locally.
#
# @param mod [Msf::Module] Module to create document for.
# @return [void]
def self.spawn_module_document(mod)
2016-02-18 21:02:24 +00:00
md = get_module_document(mod)
f = Rex::Quickfile.new(["#{mod.shortname}_doc", '.html'])
f.write(md)
f.close
kb_path = f.path
print_status("Opening web browser for file://#{kb_path}")
2016-02-18 21:02:24 +00:00
Rex::Compat.open_webrtc_browser("file://#{kb_path}")
2016-02-18 06:39:12 +00:00
end
2016-02-18 17:44:14 +00:00
# Returns a module document in HTML.
#
# @param mod [Msf::Module] Module to create document for.
# @return [void]
def self.get_module_document(mod)
md = ''
2016-02-18 21:02:24 +00:00
kb_path = File.join(PullRequestFinder::MANUAL_BASE_PATH, "#{mod.fullname}.md")
kb = ''
2016-04-20 12:11:34 +00:00
if File.exist?(kb_path)
2016-02-18 21:02:24 +00:00
File.open(kb_path, 'rb') { |f| kb = f.read }
end
2016-02-18 21:02:24 +00:00
begin
pr_finder = PullRequestFinder.new
pr = pr_finder.search(mod)
rescue PullRequestFinder::Exception => e
pr = e
end
n = DocumentNormalizer.new
items = {
mod_description: mod.description,
mod_authors: mod.send(:module_info)['Author'],
mod_fullname: mod.fullname,
mod_name: mod.name,
mod_pull_requests: pr,
mod_refs: mod.references,
mod_rank: mod.rank,
mod_platforms: mod.send(:module_info)['Platform'],
2016-02-17 20:27:29 +00:00
mod_options: mod.options,
mod_demo: mod
2016-02-18 21:02:24 +00:00
}
2016-02-18 21:02:24 +00:00
if mod.respond_to?(:targets) && mod.targets
items[:mod_targets] = mod.targets
end
2016-02-18 21:02:24 +00:00
n.get_md_content(items, kb)
end
end
end
end