nexpose 7.0.0 → 7.0.1

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 (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +2 -3
  3. data/Gemfile.lock +1 -1
  4. data/lib/nexpose/ajax.rb +12 -16
  5. data/lib/nexpose/alert.rb +20 -21
  6. data/lib/nexpose/api.rb +3 -3
  7. data/lib/nexpose/asset.rb +23 -23
  8. data/lib/nexpose/blackout.rb +6 -14
  9. data/lib/nexpose/common.rb +87 -92
  10. data/lib/nexpose/connection.rb +8 -10
  11. data/lib/nexpose/console.rb +9 -9
  12. data/lib/nexpose/dag.rb +2 -2
  13. data/lib/nexpose/data_table.rb +8 -12
  14. data/lib/nexpose/device.rb +35 -34
  15. data/lib/nexpose/discovery.rb +69 -69
  16. data/lib/nexpose/discovery/filter.rb +7 -8
  17. data/lib/nexpose/engine.rb +22 -21
  18. data/lib/nexpose/error.rb +7 -5
  19. data/lib/nexpose/external.rb +21 -16
  20. data/lib/nexpose/filter.rb +51 -52
  21. data/lib/nexpose/global_blackout.rb +6 -7
  22. data/lib/nexpose/global_settings.rb +2 -3
  23. data/lib/nexpose/group.rb +25 -19
  24. data/lib/nexpose/json_serializer.rb +4 -14
  25. data/lib/nexpose/maint.rb +8 -9
  26. data/lib/nexpose/manage.rb +2 -2
  27. data/lib/nexpose/multi_tenant_user.rb +42 -42
  28. data/lib/nexpose/password_policy.rb +14 -14
  29. data/lib/nexpose/pool.rb +6 -5
  30. data/lib/nexpose/report.rb +30 -34
  31. data/lib/nexpose/report_template.rb +17 -18
  32. data/lib/nexpose/role.rb +64 -55
  33. data/lib/nexpose/scan.rb +77 -60
  34. data/lib/nexpose/scan_template.rb +17 -17
  35. data/lib/nexpose/scheduled_backup.rb +8 -8
  36. data/lib/nexpose/scheduled_maintenance.rb +9 -9
  37. data/lib/nexpose/shared_credential.rb +30 -33
  38. data/lib/nexpose/shared_secret.rb +5 -5
  39. data/lib/nexpose/silo.rb +68 -66
  40. data/lib/nexpose/silo_profile.rb +47 -50
  41. data/lib/nexpose/site.rb +101 -123
  42. data/lib/nexpose/site_credentials.rb +15 -17
  43. data/lib/nexpose/tag.rb +73 -80
  44. data/lib/nexpose/ticket.rb +45 -42
  45. data/lib/nexpose/user.rb +45 -45
  46. data/lib/nexpose/util.rb +1 -1
  47. data/lib/nexpose/version.rb +1 -1
  48. data/lib/nexpose/vuln.rb +45 -43
  49. data/lib/nexpose/vuln_def.rb +7 -7
  50. data/lib/nexpose/vuln_exception.rb +35 -36
  51. data/lib/nexpose/wait.rb +32 -28
  52. data/lib/nexpose/web_credentials.rb +34 -36
  53. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cca766c3f916f94c4d47c1a8455c573d2fa760e0
4
- data.tar.gz: 5a56a358b2bd3a46c7cb76424828c9005eb813eb
3
+ metadata.gz: 89a7f9d4854b3ac3826f56995370a1d38d0514be
4
+ data.tar.gz: 4b5a6783ca354eae0b694f970963c5eb44cf3de3
5
5
  SHA512:
6
- metadata.gz: dfd02ba83e4d68e6503747abb684ce1a25137075786317d3a138c5e82379ed069dccb6bb44f42f51fbcb9e827b23431bbf24f1e504c5c8ab3a2eef18e0400df2
7
- data.tar.gz: '08d3540ddf9ebc5af5205e986f5226888f26436164e7aae0c511a18765d62142c789f80c9b2c6807523cf39974c6767d7186bae828fb8d48ee7ac683779493a5'
6
+ metadata.gz: 2faafc134faf7d0cd56ddf94a1119f6093e078c46164066f54ebafe1f13763be044c2c09930bc8adb7ebb93073c32c928fe09fc9c47042939960f8766675bda7
7
+ data.tar.gz: 30683f228a157c4c5c34ea74c78b991e69cc6d0ef6749299083c9e2b4e2b92df8dbfb3d8dcc535d31d41a9403ae2b31556009697adaa2378201642a2bddc53f6
@@ -1,8 +1,7 @@
1
1
  # Change Log
2
2
 
3
- ## [Unreleased](https://github.com/rapid7/nexpose-client/tree/HEAD)
4
-
5
- [Full Changelog](https://github.com/rapid7/nexpose-client/compare/v6.1.1...HEAD)
3
+ ## [v7.0.0](https://github.com/rapid7/nexpose-client/tree/v7.0.0) (2017-08-31)
4
+ [Full Changelog](https://github.com/rapid7/nexpose-client/compare/v6.1.1...v7.0.0)
6
5
 
7
6
  **Fixed bugs:**
8
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nexpose (7.0.0)
4
+ nexpose (7.0.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -15,7 +15,7 @@ module Nexpose
15
15
  # Content type strings acceptect by Nexpose.
16
16
  #
17
17
  module CONTENT_TYPE
18
- XML = 'text/xml; charset=UTF-8'
18
+ XML = 'text/xml; charset=UTF-8'
19
19
  JSON = 'application/json; charset-utf-8'
20
20
  FORM = 'application/x-www-form-urlencoded; charset=UTF-8'
21
21
  end
@@ -192,8 +192,8 @@ module Nexpose
192
192
  # Get an error message from the response body if the request url api version
193
193
  # is 2.1 or greater otherwise use the request body
194
194
  def get_error_message(request, response)
195
- version = get_request_api_version(request)
196
- data_request = use_response_error_message?(request, response)
195
+ version = get_request_api_version(request)
196
+ data_request = use_response_error_message?(request, response)
197
197
  return_response = (version >= 2.1 || data_request)
198
198
  (return_response && response.body) ? "response body: #{response.body}" : "request body: #{request.body}"
199
199
  end
@@ -220,12 +220,10 @@ module Nexpose
220
220
  # @param [String] pref Preference key value to preserve.
221
221
  #
222
222
  def preserving_preference(nsc, pref)
223
- begin
224
- orig = get_rows(nsc, pref)
225
- yield
226
- ensure
227
- set_rows(nsc, pref, orig)
228
- end
223
+ orig = get_rows(nsc, pref)
224
+ yield
225
+ ensure
226
+ set_rows(nsc, pref, orig)
229
227
  end
230
228
 
231
229
  # Get a valid row preference value.
@@ -251,10 +249,10 @@ module Nexpose
251
249
  end
252
250
 
253
251
  def get_rows(nsc, pref)
254
- uri = '/data/user/preferences/all'
252
+ uri = '/data/user/preferences/all'
255
253
  pref_key = "#{pref}.rows"
256
- resp = get(nsc, uri)
257
- json = JSON.parse(resp)
254
+ resp = get(nsc, uri)
255
+ json = JSON.parse(resp)
258
256
  if json.key?(pref_key)
259
257
  rows = json[pref_key].to_i
260
258
  rows > 0 ? rows : 10
@@ -264,10 +262,8 @@ module Nexpose
264
262
  end
265
263
 
266
264
  def set_rows(nsc, pref, value)
267
- uri = '/data/user/preference'
268
- params = { 'name' => "#{pref}.rows",
269
- 'value' => value }
270
-
265
+ uri = '/data/user/preference'
266
+ params = { 'name' => "#{pref}.rows", 'value' => value }
271
267
  form_post(nsc, uri, params)
272
268
  end
273
269
 
@@ -76,7 +76,7 @@ module Nexpose
76
76
 
77
77
  # load a particular site alert
78
78
  def self.load(nsc, site_id, alert_id)
79
- uri = "/api/2.1/site_configurations/#{site_id}/alerts/#{alert_id}"
79
+ uri = "/api/2.1/site_configurations/#{site_id}/alerts/#{alert_id}"
80
80
  resp = AJAX.get(nsc, uri, AJAX::CONTENT_TYPE::JSON)
81
81
 
82
82
  unless resp.to_s == ''
@@ -92,7 +92,7 @@ module Nexpose
92
92
 
93
93
  # load a list of alerts for a given site
94
94
  def self.list_alerts(nsc, site_id)
95
- uri = "/api/2.1/site_configurations/#{site_id}/alerts"
95
+ uri = "/api/2.1/site_configurations/#{site_id}/alerts"
96
96
  resp = AJAX.get(nsc, uri, AJAX::CONTENT_TYPE::JSON)
97
97
  data = JSON.parse(resp, symbolize_names: true)
98
98
  load_alerts(data) unless data.nil?
@@ -120,7 +120,7 @@ module Nexpose
120
120
  def save(nsc, site_id)
121
121
  validate
122
122
  uri = "/api/2.1/site_configurations/#{site_id}/alerts"
123
- id = AJAX.put(nsc, uri, self.to_json, AJAX::CONTENT_TYPE::JSON)
123
+ id = AJAX.put(nsc, uri, self.to_json, AJAX::CONTENT_TYPE::JSON)
124
124
  @id = id.to_i
125
125
  end
126
126
 
@@ -130,12 +130,10 @@ module Nexpose
130
130
  raise ArgumentError.new('Vuln filter is a required attribute.') unless @vuln_filter
131
131
  end
132
132
 
133
- private
134
-
135
133
  def self.create(hash)
136
134
  alert_type = hash[:alert_type]
137
135
  raise 'An alert must have an alert type' if alert_type.nil?
138
- raise 'Alert name cannot be empty.' if !hash.has_key?(:name) || hash[:name].to_s == ''
136
+ raise 'Alert name cannot be empty.' if !hash.key?(:name) || hash[:name].to_s == ''
139
137
  raise 'SNMP and Syslog alerts must have a server defined' if ['SNMP', 'Syslog'].include?(alert_type) && hash[:server].to_s == ''
140
138
 
141
139
  case alert_type
@@ -174,22 +172,23 @@ module Nexpose
174
172
  attr_accessor :recipients, :sender, :verbose
175
173
 
176
174
  def initialize(name, sender, server, recipients, enabled = 1, max_alerts = -1, verbose = 0)
177
- unless recipients.is_a?(Array) && recipients.length > 0
175
+ unless recipients.is_a?(Array) && !recipients.empty?
178
176
  raise 'An SMTP alert must contain an array of recipient emails with at least 1 recipient'
179
177
  end
180
- recipients.each do |recipient|
178
+
179
+ recipients.each do |recipient|
181
180
  unless recipient =~ /^.+@.+\..+$/
182
181
  raise "Recipients must contain valid emails, #{recipient} has an invalid format"
183
182
  end
184
183
  end
185
184
 
186
185
  @alert_type = 'SMTP'
187
- @name = name
188
- @enabled = enabled
186
+ @name = name
187
+ @enabled = enabled
189
188
  @max_alerts = max_alerts
190
- @sender = sender
191
- @server = server
192
- @verbose = verbose
189
+ @sender = sender
190
+ @server = server
191
+ @verbose = verbose
193
192
  @recipients = recipients.nil? ? [] : recipients
194
193
  end
195
194
 
@@ -209,13 +208,12 @@ module Nexpose
209
208
 
210
209
  def initialize(name, community, server, enabled = 1, max_alerts = -1)
211
210
  raise 'SNMP alerts must have a community defined.' if community.nil?
212
-
213
211
  @alert_type = 'SNMP'
214
- @name = name
215
- @enabled = enabled
212
+ @name = name
213
+ @enabled = enabled
216
214
  @max_alerts = max_alerts
217
- @community = community
218
- @server = server
215
+ @community = community
216
+ @server = server
219
217
  end
220
218
  end
221
219
 
@@ -225,10 +223,11 @@ module Nexpose
225
223
 
226
224
  def initialize(name, server, enabled = 1, max_alerts = -1)
227
225
  @alert_type = 'Syslog'
228
- @name = name
229
- @enabled = enabled
226
+ @name = name
227
+ @enabled = enabled
230
228
  @max_alerts = max_alerts
231
- @server = server
229
+ @server = server
232
230
  end
233
231
  end
232
+
234
233
  end
@@ -22,7 +22,7 @@ module Nexpose
22
22
  #
23
23
  def object_from_hash(nsc, hash)
24
24
  hash.each do |k, v|
25
- next if k == :url # Do not store self-referential URL.
25
+ next if k == :url # Do not store self-referential URL.
26
26
  # Store resource URLs separately and create lazy accessors.
27
27
  if v.is_a?(Hash) && v.key?(:url)
28
28
  self.class.send(:define_method, k, proc { |conn = nsc| load_resource(conn, k, v[:url].gsub(/.*\/api/, '/api')) })
@@ -52,7 +52,7 @@ module Nexpose
52
52
  # @return [Array[?]] Collection of "k" marshalled object.
53
53
  #
54
54
  def load_resource(nsc, k, url)
55
- obj = class_from_string(k)
55
+ obj = class_from_string(k)
56
56
  resp = AJAX.get(nsc, url, AJAX::CONTENT_TYPE::JSON)
57
57
  hash = JSON.parse(resp, symbolize_names: true)
58
58
  if hash.is_a?(Array)
@@ -85,7 +85,6 @@ module Nexpose
85
85
 
86
86
  module TypedAccessor
87
87
  def typed_accessor(name, type)
88
-
89
88
  # here we dynamically define accessor methods
90
89
  define_method(name) do
91
90
  instance_variable_get("@#{name}")
@@ -100,4 +99,5 @@ module Nexpose
100
99
  end
101
100
  end
102
101
  end
102
+
103
103
  end
@@ -42,7 +42,7 @@ module Nexpose
42
42
  attr_accessor :unique_identifiers
43
43
 
44
44
  def initialize
45
- @addresses = []
45
+ @addresses = []
46
46
  @host_names = []
47
47
  end
48
48
 
@@ -53,7 +53,7 @@ module Nexpose
53
53
  # @return [Asset] The requested asset, if found.
54
54
  #
55
55
  def self.load(nsc, id)
56
- uri = "/api/2.1/assets/#{id}"
56
+ uri = "/api/2.1/assets/#{id}"
57
57
  resp = AJAX.get(nsc, uri, AJAX::CONTENT_TYPE::JSON)
58
58
  hash = JSON.parse(resp, symbolize_names: true)
59
59
  new.object_from_hash(nsc, hash)
@@ -97,9 +97,9 @@ module Nexpose
97
97
 
98
98
  def <=>(other)
99
99
  c = port <=> other.port
100
- return c unless c == 0
100
+ return c unless c.zero?
101
101
  c = protocol <=> other.protocol
102
- return c unless c == 0
102
+ return c unless c.zero?
103
103
  name <=> other.name
104
104
  end
105
105
 
@@ -114,27 +114,27 @@ module Nexpose
114
114
  # Valid protocol values for a service endpoint.
115
115
  module Protocol
116
116
  # Internet Protocol
117
- IP = 'IP'
117
+ IP = 'IP'
118
118
  # Internet Control Message Protocol
119
119
  ICMP = 'ICMP'
120
120
  # Internet Group Management Protocol
121
121
  IGMP = 'IGMP'
122
122
  # Gateway-to-Gateway Protocol
123
- GGP = 'GGP'
123
+ GGP = 'GGP'
124
124
  # Transmission Control Protocol
125
- TCP = 'TCP'
125
+ TCP = 'TCP'
126
126
  # PARC Universal Protocol
127
- PUP = 'PUP'
127
+ PUP = 'PUP'
128
128
  # User Datagram Protocol
129
- UDP = 'UDP'
129
+ UDP = 'UDP'
130
130
  # Internet Datagram Protocol
131
- IDP = 'IDP'
131
+ IDP = 'IDP'
132
132
  # Encapsulating Security Payload
133
- ESP = 'ESP'
133
+ ESP = 'ESP'
134
134
  # Network Disk Protocol
135
- ND = 'ND'
135
+ ND = 'ND'
136
136
  # Raw Packet (or unknown)
137
- RAW = 'RAW'
137
+ RAW = 'RAW'
138
138
  end
139
139
  end
140
140
 
@@ -163,11 +163,11 @@ module Nexpose
163
163
 
164
164
  def <=>(other)
165
165
  c = name <=> other.name
166
- return c unless c == 0
166
+ return c unless c.zero?
167
167
  c = id <=> other.id
168
- return c unless c == 0
168
+ return c unless c.zero?
169
169
  c = full_name <=> other.full_name
170
- return c unless c == 0
170
+ return c unless c.zero?
171
171
  attributes <=> other.attributes
172
172
  end
173
173
 
@@ -204,9 +204,9 @@ module Nexpose
204
204
 
205
205
  def <=>(other)
206
206
  c = name <=> other.name
207
- return c unless c == 0
207
+ return c unless c.zero?
208
208
  c = id <=> other.id
209
- return c unless c == 0
209
+ return c unless c.zero?
210
210
  attributes <=> other.attributes
211
211
  end
212
212
 
@@ -248,11 +248,11 @@ module Nexpose
248
248
 
249
249
  def <=>(other)
250
250
  c = name <=> other.name
251
- return c unless c == 0
251
+ return c unless c.zero?
252
252
  c = size <=> other.size
253
- return c unless c == 0
253
+ return c unless c.zero?
254
254
  c = directory <=> other.directory
255
- return c unless c == 0
255
+ return c unless c.zero?
256
256
  attributes <=> other.attributes
257
257
  end
258
258
 
@@ -274,7 +274,7 @@ module Nexpose
274
274
  attr_reader :id
275
275
 
276
276
  def initialize(source = nil, id = nil)
277
- @id = id
277
+ @id = id
278
278
  @source = source
279
279
  end
280
280
 
@@ -285,7 +285,7 @@ module Nexpose
285
285
 
286
286
  def <=>(other)
287
287
  c = source <=> other.source
288
- return c unless c == 0
288
+ return c unless c.zero?
289
289
  id <=> other.id
290
290
  end
291
291
 
@@ -1,6 +1,6 @@
1
1
  module Nexpose
2
- # Constants useful across the Nexpose module.
3
- # Configuration structure for blackouts.
2
+ # Constants useful across the Nexpose module.
3
+ # Configuration structure for blackouts.
4
4
  class Blackout < APIObject
5
5
  # Whether or not this blackout is enabled.
6
6
  attr_accessor :enabled
@@ -14,7 +14,7 @@ module Nexpose
14
14
  # The amount of time, in minutes, a blackout period should last.
15
15
  attr_accessor :blackout_duration
16
16
 
17
- def initialize(start, enabled=true, duration, type, interval)
17
+ def initialize(start, enabled = true, duration, type, interval)
18
18
  @blackout_start = start
19
19
  @enabled = enabled
20
20
  @blackout_duration = duration.to_i
@@ -24,7 +24,6 @@ module Nexpose
24
24
 
25
25
  def self.from_hash(hash)
26
26
  repeat_blackout_hash = hash[:repeat_blackout]
27
-
28
27
  if repeat_blackout_hash.nil?
29
28
  type = 'daily'
30
29
  interval = 0
@@ -32,22 +31,15 @@ module Nexpose
32
31
  type = repeat_blackout_hash[:type]
33
32
  interval = repeat_blackout_hash[:interval]
34
33
  end
35
-
36
34
  new(hash[:start_date], hash[:enabled], hash[:blackout_duration], type, interval)
37
35
  end
38
36
 
39
37
  def to_h
40
- blackout_hash = {
41
- start_date: @blackout_start,
42
- enabled: @enabled,
43
- blackout_duration: @blackout_duration,
44
- }
45
- repeat_hash= {
46
- type: @blackout_type,
47
- interval: @blackout_interval
48
- }
38
+ blackout_hash = { start_date: @blackout_start, enabled: @enabled, blackout_duration: @blackout_duration }
39
+ repeat_hash = { type: @blackout_type, interval: @blackout_interval }
49
40
  blackout_hash[:repeat_blackout] = repeat_hash
50
41
  blackout_hash
51
42
  end
52
43
  end
44
+
53
45
  end
@@ -2,7 +2,7 @@ module Nexpose
2
2
  # Constants useful across the Nexpose module.
3
3
  module Scope
4
4
  GLOBAL = 'global'
5
- SILO = 'silo'
5
+ SILO = 'silo'
6
6
  end
7
7
 
8
8
  # Configuration structure for e-mail notification.
@@ -49,11 +49,10 @@ module Nexpose
49
49
 
50
50
  def initialize(to_all_authorized, send_to_owner_as, send_to_acl_as, send_as)
51
51
  @to_all_authorized = to_all_authorized
52
- @send_to_owner_as = send_to_owner_as
53
- @send_to_acl_as = send_to_acl_as
54
- @send_as = send_as
55
-
56
- @recipients = []
52
+ @send_to_owner_as = send_to_owner_as
53
+ @send_to_acl_as = send_to_acl_as
54
+ @send_as = send_as
55
+ @recipients = []
57
56
  end
58
57
 
59
58
  def to_xml
@@ -116,9 +115,9 @@ module Nexpose
116
115
 
117
116
  def as_xml
118
117
  xml = REXML::Element.new('AdHocSchedule')
119
- xml.attributes['start'] = @start
118
+ xml.attributes['start'] = @start
120
119
  xml.attributes['maxDuration'] = @max_duration if @max_duration
121
- xml.attributes['template'] = @scan_template_id
120
+ xml.attributes['template'] = @scan_template_id
122
121
  xml
123
122
  end
124
123
 
@@ -170,10 +169,10 @@ module Nexpose
170
169
 
171
170
  # @param [Time] start
172
171
  def initialize(type, interval, start, enabled = true, scan_template_id = nil)
173
- @type = type
174
- @interval = interval
175
- @start = start
176
- @enabled = enabled
172
+ @type = type
173
+ @interval = interval
174
+ @start = start
175
+ @enabled = enabled
177
176
  @scan_template_id = scan_template_id
178
177
  end
179
178
 
@@ -186,29 +185,28 @@ module Nexpose
186
185
  else
187
186
  schedule = new(repeat_scan_hash[:type], repeat_scan_hash[:interval], start)
188
187
  end
189
- schedule.enabled = hash[:enabled].nil? ? true : hash[:enabled]
188
+ schedule.enabled = hash[:enabled].nil? ? true : hash[:enabled]
190
189
  schedule.scan_template_id = hash[:scan_template_id]
191
- schedule.start = Nexpose::ISO8601.to_time(hash[:start_date]) if hash[:start_date]
192
- schedule.max_duration = hash[:maximum_scan_duration] if hash[:maximum_scan_duration]
193
- schedule.not_valid_after = Nexpose::ISO8601.to_time(hash[:not_valid_after_date]) if hash[:not_valid_after_date]
194
- schedule.timezone = hash[:time_zone] if hash[:time_zone]
195
- schedule.next_run_time = hash[:next_run_time] if hash[:next_run_time]
196
- schedule.console_start = Nexpose::ISO8601.to_time(hash[:console_start_date]) if hash[:console_start_date]
190
+ schedule.start = Nexpose::ISO8601.to_time(hash[:start_date]) if hash[:start_date]
191
+ schedule.max_duration = hash[:maximum_scan_duration] if hash[:maximum_scan_duration]
192
+ schedule.not_valid_after = Nexpose::ISO8601.to_time(hash[:not_valid_after_date]) if hash[:not_valid_after_date]
193
+ schedule.timezone = hash[:time_zone] if hash[:time_zone]
194
+ schedule.next_run_time = hash[:next_run_time] if hash[:next_run_time]
195
+ schedule.console_start = Nexpose::ISO8601.to_time(hash[:console_start_date]) if hash[:console_start_date]
197
196
  schedule.console_timezone = hash[:console_time_zone] if hash[:console_time_zone]
198
197
 
199
198
  unless repeat_scan_hash.nil?
200
- schedule.type = repeat_scan_hash[:type]
201
- schedule.interval = repeat_scan_hash[:interval]
199
+ schedule.type = repeat_scan_hash[:type]
200
+ schedule.interval = repeat_scan_hash[:interval]
202
201
  schedule.repeater_type = 'restart' if repeat_scan_hash[:on_repeat] == 'restart-scan'
203
202
  schedule.repeater_type = 'continue' if repeat_scan_hash[:on_repeat] == 'resume-scan'
204
-
205
- schedule.is_extended = repeat_scan_hash[:is_extended] if repeat_scan_hash[:is_extended]
206
- schedule.hour = repeat_scan_hash[:hour] if repeat_scan_hash[:hour]
207
- schedule.minute = repeat_scan_hash[:minute] if repeat_scan_hash[:minute]
208
- schedule.date = repeat_scan_hash[:date] if repeat_scan_hash[:date]
209
- schedule.day = repeat_scan_hash[:day] if repeat_scan_hash[:day]
210
- schedule.occurrence = repeat_scan_hash[:occurrence] if repeat_scan_hash[:occurrence]
211
- schedule.start_month = repeat_scan_hash[:start_month] if repeat_scan_hash[:start_month]
203
+ schedule.is_extended = repeat_scan_hash[:is_extended] if repeat_scan_hash[:is_extended]
204
+ schedule.hour = repeat_scan_hash[:hour] if repeat_scan_hash[:hour]
205
+ schedule.minute = repeat_scan_hash[:minute] if repeat_scan_hash[:minute]
206
+ schedule.date = repeat_scan_hash[:date] if repeat_scan_hash[:date]
207
+ schedule.day = repeat_scan_hash[:day] if repeat_scan_hash[:day]
208
+ schedule.occurrence = repeat_scan_hash[:occurrence] if repeat_scan_hash[:occurrence]
209
+ schedule.start_month = repeat_scan_hash[:start_month] if repeat_scan_hash[:start_month]
212
210
  end
213
211
 
214
212
  schedule
@@ -220,28 +218,26 @@ module Nexpose
220
218
  scan_template_id: @scan_template_id,
221
219
  maximum_scan_duration: @max_duration
222
220
  }
223
- schedule_hash[:start_date] = Nexpose::ISO8601.to_string(@start) if @start
221
+ schedule_hash[:start_date] = Nexpose::ISO8601.to_string(@start) if @start
224
222
  schedule_hash[:not_valid_after_date] = Nexpose::ISO8601.to_string(@not_valid_after) if @not_valid_after
225
- schedule_hash[:time_zone] = @timezone if @timezone
223
+ schedule_hash[:time_zone] = @timezone if @timezone
226
224
 
227
- unless (@type.nil? || @interval == 0) && !@is_extended
225
+ unless (@type.nil? || @interval.to_i.zero?) && !@is_extended
228
226
  repeat_scan_hash = {
229
227
  type: @type,
230
228
  interval: @interval
231
229
  }
232
230
  repeat_scan_hash[:on_repeat] = 'restart-scan' if @repeater_type == 'restart'
233
231
  repeat_scan_hash[:on_repeat] = 'resume-scan' if @repeater_type == 'continue'
234
-
235
232
  if @is_extended
236
233
  repeat_scan_hash[:is_extended] = @is_extended
237
- repeat_scan_hash[:hour] = @hour if @hour
238
- repeat_scan_hash[:minute] = @minute if @minute
239
- repeat_scan_hash[:date] = @date if @date
240
- repeat_scan_hash[:day] = @day if @day
241
- repeat_scan_hash[:occurrence] = @occurrence if @occurrence
234
+ repeat_scan_hash[:hour] = @hour if @hour
235
+ repeat_scan_hash[:minute] = @minute if @minute
236
+ repeat_scan_hash[:date] = @date if @date
237
+ repeat_scan_hash[:day] = @day if @day
238
+ repeat_scan_hash[:occurrence] = @occurrence if @occurrence
242
239
  repeat_scan_hash[:start_month] = @start_month if @start_month
243
240
  end
244
-
245
241
  schedule_hash[:repeat_scan] = repeat_scan_hash
246
242
  end
247
243
 
@@ -250,22 +246,22 @@ module Nexpose
250
246
 
251
247
  def as_xml
252
248
  xml = REXML::Element.new('Schedule')
253
- xml.attributes['enabled'] = @enabled ? 1 : 0
254
- xml.attributes['type'] = @type
255
- xml.attributes['interval'] = @interval
256
- xml.attributes['start'] = @start if @start
257
- xml.attributes['maxDuration'] = @max_duration if @max_duration
249
+ xml.attributes['enabled'] = @enabled ? 1 : 0
250
+ xml.attributes['type'] = @type
251
+ xml.attributes['interval'] = @interval
252
+ xml.attributes['start'] = @start if @start
253
+ xml.attributes['maxDuration'] = @max_duration if @max_duration
258
254
  xml.attributes['notValidAfter'] = @not_valid_after if @not_valid_after
259
- xml.attributes['repeaterType'] = @repeater_type if @repeater_type
260
- xml.attributes['is_extended'] = @is_extended if @is_extended
261
- xml.attributes['hour'] = @hour if @hour
262
- xml.attributes['minute'] = @minute if @minute
263
- xml.attributes['date'] = @date if @date
264
- xml.attributes['day'] = @day if @day
265
- xml.attributes['occurrence'] = @occurrence if @occurrence
266
- xml.attributes['start_month'] = @start_month if @start_month
267
- xml.attributes['timezone'] = @timezone if @timezone
268
- xml.attributes['template'] = @scan_template_id if @scan_template_id
255
+ xml.attributes['repeaterType'] = @repeater_type if @repeater_type
256
+ xml.attributes['is_extended'] = @is_extended if @is_extended
257
+ xml.attributes['hour'] = @hour if @hour
258
+ xml.attributes['minute'] = @minute if @minute
259
+ xml.attributes['date'] = @date if @date
260
+ xml.attributes['day'] = @day if @day
261
+ xml.attributes['occurrence'] = @occurrence if @occurrence
262
+ xml.attributes['start_month'] = @start_month if @start_month
263
+ xml.attributes['timezone'] = @timezone if @timezone
264
+ xml.attributes['template'] = @scan_template_id if @scan_template_id
269
265
  xml
270
266
  end
271
267
 
@@ -280,18 +276,18 @@ module Nexpose
280
276
  xml.attributes['enabled'] != '0')
281
277
 
282
278
  # Optional parameters.
283
- schedule.max_duration = xml.attributes['maxDuration'].to_i if xml.attributes['maxDuration']
284
- schedule.not_valid_after = xml.attributes['notValidAfter'] if xml.attributes['notValidAfter']
285
- schedule.repeater_type = xml.attributes['repeaterType'] if xml.attributes['repeaterType']
286
- schedule.is_extended = xml.attributes['is_extended'] if xml.attributes['is_extended']
287
- schedule.hour = xml.attributes['hour'] if xml.attributes['hour']
288
- schedule.minute = xml.attributes['minute'] if xml.attributes['minute']
289
- schedule.date = xml.attributes['date'] if xml.attributes['date']
290
- schedule.day = xml.attributes['day'] if xml.attributes['day']
291
- schedule.occurrence = xml.attributes['occurrence'] if xml.attributes['occurrence']
292
- schedule.start_month = xml.attributes['start_month'] if xml.attributes['start_month']
293
- schedule.timezone = xml.attributes['timezone'] if xml.attributes['timezone']
294
- schedule.next_run_time = xml.attributes['next_run_time'] if xml.attributes['next_run_time']
279
+ schedule.max_duration = xml.attributes['maxDuration'].to_i if xml.attributes['maxDuration']
280
+ schedule.not_valid_after = xml.attributes['notValidAfter'] if xml.attributes['notValidAfter']
281
+ schedule.repeater_type = xml.attributes['repeaterType'] if xml.attributes['repeaterType']
282
+ schedule.is_extended = xml.attributes['is_extended'] if xml.attributes['is_extended']
283
+ schedule.hour = xml.attributes['hour'] if xml.attributes['hour']
284
+ schedule.minute = xml.attributes['minute'] if xml.attributes['minute']
285
+ schedule.date = xml.attributes['date'] if xml.attributes['date']
286
+ schedule.day = xml.attributes['day'] if xml.attributes['day']
287
+ schedule.occurrence = xml.attributes['occurrence'] if xml.attributes['occurrence']
288
+ schedule.start_month = xml.attributes['start_month'] if xml.attributes['start_month']
289
+ schedule.timezone = xml.attributes['timezone'] if xml.attributes['timezone']
290
+ schedule.next_run_time = xml.attributes['next_run_time'] if xml.attributes['next_run_time']
295
291
  schedule.scan_template_id = xml.attributes['template'] if xml.attributes['template']
296
292
  schedule
297
293
  end
@@ -300,11 +296,11 @@ module Nexpose
300
296
  # may be used to create a Schedule.
301
297
  #
302
298
  module Type
303
- DAILY = 'daily'
304
- HOURLY = 'hourly'
305
- WEEKLY = 'weekly'
299
+ DAILY = 'daily'
300
+ HOURLY = 'hourly'
301
+ WEEKLY = 'weekly'
306
302
  MONTHLY_DATE = 'monthly-date'
307
- MONTHLY_DAY = 'monthly-day'
303
+ MONTHLY_DAY = 'monthly-day'
308
304
  end
309
305
  end
310
306
 
@@ -337,40 +333,39 @@ module Nexpose
337
333
  state: state,
338
334
  city: city,
339
335
  zip: zip,
340
- country: country
341
- }
336
+ country: country }
342
337
  end
343
338
 
344
339
  # Create organization object from hash
345
340
  def self.create(hash)
346
341
  new do |org|
347
- org.name = hash[:name]
348
- org.url = hash[:url]
342
+ org.name = hash[:name]
343
+ org.url = hash[:url]
349
344
  org.primary_contact = hash[:primary_contact]
350
- org.job_title = hash[:job_title]
351
- org.email = hash[:email]
352
- org.telephone = hash[:telephone]
353
- org.address = hash[:address]
354
- org.state = hash[:state]
355
- org.city = hash[:city]
356
- org.zip = hash[:zip]
357
- org.country = hash[:country]
345
+ org.job_title = hash[:job_title]
346
+ org.email = hash[:email]
347
+ org.telephone = hash[:telephone]
348
+ org.address = hash[:address]
349
+ org.state = hash[:state]
350
+ org.city = hash[:city]
351
+ org.zip = hash[:zip]
352
+ org.country = hash[:country]
358
353
  end
359
354
  end
360
355
 
361
356
  def self.parse(xml)
362
357
  new do |org|
363
- org.name = xml.attributes['name']
364
- org.url = xml.attributes['url']
358
+ org.name = xml.attributes['name']
359
+ org.url = xml.attributes['url']
365
360
  org.primary_contact = xml.attributes['primaryContact']
366
- org.job_title = xml.attributes['jobTitle']
367
- org.email = xml.attributes['email']
368
- org.telephone = xml.attributes['telephone']
369
- org.address = xml.attributes['businessAddress']
370
- org.state = xml.attributes['state']
371
- org.city = xml.attributes['city']
372
- org.zip = xml.attributes['zip']
373
- org.country = xml.attributes['country']
361
+ org.job_title = xml.attributes['jobTitle']
362
+ org.email = xml.attributes['email']
363
+ org.telephone = xml.attributes['telephone']
364
+ org.address = xml.attributes['businessAddress']
365
+ org.state = xml.attributes['state']
366
+ org.city = xml.attributes['city']
367
+ org.zip = xml.attributes['zip']
368
+ org.country = xml.attributes['country']
374
369
  end
375
370
  end
376
371