mirror of
https://github.com/bjc/prosody.git
synced 2025-04-03 21:27:38 +03:00
49 lines
1.4 KiB
Lua
49 lines
1.4 KiB
Lua
-- Prosody IM
|
|
-- Copyright (C) 2012 Florian Zeitz
|
|
--
|
|
-- This project is MIT/X11 licensed. Please see the
|
|
-- COPYING file in the source package for more information.
|
|
--
|
|
|
|
local skeleton = require "util.confusable".skeleton;
|
|
local datamanager = require "util.datamanager";
|
|
local usage = require "util.prosodyctl".show_usage;
|
|
local warn = require "util.prosodyctl".show_warning;
|
|
local users = require "usermanager".users;
|
|
|
|
module:hook("user-registered", function(user)
|
|
datamanager.store(skeleton(user.username), user.host, "skeletons", {username = user.username});
|
|
end);
|
|
|
|
module:hook("user-deregistered", function(user)
|
|
datamanager.store(skeleton(user.username), user.host, "skeletons", nil);
|
|
end);
|
|
|
|
module:hook("registration-attempt", function(user)
|
|
if datamanager.load(skeleton(user.username), user.host, "skeletons") then
|
|
user.allowed = false;
|
|
end
|
|
end);
|
|
|
|
function module.command(arg)
|
|
if (arg[1] ~= "bootstrap" or not arg[2]) then
|
|
usage("mod_mimicking bootstrap <host>", "Initialize skeleton database");
|
|
return;
|
|
end
|
|
|
|
local host = arg[2];
|
|
|
|
local host_session = prosody.hosts[host];
|
|
if not host_session then
|
|
return "No such host";
|
|
end
|
|
local provider = host_session.users;
|
|
if not(provider) or provider.name == "null" then
|
|
usermanager.initialize_host(host);
|
|
end
|
|
storagemanager.initialize_host(host);
|
|
|
|
for user in users(host) do
|
|
datamanager.store(skeleton(user), host, "skeletons", {username = user});
|
|
end
|
|
end
|