diff mod_firewall/conditions.lib.lua @ 2894:165d2877eeac

mod_firewall: Add experimental user-centric persistent marks behind a feature flag
author Kim Alvefur <zash@zash.se>
date Sat, 24 Feb 2018 21:40:56 +0100
parents 6f289283feb1
children b1cdcbcd1c90
line wrap: on
line diff
--- a/mod_firewall/conditions.lib.lua	Sat Feb 24 19:38:10 2018 +0100
+++ b/mod_firewall/conditions.lib.lua	Sat Feb 24 21:40:56 2018 +0100
@@ -276,6 +276,20 @@
 	return ("not not session.firewall_marked_"..idsafe(name));
 end
 
+function condition_handlers.USER_MARKED(name_and_time)
+	local name, time = name_and_time:match("^%s*([%w_]+)%s+%(([^)]+)s%)%s*$");
+	if not name then
+		name = name_and_time:match("^%s*([%w_]+)%s*$");
+	end
+	if not name then
+		error("Error parsing mark name, see documentation for usage examples");
+	end
+	if time then
+		return ("(current_timestamp - (session.firewall_marks and session.firewall_marks.%s or 0)) < %d"):format(idsafe(name), tonumber(time)), { "timestamp" };
+	end
+	return ("not not (session.firewall_marks and session.firewall_marks."..idsafe(name)..")");
+end
+
 function condition_handlers.SENT_DIRECTED_PRESENCE_TO_SENDER()
 	return "not not (session.directed and session.directed[from])", { "from" };
 end