This repository has been archived by the owner on Sep 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from fakenine/refactor_results_model
Refactor results model
- Loading branch information
Showing
6 changed files
with
58 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'time' | ||
|
||
module Openvas | ||
# Class used to interact with OpenVAS' scans results | ||
class Result | ||
attr_accessor :id, :name, :comment, :description, :host, :user, :port, :severity, :created_at, :updated_at | ||
|
||
def initialize(result) | ||
@id = result.at_xpath('@id').value | ||
@name = result.at_xpath('name').text | ||
@comment = result.at_xpath('comment').text | ||
@user = result.at_xpath('owner/name').text | ||
@host = result.at_xpath('host').text | ||
@port = result.at_xpath('port').text | ||
@severity = result.at_xpath('severity').text | ||
@description = result.at_xpath('description').text | ||
|
||
@created_at = Time.parse(result.at_xpath('creation_time').text) | ||
@updated_at = Time.parse(result.at_xpath('modification_time').text) | ||
end | ||
|
||
def results | ||
Openvas::Result.find_by_report_id(@id) | ||
end | ||
|
||
class << self | ||
MAX_RESULTS = 1000 | ||
|
||
def all | ||
# TODO: implement pagination | ||
query = Nokogiri::XML::Builder.new { get_results(filter: "first=1 rows=#{MAX_RESULTS}") } | ||
|
||
query(query).xpath('//get_results_response/result').map do |result| | ||
new(result) | ||
end | ||
end | ||
|
||
def find_by_id(id) | ||
query = Nokogiri::XML::Builder.new { get_results(result_id: id) } | ||
new(query(query).at_xpath('//get_results_response/result')) | ||
end | ||
|
||
def find_by_report_id(id) | ||
# TODO: implement pagination | ||
query = Nokogiri::XML::Builder.new { get_results(filter: "report_id=#{id} first=1 rows=#{MAX_RESULTS}") } | ||
|
||
query(query).xpath('//get_results_response/result').map do |result| | ||
new(result) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters