Software /
code /
prosody
Comparison
plugins/mod_privacy.lua @ 5776:bd0ff8ae98a8
Remove all trailing whitespace
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Fri, 09 Aug 2013 17:48:21 +0200 |
parent | 5500:eeea0eb2602a |
child | 6346:ba7c86406d31 |
comparison
equal
deleted
inserted
replaced
5775:a6c2b8933507 | 5776:bd0ff8ae98a8 |
---|---|
1 -- Prosody IM | 1 -- Prosody IM |
2 -- Copyright (C) 2009-2010 Matthew Wild | 2 -- Copyright (C) 2009-2010 Matthew Wild |
3 -- Copyright (C) 2009-2010 Waqas Hussain | 3 -- Copyright (C) 2009-2010 Waqas Hussain |
4 -- Copyright (C) 2009 Thilo Cestonaro | 4 -- Copyright (C) 2009 Thilo Cestonaro |
5 -- | 5 -- |
6 -- This project is MIT/X11 licensed. Please see the | 6 -- This project is MIT/X11 licensed. Please see the |
7 -- COPYING file in the source package for more information. | 7 -- COPYING file in the source package for more information. |
8 -- | 8 -- |
9 | 9 |
10 module:add_feature("jabber:iq:privacy"); | 10 module:add_feature("jabber:iq:privacy"); |
101 return {"modify", "bad-request", "Not existing list specifed to be deleted."}; | 101 return {"modify", "bad-request", "Not existing list specifed to be deleted."}; |
102 end | 102 end |
103 | 103 |
104 function createOrReplaceList (privacy_lists, origin, stanza, name, entries) | 104 function createOrReplaceList (privacy_lists, origin, stanza, name, entries) |
105 local bare_jid = origin.username.."@"..origin.host; | 105 local bare_jid = origin.username.."@"..origin.host; |
106 | 106 |
107 if privacy_lists.lists == nil then | 107 if privacy_lists.lists == nil then |
108 privacy_lists.lists = {}; | 108 privacy_lists.lists = {}; |
109 end | 109 end |
110 | 110 |
111 local list = {}; | 111 local list = {}; |
117 | 117 |
118 for _,item in ipairs(entries) do | 118 for _,item in ipairs(entries) do |
119 if to_number(item.attr.order) == nil or to_number(item.attr.order) < 0 or orderCheck[item.attr.order] ~= nil then | 119 if to_number(item.attr.order) == nil or to_number(item.attr.order) < 0 or orderCheck[item.attr.order] ~= nil then |
120 return {"modify", "bad-request", "Order attribute not valid."}; | 120 return {"modify", "bad-request", "Order attribute not valid."}; |
121 end | 121 end |
122 | 122 |
123 if item.attr.type ~= nil and item.attr.type ~= "jid" and item.attr.type ~= "subscription" and item.attr.type ~= "group" then | 123 if item.attr.type ~= nil and item.attr.type ~= "jid" and item.attr.type ~= "subscription" and item.attr.type ~= "group" then |
124 return {"modify", "bad-request", "Type attribute not valid."}; | 124 return {"modify", "bad-request", "Type attribute not valid."}; |
125 end | 125 end |
126 | 126 |
127 local tmp = {}; | 127 local tmp = {}; |
128 orderCheck[item.attr.order] = true; | 128 orderCheck[item.attr.order] = true; |
129 | 129 |
130 tmp["type"] = item.attr.type; | 130 tmp["type"] = item.attr.type; |
131 tmp["value"] = item.attr.value; | 131 tmp["value"] = item.attr.value; |
132 tmp["action"] = item.attr.action; | 132 tmp["action"] = item.attr.action; |
133 tmp["order"] = to_number(item.attr.order); | 133 tmp["order"] = to_number(item.attr.order); |
134 tmp["presence-in"] = false; | 134 tmp["presence-in"] = false; |
135 tmp["presence-out"] = false; | 135 tmp["presence-out"] = false; |
136 tmp["message"] = false; | 136 tmp["message"] = false; |
137 tmp["iq"] = false; | 137 tmp["iq"] = false; |
138 | 138 |
139 if #item.tags > 0 then | 139 if #item.tags > 0 then |
140 for _,tag in ipairs(item.tags) do | 140 for _,tag in ipairs(item.tags) do |
141 tmp[tag.name] = true; | 141 tmp[tag.name] = true; |
142 end | 142 end |
143 end | 143 end |
144 | 144 |
145 if tmp.type == "subscription" then | 145 if tmp.type == "subscription" then |
146 if tmp.value ~= "both" and | 146 if tmp.value ~= "both" and |
147 tmp.value ~= "to" and | 147 tmp.value ~= "to" and |
148 tmp.value ~= "from" and | 148 tmp.value ~= "from" and |
149 tmp.value ~= "none" then | 149 tmp.value ~= "none" then |
150 return {"cancel", "bad-request", "Subscription value must be both, to, from or none."}; | 150 return {"cancel", "bad-request", "Subscription value must be both, to, from or none."}; |
151 end | 151 end |
152 end | 152 end |
153 | 153 |
154 if tmp.action ~= "deny" and tmp.action ~= "allow" then | 154 if tmp.action ~= "deny" and tmp.action ~= "allow" then |
155 return {"cancel", "bad-request", "Action must be either deny or allow."}; | 155 return {"cancel", "bad-request", "Action must be either deny or allow."}; |
156 end | 156 end |
157 list.items[#list.items + 1] = tmp; | 157 list.items[#list.items + 1] = tmp; |
158 end | 158 end |
159 | 159 |
160 table.sort(list, function(a, b) return a.order < b.order; end); | 160 table.sort(list, function(a, b) return a.order < b.order; end); |
161 | 161 |
162 origin.send(st.reply(stanza)); | 162 origin.send(st.reply(stanza)); |
163 if bare_sessions[bare_jid] ~= nil then | 163 if bare_sessions[bare_jid] ~= nil then |
164 local iq = st.iq ( { type = "set", id="push1" } ); | 164 local iq = st.iq ( { type = "set", id="push1" } ); |
205 end | 205 end |
206 else | 206 else |
207 return {"cancel", "item-not-found", "Unknown list specified."}; | 207 return {"cancel", "item-not-found", "Unknown list specified."}; |
208 end | 208 end |
209 end | 209 end |
210 | 210 |
211 origin.send(reply); | 211 origin.send(reply); |
212 return true; | 212 return true; |
213 end | 213 end |
214 | 214 |
215 module:hook("iq/bare/jabber:iq:privacy:query", function(data) | 215 module:hook("iq/bare/jabber:iq:privacy:query", function(data) |
216 local origin, stanza = data.origin, data.stanza; | 216 local origin, stanza = data.origin, data.stanza; |
217 | 217 |
218 if stanza.attr.to == nil then -- only service requests to own bare JID | 218 if stanza.attr.to == nil then -- only service requests to own bare JID |
219 local query = stanza.tags[1]; -- the query element | 219 local query = stanza.tags[1]; -- the query element |
220 local valid = false; | 220 local valid = false; |
221 local privacy_lists = privacy_storage:get(origin.username) or { lists = {} }; | 221 local privacy_lists = privacy_storage:get(origin.username) or { lists = {} }; |
222 | 222 |
283 local origin, stanza = e.origin, e.stanza; | 283 local origin, stanza = e.origin, e.stanza; |
284 local privacy_lists = privacy_storage:get(session.username) or {}; | 284 local privacy_lists = privacy_storage:get(session.username) or {}; |
285 local bare_jid = session.username.."@"..session.host; | 285 local bare_jid = session.username.."@"..session.host; |
286 local to = stanza.attr.to or bare_jid; | 286 local to = stanza.attr.to or bare_jid; |
287 local from = stanza.attr.from; | 287 local from = stanza.attr.from; |
288 | 288 |
289 local is_to_user = bare_jid == jid_bare(to); | 289 local is_to_user = bare_jid == jid_bare(to); |
290 local is_from_user = bare_jid == jid_bare(from); | 290 local is_from_user = bare_jid == jid_bare(from); |
291 | 291 |
292 --module:log("debug", "stanza: %s, to: %s, from: %s", tostring(stanza.name), tostring(to), tostring(from)); | 292 --module:log("debug", "stanza: %s, to: %s, from: %s", tostring(stanza.name), tostring(to), tostring(from)); |
293 | 293 |
294 if privacy_lists.lists == nil or | 294 if privacy_lists.lists == nil or |
295 not (session.activePrivacyList or privacy_lists.default) | 295 not (session.activePrivacyList or privacy_lists.default) |
296 then | 296 then |
297 return; -- Nothing to block, default is Allow all | 297 return; -- Nothing to block, default is Allow all |
298 end | 298 end |
299 if is_from_user and is_to_user then | 299 if is_from_user and is_to_user then |
300 --module:log("debug", "Not blocking communications between user's resources"); | 300 --module:log("debug", "Not blocking communications between user's resources"); |
301 return; -- from one of a user's resource to another => HANDS OFF! | 301 return; -- from one of a user's resource to another => HANDS OFF! |
302 end | 302 end |
303 | 303 |
304 local listname = session.activePrivacyList; | 304 local listname = session.activePrivacyList; |
305 if listname == nil then | 305 if listname == nil then |
306 listname = privacy_lists.default; -- no active list selected, use default list | 306 listname = privacy_lists.default; -- no active list selected, use default list |
307 end | 307 end |
308 local list = privacy_lists.lists[listname]; | 308 local list = privacy_lists.lists[listname]; |