Module: Arachni::Framework::Parts::Report

Included in:
Arachni::Framework
Defined in:
lib/arachni/framework/parts/report.rb

Overview

Provides a Report::Manager and related helpers.

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#reportersArachni::Reporter::Manager (readonly)



19
20
21
# File 'lib/arachni/framework/parts/report.rb', line 19

def reporters
  @reporters
end

Instance Method Details

#initializeObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/arachni/framework/parts/report.rb', line 21

def initialize
    super

    # Deep clone the redundancy rules to preserve their original counters
    # for the reports.
    @original_redundant_path_patterns =
        options.scope.redundant_path_patterns.deep_clone

    @reporters = Arachni::Reporter::Manager.new
end

#list_reporters(patterns = nil) ⇒ Array<Hash>

Returns Information about all available Reporters.

Returns:



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/arachni/framework/parts/report.rb', line 95

def list_reporters( patterns = nil )
    loaded = @reporters.loaded

    begin
        @reporters.clear
        @reporters.available.map do |report|
            path = @reporters.name_to_path( report )
            next if patterns && !@reporters.matches_globs?( path, patterns )

            @reporters[report].info.merge(
                options:   @reporters[report].info[:options] || [],
                shortname: report,
                path:      path,
                author:    [@reporters[report].info[:author]].
                               flatten.map { |a| a.strip }
            )
        end.compact
    ensure
        @reporters.clear
        @reporters.load loaded
    end
end

#reportReport

Returns Scan results.

Returns:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/arachni/framework/parts/report.rb', line 34

def report
    opts = options.to_hash.deep_clone

    # restore the original redundancy rules and their counters
    opts[:scope][:redundant_path_patterns] = @original_redundant_path_patterns

    Arachni::Report.new(
        options:         options,
        sitemap:         sitemap,
        issues:          Arachni::Data.issues.sort,
        plugins:         @plugins.results,
        start_datetime:  @start_datetime,
        finish_datetime: @finish_datetime
    )
end

#report_as(name, external_report = report) ⇒ String

Runs a reporter component and returns the contents of the generated report.

Only accepts reporters which support an outfile option.

Parameters:

  • name (String)

    Name of the reporter component to run, as presented by #list_reporters's :shortname key.

  • external_report (Report) (defaults to: report)

    Report to use -- defaults to the local one.

Returns:

Raises:



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/arachni/framework/parts/report.rb', line 68

def report_as( name, external_report = report )
    if !@reporters.available.include?( name.to_s )
        fail Component::Error::NotFound, "Reporter '#{name}' could not be found."
    end

    loaded = @reporters.loaded
    begin
        @reporters.clear

        if !@reporters[name].has_outfile?
            fail Component::Options::Error::Invalid,
                 "Reporter '#{name}' cannot format the audit results as a String."
        end

        outfile = "#{Options.paths.tmpdir}/#{generate_token}"
        @reporters.run( name, external_report, outfile: outfile )

        IO.binread( outfile )
    ensure
        File.delete( outfile ) if outfile && File.exists?( outfile )
        @reporters.clear
        @reporters.load loaded
    end
end