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

doc[R]

The parsed XML document.

@return [Nokogiri::XML]

@api private

path[R]

The path to the XML file.

@return [String, nil]

Public Class Methods

new(doc, path: nil) { |self| ... } click to toggle source

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
open(path,&block) click to toggle source

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
parse(xml,&block) click to toggle source

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

each_scan_details() { |scan_details| ... } click to toggle source

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
Also aliased as: each_target
each_target()
Alias for: each_scan_details
hosts_test() click to toggle source

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
nikto_xml_version() click to toggle source

The Nikto XML schema version.

@return [String]

The value of the `nxmlversion` attribute.
# File lib/nikto/xml.rb, line 168
def nikto_xml_version
  @doc.root['nxmlversion']
end
options() click to toggle source

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
scan_details() click to toggle source

The scan details.

@return [Array<ScanDetails>]

# File lib/nikto/xml.rb, line 197
def scan_details
  each_scan_details.to_a
end
Also aliased as: targets
scan_elapsed() click to toggle source

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
scan_end() click to toggle source

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
scan_start() click to toggle source

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
target() click to toggle source

The first scan details object.

@return [ScanDetails, nil]

# File lib/nikto/xml.rb, line 210
def target
  each_target.first
end
targets()
Alias for: scan_details
to_s() click to toggle source

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