Software /
code /
prosody
Annotate
plugins/mod_mimicking.lua @ 9981:8758febbaca2
mod_mimicking: Import skeleton() from current location
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 29 Apr 2019 02:40:39 +0200 |
parent | 9980:73a447249fe4 |
child | 9982:d09575dae242 |
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 datamanager = require "util.datamanager"; |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 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
|
15 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
|
16 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
|
17 |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 module:hook("user-registered", function(user) |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 datamanager.store(skeleton(user.username), user.host, "skeletons", {username = user.username}); |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 end); |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 module:hook("user-deregistered", function(user) |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 datamanager.store(skeleton(user.username), user.host, "skeletons", nil); |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 end); |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 module:hook("registration-attempt", function(user) |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 if datamanager.load(skeleton(user.username), user.host, "skeletons") then |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 user.allowed = false; |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 end |
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 |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 function module.command(arg) |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 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
|
34 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
|
35 return; |
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 local host = arg[2]; |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 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
|
41 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
|
42 return "No such host"; |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 end |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 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
|
45 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
|
46 usermanager.initialize_host(host); |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 end |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 storagemanager.initialize_host(host); |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
50 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
|
51 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
|
52 end |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
53 end |