2022-12-06 03:36:15 +00:00
|
|
|
local CONFIG_PATH = ".;/etc/aproxy"
|
|
|
|
|
|
|
|
-- function loadConfig()
|
|
|
|
-- -- TODO load config_path
|
|
|
|
-- return require("./config.lua")
|
|
|
|
-- end
|
|
|
|
--
|
|
|
|
-- local config = loadConfig()
|
|
|
|
|
|
|
|
function log(msg)
|
|
|
|
ngx.log(ngx.STDERR, tostring(msg))
|
|
|
|
end
|
|
|
|
|
|
|
|
local WANTED_SCRIPTS = {
|
2022-12-06 16:48:09 +00:00
|
|
|
['scripts.webfinger_allowlist'] = {accounts = {"example@example.com"}}
|
2022-12-06 03:36:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
local compiled_chain = {}
|
|
|
|
|
2022-12-06 16:48:09 +00:00
|
|
|
for module_name, module_config in pairs(WANTED_SCRIPTS) do
|
|
|
|
module = require(module_name)
|
|
|
|
table.insert(compiled_chain, {module, module_config})
|
2022-12-06 03:36:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function onRequest()
|
2022-12-06 16:48:09 +00:00
|
|
|
local request_uri = ngx.var.uri
|
|
|
|
|
|
|
|
-- find out which modules to call based on their regexes
|
|
|
|
local callbacks_to_call = {}
|
|
|
|
for _, filter in ipairs(compiled_chain) do
|
|
|
|
local module, module_config = filter[1], filter[2]
|
|
|
|
|
|
|
|
for callback_regex, callback_function in pairs(module.callbacks) do
|
|
|
|
local match, error = ngx.re.match(request_uri, callback_regex)
|
|
|
|
if match then
|
|
|
|
table.insert(callbacks_to_call, {callback_function, module_config})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-12-06 03:36:15 +00:00
|
|
|
log('AWOOOOGA')
|
|
|
|
|
2022-12-06 16:48:09 +00:00
|
|
|
for _,tuple in ipairs(callbacks_to_call) do
|
|
|
|
local callback_function, config = tuple[1], tuple[2]
|
|
|
|
local result, body = callback_function(config)
|
|
|
|
log(result)
|
|
|
|
log(body)
|
|
|
|
if not result then
|
2022-12-06 03:36:15 +00:00
|
|
|
ngx.status = 400
|
|
|
|
ngx.say(body or "request denied")
|
|
|
|
ngx.exit(400)
|
2022-12-06 16:48:09 +00:00
|
|
|
end
|
|
|
|
end
|
2022-12-06 03:36:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return onRequest
|