Comparison

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
comparison
equal deleted inserted replaced
9979:b06f6ff878ee 9980:73a447249fe4
1 -- Prosody IM
2 -- Copyright (C) 2012 Florian Zeitz
3 --
4 -- This project is MIT/X11 licensed. Please see the
5 -- COPYING file in the source package for more information.
6 --
7
8 local skeleton = require "util.confusable".skeleton;
9 local datamanager = require "util.datamanager";
10 local usage = require "util.prosodyctl".show_usage;
11 local warn = require "util.prosodyctl".show_warning;
12 local users = require "usermanager".users;
13
14 module:hook("user-registered", function(user)
15 datamanager.store(skeleton(user.username), user.host, "skeletons", {username = user.username});
16 end);
17
18 module:hook("user-deregistered", function(user)
19 datamanager.store(skeleton(user.username), user.host, "skeletons", nil);
20 end);
21
22 module:hook("registration-attempt", function(user)
23 if datamanager.load(skeleton(user.username), user.host, "skeletons") then
24 user.allowed = false;
25 end
26 end);
27
28 function module.command(arg)
29 if (arg[1] ~= "bootstrap" or not arg[2]) then
30 usage("mod_mimicking bootstrap <host>", "Initialize skeleton database");
31 return;
32 end
33
34 local host = arg[2];
35
36 local host_session = prosody.hosts[host];
37 if not host_session then
38 return "No such host";
39 end
40 local provider = host_session.users;
41 if not(provider) or provider.name == "null" then
42 usermanager.initialize_host(host);
43 end
44 storagemanager.initialize_host(host);
45
46 for user in users(host) do
47 datamanager.store(skeleton(user), host, "skeletons", {username = user});
48 end
49 end