comparison mod_firewall/mod_firewall.lua @ 5542:048284447643

mod_firewall: Add console commands to mark/unmark users
author Matthew Wild <mwild1@gmail.com>
date Thu, 08 Jun 2023 19:47:35 +0100
parents fa8435a27f7e
children ad5c77793750
comparison
equal deleted inserted replaced
5541:3804ee5117ca 5542:048284447643
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