Mercurial > prosody-modules
diff mod_firewall/mod_firewall.lua @ 2118:643b254e75de
mod_firewall: Disable more realistic output by default, activated by adding a -v flag
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 17 Mar 2016 14:33:14 +0100 |
parents | 5aa3b93cd37a |
children | 89363766202c |
line wrap: on
line diff
--- a/mod_firewall/mod_firewall.lua Thu Mar 17 14:20:06 2016 +0100 +++ b/mod_firewall/mod_firewall.lua Thu Mar 17 14:33:14 2016 +0100 @@ -413,32 +413,42 @@ require"util.prosodyctl".show_usage([[mod_firewall <firewall.pfw>]], [[Compile files with firewall rules to Lua code]]); return 1; end + local verbose = arg[1] == "-v"; + if verbose then table.remove(arg, 1); end local serialize = require "util.serialization".serialize; - print("local logger = require \"util.logger\".init;"); - print(); - print("local function fire_event(name, data)\n\tmodule:fire_event(name, data)\nend"); - print(); + if verbose then + print("local logger = require \"util.logger\".init;"); + print(); + print("local function fire_event(name, data)\n\tmodule:fire_event(name, data)\nend"); + print(); + end for _, filename in ipairs(arg) do print("do -- File "..filename); local chain_functions = assert(compile_firewall_rules(arg[1])); - print(); - print("local active_definitions = "..serialize(active_definitions)..";"); - print(); + if verbose then + print(); + print("local active_definitions = "..serialize(active_definitions)..";"); + print(); + end for chain, handler_code in pairs(chain_functions) do print("---- Chain "..chain:gsub("_", " ")); + if not verbose then + print(("%s = %s;"):format(chain, handler_code:sub(8))); + else - print(("local %s = (%s)(active_definitions, fire_event, logger(%q));"):format(chain, handler_code:sub(8), filename)); - print(); + print(("local %s = (%s)(active_definitions, fire_event, logger(%q));"):format(chain, handler_code:sub(8), filename)); + print(); - local chain_definition = chains[chain]; - if chain_definition and chain_definition.type == "event" then - for _, event_name in ipairs(chain_definition) do - print(("module:hook(%q, %s, %d);"):format(event_name, chain, chain_definition.priority or 0)); + local chain_definition = chains[chain]; + if chain_definition and chain_definition.type == "event" then + for _, event_name in ipairs(chain_definition) do + print(("module:hook(%q, %s, %d);"):format(event_name, chain, chain_definition.priority or 0)); + end end + print(("module:hook(%q, %s, %d);"):format("firewall/chains/"..chain, chain, chain_definition.priority or 0)); end - print(("module:hook(%q, %s, %d);"):format("firewall/chains/"..chain, chain, chain_definition.priority or 0)); print("---- End of chain "..chain); print();