Mercurial > prosody-hg
annotate plugins/mod_tombstones.lua @ 14212:55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 05 Jun 2026 16:24:55 +0100 |
| parents | a8ce6f45ba35 |
| children |
| rev | line source |
|---|---|
|
12115
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 -- TODO warn when trying to create an user before the tombstone expires |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 -- e.g. via telnet or other admin interface |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12438
diff
changeset
|
3 local datetime = require "prosody.util.datetime"; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12438
diff
changeset
|
4 local errors = require "prosody.util.error"; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12438
diff
changeset
|
5 local jid_node = require"prosody.util.jid".node; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12438
diff
changeset
|
6 local st = require "prosody.util.stanza"; |
|
12115
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 -- Using a map store as key-value store so that removal of all user data |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 -- does not also remove the tombstone, which would defeat the point |
|
14211
a8ce6f45ba35
mod_tombstones: Factor out tombstone management to helper functions
Matthew Wild <mwild1@gmail.com>
parents:
13213
diff
changeset
|
10 local graveyard = module:open_store(nil, "keyval+"); |
|
13213
50324f66ca2a
plugins: Use integer config API with interval specification where sensible
Kim Alvefur <zash@zash.se>
parents:
13209
diff
changeset
|
11 local graveyard_cache = require "prosody.util.cache".new(module:get_option_integer("tombstone_cache_size", 1024, 1)); |
|
12115
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 |
|
13209
c8d949cf6b09
plugins: Switch to :get_option_period() for time range options
Kim Alvefur <zash@zash.se>
parents:
12977
diff
changeset
|
13 local ttl = module:get_option_period("user_tombstone_expiry", nil); |
|
12115
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 -- Keep tombstones forever by default |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 -- |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 -- Rationale: |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 -- There is no way to be completely sure when remote services have |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 -- forgotten and revoked all memberships. |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 |
|
12117
0c9b64178eda
mod_tombstones: Add some future TODOs
Kim Alvefur <zash@zash.se>
parents:
12115
diff
changeset
|
20 -- TODO If the user left a JID they moved to, return a gone+redirect error |
|
0c9b64178eda
mod_tombstones: Add some future TODOs
Kim Alvefur <zash@zash.se>
parents:
12115
diff
changeset
|
21 -- TODO Attempt to deregister from MUCs based on bookmarks |
|
0c9b64178eda
mod_tombstones: Add some future TODOs
Kim Alvefur <zash@zash.se>
parents:
12115
diff
changeset
|
22 -- TODO Unsubscribe from pubsub services if a notification is received |
|
0c9b64178eda
mod_tombstones: Add some future TODOs
Kim Alvefur <zash@zash.se>
parents:
12115
diff
changeset
|
23 |
|
14211
a8ce6f45ba35
mod_tombstones: Factor out tombstone management to helper functions
Matthew Wild <mwild1@gmail.com>
parents:
13213
diff
changeset
|
24 local function set_tombstone(username) |
|
a8ce6f45ba35
mod_tombstones: Factor out tombstone management to helper functions
Matthew Wild <mwild1@gmail.com>
parents:
13213
diff
changeset
|
25 local time = os.time(); |
|
a8ce6f45ba35
mod_tombstones: Factor out tombstone management to helper functions
Matthew Wild <mwild1@gmail.com>
parents:
13213
diff
changeset
|
26 local ok, err = graveyard:set_key(nil, username, time); |
|
a8ce6f45ba35
mod_tombstones: Factor out tombstone management to helper functions
Matthew Wild <mwild1@gmail.com>
parents:
13213
diff
changeset
|
27 if ok then |
|
a8ce6f45ba35
mod_tombstones: Factor out tombstone management to helper functions
Matthew Wild <mwild1@gmail.com>
parents:
13213
diff
changeset
|
28 graveyard_cache:set(username, time); |
|
a8ce6f45ba35
mod_tombstones: Factor out tombstone management to helper functions
Matthew Wild <mwild1@gmail.com>
parents:
13213
diff
changeset
|
29 end |
|
a8ce6f45ba35
mod_tombstones: Factor out tombstone management to helper functions
Matthew Wild <mwild1@gmail.com>
parents:
13213
diff
changeset
|
30 return ok, err; |
|
a8ce6f45ba35
mod_tombstones: Factor out tombstone management to helper functions
Matthew Wild <mwild1@gmail.com>
parents:
13213
diff
changeset
|
31 end |
|
a8ce6f45ba35
mod_tombstones: Factor out tombstone management to helper functions
Matthew Wild <mwild1@gmail.com>
parents:
13213
diff
changeset
|
32 |
|
a8ce6f45ba35
mod_tombstones: Factor out tombstone management to helper functions
Matthew Wild <mwild1@gmail.com>
parents:
13213
diff
changeset
|
33 local function clear_tombstone(username) |
|
a8ce6f45ba35
mod_tombstones: Factor out tombstone management to helper functions
Matthew Wild <mwild1@gmail.com>
parents:
13213
diff
changeset
|
34 local ok, err = graveyard:set_key(nil, username, nil); |
|
a8ce6f45ba35
mod_tombstones: Factor out tombstone management to helper functions
Matthew Wild <mwild1@gmail.com>
parents:
13213
diff
changeset
|
35 if ok then |
|
a8ce6f45ba35
mod_tombstones: Factor out tombstone management to helper functions
Matthew Wild <mwild1@gmail.com>
parents:
13213
diff
changeset
|
36 graveyard_cache:set(username, false); |
|
a8ce6f45ba35
mod_tombstones: Factor out tombstone management to helper functions
Matthew Wild <mwild1@gmail.com>
parents:
13213
diff
changeset
|
37 end |
|
a8ce6f45ba35
mod_tombstones: Factor out tombstone management to helper functions
Matthew Wild <mwild1@gmail.com>
parents:
13213
diff
changeset
|
38 return ok, err; |
|
a8ce6f45ba35
mod_tombstones: Factor out tombstone management to helper functions
Matthew Wild <mwild1@gmail.com>
parents:
13213
diff
changeset
|
39 end |
|
a8ce6f45ba35
mod_tombstones: Factor out tombstone management to helper functions
Matthew Wild <mwild1@gmail.com>
parents:
13213
diff
changeset
|
40 |
|
12115
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 module:hook_global("user-deleted", function(event) |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 if event.host == module.host then |
|
14211
a8ce6f45ba35
mod_tombstones: Factor out tombstone management to helper functions
Matthew Wild <mwild1@gmail.com>
parents:
13213
diff
changeset
|
43 local ok, err = set_tombstone(event.username); |
|
12115
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 if not ok then module:log("error", "Could store tombstone for %s: %s", event.username, err); end |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 end |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 end); |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 -- Public API |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 function has_tombstone(username) |
|
12438
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
50 local tombstone; |
|
12115
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
51 |
|
12438
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
52 -- Check cache |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
53 local cached_result = graveyard_cache:get(username); |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
54 if cached_result == false then |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
55 -- We cached that there is no tombstone for this user |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
56 return false; |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
57 elseif cached_result then |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
58 tombstone = cached_result; |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
59 else |
|
14211
a8ce6f45ba35
mod_tombstones: Factor out tombstone management to helper functions
Matthew Wild <mwild1@gmail.com>
parents:
13213
diff
changeset
|
60 local stored_result, err = graveyard:get_key(nil, username); |
|
12438
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
61 if not stored_result and not err then |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
62 -- Cache that there is no tombstone for this user |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
63 graveyard_cache:set(username, false); |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
64 return false; |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
65 elseif err then |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
66 -- Failed to check tombstone status |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
67 return nil, err; |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
68 end |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
69 -- We have a tombstone stored, so let's continue with that |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
70 tombstone = stored_result; |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
71 end |
|
12115
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
72 |
|
12438
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
73 -- Check expiry |
|
12115
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
74 if ttl and tombstone + ttl < os.time() then |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
75 module:log("debug", "Tombstone for %s created at %s has expired", username, datetime.datetime(tombstone)); |
|
14211
a8ce6f45ba35
mod_tombstones: Factor out tombstone management to helper functions
Matthew Wild <mwild1@gmail.com>
parents:
13213
diff
changeset
|
76 graveyard:set_key(nil, username, nil); |
|
12438
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
77 graveyard_cache:set(username, nil); -- clear cache entry (if any) |
|
12115
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
78 return nil; |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
79 end |
|
12438
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
80 |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
81 -- Cache for the future |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
82 graveyard_cache:set(username, tombstone); |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
83 |
|
12115
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
84 return tombstone; |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
85 end |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
86 |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
87 module:hook("user-registering", function(event) |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
88 local tombstone, err = has_tombstone(event.username); |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
89 |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
90 if err then |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
91 event.allowed, event.error = errors.coerce(false, err); |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
92 return true; |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
93 elseif not tombstone then |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
94 -- Feel free |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
95 return; |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
96 end |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
97 |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
98 module:log("debug", "Tombstone for %s created at %s", event.username, datetime.datetime(tombstone)); |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
99 event.allowed = false; |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
100 return true; |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
101 end); |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
102 |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
103 module:hook("presence/bare", function(event) |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
104 local origin, presence = event.origin, event.stanza; |
|
12438
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
105 local local_username = jid_node(presence.attr.to); |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
106 if not local_username then return; end |
|
12115
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
107 |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
108 -- We want to undo any left-over presence subscriptions and notify the former |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
109 -- contact that they're gone. |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
110 -- |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
111 -- FIXME This leaks that the user once existed. Hard to avoid without keeping |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
112 -- the contact list in some form, which we don't want to do for privacy |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
113 -- reasons. Bloom filter perhaps? |
|
12438
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
114 |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
115 local pres_type = presence.attr.type; |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
116 local is_probe = pres_type == "probe"; |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
117 local is_normal = pres_type == nil or pres_type == "unavailable"; |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
118 if is_probe and has_tombstone(local_username) then |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
119 origin.send(st.error_reply(presence, "cancel", "gone", "User deleted")); |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
120 origin.send(st.presence({ type = "unsubscribed"; to = presence.attr.from; from = presence.attr.to })); |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
121 return true; |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
122 elseif is_normal and has_tombstone(local_username) then |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
123 origin.send(st.error_reply(presence, "cancel", "gone", "User deleted")); |
|
a698f65df453
mod_tombstones: Add caching to improve performance on busy servers (fixes #1728)
Matthew Wild <mwild1@gmail.com>
parents:
12117
diff
changeset
|
124 origin.send(st.presence({ type = "unsubscribe"; to = presence.attr.from; from = presence.attr.to })); |
|
12115
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
125 return true; |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
126 end |
|
94de6b7596cc
mod_tombstones: Remember deleted accounts #1307
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
127 end, 1); |
|
14212
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
128 |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
129 --- shell commands |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
130 module:add_item("shell-command", { |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
131 section = "user"; |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
132 name = "list_deleted"; |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
133 desc = "List deleted user accounts (tombstones)"; |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
134 args = { |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
135 { name = "host", type = "string" }; |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
136 }; |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
137 host_selector = "host"; |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
138 handler = function (self, host) --luacheck: ignore 212/host |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
139 local c = 0; |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
140 for username in pairs(graveyard:get(nil)) do |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
141 c = c + 1; |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
142 self.session.print(username); |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
143 end |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
144 return true, ("Showing %d deleted accounts"):format(c); |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
145 end; |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
146 }); |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
147 |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
148 module:add_item("shell-command", { |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
149 section = "user"; |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
150 name = "forget"; |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
151 desc = "Forget a deleted user account (tombstone)"; |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
152 args = { |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
153 { name = "jid", type = "string" }; |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
154 }; |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
155 host_selector = "jid"; |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
156 handler = function (self, user_jid) --luacheck: ignore 212/self |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
157 local username = jid_node(user_jid); |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
158 if not has_tombstone(username) then |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
159 if require "core.usermanager".user_exists(username, module.host) then |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
160 return nil, "User account has not been deleted"; |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
161 else |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
162 return nil, "User account does not exist"; |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
163 end |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
164 end |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
165 |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
166 local ok, err = clear_tombstone(username); |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
167 if not ok then |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
168 return nil, ("Failed to remove tombstone: %s"):format(err); |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
169 end |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
170 |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
171 return true, "User account forgotten"; |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
172 end; |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
173 }); |
|
55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
Matthew Wild <mwild1@gmail.com>
parents:
14211
diff
changeset
|
174 |
