openvas-cli 0.1.1 → 0.2.0

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 (42) hide show
  1. data/Gemfile +2 -0
  2. data/Gemfile.lock +50 -0
  3. data/VERSION +1 -1
  4. data/lib/openvas-cli/configuration.rb +25 -0
  5. data/lib/openvas-cli/conn_addin.rb +27 -0
  6. data/lib/openvas-cli/immutable_children_validator.rb +15 -0
  7. data/lib/openvas-cli/vas_administrator.rb +7 -0
  8. data/lib/openvas-cli/vas_base.rb +20 -30
  9. data/lib/openvas-cli/vas_config.rb +127 -0
  10. data/lib/openvas-cli/vas_connection.rb +140 -0
  11. data/lib/openvas-cli/vas_exceptions.rb +9 -7
  12. data/lib/openvas-cli/vas_lsc_credential.rb +110 -0
  13. data/lib/openvas-cli/vas_nvt.rb +64 -64
  14. data/lib/openvas-cli/vas_nvt_family.rb +39 -30
  15. data/lib/openvas-cli/vas_override.rb +6 -4
  16. data/lib/openvas-cli/vas_period.rb +89 -0
  17. data/lib/openvas-cli/vas_preference.rb +139 -49
  18. data/lib/openvas-cli/vas_report.rb +110 -103
  19. data/lib/openvas-cli/vas_result.rb +90 -89
  20. data/lib/openvas-cli/vas_schedule.rb +163 -55
  21. data/lib/openvas-cli/vas_target.rb +200 -23
  22. data/lib/openvas-cli/vas_task.rb +229 -30
  23. data/lib/openvas-cli/vas_task_progress.rb +29 -0
  24. data/lib/openvas-cli/xml_addin.rb +34 -0
  25. data/lib/openvas_cli.rb +19 -0
  26. data/openvas-cli.gemspec +28 -6
  27. data/spec/openvas-cli/vas_administrator_spec.rb +6 -0
  28. data/spec/openvas-cli/vas_config_spec.rb +81 -0
  29. data/spec/openvas-cli/vas_lsc_credential_spec.rb +72 -0
  30. data/spec/openvas-cli/vas_nvt_family_spec.rb +7 -5
  31. data/spec/openvas-cli/vas_nvt_spec.rb +30 -26
  32. data/spec/openvas-cli/vas_period_spec.rb +7 -0
  33. data/spec/openvas-cli/vas_preference_spec.rb +23 -21
  34. data/spec/openvas-cli/vas_report_spec.rb +65 -63
  35. data/spec/openvas-cli/vas_result_spec.rb +94 -93
  36. data/spec/openvas-cli/vas_schedule_spec.rb +154 -57
  37. data/spec/openvas-cli/vas_target_spec.rb +140 -28
  38. data/spec/openvas-cli/vas_task_spec.rb +92 -11
  39. data/spec/spec_helper.rb +15 -5
  40. metadata +72 -24
  41. data/lib/openvas-cli/openvas-cli.rb +0 -273
  42. data/spec/openvas-cli/openvas-cli_spec.rb +0 -45
@@ -1,8 +1,10 @@
1
- # Continer for all cusom exceptions used in openvas-cli.
2
- module VasExceptions
3
- # Thrown when the OpenVAS management service rejects a command for some reason.
4
- class CommandException < StandardError; end
5
- # Thrown when some sort of communications error (like a timeout or unexpected
6
- # end-of-file) is encountered.
7
- class CommunicationException < StandardError; end
1
+ module OpenvasCli
2
+ # Continer for all cusom exceptions used in openvas-cli.
3
+ module VasExceptions
4
+ # Thrown when the OpenVAS management service rejects a command for some reason.
5
+ class CommandException < StandardError; end
6
+ # Thrown when some sort of communications error (like a timeout or unexpected
7
+ # end-of-file) is encountered.
8
+ class CommunicationException < StandardError; end
9
+ end
8
10
  end
@@ -0,0 +1,110 @@
1
+ require 'vas_base'
2
+
3
+ module OpenvasCli
4
+ class VasLscCredential < VasBase
5
+
6
+ attr_accessor :name
7
+ attr_accessor :login
8
+ attr_accessor :comment
9
+ attr_accessor :in_use
10
+ attr_accessor :type
11
+ attr_accessor :public_key
12
+ attr_accessor :package
13
+ attr_accessor :package_type
14
+ attr_accessor :password
15
+
16
+ validates :name, :presence => true, :length => {:minimum => 1}
17
+ validates :login, :presence => true, :length => {:minimum => 1}
18
+
19
+ def initialize(params = {})
20
+ @id = params[:id] if params[:id]
21
+ @name = params[:name] if params[:name]
22
+ @login = params[:login] if params[:login]
23
+ @comment = params[:comment] if params[:comment]
24
+ @password = params[:password] if params[:password]
25
+ end
26
+
27
+ def target_keys
28
+ @target_keys ||= []
29
+ end
30
+
31
+ def targets
32
+ @targets ||= []
33
+ end
34
+
35
+ def save!
36
+ raise "VasLscCredential is not valid" unless valid?
37
+
38
+ if @id
39
+ #update
40
+ req = Nokogiri::XML::Builder.new { |xml|
41
+ xml.modify_lsc_credential(:lsc_credential_id => @id) {
42
+ xml.name { xml.text(@name) }
43
+ xml.comment { xml.text(@comment) } if @comment
44
+ xml.login { xml.text(@login) }
45
+ xml.password { xml.text(@password) } if @password
46
+ }
47
+ }
48
+ else
49
+ #create
50
+ req = Nokogiri::XML::Builder.new { |xml|
51
+ xml.create_lsc_credential {
52
+ xml.name { xml.text(@name) }
53
+ xml.comment { xml.text(@comment) } if @comment
54
+ xml.login { xml.text(@login) }
55
+ xml.password { xml.text(@password) } if @password
56
+ }
57
+ }
58
+ end
59
+
60
+ resp = VasLscCredential.connection.send_receive(req.doc)
61
+
62
+ @id = VasLscCredential.extract_value_from("create_lsc_credential_response/@id", resp) unless @id
63
+ end
64
+
65
+ def destroy!
66
+ return unless @id
67
+ req = Nokogiri::XML::Builder.new { |xml|
68
+ xml.delete_lsc_credential( :lsc_credential_id => @id )
69
+ }
70
+
71
+ VasLscCredential.connection.send_receive(req.doc)
72
+ end
73
+
74
+ def self.get_all(options={})
75
+ params = {:sort_field => 'name'}
76
+ params[:lsc_credential_id] = options[:id] if options[:id]
77
+ req = Nokogiri::XML::Builder.new { |xml|
78
+ xml.get_lsc_credentials(params)
79
+ }
80
+
81
+ resp = connection.send_receive(req.doc)
82
+
83
+ ret = []
84
+ resp.xpath("//lsc_credential").each { |cred|
85
+ ret << from_xml_node(cred)
86
+ }
87
+
88
+ ret
89
+ end
90
+
91
+ def self.from_xml_node(node)
92
+ ret = VasLscCredential.new
93
+ ret.id = extract_value_from("@id", node)
94
+ ret.name = extract_value_from("name", node)
95
+ ret.login = extract_value_from("login", node)
96
+ ret.comment = extract_value_from("comment", node)
97
+ ret.in_use = extract_value_from("in_use", node).to_i > 0
98
+ ret.type = extract_value_from("type", node)
99
+ ret.public_key = extract_value_from("public_key", node)
100
+ ret.package = extract_value_from("package", node)
101
+ ret.package_type = extract_value_from("package/@format", node)
102
+
103
+ node.xpath("targets/target").each { |t|
104
+ ret.target_keys << extract_value_from("@id", t)
105
+ }
106
+
107
+ ret
108
+ end
109
+ end
110
+ end
@@ -1,70 +1,70 @@
1
1
  require 'vas_base'
2
2
 
3
- # Describes a NSIS/OpenVAS scan rule.
4
- #--
5
- # TODO: Filter by other useful fields
6
- # TODO: Find external links for more information
7
- # TODO: Redcloth and Autolink description
8
- # TODO: Implement sorting options[:sort_by]
9
- #++
10
- class VasNVT < VasBase
11
- # Unique identifier for rule.
12
- attr_accessor :oid
13
- # Human readable name of the rule.
14
- attr_accessor :name
15
-
16
- attr_accessor :category
17
- attr_accessor :copyright
18
- attr_accessor :description
19
- attr_accessor :summary
20
- attr_accessor :family
21
- attr_accessor :version
22
- attr_accessor :cvss_base
23
- attr_accessor :risk_factor
24
- attr_accessor :cve_id
25
- attr_accessor :bugtraq_id
26
- attr_accessor :xrefs
27
- attr_accessor :tags
28
- attr_accessor :preferences
29
-
30
- validates :oid, :presence => true, :OID => true
31
-
32
- # Pulls VasNVT rules that match the provided options.
33
- #
34
- # === Options:
35
- # [:nvt_oid => [VasNVT.oid]] will pull only the NVT rule that matches the given OID
36
- # [:family => [VasFamily.name]] will pull all NVT rules for the specified family
37
- def self.get_all(options = {})
38
- params = {:details => '1'}
39
- params[:nvt_oid] = options[:oid] if options[:oid]
40
- params[:family] = options[:family] if options[:family]
41
-
42
- req = Nokogiri::XML::Builder.new { |xml|
43
- xml.get_nvts(params)
44
- }
3
+ module OpenvasCli
4
+ # Describes a NSIS/OpenVAS scan rule.
5
+ #--
6
+ # TODO: Filter by other useful fields
7
+ # TODO: Find external links for more information
8
+ # TODO: Redcloth and Autolink description
9
+ # TODO: Implement sorting options[:sort_by]
10
+ #++
11
+ class VasNVT < VasBase
12
+ # Human readable name of the rule.
13
+ attr_accessor :name
45
14
 
46
- rules = client.send_receive(req.doc)
15
+ attr_accessor :category
16
+ attr_accessor :copyright
17
+ attr_accessor :description
18
+ attr_accessor :summary
19
+ attr_accessor :family
20
+ attr_accessor :version
21
+ attr_accessor :cvss_base
22
+ attr_accessor :risk_factor
23
+ attr_accessor :cve_id
24
+ attr_accessor :bugtraq_id
25
+ attr_accessor :xrefs
26
+ attr_accessor :tags
27
+ attr_accessor :preferences
47
28
 
48
- ret = []
49
- rules.xpath("//nvt").each { |nvt|
50
- rule = VasNVT.new
51
- rule.oid = extract_value_from("@oid", nvt)
52
- rule.name = extract_value_from("name", nvt)
53
- rule.category = extract_value_from("category", nvt)
54
- rule.copyright = extract_value_from("copyright", nvt)
55
- rule.description = extract_value_from("description", nvt).strip
56
- rule.summary = extract_value_from("summary", nvt)
57
- rule.family = extract_value_from("family", nvt)
58
- rule.version = extract_value_from("version", nvt)
59
- rule.cvss_base = extract_value_from("cvss_base", nvt)
60
- rule.risk_factor = extract_value_from("risk_factor", nvt)
61
- rule.cve_id = extract_value_from("cve_id", nvt)
62
- rule.bugtraq_id = extract_value_from("bugtraq_id", nvt)
63
- rule.xrefs = extract_value_from("xrefs", nvt).split(/, ?/)
64
- rule.tags = extract_value_from("tags", nvt).split(/, ?/)
65
- ret << rule
66
- }
29
+ validates :id, :OID => true, :presence => true
30
+ # Pulls VasNVT rules that match the provided options.
31
+ #
32
+ # === Options:
33
+ # [:id => [VasNVT.oid]] will pull only the NVT rule that matches the given OID
34
+ # [:family => [VasFamily.name]] will pull all NVT rules for the specified family
35
+ def self.get_all(options = {})
36
+ params = {:details => '1'}
37
+ params[:nvt_oid] = options[:id] if options[:id]
38
+ params[:family] = options[:family] if options[:family]
39
+ params[:config_id] = options[:config_id] if options[:config_id]
67
40
 
68
- ret
69
- end
41
+ req = Nokogiri::XML::Builder.new { |xml|
42
+ xml.get_nvts(params)
43
+ }
44
+
45
+ rules = connection.send_receive(req.doc)
46
+
47
+ ret = []
48
+ rules.xpath("/get_nvts_response/nvt").each { |nvt|
49
+ rule = VasNVT.new
50
+ rule.id = extract_value_from("@oid", nvt)
51
+ rule.name = extract_value_from("name", nvt)
52
+ rule.category = extract_value_from("category", nvt)
53
+ rule.copyright = extract_value_from("copyright", nvt)
54
+ rule.description = extract_value_from("description", nvt).strip
55
+ rule.summary = extract_value_from("summary", nvt)
56
+ rule.family = extract_value_from("family", nvt)
57
+ rule.version = extract_value_from("version", nvt)
58
+ rule.cvss_base = extract_value_from("cvss_base", nvt)
59
+ rule.risk_factor = extract_value_from("risk_factor", nvt)
60
+ rule.cve_id = extract_value_from("cve_id", nvt)
61
+ rule.bugtraq_id = extract_value_from("bugtraq_id", nvt)
62
+ rule.xrefs = extract_value_from("xrefs", nvt).split(/, ?/)
63
+ rule.tags = extract_value_from("tags", nvt).split(/, ?/)
64
+ ret << rule
65
+ }
66
+
67
+ ret
68
+ end
69
+ end
70
70
  end
@@ -1,37 +1,46 @@
1
1
  require 'vas_base'
2
2
 
3
- # Category for NVT rules
4
- class VasNVTFamily < VasBase
5
- # Category Name
6
- attr_accessor :name
7
- # Number of rules in the family
8
- attr_accessor :nvt_count
9
-
10
- validates :name, :presence => true, :length => {:minimum => 1}
11
-
12
- # Pulls all NVT Families defined on the server.
13
- #
14
- # === Options:
15
- # None.
16
- #--
17
- # TODO: Implement options[:sort_by]
18
- #++
19
- def self.get_all(options = {})
20
-
21
- req = Nokogiri::XML::Builder.new { |xml|
22
- xml.get_nvt_families
23
- }
3
+ module OpenvasCli
4
+ # Category for NVT rules
5
+ class VasNVTFamily < VasBase
6
+ # Category Name
7
+ attr_accessor :name
8
+ # Number of rules in the family
9
+ attr_accessor :nvt_count
10
+ attr_accessor :is_growing
24
11
 
25
- fams = client.send_receive(req.doc)
12
+ validates :name, :presence => true, :length => {:minimum => 1}
26
13
 
27
- ret = []
28
- fams.xpath('//family').each { |f|
29
- family = VasNVTFamily.new
30
- family.name = extract_value_from('name', f)
31
- family.nvt_count = extract_value_from('max_nvt_count', f).to_i
32
- ret << family
33
- }
14
+ # Pulls all NVT Families defined on the server.
15
+ #
16
+ # === Options:
17
+ # None.
18
+ #--
19
+ # TODO: Implement options[:sort_by]
20
+ #++
21
+ def self.get_all(options = {})
34
22
 
35
- ret
23
+ req = Nokogiri::XML::Builder.new { |xml|
24
+ xml.get_nvt_families
25
+ }
26
+
27
+ fams = connection.send_receive(req.doc)
28
+
29
+ ret = []
30
+ fams.xpath('//family').each { |f|
31
+ ret << from_xml_node(f)
32
+ }
33
+
34
+ ret
35
+ end
36
+
37
+ def self.from_xml_node(node)
38
+ family = VasNVTFamily.new
39
+ family.name = extract_value_from('name', node)
40
+ family.nvt_count = extract_value_from('max_nvt_count', node).to_i
41
+ family.is_growing = (extract_value_from("growing", node).to_i > 0)
42
+
43
+ family
44
+ end
36
45
  end
37
46
  end
@@ -1,7 +1,9 @@
1
1
  require 'vas_base'
2
2
 
3
- # NOT IMPLEMENTED
4
- class VasOverride
5
- attr_accessor :task_id, :original_threat, :rule_id, :is_new
6
-
3
+ module OpenvasCli
4
+ # NOT IMPLEMENTED
5
+ class VasOverride < VasBase
6
+ attr_accessor :task_id, :original_threat, :rule_id, :is_new
7
+
8
+ end
7
9
  end
@@ -0,0 +1,89 @@
1
+ require 'active_model'
2
+
3
+ module OpenvasCli
4
+ class VasPeriod
5
+ include ActiveModel::Validations
6
+ include ActiveModel::Dirty
7
+ include Comparable
8
+
9
+ attr_reader :number
10
+ attr_reader :period
11
+
12
+ define_attribute_methods [:number, :period]
13
+
14
+ validates :number, :numericality => { :greater_than_or_equal_to => 0 }
15
+ validates :period, :inclusion => [:second, :minute, :hour, :day, :month, :year]
16
+
17
+ def initialize(params={})
18
+ @number = params[:number] if params[:number]
19
+ @period = params[:period] if params[:period]
20
+ end
21
+
22
+ def number=(v)
23
+ number_will_change! unless @number == v
24
+ @number = v
25
+ end
26
+
27
+ def period=(v)
28
+ period_will_change! unless @period == v
29
+ @period = v
30
+ end
31
+
32
+ def <=> (rhs)
33
+ to_seconds - rhs.to_seconds
34
+ end
35
+
36
+ def + (rhs)
37
+ if rhs.kind_of? VasPeriod
38
+ VasPeriod.from_seconds(to_seconds + rhs.to_seconds)
39
+ else
40
+ VasPeriod.from_seconds(to_seconds + rhs)
41
+ end
42
+ end
43
+
44
+ def - (rhs)
45
+ if rhs.kind_of? VasPeriod
46
+ VasPeriod.from_seconds(to_seconds - rhs.to_seconds)
47
+ else
48
+ VasPeriod.from_seconds(to_seconds - rhs)
49
+ end
50
+ end
51
+
52
+ def to_seconds
53
+ case @period
54
+ when :year
55
+ @number * 365.25 * 86400
56
+ when :month
57
+ @number * 365.25 * 86400 / 12
58
+ when :day
59
+ @number * 86400
60
+ when :hour
61
+ @number * 3600
62
+ when :minute
63
+ @number * 60
64
+ else
65
+ @number
66
+ end
67
+ end
68
+
69
+ def self.from_seconds(seconds)
70
+ if seconds % 86400 == 0
71
+ VasPeriod.new(:number => seconds / 86400, :period => :day)
72
+ elsif seconds % 3600 == 0
73
+ VasPeriod.new(:number => seconds / 3600, :period => :hour)
74
+ elsif seconds % 60 == 0
75
+ VasPeriod.new(:number => seconds / 60, :period => :minute)
76
+ else
77
+ VasPeriod.new(:number => seconds, :period => :second)
78
+ end
79
+ end
80
+
81
+ def self.from_months(months)
82
+ if months % 12 == 0
83
+ VasPeriod.new(:number => months / 12, :period => :month)
84
+ else
85
+ VasPeriod.new(:number => months, :period => :month)
86
+ end
87
+ end
88
+ end
89
+ end
@@ -1,59 +1,149 @@
1
1
  require 'vas_base'
2
2
  require 'nokogiri'
3
3
 
4
- # A name-value pair for OpenVAS configuration preferences. If inspecting a
5
- # specific configuration set, +config_id+ will be populated. If +config_id+ is
6
- # non-existant, then the preference is a system-wide default.
7
- #--
8
- # TODO: Implement write functions
9
- #++
10
- class VasPreference < VasBase
11
- # Name of the configuration preference.
12
- attr_accessor :name
13
- # Value used for the preference.
14
- attr_accessor :value
15
- # Configuration Identifier. If +nil+, the preference is a system-wide
16
- # default.
17
- attr_accessor :config_id
4
+ module OpenvasCli
5
+ # A name-value pair for OpenVAS configuration preferences. If inspecting a
6
+ # specific configuration set, +config_id+ will be populated. If +config_id+ is
7
+ # non-existant, then the preference is a system-wide default.
8
+ class VasPreference < VasBase
9
+ # Type of value expected :boolean, :choice, :text
10
+ attr_accessor :val_type
11
+
12
+ attr_accessor :val_type_desc
13
+
14
+ # Configuration Identifier. If +nil+, the preference is a system-wide
15
+ # default.
16
+ attr_accessor :config_id
17
+
18
+ # NVT id
19
+ attr_accessor :nvt_id
18
20
 
19
- validates :name, :presence => true, :length=>{:minimum => 1}
20
-
21
- # Pulls Vas preferences.
22
- # === Options:
23
- # [:nvt_oid => [oid]] pulls preferences associated associated with the provided VasNVT.oid
24
- # [:name => [name]] pulls the preference with the specified name
25
- # [:sort_by => [field_name]] filters the results by the provided field name. Valid symbols are, :name, :value, :config_id.
26
- def self.get_all(options={})
27
- manual_filter = false
28
- params = {}
29
- params[:nvt_oid] = options[:nvt_oid] if options[:nvt_oid]
30
- manual_filter = true if options[:name]
31
-
32
- req = Nokogiri::XML::Builder.new { |xml|
33
- if params.empty?
34
- xml.get_preferences
35
- else
36
- xml.get_preferences(params)
37
- end
38
- }
39
-
40
- prefs = client.send_receive(req.doc)
41
- ret = []
42
- prefs.xpath("//preference").each { |p|
43
- pref = VasPreference.new
44
- pref.name = extract_value_from("name", p)
45
- pref.value = extract_value_from("value", p)
46
- if manual_filter
47
- ret << pref if options[:name] && options[:name] == pref.name
21
+ validates :name, :presence => true, :length=>{:minimum => 1}
22
+
23
+ define_attribute_methods [:name, :value]
24
+
25
+ def name
26
+ @name
27
+ end
28
+
29
+ def name=(val)
30
+ name_will_change! unless val == @name
31
+ @name = val
32
+ end
33
+
34
+ def value
35
+ @value
36
+ end
37
+
38
+ def value=(val)
39
+ value_will_change! unless val == @value
40
+ @value = val
41
+ end
42
+
43
+ def initialize(attributes={})
44
+ @name = attributes[:name] if attributes[:name]
45
+ @value = attributes[:value] if attributes[:value]
46
+ @config_id = attributes[:config_id] if attributes[:config_id]
47
+ end
48
+
49
+ def config
50
+ @config ||= VasConfig.get_all(:id => @config_id)[0]
51
+ end
52
+
53
+ def nvt
54
+ @nvt ||= VasNVT.get_all(:id => @nvt_id)[0]
55
+ end
56
+
57
+ def val_choices
58
+ @val_choices ||= []
59
+ end
60
+
61
+ def full_name
62
+ if @nvt_id && !@nvt_id.empty?
63
+ "#{nvt.name}[#{@val_type_desc}]:#{@name}"
48
64
  else
49
- ret << pref
65
+ @name
50
66
  end
51
- }
67
+ end
68
+
69
+ def save!
70
+ raise "Cannot save a preference that is not tied to a configuration" unless @config_id
71
+ req = Nokogiri::XML::Builder.new { |xml|
72
+ xml.modify_config(:config_id => @config_id) {
73
+ xml.preference {
74
+ xml.nvt(:oid=>@nvt_id) if @nvt_id && !@nvt_id.empty?
75
+ xml.name { xml.text(full_name) }
76
+ xml.value {
77
+ if @val_type == :boolean
78
+ xml.text(Base64.encode64(@value ? "yes" : "no"))
79
+ else
80
+ xml.text(Base64.encode64(@value))
81
+ end
82
+ }
83
+ }
84
+ }
85
+ }
52
86
 
53
- ret.sort!{ |a,b| a.name <=> b.name } if params[:sort_by] == :name
54
- ret.sort!{ |a,b| a.value <=> b.value } if params[:sort_by] == :value
55
- ret.sort!{ |a,b| a.config_id <=> b.config_id } if params[:sort_by] == :config_id
87
+ VasPreference.connection.send_receive(req.doc)
88
+ end
56
89
 
57
- ret
90
+ # Pulls Vas preferences.
91
+ # === Options:
92
+ # [:nvt_oid => [oid]] pulls preferences associated associated with the provided VasNVT.oid
93
+ # [:name => [name]] pulls the preference with the specified name
94
+ # [:sort_by => [field_name]] filters the results by the provided field name. Valid symbols are, :name, :value, :config_id.
95
+ def self.get_all(options={})
96
+ manual_filter = false
97
+ params = {}
98
+ params[:nvt_oid] = options[:nvt_oid] if options[:nvt_oid]
99
+ manual_filter = true if options[:name]
100
+
101
+ req = Nokogiri::XML::Builder.new { |xml|
102
+ if params.empty?
103
+ xml.get_preferences
104
+ else
105
+ xml.get_preferences(params)
106
+ end
107
+ }
108
+
109
+ prefs = connection.send_receive(req.doc)
110
+ ret = []
111
+ prefs.xpath("//preference").each { |p|
112
+ pref = from_xml_node(p)
113
+ if manual_filter
114
+ ret << pref if options[:name] && options[:name] == pref.name
115
+ else
116
+ ret << pref
117
+ end
118
+ }
119
+
120
+ ret.sort!{ |a,b| a.name <=> b.name } if params[:sort_by] == :name
121
+ ret.sort!{ |a,b| a.value <=> b.value } if params[:sort_by] == :value
122
+ ret.sort!{ |a,b| a.config_id <=> b.config_id } if params[:sort_by] == :config_id
123
+
124
+ ret
125
+ end
126
+
127
+ def self.from_xml_node(node)
128
+ pref = VasPreference.new
129
+ pref.name = extract_value_from("name", node)
130
+ pref.value = extract_value_from("value", node)
131
+ pref.nvt_id = extract_value_from("nvt/@oid", node)
132
+ pref.val_type_desc = extract_value_from("type", node)
133
+ case pref.val_type_desc
134
+ when "checkbox"
135
+ pref.val_type = :boolean
136
+ pref.value = pref.value == "yes" ? true : false
137
+ when "radio"
138
+ pref.val_type = :choice
139
+ pref.val_choices << pref.value
140
+ node.xpath("alt").each { |alt|
141
+ pref.val_choices << alt.text
142
+ }
143
+ else
144
+ pref.val_type = :text
145
+ end
146
+ pref
147
+ end
58
148
  end
59
149
  end