view mod_ipcheck/mod_ipcheck.lua @ 890:7ac1b8a799be

mod_carbons_adhoc: Initial commit. This module will add an Adhoc-command by which a user can see if Message Carbons (XEP-0280) are generated for his clients and also which version is used for the individual client. Clients which receive copies as per mod_carbons_copies will be listed as Version 0 carbons.
author Michael Holzt <kju@fqdn.org>
date Sun, 23 Dec 2012 19:36:31 +0100
parents 0525c66e7d13
children d1bc9a796daf
line wrap: on
line source


-- mod_ipcheck.lua
-- Implementation of XEP-0279: Server IP Check <http://xmpp.org/extensions/xep-0279.html>

local st = require "util.stanza";

module:add_feature("urn:xmpp:sic:0");

module:hook("iq/bare/urn:xmpp:sic:0:ip", function(event)
	local origin, stanza = event.origin, event.stanza;
	if stanza.attr.type == "get" then
		if stanza.attr.to then
			origin.send(st.error_reply(stanza, "auth", "forbidden", "You can only ask about your own IP address"));
		elseif origin.ip then
			origin.send(st.reply(stanza):tag("ip", {xmlns='urn:xmpp:sic:0'}):text(origin.ip));
		else
			-- IP addresses should normally be available, but in case they are not
			origin.send(st.error_reply(stanza, "cancel", "service-unavailable", "IP address for this session is not available"));
		end
		return true;
	end
end);