inwxupdate 0.2.0 → 0.3.0

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/inwxupdate +1 -26
  3. data/lib/inwx.rb +3 -1
  4. data/lib/inwxupdate.rb +76 -10
  5. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c06f99f473dbae0b1bc04925bc1517b199f674a
4
- data.tar.gz: 421da2c7128419f5bb3bb46b4a0c9312679dd373
3
+ metadata.gz: 01e732ecc8b4eb0888b1b0c12a5961c141f55819
4
+ data.tar.gz: 2fdcfc0a819ff787be13a67348874b38651f7a39
5
5
  SHA512:
6
- metadata.gz: 3379f90c591b310755134b9f6c84dce0cc53d6edd020e4feded40a33c75faa2c88e3e1b87e1a358cd3a38cd65360fe471c28898dc94a3f562eea2ec6230d4fcc
7
- data.tar.gz: fbe9b6a2004703345fb3eceee7c0aa4d7a44f80f034162044da7f95760d601348f4228ffd0c5236d998e2cd78fdfd5b4f06100ff11e448ac581b3928ef8f90be
6
+ metadata.gz: 94821898e8e59d13f57f92eeaae5e78e7bfea95c38ce97b6dc317bdf6835d8d7308c1c388f1388194dfca85278c75536cd406258606fe6249a467cb1062beae6
7
+ data.tar.gz: 59a006f5174f0037691b162ddbef67f7e43feef574bcccc74fa9c9136843e347e099b5b55052a5c7f75e92351017d4a9622252374e94586570b89fbee31d2dff
data/bin/inwxupdate CHANGED
@@ -2,29 +2,4 @@
2
2
 
3
3
  require 'inwxupdate'
4
4
 
5
- find_config!
6
-
7
- Account.login(user: CONFIG[:inwx_user], pass: CONFIG[:inwx_pass], lang: 'en')
8
-
9
- JOBS = CONFIG[:jobs]
10
- JOBS.each do |job|
11
- records_to_update = job[:records]
12
-
13
- records_to_update.each do |record_to_update|
14
- domains = Nameserver.list['domains']
15
- domain = domains.find do |entry|
16
- record_to_update[:name].end_with?(entry['domain'])
17
- end
18
-
19
- records = Nameserver.info(roId: domain['roId'])['record']
20
- matching_record = records.find do |record|
21
- record['name'] == record_to_update[:name] && record['type'] == record_to_update[:type]
22
- end
23
-
24
- next unless matching_record
25
-
26
- detector = Detector.setup(job[:detector])
27
- ip = detector.detect
28
- Nameserver.updateRecord(id: matching_record['id'], content: ip)
29
- end
30
- end
5
+ Inwxupdate.new.run
data/lib/inwx.rb CHANGED
@@ -10,7 +10,9 @@ class INWX
10
10
 
11
11
  def initialize
12
12
  # Create a new client instance
13
- @client = XMLRPC::Client.new(CONFIG[:inwx_api], '/xmlrpc/', '443', nil, nil, nil, nil, true, 100)
13
+ @client = XMLRPC::Client.new(
14
+ CONFIG[:inwx_api], '/xmlrpc/', '443', nil, nil, nil, nil, true, 100
15
+ )
14
16
  end
15
17
 
16
18
  def call(object, method, params = {})
data/lib/inwxupdate.rb CHANGED
@@ -1,19 +1,85 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative 'inwx.rb'
3
4
  require_relative 'detectors/detector.rb'
4
5
  require_relative 'detectors/ifconfig.rb'
5
6
  require_relative 'detectors/ipify.rb'
6
7
 
7
- def find_config!
8
- [
9
- '/etc/inwxupdate.config.rb',
10
- '/usr/local/etc/inwxupdate.config.rb',
11
- '~/inwxupdate.config.rb',
12
- './inwxupdate.config.rb'
13
- ].each do |path|
14
- return require(path) if File.exist?(path)
15
- next
8
+ require 'simpleidn'
9
+
10
+ class Inwxupdate
11
+ def run
12
+ find_config!
13
+
14
+ login
15
+
16
+ CONFIG[:jobs].each do |job|
17
+ process_job(job)
18
+ end
16
19
  end
17
20
 
18
- raise 'no config found'
21
+ private
22
+
23
+ def find_config!
24
+ [
25
+ '/etc/inwxupdate.config.rb',
26
+ '/usr/local/etc/inwxupdate.config.rb',
27
+ ENV['HOME'] + '/inwxupdate.config.rb',
28
+ './inwxupdate.config.rb'
29
+ ].each do |path|
30
+ return require(path) if File.exist?(path)
31
+ next
32
+ end
33
+
34
+ raise 'no config found'
35
+ end
36
+
37
+ def login
38
+ Account.login(
39
+ user: CONFIG[:inwx_user],
40
+ pass: CONFIG[:inwx_pass],
41
+ lang: 'en'
42
+ )
43
+ end
44
+
45
+ def process_job(job)
46
+ job[:records].each do |config_record|
47
+ matching_record = get_dns_record(config_record)
48
+
49
+ next unless matching_record
50
+
51
+ ip = Detector.setup(job[:detector]).detect
52
+ Nameserver.updateRecord(id: matching_record['id'], content: ip)
53
+ end
54
+ end
55
+
56
+ def get_dns_record(config_record)
57
+ domain = get_domain_from_name(config_record[:name])
58
+
59
+ inwx_records = Nameserver.info(roId: domain['roId'])['record']
60
+ inwx_records.find do |inwx_record|
61
+ match?(inwx_record, config_record)
62
+ end
63
+ end
64
+
65
+ def get_domain_from_name(name)
66
+ domainlist = Nameserver.list
67
+
68
+ raise 'no domainlist from inwx' unless domainlist
69
+
70
+ domainlist['domains'].find do |entry|
71
+ ace(name).end_with?(ace(entry['domain']))
72
+ end
73
+ end
74
+
75
+ def match?(inwx_record, config_record)
76
+ return false if ace(inwx_record['name']) != ace(config_record[:name])
77
+ return false if inwx_record['type'] != config_record[:type]
78
+
79
+ true
80
+ end
81
+
82
+ def ace(string)
83
+ SimpleIDN.to_ascii(string)
84
+ end
19
85
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inwxupdate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steffen Schröder
@@ -9,7 +9,21 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2016-10-16 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: simpleidn
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.7
13
27
  description: Updates your inwx-DNS records with the local IPv4/v6 address
14
28
  email: steffen@schröder.xyz
15
29
  executables: