--- a/mod_ipcheck/mod_ipcheck.lua Mon Dec 02 03:08:17 2013 +0000
+++ b/mod_ipcheck/mod_ipcheck.lua Wed Dec 04 17:37:32 2013 +0100
@@ -20,3 +20,25 @@
return true;
end
end);
+
+module:add_feature("urn:xmpp:sic:1");
+
+module:hook("iq/bare/urn:xmpp:sic:1:address", 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
+ local reply = st.reply(stanza):tag("address", {xmlns='urn:xmpp:sic:0'})
+ :tag("ip"):text(origin.ip):up()
+ if origin.conn and origin.conn.port then
+ reply:tag("port"):text(tostring(origin.conn:port()))
+ end
+ origin.send(reply);
+ 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);