comparison mod_firewall/mod_firewall.lua @ 5653:62c6e17a5e9d

Merge
author Stephen Paul Weber <singpolyma@singpolyma.net>
date Mon, 18 Sep 2023 08:24:19 -0500
parents 048284447643
children ad5c77793750
comparison
equal deleted inserted replaced
5652:eade7ff9f52c 5653:62c6e17a5e9d
314 314
315 local definition_handlers = module:require("definitions"); 315 local definition_handlers = module:require("definitions");
316 local condition_handlers = module:require("conditions"); 316 local condition_handlers = module:require("conditions");
317 local action_handlers = module:require("actions"); 317 local action_handlers = module:require("actions");
318 318
319 if module:get_option_boolean("firewall_experimental_user_marks", false) then 319 if module:get_option_boolean("firewall_experimental_user_marks", true) then
320 module:require"marks"; 320 module:require"marks";
321 end 321 end
322 322
323 local function new_rule(ruleset, chain) 323 local function new_rule(ruleset, chain)
324 assert(chain, "no chain specified"); 324 assert(chain, "no chain specified");
740 print(); 740 print();
741 end 741 end
742 print("end -- End of file "..filename); 742 print("end -- End of file "..filename);
743 end 743 end
744 end 744 end
745
746
747 -- Console
748
749 local console_env = module:shared("/*/admin_shell/env");
750
751 console_env.firewall = {};
752
753 function console_env.firewall:mark(user_jid, mark_name)
754 local username, host = jid.split(user_jid);
755 if not username or not hosts[host] then
756 return nil, "Invalid JID supplied";
757 elseif not idsafe(mark_name) then
758 return nil, "Invalid characters in mark name";
759 end
760 if not module:context(host):fire_event("firewall/marked/user", {
761 username = session.username;
762 mark = mark_name;
763 timestamp = os.time();
764 }) then
765 return nil, "Mark not set - is mod_firewall loaded on that host?";
766 end
767 return true, "User marked";
768 end
769
770 function console_env.firewall:unmark(jid, mark_name)
771 local username, host = jid.split(user_jid);
772 if not username or not hosts[host] then
773 return nil, "Invalid JID supplied";
774 elseif not idsafe(mark_name) then
775 return nil, "Invalid characters in mark name";
776 end
777 if not module:context(host):fire_event("firewall/unmarked/user", {
778 username = session.username;
779 mark = mark_name;
780 }) then
781 return nil, "Mark not removed - is mod_firewall loaded on that host?";
782 end
783 return true, "User unmarked";
784 end