Module: Arachni::UI::Output

Overview

CLI Output module.

Provides a command line output interface to the framework. All UIs should provide an Arachni::UI::Output module with these methods.

Author:

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.reset_output_optionsObject


32
33
# File 'lib/arachni/ui/foo/output.rb', line 32

def self.reset_output_options
end

Instance Method Details

#caller_locationObject


217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'ui/cli/output.rb', line 217

def caller_location
    file = nil
    line = nil
    caller_method = nil
    Kernel.caller.each do |c|
        file, line, method = *c.scan( /(.*):(\d+):in `(?:.*\s)?(.*)'/ ).flatten
        next if file == __FILE__

        caller_method = method
        break
    end

    context = nil
    if caller_method
        file.gsub!( Options.paths.lib, '' )
        file.gsub!( Options.paths.root, '' )

        dir = File.dirname( file )
        dir = '' if dir == '.'
        dir << File::SEPARATOR if !dir.empty?

        file = "#{dir}#{File.basename( file, '.rb' )}"

        context = "[#{file}##{caller_method}:#{line}]"
    end

    context
end

#debug?(level = 1) ⇒ Bool

Parameters:

  • level (Integer) (defaults to: 1)

    Checks against this level.

Returns:

  • (Bool)

See Also:


357
358
# File 'ui/cli/output.rb', line 357

def debug?(*)
end

#debug_levelInteger

Returns Debugging level.

Returns:

  • (Integer)

    Debugging level.


347
348
349
# File 'ui/cli/output.rb', line 347

def debug_level
    @@debug
end

#debug_level_1?Boolean

Returns:

  • (Boolean)

75
76
77
# File 'lib/arachni/ui/foo/output.rb', line 75

def debug_level_1?
    debug? 1
end

#debug_level_2?Boolean

Returns:

  • (Boolean)

78
79
80
# File 'lib/arachni/ui/foo/output.rb', line 78

def debug_level_2?
    debug? 2
end

#debug_level_3?Boolean

Returns:

  • (Boolean)

81
82
83
# File 'lib/arachni/ui/foo/output.rb', line 81

def debug_level_3?
    debug? 3
end

#debug_level_4?Boolean

Returns:

  • (Boolean)

84
85
86
# File 'lib/arachni/ui/foo/output.rb', line 84

def debug_level_4?
    debug? 4
end

#debug_offObject

Disables #print_debug messages.

See Also:


341
342
# File 'ui/cli/output.rb', line 341

def debug_off
end

#debug_on(level = 1) ⇒ Object Also known as: debug

Enables #print_debug messages.

Parameters:

  • level (Integer) (defaults to: 1)

    Sets the debugging level.

See Also:


333
334
# File 'ui/cli/output.rb', line 333

def debug_on(*)
end

#disable_only_positivesObject

Undoes #only_positives.


380
381
# File 'ui/cli/output.rb', line 380

def disable_only_positives
end

#error_bufferObject


159
160
161
# File 'ui/cli/output.rb', line 159

def error_buffer
    @@error_buffer
end

#error_log_fdObject


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'ui/cli/output.rb', line 74

def error_log_fd
    return @@error_fd if @@error_fd

    @@error_fd = File.open( error_logfile, 'a' )
    @@error_fd.sync = true

    Kernel.at_exit do
        begin
            @@error_fd.close if @@error_fd
        rescue IOError
        end
    end

    @@error_fd

# Errno::EMFILE (too many open files) or something, nothing we can do
# about it except catch it to avoid a crash.
rescue SystemCallError => e
    print_bad "[#{e.class}] #{e}"
    e.backtrace.each { |line| print_bad line }
    nil
end

#error_logfileString

Returns Location of the error log file.

Returns:

  • (String)

    Location of the error log file.


66
67
68
# File 'ui/cli/output.rb', line 66

def error_logfile
    @@error_logfile
end

#has_error_log?Boolean

Returns:

  • (Boolean)

70
71
72
# File 'ui/cli/output.rb', line 70

def has_error_log?
    File.exist? error_logfile
end

#included(base) ⇒ Object


18
19
20
# File 'lib/arachni/ui/foo/output.rb', line 18

def included( base )
    base.extend ClassMethods
end

#log_error(str = '') ⇒ Object

Logs an error message to the error log file.

Parameters:

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

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'ui/cli/output.rb', line 120

def log_error( str = '' )
    return if !error_log_fd

    if !@@error_log_written_env
        @@error_log_written_env = true

        ['', "#{Time.now} " + ( '-' * 80 )].each do |s|
            error_log_fd.puts s
            @@error_buffer << s
        end

        begin
            h = {}
            ENV.each { |k, v| h[k] = v }

            options = Arachni::Options.to_rpc_data
            if options['http']['authentication_username']
                options['http']['authentication_username'] = '*****'
                options['http']['authentication_password'] =
                    options['http']['authentication_username']
            end
            options = options.to_yaml

            ['ENV:', h.to_yaml, '-' * 80, 'OPTIONS:', options].each do |s|
                error_log_fd.puts s
                @@error_buffer += s.split("\n")
            end
        rescue
        end

        error_log_fd.puts '-' * 80
        @@error_buffer << '-' * 80
    end

    t = "[#{Time.now}]"
    @@error_buffer << "#{t} #{str}"
    print_color( t, 31, str, error_log_fd, true )
end

#muteObject

Mutes all output messages, unless they explicitly override the mute status.


390
391
# File 'ui/cli/output.rb', line 390

def mute
end

#muted?Bool

Returns:

  • (Bool)

400
401
# File 'ui/cli/output.rb', line 400

def muted?
end

#only_positivesObject

Mutes everything but #print_ok messages.


375
376
# File 'ui/cli/output.rb', line 375

def only_positives
end

#only_positives?Bool

Returns:

  • (Bool)

385
386
# File 'ui/cli/output.rb', line 385

def only_positives?
end

Used to draw attention to a bad situation which isn't an error.

Parameters:

  • str (String) (defaults to: '')
  • unmute (Bool) (defaults to: false)

167
168
# File 'ui/cli/output.rb', line 167

def print_bad(*)
end

Prints a debugging message.

Parameters:

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

See Also:


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

def print_debug(*)
end

Prints the backtrace of an exception as debugging messages.

Parameters:

  • e (Exception)

See Also:


275
276
# File 'ui/cli/output.rb', line 275

def print_debug_backtrace(*)
end

262
263
264
265
266
267
# File 'ui/cli/output.rb', line 262

def print_debug_exception( e, level = 1 )
    return if !debug?

    print_debug( "[#{e.class}] #{e}", level )
    print_debug_backtrace( e, level )
end

57
58
# File 'lib/arachni/ui/foo/output.rb', line 57

def print_debug_level_1(*)
end

60
61
# File 'lib/arachni/ui/foo/output.rb', line 60

def print_debug_level_2(*)
end

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

def print_debug_level_3(*)
end

66
67
# File 'lib/arachni/ui/foo/output.rb', line 66

def print_debug_level_4(*)
end

Prints and logs an error message.

Parameters:

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

100
101
# File 'ui/cli/output.rb', line 100

def print_error(*)
end

Prints the backtrace of an exception as error messages.

Parameters:

  • e (Exception)

108
109
# File 'ui/cli/output.rb', line 108

def print_error_backtrace(*)
end

39
40
# File 'lib/arachni/ui/foo/output.rb', line 39

def print_exception(*)
end

Prints an info message.

Parameters:

  • str (String) (defaults to: '')
  • unmute (Bool) (defaults to: false)

185
186
# File 'ui/cli/output.rb', line 185

def print_info(*)
end

Prints an unclassified message.

Parameters:

  • str (String) (defaults to: '')
  • unmute (Bool) (defaults to: false)

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

def print_line(*)
end

Prints a good message, something that went very very right, like the discovery of an issue.

Parameters:

  • str (String) (defaults to: '')
  • unmute (Bool) (defaults to: false)

195
196
# File 'ui/cli/output.rb', line 195

def print_ok(*)
end

Prints a status message.

Parameters:

  • str (String) (defaults to: '')
  • unmute (Bool) (defaults to: false)

    override mute


176
177
# File 'ui/cli/output.rb', line 176

def print_status(*)
end

Prints a verbose message.

Parameters:

  • str (String) (defaults to: '')
  • unmute (Bool) (defaults to: false)

See Also:


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

def print_verbose(*)
end

#reroute_to_file(file) ⇒ Object


73
74
75
# File 'lib/arachni/rpc/server/output.rb', line 73

def reroute_to_file( file )
    @@reroute_to_file = file
end

#reroute_to_file?Boolean

Returns:

  • (Boolean)

77
78
79
# File 'lib/arachni/rpc/server/output.rb', line 77

def reroute_to_file?
    @@reroute_to_file
end

#set_error_logfile(logfile) ⇒ Object

Parameters:

  • logfile (String)

    Location of the error log file.


60
61
62
# File 'ui/cli/output.rb', line 60

def set_error_logfile( logfile )
    @@error_logfile = logfile
end

#unmuteObject

Unmutes output messages.


395
396
# File 'ui/cli/output.rb', line 395

def unmute
end

#verbose?Bool

Returns:

  • (Bool)

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

def verbose?
end

#verbose_offObject

Disables #print_verbose messages.

See Also:


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

def verbose_off
    @@verbose = false
end

#verbose_onObject Also known as: verbose

Enables #print_verbose messages.

See Also:


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

def verbose_on
end