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