lib/wmap/host_tracker/primary_host.rb in wmap-2.4.6 vs lib/wmap/host_tracker/primary_host.rb in wmap-2.4.8

- old
+ new

@@ -3,20 +3,20 @@ # # A pure Ruby library for Internet web application discovery and tracking. # # Copyright (c) 2012-2015 Yang Li <yang.li@owasp.org> #++ -#require "singleton" # Implement singleton pattern to avoid race condition under parallel engine +require "singleton" # Implement singleton pattern to avoid race condition under parallel engine module Wmap class HostTracker # Class to differentiate the primary host-name from the potential aliases. This is needed in order to minimize the confusion on our final site inventory list, as it contains a large number of duplicates (aliases). More specifically, a filter could be built by using this class to track the primary url of a website. class PrimaryHost < Wmap::HostTracker include Wmap::Utils - #include Singleton + include Singleton attr_accessor :hosts_file, :verbose, :data_dir attr_reader :known_hosts, :known_ips # Initialize the instance variables @@ -33,16 +33,17 @@ de_duplicate end # Procedures to identify primary host-name from the site store SSL certificates. The assumption is that the CN used in the cert application must be primary hostname and used by the users. def update_from_site_store! - puts "Invoke internal procedures to update the primary host-name table from the site store." - begin - # Step 1 - update the prime host table based on the SSL cert CN fields + #begin + puts "Invoke internal procedures to update the primary host-name table from the site store." + # Step 1 - update the prime host table based on the SSL cert CN fields cns=Hash.new checker=Wmap::UrlChecker.new(:data_dir=>@data_dir) - my_tracker = Wmap::SiteTracker.new(:data_dir=>@data_dir) + my_tracker = Wmap::SiteTracker.instance + my_tracker.data_dir = @data_dir my_tracker.get_ssl_sites.map do |site| puts "Exam SSL enabled site entry #{site} ..." my_host=url_2_host(site) next if @known_hosts.key?(my_host) # add the logic to optimize the process puts "Pull SSL cert details on site: #{site}" @@ -60,23 +61,26 @@ end # Step 2 - Save the cache into the file self.save! checker=nil my_tracker=nil - rescue Exception => ee - puts "Exception on method #{__method__}: #{ee}" if @verbose - checker=nil - my_tracker=nil - return nil - end + #rescue Exception => ee + # puts "Exception on method #{__method__}: #{ee}" if @verbose + # checker=nil + # my_tracker=nil + # return nil + #end end alias_method :update!, :update_from_site_store! # Procedures to identify primary host-name from the site store redirection URLs. The assumption is that on site redirection, it must be directed to the well known primary site. def update_from_site_redirections! puts "Invoke internal procedures to update the primary host-name table from the site store." begin - urls=Wmap::SiteTracker.new(:data_dir=>@data_dir).get_redirection_urls + my_tracker=Wmap::SiteTracker.instance + my_tracker.data_dir=@data_dir + urls = my_tracker.get_redirection_urls + my_tracker = nil urls.map do |url| if is_url?(url) host=url_2_host(url) if is_fqdn?(host) ip=host_2_ip(host)