openvas-cli 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.7
1
+ 0.2.8
@@ -16,15 +16,15 @@ module OpenvasCli
16
16
  # reports.
17
17
  # === Options:
18
18
  # [:report_id => [report_id]] Pulls a specific +report_id+. If the id provided is bogus, an empty set is returned.
19
- # [:filter => [array_of_filter_symbols]] Filters the report results by severity. Valid symbols are: [:high, :medium, :low, :log, :deubg].
19
+ # [:levels => [array_of_filter_symbols]] Filters the report results by severity. Valid symbols are: [:high, :medium, :low, :log, :deubg].
20
20
  # [:sort => [sort_field]] Sorts the report by the given field. Possible values are +:task_name+, +:started_at+. defaults to +:started_at+
21
21
  # [:sort_order => [:ascending, :descending]] Order of sort. Defaults to :descending.
22
22
  def self.get_all(options={})
23
23
  params = {}
24
24
  params[:report_id] = options[:id] if options[:id]
25
- if options[:filter]
25
+ if options[:levels]
26
26
  params[:levels] = ""
27
- options[:filter].each { |f|
27
+ options[:levels].each { |f|
28
28
  case f
29
29
  when :high
30
30
  params[:levels] += 'h'
@@ -9,13 +9,15 @@ module OpenvasCli
9
9
  validates :id, :presence=>true, :UUID=>true
10
10
 
11
11
  def self.get_by_id(id)
12
- nil
12
+ get_all(:id => id)[0]
13
13
  end
14
14
 
15
15
  def self.get_all(options = {})
16
16
  options[:sort_by] ||= :threat
17
17
 
18
18
  params = {:overrides => 0, :notes => 0}
19
+
20
+ params[:result_id] = options[:id] if options[:id]
19
21
  if options[:task_id]
20
22
  params[:task_id] = options[:task_id]
21
23
  params[:apply_overrides] = 1 if options[:apply_overrides]
@@ -41,17 +43,21 @@ module OpenvasCli
41
43
  req = Nokogiri::XML::Builder.new { |xml|
42
44
  xml.get_results(params)
43
45
  }
44
- xml = connection.send_receive(req.doc)
45
46
 
46
47
  results = {}
47
- xml.xpath("//result").each { |xr|
48
- id = extract_value_from("@id", xr)
49
- threat = extract_value_from("threat", xr)
50
- if (levels.empty? || levels.include?(threat)) && results.has_key?(id) == false
51
- res = parse_result_node(xr, options[:task_id])
52
- results[res.result_id] = res
53
- end
54
- }
48
+
49
+ begin
50
+ xml = connection.send_receive(req.doc)
51
+ xml.xpath("//result").each { |xr|
52
+ id = extract_value_from("@id", xr)
53
+ threat = extract_value_from("threat", xr)
54
+ if (levels.empty? || levels.include?(threat)) && results.has_key?(id) == false
55
+ res = parse_result_node(xr, options[:task_id])
56
+ results[res.result_id] = res
57
+ end
58
+ }
59
+ rescue VasExceptions::CommandException => e
60
+ end
55
61
 
56
62
  ret = results.values
57
63
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{openvas-cli}
8
- s.version = "0.2.7"
8
+ s.version = "0.2.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Reed Swenson"]
12
- s.date = %q{2011-04-04}
12
+ s.date = %q{2011-04-07}
13
13
  s.description = %q{A full ruby implementation of the OpenVAS OMP (version 2.0) protocol.}
14
14
  s.email = %q{fleureed@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -39,7 +39,7 @@ module OpenvasCli
39
39
  end
40
40
 
41
41
  it 'should filter the results' do
42
- all = VasReport.get_all(:filter => [:high])
42
+ all = VasReport.get_all(:levels => [:high])
43
43
 
44
44
  all.each { |report|
45
45
  report.results.each{ |result|
@@ -47,7 +47,7 @@ module OpenvasCli
47
47
  }
48
48
  }
49
49
 
50
- all = VasReport.get_all(:filter => [:log])
50
+ all = VasReport.get_all(:levels => [:log])
51
51
 
52
52
  all.each { |report|
53
53
  report.results.each{ |result|
@@ -55,7 +55,7 @@ module OpenvasCli
55
55
  }
56
56
  }
57
57
 
58
- all = VasReport.get_all(:filter => [:medium, :debug, :low])
58
+ all = VasReport.get_all(:levels => [:medium, :debug, :low])
59
59
 
60
60
  all.each { |report|
61
61
  report.results.each{ |result|
@@ -72,13 +72,39 @@ module OpenvasCli
72
72
  end
73
73
 
74
74
  it 'default sort should be by started_at descending' do
75
-
75
+ last_date = nil
76
+ VasReport.get_all.each { |r|
77
+ last_date = r.started_at unless last_date
78
+ r.started_at.should <= last_date
79
+ last_date = r.started_at
80
+ }
76
81
  end
77
82
 
78
- it 'just adding :sort_order => :ascending should reverse the started_at sort'
83
+ it 'just adding :sort_order => :ascending should reverse the started_at sort' do
84
+ last_date = nil
85
+ VasReport.get_all(:sort_order => :ascending).each { |r|
86
+ last_date = r.started_at unless last_date
87
+ r.started_at.should >= last_date
88
+ last_date = r.started_at
89
+ }
90
+ end
79
91
 
80
- it 'should sort by task_name (default :descending)'
92
+ it 'should sort by task_name (default :descending)' do
93
+ last_name = nil
94
+ VasReport.get_all(:sort => :task_name).each { |r|
95
+ last_name = r.started_at unless last_name
96
+ r.started_at.should <= last_name
97
+ last_date = r.started_at
98
+ }
99
+ end
81
100
 
82
- it 'should sort by :task_name, :ascending'
101
+ it 'should sort by :task_name, :ascending' do
102
+ last_name = nil
103
+ VasReport.get_all(:sort => :task_name, :sort_order => :ascending).each { |r|
104
+ last_name = r.started_at unless last_name
105
+ r.started_at.should >= last_name
106
+ last_date = r.started_at
107
+ }
108
+ end
83
109
  end
84
110
  end
@@ -136,5 +136,12 @@ module OpenvasCli
136
136
  result = VasResult.get_all(:task_id => VasTask.get_all.choice.id).choice
137
137
  result.destroy.should be true
138
138
  end
139
+
140
+ it 'should return a result by ID' do
141
+ result = VasResult.get_all(:task_id => VasTask.get_all.choice.id).choice
142
+
143
+ nr = VasResult.get_by_id(result.id)
144
+ nr.should_not be nil
145
+ end
139
146
  end
140
147
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openvas-cli
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 7
10
- version: 0.2.7
9
+ - 8
10
+ version: 0.2.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Reed Swenson
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-04 00:00:00 -05:00
18
+ date: 2011-04-07 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency