linode_dynamic_dns 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ce6e7ccd29726e4f6cc09cadb24cbe207ff0f959
4
+ data.tar.gz: 8a5b6e45bee042889d24479e0f4482c8adcdcfe6
5
+ SHA512:
6
+ metadata.gz: da7921589fd6db6cb6cdfbe9e6dad68110e5d0fd0a47fa06b9ca9ed08f6fac83cefd419b81326a9264fd2763daf6fcab49a3e112fc8f7d7c33639069410dfb58
7
+ data.tar.gz: 3f57937a589bf9ff56b83c08457546ce93608140bfcf589c7a7cf6395cd0e7488a51db89ca09710bc3c4a03a914ff788a1208e971becdad53af9fa05fad61d31
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ config/linode_dynamic_dns.yaml
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ *.bundle
20
+ *.so
21
+ *.o
22
+ *.a
23
+ mkmf.log
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in linode_dynamic_dns.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Grier Johnson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Linode Dynamic Dns
2
+
3
+ This is a really simple gem to update a dns entry via Linode's DNS API to mimic something like Dyn's dynamic dns. Dyn recently killed their free dynamic record, so I dug into how to do it with Linode's DNS since I already host it through them.
4
+
5
+ ## Installation
6
+
7
+ This gem is generally used in a standalone manner using bundler. To install it run:
8
+
9
+ git clone https://github.com/grierj/linode_dynamic_dns.git
10
+ cd linode_dynamic_dns
11
+ bundle install
12
+
13
+ After that run:
14
+
15
+ cp config/linode_dynamic_dns.EXAMPLE.yaml config/linode_dynamic_dns.yaml
16
+
17
+ And edit the fields in that config file. The comments should explain what's going on.
18
+
19
+ ## Setting up your DNS
20
+
21
+ In your Linode DNS manager pick the "Domain Zone" you want to put the record in. This is what goes in the "domain" section of the config file, btw. In that zone add a new A record. Set the IP to something like 127.0.0.1 for now, it'll get updated via the script later. The name of this A record is what goes in the "record" section of the config.
22
+
23
+ ## Usage
24
+
25
+ After your config file is up to date, simply run:
26
+
27
+ bundle exec bin/linode_dynamic_dns
28
+
29
+ This should update whatever record you configured to whatever your IP address is. To run this continuously use runit or daemontools or whatever your favorite process minder is.
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( https://github.com/grierj/linode_dynamic_dns/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/ip.rb ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby
2
+ require 'cgi'
3
+ cgi = CGI.new("html3")
4
+ addr = cgi.remote_addr
5
+ cgi.out() do
6
+ addr
7
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ require 'linode'
4
+ require 'linode_dynamic_dns'
5
+
6
+ my_ip = LinodeDynamicDns.get_my_ip
7
+ puts "My IP is #{my_ip}"
8
+ domain_id = LinodeDynamicDns.get_domain_id
9
+ puts "My Domain ID is #{domain_id}"
10
+ record_id = LinodeDynamicDns.get_record_id(domain_id)
11
+ puts "My Record ID is #{record_id}"
12
+ LinodeDynamicDns.update_record_ip(domain_id, record_id, my_ip)
13
+ puts "Updated #{LinodeDynamicDns.config.record}.#{LinodeDynamicDns.config.domain} to #{my_ip}"
14
+
15
+
16
+
@@ -0,0 +1,20 @@
1
+ # A URL that returns a body of the IP address that requested it. You can find
2
+ # ip.rb in the bin directory.
3
+ # Feel free host this yourself on your linode that you probably have because
4
+ # that's the DNS this updates :)
5
+ ip_url: "http://hellspenguins.org/cgi-bin/ip.rb"
6
+
7
+ # This is your API key. It's secret. Don't check it into git. You can
8
+ # get your API key from https://manager.linode.com/profile/api
9
+ api_key: abcd1234
10
+
11
+ # The domain that the dynamic record lives in
12
+ domain: example.com
13
+
14
+ # The name of the record, "home" or "dyn" or something like that works
15
+ record: dyn
16
+
17
+ # The DNS TTL for this entry, in seconds. You probably want to leave this
18
+ # at 300
19
+ ttl: 300
20
+
@@ -0,0 +1,15 @@
1
+ require 'ostruct'
2
+ require 'yaml'
3
+
4
+ module LinodeDynamicDns
5
+ def self.config
6
+ @config ||= OpenStruct.new(
7
+ YAML.load_file(
8
+ File.join(
9
+ File.dirname(__FILE__), '../..', 'config',
10
+ 'linode_dynamic_dns.yaml'
11
+ )
12
+ )
13
+ )
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module LinodeDynamicDns
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,47 @@
1
+ require "net/http"
2
+ require "linode_dynamic_dns/version"
3
+ require "linode_dynamic_dns/config"
4
+
5
+ module LinodeDynamicDns
6
+ def self.api
7
+ @api ||= Linode.new(:api_key => config.api_key)
8
+ end
9
+
10
+ def self.ttl
11
+ config.ttl || 300
12
+ end
13
+
14
+ def self.get_my_ip
15
+ response = Net::HTTP.get_response(URI(config.ip_url))
16
+ if response.code.to_i == 200
17
+ response.body
18
+ else
19
+ raise "Got bad response code #{response.code}"
20
+ end
21
+ end
22
+
23
+ def self.get_domain_id
24
+ api.domain.list.each do |dom|
25
+ if dom.domain == config.domain
26
+ return dom.domainid
27
+ end
28
+ end
29
+ raise "No domain found matching #{config.domain}"
30
+ end
31
+
32
+ def self.get_record_id(domain_id)
33
+ api.domain.resource.list(:DomainId => domain_id).each do |res|
34
+ if res.name == config.record
35
+ return res.resourceid
36
+ end
37
+ end
38
+ raise "No resource found matching #{config.record}"
39
+ end
40
+
41
+ def self.update_record_ip(domain_id, record_id, ip)
42
+ api.domain.resource.update(:DomainId => domain_id,
43
+ :ResourceId => record_id,
44
+ :TTL_sec => ttl,
45
+ :Target => ip)
46
+ end
47
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'linode_dynamic_dns/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "linode_dynamic_dns"
8
+ spec.version = LinodeDynamicDns::VERSION
9
+ spec.authors = ["Grier Johnson"]
10
+ spec.email = ["grierj@gmail.com"]
11
+ spec.summary = %q{A small script for updating a linode dns record based on your current IP}
12
+ spec.description = %q{Dyn decided to charge for this functionality, so I wrote a few lines of code to fix it}
13
+ spec.homepage = "https://github.com/grierj/linode_dynamic_dns"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "linode", "~> 0.7.10"
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "rake"
24
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: linode_dynamic_dns
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Grier Johnson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: linode
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.7.10
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.7.10
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Dyn decided to charge for this functionality, so I wrote a few lines
56
+ of code to fix it
57
+ email:
58
+ - grierj@gmail.com
59
+ executables:
60
+ - ip.rb
61
+ - linode_dynamic_dns
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - .gitignore
66
+ - .ruby-version
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/ip.rb
72
+ - bin/linode_dynamic_dns
73
+ - config/linode_dynamic_dns.EXAMPLE.yaml
74
+ - lib/linode_dynamic_dns.rb
75
+ - lib/linode_dynamic_dns/config.rb
76
+ - lib/linode_dynamic_dns/version.rb
77
+ - linode_dynamic_dns.gemspec
78
+ homepage: https://github.com/grierj/linode_dynamic_dns
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.2.2
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: A small script for updating a linode dns record based on your current IP
102
+ test_files: []