CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/msf/base/simple/framework/module_paths.rb
Views: 1904
1
# -*- coding: binary -*-
2
require 'rails'
3
module Msf
4
module Simple
5
module Framework
6
module ModulePaths
7
8
attr_accessor :configured_module_paths
9
attr_accessor :module_paths_inited
10
11
# Initialize the module paths
12
#
13
# @return [void]
14
def init_module_paths(opts = {})
15
if @module_paths_inited
16
raise 'Module paths already initialized. To add more module paths call `modules.add_module_path`'
17
end
18
19
@configured_module_paths = []
20
extract_engine_module_paths(Rails.application).each do |path|
21
@configured_module_paths << path
22
end
23
24
if Msf::Config.user_module_directory
25
@configured_module_paths << Msf::Config.user_module_directory
26
end
27
28
::Rails::Engine.subclasses.map(&:instance).each do |engine|
29
extract_engine_module_paths(engine).each do |path|
30
@configured_module_paths << path
31
end
32
end
33
34
# If additional module paths have been defined globally, then load them.
35
# They should be separated by semi-colons.
36
self.datastore['MsfModulePaths'].to_s.split(";").each do |path|
37
@configured_module_paths << path
38
end
39
40
# If the caller had additional paths to search, load them.
41
# They should be separated by semi-colons.
42
opts.delete(:module_paths).to_s.split(";").each do |path|
43
@configured_module_paths << path
44
end
45
46
# Remove any duplicate paths
47
@configured_module_paths.uniq!
48
# return early if we're deferring module loading
49
return if opts.delete(:defer_module_loads)
50
51
# Update the module cache from the database
52
self.modules.refresh_cache_from_database(@configured_module_paths)
53
54
# Load each of the module paths
55
@configured_module_paths.each do |path|
56
self.modules.add_module_path(path, opts, recalculate: false)
57
end
58
59
@module_paths_inited = true
60
end
61
62
private
63
64
# Extract directories `engine.paths['modules']` from `engine`.
65
#
66
# @param engine [Rails::Engine] a rails engine or application
67
# @return [Array<String>] The list of module paths to load
68
def extract_engine_module_paths(engine)
69
engine.paths['modules'] ? engine.paths['modules'].existent_directories : []
70
end
71
72
end
73
end
74
end
75
end
76
77