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

<tasos.laskos@gmail.com>
<zapotek@segfault.gr>

@version: 0.1

Constant Summary collapse

FOLDERNAME =
"reports"
EXTENSION =
'.afr'

Instance Method Summary collapse

Constructor Details

#initialize(opts, settings) ⇒ ReportManager

Returns a new instance of ReportManager.



30
31
32
33
34
# File 'lib/ui/web/report_manager.rb', line 30

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

Instance Method Details

#allArray

Returns the paths of all saved report files as an array

Returns:

  • (Array)


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

def all
    Dir.glob( savedir + "*#{EXTENSION}" )
end

#availableArray

Returns all available report types

Returns:

  • (Array)


139
140
141
# File 'lib/ui/web/report_manager.rb', line 139

def available
    return @@available
end

#classesArray

Returns all available report classes

Returns:

  • (Array)


148
149
150
# File 'lib/ui/web/report_manager.rb', line 148

def classes
    @@available_rep_classes
end

#delete(report) ⇒ Object



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

def delete( report )
    FileUtils.rm( savedir + File.basename( report, '.afr' ) + '.afr' )
end

#delete_allObject



94
95
96
97
98
99
# File 'lib/ui/web/report_manager.rb', line 94

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

#get(type, report_file) ⇒ String

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

Parameters:

  • type (String)

    html, txt, xml, etc

  • report_file (String)

    path to the report

Returns:

  • (String)

    the converted report



127
128
129
130
131
132
# File 'lib/ui/web/report_manager.rb', line 127

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

    location = savedir + report_file + EXTENSION
    convert( type, File.read( location ) )
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



114
115
116
117
# File 'lib/ui/web/report_manager.rb', line 114

def get_filename( report )
    rep = YAML::load( report )
    filename = "#{URI(rep.options['url']).host}:#{rep.start_datetime}"
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:



70
71
72
# File 'lib/ui/web/report_manager.rb', line 70

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



58
59
60
61
# File 'lib/ui/web/report_manager.rb', line 58

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:



39
40
41
# File 'lib/ui/web/report_manager.rb', line 39

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

#tmpdirString

Returns tmp directory for storage while converting.

Returns:

  • (String)

    tmp directory for storage while converting



46
47
48
# File 'lib/ui/web/report_manager.rb', line 46

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)


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

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