2024-03-12 21:51:59 +01:00
|
|
|
require "ipc"
|
2024-03-12 02:36:01 +01:00
|
|
|
require "http/server"
|
|
|
|
|
|
|
|
port = ARGV[0].to_i rescue 8080
|
|
|
|
addr = ARGV[1] rescue "127.0.0.1"
|
|
|
|
|
2024-03-12 21:51:59 +01:00
|
|
|
# TODO: connect to `dnsmanagerd`.
|
2024-03-12 02:36:01 +01:00
|
|
|
|
2024-03-12 21:51:59 +01:00
|
|
|
server = HTTP::Server.new do |context|
|
2024-03-12 02:36:01 +01:00
|
|
|
pp! context.request.remote_address
|
|
|
|
|
2024-03-12 21:51:59 +01:00
|
|
|
case context.request.path
|
2024-03-12 02:36:01 +01:00
|
|
|
when /^\/token-update\/(?<token>[a-z-]+)/
|
|
|
|
token = $~["token"]
|
|
|
|
if token.nil?
|
|
|
|
context.response.status_code = 404
|
|
|
|
context.response.print "invalid token"
|
|
|
|
else
|
|
|
|
context.response.content_type = "text/html"
|
|
|
|
context.response.print "coucou, token: #{token}"
|
2024-03-12 21:51:59 +01:00
|
|
|
# TODO: send update to `dnsmanagerd`.
|
2024-03-12 02:36:01 +01:00
|
|
|
end
|
|
|
|
else
|
|
|
|
context.response.status_code = 404
|
|
|
|
context.response.print "Not found"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
address = server.bind_tcp addr, port
|
|
|
|
puts "Receiving tokens on http://#{address}/token-update/<token>"
|
|
|
|
server.listen
|