2004-04-26 17:38:07 +02:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : ejabberd_web_admin.erl
|
2007-08-31 18:13:35 +02:00
|
|
|
%%% Author : Alexey Shchepin <alexey@process-one.net>
|
2004-05-22 21:48:35 +02:00
|
|
|
%%% Purpose : Administration web interface
|
2007-08-31 18:13:35 +02:00
|
|
|
%%% Created : 9 Apr 2004 by Alexey Shchepin <alexey@process-one.net>
|
2007-12-24 12:41:41 +01:00
|
|
|
%%%
|
|
|
|
%%%
|
2023-01-09 17:09:06 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2023 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
|
|
|
%%%
|
2004-10-05 21:31:17 +02:00
|
|
|
%%%----------------------------------------------------------------------
|
2004-04-26 17:38:07 +02:00
|
|
|
|
2009-06-23 22:45:39 +02:00
|
|
|
%%%% definitions
|
|
|
|
|
2004-04-26 17:38:07 +02:00
|
|
|
-module(ejabberd_web_admin).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2007-08-31 18:13:35 +02:00
|
|
|
-author('alexey@process-one.net').
|
2004-04-26 17:38:07 +02:00
|
|
|
|
2020-03-26 13:43:24 +01:00
|
|
|
-export([process/2, list_users/4,
|
|
|
|
list_users_in_diapason/4, pretty_print_xml/1,
|
2019-06-14 11:33:26 +02:00
|
|
|
term_to_id/1]).
|
2004-04-26 17:38:07 +02:00
|
|
|
|
2013-04-08 11:12:54 +02:00
|
|
|
-include("logger.hrl").
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2020-09-03 13:45:57 +02:00
|
|
|
-include_lib("xmpp/include/xmpp.hrl").
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2004-04-26 17:38:07 +02:00
|
|
|
-include("ejabberd_http.hrl").
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2007-08-23 02:51:54 +02:00
|
|
|
-include("ejabberd_web_admin.hrl").
|
2004-04-26 17:38:07 +02:00
|
|
|
|
2019-06-22 16:08:45 +02:00
|
|
|
-include("translate.hrl").
|
|
|
|
|
2009-05-27 19:28:55 +02:00
|
|
|
-define(INPUTATTRS(Type, Name, Value, Attrs),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XA(<<"input">>,
|
|
|
|
(Attrs ++
|
|
|
|
[{<<"type">>, Type}, {<<"name">>, Name},
|
|
|
|
{<<"value">>, Value}]))).
|
2009-05-27 19:28:55 +02:00
|
|
|
|
2009-06-23 23:00:43 +02:00
|
|
|
%%%==================================
|
|
|
|
%%%% get_acl_access
|
|
|
|
|
2022-05-12 17:25:11 +02:00
|
|
|
-spec get_acl_rule(Path::[binary()], 'GET' | 'POST') ->
|
|
|
|
{HostOfRule::binary(), [AccessRule::atom()]}.
|
2009-06-23 23:00:43 +02:00
|
|
|
|
|
|
|
%% All accounts can access those URLs
|
2013-03-14 10:33:02 +01:00
|
|
|
get_acl_rule([], _) -> {<<"localhost">>, [all]};
|
|
|
|
get_acl_rule([<<"style.css">>], _) ->
|
|
|
|
{<<"localhost">>, [all]};
|
|
|
|
get_acl_rule([<<"logo.png">>], _) ->
|
|
|
|
{<<"localhost">>, [all]};
|
|
|
|
get_acl_rule([<<"logo-fill.png">>], _) ->
|
|
|
|
{<<"localhost">>, [all]};
|
|
|
|
get_acl_rule([<<"favicon.ico">>], _) ->
|
|
|
|
{<<"localhost">>, [all]};
|
|
|
|
get_acl_rule([<<"additions.js">>], _) ->
|
|
|
|
{<<"localhost">>, [all]};
|
2009-06-23 23:00:43 +02:00
|
|
|
%% This page only displays vhosts that the user is admin:
|
2013-03-14 10:33:02 +01:00
|
|
|
get_acl_rule([<<"vhosts">>], _) ->
|
|
|
|
{<<"localhost">>, [all]};
|
2019-07-16 21:07:39 +02:00
|
|
|
%% The pages of a vhost are only accessible if the user is admin of that vhost:
|
2013-03-14 10:33:02 +01:00
|
|
|
get_acl_rule([<<"server">>, VHost | _RPath], Method)
|
|
|
|
when Method =:= 'GET' orelse Method =:= 'HEAD' ->
|
2018-03-19 10:29:07 +01:00
|
|
|
{VHost, [configure, webadmin_view]};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_acl_rule([<<"server">>, VHost | _RPath], 'POST') ->
|
2018-03-19 10:29:07 +01:00
|
|
|
{VHost, [configure]};
|
2009-06-23 23:00:43 +02:00
|
|
|
%% Default rule: only global admins can access any other random page
|
2011-04-12 23:13:46 +02:00
|
|
|
get_acl_rule(_RPath, Method)
|
2013-03-14 10:33:02 +01:00
|
|
|
when Method =:= 'GET' orelse Method =:= 'HEAD' ->
|
2018-03-19 10:29:07 +01:00
|
|
|
{global, [configure, webadmin_view]};
|
2016-07-19 11:26:33 +02:00
|
|
|
get_acl_rule(_RPath, 'POST') ->
|
2018-03-19 10:29:07 +01:00
|
|
|
{global, [configure]}.
|
2009-06-23 23:00:43 +02:00
|
|
|
|
|
|
|
%%%==================================
|
|
|
|
%%%% Menu Items Access
|
|
|
|
|
2010-04-27 23:16:48 +02:00
|
|
|
get_jid(Auth, HostHTTP, Method) ->
|
|
|
|
case get_auth_admin(Auth, HostHTTP, [], Method) of
|
2013-03-14 10:33:02 +01:00
|
|
|
{ok, {User, Server}} ->
|
2017-02-25 08:01:01 +01:00
|
|
|
jid:make(User, Server);
|
2013-03-14 10:33:02 +01:00
|
|
|
{unauthorized, Error} ->
|
|
|
|
?ERROR_MSG("Unauthorized ~p: ~p", [Auth, Error]),
|
|
|
|
throw({unauthorized, Auth})
|
2009-06-23 23:00:43 +02:00
|
|
|
end.
|
|
|
|
|
2020-03-26 13:43:24 +01:00
|
|
|
get_menu_items(global, cluster, Lang, JID, Level) ->
|
|
|
|
{_Base, _, Items} = make_server_menu([], [], Lang, JID, Level),
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:map(fun ({URI, Name}) ->
|
2020-03-26 13:43:24 +01:00
|
|
|
{<<URI/binary, "/">>, Name};
|
2013-03-14 10:33:02 +01:00
|
|
|
({URI, Name, _SubMenu}) ->
|
2020-03-26 13:43:24 +01:00
|
|
|
{<<URI/binary, "/">>, Name}
|
2013-03-14 10:33:02 +01:00
|
|
|
end,
|
|
|
|
Items);
|
2020-03-26 13:43:24 +01:00
|
|
|
get_menu_items(Host, cluster, Lang, JID, Level) ->
|
|
|
|
{_Base, _, Items} = make_host_menu(Host, [], Lang, JID, Level),
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:map(fun ({URI, Name}) ->
|
2020-03-26 13:43:24 +01:00
|
|
|
{<<URI/binary, "/">>, Name};
|
2013-03-14 10:33:02 +01:00
|
|
|
({URI, Name, _SubMenu}) ->
|
2020-03-26 13:43:24 +01:00
|
|
|
{<<URI/binary, "/">>, Name}
|
2013-03-14 10:33:02 +01:00
|
|
|
end,
|
|
|
|
Items).
|
|
|
|
|
2011-09-05 10:07:50 +02:00
|
|
|
%% get_menu_items(Host, Node, Lang, JID) ->
|
|
|
|
%% {Base, _, Items} = make_host_node_menu(Host, Node, Lang, JID),
|
|
|
|
%% lists:map(
|
|
|
|
%% fun({URI, Name}) ->
|
|
|
|
%% {Base++URI++"/", Name};
|
|
|
|
%% ({URI, Name, _SubMenu}) ->
|
|
|
|
%% {Base++URI++"/", Name}
|
|
|
|
%% end,
|
|
|
|
%% Items
|
|
|
|
%% ).
|
2009-06-23 23:00:43 +02:00
|
|
|
|
2020-08-10 18:55:13 +02:00
|
|
|
is_allowed_path(global, RPath, JID) ->
|
|
|
|
is_allowed_path([], RPath, JID);
|
|
|
|
is_allowed_path(Host, RPath, JID) when is_binary(Host) ->
|
|
|
|
is_allowed_path([<<"server">>, Host], RPath, JID);
|
|
|
|
|
2020-03-26 13:43:24 +01:00
|
|
|
is_allowed_path(BasePath, {Path, _}, JID) ->
|
|
|
|
is_allowed_path(BasePath ++ [Path], JID);
|
|
|
|
is_allowed_path(BasePath, {Path, _, _}, JID) ->
|
|
|
|
is_allowed_path(BasePath ++ [Path], JID).
|
2009-06-23 23:00:43 +02:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
is_allowed_path([<<"admin">> | Path], JID) ->
|
2009-06-23 23:00:43 +02:00
|
|
|
is_allowed_path(Path, JID);
|
|
|
|
is_allowed_path(Path, JID) ->
|
2010-04-27 23:16:48 +02:00
|
|
|
{HostOfRule, AccessRule} = get_acl_rule(Path, 'GET'),
|
2019-06-14 11:33:26 +02:00
|
|
|
any_rules_allowed(HostOfRule, AccessRule, JID).
|
2009-06-23 23:00:43 +02:00
|
|
|
|
2009-06-23 22:45:39 +02:00
|
|
|
%%%==================================
|
|
|
|
%%%% process/2
|
|
|
|
|
2020-03-26 14:17:48 +01:00
|
|
|
process(Path, #request{raw_path = RawPath} = Request) ->
|
|
|
|
Continue = case Path of
|
|
|
|
[E] ->
|
|
|
|
binary:match(E, <<".">>) /= nomatch;
|
|
|
|
_ ->
|
|
|
|
false
|
|
|
|
end,
|
|
|
|
case Continue orelse binary:at(RawPath, size(RawPath) - 1) == $/ of
|
|
|
|
true ->
|
|
|
|
process2(Path, Request);
|
|
|
|
_ ->
|
|
|
|
{301, [{<<"Location">>, <<RawPath/binary, "/">>}], <<>>}
|
|
|
|
end.
|
|
|
|
|
|
|
|
process2([<<"server">>, SHost | RPath] = Path,
|
2013-03-14 10:33:02 +01:00
|
|
|
#request{auth = Auth, lang = Lang, host = HostHTTP,
|
2020-03-26 13:43:24 +01:00
|
|
|
method = Method} =
|
2013-03-14 10:33:02 +01:00
|
|
|
Request) ->
|
2015-11-24 16:44:13 +01:00
|
|
|
Host = jid:nameprep(SHost),
|
2016-12-29 22:00:36 +01:00
|
|
|
case ejabberd_router:is_my_host(Host) of
|
2013-03-14 10:33:02 +01:00
|
|
|
true ->
|
|
|
|
case get_auth_admin(Auth, HostHTTP, Path, Method) of
|
|
|
|
{ok, {User, Server}} ->
|
|
|
|
AJID = get_jid(Auth, HostHTTP, Method),
|
2020-03-26 13:43:24 +01:00
|
|
|
process_admin(Host,
|
2013-03-14 10:33:02 +01:00
|
|
|
Request#request{path = RPath,
|
2019-06-14 11:33:26 +02:00
|
|
|
us = {User, Server}},
|
|
|
|
AJID);
|
2013-03-14 10:33:02 +01:00
|
|
|
{unauthorized, <<"no-auth-provided">>} ->
|
|
|
|
{401,
|
|
|
|
[{<<"WWW-Authenticate">>,
|
|
|
|
<<"basic realm=\"ejabberd\"">>}],
|
|
|
|
ejabberd_web:make_xhtml([?XCT(<<"h1">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("Unauthorized"))])};
|
2013-03-14 10:33:02 +01:00
|
|
|
{unauthorized, Error} ->
|
|
|
|
{BadUser, _BadPass} = Auth,
|
|
|
|
{IPT, _Port} = Request#request.ip,
|
2017-04-11 12:13:58 +02:00
|
|
|
IPS = ejabberd_config:may_hide_data(misc:ip_to_list(IPT)),
|
2013-03-14 10:33:02 +01:00
|
|
|
?WARNING_MSG("Access of ~p from ~p failed with error: ~p",
|
|
|
|
[BadUser, IPS, Error]),
|
|
|
|
{401,
|
|
|
|
[{<<"WWW-Authenticate">>,
|
|
|
|
<<"basic realm=\"auth error, retry login "
|
|
|
|
"to ejabberd\"">>}],
|
|
|
|
ejabberd_web:make_xhtml([?XCT(<<"h1">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("Unauthorized"))])}
|
2013-03-14 10:33:02 +01:00
|
|
|
end;
|
|
|
|
false -> ejabberd_web:error(not_found)
|
2007-01-25 06:53:58 +01:00
|
|
|
end;
|
2020-03-26 14:17:48 +01:00
|
|
|
process2(RPath,
|
2013-03-14 10:33:02 +01:00
|
|
|
#request{auth = Auth, lang = Lang, host = HostHTTP,
|
2020-03-26 13:43:24 +01:00
|
|
|
method = Method} =
|
2013-03-14 10:33:02 +01:00
|
|
|
Request) ->
|
2019-10-09 10:31:02 +02:00
|
|
|
case get_auth_admin(Auth, HostHTTP, RPath, Method) of
|
|
|
|
{ok, {User, Server}} ->
|
|
|
|
AJID = get_jid(Auth, HostHTTP, Method),
|
2020-03-26 13:43:24 +01:00
|
|
|
process_admin(global,
|
2019-10-09 10:31:02 +02:00
|
|
|
Request#request{path = RPath,
|
|
|
|
us = {User, Server}},
|
|
|
|
AJID);
|
|
|
|
{unauthorized, <<"no-auth-provided">>} ->
|
|
|
|
{401,
|
|
|
|
[{<<"WWW-Authenticate">>,
|
|
|
|
<<"basic realm=\"ejabberd\"">>}],
|
|
|
|
ejabberd_web:make_xhtml([?XCT(<<"h1">>,
|
|
|
|
?T("Unauthorized"))])};
|
|
|
|
{unauthorized, Error} ->
|
|
|
|
{BadUser, _BadPass} = Auth,
|
|
|
|
{IPT, _Port} = Request#request.ip,
|
|
|
|
IPS = ejabberd_config:may_hide_data(misc:ip_to_list(IPT)),
|
|
|
|
?WARNING_MSG("Access of ~p from ~p failed with error: ~p",
|
|
|
|
[BadUser, IPS, Error]),
|
|
|
|
{401,
|
|
|
|
[{<<"WWW-Authenticate">>,
|
|
|
|
<<"basic realm=\"auth error, retry login "
|
|
|
|
"to ejabberd\"">>}],
|
|
|
|
ejabberd_web:make_xhtml([?XCT(<<"h1">>,
|
|
|
|
?T("Unauthorized"))])}
|
2007-01-25 06:53:58 +01:00
|
|
|
end.
|
|
|
|
|
2010-04-27 23:16:48 +02:00
|
|
|
get_auth_admin(Auth, HostHTTP, RPath, Method) ->
|
2007-01-25 06:53:58 +01:00
|
|
|
case Auth of
|
2013-03-14 10:33:02 +01:00
|
|
|
{SJID, Pass} ->
|
|
|
|
{HostOfRule, AccessRule} = get_acl_rule(RPath, Method),
|
2017-02-26 08:07:12 +01:00
|
|
|
try jid:decode(SJID) of
|
|
|
|
#jid{user = <<"">>, server = User} ->
|
2019-10-09 10:31:02 +02:00
|
|
|
case ejabberd_router:is_my_host(HostHTTP) of
|
|
|
|
true ->
|
|
|
|
get_auth_account(HostOfRule, AccessRule, User, HostHTTP,
|
|
|
|
Pass);
|
|
|
|
_ ->
|
|
|
|
{unauthorized, <<"missing-server">>}
|
|
|
|
end;
|
2017-02-26 08:07:12 +01:00
|
|
|
#jid{user = User, server = Server} ->
|
|
|
|
get_auth_account(HostOfRule, AccessRule, User, Server,
|
|
|
|
Pass)
|
|
|
|
catch _:{bad_jid, _} ->
|
|
|
|
{unauthorized, <<"badformed-jid">>}
|
|
|
|
end;
|
2019-01-30 16:34:29 +01:00
|
|
|
invalid -> {unauthorized, <<"no-auth-provided">>};
|
2013-03-14 10:33:02 +01:00
|
|
|
undefined -> {unauthorized, <<"no-auth-provided">>}
|
2009-06-23 00:58:52 +02:00
|
|
|
end.
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
get_auth_account(HostOfRule, AccessRule, User, Server,
|
|
|
|
Pass) ->
|
2019-08-22 17:56:08 +02:00
|
|
|
case lists:member(Server, ejabberd_config:get_option(hosts)) of
|
2019-08-22 17:11:48 +02:00
|
|
|
true -> get_auth_account2(HostOfRule, AccessRule, User, Server, Pass);
|
|
|
|
false -> {unauthorized, <<"inexistent-host">>}
|
|
|
|
end.
|
|
|
|
|
|
|
|
get_auth_account2(HostOfRule, AccessRule, User, Server,
|
|
|
|
Pass) ->
|
2015-04-09 03:21:09 +02:00
|
|
|
case ejabberd_auth:check_password(User, <<"">>, Server, Pass) of
|
2013-03-14 10:33:02 +01:00
|
|
|
true ->
|
2019-06-14 11:33:26 +02:00
|
|
|
case any_rules_allowed(HostOfRule, AccessRule,
|
|
|
|
jid:make(User, Server))
|
2013-03-14 10:33:02 +01:00
|
|
|
of
|
|
|
|
false -> {unauthorized, <<"unprivileged-account">>};
|
|
|
|
true -> {ok, {User, Server}}
|
|
|
|
end;
|
|
|
|
false ->
|
2017-05-11 14:49:06 +02:00
|
|
|
case ejabberd_auth:user_exists(User, Server) of
|
2013-03-14 10:33:02 +01:00
|
|
|
true -> {unauthorized, <<"bad-password">>};
|
|
|
|
false -> {unauthorized, <<"inexistent-account">>}
|
|
|
|
end
|
2007-01-25 06:53:58 +01:00
|
|
|
end.
|
|
|
|
|
2009-06-23 22:45:39 +02:00
|
|
|
%%%==================================
|
|
|
|
%%%% make_xhtml
|
|
|
|
|
2020-03-26 13:43:24 +01:00
|
|
|
make_xhtml(Els, Host, Lang, JID, Level) ->
|
|
|
|
make_xhtml(Els, Host, cluster, Lang, JID, Level).
|
2008-10-12 15:58:05 +02:00
|
|
|
|
2022-05-12 17:25:11 +02:00
|
|
|
-spec make_xhtml([xmlel()],
|
|
|
|
Host::global | binary(),
|
|
|
|
Node::cluster | atom(),
|
|
|
|
Lang::binary(),
|
|
|
|
jid(),
|
|
|
|
Level::integer()) ->
|
|
|
|
{200, [html], xmlel()}.
|
2020-03-26 13:43:24 +01:00
|
|
|
make_xhtml(Els, Host, Node, Lang, JID, Level) ->
|
|
|
|
Base = get_base_path_sum(0, 0, Level),
|
|
|
|
MenuItems = make_navigation(Host, Node, Lang, JID, Level),
|
2005-06-20 05:18:13 +02:00
|
|
|
{200, [html],
|
2013-03-14 10:33:02 +01:00
|
|
|
#xmlel{name = <<"html">>,
|
|
|
|
attrs =
|
|
|
|
[{<<"xmlns">>, <<"http://www.w3.org/1999/xhtml">>},
|
2015-07-15 19:01:32 +02:00
|
|
|
{<<"xml:lang">>, Lang}, {<<"lang">>, Lang}]++direction(Lang),
|
2013-03-14 10:33:02 +01:00
|
|
|
children =
|
|
|
|
[#xmlel{name = <<"head">>, attrs = [],
|
|
|
|
children =
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XCT(<<"title">>, ?T("ejabberd Web Admin")),
|
2013-03-14 10:33:02 +01:00
|
|
|
#xmlel{name = <<"meta">>,
|
|
|
|
attrs =
|
|
|
|
[{<<"http-equiv">>, <<"Content-Type">>},
|
|
|
|
{<<"content">>,
|
|
|
|
<<"text/html; charset=utf-8">>}],
|
|
|
|
children = []},
|
|
|
|
#xmlel{name = <<"script">>,
|
|
|
|
attrs =
|
|
|
|
[{<<"src">>,
|
2019-01-09 11:55:42 +01:00
|
|
|
<<Base/binary, "additions.js">>},
|
2013-03-14 10:33:02 +01:00
|
|
|
{<<"type">>, <<"text/javascript">>}],
|
|
|
|
children = [?C(<<" ">>)]},
|
|
|
|
#xmlel{name = <<"link">>,
|
|
|
|
attrs =
|
|
|
|
[{<<"href">>,
|
|
|
|
<<Base/binary, "favicon.ico">>},
|
|
|
|
{<<"type">>, <<"image/x-icon">>},
|
|
|
|
{<<"rel">>, <<"shortcut icon">>}],
|
|
|
|
children = []},
|
|
|
|
#xmlel{name = <<"link">>,
|
|
|
|
attrs =
|
|
|
|
[{<<"href">>,
|
|
|
|
<<Base/binary, "style.css">>},
|
|
|
|
{<<"type">>, <<"text/css">>},
|
|
|
|
{<<"rel">>, <<"stylesheet">>}],
|
|
|
|
children = []}]},
|
|
|
|
?XE(<<"body">>,
|
|
|
|
[?XAE(<<"div">>, [{<<"id">>, <<"container">>}],
|
|
|
|
[?XAE(<<"div">>, [{<<"id">>, <<"header">>}],
|
|
|
|
[?XE(<<"h1">>,
|
2019-10-02 11:54:22 +02:00
|
|
|
[?ACT(Base,
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"ejabberd Web Admin">>)])]),
|
|
|
|
?XAE(<<"div">>, [{<<"id">>, <<"navigation">>}],
|
|
|
|
[?XE(<<"ul">>, MenuItems)]),
|
|
|
|
?XAE(<<"div">>, [{<<"id">>, <<"content">>}], Els),
|
|
|
|
?XAE(<<"div">>, [{<<"id">>, <<"clearcopyright">>}],
|
|
|
|
[{xmlcdata, <<"">>}])]),
|
|
|
|
?XAE(<<"div">>, [{<<"id">>, <<"copyrightouter">>}],
|
|
|
|
[?XAE(<<"div">>, [{<<"id">>, <<"copyright">>}],
|
2015-07-15 13:09:58 +02:00
|
|
|
[?XE(<<"p">>,
|
|
|
|
[?AC(<<"https://www.ejabberd.im/">>, <<"ejabberd">>),
|
2020-05-15 10:52:40 +02:00
|
|
|
?C(<<" ">>), ?C(ejabberd_option:version()),
|
2023-01-09 17:09:06 +01:00
|
|
|
?C(<<" (c) 2002-2023 ">>),
|
2015-11-30 11:35:53 +01:00
|
|
|
?AC(<<"https://www.process-one.net/">>, <<"ProcessOne, leader in messaging and push solutions">>)]
|
2015-07-15 13:09:58 +02:00
|
|
|
)])])])]}}.
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2015-07-15 19:01:32 +02:00
|
|
|
direction(<<"he">>) -> [{<<"dir">>, <<"rtl">>}];
|
|
|
|
direction(_) -> [].
|
|
|
|
|
2020-03-26 13:43:24 +01:00
|
|
|
get_base_path(Host, Node, Level) ->
|
|
|
|
SumHost = case Host of
|
|
|
|
global -> 0;
|
|
|
|
_ -> -2
|
|
|
|
end,
|
|
|
|
SumNode = case Node of
|
|
|
|
cluster -> 0;
|
|
|
|
_ -> -2
|
|
|
|
end,
|
|
|
|
get_base_path_sum(SumHost, SumNode, Level).
|
2019-10-02 11:54:22 +02:00
|
|
|
|
2020-03-26 13:43:24 +01:00
|
|
|
get_base_path_sum(SumHost, SumNode, Level) ->
|
|
|
|
iolist_to_binary(lists:duplicate(Level + SumHost + SumNode, "../")).
|
2008-10-12 15:58:05 +02:00
|
|
|
|
2009-06-23 22:45:39 +02:00
|
|
|
%%%==================================
|
|
|
|
%%%% css & images
|
|
|
|
|
2009-05-27 19:28:55 +02:00
|
|
|
additions_js() ->
|
2017-10-09 22:35:42 +02:00
|
|
|
case misc:read_js("admin.js") of
|
|
|
|
{ok, JS} -> JS;
|
|
|
|
{error, _} -> <<>>
|
|
|
|
end.
|
2009-05-27 19:28:55 +02:00
|
|
|
|
2020-03-26 13:43:24 +01:00
|
|
|
css(Host) ->
|
2017-10-09 22:35:42 +02:00
|
|
|
case misc:read_css("admin.css") of
|
|
|
|
{ok, CSS} ->
|
2020-03-26 13:43:24 +01:00
|
|
|
Base = get_base_path(Host, cluster, 0),
|
|
|
|
re:replace(CSS, <<"@BASE@">>, Base, [{return, binary}]);
|
2017-10-09 22:35:42 +02:00
|
|
|
{error, _} ->
|
|
|
|
<<>>
|
|
|
|
end.
|
2004-04-26 17:38:07 +02:00
|
|
|
|
2007-11-26 16:12:34 +01:00
|
|
|
favicon() ->
|
2017-10-09 22:35:42 +02:00
|
|
|
case misc:read_img("favicon.png") of
|
|
|
|
{ok, ICO} -> ICO;
|
|
|
|
{error, _} -> <<>>
|
|
|
|
end.
|
2007-11-26 16:12:34 +01:00
|
|
|
|
2004-04-26 17:38:07 +02:00
|
|
|
logo() ->
|
2017-10-09 22:35:42 +02:00
|
|
|
case misc:read_img("admin-logo.png") of
|
|
|
|
{ok, Img} -> Img;
|
|
|
|
{error, _} -> <<>>
|
|
|
|
end.
|
2004-04-26 17:38:07 +02:00
|
|
|
|
|
|
|
logo_fill() ->
|
2017-10-09 22:35:42 +02:00
|
|
|
case misc:read_img("admin-logo-fill.png") of
|
|
|
|
{ok, Img} -> Img;
|
|
|
|
{error, _} -> <<>>
|
|
|
|
end.
|
2004-04-26 17:38:07 +02:00
|
|
|
|
2009-06-23 22:45:39 +02:00
|
|
|
%%%==================================
|
|
|
|
%%%% process_admin
|
2008-10-12 15:58:05 +02:00
|
|
|
|
2020-03-26 13:43:24 +01:00
|
|
|
process_admin(global, #request{path = [], lang = Lang}, AJID) ->
|
2023-09-26 15:54:32 +02:00
|
|
|
MenuItems = get_menu_items(global, cluster, Lang, AJID, 0),
|
|
|
|
Disclaimer = maybe_disclaimer_not_admin(MenuItems, AJID, Lang),
|
2019-06-22 16:08:45 +02:00
|
|
|
make_xhtml((?H1GL((translate:translate(Lang, ?T("Administration"))), <<"">>,
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"Contents">>))
|
2023-09-26 15:54:32 +02:00
|
|
|
++ Disclaimer ++
|
2013-03-14 10:33:02 +01:00
|
|
|
[?XE(<<"ul">>,
|
|
|
|
[?LI([?ACT(MIU, MIN)])
|
|
|
|
|| {MIU, MIN}
|
2023-09-26 15:54:32 +02:00
|
|
|
<- MenuItems])],
|
2020-03-26 13:43:24 +01:00
|
|
|
global, Lang, AJID, 0);
|
|
|
|
process_admin(Host, #request{path = [], lang = Lang}, AJID) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
make_xhtml([?XCT(<<"h1">>, ?T("Administration")),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"ul">>,
|
|
|
|
[?LI([?ACT(MIU, MIN)])
|
|
|
|
|| {MIU, MIN}
|
2020-03-26 13:43:24 +01:00
|
|
|
<- get_menu_items(Host, cluster, Lang, AJID, 2)])],
|
|
|
|
Host, Lang, AJID, 2);
|
|
|
|
process_admin(Host, #request{path = [<<"style.css">>]}, _) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{200,
|
|
|
|
[{<<"Content-Type">>, <<"text/css">>}, last_modified(),
|
|
|
|
cache_control_public()],
|
2020-03-26 13:43:24 +01:00
|
|
|
css(Host)};
|
|
|
|
process_admin(_Host, #request{path = [<<"favicon.ico">>]}, _) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{200,
|
|
|
|
[{<<"Content-Type">>, <<"image/x-icon">>},
|
|
|
|
last_modified(), cache_control_public()],
|
|
|
|
favicon()};
|
2020-03-26 13:43:24 +01:00
|
|
|
process_admin(_Host, #request{path = [<<"logo.png">>]}, _) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{200,
|
|
|
|
[{<<"Content-Type">>, <<"image/png">>}, last_modified(),
|
|
|
|
cache_control_public()],
|
|
|
|
logo()};
|
2020-03-26 13:43:24 +01:00
|
|
|
process_admin(_Host, #request{path = [<<"logo-fill.png">>]}, _) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{200,
|
|
|
|
[{<<"Content-Type">>, <<"image/png">>}, last_modified(),
|
|
|
|
cache_control_public()],
|
|
|
|
logo_fill()};
|
2020-03-26 13:43:24 +01:00
|
|
|
process_admin(_Host, #request{path = [<<"additions.js">>]}, _) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{200,
|
|
|
|
[{<<"Content-Type">>, <<"text/javascript">>},
|
|
|
|
last_modified(), cache_control_public()],
|
|
|
|
additions_js()};
|
2020-03-26 13:43:24 +01:00
|
|
|
process_admin(global, #request{path = [<<"vhosts">>], lang = Lang}, AJID) ->
|
2009-06-23 23:00:43 +02:00
|
|
|
Res = list_vhosts(Lang, AJID),
|
2019-06-22 16:08:45 +02:00
|
|
|
make_xhtml((?H1GL((translate:translate(Lang, ?T("Virtual Hosts"))),
|
2020-04-14 13:46:26 +02:00
|
|
|
<<"basic/#xmpp-domains">>, ?T("XMPP Domains")))
|
2013-03-14 10:33:02 +01:00
|
|
|
++ Res,
|
2020-03-26 13:43:24 +01:00
|
|
|
global, Lang, AJID, 1);
|
|
|
|
process_admin(Host, #request{path = [<<"users">>], q = Query,
|
2019-06-14 11:33:26 +02:00
|
|
|
lang = Lang}, AJID)
|
2013-03-14 10:33:02 +01:00
|
|
|
when is_binary(Host) ->
|
2020-03-26 13:43:24 +01:00
|
|
|
Res = list_users(Host, Query, Lang, fun url_func/1),
|
2019-06-22 16:08:45 +02:00
|
|
|
make_xhtml([?XCT(<<"h1">>, ?T("Users"))] ++ Res, Host,
|
2020-03-26 13:43:24 +01:00
|
|
|
Lang, AJID, 3);
|
|
|
|
process_admin(Host, #request{path = [<<"users">>, Diap],
|
2019-06-14 11:33:26 +02:00
|
|
|
lang = Lang}, AJID)
|
2013-03-14 10:33:02 +01:00
|
|
|
when is_binary(Host) ->
|
2020-03-26 13:43:24 +01:00
|
|
|
Res = list_users_in_diapason(Host, Diap, Lang,
|
2013-03-14 10:33:02 +01:00
|
|
|
fun url_func/1),
|
2019-06-22 16:08:45 +02:00
|
|
|
make_xhtml([?XCT(<<"h1">>, ?T("Users"))] ++ Res, Host,
|
2020-03-26 13:43:24 +01:00
|
|
|
Lang, AJID, 4);
|
|
|
|
process_admin(Host, #request{path = [<<"online-users">>],
|
2019-06-14 11:33:26 +02:00
|
|
|
lang = Lang}, AJID)
|
2013-03-14 10:33:02 +01:00
|
|
|
when is_binary(Host) ->
|
2005-06-20 05:18:13 +02:00
|
|
|
Res = list_online_users(Host, Lang),
|
2019-06-22 16:08:45 +02:00
|
|
|
make_xhtml([?XCT(<<"h1">>, ?T("Online Users"))] ++ Res,
|
2020-03-26 13:43:24 +01:00
|
|
|
Host, Lang, AJID, 3);
|
|
|
|
process_admin(Host, #request{path = [<<"last-activity">>],
|
2019-06-14 11:33:26 +02:00
|
|
|
q = Query, lang = Lang}, AJID)
|
2013-03-14 10:33:02 +01:00
|
|
|
when is_binary(Host) ->
|
2019-06-24 19:32:34 +02:00
|
|
|
?DEBUG("Query: ~p", [Query]),
|
2013-03-14 10:33:02 +01:00
|
|
|
Month = case lists:keysearch(<<"period">>, 1, Query) of
|
|
|
|
{value, {_, Val}} -> Val;
|
|
|
|
_ -> <<"month">>
|
2005-05-09 01:39:46 +02:00
|
|
|
end,
|
2013-03-14 10:33:02 +01:00
|
|
|
Res = case lists:keysearch(<<"ordinary">>, 1, Query) of
|
|
|
|
{value, {_, _}} ->
|
|
|
|
list_last_activity(Host, Lang, false, Month);
|
|
|
|
_ -> list_last_activity(Host, Lang, true, Month)
|
2005-05-09 01:39:46 +02:00
|
|
|
end,
|
2020-04-14 13:46:26 +02:00
|
|
|
PageH1 = ?H1GL(translate:translate(Lang, ?T("Users Last Activity")), <<"modules/#mod-last">>, <<"mod_last">>),
|
2019-08-27 12:29:05 +02:00
|
|
|
make_xhtml(PageH1 ++
|
2013-03-14 10:33:02 +01:00
|
|
|
[?XAE(<<"form">>,
|
|
|
|
[{<<"action">>, <<"">>}, {<<"method">>, <<"post">>}],
|
2019-06-22 16:08:45 +02:00
|
|
|
[?CT(?T("Period: ")),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XAE(<<"select">>, [{<<"name">>, <<"period">>}],
|
|
|
|
(lists:map(fun ({O, V}) ->
|
|
|
|
Sel = if O == Month ->
|
|
|
|
[{<<"selected">>,
|
|
|
|
<<"selected">>}];
|
|
|
|
true -> []
|
|
|
|
end,
|
|
|
|
?XAC(<<"option">>,
|
|
|
|
(Sel ++
|
|
|
|
[{<<"value">>, O}]),
|
|
|
|
V)
|
|
|
|
end,
|
2019-06-22 16:08:45 +02:00
|
|
|
[{<<"month">>, translate:translate(Lang, ?T("Last month"))},
|
|
|
|
{<<"year">>, translate:translate(Lang, ?T("Last year"))},
|
2013-03-14 10:33:02 +01:00
|
|
|
{<<"all">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
translate:translate(Lang, ?T("All activity"))}]))),
|
2013-03-14 10:33:02 +01:00
|
|
|
?C(<<" ">>),
|
|
|
|
?INPUTT(<<"submit">>, <<"ordinary">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("Show Ordinary Table")),
|
2013-03-14 10:33:02 +01:00
|
|
|
?C(<<" ">>),
|
|
|
|
?INPUTT(<<"submit">>, <<"integral">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("Show Integral Table"))])]
|
2013-03-14 10:33:02 +01:00
|
|
|
++ Res,
|
2020-03-26 13:43:24 +01:00
|
|
|
Host, Lang, AJID, 3);
|
|
|
|
process_admin(Host, #request{path = [<<"stats">>], lang = Lang}, AJID) ->
|
2005-06-20 05:18:13 +02:00
|
|
|
Res = get_stats(Host, Lang),
|
2020-04-14 13:46:26 +02:00
|
|
|
PageH1 = ?H1GL(translate:translate(Lang, ?T("Statistics")), <<"modules/#mod-stats">>, <<"mod_stats">>),
|
2020-03-26 13:43:24 +01:00
|
|
|
Level = case Host of
|
|
|
|
global -> 1;
|
|
|
|
_ -> 3
|
|
|
|
end,
|
|
|
|
make_xhtml(PageH1 ++ Res, Host, Lang, AJID, Level);
|
|
|
|
process_admin(Host, #request{path = [<<"user">>, U],
|
2019-06-14 11:33:26 +02:00
|
|
|
q = Query, lang = Lang}, AJID) ->
|
2017-05-11 14:49:06 +02:00
|
|
|
case ejabberd_auth:user_exists(U, Host) of
|
2013-03-14 10:33:02 +01:00
|
|
|
true ->
|
|
|
|
Res = user_info(U, Host, Query, Lang),
|
2020-03-26 13:43:24 +01:00
|
|
|
make_xhtml(Res, Host, Lang, AJID, 4);
|
2013-03-14 10:33:02 +01:00
|
|
|
false ->
|
2019-06-22 16:08:45 +02:00
|
|
|
make_xhtml([?XCT(<<"h1">>, ?T("Not Found"))], Host,
|
2020-03-26 13:43:24 +01:00
|
|
|
Lang, AJID, 4)
|
2008-10-13 10:32:04 +02:00
|
|
|
end;
|
2020-03-26 13:43:24 +01:00
|
|
|
process_admin(Host, #request{path = [<<"nodes">>], lang = Lang}, AJID) ->
|
2004-05-09 20:38:49 +02:00
|
|
|
Res = get_nodes(Lang),
|
2020-03-26 13:43:24 +01:00
|
|
|
Level = case Host of
|
|
|
|
global -> 1;
|
|
|
|
_ -> 3
|
|
|
|
end,
|
|
|
|
make_xhtml(Res, Host, Lang, AJID, Level);
|
|
|
|
process_admin(Host, #request{path = [<<"node">>, SNode | NPath],
|
2019-06-14 11:33:26 +02:00
|
|
|
q = Query, lang = Lang}, AJID) ->
|
2004-05-14 16:46:53 +02:00
|
|
|
case search_running_node(SNode) of
|
2013-03-14 10:33:02 +01:00
|
|
|
false ->
|
2019-06-22 16:08:45 +02:00
|
|
|
make_xhtml([?XCT(<<"h1">>, ?T("Node not found"))], Host,
|
2020-03-26 13:43:24 +01:00
|
|
|
Lang, AJID, 2);
|
2013-03-14 10:33:02 +01:00
|
|
|
Node ->
|
2020-03-26 13:43:24 +01:00
|
|
|
Res = get_node(Host, Node, NPath, Query, Lang),
|
|
|
|
Level = case Host of
|
|
|
|
global -> 2 + length(NPath);
|
|
|
|
_ -> 4 + length(NPath)
|
|
|
|
end,
|
|
|
|
make_xhtml(Res, Host, Node, Lang, AJID, Level)
|
2004-05-14 16:46:53 +02:00
|
|
|
end;
|
2009-06-23 22:45:39 +02:00
|
|
|
%%%==================================
|
|
|
|
%%%% process_admin default case
|
2020-03-26 13:43:24 +01:00
|
|
|
process_admin(Host, #request{lang = Lang} = Request, AJID) ->
|
2016-08-09 09:56:32 +02:00
|
|
|
Res = case Host of
|
|
|
|
global ->
|
|
|
|
ejabberd_hooks:run_fold(
|
|
|
|
webadmin_page_main, Host, [], [Request]);
|
|
|
|
_ ->
|
|
|
|
ejabberd_hooks:run_fold(
|
|
|
|
webadmin_page_host, Host, [], [Host, Request])
|
|
|
|
end,
|
2020-03-26 13:43:24 +01:00
|
|
|
Level = case Host of
|
|
|
|
global -> length(Request#request.path);
|
|
|
|
_ -> 2 + length(Request#request.path)
|
|
|
|
end,
|
2016-08-09 09:56:32 +02:00
|
|
|
case Res of
|
2013-03-14 10:33:02 +01:00
|
|
|
[] ->
|
|
|
|
setelement(1,
|
|
|
|
make_xhtml([?XC(<<"h1">>, <<"Not Found">>)], Host, Lang,
|
2020-03-26 13:43:24 +01:00
|
|
|
AJID, Level),
|
2013-03-14 10:33:02 +01:00
|
|
|
404);
|
2020-03-26 13:43:24 +01:00
|
|
|
_ -> make_xhtml(Res, Host, Lang, AJID, Level)
|
2007-08-23 02:51:54 +02:00
|
|
|
end.
|
2004-04-26 17:38:07 +02:00
|
|
|
|
2017-05-23 09:43:26 +02:00
|
|
|
term_to_id(T) -> base64:encode((term_to_binary(T))).
|
2004-04-26 17:38:07 +02:00
|
|
|
|
2009-06-23 22:45:39 +02:00
|
|
|
%%%==================================
|
|
|
|
%%%% list_vhosts
|
2004-04-26 17:38:07 +02:00
|
|
|
|
2009-06-23 23:00:43 +02:00
|
|
|
list_vhosts(Lang, JID) ->
|
2023-09-26 15:54:32 +02:00
|
|
|
list_vhosts2(Lang, list_vhosts_allowed(JID)).
|
|
|
|
|
|
|
|
list_vhosts_allowed(JID) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
Hosts = ejabberd_option:hosts(),
|
2023-09-26 15:54:32 +02:00
|
|
|
lists:filter(fun (Host) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
any_rules_allowed(Host,
|
2013-03-14 10:33:02 +01:00
|
|
|
[configure, webadmin_view],
|
|
|
|
JID)
|
|
|
|
end,
|
2023-09-26 15:54:32 +02:00
|
|
|
Hosts).
|
2009-06-23 23:00:43 +02:00
|
|
|
|
|
|
|
list_vhosts2(Lang, Hosts) ->
|
2005-07-29 22:34:57 +02:00
|
|
|
SHosts = lists:sort(Hosts),
|
2013-03-14 10:33:02 +01:00
|
|
|
[?XE(<<"table">>,
|
|
|
|
[?XE(<<"thead">>,
|
|
|
|
[?XE(<<"tr">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XCT(<<"td">>, ?T("Host")),
|
2021-05-19 14:51:56 +02:00
|
|
|
?XACT(<<"td">>,
|
|
|
|
[{<<"class">>, <<"alignright">>}],
|
|
|
|
?T("Registered Users")),
|
|
|
|
?XACT(<<"td">>,
|
|
|
|
[{<<"class">>, <<"alignright">>}],
|
|
|
|
?T("Online Users"))])]),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"tbody">>,
|
|
|
|
(lists:map(fun (Host) ->
|
|
|
|
OnlineUsers =
|
|
|
|
length(ejabberd_sm:get_vh_session_list(Host)),
|
|
|
|
RegisteredUsers =
|
2017-05-11 13:37:21 +02:00
|
|
|
ejabberd_auth:count_users(Host),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XE(<<"td">>,
|
|
|
|
[?AC(<<"../server/", Host/binary,
|
|
|
|
"/">>,
|
|
|
|
Host)]),
|
2021-08-26 17:21:23 +02:00
|
|
|
?XAE(<<"td">>,
|
2021-05-19 14:51:56 +02:00
|
|
|
[{<<"class">>, <<"alignright">>}],
|
2021-08-26 17:21:23 +02:00
|
|
|
[?AC(<<"../server/", Host/binary, "/users/">>,
|
|
|
|
pretty_string_int(RegisteredUsers))]),
|
|
|
|
?XAE(<<"td">>,
|
2021-05-19 14:51:56 +02:00
|
|
|
[{<<"class">>, <<"alignright">>}],
|
2021-08-27 13:39:06 +02:00
|
|
|
[?AC(<<"../server/", Host/binary, "/online-users/">>,
|
|
|
|
pretty_string_int(OnlineUsers))])])
|
2013-03-14 10:33:02 +01:00
|
|
|
end,
|
|
|
|
SHosts)))])].
|
2004-04-26 17:38:07 +02:00
|
|
|
|
2023-09-26 15:54:32 +02:00
|
|
|
maybe_disclaimer_not_admin(MenuItems, AJID, Lang) ->
|
|
|
|
case {MenuItems, list_vhosts_allowed(AJID)} of
|
|
|
|
{[_], []} ->
|
2023-09-26 23:21:45 +02:00
|
|
|
[?XREST(?T("Apparently your account has no administration rights in this server. "
|
|
|
|
"Please check how to grant admin rights in: "
|
|
|
|
"https://docs.ejabberd.im/admin/installation/#administration-account"))
|
2023-09-26 15:54:32 +02:00
|
|
|
];
|
|
|
|
_ ->
|
|
|
|
[]
|
|
|
|
end.
|
|
|
|
|
2009-06-23 22:45:39 +02:00
|
|
|
%%%==================================
|
|
|
|
%%%% list_users
|
2004-04-26 17:38:07 +02:00
|
|
|
|
2020-03-26 13:43:24 +01:00
|
|
|
list_users(Host, Query, Lang, URLFunc) ->
|
2006-07-07 10:06:12 +02:00
|
|
|
Res = list_users_parse_query(Query, Host),
|
2017-05-11 13:37:21 +02:00
|
|
|
Users = ejabberd_auth:get_users(Host),
|
2005-04-17 20:08:34 +02:00
|
|
|
SUsers = lists:sort([{S, U} || {U, S} <- Users]),
|
2013-03-14 10:33:02 +01:00
|
|
|
FUsers = case length(SUsers) of
|
|
|
|
N when N =< 100 ->
|
2020-03-26 13:43:24 +01:00
|
|
|
[list_given_users(Host, SUsers, <<"../">>, Lang,
|
2013-03-14 10:33:02 +01:00
|
|
|
URLFunc)];
|
|
|
|
N ->
|
|
|
|
NParts = trunc(math:sqrt(N * 6.17999999999999993783e-1))
|
|
|
|
+ 1,
|
|
|
|
M = trunc(N / NParts) + 1,
|
|
|
|
lists:flatmap(fun (K) ->
|
|
|
|
L = K + M - 1,
|
|
|
|
Last = if L < N ->
|
|
|
|
su_to_list(lists:nth(L,
|
|
|
|
SUsers));
|
|
|
|
true ->
|
|
|
|
su_to_list(lists:last(SUsers))
|
|
|
|
end,
|
|
|
|
Name = <<(su_to_list(lists:nth(K,
|
|
|
|
SUsers)))/binary,
|
|
|
|
$\s, 226, 128, 148, $\s,
|
|
|
|
Last/binary>>,
|
|
|
|
[?AC((URLFunc({user_diapason, K, L})),
|
|
|
|
Name),
|
|
|
|
?BR]
|
2004-10-05 21:31:17 +02:00
|
|
|
end,
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:seq(1, N, M))
|
|
|
|
end,
|
2004-10-05 21:31:17 +02:00
|
|
|
case Res of
|
2006-07-07 10:06:12 +02:00
|
|
|
%% Parse user creation query and try register:
|
2019-06-22 16:08:45 +02:00
|
|
|
ok -> [?XREST(?T("Submitted"))];
|
|
|
|
error -> [?XREST(?T("Bad format"))];
|
2013-03-14 10:33:02 +01:00
|
|
|
nothing -> []
|
|
|
|
end
|
|
|
|
++
|
|
|
|
[?XAE(<<"form">>,
|
|
|
|
[{<<"action">>, <<"">>}, {<<"method">>, <<"post">>}],
|
|
|
|
([?XE(<<"table">>,
|
|
|
|
[?XE(<<"tr">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XC(<<"td">>, <<(translate:translate(Lang, ?T("User")))/binary, ":">>),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>, <<"newusername">>, <<"">>)]),
|
|
|
|
?XE(<<"td">>, [?C(<<" @ ", Host/binary>>)])]),
|
|
|
|
?XE(<<"tr">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XC(<<"td">>, <<(translate:translate(Lang, ?T("Password")))/binary, ":">>),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"password">>, <<"newuserpassword">>,
|
|
|
|
<<"">>)]),
|
|
|
|
?X(<<"td">>)]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?X(<<"td">>),
|
|
|
|
?XAE(<<"td">>, [{<<"class">>, <<"alignright">>}],
|
|
|
|
[?INPUTT(<<"submit">>, <<"addnewuser">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("Add User"))]),
|
2013-03-14 10:33:02 +01:00
|
|
|
?X(<<"td">>)])]),
|
|
|
|
?P]
|
|
|
|
++ FUsers))].
|
|
|
|
|
2006-07-07 10:06:12 +02:00
|
|
|
list_users_parse_query(Query, Host) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
case lists:keysearch(<<"addnewuser">>, 1, Query) of
|
|
|
|
{value, _} ->
|
|
|
|
{value, {_, Username}} =
|
|
|
|
lists:keysearch(<<"newusername">>, 1, Query),
|
|
|
|
{value, {_, Password}} =
|
|
|
|
lists:keysearch(<<"newuserpassword">>, 1, Query),
|
2017-02-26 08:07:12 +01:00
|
|
|
try jid:decode(<<Username/binary, "@",
|
2013-03-14 10:33:02 +01:00
|
|
|
Host/binary>>)
|
|
|
|
of
|
|
|
|
#jid{user = User, server = Server} ->
|
|
|
|
case ejabberd_auth:try_register(User, Server, Password)
|
|
|
|
of
|
|
|
|
{error, _Reason} -> error;
|
|
|
|
_ -> ok
|
|
|
|
end
|
2017-02-26 08:07:12 +01:00
|
|
|
catch _:{bad_jid, _} ->
|
|
|
|
error
|
2013-03-14 10:33:02 +01:00
|
|
|
end;
|
|
|
|
false -> nothing
|
2004-04-26 17:38:07 +02:00
|
|
|
end.
|
|
|
|
|
2020-03-26 13:43:24 +01:00
|
|
|
list_users_in_diapason(Host, Diap, Lang, URLFunc) ->
|
2017-05-11 13:37:21 +02:00
|
|
|
Users = ejabberd_auth:get_users(Host),
|
2005-04-17 20:08:34 +02:00
|
|
|
SUsers = lists:sort([{S, U} || {U, S} <- Users]),
|
2013-03-14 10:33:02 +01:00
|
|
|
[S1, S2] = ejabberd_regexp:split(Diap, <<"-">>),
|
2016-09-24 22:34:28 +02:00
|
|
|
N1 = binary_to_integer(S1),
|
|
|
|
N2 = binary_to_integer(S2),
|
2004-04-26 17:38:07 +02:00
|
|
|
Sub = lists:sublist(SUsers, N1, N2 - N1 + 1),
|
2020-03-26 13:43:24 +01:00
|
|
|
[list_given_users(Host, Sub, <<"../../">>, Lang,
|
2013-03-14 10:33:02 +01:00
|
|
|
URLFunc)].
|
2004-10-05 21:31:17 +02:00
|
|
|
|
2020-03-26 13:43:24 +01:00
|
|
|
list_given_users(Host, Users, Prefix, Lang, URLFunc) ->
|
2010-01-12 13:02:50 +01:00
|
|
|
ModOffline = get_offlinemsg_module(Host),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"table">>,
|
|
|
|
[?XE(<<"thead">>,
|
|
|
|
[?XE(<<"tr">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XCT(<<"td">>, ?T("User")),
|
2021-05-19 14:51:56 +02:00
|
|
|
?XACT(<<"td">>,
|
|
|
|
[{<<"class">>, <<"alignright">>}],
|
|
|
|
?T("Offline Messages")),
|
2019-06-22 16:08:45 +02:00
|
|
|
?XCT(<<"td">>, ?T("Last Activity"))])]),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"tbody">>,
|
|
|
|
(lists:map(fun (_SU = {Server, User}) ->
|
|
|
|
US = {User, Server},
|
|
|
|
QueueLenStr = get_offlinemsg_length(ModOffline,
|
|
|
|
User,
|
|
|
|
Server),
|
|
|
|
FQueueLen = [?AC((URLFunc({users_queue, Prefix,
|
|
|
|
User, Server})),
|
|
|
|
QueueLenStr)],
|
|
|
|
FLast = case
|
|
|
|
ejabberd_sm:get_user_resources(User,
|
|
|
|
Server)
|
|
|
|
of
|
|
|
|
[] ->
|
2019-06-24 17:47:51 +02:00
|
|
|
case get_last_info(User, Server) of
|
2019-06-22 16:08:45 +02:00
|
|
|
not_found -> translate:translate(Lang, ?T("Never"));
|
2013-03-14 10:33:02 +01:00
|
|
|
{ok, Shift, _Status} ->
|
|
|
|
TimeStamp = {Shift div
|
|
|
|
1000000,
|
|
|
|
Shift rem
|
|
|
|
1000000,
|
|
|
|
0},
|
|
|
|
{{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
|
|
|
_ -> translate:translate(Lang, ?T("Online"))
|
2013-03-14 10:33:02 +01:00
|
|
|
end,
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XE(<<"td">>,
|
|
|
|
[?AC((URLFunc({user, Prefix,
|
2018-04-03 00:12:43 +02:00
|
|
|
misc:url_encode(User),
|
2013-03-14 10:33:02 +01:00
|
|
|
Server})),
|
|
|
|
(us_to_list(US)))]),
|
2021-05-19 14:51:56 +02:00
|
|
|
?XAE(<<"td">>,
|
|
|
|
[{<<"class">>, <<"alignright">>}],
|
|
|
|
FQueueLen),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XC(<<"td">>, FLast)])
|
|
|
|
end,
|
|
|
|
Users)))]).
|
2004-04-26 17:38:07 +02:00
|
|
|
|
2010-01-12 13:02:50 +01:00
|
|
|
get_offlinemsg_length(ModOffline, User, Server) ->
|
|
|
|
case ModOffline of
|
2013-03-14 10:33:02 +01:00
|
|
|
none -> <<"disabled">>;
|
|
|
|
_ ->
|
2016-03-04 11:09:14 +01:00
|
|
|
pretty_string_int(ModOffline:count_offline_messages(User,Server))
|
2010-01-12 13:02:50 +01:00
|
|
|
end.
|
|
|
|
|
|
|
|
get_offlinemsg_module(Server) ->
|
2012-04-27 11:52:05 +02:00
|
|
|
case gen_mod:is_loaded(Server, mod_offline) of
|
2013-03-14 10:33:02 +01:00
|
|
|
true -> mod_offline;
|
|
|
|
false -> none
|
2009-12-09 18:46:51 +01:00
|
|
|
end.
|
|
|
|
|
2009-12-09 18:47:02 +01:00
|
|
|
get_lastactivity_menuitem_list(Server) ->
|
2019-06-24 17:47:51 +02:00
|
|
|
case gen_mod:is_loaded(Server, mod_last) of
|
|
|
|
true ->
|
|
|
|
case mod_last_opt:db_type(Server) of
|
|
|
|
mnesia -> [{<<"last-activity">>, ?T("Last Activity")}];
|
|
|
|
_ -> []
|
|
|
|
end;
|
|
|
|
false ->
|
|
|
|
[]
|
|
|
|
end.
|
|
|
|
|
|
|
|
get_last_info(User, Server) ->
|
|
|
|
case gen_mod:is_loaded(Server, mod_last) of
|
|
|
|
true ->
|
|
|
|
mod_last:get_last_info(User, Server);
|
|
|
|
false ->
|
|
|
|
not_found
|
2009-12-09 18:47:02 +01:00
|
|
|
end.
|
2009-12-09 18:46:51 +01:00
|
|
|
|
2005-04-17 20:08:34 +02:00
|
|
|
us_to_list({User, Server}) ->
|
2017-02-26 08:07:12 +01:00
|
|
|
jid:encode({User, Server, <<"">>}).
|
2005-04-17 20:08:34 +02:00
|
|
|
|
|
|
|
su_to_list({Server, User}) ->
|
2017-02-26 08:07:12 +01:00
|
|
|
jid:encode({User, Server, <<"">>}).
|
2005-04-17 20:08:34 +02:00
|
|
|
|
2009-06-23 22:45:39 +02:00
|
|
|
%%%==================================
|
|
|
|
%%%% get_stats
|
2004-04-26 17:38:07 +02:00
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
get_stats(global, Lang) ->
|
2016-10-11 22:20:22 +02:00
|
|
|
OnlineUsers = ejabberd_sm:connected_users_number(),
|
2013-03-14 10:33:02 +01:00
|
|
|
RegisteredUsers = lists:foldl(fun (Host, Total) ->
|
2017-05-11 13:37:21 +02:00
|
|
|
ejabberd_auth:count_users(Host)
|
2013-03-14 10:33:02 +01:00
|
|
|
+ Total
|
|
|
|
end,
|
2019-06-14 11:33:26 +02:00
|
|
|
0, ejabberd_option:hosts()),
|
2015-10-21 12:51:22 +02:00
|
|
|
OutS2SNumber = ejabberd_s2s:outgoing_s2s_number(),
|
|
|
|
InS2SNumber = ejabberd_s2s:incoming_s2s_number(),
|
2013-03-14 10:33:02 +01:00
|
|
|
[?XAE(<<"table">>, [],
|
|
|
|
[?XE(<<"tbody">>,
|
|
|
|
[?XE(<<"tr">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XCT(<<"td">>, ?T("Registered Users:")),
|
2021-05-19 14:51:56 +02:00
|
|
|
?XAC(<<"td">>,
|
|
|
|
[{<<"class">>, <<"alignright">>}],
|
|
|
|
(pretty_string_int(RegisteredUsers)))]),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"tr">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XCT(<<"td">>, ?T("Online Users:")),
|
2021-05-19 14:51:56 +02:00
|
|
|
?XAC(<<"td">>,
|
|
|
|
[{<<"class">>, <<"alignright">>}],
|
|
|
|
(pretty_string_int(OnlineUsers)))]),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"tr">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XCT(<<"td">>, ?T("Outgoing s2s Connections:")),
|
2021-05-19 14:51:56 +02:00
|
|
|
?XAC(<<"td">>,
|
|
|
|
[{<<"class">>, <<"alignright">>}],
|
|
|
|
(pretty_string_int(OutS2SNumber)))]),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"tr">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XCT(<<"td">>, ?T("Incoming s2s Connections:")),
|
2021-05-19 14:51:56 +02:00
|
|
|
?XAC(<<"td">>,
|
|
|
|
[{<<"class">>, <<"alignright">>}],
|
|
|
|
(pretty_string_int(InS2SNumber)))])])])];
|
2005-06-20 05:18:13 +02:00
|
|
|
get_stats(Host, Lang) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
OnlineUsers =
|
|
|
|
length(ejabberd_sm:get_vh_session_list(Host)),
|
|
|
|
RegisteredUsers =
|
2017-05-11 13:37:21 +02:00
|
|
|
ejabberd_auth:count_users(Host),
|
2013-03-14 10:33:02 +01:00
|
|
|
[?XAE(<<"table">>, [],
|
|
|
|
[?XE(<<"tbody">>,
|
|
|
|
[?XE(<<"tr">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XCT(<<"td">>, ?T("Registered Users:")),
|
2021-05-19 14:51:56 +02:00
|
|
|
?XAC(<<"td">>,
|
|
|
|
[{<<"class">>, <<"alignright">>}],
|
|
|
|
(pretty_string_int(RegisteredUsers)))]),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"tr">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XCT(<<"td">>, ?T("Online Users:")),
|
2021-05-19 14:51:56 +02:00
|
|
|
?XAC(<<"td">>,
|
|
|
|
[{<<"class">>, <<"alignright">>}],
|
|
|
|
(pretty_string_int(OnlineUsers)))])])])].
|
2004-05-04 21:47:24 +02:00
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
list_online_users(Host, _Lang) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
Users = [{S, U}
|
|
|
|
|| {U, S, _R} <- ejabberd_sm:get_vh_session_list(Host)],
|
2004-10-05 21:31:17 +02:00
|
|
|
SUsers = lists:usort(Users),
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:flatmap(fun ({_S, U} = SU) ->
|
|
|
|
[?AC(<<"../user/",
|
2018-04-03 00:12:43 +02:00
|
|
|
(misc:url_encode(U))/binary, "/">>,
|
2013-03-14 10:33:02 +01:00
|
|
|
(su_to_list(SU))),
|
|
|
|
?BR]
|
|
|
|
end,
|
|
|
|
SUsers).
|
2004-10-05 21:31:17 +02:00
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
user_info(User, Server, Query, Lang) ->
|
2015-11-24 16:44:13 +01:00
|
|
|
LServer = jid:nameprep(Server),
|
|
|
|
US = {jid:nodeprep(User), LServer},
|
2005-04-17 20:08:34 +02:00
|
|
|
Res = user_parse_query(User, Server, Query),
|
2013-03-14 10:33:02 +01:00
|
|
|
Resources = ejabberd_sm:get_user_resources(User,
|
|
|
|
Server),
|
2004-05-04 21:47:24 +02:00
|
|
|
FResources =
|
2013-03-14 10:33:02 +01:00
|
|
|
case Resources of
|
2019-06-22 16:08:45 +02:00
|
|
|
[] -> [?CT(?T("None"))];
|
2013-03-14 10:33:02 +01:00
|
|
|
_ ->
|
|
|
|
[?XE(<<"ul">>,
|
|
|
|
(lists:map(
|
|
|
|
fun (R) ->
|
|
|
|
FIP = case
|
|
|
|
ejabberd_sm:get_user_info(User,
|
|
|
|
Server,
|
|
|
|
R)
|
|
|
|
of
|
|
|
|
offline -> <<"">>;
|
|
|
|
Info
|
|
|
|
when
|
|
|
|
is_list(Info) ->
|
|
|
|
Node =
|
|
|
|
proplists:get_value(node,
|
|
|
|
Info),
|
|
|
|
Conn =
|
|
|
|
proplists:get_value(conn,
|
|
|
|
Info),
|
|
|
|
{IP, Port} =
|
|
|
|
proplists:get_value(ip,
|
|
|
|
Info),
|
|
|
|
ConnS = case Conn of
|
|
|
|
c2s ->
|
|
|
|
<<"plain">>;
|
|
|
|
c2s_tls ->
|
|
|
|
<<"tls">>;
|
|
|
|
c2s_compressed ->
|
|
|
|
<<"zlib">>;
|
|
|
|
c2s_compressed_tls ->
|
|
|
|
<<"tls+zlib">>;
|
|
|
|
http_bind ->
|
2015-07-22 11:54:11 +02:00
|
|
|
<<"http-bind">>;
|
|
|
|
websocket ->
|
|
|
|
<<"websocket">>;
|
|
|
|
_ ->
|
|
|
|
<<"unknown">>
|
2013-03-14 10:33:02 +01:00
|
|
|
end,
|
2015-07-15 21:36:36 +02:00
|
|
|
<<ConnS/binary,
|
2013-03-14 10:33:02 +01:00
|
|
|
"://",
|
2017-04-11 12:13:58 +02:00
|
|
|
(misc:ip_to_list(IP))/binary,
|
2013-03-14 10:33:02 +01:00
|
|
|
":",
|
2016-09-24 22:34:28 +02:00
|
|
|
(integer_to_binary(Port))/binary,
|
2013-03-14 10:33:02 +01:00
|
|
|
"#",
|
2017-04-11 12:13:58 +02:00
|
|
|
(misc:atom_to_binary(Node))/binary>>
|
2013-03-14 10:33:02 +01:00
|
|
|
end,
|
2015-07-15 21:36:36 +02:00
|
|
|
case direction(Lang) of
|
|
|
|
[{_, <<"rtl">>}] -> ?LI([?C((<<FIP/binary, " - ", R/binary>>))]);
|
|
|
|
_ -> ?LI([?C((<<R/binary, " - ", FIP/binary>>))])
|
|
|
|
end
|
2013-03-14 10:33:02 +01:00
|
|
|
end,
|
|
|
|
lists:sort(Resources))))]
|
|
|
|
end,
|
2014-02-26 17:18:12 +01:00
|
|
|
FPassword = [?INPUT(<<"text">>, <<"password">>, <<"">>),
|
2013-03-14 10:33:02 +01:00
|
|
|
?C(<<" ">>),
|
|
|
|
?INPUTT(<<"submit">>, <<"chpassword">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("Change Password"))],
|
2013-03-14 10:33:02 +01:00
|
|
|
UserItems = ejabberd_hooks:run_fold(webadmin_user,
|
|
|
|
LServer, [], [User, Server, Lang]),
|
|
|
|
LastActivity = case ejabberd_sm:get_user_resources(User,
|
|
|
|
Server)
|
|
|
|
of
|
|
|
|
[] ->
|
2019-06-24 17:47:51 +02:00
|
|
|
case get_last_info(User, Server) of
|
2019-06-22 16:08:45 +02:00
|
|
|
not_found -> translate:translate(Lang, ?T("Never"));
|
2013-03-14 10:33:02 +01:00
|
|
|
{ok, Shift, _Status} ->
|
|
|
|
TimeStamp = {Shift div 1000000,
|
|
|
|
Shift rem 1000000, 0},
|
|
|
|
{{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
|
|
|
_ -> translate:translate(Lang, ?T("Online"))
|
2010-01-03 01:40:37 +01:00
|
|
|
end,
|
2020-11-09 12:20:23 +01:00
|
|
|
[?XC(<<"h1">>, (str:translate_and_format(Lang, ?T("User ~ts"),
|
2013-03-14 10:33:02 +01:00
|
|
|
[us_to_list(US)])))]
|
|
|
|
++
|
|
|
|
case Res of
|
2019-06-22 16:08:45 +02:00
|
|
|
ok -> [?XREST(?T("Submitted"))];
|
|
|
|
error -> [?XREST(?T("Bad format"))];
|
2013-03-14 10:33:02 +01:00
|
|
|
nothing -> []
|
|
|
|
end
|
|
|
|
++
|
|
|
|
[?XAE(<<"form">>,
|
|
|
|
[{<<"action">>, <<"">>}, {<<"method">>, <<"post">>}],
|
2019-06-22 16:08:45 +02:00
|
|
|
([?XCT(<<"h3">>, ?T("Connected Resources:"))] ++
|
2013-03-14 10:33:02 +01:00
|
|
|
FResources ++
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XCT(<<"h3">>, ?T("Password:"))] ++
|
2013-03-14 10:33:02 +01:00
|
|
|
FPassword ++
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XCT(<<"h3">>, ?T("Last Activity"))] ++
|
2013-03-14 10:33:02 +01:00
|
|
|
[?C(LastActivity)] ++
|
|
|
|
UserItems ++
|
|
|
|
[?P,
|
2020-08-24 13:38:51 +02:00
|
|
|
?INPUTTD(<<"submit">>, <<"removeuser">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("Remove User"))]))].
|
2004-05-04 21:47:24 +02:00
|
|
|
|
2005-04-17 20:08:34 +02:00
|
|
|
user_parse_query(User, Server, Query) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:foldl(fun ({Action, _Value}, Acc)
|
|
|
|
when Acc == nothing ->
|
|
|
|
user_parse_query1(Action, User, Server, Query);
|
|
|
|
({_Action, _Value}, Acc) -> Acc
|
|
|
|
end,
|
|
|
|
nothing, Query).
|
|
|
|
|
|
|
|
user_parse_query1(<<"password">>, _User, _Server,
|
|
|
|
_Query) ->
|
2008-10-12 16:16:05 +02:00
|
|
|
nothing;
|
2013-03-14 10:33:02 +01:00
|
|
|
user_parse_query1(<<"chpassword">>, User, Server,
|
|
|
|
Query) ->
|
|
|
|
case lists:keysearch(<<"password">>, 1, Query) of
|
|
|
|
{value, {_, Password}} ->
|
|
|
|
ejabberd_auth:set_password(User, Server, Password), ok;
|
|
|
|
_ -> error
|
2008-10-12 16:16:05 +02:00
|
|
|
end;
|
2013-03-14 10:33:02 +01:00
|
|
|
user_parse_query1(<<"removeuser">>, User, Server,
|
|
|
|
_Query) ->
|
|
|
|
ejabberd_auth:remove_user(User, Server), ok;
|
2008-10-12 16:16:05 +02:00
|
|
|
user_parse_query1(Action, User, Server, Query) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
case ejabberd_hooks:run_fold(webadmin_user_parse_query,
|
|
|
|
Server, [], [Action, User, Server, Query])
|
|
|
|
of
|
|
|
|
[] -> nothing;
|
|
|
|
Res -> Res
|
2004-10-05 21:31:17 +02:00
|
|
|
end.
|
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
list_last_activity(Host, Lang, Integral, Period) ->
|
2019-02-27 09:56:20 +01:00
|
|
|
TimeStamp = erlang:system_time(second),
|
2005-05-09 01:39:46 +02:00
|
|
|
case Period of
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"all">> -> TS = 0, Days = infinity;
|
|
|
|
<<"year">> -> TS = TimeStamp - 366 * 86400, Days = 366;
|
|
|
|
_ -> TS = TimeStamp - 31 * 86400, Days = 31
|
2005-05-09 01:39:46 +02:00
|
|
|
end,
|
2013-03-14 10:33:02 +01:00
|
|
|
case catch mnesia:dirty_select(last_activity,
|
|
|
|
[{{last_activity, {'_', Host}, '$1', '_'},
|
|
|
|
[{'>', '$1', TS}],
|
|
|
|
[{trunc,
|
|
|
|
{'/', {'-', TimeStamp, '$1'}, 86400}}]}])
|
|
|
|
of
|
|
|
|
{'EXIT', _Reason} -> [];
|
|
|
|
Vals ->
|
|
|
|
Hist = histogram(Vals, Integral),
|
2019-06-22 16:08:45 +02:00
|
|
|
if Hist == [] -> [?CT(?T("No Data"))];
|
2013-03-14 10:33:02 +01:00
|
|
|
true ->
|
|
|
|
Left = if Days == infinity -> 0;
|
|
|
|
true -> Days - length(Hist)
|
|
|
|
end,
|
|
|
|
Tail = if Integral ->
|
|
|
|
lists:duplicate(Left, lists:last(Hist));
|
|
|
|
true -> lists:duplicate(Left, 0)
|
|
|
|
end,
|
|
|
|
Max = lists:max(Hist),
|
|
|
|
[?XAE(<<"ol">>,
|
|
|
|
[{<<"id">>, <<"lastactivity">>},
|
|
|
|
{<<"start">>, <<"0">>}],
|
|
|
|
[?XAE(<<"li">>,
|
|
|
|
[{<<"style">>,
|
|
|
|
<<"width:",
|
2016-11-24 13:06:06 +01:00
|
|
|
(integer_to_binary(trunc(90 * V / Max)))/binary,
|
2013-03-14 10:33:02 +01:00
|
|
|
"%;">>}],
|
|
|
|
[{xmlcdata, pretty_string_int(V)}])
|
|
|
|
|| V <- Hist ++ Tail])]
|
|
|
|
end
|
2005-05-09 01:39:46 +02:00
|
|
|
end.
|
|
|
|
|
|
|
|
histogram(Values, Integral) ->
|
|
|
|
histogram(lists:sort(Values), Integral, 0, 0, []).
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
histogram([H | T], Integral, Current, Count, Hist)
|
|
|
|
when Current == H ->
|
2005-05-09 01:39:46 +02:00
|
|
|
histogram(T, Integral, Current, Count + 1, Hist);
|
2013-03-14 10:33:02 +01:00
|
|
|
histogram([H | _] = Values, Integral, Current, Count,
|
|
|
|
Hist)
|
|
|
|
when Current < H ->
|
|
|
|
if Integral ->
|
|
|
|
histogram(Values, Integral, Current + 1, Count,
|
|
|
|
[Count | Hist]);
|
|
|
|
true ->
|
|
|
|
histogram(Values, Integral, Current + 1, 0,
|
|
|
|
[Count | Hist])
|
2005-05-09 01:39:46 +02:00
|
|
|
end;
|
|
|
|
histogram([], _Integral, _Current, Count, Hist) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
if Count > 0 -> lists:reverse([Count | Hist]);
|
|
|
|
true -> lists:reverse(Hist)
|
2005-05-09 01:39:46 +02:00
|
|
|
end.
|
|
|
|
|
2009-06-23 22:45:39 +02:00
|
|
|
%%%==================================
|
|
|
|
%%%% get_nodes
|
2004-08-03 00:17:05 +02:00
|
|
|
|
2004-05-09 20:38:49 +02:00
|
|
|
get_nodes(Lang) ->
|
2017-01-03 17:21:02 +01:00
|
|
|
RunningNodes = ejabberd_cluster:get_nodes(),
|
2017-01-09 17:54:10 +01:00
|
|
|
StoppedNodes = ejabberd_cluster:get_known_nodes()
|
2013-03-14 10:33:02 +01:00
|
|
|
-- RunningNodes,
|
2019-06-22 16:08:45 +02:00
|
|
|
FRN = if RunningNodes == [] -> ?CT(?T("None"));
|
2013-03-14 10:33:02 +01:00
|
|
|
true ->
|
|
|
|
?XE(<<"ul">>,
|
|
|
|
(lists:map(fun (N) ->
|
|
|
|
S = iolist_to_binary(atom_to_list(N)),
|
|
|
|
?LI([?AC(<<"../node/", S/binary, "/">>,
|
|
|
|
S)])
|
|
|
|
end,
|
|
|
|
lists:sort(RunningNodes))))
|
2004-05-14 16:46:53 +02:00
|
|
|
end,
|
2019-06-22 16:08:45 +02:00
|
|
|
FSN = if StoppedNodes == [] -> ?CT(?T("None"));
|
2013-03-14 10:33:02 +01:00
|
|
|
true ->
|
|
|
|
?XE(<<"ul">>,
|
|
|
|
(lists:map(fun (N) ->
|
|
|
|
S = iolist_to_binary(atom_to_list(N)),
|
|
|
|
?LI([?C(S)])
|
|
|
|
end,
|
|
|
|
lists:sort(StoppedNodes))))
|
2004-05-14 16:46:53 +02:00
|
|
|
end,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XCT(<<"h1">>, ?T("Nodes")),
|
|
|
|
?XCT(<<"h3">>, ?T("Running Nodes")), FRN,
|
|
|
|
?XCT(<<"h3">>, ?T("Stopped Nodes")), FSN].
|
2004-05-14 16:46:53 +02:00
|
|
|
|
|
|
|
search_running_node(SNode) ->
|
2017-01-03 17:21:02 +01:00
|
|
|
RunningNodes = ejabberd_cluster:get_nodes(),
|
|
|
|
search_running_node(SNode, RunningNodes).
|
2004-05-09 20:38:49 +02:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
search_running_node(_, []) -> false;
|
2004-05-14 16:46:53 +02:00
|
|
|
search_running_node(SNode, [Node | Nodes]) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
case iolist_to_binary(atom_to_list(Node)) of
|
|
|
|
SNode -> Node;
|
|
|
|
_ -> search_running_node(SNode, Nodes)
|
2004-05-14 16:46:53 +02:00
|
|
|
end.
|
2004-05-09 20:38:49 +02:00
|
|
|
|
2020-03-26 13:43:24 +01:00
|
|
|
get_node(global, Node, [], Query, Lang) ->
|
2004-05-22 21:48:35 +02:00
|
|
|
Res = node_parse_query(Node, Query),
|
2020-03-26 13:43:24 +01:00
|
|
|
Base = get_base_path(global, Node, 2),
|
|
|
|
MenuItems2 = make_menu_items(global, Node, Base, Lang),
|
2013-03-14 10:33:02 +01:00
|
|
|
[?XC(<<"h1">>,
|
2020-11-09 12:20:23 +01:00
|
|
|
(str:translate_and_format(Lang, ?T("Node ~p"), [Node])))]
|
2013-03-14 10:33:02 +01:00
|
|
|
++
|
|
|
|
case Res of
|
2019-06-22 16:08:45 +02:00
|
|
|
ok -> [?XREST(?T("Submitted"))];
|
|
|
|
error -> [?XREST(?T("Bad format"))];
|
2013-03-14 10:33:02 +01:00
|
|
|
nothing -> []
|
|
|
|
end
|
|
|
|
++
|
|
|
|
[?XE(<<"ul">>,
|
2019-10-02 11:54:22 +02:00
|
|
|
([?LI([?ACT(<<"db/">>, ?T("Database"))]),
|
|
|
|
?LI([?ACT(<<"backup/">>, ?T("Backup"))]),
|
|
|
|
?LI([?ACT(<<"stats/">>, ?T("Statistics"))]),
|
|
|
|
?LI([?ACT(<<"update/">>, ?T("Update"))])]
|
2013-03-14 10:33:02 +01:00
|
|
|
++ MenuItems2)),
|
|
|
|
?XAE(<<"form">>,
|
|
|
|
[{<<"action">>, <<"">>}, {<<"method">>, <<"post">>}],
|
2019-06-22 16:08:45 +02:00
|
|
|
[?INPUTT(<<"submit">>, <<"restart">>, ?T("Restart")),
|
2013-03-14 10:33:02 +01:00
|
|
|
?C(<<" ">>),
|
2020-08-24 13:38:51 +02:00
|
|
|
?INPUTTD(<<"submit">>, <<"stop">>, ?T("Stop"))])];
|
2020-03-26 13:43:24 +01:00
|
|
|
get_node(Host, Node, [], _Query, Lang) ->
|
|
|
|
Base = get_base_path(Host, Node, 4),
|
|
|
|
MenuItems2 = make_menu_items(Host, Node, Base, Lang),
|
2020-11-09 12:20:23 +01:00
|
|
|
[?XC(<<"h1">>, (str:translate_and_format(Lang, ?T("Node ~p"), [Node]))),
|
2019-06-14 11:33:26 +02:00
|
|
|
?XE(<<"ul">>, MenuItems2)];
|
2020-03-26 13:43:24 +01:00
|
|
|
get_node(global, Node, [<<"db">>], Query, Lang) ->
|
2015-10-07 00:06:58 +02:00
|
|
|
case ejabberd_cluster:call(Node, mnesia, system_info, [tables]) of
|
2013-03-14 10:33:02 +01:00
|
|
|
{badrpc, _Reason} ->
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XCT(<<"h1">>, ?T("RPC Call Error"))];
|
2013-03-14 10:33:02 +01:00
|
|
|
Tables ->
|
|
|
|
ResS = case node_db_parse_query(Node, Tables, Query) of
|
|
|
|
nothing -> [];
|
2019-06-22 16:08:45 +02:00
|
|
|
ok -> [?XREST(?T("Submitted"))]
|
2013-03-14 10:33:02 +01:00
|
|
|
end,
|
|
|
|
STables = lists:sort(Tables),
|
|
|
|
Rows = lists:map(fun (Table) ->
|
|
|
|
STable =
|
|
|
|
iolist_to_binary(atom_to_list(Table)),
|
2015-10-07 00:06:58 +02:00
|
|
|
TInfo = case ejabberd_cluster:call(Node, mnesia,
|
2013-03-14 10:33:02 +01:00
|
|
|
table_info,
|
|
|
|
[Table, all])
|
|
|
|
of
|
|
|
|
{badrpc, _} -> [];
|
|
|
|
I -> I
|
|
|
|
end,
|
|
|
|
{Type, Size, Memory} = case
|
|
|
|
{lists:keysearch(storage_type,
|
|
|
|
1,
|
|
|
|
TInfo),
|
|
|
|
lists:keysearch(size,
|
|
|
|
1,
|
|
|
|
TInfo),
|
|
|
|
lists:keysearch(memory,
|
|
|
|
1,
|
|
|
|
TInfo)}
|
|
|
|
of
|
|
|
|
{{value,
|
|
|
|
{storage_type,
|
|
|
|
T}},
|
|
|
|
{value, {size, S}},
|
|
|
|
{value,
|
|
|
|
{memory, M}}} ->
|
|
|
|
{T, S, M};
|
|
|
|
_ -> {unknown, 0, 0}
|
|
|
|
end,
|
2021-05-18 14:53:06 +02:00
|
|
|
MemoryB = Memory*erlang:system_info(wordsize),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"tr">>,
|
2021-05-14 18:47:05 +02:00
|
|
|
[?XE(<<"td">>,
|
|
|
|
[?AC(<<"./", STable/binary,
|
|
|
|
"/">>,
|
|
|
|
STable)]),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"td">>,
|
|
|
|
[db_storage_select(STable, Type,
|
|
|
|
Lang)]),
|
2021-05-14 18:47:05 +02:00
|
|
|
?XAE(<<"td">>,
|
2013-03-14 10:33:02 +01:00
|
|
|
[{<<"class">>, <<"alignright">>}],
|
2021-05-14 18:47:05 +02:00
|
|
|
[?AC(<<"./", STable/binary,
|
|
|
|
"/1/">>,
|
|
|
|
(pretty_string_int(Size)))]),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XAC(<<"td">>,
|
|
|
|
[{<<"class">>, <<"alignright">>}],
|
2021-05-18 14:53:06 +02:00
|
|
|
(pretty_string_int(MemoryB)))])
|
2013-03-14 10:33:02 +01:00
|
|
|
end,
|
|
|
|
STables),
|
|
|
|
[?XC(<<"h1">>,
|
2020-11-09 12:20:23 +01:00
|
|
|
(str:translate_and_format(Lang, ?T("Database Tables at ~p"),
|
2013-03-14 10:33:02 +01:00
|
|
|
[Node]))
|
|
|
|
)]
|
|
|
|
++
|
|
|
|
ResS ++
|
|
|
|
[?XAE(<<"form">>,
|
|
|
|
[{<<"action">>, <<"">>}, {<<"method">>, <<"post">>}],
|
|
|
|
[?XAE(<<"table">>, [],
|
|
|
|
[?XE(<<"thead">>,
|
|
|
|
[?XE(<<"tr">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XCT(<<"td">>, ?T("Name")),
|
|
|
|
?XCT(<<"td">>, ?T("Storage Type")),
|
2021-05-19 14:51:56 +02:00
|
|
|
?XACT(<<"td">>,
|
|
|
|
[{<<"class">>, <<"alignright">>}],
|
|
|
|
?T("Elements")),
|
|
|
|
?XACT(<<"td">>,
|
|
|
|
[{<<"class">>, <<"alignright">>}],
|
|
|
|
?T("Memory"))])]),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"tbody">>,
|
|
|
|
(Rows ++
|
|
|
|
[?XE(<<"tr">>,
|
|
|
|
[?XAE(<<"td">>,
|
|
|
|
[{<<"colspan">>, <<"4">>},
|
|
|
|
{<<"class">>, <<"alignright">>}],
|
|
|
|
[?INPUTT(<<"submit">>,
|
|
|
|
<<"submit">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("Submit"))])])]))])])]
|
2004-05-14 16:46:53 +02:00
|
|
|
end;
|
2021-05-14 18:47:05 +02:00
|
|
|
get_node(global, Node, [<<"db">>, TableName], _Query, Lang) ->
|
|
|
|
make_table_view(Node, TableName, Lang);
|
|
|
|
get_node(global, Node, [<<"db">>, TableName, PageNumber], _Query, Lang) ->
|
|
|
|
make_table_elements_view(Node, TableName, Lang, binary_to_integer(PageNumber));
|
2020-03-26 13:43:24 +01:00
|
|
|
get_node(global, Node, [<<"backup">>], Query, Lang) ->
|
2009-12-03 16:59:01 +01:00
|
|
|
HomeDirRaw = case {os:getenv("HOME"), os:type()} of
|
2013-03-14 10:33:02 +01:00
|
|
|
{EnvHome, _} when is_list(EnvHome) -> list_to_binary(EnvHome);
|
|
|
|
{false, {win32, _Osname}} -> <<"C:/">>;
|
|
|
|
{false, _} -> <<"/tmp/">>
|
|
|
|
end,
|
2009-12-03 16:59:01 +01:00
|
|
|
HomeDir = filename:nativename(HomeDirRaw),
|
2009-01-12 22:48:34 +01:00
|
|
|
ResS = case node_backup_parse_query(Node, Query) of
|
2013-03-14 10:33:02 +01:00
|
|
|
nothing -> [];
|
2019-06-22 16:08:45 +02:00
|
|
|
ok -> [?XREST(?T("Submitted"))];
|
2013-03-14 10:33:02 +01:00
|
|
|
{error, Error} ->
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XRES(<<(translate:translate(Lang, ?T("Error")))/binary, ": ",
|
2016-11-24 13:06:06 +01:00
|
|
|
((str:format("~p", [Error])))/binary>>)]
|
2009-01-12 22:48:34 +01:00
|
|
|
end,
|
2020-11-09 12:20:23 +01:00
|
|
|
[?XC(<<"h1">>, (str:translate_and_format(Lang, ?T("Backup of ~p"), [Node])))]
|
2013-03-14 10:33:02 +01:00
|
|
|
++
|
|
|
|
ResS ++
|
|
|
|
[?XCT(<<"p">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("Please note that these options will "
|
|
|
|
"only backup the builtin Mnesia database. "
|
|
|
|
"If you are using the ODBC module, you "
|
|
|
|
"also need to backup your SQL database "
|
|
|
|
"separately.")),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XAE(<<"form">>,
|
|
|
|
[{<<"action">>, <<"">>}, {<<"method">>, <<"post">>}],
|
|
|
|
[?XAE(<<"table">>, [],
|
|
|
|
[?XE(<<"tbody">>,
|
|
|
|
[?XE(<<"tr">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XCT(<<"td">>, ?T("Store binary backup:")),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>, <<"storepath">>,
|
|
|
|
(filename:join(HomeDir,
|
|
|
|
"ejabberd.backup")))]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>, <<"store">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("OK"))])]),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("Restore binary backup immediately:")),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>, <<"restorepath">>,
|
|
|
|
(filename:join(HomeDir,
|
|
|
|
"ejabberd.backup")))]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>, <<"restore">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("OK"))])]),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("Restore binary backup after next ejabberd "
|
|
|
|
"restart (requires less memory):")),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>, <<"fallbackpath">>,
|
|
|
|
(filename:join(HomeDir,
|
|
|
|
"ejabberd.backup")))]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>, <<"fallback">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("OK"))])]),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"tr">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XCT(<<"td">>, ?T("Store plain text backup:")),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>, <<"dumppath">>,
|
|
|
|
(filename:join(HomeDir,
|
|
|
|
"ejabberd.dump")))]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>, <<"dump">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("OK"))])]),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("Restore plain text backup immediately:")),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>, <<"loadpath">>,
|
|
|
|
(filename:join(HomeDir,
|
|
|
|
"ejabberd.dump")))]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>, <<"load">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("OK"))])]),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("Import users data from a PIEFXIS file "
|
|
|
|
"(XEP-0227):")),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>,
|
|
|
|
<<"import_piefxis_filepath">>,
|
|
|
|
(filename:join(HomeDir,
|
|
|
|
"users.xml")))]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>,
|
|
|
|
<<"import_piefxis_file">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("OK"))])]),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("Export data of all users in the server "
|
|
|
|
"to PIEFXIS files (XEP-0227):")),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>,
|
|
|
|
<<"export_piefxis_dirpath">>,
|
|
|
|
HomeDir)]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>,
|
|
|
|
<<"export_piefxis_dir">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("OK"))])]),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XE(<<"td">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?CT(?T("Export data of users in a host to PIEFXIS "
|
|
|
|
"files (XEP-0227):")),
|
2013-03-14 10:33:02 +01:00
|
|
|
?C(<<" ">>),
|
2019-08-22 18:07:05 +02:00
|
|
|
make_select_host(Lang, <<"export_piefxis_host_dirhost">>)]),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>,
|
|
|
|
<<"export_piefxis_host_dirpath">>,
|
|
|
|
HomeDir)]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>,
|
|
|
|
<<"export_piefxis_host_dir">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("OK"))])]),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XE(<<"td">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?CT(?T("Export all tables as SQL queries "
|
|
|
|
"to a file:")),
|
2013-03-14 10:33:02 +01:00
|
|
|
?C(<<" ">>),
|
2019-08-22 18:07:05 +02:00
|
|
|
make_select_host(Lang, <<"export_sql_filehost">>)]),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>,
|
|
|
|
<<"export_sql_filepath">>,
|
|
|
|
(filename:join(HomeDir,
|
|
|
|
"db.sql")))]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>, <<"export_sql_file">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("OK"))])]),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("Import user data from jabberd14 spool "
|
|
|
|
"file:")),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>, <<"import_filepath">>,
|
|
|
|
(filename:join(HomeDir,
|
|
|
|
"user1.xml")))]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>, <<"import_file">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("OK"))])]),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("Import users data from jabberd14 spool "
|
|
|
|
"directory:")),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>, <<"import_dirpath">>,
|
|
|
|
<<"/var/spool/jabber/">>)]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>, <<"import_dir">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("OK"))])])])])])];
|
2020-03-26 13:43:24 +01:00
|
|
|
get_node(global, Node, [<<"stats">>], _Query, Lang) ->
|
2015-10-07 00:06:58 +02:00
|
|
|
UpTime = ejabberd_cluster:call(Node, erlang, statistics,
|
2013-03-14 10:33:02 +01:00
|
|
|
[wall_clock]),
|
2016-11-24 13:06:06 +01:00
|
|
|
UpTimeS = (str:format("~.3f",
|
2013-03-14 10:33:02 +01:00
|
|
|
[element(1, UpTime) / 1000])),
|
2021-05-19 14:51:03 +02:00
|
|
|
UpTimeDate = uptime_date(Node),
|
2015-10-07 00:06:58 +02:00
|
|
|
CPUTime = ejabberd_cluster:call(Node, erlang, statistics, [runtime]),
|
2016-11-24 13:06:06 +01:00
|
|
|
CPUTimeS = (str:format("~.3f",
|
2013-03-14 10:33:02 +01:00
|
|
|
[element(1, CPUTime) / 1000])),
|
2016-10-11 22:20:22 +02:00
|
|
|
OnlineUsers = ejabberd_sm:connected_users_number(),
|
2015-10-07 00:06:58 +02:00
|
|
|
TransactionsCommitted = ejabberd_cluster:call(Node, mnesia,
|
2013-03-14 10:33:02 +01:00
|
|
|
system_info, [transaction_commits]),
|
2015-10-07 00:06:58 +02:00
|
|
|
TransactionsAborted = ejabberd_cluster:call(Node, mnesia,
|
2013-03-14 10:33:02 +01:00
|
|
|
system_info, [transaction_failures]),
|
2015-10-07 00:06:58 +02:00
|
|
|
TransactionsRestarted = ejabberd_cluster:call(Node, mnesia,
|
2013-03-14 10:33:02 +01:00
|
|
|
system_info, [transaction_restarts]),
|
2015-10-07 00:06:58 +02:00
|
|
|
TransactionsLogged = ejabberd_cluster:call(Node, mnesia, system_info,
|
2013-03-14 10:33:02 +01:00
|
|
|
[transaction_log_writes]),
|
|
|
|
[?XC(<<"h1">>,
|
2020-11-09 12:20:23 +01:00
|
|
|
(str:translate_and_format(Lang, ?T("Statistics of ~p"), [Node]))),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XAE(<<"table">>, [],
|
|
|
|
[?XE(<<"tbody">>,
|
|
|
|
[?XE(<<"tr">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XCT(<<"td">>, ?T("Uptime:")),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XAC(<<"td">>, [{<<"class">>, <<"alignright">>}],
|
|
|
|
UpTimeS)]),
|
2021-05-19 14:51:03 +02:00
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?X(<<"td">>),
|
|
|
|
?XAC(<<"td">>, [{<<"class">>, <<"alignright">>}],
|
|
|
|
UpTimeDate)]),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"tr">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XCT(<<"td">>, ?T("CPU Time:")),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XAC(<<"td">>, [{<<"class">>, <<"alignright">>}],
|
|
|
|
CPUTimeS)]),
|
|
|
|
?XE(<<"tr">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XCT(<<"td">>, ?T("Online Users:")),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XAC(<<"td">>, [{<<"class">>, <<"alignright">>}],
|
|
|
|
(pretty_string_int(OnlineUsers)))]),
|
|
|
|
?XE(<<"tr">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XCT(<<"td">>, ?T("Transactions Committed:")),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XAC(<<"td">>, [{<<"class">>, <<"alignright">>}],
|
|
|
|
(pretty_string_int(TransactionsCommitted)))]),
|
|
|
|
?XE(<<"tr">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XCT(<<"td">>, ?T("Transactions Aborted:")),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XAC(<<"td">>, [{<<"class">>, <<"alignright">>}],
|
|
|
|
(pretty_string_int(TransactionsAborted)))]),
|
|
|
|
?XE(<<"tr">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XCT(<<"td">>, ?T("Transactions Restarted:")),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XAC(<<"td">>, [{<<"class">>, <<"alignright">>}],
|
|
|
|
(pretty_string_int(TransactionsRestarted)))]),
|
|
|
|
?XE(<<"tr">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XCT(<<"td">>, ?T("Transactions Logged:")),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XAC(<<"td">>, [{<<"class">>, <<"alignright">>}],
|
|
|
|
(pretty_string_int(TransactionsLogged)))])])])];
|
2020-03-26 13:43:24 +01:00
|
|
|
get_node(global, Node, [<<"update">>], Query, Lang) ->
|
2015-10-07 00:06:58 +02:00
|
|
|
ejabberd_cluster:call(Node, code, purge, [ejabberd_update]),
|
2006-02-27 05:43:16 +01:00
|
|
|
Res = node_update_parse_query(Node, Query),
|
2015-10-07 00:06:58 +02:00
|
|
|
ejabberd_cluster:call(Node, code, load_file, [ejabberd_update]),
|
2013-03-14 10:33:02 +01:00
|
|
|
{ok, _Dir, UpdatedBeams, Script, LowLevelScript,
|
|
|
|
Check} =
|
2015-10-07 00:06:58 +02:00
|
|
|
ejabberd_cluster:call(Node, ejabberd_update, update_info, []),
|
2013-03-14 10:33:02 +01:00
|
|
|
Mods = case UpdatedBeams of
|
2019-06-22 16:08:45 +02:00
|
|
|
[] -> ?CT(?T("None"));
|
2013-03-14 10:33:02 +01:00
|
|
|
_ ->
|
|
|
|
BeamsLis = lists:map(fun (Beam) ->
|
|
|
|
BeamString =
|
|
|
|
iolist_to_binary(atom_to_list(Beam)),
|
|
|
|
?LI([?INPUT(<<"checkbox">>,
|
|
|
|
<<"selected">>,
|
|
|
|
BeamString),
|
|
|
|
?C(BeamString)])
|
|
|
|
end,
|
|
|
|
UpdatedBeams),
|
|
|
|
SelectButtons = [?BR,
|
|
|
|
?INPUTATTRS(<<"button">>, <<"selectall">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("Select All"),
|
2013-03-14 10:33:02 +01:00
|
|
|
[{<<"onClick">>,
|
|
|
|
<<"selectAll()">>}]),
|
|
|
|
?C(<<" ">>),
|
|
|
|
?INPUTATTRS(<<"button">>, <<"unselectall">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("Unselect All"),
|
2013-03-14 10:33:02 +01:00
|
|
|
[{<<"onClick">>,
|
|
|
|
<<"unSelectAll()">>}])],
|
|
|
|
?XAE(<<"ul">>, [{<<"class">>, <<"nolistyle">>}],
|
|
|
|
(BeamsLis ++ SelectButtons))
|
|
|
|
end,
|
|
|
|
FmtScript = (?XC(<<"pre">>,
|
2016-11-24 13:06:06 +01:00
|
|
|
(str:format("~p", [Script])))),
|
2013-03-14 10:33:02 +01:00
|
|
|
FmtLowLevelScript = (?XC(<<"pre">>,
|
2016-11-24 13:06:06 +01:00
|
|
|
(str:format("~p", [LowLevelScript])))),
|
2013-03-14 10:33:02 +01:00
|
|
|
[?XC(<<"h1">>,
|
2020-11-09 12:20:23 +01:00
|
|
|
(str:translate_and_format(Lang, ?T("Update ~p"), [Node])))]
|
2013-03-14 10:33:02 +01:00
|
|
|
++
|
|
|
|
case Res of
|
2019-06-22 16:08:45 +02:00
|
|
|
ok -> [?XREST(?T("Submitted"))];
|
2013-03-14 10:33:02 +01:00
|
|
|
{error, ErrorText} ->
|
|
|
|
[?XREST(<<"Error: ", ErrorText/binary>>)];
|
|
|
|
nothing -> []
|
|
|
|
end
|
|
|
|
++
|
|
|
|
[?XAE(<<"form">>,
|
|
|
|
[{<<"action">>, <<"">>}, {<<"method">>, <<"post">>}],
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XCT(<<"h2">>, ?T("Update plan")),
|
|
|
|
?XCT(<<"h3">>, ?T("Modified modules")), Mods,
|
|
|
|
?XCT(<<"h3">>, ?T("Update script")), FmtScript,
|
|
|
|
?XCT(<<"h3">>, ?T("Low level update script")),
|
|
|
|
FmtLowLevelScript, ?XCT(<<"h3">>, ?T("Script check")),
|
2017-04-11 12:13:58 +02:00
|
|
|
?XC(<<"pre">>, (misc:atom_to_binary(Check))),
|
2009-05-27 19:28:55 +02:00
|
|
|
?BR,
|
2019-06-22 16:08:45 +02:00
|
|
|
?INPUTT(<<"submit">>, <<"update">>, ?T("Update"))])];
|
2020-03-26 13:43:24 +01:00
|
|
|
get_node(Host, Node, NPath, Query, Lang) ->
|
2016-08-09 09:56:32 +02:00
|
|
|
Res = case Host of
|
|
|
|
global ->
|
|
|
|
ejabberd_hooks:run_fold(webadmin_page_node, Host, [],
|
|
|
|
[Node, NPath, Query, Lang]);
|
|
|
|
_ ->
|
|
|
|
ejabberd_hooks:run_fold(webadmin_page_hostnode, Host, [],
|
|
|
|
[Host, Node, NPath, Query, Lang])
|
|
|
|
end,
|
|
|
|
case Res of
|
2013-03-14 10:33:02 +01:00
|
|
|
[] -> [?XC(<<"h1">>, <<"Not Found">>)];
|
2016-08-09 09:56:32 +02:00
|
|
|
_ -> Res
|
2007-08-23 02:51:54 +02:00
|
|
|
end.
|
|
|
|
|
2021-05-19 14:51:03 +02:00
|
|
|
uptime_date(Node) ->
|
|
|
|
Localtime = ejabberd_cluster:call(Node, erlang, localtime, []),
|
|
|
|
Now = calendar:datetime_to_gregorian_seconds(Localtime),
|
|
|
|
{Wall, _} = ejabberd_cluster:call(Node, erlang, statistics, [wall_clock]),
|
|
|
|
LastRestart = Now - (Wall div 1000),
|
|
|
|
{{Year, Month, Day}, {Hour, Minute, Second}} =
|
|
|
|
calendar:gregorian_seconds_to_datetime(LastRestart),
|
|
|
|
str:format("~w-~.2.0w-~.2.0w ~.2.0w:~.2.0w:~.2.0w",
|
|
|
|
[Year, Month, Day, Hour, Minute, Second]).
|
|
|
|
|
2009-06-23 22:45:39 +02:00
|
|
|
%%%==================================
|
|
|
|
%%%% node parse
|
2004-05-14 16:46:53 +02:00
|
|
|
|
2004-05-22 21:48:35 +02:00
|
|
|
node_parse_query(Node, Query) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
case lists:keysearch(<<"restart">>, 1, Query) of
|
|
|
|
{value, _} ->
|
2015-10-07 00:06:58 +02:00
|
|
|
case ejabberd_cluster:call(Node, init, restart, []) of
|
2013-03-14 10:33:02 +01:00
|
|
|
{badrpc, _Reason} -> error;
|
|
|
|
_ -> ok
|
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
case lists:keysearch(<<"stop">>, 1, Query) of
|
|
|
|
{value, _} ->
|
2015-10-07 00:06:58 +02:00
|
|
|
case ejabberd_cluster:call(Node, init, stop, []) of
|
2013-03-14 10:33:02 +01:00
|
|
|
{badrpc, _Reason} -> error;
|
|
|
|
_ -> ok
|
|
|
|
end;
|
|
|
|
_ -> nothing
|
|
|
|
end
|
2004-05-22 21:48:35 +02:00
|
|
|
end.
|
|
|
|
|
2019-08-22 18:07:05 +02:00
|
|
|
make_select_host(Lang, Name) ->
|
|
|
|
?XAE(<<"select">>,
|
|
|
|
[{<<"name">>, Name}],
|
|
|
|
(lists:map(fun (Host) ->
|
|
|
|
?XACT(<<"option">>,
|
|
|
|
([{<<"value">>, Host}]), Host)
|
|
|
|
end,
|
|
|
|
ejabberd_config:get_option(hosts)))).
|
|
|
|
|
2004-05-14 16:46:53 +02:00
|
|
|
db_storage_select(ID, Opt, Lang) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
?XAE(<<"select">>,
|
|
|
|
[{<<"name">>, <<"table", ID/binary>>}],
|
|
|
|
(lists:map(fun ({O, Desc}) ->
|
|
|
|
Sel = if O == Opt ->
|
|
|
|
[{<<"selected">>, <<"selected">>}];
|
|
|
|
true -> []
|
|
|
|
end,
|
|
|
|
?XACT(<<"option">>,
|
|
|
|
(Sel ++
|
|
|
|
[{<<"value">>,
|
|
|
|
iolist_to_binary(atom_to_list(O))}]),
|
|
|
|
Desc)
|
|
|
|
end,
|
2019-06-22 16:08:45 +02:00
|
|
|
[{ram_copies, ?T("RAM copy")},
|
|
|
|
{disc_copies, ?T("RAM and disc copy")},
|
|
|
|
{disc_only_copies, ?T("Disc only copy")},
|
|
|
|
{unknown, ?T("Remote copy")},
|
|
|
|
{delete_content, ?T("Delete content")},
|
|
|
|
{delete_table, ?T("Delete table")}]))).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
|
|
|
node_db_parse_query(_Node, _Tables, [{nokey, <<>>}]) ->
|
2009-01-12 22:48:34 +01:00
|
|
|
nothing;
|
2004-05-16 22:13:38 +02:00
|
|
|
node_db_parse_query(Node, Tables, Query) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:foreach(fun (Table) ->
|
|
|
|
STable = iolist_to_binary(atom_to_list(Table)),
|
|
|
|
case lists:keysearch(<<"table", STable/binary>>, 1,
|
|
|
|
Query)
|
|
|
|
of
|
|
|
|
{value, {_, SType}} ->
|
|
|
|
Type = case SType of
|
|
|
|
<<"unknown">> -> unknown;
|
|
|
|
<<"ram_copies">> -> ram_copies;
|
|
|
|
<<"disc_copies">> -> disc_copies;
|
|
|
|
<<"disc_only_copies">> ->
|
|
|
|
disc_only_copies;
|
|
|
|
<<"delete_content">> -> delete_content;
|
|
|
|
<<"delete_table">> -> delete_table;
|
|
|
|
_ -> false
|
|
|
|
end,
|
|
|
|
if Type == false -> ok;
|
|
|
|
Type == delete_content ->
|
|
|
|
mnesia:clear_table(Table);
|
|
|
|
Type == delete_table ->
|
|
|
|
mnesia:delete_table(Table);
|
|
|
|
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;
|
|
|
|
_ -> ok
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
Tables),
|
2004-05-16 22:13:38 +02:00
|
|
|
ok.
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
node_backup_parse_query(_Node, [{nokey, <<>>}]) ->
|
2009-01-12 22:48:34 +01:00
|
|
|
nothing;
|
2004-05-22 21:48:35 +02:00
|
|
|
node_backup_parse_query(Node, Query) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:foldl(fun (Action, nothing) ->
|
|
|
|
case lists:keysearch(Action, 1, Query) of
|
|
|
|
{value, _} ->
|
|
|
|
case lists:keysearch(<<Action/binary, "path">>, 1,
|
|
|
|
Query)
|
|
|
|
of
|
|
|
|
{value, {_, Path}} ->
|
|
|
|
Res = case Action of
|
|
|
|
<<"store">> ->
|
2015-10-07 00:06:58 +02:00
|
|
|
ejabberd_cluster:call(Node, mnesia, backup,
|
2013-03-14 10:33:02 +01:00
|
|
|
[binary_to_list(Path)]);
|
|
|
|
<<"restore">> ->
|
2015-10-07 00:06:58 +02:00
|
|
|
ejabberd_cluster:call(Node, ejabberd_admin,
|
2013-03-14 10:33:02 +01:00
|
|
|
restore, [Path]);
|
|
|
|
<<"fallback">> ->
|
2015-10-07 00:06:58 +02:00
|
|
|
ejabberd_cluster:call(Node, mnesia,
|
2013-03-14 10:33:02 +01:00
|
|
|
install_fallback,
|
|
|
|
[binary_to_list(Path)]);
|
|
|
|
<<"dump">> ->
|
2015-10-07 00:06:58 +02:00
|
|
|
ejabberd_cluster:call(Node, ejabberd_admin,
|
2013-03-14 10:33:02 +01:00
|
|
|
dump_to_textfile,
|
|
|
|
[Path]);
|
|
|
|
<<"load">> ->
|
2015-10-07 00:06:58 +02:00
|
|
|
ejabberd_cluster:call(Node, mnesia,
|
2013-03-14 10:33:02 +01:00
|
|
|
load_textfile,
|
|
|
|
[binary_to_list(Path)]);
|
|
|
|
<<"import_piefxis_file">> ->
|
2015-10-07 00:06:58 +02:00
|
|
|
ejabberd_cluster:call(Node, ejabberd_piefxis,
|
2013-03-14 10:33:02 +01:00
|
|
|
import_file, [Path]);
|
|
|
|
<<"export_piefxis_dir">> ->
|
2015-10-07 00:06:58 +02:00
|
|
|
ejabberd_cluster:call(Node, ejabberd_piefxis,
|
2013-03-14 10:33:02 +01:00
|
|
|
export_server, [Path]);
|
|
|
|
<<"export_piefxis_host_dir">> ->
|
|
|
|
{value, {_, Host}} =
|
|
|
|
lists:keysearch(<<Action/binary,
|
|
|
|
"host">>,
|
|
|
|
1, Query),
|
2015-10-07 00:06:58 +02:00
|
|
|
ejabberd_cluster:call(Node, ejabberd_piefxis,
|
2013-03-14 10:33:02 +01:00
|
|
|
export_host,
|
|
|
|
[Path, Host]);
|
|
|
|
<<"export_sql_file">> ->
|
|
|
|
{value, {_, Host}} =
|
|
|
|
lists:keysearch(<<Action/binary,
|
|
|
|
"host">>,
|
|
|
|
1, Query),
|
2016-04-20 11:27:32 +02:00
|
|
|
ejabberd_cluster:call(Node, ejd2sql,
|
2013-03-14 10:33:02 +01:00
|
|
|
export, [Host, Path]);
|
|
|
|
<<"import_file">> ->
|
2015-10-07 00:06:58 +02:00
|
|
|
ejabberd_cluster:call(Node, ejabberd_admin,
|
2013-03-14 10:33:02 +01:00
|
|
|
import_file, [Path]);
|
|
|
|
<<"import_dir">> ->
|
2015-10-07 00:06:58 +02:00
|
|
|
ejabberd_cluster:call(Node, ejabberd_admin,
|
2013-03-14 10:33:02 +01:00
|
|
|
import_dir, [Path])
|
|
|
|
end,
|
|
|
|
case Res of
|
|
|
|
{error, Reason} -> {error, Reason};
|
|
|
|
{badrpc, Reason} -> {badrpc, Reason};
|
|
|
|
_ -> ok
|
|
|
|
end;
|
|
|
|
OtherError -> {error, OtherError}
|
2004-05-22 21:48:35 +02:00
|
|
|
end;
|
2013-03-14 10:33:02 +01:00
|
|
|
_ -> nothing
|
|
|
|
end;
|
|
|
|
(_Action, Res) -> Res
|
|
|
|
end,
|
|
|
|
nothing,
|
|
|
|
[<<"store">>, <<"restore">>, <<"fallback">>, <<"dump">>,
|
|
|
|
<<"load">>, <<"import_file">>, <<"import_dir">>,
|
|
|
|
<<"import_piefxis_file">>, <<"export_piefxis_dir">>,
|
|
|
|
<<"export_piefxis_host_dir">>, <<"export_sql_file">>]).
|
2004-05-22 21:48:35 +02:00
|
|
|
|
2006-02-27 05:43:16 +01:00
|
|
|
node_update_parse_query(Node, Query) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
case lists:keysearch(<<"update">>, 1, Query) of
|
|
|
|
{value, _} ->
|
|
|
|
ModulesToUpdateStrings =
|
|
|
|
proplists:get_all_values(<<"selected">>, Query),
|
2017-04-11 12:13:58 +02:00
|
|
|
ModulesToUpdate = [misc:binary_to_atom(M)
|
2013-03-14 10:33:02 +01:00
|
|
|
|| M <- ModulesToUpdateStrings],
|
2015-10-07 00:06:58 +02:00
|
|
|
case ejabberd_cluster:call(Node, ejabberd_update, update,
|
2013-03-14 10:33:02 +01:00
|
|
|
[ModulesToUpdate])
|
|
|
|
of
|
|
|
|
{ok, _} -> ok;
|
|
|
|
{error, Error} ->
|
|
|
|
?ERROR_MSG("~p~n", [Error]),
|
2016-11-24 13:06:06 +01:00
|
|
|
{error, (str:format("~p", [Error]))};
|
2013-03-14 10:33:02 +01:00
|
|
|
{badrpc, Error} ->
|
|
|
|
?ERROR_MSG("Bad RPC: ~p~n", [Error]),
|
|
|
|
{error,
|
2016-11-24 13:06:06 +01:00
|
|
|
<<"Bad RPC: ", ((str:format("~p", [Error])))/binary>>}
|
2013-03-14 10:33:02 +01:00
|
|
|
end;
|
|
|
|
_ -> nothing
|
2006-02-27 05:43:16 +01:00
|
|
|
end.
|
|
|
|
|
2007-08-23 02:51:54 +02:00
|
|
|
pretty_print_xml(El) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
list_to_binary(pretty_print_xml(El, <<"">>)).
|
2004-10-05 21:31:17 +02:00
|
|
|
|
2007-08-23 02:51:54 +02:00
|
|
|
pretty_print_xml({xmlcdata, CData}, Prefix) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
IsBlankCData = lists:all(
|
|
|
|
fun($\f) -> true;
|
|
|
|
($\r) -> true;
|
|
|
|
($\n) -> true;
|
|
|
|
($\t) -> true;
|
|
|
|
($\v) -> true;
|
|
|
|
($ ) -> true;
|
|
|
|
(_) -> false
|
|
|
|
end, binary_to_list(CData)),
|
|
|
|
if IsBlankCData ->
|
|
|
|
[];
|
|
|
|
true ->
|
|
|
|
[Prefix, CData, $\n]
|
|
|
|
end;
|
|
|
|
pretty_print_xml(#xmlel{name = Name, attrs = Attrs,
|
|
|
|
children = Els},
|
|
|
|
Prefix) ->
|
2004-10-05 21:31:17 +02:00
|
|
|
[Prefix, $<, Name,
|
|
|
|
case Attrs of
|
2013-03-14 10:33:02 +01:00
|
|
|
[] -> [];
|
|
|
|
[{Attr, Val} | RestAttrs] ->
|
|
|
|
AttrPrefix = [Prefix,
|
|
|
|
str:copies(<<" ">>, byte_size(Name) + 2)],
|
2016-02-03 19:03:17 +01:00
|
|
|
[$\s, Attr, $=, $', fxml:crypt(Val) | [$',
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:map(fun ({Attr1,
|
|
|
|
Val1}) ->
|
|
|
|
[$\n,
|
|
|
|
AttrPrefix,
|
|
|
|
Attr1, $=,
|
|
|
|
$',
|
2016-02-03 19:03:17 +01:00
|
|
|
fxml:crypt(Val1),
|
2013-03-14 10:33:02 +01:00
|
|
|
$']
|
|
|
|
end,
|
|
|
|
RestAttrs)]]
|
2004-10-05 21:31:17 +02:00
|
|
|
end,
|
2013-03-14 10:33:02 +01:00
|
|
|
if Els == [] -> <<"/>\n">>;
|
|
|
|
true ->
|
|
|
|
OnlyCData = lists:all(fun ({xmlcdata, _}) -> true;
|
|
|
|
(#xmlel{}) -> false
|
|
|
|
end,
|
|
|
|
Els),
|
|
|
|
if OnlyCData ->
|
2016-02-03 19:03:17 +01:00
|
|
|
[$>, fxml:get_cdata(Els), $<, $/, Name, $>, $\n];
|
2013-03-14 10:33:02 +01:00
|
|
|
true ->
|
|
|
|
[$>, $\n,
|
|
|
|
lists:map(fun (E) ->
|
|
|
|
pretty_print_xml(E, [Prefix, <<" ">>])
|
|
|
|
end,
|
|
|
|
Els),
|
|
|
|
Prefix, $<, $/, Name, $>, $\n]
|
|
|
|
end
|
2004-10-05 21:31:17 +02:00
|
|
|
end].
|
|
|
|
|
2005-09-29 03:04:24 +02:00
|
|
|
url_func({user_diapason, From, To}) ->
|
2016-11-24 13:06:06 +01:00
|
|
|
<<(integer_to_binary(From))/binary, "-",
|
|
|
|
(integer_to_binary(To))/binary, "/">>;
|
2007-12-07 02:40:24 +01:00
|
|
|
url_func({users_queue, Prefix, User, _Server}) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
<<Prefix/binary, "user/", User/binary, "/queue/">>;
|
2007-12-07 02:40:24 +01:00
|
|
|
url_func({user, Prefix, User, _Server}) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
<<Prefix/binary, "user/", User/binary, "/">>.
|
2005-09-29 03:04:24 +02:00
|
|
|
|
2008-04-12 10:09:05 +02:00
|
|
|
last_modified() ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{<<"Last-Modified">>,
|
|
|
|
<<"Mon, 25 Feb 2008 13:23:30 GMT">>}.
|
|
|
|
|
2008-04-12 10:09:05 +02:00
|
|
|
cache_control_public() ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{<<"Cache-Control">>, <<"public">>}.
|
2008-10-12 15:58:05 +02:00
|
|
|
|
2009-02-13 23:13:34 +01:00
|
|
|
%% Transform 1234567890 into "1,234,567,890"
|
|
|
|
pretty_string_int(Integer) when is_integer(Integer) ->
|
2016-11-24 13:06:06 +01:00
|
|
|
pretty_string_int(integer_to_binary(Integer));
|
2013-03-14 10:33:02 +01:00
|
|
|
pretty_string_int(String) when is_binary(String) ->
|
|
|
|
{_, Result} = lists:foldl(fun (NewNumber, {3, Result}) ->
|
|
|
|
{1, <<NewNumber, $,, Result/binary>>};
|
|
|
|
(NewNumber, {CountAcc, Result}) ->
|
|
|
|
{CountAcc + 1, <<NewNumber, Result/binary>>}
|
|
|
|
end,
|
|
|
|
{0, <<"">>}, lists:reverse(binary_to_list(String))),
|
2009-02-13 23:13:34 +01:00
|
|
|
Result.
|
|
|
|
|
2009-06-23 22:45:39 +02:00
|
|
|
%%%==================================
|
2021-05-14 18:47:05 +02:00
|
|
|
%%%% mnesia table view
|
|
|
|
|
|
|
|
make_table_view(Node, STable, Lang) ->
|
|
|
|
Table = misc:binary_to_atom(STable),
|
|
|
|
TInfo = ejabberd_cluster:call(Node, mnesia, table_info, [Table, all]),
|
|
|
|
{value, {storage_type, Type}} = lists:keysearch(storage_type, 1, TInfo),
|
|
|
|
{value, {size, Size}} = lists:keysearch(size, 1, TInfo),
|
|
|
|
{value, {memory, Memory}} = lists:keysearch(memory, 1, TInfo),
|
2021-05-18 14:53:06 +02:00
|
|
|
MemoryB = Memory*erlang:system_info(wordsize),
|
2021-05-14 18:47:05 +02:00
|
|
|
TableInfo = str:format("~p", [TInfo]),
|
|
|
|
[?XC(<<"h1">>, (str:translate_and_format(Lang, ?T("Database Tables at ~p"),
|
|
|
|
[Node]))),
|
|
|
|
?XAE(<<"table">>, [],
|
|
|
|
[?XE(<<"tbody">>,
|
|
|
|
[?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>, ?T("Name")),
|
|
|
|
?XAC(<<"td">>, [{<<"class">>, <<"alignright">>}],
|
|
|
|
STable
|
|
|
|
)]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>, ?T("Node")),
|
|
|
|
?XAC(<<"td">>, [{<<"class">>, <<"alignright">>}],
|
|
|
|
misc:atom_to_binary(Node)
|
|
|
|
)]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>, ?T("Storage Type")),
|
|
|
|
?XAC(<<"td">>, [{<<"class">>, <<"alignright">>}],
|
|
|
|
misc:atom_to_binary(Type)
|
|
|
|
)]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>, ?T("Elements")),
|
|
|
|
?XAE(<<"td">>,
|
|
|
|
[{<<"class">>, <<"alignright">>}],
|
|
|
|
[?AC(<<"1/">>,
|
|
|
|
(pretty_string_int(Size)))])
|
|
|
|
]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>, ?T("Memory")),
|
|
|
|
?XAC(<<"td">>, [{<<"class">>, <<"alignright">>}],
|
2021-05-18 14:53:06 +02:00
|
|
|
(pretty_string_int(MemoryB))
|
2021-05-14 18:47:05 +02:00
|
|
|
)])
|
|
|
|
])]),
|
|
|
|
?XC(<<"pre">>, TableInfo)].
|
|
|
|
|
|
|
|
make_table_elements_view(Node, STable, Lang, PageNumber) ->
|
|
|
|
Table = misc:binary_to_atom(STable),
|
|
|
|
TInfo = ejabberd_cluster:call(Node, mnesia, table_info, [Table, all]),
|
|
|
|
{value, {storage_type, Type}} = lists:keysearch(storage_type, 1, TInfo),
|
|
|
|
{value, {size, Size}} = lists:keysearch(size, 1, TInfo),
|
|
|
|
PageSize = 500,
|
|
|
|
TableContentErl = get_table_content(Node, Table, Type, PageNumber, PageSize),
|
|
|
|
TableContent = str:format("~p", [TableContentErl]),
|
|
|
|
PagesLinks = build_elements_pages_list(Size, PageNumber, PageSize),
|
|
|
|
[?XC(<<"h1">>, (str:translate_and_format(Lang, ?T("Database Tables at ~p"),
|
|
|
|
[Node]))),
|
|
|
|
?P, ?AC(<<"../">>, STable), ?P
|
|
|
|
] ++ PagesLinks ++ [?XC(<<"pre">>, TableContent)].
|
|
|
|
|
|
|
|
build_elements_pages_list(Size, PageNumber, PageSize) ->
|
|
|
|
PagesNumber = calculate_pages_number(Size, PageSize),
|
|
|
|
PagesSeq = lists:seq(1, PagesNumber),
|
|
|
|
PagesList = [?AC(<<"../", (integer_to_binary(N))/binary, "/">>,
|
|
|
|
<<(integer_to_binary(N))/binary, " ">>)
|
|
|
|
|| N <- PagesSeq],
|
|
|
|
lists:keyreplace(
|
|
|
|
[?C(<<(integer_to_binary(PageNumber))/binary, " ">>)],
|
|
|
|
4,
|
|
|
|
PagesList,
|
|
|
|
?C(<<" [", (integer_to_binary(PageNumber))/binary, "] ">>)).
|
|
|
|
|
|
|
|
calculate_pages_number(Size, PageSize) ->
|
2022-01-24 01:01:39 +01:00
|
|
|
Remainder = case Size rem PageSize of
|
2021-05-14 18:47:05 +02:00
|
|
|
0 -> 0;
|
|
|
|
_ -> 1
|
|
|
|
end,
|
2022-01-24 01:01:39 +01:00
|
|
|
case (Size div PageSize) + Remainder of
|
2021-05-14 18:47:05 +02:00
|
|
|
1 -> 0;
|
|
|
|
Res -> Res
|
|
|
|
end.
|
|
|
|
|
|
|
|
get_table_content(Node, Table, _Type, PageNumber, PageSize) ->
|
|
|
|
Keys1 = lists:sort(ejabberd_cluster:call(Node, mnesia, dirty_all_keys, [Table])),
|
|
|
|
FirstKeyPos = 1 - PageSize + PageNumber*PageSize,
|
|
|
|
Keys = lists:sublist(Keys1, FirstKeyPos, PageSize),
|
|
|
|
Res = [ejabberd_cluster:call(Node, mnesia, dirty_read, [Table, Key])
|
|
|
|
|| Key <- Keys],
|
|
|
|
lists:flatten(Res).
|
|
|
|
|
|
|
|
%%%==================================
|
2009-06-23 22:45:39 +02:00
|
|
|
%%%% navigation menu
|
2008-10-12 15:58:05 +02:00
|
|
|
|
2019-10-02 11:54:22 +02:00
|
|
|
make_navigation(Host, Node, Lang, JID, Level) ->
|
|
|
|
Menu = make_navigation_menu(Host, Node, Lang, JID, Level),
|
2008-10-12 15:58:05 +02:00
|
|
|
make_menu_items(Lang, Menu).
|
|
|
|
|
2022-05-12 17:25:11 +02:00
|
|
|
-spec make_navigation_menu(Host::global | binary(),
|
|
|
|
Node::cluster | atom(),
|
|
|
|
Lang::binary(), JID::jid(), Level::integer()) ->
|
|
|
|
Menu::{URL::binary(), Title::binary()}
|
|
|
|
| {URL::binary(), Title::binary(), [Menu::any()]}.
|
2019-10-02 11:54:22 +02:00
|
|
|
make_navigation_menu(Host, Node, Lang, JID, Level) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
HostNodeMenu = make_host_node_menu(Host, Node, Lang,
|
2019-10-02 11:54:22 +02:00
|
|
|
JID, Level),
|
2013-03-14 10:33:02 +01:00
|
|
|
HostMenu = make_host_menu(Host, HostNodeMenu, Lang,
|
2019-10-02 11:54:22 +02:00
|
|
|
JID, Level),
|
|
|
|
NodeMenu = make_node_menu(Host, Node, Lang, Level),
|
|
|
|
make_server_menu(HostMenu, NodeMenu, Lang, JID, Level).
|
2009-06-23 23:00:43 +02:00
|
|
|
|
2020-03-26 13:43:24 +01:00
|
|
|
make_menu_items(global, cluster, Base, Lang) ->
|
2008-10-12 15:58:05 +02:00
|
|
|
HookItems = get_menu_items_hook(server, Lang),
|
2020-03-26 13:43:24 +01:00
|
|
|
make_menu_items(Lang, {Base, <<"">>, HookItems});
|
|
|
|
make_menu_items(global, Node, Base, Lang) ->
|
2009-02-02 11:12:44 +01:00
|
|
|
HookItems = get_menu_items_hook({node, Node}, Lang),
|
2020-03-26 13:43:24 +01:00
|
|
|
make_menu_items(Lang, {Base, <<"">>, HookItems});
|
|
|
|
make_menu_items(Host, cluster, Base, Lang) ->
|
2008-10-12 15:58:05 +02:00
|
|
|
HookItems = get_menu_items_hook({host, Host}, Lang),
|
2020-03-26 13:43:24 +01:00
|
|
|
make_menu_items(Lang, {Base, <<"">>, HookItems});
|
|
|
|
make_menu_items(Host, Node, Base, Lang) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
HookItems = get_menu_items_hook({hostnode, Host, Node},
|
|
|
|
Lang),
|
2020-03-26 13:43:24 +01:00
|
|
|
make_menu_items(Lang, {Base, <<"">>, HookItems}).
|
2008-10-12 15:58:05 +02:00
|
|
|
|
2019-10-02 11:54:22 +02:00
|
|
|
make_host_node_menu(global, _, _Lang, _JID, _Level) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{<<"">>, <<"">>, []};
|
2019-10-02 11:54:22 +02:00
|
|
|
make_host_node_menu(_, cluster, _Lang, _JID, _Level) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{<<"">>, <<"">>, []};
|
2019-10-02 11:54:22 +02:00
|
|
|
make_host_node_menu(Host, Node, Lang, JID, Level) ->
|
|
|
|
HostNodeBase = get_base_path(Host, Node, Level),
|
2019-06-14 11:33:26 +02:00
|
|
|
HostNodeFixed = get_menu_items_hook({hostnode, Host, Node}, Lang),
|
2013-03-14 10:33:02 +01:00
|
|
|
HostNodeFixed2 = [Tuple
|
|
|
|
|| Tuple <- HostNodeFixed,
|
2020-08-10 18:55:13 +02:00
|
|
|
is_allowed_path(Host, Tuple, JID)],
|
2013-03-14 10:33:02 +01:00
|
|
|
{HostNodeBase, iolist_to_binary(atom_to_list(Node)),
|
|
|
|
HostNodeFixed2}.
|
2008-10-12 15:58:05 +02:00
|
|
|
|
2019-10-02 11:54:22 +02:00
|
|
|
make_host_menu(global, _HostNodeMenu, _Lang, _JID, _Level) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{<<"">>, <<"">>, []};
|
2019-10-02 11:54:22 +02:00
|
|
|
make_host_menu(Host, HostNodeMenu, Lang, JID, Level) ->
|
|
|
|
HostBase = get_base_path(Host, cluster, Level),
|
2019-06-22 16:08:45 +02:00
|
|
|
HostFixed = [{<<"users">>, ?T("Users")},
|
|
|
|
{<<"online-users">>, ?T("Online Users")}]
|
2013-03-14 10:33:02 +01:00
|
|
|
++
|
|
|
|
get_lastactivity_menuitem_list(Host) ++
|
2019-06-22 16:08:45 +02:00
|
|
|
[{<<"nodes">>, ?T("Nodes"), HostNodeMenu},
|
|
|
|
{<<"stats">>, ?T("Statistics")}]
|
2013-03-14 10:33:02 +01:00
|
|
|
++ get_menu_items_hook({host, Host}, Lang),
|
|
|
|
HostFixed2 = [Tuple
|
|
|
|
|| Tuple <- HostFixed,
|
2020-08-10 18:55:13 +02:00
|
|
|
is_allowed_path(Host, Tuple, JID)],
|
2009-06-23 23:00:43 +02:00
|
|
|
{HostBase, Host, HostFixed2}.
|
2008-10-12 15:58:05 +02:00
|
|
|
|
2019-10-02 11:54:22 +02:00
|
|
|
make_node_menu(_Host, cluster, _Lang, _Level) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{<<"">>, <<"">>, []};
|
2019-10-02 11:54:22 +02:00
|
|
|
make_node_menu(global, Node, Lang, Level) ->
|
|
|
|
NodeBase = get_base_path(global, Node, Level),
|
|
|
|
NodeFixed = [{<<"db">>, ?T("Database")},
|
|
|
|
{<<"backup">>, ?T("Backup")},
|
|
|
|
{<<"stats">>, ?T("Statistics")},
|
|
|
|
{<<"update">>, ?T("Update")}]
|
2013-03-14 10:33:02 +01:00
|
|
|
++ get_menu_items_hook({node, Node}, Lang),
|
2020-03-26 13:43:24 +01:00
|
|
|
{NodeBase, iolist_to_binary(atom_to_list(Node)),
|
|
|
|
NodeFixed};
|
|
|
|
make_node_menu(_Host, _Node, _Lang, _Level) ->
|
|
|
|
{<<"">>, <<"">>, []}.
|
2008-10-12 15:58:05 +02:00
|
|
|
|
2019-10-02 11:54:22 +02:00
|
|
|
make_server_menu(HostMenu, NodeMenu, Lang, JID, Level) ->
|
2020-03-26 13:43:24 +01:00
|
|
|
Base = get_base_path(global, cluster, Level),
|
2019-06-22 16:08:45 +02:00
|
|
|
Fixed = [{<<"vhosts">>, ?T("Virtual Hosts"), HostMenu},
|
|
|
|
{<<"nodes">>, ?T("Nodes"), NodeMenu},
|
|
|
|
{<<"stats">>, ?T("Statistics")}]
|
2013-03-14 10:33:02 +01:00
|
|
|
++ get_menu_items_hook(server, Lang),
|
|
|
|
Fixed2 = [Tuple
|
|
|
|
|| Tuple <- Fixed,
|
2020-08-10 18:55:13 +02:00
|
|
|
is_allowed_path(global, Tuple, JID)],
|
2020-03-26 13:43:24 +01:00
|
|
|
{Base, <<"">>, Fixed2}.
|
2008-10-12 15:58:05 +02:00
|
|
|
|
2009-02-02 11:12:44 +01:00
|
|
|
get_menu_items_hook({hostnode, Host, Node}, Lang) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
ejabberd_hooks:run_fold(webadmin_menu_hostnode, Host,
|
|
|
|
[], [Host, Node, Lang]);
|
2008-10-12 15:58:05 +02:00
|
|
|
get_menu_items_hook({host, Host}, Lang) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
ejabberd_hooks:run_fold(webadmin_menu_host, Host, [],
|
|
|
|
[Host, Lang]);
|
2009-02-02 11:12:44 +01:00
|
|
|
get_menu_items_hook({node, Node}, Lang) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
ejabberd_hooks:run_fold(webadmin_menu_node, [],
|
|
|
|
[Node, Lang]);
|
2008-10-12 15:58:05 +02:00
|
|
|
get_menu_items_hook(server, Lang) ->
|
|
|
|
ejabberd_hooks:run_fold(webadmin_menu_main, [], [Lang]).
|
|
|
|
|
2022-05-12 17:25:11 +02:00
|
|
|
-spec make_menu_items(Lang::binary(),
|
|
|
|
{MURI::binary(), MName::binary(),
|
|
|
|
Items::[{IURI::binary(), IName::binary()}
|
|
|
|
| {IURI::binary(), IName::binary(), Menu::any()}]}) ->
|
|
|
|
[xmlel()].
|
2008-10-12 15:58:05 +02:00
|
|
|
make_menu_items(Lang, Menu) ->
|
|
|
|
lists:reverse(make_menu_items2(Lang, 1, Menu)).
|
|
|
|
|
|
|
|
make_menu_items2(Lang, Deep, {MURI, MName, _} = Menu) ->
|
|
|
|
Res = case MName of
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"">> -> [];
|
|
|
|
_ -> [make_menu_item(header, Deep, MURI, MName, Lang)]
|
2008-10-12 15:58:05 +02:00
|
|
|
end,
|
|
|
|
make_menu_items2(Lang, Deep, Menu, Res).
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
make_menu_items2(_, _Deep, {_, _, []}, Res) -> Res;
|
|
|
|
make_menu_items2(Lang, Deep,
|
|
|
|
{MURI, MName, [Item | Items]}, Res) ->
|
2008-10-12 15:58:05 +02:00
|
|
|
Res2 = case Item of
|
2013-03-14 10:33:02 +01:00
|
|
|
{IURI, IName} ->
|
|
|
|
[make_menu_item(item, Deep,
|
|
|
|
<<MURI/binary, IURI/binary, "/">>, IName, Lang)
|
|
|
|
| Res];
|
|
|
|
{IURI, IName, SubMenu} ->
|
|
|
|
ResTemp = [make_menu_item(item, Deep,
|
|
|
|
<<MURI/binary, IURI/binary, "/">>,
|
|
|
|
IName, Lang)
|
|
|
|
| Res],
|
|
|
|
ResSubMenu = make_menu_items2(Lang, Deep + 1, SubMenu),
|
|
|
|
ResSubMenu ++ ResTemp
|
2008-10-12 15:58:05 +02:00
|
|
|
end,
|
2013-03-14 10:33:02 +01:00
|
|
|
make_menu_items2(Lang, Deep, {MURI, MName, Items},
|
|
|
|
Res2).
|
2008-10-12 15:58:05 +02:00
|
|
|
|
|
|
|
make_menu_item(header, 1, URI, Name, _Lang) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
?LI([?XAE(<<"div">>, [{<<"id">>, <<"navhead">>}],
|
|
|
|
[?AC(URI, Name)])]);
|
2008-10-12 15:58:05 +02:00
|
|
|
make_menu_item(header, 2, URI, Name, _Lang) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
?LI([?XAE(<<"div">>, [{<<"id">>, <<"navheadsub">>}],
|
|
|
|
[?AC(URI, Name)])]);
|
2008-10-12 15:58:05 +02:00
|
|
|
make_menu_item(header, 3, URI, Name, _Lang) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
?LI([?XAE(<<"div">>, [{<<"id">>, <<"navheadsubsub">>}],
|
|
|
|
[?AC(URI, Name)])]);
|
2008-10-12 15:58:05 +02:00
|
|
|
make_menu_item(item, 1, URI, Name, Lang) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
?LI([?XAE(<<"div">>, [{<<"id">>, <<"navitem">>}],
|
|
|
|
[?ACT(URI, Name)])]);
|
2008-10-12 15:58:05 +02:00
|
|
|
make_menu_item(item, 2, URI, Name, Lang) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
?LI([?XAE(<<"div">>, [{<<"id">>, <<"navitemsub">>}],
|
|
|
|
[?ACT(URI, Name)])]);
|
2008-10-12 15:58:05 +02:00
|
|
|
make_menu_item(item, 3, URI, Name, Lang) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
?LI([?XAE(<<"div">>, [{<<"id">>, <<"navitemsubsub">>}],
|
|
|
|
[?ACT(URI, Name)])]).
|
2009-06-23 22:45:39 +02:00
|
|
|
|
2019-06-14 11:33:26 +02:00
|
|
|
any_rules_allowed(Host, Access, Entity) ->
|
|
|
|
lists:any(
|
|
|
|
fun(Rule) ->
|
|
|
|
allow == acl:match_rule(Host, Rule, Entity)
|
|
|
|
end, Access).
|
2015-10-07 00:06:58 +02:00
|
|
|
|
|
|
|
%%% vim: set foldmethod=marker foldmarker=%%%%,%%%=:
|