# HG changeset patch # User Kim Alvefur # Date 1370459699 -7200 # Node ID 80f0a3231c595ccab041c673962ca58ade7e2895 # Parent c66ea26e42248a0454e380acc3d87209c871e5ac mod_firewall: Add support for being called as a prosodyctl command diff -r c66ea26e4224 -r 80f0a3231c59 mod_firewall/mod_firewall.lua --- 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 ]], [[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