Changeset

4304:aec8148df26a

mod_muc_http_auth: Bugfix: Not properly listening on register IQs
author Seve Ferrer <seve@delape.net>
date Fri, 18 Dec 2020 16:31:01 +0100
parents 4303:d261233f7ced
children 4305:2ca55a4da3ea
files mod_muc_http_auth/mod_muc_http_auth.lua
diffstat 1 files changed, 6 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mod_muc_http_auth/mod_muc_http_auth.lua	Fri Dec 18 15:28:12 2020 +0100
+++ b/mod_muc_http_auth/mod_muc_http_auth.lua	Fri Dec 18 16:31:01 2020 +0100
@@ -11,6 +11,8 @@
 local insecure = module:get_option("muc_http_auth_insecure", false) --For development purposes
 local authorize_registration = module:get_option("muc_http_auth_authorize_registration", false)
 
+local verbs = {presence='join', iq='register'};
+
 local function must_be_authorized(room_node)
 	-- If none of these is set, all rooms need authorization
 	if not enabled_for and not disabled_for then return true; end
@@ -35,9 +37,7 @@
 
 local function handle_presence(event)
 	local stanza = event.stanza;
-	if stanza.name ~= "presence" or stanza.attr.type == "unavailable" then
-		return;
-	end
+	if stanza.name ~= "iq" and stanza.name ~= "presence" or stanza.attr.type == "unavailable" then return; end
 
 	local room, origin = event.room, event.origin;
 	if (not room) or (not origin) then return; end
@@ -50,15 +50,16 @@
 	local result = wait_for(http.request(url, {method="GET", insecure=insecure}):next(handle_success, handle_error));
 	local response, err = result.response, result.err;
 
+	local verb = verbs[stanza.name];
 	if not (response and response.allowed) then
 		-- User is not authorized to join this room
 		err = (response or {}).err or err
-		module:log("debug", user_bare_jid .. " is not authorized to join " .. room.jid .. " Error: " .. tostring(err));
+		module:log("debug", user_bare_jid .. " is not authorized to " ..verb.. ": " .. room.jid .. " Error: " .. tostring(err));
 		origin.send(st.error_reply(stanza, "error", "not-authorized", nil, module.host));
 		return true;
 	end
 
-	module:log("debug", user_bare_jid .. " is authorized to join " .. room.jid);
+	module:log("debug", user_bare_jid .. " is authorized to " .. verb .. ": " .. room.jid);
 	return;
 end