Mercurial > prosody-modules
annotate mod_blocking/mod_blocking.lua @ 968:f3b0ddeebd9d
mod_firewall/conditions: Add DAY and TIME conditions
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 06 Apr 2013 14:03:10 +0100 |
parents | 80ede103d7a3 |
children | 1b55d8f86644 |
rev | line source |
---|---|
174
d40982d130f0
mod_blocking: Various small changes to make it actually work, which I forgot to commit
Matthew Wild <mwild1@gmail.com>
parents:
173
diff
changeset
|
1 local jid_split = require "util.jid".split; |
d40982d130f0
mod_blocking: Various small changes to make it actually work, which I forgot to commit
Matthew Wild <mwild1@gmail.com>
parents:
173
diff
changeset
|
2 local st = require "util.stanza"; |
d40982d130f0
mod_blocking: Various small changes to make it actually work, which I forgot to commit
Matthew Wild <mwild1@gmail.com>
parents:
173
diff
changeset
|
3 |
d40982d130f0
mod_blocking: Various small changes to make it actually work, which I forgot to commit
Matthew Wild <mwild1@gmail.com>
parents:
173
diff
changeset
|
4 local xmlns_blocking = "urn:xmpp:blocking"; |
d40982d130f0
mod_blocking: Various small changes to make it actually work, which I forgot to commit
Matthew Wild <mwild1@gmail.com>
parents:
173
diff
changeset
|
5 |
161
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 module:add_feature("urn:xmpp:blocking"); |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 -- Add JID to default privacy list |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 function add_blocked_jid(username, host, jid) |
372
000f1d1c6ca5
mod_blocking: Properly initialize the bootstrap privacy storage
Paul Aurich <paul@darkrain42.org>
parents:
262
diff
changeset
|
10 local privacy_lists = datamanager.load(username, host, "privacy") or {lists = {}}; |
161
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 local default_list_name = privacy_lists.default; |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 if not default_list_name then |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 default_list_name = "blocklist"; |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 privacy_lists.default = default_list_name; |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 end |
174
d40982d130f0
mod_blocking: Various small changes to make it actually work, which I forgot to commit
Matthew Wild <mwild1@gmail.com>
parents:
173
diff
changeset
|
16 local default_list = privacy_lists.lists[default_list_name]; |
161
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 if not default_list then |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 default_list = { name = default_list_name, items = {} }; |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 privacy_lists.lists[default_list_name] = default_list; |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 end |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 local items = default_list.items; |
174
d40982d130f0
mod_blocking: Various small changes to make it actually work, which I forgot to commit
Matthew Wild <mwild1@gmail.com>
parents:
173
diff
changeset
|
22 local order = items[1] and items[1].order or 0; -- Must come first |
161
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 for i=1,#items do -- order must be unique |
176
26bb69a57749
mod_blocking: Ensure that a JID can be in the blocklist at most once, and have helper functions return true/false on success/error
Matthew Wild <mwild1@gmail.com>
parents:
175
diff
changeset
|
24 local item = items[i]; |
26bb69a57749
mod_blocking: Ensure that a JID can be in the blocklist at most once, and have helper functions return true/false on success/error
Matthew Wild <mwild1@gmail.com>
parents:
175
diff
changeset
|
25 item.order = item.order + 1; |
26bb69a57749
mod_blocking: Ensure that a JID can be in the blocklist at most once, and have helper functions return true/false on success/error
Matthew Wild <mwild1@gmail.com>
parents:
175
diff
changeset
|
26 if item.type == "jid" and item.action == "deny" and item.value == jid then |
26bb69a57749
mod_blocking: Ensure that a JID can be in the blocklist at most once, and have helper functions return true/false on success/error
Matthew Wild <mwild1@gmail.com>
parents:
175
diff
changeset
|
27 return false; |
26bb69a57749
mod_blocking: Ensure that a JID can be in the blocklist at most once, and have helper functions return true/false on success/error
Matthew Wild <mwild1@gmail.com>
parents:
175
diff
changeset
|
28 end |
161
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 end |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 table.insert(items, 1, { type = "jid" |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 , action = "deny" |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 , value = jid |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 , message = false |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 , ["presence-out"] = false |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 , ["presence-in"] = false |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 , iq = false |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 , order = order |
173
4f58ddade1db
mod_blocking: Fixed a syntax error.
Waqas Hussain <waqas20@gmail.com>
parents:
164
diff
changeset
|
38 }); |
161
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 datamanager.store(username, host, "privacy", privacy_lists); |
176
26bb69a57749
mod_blocking: Ensure that a JID can be in the blocklist at most once, and have helper functions return true/false on success/error
Matthew Wild <mwild1@gmail.com>
parents:
175
diff
changeset
|
40 return true; |
161
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 end |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 -- Remove JID from default privacy list |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 function remove_blocked_jid(username, host, jid) |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 local privacy_lists = datamanager.load(username, host, "privacy") or {}; |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 local default_list_name = privacy_lists.default; |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 if not default_list_name then return; end |
174
d40982d130f0
mod_blocking: Various small changes to make it actually work, which I forgot to commit
Matthew Wild <mwild1@gmail.com>
parents:
173
diff
changeset
|
48 local default_list = privacy_lists.lists[default_list_name]; |
161
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 if not default_list then return; end |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 local items = default_list.items; |
176
26bb69a57749
mod_blocking: Ensure that a JID can be in the blocklist at most once, and have helper functions return true/false on success/error
Matthew Wild <mwild1@gmail.com>
parents:
175
diff
changeset
|
51 local item, removed = nil, false; |
161
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 for i=1,#items do -- order must be unique |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 item = items[i]; |
163
9fe6d314fd07
mod_blocking: Only count rules with action == "deny" as blocked JIDs
Matthew Wild <mwild1@gmail.com>
parents:
161
diff
changeset
|
54 if item.type == "jid" and item.action == "deny" and item.value == jid then |
161
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 table.remove(items, i); |
176
26bb69a57749
mod_blocking: Ensure that a JID can be in the blocklist at most once, and have helper functions return true/false on success/error
Matthew Wild <mwild1@gmail.com>
parents:
175
diff
changeset
|
56 removed = true; |
26bb69a57749
mod_blocking: Ensure that a JID can be in the blocklist at most once, and have helper functions return true/false on success/error
Matthew Wild <mwild1@gmail.com>
parents:
175
diff
changeset
|
57 break; |
161
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 end |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 end |
176
26bb69a57749
mod_blocking: Ensure that a JID can be in the blocklist at most once, and have helper functions return true/false on success/error
Matthew Wild <mwild1@gmail.com>
parents:
175
diff
changeset
|
60 if removed then |
26bb69a57749
mod_blocking: Ensure that a JID can be in the blocklist at most once, and have helper functions return true/false on success/error
Matthew Wild <mwild1@gmail.com>
parents:
175
diff
changeset
|
61 datamanager.store(username, host, "privacy", privacy_lists); |
26bb69a57749
mod_blocking: Ensure that a JID can be in the blocklist at most once, and have helper functions return true/false on success/error
Matthew Wild <mwild1@gmail.com>
parents:
175
diff
changeset
|
62 end |
26bb69a57749
mod_blocking: Ensure that a JID can be in the blocklist at most once, and have helper functions return true/false on success/error
Matthew Wild <mwild1@gmail.com>
parents:
175
diff
changeset
|
63 return removed; |
164
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
64 end |
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
65 |
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
66 function remove_all_blocked_jids(username, host) |
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
67 local privacy_lists = datamanager.load(username, host, "privacy") or {}; |
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
68 local default_list_name = privacy_lists.default; |
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
69 if not default_list_name then return; end |
174
d40982d130f0
mod_blocking: Various small changes to make it actually work, which I forgot to commit
Matthew Wild <mwild1@gmail.com>
parents:
173
diff
changeset
|
70 local default_list = privacy_lists.lists[default_list_name]; |
164
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
71 if not default_list then return; end |
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
72 local items = default_list.items; |
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
73 local item; |
177
bcd7dc51a5e3
mod_blocking: Fix to iterate over blocklist correctly when removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
176
diff
changeset
|
74 for i=#items,1,-1 do -- order must be unique |
164
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
75 item = items[i]; |
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
76 if item.type == "jid" and item.action == "deny" then |
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
77 table.remove(items, i); |
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
78 end |
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
79 end |
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
80 datamanager.store(username, host, "privacy", privacy_lists); |
176
26bb69a57749
mod_blocking: Ensure that a JID can be in the blocklist at most once, and have helper functions return true/false on success/error
Matthew Wild <mwild1@gmail.com>
parents:
175
diff
changeset
|
81 return true; |
161
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 end |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 function get_blocked_jids(username, host) |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 -- Return array of blocked JIDs in default privacy list |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 local privacy_lists = datamanager.load(username, host, "privacy") or {}; |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 local default_list_name = privacy_lists.default; |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 if not default_list_name then return {}; end |
174
d40982d130f0
mod_blocking: Various small changes to make it actually work, which I forgot to commit
Matthew Wild <mwild1@gmail.com>
parents:
173
diff
changeset
|
89 local default_list = privacy_lists.lists[default_list_name]; |
161
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 if not default_list then return {}; end |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 local items = default_list.items; |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 local item; |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 local jid_list = {}; |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 for i=1,#items do -- order must be unique |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 item = items[i]; |
163
9fe6d314fd07
mod_blocking: Only count rules with action == "deny" as blocked JIDs
Matthew Wild <mwild1@gmail.com>
parents:
161
diff
changeset
|
96 if item.type == "jid" and item.action == "deny" then |
161
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 jid_list[#jid_list+1] = item.value; |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 end |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 end |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 return jid_list; |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 end |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 |
940
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
103 local function send_push_iqs(username, host, command_type, jids) |
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
104 local bare_jid = username.."@"..host; |
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
105 |
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
106 local stanza_content = st.stanza(command_type, { xmlns = xmlns_blocking }); |
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
107 for _, jid in ipairs(jids) do |
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
108 stanza_content:tag("item", { jid = jid }):up(); |
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
109 end |
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
110 |
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
111 for resource, session in pairs(prosody.bare_sessions[bare_jid].sessions) do |
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
112 local iq_push_stanza = st.iq({ type = "set", to = bare_jid.."/"..resource }); |
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
113 iq_push_stanza:add_child(stanza_content); |
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
114 session.send(iq_push_stanza); |
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
115 end |
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
116 end |
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
117 |
262
4986ffe35704
mod_blocking: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
177
diff
changeset
|
118 function handle_blocking_command(event) |
4986ffe35704
mod_blocking: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
177
diff
changeset
|
119 local session, stanza = event.origin, event.stanza; |
4986ffe35704
mod_blocking: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
177
diff
changeset
|
120 |
161
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 local username, host = jid_split(stanza.attr.from); |
164
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
122 if stanza.attr.type == "set" then |
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
123 if stanza.tags[1].name == "block" then |
174
d40982d130f0
mod_blocking: Various small changes to make it actually work, which I forgot to commit
Matthew Wild <mwild1@gmail.com>
parents:
173
diff
changeset
|
124 local block = stanza.tags[1]; |
164
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
125 local block_jid_list = {}; |
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
126 for item in block:childtags() do |
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
127 block_jid_list[#block_jid_list+1] = item.attr.jid; |
161
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 end |
164
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
129 if #block_jid_list == 0 then |
262
4986ffe35704
mod_blocking: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
177
diff
changeset
|
130 session.send(st.error_reply(stanza, "modify", "bad-request")); |
164
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
131 else |
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
132 for _, jid in ipairs(block_jid_list) do |
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
133 add_blocked_jid(username, host, jid); |
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
134 end |
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
135 session.send(st.reply(stanza)); |
940
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
136 send_push_iqs(username, host, "block", block_jid_list); |
164
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
137 end |
262
4986ffe35704
mod_blocking: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
177
diff
changeset
|
138 return true; |
164
0b238b2b0801
mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents:
163
diff
changeset
|
139 elseif stanza.tags[1].name == "unblock" then |
940
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
140 local unblock = stanza.tags[1]; |
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
141 local unblock_jid_list = {}; |
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
142 for item in unblock:childtags() do |
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
143 unblock_jid_list[#unblock_jid_list+1] = item.attr.jid; |
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
144 end |
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
145 if #unblock_jid_list == 0 then |
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
146 remove_all_blocked_jids(username, host); |
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
147 else |
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
148 for _, jid_to_unblock in ipairs(unblock_jid_list) do |
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
149 remove_blocked_jid(username, host, jid_to_unblock); |
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
150 end |
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
151 end |
161
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 session.send(st.reply(stanza)); |
940
80ede103d7a3
mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
Tobias Markmann <tm@ayena.de>
parents:
372
diff
changeset
|
153 send_push_iqs(username, host, "unblock", unblock_jid_list); |
262
4986ffe35704
mod_blocking: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
177
diff
changeset
|
154 return true; |
161
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 end |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 elseif stanza.attr.type == "get" and stanza.tags[1].name == "blocklist" then |
175
92a72435721a
mod_blocking: Fixed a nil global access.
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
157 local reply = st.reply(stanza):tag("blocklist", { xmlns = xmlns_blocking }); |
161
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 local blocked_jids = get_blocked_jids(username, host); |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
159 for _, jid in ipairs(blocked_jids) do |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
160 reply:tag("item", { jid = jid }):up(); |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 end |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
162 session.send(reply); |
262
4986ffe35704
mod_blocking: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
177
diff
changeset
|
163 return true; |
161
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
164 end |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
165 end |
fda7faee7677
mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
166 |
262
4986ffe35704
mod_blocking: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
177
diff
changeset
|
167 module:hook("iq/self/urn:xmpp:blocking:blocklist", handle_blocking_command); |
4986ffe35704
mod_blocking: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
177
diff
changeset
|
168 module:hook("iq/self/urn:xmpp:blocking:block", handle_blocking_command); |
4986ffe35704
mod_blocking: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
177
diff
changeset
|
169 module:hook("iq/self/urn:xmpp:blocking:unblock", handle_blocking_command); |