lua - fix missing multisite variables in LRU

This commit is contained in:
bunkerity 2023-06-15 14:42:09 +02:00
parent fdd3367a65
commit 9adb209a81
4 changed files with 11 additions and 5 deletions

View File

@ -195,6 +195,14 @@ api.global.GET["^/bans$"] = function(self)
return self:response(ngx.HTTP_OK, "success", data)
end
api.global.GET["^/variables$"] = function(self)
local variables, err = datastore:get('variables', true)
if not variables then
return self:response(ngx.HTTP_INTERNAL_SERVER_ERROR, "error", "can't access variables from datastore : " .. err)
end
return self:response(ngx.HTTP_OK, "success", variables)
end
function api:is_allowed_ip()
if utils.is_ip_in_networks(self.ctx.bw.remote_addr, self.ips) then
return true, "ok"

View File

@ -2,7 +2,7 @@ local class = require "middleclass"
local lrucache = require "resty.lrucache"
local datastore = class("datastore")
local lru, err = lrucache.new(10000)
local lru, err = lrucache.new(100000)
if not lru then
require "bunkerweb.logger":new("DATASTORE"):log(ngx.ERR,
"failed to instantiate LRU cache : " .. (err or "unknown error"))

View File

@ -159,6 +159,7 @@ helpers.fill_ctx = function()
data.kind = "stream"
end
data.remote_addr = ngx.var.remote_addr
data.server_name = ngx.var.server_name
if data.kind == "http" then
data.uri = ngx.var.uri
data.request_uri = ngx.var.request_uri
@ -239,7 +240,6 @@ function helpers.load_variables(all_variables, plugins)
local key = server_name .. "_" .. setting
if all_variables[key] then
variables[server_name][setting] = all_variables[key]
break
end
end
end
@ -249,10 +249,8 @@ function helpers.load_variables(all_variables, plugins)
if found then
if multisite and prefix and prefix ~= "" then
variables[prefix][variable] = value
break
end
variables["global"][variable] = value
break
end
end
end

View File

@ -22,7 +22,7 @@ utils.get_variable = function(var, site_search)
-- Get global value
local variables, err = datastore:get('variables', true)
if not variables then
return nil, "can't access variables " .. var .. " from datastore : " .. err
return nil, "can't access variables from datastore : " .. err
end
local value = variables["global"][var]
-- Site search case