CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/msf/util/document_generator.rb
Views: 11780
1
###
2
#
3
# This provides methods to generate documentation for a module.
4
#
5
###
6
7
8
module Msf
9
module Util
10
module DocumentGenerator
11
12
13
# Spawns a module document with a browser locally.
14
#
15
# @param mod [Msf::Module] Module to create document for.
16
# @param out_file [Rex::Quickfile] File handle to write the document to.
17
# @return [void]
18
def self.spawn_module_document(mod, out_file)
19
md = get_module_document(mod)
20
out_file.write(md)
21
Rex::Compat.open_webrtc_browser("file://#{out_file.path}")
22
end
23
24
25
# Returns a module document in HTML.
26
#
27
# @param mod [Msf::Module] Module to create document for.
28
# @return [void]
29
def self.get_module_document(mod)
30
kb_path = nil
31
kb = ''
32
33
user_path = File.join(PullRequestFinder::USER_MANUAL_BASE_PATH, "#{mod.fullname}.md")
34
global_path = File.join(PullRequestFinder::MANUAL_BASE_PATH, "#{mod.fullname}.md")
35
36
if File.exist?(user_path)
37
kb_path = user_path
38
elsif File.exist?(global_path)
39
kb_path = global_path
40
end
41
42
unless kb_path.nil?
43
File.open(kb_path, 'rb') { |f| kb = f.read }
44
end
45
46
begin
47
pr_finder = PullRequestFinder.new
48
pr = pr_finder.search(mod)
49
rescue PullRequestFinder::Exception => e
50
pr = e
51
end
52
53
n = DocumentNormalizer.new
54
items = {
55
mod_description: mod.description,
56
mod_authors: mod.send(:module_info)['Author'],
57
mod_fullname: mod.fullname,
58
mod_name: mod.name,
59
mod_pull_requests: pr,
60
mod_refs: mod.references,
61
mod_rank: mod.rank,
62
mod_rank_name: Msf::RankingName[mod.rank].capitalize,
63
mod_platforms: mod.send(:module_info)['Platform'],
64
mod_options: mod.options,
65
mod_side_effects: mod.side_effects,
66
mod_reliability: mod.reliability,
67
mod_stability: mod.stability,
68
mod_demo: mod
69
}
70
71
if mod.respond_to?(:targets) && mod.targets
72
items[:mod_targets] = mod.targets
73
end
74
75
n.get_md_content(items, kb).force_encoding('UTF-8')
76
end
77
78
end
79
end
80
end
81
82