Mercurial > prosody-modules
comparison mod_firewall/mod_firewall.lua @ 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 |
parents | 05dae9adf778 |
children | 3ebd3cb4d7d2 |
comparison
equal
deleted
inserted
replaced
2365:05dae9adf778 | 2366:14021c93a962 |
---|---|
406 end | 406 end |
407 chunk = chunk()(active_definitions, fire_event, logger(filename)); -- Returns event handler with 'zones' upvalue. | 407 chunk = chunk()(active_definitions, fire_event, logger(filename)); -- Returns event handler with 'zones' upvalue. |
408 return chunk; | 408 return chunk; |
409 end | 409 end |
410 | 410 |
411 local function resolve_script_path(script_path) | |
412 local relative_to = prosody.paths.config; | |
413 if script_path:match("^module:") then | |
414 relative_to = module.path:sub(1, -#("/mod_"..module.name..".lua")); | |
415 script_path = script_path:match("^module:(.+)$"); | |
416 end | |
417 return resolve_relative_path(relative_to, script_path); | |
418 end | |
419 | |
411 function module.load() | 420 function module.load() |
412 if not prosody.arg then return end -- Don't run in prosodyctl | 421 if not prosody.arg then return end -- Don't run in prosodyctl |
413 active_definitions = {}; | 422 active_definitions = {}; |
414 local firewall_scripts = module:get_option_set("firewall_scripts", {}); | 423 local firewall_scripts = module:get_option_set("firewall_scripts", {}); |
415 for script in firewall_scripts do | 424 for script in firewall_scripts do |
416 script = resolve_relative_path(prosody.paths.config, script); | 425 script = resolve_script_path(script); |
417 local chain_functions, err = compile_firewall_rules(script) | 426 local chain_functions, err = compile_firewall_rules(script) |
418 | 427 |
419 if not chain_functions then | 428 if not chain_functions then |
420 module:log("error", "Error compiling %s: %s", script, err or "unknown error"); | 429 module:log("error", "Error compiling %s: %s", script, err or "unknown error"); |
421 else | 430 else |
457 print("local function fire_event(name, data)\n\tmodule:fire_event(name, data)\nend"); | 466 print("local function fire_event(name, data)\n\tmodule:fire_event(name, data)\nend"); |
458 print(); | 467 print(); |
459 end | 468 end |
460 | 469 |
461 for _, filename in ipairs(arg) do | 470 for _, filename in ipairs(arg) do |
471 filename = resolve_script_path(filename); | |
462 print("do -- File "..filename); | 472 print("do -- File "..filename); |
463 local chain_functions = assert(compile_firewall_rules(filename)); | 473 local chain_functions = assert(compile_firewall_rules(filename)); |
464 if verbose then | 474 if verbose then |
465 print(); | 475 print(); |
466 print("local active_definitions = "..serialize(active_definitions)..";"); | 476 print("local active_definitions = "..serialize(active_definitions)..";"); |