<commit_before>-- Registration Redirect module for Prosody
-- 
-- Redirects IP addresses not in the whitelist to a web page to complete the registration.

local st = require "util.stanza";

function reg_redirect(event)
	local ip_wl = module:get_option("registration_whitelist") or { "127.0.0.1" };
	local url = module:get_option("registration_url");
	local no_wl = module:get_option_boolean("no_registration_whitelist", false);
	local test_ip = false;

	if not no_wl then
		for i,ip in ipairs(ip_wl) do
			if event.origin.ip == ip then test_ip = true; end
			break;
		end
	end
	
	if not test_ip and url ~= nil or no_wl and url ~= nil then
		local reply = st.reply(event.stanza);
		reply:tag("query", {xmlns = "jabber:iq:register"})
			:tag("instructions"):text("Please visit "..url.." to register an account on this server."):up()
			:tag("x", {xmlns = "jabber:x:oob"}):up()
				:tag("url"):text(url):up();
		event.origin.send(reply);
		return true;
	end
end

module:hook("stanza/iq/jabber:iq:register:query", reg_redirect, 10);<commit_msg>mod_register_url: code refactor, clean, all the rest (thanks Zash ;))<commit_after>-- Registration Redirect module for Prosody
-- 
-- Redirects IP addresses not in the whitelist to a web page to complete the registration.

local st = require "util.stanza";

function reg_redirect(event)
	local stanza, origin = event.stanza, event.origin;
	local ip_wl = module:get_option("registration_whitelist") or { "127.0.0.1" };
	local url = module:get_option("registration_url");
	local no_wl = module:get_option_boolean("no_registration_whitelist", false);
	local test_ip = false;

	if not no_wl then
		for i,ip in ipairs(ip_wl) do
			if origin.ip == ip then test_ip = true; end
			break;
		end
	end
	
	if stanza.attr.type == "get" then
		local reply = st.reply(event.stanza);
		reply:query("jabber:iq:register")
			:tag("instructions"):text("Please visit "..url.." to register an account on this server."):up()
			:tag("x", {xmlns = "jabber:x:oob"})
				:tag("url"):text(url);
		origin.send(reply);
		return true;
	else
		origin.send(st.error_reply(stanza, "cancel", "not-authorized"))
		return true
	end
end

module:hook("stanza/iq/jabber:iq:register:query", reg_redirect, 10);
{'fraction_non_alphanumeric': 0.14027149321266968, 'fraction_numerical': 0.007239819004524887, 'mean_word_length': 4.713178294573644, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2540716', 'n_tokens_mistral': 829, 'n_tokens_neox': 761, 'n_words': 211}