nexpose 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nexpose.rb +1 -0
- data/lib/nexpose/backup.rb +109 -0
- data/lib/nexpose/report.rb +8 -6
- data/lib/nexpose/site.rb +15 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 375665364ba49ff95d55ef5cf904955697a1ba5d
|
4
|
+
data.tar.gz: 863da9f7656341a934e154e5f576a6225afc3df4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 882e9bec98184b52d96c897c84cf36d226ed638125d8faa66ef1e7aa2ad8994792977b03ce799b312971c6ff677fa4cfbc5db7b511af5d502e04fb333a3d095e
|
7
|
+
data.tar.gz: 4b6460e699d3723cb50bc86f81aa0a7ddf6a1de1a9e7a3e2fc0dd1f28b761794e25f80eb063aef83b46c16eee19d6b03e2b4c4ea579078c8ed562175de02fb73
|
data/lib/nexpose.rb
CHANGED
@@ -0,0 +1,109 @@
|
|
1
|
+
module Nexpose
|
2
|
+
|
3
|
+
module NexposeAPI
|
4
|
+
|
5
|
+
# Retrieve a list of all backups currently stored on the Console.
|
6
|
+
#
|
7
|
+
# @return [Array[Backup]] List of backups.
|
8
|
+
#
|
9
|
+
def list_backups
|
10
|
+
data = DataTable._get_dyn_table(self, '/admin/global/ajax/backup_listing.txml')
|
11
|
+
data.map { |b| Backup.parse(b) }
|
12
|
+
end
|
13
|
+
|
14
|
+
# Create a backup of this security console's data.
|
15
|
+
# A restart will be initiated in order to put the product into maintenance
|
16
|
+
# mode while the backup is made. It will then restart automatically.
|
17
|
+
#
|
18
|
+
# @param [Boolean] platform_independent Whether to make a platform
|
19
|
+
# independent backup.
|
20
|
+
# @param [String] description A note about this backup which will be
|
21
|
+
# visible through the web interface.
|
22
|
+
# @return [Boolean] Whether a backup is successfully initiated.
|
23
|
+
#
|
24
|
+
def backup(platform_independent = false, description = nil)
|
25
|
+
parameters = { 'backup_desc' => description,
|
26
|
+
'cmd' => 'backup',
|
27
|
+
'platform_independent' => platform_independent,
|
28
|
+
'targetTask' => 'backupRestore' }
|
29
|
+
xml = AJAX.form_post(self, '/admin/global/maintenance/maintCmd.txml', parameters)
|
30
|
+
if !!(xml =~ /succeded="true"/)
|
31
|
+
_maintenance_restart
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def _maintenance_restart
|
36
|
+
parameters = { 'cancelAllTasks' => false,
|
37
|
+
'cmd' => 'restartServer',
|
38
|
+
'targetTask' => 'maintModeHandler' }
|
39
|
+
xml = AJAX.form_post(self, '/admin/global/maintenance/maintCmd.txml', parameters)
|
40
|
+
!!(xml =~ /succeded="true"/)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Details about an existing backup on the security console.
|
45
|
+
#
|
46
|
+
class Backup
|
47
|
+
|
48
|
+
# Filename
|
49
|
+
attr_reader :name
|
50
|
+
# Date the backup was made.
|
51
|
+
attr_reader :date
|
52
|
+
# Description of the backup.
|
53
|
+
attr_reader :description
|
54
|
+
# Nexpose version the console was on when the backup was made.
|
55
|
+
attr_reader :version
|
56
|
+
# Whether the backup is platform-idependent or not.
|
57
|
+
attr_reader :platform_independent
|
58
|
+
# Size of backup file on disk, in Bytes. Can be used to estimate the amount
|
59
|
+
# of time the backup may take to load.
|
60
|
+
attr_reader :size
|
61
|
+
|
62
|
+
def initialize(name, date, description, version, independent, size)
|
63
|
+
@name = name
|
64
|
+
@date = date
|
65
|
+
@description = description
|
66
|
+
@version = version
|
67
|
+
@platform_independent = independent
|
68
|
+
@size = size
|
69
|
+
end
|
70
|
+
|
71
|
+
# Restore this backup to the Nexpose console.
|
72
|
+
# It will restart the console after acknowledging receiving the request.
|
73
|
+
#
|
74
|
+
# @param [Connection] nsc An active connection to a Nexpose console.
|
75
|
+
# @return [Boolean] Whether the request was received.
|
76
|
+
#
|
77
|
+
def restore(nsc)
|
78
|
+
parameters = { 'backupid' => @name,
|
79
|
+
'cmd' => 'restore',
|
80
|
+
'targetTask' => 'backupRestore' }
|
81
|
+
xml = AJAX.form_post(nsc, '/admin/global/maintenance/maintCmd.txml', parameters)
|
82
|
+
if !!(xml =~ /succeded="true"/)
|
83
|
+
nsc._maintenance_restart
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Remove this backup file from the security console.
|
88
|
+
#
|
89
|
+
# @param [Connection] nsc An active connection to a Nexpose console.
|
90
|
+
# @return [Boolean] If the backup was removed.
|
91
|
+
#
|
92
|
+
def delete(nsc)
|
93
|
+
parameters = { 'backupid' => @name,
|
94
|
+
'cmd' => 'deleteBackup',
|
95
|
+
'targetTask' => 'backupRestore' }
|
96
|
+
xml = AJAX.form_post(nsc, '/admin/global/maintenance/maintCmd.txml', parameters)
|
97
|
+
!!(xml =~ /succeded="true"/)
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.parse(hash)
|
101
|
+
new(hash['Download'],
|
102
|
+
Time.at(hash['Date'].to_i / 1000),
|
103
|
+
hash['Description'],
|
104
|
+
hash['Version'],
|
105
|
+
hash['Platform-Independent'],
|
106
|
+
hash['Size'])
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
data/lib/nexpose/report.rb
CHANGED
@@ -102,7 +102,7 @@ module Nexpose
|
|
102
102
|
attr_reader :scope
|
103
103
|
|
104
104
|
def initialize(config_id, template_id, status, generated_on, uri, scope)
|
105
|
-
@config_id = config_id
|
105
|
+
@config_id = config_id.to_i
|
106
106
|
@template_id = template_id
|
107
107
|
@status = status
|
108
108
|
@generated_on = generated_on
|
@@ -111,7 +111,7 @@ module Nexpose
|
|
111
111
|
end
|
112
112
|
|
113
113
|
def self.parse(xml)
|
114
|
-
ReportConfigSummary.new(xml.attributes['cfg-id'],
|
114
|
+
ReportConfigSummary.new(xml.attributes['cfg-id'].to_i,
|
115
115
|
xml.attributes['template-id'],
|
116
116
|
xml.attributes['status'],
|
117
117
|
xml.attributes['generated-on'],
|
@@ -138,7 +138,7 @@ module Nexpose
|
|
138
138
|
|
139
139
|
def initialize(id, config_id, status, generated_on, uri)
|
140
140
|
@id = id
|
141
|
-
@config_id = config_id
|
141
|
+
@config_id = config_id.to_i
|
142
142
|
@status = status
|
143
143
|
@generated_on = generated_on
|
144
144
|
@uri = uri
|
@@ -339,8 +339,10 @@ module Nexpose
|
|
339
339
|
connection.delete_report_config(@id)
|
340
340
|
end
|
341
341
|
|
342
|
+
include Sanitize
|
343
|
+
|
342
344
|
def to_xml
|
343
|
-
xml = %(<ReportConfig format='#{@format}' id='#{@id}' name='#{@name}' template-id='#{@template_id}')
|
345
|
+
xml = %(<ReportConfig format='#{@format}' id='#{@id}' name='#{replace_entities(@name)}' template-id='#{@template_id}')
|
344
346
|
xml << %( owner='#{@owner}') if @owner
|
345
347
|
xml << %( timezone='#{@time_zone}') if @time_zone
|
346
348
|
xml << %( language='#{@language}') if @language
|
@@ -368,8 +370,8 @@ module Nexpose
|
|
368
370
|
config = ReportConfig.new(cfg.attributes['name'],
|
369
371
|
cfg.attributes['template-id'],
|
370
372
|
cfg.attributes['format'],
|
371
|
-
cfg.attributes['id'],
|
372
|
-
cfg.attributes['owner'],
|
373
|
+
cfg.attributes['id'].to_i,
|
374
|
+
cfg.attributes['owner'].to_i,
|
373
375
|
cfg.attributes['timezone'])
|
374
376
|
|
375
377
|
cfg.elements.each('//description') do |desc|
|
data/lib/nexpose/site.rb
CHANGED
@@ -423,9 +423,22 @@ module Nexpose
|
|
423
423
|
@to = to unless from == to
|
424
424
|
end
|
425
425
|
|
426
|
+
# Size of the IP range. The total number of IP addresses represented
|
427
|
+
# by this range.
|
428
|
+
#
|
429
|
+
# @return [Fixnum] size of the range.
|
430
|
+
#
|
431
|
+
def size
|
432
|
+
return 1 if @to.nil?
|
433
|
+
from = IPAddr.new(@from)
|
434
|
+
to = IPAddr.new(@to)
|
435
|
+
(from..to).to_a.size
|
436
|
+
end
|
437
|
+
|
426
438
|
include Comparable
|
427
439
|
|
428
440
|
def <=>(other)
|
441
|
+
return 1 unless other.respond_to? :from
|
429
442
|
from = IPAddr.new(@from)
|
430
443
|
to = @to.nil? ? from : IPAddr.new(@to)
|
431
444
|
cf_from = IPAddr.new(other.from)
|
@@ -444,10 +457,12 @@ module Nexpose
|
|
444
457
|
end
|
445
458
|
|
446
459
|
def eql?(other)
|
460
|
+
return false unless other.respond_to? :from
|
447
461
|
@from == other.from && @to == other.to
|
448
462
|
end
|
449
463
|
|
450
464
|
def include?(single_ip)
|
465
|
+
return false unless single_ip.respond_to? :from
|
451
466
|
from = IPAddr.new(@from)
|
452
467
|
to = @to.nil? ? from : IPAddr.new(@to)
|
453
468
|
other = IPAddr.new(single_ip)
|
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.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HD Moore
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-09-
|
13
|
+
date: 2013-09-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: librex
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- Rakefile
|
56
56
|
- lib/nexpose.rb
|
57
57
|
- lib/nexpose/pool.rb
|
58
|
+
- lib/nexpose/backup.rb
|
58
59
|
- lib/nexpose/group.rb
|
59
60
|
- lib/nexpose/device.rb
|
60
61
|
- lib/nexpose/report_template.rb
|