Sha256: 9e01ebf9160678423e71d4e0c34e358fd87b6ff44664e94c5e47f0171e5138c4

Contents?: true

Size: 1.57 KB

Versions: 39

Compression:

Stored size: 1.57 KB

Contents

module CMSScanner
  module Finders
    # This class is designed to return a unique result such as a version
    # Note: Finders contained can return multiple results but the #run will only
    # returned the best finding
    class UniqueFinders < BaseFinders
      # @param [ Hash ] opts
      # @option opts [ Symbol ] :mode :mixed, :passive or :aggressive
      # @option opts [ Int ] :confidence_threshold  If a finding's confidence reaches this value,
      #                                             it will be returned as the best finding.
      #                                             Default is 100.
      #                                             If <= 0, all finders will be ran.
      #
      # @return [ Object, false ] The best finding or false if none
      def run(opts = {})
        opts[:confidence_threshold] ||= 100

        symbols_from_mode(opts[:mode]).each do |symbol|
          each do |finder|
            run_finder(finder, symbol, opts)

            next if opts[:confidence_threshold] <= 0

            findings.each { |f| return f if f.confidence >= opts[:confidence_threshold] }
          end
        end

        filter_findings
      end

      protected

      # @return [ Object, false ] The best finding or false if none
      def filter_findings
        # results are sorted by confidence ASC
        findings.sort_by!(&:confidence)

        # If all findings have the same confidence, false is returned
        return false if findings.size > 1 && findings.first.confidence == findings.last.confidence

        findings.last || false
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
cms_scanner-0.0.41.10 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.0.41.9 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.0.41.8 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.0.41.7 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.0.41.6 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.0.41.5 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.0.41.4 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.0.41.3 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.0.41.2 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.0.41.1 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.0.41.0 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.0.40.3 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.0.40.2 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.0.40.1 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.0.40 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.0.39.4 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.0.39.3 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.0.39.2 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.0.39.1 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.0.39.0 lib/cms_scanner/finders/unique_finders.rb