Module: Arachni::UI::Output

Overview

RPC Output module

It basically classifies and buffers all system messages until it’s time to flush the buffer and send them over the wire.

Author:

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.old_reset_output_optionsObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/arachni/rpc/server/output.rb', line 35

def self.reset_output_options
    # verbosity flag
    #
    # if it's on verbose messages will be enabled
    @@verbose = false

    # debug flag
    #
    # if it's on debugging messages will be enabled
    @@debug   = false

    @@mute = false

    # only_positives flag
    #
    # if it's on status messages will be disabled
    @@only_positives  = false

    @@reroute_to_file = false

    @@opened = false

    @@error_logfile = 'error.log'
end

.reset_output_optionsObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/arachni/ui/cli/output.rb', line 31

def self.reset_output_options
    # verbosity flag
    #
    # if it's on verbose messages will be enabled
    @@verbose = false

    # debug flag
    #
    # if it's on debugging messages will be enabled
    @@debug   = false

    @@mute = false

    # only_positives flag
    #
    # if it's on status messages will be disabled
    @@only_positives  = false

    @@reroute_to_file = false

    @@opened = false

    @@error_logfile = 'error.log'
end

Instance Method Details

#debug?Bool

Returns the @@debug flag

Returns:

  • (Bool)

    @@debug

See Also:



286
287
288
# File 'lib/arachni/ui/cli/output.rb', line 286

def debug?
    @@debug
end

#debug_offObject



276
277
278
# File 'lib/arachni/ui/cli/output.rb', line 276

def debug_off
    @@debug = false
end

#debug_onvoid Also known as: debug

This method returns an undefined value.

Sets the @@debug flag to true

See Also:



271
272
273
# File 'lib/arachni/ui/cli/output.rb', line 271

def debug_on
    @@debug = true
end

#disable_only_positivesObject



300
301
302
# File 'lib/arachni/ui/cli/output.rb', line 300

def disable_only_positives
    @@only_positives = false
end

#error_logfileObject



62
63
64
# File 'lib/arachni/ui/cli/output.rb', line 62

def error_logfile
    @@error_logfile
end

#flush_bufferArray<Hash>

Empties the output buffer and returns all messages.

Messages are classified by their type.

Returns:



53
54
55
56
57
# File 'lib/arachni/rpc/server/output.rb', line 53

def flush_buffer
    buf = @@output_buffer.dup
    @@output_buffer.clear
    buf
end

#log_error(str = '') ⇒ Object



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
# File 'lib/arachni/ui/cli/output.rb', line 78

def log_error( str = '' )
    File.open( @@error_logfile, 'a' ) do |f|
        if !@@opened
            f.puts
            f.puts "#{Time.now} " + ( "-" * 80 )

            begin
                h = {}
                ENV.each { |k, v| h[k] = v }
                f.puts 'ENV:'
                f.puts h.to_yaml

                f.puts "-" * 80

                f.puts 'OPTIONS:'
                f.puts Arachni::Options.instance.to_yaml
            rescue
            end

            f.puts "-" * 80
        end
        print_color( "[#{Time.now}]", 31, str, f, true )
    end

    @@opened = true
end

#muteObject



314
315
316
# File 'lib/arachni/ui/cli/output.rb', line 314

def mute
    @@mute = true
end

#muted?Boolean

Returns:

  • (Boolean)


322
323
324
# File 'lib/arachni/ui/cli/output.rb', line 322

def muted?
    @@mute
end

#only_positivesvoid

This method returns an undefined value.

Sets the @@only_positives flag to true

See Also:



296
297
298
# File 'lib/arachni/ui/cli/output.rb', line 296

def only_positives
    @@only_positives = true
end

#only_positives?Bool

Returns the @@only_positives flag

Returns:

  • (Bool)

    @@only_positives

See Also:

  • #only_positives!


310
311
312
# File 'lib/arachni/ui/cli/output.rb', line 310

def only_positives?
    @@only_positives
end

Same as print_error but the message won’t be printed to stderr.

Used mainly to draw attention to something that didn’t behave as expected rather than display an actual error.

Parameters:

  • str (String) (defaults to: '')


113
114
115
116
# File 'lib/arachni/ui/cli/output.rb', line 113

def print_bad( str = '', unmute = false )
    return if muted? && !unmute
    print_color( '[-]', 31, str, $stdout, unmute )
end

Prints a debugging message

Obeys @@debug

Parameters:

  • str (String) (defaults to: '')

See Also:



170
171
172
173
# File 'lib/arachni/ui/cli/output.rb', line 170

def print_debug( str = '', unmute = false )
    return if !debug?
    print_color( '[!]', 36, str, $stderr, unmute )
end

Prints the backtrace of an exception

Obeys @@debug

Parameters:

  • e (Exception)

See Also:



199
200
201
202
# File 'lib/arachni/ui/cli/output.rb', line 199

def print_debug_backtrace( e )
    return if !debug?
    e.backtrace.each{ |line| print_debug( line ) }
end

Pretty prints an object, used for debugging, needs some improvement but it’ll do for now

Obeys @@debug

Parameters:

See Also:



185
186
187
188
# File 'lib/arachni/ui/cli/output.rb', line 185

def print_debug_pp( obj = nil )
    return if !debug?
    pp obj
end

Prints an error message

It ignores all flags, error messages will be output under all circumstances.

Parameters:

  • str (String) (defaults to: '')

    error string



73
74
75
76
# File 'lib/arachni/ui/cli/output.rb', line 73

def print_error( str = '' )
    print_color( '[-]', 31, str, $stderr, true )
    log_error( str )
end


204
205
206
# File 'lib/arachni/ui/cli/output.rb', line 204

def print_error_backtrace( e )
    e.backtrace.each{ |line| print_error( line ) }
end

Prints an info message

Obeys @@only_positives

Parameters:

  • str (String) (defaults to: '')

See Also:



143
144
145
146
# File 'lib/arachni/ui/cli/output.rb', line 143

def print_info( str = '', unmute = false )
    return if only_positives?
    print_color( '[~]', 30, str, $stdout, unmute )
end

Prints a line of message

Obeys @@only_positives

Parameters:

  • str (String) (defaults to: '')

See Also:



234
235
236
237
238
239
240
241
242
243
# File 'lib/arachni/ui/cli/output.rb', line 234

def print_line( str = '', unmute = false )
    return if only_positives?
    return if muted? && !unmute

    # we may get IO errors...freaky stuff...
    begin
        puts str
    rescue
    end
end

This method returns an undefined value.

Prints a good message, something that went very very right, like the discovery of a vulnerability

Disregards all flags.

Parameters:

  • str (String) (defaults to: '')


156
157
158
# File 'lib/arachni/ui/cli/output.rb', line 156

def print_ok( str = '', unmute = false )
    print_color( '[+]', 32, str, $stdout, unmute )
end

Prints a status message

Obeys @@only_positives

Parameters:

  • str (String) (defaults to: '')

See Also:



128
129
130
131
# File 'lib/arachni/ui/cli/output.rb', line 128

def print_status( str = '', unmute = false )
    return if only_positives?
    print_color( '[*]', 34, str, $stdout, unmute )
end

Prints a verbose message

Obeys @@verbose

Parameters:

  • str (String) (defaults to: '')

See Also:



219
220
221
222
# File 'lib/arachni/ui/cli/output.rb', line 219

def print_verbose( str = '', unmute = false )
    return if !verbose?
    print_color( '[v]', 37, str, $stdout, unmute )
end

#reroute_to_file(file) ⇒ Object



181
182
183
# File 'lib/arachni/rpc/server/output.rb', line 181

def reroute_to_file( file )
    @@reroute_to_file = file
end

#reroute_to_file?Boolean

Returns:

  • (Boolean)


185
186
187
# File 'lib/arachni/rpc/server/output.rb', line 185

def reroute_to_file?
    @@reroute_to_file
end

#set_buffer_cap(cap) ⇒ Object



59
60
61
# File 'lib/arachni/rpc/server/output.rb', line 59

def set_buffer_cap( cap )
    @@output_buffer_cap = cap
end

#set_error_logfile(logfile) ⇒ Object



58
59
60
# File 'lib/arachni/ui/cli/output.rb', line 58

def set_error_logfile( logfile )
    @@error_logfile = logfile
end

#uncap_bufferObject



63
64
65
# File 'lib/arachni/rpc/server/output.rb', line 63

def uncap_buffer
    @@output_buffer_cap = nil
end

#unmuteObject



318
319
320
# File 'lib/arachni/ui/cli/output.rb', line 318

def unmute
    @@mute = false
end

#verbosevoid

This method returns an undefined value.

Sets the @@verbose flag to true

See Also:



251
252
253
# File 'lib/arachni/ui/cli/output.rb', line 251

def verbose
    @@verbose = true
end

#verbose?Bool

Returns the @@verbose flag

Returns:

  • (Bool)

    @@verbose

See Also:



261
262
263
# File 'lib/arachni/ui/cli/output.rb', line 261

def verbose?
    @@verbose
end