Class: Dmarcer::Parser
- Inherits:
-
Object
- Object
- Dmarcer::Parser
- Defined in:
- lib/dmarcer.rb
Instance Method Summary collapse
- #date_range ⇒ Object
- #dkim_auth_failure_records ⇒ Object
- #id ⇒ Object
- #identifiers ⇒ Object
-
#initialize(input_file) ⇒ Parser
constructor
A new instance of Parser.
- #org_name ⇒ Object
- #print_report ⇒ Object
- #record_by_identifier(identifier) ⇒ Object
- #records ⇒ Object
- #spf_auth_failure_records ⇒ Object
- #spf_domain_ip_hash ⇒ Object
Constructor Details
#initialize(input_file) ⇒ Parser
Returns a new instance of Parser.
7 8 9 |
# File 'lib/dmarcer.rb', line 7 def initialize(input_file) @input_file = input_file end |
Instance Method Details
#date_range ⇒ Object
23 24 25 26 27 |
# File 'lib/dmarcer.rb', line 23 def date_range t_begin = Time.at(data..date_range.begin.content.to_i) t_end = Time.at(data..date_range.end.content.to_i) t_begin..t_end end |
#dkim_auth_failure_records ⇒ Object
37 38 39 |
# File 'lib/dmarcer.rb', line 37 def dkim_auth_failure_records records.select { |r| r.auth_failed_dkim_domains.any? } end |
#id ⇒ Object
29 30 31 |
# File 'lib/dmarcer.rb', line 29 def id data..report_id.content end |
#identifiers ⇒ Object
15 16 17 |
# File 'lib/dmarcer.rb', line 15 def identifiers data.record.map { |r| r.identifiers.header_from.content }.uniq.sort end |
#org_name ⇒ Object
19 20 21 |
# File 'lib/dmarcer.rb', line 19 def org_name data..org_name.content end |
#print_report ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# 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) ⇒ Object
11 12 13 |
# File 'lib/dmarcer.rb', line 11 def record_by_identifier(identifier) data.record.select { |r| r.identifiers.header_from.content == identifier } end |
#records ⇒ Object
33 34 35 |
# File 'lib/dmarcer.rb', line 33 def records @records ||= @data.record.map { |r| Record.new r } end |
#spf_auth_failure_records ⇒ Object
41 42 43 |
# 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 ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# 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 |