class Dmarcer::Parser
Public Class Methods
new(input_file)
click to toggle source
# File lib/dmarcer.rb, line 7 def initialize(input_file) @input_file = input_file end
Public Instance Methods
date_range()
click to toggle source
# File lib/dmarcer.rb, line 23 def date_range t_begin = Time.at(data.report_metadata.date_range.begin.content.to_i) t_end = Time.at(data.report_metadata.date_range.end.content.to_i) t_begin..t_end end
dkim_auth_failure_records()
click to toggle source
# File lib/dmarcer.rb, line 37 def dkim_auth_failure_records records.select { |r| r.auth_failed_dkim_domains.any? } end
id()
click to toggle source
# File lib/dmarcer.rb, line 29 def id data.report_metadata.report_id.content end
identifiers()
click to toggle source
# File lib/dmarcer.rb, line 15 def identifiers data.record.map { |r| r.identifiers.header_from.content }.uniq.sort end
org_name()
click to toggle source
# File lib/dmarcer.rb, line 19 def org_name data.report_metadata.org_name.content end
print_report()
click to toggle source
# File lib/dmarcer.rb, line 57 def print_report puts "Report Organization: #{org_name}" puts "Report ID: #{id}" puts "Date Range: #{date_range}" puts '' puts '------------------ SPF Failures ------------------' # spf_auth_failure_records.each do |r| # puts "Source IP: #{r.source_ip} (#{lookup(r.source_ip)})" # puts "Auth failed SPF domains: #{r.auth_failed_spf_domains.join(', ')}" # puts '' # end spf_domain_ip_hash.each do |domain, ips| puts domain ips.each { |ip| puts " #{lookup(ip)} [#{ip}]" } puts '' end puts '------------------ DKIM Failures ------------------' dkim_auth_failure_records.each do |r| puts "Source IP: #{r.source_ip} (#{lookup(r.source_ip)})" unless r.auth_failed_dkim_domains == ['evertrue.com'] puts "Auth failed DKIM domains: #{r.auth_failed_dkim_domains.join(', ')}" puts '' end end end
record_by_identifier(identifier)
click to toggle source
# File lib/dmarcer.rb, line 11 def record_by_identifier(identifier) data.record.select { |r| r.identifiers.header_from.content == identifier } end
records()
click to toggle source
# File lib/dmarcer.rb, line 33 def records @records ||= @data.record.map { |r| Record.new r } end
spf_auth_failure_records()
click to toggle source
# File lib/dmarcer.rb, line 41 def spf_auth_failure_records records.select { |r| r.auth_failed_spf_domains.any? } end
spf_domain_ip_hash()
click to toggle source
# File lib/dmarcer.rb, line 45 def spf_domain_ip_hash spf_auth_failure_records.each_with_object({}) do |r, m| r.auth_failed_spf_domains.each do |d| if m[d] m[d] << r.source_ip else m[d] = [r.source_ip] end end end end
Private Instance Methods
data()
click to toggle source
# File lib/dmarcer.rb, line 92 def data @data ||= Nokogiri::Slop(File.read(@input_file)).feedback end
lookup(ip)
click to toggle source
# File lib/dmarcer.rb, line 85 def lookup(ip) return Resolv.getname(ip) if ip !~ Resolv::IPv6::Regex 'err IPv6 address' rescue Resolv::ResolvError nil end