lib/arachni/rpc/server/output.rb in arachni-0.4.7 vs lib/arachni/rpc/server/output.rb in arachni-1.0
- old
+ new
@@ -1,180 +1,72 @@
=begin
- Copyright 2010-2014 Tasos Laskos <tasos.laskos@gmail.com>
+ Copyright 2010-2014 Tasos Laskos <tasos.laskos@arachni-scanner.com>
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
+ This file is part of the Arachni Framework project and is subject to
+ redistribution and commercial restrictions. Please see the Arachni Framework
+ web site for more information on licensing and terms of use.
=end
-# get some basics from the CLI UI's output interface
-require Arachni::Options.dir['lib'] + 'ui/cli/output'
-
module Arachni
+require "#{Options.paths.root}ui/cli/output"
+
module UI
+# RPC Output interface.
#
-# RPC Output module
+# Basically provides us with {#print_error error logging} and the ability to
+# reroute all other messages to a logfile.
#
-# 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 <tasos.laskos@gmail.com>
-#
+# @author Tasos "Zapotek" Laskos <tasos.laskos@arachni-scanner.com>
module Output
- class << self
- alias :old_reset_output_options :reset_output_options
- end
-
- def self.reset_output_options
- old_reset_output_options
- @@output_buffer_cap = 30
- @@output_buffer ||= []
- end
-
- reset_output_options
-
- #
- # Empties the output buffer and returns all messages.
- #
- # Messages are classified by their type.
- #
- # @return [Array<Hash>]
- #
- def flush_buffer
- buf = @@output_buffer.dup
- @@output_buffer.clear
- buf
- end
-
- def set_buffer_cap( cap )
- @@output_buffer_cap = cap
- end
-
- def uncap_buffer
- @@output_buffer_cap = nil
- end
-
- # Prints an error message
- #
- # It ignores all flags, error messages will be output under all
- # circumstances.
- #
- # @param [String] str error string
- #
def print_error( str = '' )
log_error( str )
- push_to_output_buffer( :error => str )
+ push_to_output_buffer( error: str )
end
- def print_error_backtrace( e )
- e.backtrace.each { |line| print_error( line ) }
- 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.
- #
- # @param [String] str
- #
def print_bad( str = '' )
push_to_output_buffer( bad: str )
end
- # Prints a status message
- #
- # Obeys {@@only_positives}
- #
- # @see #only_positives?
- # @see #only_positives
- #
- # @param [String] str
- #
def print_status( str = '' )
return if only_positives?
push_to_output_buffer( status: str )
end
- # Prints an info message
- #
- # Obeys {@@only_positives}
- #
- # @see #only_positives?
- # @see #only_positives
- #
- # @param [String] str
- #
def print_info( str = '' )
return if only_positives?
push_to_output_buffer( info: str )
end
- # Prints a good message, something that went very very right,
- # like the discovery of a vulnerability
- #
- # Disregards all flags.
- #
- # @param [String] str
- # @return [void]
- #
def print_ok( str = '' )
push_to_output_buffer( ok: str )
end
- # Prints a debugging message
- #
- # Obeys {@@debug}
- #
- # @see #debug?
- # @see #debug
- #
- # @param [String] str
- #
- def print_debug( str = '' )
- return if !debug?
+ def print_debug( str = '', level = 1 )
+ return if !debug?( level )
+ push_to_output_buffer( debug: str )
+ end
- if reroute_to_file?
- push_to_output_buffer( debug: str )
- else
- print_color( '[!]', 36, str, $stderr )
- end
+ def print_debug_level_1( str = '' )
+ print_debug( str, 1 )
end
- # Prints a verbose message
- #
- # Obeys {@@verbose}
- #
- # @see #verbose?
- # @see #verbose
- #
- # @param [String] str
- #
+ def print_debug_level_2( str = '' )
+ print_debug( str, 2 )
+ end
+
+ def print_debug_level_3( str = '' )
+ print_debug( str, 3 )
+ end
+
def print_verbose( str = '' )
return if !verbose?
push_to_output_buffer( verbose: str )
end
- # Prints a line of message
- #
- # Obeys {@@only_positives}
- #
- # @see #only_positives?
- # @see #only_positives
- #
- # @param [String] str
- #
def print_line( str = '' )
return if only_positives?
push_to_output_buffer( line: str )
end
@@ -187,22 +79,16 @@
end
private
def push_to_output_buffer( msg )
- if file = @@reroute_to_file
- File.open( file, 'a+' ) do |f|
- type = msg.keys[0]
- str = msg.values[0]
- next if str.empty?
+ return if !@@reroute_to_file
- f.write( "[#{Time.now.asctime}] [#{type}] #{str}\n" )
- end
- else
- @@output_buffer << msg
- if @@output_buffer_cap.is_a?( Integer )
- @@output_buffer.slice!( (@@output_buffer.size - @@output_buffer_cap)..@@output_buffer.size )
- end
+ File.open( @@reroute_to_file, 'a+' ) do |f|
+ type = msg.keys[0]
+ str = msg.values[0]
+
+ f.write( "[#{Time.now.asctime}] [#{type}] #{str}\n" )
end
end
extend self