comparison mod_poke_strangers/mod_poke_strangers.lua @ 2044:06faf7a149e3

mod_poke_strangers: Log details about JIDs that look like they are spamming.
author Thijs Alkemade <me@thijsalkema.de>
date Fri, 05 Feb 2016 11:23:13 +0100
parents
children 0aa8aa6cdb1b
comparison
equal deleted inserted replaced
2043:4ad3f25ab004 2044:06faf7a149e3
1 local st = require"util.stanza";
2 local jid_split = require "util.jid".split;
3 local jid_bare = require "util.jid".bare;
4 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed;
5 local uuid_generate = require "util.uuid".generate;
6 local set = require "util.set";
7
8 local recently_queried = set.new();
9
10 function check_subscribed(event)
11 local stanza = event.stanza;
12 local local_user_jid = stanza.attr.to;
13 local to_user, to_host, to_resource = jid_split(local_user_jid);
14 local stranger_jid = stanza.attr.from;
15
16 if recently_queried:contains(stranger_jid) then
17 module:log("debug", "Not re-poking " .. stranger_jid);
18 return nil;
19 end
20
21 local from_jid = jid_bare(stranger_jid);
22
23 if to_user and not is_contact_subscribed(to_user, to_host, from_jid) then
24 if to_resource and stanza.attr.type == "groupchat" then
25 return nil;
26 end
27
28 recently_queried:add(stranger_jid);
29
30 local version_id = uuid_generate();
31
32 module:hook("iq-result/host/" .. version_id, function (event)
33 module:log("info", "Stranger " .. stranger_jid .. " version: " .. tostring(event.stanza));
34 return true;
35 end);
36
37 module:send(st.iq({ type = "get", to = stranger_jid, from = to_host, id = version_id }):query("jabber:iq:version"));
38
39
40 local disco_id = uuid_generate();
41
42 module:hook("iq-result/host/" .. disco_id, function (event)
43 module:log("info", "Stranger " .. stranger_jid .. " disco: " .. tostring(event.stanza));
44 return true;
45 end);
46
47 module:send(st.iq({ type = "get", to = stranger_jid, from = to_host, id = disco_id }):query("http://jabber.org/protocol/disco#info"));
48 end
49
50 return nil;
51 end
52
53 module:hook("message/bare", check_subscribed, 225);
54 module:hook("message/full", check_subscribed, 225);
55 -- Not hooking iqs, as that could turn into infinite loops!