Class: Nexpose::GlobalSettings
- Inherits:
-
Object
- Object
- Nexpose::GlobalSettings
- Defined in:
- lib/nexpose/global_settings.rb
Overview
Object used to manage the global settings of a Nexpose console.
Instance Attribute Summary collapse
-
#asset_exclusions ⇒ Object
IP addresses and/or host names that will be excluded from scanning across all sites.
-
#asset_linking ⇒ Object
Whether asset linking in enabled.
-
#control_scanning ⇒ Object
Whether control scanning in enabled.
-
#xml ⇒ Object
readonly
XML document representing the entire configuration.
Class Method Summary collapse
-
.load(nsc) ⇒ GlobalSettings
Load the global settings from a Nexpose console.
Instance Method Summary collapse
-
#add_exclusion(host_or_ip) ⇒ Object
Add an asset exclusion setting.
-
#control_scanning? ⇒ Boolean
Returns true if controls scanning is enabled.
-
#initialize(xml) ⇒ GlobalSettings
constructor
Private constructor.
-
#remove_exclusion(host_or_ip) ⇒ Object
Remove an asset exclusion setting.
-
#save(nsc) ⇒ Boolean
Save any updates to this settings object to the Nexpose console.
Constructor Details
#initialize(xml) ⇒ GlobalSettings
Private constructor. See #load method for retrieving a settings object.
21 22 23 24 25 26 |
# File 'lib/nexpose/global_settings.rb', line 21 def initialize(xml) @xml = xml @asset_linking = parse_asset_linking_from_xml(xml) @asset_exclusions = HostOrIP.parse(xml) @control_scanning = parse_control_scanning_from_xml(xml) end |
Instance Attribute Details
#asset_exclusions ⇒ Object
IP addresses and/or host names that will be excluded from scanning across all sites.
7 8 9 |
# File 'lib/nexpose/global_settings.rb', line 7 def asset_exclusions @asset_exclusions end |
#asset_linking ⇒ Object
Whether asset linking in enabled.
10 11 12 |
# File 'lib/nexpose/global_settings.rb', line 10 def asset_linking @asset_linking end |
#control_scanning ⇒ Object
Whether control scanning in enabled. A feature tied to ControlsInsight integration.
14 15 16 |
# File 'lib/nexpose/global_settings.rb', line 14 def control_scanning @control_scanning end |
#xml ⇒ Object (readonly)
XML document representing the entire configuration.
17 18 19 |
# File 'lib/nexpose/global_settings.rb', line 17 def xml @xml end |
Class Method Details
.load(nsc) ⇒ GlobalSettings
Load the global settings from a Nexpose console.
87 88 89 90 |
# File 'lib/nexpose/global_settings.rb', line 87 def self.load(nsc) response = AJAX.get(nsc, '/data/admin/global-settings') new(REXML::Document.new(response)) end |
Instance Method Details
#add_exclusion(host_or_ip) ⇒ Object
Add an asset exclusion setting.
58 59 60 61 62 63 64 |
# File 'lib/nexpose/global_settings.rb', line 58 def add_exclusion(host_or_ip) asset = host_or_ip unless host_or_ip.respond_to?(:host) || host_or_ip.respond_to?(:from) asset = HostOrIP.convert(host_or_ip) end @asset_exclusions << asset end |
#control_scanning? ⇒ Boolean
Returns true if controls scanning is enabled.
29 30 31 |
# File 'lib/nexpose/global_settings.rb', line 29 def control_scanning? control_scanning end |
#remove_exclusion(host_or_ip) ⇒ Object
Remove an asset exclusion setting. If you need to remove a range of IPs, be sure to explicitly supply an IPRange object to the method.
73 74 75 76 77 78 79 80 |
# File 'lib/nexpose/global_settings.rb', line 73 def remove_exclusion(host_or_ip) asset = host_or_ip unless host_or_ip.respond_to?(:host) || host_or_ip.respond_to?(:from) # Attept to convert String to appropriate object. asset = HostOrIP.convert(host_or_ip) end @asset_exclusions = asset_exclusions.reject { |a| a.eql? asset } end |
#save(nsc) ⇒ Boolean
Save any updates to this settings object to the Nexpose console.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/nexpose/global_settings.rb', line 38 def save(nsc) # load method can return XML missing this required attribute. unless REXML::XPath.first(xml, '//*[@recalculation_duration]') risk_model = REXML::XPath.first(xml, '//riskModel') risk_model.add_attribute('recalculation_duration', 'do_not_recalculate') end replace_exclusions(xml, asset_exclusions) add_control_scanning_to_xml(xml, control_scanning) add_asset_linking_to_xml(xml, asset_linking) response = AJAX.post(nsc, '/data/admin/global-settings', xml) XMLUtils.success? response end |