Class: Arachni::UI::Web::Scheduler

Inherits:
Object
  • Object
show all
Includes:
Utilities
Defined in:
lib/arachni/ui/web/scheduler.rb

Overview

Schedules and executes scan jobs.

Author:

Version:

  • 0.1.2

Defined Under Namespace

Classes: Job

Instance Method Summary collapse

Methods included from Utilities

#escape, #escape_hash, #parse_datetime, #remove_proto, #unescape, #unescape_hash

Constructor Details

#initialize(opts, settings) ⇒ Scheduler

Initializes the Scheduler and starts the clock.



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/arachni/ui/web/scheduler.rb', line 56

def initialize( opts, settings )
    @opts     = opts
    @settings = settings

    DataMapper::setup( :default, "sqlite3://#{@settings.db}/default.db" )
    DataMapper.finalize

    Job.auto_upgrade!

    ticktock!
end

Instance Method Details

#delete(id) ⇒ Object

Removed a job.

Parameters:

  • id (Integer)


147
148
149
# File 'lib/arachni/ui/web/scheduler.rb', line 147

def delete( id )
    Job.get( id ).destroy
end

#delete_allObject

Removes all jobs.



138
139
140
# File 'lib/arachni/ui/web/scheduler.rb', line 138

def delete_all
    jobs.destroy
end

#jobs(*args) ⇒ Array

Returns all scheduled jobs.

Returns:



131
132
133
# File 'lib/arachni/ui/web/scheduler.rb', line 131

def jobs( *args )
    Job.all( *args )
end

#run(job, env = nil, session = nil, &block) ⇒ String

Runs a job.

Parameters:

  • job (Job)
  • env (Hash) (defaults to: nil)

    Sinatra environment

  • session (Hash) (defaults to: nil)

    Rack session

Returns:

  • (String)

    URL of the laucnhed scanner instance



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
108
109
110
111
# File 'lib/arachni/ui/web/scheduler.rb', line 77

def run( job, env = nil, session = nil, &block )
    raise( "This method requires a block!" ) if !block_given?

    @settings.dispatchers.connect( job.dispatcher ).dispatch( job.url ){
        |instance|

        if instance.rpc_exception?
            @settings.log.scheduler_instance_dispatch_failed( env )
            next
        end

        env = {
            'REMOTE_ADDR' => job.owner_addr,
            'REMOTE_HOST' => job.owner_host
        } if env.nil?

        @settings.log.scheduler_instance_dispatched( env, instance['url'] )
        @settings.log.scheduler_instance_owner_assigned( env, job.url )

        arachni = @settings.instances.connect( instance['url'], session, instance['token'] )

        opts = YAML::load( job.opts )

        arachni.opts.set( opts['settings'] ){
            arachni.plugins.load( opts['plugins'] ) {
                arachni.modules.load( opts['modules'] ) {
                    arachni.framework.run{
                        @settings.log.scheduler_scan_started( env, job.url )
                        block.call( instance['url'] )
                    }
                }
            }
        }
    }
end

#run_and_destroy(job, &block) ⇒ Object

Runs a job and removed it from the DB.

Parameters:



118
119
120
121
122
123
124
# File 'lib/arachni/ui/web/scheduler.rb', line 118

def run_and_destroy( job, &block )
    run( job ){
        |url|
        job.destroy
        block.call( url ) if block_given?
    }
end