view mod_muc_restrict_status/mod_muc_restrict_status.lua @ 6319:04c3273cb81f

mod_auth_cyrus: Add empty 'profile' table to SASL handler objects This is for compatibility with Prosody's built-in util.sasl objects. A SASL profile table usually includes methods supported by the backend, which can be used by SASL mechanism handlers to perform operations (such as testing the password). It also optionally contains a 'cb' field with channel binding method handlers. The Cyrus backend doesn't support channel binding, and doesn't have the same concept of auth backend methods (it handles all that internally, and Prosody has no insight or control over it). Thus, we create an empty profile which informs Prosody that the SASL handler does not support any of the auth or channel binding methods. Some features will not work, but they didn't work anyway. This just makes it explicit. This fixes a traceback in mod_sasl2_fast, which expected SASL handlers to always contain a 'profile' field.
author Matthew Wild <mwild1@gmail.com>
date Thu, 04 Sep 2025 10:14:46 +0100
parents 52bd0ac397b5
children
line wrap: on
line source

module:depends"muc";

local restrict_by_default = module:get_option_boolean("muc_room_default_restrict_status", true);

local function should_restrict_status(room)
	local restrict_status = room._data.restrict_status;
	if restrict_status == nil then
		restrict_status = restrict_by_default;
	end
	return restrict_status;
end

module:hook("muc-config-form", function(event)
	local room, form = event.room, event.form;
	table.insert(form, {
		name = "{xmpp:prosody.im}muc#roomconfig_unaffiliated_status",
		type = "boolean",
		label = "Display status message from non-members",
		value = not should_restrict_status(room),
	});
end);

module:hook("muc-config-submitted", function(event)
	local room, fields, changed = event.room, event.fields, event.changed;
	local new_restrict_status = not fields["{xmpp:prosody.im}muc#roomconfig_unaffiliated_status"];
	if new_restrict_status ~= should_restrict_status(room) then
		if new_restrict_status == restrict_by_default then
			room._data.restrict_status = nil;
		else
			room._data.restrict_status = new_restrict_status;
		end
		if type(changed) == "table" then
			changed["{xmpp:prosody.im}muc#roomconfig_unaffiliated_status"] = true;
		else
			event.changed = true;
		end
	end
end);

module:hook("muc-disco#info", function (event)
	local room, form, formdata = event.room, event.form, event.formdata;

	local allow_unaffiliated_status = not should_restrict_status(room);
	table.insert(form, {
		name = "{xmpp:prosody.im}muc#roomconfig_unaffiliated_status",
		type = "boolean",
	});
	formdata["{xmpp:prosody.im}muc#roomconfig_unaffiliated_status"] = allow_unaffiliated_status;
end);

local function filter_status_tags(tag)
	if tag.name == "status" then
		return nil;
	end
	return tag;
end

local function thehook(event)
	local stanza = event.stanza;
	if event.room:get_affiliation(stanza.attr.from) then return end
	if should_restrict_status(event.room) then
		stanza:maptags(filter_status_tags);
	end
end

module:hook("muc-occupant-pre-join", thehook, 20);
module:hook("muc-occupant-pre-leave", thehook, 20);
module:hook("muc-occupant-pre-change", thehook, 20);