diff --git a/lib/dyndnsd.rb b/lib/dyndnsd.rb index 5a0b918..8bbda1b 100644 --- a/lib/dyndnsd.rb +++ b/lib/dyndnsd.rb @@ -8,6 +8,7 @@ require 'rack' require 'dyndnsd/generator/bind' require 'dyndnsd/updater/command_with_bind_zone' +require 'dyndnsd/responder/dyndns_style' require 'dyndnsd/responder/rest_style' require 'dyndnsd/database' require 'dyndnsd/version' @@ -110,7 +111,7 @@ module Dyndnsd db = Database.new(config['db']) updater = Updater::CommandWithBindZone.new(config['updater']['params']) if config['updater']['name'] == 'command_with_bind_zone' - responder = Responder::RestStyle.new + responder = Responder::DynDNSStyle.new app = Daemon.new(config, db, updater, responder) app = Rack::Auth::Basic.new(app, "DynDNS") do |user,pass| diff --git a/lib/dyndnsd/responder/dyndns_style.rb b/lib/dyndnsd/responder/dyndns_style.rb new file mode 100644 index 0000000..584f73a --- /dev/null +++ b/lib/dyndnsd/responder/dyndns_style.rb @@ -0,0 +1,19 @@ + +module Dyndnsd + module Responder + class DynDNSStyle + def response_for(state, ip = nil) + # general http errors + return [405, {"Content-Type" => "text/plain"}, ["Method Not Allowed"]] if state == :method_forbidden + return [404, {"Content-Type" => "text/plain"}, ["Not Found"]] if state == :not_found + # specific errors + return [200, {"Content-Type" => "text/plain"}, ["notfqdn"]] if state == :hostname_missing + return [200, {"Content-Type" => "text/plain"}, ["nohost"]] if state == :host_forbidden + return [200, {"Content-Type" => "text/plain"}, ["notfqdn"]] if state == :hostname_malformed + # OKs + return [200, {"Content-Type" => "text/plain"}, ["good #{ip}"]] if state == :good + return [200, {"Content-Type" => "text/plain"}, ["nochg #{ip}"]] if state == :nochg + end + end + end +end