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>
|
|
|
|
%%%
|
|
|
|
%%%
|
2019-01-08 22:53:27 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2019 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-12 15:44:42 +01:00
|
|
|
%%%
|
2014-02-22 11:27:40 +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.,
|
|
|
|
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2007-12-24 12:41:41 +01:00
|
|
|
%%%
|
2003-01-19 21:17:56 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(mod_configure).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2007-12-24 12:41:41 +01:00
|
|
|
-author('alexey@process-one.net').
|
2003-01-19 21:17:56 +01:00
|
|
|
|
2015-05-21 17:02:36 +02:00
|
|
|
-protocol({xep, 133, '1.1'}).
|
|
|
|
|
2003-01-24 21:18:33 +01:00
|
|
|
-behaviour(gen_mod).
|
|
|
|
|
2017-02-22 17:46:47 +01:00
|
|
|
-export([start/2, stop/1, reload/3, get_local_identity/5,
|
2013-03-14 10:33:02 +01:00
|
|
|
get_local_features/5, get_local_items/5,
|
|
|
|
adhoc_local_items/4, adhoc_local_commands/4,
|
|
|
|
get_sm_identity/5, get_sm_features/5, get_sm_items/5,
|
2018-01-23 08:54:52 +01:00
|
|
|
adhoc_sm_items/4, adhoc_sm_commands/4, mod_options/1,
|
2016-07-06 13:58:48 +02:00
|
|
|
depends/2]).
|
2003-01-19 21:17:56 +01:00
|
|
|
|
2013-04-08 11:12:54 +02:00
|
|
|
-include("logger.hrl").
|
2016-08-03 09:34:54 +02:00
|
|
|
-include("xmpp.hrl").
|
2016-01-15 13:34:48 +01:00
|
|
|
-include("ejabberd_sm.hrl").
|
2019-06-22 16:08:45 +02:00
|
|
|
-include("translate.hrl").
|
2017-01-13 11:28:55 +01:00
|
|
|
-include_lib("stdlib/include/ms_transform.hrl").
|
2003-01-19 21:17:56 +01:00
|
|
|
|
2006-01-19 03:17:31 +01:00
|
|
|
start(Host, _Opts) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
ejabberd_hooks:add(disco_local_items, Host, ?MODULE,
|
|
|
|
get_local_items, 50),
|
|
|
|
ejabberd_hooks:add(disco_local_features, Host, ?MODULE,
|
|
|
|
get_local_features, 50),
|
|
|
|
ejabberd_hooks:add(disco_local_identity, Host, ?MODULE,
|
|
|
|
get_local_identity, 50),
|
|
|
|
ejabberd_hooks:add(disco_sm_items, Host, ?MODULE,
|
|
|
|
get_sm_items, 50),
|
|
|
|
ejabberd_hooks:add(disco_sm_features, Host, ?MODULE,
|
|
|
|
get_sm_features, 50),
|
|
|
|
ejabberd_hooks:add(disco_sm_identity, Host, ?MODULE,
|
|
|
|
get_sm_identity, 50),
|
|
|
|
ejabberd_hooks:add(adhoc_local_items, Host, ?MODULE,
|
|
|
|
adhoc_local_items, 50),
|
|
|
|
ejabberd_hooks:add(adhoc_local_commands, Host, ?MODULE,
|
|
|
|
adhoc_local_commands, 50),
|
|
|
|
ejabberd_hooks:add(adhoc_sm_items, Host, ?MODULE,
|
|
|
|
adhoc_sm_items, 50),
|
|
|
|
ejabberd_hooks:add(adhoc_sm_commands, Host, ?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) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
ejabberd_hooks:delete(adhoc_sm_commands, Host, ?MODULE,
|
|
|
|
adhoc_sm_commands, 50),
|
|
|
|
ejabberd_hooks:delete(adhoc_sm_items, Host, ?MODULE,
|
|
|
|
adhoc_sm_items, 50),
|
|
|
|
ejabberd_hooks:delete(adhoc_local_commands, Host,
|
|
|
|
?MODULE, adhoc_local_commands, 50),
|
|
|
|
ejabberd_hooks:delete(adhoc_local_items, Host, ?MODULE,
|
|
|
|
adhoc_local_items, 50),
|
|
|
|
ejabberd_hooks:delete(disco_sm_identity, Host, ?MODULE,
|
|
|
|
get_sm_identity, 50),
|
|
|
|
ejabberd_hooks:delete(disco_sm_features, Host, ?MODULE,
|
|
|
|
get_sm_features, 50),
|
|
|
|
ejabberd_hooks:delete(disco_sm_items, Host, ?MODULE,
|
|
|
|
get_sm_items, 50),
|
|
|
|
ejabberd_hooks:delete(disco_local_identity, Host,
|
|
|
|
?MODULE, get_local_identity, 50),
|
|
|
|
ejabberd_hooks:delete(disco_local_features, Host,
|
|
|
|
?MODULE, get_local_features, 50),
|
|
|
|
ejabberd_hooks:delete(disco_local_items, Host, ?MODULE,
|
2017-02-22 17:46:47 +01:00
|
|
|
get_local_items, 50).
|
|
|
|
|
|
|
|
reload(_Host, _NewOpts, _OldOpts) ->
|
|
|
|
ok.
|
2003-01-29 18:12:23 +01:00
|
|
|
|
2016-07-06 13:58:48 +02:00
|
|
|
depends(_Host, _Opts) ->
|
|
|
|
[{mod_adhoc, hard}, {mod_last, soft}].
|
|
|
|
|
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),
|
2019-06-22 16:08:45 +02:00
|
|
|
[#identity{category = Category, type = Type, name = tr(Lang, Name)}]).
|
2005-09-04 03:58:47 +02:00
|
|
|
|
2006-01-19 03:17:31 +01:00
|
|
|
-define(INFO_COMMAND(Name, Lang),
|
2013-03-14 10:33:02 +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),
|
2019-06-22 16:08:45 +02:00
|
|
|
#disco_item{jid = To, name = tr(Lang, Name), node = Node}).
|
2007-09-04 09:55:41 +02:00
|
|
|
|
|
|
|
-define(NODE(Name, Node),
|
2016-08-03 09:34:54 +02:00
|
|
|
#disco_item{jid = jid:make(Server),
|
|
|
|
node = Node,
|
2019-06-22 16:08:45 +02:00
|
|
|
name = tr(Lang, Name)}).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
|
|
|
-define(NS_ADMINX(Sub),
|
|
|
|
<<(?NS_ADMIN)/binary, "#", Sub/binary>>).
|
2007-09-04 09:55:41 +02:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-define(NS_ADMINL(Sub),
|
|
|
|
[<<"http:">>, <<"jabber.org">>, <<"protocol">>,
|
|
|
|
<<"admin">>, Sub]).
|
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec tokenize(binary()) -> [binary()].
|
2013-03-14 10:33:02 +01:00
|
|
|
tokenize(Node) -> str:tokens(Node, <<"/#">>).
|
2007-09-04 09:55:41 +02:00
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec get_sm_identity([identity()], jid(), jid(), binary(), binary()) -> [identity()].
|
2006-01-19 03:17:31 +01:00
|
|
|
get_sm_identity(Acc, _From, _To, Node, Lang) ->
|
|
|
|
case Node of
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"config">> ->
|
2019-06-22 16:08:45 +02:00
|
|
|
?INFO_COMMAND(?T("Configuration"), Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
_ -> Acc
|
2005-09-04 03:58:47 +02:00
|
|
|
end.
|
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec get_local_identity([identity()], jid(), jid(), binary(), binary()) -> [identity()].
|
2006-01-19 03:17:31 +01:00
|
|
|
get_local_identity(Acc, _From, _To, Node, Lang) ->
|
2007-09-04 09:55:41 +02:00
|
|
|
LNode = tokenize(Node),
|
2006-01-19 03:17:31 +01:00
|
|
|
case LNode of
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, ENode] ->
|
|
|
|
?INFO_IDENTITY(<<"ejabberd">>, <<"node">>, ENode, Lang);
|
|
|
|
[<<"running nodes">>, _ENode, <<"DB">>] ->
|
2019-06-22 16:08:45 +02:00
|
|
|
?INFO_COMMAND(?T("Database"), Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"backup">>,
|
|
|
|
<<"backup">>] ->
|
2019-06-22 16:08:45 +02:00
|
|
|
?INFO_COMMAND(?T("Backup"), Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"backup">>,
|
|
|
|
<<"restore">>] ->
|
2019-06-22 16:08:45 +02:00
|
|
|
?INFO_COMMAND(?T("Restore"), Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"backup">>,
|
|
|
|
<<"textfile">>] ->
|
2019-06-22 16:08:45 +02:00
|
|
|
?INFO_COMMAND(?T("Dump to Text File"), Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"import">>,
|
|
|
|
<<"file">>] ->
|
2019-06-22 16:08:45 +02:00
|
|
|
?INFO_COMMAND(?T("Import File"), Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"import">>,
|
|
|
|
<<"dir">>] ->
|
2019-06-22 16:08:45 +02:00
|
|
|
?INFO_COMMAND(?T("Import Directory"), Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"restart">>] ->
|
2019-06-22 16:08:45 +02:00
|
|
|
?INFO_COMMAND(?T("Restart Service"), Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"shutdown">>] ->
|
2019-06-22 16:08:45 +02:00
|
|
|
?INFO_COMMAND(?T("Shut Down Service"), Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"add-user">>) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
?INFO_COMMAND(?T("Add User"), Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"delete-user">>) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
?INFO_COMMAND(?T("Delete User"), Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"end-user-session">>) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
?INFO_COMMAND(?T("End User Session"), Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"get-user-password">>) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
?INFO_COMMAND(?T("Get User Password"), Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"change-user-password">>) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
?INFO_COMMAND(?T("Change User Password"), Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"get-user-lastlogin">>) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
?INFO_COMMAND(?T("Get User Last Login Time"), Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"user-stats">>) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
?INFO_COMMAND(?T("Get User Statistics"), Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"get-registered-users-num">>) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
?INFO_COMMAND(?T("Get Number of Registered Users"),
|
2013-03-14 10:33:02 +01:00
|
|
|
Lang);
|
|
|
|
?NS_ADMINL(<<"get-online-users-num">>) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
?INFO_COMMAND(?T("Get Number of Online Users"), Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
_ -> Acc
|
2005-09-04 03:58:47 +02:00
|
|
|
end.
|
|
|
|
|
2006-01-19 03:17:31 +01:00
|
|
|
%%%-----------------------------------------------------------------------
|
|
|
|
|
2016-04-05 12:09:44 +02:00
|
|
|
-define(INFO_RESULT(Allow, Feats, Lang),
|
2007-09-04 09:55:41 +02:00
|
|
|
case Allow of
|
2019-06-22 16:08:45 +02:00
|
|
|
deny -> {error, xmpp:err_forbidden(?T("Access denied by service policy"), Lang)};
|
2013-03-14 10:33:02 +01:00
|
|
|
allow -> {result, Feats}
|
2007-09-04 09:55:41 +02:00
|
|
|
end).
|
2005-09-04 03:58:47 +02:00
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec get_sm_features(mod_disco:features_acc(), jid(), jid(),
|
|
|
|
binary(), binary()) -> mod_disco:features_acc().
|
2013-03-14 10:33:02 +01:00
|
|
|
get_sm_features(Acc, From,
|
2016-04-05 12:09:44 +02:00
|
|
|
#jid{lserver = LServer} = _To, Node, Lang) ->
|
2006-01-19 03:17:31 +01:00
|
|
|
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
2013-03-14 10:33:02 +01:00
|
|
|
false -> Acc;
|
|
|
|
_ ->
|
|
|
|
Allow = acl:match_rule(LServer, configure, From),
|
|
|
|
case Node of
|
2016-04-05 12:09:44 +02:00
|
|
|
<<"config">> -> ?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
_ -> Acc
|
|
|
|
end
|
2006-01-19 03:17:31 +01:00
|
|
|
end.
|
2005-09-04 03:58:47 +02:00
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec get_local_features(mod_disco:features_acc(), jid(), jid(),
|
|
|
|
binary(), binary()) -> mod_disco:features_acc().
|
2013-03-14 10:33:02 +01:00
|
|
|
get_local_features(Acc, From,
|
2016-04-05 12:09:44 +02:00
|
|
|
#jid{lserver = LServer} = _To, Node, Lang) ->
|
2006-01-19 03:17:31 +01:00
|
|
|
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
2013-03-14 10:33:02 +01:00
|
|
|
false -> Acc;
|
|
|
|
_ ->
|
|
|
|
LNode = tokenize(Node),
|
|
|
|
Allow = acl:match_rule(LServer, configure, From),
|
|
|
|
case LNode of
|
2016-04-05 12:09:44 +02:00
|
|
|
[<<"config">>] -> ?INFO_RESULT(Allow, [], Lang);
|
|
|
|
[<<"user">>] -> ?INFO_RESULT(Allow, [], Lang);
|
|
|
|
[<<"online users">>] -> ?INFO_RESULT(Allow, [], Lang);
|
|
|
|
[<<"all users">>] -> ?INFO_RESULT(Allow, [], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"all users">>, <<$@, _/binary>>] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(Allow, [], Lang);
|
|
|
|
[<<"outgoing s2s">> | _] -> ?INFO_RESULT(Allow, [], Lang);
|
|
|
|
[<<"running nodes">>] -> ?INFO_RESULT(Allow, [], Lang);
|
|
|
|
[<<"stopped nodes">>] -> ?INFO_RESULT(Allow, [], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_STATS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"DB">>] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"backup">>] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(Allow, [], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"backup">>, _] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"import">>] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(Allow, [], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"import">>, _] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"restart">>] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"shutdown">>] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"config">>, _] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"add-user">>) ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"delete-user">>) ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"end-user-session">>) ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"get-user-password">>) ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"change-user-password">>) ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"get-user-lastlogin">>) ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"user-stats">>) ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"get-registered-users-num">>) ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"get-online-users-num">>) ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
_ -> Acc
|
|
|
|
end
|
2005-09-04 03:58:47 +02:00
|
|
|
end.
|
|
|
|
|
2006-01-19 03:17:31 +01:00
|
|
|
%%%-----------------------------------------------------------------------
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec adhoc_sm_items(mod_disco:items_acc(),
|
|
|
|
jid(), jid(), binary()) -> mod_disco:items_acc().
|
2013-03-14 10:33:02 +01:00
|
|
|
adhoc_sm_items(Acc, From, #jid{lserver = LServer} = To,
|
|
|
|
Lang) ->
|
2006-01-19 03:17:31 +01:00
|
|
|
case acl:match_rule(LServer, configure, From) of
|
2013-03-14 10:33:02 +01:00
|
|
|
allow ->
|
|
|
|
Items = case Acc of
|
|
|
|
{result, Its} -> Its;
|
|
|
|
empty -> []
|
|
|
|
end,
|
2016-08-03 09:34:54 +02:00
|
|
|
Nodes = [#disco_item{jid = To, node = <<"config">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
name = tr(Lang, ?T("Configuration"))}],
|
2013-03-14 10:33:02 +01:00
|
|
|
{result, Items ++ Nodes};
|
|
|
|
_ -> Acc
|
2005-09-04 03:58:47 +02:00
|
|
|
end.
|
|
|
|
|
2006-01-19 03:17:31 +01:00
|
|
|
%%%-----------------------------------------------------------------------
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec get_sm_items(mod_disco:items_acc(), jid(), jid(),
|
|
|
|
binary(), binary()) -> mod_disco:items_acc().
|
2006-01-19 03:17:31 +01:00
|
|
|
get_sm_items(Acc, From,
|
2013-03-14 10:33:02 +01:00
|
|
|
#jid{user = User, server = Server, lserver = LServer} =
|
|
|
|
To,
|
2006-01-19 03:17:31 +01:00
|
|
|
Node, Lang) ->
|
|
|
|
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
2013-03-14 10:33:02 +01:00
|
|
|
false -> Acc;
|
|
|
|
_ ->
|
|
|
|
Items = case Acc of
|
|
|
|
{result, Its} -> Its;
|
|
|
|
empty -> []
|
|
|
|
end,
|
|
|
|
case {acl:match_rule(LServer, configure, From), Node} of
|
2016-08-05 07:41:08 +02:00
|
|
|
{allow, <<"">>} ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Nodes = [?NODEJID(To, ?T("Configuration"),
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"config">>),
|
2019-06-22 16:08:45 +02:00
|
|
|
?NODEJID(To, ?T("User Management"), <<"user">>)],
|
2013-03-14 10:33:02 +01:00
|
|
|
{result,
|
|
|
|
Items ++ Nodes ++ get_user_resources(User, Server)};
|
|
|
|
{allow, <<"config">>} -> {result, []};
|
2016-04-05 12:09:44 +02:00
|
|
|
{_, <<"config">>} ->
|
2019-06-22 16:08:45 +02:00
|
|
|
{error, xmpp:err_forbidden(?T("Access denied by service policy"), Lang)};
|
2013-03-14 10:33:02 +01:00
|
|
|
_ -> Acc
|
|
|
|
end
|
2006-01-19 03:17:31 +01:00
|
|
|
end.
|
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec get_user_resources(binary(), binary()) -> [disco_item()].
|
2005-09-04 03:58:47 +02:00
|
|
|
get_user_resources(User, Server) ->
|
|
|
|
Rs = ejabberd_sm:get_user_resources(User, Server),
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:map(fun (R) ->
|
2016-08-03 09:34:54 +02:00
|
|
|
#disco_item{jid = jid:make(User, Server, R),
|
|
|
|
name = User}
|
2013-03-14 10:33:02 +01:00
|
|
|
end,
|
|
|
|
lists:sort(Rs)).
|
2005-09-04 03:58:47 +02:00
|
|
|
|
2006-01-19 03:17:31 +01:00
|
|
|
%%%-----------------------------------------------------------------------
|
2005-09-04 03:58:47 +02:00
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec adhoc_local_items(mod_disco:items_acc(),
|
|
|
|
jid(), jid(), binary()) -> mod_disco:items_acc().
|
2013-03-14 10:33:02 +01:00
|
|
|
adhoc_local_items(Acc, From,
|
|
|
|
#jid{lserver = LServer, server = Server} = To, Lang) ->
|
2006-01-19 03:17:31 +01:00
|
|
|
case acl:match_rule(LServer, configure, From) of
|
2013-03-14 10:33:02 +01:00
|
|
|
allow ->
|
|
|
|
Items = case Acc of
|
|
|
|
{result, Its} -> Its;
|
|
|
|
empty -> []
|
|
|
|
end,
|
|
|
|
PermLev = get_permission_level(From),
|
|
|
|
Nodes = recursively_get_local_items(PermLev, LServer,
|
|
|
|
<<"">>, Server, Lang),
|
2017-01-13 11:36:28 +01:00
|
|
|
Nodes1 = lists:filter(
|
|
|
|
fun (#disco_item{node = Nd}) ->
|
2019-07-10 09:31:51 +02:00
|
|
|
F = get_local_features(empty, From, To, Nd, Lang),
|
2017-01-13 11:36:28 +01:00
|
|
|
case F of
|
|
|
|
{result, [?NS_COMMANDS]} -> true;
|
|
|
|
_ -> false
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
Nodes),
|
2013-03-14 10:33:02 +01:00
|
|
|
{result, Items ++ Nodes1};
|
|
|
|
_ -> Acc
|
2006-01-19 03:17:31 +01:00
|
|
|
end.
|
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec recursively_get_local_items(global | vhost, binary(), binary(),
|
|
|
|
binary(), binary()) -> [disco_item()].
|
2013-03-14 10:33:02 +01:00
|
|
|
recursively_get_local_items(_PermLev, _LServer,
|
|
|
|
<<"online users">>, _Server, _Lang) ->
|
2006-01-19 03:17:31 +01:00
|
|
|
[];
|
2013-03-14 10:33:02 +01:00
|
|
|
recursively_get_local_items(_PermLev, _LServer,
|
|
|
|
<<"all users">>, _Server, _Lang) ->
|
2006-01-19 03:17:31 +01:00
|
|
|
[];
|
2013-03-14 10:33:02 +01:00
|
|
|
recursively_get_local_items(PermLev, LServer, Node,
|
|
|
|
Server, Lang) ->
|
2007-09-04 09:55:41 +02:00
|
|
|
LNode = tokenize(Node),
|
2013-03-14 10:33:02 +01:00
|
|
|
Items = case get_local_items({PermLev, LServer}, LNode,
|
|
|
|
Server, Lang)
|
|
|
|
of
|
|
|
|
{result, Res} -> Res;
|
|
|
|
{error, _Error} -> []
|
2005-09-04 03:58:47 +02:00
|
|
|
end,
|
2016-08-03 09:34:54 +02:00
|
|
|
lists:flatten(
|
|
|
|
lists:map(
|
|
|
|
fun(#disco_item{jid = #jid{server = S}, node = Nd} = Item) ->
|
|
|
|
if (S /= Server) or
|
|
|
|
(Nd == <<"">>) ->
|
|
|
|
[];
|
|
|
|
true ->
|
|
|
|
[Item,
|
|
|
|
recursively_get_local_items(
|
|
|
|
PermLev, LServer, Nd, Server, Lang)]
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
Items)).
|
2006-01-19 03:17:31 +01:00
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec get_permission_level(jid()) -> global | vhost.
|
2009-01-09 01:39:57 +01:00
|
|
|
get_permission_level(JID) ->
|
|
|
|
case acl:match_rule(global, configure, JID) of
|
2013-03-14 10:33:02 +01:00
|
|
|
allow -> global;
|
|
|
|
deny -> vhost
|
2009-01-09 01:39:57 +01:00
|
|
|
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
|
2013-03-14 10:33:02 +01:00
|
|
|
deny -> Fallback;
|
|
|
|
allow ->
|
|
|
|
PermLev = get_permission_level(From),
|
|
|
|
case get_local_items({PermLev, LServer}, LNode,
|
2017-02-26 08:07:12 +01:00
|
|
|
jid:encode(To), Lang)
|
2013-03-14 10:33:02 +01:00
|
|
|
of
|
|
|
|
{result, Res} -> {result, Res};
|
|
|
|
{error, Error} -> {error, Error}
|
|
|
|
end
|
2007-09-04 09:55:41 +02:00
|
|
|
end).
|
2006-01-19 03:17:31 +01:00
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec get_local_items(mod_disco:items_acc(), jid(), jid(),
|
|
|
|
binary(), binary()) -> mod_disco:items_acc().
|
2013-03-14 10:33:02 +01:00
|
|
|
get_local_items(Acc, From, #jid{lserver = LServer} = To,
|
2016-08-05 07:41:08 +02:00
|
|
|
<<"">>, Lang) ->
|
2006-01-19 03:17:31 +01:00
|
|
|
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
2013-03-14 10:33:02 +01:00
|
|
|
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 ->
|
|
|
|
PermLev = get_permission_level(From),
|
|
|
|
case get_local_items({PermLev, LServer}, [],
|
2017-02-26 08:07:12 +01:00
|
|
|
jid:encode(To), Lang)
|
2013-03-14 10:33:02 +01:00
|
|
|
of
|
|
|
|
{result, Res} -> {result, Items ++ Res};
|
|
|
|
{error, _Error} -> {result, Items}
|
|
|
|
end
|
|
|
|
end
|
2006-01-19 03:17:31 +01:00
|
|
|
end;
|
2013-03-14 10:33:02 +01:00
|
|
|
get_local_items(Acc, From, #jid{lserver = LServer} = To,
|
|
|
|
Node, Lang) ->
|
2006-01-19 03:17:31 +01:00
|
|
|
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
2013-03-14 10:33:02 +01:00
|
|
|
false -> Acc;
|
|
|
|
_ ->
|
|
|
|
LNode = tokenize(Node),
|
|
|
|
Allow = acl:match_rule(LServer, configure, From),
|
2019-06-22 16:08:45 +02:00
|
|
|
Err = xmpp:err_forbidden(?T("Access denied by service policy"), Lang),
|
2013-03-14 10:33:02 +01:00
|
|
|
case LNode of
|
|
|
|
[<<"config">>] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"user">>] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"online users">>] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"all users">>] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"all users">>, <<$@, _/binary>>] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"outgoing s2s">> | _] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"stopped nodes">>] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"DB">>] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"backup">>] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"backup">>, _] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"import">>] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"import">>, _] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"restart">>] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"shutdown">>] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"config">>, _] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"add-user">>) ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"delete-user">>) ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"end-user-session">>) ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"get-user-password">>) ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"change-user-password">>) ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"get-user-lastlogin">>) ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"user-stats">>) ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"get-registered-users-num">>) ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(<<"get-online-users-num">>) ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, LNode, {error, Err});
|
2013-03-14 10:33:02 +01:00
|
|
|
_ -> Acc
|
|
|
|
end
|
2005-09-04 03:58:47 +02:00
|
|
|
end.
|
|
|
|
|
2006-01-19 03:17:31 +01:00
|
|
|
%%%-----------------------------------------------------------------------
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec get_local_items({global | vhost, binary()}, [binary()],
|
|
|
|
binary(), binary()) -> {result, [disco_item()]} | {error, stanza_error()}.
|
2005-09-04 03:58:47 +02:00
|
|
|
get_local_items(_Host, [], Server, Lang) ->
|
|
|
|
{result,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?NODE(?T("Configuration"), <<"config">>),
|
|
|
|
?NODE(?T("User Management"), <<"user">>),
|
|
|
|
?NODE(?T("Online Users"), <<"online users">>),
|
|
|
|
?NODE(?T("All Users"), <<"all users">>),
|
|
|
|
?NODE(?T("Outgoing s2s Connections"),
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"outgoing s2s">>),
|
2019-06-22 16:08:45 +02:00
|
|
|
?NODE(?T("Running Nodes"), <<"running nodes">>),
|
|
|
|
?NODE(?T("Stopped Nodes"), <<"stopped nodes">>)]};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_local_items(_Host, [<<"config">>, _], _Server,
|
|
|
|
_Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
{result, []};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_local_items(_Host, [<<"user">>], Server, Lang) ->
|
2007-09-04 09:55:41 +02:00
|
|
|
{result,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?NODE(?T("Add User"), (?NS_ADMINX(<<"add-user">>))),
|
|
|
|
?NODE(?T("Delete User"),
|
2013-03-14 10:33:02 +01:00
|
|
|
(?NS_ADMINX(<<"delete-user">>))),
|
2019-06-22 16:08:45 +02:00
|
|
|
?NODE(?T("End User Session"),
|
2013-03-14 10:33:02 +01:00
|
|
|
(?NS_ADMINX(<<"end-user-session">>))),
|
2019-06-22 16:08:45 +02:00
|
|
|
?NODE(?T("Get User Password"),
|
2013-03-14 10:33:02 +01:00
|
|
|
(?NS_ADMINX(<<"get-user-password">>))),
|
2019-06-22 16:08:45 +02:00
|
|
|
?NODE(?T("Change User Password"),
|
2013-03-14 10:33:02 +01:00
|
|
|
(?NS_ADMINX(<<"change-user-password">>))),
|
2019-06-22 16:08:45 +02:00
|
|
|
?NODE(?T("Get User Last Login Time"),
|
2013-03-14 10:33:02 +01:00
|
|
|
(?NS_ADMINX(<<"get-user-lastlogin">>))),
|
2019-06-22 16:08:45 +02:00
|
|
|
?NODE(?T("Get User Statistics"),
|
2013-03-14 10:33:02 +01:00
|
|
|
(?NS_ADMINX(<<"user-stats">>))),
|
2019-06-22 16:08:45 +02:00
|
|
|
?NODE(?T("Get Number of Registered Users"),
|
2013-03-14 10:33:02 +01:00
|
|
|
(?NS_ADMINX(<<"get-registered-users-num">>))),
|
2019-06-22 16:08:45 +02:00
|
|
|
?NODE(?T("Get Number of Online Users"),
|
2013-03-14 10:33:02 +01:00
|
|
|
(?NS_ADMINX(<<"get-online-users-num">>)))]};
|
|
|
|
get_local_items(_Host, [<<"http:">> | _], _Server,
|
|
|
|
_Lang) ->
|
2007-09-04 09:55:41 +02:00
|
|
|
{result, []};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_local_items({_, Host}, [<<"online users">>],
|
|
|
|
_Server, _Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
{result, get_online_vh_users(Host)};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_local_items({_, Host}, [<<"all users">>], _Server,
|
|
|
|
_Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
{result, get_all_vh_users(Host)};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_local_items({_, Host},
|
|
|
|
[<<"all users">>, <<$@, Diap/binary>>], _Server,
|
|
|
|
_Lang) ->
|
2017-05-11 13:37:21 +02:00
|
|
|
Users = ejabberd_auth:get_users(Host),
|
2016-04-05 12:09:44 +02:00
|
|
|
SUsers = lists:sort([{S, U} || {U, S} <- Users]),
|
2016-08-03 09:34:54 +02:00
|
|
|
try
|
|
|
|
[S1, S2] = ejabberd_regexp:split(Diap, <<"-">>),
|
2016-09-24 22:34:28 +02:00
|
|
|
N1 = binary_to_integer(S1),
|
|
|
|
N2 = binary_to_integer(S2),
|
2016-08-03 09:34:54 +02:00
|
|
|
Sub = lists:sublist(SUsers, N1, N2 - N1 + 1),
|
|
|
|
{result, lists:map(
|
|
|
|
fun({S, U}) ->
|
|
|
|
#disco_item{jid = jid:make(U, S),
|
|
|
|
name = <<U/binary, $@, S/binary>>}
|
|
|
|
end, Sub)}
|
|
|
|
catch _:_ ->
|
2019-07-10 09:31:51 +02:00
|
|
|
{error, xmpp:err_not_acceptable()}
|
2005-09-04 03:58:47 +02:00
|
|
|
end;
|
2013-03-14 10:33:02 +01:00
|
|
|
get_local_items({_, Host}, [<<"outgoing s2s">>],
|
|
|
|
_Server, Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
{result, get_outgoing_s2s(Host, Lang)};
|
2013-03-14 10:33:02 +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)};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_local_items(_Host, [<<"running nodes">>], Server,
|
|
|
|
Lang) ->
|
2007-09-06 09:45:01 +02:00
|
|
|
{result, get_running_nodes(Server, Lang)};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_local_items(_Host, [<<"stopped nodes">>], _Server,
|
|
|
|
Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
{result, get_stopped_nodes(Lang)};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_local_items({global, _Host},
|
|
|
|
[<<"running nodes">>, ENode], Server, Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
{result,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?NODE(?T("Database"),
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"running nodes/", ENode/binary, "/DB">>),
|
2019-06-22 16:08:45 +02:00
|
|
|
?NODE(?T("Backup Management"),
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"running nodes/", ENode/binary, "/backup">>),
|
2019-06-22 16:08:45 +02:00
|
|
|
?NODE(?T("Import Users From jabberd14 Spool Files"),
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"running nodes/", ENode/binary, "/import">>),
|
2019-06-22 16:08:45 +02:00
|
|
|
?NODE(?T("Restart Service"),
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"running nodes/", ENode/binary, "/restart">>),
|
2019-06-22 16:08:45 +02:00
|
|
|
?NODE(?T("Shut Down Service"),
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"running nodes/", ENode/binary, "/shutdown">>)]};
|
|
|
|
get_local_items(_Host,
|
|
|
|
[<<"running nodes">>, _ENode, <<"DB">>], _Server,
|
|
|
|
_Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
{result, []};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_local_items(_Host,
|
|
|
|
[<<"running nodes">>, ENode, <<"backup">>], Server,
|
|
|
|
Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
{result,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?NODE(?T("Backup"),
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"running nodes/", ENode/binary, "/backup/backup">>),
|
2019-06-22 16:08:45 +02:00
|
|
|
?NODE(?T("Restore"),
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"running nodes/", ENode/binary, "/backup/restore">>),
|
2019-06-22 16:08:45 +02:00
|
|
|
?NODE(?T("Dump to Text File"),
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"running nodes/", ENode/binary,
|
|
|
|
"/backup/textfile">>)]};
|
|
|
|
get_local_items(_Host,
|
|
|
|
[<<"running nodes">>, _ENode, <<"backup">>, _], _Server,
|
|
|
|
_Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
{result, []};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_local_items(_Host,
|
|
|
|
[<<"running nodes">>, ENode, <<"import">>], Server,
|
|
|
|
Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
{result,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?NODE(?T("Import File"),
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"running nodes/", ENode/binary, "/import/file">>),
|
2019-06-22 16:08:45 +02:00
|
|
|
?NODE(?T("Import Directory"),
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"running nodes/", ENode/binary, "/import/dir">>)]};
|
|
|
|
get_local_items(_Host,
|
|
|
|
[<<"running nodes">>, _ENode, <<"import">>, _], _Server,
|
|
|
|
_Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
{result, []};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_local_items(_Host,
|
|
|
|
[<<"running nodes">>, _ENode, <<"restart">>], _Server,
|
|
|
|
_Lang) ->
|
2007-09-04 09:55:41 +02:00
|
|
|
{result, []};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_local_items(_Host,
|
|
|
|
[<<"running nodes">>, _ENode, <<"shutdown">>], _Server,
|
|
|
|
_Lang) ->
|
2007-09-04 09:55:41 +02:00
|
|
|
{result, []};
|
2005-09-04 03:58:47 +02:00
|
|
|
get_local_items(_Host, _, _Server, _Lang) ->
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, xmpp:err_item_not_found()}.
|
2005-09-04 03:58:47 +02:00
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec get_online_vh_users(binary()) -> [disco_item()].
|
2005-09-04 03:58:47 +02:00
|
|
|
get_online_vh_users(Host) ->
|
2019-07-15 16:03:29 +02:00
|
|
|
USRs = ejabberd_sm:get_vh_session_list(Host),
|
|
|
|
SURs = lists:sort([{S, U, R} || {U, S, R} <- USRs]),
|
|
|
|
lists:map(
|
|
|
|
fun({S, U, R}) ->
|
|
|
|
#disco_item{jid = jid:make(U, S, R),
|
|
|
|
name = <<U/binary, "@", S/binary>>}
|
|
|
|
end, SURs).
|
2005-09-04 03:58:47 +02:00
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec get_all_vh_users(binary()) -> [disco_item()].
|
2005-09-04 03:58:47 +02:00
|
|
|
get_all_vh_users(Host) ->
|
2019-07-15 16:03:29 +02:00
|
|
|
Users = ejabberd_auth:get_users(Host),
|
|
|
|
SUsers = lists:sort([{S, U} || {U, S} <- Users]),
|
|
|
|
case length(SUsers) of
|
|
|
|
N when N =< 100 ->
|
|
|
|
lists:map(fun({S, U}) ->
|
|
|
|
#disco_item{jid = jid:make(U, S),
|
|
|
|
name = <<U/binary, $@, S/binary>>}
|
|
|
|
end, SUsers);
|
|
|
|
N ->
|
|
|
|
NParts = trunc(math:sqrt(N * 6.17999999999999993783e-1)) + 1,
|
|
|
|
M = trunc(N / NParts) + 1,
|
|
|
|
lists:map(
|
|
|
|
fun (K) ->
|
|
|
|
L = K + M - 1,
|
|
|
|
Node = <<"@",
|
|
|
|
(integer_to_binary(K))/binary,
|
|
|
|
"-",
|
|
|
|
(integer_to_binary(L))/binary>>,
|
|
|
|
{FS, FU} = lists:nth(K, SUsers),
|
|
|
|
{LS, LU} = if L < N -> lists:nth(L, SUsers);
|
|
|
|
true -> lists:last(SUsers)
|
|
|
|
end,
|
|
|
|
Name = <<FU/binary, "@", FS/binary, " -- ",
|
|
|
|
LU/binary, "@", LS/binary>>,
|
|
|
|
#disco_item{jid = jid:make(Host),
|
|
|
|
node = <<"all users/", Node/binary>>,
|
|
|
|
name = Name}
|
|
|
|
end, lists:seq(1, N, M))
|
2005-09-04 03:58:47 +02:00
|
|
|
end.
|
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec get_outgoing_s2s(binary(), binary()) -> [disco_item()].
|
2005-09-04 03:58:47 +02:00
|
|
|
get_outgoing_s2s(Host, Lang) ->
|
2019-07-15 16:03:29 +02:00
|
|
|
Connections = ejabberd_s2s:dirty_get_connections(),
|
|
|
|
DotHost = <<".", Host/binary>>,
|
|
|
|
TConns = [TH || {FH, TH} <- Connections,
|
|
|
|
Host == FH orelse str:suffix(DotHost, FH)],
|
|
|
|
lists:map(
|
|
|
|
fun (T) ->
|
|
|
|
Name = str:format(tr(Lang, ?T("To ~s")),[T]),
|
|
|
|
#disco_item{jid = jid:make(Host),
|
|
|
|
node = <<"outgoing s2s/", T/binary>>,
|
|
|
|
name = Name}
|
|
|
|
end, lists:usort(TConns)).
|
2005-09-04 03:58:47 +02:00
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec get_outgoing_s2s(binary(), binary(), binary()) -> [disco_item()].
|
2005-09-04 03:58:47 +02:00
|
|
|
get_outgoing_s2s(Host, Lang, To) ->
|
2019-07-15 16:03:29 +02:00
|
|
|
Connections = ejabberd_s2s:dirty_get_connections(),
|
|
|
|
lists:map(
|
|
|
|
fun ({F, _T}) ->
|
|
|
|
Node = <<"outgoing s2s/", To/binary, "/", F/binary>>,
|
|
|
|
Name = str:format(tr(Lang, ?T("From ~s")), [F]),
|
|
|
|
#disco_item{jid = jid:make(Host), node = Node, name = Name}
|
|
|
|
end,
|
|
|
|
lists:keysort(
|
|
|
|
1,
|
|
|
|
lists:filter(fun (E) -> element(2, E) == To end,
|
|
|
|
Connections))).
|
2005-09-04 03:58:47 +02:00
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec get_running_nodes(binary(), binary()) -> [disco_item()].
|
2007-09-06 09:45:01 +02:00
|
|
|
get_running_nodes(Server, _Lang) ->
|
2019-07-15 16:03:29 +02:00
|
|
|
DBNodes = mnesia:system_info(running_db_nodes),
|
|
|
|
lists:map(
|
|
|
|
fun (N) ->
|
|
|
|
S = iolist_to_binary(atom_to_list(N)),
|
|
|
|
#disco_item{jid = jid:make(Server),
|
|
|
|
node = <<"running nodes/", S/binary>>,
|
|
|
|
name = S}
|
|
|
|
end, lists:sort(DBNodes)).
|
2005-09-04 03:58:47 +02:00
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec get_stopped_nodes(binary()) -> [disco_item()].
|
2005-09-04 03:58:47 +02:00
|
|
|
get_stopped_nodes(_Lang) ->
|
2019-07-15 16:03:29 +02:00
|
|
|
DBNodes = lists:usort(mnesia:system_info(db_nodes) ++
|
|
|
|
mnesia:system_info(extra_db_nodes))
|
|
|
|
-- mnesia:system_info(running_db_nodes),
|
|
|
|
lists:map(
|
|
|
|
fun (N) ->
|
|
|
|
S = iolist_to_binary(atom_to_list(N)),
|
|
|
|
#disco_item{jid = jid:make(ejabberd_config:get_myname()),
|
|
|
|
node = <<"stopped nodes/", S/binary>>,
|
|
|
|
name = S}
|
|
|
|
end, lists:sort(DBNodes)).
|
2005-09-04 03:58:47 +02:00
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
%%-------------------------------------------------------------------------
|
2005-09-04 03:58:47 +02:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-define(COMMANDS_RESULT(LServerOrGlobal, From, To,
|
2016-04-05 12:09:44 +02:00
|
|
|
Request, Lang),
|
2009-01-09 01:39:57 +01:00
|
|
|
case acl:match_rule(LServerOrGlobal, configure, From) of
|
2019-06-22 16:08:45 +02:00
|
|
|
deny -> {error, xmpp:err_forbidden(?T("Access denied by service policy"), Lang)};
|
2013-03-14 10:33:02 +01:00
|
|
|
allow -> adhoc_local_commands(From, To, Request)
|
2007-09-04 09:55:41 +02:00
|
|
|
end).
|
2006-01-19 03:17:31 +01:00
|
|
|
|
2016-08-09 09:56:32 +02:00
|
|
|
-spec adhoc_local_commands(adhoc_command(), jid(), jid(), adhoc_command()) ->
|
2016-09-08 16:08:48 +02:00
|
|
|
adhoc_command() | {error, stanza_error()}.
|
2013-03-14 10:33:02 +01:00
|
|
|
adhoc_local_commands(Acc, From,
|
|
|
|
#jid{lserver = LServer} = To,
|
2016-08-03 09:34:54 +02:00
|
|
|
#adhoc_command{node = Node, lang = Lang} = Request) ->
|
2007-09-04 09:55:41 +02:00
|
|
|
LNode = tokenize(Node),
|
2006-01-19 03:17:31 +01:00
|
|
|
case LNode of
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"DB">>] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?COMMANDS_RESULT(global, From, To, Request, Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"backup">>, _] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?COMMANDS_RESULT(global, From, To, Request, Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"import">>, _] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?COMMANDS_RESULT(global, From, To, Request, Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"restart">>] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?COMMANDS_RESULT(global, From, To, Request, Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"running nodes">>, _ENode, <<"shutdown">>] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?COMMANDS_RESULT(global, From, To, Request, Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"config">>, _] ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?COMMANDS_RESULT(LServer, From, To, Request, Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMINL(_) ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?COMMANDS_RESULT(LServer, From, To, Request, Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
_ -> Acc
|
2006-01-19 03:17:31 +01:00
|
|
|
end.
|
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec adhoc_local_commands(jid(), jid(), adhoc_command()) -> adhoc_command() | {error, stanza_error()}.
|
2013-03-14 10:33:02 +01:00
|
|
|
adhoc_local_commands(From,
|
|
|
|
#jid{lserver = LServer} = _To,
|
2016-08-03 09:34:54 +02:00
|
|
|
#adhoc_command{lang = Lang, node = Node,
|
|
|
|
sid = SessionID, action = Action,
|
|
|
|
xdata = XData} = Request) ->
|
2007-09-04 09:55:41 +02:00
|
|
|
LNode = tokenize(Node),
|
2016-08-03 09:34:54 +02:00
|
|
|
ActionIsExecute = Action == execute orelse Action == complete,
|
|
|
|
if Action == cancel ->
|
|
|
|
#adhoc_command{status = canceled, lang = Lang,
|
|
|
|
node = Node, sid = SessionID};
|
|
|
|
XData == undefined, ActionIsExecute ->
|
2013-03-14 10:33:02 +01:00
|
|
|
case get_form(LServer, LNode, Lang) of
|
|
|
|
{result, Form} ->
|
2016-08-03 09:34:54 +02:00
|
|
|
xmpp_util:make_adhoc_response(
|
|
|
|
Request,
|
|
|
|
#adhoc_command{status = executing, xdata = Form});
|
2013-03-14 10:33:02 +01:00
|
|
|
{result, Status, Form} ->
|
2016-08-03 09:34:54 +02:00
|
|
|
xmpp_util:make_adhoc_response(
|
|
|
|
Request,
|
|
|
|
#adhoc_command{status = Status, xdata = Form});
|
2013-03-14 10:33:02 +01:00
|
|
|
{error, Error} -> {error, Error}
|
|
|
|
end;
|
2016-08-03 09:34:54 +02:00
|
|
|
XData /= undefined, ActionIsExecute ->
|
2019-07-15 16:03:29 +02:00
|
|
|
case set_form(From, LServer, LNode, Lang, XData) of
|
2016-08-03 09:34:54 +02:00
|
|
|
{result, Res} ->
|
|
|
|
xmpp_util:make_adhoc_response(
|
|
|
|
Request,
|
|
|
|
#adhoc_command{xdata = Res, status = completed});
|
2019-07-15 16:03:29 +02:00
|
|
|
%%{'EXIT', _} -> {error, xmpp:err_bad_request()};
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, Error} -> {error, Error}
|
|
|
|
end;
|
2016-04-05 12:09:44 +02:00
|
|
|
true ->
|
2019-06-22 16:08:45 +02:00
|
|
|
{error, xmpp:err_bad_request(?T("Unexpected action"), Lang)}
|
2003-01-19 21:17:56 +01:00
|
|
|
end.
|
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
-define(TVFIELD(Type, Var, Val),
|
2016-08-03 09:34:54 +02:00
|
|
|
#xdata_field{type = Type, var = Var, values = [Val]}).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
|
|
|
-define(HFIELD(),
|
2016-08-03 09:34:54 +02:00
|
|
|
?TVFIELD(hidden, <<"FORM_TYPE">>, (?NS_ADMIN))).
|
2007-09-04 09:55:41 +02:00
|
|
|
|
2003-01-19 21:17:56 +01:00
|
|
|
-define(TLFIELD(Type, Label, Var),
|
2019-06-22 16:08:45 +02:00
|
|
|
#xdata_field{type = Type, label = tr(Lang, Label), var = Var}).
|
2003-01-19 21:17:56 +01:00
|
|
|
|
2003-01-21 21:36:55 +01:00
|
|
|
-define(XFIELD(Type, Label, Var, Val),
|
2019-06-22 16:08:45 +02:00
|
|
|
#xdata_field{type = Type, label = tr(Lang, Label),
|
2016-08-03 09:34:54 +02:00
|
|
|
var = Var, values = [Val]}).
|
2003-01-21 21:36:55 +01:00
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
-define(XMFIELD(Type, Label, Var, Vals),
|
2019-06-22 16:08:45 +02:00
|
|
|
#xdata_field{type = Type, label = tr(Lang, Label),
|
2016-08-03 09:34:54 +02:00
|
|
|
var = Var, values = Vals}).
|
2007-09-04 09:55:41 +02:00
|
|
|
|
2003-01-19 21:17:56 +01:00
|
|
|
-define(TABLEFIELD(Table, Val),
|
2016-08-03 09:34:54 +02:00
|
|
|
#xdata_field{
|
|
|
|
type = 'list-single',
|
|
|
|
label = iolist_to_binary(atom_to_list(Table)),
|
|
|
|
var = iolist_to_binary(atom_to_list(Table)),
|
|
|
|
values = [iolist_to_binary(atom_to_list(Val))],
|
2019-06-22 16:08:45 +02:00
|
|
|
options = [#xdata_option{label = tr(Lang, ?T("RAM copy")),
|
2016-08-03 09:34:54 +02:00
|
|
|
value = <<"ram_copies">>},
|
2019-06-22 16:08:45 +02:00
|
|
|
#xdata_option{label = tr(Lang, ?T("RAM and disc copy")),
|
2016-08-03 09:34:54 +02:00
|
|
|
value = <<"disc_copies">>},
|
2019-06-22 16:08:45 +02:00
|
|
|
#xdata_option{label = tr(Lang, ?T("Disc only copy")),
|
2016-08-03 09:34:54 +02:00
|
|
|
value = <<"disc_only_copies">>},
|
2019-06-22 16:08:45 +02:00
|
|
|
#xdata_option{label = tr(Lang, ?T("Remote copy")),
|
2016-08-03 09:34:54 +02:00
|
|
|
value = <<"unknown">>}]}).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec get_form(binary(), [binary()], binary()) -> {result, xdata()} |
|
|
|
|
{result, completed, xdata()} |
|
|
|
|
{error, stanza_error()}.
|
2013-03-14 10:33:02 +01:00
|
|
|
get_form(_Host, [<<"running nodes">>, ENode, <<"DB">>],
|
|
|
|
Lang) ->
|
2003-01-19 21:17:56 +01:00
|
|
|
case search_running_node(ENode) of
|
2016-04-05 12:09:44 +02:00
|
|
|
false ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("No running node found"),
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, xmpp:err_item_not_found(Txt, Lang)};
|
2013-03-14 10:33:02 +01:00
|
|
|
Node ->
|
2015-10-07 00:06:58 +02:00
|
|
|
case ejabberd_cluster:call(Node, mnesia, system_info, [tables]) of
|
2016-04-05 12:09:44 +02:00
|
|
|
{badrpc, Reason} ->
|
|
|
|
?ERROR_MSG("RPC call mnesia:system_info(tables) on node "
|
|
|
|
"~s failed: ~p", [Node, Reason]),
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, xmpp:err_internal_server_error()};
|
2013-03-14 10:33:02 +01:00
|
|
|
Tables ->
|
|
|
|
STables = lists:sort(Tables),
|
2019-06-22 16:08:45 +02:00
|
|
|
Title = <<(tr(Lang, ?T("Database Tables Configuration at ")))/binary,
|
2016-08-03 09:34:54 +02:00
|
|
|
ENode/binary>>,
|
2019-06-22 16:08:45 +02:00
|
|
|
Instr = tr(Lang, ?T("Choose storage type of tables")),
|
2016-08-03 09:34:54 +02:00
|
|
|
try
|
|
|
|
Fs = lists:map(
|
|
|
|
fun(Table) ->
|
|
|
|
case ejabberd_cluster:call(
|
|
|
|
Node, mnesia, table_info,
|
|
|
|
[Table, storage_type]) of
|
|
|
|
Type when is_atom(Type) ->
|
|
|
|
?TABLEFIELD(Table, Type)
|
|
|
|
end
|
|
|
|
end, STables),
|
|
|
|
{result, #xdata{title = Title,
|
|
|
|
type = form,
|
|
|
|
instructions = [Instr],
|
|
|
|
fields = [?HFIELD()|Fs]}}
|
|
|
|
catch _:{case_clause, {badrpc, Reason}} ->
|
|
|
|
?ERROR_MSG("RPC call mnesia:table_info/2 "
|
|
|
|
"on node ~s failed: ~p", [Node, Reason]),
|
|
|
|
{error, xmpp:err_internal_server_error()}
|
|
|
|
end
|
2013-03-14 10:33:02 +01:00
|
|
|
end
|
2003-01-19 21:17:56 +01:00
|
|
|
end;
|
2013-03-14 10:33:02 +01:00
|
|
|
get_form(_Host,
|
|
|
|
[<<"running nodes">>, ENode, <<"backup">>,
|
|
|
|
<<"backup">>],
|
|
|
|
Lang) ->
|
|
|
|
{result,
|
2019-06-22 16:08:45 +02:00
|
|
|
#xdata{title = <<(tr(Lang, ?T("Backup to File at ")))/binary, ENode/binary>>,
|
2016-08-03 09:34:54 +02:00
|
|
|
type = form,
|
2019-06-22 16:08:45 +02:00
|
|
|
instructions = [tr(Lang, ?T("Enter path to backup file"))],
|
2016-08-03 09:34:54 +02:00
|
|
|
fields = [?HFIELD(),
|
2019-06-22 16:08:45 +02:00
|
|
|
?XFIELD('text-single', ?T("Path to File"),
|
2016-08-03 09:34:54 +02:00
|
|
|
<<"path">>, <<"">>)]}};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_form(_Host,
|
|
|
|
[<<"running nodes">>, ENode, <<"backup">>,
|
|
|
|
<<"restore">>],
|
|
|
|
Lang) ->
|
|
|
|
{result,
|
2019-06-22 16:08:45 +02:00
|
|
|
#xdata{title = <<(tr(Lang, ?T("Restore Backup from File at ")))/binary,
|
2016-08-03 09:34:54 +02:00
|
|
|
ENode/binary>>,
|
|
|
|
type = form,
|
2019-06-22 16:08:45 +02:00
|
|
|
instructions = [tr(Lang, ?T("Enter path to backup file"))],
|
2016-08-03 09:34:54 +02:00
|
|
|
fields = [?HFIELD(),
|
2019-06-22 16:08:45 +02:00
|
|
|
?XFIELD('text-single', ?T("Path to File"),
|
2016-08-03 09:34:54 +02:00
|
|
|
<<"path">>, <<"">>)]}};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_form(_Host,
|
|
|
|
[<<"running nodes">>, ENode, <<"backup">>,
|
|
|
|
<<"textfile">>],
|
|
|
|
Lang) ->
|
|
|
|
{result,
|
2019-06-22 16:08:45 +02:00
|
|
|
#xdata{title = <<(tr(Lang, ?T("Dump Backup to Text File at ")))/binary,
|
2016-08-03 09:34:54 +02:00
|
|
|
ENode/binary>>,
|
|
|
|
type = form,
|
2019-06-22 16:08:45 +02:00
|
|
|
instructions = [tr(Lang, ?T("Enter path to text file"))],
|
2016-08-03 09:34:54 +02:00
|
|
|
fields = [?HFIELD(),
|
2019-06-22 16:08:45 +02:00
|
|
|
?XFIELD('text-single', ?T("Path to File"),
|
2016-08-03 09:34:54 +02:00
|
|
|
<<"path">>, <<"">>)]}};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_form(_Host,
|
|
|
|
[<<"running nodes">>, ENode, <<"import">>, <<"file">>],
|
|
|
|
Lang) ->
|
|
|
|
{result,
|
2019-06-22 16:08:45 +02:00
|
|
|
#xdata{title = <<(tr(Lang, ?T("Import User from File at ")))/binary,
|
2016-08-03 09:34:54 +02:00
|
|
|
ENode/binary>>,
|
|
|
|
type = form,
|
2019-06-22 16:08:45 +02:00
|
|
|
instructions = [tr(Lang, ?T("Enter path to jabberd14 spool file"))],
|
2016-08-03 09:34:54 +02:00
|
|
|
fields = [?HFIELD(),
|
2019-06-22 16:08:45 +02:00
|
|
|
?XFIELD('text-single', ?T("Path to File"),
|
2016-08-03 09:34:54 +02:00
|
|
|
<<"path">>, <<"">>)]}};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_form(_Host,
|
|
|
|
[<<"running nodes">>, ENode, <<"import">>, <<"dir">>],
|
|
|
|
Lang) ->
|
|
|
|
{result,
|
2019-06-22 16:08:45 +02:00
|
|
|
#xdata{title = <<(tr(Lang, ?T("Import Users from Dir at ")))/binary,
|
2016-08-03 09:34:54 +02:00
|
|
|
ENode/binary>>,
|
|
|
|
type = form,
|
2019-06-22 16:08:45 +02:00
|
|
|
instructions = [tr(Lang, ?T("Enter path to jabberd14 spool dir"))],
|
2016-08-03 09:34:54 +02:00
|
|
|
fields = [?HFIELD(),
|
2019-06-22 16:08:45 +02:00
|
|
|
?XFIELD('text-single', ?T("Path to Dir"),
|
2016-08-03 09:34:54 +02:00
|
|
|
<<"path">>, <<"">>)]}};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_form(_Host,
|
|
|
|
[<<"running nodes">>, _ENode, <<"restart">>], Lang) ->
|
2016-08-03 09:34:54 +02:00
|
|
|
Make_option =
|
|
|
|
fun (LabelNum, LabelUnit, Value) ->
|
|
|
|
#xdata_option{
|
2019-06-22 16:08:45 +02:00
|
|
|
label = <<LabelNum/binary, (tr(Lang, LabelUnit))/binary>>,
|
2016-08-03 09:34:54 +02:00
|
|
|
value = Value}
|
|
|
|
end,
|
2013-03-14 10:33:02 +01:00
|
|
|
{result,
|
2019-06-22 16:08:45 +02:00
|
|
|
#xdata{title = tr(Lang, ?T("Restart Service")),
|
2016-08-03 09:34:54 +02:00
|
|
|
type = form,
|
|
|
|
fields = [?HFIELD(),
|
|
|
|
#xdata_field{
|
|
|
|
type = 'list-single',
|
2019-06-22 16:08:45 +02:00
|
|
|
label = tr(Lang, ?T("Time delay")),
|
2016-08-03 09:34:54 +02:00
|
|
|
var = <<"delay">>,
|
|
|
|
required = true,
|
|
|
|
options =
|
2013-03-14 10:33:02 +01: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">>),
|
2016-08-03 09:34:54 +02:00
|
|
|
Make_option(<<"30 ">>, <<"minutes">>, <<"1800">>)]},
|
|
|
|
#xdata_field{type = fixed,
|
2019-06-22 16:08:45 +02:00
|
|
|
label = tr(Lang,
|
|
|
|
?T("Send announcement to all online users "
|
|
|
|
"on all hosts"))},
|
2016-08-03 09:34:54 +02:00
|
|
|
#xdata_field{var = <<"subject">>,
|
|
|
|
type = 'text-single',
|
2019-06-22 16:08:45 +02:00
|
|
|
label = tr(Lang, ?T("Subject"))},
|
2016-08-03 09:34:54 +02:00
|
|
|
#xdata_field{var = <<"announcement">>,
|
|
|
|
type = 'text-multi',
|
2019-06-22 16:08:45 +02:00
|
|
|
label = tr(Lang, ?T("Message body"))}]}};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_form(_Host,
|
|
|
|
[<<"running nodes">>, _ENode, <<"shutdown">>], Lang) ->
|
2016-08-03 09:34:54 +02:00
|
|
|
Make_option =
|
|
|
|
fun (LabelNum, LabelUnit, Value) ->
|
|
|
|
#xdata_option{
|
2019-06-22 16:08:45 +02:00
|
|
|
label = <<LabelNum/binary, (tr(Lang, LabelUnit))/binary>>,
|
2016-08-03 09:34:54 +02:00
|
|
|
value = Value}
|
|
|
|
end,
|
2013-03-14 10:33:02 +01:00
|
|
|
{result,
|
2019-06-22 16:08:45 +02:00
|
|
|
#xdata{title = tr(Lang, ?T("Shut Down Service")),
|
2016-08-03 09:34:54 +02:00
|
|
|
type = form,
|
|
|
|
fields = [?HFIELD(),
|
|
|
|
#xdata_field{
|
|
|
|
type = 'list-single',
|
2019-06-22 16:08:45 +02:00
|
|
|
label = tr(Lang, ?T("Time delay")),
|
2016-08-03 09:34:54 +02:00
|
|
|
var = <<"delay">>,
|
|
|
|
required = true,
|
|
|
|
options =
|
2013-03-14 10:33:02 +01: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">>),
|
2016-08-03 09:34:54 +02:00
|
|
|
Make_option(<<"30 ">>, <<"minutes">>, <<"1800">>)]},
|
|
|
|
#xdata_field{type = fixed,
|
2019-06-22 16:08:45 +02:00
|
|
|
label = tr(Lang,
|
|
|
|
?T("Send announcement to all online users "
|
|
|
|
"on all hosts"))},
|
2016-08-03 09:34:54 +02:00
|
|
|
#xdata_field{var = <<"subject">>,
|
|
|
|
type = 'text-single',
|
2019-06-22 16:08:45 +02:00
|
|
|
label = tr(Lang, ?T("Subject"))},
|
2016-08-03 09:34:54 +02:00
|
|
|
#xdata_field{var = <<"announcement">>,
|
|
|
|
type = 'text-multi',
|
2019-06-22 16:08:45 +02:00
|
|
|
label = tr(Lang, ?T("Message body"))}]}};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_form(_Host, ?NS_ADMINL(<<"add-user">>), Lang) ->
|
|
|
|
{result,
|
2019-06-22 16:08:45 +02:00
|
|
|
#xdata{title = tr(Lang, ?T("Add User")),
|
2016-08-03 09:34:54 +02:00
|
|
|
type = form,
|
|
|
|
fields = [?HFIELD(),
|
|
|
|
#xdata_field{type = 'jid-single',
|
2019-06-22 16:08:45 +02:00
|
|
|
label = tr(Lang, ?T("Jabber ID")),
|
2016-08-03 09:34:54 +02:00
|
|
|
required = true,
|
|
|
|
var = <<"accountjid">>},
|
|
|
|
#xdata_field{type = 'text-private',
|
2019-06-22 16:08:45 +02:00
|
|
|
label = tr(Lang, ?T("Password")),
|
2016-08-03 09:34:54 +02:00
|
|
|
required = true,
|
|
|
|
var = <<"password">>},
|
|
|
|
#xdata_field{type = 'text-private',
|
2019-06-22 16:08:45 +02:00
|
|
|
label = tr(Lang, ?T("Password Verification")),
|
2016-08-03 09:34:54 +02:00
|
|
|
required = true,
|
|
|
|
var = <<"password-verify">>}]}};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_form(_Host, ?NS_ADMINL(<<"delete-user">>), Lang) ->
|
|
|
|
{result,
|
2019-06-22 16:08:45 +02:00
|
|
|
#xdata{title = tr(Lang, ?T("Delete User")),
|
2016-08-03 09:34:54 +02:00
|
|
|
type = form,
|
|
|
|
fields = [?HFIELD(),
|
|
|
|
#xdata_field{type = 'jid-multi',
|
2019-06-22 16:08:45 +02:00
|
|
|
label = tr(Lang, ?T("Jabber ID")),
|
2016-08-03 09:34:54 +02:00
|
|
|
required = true,
|
|
|
|
var = <<"accountjids">>}]}};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_form(_Host, ?NS_ADMINL(<<"end-user-session">>),
|
|
|
|
Lang) ->
|
|
|
|
{result,
|
2019-06-22 16:08:45 +02:00
|
|
|
#xdata{title = tr(Lang, ?T("End User Session")),
|
2016-08-03 09:34:54 +02:00
|
|
|
type = form,
|
|
|
|
fields = [?HFIELD(),
|
|
|
|
#xdata_field{type = 'jid-single',
|
2019-06-22 16:08:45 +02:00
|
|
|
label = tr(Lang, ?T("Jabber ID")),
|
2016-08-03 09:34:54 +02:00
|
|
|
required = true,
|
|
|
|
var = <<"accountjid">>}]}};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_form(_Host, ?NS_ADMINL(<<"get-user-password">>),
|
|
|
|
Lang) ->
|
|
|
|
{result,
|
2019-06-22 16:08:45 +02:00
|
|
|
#xdata{title = tr(Lang, ?T("Get User Password")),
|
2016-08-03 09:34:54 +02:00
|
|
|
type = form,
|
|
|
|
fields = [?HFIELD(),
|
|
|
|
#xdata_field{type = 'jid-single',
|
2019-06-22 16:08:45 +02:00
|
|
|
label = tr(Lang, ?T("Jabber ID")),
|
2016-08-03 09:34:54 +02:00
|
|
|
var = <<"accountjid">>,
|
|
|
|
required = true}]}};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_form(_Host, ?NS_ADMINL(<<"change-user-password">>),
|
|
|
|
Lang) ->
|
|
|
|
{result,
|
2019-06-22 16:08:45 +02:00
|
|
|
#xdata{title = tr(Lang, ?T("Change User Password")),
|
2016-08-03 09:34:54 +02:00
|
|
|
type = form,
|
|
|
|
fields = [?HFIELD(),
|
|
|
|
#xdata_field{type = 'jid-single',
|
2019-06-22 16:08:45 +02:00
|
|
|
label = tr(Lang, ?T("Jabber ID")),
|
2016-08-03 09:34:54 +02:00
|
|
|
required = true,
|
|
|
|
var = <<"accountjid">>},
|
|
|
|
#xdata_field{type = 'text-private',
|
2019-06-22 16:08:45 +02:00
|
|
|
label = tr(Lang, ?T("Password")),
|
2016-08-03 09:34:54 +02:00
|
|
|
required = true,
|
|
|
|
var = <<"password">>}]}};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_form(_Host, ?NS_ADMINL(<<"get-user-lastlogin">>),
|
|
|
|
Lang) ->
|
|
|
|
{result,
|
2019-06-22 16:08:45 +02:00
|
|
|
#xdata{title = tr(Lang, ?T("Get User Last Login Time")),
|
2016-08-03 09:34:54 +02:00
|
|
|
type = form,
|
|
|
|
fields = [?HFIELD(),
|
|
|
|
#xdata_field{type = 'jid-single',
|
2019-06-22 16:08:45 +02:00
|
|
|
label = tr(Lang, ?T("Jabber ID")),
|
2016-08-03 09:34:54 +02:00
|
|
|
var = <<"accountjid">>,
|
|
|
|
required = true}]}};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_form(_Host, ?NS_ADMINL(<<"user-stats">>), Lang) ->
|
|
|
|
{result,
|
2019-06-22 16:08:45 +02:00
|
|
|
#xdata{title = tr(Lang, ?T("Get User Statistics")),
|
2016-08-03 09:34:54 +02:00
|
|
|
type = form,
|
|
|
|
fields = [?HFIELD(),
|
|
|
|
#xdata_field{type = 'jid-single',
|
2019-06-22 16:08:45 +02:00
|
|
|
label = tr(Lang, ?T("Jabber ID")),
|
2016-08-03 09:34:54 +02:00
|
|
|
var = <<"accountjid">>,
|
|
|
|
required = true}]}};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_form(Host,
|
|
|
|
?NS_ADMINL(<<"get-registered-users-num">>), Lang) ->
|
2017-05-11 13:37:21 +02:00
|
|
|
Num = integer_to_binary(ejabberd_auth:count_users(Host)),
|
2007-09-04 09:55:41 +02:00
|
|
|
{result, completed,
|
2016-08-03 09:34:54 +02:00
|
|
|
#xdata{type = form,
|
|
|
|
fields = [?HFIELD(),
|
|
|
|
#xdata_field{type = 'text-single',
|
2019-06-22 16:08:45 +02:00
|
|
|
label = tr(Lang, ?T("Number of registered users")),
|
2016-08-03 09:34:54 +02:00
|
|
|
var = <<"registeredusersnum">>,
|
|
|
|
values = [Num]}]}};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_form(Host, ?NS_ADMINL(<<"get-online-users-num">>),
|
|
|
|
Lang) ->
|
2016-11-24 13:06:06 +01:00
|
|
|
Num = integer_to_binary(ejabberd_sm:get_vh_session_number(Host)),
|
2007-09-04 09:55:41 +02:00
|
|
|
{result, completed,
|
2016-08-03 09:34:54 +02:00
|
|
|
#xdata{type = form,
|
|
|
|
fields = [?HFIELD(),
|
|
|
|
#xdata_field{type = 'text-single',
|
2019-06-22 16:08:45 +02:00
|
|
|
label = tr(Lang, ?T("Number of online users")),
|
2016-08-03 09:34:54 +02:00
|
|
|
var = <<"onlineusersnum">>,
|
|
|
|
values = [Num]}]}};
|
2006-02-06 06:12:54 +01:00
|
|
|
get_form(_Host, _, _Lang) ->
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, xmpp:err_service_unavailable()}.
|
2003-01-19 21:17:56 +01:00
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec set_form(jid(), binary(), [binary()], binary(), xdata()) -> {result, xdata() | undefined} |
|
|
|
|
{error, stanza_error()}.
|
2013-03-14 10:33:02 +01:00
|
|
|
set_form(_From, _Host,
|
2016-04-05 12:09:44 +02:00
|
|
|
[<<"running nodes">>, ENode, <<"DB">>], Lang, XData) ->
|
2003-01-19 21:17:56 +01:00
|
|
|
case search_running_node(ENode) of
|
2016-04-05 12:09:44 +02:00
|
|
|
false ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("No running node found"),
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, xmpp:err_item_not_found(Txt, Lang)};
|
2013-03-14 10:33:02 +01:00
|
|
|
Node ->
|
2016-08-03 09:34:54 +02:00
|
|
|
lists:foreach(
|
|
|
|
fun(#xdata_field{var = SVar, values = SVals}) ->
|
2017-04-11 12:13:58 +02:00
|
|
|
Table = misc:binary_to_atom(SVar),
|
2016-08-03 09:34:54 +02:00
|
|
|
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#xdata.fields),
|
|
|
|
{result, undefined}
|
2003-01-19 21:17:56 +01:00
|
|
|
end;
|
2013-03-14 10:33:02 +01:00
|
|
|
set_form(_From, _Host,
|
|
|
|
[<<"running nodes">>, ENode, <<"backup">>,
|
|
|
|
<<"backup">>],
|
2016-04-05 12:09:44 +02:00
|
|
|
Lang, XData) ->
|
2003-02-22 20:11:00 +01:00
|
|
|
case search_running_node(ENode) of
|
2016-08-03 09:34:54 +02:00
|
|
|
false ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("No running node found"),
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, xmpp:err_item_not_found(Txt, Lang)};
|
|
|
|
Node ->
|
|
|
|
case xmpp_util:get_xdata_values(<<"path">>, XData) of
|
|
|
|
[] ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("No 'path' found in data form"),
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, xmpp:err_bad_request(Txt, Lang)};
|
|
|
|
[String] ->
|
2019-07-17 19:51:33 +02:00
|
|
|
case ejabberd_cluster:call(
|
|
|
|
Node, mnesia, backup, [binary_to_list(String)],
|
|
|
|
timer:minutes(10)) of
|
2016-08-03 09:34:54 +02:00
|
|
|
{badrpc, Reason} ->
|
|
|
|
?ERROR_MSG("RPC call mnesia:backup(~s) to node ~s "
|
|
|
|
"failed: ~p", [String, Node, Reason]),
|
|
|
|
{error, xmpp:err_internal_server_error()};
|
|
|
|
{error, Reason} ->
|
|
|
|
?ERROR_MSG("RPC call mnesia:backup(~s) to node ~s "
|
|
|
|
"failed: ~p", [String, Node, Reason]),
|
|
|
|
{error, xmpp:err_internal_server_error()};
|
|
|
|
_ ->
|
|
|
|
{result, undefined}
|
|
|
|
end;
|
|
|
|
_ ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("Incorrect value of 'path' in data form"),
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, xmpp:err_bad_request(Txt, Lang)}
|
|
|
|
end
|
2003-02-22 20:11:00 +01:00
|
|
|
end;
|
2013-03-14 10:33:02 +01:00
|
|
|
set_form(_From, _Host,
|
|
|
|
[<<"running nodes">>, ENode, <<"backup">>,
|
|
|
|
<<"restore">>],
|
2016-04-05 12:09:44 +02:00
|
|
|
Lang, XData) ->
|
2003-02-22 20:11:00 +01:00
|
|
|
case search_running_node(ENode) of
|
2016-08-03 09:34:54 +02:00
|
|
|
false ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("No running node found"),
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, xmpp:err_item_not_found(Txt, Lang)};
|
|
|
|
Node ->
|
|
|
|
case xmpp_util:get_xdata_values(<<"path">>, XData) of
|
|
|
|
[] ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("No 'path' found in data form"),
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, xmpp:err_bad_request(Txt, Lang)};
|
|
|
|
[String] ->
|
2019-07-17 19:51:33 +02:00
|
|
|
case ejabberd_cluster:call(
|
|
|
|
Node, ejabberd_admin, restore,
|
|
|
|
[String], timer:minutes(10)) of
|
2016-08-03 09:34:54 +02:00
|
|
|
{badrpc, Reason} ->
|
|
|
|
?ERROR_MSG("RPC call ejabberd_admin:restore(~s) to node "
|
|
|
|
"~s failed: ~p", [String, Node, Reason]),
|
|
|
|
{error, xmpp:err_internal_server_error()};
|
|
|
|
{error, Reason} ->
|
|
|
|
?ERROR_MSG("RPC call ejabberd_admin:restore(~s) to node "
|
|
|
|
"~s failed: ~p", [String, Node, Reason]),
|
|
|
|
{error, xmpp:err_internal_server_error()};
|
|
|
|
_ ->
|
|
|
|
{result, undefined}
|
|
|
|
end;
|
|
|
|
_ ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("Incorrect value of 'path' in data form"),
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, xmpp:err_bad_request(Txt, Lang)}
|
|
|
|
end
|
2003-02-22 20:11:00 +01:00
|
|
|
end;
|
2013-03-14 10:33:02 +01:00
|
|
|
set_form(_From, _Host,
|
|
|
|
[<<"running nodes">>, ENode, <<"backup">>,
|
|
|
|
<<"textfile">>],
|
2016-04-05 12:09:44 +02:00
|
|
|
Lang, XData) ->
|
2003-02-22 20:11:00 +01:00
|
|
|
case search_running_node(ENode) of
|
2016-08-03 09:34:54 +02:00
|
|
|
false ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("No running node found"),
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, xmpp:err_item_not_found(Txt, Lang)};
|
|
|
|
Node ->
|
|
|
|
case xmpp_util:get_xdata_values(<<"path">>, XData) of
|
|
|
|
[] ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("No 'path' found in data form"),
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, xmpp:err_bad_request(Txt, Lang)};
|
|
|
|
[String] ->
|
2019-07-17 19:51:33 +02:00
|
|
|
case ejabberd_cluster:call(
|
|
|
|
Node, ejabberd_admin, dump_to_textfile,
|
|
|
|
[String], timer:minutes(10)) of
|
2016-08-03 09:34:54 +02:00
|
|
|
{badrpc, Reason} ->
|
|
|
|
?ERROR_MSG("RPC call ejabberd_admin:dump_to_textfile(~s) "
|
|
|
|
"to node ~s failed: ~p", [String, Node, Reason]),
|
|
|
|
{error, xmpp:err_internal_server_error()};
|
|
|
|
{error, Reason} ->
|
|
|
|
?ERROR_MSG("RPC call ejabberd_admin:dump_to_textfile(~s) "
|
|
|
|
"to node ~s failed: ~p", [String, Node, Reason]),
|
|
|
|
{error, xmpp:err_internal_server_error()};
|
|
|
|
_ ->
|
|
|
|
{result, undefined}
|
|
|
|
end;
|
|
|
|
_ ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("Incorrect value of 'path' in data form"),
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, xmpp:err_bad_request(Txt, Lang)}
|
|
|
|
end
|
2003-02-22 20:11:00 +01:00
|
|
|
end;
|
2013-03-14 10:33:02 +01:00
|
|
|
set_form(_From, _Host,
|
|
|
|
[<<"running nodes">>, ENode, <<"import">>, <<"file">>],
|
2016-04-05 12:09:44 +02:00
|
|
|
Lang, XData) ->
|
2003-02-04 21:45:23 +01:00
|
|
|
case search_running_node(ENode) of
|
2016-08-03 09:34:54 +02:00
|
|
|
false ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("No running node found"),
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, xmpp:err_item_not_found(Txt, Lang)};
|
|
|
|
Node ->
|
|
|
|
case xmpp_util:get_xdata_values(<<"path">>, XData) of
|
|
|
|
[] ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("No 'path' found in data form"),
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, xmpp:err_bad_request(Txt, Lang)};
|
|
|
|
[String] ->
|
|
|
|
ejabberd_cluster:call(Node, jd2ejd, import_file, [String]),
|
|
|
|
{result, undefined};
|
|
|
|
_ ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("Incorrect value of 'path' in data form"),
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, xmpp:err_bad_request(Txt, Lang)}
|
|
|
|
end
|
2003-02-04 21:45:23 +01:00
|
|
|
end;
|
2013-03-14 10:33:02 +01:00
|
|
|
set_form(_From, _Host,
|
|
|
|
[<<"running nodes">>, ENode, <<"import">>, <<"dir">>],
|
2016-04-05 12:09:44 +02:00
|
|
|
Lang, XData) ->
|
2003-02-04 21:45:23 +01:00
|
|
|
case search_running_node(ENode) of
|
2016-08-03 09:34:54 +02:00
|
|
|
false ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("No running node found"),
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, xmpp:err_item_not_found(Txt, Lang)};
|
|
|
|
Node ->
|
|
|
|
case xmpp_util:get_xdata_values(<<"path">>, XData) of
|
|
|
|
[] ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("No 'path' found in data form"),
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, xmpp:err_bad_request(Txt, Lang)};
|
|
|
|
[String] ->
|
|
|
|
ejabberd_cluster:call(Node, jd2ejd, import_dir, [String]),
|
|
|
|
{result, undefined};
|
|
|
|
_ ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("Incorrect value of 'path' in data form"),
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, xmpp:err_bad_request(Txt, Lang)}
|
|
|
|
end
|
2003-01-28 20:45:13 +01:00
|
|
|
end;
|
2013-03-14 10:33:02 +01:00
|
|
|
set_form(From, Host,
|
|
|
|
[<<"running nodes">>, ENode, <<"restart">>], _Lang,
|
|
|
|
XData) ->
|
2007-09-04 09:55:41 +02:00
|
|
|
stop_node(From, Host, ENode, restart, XData);
|
2013-03-14 10:33:02 +01:00
|
|
|
set_form(From, Host,
|
|
|
|
[<<"running nodes">>, ENode, <<"shutdown">>], _Lang,
|
|
|
|
XData) ->
|
2007-09-04 09:55:41 +02:00
|
|
|
stop_node(From, Host, ENode, stop, XData);
|
2013-03-14 10:33:02 +01:00
|
|
|
set_form(From, Host, ?NS_ADMINL(<<"add-user">>), _Lang,
|
|
|
|
XData) ->
|
|
|
|
AccountString = get_value(<<"accountjid">>, XData),
|
|
|
|
Password = get_value(<<"password">>, XData),
|
|
|
|
Password = get_value(<<"password-verify">>, XData),
|
2017-02-26 08:07:12 +01:00
|
|
|
AccountJID = jid:decode(AccountString),
|
2007-09-04 09:55:41 +02:00
|
|
|
User = AccountJID#jid.luser,
|
|
|
|
Server = AccountJID#jid.lserver,
|
2019-06-14 11:33:26 +02:00
|
|
|
true = lists:member(Server, ejabberd_option:hosts()),
|
2013-03-14 10:33:02 +01:00
|
|
|
true = Server == Host orelse
|
|
|
|
get_permission_level(From) == global,
|
2018-03-12 13:32:24 +01:00
|
|
|
case ejabberd_auth:try_register(User, Server, Password) of
|
|
|
|
ok -> {result, undefined};
|
|
|
|
{error, exists} -> {error, xmpp:err_conflict()};
|
|
|
|
{error, not_allowed} -> {error, xmpp:err_not_allowed()}
|
|
|
|
end;
|
2013-03-14 10:33:02 +01:00
|
|
|
set_form(From, Host, ?NS_ADMINL(<<"delete-user">>),
|
|
|
|
_Lang, XData) ->
|
|
|
|
AccountStringList = get_values(<<"accountjids">>,
|
|
|
|
XData),
|
|
|
|
[_ | _] = AccountStringList,
|
|
|
|
ASL2 = lists:map(fun (AccountString) ->
|
2017-02-26 08:07:12 +01:00
|
|
|
JID = jid:decode(AccountString),
|
2013-03-14 10:33:02 +01:00
|
|
|
User = JID#jid.luser,
|
|
|
|
Server = JID#jid.lserver,
|
|
|
|
true = Server == Host orelse
|
|
|
|
get_permission_level(From) == global,
|
2017-05-11 14:49:06 +02:00
|
|
|
true = ejabberd_auth:user_exists(User, Server),
|
2013-03-14 10:33:02 +01:00
|
|
|
{User, Server}
|
|
|
|
end,
|
|
|
|
AccountStringList),
|
|
|
|
[ejabberd_auth:remove_user(User, Server)
|
|
|
|
|| {User, Server} <- ASL2],
|
2016-08-03 09:34:54 +02:00
|
|
|
{result, undefined};
|
2013-03-14 10:33:02 +01:00
|
|
|
set_form(From, Host, ?NS_ADMINL(<<"end-user-session">>),
|
2018-05-30 18:21:56 +02:00
|
|
|
_Lang, XData) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
AccountString = get_value(<<"accountjid">>, XData),
|
2017-02-26 08:07:12 +01:00
|
|
|
JID = jid:decode(AccountString),
|
2013-03-14 10:33:02 +01:00
|
|
|
LServer = JID#jid.lserver,
|
|
|
|
true = LServer == Host orelse
|
|
|
|
get_permission_level(From) == global,
|
2007-09-04 09:55:41 +02:00
|
|
|
case JID#jid.lresource of
|
2018-05-30 18:21:56 +02:00
|
|
|
<<>> ->
|
|
|
|
ejabberd_sm:kick_user(JID#jid.luser, JID#jid.lserver);
|
|
|
|
R ->
|
|
|
|
ejabberd_sm:kick_user(JID#jid.luser, JID#jid.lserver, R)
|
2013-03-14 10:33:02 +01:00
|
|
|
end,
|
2016-08-03 09:34:54 +02:00
|
|
|
{result, undefined};
|
2013-03-14 10:33:02 +01:00
|
|
|
set_form(From, Host,
|
|
|
|
?NS_ADMINL(<<"get-user-password">>), Lang, XData) ->
|
|
|
|
AccountString = get_value(<<"accountjid">>, XData),
|
2017-02-26 08:07:12 +01:00
|
|
|
JID = jid:decode(AccountString),
|
2013-03-14 10:33:02 +01:00
|
|
|
User = JID#jid.luser,
|
|
|
|
Server = JID#jid.lserver,
|
|
|
|
true = Server == Host orelse
|
|
|
|
get_permission_level(From) == global,
|
2007-09-04 09:55:41 +02:00
|
|
|
Password = ejabberd_auth:get_password(User, Server),
|
2013-03-14 10:33:02 +01:00
|
|
|
true = is_binary(Password),
|
|
|
|
{result,
|
2016-08-03 09:34:54 +02:00
|
|
|
#xdata{type = form,
|
|
|
|
fields = [?HFIELD(),
|
2019-06-22 16:08:45 +02:00
|
|
|
?XFIELD('jid-single', ?T("Jabber ID"),
|
2016-08-03 09:34:54 +02:00
|
|
|
<<"accountjid">>, AccountString),
|
2019-06-22 16:08:45 +02:00
|
|
|
?XFIELD('text-single', ?T("Password"),
|
2016-08-03 09:34:54 +02:00
|
|
|
<<"password">>, Password)]}};
|
2013-03-14 10:33:02 +01:00
|
|
|
set_form(From, Host,
|
|
|
|
?NS_ADMINL(<<"change-user-password">>), _Lang, XData) ->
|
|
|
|
AccountString = get_value(<<"accountjid">>, XData),
|
|
|
|
Password = get_value(<<"password">>, XData),
|
2017-02-26 08:07:12 +01:00
|
|
|
JID = jid:decode(AccountString),
|
2013-03-14 10:33:02 +01:00
|
|
|
User = JID#jid.luser,
|
|
|
|
Server = JID#jid.lserver,
|
|
|
|
true = Server == Host orelse
|
|
|
|
get_permission_level(From) == global,
|
2017-05-11 14:49:06 +02:00
|
|
|
true = ejabberd_auth:user_exists(User, Server),
|
2007-09-04 09:55:41 +02:00
|
|
|
ejabberd_auth:set_password(User, Server, Password),
|
2016-08-03 09:34:54 +02:00
|
|
|
{result, undefined};
|
2013-03-14 10:33:02 +01:00
|
|
|
set_form(From, Host,
|
|
|
|
?NS_ADMINL(<<"get-user-lastlogin">>), Lang, XData) ->
|
|
|
|
AccountString = get_value(<<"accountjid">>, XData),
|
2017-02-26 08:07:12 +01:00
|
|
|
JID = jid:decode(AccountString),
|
2013-03-14 10:33:02 +01:00
|
|
|
User = JID#jid.luser,
|
|
|
|
Server = JID#jid.lserver,
|
|
|
|
true = Server == Host orelse
|
|
|
|
get_permission_level(From) == global,
|
|
|
|
FLast = case ejabberd_sm:get_user_resources(User,
|
|
|
|
Server)
|
|
|
|
of
|
|
|
|
[] ->
|
|
|
|
case get_last_info(User, Server) of
|
2019-06-22 16:08:45 +02:00
|
|
|
not_found -> tr(Lang, ?T("Never"));
|
2007-11-27 19:54:06 +01:00
|
|
|
{ok, Timestamp, _Status} ->
|
|
|
|
Shift = Timestamp,
|
2013-03-14 10:33:02 +01:00
|
|
|
TimeStamp = {Shift div 1000000, Shift rem 1000000, 0},
|
2007-09-04 09:55:41 +02:00
|
|
|
{{Year, Month, Day}, {Hour, Minute, Second}} =
|
|
|
|
calendar:now_to_local_time(TimeStamp),
|
2016-11-24 13:06:06 +01:00
|
|
|
(str:format("~w-~.2.0w-~.2.0w ~.2.0w:~.2.0w:~.2.0w",
|
2013-03-14 10:33:02 +01:00
|
|
|
[Year, Month, Day, Hour,
|
|
|
|
Minute, Second]))
|
|
|
|
end;
|
2019-06-22 16:08:45 +02:00
|
|
|
_ -> tr(Lang, ?T("Online"))
|
2013-03-14 10:33:02 +01:00
|
|
|
end,
|
|
|
|
{result,
|
2016-08-03 09:34:54 +02:00
|
|
|
#xdata{type = form,
|
|
|
|
fields = [?HFIELD(),
|
2019-06-22 16:08:45 +02:00
|
|
|
?XFIELD('jid-single', ?T("Jabber ID"),
|
2016-08-03 09:34:54 +02:00
|
|
|
<<"accountjid">>, AccountString),
|
2019-06-22 16:08:45 +02:00
|
|
|
?XFIELD('text-single', ?T("Last login"),
|
2016-08-03 09:34:54 +02:00
|
|
|
<<"lastlogin">>, FLast)]}};
|
2013-03-14 10:33:02 +01:00
|
|
|
set_form(From, Host, ?NS_ADMINL(<<"user-stats">>), Lang,
|
|
|
|
XData) ->
|
|
|
|
AccountString = get_value(<<"accountjid">>, XData),
|
2017-02-26 08:07:12 +01:00
|
|
|
JID = jid:decode(AccountString),
|
2013-03-14 10:33:02 +01:00
|
|
|
User = JID#jid.luser,
|
|
|
|
Server = JID#jid.lserver,
|
|
|
|
true = Server == Host orelse
|
|
|
|
get_permission_level(From) == global,
|
|
|
|
Resources = ejabberd_sm:get_user_resources(User,
|
|
|
|
Server),
|
|
|
|
IPs1 = [ejabberd_sm:get_user_ip(User, Server, Resource)
|
|
|
|
|| Resource <- Resources],
|
2017-04-11 12:13:58 +02:00
|
|
|
IPs = [<<(misc:ip_to_list(IP))/binary, ":",
|
2016-09-24 22:34:28 +02:00
|
|
|
(integer_to_binary(Port))/binary>>
|
2013-03-14 10:33:02 +01:00
|
|
|
|| {IP, Port} <- IPs1],
|
|
|
|
Items = ejabberd_hooks:run_fold(roster_get, Server, [],
|
|
|
|
[{User, Server}]),
|
2016-09-24 22:34:28 +02:00
|
|
|
Rostersize = integer_to_binary(erlang:length(Items)),
|
2013-03-14 10:33:02 +01:00
|
|
|
{result,
|
2016-08-03 09:34:54 +02:00
|
|
|
#xdata{type = form,
|
|
|
|
fields = [?HFIELD(),
|
2019-06-22 16:08:45 +02:00
|
|
|
?XFIELD('jid-single', ?T("Jabber ID"),
|
2016-08-03 09:34:54 +02:00
|
|
|
<<"accountjid">>, AccountString),
|
2019-06-22 16:08:45 +02:00
|
|
|
?XFIELD('text-single', ?T("Roster size"),
|
2016-08-03 09:34:54 +02:00
|
|
|
<<"rostersize">>, Rostersize),
|
2019-06-22 16:08:45 +02:00
|
|
|
?XMFIELD('text-multi', ?T("IP addresses"),
|
2016-08-03 09:34:54 +02:00
|
|
|
<<"ipaddresses">>, IPs),
|
2019-06-22 16:08:45 +02:00
|
|
|
?XMFIELD('text-multi', ?T("Resources"),
|
2016-08-03 09:34:54 +02:00
|
|
|
<<"onlineresources">>, Resources)]}};
|
2007-09-04 09:55:41 +02:00
|
|
|
set_form(_From, _Host, _, _Lang, _XData) ->
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, xmpp:err_service_unavailable()}.
|
2003-01-19 21:17:56 +01:00
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec get_value(binary(), xdata()) -> binary().
|
|
|
|
get_value(Field, XData) ->
|
|
|
|
hd(get_values(Field, XData)).
|
2003-01-19 21:17:56 +01:00
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec get_values(binary(), xdata()) -> [binary()].
|
2013-03-14 10:33:02 +01:00
|
|
|
get_values(Field, XData) ->
|
2016-08-09 09:56:32 +02:00
|
|
|
xmpp_util:get_xdata_values(Field, XData).
|
2003-01-19 21:17:56 +01:00
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec search_running_node(binary()) -> false | node().
|
2003-01-19 21:17:56 +01:00
|
|
|
search_running_node(SNode) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
search_running_node(SNode,
|
|
|
|
mnesia:system_info(running_db_nodes)).
|
2003-01-19 21:17:56 +01:00
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec search_running_node(binary(), [node()]) -> false | node().
|
2013-03-14 10:33:02 +01:00
|
|
|
search_running_node(_, []) -> false;
|
2003-01-19 21:17:56 +01:00
|
|
|
search_running_node(SNode, [Node | Nodes]) ->
|
2019-07-10 09:31:51 +02:00
|
|
|
case atom_to_binary(Node, utf8) of
|
|
|
|
SNode -> Node;
|
|
|
|
_ -> search_running_node(SNode, Nodes)
|
2003-01-19 21:17:56 +01:00
|
|
|
end.
|
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec stop_node(jid(), binary(), binary(), restart | stop, xdata()) -> {result, undefined}.
|
2007-09-04 09:55:41 +02:00
|
|
|
stop_node(From, Host, ENode, Action, XData) ->
|
2016-09-24 22:34:28 +02:00
|
|
|
Delay = binary_to_integer(get_value(<<"delay">>, XData)),
|
2019-07-15 16:03:29 +02:00
|
|
|
Subject = case get_values(<<"subject">>, XData) of
|
|
|
|
[] ->
|
2016-08-03 09:34:54 +02:00
|
|
|
[];
|
2019-07-15 16:03:29 +02:00
|
|
|
[S|_] ->
|
2016-08-03 09:34:54 +02:00
|
|
|
[#xdata_field{var = <<"subject">>, values = [S]}]
|
2007-09-04 09:55:41 +02:00
|
|
|
end,
|
2016-08-03 09:34:54 +02:00
|
|
|
Announcement = case get_values(<<"announcement">>, XData) of
|
|
|
|
[] ->
|
|
|
|
[];
|
|
|
|
As ->
|
|
|
|
[#xdata_field{var = <<"body">>, values = As}]
|
2007-09-04 09:55:41 +02:00
|
|
|
end,
|
|
|
|
case Subject ++ Announcement of
|
2016-08-03 09:34:54 +02:00
|
|
|
[] ->
|
|
|
|
ok;
|
|
|
|
Fields ->
|
|
|
|
Request = #adhoc_command{node = ?NS_ADMINX(<<"announce-allhosts">>),
|
|
|
|
action = complete,
|
|
|
|
xdata = #xdata{type = submit,
|
|
|
|
fields = Fields}},
|
|
|
|
To = jid:make(Host),
|
|
|
|
mod_announce:announce_commands(empty, From, To, Request)
|
2007-09-04 09:55:41 +02:00
|
|
|
end,
|
|
|
|
Time = timer:seconds(Delay),
|
2017-04-11 12:13:58 +02:00
|
|
|
Node = misc:binary_to_atom(ENode),
|
2019-07-10 09:31:51 +02:00
|
|
|
{ok, _} = timer:apply_after(Time, ejabberd_cluster, call, [Node, init, Action, []]),
|
2016-08-03 09:34:54 +02:00
|
|
|
{result, undefined}.
|
2007-09-04 09:55:41 +02:00
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec get_last_info(binary(), binary()) -> {ok, non_neg_integer(), binary()} | not_found.
|
2007-11-27 19:54:06 +01:00
|
|
|
get_last_info(User, Server) ->
|
2012-04-27 11:52:05 +02:00
|
|
|
case gen_mod:is_loaded(Server, mod_last) of
|
2013-03-14 10:33:02 +01:00
|
|
|
true -> mod_last:get_last_info(User, Server);
|
|
|
|
false -> not_found
|
2007-11-27 19:54:06 +01:00
|
|
|
end.
|
|
|
|
|
2003-01-21 21:36:55 +01:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec adhoc_sm_commands(adhoc_command(), jid(), jid(), adhoc_command()) -> adhoc_command() |
|
|
|
|
{error, stanza_error()}.
|
2006-01-19 03:17:31 +01:00
|
|
|
adhoc_sm_commands(_Acc, From,
|
2016-08-03 09:34:54 +02:00
|
|
|
#jid{user = User, server = Server, lserver = LServer},
|
|
|
|
#adhoc_command{lang = Lang, node = <<"config">>,
|
|
|
|
action = Action, xdata = XData} = Request) ->
|
2006-01-19 03:17:31 +01:00
|
|
|
case acl:match_rule(LServer, configure, From) of
|
2016-08-03 09:34:54 +02:00
|
|
|
deny ->
|
2019-06-22 16:08:45 +02:00
|
|
|
{error, xmpp:err_forbidden(?T("Access denied by service policy"), Lang)};
|
2016-08-03 09:34:54 +02:00
|
|
|
allow ->
|
|
|
|
ActionIsExecute = Action == execute orelse Action == complete,
|
|
|
|
if Action == cancel ->
|
|
|
|
xmpp_util:make_adhoc_response(
|
|
|
|
Request, #adhoc_command{status = canceled});
|
|
|
|
XData == undefined, ActionIsExecute ->
|
|
|
|
case get_sm_form(User, Server, <<"config">>, Lang) of
|
|
|
|
{result, Form} ->
|
|
|
|
xmpp_util:make_adhoc_response(
|
|
|
|
Request, #adhoc_command{status = executing,
|
|
|
|
xdata = Form});
|
|
|
|
{error, Error} ->
|
|
|
|
{error, Error}
|
|
|
|
end;
|
|
|
|
XData /= undefined, ActionIsExecute ->
|
|
|
|
set_sm_form(User, Server, <<"config">>, Request);
|
|
|
|
true ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("Unexpected action"),
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, xmpp:err_bad_request(Txt, Lang)}
|
|
|
|
end
|
2006-01-19 03:17:31 +01:00
|
|
|
end;
|
2013-03-14 10:33:02 +01:00
|
|
|
adhoc_sm_commands(Acc, _From, _To, _Request) -> Acc.
|
2003-01-21 21:36:55 +01:00
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec get_sm_form(binary(), binary(), binary(), binary()) -> {result, xdata()} |
|
|
|
|
{error, stanza_error()}.
|
2013-03-14 10:33:02 +01:00
|
|
|
get_sm_form(User, Server, <<"config">>, Lang) ->
|
|
|
|
{result,
|
2016-08-03 09:34:54 +02:00
|
|
|
#xdata{type = form,
|
2019-06-22 16:08:45 +02:00
|
|
|
title = <<(tr(Lang, ?T("Administration of ")))/binary, User/binary>>,
|
2016-08-03 09:34:54 +02:00
|
|
|
fields =
|
|
|
|
[?HFIELD(),
|
|
|
|
#xdata_field{
|
|
|
|
type = 'list-single',
|
2019-06-22 16:08:45 +02:00
|
|
|
label = tr(Lang, ?T("Action on user")),
|
2016-08-03 09:34:54 +02:00
|
|
|
var = <<"action">>,
|
|
|
|
values = [<<"edit">>],
|
|
|
|
options = [#xdata_option{
|
2019-06-22 16:08:45 +02:00
|
|
|
label = tr(Lang, ?T("Edit Properties")),
|
2016-08-03 09:34:54 +02:00
|
|
|
value = <<"edit">>},
|
|
|
|
#xdata_option{
|
2019-06-22 16:08:45 +02:00
|
|
|
label = tr(Lang, ?T("Remove User")),
|
2016-08-03 09:34:54 +02:00
|
|
|
value = <<"remove">>}]},
|
2019-06-22 16:08:45 +02:00
|
|
|
?XFIELD('text-private', ?T("Password"),
|
2016-08-03 09:34:54 +02:00
|
|
|
<<"password">>,
|
|
|
|
ejabberd_auth:get_password_s(User, Server))]}};
|
2005-09-04 03:58:47 +02:00
|
|
|
get_sm_form(_User, _Server, _Node, _Lang) ->
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, xmpp:err_service_unavailable()}.
|
2003-01-21 21:36:55 +01:00
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec set_sm_form(binary(), binary(), binary(), adhoc_command()) -> adhoc_command() |
|
|
|
|
{error, stanza_error()}.
|
2013-03-14 10:33:02 +01:00
|
|
|
set_sm_form(User, Server, <<"config">>,
|
2016-08-03 09:34:54 +02:00
|
|
|
#adhoc_command{lang = Lang, node = Node,
|
|
|
|
sid = SessionID, xdata = XData}) ->
|
|
|
|
Response = #adhoc_command{lang = Lang, node = Node,
|
|
|
|
sid = SessionID, status = completed},
|
|
|
|
case xmpp_util:get_xdata_values(<<"action">>, XData) of
|
|
|
|
[<<"edit">>] ->
|
|
|
|
case xmpp_util:get_xdata_values(<<"password">>, XData) of
|
|
|
|
[Password] ->
|
|
|
|
ejabberd_auth:set_password(User, Server, Password),
|
|
|
|
xmpp_util:make_adhoc_response(Response);
|
|
|
|
_ ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("No 'password' found in data form"),
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, xmpp:err_not_acceptable(Txt, Lang)}
|
|
|
|
end;
|
|
|
|
[<<"remove">>] ->
|
2019-07-15 16:03:29 +02:00
|
|
|
ejabberd_auth:remove_user(User, Server),
|
2016-08-03 09:34:54 +02:00
|
|
|
xmpp_util:make_adhoc_response(Response);
|
|
|
|
_ ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("Incorrect value of 'action' in data form"),
|
2016-08-03 09:34:54 +02:00
|
|
|
{error, xmpp:err_not_acceptable(Txt, Lang)}
|
2003-10-09 20:09:05 +02:00
|
|
|
end;
|
2016-08-03 09:34:54 +02:00
|
|
|
set_sm_form(_User, _Server, _Node, _Request) ->
|
|
|
|
{error, xmpp:err_service_unavailable()}.
|
2015-06-01 14:38:27 +02:00
|
|
|
|
2019-06-22 16:08:45 +02:00
|
|
|
-spec tr(binary(), binary()) -> binary().
|
|
|
|
tr(Lang, Text) ->
|
|
|
|
translate:translate(Lang, Text).
|
|
|
|
|
2018-01-23 08:54:52 +01:00
|
|
|
mod_options(_) -> [].
|