comparison mod_muc_ban_ip/mod_muc_ban_ip.lua @ 3403:823027110e29

mod_muc_ban_ip: Improve logging to use session, and log when a ban is enforced
author Matthew Wild <mwild1@gmail.com>
date Thu, 13 Dec 2018 10:35:26 +0000
parents 933403ee07ec
children 4c9805f29f2d
comparison
equal deleted inserted replaced
3402:6a3060d5e85d 3403:823027110e29
17 if not banned_from then 17 if not banned_from then
18 banned_from = {}; 18 banned_from = {};
19 ip_bans[ip] = banned_from; 19 ip_bans[ip] = banned_from;
20 end 20 end
21 banned_from[from] = true; 21 banned_from[from] = true;
22 module:log("debug", "Banned IP address %s from %s", ip, from); 22 module:log("debug", "Added ban for IP address %s from %s", ip, from);
23 end 23 end
24 24
25 local function check_for_incoming_ban(event) 25 local function check_for_incoming_ban(event)
26 local stanza = event.stanza; 26 local stanza = event.stanza;
27 local to_session = full_sessions[stanza.attr.to]; 27 local to_session = full_sessions[stanza.attr.to];
41 end 41 end
42 end 42 end
43 end 43 end
44 44
45 local function check_for_ban(event) 45 local function check_for_ban(event)
46 local ip = event.origin.ip; 46 local origin, stanza = event.origin, event.stanza;
47 local to = jid_bare(event.stanza.attr.to); 47 local ip = origin.ip;
48 local to = jid_bare(stanza.attr.to);
48 if ip_bans[ip] and ip_bans[ip][to] then 49 if ip_bans[ip] and ip_bans[ip][to] then
49 event.origin.send(st.error_reply(event.stanza, "auth", "forbidden") 50 origin.log("debug", "IP banned: %s is banned from %s", ip, to)
51 origin.send(st.error_reply(stanza, "auth", "forbidden")
50 :tag("x", { xmlns = xmlns_muc_user }) 52 :tag("x", { xmlns = xmlns_muc_user })
51 :tag("status", { code = '301' })); 53 :tag("status", { code = '301' }));
52 return true; 54 return true;
53 end 55 end
54 module:log("debug", "Not banned: %s from %s", ip, to) 56 origin.log("debug", "IP not banned: %s from %s", ip, to)
55 end 57 end
56 58
57 function module.add_host(module) 59 function module.add_host(module)
58 module:hook("presence/full", check_for_incoming_ban, 100); 60 module:hook("presence/full", check_for_incoming_ban, 100);
59 module:hook("pre-presence/full", check_for_ban, 100); 61 module:hook("pre-presence/full", check_for_ban, 100);