Class: Arachni::UI::Web::ReportManager
- 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
-
#all(*args) ⇒ Array
Returns the paths of all saved report files as an array.
-
#available ⇒ Array
Returns all available report types.
-
#classes ⇒ Array
Returns all available report classes.
- #delete(id) ⇒ Object
- #delete_all ⇒ Object
-
#get(type, id) ⇒ String
Returns a stored report as a <type> file.
-
#get_filename(report) ⇒ String
Generates a filename based on the contents of the report in the form of host:audit_date.
- #get_finish_datetime(report) ⇒ Object
- #get_host(report) ⇒ Object
- #get_issue_count(report) ⇒ Object
-
#initialize(opts, settings) ⇒ ReportManager
constructor
A new instance of ReportManager.
-
#migrate_files ⇒ Object
Migrates AFR reports from the savedir folder into the DB so that users will be able to manage them via the WebUI.
-
#report_to_path(report) ⇒ String
Gets the path to a given report based on the contents of the report.
-
#save(report) ⇒ String
Saves the report to a file.
-
#savedir ⇒ String
Save directory.
-
#tmpdir ⇒ String
Tmp directory for storage while converting.
-
#valid_class?(type) ⇒ Bool
Checks whether the provided type is a usable report.
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
132 133 134 |
# File 'lib/ui/web/report_manager.rb', line 132 def all( *args ) Report.all( *args ) end |
#available ⇒ Array
Returns all available report types
207 208 209 |
# File 'lib/ui/web/report_manager.rb', line 207 def available return @@available end |
#classes ⇒ Array
Returns all available report classes
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_all ⇒ Object
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.
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
166 167 168 169 |
# File 'lib/ui/web/report_manager.rb', line 166 def get_filename( report ) rep = unserialize( report ) filename = "#{URI(rep.['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 ).['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_files ⇒ Object
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
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
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 |
#savedir ⇒ String
Returns save directory.
81 82 83 |
# File 'lib/ui/web/report_manager.rb', line 81 def savedir @settings.public + "/#{FOLDERNAME}/" end |
#tmpdir ⇒ String
Returns 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
123 124 125 |
# File 'lib/ui/web/report_manager.rb', line 123 def valid_class?( type ) classes[type] || false end |