class Nikto::XML
Represents an nikto XML
file or XML
data.
## Example
require 'nikto/xml' Nikto::XML.open('nikto.xml') do |xml| xml.each_scan_details do |scan_details| puts "#{scan_details.site_name}" scan_details.each_item do |item| puts " #{item.uri}" puts puts " #{item.description}" puts end end end
Attributes
The path to the XML
file.
@return [String, nil]
Public Class Methods
Creates a new XML
object.
@param [Nokogiri::XML] doc
The parsed XML document.
@param [String, nil] path
The path to the XML file.
@yield [xml]
If a block is given, it will be passed the newly created XML parser.
@yieldparam [XML] xml
The newly created XML parser.
@api private
# File lib/nikto/xml.rb, line 58 def initialize(doc, path: nil) @doc = doc @path = File.expand_path(path) if path yield self if block_given? end
Opens an parses an XML
file.
@param [String] path
The path to the XML file.
@yield [xml]
If a block is given, it will be passed the newly created XML parser.
@yieldparam [XML] xml
The newly created XML parser.
@return [XML]
The parsed XML.
@api public
# File lib/nikto/xml.rb, line 105 def self.open(path,&block) path = File.expand_path(path) doc = Nokogiri::XML(File.open(path)) new(doc, path: path, &block) end
Parses the given XML
String.
@param [String] xml
The XML String.
@yield [xml]
If a block is given, it will be passed the newly created XML parser.
@yieldparam [XML] xml
The newly created XML parser.
@return [XML]
The parsed XML.
@api public
# File lib/nikto/xml.rb, line 83 def self.parse(xml,&block) new(Nokogiri::XML(xml),&block) end
Public Instance Methods
Parses each ‘scandetails` child element.
@yield [scan_details]
If a block is given, it will be yielded each scan details object.
@yieldparam [ScanDetails] scan_details
A scan details object.
@return [Enumerator]
If no block is given, an Enumerator will be returned.
# File lib/nikto/xml.rb, line 184 def each_scan_details return enum_for(__method__) unless block_given? @doc.xpath('/niktoscan/scandetails').each do |node| yield ScanDetails.new(node) end end
The ‘hoststest` value.
@return [Integer]
The parsed value of the `hoststest` attribute.
# File lib/nikto/xml.rb, line 118 def hosts_test @hosts_test ||= @doc.root['@hoststest'].to_i end
Additional command-line options passed to ‘nikto`.
@return [String]
The value of the `options` attribute.
# File lib/nikto/xml.rb, line 128 def options @doc.root['options'] end
The scan details.
@return [Array<ScanDetails>]
# File lib/nikto/xml.rb, line 197 def scan_details each_scan_details.to_a end
The duration of the scan.
@return [String]
The value of the `scanelapsed` attribute.
# File lib/nikto/xml.rb, line 158 def scan_elapsed @doc.root['scanelapsed'] end
When the scan completed.
@return [Time]
The parsed value `scanned` attribute.
# File lib/nikto/xml.rb, line 148 def scan_end @scan_end ||= Time.parse(@doc.root['scanend']) end
When the scan started.
@return [Time]
The parsed value of the `scanstart` attribute.
# File lib/nikto/xml.rb, line 138 def scan_start @scan_start ||= Time.parse(@doc.root['scanstart']) end
The first scan details object.
@return [ScanDetails, nil]
# File lib/nikto/xml.rb, line 210 def target each_target.first end
Converts the XML
object to a String.
@return [String]
The path to the XML if {#path} is set, or the XML if the XML was parsed from a String.
# File lib/nikto/xml.rb, line 221 def to_s if @path @path else @doc.to_s end end