1
0
mirror of https://github.com/cmur2/dyndnsd.git synced 2025-08-09 04:48:39 +02:00

Compare commits

..

35 Commits

Author SHA1 Message Date
cn
2a5140fcf0 Bump version 2017-10-31 11:18:08 +01:00
2edb9522f1 auth: fix broken password check
Guessing an existing user's name was enough to successfully authenticate.
2017-10-20 16:20:38 +00:00
cn
13613643cc Bump version 2016-12-07 14:20:52 +01:00
cn
4894015325 Add "myip6" URL parameter to provide an IPv6 address in addition to an IPv4 one as "myip" 2016-12-07 14:20:01 +01:00
cn
ae095c22b7 Force bundler update on travis-ci to prevent bug pre bundler 1.9.3 2016-12-01 19:05:38 +01:00
cn
3e1a391281 Bump version 2016-12-01 00:24:50 +01:00
cn
cf40e167d1 travis: disable ruby 1.8.7 2016-11-30 22:20:49 +01:00
cn
af97e162a0 Change dependency to json version that does not require ruby >= 2 2016-11-30 22:16:54 +01:00
cn
7ce1c1f480 Fix tests to use rspec expect syntax 2016-11-30 22:07:51 +01:00
cn
f76c5933d7 Allow dyndnsd to use address from X-Real-IP 2016-11-30 21:59:12 +01:00
cn
a9083e916e Add coverage of IPv6 addresses in tests 2016-11-30 21:24:56 +01:00
cn
cfce5be361 Bump version 2016-11-27 22:21:16 +01:00
cn
9ae2a63af2 Pin rack gem in Gemfile to ~> 1.6 for ruby < 2.2.2 support 2016-11-27 22:21:08 +01:00
Christian Nicolai
567f252cad Merge pull request #2 from haasn/ipv6
Support IPv6 addresses
2015-06-18 14:11:37 +02:00
Niklas Haas
d2747549fe Support IPv6 addresses
This also checks for IPv6-mapped IPv4 addresses.

Closes #1.
2015-06-18 06:09:46 +02:00
cn
c3331d19ca Bump version 2013-10-08 13:25:53 +02:00
cn
d7b2250923 Stop on SIGTERM 2013-10-08 13:25:35 +02:00
cn
b2a408acba Bump version 2013-06-08 10:00:13 +02:00
cn
c6c10a5a69 Improve init script 2013-06-08 09:59:32 +02:00
cn
0c0c2ffffb Bump version 2013-06-05 20:18:56 +02:00
cn
f3124d007c Fix bug with uninitialized constant since an extra require is required 2013-06-05 20:18:17 +02:00
cn
fcd963f4cf Bump version 2013-05-29 21:05:41 +02:00
cn
0b3d92e1f2 Support graphite metriks reporter 2013-05-29 21:05:41 +02:00
cn
a221fcc506 Update README 2013-05-03 16:06:53 +02:00
cn
b14da0df09 Update README 2013-05-01 10:17:40 +02:00
cn
5ed1129e6c Bump version 2013-04-30 23:19:51 +02:00
cn
1073312110 Support dropping priviliges 2013-04-30 23:19:08 +02:00
cn
f0bd538728 Use metriks with ProcTitle for some initial metrics 2013-04-28 16:29:36 +02:00
cn
a4b6a63383 Prevent zombie processes 2013-04-28 16:06:07 +02:00
cn
00255ebed9 Bump version 2013-04-28 15:06:56 +02:00
cn
e50430b177 Fix again -.- 2013-04-28 14:39:18 +02:00
cn
8ab3abd4bd Fix travis 2013-04-28 14:35:42 +02:00
cn
7f593227f2 Need json 2013-04-28 14:09:03 +02:00
cn
0cc1567ade Add init.d script 2013-04-28 00:25:02 +02:00
cn
fab95058bf Fix log format 2013-04-27 23:27:55 +02:00
11 changed files with 315 additions and 122 deletions

View File

@@ -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

View File

@@ -6,9 +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.
## General Usage ## General Usage
@@ -22,6 +24,9 @@ Create a configuration file in YAML format somewhere:
# listen address and port # listen address and port
host: "0.0.0.0" host: "0.0.0.0"
port: "80" port: "80"
# optional: drop priviliges in case you want to but you may need sudo for external commands
user: "nobody"
group: "nogroup"
# logfile is optional, logs to STDOUT else # logfile is optional, logs to STDOUT else
logfile: "dyndnsd.log" logfile: "dyndnsd.log"
# interal database file # interal database file
@@ -107,13 +112,23 @@ 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.
### Init scripts ### Init scripts
Coming soon for Debian 6. The [Debian 6 init.d script](init.d/debian-6-dyndnsd) assumes that dyndnsd.rb is installed into the system ruby (no RVM support) and the config.yaml is at /opt/dyndnsd/config.yaml. Modify to your needs.
## License ## License

View File

@@ -20,8 +20,9 @@ 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') if RUBY_VERSION < '1.9' s.add_runtime_dependency 'json', '~> 1.8'
s.add_runtime_dependency 'metriks'
s.add_development_dependency 'bundler', '~> 1.3' s.add_development_dependency 'bundler', '~> 1.3'
s.add_development_dependency 'rake' s.add_development_dependency 'rake'

43
init.d/debian-6-dyndnsd Normal file
View File

@@ -0,0 +1,43 @@
#! /bin/sh
### BEGIN INIT INFO
# Provides: dyndnsd
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Handle dyndnsd.rb gem
### END INIT INFO
# using the system ruby's gem binaries directory
DAEMON="/var/lib/gems/1.8/bin/dyndnsd"
CONFIG_FILE="/opt/dyndnsd/config.yaml"
DAEMON_OPTS="$CONFIG_FILE"
test -x $DAEMON || exit 0
. /lib/lsb/init-functions
case "$1" in
start)
log_daemon_msg "Starting dyndnsd.rb" "dyndnsd"
start-stop-daemon --start --quiet --oknodo --make-pidfile --pidfile "/var/run/dyndnsd.pid" --background --exec $DAEMON -- $DAEMON_OPTS
log_end_msg $?
;;
stop)
log_daemon_msg "Stopping dyndnsd.rb" "dyndnsd"
start-stop-daemon --stop --quiet --oknodo --pidfile "/var/run/dyndnsd.pid"
log_end_msg $?
;;
restart|force-reload)
log_daemon_msg "Restarting dyndnsd.rb" "dyndnsd"
start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile "/var/run/dyndsd.pid"
start-stop-daemon --start --quiet --oknodo --make-pidfile --pidfile "/var/run/dyndnsd.pid" --background --exec $DAEMON -- $DAEMON_OPTS
log_end_msg $?
;;
*)
log_action_msg "Usage: $0 {start|stop|restart|force-reload}"
exit 2
;;
esac

View File

@@ -1,10 +1,13 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
require 'etc'
require 'logger' require 'logger'
require 'ipaddr' require 'ipaddr'
require 'json' require 'json'
require 'yaml' require 'yaml'
require 'rack' require 'rack'
require 'metriks'
require 'metriks/reporter/graphite'
require 'dyndnsd/generator/bind' require 'dyndnsd/generator/bind'
require 'dyndnsd/updater/command_with_bind_zone' require 'dyndnsd/updater/command_with_bind_zone'
@@ -24,7 +27,7 @@ module Dyndnsd
class LogFormatter class LogFormatter
def call(lvl, time, progname, msg) def call(lvl, time, progname, msg)
"%s: %s\n" % [lvl, msg.to_s] "[%s] %-5s %s\n" % [Time.now.strftime('%Y-%m-%d %H:%M:%S'), lvl, msg.to_s]
end end
end end
@@ -75,20 +78,44 @@ 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"] 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(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
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 end
# malformed myip? Metriks.meter('requests.valid').mark
begin
IPAddr.new(params["myip"], Socket::AF_INET)
rescue ArgumentError
params["myip"] = env["REMOTE_ADDR"]
end
myip = params["myip"]
Dyndnsd.logger.info "Request to update #{hostnames} to #{myip} for user #{user}" Dyndnsd.logger.info "Request to update #{hostnames} to #{myip} for user #{user}"
changes = [] changes = []
@@ -96,8 +123,10 @@ module Dyndnsd
if (not @db['hosts'].include? hostname) or (@db['hosts'][hostname] != myip) if (not @db['hosts'].include? hostname) or (@db['hosts'][hostname] != myip)
changes << :good changes << :good
@db['hosts'][hostname] = myip @db['hosts'][hostname] = myip
Metriks.meter('requests.good').mark
else else
changes << :nochg changes << :nochg
Metriks.meter('requests.nochg').mark
end end
end end
@@ -106,6 +135,7 @@ module Dyndnsd
Dyndnsd.logger.info "Committing update ##{@db['serial']}" Dyndnsd.logger.info "Committing update ##{@db['serial']}"
@db.save @db.save
update update
Metriks.meter('updates.committed').mark
end end
@responder.response_for_changes(changes, myip) @responder.response_for_changes(changes, myip)
@@ -140,14 +170,42 @@ module Dyndnsd
Dyndnsd.logger.info "Starting..." Dyndnsd.logger.info "Starting..."
# drop privs (first change group than user)
Process::Sys.setgid(Etc.getgrnam(config['group']).gid) if config['group']
Process::Sys.setuid(Etc.getpwnam(config['user']).uid) if config['user']
# configure metriks
if config['graphite']
host = config['graphite']['host'] || 'localhost'
port = config['graphite']['port'] || 2003
options = {}
options[:prefix] = config['graphite']['prefix'] if config['graphite']['prefix']
reporter = Metriks::Reporter::Graphite.new(host, port, options)
reporter.start
else
reporter = Metriks::Reporter::ProcTitle.new
reporter.add 'good', 'sec' do
Metriks.meter('requests.good').mean_rate
end
reporter.add 'nochg', 'sec' do
Metriks.meter('requests.nochg').mean_rate
end
reporter.start
end
# configure daemon
db = Database.new(config['db']) db = Database.new(config['db'])
updater = Updater::CommandWithBindZone.new(config['domain'], config['updater']['params']) if config['updater']['name'] == 'command_with_bind_zone' updater = Updater::CommandWithBindZone.new(config['domain'], config['updater']['params']) if config['updater']['name'] == 'command_with_bind_zone'
responder = Responder::DynDNSStyle.new responder = Responder::DynDNSStyle.new
# configure rack
app = Daemon.new(config, db, updater, responder) app = Daemon.new(config, db, updater, responder)
app = Rack::Auth::Basic.new(app, "DynDNS") do |user,pass| 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))
Dyndnsd.logger.warn "Login failed for #{user}" if not allow if not allow
Dyndnsd.logger.warn "Login failed for #{user}"
Metriks.meter('requests.auth_failed').mark
end
allow allow
end end
@@ -155,6 +213,10 @@ module Dyndnsd
Dyndnsd.logger.info "Quitting..." Dyndnsd.logger.info "Quitting..."
Rack::Handler::WEBrick.shutdown Rack::Handler::WEBrick.shutdown
end end
Signal.trap('TERM') do
Dyndnsd.logger.info "Quitting..."
Rack::Handler::WEBrick.shutdown
end
Rack::Handler::WEBrick.run app, :Host => config['host'], :Port => config['port'] Rack::Handler::WEBrick.run app, :Host => config['host'], :Port => config['port']
end end

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -15,6 +15,8 @@ module Dyndnsd
pid = fork do pid = fork do
exec @command exec @command
end end
# detach so children don't become zombies
Process.detach(pid)
end end
end end
end end

View File

@@ -1,4 +1,4 @@
module Dyndnsd module Dyndnsd
VERSION = "0.0.4" VERSION = "1.6.1"
end end

View File

@@ -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' 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 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 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 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 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