author | Kim Alvefur <zash@zash.se> |
Mon, 29 Apr 2019 02:38:55 +0200 | |
changeset 9987 | f7d11503fdce |
parent 9986 | d09575dae242 |
child 9988 | bbabd35b30ae |
permissions | -rw-r--r-- |
9984
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 |
9985
8758febbaca2
mod_mimicking: Import skeleton() from current location
Kim Alvefur <zash@zash.se>
parents:
9984
diff
changeset
|
3 |
-- Copyright (C) 2019 Kim Alvefur |
9984
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 |
|
9985
8758febbaca2
mod_mimicking: Import skeleton() from current location
Kim Alvefur <zash@zash.se>
parents:
9984
diff
changeset
|
9 |
local encodings = require "util.encodings"; |
8758febbaca2
mod_mimicking: Import skeleton() from current location
Kim Alvefur <zash@zash.se>
parents:
9984
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:
9984
diff
changeset
|
11 |
local skeleton = encodings.confusable.skeleton; |
8758febbaca2
mod_mimicking: Import skeleton() from current location
Kim Alvefur <zash@zash.se>
parents:
9984
diff
changeset
|
12 |
|
9984
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; |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 |
local warn = require "util.prosodyctl".show_warning; |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 |
local users = require "usermanager".users; |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 |
|
9987
f7d11503fdce
mod_mimicking: Use new storage API
Kim Alvefur <zash@zash.se>
parents:
9986
diff
changeset
|
17 |
local skeletons = module:open_store("skeletons"); |
f7d11503fdce
mod_mimicking: Use new storage API
Kim Alvefur <zash@zash.se>
parents:
9986
diff
changeset
|
18 |
|
9984
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 |
module:hook("user-registered", function(user) |
9987
f7d11503fdce
mod_mimicking: Use new storage API
Kim Alvefur <zash@zash.se>
parents:
9986
diff
changeset
|
20 |
skeletons:set(skeleton(user.username), { username = user.username }); |
9984
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 |
end); |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 |
|
9986
d09575dae242
mod_mimicking: Hook the correct event names
Kim Alvefur <zash@zash.se>
parents:
9985
diff
changeset
|
23 |
module:hook("user-deleted", function(user) |
9987
f7d11503fdce
mod_mimicking: Use new storage API
Kim Alvefur <zash@zash.se>
parents:
9986
diff
changeset
|
24 |
skeletons:set(skeleton(user.username), nil); |
9984
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 |
end); |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 |
|
9986
d09575dae242
mod_mimicking: Hook the correct event names
Kim Alvefur <zash@zash.se>
parents:
9985
diff
changeset
|
27 |
module:hook("user-registering", function(user) |
9987
f7d11503fdce
mod_mimicking: Use new storage API
Kim Alvefur <zash@zash.se>
parents:
9986
diff
changeset
|
28 |
if skeletons:get(skeleton(user.username)) then |
9984
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 |
user.allowed = false; |
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 |
end); |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 |
function module.command(arg) |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 |
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
|
35 |
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
|
36 |
return; |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 |
end |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 |
local host = arg[2]; |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 |
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
|
42 |
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
|
43 |
return "No such host"; |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 |
end |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 |
local provider = host_session.users; |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 |
if not(provider) or provider.name == "null" then |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 |
usermanager.initialize_host(host); |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 |
end |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 |
storagemanager.initialize_host(host); |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
50 |
|
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
51 |
for user in users(host) do |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
52 |
datamanager.store(skeleton(user), host, "skeletons", {username = user}); |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
53 |
end |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
54 |
end |