class RubyNessus::Parse

Public Class Methods

new(file = nil, options = {}) { |xml_parser| ... } click to toggle source
# File lib/ruby-nessus/parse.rb, line 13
def initialize(file = nil, options = {}, &block)
  doc = file ? File.read(file) : options[:xml]
  @xml = Nokogiri::XML.parse(doc)
  @version = options[:version] || detect_version

  @xml_parser = case @version
                when 1
                  Version1::XML.new(@xml)
                when 2
                  Version2::XML.new(@xml)
                else
                  raise 'Error: Supported .Nessus Version are 1 and 2.'
                end

  yield(@xml_parser) if block
end

Public Instance Methods

detect_version() click to toggle source

Try to detection version with the XML given

# File lib/ruby-nessus/parse.rb, line 36
def detect_version
  if @xml.at('NessusClientData')
    1
  elsif @xml.at('NessusClientData_v2')
    2
  else
    raise 'Error: Supported .Nessus Version are 1 and 2.'
  end
end
scan() click to toggle source

Retrive scan from file

# File lib/ruby-nessus/parse.rb, line 31
def scan
  @xml_parser
end