comparison mod_firewall/mod_firewall.lua @ 2117:5aa3b93cd37a

mod_firewall: Make prosodyctl command output more realistic source (not guaranteed to work)
author Kim Alvefur <zash@zash.se>
date Thu, 17 Mar 2016 14:20:06 +0100
parents d75145297bf9
children 643b254e75de
comparison
equal deleted inserted replaced
2116:2bb42ba342f3 2117:5aa3b93cd37a
412 if not arg[1] or arg[1] == "--help" then 412 if not arg[1] or arg[1] == "--help" then
413 require"util.prosodyctl".show_usage([[mod_firewall <firewall.pfw>]], [[Compile files with firewall rules to Lua code]]); 413 require"util.prosodyctl".show_usage([[mod_firewall <firewall.pfw>]], [[Compile files with firewall rules to Lua code]]);
414 return 1; 414 return 1;
415 end 415 end
416 416
417 local serialize = require "util.serialization".serialize;
418 print("local logger = require \"util.logger\".init;");
419 print();
420 print("local function fire_event(name, data)\n\tmodule:fire_event(name, data)\nend");
421 print();
422
417 for _, filename in ipairs(arg) do 423 for _, filename in ipairs(arg) do
418 print("\n-- File "..filename); 424 print("do -- File "..filename);
419 local chain_functions = assert(compile_firewall_rules(arg[1])); 425 local chain_functions = assert(compile_firewall_rules(arg[1]));
426 print();
427 print("local active_definitions = "..serialize(active_definitions)..";");
428 print();
420 for chain, handler_code in pairs(chain_functions) do 429 for chain, handler_code in pairs(chain_functions) do
421 print("\n---- Chain "..chain); 430 print("---- Chain "..chain:gsub("_", " "));
422 print(handler_code); 431
423 print("\n---- End of chain "..chain); 432 print(("local %s = (%s)(active_definitions, fire_event, logger(%q));"):format(chain, handler_code:sub(8), filename));
424 end 433 print();
425 print("\n-- End of file "..filename); 434
426 end 435 local chain_definition = chains[chain];
427 end 436 if chain_definition and chain_definition.type == "event" then
437 for _, event_name in ipairs(chain_definition) do
438 print(("module:hook(%q, %s, %d);"):format(event_name, chain, chain_definition.priority or 0));
439 end
440 end
441 print(("module:hook(%q, %s, %d);"):format("firewall/chains/"..chain, chain, chain_definition.priority or 0));
442
443 print("---- End of chain "..chain);
444 print();
445 end
446 print("end -- End of file "..filename);
447 end
448 end