From 4029ca7cd05777283f15f5382dd8ffe6846dcc0e Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Mon, 11 Nov 2024 20:39:54 +0100 Subject: [PATCH] Token handler: now works fine with IPv6. --- tools/token-handler.cr | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/token-handler.cr b/tools/token-handler.cr index fbae2a3..ff73f8f 100644 --- a/tools/token-handler.cr +++ b/tools/token-handler.cr @@ -15,6 +15,14 @@ dnsmanagerd = DNSManager::Client.new server = HTTP::Server.new do |context| 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" a = context.request.remote_address.not_nil! case a @@ -43,10 +51,10 @@ server = HTTP::Server.new do |context| response = dnsmanagerd.use_token token, ip case response when DNSManager::Response::Success - context.response.print "; Success!" # 🔻 + context.response.puts "; Success!" # 🔻 when DNSManager::Response::Error puts "error while updating token: #{response.reason}" - context.response.print "; command failed: #{response.reason}" # ⚠ + context.response.puts "; command failed: #{response.reason}" # ⚠ end rescue e puts "error while updating token: #{e}" @@ -59,6 +67,6 @@ server = HTTP::Server.new do |context| 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/" server.listen