openvas-cli 0.2.9 → 0.2.10

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.9
1
+ 0.2.10
@@ -47,33 +47,37 @@ module OpenvasCli
47
47
  req = Nokogiri::XML::Builder.new { |xml|
48
48
  xml.get_configs(params)
49
49
  }
50
-
51
- resp = connection.send_receive(req.doc)
52
-
53
50
  ret = []
54
- resp.xpath("/get_configs_response/config").each { |xml|
55
- cfg = VasConfig.new
56
- cfg.id = extract_value_from("@id", xml)
57
- cfg.name = extract_value_from("name", xml)
58
- cfg.comment = extract_value_from("comment", xml)
59
- cfg.families_grow = extract_value_from("family_count/growing", xml).to_i > 0
60
- cfg.rules_grow = extract_value_from("nvt_count/growing", xml).to_i > 0
61
- cfg.in_use = extract_value_from("in_use", xml).to_i > 0
51
+
52
+ begin
53
+ resp = connection.send_receive(req.doc)
62
54
 
63
- xml.xpath("tasks/task").each { |t| cfg.tasks << VasTask.from_xml_node(t) }
64
- xml.xpath("families/family").each { |f| cfg.families << VasNVTFamily.from_xml_node(f) }
65
- xml.xpath("preferences/preference").each { |p|
66
- p = VasPreference.from_xml_node(p)
67
- p.config_id = cfg.id
68
- p.reset_changes
69
- cfg.preferences << p
55
+
56
+ resp.xpath("/get_configs_response/config").each { |xml|
57
+ cfg = VasConfig.new
58
+ cfg.id = extract_value_from("@id", xml)
59
+ cfg.name = extract_value_from("name", xml)
60
+ cfg.comment = extract_value_from("comment", xml)
61
+ cfg.families_grow = extract_value_from("family_count/growing", xml).to_i > 0
62
+ cfg.rules_grow = extract_value_from("nvt_count/growing", xml).to_i > 0
63
+ cfg.in_use = extract_value_from("in_use", xml).to_i > 0
64
+
65
+ xml.xpath("tasks/task").each { |t| cfg.tasks << VasTask.from_xml_node(t) }
66
+ xml.xpath("families/family").each { |f| cfg.families << VasNVTFamily.from_xml_node(f) }
67
+ xml.xpath("preferences/preference").each { |p|
68
+ p = VasPreference.from_xml_node(p)
69
+ p.config_id = cfg.id
70
+ p.reset_changes
71
+ cfg.preferences << p
72
+ }
73
+
74
+ cfg.reset_changes
75
+
76
+ ret << cfg
70
77
  }
71
-
72
- cfg.reset_changes
73
-
74
- ret << cfg
75
- }
76
-
78
+ rescue Exception => e
79
+ end
80
+
77
81
  ret
78
82
  end
79
83
 
@@ -56,7 +56,7 @@ module OpenvasCli
56
56
 
57
57
  def full_name
58
58
  if @nvt_id && !@nvt_id.empty?
59
- "#{nvt.name}[#{@val_type_desc}]:#{@name}"
59
+ "#{nvt_name}[#{@val_type_desc}]:#{@name}"
60
60
  else
61
61
  @name
62
62
  end
@@ -98,6 +98,14 @@ module OpenvasCli
98
98
  nil
99
99
  end
100
100
 
101
+ def self.get_by_name(config_id, name, nvt_id=nil)
102
+ if nvt_id
103
+ get_all(:config_id => config_id, :name => name, :nvt_oid => nvt_id).first
104
+ else
105
+ get_all(:config_id => config_id, :name => name).first
106
+ end
107
+ end
108
+
101
109
  # Pulls Vas preferences.
102
110
  # === Options:
103
111
  # [:config_id] => [configuration_id]] pulls preferences associated with the provided configuration id
@@ -109,7 +117,13 @@ module OpenvasCli
109
117
  params = {}
110
118
  params[:config_id] = options[:config_id] if options[:config_id]
111
119
  params[:nvt_oid] = options[:nvt_oid] if options[:nvt_oid]
112
- manual_filter = true if options[:name]
120
+ if options[:name]
121
+ if options[:nvt_oid]
122
+ params[:preference] = options[:name]
123
+ else
124
+ manual_filter = true
125
+ end
126
+ end
113
127
 
114
128
  req = Nokogiri::XML::Builder.new { |xml|
115
129
  if params.empty?
@@ -122,10 +136,10 @@ module OpenvasCli
122
136
  begin
123
137
  prefs = connection.send_receive(req.doc)
124
138
 
125
- prefs.xpath("//preference").each { |p|
126
- pref = from_xml_node(p, options[:config_id])
139
+ prefs.xpath("/get_preferences_response/preference").each { |p|
140
+ pref = from_xml_node(p, options[:config_id])
127
141
  if manual_filter
128
- ret << pref if options[:name] && options[:name] == pref.name
142
+ ret << pref if pref.name == options[:name] && pref.nvt_id.empty?
129
143
  else
130
144
  ret << pref
131
145
  end
@@ -56,7 +56,8 @@ module OpenvasCli
56
56
  end
57
57
 
58
58
  ret = []
59
- repts.xpath('//report').each { |r|
59
+
60
+ repts.xpath('/get_reports_response/report/report').each { |r|
60
61
  rep = VasReport.new
61
62
  rep.id = extract_value_from("@id", r)
62
63
  rep.task_id = extract_value_from("task/@id", r)
@@ -77,7 +78,7 @@ module OpenvasCli
77
78
  rep.result_count[:medium][:total] = extract_value_from("result_count/warning/full", r).to_i
78
79
  rep.result_count[:medium][:filtered] = extract_value_from("result_count/warning/filtered", r).to_i
79
80
 
80
- r.xpath("results/result").each { |result|
81
+ r.xpath("./results/result").each { |result|
81
82
  rep.results << VasResult.parse_result_node(result)
82
83
  }
83
84
 
@@ -86,18 +87,19 @@ module OpenvasCli
86
87
 
87
88
  options[:sort] = :started_at unless options[:sort]
88
89
  options[:sort_order] = :descending unless options[:sort_order]
89
-
90
- if options[:sort] == :started_at
91
- if options[:sort_order] == :ascending
92
- ret.sort! { |a,b| a.started_at <=> b.started_at }
93
- else
94
- ret.sort! { |a,b| b.started_at <=> a.started_at }
95
- end
96
- elsif options[:sort] == :task_name
97
- if options[:sort_order] == :ascending
98
- ret.sort! { |a,b| a.task_name <=> b.task_name }
99
- else
100
- ret.sort! { |a,b| b.task_name <=> a.task_name }
90
+ unless options[:id]
91
+ if options[:sort] == :started_at
92
+ if options[:sort_order] == :ascending
93
+ ret.sort! { |a,b| a.started_at <=> b.started_at }
94
+ else
95
+ ret.sort! { |a,b| b.started_at <=> a.started_at }
96
+ end
97
+ elsif options[:sort] == :task_name
98
+ if options[:sort_order] == :ascending
99
+ ret.sort! { |a,b| a.task_name <=> b.task_name }
100
+ else
101
+ ret.sort! { |a,b| b.task_name <=> a.task_name }
102
+ end
101
103
  end
102
104
  end
103
105
 
@@ -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.9"
8
+ s.version = "0.2.10"
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-13}
12
+ s.date = %q{2011-04-14}
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 = [
@@ -77,5 +77,12 @@ module OpenvasCli
77
77
  n_pref = new_cfg.preferences[i]
78
78
  n_pref.value.should == pref.value
79
79
  end
80
+
81
+ it 'should not throw an exception when trying to pull with an invalid ID' do
82
+ lambda {
83
+ cfg = VasConfig.get_by_id("foo")
84
+ cfg.should be nil
85
+ }.should_not raise_error
86
+ end
80
87
  end
81
88
  end
@@ -11,16 +11,82 @@ module OpenvasCli
11
11
  }
12
12
  end
13
13
 
14
- it 'should pull a single preference by name' do
15
- all = VasPreference.get_all
14
+ it 'should pull a single preference by name and nvt_oid' do
15
+ config = VasConfig.get_all.choice
16
+
17
+ prefs = VasPreference.get_all(:config_id => config.id)
18
+ o_pref = prefs.choice
19
+ while o_pref.nvt_id.empty?
20
+ o_pref = prefs.choice
21
+ end
22
+ o_pref.should_not be nil
23
+
24
+
25
+ prefs = VasPreference.get_all(:config_id => config.id, :nvt_oid => o_pref.nvt_id, :name=>o_pref.name)
26
+ prefs.count.should == 1
27
+
28
+ n_pref = prefs.first
29
+ n_pref.should_not be nil
30
+
31
+ o_pref.full_name.should == n_pref.full_name
32
+ o_pref.value.should == n_pref.value
33
+ o_pref.config_id.should == n_pref.config_id
34
+ end
35
+
36
+ it 'should pull a single preference by name for the global configuration' do
37
+ config = VasConfig.get_all.choice
38
+
39
+ prefs = VasPreference.get_all(:config_id => config.id)
40
+ o_pref = prefs.choice
41
+ while !o_pref.nvt_id.empty?
42
+ o_pref = prefs.choice
43
+ end
44
+ o_pref.should_not be nil
45
+
46
+
47
+ prefs = VasPreference.get_all(:config_id => config.id, :name=>o_pref.name)
48
+ prefs.count.should == 1
49
+
50
+ n_pref = prefs.first
51
+ n_pref.should_not be nil
52
+
53
+ o_pref.full_name.should == n_pref.full_name
54
+ o_pref.value.should == n_pref.value
55
+ o_pref.config_id.should == n_pref.config_id
56
+ end
57
+
58
+ it 'get_by_name should pull a single preference by name and nvt_oid' do
59
+ config = VasConfig.get_all.choice
60
+
61
+ prefs = VasPreference.get_all(:config_id => config.id)
62
+ o_pref = prefs.choice
63
+ while o_pref.nvt_id.empty?
64
+ o_pref = prefs.choice
65
+ end
66
+ o_pref.should_not be nil
67
+
68
+ n_pref = VasPreference.get_by_name(config.id, o_pref.name, o_pref.nvt_id)
69
+ n_pref.should_not be nil
70
+
71
+ o_pref.full_name.should == n_pref.full_name
72
+ o_pref.value.should == n_pref.value
73
+ o_pref.config_id.should == n_pref.config_id
74
+ end
75
+
76
+ it 'get_by_name should pull a single preference by name for the global configuration' do
77
+ config = VasConfig.get_all.choice
16
78
 
17
- o_pref = all[rand(all.count)]
79
+ prefs = VasPreference.get_all(:config_id => config.id)
80
+ o_pref = prefs.choice
81
+ while !o_pref.nvt_id.empty?
82
+ o_pref = prefs.choice
83
+ end
18
84
  o_pref.should_not be nil
19
85
 
20
- n_pref = VasPreference.get_all(:name=>o_pref.name)[0]
86
+ n_pref = VasPreference.get_by_name(config.id, o_pref.name)
21
87
  n_pref.should_not be nil
22
88
 
23
- o_pref.name.should == n_pref.name
89
+ o_pref.full_name.should == n_pref.full_name
24
90
  o_pref.value.should == n_pref.value
25
91
  o_pref.config_id.should == n_pref.config_id
26
92
  end
@@ -106,5 +106,24 @@ module OpenvasCli
106
106
  last_date = r.task_name
107
107
  }
108
108
  end
109
+
110
+ it 'should pull results for a report when the ID and a filter is specified' do
111
+ report_ids = {}
112
+ VasReport.get_all(:levels => [:high, :medium]).each { |r|
113
+ report_ids[r.id] = r.results.count unless r.results.empty?
114
+ }
115
+ report_ids.each { |id, count|
116
+ options = {
117
+ :sort_order => :descending,
118
+ :sort => :started_at,
119
+ :levels => [:high, :medium],
120
+ :id => id
121
+ }
122
+ rept = VasReport.get_all(options)[0]
123
+ rept.should_not be nil
124
+ rept.should have(count).results
125
+ }
126
+
127
+ end
109
128
  end
110
129
  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: 5
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 9
10
- version: 0.2.9
9
+ - 10
10
+ version: 0.2.10
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-13 00:00:00 -05:00
18
+ date: 2011-04-14 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency