mirror of
https://github.com/cmur2/dyndnsd.git
synced 2024-12-22 00:54:22 +01:00
daemon: add host offlining by deleting the associated DNS records
This commit is contained in:
parent
8d4e96a1dd
commit
147071da9e
@ -22,12 +22,18 @@ Metrics/BlockLength:
|
|||||||
Metrics/ClassLength:
|
Metrics/ClassLength:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
|
Metrics/CyclomaticComplexity:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
Metrics/LineLength:
|
Metrics/LineLength:
|
||||||
Max: 200
|
Max: 200
|
||||||
|
|
||||||
Metrics/MethodLength:
|
Metrics/MethodLength:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
|
Metrics/PerceivedComplexity:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
Style/ConditionalAssignment:
|
Style/ConditionalAssignment:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ IMPROVEMENTS:
|
|||||||
- Update dependencies, mainly `rack` to new major version 2
|
- Update dependencies, mainly `rack` to new major version 2
|
||||||
- Add Ruby 2.5 support
|
- Add Ruby 2.5 support
|
||||||
- Add experimental [OpenTracing](http://opentracing.io/) support with [CNCF Jaeger](https://github.com/jaegertracing/jaeger)
|
- Add experimental [OpenTracing](http://opentracing.io/) support with [CNCF Jaeger](https://github.com/jaegertracing/jaeger)
|
||||||
|
- Support host offlining by deleting the associated DNS records
|
||||||
|
|
||||||
## 1.6.1 (October 31, 2017)
|
## 1.6.1 (October 31, 2017)
|
||||||
|
|
||||||
|
@ -141,7 +141,11 @@ module Dyndnsd
|
|||||||
|
|
||||||
hostnames.each do |hostname|
|
hostnames.each do |hostname|
|
||||||
# myips order is always deterministic
|
# myips order is always deterministic
|
||||||
if Helper.changed?(hostname, myips, @db['hosts'])
|
if myips.empty? && @db['hosts'].include?(hostname)
|
||||||
|
@db['hosts'].delete(hostname)
|
||||||
|
changes << :good
|
||||||
|
Metriks.meter('requests.good').mark
|
||||||
|
elsif Helper.changed?(hostname, myips, @db['hosts'])
|
||||||
@db['hosts'][hostname] = myips
|
@db['hosts'][hostname] = myips
|
||||||
changes << :good
|
changes << :good
|
||||||
Metriks.meter('requests.good').mark
|
Metriks.meter('requests.good').mark
|
||||||
@ -180,10 +184,13 @@ module Dyndnsd
|
|||||||
forbidden_hostnames = hostnames - @users[user]['hosts']
|
forbidden_hostnames = hostnames - @users[user]['hosts']
|
||||||
return [422, {'X-DynDNS-Response' => 'host_forbidden'}, []] if forbidden_hostnames.any?
|
return [422, {'X-DynDNS-Response' => 'host_forbidden'}, []] if forbidden_hostnames.any?
|
||||||
|
|
||||||
|
if params['offline'] == 'YES'
|
||||||
|
myips = []
|
||||||
|
else
|
||||||
myips = extract_myips(env, params)
|
myips = extract_myips(env, params)
|
||||||
|
|
||||||
# require at least one IP to update
|
# require at least one IP to update
|
||||||
return [422, {'X-DynDNS-Response' => 'host_forbidden'}, []] if myips.empty?
|
return [422, {'X-DynDNS-Response' => 'host_forbidden'}, []] if myips.empty?
|
||||||
|
end
|
||||||
|
|
||||||
Metriks.meter('requests.valid').mark
|
Metriks.meter('requests.valid').mark
|
||||||
Dyndnsd.logger.info "Request to update #{hostnames} to #{myips} for user #{user}"
|
Dyndnsd.logger.info "Request to update #{hostnames} to #{myips} for user #{user}"
|
||||||
|
@ -24,7 +24,7 @@ module Dyndnsd
|
|||||||
|
|
||||||
def self.changed?(hostname, myips, hosts)
|
def self.changed?(hostname, myips, hosts)
|
||||||
# myips order is always deterministic
|
# myips order is always deterministic
|
||||||
(!hosts.include? hostname) || (hosts[hostname] != myips)
|
((!hosts.include? hostname) || (hosts[hostname] != myips)) && !myips.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.span(operation, &block)
|
def self.span(operation, &block)
|
||||||
|
@ -167,6 +167,34 @@ describe Dyndnsd::Daemon do
|
|||||||
expect(last_response.body).to eq("nochg 2001:db8::1\ngood 2001:db8::1")
|
expect(last_response.body).to eq("nochg 2001:db8::1\ngood 2001:db8::1")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'offlines a host' do
|
||||||
|
authorize 'test', 'secret'
|
||||||
|
|
||||||
|
get '/nic/update?hostname=foo.example.org&myip=1.2.3.4'
|
||||||
|
expect(last_response).to be_ok
|
||||||
|
expect(last_response.body).to eq('good 1.2.3.4')
|
||||||
|
|
||||||
|
get '/nic/update?hostname=foo.example.org&offline=YES'
|
||||||
|
expect(last_response).to be_ok
|
||||||
|
expect(last_response.body).to eq('good ')
|
||||||
|
|
||||||
|
get '/nic/update?hostname=foo.example.org&offline=YES'
|
||||||
|
expect(last_response).to be_ok
|
||||||
|
expect(last_response.body).to eq('nochg ')
|
||||||
|
|
||||||
|
get '/nic/update?hostname=foo.example.org&myip=1.2.3.4'
|
||||||
|
expect(last_response).to be_ok
|
||||||
|
expect(last_response.body).to eq('good 1.2.3.4')
|
||||||
|
|
||||||
|
get '/nic/update?hostname=foo.example.org&myip=1.2.3.4&offline=YES'
|
||||||
|
expect(last_response).to be_ok
|
||||||
|
expect(last_response.body).to eq('good ')
|
||||||
|
|
||||||
|
get '/nic/update?hostname=foo.example.org&myip=1.2.3.4&offline=YES'
|
||||||
|
expect(last_response).to be_ok
|
||||||
|
expect(last_response.body).to eq('nochg ')
|
||||||
|
end
|
||||||
|
|
||||||
it 'uses clients remote IP 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'
|
||||||
|
Loading…
Reference in New Issue
Block a user