mirror of
https://gitgud.io/fatchan/haproxy-protection.git
synced 2025-05-09 02:05:37 +00:00
update, dynamic backends based on hostname ,can be updated live control panel/management socket
This commit is contained in:
@ -14,9 +14,28 @@ local pow_cookie_secret = os.getenv("POW_COOKIE_SECRET")
|
||||
local ray_id = os.getenv("RAY_ID")
|
||||
|
||||
local captcha_provider_domain = "hcaptcha.com"
|
||||
|
||||
local captcha_map = Map.new("/etc/haproxy/ddos.map", Map._str);
|
||||
|
||||
function _M.setup_servers()
|
||||
local backend_name = os.getenv("BACKEND_NAME")
|
||||
local server_prefix = os.getenv("SERVER_PREFIX")
|
||||
local hosts_map = Map.new("/etc/haproxy/hosts.map", Map._str);
|
||||
local backends_map = Map.new("/etc/haproxy/backends.map", Map._str);
|
||||
local handle = io.open("/etc/haproxy/hosts.map", "r")
|
||||
local line = handle:read("*line")
|
||||
local counter = 1
|
||||
while line do
|
||||
local hostname, backend_address = line:match("([^%s]+)%s+([^%s]+)")
|
||||
core.set_map("/etc/haproxy/backends.map", hostname, "websrv"..counter)
|
||||
local proxy = core.proxies[backend_name].servers[server_prefix..counter]
|
||||
proxy:set_addr(backend_address)
|
||||
proxy:set_ready()
|
||||
line = handle:read("*line")
|
||||
counter = counter + 1
|
||||
end
|
||||
handle:close()
|
||||
end
|
||||
|
||||
-- main page template
|
||||
local body_template = [[
|
||||
<!DOCTYPE html>
|
||||
|
@ -6,3 +6,4 @@ core.register_service("hcaptcha-view", "http", hcaptcha.view)
|
||||
core.register_action("hcaptcha-check", { 'http-req', }, hcaptcha.check_captcha_status)
|
||||
core.register_action("pow-check", { 'http-req', }, hcaptcha.check_pow_status)
|
||||
core.register_action("decide-checks-necessary", { 'http-req', }, hcaptcha.decide_checks_necessary)
|
||||
core.register_init(hcaptcha.setup_servers)
|
||||
|
Reference in New Issue
Block a user