hotfix - fix API in autoconf swarm mode

This commit is contained in:
bunkerity 2021-04-28 17:40:54 +02:00
parent 3bb164395e
commit 07be626842
No known key found for this signature in database
GPG Key ID: 3D80806F12602A7C
2 changed files with 3 additions and 2 deletions

View File

@ -220,6 +220,7 @@ if [ "$USE_API" = "yes" ] ; then
API_URI="/$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
echo "[*] Generated API URI : $API_URI"
fi
replace_in_file "/etc/nginx/api.conf" "%API_URI%" "$API_URI"
else
replace_in_file "/etc/nginx/nginx.conf" "%USE_API%" ""
fi

View File

@ -1,8 +1,8 @@
local M = {}
local api_list = {}
local api_whitelist_ip = {%API_WHITELIST_IP%}
local iputils = require "resty.iputils"
local whitelist = iputils.parse_cidrs(api_whitelist_ip)
local ip = ngx.var.remote_addr
api_list["^/ping$"] = function ()
return true
@ -13,7 +13,7 @@ api_list["^/reload$"] = function ()
end
function M.is_api_call (api_uri)
if iputils.ip_in_cidrs(ip, whitelist) and ngx.var.request_uri:sub(1, #api_uri) .. "/" == api_uri .. "/" then
if iputils.ip_in_cidrs(ngx.var.remote_addr, whitelist) and ngx.var.request_uri:sub(1, #api_uri) .. "/" == api_uri .. "/" then
for uri, code in pairs(api_list) do
if string.match(ngx.var.request_uri:sub(#api_uri + 1), uri) then
return true