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

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

@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.



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/arachni/ui/web/report_manager.rb', line 42

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:



133
134
135
# File 'lib/arachni/ui/web/report_manager.rb', line 133

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

#availableArray

Returns all available report types

Returns:



215
216
217
# File 'lib/arachni/ui/web/report_manager.rb', line 215

def available
    return @@available
end

#classesArray

Returns all available report classes

Returns:



224
225
226
# File 'lib/arachni/ui/web/report_manager.rb', line 224

def classes
    @@available_rep_classes
end

#delete(id) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/arachni/ui/web/report_manager.rb', line 145

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



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

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



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/arachni/ui/web/report_manager.rb', line 191

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



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

def get_finish_datetime( report )
    return report.finish_datetime
end

#get_host(report) ⇒ Object



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

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

#get_issue_count(report) ⇒ Object



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

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



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/arachni/ui/web/report_manager.rb', line 60

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



166
167
168
169
# File 'lib/arachni/ui/web/report_manager.rb', line 166

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:



113
114
115
# File 'lib/arachni/ui/web/report_manager.rb', line 113

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



102
103
104
105
# File 'lib/arachni/ui/web/report_manager.rb', line 102

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:



84
85
86
# File 'lib/arachni/ui/web/report_manager.rb', line 84

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

#tmpdirString

Returns tmp directory for storage while converting.

Returns:

  • (String)

    tmp directory for storage while converting



91
92
93
# File 'lib/arachni/ui/web/report_manager.rb', line 91

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)


124
125
126
# File 'lib/arachni/ui/web/report_manager.rb', line 124

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