mirror of
https://github.com/cmur2/dyndnsd.git
synced 2025-08-08 08:33:56 +02:00
Compare commits
9 Commits
v1.5.0
...
dyndnsd-1.
Author | SHA1 | Date | |
---|---|---|---|
efe516276c | |||
16af27ae52 | |||
16518dca9b | |||
b31ccafe9c | |||
2a5140fcf0 | |||
2edb9522f1 | |||
13613643cc | |||
4894015325 | |||
ae095c22b7 |
@@ -1,8 +1,5 @@
|
||||
language: ruby
|
||||
|
||||
rvm:
|
||||
- 2.0.0
|
||||
- 2.4
|
||||
- 2.1
|
||||
- 1.9.3
|
||||
|
||||
gemfile:
|
||||
- Gemfile
|
||||
|
@@ -1,12 +1,14 @@
|
||||
# dyndnsd.rb
|
||||
|
||||
[](https://travis-ci.org/cmur2/dyndnsd)
|
||||
[](https://travis-ci.org/cmur2/dyndnsd)
|
||||
|
||||
A small, lightweight and extensible DynDNS server written with Ruby and Rack.
|
||||
|
||||
**Note:** a newer version of dyndnsd.rb is available on [branch master](https://github.com/cmur2/dyndnsd), see also the [changelog](https://github.com/cmur2/dyndnsd/blob/master/CHANGELOG.md).
|
||||
|
||||
## Description
|
||||
|
||||
dyndnsd.rb aims to implement a small [DynDNS-compliant](http://dyn.com/support/developers/api/) server in Ruby supporting IPv4 and IPv6 addresses. It has an integrated user and hostname database in it's configuration file that is used for authentication and authorization. Besides talking the DynDNS protocol it is able to invoke an so-called *updater*, a small Ruby module that takes care of supplying the current host => ip mapping to a DNS server.
|
||||
dyndnsd.rb aims to implement a small [DynDNS-compliant](https://help.dyn.com/remote-access-api/) server in Ruby supporting IPv4 and IPv6 addresses. It has an integrated user and hostname database in it's configuration file that is used for authentication and authorization. Besides talking the DynDNS protocol it is able to invoke an so-called *updater*, a small Ruby module that takes care of supplying the current host => ip mapping to a DNS server.
|
||||
|
||||
There is currently one updater shipped with dyndnsd.rb `command_with_bind_zone` that writes out a zone file in BIND syntax onto the current system and invokes a user-supplied command afterwards that is assumed to trigger the DNS server (not necessarily BIND since it's zone files are read by other DNS servers too) to reload it's zone configuration.
|
||||
|
||||
@@ -120,6 +122,8 @@ The following rules apply:
|
||||
* use any IP address provided via the X-Real-IP header e.g. when used behind HTTP reverse proxy such as nginx, or
|
||||
* use any IP address used by the connecting HTTP client
|
||||
|
||||
If you want to provide an additional IPv6 address as myip6 parameter the myip parameter containing an IPv4 address has to be present, too! No automatism is applied then.
|
||||
|
||||
### SSL, multiple listen ports
|
||||
|
||||
Use a webserver as a proxy to handle SSL and/or multiple listen addresses and ports. DynDNS.com provides HTTP on port 80 and 8245 and HTTPS on port 443.
|
||||
|
@@ -21,10 +21,10 @@ Gem::Specification.new do |s|
|
||||
s.executables = ['dyndnsd']
|
||||
|
||||
s.add_runtime_dependency 'rack', '~> 1.6'
|
||||
s.add_runtime_dependency 'json', '~> 1.8'
|
||||
s.add_runtime_dependency 'json'
|
||||
s.add_runtime_dependency 'metriks'
|
||||
|
||||
s.add_development_dependency 'bundler', '~> 1.3'
|
||||
s.add_development_dependency 'bundler'
|
||||
s.add_development_dependency 'rake'
|
||||
s.add_development_dependency 'rspec'
|
||||
s.add_development_dependency 'rack-test'
|
||||
|
@@ -78,24 +78,40 @@ module Dyndnsd
|
||||
return @responder.response_for_error(:host_forbidden) if not @users[user]['hosts'].include? hostname
|
||||
end
|
||||
|
||||
# fallback value, always present
|
||||
myip = env["REMOTE_ADDR"]
|
||||
myip = nil
|
||||
|
||||
# check whether X-Real-IP header has valid IPAddr
|
||||
if env.has_key?("HTTP_X_REAL_IP")
|
||||
if params.has_key?("myip6")
|
||||
# require presence of myip parameter as valid IPAddr (v4) and valid myip6
|
||||
return @responder.response_for_error(:host_forbidden) if not params["myip"]
|
||||
begin
|
||||
IPAddr.new(env["HTTP_X_REAL_IP"])
|
||||
myip = env["HTTP_X_REAL_IP"]
|
||||
IPAddr.new(params["myip"], Socket::AF_INET)
|
||||
IPAddr.new(params["myip6"], Socket::AF_INET6)
|
||||
|
||||
# myip will be an array
|
||||
myip = [params["myip"], params["myip6"]]
|
||||
rescue ArgumentError
|
||||
return @responder.response_for_error(:host_forbidden)
|
||||
end
|
||||
end
|
||||
else
|
||||
# fallback value, always present
|
||||
myip = env["REMOTE_ADDR"]
|
||||
|
||||
# check whether myip parameter has valid IPAddr
|
||||
if params.has_key?("myip")
|
||||
begin
|
||||
IPAddr.new(params["myip"])
|
||||
myip = params["myip"]
|
||||
rescue ArgumentError
|
||||
# check whether X-Real-IP header has valid IPAddr
|
||||
if env.has_key?("HTTP_X_REAL_IP")
|
||||
begin
|
||||
IPAddr.new(env["HTTP_X_REAL_IP"])
|
||||
myip = env["HTTP_X_REAL_IP"]
|
||||
rescue ArgumentError
|
||||
end
|
||||
end
|
||||
|
||||
# check whether myip parameter has valid IPAddr
|
||||
if params.has_key?("myip")
|
||||
begin
|
||||
IPAddr.new(params["myip"])
|
||||
myip = params["myip"]
|
||||
rescue ArgumentError
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -185,7 +201,7 @@ module Dyndnsd
|
||||
# configure rack
|
||||
app = Daemon.new(config, db, updater, responder)
|
||||
app = Rack::Auth::Basic.new(app, "DynDNS") do |user,pass|
|
||||
allow = (config['users'].has_key? user) and (config['users'][user]['password'] == pass)
|
||||
allow = ((config['users'].has_key? user) and (config['users'][user]['password'] == pass))
|
||||
if not allow
|
||||
Dyndnsd.logger.warn "Login failed for #{user}"
|
||||
Metriks.meter('requests.auth_failed').mark
|
||||
|
@@ -18,11 +18,13 @@ module Dyndnsd
|
||||
out << "@ IN SOA #{@dns} #{@email_addr} ( #{zone['serial']} 3h 5m 1w 1h )"
|
||||
out << "@ IN NS #{@dns}"
|
||||
out << ""
|
||||
zone['hosts'].each do |hostname,ip|
|
||||
ip = IPAddr.new(ip).native
|
||||
type = ip.ipv6? ? "AAAA" : "A"
|
||||
name = hostname.chomp('.' + @domain)
|
||||
out << "#{name} IN #{type} #{ip}"
|
||||
zone['hosts'].each do |hostname,ips|
|
||||
(ips.is_a?(Array) ? ips : [ips]).each do |ip|
|
||||
ip = IPAddr.new(ip).native
|
||||
type = ip.ipv6? ? "AAAA" : "A"
|
||||
name = hostname.chomp('.' + @domain)
|
||||
out << "#{name} IN #{type} #{ip}"
|
||||
end
|
||||
end
|
||||
out << ""
|
||||
out << @additional_zone_content
|
||||
|
@@ -13,7 +13,7 @@ module Dyndnsd
|
||||
end
|
||||
|
||||
def response_for_changes(states, ip)
|
||||
body = states.map { |state| "#{state} #{ip}" }.join("\n")
|
||||
body = states.map { |state| "#{state} #{ip.is_a?(Array) ? ip.join(' ') : ip}" }.join("\n")
|
||||
return [200, {"Content-Type" => "text/plain"}, [body]]
|
||||
end
|
||||
end
|
||||
|
@@ -13,7 +13,7 @@ module Dyndnsd
|
||||
end
|
||||
|
||||
def response_for_changes(states, ip)
|
||||
body = states.map { |state| state == :good ? "Changed to #{ip}" : "No change needed for #{ip}" }.join("\n")
|
||||
body = states.map { |state| state == :good ? "Changed to #{ip.is_a?(Array) ? ip.join(' ') : ip}" : "No change needed for #{ip.is_a?(Array) ? ip.join(' ') : ip}" }.join("\n")
|
||||
return [200, {"Content-Type" => "text/plain"}, [body]]
|
||||
end
|
||||
end
|
||||
|
@@ -1,4 +1,4 @@
|
||||
|
||||
module Dyndnsd
|
||||
VERSION = "1.5.0"
|
||||
VERSION = "1.6.1"
|
||||
end
|
||||
|
@@ -170,8 +170,37 @@ describe Dyndnsd::Daemon do
|
||||
|
||||
it 'uses clients remote IP address from X-Real-IP header if behind proxy' do
|
||||
authorize 'test', 'secret'
|
||||
|
||||
get '/nic/update?hostname=foo.example.org', '', 'HTTP_X_REAL_IP' => '10.0.0.1'
|
||||
expect(last_response).to be_ok
|
||||
expect(last_response.body).to eq('good 10.0.0.1')
|
||||
|
||||
get '/nic/update?hostname=foo.example.org', '', 'HTTP_X_REAL_IP' => '2001:db8::1'
|
||||
expect(last_response).to be_ok
|
||||
expect(last_response.body).to eq('good 2001:db8::1')
|
||||
end
|
||||
|
||||
it 'supports an IPv4 and an IPv6 address in one request' do
|
||||
authorize 'test', 'secret'
|
||||
|
||||
get '/nic/update?hostname=foo.example.org&myip=1.2.3.4&myip6=2001:db8::1'
|
||||
expect(last_response).to be_ok
|
||||
expect(last_response.body).to eq("good 1.2.3.4 2001:db8::1")
|
||||
|
||||
get '/nic/update?hostname=foo.example.org&myip=BROKENIP&myip6=2001:db8::1'
|
||||
expect(last_response).to be_ok
|
||||
expect(last_response.body).to eq('nohost')
|
||||
|
||||
get '/nic/update?hostname=foo.example.org&myip=1.2.3.4&myip6=BROKENIP'
|
||||
expect(last_response).to be_ok
|
||||
expect(last_response.body).to eq('nohost')
|
||||
|
||||
get '/nic/update?hostname=foo.example.org&myip6=2001:db8::10'
|
||||
expect(last_response).to be_ok
|
||||
expect(last_response.body).to eq('nohost')
|
||||
|
||||
get '/nic/update?hostname=foo.example.org&myip=1.2.3.40'
|
||||
expect(last_response).to be_ok
|
||||
expect(last_response.body).to eq('good 1.2.3.40')
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user