Software /
code /
prosody-modules
Diff
mod_firewall/mod_firewall.lua @ 5676:62c6e17a5e9d
Merge
author | Stephen Paul Weber <singpolyma@singpolyma.net> |
---|---|
date | Mon, 18 Sep 2023 08:24:19 -0500 |
parent | 5542:048284447643 |
child | 5727:ad5c77793750 |
line wrap: on
line diff
--- a/mod_firewall/mod_firewall.lua Mon Sep 18 08:22:07 2023 -0500 +++ b/mod_firewall/mod_firewall.lua Mon Sep 18 08:24:19 2023 -0500 @@ -316,7 +316,7 @@ local condition_handlers = module:require("conditions"); local action_handlers = module:require("actions"); -if module:get_option_boolean("firewall_experimental_user_marks", false) then +if module:get_option_boolean("firewall_experimental_user_marks", true) then module:require"marks"; end @@ -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