Mercurial > prosody-hg
annotate plugins/mod_mimicking.lua @ 9984:bbabd35b30ae
mod_mimicking: Update command to work with current code
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Mon, 29 Apr 2019 02:40:14 +0200 |
| parents | f7d11503fdce |
| children | 46c038969eb3 |
| rev | line source |
|---|---|
|
9980
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 -- Prosody IM |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 -- Copyright (C) 2012 Florian Zeitz |
|
9981
8758febbaca2
mod_mimicking: Import skeleton() from current location
Kim Alvefur <zash@zash.se>
parents:
9980
diff
changeset
|
3 -- Copyright (C) 2019 Kim Alvefur |
|
9980
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 -- |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 -- This project is MIT/X11 licensed. Please see the |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 -- COPYING file in the source package for more information. |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 -- |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 |
|
9981
8758febbaca2
mod_mimicking: Import skeleton() from current location
Kim Alvefur <zash@zash.se>
parents:
9980
diff
changeset
|
9 local encodings = require "util.encodings"; |
|
8758febbaca2
mod_mimicking: Import skeleton() from current location
Kim Alvefur <zash@zash.se>
parents:
9980
diff
changeset
|
10 assert(encodings.confusable, "This module requires that Prosody be built with ICU"); |
|
8758febbaca2
mod_mimicking: Import skeleton() from current location
Kim Alvefur <zash@zash.se>
parents:
9980
diff
changeset
|
11 local skeleton = encodings.confusable.skeleton; |
|
8758febbaca2
mod_mimicking: Import skeleton() from current location
Kim Alvefur <zash@zash.se>
parents:
9980
diff
changeset
|
12 |
|
9980
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 local usage = require "util.prosodyctl".show_usage; |
|
9984
bbabd35b30ae
mod_mimicking: Update command to work with current code
Kim Alvefur <zash@zash.se>
parents:
9983
diff
changeset
|
14 local usermanager = require "core.usermanager"; |
|
bbabd35b30ae
mod_mimicking: Update command to work with current code
Kim Alvefur <zash@zash.se>
parents:
9983
diff
changeset
|
15 local storagemanager = require "core.storagemanager"; |
|
9980
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 |
|
9984
bbabd35b30ae
mod_mimicking: Update command to work with current code
Kim Alvefur <zash@zash.se>
parents:
9983
diff
changeset
|
17 local skeletons |
|
bbabd35b30ae
mod_mimicking: Update command to work with current code
Kim Alvefur <zash@zash.se>
parents:
9983
diff
changeset
|
18 function module.load() |
|
bbabd35b30ae
mod_mimicking: Update command to work with current code
Kim Alvefur <zash@zash.se>
parents:
9983
diff
changeset
|
19 if module.host ~= "*" then |
|
bbabd35b30ae
mod_mimicking: Update command to work with current code
Kim Alvefur <zash@zash.se>
parents:
9983
diff
changeset
|
20 skeletons = module:open_store("skeletons"); |
|
bbabd35b30ae
mod_mimicking: Update command to work with current code
Kim Alvefur <zash@zash.se>
parents:
9983
diff
changeset
|
21 end |
|
bbabd35b30ae
mod_mimicking: Update command to work with current code
Kim Alvefur <zash@zash.se>
parents:
9983
diff
changeset
|
22 end |
|
9983
f7d11503fdce
mod_mimicking: Use new storage API
Kim Alvefur <zash@zash.se>
parents:
9982
diff
changeset
|
23 |
|
9980
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 module:hook("user-registered", function(user) |
|
9983
f7d11503fdce
mod_mimicking: Use new storage API
Kim Alvefur <zash@zash.se>
parents:
9982
diff
changeset
|
25 skeletons:set(skeleton(user.username), { username = user.username }); |
|
9980
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 end); |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 |
|
9982
d09575dae242
mod_mimicking: Hook the correct event names
Kim Alvefur <zash@zash.se>
parents:
9981
diff
changeset
|
28 module:hook("user-deleted", function(user) |
|
9983
f7d11503fdce
mod_mimicking: Use new storage API
Kim Alvefur <zash@zash.se>
parents:
9982
diff
changeset
|
29 skeletons:set(skeleton(user.username), nil); |
|
9980
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 end); |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 |
|
9982
d09575dae242
mod_mimicking: Hook the correct event names
Kim Alvefur <zash@zash.se>
parents:
9981
diff
changeset
|
32 module:hook("user-registering", function(user) |
|
9983
f7d11503fdce
mod_mimicking: Use new storage API
Kim Alvefur <zash@zash.se>
parents:
9982
diff
changeset
|
33 if skeletons:get(skeleton(user.username)) then |
|
9980
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 user.allowed = false; |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 end |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 end); |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 function module.command(arg) |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 if (arg[1] ~= "bootstrap" or not arg[2]) then |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 usage("mod_mimicking bootstrap <host>", "Initialize skeleton database"); |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 return; |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 end |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 local host = arg[2]; |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 local host_session = prosody.hosts[host]; |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 if not host_session then |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 return "No such host"; |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 end |
|
9984
bbabd35b30ae
mod_mimicking: Update command to work with current code
Kim Alvefur <zash@zash.se>
parents:
9983
diff
changeset
|
50 |
|
9980
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
51 storagemanager.initialize_host(host); |
|
9984
bbabd35b30ae
mod_mimicking: Update command to work with current code
Kim Alvefur <zash@zash.se>
parents:
9983
diff
changeset
|
52 usermanager.initialize_host(host); |
|
9980
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
53 |
|
9984
bbabd35b30ae
mod_mimicking: Update command to work with current code
Kim Alvefur <zash@zash.se>
parents:
9983
diff
changeset
|
54 skeletons = storagemanager.open(host, "skeletons"); |
|
bbabd35b30ae
mod_mimicking: Update command to work with current code
Kim Alvefur <zash@zash.se>
parents:
9983
diff
changeset
|
55 |
|
bbabd35b30ae
mod_mimicking: Update command to work with current code
Kim Alvefur <zash@zash.se>
parents:
9983
diff
changeset
|
56 for user in usermanager.users(host) do |
|
bbabd35b30ae
mod_mimicking: Update command to work with current code
Kim Alvefur <zash@zash.se>
parents:
9983
diff
changeset
|
57 skeletons:set(skeleton(user), { username = user }); |
|
9980
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
58 end |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
59 end |
