mirror of
https://github.com/cmur2/dyndnsd.git
synced 2025-08-08 08:33:56 +02:00
Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
13613643cc | |||
4894015325 | |||
ae095c22b7 | |||
3e1a391281 | |||
cf40e167d1 | |||
af97e162a0 | |||
7ce1c1f480 | |||
f76c5933d7 | |||
a9083e916e | |||
cfce5be361 | |||
9ae2a63af2 | |||
![]() |
567f252cad | ||
![]() |
d2747549fe |
@@ -3,7 +3,9 @@ language: ruby
|
|||||||
rvm:
|
rvm:
|
||||||
- 2.0.0
|
- 2.0.0
|
||||||
- 1.9.3
|
- 1.9.3
|
||||||
- 1.8.7
|
|
||||||
|
|
||||||
gemfile:
|
gemfile:
|
||||||
- Gemfile
|
- Gemfile
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
- gem install bundler
|
||||||
|
16
README.md
16
README.md
@@ -6,11 +6,11 @@ A small, lightweight and extensible DynDNS server written with Ruby and Rack.
|
|||||||
|
|
||||||
## Description
|
## Description
|
||||||
|
|
||||||
dyndnsd.rb is aimed to implement a small [DynDNS-compliant](http://dyn.com/support/developers/api/) server in Ruby. 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](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.
|
||||||
|
|
||||||
The 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.
|
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.
|
||||||
|
|
||||||
Because of the mechanisms used dyndnsd.rb is known to work only on *nix systems.
|
Because of the mechanisms used dyndnsd.rb is known to work only on \*nix systems.
|
||||||
|
|
||||||
## General Usage
|
## General Usage
|
||||||
|
|
||||||
@@ -112,6 +112,16 @@ where:
|
|||||||
* HOSTNAMES is a required list of comma separated FQDNs (they all have to end with your config.yaml domain) the user wants to update
|
* HOSTNAMES is a required list of comma separated FQDNs (they all have to end with your config.yaml domain) the user wants to update
|
||||||
* MYIP is optional and the HTTP client's address will be used if missing
|
* MYIP is optional and the HTTP client's address will be used if missing
|
||||||
|
|
||||||
|
### IP address determination
|
||||||
|
|
||||||
|
The following rules apply:
|
||||||
|
|
||||||
|
* use any IP address provided via the myip parameter when present, or
|
||||||
|
* 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
|
### 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.
|
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.
|
||||||
|
@@ -20,8 +20,8 @@ Gem::Specification.new do |s|
|
|||||||
|
|
||||||
s.executables = ['dyndnsd']
|
s.executables = ['dyndnsd']
|
||||||
|
|
||||||
s.add_runtime_dependency 'rack'
|
s.add_runtime_dependency 'rack', '~> 1.6'
|
||||||
s.add_runtime_dependency 'json'
|
s.add_runtime_dependency 'json', '~> 1.8'
|
||||||
s.add_runtime_dependency 'metriks'
|
s.add_runtime_dependency 'metriks'
|
||||||
|
|
||||||
s.add_development_dependency 'bundler', '~> 1.3'
|
s.add_development_dependency 'bundler', '~> 1.3'
|
||||||
|
@@ -78,19 +78,42 @@ module Dyndnsd
|
|||||||
return @responder.response_for_error(:host_forbidden) if not @users[user]['hosts'].include? hostname
|
return @responder.response_for_error(:host_forbidden) if not @users[user]['hosts'].include? hostname
|
||||||
end
|
end
|
||||||
|
|
||||||
# no myip?
|
myip = nil
|
||||||
if not params["myip"]
|
|
||||||
params["myip"] = env["REMOTE_ADDR"]
|
|
||||||
end
|
|
||||||
|
|
||||||
# malformed myip?
|
if params.has_key?("myip6")
|
||||||
begin
|
# require presence of myip parameter as valid IPAddr (v4) and valid myip6
|
||||||
IPAddr.new(params["myip"], Socket::AF_INET)
|
return @responder.response_for_error(:host_forbidden) if not params["myip"]
|
||||||
rescue ArgumentError
|
begin
|
||||||
params["myip"] = env["REMOTE_ADDR"]
|
IPAddr.new(params["myip"], Socket::AF_INET)
|
||||||
end
|
IPAddr.new(params["myip6"], Socket::AF_INET6)
|
||||||
|
|
||||||
myip = params["myip"]
|
# myip will be an array
|
||||||
|
myip = [params["myip"], params["myip6"]]
|
||||||
|
rescue ArgumentError
|
||||||
|
return @responder.response_for_error(:host_forbidden)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
# fallback value, always present
|
||||||
|
myip = env["REMOTE_ADDR"]
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
Metriks.meter('requests.valid').mark
|
Metriks.meter('requests.valid').mark
|
||||||
Dyndnsd.logger.info "Request to update #{hostnames} to #{myip} for user #{user}"
|
Dyndnsd.logger.info "Request to update #{hostnames} to #{myip} for user #{user}"
|
||||||
|
@@ -18,9 +18,13 @@ module Dyndnsd
|
|||||||
out << "@ IN SOA #{@dns} #{@email_addr} ( #{zone['serial']} 3h 5m 1w 1h )"
|
out << "@ IN SOA #{@dns} #{@email_addr} ( #{zone['serial']} 3h 5m 1w 1h )"
|
||||||
out << "@ IN NS #{@dns}"
|
out << "@ IN NS #{@dns}"
|
||||||
out << ""
|
out << ""
|
||||||
zone['hosts'].each do |hostname,ip|
|
zone['hosts'].each do |hostname,ips|
|
||||||
name = hostname.chomp('.' + @domain)
|
(ips.is_a?(Array) ? ips : [ips]).each do |ip|
|
||||||
out << "#{name} IN A #{ip}"
|
ip = IPAddr.new(ip).native
|
||||||
|
type = ip.ipv6? ? "AAAA" : "A"
|
||||||
|
name = hostname.chomp('.' + @domain)
|
||||||
|
out << "#{name} IN #{type} #{ip}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
out << ""
|
out << ""
|
||||||
out << @additional_zone_content
|
out << @additional_zone_content
|
||||||
|
@@ -13,7 +13,7 @@ module Dyndnsd
|
|||||||
end
|
end
|
||||||
|
|
||||||
def response_for_changes(states, ip)
|
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]]
|
return [200, {"Content-Type" => "text/plain"}, [body]]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@@ -13,7 +13,7 @@ module Dyndnsd
|
|||||||
end
|
end
|
||||||
|
|
||||||
def response_for_changes(states, ip)
|
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]]
|
return [200, {"Content-Type" => "text/plain"}, [body]]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
|
|
||||||
module Dyndnsd
|
module Dyndnsd
|
||||||
VERSION = "1.3.0"
|
VERSION = "1.6.0"
|
||||||
end
|
end
|
||||||
|
@@ -28,115 +28,179 @@ describe Dyndnsd::Daemon do
|
|||||||
|
|
||||||
it 'requires authentication' do
|
it 'requires authentication' do
|
||||||
get '/'
|
get '/'
|
||||||
last_response.status.should == 401
|
expect(last_response.status).to eq(401)
|
||||||
|
|
||||||
pending 'Need to find a way to add custom body on 401 responses'
|
pending 'Need to find a way to add custom body on 401 responses'
|
||||||
last_response.should be_ok 'badauth'
|
expect(last_response).not_to be_ok
|
||||||
|
expect(last_response.body).to eq('badauth')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'only supports GET requests' do
|
it 'only supports GET requests' do
|
||||||
authorize 'test', 'secret'
|
authorize 'test', 'secret'
|
||||||
post '/nic/update'
|
post '/nic/update'
|
||||||
last_response.status.should == 405
|
expect(last_response.status).to eq(405)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'provides only the /nic/update URL' do
|
it 'provides only the /nic/update URL' do
|
||||||
authorize 'test', 'secret'
|
authorize 'test', 'secret'
|
||||||
get '/other/url'
|
get '/other/url'
|
||||||
last_response.status.should == 404
|
expect(last_response.status).to eq(404)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'requires the hostname query parameter' do
|
it 'requires the hostname query parameter' do
|
||||||
authorize 'test', 'secret'
|
authorize 'test', 'secret'
|
||||||
get '/nic/update'
|
get '/nic/update'
|
||||||
last_response.should be_ok
|
expect(last_response).to be_ok
|
||||||
last_response.body.should == 'notfqdn'
|
expect(last_response.body).to eq('notfqdn')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'supports multiple hostnames in request' do
|
it 'supports multiple hostnames in request' do
|
||||||
authorize 'test', 'secret'
|
authorize 'test', 'secret'
|
||||||
|
|
||||||
get '/nic/update?hostname=foo.example.org,bar.example.org&myip=1.2.3.4'
|
get '/nic/update?hostname=foo.example.org,bar.example.org&myip=1.2.3.4'
|
||||||
last_response.should be_ok
|
expect(last_response).to be_ok
|
||||||
last_response.body.should == "good 1.2.3.4\ngood 1.2.3.4"
|
expect(last_response.body).to eq("good 1.2.3.4\ngood 1.2.3.4")
|
||||||
|
|
||||||
|
get '/nic/update?hostname=foo.example.org,bar.example.org&myip=2001:db8::1'
|
||||||
|
expect(last_response).to be_ok
|
||||||
|
expect(last_response.body).to eq("good 2001:db8::1\ngood 2001:db8::1")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'rejects request if one hostname is invalid' do
|
it 'rejects request if one hostname is invalid' do
|
||||||
authorize 'test', 'secret'
|
authorize 'test', 'secret'
|
||||||
|
|
||||||
get '/nic/update?hostname=test'
|
get '/nic/update?hostname=test'
|
||||||
last_response.should be_ok
|
expect(last_response).to be_ok
|
||||||
last_response.body.should == 'notfqdn'
|
expect(last_response.body).to eq('notfqdn')
|
||||||
|
|
||||||
get '/nic/update?hostname=test.example.com'
|
get '/nic/update?hostname=test.example.com'
|
||||||
last_response.should be_ok
|
expect(last_response).to be_ok
|
||||||
last_response.body.should == 'notfqdn'
|
expect(last_response.body).to eq('notfqdn')
|
||||||
|
|
||||||
get '/nic/update?hostname=test.example.org.me'
|
get '/nic/update?hostname=test.example.org.me'
|
||||||
last_response.should be_ok
|
expect(last_response).to be_ok
|
||||||
last_response.body.should == 'notfqdn'
|
expect(last_response.body).to eq('notfqdn')
|
||||||
|
|
||||||
get '/nic/update?hostname=foo.test.example.org'
|
get '/nic/update?hostname=foo.test.example.org'
|
||||||
last_response.should be_ok
|
expect(last_response).to be_ok
|
||||||
last_response.body.should == 'notfqdn'
|
expect(last_response.body).to eq('notfqdn')
|
||||||
|
|
||||||
get '/nic/update?hostname=in%20valid.example.org'
|
get '/nic/update?hostname=in%20valid.example.org'
|
||||||
last_response.should be_ok
|
expect(last_response).to be_ok
|
||||||
last_response.body.should == 'notfqdn'
|
expect(last_response.body).to eq('notfqdn')
|
||||||
|
|
||||||
get '/nic/update?hostname=valid.example.org,in.valid.example.org'
|
get '/nic/update?hostname=valid.example.org,in.valid.example.org'
|
||||||
last_response.should be_ok
|
expect(last_response).to be_ok
|
||||||
last_response.body.should == 'notfqdn'
|
expect(last_response.body).to eq('notfqdn')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'rejects request if user does not own one hostname' do
|
it 'rejects request if user does not own one hostname' do
|
||||||
authorize 'test', 'secret'
|
authorize 'test', 'secret'
|
||||||
get '/nic/update?hostname=notmyhost.example.org'
|
get '/nic/update?hostname=notmyhost.example.org'
|
||||||
last_response.should be_ok
|
expect(last_response).to be_ok
|
||||||
last_response.body.should == 'nohost'
|
expect(last_response.body).to eq('nohost')
|
||||||
|
|
||||||
get '/nic/update?hostname=foo.example.org,notmyhost.example.org'
|
get '/nic/update?hostname=foo.example.org,notmyhost.example.org'
|
||||||
last_response.should be_ok
|
expect(last_response).to be_ok
|
||||||
last_response.body.should == 'nohost'
|
expect(last_response.body).to eq('nohost')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'updates a host on IPv4 change' do
|
it 'updates a host on IP change' do
|
||||||
authorize 'test', 'secret'
|
authorize 'test', 'secret'
|
||||||
|
|
||||||
get '/nic/update?hostname=foo.example.org&myip=1.2.3.4'
|
get '/nic/update?hostname=foo.example.org&myip=1.2.3.4'
|
||||||
last_response.should be_ok
|
expect(last_response).to be_ok
|
||||||
|
|
||||||
get '/nic/update?hostname=foo.example.org&myip=1.2.3.40'
|
get '/nic/update?hostname=foo.example.org&myip=1.2.3.40'
|
||||||
last_response.should be_ok
|
expect(last_response).to be_ok
|
||||||
last_response.body.should == 'good 1.2.3.40'
|
expect(last_response.body).to eq('good 1.2.3.40')
|
||||||
|
|
||||||
|
get '/nic/update?hostname=foo.example.org&myip=2001:db8::1'
|
||||||
|
expect(last_response).to be_ok
|
||||||
|
|
||||||
|
get '/nic/update?hostname=foo.example.org&myip=2001:db8::10'
|
||||||
|
expect(last_response).to be_ok
|
||||||
|
expect(last_response.body).to eq('good 2001:db8::10')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns IPv4 no change' do
|
it 'returns IP no change' do
|
||||||
authorize 'test', 'secret'
|
authorize 'test', 'secret'
|
||||||
|
|
||||||
get '/nic/update?hostname=foo.example.org&myip=1.2.3.4'
|
get '/nic/update?hostname=foo.example.org&myip=1.2.3.4'
|
||||||
last_response.should be_ok
|
expect(last_response).to be_ok
|
||||||
|
|
||||||
get '/nic/update?hostname=foo.example.org&myip=1.2.3.4'
|
get '/nic/update?hostname=foo.example.org&myip=1.2.3.4'
|
||||||
last_response.should be_ok
|
expect(last_response).to be_ok
|
||||||
last_response.body.should == 'nochg 1.2.3.4'
|
expect(last_response.body).to eq('nochg 1.2.3.4')
|
||||||
|
|
||||||
|
get '/nic/update?hostname=foo.example.org&myip=2001:db8::1'
|
||||||
|
expect(last_response).to be_ok
|
||||||
|
|
||||||
|
get '/nic/update?hostname=foo.example.org&myip=2001:db8::1'
|
||||||
|
expect(last_response).to be_ok
|
||||||
|
expect(last_response.body).to eq('nochg 2001:db8::1')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'outputs IPv4 status per hostname' do
|
it 'outputs IP status per hostname' do
|
||||||
authorize 'test', 'secret'
|
authorize 'test', 'secret'
|
||||||
|
|
||||||
get '/nic/update?hostname=foo.example.org&myip=1.2.3.4'
|
get '/nic/update?hostname=foo.example.org&myip=1.2.3.4'
|
||||||
last_response.should be_ok
|
expect(last_response).to be_ok
|
||||||
last_response.body.should == 'good 1.2.3.4'
|
expect(last_response.body).to eq('good 1.2.3.4')
|
||||||
|
|
||||||
get '/nic/update?hostname=foo.example.org,bar.example.org&myip=1.2.3.4'
|
get '/nic/update?hostname=foo.example.org,bar.example.org&myip=1.2.3.4'
|
||||||
last_response.should be_ok
|
expect(last_response).to be_ok
|
||||||
last_response.body.should == "nochg 1.2.3.4\ngood 1.2.3.4"
|
expect(last_response.body).to eq("nochg 1.2.3.4\ngood 1.2.3.4")
|
||||||
|
|
||||||
|
get '/nic/update?hostname=foo.example.org&myip=2001:db8::1'
|
||||||
|
expect(last_response).to be_ok
|
||||||
|
expect(last_response.body).to eq('good 2001:db8::1')
|
||||||
|
|
||||||
|
get '/nic/update?hostname=foo.example.org,bar.example.org&myip=2001:db8::1'
|
||||||
|
expect(last_response).to be_ok
|
||||||
|
expect(last_response.body).to eq("nochg 2001:db8::1\ngood 2001:db8::1")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'uses clients remote IPv4 address if myip not specified' do
|
it 'uses clients remote IP address if myip not specified' do
|
||||||
authorize 'test', 'secret'
|
authorize 'test', 'secret'
|
||||||
get '/nic/update?hostname=foo.example.org'
|
get '/nic/update?hostname=foo.example.org'
|
||||||
last_response.should be_ok
|
expect(last_response).to be_ok
|
||||||
last_response.body.should == 'good 127.0.0.1'
|
expect(last_response.body).to eq('good 127.0.0.1')
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user