aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_register_limits.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2020-11-05 22:31:25 +0100
committerKim Alvefur <zash@zash.se>2020-11-05 22:31:25 +0100
commit238b2bfc1cdb65ae7d051c2f29c1427149317795 (patch)
tree58547de6e7795740633c1b93e67c217eb621fe8f /plugins/mod_register_limits.lua
parentce3e3808f5359f481f3ea063220ba71428b26ad5 (diff)
parent48521ba1538f797f5bef64f5fe5f3a9fb6e68f7f (diff)
downloadprosody-238b2bfc1cdb65ae7d051c2f29c1427149317795.tar.gz
prosody-238b2bfc1cdb65ae7d051c2f29c1427149317795.zip
Merge 0.11->trunk
Diffstat (limited to 'plugins/mod_register_limits.lua')
-rw-r--r--plugins/mod_register_limits.lua31
1 files changed, 28 insertions, 3 deletions
diff --git a/plugins/mod_register_limits.lua b/plugins/mod_register_limits.lua
index 736282a5..7c80f18b 100644
--- a/plugins/mod_register_limits.lua
+++ b/plugins/mod_register_limits.lua
@@ -13,6 +13,7 @@ local ip_util = require "util.ip";
local new_ip = ip_util.new_ip;
local match_ip = ip_util.match;
local parse_cidr = ip_util.parse_cidr;
+local errors = require "util.error";
local min_seconds_between_registrations = module:get_option_number("min_seconds_between_registrations");
local whitelist_only = module:get_option_boolean("whitelist_registration_only");
@@ -54,6 +55,24 @@ local function ip_in_set(set, ip)
return false;
end
+local err_registry = {
+ blacklisted = {
+ text = "Your IP address is blacklisted";
+ type = "auth";
+ condition = "forbidden";
+ };
+ not_whitelisted = {
+ text = "Your IP address is not whitelisted";
+ type = "auth";
+ condition = "forbidden";
+ };
+ throttled = {
+ text = "Too many registrations from this IP address recently";
+ type = "wait";
+ condition = "policy-violation";
+ };
+}
+
module:hook("user-registering", function (event)
local session = event.session;
local ip = event.ip or session and session.ip;
@@ -63,16 +82,22 @@ module:hook("user-registering", function (event)
elseif ip_in_set(blacklisted_ips, ip) then
log("debug", "Registration disallowed by blacklist");
event.allowed = false;
- event.reason = "Your IP address is blacklisted";
+ event.error = errors.new("blacklisted", event, err_registry);
elseif (whitelist_only and not ip_in_set(whitelisted_ips, ip)) then
log("debug", "Registration disallowed by whitelist");
event.allowed = false;
- event.reason = "Your IP address is not whitelisted";
+ event.error = errors.new("not_whitelisted", event, err_registry);
elseif throttle_max and not ip_in_set(whitelisted_ips, ip) then
if not check_throttle(ip) then
log("debug", "Registrations over limit for ip %s", ip or "?");
event.allowed = false;
- event.reason = "Too many registrations from this IP address recently";
+ event.error = errors.new("throttled", event, err_registry);
end
end
+ if event.error then
+ -- COMPAT pre-util.error
+ event.reason = event.error.text;
+ event.error_type = event.error.type;
+ event.error_condition = event.error.condition;
+ end
end);