Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Bundle update and a few tidy ups. Something seems broken with the jso…

…n endpoint (it 404s) when updating the hostname. Needs more investigating.
  • Loading branch information...
commit 164c29459b760d3face2ffd0ddae70285aa57288 1 parent a4dcd42
@hamstarr authored
View
82 Gemfile.lock
@@ -1,37 +1,45 @@
-GEM
- remote: http://rubygems.org/
- specs:
- addressable (2.2.5)
- crack (0.1.8)
- daemons (1.1.3)
- dnsimple-ruby (0.9.7)
- httparty
- httparty
- em-http-request (0.3.0)
- addressable (>= 2.0.0)
- escape_utils
- eventmachine (>= 0.12.9)
- escape_utils (0.2.3)
- eventmachine (0.12.10)
- haml (3.1.1)
- httparty (0.7.7)
- crack (= 0.1.8)
- rack (1.2.2)
- sinatra (1.2.6)
- rack (~> 1.1)
- tilt (>= 1.2.2, < 2.0)
- thin (1.2.11)
- daemons (>= 1.0.9)
- eventmachine (>= 0.12.6)
- rack (>= 1.0.0)
- tilt (1.3)
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
- dnsimple-ruby
- em-http-request
- haml
- sinatra
- thin
+GEM
+ remote: http://rubygems.org/
+ specs:
+ addressable (2.2.6)
+ daemons (1.1.4)
+ dnsimple-ruby (1.1.1)
+ httparty
+ httparty
+ em-http-request (1.0.0)
+ addressable (>= 2.2.3)
+ em-socksify
+ eventmachine (>= 1.0.0.beta.3)
+ http_parser.rb (>= 0.5.2)
+ em-socksify (0.1.0)
+ eventmachine
+ eventmachine (1.0.0.beta.4)
+ haml (3.1.3)
+ http_parser.rb (0.5.3)
+ httparty (0.8.1)
+ multi_json
+ multi_xml
+ multi_json (1.0.3)
+ multi_xml (0.4.1)
+ rack (1.3.5)
+ rack-protection (1.1.4)
+ rack
+ sinatra (1.3.1)
+ rack (~> 1.3, >= 1.3.4)
+ rack-protection (~> 1.1, >= 1.1.2)
+ tilt (~> 1.3, >= 1.3.3)
+ thin (1.3.0)
+ daemons (>= 1.0.9)
+ eventmachine (>= 0.12.6)
+ rack (>= 1.0.0)
+ tilt (1.3.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ dnsimple-ruby
+ em-http-request
+ haml
+ sinatra
+ thin
View
7 app/app.rb
@@ -5,13 +5,10 @@ class App < Sinatra::Base
set :root, File.join(File.dirname(__FILE__), "..")
set :views, Proc.new { File.join(root, "app", "views") }
- set :public, Proc.new { File.join(root, "public") }
+ set :public_folder, Proc.new { File.join(root, "public") }
get '/' do
- unless DynDNSimple.refreshable?
- redirect '/settings'
- end
-
+ redirect '/settings' unless DynDNSimple.refreshable?
haml :index
end
View
1  dyn-dnsimple
@@ -10,7 +10,6 @@ require 'dnsimple'
APP_ROOT = File.dirname(__FILE__)
-
$log = Logger.new( File.join(APP_ROOT, 'log', 'dyn-dnsimple.log'), 'daily' )
$log.level = Logger::INFO
View
38 lib/dyn-dnsimple.rb
@@ -5,34 +5,38 @@ def self.refresh!
DNSimple::Client.username = $settings.username
DNSimple::Client.password = $settings.password
- EM::HttpRequest.new('http://icanhazip.com').get.callback { |http|
+ EM::HttpRequest.new('http://icanhazip.com').get.callback do |http|
$settings.current_ip = http.response.strip!
- $settings.save_to_config!
+ $settings.save!
$log.info "DynDNSimple: Current External IP is #{$settings.current_ip}"
-
- records = DNSimple::Record.all($settings.domain)
-
- records.each do |record|
- #only update if the record is an A Record and the IP is different from the current external IP
- if self.need_to_update?(record)
- self.update!
- end
- end
- }
+ self.update!
+ end
end
def self.refreshable?
- !$settings.username.nil? && !$settings.password.nil? && !$settings.domain.nil? && !$settings.hostname.nil?
+ !$settings.username.nil? &&
+ !$settings.password.nil? &&
+ !$settings.domain.nil? &&
+ !$settings.hostname.nil?
end
def self.need_to_update?(record)
- record.name == $settings.hostname && record.record_type == "A" && record.content != $settings.current_ip
+ record.name == $settings.hostname &&
+ record.record_type == "A" &&
+ record.content != $settings.current_ip
end
def self.update!
- record.content = $settings.current_ip #"1.2.3.4"
- record.save
- $log.info "DynDNSimple: New External IP is #{record.content}"
+ domain = DNSimple::Domain.new(:name => $settings.domain)
+ records = DNSimple::Record.all(domain)
+
+ records.each do |record|
+ next unless self.need_to_update?(record)
+ #only update if the record is an A Record and the IP is different from the current external IP
+ record.content = $settings.current_ip #"1.2.3.4"
+ record.save
+ $log.info "DynDNSimple: New External IP is #{record.content}"
+ end
end
end
View
14 lib/settings.rb
@@ -17,7 +17,7 @@ def clear
self.errors ||= {}
end
- def save_to_config!
+ def save!
settings = {
:username => self.username,
:password => self.password,
@@ -50,9 +50,7 @@ def load(options = {})
:current_ip => nil
}
- if File.exist? @config_file
- settings = YAML.load_file(@config_file)
- end
+ settings = YAML.load_file(@config_file) if File.exist? @config_file
if options.any?
# convert the keys to symbols
@@ -60,10 +58,10 @@ def load(options = {})
settings = settings.merge(options)
end
- self.username = (settings[:username]) ? settings[:username] : nil
- self.password = (settings[:password]) ? settings[:password] : nil
- self.domain = (settings[:domain]) ? settings[:domain] : nil
- self.hostname = (settings[:hostname]) ? settings[:hostname] : nil
+ self.username = settings[:username]
+ self.password = settings[:password]
+ self.domain = settings[:domain]
+ self.hostname = settings[:hostname]
self.update_frequency = (settings[:update_frequency] && settings[:update_frequency] >= 360) ? settings[:update_frequency] : 360
self.http_port = (settings[:http_port] && settings[:http_port] > 0) ? settings[:http_port] : 3333
Please sign in to comment.
Something went wrong with that request. Please try again.