changeset 2860:a7c2df6b2662

mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
author Daniel Gultsch <daniel@gultsch.de>
date Wed, 03 Jan 2018 15:19:55 +0100
parents 22e11645a895
children afeb06e4cdea
files mod_register_oob_url/README.markdown mod_register_oob_url/mod_register_oob_url.lua
diffstat 2 files changed, 77 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_register_oob_url/README.markdown	Wed Jan 03 15:19:55 2018 +0100
@@ -0,0 +1,29 @@
+---
+labels:
+- 'Stage-Alpha'
+summary: 'XEP-077 IBR registration URL redirect'
+---
+
+Introduction
+============
+
+Registration redirect to out of band URL as described in  [XEP-0077: In-Band Registration](http://xmpp.org/extensions/xep-0077.html#redirect).
+
+Details
+=======
+
+The already existing module `mod_register_redirect` doesn’t add a stream feature advertising its capabilities  and thus doesn’t work with clients like Conversations.
+
+This module tries to take a simpler and more straight forward approach for admins who just want to redirect to an URL and do not need the features provided by `mod_register_redirect`.
+
+Usage
+=====
+
+Set `allow_registration` to `false` and point `register_oob_url` to the URL that handles your registration.
+
+Compatibility
+=============
+
+  ----- -----------------------------------------------------------------------------
+  0.10  Works
+  ----- -----------------------------------------------------------------------------
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_register_oob_url/mod_register_oob_url.lua	Wed Jan 03 15:19:55 2018 +0100
@@ -0,0 +1,48 @@
+-- Register via OOB URL
+-- Copyright (c) 2018 Daniel Gultsch
+--
+-- This module is MIT/X11 licensed
+--
+
+local st = require "util.stanza";
+local namespace = "http://jabber.org/features/iq-register"
+local register_stream_feature = st.stanza("register", {xmlns=namespace}):up();
+local allow_registration = module:get_option_boolean("allow_registration", false);
+local registration_url = module:get_option_string("register_oob_url", nil)
+
+if allow_registration then
+	module:log("info","obb registration is disabled as long as IBR is allowed. Set `allow_registration` to false")
+end
+
+if not registration_url then
+	module:log("info","registration url not configured. Add `register_oob_url` to prosody.cfg")
+end
+
+local function on_stream_features(event)
+	if not registration_url then
+		return
+	end
+	local session, features = event.origin, event.features;
+	if session.type == "c2s_unauthed" and not allow_registration then
+		features:add_child(register_stream_feature);
+	end
+end
+
+local function on_registration_requested(event)
+	local session, stanza = event.origin, event.stanza
+	if session.type ~= "c2s_unauthed" or stanza.attr.type ~= "get" then
+		return
+	end
+	if not allow_registration and registration_url then
+		local reply = st.reply(stanza)
+		reply:query("jabber:iq:register")
+			:tag("x", {xmlns = "jabber:x:oob"})
+				:tag("url"):text(registration_url);
+		return session.send(reply)
+	end
+end
+
+module:hook("stream-features", on_stream_features)
+module:hook("stanza/iq/jabber:iq:register:query", on_registration_requested, 1)
+
+-- vim: noexpandtab tabstop=4 shiftwidth=4