reverie 1.0.1 → 1.0.2
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 +4 -4
- data/Rakefile +1 -1
- data/lib/reverie/version.rb +2 -1
- data/lib/reverie.rb +92 -45
- data/reverie.gemspec +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fb22911434d9be837fe65b4501636427a964ffd
|
4
|
+
data.tar.gz: 9021a07c63cc95a0e3c5b15fb59e523ddb6930b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c0ff4ad9779d50c494aca3cd16c879822f8ef107f8680bda4f10aa088c5770da335ab0f4e5766dfb5aa3429619d192d5dfab3d6454bf2db034c3c5e0cd2d85c
|
7
|
+
data.tar.gz: 4630eda64eb8711f3627a096cb295b4c6ad7814dc2f9e7d58a9b3d35248c346593389893c22d5b99e2a7905ab0be8dd9b7ae0a0758655a062f1bdd8919ba70a4
|
data/Rakefile
CHANGED
data/lib/reverie/version.rb
CHANGED
data/lib/reverie.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Reverie
|
2
|
-
|
2
|
+
|
3
3
|
# Ported from Ian McKellar's dreamhost-ddns
|
4
4
|
# https://github.com/ianloic/dreamhost-ddns
|
5
5
|
|
@@ -16,41 +16,67 @@ class Reverie
|
|
16
16
|
DH_URI = URI 'https://api.dreamhost.com/'
|
17
17
|
IP_URI = URI 'http://myexternalip.com/raw'
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
OPENSSL_V3 = {
|
20
|
+
use_ssl: true,
|
21
|
+
ssl_version: :SSLv3,
|
22
|
+
verify_mode: OpenSSL::SSL::VERIFY_PEER
|
23
|
+
}
|
24
|
+
|
25
|
+
MSGS = {
|
26
|
+
success: '%s updated to %s',
|
27
|
+
fail: '%s failed',
|
28
|
+
found: 'get_ip found %s',
|
29
|
+
too_soon: 'too soon, updated %ds ago',
|
30
|
+
same: 'not updating %s',
|
31
|
+
timeout: '%s timed out on %s',
|
32
|
+
kv: '%s: %s'
|
33
|
+
}
|
34
|
+
|
35
|
+
Settings.define :conf,
|
36
|
+
type: :filename,
|
37
|
+
description: 'The location of the configuration file',
|
38
|
+
default: Configliere::DEFAULT_CONFIG_LOCATION[:user].call('reverie')
|
39
|
+
|
40
|
+
Settings.define :log,
|
41
|
+
type: :filename,
|
42
|
+
description: 'The location of the log file'
|
24
43
|
|
25
44
|
def self.update_dns
|
26
45
|
Reverie.new.tap { |r| r.update_dns }
|
27
46
|
end
|
28
47
|
|
29
48
|
def initialize
|
30
|
-
|
31
|
-
@
|
32
|
-
|
49
|
+
Settings.resolve!
|
50
|
+
Settings.read(@conf = Settings.delete('conf'))
|
51
|
+
|
52
|
+
@log = Logger.new(Settings.log || STDOUT)
|
53
|
+
@log.level = Settings.delete('debug') ? Logger::DEBUG : Logger::INFO
|
54
|
+
Settings.delete('log') unless Settings.log
|
33
55
|
|
34
|
-
@
|
35
|
-
|
36
|
-
|
56
|
+
@args = {
|
57
|
+
key: Settings[:key],
|
58
|
+
record: Settings[:record],
|
59
|
+
format: 'yaml'
|
60
|
+
}
|
61
|
+
end
|
37
62
|
|
38
|
-
|
39
|
-
|
40
|
-
format: 'yaml' }
|
63
|
+
def settings
|
64
|
+
Settings
|
41
65
|
end
|
42
66
|
|
43
67
|
def update_dns
|
44
|
-
t = Time.now - (
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
68
|
+
t = Time.now - (Settings[:updated_at] || Time.mktime(0))
|
69
|
+
|
70
|
+
if (t < 900 and d :too_soon, t) ||
|
71
|
+
((ip = get_ip).nil? and d :fail, 'get_ip') ||
|
72
|
+
(ip == Settings[:ip] and d :same, Settings[:record]) ||
|
73
|
+
(!replace_record Settings[:record], ip and d :fail, 'replace_record')
|
74
|
+
return
|
75
|
+
end
|
76
|
+
|
77
|
+
Settings.merge! ip: ip, updated_at: Time.now
|
78
|
+
Settings.save! @conf
|
79
|
+
i :success, Settings[:record], ip
|
54
80
|
end
|
55
81
|
|
56
82
|
def replace_record(record, ip)
|
@@ -59,41 +85,62 @@ class Reverie
|
|
59
85
|
status, res = api_call :list_records
|
60
86
|
return false unless status == 'success'
|
61
87
|
|
62
|
-
res.detect { |r| r['record'] == record && r['editable'] == 1 }.tap
|
63
|
-
api_call :remove_record,
|
64
|
-
|
65
|
-
|
66
|
-
|
88
|
+
res.detect { |r| r['record'] == record && r['editable'] == 1 }.tap do |r|
|
89
|
+
api_call :remove_record,
|
90
|
+
record: record,
|
91
|
+
type: r['type'],
|
92
|
+
value: r['value'] if r
|
93
|
+
end
|
94
|
+
|
95
|
+
status, _ = api_call :add_record,
|
96
|
+
record: record,
|
97
|
+
type: 'A',
|
98
|
+
value: ip,
|
99
|
+
comment: "Reverie (#{ Time.now })"
|
67
100
|
status == 'success'
|
68
101
|
end
|
69
102
|
|
70
103
|
def get_ip
|
71
|
-
ip = Net::HTTP.get_response(IP_URI).body.
|
72
|
-
|
104
|
+
ip = Net::HTTP.get_response(IP_URI).body.strip
|
105
|
+
d :found, ip
|
73
106
|
ip if ip =~ Resolv::IPv4::Regex
|
74
107
|
rescue Net::ReadTimeout
|
75
|
-
|
108
|
+
w :timeout, 'IP Lookup', IP_URI
|
76
109
|
end
|
77
110
|
|
78
|
-
private
|
111
|
+
private
|
79
112
|
|
80
113
|
def api_call(cmd, args = {})
|
81
|
-
a = @args.merge
|
114
|
+
a = @args.merge(cmd: "dns-#{ cmd }", unique_id: SecureRandom.uuid)
|
82
115
|
a.merge! args
|
83
116
|
|
84
|
-
DH_URI.query = URI.encode_www_form
|
85
|
-
@log.debug DH_URI.query
|
117
|
+
d(DH_URI.query = URI.encode_www_form(a))
|
86
118
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
@log.debug "#{ a[:cmd] }: #{ res['result'] }"
|
119
|
+
req = Net::HTTP.start(DH_URI.host, DH_URI.port, OPENSSL_V3) do |http|
|
120
|
+
http.get DH_URI
|
121
|
+
end
|
122
|
+
|
123
|
+
res = YAML.load(req.body)
|
124
|
+
d :kv, a[:cmd], res['result']
|
94
125
|
|
95
126
|
return res['result'], res['data']
|
96
127
|
rescue Net::ReadTimeout
|
97
|
-
|
128
|
+
w :timeout, 'Dreamhost API', a[:cmd]
|
129
|
+
end
|
130
|
+
|
131
|
+
def d(msg, *args)
|
132
|
+
log :debug, msg, *args
|
133
|
+
end
|
134
|
+
|
135
|
+
def w(msg, *args)
|
136
|
+
log :warn, msg, *args
|
137
|
+
end
|
138
|
+
|
139
|
+
def i(msg, *args)
|
140
|
+
log :info, msg, *args
|
141
|
+
end
|
142
|
+
|
143
|
+
def log(level, msg, *args)
|
144
|
+
@log.send level, MSGS[msg] ? MSGS[msg] % args : msg
|
98
145
|
end
|
99
146
|
end
|
data/reverie.gemspec
CHANGED
@@ -15,9 +15,9 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.summary = 'Dreamhost DNS updater'
|
16
16
|
s.description = 'A ruby script to update Dreamhost DNS'
|
17
17
|
|
18
|
-
s.files = `git ls-files`.split
|
19
|
-
s.executables = s.files.grep(
|
20
|
-
s.test_files = s.files.grep(
|
18
|
+
s.files = `git ls-files`.split "\n"
|
19
|
+
s.executables = s.files.grep(/^bin\//) { |f| File.basename f }
|
20
|
+
s.test_files = s.files.grep(/^(test|spec|features)\//)
|
21
21
|
s.require_paths = ['lib']
|
22
22
|
|
23
23
|
s.add_runtime_dependency 'configliere', '~> 0.4'
|
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.
|
4
|
+
version: 1.0.2
|
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-04-
|
11
|
+
date: 2014-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: configliere
|