1
0
mirror of https://github.com/cmur2/dyndnsd.git synced 2025-06-26 02:30:22 +02:00

Add "myip6" URL parameter to provide an IPv6 address in addition to an IPv4 one as "myip"

This commit is contained in:
cn
2016-12-07 14:16:57 +01:00
parent ae095c22b7
commit 4894015325
6 changed files with 71 additions and 22 deletions

View File

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

View File

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

View File

@ -11,9 +11,9 @@ module Dyndnsd
return [200, {"Content-Type" => "text/plain"}, ["nohost"]] if state == :host_forbidden
return [200, {"Content-Type" => "text/plain"}, ["notfqdn"]] if state == :hostname_malformed
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

View File

@ -11,9 +11,9 @@ module Dyndnsd
return [403, {"Content-Type" => "text/plain"}, ["Forbidden"]] if state == :host_forbidden
return [422, {"Content-Type" => "text/plain"}, ["Hostname malformed"]] if state == :hostname_malformed
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