Class: Nexpose::ScanTemplate
- Inherits:
-
Object
- Object
- Nexpose::ScanTemplate
- Defined in:
- lib/nexpose/scan_template.rb
Overview
Configuration object for a scan template. This class is only a partial representation of some of the features available for configuration.
Instance Attribute Summary collapse
-
#correlate ⇒ Object
Whether to correlate reliable checks with regular checks.
-
#description ⇒ Object
Returns the value of attribute description.
-
#id ⇒ Object
Unique identifier of the scan template.
-
#name ⇒ Object
Returns the value of attribute name.
-
#xml ⇒ Object
Parsed XML of a scan template.
Class Method Summary collapse
-
.copy(nsc, id) ⇒ ScanTemplate
Copy an existing scan template, changing the id and title.
-
.load(nsc, id) ⇒ ScanTemplate
Load an existing scan template.
Instance Method Summary collapse
-
#initialize(xml) ⇒ ScanTemplate
constructor
A new instance of ScanTemplate.
-
#save(nsc) ⇒ Object
Save this scan template configuration to a Nexpose console.
Constructor Details
#initialize(xml) ⇒ ScanTemplate
Returns a new instance of ScanTemplate.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/nexpose/scan_template.rb', line 43 def initialize(xml) @xml = xml root = REXML::XPath.first(xml, 'ScanTemplate') @id = root.attributes['id'] desc = REXML::XPath.first(root, 'templateDescription') @name = desc.attributes['title'] @description = desc.text.to_s vuln_checks = REXML::XPath.first(root, 'VulnerabilityChecks') @correlate = vuln_checks.attributes['correlate'] == '1' end |
Instance Attribute Details
#correlate ⇒ Object
Whether to correlate reliable checks with regular checks.
38 39 40 |
# File 'lib/nexpose/scan_template.rb', line 38 def correlate @correlate end |
#description ⇒ Object
Returns the value of attribute description.
35 36 37 |
# File 'lib/nexpose/scan_template.rb', line 35 def description @description end |
#id ⇒ Object
Unique identifier of the scan template.
32 33 34 |
# File 'lib/nexpose/scan_template.rb', line 32 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
34 35 36 |
# File 'lib/nexpose/scan_template.rb', line 34 def name @name end |
#xml ⇒ Object
Parsed XML of a scan template
41 42 43 |
# File 'lib/nexpose/scan_template.rb', line 41 def xml @xml end |
Class Method Details
.copy(nsc, id) ⇒ ScanTemplate
Copy an existing scan template, changing the id and title.
96 97 98 99 100 101 |
# File 'lib/nexpose/scan_template.rb', line 96 def self.copy(nsc, id) dupe = load(nsc, id) dupe.id = "#{dupe.id}-copy" dupe.title = "#{dupe.title} Copy" dupe end |
.load(nsc, id) ⇒ ScanTemplate
Load an existing scan template.
85 86 87 88 |
# File 'lib/nexpose/scan_template.rb', line 85 def self.load(nsc, id) response = JSON.parse(AJAX.get(nsc, "/data/scan/templates/#{URI.encode(id)}")) new(REXML::Document.new(response['value'])) end |
Instance Method Details
#save(nsc) ⇒ Object
Save this scan template configuration to a Nexpose console.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/nexpose/scan_template.rb', line 59 def save(nsc) root = REXML::XPath.first(@xml, 'ScanTemplate') existing = root.attributes['id'] == @id root.attributes['id'] = @id unless existing desc = REXML::XPath.first(root, 'templateDescription') desc.attributes['title'] = @name desc.text = @description vuln_checks = REXML::XPath.first(root, 'VulnerabilityChecks') vuln_checks.attributes['correlate'] = (@correlate ? '1' : '0') if existing response = AJAX.put(nsc, "/data/scan/templates/#{URI.encode(id)}", xml) else response = JSON.parse(AJAX.post(nsc, '/data/scan/templates', xml)) @id = response['value'] end end |