Mercurial > prosody-modules
annotate mod_privacy/mod_privacy.lua @ 424:22935ef37284
mod_auth_wordpress: Rename functions to match module name
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 11 Sep 2011 21:59:01 +0200 |
parents | b07193056935 |
children |
rev | line source |
---|---|
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
1 -- Prosody IM |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
2 -- Copyright (C) 2008-2009 Matthew Wild |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
3 -- Copyright (C) 2008-2009 Waqas Hussain |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
4 -- Copyright (C) 2009 Thilo Cestonaro |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
5 -- |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
6 -- This project is MIT/X11 licensed. Please see the |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
7 -- COPYING file in the source package for more information. |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
8 -- |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
9 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
10 local prosody = prosody; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
11 local st = require "util.stanza"; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
12 local datamanager = require "util.datamanager"; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
13 local bare_sessions = bare_sessions; |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
14 local util_Jid = require "util.jid"; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
15 local jid_bare = util_Jid.bare; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
16 local jid_split = util_Jid.split; |
16
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
17 local load_roster = require "core.rostermanager".load_roster; |
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
18 local to_number = _G.tonumber; |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
19 |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
20 function findNamedList (privacy_lists, name) |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
21 local ret = nil |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
22 if privacy_lists.lists == nil then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
23 return nil; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
24 end |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
25 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
26 for i=1, #privacy_lists.lists do |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
27 if privacy_lists.lists[i].name == name then |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
28 ret = i; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
29 break; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
30 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
31 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
32 return ret; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
33 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
34 |
20
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
35 function isListUsed(origin, name, privacy_lists) |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
36 if bare_sessions[origin.username.."@"..origin.host].sessions ~= nil then |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
37 for resource, session in pairs(bare_sessions[origin.username.."@"..origin.host].sessions) do |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
38 if resource ~= origin.resource then |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
39 if session.activePrivacyList == name then |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
40 return true; |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
41 elseif session.activePrivacyList == nil and privacy_lists.default == name then |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
42 return true; |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
43 end |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
44 end |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
45 end |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
46 end |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
47 return false; |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
48 end |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
49 |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
50 function isAnotherSessionUsingDefaultList(origin) |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
51 local ret = false |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
52 if bare_sessions[origin.username.."@"..origin.host].sessions ~= nil then |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
53 for resource, session in pairs(bare_sessions[origin.username.."@"..origin.host].sessions) do |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
54 if resource ~= origin.resource and session.activePrivacyList == nil then |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
55 ret = true; |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
56 break; |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
57 end |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
58 end |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
59 end |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
60 return ret; |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
61 end |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
62 |
58
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
63 function sendUnavailable(to, from) |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
64 --[[ example unavailable presence stanza |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
65 <presence from="node@host/resource" type="unavailable" to="node@host" > |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
66 <status>Logged out</status> |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
67 </presence> |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
68 ]]-- |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
69 local presence = st.presence({from=from, type="unavailable"}) |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
70 presence:tag("status"):text("Logged out"); |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
71 |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
72 local node, host = jid_bare(to); |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
73 local bare = node .. "@" .. host; |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
74 |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
75 if bare_sessions[bare].sessions ~= nil then |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
76 for resource, session in pairs(bare_sessions[bare].sessions) do |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
77 presence.attr.to = session.full_jid; |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
78 module:log("debug", "send unavailable to: %s; from: %s", tostring(presence.attr.to), tostring(presence.attr.from)); |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
79 origin.send(presence); |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
80 end |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
81 end |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
82 end |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
83 |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
84 function sendNeededUnavailablePersences(origin, listnameOrItem) -- TODO implement it correctly! |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
85 if type(listnameOrItem) == "string" then |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
86 local listname = listnameOrItem; |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
87 for _,list in ipairs(privacy_lists.lists) do |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
88 if list.name == listname then |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
89 for _,item in ipairs(list.items) do |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
90 sendNeededUnavailablePersences(origin, item); |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
91 end |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
92 end |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
93 end |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
94 elseif type(listnameOrItem) == "table" then |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
95 module:log("debug", "got an item, check wether to send unavailable presence stanza or not"); |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
96 local item = listnameOrItem; |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
97 local serialize = require "util.serialization".serialize; |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
98 |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
99 |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
100 if item["presence-out"] == true then |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
101 if item.type == "jid" then |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
102 sendUnavailable(item.value, origin.full_jid); |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
103 elseif item.type == "group" then |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
104 elseif item.type == "subscription" then |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
105 elseif item.type == nil then |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
106 end |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
107 elseif item["presence-in"] == true then |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
108 if item.type == "jid" then |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
109 sendUnavailable(origin.full_jid, item.value); |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
110 elseif item.type == "group" then |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
111 elseif item.type == "subscription" then |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
112 elseif item.type == nil then |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
113 end |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
114 end |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
115 else |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
116 module:log("debug", "got unknown type: %s", type(listnameOrItem)); |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
117 end |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
118 end |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
119 |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
120 function declineList (privacy_lists, origin, stanza, which) |
17
ccb07c0efc7e
mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents:
16
diff
changeset
|
121 if which == "default" then |
20
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
122 if isAnotherSessionUsingDefaultList(origin) then |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
123 return { "cancel", "conflict", "Another session is online and using the default list."}; |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
124 end |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
125 privacy_lists.default = nil; |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
126 origin.send(st.reply(stanza)); |
17
ccb07c0efc7e
mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents:
16
diff
changeset
|
127 elseif which == "active" then |
ccb07c0efc7e
mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents:
16
diff
changeset
|
128 origin.activePrivacyList = nil; |
20
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
129 origin.send(st.reply(stanza)); |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
130 else |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
131 return {"modify", "bad-request", "Neither default nor active list specifed to decline."}; |
17
ccb07c0efc7e
mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents:
16
diff
changeset
|
132 end |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
133 return true; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
134 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
135 |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
136 function activateList (privacy_lists, origin, stanza, which, name) |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
137 local idx = findNamedList(privacy_lists, name); |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
138 |
20
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
139 if privacy_lists.default == nil then |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
140 privacy_lists.default = ""; |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
141 end |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
142 if origin.activePrivacyList == nil then |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
143 origin.activePrivacyList = ""; |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
144 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
145 |
20
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
146 if which == "default" and idx ~= nil then |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
147 if isAnotherSessionUsingDefaultList(origin) then |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
148 return {"cancel", "conflict", "Another session is online and using the default list."}; |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
149 end |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
150 privacy_lists.default = name; |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
151 origin.send(st.reply(stanza)); |
58
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
152 --[[ |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
153 if origin.activePrivacyList == nil then |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
154 sendNeededUnavailablePersences(origin, name); |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
155 end |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
156 ]]-- |
20
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
157 elseif which == "active" and idx ~= nil then |
17
ccb07c0efc7e
mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents:
16
diff
changeset
|
158 origin.activePrivacyList = name; |
20
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
159 origin.send(st.reply(stanza)); |
58
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
160 -- sendNeededUnavailablePersences(origin, name); |
20
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
161 else |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
162 return {"modify", "bad-request", "Either not active or default given or unknown list name specified."}; |
17
ccb07c0efc7e
mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents:
16
diff
changeset
|
163 end |
20
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
164 return true; |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
165 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
166 |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
167 function deleteList (privacy_lists, origin, stanza, name) |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
168 local idx = findNamedList(privacy_lists, name); |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
169 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
170 if idx ~= nil then |
20
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
171 if isListUsed(origin, name, privacy_lists) then |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
172 return {"cancel", "conflict", "Another session is online and using the list which should be deleted."}; |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
173 end |
27
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
174 if privacy_lists.default == name then |
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
175 privacy_lists.default = ""; |
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
176 end |
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
177 if origin.activePrivacyList == name then |
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
178 origin.activePrivacyList = ""; |
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
179 end |
20
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
180 table.remove(privacy_lists.lists, idx); |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
181 origin.send(st.reply(stanza)); |
20
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
182 return true; |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
183 end |
20
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
184 return {"modify", "bad-request", "Not existing list specifed to be deleted."}; |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
185 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
186 |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
187 local function sortByOrder(a, b) |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
188 if a.order < b.order then |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
189 return true; |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
190 end |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
191 return false; |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
192 end |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
193 |
16
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
194 function createOrReplaceList (privacy_lists, origin, stanza, name, entries, roster) |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
195 local idx = findNamedList(privacy_lists, name); |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
196 local bare_jid = origin.username.."@"..origin.host; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
197 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
198 if privacy_lists.lists == nil then |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
199 privacy_lists.lists = {}; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
200 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
201 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
202 if idx == nil then |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
203 idx = #privacy_lists.lists + 1; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
204 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
205 |
16
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
206 local orderCheck = {}; |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
207 local list = {}; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
208 list.name = name; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
209 list.items = {}; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
210 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
211 for _,item in ipairs(entries) do |
16
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
212 if to_number(item.attr.order) == nil or to_number(item.attr.order) < 0 or orderCheck[item.attr.order] ~= nil then |
20
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
213 return {"modify", "bad-request", "Order attribute not valid."}; |
16
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
214 end |
20
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
215 |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
216 if item.attr.type ~= nil and item.attr.type ~= "jid" and item.attr.type ~= "subscription" and item.attr.type ~= "group" then |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
217 return {"modify", "bad-request", "Type attribute not valid."}; |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
218 end |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
219 |
14
0892941186f2
mod_privacy: Make tmp variable a local
Matthew Wild <mwild1@gmail.com>
parents:
10
diff
changeset
|
220 local tmp = {}; |
16
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
221 orderCheck[item.attr.order] = true; |
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
222 |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
223 tmp["type"] = item.attr.type; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
224 tmp["value"] = item.attr.value; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
225 tmp["action"] = item.attr.action; |
16
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
226 tmp["order"] = to_number(item.attr.order); |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
227 tmp["presence-in"] = false; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
228 tmp["presence-out"] = false; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
229 tmp["message"] = false; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
230 tmp["iq"] = false; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
231 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
232 if #item.tags > 0 then |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
233 for _,tag in ipairs(item.tags) do |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
234 tmp[tag.name] = true; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
235 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
236 end |
16
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
237 |
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
238 if tmp.type == "group" then |
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
239 local found = false; |
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
240 local roster = load_roster(origin.username, origin.host); |
27
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
241 for jid,item in pairs(roster) do |
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
242 if item.groups ~= nil then |
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
243 for group in pairs(item.groups) do |
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
244 if group == tmp.value then |
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
245 found = true; |
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
246 break; |
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
247 end |
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
248 end |
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
249 if found == true then |
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
250 break; |
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
251 end |
16
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
252 end |
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
253 end |
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
254 if found == false then |
20
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
255 return {"cancel", "item-not-found", "Specifed roster group not existing."}; |
16
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
256 end |
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
257 elseif tmp.type == "subscription" then |
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
258 if tmp.value ~= "both" and |
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
259 tmp.value ~= "to" and |
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
260 tmp.value ~= "from" and |
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
261 tmp.value ~= "none" then |
20
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
262 return {"cancel", "bad-request", "Subscription value must be both, to, from or none."}; |
16
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
263 end |
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
264 end |
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
265 |
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
266 if tmp.action ~= "deny" and tmp.action ~= "allow" then |
20
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
267 return {"cancel", "bad-request", "Action must be either deny or allow."}; |
16
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
268 end |
35e74c1094a7
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents:
15
diff
changeset
|
269 |
58
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
270 --[[ |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
271 if (privacy_lists.default == name and origin.activePrivacyList == nil) or origin.activePrivacyList == name then |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
272 module:log("debug", "calling sendNeededUnavailablePresences!"); |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
273 -- item is valid and list is active, so send needed unavailable stanzas |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
274 sendNeededUnavailablePersences(origin, tmp); |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
275 end |
b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
Thilo Cestonaro <thilo@cestona.ro>
parents:
46
diff
changeset
|
276 ]]-- |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
277 list.items[#list.items + 1] = tmp; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
278 end |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
279 |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
280 table.sort(list, sortByOrder); |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
281 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
282 privacy_lists.lists[idx] = list; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
283 origin.send(st.reply(stanza)); |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
284 if bare_sessions[bare_jid] ~= nil then |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
285 iq = st.iq ( { type = "set", id="push1" } ); |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
286 iq:tag ("query", { xmlns = "jabber:iq:privacy" } ); |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
287 iq:tag ("list", { name = list.name } ):up(); |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
288 iq:up(); |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
289 for resource, session in pairs(bare_sessions[bare_jid].sessions) do |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
290 iq.attr.to = bare_jid.."/"..resource |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
291 session.send(iq); |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
292 end |
20
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
293 else |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
294 return {"cancel", "bad-request", "internal error."}; |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
295 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
296 return true; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
297 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
298 |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
299 function getList(privacy_lists, origin, stanza, name) |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
300 local reply = st.reply(stanza); |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
301 reply:tag("query", {xmlns="jabber:iq:privacy"}); |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
302 |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
303 if name == nil then |
17
ccb07c0efc7e
mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents:
16
diff
changeset
|
304 reply:tag("active", {name=origin.activePrivacyList or ""}):up(); |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
305 reply:tag("default", {name=privacy_lists.default or ""}):up(); |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
306 if privacy_lists.lists then |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
307 for _,list in ipairs(privacy_lists.lists) do |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
308 reply:tag("list", {name=list.name}):up(); |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
309 end |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
310 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
311 else |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
312 local idx = findNamedList(privacy_lists, name); |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
313 if idx ~= nil then |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
314 list = privacy_lists.lists[idx]; |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
315 reply = reply:tag("list", {name=list.name}); |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
316 for _,item in ipairs(list.items) do |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
317 reply:tag("item", {type=item.type, value=item.value, action=item.action, order=item.order}); |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
318 if item["message"] then reply:tag("message"):up(); end |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
319 if item["iq"] then reply:tag("iq"):up(); end |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
320 if item["presence-in"] then reply:tag("presence-in"):up(); end |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
321 if item["presence-out"] then reply:tag("presence-out"):up(); end |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
322 reply:up(); |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
323 end |
20
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
324 else |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
325 return {"cancel", "item-not-found", "Unknown list specified."}; |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
326 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
327 end |
20
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
328 |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
329 origin.send(reply); |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
330 return true; |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
331 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
332 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
333 module:hook("iq/bare/jabber:iq:privacy:query", function(data) |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
334 local origin, stanza = data.origin, data.stanza; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
335 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
336 if stanza.attr.to == nil then -- only service requests to own bare JID |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
337 local query = stanza.tags[1]; -- the query element |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
338 local valid = false; |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
339 local privacy_lists = datamanager.load(origin.username, origin.host, "privacy") or {}; |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
340 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
341 if stanza.attr.type == "set" then |
17
ccb07c0efc7e
mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents:
16
diff
changeset
|
342 if #query.tags == 1 then -- the <query/> element MUST NOT include more than one child element |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
343 for _,tag in ipairs(query.tags) do |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
344 if tag.name == "active" or tag.name == "default" then |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
345 if tag.attr.name == nil then -- Client declines the use of active / default list |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
346 valid = declineList(privacy_lists, origin, stanza, tag.name); |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
347 else -- Client requests change of active / default list |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
348 valid = activateList(privacy_lists, origin, stanza, tag.name, tag.attr.name); |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
349 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
350 elseif tag.name == "list" and tag.attr.name then -- Client adds / edits a privacy list |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
351 if #tag.tags == 0 then -- Client removes a privacy list |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
352 valid = deleteList(privacy_lists, origin, stanza, tag.attr.name); |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
353 else -- Client edits a privacy list |
42
bbb3d3a90a70
mod_privacy: decrease the log messages count.
Thilo Cestonaro <thilo@cestona.ro>
parents:
41
diff
changeset
|
354 valid = createOrReplaceList(privacy_lists, origin, stanza, tag.attr.name, tag.tags); |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
355 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
356 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
357 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
358 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
359 elseif stanza.attr.type == "get" then |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
360 local name = nil; |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
361 local listsToRetrieve = 0; |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
362 if #query.tags >= 1 then |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
363 for _,tag in ipairs(query.tags) do |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
364 if tag.name == "list" then -- Client requests a privacy list from server |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
365 name = tag.attr.name; |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
366 listsToRetrieve = listsToRetrieve + 1; |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
367 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
368 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
369 end |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
370 if listsToRetrieve == 0 or listsToRetrieve == 1 then |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
371 valid = getList(privacy_lists, origin, stanza, name); |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
372 end |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
373 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
374 |
20
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
375 if valid ~= true then |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
376 if valid[0] == nil then |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
377 valid[0] = "cancel"; |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
378 end |
20
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
379 if valid[1] == nil then |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
380 valid[1] = "bad-request"; |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
381 end |
2675dc25445b
mod_privacy: overworked error returns while creating, editing, deleting or de/activating lists.
Thilo Cestonaro <thilo@cestona.ro>
parents:
19
diff
changeset
|
382 origin.send(st.error_reply(stanza, valid[0], valid[1], valid[2])); |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
383 else |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
384 datamanager.store(origin.username, origin.host, "privacy", privacy_lists); |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
385 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
386 return true; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
387 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
388 return false; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
389 end, 500); |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
390 |
17
ccb07c0efc7e
mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents:
16
diff
changeset
|
391 function checkIfNeedToBeBlocked(e, session) |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
392 local origin, stanza = e.origin, e.stanza; |
17
ccb07c0efc7e
mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents:
16
diff
changeset
|
393 local privacy_lists = datamanager.load(session.username, session.host, "privacy") or {}; |
ccb07c0efc7e
mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents:
16
diff
changeset
|
394 local bare_jid = session.username.."@"..session.host; |
39
b84b2b026eb4
mod_privacy: never block communications from one of a user's resources to another.
Thilo Cestonaro <thilo@cestona.ro>
parents:
27
diff
changeset
|
395 |
46
ea756d96584f
mod_privacy: nicer debug logging ...
Thilo Cestonaro <thilo@cestona.ro>
parents:
45
diff
changeset
|
396 module:log("debug", "stanza: %s, to: %s, from: %s", tostring(stanza.name), tostring(stanza.attr.to), tostring(stanza.attr.from)); |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
397 |
27
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
398 if stanza.attr.to ~= nil and stanza.attr.from ~= nil then |
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
399 if privacy_lists.lists == nil or |
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
400 (session.activePrivacyList == nil or session.activePrivacyList == "") and |
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
401 (privacy_lists.default == nil or privacy_lists.default == "") |
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
402 then |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
403 return; -- Nothing to block, default is Allow all |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
404 end |
39
b84b2b026eb4
mod_privacy: never block communications from one of a user's resources to another.
Thilo Cestonaro <thilo@cestona.ro>
parents:
27
diff
changeset
|
405 if jid_bare(stanza.attr.from) == bare_jid and jid_bare(stanza.attr.to) == bare_jid then |
b84b2b026eb4
mod_privacy: never block communications from one of a user's resources to another.
Thilo Cestonaro <thilo@cestona.ro>
parents:
27
diff
changeset
|
406 module:log("debug", "Never block communications from one of a user's resources to another."); |
b84b2b026eb4
mod_privacy: never block communications from one of a user's resources to another.
Thilo Cestonaro <thilo@cestona.ro>
parents:
27
diff
changeset
|
407 return; -- from one of a user's resource to another => HANDS OFF! |
b84b2b026eb4
mod_privacy: never block communications from one of a user's resources to another.
Thilo Cestonaro <thilo@cestona.ro>
parents:
27
diff
changeset
|
408 end |
41
0381d5d38c37
mod_privacy: fix bug where priority was nil and compared to a number (Thx flo for reporting!)
Thilo Cestonaro <thilo@cestona.ro>
parents:
39
diff
changeset
|
409 |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
410 local idx; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
411 local list; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
412 local item; |
17
ccb07c0efc7e
mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents:
16
diff
changeset
|
413 local listname = session.activePrivacyList; |
27
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
414 if listname == nil or listname == "" then |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
415 listname = privacy_lists.default; -- no active list selected, use default list |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
416 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
417 idx = findNamedList(privacy_lists, listname); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
418 if idx == nil then |
27
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
419 module:log("error", "given privacy listname not found. name: %s", listname); |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
420 return; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
421 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
422 list = privacy_lists.lists[idx]; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
423 if list == nil then |
27
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
424 module:log("info", "privacy list index wrong. index: %d", idx); |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
425 return; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
426 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
427 for _,item in ipairs(list.items) do |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
428 local apply = false; |
17
ccb07c0efc7e
mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents:
16
diff
changeset
|
429 local block = false; |
42
bbb3d3a90a70
mod_privacy: decrease the log messages count.
Thilo Cestonaro <thilo@cestona.ro>
parents:
41
diff
changeset
|
430 if ( |
bbb3d3a90a70
mod_privacy: decrease the log messages count.
Thilo Cestonaro <thilo@cestona.ro>
parents:
41
diff
changeset
|
431 (stanza.name == "message" and item.message) or |
bbb3d3a90a70
mod_privacy: decrease the log messages count.
Thilo Cestonaro <thilo@cestona.ro>
parents:
41
diff
changeset
|
432 (stanza.name == "iq" and item.iq) or |
bbb3d3a90a70
mod_privacy: decrease the log messages count.
Thilo Cestonaro <thilo@cestona.ro>
parents:
41
diff
changeset
|
433 (stanza.name == "presence" and jid_bare(stanza.attr.to) == bare_jid and item["presence-in"]) or |
bbb3d3a90a70
mod_privacy: decrease the log messages count.
Thilo Cestonaro <thilo@cestona.ro>
parents:
41
diff
changeset
|
434 (stanza.name == "presence" and jid_bare(stanza.attr.from) == bare_jid and item["presence-out"]) or |
bbb3d3a90a70
mod_privacy: decrease the log messages count.
Thilo Cestonaro <thilo@cestona.ro>
parents:
41
diff
changeset
|
435 (item.message == false and item.iq == false and item["presence-in"] == false and item["presence-in"] == false) |
bbb3d3a90a70
mod_privacy: decrease the log messages count.
Thilo Cestonaro <thilo@cestona.ro>
parents:
41
diff
changeset
|
436 ) then |
17
ccb07c0efc7e
mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents:
16
diff
changeset
|
437 apply = true; |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
438 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
439 if apply then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
440 local evilJid = {}; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
441 apply = false; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
442 if jid_bare(stanza.attr.to) == bare_jid then |
27
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
443 module:log("debug", "evil jid is (from): %s", stanza.attr.from); |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
444 evilJid.node, evilJid.host, evilJid.resource = jid_split(stanza.attr.from); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
445 else |
27
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
446 module:log("debug", "evil jid is (to): %s", stanza.attr.to); |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
447 evilJid.node, evilJid.host, evilJid.resource = jid_split(stanza.attr.to); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
448 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
449 if item.type == "jid" and |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
450 (evilJid.node and evilJid.host and evilJid.resource and item.value == evilJid.node.."@"..evilJid.host.."/"..evilJid.resource) or |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
451 (evilJid.node and evilJid.host and item.value == evilJid.node.."@"..evilJid.host) or |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
452 (evilJid.host and evilJid.resource and item.value == evilJid.host.."/"..evilJid.resource) or |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
453 (evilJid.host and item.value == evilJid.host) then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
454 apply = true; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
455 block = (item.action == "deny"); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
456 elseif item.type == "group" then |
17
ccb07c0efc7e
mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents:
16
diff
changeset
|
457 local roster = load_roster(session.username, session.host); |
27
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
458 local groups = roster[evilJid.node .. "@" .. evilJid.host].groups; |
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
459 for group in pairs(groups) do |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
460 if group == item.value then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
461 apply = true; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
462 block = (item.action == "deny"); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
463 break; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
464 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
465 end |
27
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
466 elseif item.type == "subscription" and evilJid.node ~= nil and evilJid.host ~= nil then -- we need a valid bare evil jid |
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
467 local roster = load_roster(session.username, session.host); |
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
468 if roster[evilJid.node .. "@" .. evilJid.host].subscription == item.value then |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
469 apply = true; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
470 block = (item.action == "deny"); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
471 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
472 elseif item.type == nil then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
473 apply = true; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
474 block = (item.action == "deny"); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
475 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
476 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
477 if apply then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
478 if block then |
46
ea756d96584f
mod_privacy: nicer debug logging ...
Thilo Cestonaro <thilo@cestona.ro>
parents:
45
diff
changeset
|
479 module:log("info", "stanza blocked: %s, to: %s, from: %s", tostring(stanza.name), tostring(stanza.attr.to), tostring(stanza.attr.from)); |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
480 if stanza.name == "message" then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
481 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
482 elseif stanza.name == "iq" and (stanza.attr.type == "get" or stanza.attr.type == "set") then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
483 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
484 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
485 return true; -- stanza blocked ! |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
486 else |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
487 module:log("info", "stanza explicit allowed!") |
27
d91cb13ef0ee
mod_privacy: make the block function work; retrieve the roster groups correctly
Thilo Cestonaro <thilo@cestona.ro>
parents:
20
diff
changeset
|
488 return; |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
489 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
490 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
491 end |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
492 end |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
493 return; |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
494 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
495 |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
496 function preCheckIncoming(e) |
17
ccb07c0efc7e
mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents:
16
diff
changeset
|
497 local session; |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
498 if e.stanza.attr.to ~= nil then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
499 local node, host, resource = jid_split(e.stanza.attr.to); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
500 if node == nil or host == nil then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
501 return; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
502 end |
17
ccb07c0efc7e
mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents:
16
diff
changeset
|
503 if resource == nil then |
ccb07c0efc7e
mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents:
16
diff
changeset
|
504 local prio = 0; |
ccb07c0efc7e
mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents:
16
diff
changeset
|
505 local session_; |
18
2df11ec081fe
mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents:
17
diff
changeset
|
506 if bare_sessions[node.."@"..host] ~= nil then |
2df11ec081fe
mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents:
17
diff
changeset
|
507 for resource, session_ in pairs(bare_sessions[node.."@"..host].sessions) do |
41
0381d5d38c37
mod_privacy: fix bug where priority was nil and compared to a number (Thx flo for reporting!)
Thilo Cestonaro <thilo@cestona.ro>
parents:
39
diff
changeset
|
508 if session_.priority ~= nil and session_.priority > prio then |
18
2df11ec081fe
mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents:
17
diff
changeset
|
509 session = session_; |
2df11ec081fe
mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents:
17
diff
changeset
|
510 prio = session_.priority; |
2df11ec081fe
mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents:
17
diff
changeset
|
511 end |
17
ccb07c0efc7e
mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents:
16
diff
changeset
|
512 end |
ccb07c0efc7e
mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents:
16
diff
changeset
|
513 end |
ccb07c0efc7e
mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents:
16
diff
changeset
|
514 else |
ccb07c0efc7e
mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents:
16
diff
changeset
|
515 session = full_sessions[node.."@"..host.."/"..resource]; |
ccb07c0efc7e
mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents:
16
diff
changeset
|
516 end |
18
2df11ec081fe
mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents:
17
diff
changeset
|
517 if session ~= nil then |
2df11ec081fe
mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents:
17
diff
changeset
|
518 return checkIfNeedToBeBlocked(e, session); |
2df11ec081fe
mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents:
17
diff
changeset
|
519 else |
46
ea756d96584f
mod_privacy: nicer debug logging ...
Thilo Cestonaro <thilo@cestona.ro>
parents:
45
diff
changeset
|
520 module:log("debug", "preCheckIncoming: Couldn't get session for jid: %s@%s/%s", tostring(node), tostring(host), tostring(resource)) |
18
2df11ec081fe
mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents:
17
diff
changeset
|
521 end |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
522 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
523 return; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
524 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
525 |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
526 function preCheckOutgoing(e) |
39
b84b2b026eb4
mod_privacy: never block communications from one of a user's resources to another.
Thilo Cestonaro <thilo@cestona.ro>
parents:
27
diff
changeset
|
527 local session = e.origin; |
b84b2b026eb4
mod_privacy: never block communications from one of a user's resources to another.
Thilo Cestonaro <thilo@cestona.ro>
parents:
27
diff
changeset
|
528 if e.stanza.attr.from == nil then |
45
3f5bbd7c90d4
mod_privacy: it says "from" not "form" (thx flo for reporting!)
Thilo Cestonaro <thilo@cestona.ro>
parents:
42
diff
changeset
|
529 e.stanza.attr.from = session.username .. "@" .. session.host; |
39
b84b2b026eb4
mod_privacy: never block communications from one of a user's resources to another.
Thilo Cestonaro <thilo@cestona.ro>
parents:
27
diff
changeset
|
530 if session.resource ~= nil then |
45
3f5bbd7c90d4
mod_privacy: it says "from" not "form" (thx flo for reporting!)
Thilo Cestonaro <thilo@cestona.ro>
parents:
42
diff
changeset
|
531 e.stanza.attr.from = e.stanza.attr.from .. "/" .. session.resource; |
18
2df11ec081fe
mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents:
17
diff
changeset
|
532 end |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
533 end |
39
b84b2b026eb4
mod_privacy: never block communications from one of a user's resources to another.
Thilo Cestonaro <thilo@cestona.ro>
parents:
27
diff
changeset
|
534 return checkIfNeedToBeBlocked(e, session); |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
535 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
536 |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
537 |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
538 module:hook("pre-message/full", preCheckOutgoing, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
539 module:hook("pre-message/bare", preCheckOutgoing, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
540 module:hook("pre-message/host", preCheckOutgoing, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
541 module:hook("pre-iq/full", preCheckOutgoing, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
542 module:hook("pre-iq/bare", preCheckOutgoing, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
543 module:hook("pre-iq/host", preCheckOutgoing, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
544 module:hook("pre-presence/full", preCheckOutgoing, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
545 module:hook("pre-presence/bare", preCheckOutgoing, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
546 module:hook("pre-presence/host", preCheckOutgoing, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
547 |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
548 module:hook("message/full", preCheckIncoming, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
549 module:hook("message/bare", preCheckIncoming, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
550 module:hook("message/host", preCheckIncoming, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
551 module:hook("iq/full", preCheckIncoming, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
552 module:hook("iq/bare", preCheckIncoming, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
553 module:hook("iq/host", preCheckIncoming, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
554 module:hook("presence/full", preCheckIncoming, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
555 module:hook("presence/bare", preCheckIncoming, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
556 module:hook("presence/host", preCheckIncoming, 500); |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
557 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
558 module:log("info", "mod_privacy loaded ..."); |