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

Inherits:
Object
  • Object
show all
Defined in:
lib/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.1.1

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.



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

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

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

    Report.auto_upgrade!

    migrate_files
end

Instance Method Details

#all(*args) ⇒ Array

Returns the paths of all saved report files as an array

Returns:

  • (Array)


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

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

#availableArray

Returns all available report types

Returns:

  • (Array)


207
208
209
# File 'lib/ui/web/report_manager.rb', line 207

def available
    return @@available
end

#classesArray

Returns all available report classes

Returns:

  • (Array)


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

def classes
    @@available_rep_classes
end

#delete(id) ⇒ Object



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

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



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

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
# File 'lib/ui/web/report_manager.rb', line 191

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

    begin
        location = savedir + Report.get( id ).filename + EXTENSION
        convert( type, File.read( location ) )
    rescue
        return nil
    end
end

#get_filename(report) ⇒ String

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

Parameters:

  • report (String)

    YAML serialized audistore object as returned by the Arachni XMLRPC server. Basically an ‘afr’ report as a string.

Returns:

  • (String)

    host:audit_date



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

def get_filename( report )
    rep = unserialize( report )
    filename = "#{URI(rep.options['url']).host}:#{rep.start_datetime}"
end

#get_finish_datetime(report) ⇒ Object



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

def get_finish_datetime( report )
    return unserialize( report ).finish_datetime
end

#get_host(report) ⇒ Object



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

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

#get_issue_count(report) ⇒ Object



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

def get_issue_count( report )
    unserialize( 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
# File 'lib/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
            data = File.read( file )
            Report.create(
                :issue_count => get_issue_count( data ),
                :host        => get_host( data ),
                :filename    => File.basename( file, EXTENSION ),
                :datestamp   => get_finish_datetime( data )
            )
        rescue
        end
    }
end

#report_to_path(report) ⇒ String

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

Parameters:

  • report (String)

    YAML serialized audistore object as returned by the Arachni XMLRPC server. Basically an ‘afr’ report as a string.

Returns:



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

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

#save(report) ⇒ String

Saves the report to a file

Parameters:

  • report (String)

    YAML serialized audistore object as returned by the Arachni XMLRPC server. Basically an ‘afr’ report as a string.

Returns:

  • (String)

    the path to the saved report



100
101
102
103
# File 'lib/ui/web/report_manager.rb', line 100

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

#savedirString

Returns save directory.

Returns:



81
82
83
# File 'lib/ui/web/report_manager.rb', line 81

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

#tmpdirString

Returns tmp directory for storage while converting.

Returns:

  • (String)

    tmp directory for storage while converting



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

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)


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

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