cloudflare-dns-update 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/README.md +45 -0
- data/Rakefile +1 -0
- data/bin/cloudflare-dns-update +135 -0
- data/cloudflare-dns-update.gemspec +30 -0
- data/cloudflare-dns.yml +32 -0
- data/lib/cloudflare/dns/update.rb +28 -0
- data/lib/cloudflare/dns/update/version.rb +28 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cfd1d7cdb372156dae4df530134cafabe534eff9
|
4
|
+
data.tar.gz: d1d015bc4534779c80a0b9d9e84277724091a11f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b26ee451d1feab4842b9a15da29ea79c72b35ec05160d8a1474a7fe780f1ecc9ebaacbb461b1eafd0250f4ab9d79c212623be43fa78c26ba3360d972258efb61
|
7
|
+
data.tar.gz: 4a89074cb8c9d70579a222f1efce524cc3cb5b5a10a1200e0e0f3e636ae741b297b3228dc266a631bc462f67ab1f547725c5f91bf3fc467b96af1a95ad4465b8
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# CloudFlare::DNS::Update
|
2
|
+
|
3
|
+
This gem provides a simple executable tool for managing CloudFlare records to provide dynamic DNS like functionality. You need to add it to whatever `cron` system your host system uses.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install it yourself as:
|
8
|
+
|
9
|
+
$ gem install cloudflare-dns-update
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Run the included `cloudflare-dns-update` tool and you will be walked through the configuration process. You might want to specify a specific configuration file, using the `--configuration /path/to/configuration.yml` option.
|
14
|
+
|
15
|
+
## Contributing
|
16
|
+
|
17
|
+
1. Fork it
|
18
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
19
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
20
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
21
|
+
5. Create new Pull Request
|
22
|
+
|
23
|
+
## License
|
24
|
+
|
25
|
+
Released under the MIT license.
|
26
|
+
|
27
|
+
Copyright, 2013, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
|
28
|
+
|
29
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
30
|
+
of this software and associated documentation files (the "Software"), to deal
|
31
|
+
in the Software without restriction, including without limitation the rights
|
32
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
33
|
+
copies of the Software, and to permit persons to whom the Software is
|
34
|
+
furnished to do so, subject to the following conditions:
|
35
|
+
|
36
|
+
The above copyright notice and this permission notice shall be included in
|
37
|
+
all copies or substantial portions of the Software.
|
38
|
+
|
39
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
40
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
41
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
42
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
43
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
44
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
45
|
+
THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,135 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright, 2013, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
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.
|
22
|
+
|
23
|
+
require 'trollop'
|
24
|
+
require 'yaml/store'
|
25
|
+
|
26
|
+
require 'cloudflare'
|
27
|
+
|
28
|
+
def check_result(result, success_message = 'Finished.')
|
29
|
+
if result['result'] == 'success'
|
30
|
+
puts success_message
|
31
|
+
yield
|
32
|
+
else
|
33
|
+
puts result['msg'] # error message
|
34
|
+
exit(1)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_input(message)
|
39
|
+
$stdout.write(message)
|
40
|
+
gets.chomp
|
41
|
+
end
|
42
|
+
|
43
|
+
def run(*command)
|
44
|
+
puts "Running command #{command.inspect}"
|
45
|
+
|
46
|
+
IO.popen(*command) do |io|
|
47
|
+
return io.read.chomp
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
command = ARGV.shift
|
52
|
+
|
53
|
+
opts = Trollop::options do
|
54
|
+
opt :configuration, "Path to the configuration database.", :default => "cloudflare-dns.yml"
|
55
|
+
end
|
56
|
+
|
57
|
+
configuration_store = YAML::Store.new(opts[:configuration])
|
58
|
+
|
59
|
+
configuration_store.transaction do |configuration|
|
60
|
+
unless configuration[:key] && configuration[:email]
|
61
|
+
puts "This configuration file appears to be new, we require some details."
|
62
|
+
configuration[:key] = get_input "CloudFlare Key:"
|
63
|
+
configuration[:email] = get_input "CloudFlare Email:"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
cloudflare = nil
|
68
|
+
|
69
|
+
configuration_store.transaction do |configuration|
|
70
|
+
cloudflare = CloudFlare.new(configuration[:key], configuration[:email])
|
71
|
+
end
|
72
|
+
|
73
|
+
configuration_store.transaction do |configuration|
|
74
|
+
unless configuration[:zone]
|
75
|
+
puts "What zone do you want to modify? e.g. 'oriontransfer.co.nz'"
|
76
|
+
configuration[:zone] = get_input "DNS Zone:"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
configuration_store.transaction do |configuration|
|
81
|
+
unless configuration[:domain]
|
82
|
+
puts "Getting list of domains for #{configuration[:zone]}..."
|
83
|
+
|
84
|
+
result = cloudflare.rec_load_all(configuration[:zone])
|
85
|
+
|
86
|
+
check_result(result) do
|
87
|
+
records = result['response']['recs']['objs']
|
88
|
+
|
89
|
+
|
90
|
+
records.each.with_index do |record, index|
|
91
|
+
puts "(#{index}) #{record['name']} #{record['type']} #{record['content']}"
|
92
|
+
end
|
93
|
+
|
94
|
+
index = get_input "Which record to update?"
|
95
|
+
|
96
|
+
configuration[:domain] = records[index.to_i]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
configuration_store.transaction do |configuration|
|
102
|
+
unless configuration[:content_command]
|
103
|
+
puts "What command to get content for record? e.g. 'curl ipinfo.io/ip'"
|
104
|
+
configuration[:content_command] = get_input "Command to get latest IP address:"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
configuration_store.transaction do |configuration|
|
109
|
+
content = run(configuration[:content_command])
|
110
|
+
domain = configuration[:domain]
|
111
|
+
|
112
|
+
if domain['content'] != content
|
113
|
+
puts "Content changed #{content.dump}, updating record..."
|
114
|
+
# zone, type, zoneid, name, content, ttl, service_mode = nil, prio = nil, service = nil, srvname = nil, protocol = nil, weight = nil, port = nil, target = nil
|
115
|
+
|
116
|
+
arguments = [
|
117
|
+
configuration[:zone],
|
118
|
+
domain['type'],
|
119
|
+
domain['rec_id'],
|
120
|
+
domain['name'],
|
121
|
+
content,
|
122
|
+
domain['ttl']
|
123
|
+
]
|
124
|
+
|
125
|
+
result = cloudflare.rec_edit(*arguments)
|
126
|
+
|
127
|
+
check_result(result) do
|
128
|
+
puts "Updating domain content: #{content}"
|
129
|
+
domain['content'] = content
|
130
|
+
configuration[:domain] = domain
|
131
|
+
end
|
132
|
+
else
|
133
|
+
puts "Content hasn't changed."
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cloudflare/dns/update/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cloudflare-dns-update"
|
8
|
+
spec.version = CloudFlare::DNS::Update::VERSION
|
9
|
+
spec.authors = ["Samuel Williams"]
|
10
|
+
spec.email = ["samuel.williams@oriontransfer.co.nz"]
|
11
|
+
spec.description = <<-EOF
|
12
|
+
Provides a client tool for updating CloudFlare records, with a specific
|
13
|
+
emphasis on updating IP addresses for domain records. This provides
|
14
|
+
dyndns-like functionality.
|
15
|
+
EOF
|
16
|
+
spec.summary = "A dyndns client for CloudFlare."
|
17
|
+
spec.homepage = ""
|
18
|
+
spec.license = "MIT"
|
19
|
+
|
20
|
+
spec.files = `git ls-files`.split($/)
|
21
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
22
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
|
28
|
+
spec.add_dependency "trollop"
|
29
|
+
spec.add_dependency "cloudflare"
|
30
|
+
end
|
data/cloudflare-dns.yml
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
---
|
2
|
+
:key: e949a982e76093acbcd21277fcd3915e25163
|
3
|
+
:email: samuel@oriontransfer.org
|
4
|
+
:zone: oriontransfer.co.nz
|
5
|
+
:domain:
|
6
|
+
rec_id: '23414485'
|
7
|
+
rec_tag: 6978e0f1c24639abffb1d23a84ecb102
|
8
|
+
zone_name: oriontransfer.co.nz
|
9
|
+
name: hinoki.oriontransfer.co.nz
|
10
|
+
display_name: hinoki
|
11
|
+
type: A
|
12
|
+
prio:
|
13
|
+
content: 111.69.246.106
|
14
|
+
display_content: 111.69.246.106
|
15
|
+
ttl: '7200'
|
16
|
+
ttl_ceil: 86400
|
17
|
+
ssl_id:
|
18
|
+
ssl_status:
|
19
|
+
ssl_expires_on:
|
20
|
+
auto_ttl: 0
|
21
|
+
service_mode: '0'
|
22
|
+
props:
|
23
|
+
proxiable: 1
|
24
|
+
cloud_on: 0
|
25
|
+
cf_open: 1
|
26
|
+
ssl: 0
|
27
|
+
expired_ssl: 0
|
28
|
+
expiring_ssl: 0
|
29
|
+
pending_ssl: 0
|
30
|
+
vanity_lock: 0
|
31
|
+
:content: 111.69.238.117
|
32
|
+
:content_command: curl ipinfo.io/ip
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright, 2013, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require "cloudflare/dns/update/version"
|
22
|
+
|
23
|
+
module CloudFlare
|
24
|
+
module DNS
|
25
|
+
module Update
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright, 2013, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
|
22
|
+
module CloudFlare
|
23
|
+
module DNS
|
24
|
+
module Update
|
25
|
+
VERSION = "0.0.1"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cloudflare-dns-update
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Samuel Williams
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-04 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: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: trollop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: cloudflare
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: "\tProvides a client tool for updating CloudFlare records, with a specific\n\temphasis
|
70
|
+
on updating IP addresses for domain records. This provides\n\tdyndns-like functionality.\n"
|
71
|
+
email:
|
72
|
+
- samuel.williams@oriontransfer.co.nz
|
73
|
+
executables:
|
74
|
+
- cloudflare-dns-update
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- .gitignore
|
79
|
+
- Gemfile
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/cloudflare-dns-update
|
83
|
+
- cloudflare-dns-update.gemspec
|
84
|
+
- cloudflare-dns.yml
|
85
|
+
- lib/cloudflare/dns/update.rb
|
86
|
+
- lib/cloudflare/dns/update/version.rb
|
87
|
+
homepage: ''
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.0.6
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: A dyndns client for CloudFlare.
|
111
|
+
test_files: []
|