Software /
code /
prosody
Comparison
plugins/mod_privacy.lua @ 3085:cf01b0725272
mod_privacy: Improved logging.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sat, 22 May 2010 03:54:50 +0500 |
parent | 3069:c3df9053e0a9 |
child | 3221:01da55cffcfb |
child | 3300:b651f8290e27 |
comparison
equal
deleted
inserted
replaced
3084:9b17449fb5f4 | 3085:cf01b0725272 |
---|---|
305 local from = stanza.attr.from; | 305 local from = stanza.attr.from; |
306 | 306 |
307 local is_to_user = bare_jid == jid_bare(to); | 307 local is_to_user = bare_jid == jid_bare(to); |
308 local is_from_user = bare_jid == jid_bare(from); | 308 local is_from_user = bare_jid == jid_bare(from); |
309 | 309 |
310 module:log("debug", "stanza: %s, to: %s, from: %s", tostring(stanza.name), tostring(to), tostring(from)); | 310 --module:log("debug", "stanza: %s, to: %s, from: %s", tostring(stanza.name), tostring(to), tostring(from)); |
311 | 311 |
312 if privacy_lists.lists == nil or | 312 if privacy_lists.lists == nil or |
313 not (session.activePrivacyList or privacy_lists.default) | 313 not (session.activePrivacyList or privacy_lists.default) |
314 then | 314 then |
315 return; -- Nothing to block, default is Allow all | 315 return; -- Nothing to block, default is Allow all |
316 end | 316 end |
317 if is_from_user and is_to_user then | 317 if is_from_user and is_to_user then |
318 module:log("debug", "Not blocking communications between user's resources"); | 318 --module:log("debug", "Not blocking communications between user's resources"); |
319 return; -- from one of a user's resource to another => HANDS OFF! | 319 return; -- from one of a user's resource to another => HANDS OFF! |
320 end | 320 end |
321 | 321 |
322 local item; | 322 local item; |
323 local listname = session.activePrivacyList; | 323 local listname = session.activePrivacyList; |
324 if listname == nil then | 324 if listname == nil then |
325 listname = privacy_lists.default; -- no active list selected, use default list | 325 listname = privacy_lists.default; -- no active list selected, use default list |
326 end | 326 end |
327 local list = privacy_lists.lists[listname]; | 327 local list = privacy_lists.lists[listname]; |
328 if not list then | 328 if not list then -- should never happen |
329 module:log("debug", "given privacy list not found. name: %s", listname); | 329 module:log("warn", "given privacy list not found. name: %s for user %s", listname, bare_jid); |
330 return; | 330 return; |
331 end | 331 end |
332 for _,item in ipairs(list.items) do | 332 for _,item in ipairs(list.items) do |
333 local apply = false; | 333 local apply = false; |
334 local block = false; | 334 local block = false; |
343 end | 343 end |
344 if apply then | 344 if apply then |
345 local evilJid = {}; | 345 local evilJid = {}; |
346 apply = false; | 346 apply = false; |
347 if is_to_user then | 347 if is_to_user then |
348 module:log("debug", "evil jid is (from): %s", from); | 348 --module:log("debug", "evil jid is (from): %s", from); |
349 evilJid.node, evilJid.host, evilJid.resource = jid_split(from); | 349 evilJid.node, evilJid.host, evilJid.resource = jid_split(from); |
350 else | 350 else |
351 module:log("debug", "evil jid is (to): %s", to); | 351 --module:log("debug", "evil jid is (to): %s", to); |
352 evilJid.node, evilJid.host, evilJid.resource = jid_split(to); | 352 evilJid.node, evilJid.host, evilJid.resource = jid_split(to); |
353 end | 353 end |
354 if item.type == "jid" and | 354 if item.type == "jid" and |
355 (evilJid.node and evilJid.host and evilJid.resource and item.value == evilJid.node.."@"..evilJid.host.."/"..evilJid.resource) or | 355 (evilJid.node and evilJid.host and evilJid.resource and item.value == evilJid.node.."@"..evilJid.host.."/"..evilJid.resource) or |
356 (evilJid.node and evilJid.host and item.value == evilJid.node.."@"..evilJid.host) or | 356 (evilJid.node and evilJid.host and item.value == evilJid.node.."@"..evilJid.host) or |
392 elseif stanza.name == "iq" and (stanza.attr.type == "get" or stanza.attr.type == "set") then | 392 elseif stanza.name == "iq" and (stanza.attr.type == "get" or stanza.attr.type == "set") then |
393 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); | 393 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
394 end | 394 end |
395 return true; -- stanza blocked ! | 395 return true; -- stanza blocked ! |
396 else | 396 else |
397 module:log("debug", "stanza explicitly allowed!") | 397 --module:log("debug", "stanza explicitly allowed!") |
398 return; | 398 return; |
399 end | 399 end |
400 end | 400 end |
401 end | 401 end |
402 end | 402 end |
423 session = full_sessions[node.."@"..host.."/"..resource]; | 423 session = full_sessions[node.."@"..host.."/"..resource]; |
424 end | 424 end |
425 if session ~= nil then | 425 if session ~= nil then |
426 return checkIfNeedToBeBlocked(e, session); | 426 return checkIfNeedToBeBlocked(e, session); |
427 else | 427 else |
428 module:log("debug", "preCheckIncoming: Couldn't get session for jid: %s@%s/%s", tostring(node), tostring(host), tostring(resource)); | 428 --module:log("debug", "preCheckIncoming: Couldn't get session for jid: %s@%s/%s", tostring(node), tostring(host), tostring(resource)); |
429 end | 429 end |
430 end | 430 end |
431 end | 431 end |
432 | 432 |
433 function preCheckOutgoing(e) | 433 function preCheckOutgoing(e) |