do-dyndns 0.2.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6acae6a533a232c1b1a6669a654a720a888ec149ab2caee17c08db14e81e5a11
4
- data.tar.gz: '09b944f01f9b9aefbadfabb50c23c71a31981cee7817eb9117153d95ead2bd74'
3
+ metadata.gz: a45320eb7b5dd1d027f5c12daa59498f6e861ca38005b6fc80ec559106ba0f43
4
+ data.tar.gz: cc4f5886a47dd1f86c5f6cd297d2c90a1b785b8066b4868ca6f5344e2d40ed29
5
5
  SHA512:
6
- metadata.gz: db766ce0f59398b1834bf0e7f199730371aef8d0d41c64f1f912c07831bf4ddd25a2a3bf594a9c4233cc4f4697293138c493efc91c69f8983d65a39314f789d2
7
- data.tar.gz: dacd17e32bce6057f759d0a4655aa0dd59da5110dbc6e26df48e3512f1ce9a12a2824002ca4d28f3b9ed974f97d1ca0ec1d9d61735e96426e2286312c1265d4d
6
+ metadata.gz: 489d3253a1c6ed719158254bd2a246f6f63a0a79a6ed62f8908d470731825793954656b5603613a8e8e148a60c59f8bac077466185a41888b214cccac6c9108f
7
+ data.tar.gz: 727165fd149526b1dd4cc6edd28b896361755046a34188331cde0a4a92c19d0af67903bbcd5e4a54dcd3235703e7fd9f71028ed1b5ea2801115eb911592047c3
data/README.md CHANGED
@@ -1,16 +1,44 @@
1
1
  # DO-Dyndns
2
2
 
3
- Automatically update DNS records on DigitalOcean
3
+ Automatically update DNS records on DigitalOcean to the current IP of the machine running the script.
4
4
 
5
5
  Finds the wan IPv4 address of the server it's running on and
6
6
  updates the corresponding DNS records on digital ocean.
7
7
 
8
+ This is useful if you don't have a static ip from your ISP.
9
+
8
10
  ## Installation
9
11
  `$ gem install do-dyndns`
10
12
 
11
- ## Configuration
13
+ ## Gemfile
14
+
15
+ `gem 'do-dyndns', '~> 0.3.0'`
16
+
17
+ `require 'do_dydns'`
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ require 'do_dyndns'
23
+
24
+ updater = DoDyndns::Updater.new(
25
+ token: '...',
26
+ domains: {
27
+ 'example.com' => [
28
+ 'subdomain'
29
+ ]
30
+ },
31
+ logger: Logger.new($stdout)
32
+ )
33
+
34
+ updater.update_ips # Updates 'subdomain.example.com' to your current IPv4 address
35
+ ```
36
+
37
+ ## CLI Configuration
38
+ When runninng `do_dyndns`, the updater reads a configuration file:
39
+
12
40
  Configuration is located at:
13
- `~/.config/dyndns.yml`
41
+ `~/.config/do-dyndns.yml`
14
42
 
15
43
  if no config file is found, do-dyndns will create one and open it with your `$EDITOR`
16
44
 
@@ -21,19 +49,50 @@ if no config file is found, do-dyndns will create one and open it with your `$ED
21
49
  - example-subdomain1
22
50
  ```
23
51
 
24
- ## Usage
52
+ ## CLI Usage
25
53
  ```
26
- $ dyndns
54
+ $ do-dyndns
27
55
  I, [2019-03-26T14:39:20.643564 #11387] INFO -- : Started IP check
28
56
  I, [2019-03-26T14:39:20.720905 #11387] INFO -- : Current WAN IP: **.**.**.**
29
57
  I, [2019-03-26T14:39:21.977426 #11387] INFO -- : IPs Match for ***.***.***
30
58
  ```
31
59
 
32
60
  ## Automation
61
+ Following are examples on how to run this script periodically to update your VPS with the machine's current IP
33
62
 
34
63
  ### Cron:
35
64
  Check every 15 minutes:
36
65
 
37
66
  ```
38
- */15 * * * * dyndns
67
+ */15 * * * * /path/to/do-dyndns
68
+ ```
69
+
70
+
71
+ ### Launchctl
72
+ Check every 15 minutes:
73
+
74
+ ```xml
75
+ <?xml version="1.0" encoding="UTF-8"?>
76
+ <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
77
+ <plist version="1.0">
78
+ <dict>
79
+ <key>Label</key>
80
+ <string>com.pixelfaucet.do-dyndns</string>
81
+
82
+ <key>WorkingDirectory</key>
83
+ <string>~/</string>
84
+
85
+ <key>UserName</key>
86
+ <string>nobody</string>
87
+
88
+ <key>ProgramArguments</key>
89
+ <array>
90
+ <string>~/.rvm/wrappers/ruby-2.6.5@do-dyndns</string>
91
+ <string>do-dyndns</string>
92
+ </array>
93
+
94
+ <key>StartInterval</key>
95
+ <integer>900</integer>
96
+ </dict>
97
+ </plist>
39
98
  ```
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "dyndns"
4
+ require "do_dyndns"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -6,22 +6,37 @@ require 'yaml'
6
6
  require 'fileutils'
7
7
  require 'logger'
8
8
  require 'shellwords'
9
- require 'dyndns'
9
+ require 'do_dyndns'
10
10
 
11
11
  LOG = Logger.new($stdout)
12
12
 
13
13
  rpath = File.expand_path(File.dirname(__FILE__))
14
14
  Dir.chdir rpath
15
15
 
16
- config_path = File.expand_path "~/.config/dyndns.yml"
16
+ config_path = File.expand_path "~/.config/do-dyndns.yml"
17
17
 
18
18
  if File.exist? config_path
19
19
  config = YAML.load_file config_path
20
- Dyndns::Updater.new(**config, logger: LOG).update_ips
20
+
21
+ key_missing = false
22
+ %i[token domains ipv4_commands ipv6_commands].each do |key|
23
+ unless config.key?(key)
24
+ key_missing = true
25
+ $stderr.puts "missing configuration: `:#{key}`"
26
+ end
27
+ end
28
+
29
+ if key_missing
30
+ $stderr.puts "\nExample configuration:\n\n```yml\n#{File.read("../config.example.yml")}\n```"
31
+ exit 1
32
+ end
33
+
34
+ DoDyndns::Updater.new(**config, logger: LOG).update_ips
21
35
  else
22
36
  LOG.warn "No configuration exists @ #{config_path}: Creating file."
23
37
  FileUtils.mkdir_p File.dirname(config_path)
24
38
  FileUtils.cp("../config.example.yml", config_path)
25
39
  editor = ENV['EDITOR'] || 'nano'
26
40
  system "#{editor} #{Shellwords.shellescape(config_path)}"
41
+ LOG.info "Config created."
27
42
  end
data/config.example.yml CHANGED
@@ -1,4 +1,13 @@
1
1
  :token: your_digital_ocean_token_here
2
+
2
3
  :domains:
3
4
  example-domain1.com:
4
5
  - example-subdomain1
6
+
7
+ :ipv4_commands:
8
+ - "dig -4 @ns1-1.akamaitech.net ANY whoami.akamai.net +short"
9
+ - "dig -4 @ns1.google.com ANY o-o.myaddr.l.google.com +short"
10
+
11
+ :ipv6_commands:
12
+ - "dig -6 @resolver1.opendns.com ANY myip.opendns.com +short"
13
+ - "dig -6 @ns1.google.com ANY o-o.myaddr.l.google.com +short"
@@ -1,14 +1,19 @@
1
- module Dyndns
1
+ module DoDyndns
2
2
  class Updater
3
3
  require 'droplet_kit'
4
4
 
5
- def initialize(token:, domains:, logger: Logger.new($stdout))
5
+ IPV4_RE = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/m
6
+ IPV6_RE = /(?:\:{,2}[A-Z\d]{1,4}\:{,2}){1,8}/im
7
+
8
+ def initialize(token:, domains:, ipv4_commands:, ipv6_commands:, logger: Logger.new($stdout))
6
9
  @logger = logger
7
10
  @domains = domains
11
+ @ipv4_commands = ipv4_commands
12
+ @ipv6_commands = ipv6_commands
8
13
  @api = DropletKit::Client.new(access_token: token)
9
14
  end
10
15
 
11
- # Get the domains from DO's API and selecto only ones specified in the config
16
+ # Get the domains from DO's API and select only ones specified in the config
12
17
  def domains
13
18
  @api.domains
14
19
  .all
@@ -57,29 +62,24 @@ module Dyndns
57
62
  end
58
63
 
59
64
  def wan_ipv4
60
- resolve([
61
- "dig -4 @resolver1.opendns.com ANY myip.opendns.com +short",
62
- "dig -4 @ns1-1.akamaitech.net ANY whoami.akamai.net +short",
63
- "dig -4 @ns1.google.com ANY o-o.myaddr.l.google.com +short"
64
- ])
65
+ resolve(@ipv4_commands, regex: IPV4_RE)
65
66
  end
66
67
 
67
68
  def wan_ipv6
68
- resolve([
69
- "dig -6 @resolver1.opendns.com ANY myip.opendns.com +short",
70
- "dig -6 @ns1.google.com ANY o-o.myaddr.l.google.com +short"
71
- ])
69
+ resolve(@ipv6_commands, regex: IPV6_RE)
72
70
  end
73
71
 
74
72
  private
75
73
 
76
- def resolve(commands)
74
+ # Try all the commands until one of them works
75
+ def resolve(commands, regex:)
77
76
  _ip = nil
78
- commands.each do |service|
79
- _ip = `#{service}`.chomp.gsub(/[^a-z0-9\:\.]/i, '')
80
- _ip = _ip and break unless _ip.empty?
77
+ commands.each do |command|
78
+ result = `#{command}`
79
+ _ip = result[regex]
80
+ break if _ip
81
81
  end
82
- _ip.empty? ? nil : _ip
82
+ _ip
83
83
  end
84
84
  end
85
- end
85
+ end
@@ -0,0 +1,3 @@
1
+ module DoDyndns
2
+ VERSION = "0.4.0"
3
+ end
data/lib/do_dyndns.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "do_dyndns/version"
2
+ require "do_dyndns/updater"
3
+
4
+ module DoDyndns
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: do-dyndns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Clink
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-27 00:00:00.000000000 Z
11
+ date: 2022-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,79 +16,79 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.13'
19
+ version: '2.1'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.13'
26
+ version: '2.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: 13.0.6
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: 13.0.6
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: '3.11'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
54
+ version: '3.11'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: droplet_kit
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 3.18.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 3.18.0
69
69
  description: |
70
70
  Finds the wan IPv4 address of the server it's running on and
71
71
  updates the corresponding DNS records on digital ocean.
72
72
  email:
73
73
  - alexclink@gmail.com
74
74
  executables:
75
- - dyndns
75
+ - do_dyndns
76
76
  extensions: []
77
77
  extra_rdoc_files: []
78
78
  files:
79
79
  - README.md
80
80
  - bin/console
81
- - bin/dyndns
81
+ - bin/do_dyndns
82
82
  - bin/setup
83
83
  - config.example.yml
84
- - lib/dyndns.rb
85
- - lib/dyndns/updater.rb
86
- - lib/dyndns/version.rb
87
- homepage: http://alexclink.com/gems/dyndns
84
+ - lib/do_dyndns.rb
85
+ - lib/do_dyndns/updater.rb
86
+ - lib/do_dyndns/version.rb
87
+ homepage: https://github.com/SleepingInsomniac/dyndns
88
88
  licenses:
89
- - UNLICENSED
89
+ - MIT
90
90
  metadata: {}
91
- post_install_message:
91
+ post_install_message:
92
92
  rdoc_options: []
93
93
  require_paths:
94
94
  - lib
@@ -103,8 +103,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  requirements: []
106
- rubygems_version: 3.0.3
107
- signing_key:
106
+ rubygems_version: 3.3.7
107
+ signing_key:
108
108
  specification_version: 4
109
109
  summary: Automatically update DNS records on DigitalOcean
110
110
  test_files: []
@@ -1,3 +0,0 @@
1
- module Dyndns
2
- VERSION = "0.2.0"
3
- end
data/lib/dyndns.rb DELETED
@@ -1,5 +0,0 @@
1
- require "dyndns/version"
2
- require "dyndns/updater"
3
-
4
- module Dyndns
5
- end