2003-01-19 21:17:56 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : mod_configure.erl
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% Author : Alexey Shchepin <alexey@process-one.net>
|
2003-02-23 21:13:39 +01:00
|
|
|
%%% Purpose : Support for online configuration of ejabberd
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% Created : 19 Jan 2003 by Alexey Shchepin <alexey@process-one.net>
|
|
|
|
%%%
|
|
|
|
%%%
|
2009-01-19 15:47:33 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2009 ProcessOne
|
2007-12-24 12:41:41 +01:00
|
|
|
%%%
|
|
|
|
%%% This program is free software; you can redistribute it and/or
|
|
|
|
%%% modify it under the terms of the GNU General Public License as
|
|
|
|
%%% published by the Free Software Foundation; either version 2 of the
|
|
|
|
%%% License, or (at your option) any later version.
|
|
|
|
%%%
|
|
|
|
%%% This program is distributed in the hope that it will be useful,
|
|
|
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
%%% General Public License for more details.
|
2009-01-19 15:47:33 +01:00
|
|
|
%%%
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% You should have received a copy of the GNU General Public License
|
|
|
|
%%% along with this program; if not, write to the Free Software
|
|
|
|
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
|
|
%%% 02111-1307 USA
|
|
|
|
%%%
|
2003-01-19 21:17:56 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% Implements most of XEP-0133: Service Administration Version 1.1
|
|
|
|
%%% (2005-08-19)
|
2007-09-04 09:55:41 +02:00
|
|
|
|
2003-01-19 21:17:56 +01:00
|
|
|
-module(mod_configure).
|
2007-12-24 12:41:41 +01:00
|
|
|
-author('alexey@process-one.net').
|
2003-01-19 21:17:56 +01:00
|
|
|
|
2003-01-24 21:18:33 +01:00
|
|
|
-behaviour(gen_mod).
|
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
-export([start/2,
|
|
|
|
stop/1,
|
2005-09-04 03:58:47 +02:00
|
|
|
get_local_identity/5,
|
|
|
|
get_local_features/5,
|
|
|
|
get_local_items/5,
|
2006-01-19 03:17:31 +01:00
|
|
|
adhoc_local_items/4,
|
|
|
|
adhoc_local_commands/4,
|
|
|
|
get_sm_identity/5,
|
2005-09-04 03:58:47 +02:00
|
|
|
get_sm_features/5,
|
|
|
|
get_sm_items/5,
|
2006-01-19 03:17:31 +01:00
|
|
|
adhoc_sm_items/4,
|
|
|
|
adhoc_sm_commands/4]).
|
2003-01-19 21:17:56 +01:00
|
|
|
|
2008-07-25 16:26:59 +02:00
|
|
|
|
|
|
|
-include_lib("exmpp/include/exmpp.hrl").
|
|
|
|
|
2003-01-19 21:17:56 +01:00
|
|
|
-include("ejabberd.hrl").
|
2006-01-19 03:17:31 +01:00
|
|
|
-include("adhoc.hrl").
|
2003-01-19 21:17:56 +01:00
|
|
|
|
2009-02-20 17:34:56 +01:00
|
|
|
-define(T(Lang, Text), translate:translate(Lang, Text)).
|
2007-09-04 09:55:41 +02:00
|
|
|
|
|
|
|
%% Copied from ejabberd_sm.erl
|
|
|
|
-record(session, {sid, usr, us, priority, info}).
|
2003-01-19 21:17:56 +01:00
|
|
|
|
2008-07-25 16:26:59 +02:00
|
|
|
-define(NS_ADMIN_s, "http://jabber.org/protocol/admin").
|
|
|
|
|
2006-01-19 03:17:31 +01:00
|
|
|
start(Host, _Opts) ->
|
2009-01-03 16:15:38 +01:00
|
|
|
HostB = list_to_binary(Host),
|
|
|
|
ejabberd_hooks:add(disco_local_items, HostB, ?MODULE, get_local_items, 50),
|
|
|
|
ejabberd_hooks:add(disco_local_features, HostB, ?MODULE, get_local_features, 50),
|
|
|
|
ejabberd_hooks:add(disco_local_identity, HostB, ?MODULE, get_local_identity, 50),
|
|
|
|
ejabberd_hooks:add(disco_sm_items, HostB, ?MODULE, get_sm_items, 50),
|
|
|
|
ejabberd_hooks:add(disco_sm_features, HostB, ?MODULE, get_sm_features, 50),
|
|
|
|
ejabberd_hooks:add(disco_sm_identity, HostB, ?MODULE, get_sm_identity, 50),
|
|
|
|
ejabberd_hooks:add(adhoc_local_items, HostB, ?MODULE, adhoc_local_items, 50),
|
|
|
|
ejabberd_hooks:add(adhoc_local_commands, HostB, ?MODULE, adhoc_local_commands, 50),
|
|
|
|
ejabberd_hooks:add(adhoc_sm_items, HostB, ?MODULE, adhoc_sm_items, 50),
|
|
|
|
ejabberd_hooks:add(adhoc_sm_commands, HostB, ?MODULE, adhoc_sm_commands, 50),
|
2003-01-21 21:36:55 +01:00
|
|
|
ok.
|
2003-01-19 21:17:56 +01:00
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
stop(Host) ->
|
2009-01-03 16:15:38 +01:00
|
|
|
HostB = list_to_binary(Host),
|
|
|
|
ejabberd_hooks:delete(adhoc_sm_commands, HostB, ?MODULE, adhoc_sm_commands, 50),
|
|
|
|
ejabberd_hooks:delete(adhoc_sm_items, HostB, ?MODULE, adhoc_sm_items, 50),
|
|
|
|
ejabberd_hooks:delete(adhoc_local_commands, HostB, ?MODULE, adhoc_local_commands, 50),
|
|
|
|
ejabberd_hooks:delete(adhoc_local_items, HostB, ?MODULE, adhoc_local_items, 50),
|
|
|
|
ejabberd_hooks:delete(disco_sm_identity, HostB, ?MODULE, get_sm_identity, 50),
|
|
|
|
ejabberd_hooks:delete(disco_sm_features, HostB, ?MODULE, get_sm_features, 50),
|
|
|
|
ejabberd_hooks:delete(disco_sm_items, HostB, ?MODULE, get_sm_items, 50),
|
|
|
|
ejabberd_hooks:delete(disco_local_identity, HostB, ?MODULE, get_local_identity, 50),
|
|
|
|
ejabberd_hooks:delete(disco_local_features, HostB, ?MODULE, get_local_features, 50),
|
|
|
|
ejabberd_hooks:delete(disco_local_items, HostB, ?MODULE, get_local_items, 50),
|
2009-01-10 17:10:12 +01:00
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_local, HostB, ?NS_ADHOC),
|
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, HostB, ?NS_ADHOC).
|
2003-01-29 18:12:23 +01:00
|
|
|
|
2006-01-19 03:17:31 +01:00
|
|
|
%%%-----------------------------------------------------------------------
|
2003-01-19 21:17:56 +01:00
|
|
|
|
2006-01-19 03:17:31 +01:00
|
|
|
-define(INFO_IDENTITY(Category, Type, Name, Lang),
|
2008-07-25 16:26:59 +02:00
|
|
|
[#xmlel{ns = ?NS_DISCO_INFO, name = 'identity', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('category', Category),
|
|
|
|
?XMLATTR('type', Type),
|
|
|
|
?XMLATTR('name', ?T(Lang, Name))]}]).
|
2005-09-04 03:58:47 +02:00
|
|
|
|
2006-01-19 03:17:31 +01:00
|
|
|
-define(INFO_COMMAND(Name, Lang),
|
2009-01-08 15:54:00 +01:00
|
|
|
?INFO_IDENTITY(<<"automation">>, <<"command-node">>, Name, Lang)).
|
2005-09-04 03:58:47 +02:00
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
-define(NODEJID(To, Name, Node),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs =
|
2009-06-01 18:59:08 +02:00
|
|
|
[?XMLATTR('jid', exmpp_jid:to_binary(To)),
|
2009-01-21 14:34:26 +01:00
|
|
|
?XMLATTR('name', ?T(Lang, Name)),
|
|
|
|
?XMLATTR('node', Node)]}).
|
2007-09-04 09:55:41 +02:00
|
|
|
|
|
|
|
-define(NODE(Name, Node),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('jid', Server),
|
|
|
|
?XMLATTR('name', ?T(Lang, Name)),
|
|
|
|
?XMLATTR('node', Node)]}).
|
2007-09-04 09:55:41 +02:00
|
|
|
|
2009-01-08 15:54:00 +01:00
|
|
|
-define(NS_ADMINX(Sub), <<?NS_ADMIN_s,"#", Sub/binary>>).
|
2007-09-04 09:55:41 +02:00
|
|
|
-define(NS_ADMINL(Sub), ["http:","jabber.org","protocol","admin", Sub]).
|
|
|
|
tokenize(Node) -> string:tokens(Node, "/#").
|
|
|
|
|
2006-01-19 03:17:31 +01:00
|
|
|
get_sm_identity(Acc, _From, _To, Node, Lang) ->
|
|
|
|
case Node of
|
|
|
|
"config" ->
|
|
|
|
?INFO_COMMAND("Configuration", Lang);
|
2005-09-04 03:58:47 +02:00
|
|
|
_ ->
|
|
|
|
Acc
|
|
|
|
end.
|
|
|
|
|
2006-01-19 03:17:31 +01:00
|
|
|
get_local_identity(Acc, _From, _To, Node, Lang) ->
|
2009-01-08 15:54:00 +01:00
|
|
|
LNode = tokenize(binary_to_list(Node)),
|
2006-01-19 03:17:31 +01:00
|
|
|
case LNode of
|
2005-09-04 03:58:47 +02:00
|
|
|
["running nodes", ENode] ->
|
2009-01-08 15:54:00 +01:00
|
|
|
?INFO_IDENTITY(<<"ejabberd">>, <<"node">>, ENode, Lang);
|
2006-01-19 03:17:31 +01:00
|
|
|
["running nodes", _ENode, "DB"] ->
|
2006-04-01 23:43:52 +02:00
|
|
|
?INFO_COMMAND("Database", Lang);
|
2006-01-19 03:17:31 +01:00
|
|
|
["running nodes", _ENode, "modules", "start"] ->
|
|
|
|
?INFO_COMMAND("Start Modules", Lang);
|
|
|
|
["running nodes", _ENode, "modules", "stop"] ->
|
|
|
|
?INFO_COMMAND("Stop Modules", Lang);
|
|
|
|
["running nodes", _ENode, "backup", "backup"] ->
|
|
|
|
?INFO_COMMAND("Backup", Lang);
|
|
|
|
["running nodes", _ENode, "backup", "restore"] ->
|
|
|
|
?INFO_COMMAND("Restore", Lang);
|
|
|
|
["running nodes", _ENode, "backup", "textfile"] ->
|
|
|
|
?INFO_COMMAND("Dump to Text File", Lang);
|
|
|
|
["running nodes", _ENode, "import", "file"] ->
|
|
|
|
?INFO_COMMAND("Import File", Lang);
|
|
|
|
["running nodes", _ENode, "import", "dir"] ->
|
|
|
|
?INFO_COMMAND("Import Directory", Lang);
|
2007-09-04 09:55:41 +02:00
|
|
|
["running nodes", _ENode, "restart"] ->
|
|
|
|
?INFO_COMMAND("Restart Service", Lang);
|
|
|
|
["running nodes", _ENode, "shutdown"] ->
|
|
|
|
?INFO_COMMAND("Shut Down Service", Lang);
|
|
|
|
?NS_ADMINL("add-user") ->
|
|
|
|
?INFO_COMMAND("Add User", Lang);
|
|
|
|
?NS_ADMINL("delete-user") ->
|
|
|
|
?INFO_COMMAND("Delete User", Lang);
|
|
|
|
?NS_ADMINL("end-user-session") ->
|
|
|
|
?INFO_COMMAND("End User Session", Lang);
|
|
|
|
?NS_ADMINL("get-user-password") ->
|
|
|
|
?INFO_COMMAND("Get User Password", Lang);
|
|
|
|
?NS_ADMINL("change-user-password") ->
|
|
|
|
?INFO_COMMAND("Change User Password", Lang);
|
|
|
|
?NS_ADMINL("get-user-lastlogin") ->
|
|
|
|
?INFO_COMMAND("Get User Last Login Time", Lang);
|
|
|
|
?NS_ADMINL("user-stats") ->
|
|
|
|
?INFO_COMMAND("Get User Statistics", Lang);
|
|
|
|
?NS_ADMINL("get-registered-users-num") ->
|
|
|
|
?INFO_COMMAND("Get Number of Registered Users", Lang);
|
|
|
|
?NS_ADMINL("get-online-users-num") ->
|
|
|
|
?INFO_COMMAND("Get Number of Online Users", Lang);
|
2006-01-19 03:17:31 +01:00
|
|
|
["config", "acls"] ->
|
|
|
|
?INFO_COMMAND("Access Control Lists", Lang);
|
|
|
|
["config", "access"] ->
|
|
|
|
?INFO_COMMAND("Access Rules", Lang);
|
2005-09-04 03:58:47 +02:00
|
|
|
_ ->
|
|
|
|
Acc
|
|
|
|
end.
|
|
|
|
|
2006-01-19 03:17:31 +01:00
|
|
|
%%%-----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-define(INFO_RESULT(Allow, Feats),
|
2007-09-04 09:55:41 +02:00
|
|
|
case Allow of
|
|
|
|
deny ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'forbidden'};
|
2007-09-04 09:55:41 +02:00
|
|
|
allow ->
|
|
|
|
{result, Feats}
|
|
|
|
end).
|
2005-09-04 03:58:47 +02:00
|
|
|
|
2009-01-03 16:15:38 +01:00
|
|
|
get_sm_features(Acc, From, To, Node, _Lang) ->
|
2009-06-01 18:38:28 +02:00
|
|
|
LServer = exmpp_jid:prep_domain_as_list(To),
|
2006-01-19 03:17:31 +01:00
|
|
|
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
|
|
|
false ->
|
|
|
|
Acc;
|
|
|
|
_ ->
|
|
|
|
Allow = acl:match_rule(LServer, configure, From),
|
|
|
|
case Node of
|
|
|
|
"config" ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_ADHOC_s]);
|
2006-01-19 03:17:31 +01:00
|
|
|
_ ->
|
|
|
|
Acc
|
|
|
|
end
|
|
|
|
end.
|
2005-09-04 03:58:47 +02:00
|
|
|
|
2009-01-03 16:15:38 +01:00
|
|
|
get_local_features(Acc, From, To, Node, _Lang) ->
|
2009-06-01 18:38:28 +02:00
|
|
|
LServer = exmpp_jid:prep_domain_as_list(To),
|
2006-01-19 03:17:31 +01:00
|
|
|
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
|
|
|
false ->
|
|
|
|
Acc;
|
2005-09-04 03:58:47 +02:00
|
|
|
_ ->
|
2009-01-08 15:54:00 +01:00
|
|
|
LNode = tokenize(binary_to_list(Node)),
|
2006-01-19 03:17:31 +01:00
|
|
|
Allow = acl:match_rule(LServer, configure, From),
|
|
|
|
case LNode of
|
|
|
|
["config"] ->
|
|
|
|
?INFO_RESULT(Allow, []);
|
2007-09-04 09:55:41 +02:00
|
|
|
["user"] ->
|
|
|
|
?INFO_RESULT(Allow, []);
|
2006-01-19 03:17:31 +01:00
|
|
|
["online users"] ->
|
|
|
|
?INFO_RESULT(Allow, []);
|
|
|
|
["all users"] ->
|
|
|
|
?INFO_RESULT(Allow, []);
|
|
|
|
["all users", [$@ | _]] ->
|
|
|
|
?INFO_RESULT(Allow, []);
|
|
|
|
["outgoing s2s" | _] ->
|
|
|
|
?INFO_RESULT(Allow, []);
|
|
|
|
["running nodes"] ->
|
|
|
|
?INFO_RESULT(Allow, []);
|
|
|
|
["stopped nodes"] ->
|
|
|
|
?INFO_RESULT(Allow, []);
|
|
|
|
["running nodes", _ENode] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_STATS_s]);
|
2006-01-19 03:17:31 +01:00
|
|
|
["running nodes", _ENode, "DB"] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_ADHOC_s]);
|
2006-01-19 03:17:31 +01:00
|
|
|
["running nodes", _ENode, "modules"] ->
|
|
|
|
?INFO_RESULT(Allow, []);
|
|
|
|
["running nodes", _ENode, "modules", _] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_ADHOC_s]);
|
2006-01-19 03:17:31 +01:00
|
|
|
["running nodes", _ENode, "backup"] ->
|
|
|
|
?INFO_RESULT(Allow, []);
|
|
|
|
["running nodes", _ENode, "backup", _] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_ADHOC_s]);
|
2006-01-19 03:17:31 +01:00
|
|
|
["running nodes", _ENode, "import"] ->
|
|
|
|
?INFO_RESULT(Allow, []);
|
|
|
|
["running nodes", _ENode, "import", _] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_ADHOC_s]);
|
2007-09-04 09:55:41 +02:00
|
|
|
["running nodes", _ENode, "restart"] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_ADHOC_s]);
|
2007-09-04 09:55:41 +02:00
|
|
|
["running nodes", _ENode, "shutdown"] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_ADHOC_s]);
|
2006-01-19 03:17:31 +01:00
|
|
|
["config", _] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_ADHOC_s]);
|
2007-09-04 09:55:41 +02:00
|
|
|
["http:" | _] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_ADHOC_s]);
|
2006-01-19 03:17:31 +01:00
|
|
|
_ ->
|
|
|
|
Acc
|
|
|
|
end
|
2005-09-04 03:58:47 +02:00
|
|
|
end.
|
|
|
|
|
2006-01-19 03:17:31 +01:00
|
|
|
%%%-----------------------------------------------------------------------
|
2005-09-04 03:58:47 +02:00
|
|
|
|
2009-01-03 16:15:38 +01:00
|
|
|
adhoc_sm_items(Acc, From, To, Lang) ->
|
2009-06-01 18:38:28 +02:00
|
|
|
LServer = exmpp_jid:prep_domain_as_list(To),
|
2006-01-19 03:17:31 +01:00
|
|
|
case acl:match_rule(LServer, configure, From) of
|
|
|
|
allow ->
|
2005-09-04 03:58:47 +02:00
|
|
|
Items = case Acc of
|
2006-01-19 03:17:31 +01:00
|
|
|
{result, Its} -> Its;
|
|
|
|
empty -> []
|
2005-09-04 03:58:47 +02:00
|
|
|
end,
|
2008-07-25 16:26:59 +02:00
|
|
|
Nodes = [#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs =
|
2009-06-01 18:59:08 +02:00
|
|
|
[?XMLATTR('jid', exmpp_jid:to_binary(To)),
|
2009-01-21 14:34:26 +01:00
|
|
|
?XMLATTR('name', ?T(Lang, "Configuration")),
|
|
|
|
?XMLATTR('node', <<"config">>)]}],
|
2006-01-19 03:17:31 +01:00
|
|
|
{result, Items ++ Nodes};
|
2005-09-04 03:58:47 +02:00
|
|
|
_ ->
|
|
|
|
Acc
|
|
|
|
end.
|
|
|
|
|
2006-01-19 03:17:31 +01:00
|
|
|
%%%-----------------------------------------------------------------------
|
|
|
|
|
2009-01-03 16:15:38 +01:00
|
|
|
get_sm_items(Acc, From, To, Node, Lang) ->
|
2009-06-01 18:38:28 +02:00
|
|
|
LServer = exmpp_jid:prep_domain_as_list(To),
|
2006-01-19 03:17:31 +01:00
|
|
|
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
|
|
|
false ->
|
|
|
|
Acc;
|
|
|
|
_ ->
|
|
|
|
Items = case Acc of
|
|
|
|
{result, Its} -> Its;
|
|
|
|
empty -> []
|
|
|
|
end,
|
2009-01-08 15:54:00 +01:00
|
|
|
case {acl:match_rule(LServer, configure, From), binary_to_list(Node)} of
|
2006-01-19 03:17:31 +01:00
|
|
|
{allow, ""} ->
|
2009-01-08 15:54:00 +01:00
|
|
|
Nodes = [?NODEJID(To, "Configuration", <<"config">>),
|
|
|
|
?NODEJID(To, "User Management", <<"user">>)],
|
2009-02-18 19:03:11 +01:00
|
|
|
{result, Items ++ Nodes ++ [binary_to_list(R) || R <- get_user_resources(To)]};
|
2006-01-19 03:17:31 +01:00
|
|
|
{allow, "config"} ->
|
|
|
|
{result, []};
|
|
|
|
{_, "config"} ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'forbidden'};
|
2006-01-19 03:17:31 +01:00
|
|
|
_ ->
|
|
|
|
Acc
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
2009-01-03 16:15:38 +01:00
|
|
|
get_user_resources(BareJID) ->
|
2009-06-01 18:39:36 +02:00
|
|
|
Rs = ejabberd_sm:get_user_resources(exmpp_jid:prep_node(BareJID),
|
2009-06-01 18:37:15 +02:00
|
|
|
exmpp_jid:prep_domain(BareJID)),
|
2005-09-04 03:58:47 +02:00
|
|
|
lists:map(fun(R) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('jid',
|
2009-06-01 18:59:08 +02:00
|
|
|
exmpp_jid:to_binary(
|
2009-06-01 18:34:38 +02:00
|
|
|
exmpp_jid:full(BareJID, R))),
|
2009-01-21 14:34:26 +01:00
|
|
|
?XMLATTR('name',
|
2009-06-01 18:39:36 +02:00
|
|
|
exmpp_jid:prep_node(BareJID))]}
|
2005-09-04 03:58:47 +02:00
|
|
|
end, lists:sort(Rs)).
|
|
|
|
|
2006-01-19 03:17:31 +01:00
|
|
|
%%%-----------------------------------------------------------------------
|
2005-09-04 03:58:47 +02:00
|
|
|
|
2009-01-03 16:15:38 +01:00
|
|
|
adhoc_local_items(Acc, From, To, Lang) ->
|
2009-06-01 18:38:28 +02:00
|
|
|
LServer = exmpp_jid:prep_domain_as_list(To),
|
2006-01-19 03:17:31 +01:00
|
|
|
case acl:match_rule(LServer, configure, From) of
|
|
|
|
allow ->
|
|
|
|
Items = case Acc of
|
|
|
|
{result, Its} -> Its;
|
|
|
|
empty -> []
|
|
|
|
end,
|
2009-01-19 12:59:40 +01:00
|
|
|
PermLev = get_permission_level(From),
|
2006-01-19 03:17:31 +01:00
|
|
|
%% Recursively get all configure commands
|
2009-01-19 15:47:33 +01:00
|
|
|
Nodes = recursively_get_local_items(PermLev, LServer, "", exmpp_jid:domain_as_list(To),
|
2009-01-19 12:59:40 +01:00
|
|
|
Lang),
|
2006-01-19 03:17:31 +01:00
|
|
|
Nodes1 = lists:filter(
|
|
|
|
fun(N) ->
|
2009-01-21 14:34:26 +01:00
|
|
|
Nd = exmpp_xml:get_attribute_as_list(N, 'node', ""),
|
2007-09-04 09:55:41 +02:00
|
|
|
F = get_local_features([], From, To, Nd, Lang),
|
|
|
|
case F of
|
2008-07-25 16:26:59 +02:00
|
|
|
{result, [?NS_ADHOC_s]} ->
|
2007-09-04 09:55:41 +02:00
|
|
|
true;
|
|
|
|
_ ->
|
|
|
|
false
|
|
|
|
end
|
2006-01-19 03:17:31 +01:00
|
|
|
end, Nodes),
|
|
|
|
{result, Items ++ Nodes1};
|
|
|
|
_ ->
|
|
|
|
Acc
|
|
|
|
end.
|
|
|
|
|
2009-01-19 12:59:40 +01:00
|
|
|
recursively_get_local_items(_PermLev, _LServer, "online users", _Server, _Lang) ->
|
2006-01-19 03:17:31 +01:00
|
|
|
[];
|
|
|
|
|
2009-01-19 12:59:40 +01:00
|
|
|
recursively_get_local_items(_PermLev, _LServer, "all users", _Server, _Lang) ->
|
2006-01-19 03:17:31 +01:00
|
|
|
[];
|
|
|
|
|
2009-01-19 12:59:40 +01:00
|
|
|
recursively_get_local_items(PermLev, LServer, Node, Server, Lang) ->
|
2007-09-04 09:55:41 +02:00
|
|
|
LNode = tokenize(Node),
|
2009-01-19 12:59:40 +01:00
|
|
|
Items = case get_local_items({PermLev, LServer}, LNode, Server, Lang) of
|
2006-01-19 03:17:31 +01:00
|
|
|
{result, Res} ->
|
|
|
|
Res;
|
|
|
|
{error, _Error} ->
|
2005-09-04 03:58:47 +02:00
|
|
|
[]
|
|
|
|
end,
|
2006-01-19 03:17:31 +01:00
|
|
|
Nodes = lists:flatten(
|
2007-09-04 09:55:41 +02:00
|
|
|
lists:map(
|
|
|
|
fun(N) ->
|
2009-01-21 14:34:26 +01:00
|
|
|
S = exmpp_xml:get_attribute_as_list(N, 'jid', ""),
|
|
|
|
Nd = exmpp_xml:get_attribute_as_list(N, 'node', ""),
|
2007-09-04 09:55:41 +02:00
|
|
|
if (S /= Server) or (Nd == "") ->
|
|
|
|
[];
|
|
|
|
true ->
|
|
|
|
[N, recursively_get_local_items(
|
2009-01-19 12:59:40 +01:00
|
|
|
PermLev, LServer, Nd, Server, Lang)]
|
2007-09-04 09:55:41 +02:00
|
|
|
end
|
|
|
|
end, Items)),
|
2006-01-19 03:17:31 +01:00
|
|
|
Nodes.
|
|
|
|
|
2009-01-19 12:59:40 +01:00
|
|
|
get_permission_level(JID) ->
|
|
|
|
case acl:match_rule(global, configure, JID) of
|
|
|
|
allow -> global;
|
|
|
|
deny -> vhost
|
|
|
|
end.
|
|
|
|
|
2006-01-19 03:17:31 +01:00
|
|
|
%%%-----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-define(ITEMS_RESULT(Allow, LNode, Fallback),
|
2007-09-04 09:55:41 +02:00
|
|
|
case Allow of
|
|
|
|
deny ->
|
|
|
|
Fallback;
|
|
|
|
allow ->
|
2009-01-19 12:59:40 +01:00
|
|
|
PermLev = get_permission_level(From),
|
|
|
|
case get_local_items({PermLev, LServer}, LNode,
|
2009-06-01 18:59:08 +02:00
|
|
|
exmpp_jid:to_binary(To), Lang) of
|
2007-09-04 09:55:41 +02:00
|
|
|
{result, Res} ->
|
|
|
|
{result, Res};
|
|
|
|
{error, Error} ->
|
|
|
|
{error, Error}
|
|
|
|
end
|
|
|
|
end).
|
2006-01-19 03:17:31 +01:00
|
|
|
|
2009-01-08 15:54:00 +01:00
|
|
|
get_local_items(Acc, From, To, <<>>, Lang) ->
|
2009-06-01 18:38:28 +02:00
|
|
|
LServer = exmpp_jid:prep_domain_as_list(To),
|
2006-01-19 03:17:31 +01:00
|
|
|
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
|
|
|
false ->
|
|
|
|
Acc;
|
|
|
|
_ ->
|
|
|
|
Items = case Acc of
|
|
|
|
{result, Its} -> Its;
|
|
|
|
empty -> []
|
|
|
|
end,
|
|
|
|
Allow = acl:match_rule(LServer, configure, From),
|
|
|
|
case Allow of
|
|
|
|
deny ->
|
|
|
|
{result, Items};
|
|
|
|
allow ->
|
2009-01-19 12:59:40 +01:00
|
|
|
PermLev = get_permission_level(From),
|
|
|
|
case get_local_items({PermLev, LServer}, [],
|
2009-06-01 18:59:08 +02:00
|
|
|
exmpp_jid:to_binary(To), Lang) of
|
2006-01-19 03:17:31 +01:00
|
|
|
{result, Res} ->
|
|
|
|
{result, Items ++ Res};
|
|
|
|
{error, _Error} ->
|
|
|
|
{result, Items}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end;
|
|
|
|
|
2009-01-03 16:15:38 +01:00
|
|
|
get_local_items(Acc, From, To, Node, Lang) ->
|
2009-06-01 18:38:28 +02:00
|
|
|
LServer = exmpp_jid:prep_domain_as_list(To),
|
2006-01-19 03:17:31 +01:00
|
|
|
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
|
|
|
false ->
|
|
|
|
Acc;
|
|
|
|
_ ->
|
2009-01-08 15:54:00 +01:00
|
|
|
LNode = tokenize(binary_to_list(Node)),
|
2006-01-19 03:17:31 +01:00
|
|
|
Allow = acl:match_rule(LServer, configure, From),
|
|
|
|
case LNode of
|
|
|
|
["config"] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, 'forbidden'});
|
2007-09-04 09:55:41 +02:00
|
|
|
["user"] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, 'forbidden'});
|
2006-01-19 03:17:31 +01:00
|
|
|
["online users"] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, 'forbidden'});
|
2006-01-19 03:17:31 +01:00
|
|
|
["all users"] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, 'forbidden'});
|
2006-01-19 03:17:31 +01:00
|
|
|
["all users", [$@ | _]] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, 'forbidden'});
|
2006-01-19 03:17:31 +01:00
|
|
|
["outgoing s2s" | _] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, 'forbidden'});
|
2006-01-19 03:17:31 +01:00
|
|
|
["running nodes"] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, 'forbidden'});
|
2006-01-19 03:17:31 +01:00
|
|
|
["stopped nodes"] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, 'forbidden'});
|
2006-01-19 03:17:31 +01:00
|
|
|
["running nodes", _ENode] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, 'forbidden'});
|
2006-01-19 03:17:31 +01:00
|
|
|
["running nodes", _ENode, "DB"] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, 'forbidden'});
|
2006-01-19 03:17:31 +01:00
|
|
|
["running nodes", _ENode, "modules"] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, 'forbidden'});
|
2006-01-19 03:17:31 +01:00
|
|
|
["running nodes", _ENode, "modules", _] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, 'forbidden'});
|
2006-01-19 03:17:31 +01:00
|
|
|
["running nodes", _ENode, "backup"] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, 'forbidden'});
|
2006-01-19 03:17:31 +01:00
|
|
|
["running nodes", _ENode, "backup", _] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, 'forbidden'});
|
2006-01-19 03:17:31 +01:00
|
|
|
["running nodes", _ENode, "import"] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, 'forbidden'});
|
2006-01-19 03:17:31 +01:00
|
|
|
["running nodes", _ENode, "import", _] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, 'forbidden'});
|
2007-09-04 09:55:41 +02:00
|
|
|
["running nodes", _ENode, "restart"] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, 'forbidden'});
|
2007-09-04 09:55:41 +02:00
|
|
|
["running nodes", _ENode, "shutdown"] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, 'forbidden'});
|
2006-01-19 03:17:31 +01:00
|
|
|
["config", _] ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, 'forbidden'});
|
2007-09-04 09:55:41 +02:00
|
|
|
?NS_ADMINL(_) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, 'forbidden'});
|
2006-01-19 03:17:31 +01:00
|
|
|
_ ->
|
|
|
|
Acc
|
2005-09-04 03:58:47 +02:00
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
2006-01-19 03:17:31 +01:00
|
|
|
%%%-----------------------------------------------------------------------
|
|
|
|
|
2009-01-19 12:59:40 +01:00
|
|
|
%% @spec ({PermissionLevel, Host}, [string()], Server::string(), Lang)
|
|
|
|
%% -> {result, [xmlelement()]}
|
|
|
|
%% PermissionLevel = global | vhost
|
2005-09-04 03:58:47 +02:00
|
|
|
get_local_items(_Host, [], Server, Lang) ->
|
|
|
|
{result,
|
2009-01-08 15:54:00 +01:00
|
|
|
[?NODE("Configuration", <<"config">>),
|
|
|
|
?NODE("User Management", <<"user">>),
|
|
|
|
?NODE("Online Users", <<"online users">>),
|
|
|
|
?NODE("All Users", <<"all users">>),
|
|
|
|
?NODE("Outgoing s2s Connections", <<"outgoing s2s">>),
|
|
|
|
?NODE("Running Nodes", <<"running nodes">>),
|
|
|
|
?NODE("Stopped Nodes", <<"stopped nodes">>)
|
2005-09-04 03:58:47 +02:00
|
|
|
]};
|
|
|
|
|
|
|
|
get_local_items(_Host, ["config"], Server, Lang) ->
|
|
|
|
{result,
|
2009-01-08 15:54:00 +01:00
|
|
|
[?NODE("Access Control Lists", <<"config/acls">>),
|
|
|
|
?NODE("Access Rules", <<"config/access">>)
|
2005-09-04 03:58:47 +02:00
|
|
|
]};
|
|
|
|
|
|
|
|
get_local_items(_Host, ["config", _], _Server, _Lang) ->
|
|
|
|
{result, []};
|
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
get_local_items(_Host, ["user"], Server, Lang) ->
|
|
|
|
{result,
|
2009-01-08 15:54:00 +01:00
|
|
|
[?NODE("Add User", ?NS_ADMINX(<<"add-user">>)),
|
|
|
|
?NODE("Delete User", ?NS_ADMINX(<<"delete-user">>)),
|
|
|
|
?NODE("End User Session", ?NS_ADMINX(<<"end-user-session">>)),
|
|
|
|
?NODE("Get User Password", ?NS_ADMINX(<<"get-user-password">>)),
|
|
|
|
?NODE("Change User Password",?NS_ADMINX(<<"change-user-password">>)),
|
|
|
|
?NODE("Get User Last Login Time", ?NS_ADMINX(<<"get-user-lastlogin">>)),
|
|
|
|
?NODE("Get User Statistics", ?NS_ADMINX(<<"user-stats">>)),
|
|
|
|
?NODE("Get Number of Registered Users",?NS_ADMINX(<<"get-registered-users-num">>)),
|
|
|
|
?NODE("Get Number of Online Users",?NS_ADMINX(<<"get-online-users-num">>))
|
2007-09-04 09:55:41 +02:00
|
|
|
]};
|
|
|
|
|
|
|
|
get_local_items(_Host, ["http:" | _], _Server, _Lang) ->
|
|
|
|
{result, []};
|
|
|
|
|
2009-01-19 12:59:40 +01:00
|
|
|
get_local_items({_, Host}, ["online users"], _Server, _Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
{result, get_online_vh_users(Host)};
|
|
|
|
|
2009-01-19 12:59:40 +01:00
|
|
|
get_local_items({_, Host}, ["all users"], _Server, _Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
{result, get_all_vh_users(Host)};
|
|
|
|
|
2009-01-19 12:59:40 +01:00
|
|
|
get_local_items({_, Host}, ["all users", [$@ | Diap]], _Server, _Lang) ->
|
2007-07-17 10:21:28 +02:00
|
|
|
case catch ejabberd_auth:get_vh_registered_users(Host) of
|
2005-09-04 03:58:47 +02:00
|
|
|
{'EXIT', _Reason} ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'internal-server-error'};
|
2005-09-04 03:58:47 +02:00
|
|
|
Users ->
|
|
|
|
SUsers = lists:sort([{S, U} || {U, S} <- Users]),
|
|
|
|
case catch begin
|
|
|
|
{ok, [S1, S2]} = regexp:split(Diap, "-"),
|
|
|
|
N1 = list_to_integer(S1),
|
|
|
|
N2 = list_to_integer(S2),
|
|
|
|
Sub = lists:sublist(SUsers, N1, N2 - N1 + 1),
|
|
|
|
lists:map(fun({S, U}) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs =
|
2009-06-01 18:59:08 +02:00
|
|
|
[?XMLATTR('jid', exmpp_jid:to_binary(U, S)),
|
|
|
|
?XMLATTR('name', exmpp_jid:to_binary(U, S))]}
|
2005-09-04 03:58:47 +02:00
|
|
|
end, Sub)
|
|
|
|
end of
|
2007-09-04 09:55:41 +02:00
|
|
|
{'EXIT', _Reason} ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'not-acceptable'};
|
2007-09-04 09:55:41 +02:00
|
|
|
Res ->
|
|
|
|
{result, Res}
|
|
|
|
end
|
2005-09-04 03:58:47 +02:00
|
|
|
end;
|
|
|
|
|
2009-01-19 12:59:40 +01:00
|
|
|
get_local_items({_, Host}, ["outgoing s2s"], _Server, Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
{result, get_outgoing_s2s(Host, Lang)};
|
|
|
|
|
2009-01-19 12:59:40 +01:00
|
|
|
get_local_items({_, Host}, ["outgoing s2s", To], _Server, Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
{result, get_outgoing_s2s(Host, Lang, To)};
|
|
|
|
|
2007-09-06 09:45:01 +02:00
|
|
|
get_local_items(_Host, ["running nodes"], Server, Lang) ->
|
|
|
|
{result, get_running_nodes(Server, Lang)};
|
2005-09-04 03:58:47 +02:00
|
|
|
|
|
|
|
get_local_items(_Host, ["stopped nodes"], _Server, Lang) ->
|
|
|
|
{result, get_stopped_nodes(Lang)};
|
|
|
|
|
2009-01-19 12:59:40 +01:00
|
|
|
get_local_items({global, _Host}, ["running nodes", ENode], Server, Lang) ->
|
2009-01-08 15:54:00 +01:00
|
|
|
ENodeB = list_to_binary(ENode),
|
2005-09-04 03:58:47 +02:00
|
|
|
{result,
|
2009-01-08 15:54:00 +01:00
|
|
|
[?NODE("Database", <<"running nodes/", ENodeB/binary, "/DB">>),
|
|
|
|
?NODE("Modules", <<"running nodes/", ENodeB/binary, "/modules">>),
|
|
|
|
?NODE("Backup Management", <<"running nodes/", ENodeB/binary, "/backup">>),
|
2009-01-19 16:27:07 +01:00
|
|
|
?NODE("Import Users From jabberd14 Spool Files",
|
2009-01-08 15:54:00 +01:00
|
|
|
<<"running nodes/", ENodeB/binary, "/import">>),
|
|
|
|
?NODE("Restart Service", <<"running nodes/", ENodeB/binary, "/restart">>),
|
|
|
|
?NODE("Shut Down Service", <<"running nodes/", ENodeB/binary, "/shutdown">>)
|
2005-09-04 03:58:47 +02:00
|
|
|
]};
|
|
|
|
|
2009-01-19 12:59:40 +01:00
|
|
|
get_local_items({vhost, _Host}, ["running nodes", ENode], Server, Lang) ->
|
|
|
|
{result,
|
|
|
|
[?NODE("Modules", "running nodes/" ++ ENode ++ "/modules")
|
|
|
|
]};
|
|
|
|
|
2005-09-04 03:58:47 +02:00
|
|
|
get_local_items(_Host, ["running nodes", _ENode, "DB"], _Server, _Lang) ->
|
|
|
|
{result, []};
|
|
|
|
|
|
|
|
get_local_items(_Host, ["running nodes", ENode, "modules"], Server, Lang) ->
|
2009-01-08 15:54:00 +01:00
|
|
|
ENodeB = list_to_binary(ENode),
|
2005-09-04 03:58:47 +02:00
|
|
|
{result,
|
2009-01-08 15:54:00 +01:00
|
|
|
[?NODE("Start Modules", <<"running nodes/", ENodeB/binary, "/modules/start">>),
|
|
|
|
?NODE("Stop Modules", <<"running nodes/", ENodeB/binary, "/modules/stop">>)
|
2005-09-04 03:58:47 +02:00
|
|
|
]};
|
|
|
|
|
|
|
|
get_local_items(_Host, ["running nodes", _ENode, "modules", _], _Server, _Lang) ->
|
|
|
|
{result, []};
|
|
|
|
|
|
|
|
get_local_items(_Host, ["running nodes", ENode, "backup"], Server, Lang) ->
|
2009-01-08 15:54:00 +01:00
|
|
|
ENodeB = list_to_binary(ENode),
|
2005-09-04 03:58:47 +02:00
|
|
|
{result,
|
2009-01-08 15:54:00 +01:00
|
|
|
[?NODE("Backup", <<"running nodes/", ENodeB/binary, "/backup/backup">>),
|
|
|
|
?NODE("Restore", <<"running nodes/", ENodeB/binary, "/backup/restore">>),
|
2005-09-04 03:58:47 +02:00
|
|
|
?NODE("Dump to Text File",
|
2009-01-08 15:54:00 +01:00
|
|
|
<<"running nodes/", ENodeB/binary, "/backup/textfile">>)
|
2005-09-04 03:58:47 +02:00
|
|
|
]};
|
|
|
|
|
|
|
|
get_local_items(_Host, ["running nodes", _ENode, "backup", _], _Server, _Lang) ->
|
|
|
|
{result, []};
|
|
|
|
|
|
|
|
get_local_items(_Host, ["running nodes", ENode, "import"], Server, Lang) ->
|
2009-01-08 15:54:00 +01:00
|
|
|
ENodeB = list_to_binary(ENode),
|
2005-09-04 03:58:47 +02:00
|
|
|
{result,
|
2009-01-08 15:54:00 +01:00
|
|
|
[?NODE("Import File", <<"running nodes/", ENodeB/binary, "/import/file">>),
|
|
|
|
?NODE("Import Directory", <<"running nodes/", ENodeB/binary, "/import/dir">>)
|
2005-09-04 03:58:47 +02:00
|
|
|
]};
|
|
|
|
|
|
|
|
get_local_items(_Host, ["running nodes", _ENode, "import", _], _Server, _Lang) ->
|
|
|
|
{result, []};
|
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
get_local_items(_Host, ["running nodes", _ENode, "restart"], _Server, _Lang) ->
|
|
|
|
{result, []};
|
|
|
|
|
|
|
|
get_local_items(_Host, ["running nodes", _ENode, "shutdown"], _Server, _Lang) ->
|
|
|
|
{result, []};
|
|
|
|
|
2005-09-04 03:58:47 +02:00
|
|
|
get_local_items(_Host, _, _Server, _Lang) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'item-not-found'}.
|
2005-09-04 03:58:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
get_online_vh_users(Host) ->
|
2009-01-03 16:15:38 +01:00
|
|
|
case catch ejabberd_sm:get_vh_session_list(list_to_binary(Host)) of
|
2005-09-04 03:58:47 +02:00
|
|
|
{'EXIT', _Reason} ->
|
|
|
|
[];
|
|
|
|
USRs ->
|
|
|
|
SURs = lists:sort([{S, U, R} || {U, S, R} <- USRs]),
|
|
|
|
lists:map(fun({S, U, R}) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs =
|
2009-06-01 18:59:08 +02:00
|
|
|
[?XMLATTR('jid', exmpp_jid:to_binary(U, S, R)),
|
|
|
|
?XMLATTR('name', exmpp_jid:to_binary(U, S))]}
|
2005-09-04 03:58:47 +02:00
|
|
|
end, SURs)
|
|
|
|
end.
|
|
|
|
|
|
|
|
get_all_vh_users(Host) ->
|
|
|
|
case catch ejabberd_auth:get_vh_registered_users(Host) of
|
|
|
|
{'EXIT', _Reason} ->
|
|
|
|
[];
|
|
|
|
Users ->
|
|
|
|
SUsers = lists:sort([{S, U} || {U, S} <- Users]),
|
|
|
|
case length(SUsers) of
|
|
|
|
N when N =< 100 ->
|
|
|
|
lists:map(fun({S, U}) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs =
|
2009-06-01 18:59:08 +02:00
|
|
|
[?XMLATTR('jid', exmpp_jid:to_binary(U, S)),
|
|
|
|
?XMLATTR('name', exmpp_jid:to_binary(U, S))]}
|
2005-09-04 03:58:47 +02:00
|
|
|
end, SUsers);
|
|
|
|
N ->
|
|
|
|
NParts = trunc(math:sqrt(N * 0.618)) + 1,
|
|
|
|
M = trunc(N / NParts) + 1,
|
|
|
|
lists:map(fun(K) ->
|
|
|
|
L = K + M - 1,
|
|
|
|
Node =
|
2009-01-08 15:54:00 +01:00
|
|
|
<<"@", (list_to_binary(integer_to_list(K)))/binary,
|
|
|
|
"-", (list_to_binary(integer_to_list(L)))/binary>>,
|
2005-09-04 03:58:47 +02:00
|
|
|
{FS, FU} = lists:nth(K, SUsers),
|
|
|
|
{LS, LU} =
|
|
|
|
if L < N -> lists:nth(L, SUsers);
|
|
|
|
true -> lists:last(SUsers)
|
|
|
|
end,
|
|
|
|
Name =
|
2009-01-08 15:54:00 +01:00
|
|
|
<<(list_to_binary(FU))/binary, "@", (list_to_binary(FS))/binary,
|
|
|
|
" -- ", (list_to_binary(LU))/binary, "@", (list_to_binary(LS))/binary>>,
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('jid', Host),
|
|
|
|
?XMLATTR('node', <<"all users/", Node/binary>>),
|
|
|
|
?XMLATTR('name', Name)]}
|
2005-09-04 03:58:47 +02:00
|
|
|
end, lists:seq(1, N, M))
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
|
|
|
get_outgoing_s2s(Host, Lang) ->
|
|
|
|
case catch ejabberd_s2s:dirty_get_connections() of
|
|
|
|
{'EXIT', _Reason} ->
|
|
|
|
[];
|
|
|
|
Connections ->
|
|
|
|
DotHost = "." ++ Host,
|
|
|
|
TConns = [TH || {FH, TH} <- Connections,
|
|
|
|
Host == FH orelse lists:suffix(DotHost, FH)],
|
|
|
|
lists:map(
|
|
|
|
fun(T) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('jid', Host),
|
|
|
|
?XMLATTR('node', <<"outgoing s2s/", (list_to_binary(T))/binary>>),
|
|
|
|
?XMLATTR('name',
|
|
|
|
io_lib:format(?T(Lang, "To ~s"), [T]))]}
|
2005-09-04 03:58:47 +02:00
|
|
|
end, lists:usort(TConns))
|
|
|
|
end.
|
|
|
|
|
|
|
|
get_outgoing_s2s(Host, Lang, To) ->
|
|
|
|
case catch ejabberd_s2s:dirty_get_connections() of
|
|
|
|
{'EXIT', _Reason} ->
|
|
|
|
[];
|
|
|
|
Connections ->
|
|
|
|
lists:map(
|
|
|
|
fun({F, _T}) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('jid', Host),
|
|
|
|
?XMLATTR('node', <<"outgoing s2s/", (list_to_binary(To))/binary, "/", (list_to_binary(F))/binary>>),
|
|
|
|
?XMLATTR('name',
|
|
|
|
io_lib:format(?T(Lang, "From ~s"), [F]))]}
|
2005-09-04 03:58:47 +02:00
|
|
|
end, lists:keysort(1, lists:filter(fun(E) ->
|
|
|
|
element(2, E) == To
|
|
|
|
end, Connections)))
|
|
|
|
end.
|
|
|
|
|
|
|
|
|
2007-09-06 09:45:01 +02:00
|
|
|
get_running_nodes(Server, _Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
case catch mnesia:system_info(running_db_nodes) of
|
|
|
|
{'EXIT', _Reason} ->
|
|
|
|
[];
|
|
|
|
DBNodes ->
|
|
|
|
lists:map(
|
|
|
|
fun(N) ->
|
2009-01-08 15:54:00 +01:00
|
|
|
S = list_to_binary(atom_to_list(N)),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('jid', Server),
|
2009-02-20 17:34:56 +01:00
|
|
|
?XMLATTR('node', <<"running nodes/", S/binary>>),
|
2009-01-21 14:34:26 +01:00
|
|
|
?XMLATTR('name', S)]}
|
2005-09-04 03:58:47 +02:00
|
|
|
end, lists:sort(DBNodes))
|
|
|
|
end.
|
|
|
|
|
|
|
|
get_stopped_nodes(_Lang) ->
|
|
|
|
case catch (lists:usort(mnesia:system_info(db_nodes) ++
|
|
|
|
mnesia:system_info(extra_db_nodes)) --
|
|
|
|
mnesia:system_info(running_db_nodes)) of
|
|
|
|
{'EXIT', _Reason} ->
|
|
|
|
[];
|
|
|
|
DBNodes ->
|
|
|
|
lists:map(
|
|
|
|
fun(N) ->
|
2009-01-08 15:54:00 +01:00
|
|
|
S = list_to_binary(atom_to_list(N)),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('jid', ?MYNAME),
|
|
|
|
?XMLATTR('node', <<"stopped nodes/", S/binary>>),
|
|
|
|
?XMLATTR('name', S)]}
|
2005-09-04 03:58:47 +02:00
|
|
|
end, lists:sort(DBNodes))
|
|
|
|
end.
|
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
%%-------------------------------------------------------------------------
|
2005-09-04 03:58:47 +02:00
|
|
|
|
2009-01-19 12:59:40 +01:00
|
|
|
-define(COMMANDS_RESULT(LServerOrGlobal, From, To, Request),
|
|
|
|
case acl:match_rule(LServerOrGlobal, configure, From) of
|
2007-09-04 09:55:41 +02:00
|
|
|
deny ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'forbidden'};
|
2007-09-04 09:55:41 +02:00
|
|
|
allow ->
|
|
|
|
adhoc_local_commands(From, To, Request)
|
|
|
|
end).
|
2006-01-19 03:17:31 +01:00
|
|
|
|
2009-01-03 16:15:38 +01:00
|
|
|
adhoc_local_commands(Acc, From, To, #adhoc_request{node = Node} = Request) ->
|
2009-06-01 18:38:28 +02:00
|
|
|
LServer = exmpp_jid:prep_domain_as_list(To),
|
2007-09-04 09:55:41 +02:00
|
|
|
LNode = tokenize(Node),
|
2006-01-19 03:17:31 +01:00
|
|
|
case LNode of
|
|
|
|
["running nodes", _ENode, "DB"] ->
|
2009-01-19 12:59:40 +01:00
|
|
|
?COMMANDS_RESULT(global, From, To, Request);
|
2006-01-19 03:17:31 +01:00
|
|
|
["running nodes", _ENode, "modules", _] ->
|
2009-01-19 12:59:40 +01:00
|
|
|
?COMMANDS_RESULT(LServer, From, To, Request);
|
2006-01-19 03:17:31 +01:00
|
|
|
["running nodes", _ENode, "backup", _] ->
|
2009-01-19 12:59:40 +01:00
|
|
|
?COMMANDS_RESULT(global, From, To, Request);
|
2006-01-19 03:17:31 +01:00
|
|
|
["running nodes", _ENode, "import", _] ->
|
2009-01-19 12:59:40 +01:00
|
|
|
?COMMANDS_RESULT(global, From, To, Request);
|
2007-09-04 09:55:41 +02:00
|
|
|
["running nodes", _ENode, "restart"] ->
|
2009-01-19 12:59:40 +01:00
|
|
|
?COMMANDS_RESULT(global, From, To, Request);
|
2007-09-04 09:55:41 +02:00
|
|
|
["running nodes", _ENode, "shutdown"] ->
|
2009-01-19 12:59:40 +01:00
|
|
|
?COMMANDS_RESULT(global, From, To, Request);
|
2006-01-19 03:17:31 +01:00
|
|
|
["config", _] ->
|
2009-01-19 12:59:40 +01:00
|
|
|
?COMMANDS_RESULT(LServer, From, To, Request);
|
2007-09-04 09:55:41 +02:00
|
|
|
?NS_ADMINL(_) ->
|
2009-01-19 12:59:40 +01:00
|
|
|
?COMMANDS_RESULT(LServer, From, To, Request);
|
2006-01-19 03:17:31 +01:00
|
|
|
_ ->
|
|
|
|
Acc
|
|
|
|
end.
|
|
|
|
|
2009-01-03 16:15:38 +01:00
|
|
|
adhoc_local_commands(From, To,
|
2006-01-19 03:17:31 +01:00
|
|
|
#adhoc_request{lang = Lang,
|
|
|
|
node = Node,
|
|
|
|
sessionid = SessionID,
|
|
|
|
action = Action,
|
|
|
|
xdata = XData} = Request) ->
|
2009-06-01 18:38:28 +02:00
|
|
|
LServer = exmpp_jid:prep_domain_as_list(To),
|
2007-09-04 09:55:41 +02:00
|
|
|
LNode = tokenize(Node),
|
2006-01-19 03:17:31 +01:00
|
|
|
%% If the "action" attribute is not present, it is
|
|
|
|
%% understood as "execute". If there was no <actions/>
|
|
|
|
%% element in the first response (which there isn't in our
|
|
|
|
%% case), "execute" and "complete" are equivalent.
|
|
|
|
ActionIsExecute = lists:member(Action,
|
|
|
|
["", "execute", "complete"]),
|
|
|
|
if Action == "cancel" ->
|
|
|
|
%% User cancels request
|
|
|
|
adhoc:produce_response(
|
|
|
|
Request,
|
|
|
|
#adhoc_response{status = canceled});
|
|
|
|
XData == false, ActionIsExecute ->
|
|
|
|
%% User requests form
|
2006-02-06 06:12:54 +01:00
|
|
|
case get_form(LServer, LNode, Lang) of
|
2006-01-19 03:17:31 +01:00
|
|
|
{result, Form} ->
|
|
|
|
adhoc:produce_response(
|
|
|
|
Request,
|
|
|
|
#adhoc_response{status = executing,
|
|
|
|
elements = Form});
|
2007-09-04 09:55:41 +02:00
|
|
|
{result, Status, Form} ->
|
|
|
|
adhoc:produce_response(
|
|
|
|
Request,
|
|
|
|
#adhoc_response{status = Status,
|
|
|
|
elements = Form});
|
2006-01-19 03:17:31 +01:00
|
|
|
{error, Error} ->
|
|
|
|
{error, Error}
|
|
|
|
end;
|
|
|
|
XData /= false, ActionIsExecute ->
|
|
|
|
%% User returns form.
|
|
|
|
case jlib:parse_xdata_submit(XData) of
|
|
|
|
invalid ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'};
|
2006-01-19 03:17:31 +01:00
|
|
|
Fields ->
|
2007-09-04 09:55:41 +02:00
|
|
|
case catch set_form(From, LServer, LNode, Lang, Fields) of
|
|
|
|
{result, Res} ->
|
2006-01-19 03:17:31 +01:00
|
|
|
adhoc:produce_response(
|
|
|
|
#adhoc_response{lang = Lang,
|
|
|
|
node = Node,
|
|
|
|
sessionid = SessionID,
|
2007-09-04 09:55:41 +02:00
|
|
|
elements = Res,
|
2006-01-19 03:17:31 +01:00
|
|
|
status = completed});
|
2007-09-04 09:55:41 +02:00
|
|
|
{'EXIT', _} ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'};
|
2003-03-09 21:46:47 +01:00
|
|
|
{error, Error} ->
|
2006-01-19 03:17:31 +01:00
|
|
|
{error, Error}
|
2003-01-19 21:17:56 +01:00
|
|
|
end
|
2006-01-19 03:17:31 +01:00
|
|
|
end;
|
|
|
|
true ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'}
|
2003-01-19 21:17:56 +01:00
|
|
|
end.
|
|
|
|
|
2006-01-19 03:17:31 +01:00
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
-define(TVFIELD(Type, Var, Val),
|
2009-01-21 14:34:26 +01:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('type', Type),
|
|
|
|
?XMLATTR('var', Var)],
|
2009-01-08 15:54:00 +01:00
|
|
|
children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = Val}]}]}).
|
|
|
|
-define(HFIELD(), ?TVFIELD(<<"hidden">>, <<"FORM_TYPE">>, list_to_binary(?NS_ADMIN_s))).
|
2007-09-04 09:55:41 +02:00
|
|
|
|
2003-01-19 21:17:56 +01:00
|
|
|
-define(TLFIELD(Type, Label, Var),
|
2009-01-21 14:34:26 +01:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('type', Type),
|
|
|
|
?XMLATTR('label', ?T(Lang, Label)),
|
|
|
|
?XMLATTR('var', Var)]}).
|
2003-01-19 21:17:56 +01:00
|
|
|
|
2003-01-21 21:36:55 +01:00
|
|
|
-define(XFIELD(Type, Label, Var, Val),
|
2009-01-21 14:34:26 +01:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('type', Type),
|
|
|
|
?XMLATTR('label', ?T(Lang, Label)),
|
|
|
|
?XMLATTR('var', Var)],
|
2009-01-08 15:54:00 +01:00
|
|
|
children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = Val}]}]}).
|
2003-01-21 21:36:55 +01:00
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
-define(XMFIELD(Type, Label, Var, Vals),
|
2009-01-21 14:34:26 +01:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('type', Type),
|
|
|
|
?XMLATTR('label', ?T(Lang, Label)),
|
|
|
|
?XMLATTR('var', Var)],
|
2008-07-25 16:26:59 +02:00
|
|
|
children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary(Val)}]} || Val <- Vals]}).
|
2007-09-04 09:55:41 +02:00
|
|
|
|
2003-01-19 21:17:56 +01:00
|
|
|
-define(TABLEFIELD(Table, Val),
|
2009-01-21 14:34:26 +01:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('type', <<"list-single">>),
|
|
|
|
?XMLATTR('label', Table),
|
|
|
|
?XMLATTR('var', Table)],
|
2008-07-25 16:26:59 +02:00
|
|
|
children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary(atom_to_list(Val))}]},
|
2009-01-21 14:34:26 +01:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'option', attrs = [?XMLATTR('label',
|
|
|
|
?T(Lang, "RAM copy"))],
|
2008-07-25 16:26:59 +02:00
|
|
|
children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = <<"ram_copies">>}]}]},
|
2009-01-21 14:34:26 +01:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'option', attrs = [?XMLATTR('label',
|
2007-09-04 09:55:41 +02:00
|
|
|
?T(Lang,
|
2009-01-21 14:34:26 +01:00
|
|
|
"RAM and disc copy"))],
|
2008-07-25 16:26:59 +02:00
|
|
|
children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = <<"disc_copies">>}]}]},
|
2009-01-21 14:34:26 +01:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'option', attrs = [?XMLATTR('label',
|
2007-09-04 09:55:41 +02:00
|
|
|
?T(Lang,
|
2009-01-21 14:34:26 +01:00
|
|
|
"Disc only copy"))],
|
2008-07-25 16:26:59 +02:00
|
|
|
children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = <<"disc_only_copies">>}]}]},
|
2009-01-21 14:34:26 +01:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'option', attrs = [?XMLATTR('label',
|
|
|
|
?T(Lang, "Remote copy"))],
|
2008-07-25 16:26:59 +02:00
|
|
|
children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = <<"unknown">>}]}]}
|
2003-01-19 21:17:56 +01:00
|
|
|
]}).
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-02-06 06:12:54 +01:00
|
|
|
get_form(_Host, ["running nodes", ENode, "DB"], Lang) ->
|
2003-01-19 21:17:56 +01:00
|
|
|
case search_running_node(ENode) of
|
|
|
|
false ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'item-not-found'};
|
2003-01-19 21:17:56 +01:00
|
|
|
Node ->
|
|
|
|
case rpc:call(Node, mnesia, system_info, [tables]) of
|
2003-12-17 21:13:21 +01:00
|
|
|
{badrpc, _Reason} ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'internal-server-error'};
|
2003-01-19 21:17:56 +01:00
|
|
|
Tables ->
|
2003-01-21 21:36:55 +01:00
|
|
|
STables = lists:sort(Tables),
|
2008-07-25 16:26:59 +02:00
|
|
|
{result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[?HFIELD(),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children =
|
|
|
|
[#xmlcdata{cdata =
|
|
|
|
list_to_binary(?T(
|
2007-09-04 09:55:41 +02:00
|
|
|
Lang, "Database Tables Configuration at ") ++
|
2008-07-25 16:26:59 +02:00
|
|
|
ENode)}]},
|
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'instructions', children =
|
|
|
|
[#xmlcdata{cdata =
|
|
|
|
list_to_binary(?T(
|
|
|
|
Lang, "Choose storage type of tables"))}]} |
|
2004-02-15 21:10:40 +01:00
|
|
|
lists:map(
|
|
|
|
fun(Table) ->
|
|
|
|
case rpc:call(Node,
|
|
|
|
mnesia,
|
|
|
|
table_info,
|
|
|
|
[Table, storage_type]) of
|
|
|
|
{badrpc, _} ->
|
|
|
|
?TABLEFIELD(Table, unknown);
|
|
|
|
Type ->
|
|
|
|
?TABLEFIELD(Table, Type)
|
|
|
|
end
|
|
|
|
end, STables)
|
2007-09-04 09:55:41 +02:00
|
|
|
]}]}
|
2003-01-19 21:17:56 +01:00
|
|
|
end
|
|
|
|
end;
|
|
|
|
|
2006-02-06 06:12:54 +01:00
|
|
|
get_form(Host, ["running nodes", ENode, "modules", "stop"], Lang) ->
|
2003-01-28 20:45:13 +01:00
|
|
|
case search_running_node(ENode) of
|
|
|
|
false ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'item-not-found'};
|
2003-01-28 20:45:13 +01:00
|
|
|
Node ->
|
2006-02-06 06:12:54 +01:00
|
|
|
case rpc:call(Node, gen_mod, loaded_modules, [Host]) of
|
2003-12-17 21:13:21 +01:00
|
|
|
{badrpc, _Reason} ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'internal-server-error'};
|
2003-01-28 20:45:13 +01:00
|
|
|
Modules ->
|
|
|
|
SModules = lists:sort(Modules),
|
2008-07-25 16:26:59 +02:00
|
|
|
{result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[?HFIELD(),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children =
|
|
|
|
[#xmlcdata{cdata =
|
|
|
|
list_to_binary(?T(
|
|
|
|
Lang, "Stop Modules at ") ++ ENode)}]},
|
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'instructions', children =
|
|
|
|
[#xmlcdata{cdata =
|
|
|
|
list_to_binary(?T(
|
|
|
|
Lang, "Choose modules to stop"))}]} |
|
2004-02-15 21:10:40 +01:00
|
|
|
lists:map(fun(M) ->
|
|
|
|
S = atom_to_list(M),
|
2009-01-08 15:54:00 +01:00
|
|
|
?XFIELD(<<"boolean">>, S, list_to_binary(S), <<"0">>)
|
2004-02-15 21:10:40 +01:00
|
|
|
end, SModules)
|
2007-09-04 09:55:41 +02:00
|
|
|
]}]}
|
2003-01-28 20:45:13 +01:00
|
|
|
end
|
|
|
|
end;
|
|
|
|
|
2006-02-06 06:12:54 +01:00
|
|
|
get_form(_Host, ["running nodes", ENode, "modules", "start"], Lang) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[?HFIELD(),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children =
|
|
|
|
[#xmlcdata{cdata =
|
|
|
|
list_to_binary(?T(
|
|
|
|
Lang, "Start Modules at ") ++ ENode)}]},
|
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'instructions', children =
|
|
|
|
[#xmlcdata{cdata =
|
|
|
|
list_to_binary(?T(
|
|
|
|
Lang, "Enter list of {Module, [Options]}"))}]},
|
2009-01-08 15:54:00 +01:00
|
|
|
?XFIELD(<<"text-multi">>, "List of modules to start", <<"modules">>, <<"[].">>)
|
2007-09-04 09:55:41 +02:00
|
|
|
]}]};
|
2003-01-28 20:45:13 +01:00
|
|
|
|
2006-02-06 06:12:54 +01:00
|
|
|
get_form(_Host, ["running nodes", ENode, "backup", "backup"], Lang) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children =
|
2009-01-08 15:54:00 +01:00
|
|
|
[
|
|
|
|
?HFIELD(),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children =
|
|
|
|
[#xmlcdata{cdata =
|
|
|
|
list_to_binary(?T(
|
|
|
|
Lang, "Backup to File at ") ++ ENode)}]},
|
2009-01-08 15:54:00 +01:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'instructions', children =
|
2008-07-25 16:26:59 +02:00
|
|
|
[#xmlcdata{cdata =
|
|
|
|
list_to_binary(?T(
|
2009-01-08 15:54:00 +01:00
|
|
|
Lang, "Enter path to backup file"))}]},
|
|
|
|
?XFIELD(<<"text-single">>, "Path to File", <<"path">>, <<"">>)
|
2007-09-04 09:55:41 +02:00
|
|
|
]}]};
|
2003-02-22 20:11:00 +01:00
|
|
|
|
2006-02-06 06:12:54 +01:00
|
|
|
get_form(_Host, ["running nodes", ENode, "backup", "restore"], Lang) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[?HFIELD(),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children =
|
|
|
|
[#xmlcdata{cdata =
|
|
|
|
list_to_binary(?T(
|
|
|
|
Lang, "Restore Backup from File at ") ++ ENode)}]},
|
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'instructions', children =
|
|
|
|
[#xmlcdata{cdata =
|
|
|
|
list_to_binary(?T(
|
|
|
|
Lang, "Enter path to backup file"))}]},
|
2009-01-08 15:54:00 +01:00
|
|
|
?XFIELD(<<"text-single">>, "Path to File", <<"path">>, <<"">>)
|
2007-09-04 09:55:41 +02:00
|
|
|
]}]};
|
2003-02-22 20:11:00 +01:00
|
|
|
|
2006-02-06 06:12:54 +01:00
|
|
|
get_form(_Host, ["running nodes", ENode, "backup", "textfile"], Lang) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[?HFIELD(),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children =
|
|
|
|
[#xmlcdata{cdata =
|
|
|
|
list_to_binary(?T(
|
|
|
|
Lang, "Dump Backup to Text File at ") ++ ENode)}]},
|
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'instructions', children =
|
|
|
|
[#xmlcdata{cdata =
|
|
|
|
list_to_binary(?T(
|
|
|
|
Lang, "Enter path to text file"))}]},
|
2009-01-08 15:54:00 +01:00
|
|
|
?XFIELD(<<"text-single">>, "Path to File", <<"path">>, <<"">>)
|
2007-09-04 09:55:41 +02:00
|
|
|
]}]};
|
2003-02-22 20:11:00 +01:00
|
|
|
|
2006-02-06 06:12:54 +01:00
|
|
|
get_form(_Host, ["running nodes", ENode, "import", "file"], Lang) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[?HFIELD(),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children =
|
|
|
|
[#xmlcdata{cdata =
|
|
|
|
list_to_binary(?T(
|
|
|
|
Lang, "Import User from File at ") ++ ENode)}]},
|
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'instructions', children =
|
|
|
|
[#xmlcdata{cdata =
|
|
|
|
list_to_binary(?T(
|
2009-01-19 16:27:07 +01:00
|
|
|
Lang, "Enter path to jabberd14 spool file"))}]},
|
2009-01-08 15:54:00 +01:00
|
|
|
?XFIELD(<<"text-single">>, "Path to File", <<"path">>, <<"">>)
|
2007-09-04 09:55:41 +02:00
|
|
|
]}]};
|
2003-02-04 21:45:23 +01:00
|
|
|
|
2006-02-06 06:12:54 +01:00
|
|
|
get_form(_Host, ["running nodes", ENode, "import", "dir"], Lang) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[?HFIELD(),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children =
|
|
|
|
[#xmlcdata{cdata =
|
|
|
|
list_to_binary(?T(
|
|
|
|
Lang, "Import Users from Dir at ") ++ ENode)}]},
|
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'instructions', children =
|
|
|
|
[#xmlcdata{cdata =
|
|
|
|
list_to_binary(?T(
|
2009-01-19 16:27:07 +01:00
|
|
|
Lang, "Enter path to jabberd14 spool dir"))}]},
|
2009-01-08 15:54:00 +01:00
|
|
|
?XFIELD(<<"text-single">>, "Path to Dir", <<"path">>, <<"">>)
|
2007-09-04 09:55:41 +02:00
|
|
|
]}]};
|
|
|
|
|
|
|
|
get_form(_Host, ["running nodes", _ENode, "restart"], Lang) ->
|
|
|
|
Make_option =
|
|
|
|
fun(LabelNum, LabelUnit, Value)->
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'option', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('label', LabelNum ++ ?T(Lang, LabelUnit))], children =
|
2008-07-25 16:26:59 +02:00
|
|
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary(Value)}]}]}
|
2007-09-04 09:55:41 +02:00
|
|
|
end,
|
2008-07-25 16:26:59 +02:00
|
|
|
{result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[?HFIELD(),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children =
|
|
|
|
[#xmlcdata{cdata = list_to_binary(?T(Lang, "Restart Service"))}]},
|
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('type', <<"list-single">>),
|
|
|
|
?XMLATTR('label', ?T(Lang, "Time delay")),
|
|
|
|
?XMLATTR('var', <<"delay">>)], children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[Make_option("", "immediately", "1"),
|
|
|
|
Make_option("15 ", "seconds", "15"),
|
|
|
|
Make_option("30 ", "seconds", "30"),
|
|
|
|
Make_option("60 ", "seconds", "60"),
|
|
|
|
Make_option("90 ", "seconds", "90"),
|
|
|
|
Make_option("2 ", "minutes", "120"),
|
|
|
|
Make_option("3 ", "minutes", "180"),
|
|
|
|
Make_option("4 ", "minutes", "240"),
|
|
|
|
Make_option("5 ", "minutes", "300"),
|
|
|
|
Make_option("10 ", "minutes", "600"),
|
|
|
|
Make_option("15 ", "minutes", "900"),
|
|
|
|
Make_option("30 ", "minutes", "1800"),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'required'}
|
2007-09-04 09:55:41 +02:00
|
|
|
]},
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('type', <<"fixed">>),
|
|
|
|
?XMLATTR('label', ?T(Lang, "Send announcement to all online users on all hosts"))]},
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('var', <<"subject">>),
|
|
|
|
?XMLATTR('type', <<"text-single">>),
|
|
|
|
?XMLATTR('label', ?T(Lang, "Subject"))]},
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('var', <<"announcement">>),
|
|
|
|
?XMLATTR('type', <<"text-multi">>),
|
|
|
|
?XMLATTR('label', ?T(Lang, "Message body"))]}
|
2007-09-04 09:55:41 +02:00
|
|
|
]}]};
|
|
|
|
|
|
|
|
get_form(_Host, ["running nodes", _ENode, "shutdown"], Lang) ->
|
|
|
|
Make_option =
|
|
|
|
fun(LabelNum, LabelUnit, Value)->
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'option', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('label', LabelNum ++ ?T(Lang, LabelUnit))], children =
|
2008-07-25 16:26:59 +02:00
|
|
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary(Value)}]}]}
|
2007-09-04 09:55:41 +02:00
|
|
|
end,
|
2008-07-25 16:26:59 +02:00
|
|
|
{result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[?HFIELD(),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children =
|
|
|
|
[#xmlcdata{cdata = list_to_binary(?T(Lang, "Shut Down Service"))}]},
|
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('type', <<"list-single">>),
|
|
|
|
?XMLATTR('label', ?T(Lang, "Time delay")),
|
|
|
|
?XMLATTR('var', <<"delay">>)], children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[Make_option("", "immediately", "1"),
|
|
|
|
Make_option("15 ", "seconds", "15"),
|
|
|
|
Make_option("30 ", "seconds", "30"),
|
|
|
|
Make_option("60 ", "seconds", "60"),
|
|
|
|
Make_option("90 ", "seconds", "90"),
|
|
|
|
Make_option("2 ", "minutes", "120"),
|
|
|
|
Make_option("3 ", "minutes", "180"),
|
|
|
|
Make_option("4 ", "minutes", "240"),
|
|
|
|
Make_option("5 ", "minutes", "300"),
|
|
|
|
Make_option("10 ", "minutes", "600"),
|
|
|
|
Make_option("15 ", "minutes", "900"),
|
|
|
|
Make_option("30 ", "minutes", "1800"),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'required'}
|
2007-09-04 09:55:41 +02:00
|
|
|
]},
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('type', <<"fixed">>),
|
|
|
|
?XMLATTR('label', ?T(Lang, "Send announcement to all online users on all hosts"))]},
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('var', <<"subject">>),
|
|
|
|
?XMLATTR('type', <<"text-single">>),
|
|
|
|
?XMLATTR('label', ?T(Lang, "Subject"))]},
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('var', <<"announcement">>),
|
|
|
|
?XMLATTR('type', <<"text-multi">>),
|
|
|
|
?XMLATTR('label', ?T(Lang, "Message body"))]}
|
2007-09-04 09:55:41 +02:00
|
|
|
]}]};
|
2003-02-04 21:45:23 +01:00
|
|
|
|
2007-09-06 09:45:01 +02:00
|
|
|
get_form(Host, ["config", "acls"], Lang) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[?HFIELD(),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children =
|
|
|
|
[#xmlcdata{cdata =
|
|
|
|
list_to_binary(?T(
|
|
|
|
Lang, "Access Control List Configuration"))}]},
|
2009-01-21 14:34:26 +01:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('type', <<"text-multi">>),
|
|
|
|
?XMLATTR('label',
|
2007-09-04 09:55:41 +02:00
|
|
|
?T(
|
2009-01-21 14:34:26 +01:00
|
|
|
Lang, "Access control lists")),
|
|
|
|
?XMLATTR('var', <<"acls">>)],
|
2008-07-25 16:26:59 +02:00
|
|
|
children = lists:map(fun(S) ->
|
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary(S)}]}
|
2004-02-15 21:10:40 +01:00
|
|
|
end,
|
|
|
|
string:tokens(
|
2007-09-06 09:45:01 +02:00
|
|
|
lists:flatten(
|
|
|
|
io_lib:format(
|
|
|
|
"~p.",
|
|
|
|
[ets:select(acl,
|
|
|
|
[{{acl, {'$1', '$2'}, '$3'},
|
|
|
|
[{'==', '$2', Host}],
|
|
|
|
[{{acl, '$1', '$3'}}]}])
|
|
|
|
])),
|
2004-02-15 21:10:40 +01:00
|
|
|
"\n"))
|
|
|
|
}
|
2007-09-04 09:55:41 +02:00
|
|
|
]}]};
|
2003-02-06 20:09:22 +01:00
|
|
|
|
2007-09-06 09:45:01 +02:00
|
|
|
get_form(Host, ["config", "access"], Lang) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[?HFIELD(),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children =
|
|
|
|
[#xmlcdata{cdata =
|
|
|
|
list_to_binary(?T(
|
|
|
|
Lang, "Access Configuration"))}]},
|
2009-01-21 14:34:26 +01:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =[?XMLATTR('type', <<"text-multi">>),
|
|
|
|
?XMLATTR('label',
|
2007-09-04 09:55:41 +02:00
|
|
|
?T(
|
2009-01-21 14:34:26 +01:00
|
|
|
Lang, "Access rules")),
|
|
|
|
?XMLATTR('var', <<"access">>)],
|
2008-07-25 16:26:59 +02:00
|
|
|
children = lists:map(fun(S) ->
|
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children =[#xmlcdata{cdata = list_to_binary(S)}]}
|
2004-02-15 21:10:40 +01:00
|
|
|
end,
|
|
|
|
string:tokens(
|
|
|
|
lists:flatten(
|
|
|
|
io_lib:format(
|
|
|
|
"~p.",
|
|
|
|
[ets:select(config,
|
2007-09-06 09:45:01 +02:00
|
|
|
[{{config, {access, '$1', '$2'}, '$3'},
|
|
|
|
[{'==', '$2', Host}],
|
|
|
|
[{{access, '$1', '$3'}}]}])
|
2004-02-15 21:10:40 +01:00
|
|
|
])),
|
|
|
|
"\n"))
|
|
|
|
}
|
2007-09-04 09:55:41 +02:00
|
|
|
]}]};
|
2003-01-22 21:40:40 +01:00
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
get_form(_Host, ?NS_ADMINL("add-user"), Lang) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[?HFIELD(),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children =
|
|
|
|
[#xmlcdata{cdata = list_to_binary(?T(Lang, "Add User"))}]},
|
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('type', <<"jid-single">>),
|
|
|
|
?XMLATTR('label', ?T(Lang, "Jabber ID")),
|
|
|
|
?XMLATTR('var', <<"accountjid">>)], children =
|
2008-07-25 16:26:59 +02:00
|
|
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'required'}]},
|
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('type', <<"text-private">>),
|
|
|
|
?XMLATTR('label', ?T(Lang, "Password")),
|
|
|
|
?XMLATTR('var', <<"password">>)], children =
|
2008-07-25 16:26:59 +02:00
|
|
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'required'}]},
|
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('type', <<"text-private">>),
|
|
|
|
?XMLATTR('label', ?T(Lang, "Password Verification")),
|
|
|
|
?XMLATTR('var', <<"password-verify">>)], children =
|
2008-07-25 16:26:59 +02:00
|
|
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'required'}]}
|
2007-09-04 09:55:41 +02:00
|
|
|
]}]};
|
|
|
|
|
|
|
|
get_form(_Host, ?NS_ADMINL("delete-user"), Lang) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[?HFIELD(),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children =
|
|
|
|
[#xmlcdata{cdata = list_to_binary(?T(Lang, "Delete User"))}]},
|
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('type', <<"jid-multi">>),
|
|
|
|
?XMLATTR('label', ?T(Lang, "Jabber ID")),
|
|
|
|
?XMLATTR('var', <<"accountjids">>)], children =
|
2008-07-25 16:26:59 +02:00
|
|
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'required'}]}
|
2007-09-04 09:55:41 +02:00
|
|
|
]}]};
|
|
|
|
|
|
|
|
get_form(_Host, ?NS_ADMINL("end-user-session"), Lang) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[?HFIELD(),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children =
|
|
|
|
[#xmlcdata{cdata = list_to_binary(?T(Lang, "End User Session"))}]},
|
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('type', <<"jid-single">>),
|
|
|
|
?XMLATTR('label', ?T(Lang, "Jabber ID")),
|
|
|
|
?XMLATTR('var', <<"accountjid">>)], children =
|
2008-07-25 16:26:59 +02:00
|
|
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'required'}]}
|
2007-09-04 09:55:41 +02:00
|
|
|
]}]};
|
|
|
|
|
|
|
|
get_form(_Host, ?NS_ADMINL("get-user-password"), Lang) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[?HFIELD(),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children =
|
|
|
|
[#xmlcdata{cdata = list_to_binary(?T(Lang, "Get User Password"))}]},
|
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('type', <<"jid-single">>),
|
|
|
|
?XMLATTR('label', ?T(Lang, "Jabber ID")),
|
|
|
|
?XMLATTR('var', <<"accountjid">>)], children =
|
2008-07-25 16:26:59 +02:00
|
|
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'required'}]}
|
2007-09-04 09:55:41 +02:00
|
|
|
]}]};
|
|
|
|
|
|
|
|
get_form(_Host, ?NS_ADMINL("change-user-password"), Lang) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[?HFIELD(),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children =
|
|
|
|
[#xmlcdata{cdata = list_to_binary(?T(Lang, "Get User Password"))}]},
|
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('type', <<"jid-single">>),
|
|
|
|
?XMLATTR('label', ?T(Lang, "Jabber ID")),
|
|
|
|
?XMLATTR('var', <<"accountjid">>)], children =
|
2008-07-25 16:26:59 +02:00
|
|
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'required'}]},
|
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('type', <<"text-private">>),
|
|
|
|
?XMLATTR('label', ?T(Lang, "Password")),
|
|
|
|
?XMLATTR('var', <<"password">>)], children =
|
2008-07-25 16:26:59 +02:00
|
|
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'required'}]}
|
2007-09-04 09:55:41 +02:00
|
|
|
]}]};
|
|
|
|
|
|
|
|
get_form(_Host, ?NS_ADMINL("get-user-lastlogin"), Lang) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[?HFIELD(),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children =
|
|
|
|
[#xmlcdata{cdata = list_to_binary(?T(Lang, "Get User Last Login Time"))}]},
|
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('type', <<"jid-single">>),
|
|
|
|
?XMLATTR('label', ?T(Lang, "Jabber ID")),
|
|
|
|
?XMLATTR('var', <<"accountjid">>)], children =
|
2008-07-25 16:26:59 +02:00
|
|
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'required'}]}
|
2007-09-04 09:55:41 +02:00
|
|
|
]}]};
|
|
|
|
|
|
|
|
get_form(_Host, ?NS_ADMINL("user-stats"), Lang) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[?HFIELD(),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children =
|
|
|
|
[#xmlcdata{cdata = list_to_binary(?T(Lang, "Get User Statistics"))}]},
|
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('type', <<"jid-single">>),
|
|
|
|
?XMLATTR('label', ?T(Lang, "Jabber ID")),
|
|
|
|
?XMLATTR('var', <<"accountjid">>)], children =
|
2008-07-25 16:26:59 +02:00
|
|
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'required'}]}
|
2007-09-04 09:55:41 +02:00
|
|
|
]}]};
|
|
|
|
|
|
|
|
get_form(Host, ?NS_ADMINL("get-registered-users-num"), Lang) ->
|
|
|
|
[Num] = io_lib:format("~p", [ejabberd_auth:get_vh_registered_users_number(Host)]),
|
|
|
|
{result, completed,
|
2008-07-25 16:26:59 +02:00
|
|
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[?HFIELD(),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('type', <<"text-single">>),
|
|
|
|
?XMLATTR('label', ?T(Lang, "Number of registered users")),
|
|
|
|
?XMLATTR('var', <<"registeredusersnum">>)], children =
|
2008-07-25 16:26:59 +02:00
|
|
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary(Num)}]}]
|
2007-09-04 09:55:41 +02:00
|
|
|
}]}]};
|
|
|
|
|
|
|
|
get_form(Host, ?NS_ADMINL("get-online-users-num"), Lang) ->
|
2009-01-03 16:15:38 +01:00
|
|
|
Num = io_lib:format("~p", [length(ejabberd_sm:get_vh_session_list(list_to_binary(Host)))]),
|
2007-09-04 09:55:41 +02:00
|
|
|
{result, completed,
|
2008-07-25 16:26:59 +02:00
|
|
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[?HFIELD(),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('type', <<"text-single">>),
|
|
|
|
?XMLATTR('label', ?T(Lang, "Number of online users")),
|
|
|
|
?XMLATTR('var', <<"onlineusersnum">>)], children =
|
2008-07-25 16:26:59 +02:00
|
|
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary(Num)}]}]
|
2007-09-04 09:55:41 +02:00
|
|
|
}]}]};
|
2003-01-26 21:16:53 +01:00
|
|
|
|
2006-02-06 06:12:54 +01:00
|
|
|
get_form(_Host, _, _Lang) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'service-unavailable'}.
|
2003-01-19 21:17:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
set_form(_From, _Host, ["running nodes", ENode, "DB"], _Lang, XData) ->
|
2003-01-19 21:17:56 +01:00
|
|
|
case search_running_node(ENode) of
|
|
|
|
false ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'item-not-found'};
|
2003-01-19 21:17:56 +01:00
|
|
|
Node ->
|
|
|
|
lists:foreach(
|
|
|
|
fun({SVar, SVals}) ->
|
2007-12-07 01:09:48 +01:00
|
|
|
%% We believe that this is allowed only for good people
|
2003-01-19 21:17:56 +01:00
|
|
|
Table = list_to_atom(SVar),
|
|
|
|
Type = case SVals of
|
|
|
|
["unknown"] -> unknown;
|
|
|
|
["ram_copies"] -> ram_copies;
|
|
|
|
["disc_copies"] -> disc_copies;
|
|
|
|
["disc_only_copies"] -> disc_only_copies;
|
|
|
|
_ -> false
|
|
|
|
end,
|
|
|
|
if
|
|
|
|
Type == false ->
|
|
|
|
ok;
|
|
|
|
Type == unknown ->
|
|
|
|
mnesia:del_table_copy(Table, Node);
|
|
|
|
true ->
|
|
|
|
case mnesia:add_table_copy(Table, Node, Type) of
|
|
|
|
{aborted, _} ->
|
|
|
|
mnesia:change_table_copy_type(
|
|
|
|
Table, Node, Type);
|
|
|
|
_ ->
|
|
|
|
ok
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end, XData),
|
|
|
|
{result, []}
|
|
|
|
end;
|
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
set_form(_From, Host, ["running nodes", ENode, "modules", "stop"], _Lang, XData) ->
|
2003-01-28 20:45:13 +01:00
|
|
|
case search_running_node(ENode) of
|
|
|
|
false ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'item-not-found'};
|
2003-01-28 20:45:13 +01:00
|
|
|
Node ->
|
|
|
|
lists:foreach(
|
|
|
|
fun({Var, Vals}) ->
|
|
|
|
case Vals of
|
|
|
|
["1"] ->
|
|
|
|
Module = list_to_atom(Var),
|
2006-02-06 06:12:54 +01:00
|
|
|
rpc:call(Node, gen_mod, stop_module, [Host, Module]);
|
2003-01-28 20:45:13 +01:00
|
|
|
_ ->
|
|
|
|
ok
|
|
|
|
end
|
|
|
|
end, XData),
|
|
|
|
{result, []}
|
|
|
|
end;
|
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
set_form(_From, Host, ["running nodes", ENode, "modules", "start"], _Lang, XData) ->
|
2003-01-28 20:45:13 +01:00
|
|
|
case search_running_node(ENode) of
|
|
|
|
false ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'item-not-found'};
|
2003-01-28 20:45:13 +01:00
|
|
|
Node ->
|
|
|
|
case lists:keysearch("modules", 1, XData) of
|
|
|
|
false ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'};
|
2003-01-28 20:45:13 +01:00
|
|
|
{value, {_, Strings}} ->
|
|
|
|
String = lists:foldl(fun(S, Res) ->
|
|
|
|
Res ++ S ++ "\n"
|
|
|
|
end, "", Strings),
|
|
|
|
case erl_scan:string(String) of
|
|
|
|
{ok, Tokens, _} ->
|
|
|
|
case erl_parse:parse_term(Tokens) of
|
|
|
|
{ok, Modules} ->
|
2003-02-01 21:21:28 +01:00
|
|
|
lists:foreach(
|
|
|
|
fun({Module, Args}) ->
|
|
|
|
rpc:call(Node,
|
|
|
|
gen_mod,
|
|
|
|
start_module,
|
2006-02-06 06:12:54 +01:00
|
|
|
[Host, Module, Args])
|
2003-02-01 21:21:28 +01:00
|
|
|
end, Modules),
|
|
|
|
{result, []};
|
2003-01-28 20:45:13 +01:00
|
|
|
_ ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'}
|
2003-01-28 20:45:13 +01:00
|
|
|
end;
|
|
|
|
_ ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'}
|
2003-01-28 20:45:13 +01:00
|
|
|
end;
|
|
|
|
_ ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'}
|
2003-01-28 20:45:13 +01:00
|
|
|
end
|
2003-02-04 21:45:23 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
set_form(_From, _Host, ["running nodes", ENode, "backup", "backup"], _Lang, XData) ->
|
2003-02-22 20:11:00 +01:00
|
|
|
case search_running_node(ENode) of
|
|
|
|
false ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'item-not-found'};
|
2003-02-22 20:11:00 +01:00
|
|
|
Node ->
|
|
|
|
case lists:keysearch("path", 1, XData) of
|
|
|
|
false ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'};
|
2003-02-22 20:11:00 +01:00
|
|
|
{value, {_, [String]}} ->
|
|
|
|
case rpc:call(Node, mnesia, backup, [String]) of
|
2005-09-04 03:58:47 +02:00
|
|
|
{badrpc, _Reason} ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'internal-server-error'};
|
2005-09-04 03:58:47 +02:00
|
|
|
{error, _Reason} ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'internal-server-error'};
|
2003-02-22 20:11:00 +01:00
|
|
|
_ ->
|
|
|
|
{result, []}
|
2007-09-04 09:55:41 +02:00
|
|
|
end;
|
2003-02-22 20:11:00 +01:00
|
|
|
_ ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'}
|
2003-02-22 20:11:00 +01:00
|
|
|
end
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
set_form(_From, _Host, ["running nodes", ENode, "backup", "restore"], _Lang, XData) ->
|
2003-02-22 20:11:00 +01:00
|
|
|
case search_running_node(ENode) of
|
|
|
|
false ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'item-not-found'};
|
2003-02-22 20:11:00 +01:00
|
|
|
Node ->
|
|
|
|
case lists:keysearch("path", 1, XData) of
|
|
|
|
false ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'};
|
2003-02-22 20:11:00 +01:00
|
|
|
{value, {_, [String]}} ->
|
2006-05-07 18:52:21 +02:00
|
|
|
case rpc:call(Node, ejabberd_admin, restore, [String]) of
|
2005-09-04 03:58:47 +02:00
|
|
|
{badrpc, _Reason} ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'internal-server-error'};
|
2005-09-04 03:58:47 +02:00
|
|
|
{error, _Reason} ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'internal-server-error'};
|
2003-02-22 20:11:00 +01:00
|
|
|
_ ->
|
|
|
|
{result, []}
|
2007-09-04 09:55:41 +02:00
|
|
|
end;
|
2003-02-22 20:11:00 +01:00
|
|
|
_ ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'}
|
2003-02-22 20:11:00 +01:00
|
|
|
end
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
set_form(_From, _Host, ["running nodes", ENode, "backup", "textfile"], _Lang, XData) ->
|
2003-02-22 20:11:00 +01:00
|
|
|
case search_running_node(ENode) of
|
|
|
|
false ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'item-not-found'};
|
2003-02-22 20:11:00 +01:00
|
|
|
Node ->
|
|
|
|
case lists:keysearch("path", 1, XData) of
|
|
|
|
false ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'};
|
2003-02-22 20:11:00 +01:00
|
|
|
{value, {_, [String]}} ->
|
2008-10-13 12:11:19 +02:00
|
|
|
case rpc:call(Node, ejabberd_admin, dump_to_textfile, [String]) of
|
2005-09-04 03:58:47 +02:00
|
|
|
{badrpc, _Reason} ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'internal-server-error'};
|
2005-09-04 03:58:47 +02:00
|
|
|
{error, _Reason} ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'internal-server-error'};
|
2003-02-22 20:11:00 +01:00
|
|
|
_ ->
|
|
|
|
{result, []}
|
2007-09-04 09:55:41 +02:00
|
|
|
end;
|
2003-02-22 20:11:00 +01:00
|
|
|
_ ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'}
|
2003-02-22 20:11:00 +01:00
|
|
|
end
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
set_form(_From, _Host, ["running nodes", ENode, "import", "file"], _Lang, XData) ->
|
2003-02-04 21:45:23 +01:00
|
|
|
case search_running_node(ENode) of
|
|
|
|
false ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'item-not-found'};
|
2003-02-04 21:45:23 +01:00
|
|
|
Node ->
|
|
|
|
case lists:keysearch("path", 1, XData) of
|
|
|
|
false ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'};
|
2003-02-04 21:45:23 +01:00
|
|
|
{value, {_, [String]}} ->
|
2003-02-22 20:11:00 +01:00
|
|
|
rpc:call(Node, jd2ejd, import_file, [String]),
|
|
|
|
{result, []};
|
2003-02-04 21:45:23 +01:00
|
|
|
_ ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'}
|
2003-02-04 21:45:23 +01:00
|
|
|
end
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
set_form(_From, _Host, ["running nodes", ENode, "import", "dir"], _Lang, XData) ->
|
2003-02-04 21:45:23 +01:00
|
|
|
case search_running_node(ENode) of
|
|
|
|
false ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'item-not-found'};
|
2003-02-04 21:45:23 +01:00
|
|
|
Node ->
|
|
|
|
case lists:keysearch("path", 1, XData) of
|
|
|
|
false ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'};
|
2003-02-04 21:45:23 +01:00
|
|
|
{value, {_, [String]}} ->
|
2003-10-20 20:23:30 +02:00
|
|
|
rpc:call(Node, jd2ejd, import_dir, [String]),
|
|
|
|
{result, []};
|
2003-02-04 21:45:23 +01:00
|
|
|
_ ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'}
|
2003-02-04 21:45:23 +01:00
|
|
|
end
|
2003-01-28 20:45:13 +01:00
|
|
|
end;
|
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
set_form(From, Host, ["running nodes", ENode, "restart"], _Lang, XData) ->
|
|
|
|
stop_node(From, Host, ENode, restart, XData);
|
|
|
|
|
|
|
|
set_form(From, Host, ["running nodes", ENode, "shutdown"], _Lang, XData) ->
|
|
|
|
stop_node(From, Host, ENode, stop, XData);
|
2003-01-28 20:45:13 +01:00
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
set_form(_From, Host, ["config", "acls"], _Lang, XData) ->
|
2003-02-01 21:21:28 +01:00
|
|
|
case lists:keysearch("acls", 1, XData) of
|
|
|
|
{value, {_, Strings}} ->
|
2003-02-06 20:09:22 +01:00
|
|
|
String = lists:foldl(fun(S, Res) ->
|
|
|
|
Res ++ S ++ "\n"
|
|
|
|
end, "", Strings),
|
|
|
|
case erl_scan:string(String) of
|
|
|
|
{ok, Tokens, _} ->
|
|
|
|
case erl_parse:parse_term(Tokens) of
|
|
|
|
{ok, ACLs} ->
|
2007-07-26 11:49:23 +02:00
|
|
|
case acl:add_list(Host, ACLs, true) of
|
2003-02-06 20:09:22 +01:00
|
|
|
ok ->
|
|
|
|
{result, []};
|
2003-02-01 21:21:28 +01:00
|
|
|
_ ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'}
|
2003-02-01 21:21:28 +01:00
|
|
|
end;
|
|
|
|
_ ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'}
|
2003-02-01 21:21:28 +01:00
|
|
|
end;
|
2003-02-06 20:09:22 +01:00
|
|
|
_ ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'}
|
2003-02-06 20:09:22 +01:00
|
|
|
end;
|
|
|
|
_ ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'}
|
2003-02-06 20:09:22 +01:00
|
|
|
end;
|
|
|
|
|
2007-09-06 09:45:01 +02:00
|
|
|
set_form(_From, Host, ["config", "access"], _Lang, XData) ->
|
2003-02-06 20:09:22 +01:00
|
|
|
SetAccess =
|
|
|
|
fun(Rs) ->
|
|
|
|
mnesia:transaction(
|
|
|
|
fun() ->
|
|
|
|
Os = mnesia:select(config,
|
2007-09-06 09:45:01 +02:00
|
|
|
[{{config, {access, '$1', '$2'}, '$3'},
|
|
|
|
[{'==', '$2', Host}],
|
2003-02-06 20:09:22 +01:00
|
|
|
['$_']}]),
|
|
|
|
lists:foreach(fun(O) ->
|
|
|
|
mnesia:delete_object(O)
|
|
|
|
end, Os),
|
|
|
|
lists:foreach(
|
|
|
|
fun({access, Name, Rules}) ->
|
|
|
|
mnesia:write({config,
|
2007-09-06 09:45:01 +02:00
|
|
|
{access, Name, Host},
|
2003-02-06 20:09:22 +01:00
|
|
|
Rules})
|
|
|
|
end, Rs)
|
|
|
|
end)
|
|
|
|
end,
|
|
|
|
case lists:keysearch("access", 1, XData) of
|
|
|
|
{value, {_, Strings}} ->
|
|
|
|
String = lists:foldl(fun(S, Res) ->
|
|
|
|
Res ++ S ++ "\n"
|
|
|
|
end, "", Strings),
|
|
|
|
case erl_scan:string(String) of
|
|
|
|
{ok, Tokens, _} ->
|
|
|
|
case erl_parse:parse_term(Tokens) of
|
|
|
|
{ok, Rs} ->
|
|
|
|
case SetAccess(Rs) of
|
|
|
|
{atomic, _} ->
|
|
|
|
{result, []};
|
2007-09-04 09:55:41 +02:00
|
|
|
_ ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'}
|
2003-02-06 20:09:22 +01:00
|
|
|
end;
|
|
|
|
_ ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'}
|
2003-02-06 20:09:22 +01:00
|
|
|
end;
|
|
|
|
_ ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'}
|
2003-02-06 20:09:22 +01:00
|
|
|
end;
|
2003-02-01 21:21:28 +01:00
|
|
|
_ ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'}
|
2003-02-01 21:21:28 +01:00
|
|
|
end;
|
2003-01-21 21:36:55 +01:00
|
|
|
|
2009-01-19 12:59:40 +01:00
|
|
|
set_form(From, Host, ?NS_ADMINL("add-user"), _Lang, XData) ->
|
2007-09-04 09:55:41 +02:00
|
|
|
AccountString = get_value("accountjid", XData),
|
|
|
|
Password = get_value("password", XData),
|
|
|
|
Password = get_value("password-verify", XData),
|
2009-06-01 18:35:55 +02:00
|
|
|
AccountJID = exmpp_jid:parse(AccountString),
|
2009-06-01 18:40:51 +02:00
|
|
|
User = exmpp_jid:prep_node_as_list(AccountJID),
|
2009-06-01 18:38:28 +02:00
|
|
|
Server = exmpp_jid:prep_domain_as_list(AccountJID),
|
2007-09-04 09:55:41 +02:00
|
|
|
true = lists:member(Server, ?MYHOSTS),
|
2009-01-19 12:59:40 +01:00
|
|
|
true = (Server == Host) orelse (get_permission_level(From) == global),
|
2007-09-04 09:55:41 +02:00
|
|
|
ejabberd_auth:try_register(User, Server, Password),
|
2003-01-26 21:16:53 +01:00
|
|
|
{result, []};
|
|
|
|
|
2009-01-19 12:59:40 +01:00
|
|
|
set_form(From, Host, ?NS_ADMINL("delete-user"), _Lang, XData) ->
|
2007-09-04 09:55:41 +02:00
|
|
|
AccountStringList = get_values("accountjids", XData),
|
|
|
|
[_|_] = AccountStringList,
|
|
|
|
ASL2 = lists:map(
|
|
|
|
fun(AccountString) ->
|
2009-06-01 18:35:55 +02:00
|
|
|
JID = exmpp_jid:parse(AccountString),
|
2009-06-01 18:40:51 +02:00
|
|
|
User = [_|_] = exmpp_jid:prep_node_as_list(JID),
|
2009-06-01 18:38:28 +02:00
|
|
|
Server = exmpp_jid:prep_domain_as_list(JID),
|
2009-01-19 12:59:40 +01:00
|
|
|
true = (Server == Host) orelse (get_permission_level(From) == global),
|
2007-09-04 09:55:41 +02:00
|
|
|
true = ejabberd_auth:is_user_exists(User, Server),
|
|
|
|
{User, Server}
|
|
|
|
end,
|
|
|
|
AccountStringList),
|
|
|
|
[ejabberd_auth:remove_user(User, Server) || {User, Server} <- ASL2],
|
|
|
|
{result, []};
|
|
|
|
|
2009-01-19 12:59:40 +01:00
|
|
|
set_form(From, Host, ?NS_ADMINL("end-user-session"), _Lang, XData) ->
|
2007-09-04 09:55:41 +02:00
|
|
|
AccountString = get_value("accountjid", XData),
|
2009-06-01 18:35:55 +02:00
|
|
|
JID = exmpp_jid:parse(AccountString),
|
2009-06-01 18:40:51 +02:00
|
|
|
LUser = [_|_] = exmpp_jid:prep_node_as_list(JID),
|
2009-06-01 18:38:28 +02:00
|
|
|
LServer = exmpp_jid:prep_domain_as_list(JID),
|
2009-01-19 12:59:40 +01:00
|
|
|
true = (LServer == Host) orelse (get_permission_level(From) == global),
|
2007-09-04 09:55:41 +02:00
|
|
|
%% Code copied from ejabberd_sm.erl
|
2009-06-01 18:43:15 +02:00
|
|
|
case exmpp_jid:prep_resource_as_list(JID) of
|
2008-07-25 16:26:59 +02:00
|
|
|
undefined ->
|
2007-09-04 09:55:41 +02:00
|
|
|
SIDs = mnesia:dirty_select(session,
|
|
|
|
[{#session{sid = '$1', usr = {LUser, LServer, '_'}, _ = '_'}, [], ['$1']}]),
|
|
|
|
[Pid ! replaced || {_, Pid} <- SIDs];
|
|
|
|
R ->
|
|
|
|
[{_, Pid}] = mnesia:dirty_select(session,
|
|
|
|
[{#session{sid = '$1', usr = {LUser, LServer, R}, _ = '_'}, [], ['$1']}]),
|
|
|
|
Pid ! replaced
|
|
|
|
end,
|
|
|
|
{result, []};
|
|
|
|
|
2009-01-19 12:59:40 +01:00
|
|
|
set_form(From, Host, ?NS_ADMINL("get-user-password"), Lang, XData) ->
|
2007-09-04 09:55:41 +02:00
|
|
|
AccountString = get_value("accountjid", XData),
|
2009-06-01 18:35:55 +02:00
|
|
|
JID = exmpp_jid:parse(AccountString),
|
2009-06-01 18:40:51 +02:00
|
|
|
User = [_|_] = exmpp_jid:prep_node_as_list(JID),
|
2009-06-01 18:38:28 +02:00
|
|
|
Server = exmpp_jid:prep_domain_as_list(JID),
|
2009-01-19 12:59:40 +01:00
|
|
|
true = (Server == Host) orelse (get_permission_level(From) == global),
|
2007-09-04 09:55:41 +02:00
|
|
|
Password = ejabberd_auth:get_password(User, Server),
|
|
|
|
true = is_list(Password),
|
2008-07-25 16:26:59 +02:00
|
|
|
{result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[?HFIELD(),
|
2009-01-08 15:54:00 +01:00
|
|
|
?XFIELD(<<"jid-single">>, "Jabber ID", <<"accountjid">>, list_to_binary(AccountString)),
|
|
|
|
?XFIELD(<<"text-single">>, "Password", <<"password">>, list_to_binary(Password))
|
2007-09-04 09:55:41 +02:00
|
|
|
]}]};
|
|
|
|
|
2009-01-19 12:59:40 +01:00
|
|
|
set_form(From, Host, ?NS_ADMINL("change-user-password"), _Lang, XData) ->
|
2007-09-04 09:55:41 +02:00
|
|
|
AccountString = get_value("accountjid", XData),
|
|
|
|
Password = get_value("password", XData),
|
2009-06-01 18:35:55 +02:00
|
|
|
JID = exmpp_jid:parse(AccountString),
|
2009-06-01 18:40:51 +02:00
|
|
|
User = [_|_] = exmpp_jid:prep_node_as_list(JID),
|
2009-06-01 18:38:28 +02:00
|
|
|
Server = exmpp_jid:prep_domain_as_list(JID),
|
2009-01-19 12:59:40 +01:00
|
|
|
true = (Server == Host) orelse (get_permission_level(From) == global),
|
2007-09-04 09:55:41 +02:00
|
|
|
true = ejabberd_auth:is_user_exists(User, Server),
|
|
|
|
ejabberd_auth:set_password(User, Server, Password),
|
|
|
|
{result, []};
|
|
|
|
|
2009-01-19 12:59:40 +01:00
|
|
|
set_form(From, Host, ?NS_ADMINL("get-user-lastlogin"), Lang, XData) ->
|
2007-09-04 09:55:41 +02:00
|
|
|
AccountString = get_value("accountjid", XData),
|
2009-06-01 18:35:55 +02:00
|
|
|
JID = exmpp_jid:parse(AccountString),
|
2009-06-01 18:40:51 +02:00
|
|
|
User = [_|_] = exmpp_jid:prep_node_as_list(JID),
|
2009-06-01 18:38:28 +02:00
|
|
|
Server = exmpp_jid:prep_domain_as_list(JID),
|
2009-01-19 12:59:40 +01:00
|
|
|
true = (Server == Host) orelse (get_permission_level(From) == global),
|
2007-09-04 09:55:41 +02:00
|
|
|
|
|
|
|
%% Code copied from web/ejabberd_web_admin.erl
|
|
|
|
%% TODO: Update time format to XEP-0202: Entity Time
|
|
|
|
FLast =
|
2009-06-01 18:39:36 +02:00
|
|
|
case ejabberd_sm:get_user_resources(exmpp_jid:prep_node(User),
|
2009-06-01 18:37:15 +02:00
|
|
|
exmpp_jid:prep_domain(Server)) of
|
2007-09-04 09:55:41 +02:00
|
|
|
[] ->
|
2007-12-07 01:09:48 +01:00
|
|
|
_US = {User, Server},
|
2007-11-27 19:54:06 +01:00
|
|
|
case get_last_info(User, Server) of
|
|
|
|
not_found ->
|
2007-09-04 09:55:41 +02:00
|
|
|
?T(Lang, "Never");
|
2007-11-27 19:54:06 +01:00
|
|
|
{ok, Timestamp, _Status} ->
|
|
|
|
Shift = Timestamp,
|
2007-09-04 09:55:41 +02:00
|
|
|
TimeStamp = {Shift div 1000000,
|
|
|
|
Shift rem 1000000,
|
|
|
|
0},
|
|
|
|
{{Year, Month, Day}, {Hour, Minute, Second}} =
|
|
|
|
calendar:now_to_local_time(TimeStamp),
|
|
|
|
lists:flatten(
|
|
|
|
io_lib:format(
|
|
|
|
"~w-~.2.0w-~.2.0w ~.2.0w:~.2.0w:~.2.0w",
|
|
|
|
[Year, Month, Day, Hour, Minute, Second]))
|
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
?T(Lang, "Online")
|
|
|
|
end,
|
2009-01-21 14:34:26 +01:00
|
|
|
{result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs = [?XMLATTR('type', <<"result">>)], children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[?HFIELD(),
|
2009-01-08 15:54:00 +01:00
|
|
|
?XFIELD(<<"jid-single">>, "Jabber ID", <<"accountjid">>, list_to_binary(AccountString)),
|
|
|
|
?XFIELD(<<"text-single">>, "Last login", <<"lastlogin">>, list_to_binary(FLast))
|
2007-09-04 09:55:41 +02:00
|
|
|
]}]};
|
|
|
|
|
2009-01-19 12:59:40 +01:00
|
|
|
set_form(From, Host, ?NS_ADMINL("user-stats"), Lang, XData) ->
|
2007-09-04 09:55:41 +02:00
|
|
|
AccountString = get_value("accountjid", XData),
|
2009-06-01 18:35:55 +02:00
|
|
|
JID = exmpp_jid:parse(AccountString),
|
2009-06-01 18:40:51 +02:00
|
|
|
User = [_|_] = exmpp_jid:prep_node_as_list(JID),
|
2009-06-01 18:38:28 +02:00
|
|
|
Server = exmpp_jid:prep_domain_as_list(JID),
|
2009-01-19 12:59:40 +01:00
|
|
|
true = (Server == Host) orelse (get_permission_level(From) == global),
|
2007-09-04 09:55:41 +02:00
|
|
|
|
2009-06-01 18:39:36 +02:00
|
|
|
Resources = ejabberd_sm:get_user_resources(exmpp_jid:prep_node(JID),
|
2009-06-01 18:37:15 +02:00
|
|
|
exmpp_jid:prep_domain(JID)),
|
2009-06-01 18:34:38 +02:00
|
|
|
IPs1 = [ejabberd_sm:get_user_ip(exmpp_jid:full(JID,Resource))
|
2009-01-03 16:15:38 +01:00
|
|
|
|| Resource <- Resources],
|
2007-09-04 09:55:41 +02:00
|
|
|
IPs = [inet_parse:ntoa(IP)++":"++integer_to_list(Port) || {IP, Port} <- IPs1],
|
|
|
|
|
2009-01-03 16:15:38 +01:00
|
|
|
Items = ejabberd_hooks:run_fold(roster_get,
|
2009-06-01 18:37:15 +02:00
|
|
|
exmpp_jid:prep_domain(JID),
|
2009-01-03 16:15:38 +01:00
|
|
|
[],
|
|
|
|
[{list_to_binary(User), list_to_binary(Server)}]),
|
2007-09-04 09:55:41 +02:00
|
|
|
Rostersize = integer_to_list(erlang:length(Items)),
|
|
|
|
|
2008-07-25 16:26:59 +02:00
|
|
|
{result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[?HFIELD(),
|
2009-01-08 15:54:00 +01:00
|
|
|
?XFIELD(<<"jid-single">>, "Jabber ID", <<"accountjid">>, AccountString),
|
|
|
|
?XFIELD(<<"text-single">>, "Roster size", <<"rostersize">>, Rostersize),
|
|
|
|
?XMFIELD(<<"text-multi">>, "IP addresses", <<"ipaddresses">>, IPs),
|
|
|
|
?XMFIELD(<<"text-multi">>, "Resources", <<"onlineresources">>, Resources)
|
2007-09-04 09:55:41 +02:00
|
|
|
]}]};
|
|
|
|
|
|
|
|
set_form(_From, _Host, _, _Lang, _XData) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'service-unavailable'}.
|
2003-01-19 21:17:56 +01:00
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
get_value(Field, XData) ->
|
|
|
|
hd(get_values(Field, XData)).
|
|
|
|
get_values(Field, XData) ->
|
|
|
|
{value, {_, ValueList}} = lists:keysearch(Field, 1, XData),
|
|
|
|
ValueList.
|
2003-01-19 21:17:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
search_running_node(SNode) ->
|
|
|
|
search_running_node(SNode, mnesia:system_info(running_db_nodes)).
|
|
|
|
|
|
|
|
search_running_node(_, []) ->
|
|
|
|
false;
|
|
|
|
search_running_node(SNode, [Node | Nodes]) ->
|
|
|
|
case atom_to_list(Node) of
|
|
|
|
SNode ->
|
|
|
|
Node;
|
|
|
|
_ ->
|
|
|
|
search_running_node(SNode, Nodes)
|
|
|
|
end.
|
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
stop_node(From, Host, ENode, Action, XData) ->
|
|
|
|
Delay = list_to_integer(get_value("delay", XData)),
|
|
|
|
Subject = case get_value("subject", XData) of
|
|
|
|
[] -> [];
|
2009-01-21 14:34:26 +01:00
|
|
|
S -> [#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('var', <<"subject">>)], children =
|
2008-07-25 16:26:59 +02:00
|
|
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary(S)}]}]}]
|
2007-09-04 09:55:41 +02:00
|
|
|
end,
|
|
|
|
Announcement = case get_values("announcement", XData) of
|
|
|
|
[] -> [];
|
2009-01-21 14:34:26 +01:00
|
|
|
As -> [#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('var', <<"body">>)], children =
|
2008-07-25 16:26:59 +02:00
|
|
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary(Line)}]} || Line <- As] }]
|
2007-09-04 09:55:41 +02:00
|
|
|
end,
|
|
|
|
case Subject ++ Announcement of
|
|
|
|
[] -> ok;
|
|
|
|
SubEls ->
|
|
|
|
Request = #adhoc_request{
|
2009-01-08 15:54:00 +01:00
|
|
|
node = binary_to_list(?NS_ADMINX(<<"announce-allhosts">>)),
|
2007-09-04 09:55:41 +02:00
|
|
|
action = "complete",
|
2008-07-25 16:26:59 +02:00
|
|
|
xdata = #xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('type', <<"submit">>)], children =
|
2007-09-04 09:55:41 +02:00
|
|
|
SubEls},
|
2008-07-25 16:26:59 +02:00
|
|
|
others= [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('type', <<"submit">>)], children =
|
2007-09-04 09:55:41 +02:00
|
|
|
SubEls}]
|
|
|
|
},
|
2009-06-01 18:26:00 +02:00
|
|
|
To = exmpp_jid:make(Host),
|
2007-09-04 09:55:41 +02:00
|
|
|
mod_announce:announce_commands(empty, From, To, Request)
|
|
|
|
end,
|
|
|
|
Time = timer:seconds(Delay),
|
|
|
|
Node = list_to_atom(ENode),
|
|
|
|
{ok, _} = timer:apply_after(Time, rpc, call, [Node, init, Action, []]),
|
|
|
|
{result, []}.
|
|
|
|
|
|
|
|
|
2007-11-27 19:54:06 +01:00
|
|
|
get_last_info(User, Server) ->
|
|
|
|
ML = lists:member(mod_last, gen_mod:loaded_modules(Server)),
|
|
|
|
MLO = lists:member(mod_last_odbc, gen_mod:loaded_modules(Server)),
|
|
|
|
case {ML, MLO} of
|
|
|
|
{true, _} -> mod_last:get_last_info(User, Server);
|
|
|
|
{false, true} -> mod_last_odbc:get_last_info(User, Server);
|
|
|
|
{false, false} -> not_found
|
|
|
|
end.
|
|
|
|
|
|
|
|
|
2003-01-21 21:36:55 +01:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2003-01-19 21:17:56 +01:00
|
|
|
|
2009-01-03 16:15:38 +01:00
|
|
|
adhoc_sm_commands(_Acc, From, To,
|
2006-01-19 03:17:31 +01:00
|
|
|
#adhoc_request{lang = Lang,
|
|
|
|
node = "config",
|
|
|
|
action = Action,
|
|
|
|
xdata = XData} = Request) ->
|
2009-01-03 16:15:38 +01:00
|
|
|
User = exmpp_jid:node_as_list(To),
|
|
|
|
Server = exmpp_jid:domain_as_list(To),
|
2009-06-01 18:38:28 +02:00
|
|
|
LServer = exmpp_jid:prep_domain_as_list(To),
|
2006-01-19 03:17:31 +01:00
|
|
|
case acl:match_rule(LServer, configure, From) of
|
2003-01-21 21:36:55 +01:00
|
|
|
deny ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'forbidden'};
|
2003-01-21 21:36:55 +01:00
|
|
|
allow ->
|
2006-01-19 03:17:31 +01:00
|
|
|
%% If the "action" attribute is not present, it is
|
|
|
|
%% understood as "execute". If there was no <actions/>
|
|
|
|
%% element in the first response (which there isn't in our
|
|
|
|
%% case), "execute" and "complete" are equivalent.
|
|
|
|
ActionIsExecute = lists:member(Action,
|
|
|
|
["", "execute", "complete"]),
|
|
|
|
if Action == "cancel" ->
|
|
|
|
%% User cancels request
|
|
|
|
adhoc:produce_response(
|
|
|
|
Request,
|
|
|
|
#adhoc_response{status = canceled});
|
|
|
|
XData == false, ActionIsExecute ->
|
|
|
|
%% User requests form
|
|
|
|
case get_sm_form(User, Server, "config", Lang) of
|
|
|
|
{result, Form} ->
|
|
|
|
adhoc:produce_response(
|
|
|
|
Request,
|
|
|
|
#adhoc_response{status = executing,
|
|
|
|
elements = Form});
|
2003-03-09 21:46:47 +01:00
|
|
|
{error, Error} ->
|
2006-01-19 03:17:31 +01:00
|
|
|
{error, Error}
|
|
|
|
end;
|
|
|
|
XData /= false, ActionIsExecute ->
|
|
|
|
%% User returns form.
|
|
|
|
case jlib:parse_xdata_submit(XData) of
|
|
|
|
invalid ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'};
|
2006-01-19 03:17:31 +01:00
|
|
|
Fields ->
|
|
|
|
set_sm_form(User, Server, "config", Request, Fields)
|
|
|
|
end;
|
|
|
|
true ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'bad-request'}
|
2003-01-21 21:36:55 +01:00
|
|
|
end
|
2006-01-19 03:17:31 +01:00
|
|
|
end;
|
2003-01-21 21:36:55 +01:00
|
|
|
|
2006-01-19 03:17:31 +01:00
|
|
|
adhoc_sm_commands(Acc, _From, _To, _Request) ->
|
|
|
|
Acc.
|
2003-01-21 21:36:55 +01:00
|
|
|
|
2006-01-19 03:17:31 +01:00
|
|
|
get_sm_form(User, Server, "config", Lang) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children =
|
2007-09-04 09:55:41 +02:00
|
|
|
[?HFIELD(),
|
2008-07-25 16:26:59 +02:00
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children =
|
|
|
|
[#xmlcdata{cdata =
|
|
|
|
list_to_binary(?T(
|
|
|
|
Lang, "Administration of ") ++ User)}]},
|
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('type', <<"list-single">>),
|
|
|
|
?XMLATTR('label', ?T(Lang, "Action on user")),
|
|
|
|
?XMLATTR('var', <<"action">>)], children =
|
2008-07-25 16:26:59 +02:00
|
|
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = <<"edit">>}]},
|
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'option', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('label', ?T(Lang, "Edit Properties"))], children =
|
2008-07-25 16:26:59 +02:00
|
|
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = <<"edit">>}]}]},
|
|
|
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'option', attrs =
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('label', ?T(Lang, "Remove User"))], children =
|
2008-07-25 16:26:59 +02:00
|
|
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = <<"remove">>}]}]}
|
2004-02-15 21:10:40 +01:00
|
|
|
]},
|
2009-01-08 15:54:00 +01:00
|
|
|
?XFIELD(<<"text-private">>, "Password", <<"password">>,
|
|
|
|
list_to_binary(ejabberd_auth:get_password_s(User, Server)))
|
2007-09-04 09:55:41 +02:00
|
|
|
]}]};
|
2003-01-21 21:36:55 +01:00
|
|
|
|
2005-09-04 03:58:47 +02:00
|
|
|
get_sm_form(_User, _Server, _Node, _Lang) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'service-unavailable'}.
|
2003-01-21 21:36:55 +01:00
|
|
|
|
|
|
|
|
2006-01-19 03:17:31 +01:00
|
|
|
set_sm_form(User, Server, "config",
|
|
|
|
#adhoc_request{lang = Lang,
|
|
|
|
node = Node,
|
|
|
|
sessionid = SessionID}, XData) ->
|
|
|
|
Response = #adhoc_response{lang = Lang,
|
|
|
|
node = Node,
|
|
|
|
sessionid = SessionID,
|
|
|
|
status = completed},
|
2003-10-09 20:09:05 +02:00
|
|
|
case lists:keysearch("action", 1, XData) of
|
|
|
|
{value, {_, ["edit"]}} ->
|
2003-11-09 21:18:36 +01:00
|
|
|
case lists:keysearch("password", 1, XData) of
|
|
|
|
{value, {_, [Password]}} ->
|
2005-04-17 20:08:34 +02:00
|
|
|
ejabberd_auth:set_password(User, Server, Password),
|
2006-01-19 03:17:31 +01:00
|
|
|
adhoc:produce_response(Response);
|
2003-11-09 21:18:36 +01:00
|
|
|
_ ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'not-acceptable'}
|
2003-11-09 21:18:36 +01:00
|
|
|
end;
|
2003-10-09 20:09:05 +02:00
|
|
|
{value, {_, ["remove"]}} ->
|
2005-04-17 20:08:34 +02:00
|
|
|
catch ejabberd_auth:remove_user(User, Server),
|
2006-01-19 03:17:31 +01:00
|
|
|
adhoc:produce_response(Response);
|
2003-10-09 20:09:05 +02:00
|
|
|
_ ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'not-acceptable'}
|
2003-10-09 20:09:05 +02:00
|
|
|
end;
|
2004-02-15 21:10:40 +01:00
|
|
|
|
2006-01-19 03:17:31 +01:00
|
|
|
set_sm_form(_User, _Server, _Node, _Request, _Fields) ->
|
2008-07-25 16:26:59 +02:00
|
|
|
{error, 'service-unavailable'}.
|
2004-02-15 21:10:40 +01:00
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
|
|
|
|
|