Class: Arachni::Processes::Instances
- Includes:
- Utilities, Singleton
- Defined in:
- lib/arachni/processes/instances.rb
Overview
Helper for managing RPC::Server::Instance processes.
Instance Attribute Summary collapse
-
#list ⇒ Array<String>
readonly
URLs and tokens of all running Instances.
Class Method Summary collapse
Instance Method Summary collapse
-
#connect(url, token = nil) ⇒ RPC::Client::Instance
Connects to a Instance by URL.
-
#dispatcher_spawn ⇒ RPC::Client::Instance
Starts RPC::Server::Dispatcher and returns an Instance.
- #each(&block) ⇒ Object
-
#grid_spawn(options = {}) ⇒ RPC::Client::Instance
Starts RPC::Server::Dispatcher grid and returns a high-performance Instance.
-
#initialize ⇒ Instances
constructor
A new instance of Instances.
-
#killall ⇒ Object
Kills all #list.
-
#spawn(options = {}, &block) ⇒ RPC::Client::Instance
Spawns an RPC::Server::Instance process.
-
#token_for(client_or_url) ⇒ String
Cached authentication token for the given Instance.
Methods included from Utilities
#available_port, #cookie_encode, #cookies_from_document, #cookies_from_file, #cookies_from_response, #exception_jail, #exclude_path?, #extract_domain, #follow_protocol?, #form_decode, #form_encode, #form_parse_request_body, #forms_from_document, #forms_from_response, #generate_token, #get_path, #html_decode, #html_encode, #include_path?, #links_from_document, #links_from_response, #normalize_url, #page_from_response, #page_from_url, #parse_query, #parse_set_cookie, #parse_url_vars, #path_in_domain?, #path_too_deep?, #port_available?, #rand_port, #redundant_path?, #remove_constants, #seed, #skip_page?, #skip_path?, #skip_resource?, #to_absolute, #uri_decode, #uri_encode, #uri_parse, #uri_parser, #url_sanitize
Constructor Details
#initialize ⇒ Instances
Returns a new instance of Instances.
32 33 34 35 |
# File 'lib/arachni/processes/instances.rb', line 32 def initialize @list = {} @instance_connections = {} end |
Instance Attribute Details
Class Method Details
.method_missing(sym, *args, &block) ⇒ Object
182 183 184 185 186 187 188 |
# File 'lib/arachni/processes/instances.rb', line 182 def self.method_missing( sym, *args, &block ) if instance.respond_to?( sym ) instance.send( sym, *args, &block ) elsif super( sym, *args, &block ) end end |
.respond_to?(m) ⇒ Boolean
190 191 192 |
# File 'lib/arachni/processes/instances.rb', line 190 def self.respond_to?( m ) super( m ) || instance.respond_to?( m ) end |
Instance Method Details
#connect(url, token = nil) ⇒ RPC::Client::Instance
Connects to a Instance by URL.
46 47 48 49 50 51 |
# File 'lib/arachni/processes/instances.rb', line 46 def connect( url, token = nil ) token ||= @list[url] @list[url] ||= token @instance_connections[url] ||= RPC::Client::Instance.new( Options.instance, url, token ) end |
#dispatcher_spawn ⇒ RPC::Client::Instance
Starts RPC::Server::Dispatcher and returns an Instance.
160 161 162 163 |
# File 'lib/arachni/processes/instances.rb', line 160 def dispatcher_spawn info = Dispatchers.light_spawn.dispatch connect( info['url'], info['token'] ) end |
#each(&block) ⇒ Object
54 55 56 57 58 |
# File 'lib/arachni/processes/instances.rb', line 54 def each( &block ) @list.keys.each do |url| block.call connect( url ) end end |
#grid_spawn(options = {}) ⇒ RPC::Client::Instance
Starts RPC::Server::Dispatcher grid and returns a high-performance Instance.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/arachni/processes/instances.rb', line 136 def grid_spawn( = {} ) [:grid_size] ||= 3 last_member = nil [:grid_size].times do |i| last_member = Dispatchers.light_spawn( neighbour: last_member ? last_member.url : last_member, pipe_id: available_port.to_s + available_port.to_s ) end info = last_member.dispatch instance = connect( info['url'], info['token'] ) instance.framework.set_as_master instance.opts.grid_mode = :aggregate instance end |
#killall ⇒ Object
Kills all #list.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/arachni/processes/instances.rb', line 166 def killall pids = [] each do |instance| begin pids |= instance.service.consumed_pids rescue => e #ap e #ap e.backtrace end end @list.clear @instance_connections.clear Manager.kill_many pids end |
#spawn(options = {}, &block) ⇒ RPC::Client::Instance
Spawns an RPC::Server::Instance process.
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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/arachni/processes/instances.rb', line 81 def spawn( = {}, &block ) [:token] ||= generate_token = Options.to_hash.symbolize_keys( false ).merge( ) [:rpc_port] = .delete( :port ) if .include?( :port ) [:rpc_address] = .delete( :address ) if .include?( :address ) [:rpc_socket] = .delete( :socket ) if .include?( :socket ) [:rpc_port] ||= available_port url = nil if [:rpc_socket] url = [:rpc_socket] .delete :rpc_address .delete :rpc_port else url = "#{[:rpc_address]}:#{[:rpc_port]}" end Manager.quiet_fork do Options.set( ) block.call( Options.instance ) if block_given? require "#{Arachni::Options.dir['lib']}/rpc/server/instance" RPC::Server::Instance.new( Options.instance, [:token] ) end begin Timeout.timeout( 10 ) do while sleep( 0.1 ) begin connect( url, [:token] ).service.alive? break rescue Exception end end end rescue Timeout::Error abort "Instance '#{url}' never started!" end @list[url] = [:token] connect( url ) end |