Changeset

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 5541:3804ee5117ca
children 5543:fed5995180c5
files mod_firewall/marks.lib.lua mod_firewall/mod_firewall.lua
diffstat 2 files changed, 44 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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);
--- 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