Class: Nexpose::Engine
- Inherits:
-
Object
- Object
- Nexpose::Engine
- Includes:
- Sanitize
- Defined in:
- lib/nexpose/engine.rb
Overview
Engine connnection to a Nexpose console.
Instance Attribute Summary collapse
-
#address ⇒ Object
The IP address or DNS name of a scan engine.
-
#id ⇒ Object
Unique numeric identifier for the scan engine, assigned by the console in the order of creation.
-
#name ⇒ Object
A name assigned to the scan engine by the security console.
-
#port ⇒ Object
The port on which the engine listens for requests from the security console.
-
#priority ⇒ Object
Relative priority of a scan engine.
-
#scope ⇒ Object
Whether the engine has a global or silo-specific scope.
-
#sites ⇒ Object
Sites to which the scan engine is assigned.
Class Method Summary collapse
Instance Method Summary collapse
-
#add_site(site_id) ⇒ Object
Assign a site to this scan engine.
-
#delete(connection) ⇒ Object
Delete this scan engine configuration from the security console.
-
#initialize(address, name = nil, port = 40814) ⇒ Engine
constructor
A new instance of Engine.
-
#save(connection) ⇒ Fixnum
Save this engine configuration to the security console.
- #to_xml ⇒ Object
Methods included from Sanitize
Constructor Details
#initialize(address, name = nil, port = 40814) ⇒ Engine
Returns a new instance of Engine.
144 145 146 147 148 149 150 151 152 |
# File 'lib/nexpose/engine.rb', line 144 def initialize(address, name = nil, port = 40814) @id = -1 @address = address @name = name @name ||= address @port = port @scope = 'silo' @sites = [] end |
Instance Attribute Details
#address ⇒ Object
The IP address or DNS name of a scan engine.
129 130 131 |
# File 'lib/nexpose/engine.rb', line 129 def address @address end |
#id ⇒ Object
Unique numeric identifier for the scan engine, assigned by the console in the order of creation.
127 128 129 |
# File 'lib/nexpose/engine.rb', line 127 def id @id end |
#name ⇒ Object
A name assigned to the scan engine by the security console.
131 132 133 |
# File 'lib/nexpose/engine.rb', line 131 def name @name end |
#port ⇒ Object
The port on which the engine listens for requests from the security console.
134 135 136 |
# File 'lib/nexpose/engine.rb', line 134 def port @port end |
#priority ⇒ Object
Relative priority of a scan engine. One of: very-low, low, normal, high, very-high
139 140 141 |
# File 'lib/nexpose/engine.rb', line 139 def priority @priority end |
#scope ⇒ Object
Whether the engine has a global or silo-specific scope.
136 137 138 |
# File 'lib/nexpose/engine.rb', line 136 def scope @scope end |
#sites ⇒ Object
Sites to which the scan engine is assigned.
142 143 144 |
# File 'lib/nexpose/engine.rb', line 142 def sites @sites end |
Class Method Details
.load(connection, id) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/nexpose/engine.rb', line 154 def self.load(connection, id) xml = '<EngineConfigRequest session-id="' + connection.session_id + '"' xml << %( engine-id="#{id}") xml << ' />' r = connection.execute(xml, '1.2') if r.success r.res.elements.each('EngineConfigResponse/EngineConfig') do |config| engine = Engine.new(config.attributes['address'], config.attributes['name'], config.attributes['port']) engine.id = config.attributes['id'] engine.scope = config.attributes['scope'] if config.attributes['scope'] engine.priority = config.attributes['priority'] if config.attributes['priority'] config.elements.each('Site') do |site| engine.sites << SiteSummary.new(site.attributes['id'], site.attributes['name']) end return engine end end nil end |
Instance Method Details
#add_site(site_id) ⇒ Object
Assign a site to this scan engine.
183 184 185 |
# File 'lib/nexpose/engine.rb', line 183 def add_site(site_id) sites << SiteSummary.new(site_id, nil) end |
#delete(connection) ⇒ Object
Delete this scan engine configuration from the security console.
227 228 229 |
# File 'lib/nexpose/engine.rb', line 227 def delete(connection) connection.delete_engine(@id, @scope) end |
#save(connection) ⇒ Fixnum
Save this engine configuration to the security console.
210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/nexpose/engine.rb', line 210 def save(connection) xml = '<EngineSaveRequest session-id="' + connection.session_id + '">' xml << to_xml xml << '</EngineSaveRequest>' r = connection.execute(xml, '1.2') if r.success r.res.elements.each('EngineSaveResponse/EngineConfig') do |v| return @id = v.attributes['id'].to_i end end end |
#to_xml ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/nexpose/engine.rb', line 189 def to_xml xml = '<EngineConfig' xml << %( id="#{id}") xml << %( address="#{address}") xml << %( name="#{replace_entities(name)}") xml << %( port="#{port}") xml << %( scope="#{scope}") if scope xml << %( priority="#{priority}") if priority xml << '>' sites.each do |site| xml << %(<Site id="#{site.id}" />) end xml << '</EngineConfig>' xml end |