Software /
code /
prosody
Annotate
plugins/mod_mimicking.lua @ 9980:73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 06 Aug 2012 15:35:27 +0200 |
child | 9981:8758febbaca2 |
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 |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 -- |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 -- 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
|
5 -- 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
|
6 -- |
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 local skeleton = require "util.confusable".skeleton; |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 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
|
10 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
|
11 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
|
12 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
|
13 |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 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
|
15 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
|
16 end); |
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-deregistered", 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", nil); |
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("registration-attempt", function(user) |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 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
|
24 user.allowed = false; |
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 end); |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 function module.command(arg) |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 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
|
30 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
|
31 return; |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 end |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 local host = arg[2]; |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 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
|
37 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
|
38 return "No such host"; |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 end |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 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
|
41 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
|
42 usermanager.initialize_host(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 storagemanager.initialize_host(host); |
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 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
|
47 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
|
48 end |
73a447249fe4
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 end |