Mercurial > prosody-modules
annotate mod_privacy/mod_privacy.lua @ 15:14b18ef8b554
merge with repos
author | Thilo Cestonaro <thilo@cestona.ro> |
---|---|
date | Sat, 26 Sep 2009 22:30:33 +0200 |
parents | 529819205379 0892941186f2 |
children | 35e74c1094a7 |
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 helpers = require "util/helpers"; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
12 local st = require "util.stanza"; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
13 local datamanager = require "util.datamanager"; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
14 local bare_sessions = bare_sessions; |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
15 local util_Jid = require "util.jid"; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
16 local jid_bare = util_Jid.bare; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
17 local jid_split = util_Jid.split; |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
18 |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
19 function findNamedList (privacy_lists, name) |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
20 local ret = nil |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
21 if privacy_lists.lists == nil then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
22 module:log("debug", "no lists loaded.") |
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 |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
26 module:log("debug", "searching for list: %s", name); |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
27 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
|
28 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
|
29 ret = i; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
30 break; |
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 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
33 return ret; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
34 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
35 |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
36 function declineList (privacy_lists, origin, stanza, which) |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
37 module:log("info", "User requests to decline the use of privacy list: %s", which); |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
38 privacy_lists[which] = nil; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
39 origin.send(st.reply(stanza)); |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
40 return true; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
41 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
42 |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
43 function activateList (privacy_lists, origin, stanza, which, name) |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
44 module:log("info", "User requests to change the privacy list: %s, to be list named %s", which, name); |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
45 local ret = false; |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
46 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
|
47 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
48 if privacy_lists[which] == nil then |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
49 privacy_lists[which] = ""; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
50 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
51 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
52 if privacy_lists[which] ~= name and idx ~= nil then |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
53 privacy_lists[which] = name; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
54 origin.send(st.reply(stanza)); |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
55 ret = true; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
56 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
57 return ret; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
58 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
59 |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
60 function deleteList (privacy_lists, origin, stanza, name) |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
61 module:log("info", "User requests to delete privacy list: %s", name); |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
62 local ret = false; |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
63 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
|
64 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
65 if idx ~= nil then |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
66 table.remove(privacy_lists.lists, idx); |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
67 origin.send(st.reply(stanza)); |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
68 ret = true; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
69 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
70 return ret; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
71 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
72 |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
73 local function sortByOrder(a, b) |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
74 if a.order < b.order then |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
75 return true; |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
76 end |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
77 return false; |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
78 end |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
79 |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
80 function createOrReplaceList (privacy_lists, origin, stanza, name, entries) |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
81 module:log("info", "User requests to create / replace list named %s, item count: %d", name, #entries); |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
82 local ret = true; |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
83 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
|
84 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
|
85 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
86 if privacy_lists.lists == nil then |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
87 privacy_lists.lists = {}; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
88 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
89 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
90 if idx == nil then |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
91 idx = #privacy_lists.lists + 1; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
92 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
93 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
94 local list = {}; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
95 list.name = name; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
96 list.items = {}; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
97 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
98 for _,item in ipairs(entries) do |
14
0892941186f2
mod_privacy: Make tmp variable a local
Matthew Wild <mwild1@gmail.com>
parents:
10
diff
changeset
|
99 local tmp = {}; |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
100 tmp["type"] = item.attr.type; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
101 tmp["value"] = item.attr.value; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
102 tmp["action"] = item.attr.action; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
103 tmp["order"] = item.attr.order; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
104 tmp["presence-in"] = false; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
105 tmp["presence-out"] = false; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
106 tmp["message"] = false; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
107 tmp["iq"] = false; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
108 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
109 if #item.tags > 0 then |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
110 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
|
111 tmp[tag.name] = true; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
112 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
113 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
114 list.items[#list.items + 1] = tmp; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
115 end |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
116 |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
117 table.sort(list, sortByOrder); |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
118 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
119 privacy_lists.lists[idx] = list; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
120 origin.send(st.reply(stanza)); |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
121 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
|
122 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
|
123 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
|
124 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
|
125 iq:up(); |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
126 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
|
127 iq.attr.to = bare_jid.."/"..resource |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
128 session.send(iq); |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
129 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
130 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
131 return true; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
132 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
133 |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
134 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
|
135 module:log("info", "User requests list named: %s", name or "nil"); |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
136 local ret = false; |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
137 local reply = st.reply(stanza); |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
138 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
|
139 |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
140 if name == nil then |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
141 reply:tag("active", {name=privacy_lists.active or ""}):up(); |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
142 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
|
143 if privacy_lists.lists then |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
144 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
|
145 reply:tag("list", {name=list.name}):up(); |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
146 end |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
147 ret = true; |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
148 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
149 else |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
150 local idx = findNamedList(privacy_lists, name); |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
151 module:log("debug", "list idx: %d", idx or -1); |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
152 if idx ~= nil then |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
153 list = privacy_lists.lists[idx]; |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
154 reply = reply:tag("list", {name=list.name}); |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
155 for _,item in ipairs(list.items) do |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
156 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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 reply:up(); |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
162 end |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
163 ret = true; |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
164 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
165 end |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
166 |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
167 if ret then |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
168 origin.send(reply); |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
169 end |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
170 return ret; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
171 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
172 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
173 -- "[tagname]/[target-type]/[payload-namespace]:[payload-tagname]" |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
174 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
|
175 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
|
176 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
177 if stanza.attr.to == nil then -- only service requests to own bare JID |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
178 local err_reply = nil; |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
179 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
|
180 local valid = false; |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
181 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
|
182 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
183 if stanza.attr.type == "set" then |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
184 if #query.tags >= 1 then |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
185 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
|
186 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
|
187 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
|
188 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
|
189 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
|
190 valid = activateList(privacy_lists, origin, stanza, tag.name, tag.attr.name); |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
191 err_reply = st.error_reply(stanza, "cancel", "item-not-found"); |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
192 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
193 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
|
194 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
|
195 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
|
196 else -- Client edits a privacy list |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
197 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
|
198 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
199 end |
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 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
202 elseif stanza.attr.type == "get" then |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
203 local name = nil; |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
204 local listsToRetrieve = 0; |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
205 if #query.tags >= 1 then |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
206 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
|
207 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
|
208 name = tag.attr.name; |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
209 listsToRetrieve = listsToRetrieve + 1; |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
210 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
211 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
212 end |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
213 if listsToRetrieve == 0 or listsToRetrieve == 1 then |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
214 valid = getList(privacy_lists, origin, stanza, name); |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
215 err_reply = st.error_reply(stanza, "cancel", "item-not-found"); |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
216 end |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
217 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
218 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
219 if valid == false then |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
220 if err_reply == nil then |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
221 err_reply = st.error_reply(stanza, "modify", "bad-request"); |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
222 end |
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
223 origin.send(err_reply); |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
224 else |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
225 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
|
226 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
227 return true; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
228 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
229 return false; |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
230 end, 500); |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
231 |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
232 function checkIfNeedToBeBlocked(e, node_, host_) |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
233 local origin, stanza = e.origin, e.stanza; |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
234 local privacy_lists = datamanager.load(node_, host_, "privacy") or {}; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
235 local bare_jid = node_.."@"..host_; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
236 |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
237 module:log("debug", "checkIfNeedToBeBlocked: username: %s, host: %s", node_, host_); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
238 module:log("debug", "stanza: %s, to: %s, form: %s", stanza.name, stanza.attr.to or "nil", stanza.attr.from or "nil"); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
239 |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
240 if privacy_lists.lists ~= nil and stanza.attr.to ~= nil and stanza.attr.from ~= nil then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
241 if privacy_lists.active == nil and privacy_lists.default == nil then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
242 return; -- Nothing to block, default is Allow all |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
243 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
244 |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
245 local idx; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
246 local list; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
247 local item; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
248 local block = false; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
249 local apply = false; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
250 local listname = privacy_lists.active; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
251 if listname == nil then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
252 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
|
253 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
254 idx = findNamedList(privacy_lists, listname); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
255 if idx == nil then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
256 module:log("info", "given privacy listname not found."); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
257 return; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
258 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
259 list = privacy_lists.lists[idx]; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
260 if list == nil then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
261 module:log("info", "privacy list index wrong."); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
262 return; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
263 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
264 for _,item in ipairs(list.items) do |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
265 local apply = false; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
266 block = false; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
267 if (stanza.name == "message" and item.message) or |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
268 (stanza.name == "iq" and item.iq) or |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
269 (stanza.name == "presence" and jid_bare(stanza.attr.to) == bare_jid and item["presence-in"]) or |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
270 (stanza.name == "presence" and jid_bare(stanza.attr.from) == bare_jid and item["presence-out"]) or |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
271 (item.message == false and item.iq == false and item["presence-in"] == false and item["presence-in"] == false) then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
272 module:log("debug", "stanza type matched."); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
273 apply = true; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
274 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
275 if apply then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
276 local evilJid = {}; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
277 apply = false; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
278 if jid_bare(stanza.attr.to) == bare_jid then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
279 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
|
280 else |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
281 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
|
282 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
283 if item.type == "jid" and |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
284 (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
|
285 (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
|
286 (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
|
287 (evilJid.host and item.value == evilJid.host) then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
288 module:log("debug", "jid matched."); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
289 apply = true; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
290 block = (item.action == "deny"); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
291 elseif item.type == "group" then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
292 local groups = origin.roster[jid_bare(stanza.from)].groups; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
293 for _,group in ipairs(groups) do |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
294 if group == item.value then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
295 module:log("debug", "group matched."); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
296 apply = true; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
297 block = (item.action == "deny"); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
298 break; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
299 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
300 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
301 elseif item.type == "subscription" then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
302 if origin.roster[jid_bare(stanza.from)].subscription == item.value then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
303 module:log("debug", "subscription matched."); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
304 apply = true; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
305 block = (item.action == "deny"); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
306 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
307 elseif item.type == nil then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
308 module:log("debug", "no item.type, so matched."); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
309 apply = true; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
310 block = (item.action == "deny"); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
311 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
312 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
313 if apply then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
314 if block then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
315 module:log("info", "stanza blocked: %s, to: %s, from: %s", stanza.name, stanza.attr.to or "nil", stanza.attr.from or "nil"); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
316 if stanza.name == "message" then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
317 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
|
318 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
|
319 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
|
320 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
321 return true; -- stanza blocked ! |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
322 else |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
323 module:log("info", "stanza explicit allowed!") |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
324 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
325 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
326 end |
10
7d70faba234c
some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
327 end |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
328 return; |
8
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
329 end |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
330 |
11
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
331 function preCheckIncoming(e) |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
332 if e.stanza.attr.to ~= nil then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
333 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
|
334 if node == nil or host == nil then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
335 return; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
336 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
337 return checkIfNeedToBeBlocked(e, node, host); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
338 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
339 return; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
340 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
341 |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
342 function preCheckOutgoing(e) |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
343 if e.stanza.attr.from ~= nil then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
344 local node, host, resource = jid_split(e.stanza.attr.from); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
345 if node == nil or host == nil then |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
346 return; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
347 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
348 return checkIfNeedToBeBlocked(e, node, host); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
349 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
350 return; |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
351 end |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
352 |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
353 |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
354 module:hook("pre-message/full", preCheckOutgoing, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
355 module:hook("pre-message/bare", preCheckOutgoing, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
356 module:hook("pre-message/host", preCheckOutgoing, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
357 module:hook("pre-iq/full", preCheckOutgoing, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
358 module:hook("pre-iq/bare", preCheckOutgoing, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
359 module:hook("pre-iq/host", preCheckOutgoing, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
360 module:hook("pre-presence/full", preCheckOutgoing, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
361 module:hook("pre-presence/bare", preCheckOutgoing, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
362 module:hook("pre-presence/host", preCheckOutgoing, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
363 |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
364 module:hook("message/full", preCheckIncoming, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
365 module:hook("message/bare", preCheckIncoming, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
366 module:hook("message/host", preCheckIncoming, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
367 module:hook("iq/full", preCheckIncoming, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
368 module:hook("iq/bare", preCheckIncoming, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
369 module:hook("iq/host", preCheckIncoming, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
370 module:hook("presence/full", preCheckIncoming, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
371 module:hook("presence/bare", preCheckIncoming, 500); |
529819205379
do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents:
10
diff
changeset
|
372 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
|
373 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
374 -- helpers.log_events(hosts["albastru.de"].events, "albastru.de"); |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
375 -- helpers.log_events(prosody.events, "*"); |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
376 |
10502594a49b
adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
377 module:log("info", "mod_privacy loaded ..."); |