dns-monitor 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 65b7d37e5226c986ff4203bbdc37095b6c5b8468aecfdf7bc1e5516d8ea98ec8
4
+ data.tar.gz: b56437c517597311556fa0e18ff76d2eb077e85d9726ccc344eda45dcd50f5a4
5
+ SHA512:
6
+ metadata.gz: 67f4049c13cc79dfc99edbdf8fa0806dc934014fb6809016e7ce37901972719c69f4182a4ad3934465edb06a6a8f3b1840b7cc4c2ebfd145882c95d02e61101f
7
+ data.tar.gz: 8eca6a23137098f6855ce7ebb8381787421ce57dc5e27e035db8a074cd4bbc89fca4fc68d0639e5da066c3b8671848bbaada842ebca1402b3b8955ab6f9981f2
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ *.sw*
@@ -0,0 +1 @@
1
+ 2.6.3
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.4.2
7
+ before_install: gem install bundler -v 1.16.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at dmerand@explo.org. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in dns-monitor.gemspec
6
+ gemspec
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dns-monitor (0.1.7)
5
+ easy_diff (~> 1.0.0)
6
+ sqlite3 (~> 1.4.2)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ coderay (1.1.2)
12
+ easy_diff (1.0.0)
13
+ method_source (0.9.2)
14
+ minitest (5.14.0)
15
+ pry (0.12.2)
16
+ coderay (~> 1.1.0)
17
+ method_source (~> 0.9.0)
18
+ rake (13.0.1)
19
+ sqlite3 (1.4.2)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ bundler (~> 2.0.2)
26
+ dns-monitor!
27
+ minitest (~> 5.0)
28
+ pry (~> 0.12.2)
29
+ rake (~> 13.0)
30
+
31
+ BUNDLED WITH
32
+ 2.0.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Donald Merand
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,110 @@
1
+ # DNS::Monitor
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/dns-monitor.svg)](https://badge.fury.io/rb/dns-monitor)
4
+
5
+ The point of this gem is to monitor your hosts for (unwanted) DNS changes. The `dns-monitor` app is designed to be run as a CRON job. It takes a return-delimited text file listing domain names, and checks an [RDAP](https://www.icann.org/rdap) database (which you can specify) for JSON entries that match. You will get an error, optionally by GChat, if you encounter a changed entry.
6
+
7
+ If you don't think this is something you need, perhaps give [this article](https://krebsonsecurity.com/2019/02/a-deep-dive-on-the-recent-widespread-dns-hijacking-attacks/) a read.
8
+
9
+
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'dns-monitor'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install dns-monitor
26
+
27
+
28
+
29
+ ## Usage
30
+
31
+ For usage, run `dns-monitor -h`.
32
+
33
+ Since we use them at [EXPLO](https://www.explo.org), we've added flags to send notifications directly via Google Hangouts Chat or via a Mandrill API call. The script will also send updates to STDOUT and STDERR as necessary, so if you don't use either of those services you can pipe output into whichever notification setup you prefer.
34
+
35
+ ### Checking All Hosts
36
+
37
+ The main mode is `--check` or `-c`, which will check all hosts in your host file (just a return-delimited text file of top-level hostnames) for DNS changes. Changes will be stored in an SQLite3 database and logged. As noted above, you can be optionally alerted by GChat or email, or you can simply pipe output into whichever alert utility you prefer.
38
+
39
+ ### Checking a Specific Domain
40
+
41
+ You can get all domain history for a specific domain like this:
42
+
43
+ ```bash
44
+ dns-monitor --domain DOMAIN
45
+ ```
46
+
47
+ You'll get a JSON array of RDAP entries back - every change that's been logged on that domain since you started tracking.
48
+
49
+ ### RDAP Server
50
+
51
+ DNS::Monitor uses [RDAP](https://www.icann.org/rdap) for checking WHOIS records, because it gives you JSON back! The nice thing about this is that because it's all just JSON + hashes, DNS::Monitor can only display specifically what changed for a domain.
52
+
53
+ We use and love [Pair Domains](https://pairdomains.com) as our registrar, so we've coded their RDAP server in by default, but if you have a different registrar, you'll want to pass a flag to change that server eg:
54
+
55
+ ```bash
56
+ dns-monitor --check --rdap_url https://your-rdap-server.com
57
+ ```
58
+
59
+ ### File Paths
60
+
61
+ Since the script is designed to be run as a CRON job, you can specify with flags where you want to store your `hosts.txt` and database (sqlite) file:
62
+
63
+ ```bash
64
+ dns-monitor --check --db_path "/your/db/folder/and_filename.sqlite3" --domains_path "/your/domains/textfile/folder/and_filename.txt"
65
+ ```
66
+
67
+
68
+ ### Usage with Google Hangouts Chat
69
+
70
+ To use with Google Hangouts Chat, you'll need to set up a webhook in the appropriate chat room. You'll get a webhook URL which you can send to `dns-monitor` with `-g` or `--gchat` like this:
71
+
72
+ ```bash
73
+ dns-monitor --check --gchat YOUR_WEBHOOK_URL
74
+ ```
75
+
76
+ ### Usage with Mandrill
77
+
78
+ To use with Mandrill, you'll need an API key capable of sending messages, and a recipient email. The 'from' email will automatically be set to `dns-monitor` at your domain, so if you sent `donald@explo.org`, the `FROM` address would be `dns-monitor@explo.org`.
79
+
80
+ You need to set both flags on the command-line client for Mandrill to be activated, and emails will only be sent if there are changes to the domain list since the previous run:
81
+
82
+ ```bash
83
+ dns-monitor --check --mandrill_api "YOURAPIKEY" --mandrill_email "recipient@yourdomain.com"
84
+ ```
85
+
86
+
87
+
88
+ ## Development
89
+
90
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
91
+
92
+ 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).
93
+
94
+
95
+
96
+ ## Contributing
97
+
98
+ Bug reports and pull requests are welcome on Bitbucket at https://github.com/exploration/dns-monitor. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
99
+
100
+
101
+
102
+ ## License
103
+
104
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
105
+
106
+
107
+
108
+ ## Code of Conduct
109
+
110
+ Everyone interacting in the DNS::Monitor project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/exploration/dns-monitor/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dns/monitor"
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,46 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "dns/monitor/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "dns-monitor"
7
+ spec.version = DNS::Monitor::VERSION
8
+ spec.authors = ["Donald Merand"]
9
+ spec.email = ["dmerand@explo.org"]
10
+
11
+ spec.summary = %q{Monitor a list of hosts for DNS changes}
12
+ spec.description = <<~DESCRIPTION
13
+ The point of this gem is to monitor your hosts for (unwanted) DNS changes.
14
+ The `dns-monitor` file is designed to be run as a CRON job. It takes a
15
+ return-delimited text file listing domain names, and checks an RDAP
16
+ database (which you can specify) for JSON entries that match.
17
+ DESCRIPTION
18
+ spec.homepage = "https://github.com/exploration/dns-monitor"
19
+ spec.license = "MIT"
20
+
21
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
22
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
23
+ if spec.respond_to?(:metadata)
24
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_development_dependency "bundler", "~> 2.0.2"
40
+ spec.add_development_dependency "rake", "~> 13.0"
41
+ spec.add_development_dependency "minitest", "~> 5.0"
42
+ spec.add_development_dependency "pry", "~> 0.12.2"
43
+
44
+ spec.add_dependency "sqlite3", "~>1.4.2"
45
+ spec.add_dependency "easy_diff", "~>1.0.0"
46
+ end
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'dns/monitor'
4
+
5
+
6
+ # Working directory
7
+ def wd(*path_bits)
8
+ File.join Dir.pwd, *path_bits
9
+ end
10
+
11
+
12
+ # Default params
13
+ params = {
14
+ db_path: ENV['DB_PATH'] || wd('dns-monitor.sqlite3'),
15
+ domains_path: ENV['DOMAINS_PATH'] || wd('dns_monitor_hosts.txt'),
16
+ rdap_url: ENV['RDAP_URL'] || 'https://www.pairdomains.com/rdap'
17
+ }
18
+
19
+
20
+ # Command-line options
21
+ OptionParser.new do |opts|
22
+ opts.on('-g', '--gchat URL', String, 'Optional GChat webhook URL for notifications')
23
+ opts.on('-c', '--check', 'Check your domain name list')
24
+ opts.on('-d', '--db_path PATH', String, "Path to the database file. Defaults to #{params[:db_path]}")
25
+ opts.on('-h', '--help', 'Print this help') do
26
+ puts opts
27
+ exit 1
28
+ end
29
+ opts.on('-p', '--domains_path PATH', String, "Path to your domain file list. Defaults to #{params[:domains_path]}")
30
+ opts.on('-m', '--domain DOMAIN', String, 'Print existing results for a given domain as a JSON array')
31
+ opts.on('-u', '--rdap_url URL', String, "URL of your RDAP resolver. Defaults to #{params[:rdap_url]}")
32
+ opts.on('--mandrill_key KEY', String, "Mandrill API key. REQUIRES --mandrill-email to work.")
33
+ opts.on('--mandrill_email EMAIL', String, "Mandrill recipient email.")
34
+ end.parse!(into: params)
35
+
36
+
37
+ # Do the things
38
+ DNS::Monitor::Runner.new(params).check if params[:check]
39
+ DNS::Monitor::Runner.new(params).entries if params[:domain]
@@ -0,0 +1,18 @@
1
+ require 'easy_diff'
2
+ require 'json'
3
+ require 'net/http'
4
+ require 'optparse'
5
+ require 'sqlite3'
6
+
7
+ require 'dns/monitor/version'
8
+ require 'dns/monitor/check'
9
+ require 'dns/monitor/database'
10
+ require 'dns/monitor/domain'
11
+ require 'dns/monitor/gchat'
12
+ require 'dns/monitor/mandrill'
13
+ require 'dns/monitor/runner'
14
+
15
+ module DNS
16
+ module Monitor
17
+ end
18
+ end
@@ -0,0 +1,35 @@
1
+ module DNS
2
+ module Monitor
3
+ class Check
4
+ # A "Check" is an encapsulated domain query result.
5
+ def initialize(domain, status, diff={})
6
+ @diff = diff
7
+ @domain = domain
8
+ @status = status
9
+ end
10
+
11
+ def changed?
12
+ @status == :changed
13
+ end
14
+
15
+ def ok?
16
+ @status == :ok
17
+ end
18
+
19
+ def status
20
+ case @status
21
+ when :ok
22
+ { domain: @domain, ok: true }
23
+ when :changed
24
+ { domain: @domain, changes: @diff }
25
+ else
26
+ :error
27
+ end
28
+ end
29
+
30
+ def to_s
31
+ status.inspect
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,92 @@
1
+ module DNS
2
+ module Monitor
3
+ class Database
4
+ # This is the general DB structure
5
+ TABLE = 'domains'
6
+
7
+ def initialize(db_path)
8
+ @db_path = db_path
9
+ initialize_db
10
+ end
11
+
12
+ # Returns a Check object, or nothing if the params were empty
13
+ def check(domain, rdap)
14
+ return if domain.nil? || rdap.nil?
15
+
16
+ changes = diff((most_recent(domain).rdap || '{}'), rdap)
17
+
18
+ if changes.empty?
19
+ Check.new domain, :ok
20
+ else
21
+ insert(domain, rdap)
22
+ Check.new domain, :changed, changes
23
+ end
24
+ end
25
+
26
+ # This is mostly for testing
27
+ def clear
28
+ query { |db| db.execute "DELETE FROM #{TABLE} WHERE 1" }
29
+ end
30
+
31
+ # Compare two different RDAP values
32
+ # NOTE: We have to do a JSON conversion to compare instead of
33
+ # String, because the values come back from the server in arbitrary JSON
34
+ # key order.
35
+ def diff(previous_rdap, rdap)
36
+ # easy_diff returns [added, removed] hashes, we want "removed"
37
+ changes = JSON.parse(previous_rdap).easy_diff(JSON.parse(rdap)).last
38
+ filter_noisy_keys(changes)
39
+ end
40
+
41
+ # Return all entries for a given domain as a Domain struct
42
+ def entries(domain)
43
+ sql = "SELECT * FROM #{TABLE} WHERE domain=? ORDER BY created_at DESC"
44
+ query {|db| db.execute(sql, [domain]) }.map{ |row| Domain.new(*row) }
45
+ end
46
+
47
+ def filter_noisy_keys(changes)
48
+ # We get a lot of "last update of RDAP" events which aren't something
49
+ # we need notifications about. Remove those.
50
+ # WARNING: mutation follows
51
+ if changes.fetch('events', false)
52
+ changes['events'] = changes['events'].reject do |event|
53
+ event.fetch('eventAction', '').match?(/last update of RDAP/i)
54
+ end
55
+ changes.delete('events') if changes['events'].empty?
56
+ end
57
+ changes
58
+ end
59
+
60
+ # Just the latest entry plz
61
+ def most_recent(domain)
62
+ entries(domain).first || Domain.new
63
+ end
64
+
65
+ private
66
+
67
+ def initialize_db
68
+ query do |db| db.execute <<~SQL
69
+ CREATE TABLE IF NOT EXISTS #{TABLE} (
70
+ domain VARCHAR(255),
71
+ rdap TEXT,
72
+ created_at TIMESTAMP DEFAULT (DATETIME('now','localtime'))
73
+ );
74
+ SQL
75
+ end
76
+ end
77
+
78
+ def insert(domain, rdap)
79
+ query do |db|
80
+ db.execute "INSERT INTO #{TABLE} (domain, rdap) VALUES (?,?)", [ domain, rdap ]
81
+ end
82
+ end
83
+
84
+ def query
85
+ db = SQLite3::Database.new @db_path
86
+ result = yield db
87
+ db.close if db
88
+ result
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,15 @@
1
+ module DNS
2
+ module Monitor
3
+
4
+ # It's handy to be able to refer to Domains as objects
5
+ Domain = Struct.new(:name, :rdap, :created_at) do
6
+ def to_parsed_h
7
+ to_h.merge(rdap: JSON.parse(self.rdap))
8
+ end
9
+
10
+ def to_s
11
+ to_parsed_h.to_json
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ module DNS
2
+ module Monitor
3
+ class GChat
4
+ def initialize(webhook_url)
5
+ @webhook_url = webhook_url
6
+ end
7
+
8
+ def message(text)
9
+ Net::HTTP.post(
10
+ URI(@webhook_url),
11
+ {text: text}.to_json,
12
+ 'Content-Type' => 'application/json'
13
+ )
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,114 @@
1
+ module DNS
2
+ module Monitor
3
+ class Mandrill
4
+ API_URL = 'https://mandrillapp.com/api/1.0/messages/send.json'
5
+
6
+ attr_reader :from_email, :recipient_email
7
+
8
+ def initialize(api_key, recipient_email)
9
+ @api_key = api_key
10
+ @recipient_email = recipient_email
11
+ @from_email = "dns-monitor@#{@recipient_email.split('@').last}"
12
+ end
13
+
14
+ def message(text)
15
+ Net::HTTP.post(
16
+ URI(API_URL),
17
+ request(text).to_json,
18
+ 'Content-Type' => 'application/json'
19
+ )
20
+ end
21
+
22
+ def request(text)
23
+ {
24
+ "key" => @api_key,
25
+ "message" => {
26
+ #"html" => "<p>Example HTML content</p>",
27
+ "text" => text,
28
+ "subject" => "DNS Change Alert",
29
+ "from_email" => @from_email,
30
+ "from_name" => "DNS Monitor",
31
+ "to" => [
32
+ {
33
+ "email" => @recipient_email,
34
+ "name" => @recipient_email,
35
+ "type" => "to"
36
+ }
37
+ ],
38
+ #"headers" => {
39
+ #"Reply-To" => "message.reply@example.com"
40
+ #},
41
+ #"important" => false,
42
+ #"track_opens" => null,
43
+ #"track_clicks" => null,
44
+ #"auto_text" => null,
45
+ #"auto_html" => null,
46
+ #"inline_css" => null,
47
+ #"url_strip_qs" => null,
48
+ #"preserve_recipients" => null,
49
+ #"view_content_link" => null,
50
+ #"bcc_address" => "message.bcc_address@example.com",
51
+ #"tracking_domain" => null,
52
+ #"signing_domain" => null,
53
+ #"return_path_domain" => null,
54
+ #"merge" => true,
55
+ #"merge_language" => "mailchimp",
56
+ #"global_merge_vars" => [
57
+ #{
58
+ #"name" => "merge1",
59
+ #"content" => "merge1 content"
60
+ #}
61
+ #],
62
+ #"merge_vars" => [
63
+ #{
64
+ #"rcpt" => "recipient.email@example.com",
65
+ #"vars" => [
66
+ #{
67
+ #"name" => "merge2",
68
+ #"content" => "merge2 content"
69
+ #}
70
+ #]
71
+ #}
72
+ #],
73
+ #"tags" => [
74
+ #"password-resets"
75
+ #],
76
+ #"subaccount" => "customer-123",
77
+ #"google_analytics_domains" => [
78
+ #"example.com"
79
+ #],
80
+ #"google_analytics_campaign" => "message.from_email@example.com",
81
+ #"metadata" => {
82
+ #"website" => "www.example.com"
83
+ #},
84
+ #"recipient_metadata" => [
85
+ #{
86
+ #"rcpt" => "recipient.email@example.com",
87
+ #"values" => {
88
+ #"user_id" => 123456
89
+ #}
90
+ #}
91
+ #],
92
+ #"attachments" => [
93
+ #{
94
+ #"type" => "text/plain",
95
+ #"name" => "myfile.txt",
96
+ #"content" => "ZXhhbXBsZSBmaWxl"
97
+ #}
98
+ #],
99
+ #"images" => [
100
+ #{
101
+ #"type" => "image/png",
102
+ #"name" => "IMAGECID",
103
+ #"content" => "ZXhhbXBsZSBmaWxl"
104
+ #}
105
+ #]
106
+ },
107
+ #"async" => false,
108
+ #"ip_pool" => "Main Pool",
109
+ #"send_at" => "example send_at"
110
+ }
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,48 @@
1
+ module DNS
2
+ module Monitor
3
+ class Runner
4
+ # The "Runner" is the back-end for the command-line utility
5
+ def initialize(params)
6
+ @params = params
7
+ end
8
+
9
+ # This is the main action we do with this app - check all of the domains
10
+ def check
11
+ begin
12
+ domains = File.read(@params[:domains_path]).split
13
+ rescue Errno::ENOENT
14
+ STDERR.puts "File #{@params[:domains_path]} does not exist"
15
+ exit 1
16
+ end
17
+
18
+ checks = domains.map do |domain|
19
+ rdap = Net::HTTP.get(URI("#{@params[:rdap_url]}/domain/#{domain}"))
20
+ db.check domain, rdap
21
+ end
22
+
23
+ message = checks.map {|check| check.status}.to_json
24
+ STDOUT.puts message
25
+
26
+ if @params[:gchat]
27
+ # GChat gets every status update
28
+ GChat.new(@params[:gchat]).message(message)
29
+ end
30
+ if @params[:mandrill_key] && @params[:mandrill_email] && checks.any?(&:changed?)
31
+ # We only email changed domains
32
+ Mandrill.new(@params[:mandrill_key], @params[:mandrill_email]).message(message)
33
+ end
34
+ end
35
+
36
+ # This is an alternative app action - check the history for a particular domain.
37
+ def entries
38
+ STDOUT.puts db.entries(@params[:domain]).map{|row| row.to_parsed_h}.to_json
39
+ end
40
+
41
+ private
42
+
43
+ def db
44
+ @db ||= Database.new(@params[:db_path])
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,5 @@
1
+ module DNS
2
+ module Monitor
3
+ VERSION = "0.1.7"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dns-monitor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.7
5
+ platform: ruby
6
+ authors:
7
+ - Donald Merand
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-03-02 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.2
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.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.12.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.12.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.4.2
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.4.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: easy_diff
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.0.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.0.0
97
+ description: "The point of this gem is to monitor your hosts for (unwanted) DNS changes.\nThe
98
+ `dns-monitor` file is designed to be run as a CRON job. It takes a\nreturn-delimited
99
+ text file listing domain names, and checks an RDAP\ndatabase (which you can specify)
100
+ for JSON entries that match. \n"
101
+ email:
102
+ - dmerand@explo.org
103
+ executables:
104
+ - dns-monitor
105
+ extensions: []
106
+ extra_rdoc_files: []
107
+ files:
108
+ - ".gitignore"
109
+ - ".ruby-version"
110
+ - ".travis.yml"
111
+ - CODE_OF_CONDUCT.md
112
+ - Gemfile
113
+ - Gemfile.lock
114
+ - LICENSE.txt
115
+ - README.md
116
+ - Rakefile
117
+ - bin/console
118
+ - bin/setup
119
+ - dns-monitor.gemspec
120
+ - exe/dns-monitor
121
+ - lib/dns/monitor.rb
122
+ - lib/dns/monitor/check.rb
123
+ - lib/dns/monitor/database.rb
124
+ - lib/dns/monitor/domain.rb
125
+ - lib/dns/monitor/gchat.rb
126
+ - lib/dns/monitor/mandrill.rb
127
+ - lib/dns/monitor/runner.rb
128
+ - lib/dns/monitor/version.rb
129
+ homepage: https://github.com/exploration/dns-monitor
130
+ licenses:
131
+ - MIT
132
+ metadata:
133
+ allowed_push_host: https://rubygems.org
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubygems_version: 3.0.3
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: Monitor a list of hosts for DNS changes
153
+ test_files: []