Sha256: 57fbf000c15ad94579bbb57ddfdfd6894578a3fb912f3fd8d015caecf8a02631

Contents?: true

Size: 1.77 KB

Versions: 32

Compression:

Stored size: 1.77 KB

Contents

module Nikto
  # This class represents the <scandetails> element in the Nikto 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.
  class Scan
    # Accepts an XML node from Nokogiri::XML.
    def initialize(xml_node)
      @xml = xml_node
    end

    # List of supported tags. They can be attributes, simple descendants or
    # collections (e.g. <references/>, <tags/>)
    def supported_tags
      [
        # attributes
        :targetip, :targethostname, :targetport, :targetbanner, :starttime,
        :sitename, :siteip, :hostheader, :errors, :checks, :filename
      ]
    end

    # This allows external callers (and specs) to check for implemented
    # properties
    def respond_to?(method, include_private=false)
      return true if supported_tags.include?(method.to_sym)
      super
    end

    # 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
    # attribute, simple descendent or collection that it maps to in the XML
    # tree.
    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
      unless supported_tags.include?(method)
        super
        return
      end
      method_name = method.to_s
      return @xml.attributes[method_name].value if @xml.attributes.key?(method_name)
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
dradis-nikto-4.15.0 lib/nikto/scan.rb
dradis-nikto-4.14.0 lib/nikto/scan.rb
dradis-nikto-4.13.0 lib/nikto/scan.rb
dradis-nikto-4.11.0 lib/nikto/scan.rb
dradis-nikto-4.10.0 lib/nikto/scan.rb
dradis-nikto-4.9.0 lib/nikto/scan.rb
dradis-nikto-4.8.0 lib/nikto/scan.rb
dradis-nikto-4.7.0 lib/nikto/scan.rb
dradis-nikto-4.6.0 lib/nikto/scan.rb
dradis-nikto-4.5.0 lib/nikto/scan.rb
dradis-nikto-4.4.0 lib/nikto/scan.rb
dradis-nikto-4.3.0 lib/nikto/scan.rb
dradis-nikto-4.2.0 lib/nikto/scan.rb
dradis-nikto-4.1.0 lib/nikto/scan.rb
dradis-nikto-4.0.0 lib/nikto/scan.rb
dradis-nikto-3.22.0 lib/nikto/scan.rb
dradis-nikto-3.21.0 lib/nikto/scan.rb
dradis-nikto-3.20.0 lib/nikto/scan.rb
dradis-nikto-3.19.0 lib/nikto/scan.rb
dradis-nikto-3.18.0 lib/nikto/scan.rb