Class: Arachni::RPC::Server::Instance

Inherits:
Object
  • Object
show all
Includes:
Module::Utilities, UI::Output
Defined in:
lib/arachni/rpc/server/instance.rb

Overview

RPC Server class

Provides an RPC server to assist with general integration and UI development.

Only instantiated by the Dispatcher to provide support for multiple and concurent RPC clients/scans.

@author: Tasos “Zapotek” Laskos

<[email protected]>
<[email protected]>

@version: 0.1.5

Instance Method Summary collapse

Methods included from Module::Utilities

#exception_jail, #get_path, #hash_keys_to_str, #normalize_url, #read_file, #seed, #uri_decode, #uri_encode, #uri_parse, #uri_parser, #url_sanitize

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

#initialize(opts, token) ⇒ Instance

Initializes the RPC interface, the HTTP(S) server and the framework.

Parameters:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/arachni/rpc/server/instance.rb', line 49

def initialize( opts, token )

    prep_framework
    banner

    @opts  = opts
    @token = token
    @server = Base.new( @opts, token )

    @opts.datastore[:token] = token

    debug! if @opts.debug


    if logfile = @opts.reroute_to_logfile
        reroute_to_file( @opts.dir['logs'] +
            "Instance - #{Process.pid}-#{@opts.rpc_port}.log" )
    else
        reroute_to_file( false )
    end

    set_handlers

    # trap interrupts and exit cleanly when required
    [ 'QUIT', 'INT' ].each {
        |signal|
        trap( signal ){ shutdown } if Signal.list.has_key?( signal )
    }

    run
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/arachni/rpc/server/instance.rb', line 116

def alive?
    @server.alive?
end

#output(&block) ⇒ Array<Hash>

Flushes the output buffer and returns all pending system messages.

All messages are classified based on their type.

Returns:



88
89
90
# File 'lib/arachni/rpc/server/instance.rb', line 88

def output( &block )
    @framework.output( &block )
end

#shutdownObject Also known as: shutdown!

Makes the server go bye-bye…Lights out!



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/arachni/rpc/server/instance.rb', line 95

def shutdown
    print_status( 'Shutting down...' )

    t = []
    @framework.instances.each {
        |instance|
        # Don't know why but this works better than EM's stuff
        t << Thread.new {
            @framework.instance_eval{
                connect_to_instance( instance ).service.shutdown!
            }
        }
    }

    t.join

    @server.shutdown
    return true
end