Class: Risu::Parsers::Nessus::NessusDocument
- Inherits:
-
Object
- Object
- Risu::Parsers::Nessus::NessusDocument
- Defined in:
- lib/risu/parsers/nessus/nessus_document.rb
Overview
A Object to represents the Nessus XML file in memory
Instance Attribute Summary collapse
-
#new_tags ⇒ Object
Returns the value of attribute new_tags.
Instance Method Summary collapse
-
#fix_ips ⇒ Object
Fixes the ip field if nil and replaces it with the name if its an ip.
-
#initialize(document) ⇒ NessusDocument
constructor
Creates a instance of the NessusDocument class.
-
#parse ⇒ Object
Invokes the SAX parser on the XML document.
-
#valid? ⇒ Boolean
Checks the validness of a NessusDocument.
Constructor Details
#initialize(document) ⇒ NessusDocument
Creates a instance of the NessusDocument class
31 32 33 34 |
# File 'lib/risu/parsers/nessus/nessus_document.rb', line 31 def initialize document @document = document @new_tags = Array.new end |
Instance Attribute Details
#new_tags ⇒ Object
Returns the value of attribute new_tags.
28 29 30 |
# File 'lib/risu/parsers/nessus/nessus_document.rb', line 28 def @new_tags end |
Instance Method Details
#fix_ips ⇒ Object
Fixes the ip field if nil and replaces it with the name if its an ip
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/risu/parsers/nessus/nessus_document.rb', line 77 def fix_ips @hosts = Host.all @hosts.each do |host| if host.ip == nil begin ip = IPAddr.new host.name host.ip = ip.to_string host.save rescue ArgumentError next end end end end |
#parse ⇒ Object
Invokes the SAX parser on the XML document
66 67 68 69 70 71 72 73 74 |
# File 'lib/risu/parsers/nessus/nessus_document.rb', line 66 def parse @parser = LibXML::XML::SaxParser.file @document @parser.callbacks = NessusSaxListener.new @parser.parse #require 'pry' #binding.pry @new_tags == @parser.callbacks. end |
#valid? ⇒ Boolean
Checks the validness of a NessusDocument
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/risu/parsers/nessus/nessus_document.rb', line 39 def valid? parser = nil if File.exist?(@document) parser = LibXML::XML::Parser.file @document elsif @document.class == "String" parser = LibXML::XML::Parser.string @document else return false end doc = parser.parse if doc.root.name == nil return false end if doc.root.name == "NessusClientData_v2" #.nessus v2 return true elsif doc.root.name == "NessusClientData" #.nessus v1 return false else return false end end |