class OpenvasCli::VasConfig

Attributes

comment[RW]
families_grow[RW]
in_use[RW]
name[RW]
rules_grow[RW]

Public Class Methods

copy_config(id, name, comment = nil) click to toggle source
# File lib/openvas-cli/vas_config.rb, line 84
def self.copy_config(id, name, comment = nil)
  begin
    req = Nokogiri::XML::Builder.new { |xml|
      xml.create_config {
        xml.copy { xml.text(id) }
        xml.name { xml.text(name) }
        if comment && !comment.empty?
          xml.comment { xml.text(comment) }
        end
      }
    }
    
    resp = connection.send_receive(req.doc)
    new_id = extract_value_from("/create_config_response/@id", resp)
    
    get_all(:id => new_id, :show_details => true)[0]
  rescue VasExceptions::CommandException => e
    nil
  end
end
get_all(options = {}) click to toggle source
# File lib/openvas-cli/vas_config.rb, line 41
def self.get_all(options = {})
  params = {:sort_field  => "name"}
  if options[:show_details] && options[:show_details] == true
    params.merge!({:families => "1", :preferences => "1"})
  end    
  params[:config_id] = options[:id] if options[:id]
  req = Nokogiri::XML::Builder.new { |xml|
    xml.get_configs(params)
  }
  ret = []
  
  begin
    resp = connection.send_receive(req.doc)
    

    resp.xpath("/get_configs_response/config").each { |xml|
      cfg               = VasConfig.new
      cfg.id            = extract_value_from("@id", xml)
      cfg.name          = extract_value_from("name", xml)
      cfg.comment       = extract_value_from("comment", xml)
      cfg.families_grow = extract_value_from("family_count/growing", xml).to_i > 0
      cfg.rules_grow    = extract_value_from("nvt_count/growing", xml).to_i > 0
      cfg.in_use        = extract_value_from("in_use", xml).to_i > 0
      
      xml.xpath("tasks/task").each { |t| cfg.tasks << VasTask.from_xml_node(t) }
      xml.xpath("families/family").each { |f| cfg.families << VasNVTFamily.from_xml_node(f) }
      xml.xpath("preferences/preference").each { |p| 
        p = VasPreference.from_xml_node(p) 
        p.config_id = cfg.id
        p.reset_changes
        cfg.preferences << p
      }
      
      cfg.reset_changes
      
      ret << cfg
    }
  rescue Exception => e
  end

  ret
end
new(attributes = {}) click to toggle source
# File lib/openvas-cli/vas_config.rb, line 21
def initialize(attributes = {})
  @id = attributes[:id] if attributes[:id]
  @name = attributes[:name] if attributes[:name]
  @comment = attributes[:comment] if attributes[:comment] 
  @families_grow = attributes[:families_grow] if attributes[:families_grow]
  @rules_grow = attributes[:rules_grow] if attributes[:rules_grow]
end

Public Instance Methods

create_or_update() click to toggle source
# File lib/openvas-cli/vas_config.rb, line 105
def create_or_update
  @previously_changed = changes
  begin
    preferences.each{ |p| p.save! if p.changed? }
    @changed_attributes.clear
    
    self
  rescue Exception => e
    errors[:command] << e.message
    nil
  end
end
delete_record() click to toggle source
# File lib/openvas-cli/vas_config.rb, line 118
def delete_record
  req = Nokogiri::XML::Builder.new { |xml|
    xml.delete_config(:config_id => @id)
  }
  
  begin
    VasConfig.connection.send_receive(req.doc)
    self
  rescue Exception => e
    errors[:command] << e.message
    nil
  end
end
families() click to toggle source
# File lib/openvas-cli/vas_config.rb, line 37
def families
  @families ||= []
end
preferences() click to toggle source
# File lib/openvas-cli/vas_config.rb, line 33
def preferences
  @preferences ||= []
end
tasks() click to toggle source
# File lib/openvas-cli/vas_config.rb, line 29
def tasks
  @tasks ||= []
end