class OpenvasCli::VasPreference
A name-value pair for OpenVAS configuration preferences. If inspecting a specific configuration set, config_id
will be populated. If config_id
is non-existant, then the preference is a system-wide default.
Attributes
config_id[RW]
Configuration
Identifier. If nil
, the preference is a system-wide default.
nvt_id[RW]
NVT id
nvt_name[RW]
val_type[RW]
Type of value expected :boolean, :choice, :text
val_type_desc[RW]
Public Class Methods
from_xml_node(node, config_id=nil)
click to toggle source
# File lib/openvas-cli/vas_preference.rb, line 156 def self.from_xml_node(node, config_id=nil) pref = VasPreference.new pref.name = extract_value_from("name", node) pref.value = extract_value_from("value", node) pref.nvt_id = extract_value_from("nvt/@oid", node) pref.nvt_name = extract_value_from("nvt/name", node) pref.val_type_desc = extract_value_from("type", node) pref.config_id = config_id case pref.val_type_desc when "checkbox" pref.val_type = :boolean pref.value = pref.value == "yes" ? true : false when "radio" pref.val_type = :choice pref.val_choices << pref.value node.xpath("alt").each { |alt| pref.val_choices << alt.text } else pref.val_type = :text end pref end
get_all(options={})
click to toggle source
Pulls Vas preferences.
Options:¶ ↑
- :config_id
-
> [configuration_id]] pulls preferences associated with the provided configuration id¶ ↑
- :nvt_oid => [oid]
-
pulls preferences associated associated with the provided VasNVT.oid
- :name => [name]
-
pulls the preference with the specified name
- :sort_by => [field_name]
-
filters the results by the provided field name. Valid symbols are, :name, :nvt_name, :nvt_id.
# File lib/openvas-cli/vas_preference.rb, line 115 def self.get_all(options={}) manual_filter = false params = {} params[:config_id] = options[:config_id] if options[:config_id] params[:nvt_oid] = options[:nvt_oid] if options[:nvt_oid] if options[:name] if options[:nvt_oid] params[:preference] = options[:name] else manual_filter = true end end req = Nokogiri::XML::Builder.new { |xml| if params.empty? xml.get_preferences else xml.get_preferences(params) end } ret = [] begin prefs = connection.send_receive(req.doc) prefs.xpath("/get_preferences_response/preference").each { |p| pref = from_xml_node(p, options[:config_id]) if manual_filter ret << pref if pref.name == options[:name] && pref.nvt_id.empty? else ret << pref end } ret.sort!{ |a,b| a.name <=> b.name } if options[:sort_by] == :name ret.sort!{ |a,b| a.nvt_id <=> b.nvt_id } if options[:sort_by] == :nvt_id ret.sort!{ |a,b| a.nvt_name <=> b.nvt_name } if options[:sort_by] == :nvt_name rescue VasExceptions::CommandException => e end ret end
get_by_id(id)
click to toggle source
# File lib/openvas-cli/vas_preference.rb, line 97 def self.get_by_id(id) nil end
get_by_name(config_id, name, nvt_id=nil)
click to toggle source
# File lib/openvas-cli/vas_preference.rb, line 101 def self.get_by_name(config_id, name, nvt_id=nil) if nvt_id get_all(:config_id => config_id, :name => name, :nvt_oid => nvt_id).first else get_all(:config_id => config_id, :name => name).first end end
Public Instance Methods
config()
click to toggle source
# File lib/openvas-cli/vas_preference.rb, line 45 def config @config ||= VasConfig.get_by_id(@config_id) end
create_or_update()
click to toggle source
# File lib/openvas-cli/vas_preference.rb, line 65 def create_or_update unless @config_id errors[:config_id] << "Config_id required to save" return end req = Nokogiri::XML::Builder.new { |xml| xml.modify_config(:config_id => @config_id) { xml.preference { xml.nvt(:oid=>@nvt_id) if @nvt_id && !@nvt_id.empty? xml.name { xml.text(full_name) } xml.value { if @val_type == :boolean xml.text(Base64.encode64(@value ? "yes" : "no")) else xml.text(Base64.encode64(@value)) end } } } } begin VasPreference.connection.send_receive(req.doc) true rescue VasExceptions::CommandException => e errors[:command_failure] << e.message nil end end
full_name()
click to toggle source
# File lib/openvas-cli/vas_preference.rb, line 57 def full_name if @nvt_id && !@nvt_id.empty? "#{nvt_name}[#{@val_type_desc}]:#{@name}" else @name end end
name()
click to toggle source
# File lib/openvas-cli/vas_preference.rb, line 27 def name @name end
name=(val)
click to toggle source
# File lib/openvas-cli/vas_preference.rb, line 31 def name=(val) name_will_change! unless val == @name @name = val end
nvt()
click to toggle source
# File lib/openvas-cli/vas_preference.rb, line 49 def nvt @nvt ||= VasNVT.get_by_id(@nvt_id) end
val_choices()
click to toggle source
# File lib/openvas-cli/vas_preference.rb, line 53 def val_choices @val_choices ||= [] end
value()
click to toggle source
# File lib/openvas-cli/vas_preference.rb, line 36 def value @value end
value=(val)
click to toggle source
# File lib/openvas-cli/vas_preference.rb, line 40 def value=(val) value_will_change! unless val == @value @value = val end