dns-monitor 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 47ecb7b4c773ba128eee68fddf6177ea819020f5b406bf7656c893bcc10df342
4
+ data.tar.gz: 4876e6d57d8f9ccf9339c0002cb54c2a1b13b6c61bf13bd12d7a232466efd7f7
5
+ SHA512:
6
+ metadata.gz: 770c6890458fc5ba3d9dac4242ced6715b32c3e82715863aa4aa2df7eace9a6b931c530bff0589fb95b43edeccd2a0fa06c21df79953cf9c7b2d28db6f251070
7
+ data.tar.gz: e9fbc7a0912c7317dcee5d9ed46794d9dd1611aa286671837b9fd799b86d1e57eed42549e3138ad99c50e7d8dcc6e8d5182967aedfd653574277d60b8445be8a
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ *.sw*
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.3
data/.travis.yml ADDED
@@ -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
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dns-monitor (0.1.1)
5
+ sqlite3 (~> 1.4.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.2)
11
+ method_source (0.9.2)
12
+ minitest (5.14.0)
13
+ pry (0.12.2)
14
+ coderay (~> 1.1.0)
15
+ method_source (~> 0.9.0)
16
+ rake (10.5.0)
17
+ sqlite3 (1.4.2)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ bundler (~> 2.0.2)
24
+ dns-monitor!
25
+ minitest (~> 5.0)
26
+ pry (~> 0.12.2)
27
+ rake (~> 10.0)
28
+
29
+ BUNDLED WITH
30
+ 2.0.2
data/LICENSE.txt ADDED
@@ -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.
data/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # DNS::Monitor
2
+
3
+ The point of this gem is to monitor your hosts for (unwanted) DNS changes. The executable `dns-monitor` file is designed to be run as a CRON job. It takes a return-delimited text file listing domain names, and checks an 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.
4
+
5
+
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'dns-monitor'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dns-monitor
22
+
23
+
24
+
25
+ ## Usage
26
+
27
+ For usage, run `dns-monitor -h`.
28
+
29
+ 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.
30
+
31
+ ### Checking All Hosts
32
+
33
+ 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.
34
+
35
+ ### Checking a Specific Domain
36
+
37
+ You can get all domain history for a specific domain like this:
38
+
39
+ ```bash
40
+ dns-monitor --domain DOMAIN
41
+ ```
42
+
43
+ You'll get a JSON array of RDAP entries back - every change that's been logged on that domain since you started tracking.
44
+
45
+ ### RDAP Server
46
+
47
+ 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.
48
+
49
+ 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:
50
+
51
+ ```bash
52
+ dns-monitor --check --rdap_url https://your-rdap-server.com
53
+ ```
54
+
55
+ ### File Paths
56
+
57
+ 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:
58
+
59
+ ```bash
60
+ dns-monitor --check --db_path "/your/db/folder/and_filename.sqlite3" --domains_path "/your/domains/textfile/folder/and_filename.txt"
61
+ ```
62
+
63
+
64
+ ### Usage with Google Hangouts Chat
65
+
66
+ 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:
67
+
68
+ ```bash
69
+ dns-monitor --check --gchat YOUR_WEBHOOK_URL
70
+ ```
71
+
72
+ ### Usage with Mandrill
73
+
74
+ 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`.
75
+
76
+ 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:
77
+
78
+ ```bash
79
+ dns-monitor --check --mandrill_api "YOURAPIKEY" --mandrill_email "recipient@yourdomain.com"
80
+ ```
81
+
82
+
83
+
84
+ ## Development
85
+
86
+ 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.
87
+
88
+ 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).
89
+
90
+
91
+
92
+ ## Contributing
93
+
94
+ 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.
95
+
96
+
97
+
98
+ ## License
99
+
100
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
101
+
102
+
103
+
104
+ ## Code of Conduct
105
+
106
+ 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).
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -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__)
data/bin/setup ADDED
@@ -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. You will get
17
+ an error, optionally by GChat, if you encounter a changed entry.
18
+ DESCRIPTION
19
+ spec.homepage = "https://github.com/exploration/dns-monitor"
20
+ spec.license = "MIT"
21
+
22
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
23
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
24
+ if spec.respond_to?(:metadata)
25
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
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.2"
41
+ spec.add_development_dependency "rake", "~> 10.0"
42
+ spec.add_development_dependency "minitest", "~> 5.0"
43
+ spec.add_development_dependency "pry", "~> 0.12.2"
44
+
45
+ spec.add_dependency "sqlite3", "~>1.4.2"
46
+ end
data/exe/dns-monitor ADDED
@@ -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,17 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'optparse'
4
+ require 'sqlite3'
5
+
6
+ require 'dns/monitor/version'
7
+ require 'dns/monitor/check'
8
+ require 'dns/monitor/database'
9
+ require 'dns/monitor/domain'
10
+ require 'dns/monitor/gchat'
11
+ require 'dns/monitor/mandrill'
12
+ require 'dns/monitor/runner'
13
+
14
+ module DNS
15
+ module Monitor
16
+ end
17
+ end
@@ -0,0 +1,34 @@
1
+ module DNS
2
+ module Monitor
3
+ class Check
4
+ def initialize(domain, status, diff={})
5
+ @diff = diff
6
+ @domain = domain
7
+ @status = status
8
+ end
9
+
10
+ def changed?
11
+ @status == :changed
12
+ end
13
+
14
+ def ok?
15
+ @status == :ok
16
+ end
17
+
18
+ def status
19
+ case @status
20
+ when :ok
21
+ { domain: @domain, ok: true }
22
+ when :changed
23
+ { domain: @domain, changes: @diff }
24
+ else
25
+ :error
26
+ end
27
+ end
28
+
29
+ def to_s
30
+ status.inspect
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,78 @@
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
+ if changes.empty?
18
+ Check.new domain, :ok
19
+ else
20
+ insert(domain, rdap)
21
+ Check.new domain, :changed, changes
22
+ end
23
+ end
24
+
25
+ # This is mostly for testing
26
+ def clear
27
+ query { |db| db.execute "DELETE FROM #{TABLE} WHERE 1" }
28
+ end
29
+
30
+ # Compare two different RDAP values
31
+ # NOTE: We have to do a JSON conversion because the values come back
32
+ # from the server in arbitrary JSON key order.
33
+ def diff(rdap, previous_rdap)
34
+ (
35
+ JSON.parse(previous_rdap || '{}').to_a -
36
+ JSON.parse(rdap || '{}').to_a
37
+ ).to_h
38
+ end
39
+
40
+ # Return all entries for a given domain as a Domain struct
41
+ def entries(domain)
42
+ sql = "SELECT * FROM #{TABLE} WHERE domain=? ORDER BY created_at DESC"
43
+ query {|db| db.execute(sql, [domain]) }.map{ |row| Domain.new(*row) }
44
+ end
45
+
46
+ # Just the latest entry plz
47
+ def most_recent(domain)
48
+ entries(domain).first || Domain.new
49
+ end
50
+
51
+ private
52
+
53
+ def initialize_db
54
+ query do |db| db.execute <<~SQL
55
+ CREATE TABLE IF NOT EXISTS #{TABLE} (
56
+ domain VARCHAR(255),
57
+ rdap TEXT,
58
+ created_at TIMESTAMP DEFAULT (DATETIME('now','localtime'))
59
+ );
60
+ SQL
61
+ end
62
+ end
63
+
64
+ def insert(domain, rdap)
65
+ query do |db|
66
+ db.execute "INSERT INTO #{TABLE} (domain, rdap) VALUES (?,?)", [ domain, rdap ]
67
+ end
68
+ end
69
+
70
+ def query
71
+ db = SQLite3::Database.new @db_path
72
+ result = yield db
73
+ db.close if db
74
+ result
75
+ end
76
+ end
77
+ end
78
+ 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,45 @@
1
+ module DNS
2
+ module Monitor
3
+ class Runner
4
+ def initialize(params)
5
+ @params = params
6
+ end
7
+
8
+ def check
9
+ begin
10
+ domains = File.read(@params[:domains_path]).split
11
+ rescue Errno::ENOENT
12
+ STDERR.puts "File #{@params[:domains_path]} does not exist"
13
+ exit 1
14
+ end
15
+
16
+ checks = domains.map do |domain|
17
+ rdap = Net::HTTP.get(URI("#{@params[:rdap_url]}/domain/#{domain}"))
18
+ db.check domain, rdap
19
+ end
20
+
21
+ message = checks.map {|check| check.status}.to_json
22
+ STDOUT.puts message
23
+
24
+ if @params[:gchat]
25
+ # GChat gets every status update
26
+ GChat.new(@params[:gchat]).message(message)
27
+ end
28
+ if @params[:mandrill_key] && @params[:mandrill_email] && checks.any?(&:changed?)
29
+ # We only email changed domains
30
+ Mandrill.new(@params[:mandrill_key], @params[:mandrill_email]).message(message)
31
+ end
32
+ end
33
+
34
+ def entries
35
+ STDOUT.puts db.entries(@params[:domain]).map{|row| row.to_parsed_h}.to_json
36
+ end
37
+
38
+ private
39
+
40
+ def db
41
+ @db ||= Database.new(@params[:db_path])
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,5 @@
1
+ module DNS
2
+ module Monitor
3
+ VERSION = "0.1.2"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dns-monitor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Donald Merand
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-01-27 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: '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: 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
+ description: |
84
+ The point of this gem is to monitor your hosts for (unwanted) DNS changes.
85
+ The `dns-monitor` file is designed to be run as a CRON job. It takes a
86
+ return-delimited text file listing domain names, and checks an RDAP
87
+ database (which you can specify) for JSON entries that match. You will get
88
+ an error, optionally by GChat, if you encounter a changed entry.
89
+ email:
90
+ - dmerand@explo.org
91
+ executables:
92
+ - dns-monitor
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".gitignore"
97
+ - ".ruby-version"
98
+ - ".travis.yml"
99
+ - CODE_OF_CONDUCT.md
100
+ - Gemfile
101
+ - Gemfile.lock
102
+ - LICENSE.txt
103
+ - README.md
104
+ - Rakefile
105
+ - bin/console
106
+ - bin/setup
107
+ - dns-monitor.gemspec
108
+ - exe/dns-monitor
109
+ - lib/dns/monitor.rb
110
+ - lib/dns/monitor/check.rb
111
+ - lib/dns/monitor/database.rb
112
+ - lib/dns/monitor/domain.rb
113
+ - lib/dns/monitor/gchat.rb
114
+ - lib/dns/monitor/mandrill.rb
115
+ - lib/dns/monitor/runner.rb
116
+ - lib/dns/monitor/version.rb
117
+ homepage: https://github.com/exploration/dns-monitor
118
+ licenses:
119
+ - MIT
120
+ metadata:
121
+ allowed_push_host: https://rubygems.org
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubygems_version: 3.0.3
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Monitor a list of hosts for DNS changes
141
+ test_files: []