Comparison

mod_firewall/conditions.lib.lua @ 5856:75dee6127829 draft

Merge upstream
author Trần H. Trung <xmpp:trần.h.trung@trung.fun>
date Tue, 06 Feb 2024 18:32:01 +0700
parent 5816:e304e19536f2
comparison
equal deleted inserted replaced
5664:52db2da66680 5856:75dee6127829
203 function condition_handlers.MAY(permission_to_check) 203 function condition_handlers.MAY(permission_to_check)
204 return ("module:may(%q, event)"):format(permission_to_check); 204 return ("module:may(%q, event)"):format(permission_to_check);
205 end 205 end
206 206
207 function condition_handlers.TO_ROLE(role_name) 207 function condition_handlers.TO_ROLE(role_name)
208 return ("get_jid_role(bare_to, current_host) == %q"):format(role_name), { "get_jid_role", "current_host", "bare_to" }; 208 return ("recipient_role and recipient_role.name == %q"):format(role_name), { "recipient_role" };
209 end 209 end
210 210
211 function condition_handlers.FROM_ROLE(role_name) 211 function condition_handlers.FROM_ROLE(role_name)
212 return ("get_jid_role(bare_from, current_host) == %q"):format(role_name), { "get_jid_role", "current_host", "bare_from" }; 212 return ("sender_role and sender_role.name == %q"):format(role_name), { "sender_role" };
213 end 213 end
214 214
215 local day_numbers = { sun = 0, mon = 2, tue = 3, wed = 4, thu = 5, fri = 6, sat = 7 }; 215 local day_numbers = { sun = 0, mon = 2, tue = 3, wed = 4, thu = 5, fri = 6, sat = 7 };
216 216
217 local function current_time_check(op, hour, minute) 217 local function current_time_check(op, hour, minute)
379 "it_count", 379 "it_count",
380 "search:"..search_name, "pattern:"..pattern_name 380 "search:"..search_name, "pattern:"..pattern_name
381 }; 381 };
382 end 382 end
383 383
384 -- FROM COUNTRY: SE
385 -- FROM COUNTRY: code=SE
386 -- FROM COUNTRY: SWE
387 -- FROM COUNTRY: code3=SWE
388 -- FROM COUNTRY: continent=EU
389 -- FROM COUNTRY? --> NOT FROM COUNTRY: -- (for unknown/invalid)
390 -- TODO list support?
391 function condition_handlers.FROM_COUNTRY(geoip_spec)
392 local condition = "==";
393 if not geoip_spec then
394 geoip_spec = "--";
395 condition = "~=";
396 end
397 local field, country = geoip_spec:match("(%w+)=(%w+)");
398 if not field then
399 if #geoip_spec == 3 then
400 field, country = "code3", geoip_spec;
401 elseif #geoip_spec == 2 then
402 field, country = "code", geoip_spec;
403 else
404 error("Unknown country code type");
405 end
406 end
407 return ("get_geoip(session.ip, %q) %s %q"):format(field:lower(), condition, country:upper()), { "geoip_country" };
408 end
409
384 return condition_handlers; 410 return condition_handlers;