Mercurial > prosody-modules
changeset 1052:80f0a3231c59
mod_firewall: Add support for being called as a prosodyctl command
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 05 Jun 2013 21:14:59 +0200 |
parents | c66ea26e4224 |
children | cabbcc1997d9 |
files | mod_firewall/mod_firewall.lua |
diffstat | 1 files changed, 19 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_firewall/mod_firewall.lua Wed Jun 05 21:13:20 2013 +0200 +++ b/mod_firewall/mod_firewall.lua Wed Jun 05 21:14:59 2013 +0200 @@ -341,6 +341,7 @@ 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 @@ -372,3 +373,21 @@ for k in it.keys(definitions) do definitions[k] = nil; end for k,v in pairs(active_definitions) do definitions[k] = v; end end + +function module.command(arg) + if not arg[1] or arg[1] == "--help" then + require"util.prosodyctl".show_usage([[mod_firewall <firewall.pfw>]], [[Compile files with firewall rules to Lua code]]); + return 1; + end + + for _, filename in ipairs(arg) do + print("\n-- File "..filename); + local chain_functions = assert(compile_firewall_rules(arg[1])); + for chain, handler_code in pairs(chain_functions) do + print("\n---- Chain "..chain); + print(handler_code); + print("\n---- End of chain "..chain); + end + print("\n-- End of file "..filename); + end +end