Module: Msf::DBManager::Report
- Included in:
- Msf::DBManager
- Defined in:
- lib/msf/core/db_manager/report.rb
Instance Method Summary collapse
-
#find_or_create_report(opts) ⇒ Object
TODO This method does not attempt to find.
-
#report_artifact(opts) ⇒ Object
Creates a ReportArtifact based on passed parameters.
-
#report_report(opts) ⇒ Integer
Creates a Report based on passed parameters.
-
#reports(wspace = framework.db.workspace) ⇒ Object
This methods returns a list of all reports in the database.
Instance Method Details
#find_or_create_report(opts) ⇒ Object
TODO This method does not attempt to find. It just creates a report based on the passed params.
10 11 12 |
# File 'lib/msf/core/db_manager/report.rb', line 10 def find_or_create_report(opts) report_report(opts) end |
#report_artifact(opts) ⇒ Object
Creates a ReportArtifact based on passed parameters.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/msf/core/db_manager/report.rb', line 16 def report_artifact(opts) return if not active artifacts_dir = Report::ARTIFACT_DIR tmp_path = opts[:file_path] artifact_name = File.basename tmp_path new_path = File.join(artifacts_dir, artifact_name) opts = opts.clone() # protect the original caller's opts created = opts.delete(:created_at) updated = opts.delete(:updated_at) unless File.exist? tmp_path raise Msf::DBImportError 'Report artifact file to be imported does not exist.' end unless (File.directory?(artifacts_dir) && File.writable?(artifacts_dir)) raise Msf::DBImportError "Could not move report artifact file to #{artifacts_dir}." end if File.exist? new_path unique_basename = "#{(Time.now.to_f*1000).to_i}_#{artifact_name}" new_path = File.join(artifacts_dir, unique_basename) end FileUtils.copy(tmp_path, new_path) opts[:file_path] = new_path artifact = ReportArtifact.new(opts) artifact.created_at = created artifact.updated_at = updated unless artifact.valid? errors = artifact.errors..join('; ') raise "Artifact to be imported is not valid: #{errors}" end artifact.save end |
#report_report(opts) ⇒ Integer
Creates a Report based on passed parameters. Does not handle child artifacts.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/msf/core/db_manager/report.rb', line 57 def report_report(opts) return if not active opts = opts.clone() # protect the original caller's opts created = opts.delete(:created_at) updated = opts.delete(:updated_at) state = opts.delete(:state) ::ApplicationRecord.connection_pool.with_connection { report = Report.new(opts) report.created_at = created report.updated_at = updated unless report.valid? errors = report.errors..join('; ') raise "Report to be imported is not valid: #{errors}" end report.state = :complete # Presume complete since it was exported report.save report.id } end |
#reports(wspace = framework.db.workspace) ⇒ Object
This methods returns a list of all reports in the database
83 84 85 86 87 |
# File 'lib/msf/core/db_manager/report.rb', line 83 def reports(wspace=framework.db.workspace) ::ApplicationRecord.connection_pool.with_connection { wspace.reports } end |