dmarc_parser 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8f971fb0c37417274aff8a1890e225a33d103954
4
+ data.tar.gz: cd7687feb50dc597f427f7fef701da4bf74fa54b
5
+ SHA512:
6
+ metadata.gz: e00369d4740a7822f461eac5405c78fa66abccfd606465e76bc59421fd33622f1732e9ff0dcb693d8237ead86b7f30bde9644cf1173def1a3c17f76805a2e82b
7
+ data.tar.gz: 4094cee4b99de7d54a72e7c36a02c6cb95c351648cf97276b78053d0d3ca91d008d211429f3def8cd488d1301c49ba79871ab5f1a6b7970b51c5ba60e9991d39
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.3
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in dmarc_parser.gemspec
4
+ gemspec
@@ -0,0 +1,47 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dmarc_parser (0.1.0)
5
+ nokogiri
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.3)
11
+ diff-lcs (1.4.4)
12
+ method_source (1.0.0)
13
+ mini_portile2 (2.4.0)
14
+ nokogiri (1.10.9)
15
+ mini_portile2 (~> 2.4.0)
16
+ pry (0.13.1)
17
+ coderay (~> 1.1)
18
+ method_source (~> 1.0)
19
+ rake (10.5.0)
20
+ rb-readline (0.5.5)
21
+ rspec (3.9.0)
22
+ rspec-core (~> 3.9.0)
23
+ rspec-expectations (~> 3.9.0)
24
+ rspec-mocks (~> 3.9.0)
25
+ rspec-core (3.9.2)
26
+ rspec-support (~> 3.9.3)
27
+ rspec-expectations (3.9.2)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.9.0)
30
+ rspec-mocks (3.9.1)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.9.0)
33
+ rspec-support (3.9.3)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ bundler (~> 2.0)
40
+ dmarc_parser!
41
+ pry
42
+ rake (~> 10.0)
43
+ rb-readline
44
+ rspec (~> 3.0)
45
+
46
+ BUNDLED WITH
47
+ 2.0.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 D Salko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,57 @@
1
+ # DMARC Parser
2
+
3
+ Parses DMARC XML reports for future processing.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'dmarc_parser'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install dmarc_parser
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ report = DmarcParser::Report.new(xml_string)
25
+ ```
26
+
27
+ Getting metadata:
28
+
29
+ ```
30
+ report.metadata
31
+ ```
32
+
33
+ Getting DMARC policy information:
34
+
35
+ ```
36
+ report.policy
37
+ ```
38
+
39
+ Getting collection of report records:
40
+
41
+ ```
42
+ report.records
43
+ ```
44
+
45
+ ## Development
46
+
47
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
48
+
49
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at https://github.com/DSalko/dmarc_parser.
54
+
55
+ ## License
56
+
57
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dmarc_parser"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,47 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "dmarc_parser/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dmarc_parser"
8
+ spec.version = DmarcParser::VERSION
9
+ spec.authors = ["Dmytro Salko"]
10
+ spec.email = ["dm.salko@gmail.com"]
11
+ spec.required_ruby_version = '>= 2.3'
12
+
13
+ spec.summary = %q{Reads and parses DMARC XML reports.}
14
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
15
+ spec.homepage = "https://github.com/DSalko/dmarc_parser"
16
+ spec.license = "MIT"
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ if spec.respond_to?(:metadata)
21
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
22
+
23
+ spec.metadata["homepage_uri"] = spec.homepage
24
+ spec.metadata["source_code_uri"] = "https://github.com/DSalko/dmarc_parser"
25
+ spec.metadata["changelog_uri"] = "https://github.com/DSalko/dmarc_parser/README.md"
26
+ else
27
+ raise "RubyGems 2.0 or newer is required to protect against " \
28
+ "public gem pushes."
29
+ end
30
+
31
+ # Specify which files should be added to the gem when it is released.
32
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
33
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
34
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
35
+ end
36
+ spec.bindir = "exe"
37
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
38
+ spec.require_paths = ["lib"]
39
+
40
+ spec.add_development_dependency "bundler", "~> 2.0"
41
+ spec.add_development_dependency "rake", "~> 10.0"
42
+ spec.add_development_dependency "rspec", "~> 3.0"
43
+ spec.add_development_dependency "rb-readline"
44
+ spec.add_development_dependency "pry"
45
+
46
+ spec.add_dependency "nokogiri"
47
+ end
@@ -0,0 +1,7 @@
1
+ require "dmarc_parser/version"
2
+
3
+ module DmarcParser
4
+ class Error < StandardError; end
5
+
6
+ require "dmarc_parser/report"
7
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ require 'nokogiri'
3
+ require_relative 'xml_helper'
4
+
5
+ module DmarcParser
6
+ class AuthResult
7
+ include XmlHelper
8
+ ATTRIBUTES = [:type, :domain, :result, :selector]
9
+
10
+ ATTRIBUTES.each do |attr|
11
+ attr_accessor attr
12
+ end
13
+
14
+ def initialize(node)
15
+ @node = node
16
+ self.type = node.name
17
+ self.domain = get_text('domain')
18
+ self.result = get_text('result')
19
+ self.selector = get_text('selector')
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ require 'nokogiri'
3
+ require_relative 'xml_helper'
4
+
5
+ module DmarcParser
6
+ class Metadata
7
+ include XmlHelper
8
+ ATTRIBUTES = [:org_name, :email, :extra_contact_info, :report_id, :begin_at, :end_at]
9
+
10
+ ATTRIBUTES.each do |attr|
11
+ attr_accessor attr
12
+ end
13
+
14
+ def initialize(node)
15
+ @node = node
16
+ self.org_name = get_text("feedback/report_metadata/org_name")
17
+ self.email = get_text("feedback/report_metadata/email")
18
+ self.extra_contact_info = get_text("feedback/report_metadata/extra_contact_info")
19
+ self.report_id = get_text("feedback/report_metadata/report_id")
20
+ self.begin_at = get_timestamp("feedback/report_metadata/date_range/begin")
21
+ self.end_at = get_timestamp("feedback/report_metadata/date_range/end")
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ require 'nokogiri'
3
+ require_relative 'xml_helper'
4
+
5
+ module DmarcParser
6
+ class Policy
7
+ include XmlHelper
8
+ ATTRIBUTES = [:domain, :adkim, :aspf, :p, :sp, :pct]
9
+
10
+ ATTRIBUTES.each do |attr|
11
+ attr_accessor attr
12
+ end
13
+
14
+ def initialize(node)
15
+ @node = node
16
+ ATTRIBUTES.each do |attr|
17
+ self.send("#{attr}=", get_text("feedback/policy_published/#{attr}"))
18
+ end
19
+ self.pct = self.pct ? self.pct.to_i : nil
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+ require 'nokogiri'
3
+ require_relative 'xml_helper'
4
+ require_relative 'auth_result'
5
+
6
+ module DmarcParser
7
+ class Record
8
+ include XmlHelper
9
+ ATTRIBUTES = [:source_ip, :count, :disposition, :dkim, :spf, :header_from, :auth_results]
10
+
11
+ ATTRIBUTES.each do |attr|
12
+ attr_accessor attr
13
+ end
14
+
15
+ def initialize(node)
16
+ @node = node
17
+ self.source_ip = get_text('row/source_ip')
18
+ self.count = get_int('row/count')
19
+ self.disposition = get_text('row/policy_evaluated/disposition')
20
+ self.dkim = get_text('row/policy_evaluated/dkim')
21
+ self.spf = get_text('row/policy_evaluated/spf')
22
+ self.header_from = get_text('identifiers/header_from')
23
+ self.auth_results = node.xpath('auth_results/*').map do |auth_results_node|
24
+ DmarcParser::AuthResult.new(auth_results_node)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ require 'nokogiri'
2
+ require_relative 'metadata'
3
+ require_relative 'policy'
4
+ require_relative 'record'
5
+
6
+ module DmarcParser
7
+ class Report
8
+ def initialize(xml)
9
+ @xml = xml
10
+ @node = Nokogiri::XML(xml)
11
+ end
12
+
13
+ def metadata
14
+ @metadata ||= DmarcParser::Metadata.new(@node)
15
+ end
16
+
17
+ def policy
18
+ @policy ||=DmarcParser::Policy.new(@node)
19
+ end
20
+
21
+ def records
22
+ @records ||= @node.xpath('feedback/record').map do |node|
23
+ DmarcParser::Record.new(node)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module DmarcParser
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,19 @@
1
+ require 'nokogiri'
2
+
3
+ module DmarcParser
4
+ module XmlHelper
5
+ def get_text(xpath)
6
+ @node.xpath(xpath).first.text rescue nil
7
+ end
8
+
9
+ def get_timestamp(xpath)
10
+ value = get_text(xpath)
11
+ value ? Time.at(value.to_i) : nil
12
+ end
13
+
14
+ def get_int(xpath)
15
+ value = get_text(xpath)
16
+ value ? value.to_i : nil
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dmarc_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dmytro Salko
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-07-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rb-readline
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: nokogiri
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - dm.salko@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - dmarc_parser.gemspec
115
+ - lib/dmarc_parser.rb
116
+ - lib/dmarc_parser/auth_result.rb
117
+ - lib/dmarc_parser/metadata.rb
118
+ - lib/dmarc_parser/policy.rb
119
+ - lib/dmarc_parser/record.rb
120
+ - lib/dmarc_parser/report.rb
121
+ - lib/dmarc_parser/version.rb
122
+ - lib/dmarc_parser/xml_helper.rb
123
+ homepage: https://github.com/DSalko/dmarc_parser
124
+ licenses:
125
+ - MIT
126
+ metadata:
127
+ homepage_uri: https://github.com/DSalko/dmarc_parser
128
+ source_code_uri: https://github.com/DSalko/dmarc_parser
129
+ changelog_uri: https://github.com/DSalko/dmarc_parser/README.md
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '2.3'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 2.6.8
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: Reads and parses DMARC XML reports.
150
+ test_files: []