mirror of
https://gitgud.io/fatchan/haproxy-protection.git
synced 2025-05-09 02:05:37 +00:00
add dataplaneapi for --save-map-files, and bugfix some small things. custom domain/backendip working pretty well now
This commit is contained in:
@ -12,12 +12,14 @@ services:
|
||||
ports:
|
||||
- 80:80 #http
|
||||
- 2000:2000 #port 2000 haproxy socket for external management
|
||||
- 2001:2001 #dataplaneapi
|
||||
volumes:
|
||||
- ./haproxy/haproxy.cfg:/etc/haproxy/haproxy.cfg
|
||||
- ./haproxy/ddos.map:/etc/haproxy/ddos.map
|
||||
- ./haproxy/hosts.map:/etc/haproxy/hosts.map
|
||||
- ./haproxy/backends.map:/etc/haproxy/backends.map
|
||||
- ./haproxy/blocked.map:/etc/haproxy/blocked.map
|
||||
- ./haproxy/dataplaneapi.hcl:/etc/haproxy/dataplaneapi.hcl
|
||||
- ./src/scripts/:/etc/haproxy/scripts/
|
||||
- ./src/libs/:/etc/haproxy/libs/
|
||||
- ./haproxy/js/:/var/www/js/
|
||||
@ -28,8 +30,8 @@ services:
|
||||
- POW_COOKIE_SECRET=
|
||||
- RAY_ID=
|
||||
- BUCKET_DURATION=43200
|
||||
- BACKEND_NAME="servers"
|
||||
- SERVER_PREFIX="websrv"
|
||||
- BACKEND_NAME=servers
|
||||
- SERVER_PREFIX=websrv
|
||||
nginx:
|
||||
ports:
|
||||
- 81:80
|
||||
|
@ -39,6 +39,11 @@ RUN set -eux; \
|
||||
; \
|
||||
rm -rf /var/lib/apt/lists/*; \
|
||||
\
|
||||
wget -O dataplaneapi_2.4.4_Linux_x86_64.tar.gz https://github.com/haproxytech/dataplaneapi/releases/download/v2.4.4/dataplaneapi_2.4.4_Linux_x86_64.tar.gz; \
|
||||
tar -zxvf dataplaneapi_2.4.4_Linux_x86_64.tar.gz; \
|
||||
chmod +x build/dataplaneapi; \
|
||||
cp build/dataplaneapi /usr/local/bin/; \
|
||||
\
|
||||
wget -O haproxy.tar.gz "$HAPROXY_URL"; \
|
||||
echo "$HAPROXY_SHA256 *haproxy.tar.gz" | sha256sum -c; \
|
||||
mkdir -p /usr/src/haproxy; \
|
||||
|
29
haproxy/dataplaneapi.hcl
Normal file
29
haproxy/dataplaneapi.hcl
Normal file
@ -0,0 +1,29 @@
|
||||
config_version = 2
|
||||
|
||||
name = "meet_bedbug"
|
||||
|
||||
mode = "single"
|
||||
|
||||
dataplaneapi {
|
||||
user "admin" {
|
||||
insecure = true
|
||||
password = "adminpwd"
|
||||
}
|
||||
|
||||
transaction {
|
||||
transaction_dir = "/tmp/haproxy"
|
||||
}
|
||||
|
||||
advertised {}
|
||||
}
|
||||
|
||||
haproxy {
|
||||
config_file = "/etc/haproxy/haproxy.cfg"
|
||||
haproxy_bin = "/usr/local/sbin/haproxy"
|
||||
|
||||
reload {
|
||||
reload_delay = 5
|
||||
reload_cmd = "service haproxy reload"
|
||||
restart_cmd = "service haproxy restart"
|
||||
}
|
||||
}
|
@ -12,10 +12,13 @@ defaults
|
||||
timeout client 50000ms
|
||||
timeout server 50000ms
|
||||
|
||||
program api
|
||||
command dataplaneapi -f /etc/haproxy/dataplaneapi.hcl --update-map-files
|
||||
no option start-on-reload
|
||||
|
||||
frontend http-in
|
||||
option httplog
|
||||
bind *:80
|
||||
bind *:443
|
||||
|
||||
acl is_existing_vhost hdr(host),lower,map_str(/etc/haproxy/hosts.map) -m found
|
||||
http-request silent-drop unless is_existing_vhost
|
||||
|
@ -16,19 +16,22 @@ local ray_id = os.getenv("RAY_ID")
|
||||
local captcha_provider_domain = "hcaptcha.com"
|
||||
local captcha_map = Map.new("/etc/haproxy/ddos.map", Map._str);
|
||||
|
||||
require("print_r")
|
||||
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 domain, backend_host = line:match("([^%s]+)%s+([^%s]+)")
|
||||
local port_index = backend_host:match'^.*():'
|
||||
local backend_hostname = backend_host:sub(0, port_index-1)
|
||||
local backend_port = backend_host:sub(port_index + 1)
|
||||
core.set_map("/etc/haproxy/backends.map", domain, server_prefix..counter)
|
||||
local proxy = core.proxies[backend_name].servers[server_prefix..counter]
|
||||
proxy:set_addr(backend_address)
|
||||
proxy:set_addr(backend_hostname, backend_port)
|
||||
proxy:set_ready()
|
||||
line = handle:read("*line")
|
||||
counter = counter + 1
|
||||
|
Reference in New Issue
Block a user