# HG changeset patch # User Matthew Wild # Date 1686250055 -3600 # Node ID 04828444764389d0ba06ee49e1c34373e26af108 # Parent 3804ee5117ca8a206e0f1a03e3020d0708af1be4 mod_firewall: Add console commands to mark/unmark users diff -r 3804ee5117ca -r 048284447643 mod_firewall/marks.lib.lua --- a/mod_firewall/marks.lib.lua Thu Jun 08 19:19:46 2023 +0100 +++ b/mod_firewall/marks.lib.lua Thu Jun 08 19:47:35 2023 +0100 @@ -18,7 +18,8 @@ if not ok then module:log("error", "Failed to mark user %q with %q: %s", event.username, event.mark, err); end -end, 1); + return true; +end, -1); module:hook("firewall/unmarked/user", function (event) local user = user_sessions[event.username]; @@ -30,4 +31,5 @@ if not ok then module:log("error", "Failed to unmark user %q with %q: %s", event.username, event.mark, err); end -end, 1); + return true; +end, -1); diff -r 3804ee5117ca -r 048284447643 mod_firewall/mod_firewall.lua --- a/mod_firewall/mod_firewall.lua Thu Jun 08 19:19:46 2023 +0100 +++ b/mod_firewall/mod_firewall.lua Thu Jun 08 19:47:35 2023 +0100 @@ -742,3 +742,43 @@ print("end -- End of file "..filename); end end + + +-- Console + +local console_env = module:shared("/*/admin_shell/env"); + +console_env.firewall = {}; + +function console_env.firewall:mark(user_jid, mark_name) + local username, host = jid.split(user_jid); + if not username or not hosts[host] then + return nil, "Invalid JID supplied"; + elseif not idsafe(mark_name) then + return nil, "Invalid characters in mark name"; + end + if not module:context(host):fire_event("firewall/marked/user", { + username = session.username; + mark = mark_name; + timestamp = os.time(); + }) then + return nil, "Mark not set - is mod_firewall loaded on that host?"; + end + return true, "User marked"; +end + +function console_env.firewall:unmark(jid, mark_name) + local username, host = jid.split(user_jid); + if not username or not hosts[host] then + return nil, "Invalid JID supplied"; + elseif not idsafe(mark_name) then + return nil, "Invalid characters in mark name"; + end + if not module:context(host):fire_event("firewall/unmarked/user", { + username = session.username; + mark = mark_name; + }) then + return nil, "Mark not removed - is mod_firewall loaded on that host?"; + end + return true, "User unmarked"; +end