Class: Acunetix::Scan

Inherits:
Object
  • Object
show all
Defined in:
lib/acunetix/scan.rb

Overview

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.

Constant Summary collapse

SUPPORTED_TAGS =

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

[
  # attributes

  # simple tags
  :name, :short_name, :start_url, :start_time, :finish_time, :scan_time,
  :aborted, :responsive, :banner, :os, :web_server, :technologies, :ip,
  :fqdn, :operating_system, :mac_address, :netbios_name, :scan_start_time,
  :scan_stop_time
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml_node) ⇒ Scan

Accepts an XML node from Nokogiri::XML.



13
14
15
16
17
18
# 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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

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.



43
44
45
46
47
48
49
50
51
52
53
54
55
# 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

Instance Attribute Details

#xmlObject

Returns the value of attribute xml.



11
12
13
# File 'lib/acunetix/scan.rb', line 11

def xml
  @xml
end

Instance Method Details

#report_itemsObject



58
59
60
# File 'lib/acunetix/scan.rb', line 58

def report_items
  @xml.xpath('./ReportItems/ReportItem')
end

#respond_to?(method, include_private = false) ⇒ Boolean

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

Returns:

  • (Boolean)


33
34
35
36
# 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

#serviceObject



63
64
65
# File 'lib/acunetix/scan.rb', line 63

def service
  "port #{start_url_port}, #{banner}"
end

#start_url_hostObject Also known as: hostname



68
69
70
# File 'lib/acunetix/scan.rb', line 68

def start_url_host
  start_uri.host
end

#start_url_portObject



74
75
76
# File 'lib/acunetix/scan.rb', line 74

def start_url_port
  start_uri.port
end