Mercurial > prosody-modules
changeset 2366:14021c93a962
mod_firewall: Allow prefixing script paths with 'module:' to specify path relative to module file
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 15 Nov 2016 15:00:38 +0000 (2016-11-15) |
parents | 05dae9adf778 |
children | 3ebd3cb4d7d2 |
files | mod_firewall/mod_firewall.lua |
diffstat | 1 files changed, 11 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_firewall/mod_firewall.lua Tue Nov 15 14:59:49 2016 +0000 +++ b/mod_firewall/mod_firewall.lua Tue Nov 15 15:00:38 2016 +0000 @@ -408,12 +408,21 @@ return chunk; end +local function resolve_script_path(script_path) + local relative_to = prosody.paths.config; + if script_path:match("^module:") then + relative_to = module.path:sub(1, -#("/mod_"..module.name..".lua")); + script_path = script_path:match("^module:(.+)$"); + end + return resolve_relative_path(relative_to, script_path); +end + function module.load() if not prosody.arg then return end -- Don't run in prosodyctl active_definitions = {}; local firewall_scripts = module:get_option_set("firewall_scripts", {}); for script in firewall_scripts do - script = resolve_relative_path(prosody.paths.config, script); + script = resolve_script_path(script); local chain_functions, err = compile_firewall_rules(script) if not chain_functions then @@ -459,6 +468,7 @@ end for _, filename in ipairs(arg) do + filename = resolve_script_path(filename); print("do -- File "..filename); local chain_functions = assert(compile_firewall_rules(filename)); if verbose then