Sha256: 27cf22a1f26f39b8ff7331c186ccbc52c3b55cc35fd2178f4281550541f207d8

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

module CMSScanner
  # Scope system logic
  class Target < WebSite
    # @note Comments are deleted to avoid cache generation details
    #
    # @param [ Typhoeus::Response, String ] page
    #
    # @return [ String ] The md5sum of the page
    def self.page_hash(page)
      page = NS::Browser.get(page, followlocation: true) unless page.is_a?(Typhoeus::Response)

      Digest::MD5.hexdigest(page.body.gsub(/<!--.*?-->/m, ''))
    end

    # @return [ String ] The hash of the homepage
    def homepage_hash
      @homepage_hash ||= Target.page_hash(url)
    end

    # @note This is used to detect potential custom 404 responding with a 200
    # @return [ String ] The hash of a 404
    def error_404_hash
      @error_404_hash ||= Target.page_hash(non_existant_page_url)
    end

    # @return [ String ] The URL of an unlikely existant page
    def non_existant_page_url
      uri.join(Digest::MD5.hexdigest(rand(999_999_999).to_s) + '.html').to_s
    end

    # @param [ Typhoeus::Response, String ] page
    # @return [ Boolean ] Wether or not the page is a the homepage or a 404 based on its md5sum
    def homepage_or_404?(page)
      md5sum = Target.page_hash(page)

      md5sum == homepage_hash || md5sum == error_404_hash
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cms_scanner-0.0.14 lib/cms_scanner/target/hashes.rb
cms_scanner-0.0.13 lib/cms_scanner/target/hashes.rb
cms_scanner-0.0.12 lib/cms_scanner/target/hashes.rb