inwxupdate 0.2.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5c06f99f473dbae0b1bc04925bc1517b199f674a
4
+ data.tar.gz: 421da2c7128419f5bb3bb46b4a0c9312679dd373
5
+ SHA512:
6
+ metadata.gz: 3379f90c591b310755134b9f6c84dce0cc53d6edd020e4feded40a33c75faa2c88e3e1b87e1a358cd3a38cd65360fe471c28898dc94a3f562eea2ec6230d4fcc
7
+ data.tar.gz: fbe9b6a2004703345fb3eceee7c0aa4d7a44f80f034162044da7f95760d601348f4228ffd0c5236d998e2cd78fdfd5b4f06100ff11e448ac581b3928ef8f90be
data/bin/inwxupdate ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'inwxupdate'
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
@@ -0,0 +1,11 @@
1
+ module Detector
2
+ def self.setup(paramters)
3
+ if paramters[:type] == 'ifconfig' && paramters[:version] == 6
4
+ return Ifconfig.new(paramters[:network_interface], paramters[:version])
5
+ end
6
+
7
+ if paramters[:type] == 'ipify'
8
+ return Ipify.new(paramters[:network_interface], paramters[:version])
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Detects your current IP via `ifconfig`
4
+ class Ifconfig
5
+ def initialize(network_interface, _version)
6
+ @network_interface = network_interface
7
+ end
8
+
9
+ def detect
10
+ raw = `ifconfig #{@network_interface} inet6 | grep inet6 | grep -v fe80 | grep -v deprecated`
11
+ ip = raw.lstrip.split(' ')[1]
12
+
13
+ raise 'no ip detected' unless ip
14
+
15
+ ip
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Detects your current IP via `ifconfig`
4
+ class Ipify
5
+ def initialize(network_interface, version)
6
+ @network_interface = network_interface
7
+ @version = version == 6 ? 6 : 4
8
+
9
+ raise 'Ipify supports only IPv4 yet' if version == 6
10
+ end
11
+
12
+ def detect
13
+ ip = `curl -#{@version} --interface #{@network_interface} 'https://api.ipify.org?format=text' -s`
14
+
15
+ raise 'no ip detected' unless ip
16
+
17
+ ip
18
+ end
19
+ end
data/lib/inwx.rb ADDED
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'singleton'
4
+ require 'xmlrpc/client'
5
+ require 'yaml'
6
+
7
+ # Wrapper for the INWX XMLRPC Client
8
+ class INWX
9
+ include Singleton
10
+
11
+ def initialize
12
+ # Create a new client instance
13
+ @client = XMLRPC::Client.new(CONFIG[:inwx_api], '/xmlrpc/', '443', nil, nil, nil, nil, true, 100)
14
+ end
15
+
16
+ def call(object, method, params = {})
17
+ @client.call("#{object}.#{method}", params)
18
+ end
19
+ end
20
+
21
+ # Implements the convienience
22
+ class APIObject
23
+ def self.method_missing(*args)
24
+ args = [name.downcase] + args
25
+
26
+ result = INWX.instance.call(*args)
27
+
28
+ puts YAML.dump(result) if CONFIG[:debug]
29
+
30
+ result['resData']
31
+ end
32
+ end
33
+
34
+ class Account < APIObject; end
35
+ class Accounting < APIObject; end
36
+ class Application < APIObject; end
37
+ class Contact < APIObject; end
38
+ class Domain < APIObject; end
39
+ class Host < APIObject; end
40
+ class Hosting < APIObject; end
41
+ class Message < APIObject; end
42
+ class Nameserver < APIObject; end
43
+ class NameserverSet < APIObject; end
44
+ class Pdf < APIObject; end
45
+ class Tag < APIObject; end
data/lib/inwxupdate.rb ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'inwx.rb'
3
+ require_relative 'detectors/detector.rb'
4
+ require_relative 'detectors/ifconfig.rb'
5
+ require_relative 'detectors/ipify.rb'
6
+
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
16
+ end
17
+
18
+ raise 'no config found'
19
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inwxupdate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Steffen Schröder
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Updates your inwx-DNS records with the local IPv4/v6 address
14
+ email: steffen@schröder.xyz
15
+ executables:
16
+ - inwxupdate
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/inwxupdate
21
+ - lib/detectors/detector.rb
22
+ - lib/detectors/ifconfig.rb
23
+ - lib/detectors/ipify.rb
24
+ - lib/inwx.rb
25
+ - lib/inwxupdate.rb
26
+ homepage: https://github.com/ChaosSteffen/inwxupdate
27
+ licenses:
28
+ - BSD
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.4.5.1
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: inwxupdate
50
+ test_files: []