Class: Arachni::ComponentManager
- Includes:
- UI::Output
- Defined in:
- lib/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
<[email protected]>
<[email protected]>
@version: 0.1
Direct Known Subclasses
Module::Manager, Plugin::Manager, Report::FormatterManager, Report::Manager
Constant Summary collapse
- WILDCARD =
The following are used by #parse:
* '*' means all modules * module names prefixed with '-' will be excluded
'*'
- EXCLUDE =
'-'
Instance Method Summary collapse
-
#[](name) ⇒ Class
Returns a component class object by name, loading it on the fly need be.
-
#available ⇒ Array
Returns array of available component names.
-
#initialize(lib, parent) ⇒ ComponentManager
constructor
A new instance of ComponentManager.
-
#load(components) ⇒ Object
Loads components.
-
#name_to_path(name) ⇒ String
Converts the name of a component to a file-path.
-
#parse(components) ⇒ Array
It parses the component array making sure that its structure is valid.
-
#path_to_name(path) ⇒ String
Converts the path of a component to a component name.
-
#paths ⇒ Array
Returns the paths of all available components (excluding helper files).
-
#prep_opts(component_name, component, user_opts = {}) ⇒ Hash
Validates and prepares options for a given component.
- #wilcard_to_names(name) ⇒ Object
Methods included from UI::Output
#buffer, #debug!, #debug?, #flush_buffer, #mute!, #muted?, #only_positives!, #only_positives?, #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?, #unmute!, #verbose!, #verbose?
Constructor Details
#initialize(lib, parent) ⇒ ComponentManager
Returns a new instance of ComponentManager.
45 46 47 48 |
# File 'lib/component_manager.rb', line 45 def initialize( lib, parent ) @lib = lib @parent = parent end |
Instance Method Details
#[](name) ⇒ Class
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/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 |
#available ⇒ Array
Returns array of available component names.
206 207 208 209 210 211 212 213 214 |
# File 'lib/component_manager.rb', line 206 def available components = [] paths.each { |path| name = path_to_name( path ) components << name } return components end |
#load(components) ⇒ Object
Loads components.
55 56 57 58 59 60 |
# File 'lib/component_manager.rb', line 55 def load( components ) parse( components ).each { |component| self.[]( component ) } end |
#name_to_path(name) ⇒ String
Converts the name of a component to a file-path.
223 224 225 226 227 228 229 |
# File 'lib/component_manager.rb', line 223 def name_to_path( name ) paths.each { |path| return path if name == path_to_name( path ) } return end |
#parse(components) ⇒ Array
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/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 |
#path_to_name(path) ⇒ String
Converts the path of a component to a component name.
238 239 240 |
# File 'lib/component_manager.rb', line 238 def path_to_name( path ) File.basename( path, '.rb' ) end |
#paths ⇒ Array
Returns the paths of all available components (excluding helper files).
247 248 249 250 |
# File 'lib/component_manager.rb', line 247 def paths cpaths = paths = Dir.glob( File.join( "#{@lib}**", "*.rb" ) ) return paths.reject { |path| helper?( path ) } end |
#prep_opts(component_name, component, user_opts = {}) ⇒ Hash
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/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] 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 |