# HG changeset patch # User Matthew Wild # Date 1479222038 0 # Node ID 14021c93a962ca02e5e902dac097a03bb9b51ffc # Parent 05dae9adf778ae2bfd93a42878df067391ab42e7 mod_firewall: Allow prefixing script paths with 'module:' to specify path relative to module file diff -r 05dae9adf778 -r 14021c93a962 mod_firewall/mod_firewall.lua --- 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