Class: Arachni::UI::Web::ReportManager

Inherits:
Object
  • Object
show all
Defined in:
lib/arachni/ui/web/report_manager.rb

Overview

Provides nice little wrapper for the Arachni::Report::Manager while also handling<br/> conversions, storing etc.

Author:

Version:

  • 0.2

Defined Under Namespace

Classes: Report

Constant Summary collapse

FOLDERNAME =
"reports"
EXTENSION =
'.afr'

Instance Method Summary collapse

Constructor Details

#initialize(opts, settings) ⇒ ReportManager

Returns a new instance of ReportManager.



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/arachni/ui/web/report_manager.rb', line 46

def initialize( opts, settings )
    @opts     = opts
    @settings = settings
    populate_available

    DataMapper::setup( :default, "sqlite3://#{@settings.db}/default.db" )
    DataMapper.finalize

    # Report.raise_on_save_failure = true
    Report.auto_upgrade!

    migrate_files
end

Instance Method Details

#all(*args) ⇒ Array

Returns the paths of all saved report files as an array

Returns:



137
138
139
# File 'lib/arachni/ui/web/report_manager.rb', line 137

def all( *args )
    Report.all( *args )
end

#availableArray

Returns all available report types

Returns:



219
220
221
# File 'lib/arachni/ui/web/report_manager.rb', line 219

def available
    return @@available
end

#classesArray

Returns all available report classes

Returns:



228
229
230
# File 'lib/arachni/ui/web/report_manager.rb', line 228

def classes
    @@available_rep_classes
end

#delete(id) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/arachni/ui/web/report_manager.rb', line 149

def delete( id )
    report = Report.get( id )
    begin
        FileUtils.rm( savedir + Report.get( id ).filename + EXTENSION )
    rescue
    end

    begin
        report.destroy
    rescue
    end
end

#delete_allObject



141
142
143
144
145
146
147
# File 'lib/arachni/ui/web/report_manager.rb', line 141

def delete_all
    all.each {
        |report|
        delete( report.id )
    }
    all.destroy
end

#get(type, id) ⇒ String

Returns a stored report as a <type> file. Basically a convertion/export method.

Parameters:

  • type (String)

    html, txt, xml, etc

  • id (Integer)

    report id

Returns:

  • (String)

    the converted report



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/arachni/ui/web/report_manager.rb', line 195

def get( type, id )
    return if !valid_class?( type )

    # begin
        location = savedir + Report.get( id ).filename + EXTENSION

        # if it's the default report type don't waste time converting
        if '.' + type == EXTENSION
            return File.read( location )
        else
            return convert( type, ::Arachni::AuditStore.load( location ) )
        end
    # rescue Exception => e
        # ap e
        # ap e.backtrace
        # return nil
    # end
end

#get_finish_datetime(report) ⇒ Object



183
184
185
# File 'lib/arachni/ui/web/report_manager.rb', line 183

def get_finish_datetime( report )
    return report.finish_datetime
end

#get_host(report) ⇒ Object



179
180
181
# File 'lib/arachni/ui/web/report_manager.rb', line 179

def get_host( report )
    return URI( report.options['url'] ).host
end

#get_issue_count(report) ⇒ Object



175
176
177
# File 'lib/arachni/ui/web/report_manager.rb', line 175

def get_issue_count( report )
    report.issues.size
end

#migrate_filesObject

Migrates AFR reports from the savedir folder into the DB so that users will be able to manage them via the WebUI



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/arachni/ui/web/report_manager.rb', line 64

def migrate_files
    Dir.glob( "#{savedir}*" + EXTENSION ).each {
        |file|
        next if Report.first( :filename => File.basename( file, EXTENSION ) )

        begin
            report = ::Arachni::AuditStore.load( file )
            Report.create(
                :issue_count => get_issue_count( report ),
                :host        => get_host( report ),
                :filename    => File.basename( file, EXTENSION ),
                :datestamp   => get_finish_datetime( report )
            )
        rescue Exception => e
            # p file
            # ap e
            # ap e.backtrace
        end
    }
end

#report_to_filename(report) ⇒ String

Generates a filename based on the contents of the report in the form of host:audit_date

Parameters:

Returns:

  • (String)

    host.audit_date.ext



170
171
172
173
# File 'lib/arachni/ui/web/report_manager.rb', line 170

def report_to_filename( report )
    filename = "#{URI(report.options['url']).host}:#{report.start_datetime}"
    filename.gsub( ':', '.' ).gsub( ' ', '_' ).gsub( '-', '_' ).gsub( '__', '_' )
end

#report_to_path(report) ⇒ String

Gets the path to a given report based on the contents of the report

Parameters:

Returns:



117
118
119
# File 'lib/arachni/ui/web/report_manager.rb', line 117

def report_to_path( report )
    savedir + File.basename( report_to_filename( report ) + EXTENSION )
end

#save(report) ⇒ String

Saves the report to a file

Parameters:

Returns:

  • (String)

    the path to the saved report



106
107
108
109
# File 'lib/arachni/ui/web/report_manager.rb', line 106

def save( report )
    @settings.log.report_saved( {}, report_to_filename( report ) )
    return save_to_file( report, report_to_path( report ) )
end

#savedirString

Returns save directory.

Returns:



88
89
90
# File 'lib/arachni/ui/web/report_manager.rb', line 88

def savedir
    @settings.public_folder + "/#{FOLDERNAME}/"
end

#tmpdirString

Returns tmp directory for storage while converting.

Returns:

  • (String)

    tmp directory for storage while converting



95
96
97
# File 'lib/arachni/ui/web/report_manager.rb', line 95

def tmpdir
    @settings.tmp + '/'
end

#valid_class?(type) ⇒ Bool

Checks whether the provided type is a usable report

Parameters:

  • type (String)

    usually html,txt,xml etc

Returns:

  • (Bool)


128
129
130
# File 'lib/arachni/ui/web/report_manager.rb', line 128

def valid_class?( type )
    classes[type] || false
end