Class: RubyNessus::Parse

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-nessus/parse.rb

Instance Method Summary collapse

Constructor Details

#initialize(file = nil, options = {}) {|@xml_parser| ... } ⇒ Parse

Returns a new instance of Parse.

Yields:

  • (@xml_parser)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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

Instance Method Details

#detect_versionObject

Try to detection version with the XML given



36
37
38
39
40
41
42
43
44
# 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

#scanObject

Retrive scan from file



31
32
33
# File 'lib/ruby-nessus/parse.rb', line 31

def scan
  @xml_parser
end