reverie 1.0.1

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: a16fb53c6a3336f4e30f595f703462173159ae46
4
+ data.tar.gz: b353004ce2dd8796f981f9080e2faefa0308e133
5
+ SHA512:
6
+ metadata.gz: c4d53f9ff6e597d11a8e98a6581f5441d708a4eb765e09bfb0774b051d6cd1cfe72823b45e4d8c2f0fbb589bd425af5533a2d189562ae83c87784c9e1948e617
7
+ data.tar.gz: d54c9d8093a4b067fd1dc4e6baa8c007c31f5c143e894ac593fa57a1a55a010672c24110580d3d668a3733396d354e7947eb07cfe5a8232202f2194cc4577b18
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ Gemfile.lock
7
+ Guardfile
8
+ InstalledFiles
9
+ lib/bundler/man
10
+ pkg
11
+ rdoc
12
+ spec/reports
13
+ test/tmp
14
+ test/version_tmp
15
+ tmp
16
+
17
+ # YARD artifacts
18
+ .yardoc
19
+ _yardoc
20
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in reverie.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'rake'
8
+ gem 'minitest', '~> 4.3'
9
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Fission Xuiptz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ reverie
2
+ =======
3
+
4
+ A ruby script for updating Dreamhost DNS.
5
+
6
+ Ported from Ian McKellar's [dreamhost-ddns](https://github.com/ianloic/dreamhost-ddns).
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ task :default => :test
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs.push 'lib'
8
+ t.test_files = FileList['test/*_test.rb']
9
+ end
data/bin/reverie ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../lib/reverie'
4
+
5
+ Reverie.update_dns
@@ -0,0 +1,3 @@
1
+ class Reverie
2
+ VERSION = '1.0.1'
3
+ end
data/lib/reverie.rb ADDED
@@ -0,0 +1,99 @@
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
+ require 'reverie/version'
12
+
13
+ Settings.use :commandline, :config_file, :define
14
+
15
+ class Reverie
16
+ DH_URI = URI 'https://api.dreamhost.com/'
17
+ IP_URI = URI 'http://myexternalip.com/raw'
18
+
19
+ Settings.define :conf, type: :filename, description: 'The location of the configuration file',
20
+ default: Configliere::DEFAULT_CONFIG_LOCATION[:user].call('reverie')
21
+ Settings.define :log, type: :filename, description: 'The location of the log file'
22
+
23
+ attr_accessor :options, :args
24
+
25
+ def self.update_dns
26
+ Reverie.new.tap { |r| r.update_dns }
27
+ end
28
+
29
+ def initialize
30
+ @options = Settings
31
+ @options.resolve!
32
+ @options.read(@conf = @options.delete('conf'))
33
+
34
+ @log = Logger.new(@options.log || STDOUT)
35
+ @log.level = @options.delete('debug') ? Logger::DEBUG : Logger::INFO
36
+ @options.delete('log') unless @options.log
37
+
38
+ @args = { key: @options[:key],
39
+ record: @options[:record],
40
+ format: 'yaml' }
41
+ end
42
+
43
+ def update_dns
44
+ t = Time.now - (@options[:updated_at] || Time.mktime(0))
45
+ return if
46
+ (t < 900 and @log.debug "too soon, updated #{ t.to_int }s ago") ||
47
+ ((ip = get_ip).nil? and @log.debug 'get_ip failed') ||
48
+ (ip == @options[:ip] and @log.debug "not updating #{ @options[:record ]}") ||
49
+ (!replace_record @options[:record], ip and @log.debug 'replace_record failed')
50
+
51
+ @options.merge! ip: ip, updated_at: Time.now
52
+ @options.save! @conf
53
+ @log.info "#{ @options[:record] } updated to #{ ip }"
54
+ end
55
+
56
+ def replace_record(record, ip)
57
+ return false unless record && ip
58
+
59
+ status, res = api_call :list_records
60
+ return false unless status == 'success'
61
+
62
+ res.detect { |r| r['record'] == record && r['editable'] == 1 }.tap { |r|
63
+ api_call :remove_record, record: record, type: r['type'], value: r['value'] if r
64
+ }
65
+
66
+ status, res = api_call :add_record, record: record, type: 'A', value: ip, comment: "Reverie (#{ Time.now })"
67
+ status == 'success'
68
+ end
69
+
70
+ def get_ip
71
+ ip = Net::HTTP.get_response(IP_URI).body.chomp
72
+ @log.debug "get_ip found #{ ip }"
73
+ ip if ip =~ Resolv::IPv4::Regex
74
+ rescue Net::ReadTimeout
75
+ @log.warn 'IP lookup timed out'
76
+ end
77
+
78
+ private
79
+
80
+ def api_call(cmd, args = {})
81
+ a = @args.merge cmd: "dns-#{ cmd }", unique_id: SecureRandom.uuid
82
+ a.merge! args
83
+
84
+ DH_URI.query = URI.encode_www_form a
85
+ @log.debug DH_URI.query
86
+
87
+ opts = {
88
+ use_ssl: true,
89
+ ssl_version: :SSLv3,
90
+ verify_mode: OpenSSL::SSL::VERIFY_PEER
91
+ }
92
+ res = YAML.load(Net::HTTP.start(DH_URI.host, DH_URI.port, opts) { |http| http.get DH_URI }.body)
93
+ @log.debug "#{ a[:cmd] }: #{ res['result'] }"
94
+
95
+ return res['result'], res['data']
96
+ rescue Net::ReadTimeout
97
+ @log.warn "Dreamhost API timed out on #{ a[:cmd] }"
98
+ end
99
+ end
data/reverie.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path '../lib', __FILE__
3
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib
4
+ require 'reverie/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'reverie'
8
+ s.version = Reverie::VERSION
9
+ s.date = Time.new.strftime '%Y-%m-%d'
10
+ s.author = 'Fission Xuiptz'
11
+ s.email = 'fissionxuiptz@softwaremojo.com'
12
+ s.homepage = 'http://github.com/fissionxuiptz/reverie'
13
+ s.license = 'MIT'
14
+
15
+ s.summary = 'Dreamhost DNS updater'
16
+ s.description = 'A ruby script to update Dreamhost DNS'
17
+
18
+ s.files = `git ls-files`.split $/
19
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename f }
20
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
21
+ s.require_paths = ['lib']
22
+
23
+ s.add_runtime_dependency 'configliere', '~> 0.4'
24
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reverie
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Fission Xuiptz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: configliere
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.4'
27
+ description: A ruby script to update Dreamhost DNS
28
+ email: fissionxuiptz@softwaremojo.com
29
+ executables:
30
+ - reverie
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - Gemfile
36
+ - LICENSE
37
+ - README.md
38
+ - Rakefile
39
+ - bin/reverie
40
+ - lib/reverie.rb
41
+ - lib/reverie/version.rb
42
+ - reverie.gemspec
43
+ homepage: http://github.com/fissionxuiptz/reverie
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.2.2
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Dreamhost DNS updater
67
+ test_files: []