From 6a9516e2c86799fe4f884d5b5c0344e3b048c34e Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Sun, 31 Mar 2024 17:57:11 +0200 Subject: [PATCH] Token handler: now handles local updates (from a dev environment). --- tools/token-handler.cr | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/token-handler.cr b/tools/token-handler.cr index ad1ccd5..883f8f0 100644 --- a/tools/token-handler.cr +++ b/tools/token-handler.cr @@ -15,13 +15,20 @@ dnsmanagerd = DNSManager::Client.new server = HTTP::Server.new do |context| ip = case addr when "127.0.0.1" - pp! context.request.remote_address - context.request.remote_address.not_nil!.to_s + a = context.request.remote_address.not_nil! + case a + when Socket::IPAddress + a.address.to_s + when Socket::UNIXAddress + next + end else - pp! context.request.headers["Host"] context.request.headers["Host"] rescue next end + next if ip.nil? + pp! ip + case context.request.path when /^\/token-update\/(?[a-z0-9-]+)/ token = $~["token"] @@ -30,7 +37,7 @@ server = HTTP::Server.new do |context| context.response.print "invalid token" else context.response.content_type = "text/html" - context.response.print "coucou, token: #{token} from #{ip}" + context.response.print "token: #{token} from #{ip}" begin response = dnsmanagerd.use_token token, ip case response