reverie 1.0.3 → 1.0.4

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
  SHA1:
3
- metadata.gz: 5fb63e6f97b5fad26cf7c215a088818b878a0040
4
- data.tar.gz: cbaa469c22dfe7a79a20dd502db1e8765b68d649
3
+ metadata.gz: f0e6d535ee29c82c33b1eeb63db13c8acbd08366
4
+ data.tar.gz: 5ee709ab0738226460c42dec5c6d4d3c28b92ddd
5
5
  SHA512:
6
- metadata.gz: c0c8f81f5485be3cfeebc94a1c40b2dd271d7edc2efdc08baf79de5a3b7272ac0c9ce55d97140ed7a587145c390820b63990d888a60a3c4536e81df3636113c2
7
- data.tar.gz: b1e8c09e49e09899e1a8cda3a457a72584f7b19999b6fab0a5156bd3c498d47f8f970e93240fdfa24c42137c5c332e40dd7120b971010925c87035a94205514c
6
+ metadata.gz: d1bc28925e1c9b8f02bfefc5aa510e5a8a8972b812522dfcf413ab8939b15e71e0fa9e7f881681224790a7d828a021ec9de0e7e31139682a8694e6d6d1c274bf
7
+ data.tar.gz: 6ff0838c163933e574fc21362932c7cbb9fdfd47d3cf26adc50fa2706989f021080efab5f71a6ffd67a14006a0dfb7be091566f4dceba2eed583c4e8937c3d71
@@ -1,165 +1 @@
1
- # Reverie
2
-
3
- # Ported from Ian McKellar's dreamhost-ddns
4
- # https://github.com/ianloic/dreamhost-ddns
5
-
6
- require 'net/http'
7
- require 'resolv'
8
- require 'logger'
9
- require 'yaml'
10
- require 'configliere'
11
-
12
- require_relative 'reverie/configliere'
13
- require_relative 'reverie/version'
14
-
15
- Settings.use :commandline, :config_file, :define
16
-
17
- class Reverie
18
- attr_accessor :log, :conf, :args
19
-
20
- DH_URI = URI 'https://api.dreamhost.com/'
21
- IP_URI = URI 'http://myexternalip.com/raw'
22
- CONF = Configliere::DEFAULT_CONFIG_LOCATION[:user_config][:reverie]
23
-
24
- OPENSSL_V3 = {
25
- use_ssl: true,
26
- ssl_version: :SSLv3,
27
- verify_mode: OpenSSL::SSL::VERIFY_PEER
28
- }
29
-
30
- MSGS = {
31
- success: '%s updated to %s',
32
- fail: '%s failed',
33
- found: 'get_ip found %s',
34
- too_soon: 'too soon, updated %ds ago',
35
- same: 'not updating %s',
36
- timeout: '%s timed out on %s',
37
- kv: '%s: %s',
38
- start: 'connecting to %s'
39
- }
40
-
41
- Settings.define :conf,
42
- type: :filename,
43
- description: 'The location of the configuration file',
44
- default: CONF
45
-
46
- Settings.define :log,
47
- type: :filename,
48
- description: 'The location of the log file'
49
-
50
- def self.update_dns
51
- Reverie.new.tap { |r| r.update_dns }
52
- end
53
-
54
- def initialize
55
- Settings.resolve!
56
-
57
- init_conf
58
- init_log
59
- init_args
60
- end
61
-
62
- def init_args
63
- @args = {
64
- key: Settings[:key],
65
- record: Settings[:record],
66
- format: 'yaml'
67
- }
68
- end
69
-
70
- def init_conf
71
- @conf = Settings.delete('conf') || CONF
72
- Settings.read @conf
73
- end
74
-
75
- def init_log
76
- @log = Logger.new(Settings.log || STDOUT)
77
- @log.level = Settings.delete('debug') ? Logger::DEBUG : Logger::INFO
78
- Settings.delete('log') unless Settings.log
79
- end
80
-
81
- def settings
82
- Settings
83
- end
84
-
85
- def update_dns
86
- t = Time.now - (Settings[:updated_at] || Time.mktime(0))
87
-
88
- if (t < 900 and d :too_soon, t) ||
89
- ((ip = get_ip).nil? and d :fail, 'get_ip') ||
90
- (ip == Settings[:ip] and d :same, Settings[:record]) ||
91
- (!replace_record Settings[:record], ip and d :fail, 'replace_record')
92
- return
93
- end
94
-
95
- Settings.merge! ip: ip, updated_at: Time.now
96
- Settings.save! @conf
97
- i :success, Settings[:record], ip
98
- end
99
-
100
- def replace_record(record, ip)
101
- return false unless record && ip
102
-
103
- status, res = api_call :list_records
104
- return false unless status == 'success'
105
-
106
- res.detect { |r| r['record'] == record && r['editable'] == 1 }.tap do |r|
107
- api_call :remove_record,
108
- record: record,
109
- type: r['type'],
110
- value: r['value'] if r
111
- end
112
-
113
- status, _ = api_call :add_record,
114
- record: record,
115
- type: 'A',
116
- value: ip,
117
- comment: "Reverie (#{ Time.now })"
118
- status == 'success'
119
- end
120
-
121
- def get_ip
122
- d :start, IP_URI
123
- ip = Net::HTTP.get_response(IP_URI).body.strip
124
- d :found, ip
125
- ip if ip =~ Resolv::IPv4::Regex
126
- rescue Net::ReadTimeout
127
- w :timeout, 'IP Lookup', IP_URI
128
- end
129
-
130
- private
131
-
132
- def api_call(cmd, args = {})
133
- a = @args.merge(cmd: "dns-#{ cmd }", unique_id: SecureRandom.uuid)
134
- a.merge! args
135
-
136
- d(DH_URI.query = URI.encode_www_form(a))
137
-
138
- req = Net::HTTP.start(DH_URI.host, DH_URI.port, OPENSSL_V3) do |http|
139
- http.get DH_URI
140
- end
141
-
142
- res = YAML.load(req.body)
143
- d :kv, a[:cmd], res['result']
144
-
145
- [res['result'], res['data']]
146
- rescue Net::ReadTimeout
147
- w :timeout, 'Dreamhost API', a[:cmd]
148
- end
149
-
150
- def d(msg, *args)
151
- __log :debug, msg, *args
152
- end
153
-
154
- def w(msg, *args)
155
- __log :warn, msg, *args
156
- end
157
-
158
- def i(msg, *args)
159
- __log :info, msg, *args
160
- end
161
-
162
- def __log(level, msg, *args)
163
- @log.send level, MSGS[msg] ? MSGS[msg] % args : msg
164
- end
165
- end
1
+ require_relative 'reverie/reverie'
@@ -0,0 +1,138 @@
1
+ # Reverie
2
+
3
+ # Ported from Ian McKellar's dreamhost-ddns
4
+ # https://github.com/ianloic/dreamhost-ddns
5
+
6
+ require 'net/http'
7
+ require 'resolv'
8
+ require 'logger'
9
+ require 'yaml'
10
+ require 'configliere'
11
+
12
+ require_relative 'configliere'
13
+ require_relative 'version'
14
+
15
+ Settings.use :commandline, :config_file, :define
16
+
17
+ class Reverie
18
+ attr_accessor :log, :conf, :args
19
+
20
+ DH_URI = URI 'https://api.dreamhost.com/'
21
+ IP_URI = URI 'http://myexternalip.com/raw'
22
+ CONF = Configliere::DEFAULT_CONFIG_LOCATION[:user_config][:reverie]
23
+
24
+ OPENSSL_OPTIONS = {
25
+ use_ssl: true,
26
+ ssl_version: :TLSv1,
27
+ verify_mode: OpenSSL::SSL::VERIFY_PEER
28
+ }
29
+
30
+ Settings.define :conf,
31
+ type: :filename,
32
+ description: 'The location of the configuration file',
33
+ default: CONF
34
+
35
+ Settings.define :log,
36
+ type: :filename,
37
+ description: 'The location of the log file'
38
+
39
+ def self.update_dns
40
+ Reverie.new.tap { |r| r.update_dns }
41
+ end
42
+
43
+ def initialize
44
+ Settings.resolve!
45
+
46
+ init_conf
47
+ init_log
48
+ init_args
49
+ end
50
+
51
+ def init_args
52
+ @args = {
53
+ key: Settings[:key],
54
+ record: Settings[:record],
55
+ format: 'yaml'
56
+ }
57
+ end
58
+
59
+ def init_conf
60
+ @conf = Settings.delete('conf') || CONF
61
+ Settings.read conf
62
+ end
63
+
64
+ def init_log
65
+ @log = Logger.new(Settings.log || STDOUT)
66
+ log.level = Settings.delete('debug') ? Logger::DEBUG : Logger::INFO
67
+ Settings.delete('log') unless Settings.log
68
+ end
69
+
70
+ def settings
71
+ Settings
72
+ end
73
+
74
+ def update_dns
75
+ last_update = Time.now - (Settings[:updated_at] || Time.mktime(0))
76
+
77
+ if (last_update < 900 and log.debug "too soon, updated #{last_update}s ago") ||
78
+ ((ip = get_ip).nil? and log.debug "get_ip failed") ||
79
+ (ip == Settings[:ip] and log.debug "not updating #{Settings[:record]}") ||
80
+ (!replace_record Settings[:record], ip and log.debug "replace_record failed")
81
+ return
82
+ end
83
+
84
+ Settings.merge! ip: ip, updated_at: Time.now
85
+ Settings.save! conf
86
+ log.info "#{Settings[:record]} updated to #{ip}"
87
+ end
88
+
89
+ def replace_record(record, ip)
90
+ return false unless record && ip
91
+
92
+ status, res = api_call :list_records
93
+ return false unless status == 'success'
94
+
95
+ res.detect { |r| r['record'] == record && r['editable'] == 1 }.tap do |r|
96
+ api_call :remove_record,
97
+ record: record,
98
+ type: r['type'],
99
+ value: r['value'] if r
100
+ end
101
+
102
+ status, _ = api_call :add_record,
103
+ record: record,
104
+ type: 'A',
105
+ value: ip,
106
+ comment: "Reverie (#{ Time.now })"
107
+ status == 'success'
108
+ end
109
+
110
+ def get_ip
111
+ log.debug "connecting to #{IP_URI}"
112
+ ip = Net::HTTP.get_response(IP_URI).body.strip
113
+ log.debug "got #{ip}"
114
+ ip if ip =~ Resolv::IPv4::Regex
115
+ rescue Net::ReadTimeout
116
+ log.warn :timeout, 'IP Lookup', IP_URI
117
+ end
118
+
119
+ private
120
+
121
+ def api_call(cmd, args = {})
122
+ a = @args.merge(cmd: "dns-#{ cmd }", unique_id: SecureRandom.uuid)
123
+ a.merge! args
124
+
125
+ log.info(DH_URI.query = URI.encode_www_form(a))
126
+
127
+ req = Net::HTTP.start(DH_URI.host, DH_URI.port, OPENSSL_OPTIONS) do |http|
128
+ http.get DH_URI
129
+ end
130
+
131
+ res = YAML.load(req.body)
132
+ log.info "#{a[:cmd]}: #{res['result']}"
133
+
134
+ [res['result'], res['data']]
135
+ rescue Net::ReadTimeout
136
+ log.warn "Dreamhost API timed out on #{a[:cmd]}"
137
+ end
138
+ end
@@ -1,4 +1,4 @@
1
1
  # Reverie version
2
2
  class Reverie
3
- VERSION = '1.0.3'
3
+ VERSION = '1.0.4'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reverie
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fission Xuiptz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-11 00:00:00.000000000 Z
11
+ date: 2017-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: configliere
@@ -39,6 +39,7 @@ files:
39
39
  - bin/reverie
40
40
  - lib/reverie.rb
41
41
  - lib/reverie/configliere.rb
42
+ - lib/reverie/reverie.rb
42
43
  - lib/reverie/version.rb
43
44
  - reverie.gemspec
44
45
  - test/test_reverie.rb
@@ -62,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
63
  version: '0'
63
64
  requirements: []
64
65
  rubyforge_project:
65
- rubygems_version: 2.2.2
66
+ rubygems_version: 2.6.8
66
67
  signing_key:
67
68
  specification_version: 4
68
69
  summary: Dreamhost DNS updater