Class: Arachni::ComponentManager
- Inherits:
-
Hash
- Object
- Hash
- Arachni::ComponentManager
- Includes:
- UI::Output
- Defined in:
- lib/arachni/component_manager.rb
Overview
Component Manager
Handles modules, reports, path extrator modules, plug-ins, pretty much every modular aspect of the framework.
It is usually extended to fill-in for system specific functionality.
@author: Tasos "Zapotek" Laskos
<tasos.laskos@gmail.com>
<zapotek@segfault.gr>
@version: 0.1
Direct Known Subclasses
Module::Manager, Plugin::Manager, Report::FormatterManager, Report::Manager, UI::Web::AddonManager::RestrictedComponentManager
Constant Summary
- WILDCARD =
The following are used by #parse:
* '*' means all modules * module names prefixed with '-' will be excluded '*'- EXCLUDE =
'-'
Instance Method Summary (collapse)
-
- (Class) [](name)
Returns a component class object by name, loading it on the fly need be.
-
- (Array) available
Returns array of available component names.
-
- (ComponentManager) initialize(lib, namespace)
constructor
A new instance of ComponentManager.
-
- (Object) load(components)
Loads components.
-
- (String) name_to_path(name)
Converts the name of a component to a file-path.
-
- (Array) parse(components)
It parses the component array making sure that its structure is valid.
-
- (String) path_to_name(path)
Converts the path of a component to a component name.
-
- (Array) paths
Returns the paths of all available components (excluding helper files).
-
- (Hash) prep_opts(component_name, component, user_opts = {})
Validates and prepares options for a given component.
- - (Object) wilcard_to_names(name)
Methods included from UI::Output
#buffer, #debug!, #debug?, #flush_buffer, #mute!, #muted?, #only_positives!, #only_positives?, #print_bad, #print_debug, #print_debug_backtrace, #print_debug_pp, #print_error, #print_error_backtrace, #print_info, #print_line, #print_ok, #print_status, #print_verbose, #reroute_to_file, #reroute_to_file?, #uncap_buffer!, #unmute!, #verbose!, #verbose?
Constructor Details
- (ComponentManager) initialize(lib, namespace)
A new instance of ComponentManager
45 46 47 48 |
# File 'lib/arachni/component_manager.rb', line 45 def initialize( lib, namespace ) @lib = lib @namespace = namespace end |
Instance Method Details
- (Class) [](name)
Returns a component class object by name, loading it on the fly need be.
176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/arachni/component_manager.rb', line 176 def []( name ) return fetch( name ) if include?( name ) paths.each { |path| next if name != path_to_name( path ) self[path_to_name( path )] = load_from_path( path ) } return fetch( name ) rescue nil end |
- (Array) available
Returns array of available component names.
206 207 208 209 210 211 212 213 214 |
# File 'lib/arachni/component_manager.rb', line 206 def available components = [] paths.each { |path| name = path_to_name( path ) components << name } return components end |
- (Object) load(components)
Loads components.
55 56 57 58 59 60 |
# File 'lib/arachni/component_manager.rb', line 55 def load( components ) parse( components ).each { |component| self.[]( component ) } end |
- (String) name_to_path(name)
Converts the name of a component to a file-path.
223 224 225 226 227 228 229 |
# File 'lib/arachni/component_manager.rb', line 223 def name_to_path( name ) paths.each { |path| return path if name == path_to_name( path ) } return end |
- (Array) parse(components)
It parses the component array making sure that its structure is valid
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/arachni/component_manager.rb', line 117 def parse( components ) unload = [] load = [] return load if components[0] == EXCLUDE components.each { |component| if component[0] == EXCLUDE component[0] = '' if component[WILDCARD] unload |= wilcard_to_names( component ) else unload << component end end } if( !components.include?( WILDCARD ) ) avail_components = available( ) components.each { |component| if component.substring?( WILDCARD ) load |= wilcard_to_names( component ) else if( avail_components.include?( component ) ) load << component else raise( Arachni::Exceptions::ComponentNotFound, "Error: Component #{component} wasn't found." ) end end } load.flatten! else available( ).map { |component| load << component } end return load - unload end |
- (String) path_to_name(path)
Converts the path of a component to a component name.
238 239 240 |
# File 'lib/arachni/component_manager.rb', line 238 def path_to_name( path ) File.basename( path, '.rb' ) end |
- (Array) paths
Returns the paths of all available components (excluding helper files).
247 248 249 250 |
# File 'lib/arachni/component_manager.rb', line 247 def paths cpaths = paths = Dir.glob( File.join( "#{@lib}**", "*.rb" ) ) return paths.reject { |path| helper?( path ) } end |
- (Hash) prep_opts(component_name, component, user_opts = {})
Validates and prepares options for a given component.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/arachni/component_manager.rb', line 71 def prep_opts( component_name, component, user_opts = {} ) info = component.info return {} if !info.include?( :options ) || info[:options].empty? user_opts ||= {} = { } errors = { } info[:options].each { |opt| name = opt.name val = user_opts[name] || opt.default if( opt.empty_required_value?( val ) ) errors[name] = { :opt => opt, :value => val, :type => :empty_required_value } elsif( !opt.valid?( val ) ) errors[name] = { :opt => opt, :value => val, :type => :invalid } end val = !val.nil? ? val : opt.default [name] = opt.normalize( val ) } if( !errors.empty? ) print_errors( component_name, errors ) end return end |
- (Object) wilcard_to_names(name)
190 191 192 193 194 195 196 197 198 199 |
# File 'lib/arachni/component_manager.rb', line 190 def wilcard_to_names( name ) if name[WILDCARD] return paths.map { |path| path_to_name( path ) if path.match( Regexp.new( name ) ) }.compact end return end |