Class: Nexpose::Site
- Includes:
- JsonSerializer
- Defined in:
- lib/nexpose/site.rb
Overview
Configuration object representing a Nexpose site.
For a basic walk-through, see https://github.com/rapid7/nexpose-client/wiki/Using-Sites
Instance Attribute Summary collapse
-
#alerts ⇒ Object
- Array
-
Collection of real-time alerts.
-
#auto_engine_selection_enabled ⇒ Object
Scan the assets with last scanned engine or not.
-
#config_version ⇒ Object
Configuration version.
-
#description ⇒ Object
Description of the site.
-
#discovery_config ⇒ Object
discovery config of the discovery connection associated with this site if it is dynamic.
-
#engine_id ⇒ Object
Scan Engine to use.
-
#excluded_scan_targets ⇒ Object
Excluded scan targets.
-
#id ⇒ Object
The site ID.
-
#included_scan_targets ⇒ Object
Included scan targets.
-
#name ⇒ Object
Unique name of the site.
-
#organization ⇒ Object
Information about the organization that this site belongs to.
-
#risk_factor ⇒ Object
The risk factor associated with this site.
-
#scan_template_id ⇒ Object
Scan template to use when starting a scan job.
-
#scan_template_name ⇒ Object
Friendly name of scan template to use when starting a scan job.
-
#schedules ⇒ Object
- Array
-
Schedule starting dates and times for scans, and set their frequency.
-
#search_criteria ⇒ Object
Asset filter criteria if this site is dynamic.
-
#shared_credentials ⇒ Object
- Array
-
Collection of shared credentials associated with this site.
-
#site_credentials ⇒ Object
- Array
-
Collection of credentials associated with this site.
-
#tags ⇒ Object
- Array
-
Collection of TagSummary.
-
#users ⇒ Object
- Array
-
List of user IDs for users who have access to the site.
-
#web_credentials ⇒ Object
- Array
-
Collection of web credentials associated with the site.
Class Method Summary collapse
-
.copy(connection, id) ⇒ Site
Copy an existing configuration from a Nexpose instance.
- .from_hash(hash) ⇒ Object
- .json_initializer(data) ⇒ Object
-
.load(nsc, id) ⇒ Site
Load an site from the provided console.
Instance Method Summary collapse
-
#add_asset(asset) ⇒ Object
(also: #add_host, #add_ip)
deprecated
Deprecated.
Use #include_asset instead.
-
#add_ip_range(from, to) ⇒ Object
deprecated
Deprecated.
Use #include_ip_range instead.
- #add_user(user_id) ⇒ Object
-
#delete(connection) ⇒ Boolean
Delete this site from a Nexpose console.
-
#exclude_asset(asset) ⇒ Object
Adds an asset to this site excluded scan targets, resolving whether an IP or hostname is provided.
-
#exclude_asset_group(asset_group_id) ⇒ Object
Adds an asset group ID to this site excluded scan targets.
-
#exclude_ip_range(from, to) ⇒ Object
Adds assets to this site excluded scan targets by IP address range.
-
#excluded_addresses ⇒ Array[IPRange|HostName]
Returns the array of excluded scan target addresses.
-
#excluded_addresses=(new_addresses) ⇒ Array[IPRange|HostName]
Sets the array of excluded scan target addresses.
-
#excluded_asset_groups ⇒ Array[Fixnum]
Returns the array of IDs for excluded scan target asset groups.
-
#excluded_asset_groups=(new_asset_groups) ⇒ Array[Fixnum]
Sets the array IDs for excluded scan target asset groups.
-
#include_asset(asset) ⇒ Object
Adds an asset to this site included scan targets, resolving whether an IP or hostname is provided.
-
#include_asset_group(asset_group_id) ⇒ Object
Adds an asset group ID to this site included scan targets.
-
#include_ip_range(from, to) ⇒ Object
Adds assets to this site by IP address range.
-
#included_addresses ⇒ Array[IPRange|HostName]
Returns the array of included scan target addresses.
-
#included_addresses=(new_addresses) ⇒ Array[IPRange|HostName]
Sets the array of included scan target addresses.
-
#included_asset_groups ⇒ Array[Fixnum]
Returns the array of IDs for included scan target asset groups.
-
#included_asset_groups=(new_asset_groups) ⇒ Array[Fixnum] Array of IDs of the updated scan target asset groups.
Sets the array of IDs for included scan target asset groups.
-
#initialize(name = nil, scan_template_id = 'full-audit-without-web-spider') ⇒ Site
constructor
Site constructor.
-
#is_dynamic? ⇒ Boolean
Returns true when the site is dynamic.
-
#remove_asset(asset) ⇒ Object
(also: #remove_host, #remove_ip)
deprecated
Deprecated.
Use #remove_included_asset instead.
-
#remove_excluded_asset(asset) ⇒ Object
Removes an asset to this site excluded scan targets, resolving whether an IP or hostname is provided.
-
#remove_excluded_asset_group(asset_group_id) ⇒ Object
Adds an asset group ID to this site excluded scan targets.
-
#remove_excluded_ip_range(from, to) ⇒ Object
Remove assets from this site excluded scan targets by IP address range.
-
#remove_included_asset(asset) ⇒ Object
Remove an asset to this site included scan targets, resolving whether an IP or hostname is provided.
-
#remove_included_asset_group(asset_group_id) ⇒ Object
Adds an asset group ID to this site included scan targets.
-
#remove_included_ip_range(from, to) ⇒ Object
Remove assets to this site by IP address range.
-
#remove_ip_range(from, to) ⇒ Object
deprecated
Deprecated.
Use #remove_included_ip_range instead.
- #remove_user(user_id) ⇒ Object
-
#save(connection) ⇒ Fixnum
Saves this site to a Nexpose console.
-
#scan(connection, sync_id = nil) ⇒ Scan
Scan this site.
- #to_h ⇒ Object
- #to_json ⇒ Object
- #validate_asset_group(asset_group_id) ⇒ Object
Methods included from JsonSerializer
#deserialize, #serialize, #to_hash
Methods inherited from APIObject
Constructor Details
#initialize(name = nil, scan_template_id = 'full-audit-without-web-spider') ⇒ Site
Site constructor. Both arguments are optional.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/nexpose/site.rb', line 158 def initialize(name = nil, scan_template_id = 'full-audit-without-web-spider') @name = name @scan_template_id = scan_template_id @id = -1 @risk_factor = 1.0 @config_version = 3 @schedules = [] @included_scan_targets = { addresses: [], asset_groups: [] } @excluded_scan_targets = { addresses: [], asset_groups: [] } @site_credentials = [] @shared_credentials = [] @web_credentials = [] @alerts = [] @users = [] @tags = [] end |
Instance Attribute Details
#alerts ⇒ Object
- Array
-
Collection of real-time alerts.
133 134 135 |
# File 'lib/nexpose/site.rb', line 133 def alerts @alerts end |
#auto_engine_selection_enabled ⇒ Object
Scan the assets with last scanned engine or not.
126 127 128 |
# File 'lib/nexpose/site.rb', line 126 def auto_engine_selection_enabled @auto_engine_selection_enabled end |
#config_version ⇒ Object
Configuration version. Default: 3
143 144 145 |
# File 'lib/nexpose/site.rb', line 143 def config_version @config_version end |
#description ⇒ Object
Description of the site.
90 91 92 |
# File 'lib/nexpose/site.rb', line 90 def description @description end |
#discovery_config ⇒ Object
discovery config of the discovery connection associated with this site if it is dynamic.
149 150 151 |
# File 'lib/nexpose/site.rb', line 149 def discovery_config @discovery_config end |
#engine_id ⇒ Object
Scan Engine to use. Will use the default engine if nil or -1.
106 107 108 |
# File 'lib/nexpose/site.rb', line 106 def engine_id @engine_id end |
#excluded_scan_targets ⇒ Object
Excluded scan targets. May be IPv4, IPv6, DNS names, IPRanges or assetgroup ids.
96 97 98 |
# File 'lib/nexpose/site.rb', line 96 def excluded_scan_targets @excluded_scan_targets end |
#id ⇒ Object
The site ID. An ID of -1 is used to designate a site that has not been saved to a Nexpose console.
84 85 86 |
# File 'lib/nexpose/site.rb', line 84 def id @id end |
#included_scan_targets ⇒ Object
Included scan targets. May be IPv4, IPv6, DNS names, IPRanges or assetgroup ids.
93 94 95 |
# File 'lib/nexpose/site.rb', line 93 def included_scan_targets @included_scan_targets end |
#name ⇒ Object
Unique name of the site. Required.
87 88 89 |
# File 'lib/nexpose/site.rb', line 87 def name @name end |
#organization ⇒ Object
Information about the organization that this site belongs to. Used by some reports.
137 138 139 |
# File 'lib/nexpose/site.rb', line 137 def organization @organization end |
#risk_factor ⇒ Object
The risk factor associated with this site. Default: 1.0
113 114 115 |
# File 'lib/nexpose/site.rb', line 113 def risk_factor @risk_factor end |
#scan_template_id ⇒ Object
Scan template to use when starting a scan job. Default: full-audit-without-web-spider
99 100 101 |
# File 'lib/nexpose/site.rb', line 99 def scan_template_id @scan_template_id end |
#scan_template_name ⇒ Object
Friendly name of scan template to use when starting a scan job. Value is populated when a site is saved or loaded from a console.
103 104 105 |
# File 'lib/nexpose/site.rb', line 103 def scan_template_name @scan_template_name end |
#schedules ⇒ Object
- Array
-
Schedule starting dates and times for scans, and set their frequency.
109 110 111 |
# File 'lib/nexpose/site.rb', line 109 def schedules @schedules end |
#search_criteria ⇒ Object
Asset filter criteria if this site is dynamic.
146 147 148 |
# File 'lib/nexpose/site.rb', line 146 def search_criteria @search_criteria end |
#shared_credentials ⇒ Object
- Array
-
Collection of shared credentials associated with this site.
120 121 122 |
# File 'lib/nexpose/site.rb', line 120 def shared_credentials @shared_credentials end |
#site_credentials ⇒ Object
- Array
-
Collection of credentials associated with this site. Does not
include shared credentials.
117 118 119 |
# File 'lib/nexpose/site.rb', line 117 def site_credentials @site_credentials end |
#tags ⇒ Object
- Array
-
Collection of TagSummary
152 153 154 |
# File 'lib/nexpose/site.rb', line 152 def @tags end |
#users ⇒ Object
- Array
-
List of user IDs for users who have access to the site.
140 141 142 |
# File 'lib/nexpose/site.rb', line 140 def users @users end |
#web_credentials ⇒ Object
- Array
-
Collection of web credentials associated with the site.
123 124 125 |
# File 'lib/nexpose/site.rb', line 123 def web_credentials @web_credentials end |
Class Method Details
.copy(connection, id) ⇒ Site
Copy an existing configuration from a Nexpose instance. Returned object will reset the site ID and append “Copy” to the existing name.
539 540 541 542 543 544 |
# File 'lib/nexpose/site.rb', line 539 def self.copy(connection, id) site = self.load(connection, id) site.id = -1 site.name = "#{site.name} Copy" site end |
.from_hash(hash) ⇒ Object
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
# File 'lib/nexpose/site.rb', line 432 def self.from_hash(hash) site = new(hash[:name], hash[:scan_template_id]) hash.each do |k, v| site.instance_variable_set("@#{k}", v) end # Convert each string address to either a HostName or IPRange object included_scan_targets = { addresses: [], asset_groups: [] } site.included_scan_targets[:addresses].each { |asset| included_scan_targets[:addresses] << HostOrIP.convert(asset) } included_scan_targets[:asset_groups] = site.included_scan_targets[:asset_groups] site.included_scan_targets = included_scan_targets excluded_scan_targets = { addresses: [], asset_groups: [] } site.excluded_scan_targets[:addresses].each { |asset| excluded_scan_targets[:addresses] << HostOrIP.convert(asset) } excluded_scan_targets[:asset_groups] = site.excluded_scan_targets[:asset_groups] site.excluded_scan_targets = excluded_scan_targets site end |
.json_initializer(data) ⇒ Object
527 528 529 |
# File 'lib/nexpose/site.rb', line 527 def self.json_initializer(data) new(data[:name], data[:scan_template_id]) end |
.load(nsc, id) ⇒ Site
Load an site from the provided console.
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 |
# File 'lib/nexpose/site.rb', line 496 def self.load(nsc, id) uri = "/api/2.1/site_configurations/#{id}" resp = AJAX.get(nsc, uri, AJAX::CONTENT_TYPE::JSON) hash = JSON.parse(resp, symbolize_names: true) site = self.json_initializer(hash).deserialize(hash) # Convert each string address to either a HostName or IPRange object included_addresses = hash[:included_scan_targets][:addresses] site.included_scan_targets[:addresses] = [] included_addresses.each { |asset| site.include_asset(asset) } excluded_addresses = hash[:excluded_scan_targets][:addresses] site.excluded_scan_targets[:addresses] = [] excluded_addresses.each { |asset| site.exclude_asset(asset) } site.organization = Organization.create(site.organization) site.schedules = (hash[:schedules] || []).map {|schedule| Nexpose::Schedule.from_hash(schedule) } site.site_credentials = hash[:site_credentials].map {|cred| Nexpose::SiteCredentials.new.object_from_hash(nsc,cred)} site.shared_credentials = hash[:shared_credentials].map {|cred| Nexpose::SiteCredentials.new.object_from_hash(nsc,cred)} site.discovery_config = Nexpose::DiscoveryConnection.new.object_from_hash(nsc, hash[:discovery_config]) unless hash[:discovery_config].nil? site.search_criteria = Nexpose::DiscoveryConnection::Criteria.parseHash(hash[:search_criteria]) unless hash[:search_criteria].nil? site.alerts = Alert.load_alerts(hash[:alerts]) site. = Tag.(hash[:tags]) site.web_credentials = hash[:web_credentials].map {|webCred| ( webCred[:service] == Nexpose::WebCredentials::WebAppAuthType::HTTP_HEADER ? Nexpose::WebCredentials::Headers.new(webCred[:name], webCred[:baseURL], webCred[:soft403Pattern], webCred[:id]).object_from_hash(nsc,webCred) : Nexpose::WebCredentials::HTMLForms.new(webCred[:name], webCred[:baseURL], webCred[:loginURL], webCred[:soft403Pattern], webCred[:id]).object_from_hash(nsc,webCred))} site end |
Instance Method Details
#add_asset(asset) ⇒ Object Also known as: add_host, add_ip
Use #include_asset instead.
290 291 292 293 |
# File 'lib/nexpose/site.rb', line 290 def add_asset(asset) warn "[DEPRECATED] Use #{self.class}#include_asset instead of #{self.class}#add_asset." include_asset(asset) end |
#add_ip_range(from, to) ⇒ Object
Use #include_ip_range instead.
251 252 253 254 |
# File 'lib/nexpose/site.rb', line 251 def add_ip_range(from, to) warn "[DEPRECATED] Use #{self.class}#include_ip_range instead of #{self.class}#add_ip_range." include_ip_range(from, to) end |
#add_user(user_id) ⇒ Object
416 417 418 419 420 421 422 |
# File 'lib/nexpose/site.rb', line 416 def add_user(user_id) unless user_id.is_a?(Numeric) && user_id > 0 raise 'Invalid user id. A user id must be a positive number and refer to an existing system user.' end @users << { id: user_id} end |
#delete(connection) ⇒ Boolean
Delete this site from a Nexpose console.
577 578 579 580 |
# File 'lib/nexpose/site.rb', line 577 def delete(connection) r = connection.execute(%(<SiteDeleteRequest session-id="#{connection.session_id}" site-id="#{@id}"/>)) r.success end |
#exclude_asset(asset) ⇒ Object
Adds an asset to this site excluded scan targets, resolving whether an IP or hostname is provided.
357 358 359 |
# File 'lib/nexpose/site.rb', line 357 def exclude_asset(asset) @excluded_scan_targets[:addresses] << HostOrIP.convert(asset) end |
#exclude_asset_group(asset_group_id) ⇒ Object
Adds an asset group ID to this site excluded scan targets.
392 393 394 395 |
# File 'lib/nexpose/site.rb', line 392 def exclude_asset_group(asset_group_id) validate_asset_group(asset_group_id) @excluded_scan_targets[:asset_groups] << asset_group_id.to_i end |
#exclude_ip_range(from, to) ⇒ Object
Adds assets to this site excluded scan targets by IP address range.
320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/nexpose/site.rb', line 320 def exclude_ip_range(from, to) begin from_ip = IPAddr.new(from) to_ip = IPAddr.new(to) (from_ip..to_ip) if (from_ip..to_ip).to_a.size == 0 raise 'Invalid IP range specified' end @excluded_scan_targets[:addresses] << IPRange.new(from, to) rescue ArgumentError => e raise "#{e.} in given IP range" end end |
#excluded_addresses ⇒ Array[IPRange|HostName]
Returns the array of excluded scan target addresses.
203 204 205 |
# File 'lib/nexpose/site.rb', line 203 def excluded_addresses @excluded_scan_targets[:addresses] end |
#excluded_addresses=(new_addresses) ⇒ Array[IPRange|HostName]
Sets the array of excluded scan target addresses.
210 211 212 |
# File 'lib/nexpose/site.rb', line 210 def excluded_addresses=(new_addresses) @excluded_scan_targets[:addresses] = new_addresses end |
#excluded_asset_groups ⇒ Array[Fixnum]
Returns the array of IDs for excluded scan target asset groups.
216 217 218 |
# File 'lib/nexpose/site.rb', line 216 def excluded_asset_groups @excluded_scan_targets[:asset_groups] end |
#excluded_asset_groups=(new_asset_groups) ⇒ Array[Fixnum]
Sets the array IDs for excluded scan target asset groups.
223 224 225 |
# File 'lib/nexpose/site.rb', line 223 def excluded_asset_groups=(new_asset_groups) @excluded_scan_targets[:asset_groups] = new_asset_groups end |
#include_asset(asset) ⇒ Object
Adds an asset to this site included scan targets, resolving whether an IP or hostname is provided.
285 286 287 |
# File 'lib/nexpose/site.rb', line 285 def include_asset(asset) @included_scan_targets[:addresses] << HostOrIP.convert(asset) end |
#include_asset_group(asset_group_id) ⇒ Object
Adds an asset group ID to this site included scan targets.
374 375 376 377 |
# File 'lib/nexpose/site.rb', line 374 def include_asset_group(asset_group_id) validate_asset_group(asset_group_id) @included_scan_targets[:asset_groups] << asset_group_id.to_i end |
#include_ip_range(from, to) ⇒ Object
Adds assets to this site by IP address range.
236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/nexpose/site.rb', line 236 def include_ip_range(from, to) begin from_ip = IPAddr.new(from) to_ip = IPAddr.new(to) (from_ip..to_ip) if (from_ip..to_ip).to_a.size == 0 raise 'Invalid IP range specified' end @included_scan_targets[:addresses] << IPRange.new(from, to) rescue ArgumentError => e raise "#{e.} in given IP range" end end |
#included_addresses ⇒ Array[IPRange|HostName]
Returns the array of included scan target addresses.
177 178 179 |
# File 'lib/nexpose/site.rb', line 177 def included_addresses @included_scan_targets[:addresses] end |
#included_addresses=(new_addresses) ⇒ Array[IPRange|HostName]
Sets the array of included scan target addresses.
184 185 186 |
# File 'lib/nexpose/site.rb', line 184 def included_addresses=(new_addresses) @included_scan_targets[:addresses] = new_addresses end |
#included_asset_groups ⇒ Array[Fixnum]
Returns the array of IDs for included scan target asset groups.
190 191 192 |
# File 'lib/nexpose/site.rb', line 190 def included_asset_groups @included_scan_targets[:asset_groups] end |
#included_asset_groups=(new_asset_groups) ⇒ Array[Fixnum] Array of IDs of the updated scan target asset groups.
Sets the array of IDs for included scan target asset groups.
197 198 199 |
# File 'lib/nexpose/site.rb', line 197 def included_asset_groups=(new_asset_groups) @included_scan_targets[:asset_groups] = new_asset_groups end |
#is_dynamic? ⇒ Boolean
Returns true when the site is dynamic.
228 229 230 |
# File 'lib/nexpose/site.rb', line 228 def is_dynamic? !@discovery_config.nil? end |
#remove_asset(asset) ⇒ Object Also known as: remove_host, remove_ip
Use #remove_included_asset instead.
308 309 310 311 |
# File 'lib/nexpose/site.rb', line 308 def remove_asset(asset) warn "[DEPRECATED] Use #{self.class}#remove_included_asset instead of #{self.class}#remove_asset." remove_included_asset(asset) end |
#remove_excluded_asset(asset) ⇒ Object
Removes an asset to this site excluded scan targets, resolving whether an IP or hostname is provided.
366 367 368 |
# File 'lib/nexpose/site.rb', line 366 def remove_excluded_asset(asset) @excluded_scan_targets[:addresses].reject! { |existing_asset| existing_asset == HostOrIP.convert(asset) } end |
#remove_excluded_asset_group(asset_group_id) ⇒ Object
Adds an asset group ID to this site excluded scan targets.
401 402 403 404 |
# File 'lib/nexpose/site.rb', line 401 def remove_excluded_asset_group(asset_group_id) validate_asset_group(asset_group_id) @excluded_scan_targets[:asset_groups].reject! { |t| t.eql? asset_group_id.to_i } end |
#remove_excluded_ip_range(from, to) ⇒ Object
Remove assets from this site excluded scan targets by IP address range.
338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/nexpose/site.rb', line 338 def remove_excluded_ip_range(from, to) begin from_ip = IPAddr.new(from) to_ip = IPAddr.new(to) (from_ip..to_ip) if (from_ip..to_ip).to_a.size == 0 raise 'Invalid IP range specified' end @excluded_scan_targets[:addresses].reject! { |t| t.eql? IPRange.new(from, to) } rescue ArgumentError => e raise "#{e.} in given IP range" end end |
#remove_included_asset(asset) ⇒ Object
Remove an asset to this site included scan targets, resolving whether an IP or hostname is provided.
303 304 305 |
# File 'lib/nexpose/site.rb', line 303 def remove_included_asset(asset) @included_scan_targets[:addresses].reject! { |existing_asset| existing_asset == HostOrIP.convert(asset) } end |
#remove_included_asset_group(asset_group_id) ⇒ Object
Adds an asset group ID to this site included scan targets.
383 384 385 386 |
# File 'lib/nexpose/site.rb', line 383 def remove_included_asset_group(asset_group_id) validate_asset_group(asset_group_id) @included_scan_targets[:asset_groups].reject! { |t| t.eql? asset_group_id.to_i } end |
#remove_included_ip_range(from, to) ⇒ Object
Remove assets to this site by IP address range.
260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/nexpose/site.rb', line 260 def remove_included_ip_range(from, to) begin from_ip = IPAddr.new(from) to_ip = IPAddr.new(to) (from_ip..to_ip) if (from_ip..to_ip).to_a.size == 0 raise 'Invalid IP range specified' end @included_scan_targets[:addresses].reject! { |t| t.eql? IPRange.new(from, to) } rescue ArgumentError => e raise "#{e.} in given IP range" end end |
#remove_ip_range(from, to) ⇒ Object
Use #remove_included_ip_range instead.
275 276 277 278 |
# File 'lib/nexpose/site.rb', line 275 def remove_ip_range(from, to) warn "[DEPRECATED] Use #{self.class}#remove_included_ip_range instead of #{self.class}#remove_ip_range." remove_included_ip_range(from, to) end |
#remove_user(user_id) ⇒ Object
424 425 426 427 428 429 430 |
# File 'lib/nexpose/site.rb', line 424 def remove_user(user_id) unless user_id.is_a?(Numeric) && user_id > 0 raise 'Invalid user id. A user id must be a positive number and refer to an existing system user.' end @users.delete_if { |h| h[:id] == user_id } end |
#save(connection) ⇒ Fixnum
Saves this site to a Nexpose console. If the site is dynamic, connection and asset filter changes must be saved through the DiscoveryConnection#update_site call.
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 |
# File 'lib/nexpose/site.rb', line 553 def save(connection) new_site = @id == -1 if new_site resp = AJAX.post(connection, '/api/2.1/site_configurations/', to_json, AJAX::CONTENT_TYPE::JSON) @id = resp.to_i else resp = AJAX.put(connection, "/api/2.1/site_configurations/#{@id}", to_json, AJAX::CONTENT_TYPE::JSON) end # Retrieve the scan engine and shared credentials and add them to the site configuration site_config = Site.load(connection, @id) @engine_id = site_config.engine_id @shared_credentials = site_config.shared_credentials @alerts = site_config.alerts @id end |
#scan(connection, sync_id = nil) ⇒ Scan
Scan this site.
588 589 590 591 592 593 594 595 596 |
# File 'lib/nexpose/site.rb', line 588 def scan(connection, sync_id = nil) xml = REXML::Element.new('SiteScanRequest') xml.add_attributes({ 'session-id' => connection.session_id, 'site-id' => @id, 'sync-id' => sync_id }) response = connection.execute(xml, '1.1', timeout: 60) Scan.parse(response.res) if response.success end |
#to_h ⇒ Object
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 |
# File 'lib/nexpose/site.rb', line 456 def to_h included_scan_targets = { addresses: @included_scan_targets[:addresses].compact, asset_groups: @included_scan_targets[:asset_groups].compact } excluded_scan_targets = { addresses: @excluded_scan_targets[:addresses].compact, asset_groups: @excluded_scan_targets[:asset_groups].compact } { id: @id, name: @name, description: @description, auto_engine_selection_enabled: @auto_engine_selection_enabled, included_scan_targets: included_scan_targets, excluded_scan_targets: excluded_scan_targets, engine_id: @engine_id, scan_template_id: @scan_template_id, risk_factor: @risk_factor, schedules: (@schedules || []).map {|schedule| schedule.to_h}, shared_credentials: (@shared_credentials || []).map {|cred| cred.to_h}, site_credentials: (@site_credentials || []).map {|cred| cred.to_h}, web_credentials: (@web_credentials || []).map {|webCred| webCred.to_h}, discovery_config: @discovery_config.to_h, search_criteria: @search_criteria.to_h, tags: (@tags || []).map{|tag| tag.to_h}, alerts: (@alerts || []).map {|alert| alert.to_h }, organization: @organization.to_h, users: users } end |
#to_json ⇒ Object
452 453 454 |
# File 'lib/nexpose/site.rb', line 452 def to_json JSON.generate(to_h) end |
#validate_asset_group(asset_group_id) ⇒ Object
406 407 408 409 410 411 412 413 414 |
# File 'lib/nexpose/site.rb', line 406 def validate_asset_group(asset_group_id) begin Integer(asset_group_id) rescue ArgumentError => e raise "Invalid asset_group id. #{e.}" end raise 'Invalid asset_group id. Must be positive number.' if asset_group_id.to_i < 1 end |