Token handler: now handles local updates (from a dev environment).

This commit is contained in:
Philippe Pittoli 2024-03-31 17:57:11 +02:00
parent f63eff59a8
commit 6a9516e2c8

View File

@ -15,13 +15,20 @@ dnsmanagerd = DNSManager::Client.new
server = HTTP::Server.new do |context| server = HTTP::Server.new do |context|
ip = case addr ip = case addr
when "127.0.0.1" when "127.0.0.1"
pp! context.request.remote_address a = context.request.remote_address.not_nil!
context.request.remote_address.not_nil!.to_s case a
when Socket::IPAddress
a.address.to_s
when Socket::UNIXAddress
next
end
else else
pp! context.request.headers["Host"]
context.request.headers["Host"] rescue next context.request.headers["Host"] rescue next
end end
next if ip.nil?
pp! ip
case context.request.path case context.request.path
when /^\/token-update\/(?<token>[a-z0-9-]+)/ when /^\/token-update\/(?<token>[a-z0-9-]+)/
token = $~["token"] token = $~["token"]
@ -30,7 +37,7 @@ server = HTTP::Server.new do |context|
context.response.print "invalid token" context.response.print "invalid token"
else else
context.response.content_type = "text/html" context.response.content_type = "text/html"
context.response.print "coucou, token: #{token} from #{ip}" context.response.print "token: #{token} from #{ip}"
begin begin
response = dnsmanagerd.use_token token, ip response = dnsmanagerd.use_token token, ip
case response case response