lib/wmap/host_tracker/primary_host.rb in wmap-2.5.5 vs lib/wmap/host_tracker/primary_host.rb in wmap-2.5.6
- old
+ new
@@ -14,23 +14,21 @@
# 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
- attr_accessor :hosts_file, :verbose, :data_dir
- attr_reader :known_hosts, :known_ips
+ attr_accessor :hosts_file, :verbose, :data_dir, :known_hosts, :known_ips
# Initialize the instance variables
def initialize (params = {})
@verbose=params.fetch(:verbose, false)
@data_dir=params.fetch(:data_dir, File.dirname(__FILE__)+'/../../../data/')
# Set default instance variables
- @file_hosts=@data_dir + 'prime_hosts'
- file=params.fetch(:hosts_file, @file_hosts)
+ @hosts_file=params.fetch(:hosts_file, @data_dir + 'prime_hosts')
# Initialize the instance variables
- File.write(@file_hosts, "") unless File.exist?(@file_hosts)
- @known_hosts=load_known_hosts_from_file(file)
+ File.write(@hosts_file, "") unless File.exist?(@hosts_file)
+ @known_hosts=load_known_hosts_from_file(@hosts_file)
@known_ips=Hash.new
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.
@@ -39,11 +37,12 @@
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.instance
- my_tracker.data_dir = @data_dir
+ my_tracker.sites_file = @data_dir + "sites"
+ my_tracker.load_site_stores_from_file
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}"
@@ -75,12 +74,13 @@
# 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
my_tracker=Wmap::SiteTracker.instance
- my_tracker.data_dir=@data_dir
+ my_tracker.sites_file=@data_dir + "sites"
+ my_tracker.load_site_stores_from_file
urls = my_tracker.get_redirection_urls
- my_tracker = nil
+ 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)