google-ddns 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/google-ddns +5 -0
- data/google-ddns.gemspec +27 -0
- data/lib/google/ddns.rb +102 -0
- data/lib/google/ddns/version.rb +5 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 417b854687f96dc891a708f1b4ad2a94a1fda888
|
4
|
+
data.tar.gz: f9ab7be5822aaa34b763bcaadd7184f95a069dd7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dff0180f6b3df1164270a63814536d9cf5bf9d19a7dce8ff657403b2ca6d15c1fd326dca31388602479d6c73db875e454985cc90e4f41688fdae9798393f6f7b
|
7
|
+
data.tar.gz: 8fbf801f228ff6eb972c1ad1168686d626ba69619f2225fd905864570f57cf7416cba9effc5a158217811fc347869bbcb3bfaaf28ff5b4a535e0009db8e4d24c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Brian John
|
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,36 @@
|
|
1
|
+
# Google::Ddns
|
2
|
+
|
3
|
+
Client for Google DDNS. Designed to be run as a scheduled job on a *nix machine (e.g. cron).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```
|
8
|
+
$ gem install google-ddns
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
To get setup, run the `google-ddns` command and you will be prompted for your Google DDNS credentials. See [this
|
14
|
+
documentation on how to retrieve the credentials for your domain](https://support.google.com/domains/answer/6147083?hl=en).
|
15
|
+
|
16
|
+
NOTE: Your Google DDNS credentials will be stored in plaintext on your local machine.
|
17
|
+
|
18
|
+
Once you've provided your credentials, you can create a scheduled task to update your IP at an interval of your
|
19
|
+
choosing.
|
20
|
+
|
21
|
+
## Development
|
22
|
+
|
23
|
+
Fork the repo
|
24
|
+
Write tests
|
25
|
+
Submit a pull request
|
26
|
+
|
27
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/f1sherman/google-ddns.
|
32
|
+
|
33
|
+
|
34
|
+
## License
|
35
|
+
|
36
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "google/ddns"
|
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
|
data/bin/setup
ADDED
data/exe/google-ddns
ADDED
data/google-ddns.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'google/ddns/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "google-ddns"
|
8
|
+
spec.version = Google::Ddns::VERSION
|
9
|
+
spec.authors = ["Brian John"]
|
10
|
+
spec.email = ["brian@brianjohn.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Google DDNS Client}
|
13
|
+
spec.homepage = "https://github.com/f1sherman/google-ddns"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_development_dependency "webmock", "~> 2.3"
|
27
|
+
end
|
data/lib/google/ddns.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
require "google/ddns/version"
|
2
|
+
require 'yaml'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'io/console'
|
5
|
+
require 'net/http'
|
6
|
+
require 'logger'
|
7
|
+
require 'resolv'
|
8
|
+
|
9
|
+
module Google
|
10
|
+
module Ddns
|
11
|
+
def self.run
|
12
|
+
settings_directory = File.join Dir.home, ".google-ddns-gem"
|
13
|
+
settings_file = File.join settings_directory, "settings.yml"
|
14
|
+
|
15
|
+
if File.exist?(settings_file)
|
16
|
+
update_on_change settings_file
|
17
|
+
else
|
18
|
+
init_settings settings_directory, settings_file
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.update_on_change(settings_file)
|
23
|
+
settings = YAML.load_file settings_file
|
24
|
+
old_ip = settings["ip_address"]
|
25
|
+
|
26
|
+
current_ip = get_current_ip
|
27
|
+
|
28
|
+
if old_ip != current_ip
|
29
|
+
# Using the "warn" level will cause cron to send mail, so we know when our IP address changes
|
30
|
+
logger.warn "IP Address changed from #{old_ip} to #{current_ip}, updating..."
|
31
|
+
update_ip settings, settings_file
|
32
|
+
else
|
33
|
+
logger.info "IP Address has not changed from #{old_ip}, skipping update."
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.init_settings(settings_directory, settings_file)
|
38
|
+
unless $stdout.isatty
|
39
|
+
error "No Google DDNS setup information found! Please run google-ddns from an interactive terminal to get setup."
|
40
|
+
end
|
41
|
+
|
42
|
+
puts "Hi there! Looks like you don't have a settings file. Let's get you setup!"
|
43
|
+
FileUtils.mkdir_p settings_directory
|
44
|
+
|
45
|
+
settings = {}
|
46
|
+
|
47
|
+
print "Google DDNS Hostname: "
|
48
|
+
settings["hostname"] = $stdin.gets.chomp
|
49
|
+
print "Google DDNS Username: "
|
50
|
+
settings["username"] = $stdin.gets.chomp
|
51
|
+
print "Google DDNS Password (typing will be hidden): "
|
52
|
+
settings["password"] = $stdin.noecho(&:gets).chomp
|
53
|
+
puts
|
54
|
+
|
55
|
+
update_ip settings, settings_file
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.update_ip(settings, settings_file)
|
59
|
+
response = Net::HTTP.post_form URI("https://#{settings["username"]}:#{settings["password"]}@domains.google.com/nic/update"), "hostname" => settings["hostname"]
|
60
|
+
|
61
|
+
response_type, ip_address = response.body.split
|
62
|
+
|
63
|
+
unless response.code == "200" && ["good", "nochg"].include?(response_type)
|
64
|
+
error "Error updating IP Address! Received response code #{response.code} and body \"#{response.body}\"."
|
65
|
+
end
|
66
|
+
|
67
|
+
success_message = if response_type == "good"
|
68
|
+
"Updated #{settings["hostname"]} IP Address to #{ip_address}."
|
69
|
+
else
|
70
|
+
"Tried to update, but #{settings["hostname"]} IP Address was already set to #{ip_address}."
|
71
|
+
end
|
72
|
+
|
73
|
+
logger.info success_message
|
74
|
+
|
75
|
+
settings["ip_address"] = ip_address
|
76
|
+
settings["updated_at"] = Time.now.utc.to_s
|
77
|
+
|
78
|
+
YAML.dump settings, File.new(settings_file, "w")
|
79
|
+
FileUtils.chmod 0600, settings_file
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.get_current_ip
|
83
|
+
Resolv::DNS.new(:nameserver => "resolver1.opendns.com").getaddress("myip.opendns.com").to_s
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.logger
|
87
|
+
@logger ||= Logger.new($stdout).tap do |logger_instance|
|
88
|
+
logger_instance.level = $stdout.isatty ? Logger::INFO : Logger::WARN
|
89
|
+
logger_instance.formatter = proc { |_severity, _time, _progname, msg|
|
90
|
+
"#{msg}\n"
|
91
|
+
}
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.error(message)
|
96
|
+
logger.error message
|
97
|
+
exit false
|
98
|
+
end
|
99
|
+
|
100
|
+
run if defined? IN_EXECUTABLE_CONTEXT
|
101
|
+
end
|
102
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: google-ddns
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian John
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-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: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.3'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- brian@brianjohn.com
|
72
|
+
executables:
|
73
|
+
- google-ddns
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- exe/google-ddns
|
87
|
+
- google-ddns.gemspec
|
88
|
+
- lib/google/ddns.rb
|
89
|
+
- lib/google/ddns/version.rb
|
90
|
+
homepage: https://github.com/f1sherman/google-ddns
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.6.8
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Google DDNS Client
|
114
|
+
test_files: []
|