Class: Arachni::UI::Web::DispatcherManager
- Defined in:
- lib/arachni/ui/web/dispatcher_manager.rb
Overview
Provides methods for dispatcher management.
Defined Under Namespace
Classes: Dispatcher
Instance Method Summary collapse
-
#alive?(url, &block) ⇒ Boolean
Checks wether the dispatcher is alive.
-
#all(*args) ⇒ Array
Returns all dispatchers stored in the DB.
- #all_with_liveness(&block) ⇒ Object
-
#connect(url) ⇒ Arachni::RPC::Client::Dispatcher
Provides an easy way to connect to a dispatcher.
-
#delete(id) ⇒ Object
Removed a dispatcher from the DB.
-
#delete_all ⇒ Object
Removed all dispatchers from the DB.
- #first_alive(&block) ⇒ Object
-
#initialize(opts, settings) ⇒ DispatcherManager
constructor
A new instance of DispatcherManager.
- #jobs(&block) ⇒ Object
-
#new(url, neighbours = true) ⇒ Object
Puts a new dispatcher (and it’s neighbours) in the DB.
-
#stats(&block) ⇒ Hash
Provides statistics about running jobs etc using the dispatcher.
Constructor Details
#initialize(opts, settings) ⇒ DispatcherManager
Returns a new instance of DispatcherManager.
43 44 45 46 47 48 49 50 51 |
# File 'lib/arachni/ui/web/dispatcher_manager.rb', line 43 def initialize( opts, settings ) @opts = opts @settings = settings DataMapper::setup( :default, "sqlite3://#{@settings.db}/default.db" ) DataMapper.finalize Dispatcher.auto_upgrade! end |
Instance Method Details
#alive?(url, &block) ⇒ Boolean
Checks wether the dispatcher is alive.
88 89 90 91 92 93 94 95 |
# File 'lib/arachni/ui/web/dispatcher_manager.rb', line 88 def alive?( url, &block ) raise( "This method requires a block!" ) if !block_given? connect( url ).alive? { |ret| block.call( ret.rpc_connection_error? ? false : true ) } end |
#all(*args) ⇒ Array
Returns all dispatchers stored in the DB.
229 230 231 |
# File 'lib/arachni/ui/web/dispatcher_manager.rb', line 229 def all( *args ) Dispatcher.all( *args ) end |
#all_with_liveness(&block) ⇒ Object
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/arachni/ui/web/dispatcher_manager.rb', line 233 def all_with_liveness( &block ) raise( "This method requires a block!" ) if !block_given? EM::Iterator.new( all ).map( proc{ |dispatcher, iter| alive?( dispatcher.url ) { |liveness| m_dispatcher = {} dispatcher.attributes.each_pair { |k, v| m_dispatcher[k.to_s] = v } m_dispatcher['alive'] = liveness iter.return( m_dispatcher ) } }, proc{ |dispatchers| block.call( dispatchers ) }) end |
#connect(url) ⇒ Arachni::RPC::Client::Dispatcher
Provides an easy way to connect to a dispatcher.
79 80 81 |
# File 'lib/arachni/ui/web/dispatcher_manager.rb', line 79 def connect( url ) Arachni::RPC::Client::Dispatcher.new( @opts, url ) end |
#delete(id) ⇒ Object
Removed a dispatcher from the DB.
272 273 274 |
# File 'lib/arachni/ui/web/dispatcher_manager.rb', line 272 def delete( id ) Dispatcher.get( id ).destroy end |
#delete_all ⇒ Object
Removed all dispatchers from the DB.
259 260 261 262 263 264 265 |
# File 'lib/arachni/ui/web/dispatcher_manager.rb', line 259 def delete_all all.each { |report| delete( report.id ) } all.destroy end |
#first_alive(&block) ⇒ Object
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 |
# File 'lib/arachni/ui/web/dispatcher_manager.rb', line 97 def first_alive( &block ) raise( "This method requires a block!" ) if !block_given? if !all.empty? EM.synchrony do dispatchers = EM::Synchrony::Iterator.new( all ).map { |dispatcher, iter| alive?( dispatcher.url ){ |bool| if bool iter.return( dispatcher ) else iter.return( nil ) end } }.compact if dispatchers.empty? block.call( false ) else block.call( dispatchers.pop ) end end else block.call( false ) end end |
#jobs(&block) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/arachni/ui/web/dispatcher_manager.rb', line 125 def jobs( &block ) ::EM::Iterator.new( all, 20 ).map( proc { |dispatcher, iter| connect( dispatcher.url ).stats { |stats| iter.return( stats['running_jobs'] ) if !stats.rpc_connection_error? } }, proc { |running| block.call( running.flatten ) }) end |
#new(url, neighbours = true) ⇒ Object
Puts a new dispatcher (and it’s neighbours) in the DB.
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/arachni/ui/web/dispatcher_manager.rb', line 59 def new( url, neighbours = true ) Dispatcher.first_or_create( :url => url ) return if !neighbours connect( url ).node.neighbours { |neighbours| neighbours.each { |node| Dispatcher.first_or_create( :url => node ) } } end |
#stats(&block) ⇒ Hash
Provides statistics about running jobs etc using the dispatcher
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/arachni/ui/web/dispatcher_manager.rb', line 145 def stats( &block ) raise( "This method requires a block!" ) if !block_given? EM.synchrony do stats = EM::Synchrony::Iterator.new( all ).map { |dispatcher, iter| if !dispatcher.rpc_connection_error? connect( dispatcher.url ).stats { |stats| if !stats.rpc_exception? # automatically grab and save neighbours stats['neighbours'].each { |n| new( n ) } iter.return( { dispatcher.url => stats } ) else iter.return( nil ) end } end }.compact sorted_stats = {} stats.sort{ |a, b| a.keys[0] <=> b.keys[0] }.each { |stat| sorted_stats.merge!( stat ) } sorted_stats.each_pair { |k, stats| sorted_stats[k]['running_jobs'] = EM::Synchrony::Iterator.new( stats['running_jobs'] ).map { |instance, iter| if instance['helpers']['rank'] != 'slave' @settings.instances.connect( instance['url'] ).framework.progress_data( :slaves => false, :messages => false, :issues => false ) { |prog_data| if prog_data.rpc_exception? iter.return( nil ) else instance.merge!( prog_data['stats'] ) instance['status'] = prog_data['status'].capitalize! iter.return( instance ) end } else @settings.instances.connect( instance['helpers']['master'] ).framework.progress_data( :messages => false, :issues => false ) { |prog_data| if prog_data.rpc_exception? iter.return( nil ) else prog_data['instances'].each { |insdat| if insdat['url'] == instance['url'] instance.merge!( insdat ) instance['status'].capitalize! iter.return( instance ) end } end } end }.compact } block.call( sorted_stats ) end end |