comparison mod_firewall/mod_firewall.lua @ 6533:0f61d13ebbde

mod_firewall: Update module status when scripts succeed/fail to load
author Matthew Wild <mwild1@gmail.com>
date Wed, 06 May 2026 15:41:56 +0100
parents f61564e11d3b
children 5aeefc2251d4
comparison
equal deleted inserted replaced
6532:ac6f0db675aa 6533:0f61d13ebbde
711 module:hook(event_name, handler); 711 module:hook(event_name, handler);
712 end 712 end
713 end 713 end
714 loaded_scripts[script] = { last_modified = last_modified, events_hooked = events_hooked }; 714 loaded_scripts[script] = { last_modified = last_modified, events_hooked = events_hooked };
715 module:log("debug", "Loaded %s", script); 715 module:log("debug", "Loaded %s", script);
716 return true;
716 end 717 end
717 718
718 --COMPAT w/0.9 (no module:unhook()!) 719 --COMPAT w/0.9 (no module:unhook()!)
719 local function module_unhook(event, handler) 720 local function module_unhook(event, handler)
720 return module:unhook_object_event((hosts[module.host] or prosody).events, event, handler); 721 return module:unhook_object_event((hosts[module.host] or prosody).events, event, handler);
741 -- be loaded, which are already loaded but need unloading, and which to reload 742 -- be loaded, which are already loaded but need unloading, and which to reload
742 function load_unload_scripts(script_list) 743 function load_unload_scripts(script_list)
743 local wanted_scripts = script_list / resolve_script_path; 744 local wanted_scripts = script_list / resolve_script_path;
744 local currently_loaded = set.new(it.to_array(it.keys(loaded_scripts))); 745 local currently_loaded = set.new(it.to_array(it.keys(loaded_scripts)));
745 local scripts_to_unload = currently_loaded - wanted_scripts; 746 local scripts_to_unload = currently_loaded - wanted_scripts;
747 local n_wanted, n_loaded = 0, 0;
746 for script in wanted_scripts do 748 for script in wanted_scripts do
749 n_wanted = n_wanted + 1;
747 -- If the script is already loaded, this is fine - it will 750 -- If the script is already loaded, this is fine - it will
748 -- reload the script for us if the file has changed 751 -- reload the script for us if the file has changed
749 load_script(script); 752 if load_script(script) then
753 n_loaded = n_loaded + 1;
754 end
750 end 755 end
751 for script in scripts_to_unload do 756 for script in scripts_to_unload do
752 unload_script(script); 757 unload_script(script);
753 end 758 end
759 module:log_status(n_wanted == n_loaded and "info" or "warn", "Loaded %d of %d scripts", n_loaded, n_wanted);
754 end 760 end
755 761
756 function module.load() 762 function module.load()
757 if not prosody.arg then return end -- Don't run in prosodyctl 763 if not prosody.arg then return end -- Don't run in prosodyctl
758 local firewall_scripts = module:get_option_set("firewall_scripts", {}); 764 local firewall_scripts = module:get_option_set("firewall_scripts", {});