Module: Arachni::UI::Output

Overview

RPC deamon 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: Tasos “Zapotek” Laskos

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

@version: 0.1.1

Constant Summary collapse

@@verbose =

verbosity flag

if it’s on verbose messages will be enabled

false
@@debug =

debug flag

if it’s on debugging messages will be enabled

false
@@only_positives =

only_positives flag

if it’s on status messages will be disabled

false
@@mute =
false
@@opened =
false
@@reroute_to_file =
false
@@buffer_cap =
30

Instance Method Summary collapse

Instance Method Details

#buffer(msg) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/arachni/rpc/server/output.rb', line 62

def buffer( msg )
    if file = @@reroute_to_file
        File.open( file, 'a+' ) {
            |f|

            type = msg.keys[0]
            str  = msg.values[0]
            next if str.empty?

            f.write( "[#{Time.now.asctime}] [#{type}]  #{str}\n" )
        }
    else
        @@buffer << msg
        if @@buffer_cap.is_a? Integer
            @@buffer.slice!( (@@buffer.size - @@buffer_cap)..@@buffer.size  )
        end
    end
end

#debug!void

This method returns an undefined value.

Sets the @@debug flag to true

See Also:



243
244
245
# File 'lib/arachni/ui/cli/output.rb', line 243

def debug!
    @@debug = true
end

#debug?Bool

Returns the @@debug flag

Returns:

  • (Bool)

    @@debug

See Also:



253
254
255
# File 'lib/arachni/ui/cli/output.rb', line 253

def debug?
    @@debug
end

#flush_bufferArray<Hash>

Empties the output buffer and returns all messages.

Messages are classified by their type.

Returns:



56
57
58
59
60
# File 'lib/arachni/rpc/server/output.rb', line 56

def flush_buffer
    buf = @@buffer.dup
    @@buffer.clear
    return buf
end

#mute!Object



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

def mute!
    @@mute = true
end

#muted?Boolean

Returns:

  • (Boolean)


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

def muted?
    @@mute
end

#only_positives!void

This method returns an undefined value.

Sets the @@only_positives flag to true

See Also:



263
264
265
# File 'lib/arachni/ui/cli/output.rb', line 263

def only_positives!
    @@only_positives = true
end

#only_positives?Bool

Returns the @@only_positives flag

Returns:

  • (Bool)

    @@only_positives

See Also:



273
274
275
# File 'lib/arachni/ui/cli/output.rb', line 273

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:



88
89
90
91
# File 'lib/arachni/ui/cli/output.rb', line 88

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

This method returns an undefined value.

Prints a debugging message

Obeys @@debug

Parameters:

  • debugging (String)

    string

See Also:



145
146
147
148
# File 'lib/arachni/ui/cli/output.rb', line 145

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

This method returns an undefined value.

Prints the backtrace of an exception

Obeys @@debug

Parameters:

  • (Exception)

See Also:



176
177
178
179
# File 'lib/arachni/ui/cli/output.rb', line 176

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

This method returns an undefined value.

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

Obeys @@debug

Parameters:

See Also:



161
162
163
164
# File 'lib/arachni/ui/cli/output.rb', line 161

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

This method returns an undefined value.

Prints an error message

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

Parameters:



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/ui/cli/output.rb', line 55

def print_error( str = '' )
    print_color( '[-]', 31, str, $stderr, true )
    File.open( 'error.log', 'a' ){
        |f|
        if !@@opened
            f.puts
            f.puts "#{Time.now} " + ( "-" * 80 )

            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

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

    @@opened = true
end


181
182
183
# File 'lib/arachni/ui/cli/output.rb', line 181

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

This method returns an undefined value.

Prints an info message

Obeys @@only_positives

Parameters:

See Also:



118
119
120
121
# File 'lib/arachni/ui/cli/output.rb', line 118

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

This method returns an undefined value.

Prints a line of message

Obeys @@only_positives

Parameters:

See Also:



211
212
213
214
215
# File 'lib/arachni/ui/cli/output.rb', line 211

def print_line( str = '', unmute = false )
    if @@only_positives then return end
    return if muted? && !unmute
    puts str
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:



131
132
133
# File 'lib/arachni/ui/cli/output.rb', line 131

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

This method returns an undefined value.

Prints a status message

Obeys @@only_positives

Parameters:

See Also:



103
104
105
106
# File 'lib/arachni/ui/cli/output.rb', line 103

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

This method returns an undefined value.

Prints a verbose message

Obeys @@verbose

Parameters:

See Also:



196
197
198
199
# File 'lib/arachni/ui/cli/output.rb', line 196

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

#reroute_to_file(file) ⇒ Object



296
297
298
# File 'lib/arachni/rpc/server/output.rb', line 296

def reroute_to_file( file )
    @@reroute_to_file = file
end

#reroute_to_file?Boolean

Returns:

  • (Boolean)


300
301
302
# File 'lib/arachni/rpc/server/output.rb', line 300

def reroute_to_file?
    @@reroute_to_file
end

#uncap_buffer!Object



81
82
83
# File 'lib/arachni/rpc/server/output.rb', line 81

def uncap_buffer!
    @@buffer_cap = nil
end

#unmute!Object



281
282
283
# File 'lib/arachni/ui/cli/output.rb', line 281

def unmute!
    @@mute = false
end

#verbose!void

This method returns an undefined value.

Sets the @@verbose flag to true

See Also:



223
224
225
# File 'lib/arachni/ui/cli/output.rb', line 223

def verbose!
    @@verbose = true
end

#verbose?Bool

Returns the @@verbose flag

Returns:

  • (Bool)

    @@verbose

See Also:



233
234
235
# File 'lib/arachni/ui/cli/output.rb', line 233

def verbose?
    @@verbose
end