Token handler: now works fine with IPv6.
parent
009928a8ee
commit
4029ca7cd0
|
@ -15,6 +15,14 @@ dnsmanagerd = DNSManager::Client.new
|
||||||
|
|
||||||
server = HTTP::Server.new do |context|
|
server = HTTP::Server.new do |context|
|
||||||
ip = case addr
|
ip = case addr
|
||||||
|
when "::1"
|
||||||
|
a = context.request.remote_address.not_nil!
|
||||||
|
case a
|
||||||
|
when Socket::IPAddress
|
||||||
|
a.address.to_s
|
||||||
|
when Socket::UNIXAddress
|
||||||
|
next
|
||||||
|
end
|
||||||
when "127.0.0.1"
|
when "127.0.0.1"
|
||||||
a = context.request.remote_address.not_nil!
|
a = context.request.remote_address.not_nil!
|
||||||
case a
|
case a
|
||||||
|
@ -43,10 +51,10 @@ server = HTTP::Server.new do |context|
|
||||||
response = dnsmanagerd.use_token token, ip
|
response = dnsmanagerd.use_token token, ip
|
||||||
case response
|
case response
|
||||||
when DNSManager::Response::Success
|
when DNSManager::Response::Success
|
||||||
context.response.print "; Success!" # 🔻
|
context.response.puts "; Success!" # 🔻
|
||||||
when DNSManager::Response::Error
|
when DNSManager::Response::Error
|
||||||
puts "error while updating token: #{response.reason}"
|
puts "error while updating token: #{response.reason}"
|
||||||
context.response.print "; command failed: #{response.reason}" # ⚠
|
context.response.puts "; command failed: #{response.reason}" # ⚠
|
||||||
end
|
end
|
||||||
rescue e
|
rescue e
|
||||||
puts "error while updating token: #{e}"
|
puts "error while updating token: #{e}"
|
||||||
|
@ -59,6 +67,6 @@ server = HTTP::Server.new do |context|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
address = server.bind_tcp addr, port
|
address = server.bind_tcp Socket::IPAddress.new(addr, port)
|
||||||
puts "Receiving tokens on http://#{address}/token-update/<token>"
|
puts "Receiving tokens on http://#{address}/token-update/<token>"
|
||||||
server.listen
|
server.listen
|
||||||
|
|
Loading…
Reference in New Issue