Comparison

plugins/mod_register_limits.lua @ 13209:c8d949cf6b09

plugins: Switch to :get_option_period() for time range options Improves readability ("1 day" vs 86400) and centralizes validation.
author Kim Alvefur <zash@zash.se>
date Sun, 16 Jul 2023 20:49:33 +0200
parent 12977:74b9e05af71e
child 13213:50324f66ca2a
comparison
equal deleted inserted replaced
13208:a7c6ea1c5308 13209:c8d949cf6b09
14 local match_ip = ip_util.match; 14 local match_ip = ip_util.match;
15 local parse_cidr = ip_util.parse_cidr; 15 local parse_cidr = ip_util.parse_cidr;
16 local errors = require "prosody.util.error"; 16 local errors = require "prosody.util.error";
17 17
18 -- COMPAT drop old option names 18 -- COMPAT drop old option names
19 local min_seconds_between_registrations = module:get_option_number("min_seconds_between_registrations"); 19 local min_seconds_between_registrations = module:get_option_period("min_seconds_between_registrations");
20 local allowlist_only = module:get_option_boolean("allowlist_registration_only", module:get_option_boolean("whitelist_registration_only")); 20 local allowlist_only = module:get_option_boolean("allowlist_registration_only", module:get_option_boolean("whitelist_registration_only"));
21 local allowlisted_ips = module:get_option_set("registration_allowlist", module:get_option("registration_whitelist", { "127.0.0.1", "::1" }))._items; 21 local allowlisted_ips = module:get_option_set("registration_allowlist", module:get_option("registration_whitelist", { "127.0.0.1", "::1" }))._items;
22 local blocklisted_ips = module:get_option_set("registration_blocklist", module:get_option_set("registration_blacklist", {}))._items; 22 local blocklisted_ips = module:get_option_set("registration_blocklist", module:get_option_set("registration_blacklist", {}))._items;
23 23
24 local throttle_max = module:get_option_number("registration_throttle_max", min_seconds_between_registrations and 1); 24 local throttle_max = module:get_option_number("registration_throttle_max", min_seconds_between_registrations and 1);
25 local throttle_period = module:get_option_number("registration_throttle_period", min_seconds_between_registrations); 25 local throttle_period = module:get_option_period("registration_throttle_period", min_seconds_between_registrations);
26 local throttle_cache_size = module:get_option_number("registration_throttle_cache_size", 100); 26 local throttle_cache_size = module:get_option_number("registration_throttle_cache_size", 100);
27 local blocklist_overflow = module:get_option_boolean("blocklist_on_registration_throttle_overload", 27 local blocklist_overflow = module:get_option_boolean("blocklist_on_registration_throttle_overload",
28 module:get_option_boolean("blacklist_on_registration_throttle_overload", false)); 28 module:get_option_boolean("blacklist_on_registration_throttle_overload", false));
29 29
30 local throttle_cache = new_cache(throttle_cache_size, blocklist_overflow and function (ip, throttle) 30 local throttle_cache = new_cache(throttle_cache_size, blocklist_overflow and function (ip, throttle)