nexpose 0.1.12 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/nexpose/group.rb +36 -5
  2. metadata +2 -2
data/lib/nexpose/group.rb CHANGED
@@ -59,16 +59,45 @@ module Nexpose
59
59
  # Asset group configuration object containing Device details.
60
60
  #
61
61
  class AssetGroup < AssetGroupSummary
62
+ attr_accessor :name, :description, :id
62
63
 
63
64
  # Array[Device] of devices associated with this asset group.
64
65
  attr_accessor :devices
65
66
 
66
- def initialize(id, name, desc, risk)
67
- @id, @name, @description, @risk_score = id, name, desc, risk
67
+ def initialize(name, desc, id = -1, risk = 0.0)
68
+ @name, @description, @id, @risk_score = name, desc, id, risk
68
69
  @devices = []
69
70
  end
70
71
 
71
- # Launch adhoc scans against each group of assets per site.
72
+ def save(connection)
73
+ xml = %Q(<AssetGroupSaveRequest session-id='#{connection.session_id}'>)
74
+ xml << to_xml
75
+ xml << '</AssetGroupSaveRequest>'
76
+ response = connection.execute(xml)
77
+ if response.success
78
+ @id = response.attributes['group-id'] if @id < 0
79
+ end
80
+ end
81
+
82
+ # Get an XML representation of the group that is valid for a save request.
83
+ # Note that only name, description, and device ID information is accepted
84
+ # by a save request.
85
+ #
86
+ # @return [String] XML representation of the asset group.
87
+ #
88
+ def to_xml
89
+ xml = %Q(<AssetGroup id="#{@id}" name="#{@name}")
90
+ xml << %Q( description="#{@description}") if @description
91
+ xml << '>'
92
+ xml << '<Devices>'
93
+ @devices.each do |device|
94
+ xml << %Q(<device id="#{device.id}"/>)
95
+ end
96
+ xml << '</Devices>'
97
+ xml << '</AssetGroup>'
98
+ end
99
+
100
+ # Launch ad hoc scans against each group of assets per site.
72
101
  #
73
102
  # @param [Connection] connection Connection to console where asset group is configured.
74
103
  # @return [Array[Hash[Fixnum, Fixnum]]] Array of scan ID and engine ID
@@ -96,13 +125,15 @@ module Nexpose
96
125
  parse(r.res)
97
126
  end
98
127
 
128
+ alias_method :get, :load
129
+
99
130
  def self.parse(rexml)
100
131
  return nil unless rexml
101
132
 
102
133
  rexml.elements.each('//AssetGroup') do |group|
103
- asset_group = new(group.attributes['id'].to_i,
104
- group.attributes['name'].to_s,
134
+ asset_group = new(group.attributes['name'].to_s,
105
135
  group.attributes['description'].to_s,
136
+ group.attributes['id'].to_i,
106
137
  group.attributes['riskscore'].to_f)
107
138
  rexml.elements.each('//Devices/device') do |dev|
108
139
  asset_group.devices << Device.new(dev.attributes['id'].to_i,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexpose
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-04-18 00:00:00.000000000 Z
14
+ date: 2013-04-19 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: librex