mirror of
https://gitgud.io/fatchan/haproxy-protection.git
synced 2025-05-09 02:05:37 +00:00
refactor: sets ratelimit as action
This commit is contained in:
@@ -17,7 +17,7 @@ frontend http-in
|
|||||||
http-request lua.hcaptcha-redirect if !{ path -m beg /captcha }
|
http-request lua.hcaptcha-redirect if !{ path -m beg /captcha }
|
||||||
http-request use-service lua.hello-world if { path /hello_world }
|
http-request use-service lua.hello-world if { path /hello_world }
|
||||||
http-request use-service lua.hcaptcha-view if { path /captcha/ }
|
http-request use-service lua.hcaptcha-view if { path /captcha/ }
|
||||||
http-request use-service lua.ratelimit if { path /test }
|
http-request lua.ratelimit if !{ path -m beg /captcha }
|
||||||
|
|
||||||
acl captcha_passed var(txn.captcha_passed) -m bool
|
acl captcha_passed var(txn.captcha_passed) -m bool
|
||||||
acl on_captcha_url path -m beg /captcha
|
acl on_captcha_url path -m beg /captcha
|
||||||
|
@@ -2,26 +2,10 @@ package.path = package.path .. "./?.lua;/usr/local/etc/haproxy/scripts/?.lua"
|
|||||||
test = {}
|
test = {}
|
||||||
local redis = require 'redis'
|
local redis = require 'redis'
|
||||||
client = redis.connect('redis', 6379)
|
client = redis.connect('redis', 6379)
|
||||||
-- response = client:ping()
|
local expire_time
|
||||||
-- print(response)
|
|
||||||
function test.ratelimit(applet)
|
function test.ratelimit(txn)
|
||||||
host = applet.headers.host[0]
|
local host = txn.sf:hdr("Host")
|
||||||
current = client:llen(host)
|
|
||||||
if current > 3 then
|
|
||||||
applet:set_status(200)
|
|
||||||
local response = string.format([[<html><body>powel naxyi %s, current - %s\n</body></html>]], host, current, message);
|
|
||||||
applet:add_header("content-type", "text/html");
|
|
||||||
applet:add_header("content-length", string.len(response))
|
|
||||||
applet:start_response()
|
|
||||||
applet:send(response)
|
|
||||||
else
|
|
||||||
client:rpush(host,host)
|
client:rpush(host,host)
|
||||||
client:expire(host, 10)
|
client:expire(host, expire_time)
|
||||||
applet:set_status(200)
|
|
||||||
local response = string.format([[<html><body>lox %s, current - %s\n</body></html>]], host, current, message);
|
|
||||||
applet:add_header("content-type", "text/html");
|
|
||||||
applet:add_header("content-length", string.len(response))
|
|
||||||
applet:start_response()
|
|
||||||
applet:send(response)
|
|
||||||
end
|
|
||||||
end
|
end
|
Reference in New Issue
Block a user