Class: Nexpose::GlobalSettings

Inherits:
Object
  • Object
show all
Defined in:
lib/nexpose/global_settings.rb

Overview

Object used to manage the global settings of a Nexpose console.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ GlobalSettings

Private constructor. See #load method for retrieving a settings object.



18
19
20
21
22
23
# File 'lib/nexpose/global_settings.rb', line 18

def initialize(xml)
  @xml = xml

  @asset_exclusions = HostOrIP.parse(xml)
  @control_scanning = parse_control_scanning_from_xml(xml)
end

Instance Attribute Details

#asset_exclusionsObject

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

#control_scanningObject

Whether control scanning in enabled. A feature tied to ControlsInsight integration.



11
12
13
# File 'lib/nexpose/global_settings.rb', line 11

def control_scanning
  @control_scanning
end

#xmlObject (readonly)

XML document representing the entire configuration.



14
15
16
# File 'lib/nexpose/global_settings.rb', line 14

def xml
  @xml
end

Class Method Details

.load(nsc) ⇒ GlobalSettings

Load the global settings from a Nexpose console.

Parameters:

  • nsc (Connection)

    Connection to a Nexpose console.

Returns:



83
84
85
86
# File 'lib/nexpose/global_settings.rb', line 83

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.

Parameters:

  • host_or_ip (IPRange|HostName|String)

    Host or IP (range) to exclude from scanning by the Nexpose console.



54
55
56
57
58
59
60
# File 'lib/nexpose/global_settings.rb', line 54

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.

Returns:

  • (Boolean)


26
27
28
# File 'lib/nexpose/global_settings.rb', line 26

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.

Parameters:



69
70
71
72
73
74
75
76
# File 'lib/nexpose/global_settings.rb', line 69

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.

Parameters:

  • nsc (Connection)

    Connection to a Nexpose console.

Returns:

  • (Boolean)

    Whether saving was successful.



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/nexpose/global_settings.rb', line 35

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)

  response = AJAX.post(nsc, '/data/admin/global-settings', xml)
  XMLUtils.success? response
end