domain_info 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rvmrc
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :test do
4
+ gem "rake", "~> 0.9.2.2"
5
+ end
6
+
7
+ # Specify your gem's dependencies in domain_info.gemspec
8
+ gemspec
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ ## Domain info
2
+
3
+ [![Build Status](https://secure.travis-ci.org/iafonov/domain_info.png)](http://travis-ci.org/iafonov/domain_info)
4
+
5
+ Basic domain configuration wrapper & verifier. Allows one to verify whether domain is configured correctly for sending emails under its name. Built on top of ruby's built-in [`Resolv`](http://ruby-doc.org/stdlib-1.9.2/libdoc/resolv/rdoc/Resolv.html).
6
+
7
+ ```ruby
8
+ domain = DomainInfo::Domain.new("github.com")
9
+
10
+ # IP
11
+ domain.ip # => "207.97.227.239"
12
+
13
+ # PTR record validation
14
+ domain.ptr.value # => "github.com"
15
+ domain.ptr.present? # => true
16
+ domain.ptr.valid? # => true, domain's ip resolves to itself
17
+
18
+ # Extracting SPF record
19
+ domain.spf.value # => v=spf1 a mx include:spf.mtasv.net...
20
+ domain.spf.present? # => true
21
+
22
+ # Extracting DKIM public key
23
+ domain.dkim("_key").value # => v=DKIM1...
24
+ domain.dkim("_key").present? # => true
25
+
26
+ # Extracting DKIM record with defaut name usually generated by dkim-filter
27
+ domain.default_dkim.value # => v=DKIM1...
28
+ ```
29
+
30
+ All values are lazy evaluated and cached on instance level after the first call so subsequent calls will not issue network requests.
31
+
32
+ For more advanced things I recommend to go with [dnsruby](http://rubyforge.org/projects/dnsruby).
33
+
34
+ [Igor Afonov](http://iafonov.github.com) 2012 MIT License
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => [:spec]
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "domain_info/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "domain_info"
7
+ s.version = DomainInfo::VERSION
8
+ s.authors = ["Igor Afonov"]
9
+ s.email = ["afonov@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Wraps access to basic domain DNS records}
12
+ s.description = %q{Wraps access to basic domain DNS records needed to verify domain configuration}
13
+
14
+ s.rubyforge_project = "domain_info"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency "rspec"
22
+ end
@@ -0,0 +1,10 @@
1
+ require "domain_info/version"
2
+ require 'resolv'
3
+
4
+ module DomainInfo
5
+ require 'domain_info/record'
6
+ require 'domain_info/ptr'
7
+ require 'domain_info/spf'
8
+ require 'domain_info/dkim'
9
+ require 'domain_info/domain'
10
+ end
@@ -0,0 +1,16 @@
1
+ require 'domain_info/util/dns_records'
2
+
3
+ class DomainInfo::DKIM < DomainInfo::Record
4
+ def initialize(domain, txt_name)
5
+ @dkim = extract_dkim(domain, txt_name)
6
+ end
7
+
8
+ def value
9
+ @dkim
10
+ end
11
+
12
+ private
13
+ def extract_dkim(domain, txt_name)
14
+ DomainInfo::DNSRecords.new("#{txt_name}.#{domain}").detect{|txt_record| txt_record.start_with?("v=DKIM")}
15
+ end
16
+ end
@@ -0,0 +1,27 @@
1
+ class DomainInfo::Domain
2
+ attr_accessor :domain
3
+
4
+ def initialize(domain)
5
+ @domain = domain
6
+ end
7
+
8
+ def ip
9
+ @ip ||= IPSocket::getaddress(domain)
10
+ end
11
+
12
+ def ptr
13
+ @ptr ||= DomainInfo::PTR.new(domain)
14
+ end
15
+
16
+ def spf
17
+ @spf ||= DomainInfo::SPF.new(domain)
18
+ end
19
+
20
+ def dkim(txt_name)
21
+ @dkim ||= DomainInfo::DKIM.new(domain, txt_name)
22
+ end
23
+
24
+ def default_dkim
25
+ @default_dkim_dkim ||= DomainInfo::DKIM.new(domain, "#{domain}._domainkey")
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ class DomainInfo::PTR < DomainInfo::Record
2
+ def initialize(domain)
3
+ @domain = domain
4
+ @ptr = Resolv.getname(IPSocket::getaddress(domain))
5
+ end
6
+
7
+ def valid?
8
+ value == @domain
9
+ end
10
+
11
+ def value
12
+ @ptr
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ class DomainInfo::Record
2
+ def present?
3
+ !value.nil?
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ require 'domain_info/util/dns_records'
2
+
3
+ class DomainInfo::SPF < DomainInfo::Record
4
+ def initialize(domain)
5
+ @domain = domain
6
+ @spf = DomainInfo::DNSRecords.new(domain).detect{|txt_record| txt_record.start_with?("v=spf1")}
7
+ end
8
+
9
+ def value
10
+ @spf
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ class DomainInfo::DNSRecords
2
+ include Enumerable
3
+
4
+ def initialize(domain)
5
+ @domain = domain
6
+ end
7
+
8
+ def each
9
+ Resolv::DNS.open do |dns|
10
+ dns.each_resource(@domain, Resolv::DNS::Resource::IN::TXT) do |dns_record|
11
+ dns_record.strings.each{ |dns_string| yield dns_string }
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module DomainInfo
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+
3
+ describe DomainInfo::DKIM do
4
+ let(:dkim) { DomainInfo::DKIM.new("plaintracker.com", "plaintracker.com._domainkey") }
5
+
6
+ it "returns DKIM record for ip associated with domain" do
7
+ dkim.value.should match("v=DKIM1")
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ require "spec_helper"
2
+
3
+ describe DomainInfo::Domain do
4
+ let (:domain) { DomainInfo::Domain.new("github.com") }
5
+
6
+ it "has an IP address" do
7
+ domain.ip.should_not be_nil
8
+ end
9
+
10
+ it "has a PTR record" do
11
+ domain.ptr.should_not be_nil
12
+ end
13
+
14
+ it "has a SPF record" do
15
+ domain.ptr.should_not be_nil
16
+ end
17
+
18
+ it "has a DKIM record" do
19
+ domain.dkim("_key").should_not be_nil
20
+ end
21
+
22
+ it "has a default DKIM record" do
23
+ domain.default_dkim.should_not be_nil
24
+ end
25
+ end
@@ -0,0 +1,16 @@
1
+ require "spec_helper"
2
+
3
+ describe DomainInfo::PTR do
4
+ let(:ptr) { DomainInfo::PTR.new("github.com") }
5
+
6
+ it "returns PTR record for ip associated with domain" do
7
+ ptr.value.should == "github.com"
8
+ end
9
+
10
+ context "#valid?" do
11
+ it "returns true if domain resolves to itself" do
12
+ ptr.stub(:value).and_return("github.com")
13
+ ptr.should be_valid
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+
3
+ describe DomainInfo::SPF do
4
+ let(:spf) { DomainInfo::SPF.new("plaintracker.com") }
5
+
6
+ it "returns SPF record for ip associated with domain" do
7
+ spf.value.should == "v=spf1 mx ip4:178.63.56.8 -all"
8
+ end
9
+ end
@@ -0,0 +1 @@
1
+ require 'domain_info'
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: domain_info
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Igor Afonov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2012-03-15 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Wraps access to basic domain DNS records needed to verify domain configuration
26
+ email:
27
+ - afonov@gmail.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files: []
33
+
34
+ files:
35
+ - .gitignore
36
+ - .travis.yml
37
+ - Gemfile
38
+ - README.md
39
+ - Rakefile
40
+ - domain_info.gemspec
41
+ - lib/domain_info.rb
42
+ - lib/domain_info/dkim.rb
43
+ - lib/domain_info/domain.rb
44
+ - lib/domain_info/ptr.rb
45
+ - lib/domain_info/record.rb
46
+ - lib/domain_info/spf.rb
47
+ - lib/domain_info/util/dns_records.rb
48
+ - lib/domain_info/version.rb
49
+ - spec/lib/domain_info/dkim_spec.rb
50
+ - spec/lib/domain_info/domain_spec.rb
51
+ - spec/lib/domain_info/ptr_spec.rb
52
+ - spec/lib/domain_info/spf_spec.rb
53
+ - spec/spec_helper.rb
54
+ has_rdoc: false
55
+ homepage: ""
56
+ post_install_message:
57
+ rdoc_options: []
58
+
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ requirements: []
74
+
75
+ rubyforge_project: domain_info
76
+ rubygems_version: 1.3.1
77
+ signing_key:
78
+ specification_version: 2
79
+ summary: Wraps access to basic domain DNS records
80
+ test_files:
81
+ - spec/lib/domain_info/dkim_spec.rb
82
+ - spec/lib/domain_info/domain_spec.rb
83
+ - spec/lib/domain_info/ptr_spec.rb
84
+ - spec/lib/domain_info/spf_spec.rb
85
+ - spec/spec_helper.rb