class Acunetix::Scan

This class represents each of the /ScanGroup/Scan elements in the Acunetix XML document.

It provides a convenient way to access the information scattered all over the XML in attributes and nested tags.

Instead of providing separate methods for each supported property we rely on Ruby's method_missing to do most of the work.

Constants

SUPPORTED_TAGS

List of supported tags. They are all descendents of the ./Scan node.

Attributes

xml[RW]

Public Class Methods

new(xml_node) click to toggle source

Accepts an XML node from Nokogiri::XML.

# File lib/acunetix/scan.rb, line 13
def initialize(xml_node)
  @xml = xml_node
  unless @xml.name == "Scan"
    raise "Invalid XML; root node must be called 'Scan'"
  end
end

Public Instance Methods

hostname()
Alias for: start_url_host
method_missing(method, *args) click to toggle source

This method is invoked by Ruby when a method that is not defined in this instance is called.

In our case we inspect the @method@ parameter and try to find the corresponding <tag/> element inside the ./Scan child.

Calls superclass method
# File lib/acunetix/scan.rb, line 43
def method_missing(method, *args)
  # We could remove this check and return nil for any non-recognized tag.
  # The problem would be that it would make tricky to debug problems with
  # typos. For instance: <>.potr would return nil instead of raising an
  # exception
  super and return unless SUPPORTED_TAGS.include?(method)

  if tag = xml.at_xpath("./#{tag_name_for_method(method)}")
    tag.text
  else
    nil
  end
end
report_items() click to toggle source
# File lib/acunetix/scan.rb, line 58
def report_items
  @xml.xpath('./ReportItems/ReportItem')
end
respond_to?(method, include_private=false) click to toggle source

This allows external callers (and specs) to check for implemented properties

Calls superclass method
# File lib/acunetix/scan.rb, line 33
def respond_to?(method, include_private=false)
  return true if SUPPORTED_TAGS.include?(method.to_sym)
  super
end
service() click to toggle source
# File lib/acunetix/scan.rb, line 63
def service
  "port #{start_url_port}, #{banner}"
end
start_url_host() click to toggle source
# File lib/acunetix/scan.rb, line 68
def start_url_host
  start_uri.host
end
Also aliased as: hostname
start_url_port() click to toggle source
# File lib/acunetix/scan.rb, line 74
def start_url_port
  start_uri.port
end

Private Instance Methods

start_uri() click to toggle source
# File lib/acunetix/scan.rb, line 80
def start_uri
  @start_uri ||= URI::parse(start_url)
end
tag_name_for_method(method) click to toggle source
# File lib/acunetix/scan.rb, line 84
def tag_name_for_method(method)
  # Any fields where a simple .camelcase() won't work we need to translate,
  # this includes acronyms (e.g. :scan_url would become 'ScanUrl').
  {
    start_url: 'StartURL'
  }[method] || method.to_s.camelcase
end