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.



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_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

#asset_linkingObject

Whether asset linking in enabled.



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

def asset_linking
  @asset_linking
end

#control_scanningObject

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

#xmlObject (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.

Parameters:

  • nsc (Connection)

    Connection to a Nexpose console.

Returns:



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.

Parameters:

  • host_or_ip (IPRange|HostName|String)

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



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.

Returns:

  • (Boolean)


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.

Parameters:

  • host_or_ip (IPRange|HostName|String)

    Host or IP (range) to remove from the exclusion list.



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.

Parameters:

  • nsc (Connection)

    Connection to a Nexpose console.

Returns:

  • (Boolean)

    Whether saving was successful.



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