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
|
|
|
%%%
|
|
|
|
%%%
|
2017-01-02 21:41:53 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2017 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
|
|
|
|
2015-06-01 14:38:27 +02:00
|
|
|
-behaviour(ejabberd_config).
|
|
|
|
|
2007-08-31 18:13:35 +02:00
|
|
|
-author('alexey@process-one.net').
|
2004-04-26 17:38:07 +02:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-export([process/2, list_users/4,
|
|
|
|
list_users_in_diapason/4, pretty_print_xml/1,
|
2015-06-01 14:38:27 +02:00
|
|
|
term_to_id/1, opt_type/1]).
|
2004-04-26 17:38:07 +02:00
|
|
|
|
|
|
|
-include("ejabberd.hrl").
|
2013-04-08 11:12:54 +02:00
|
|
|
-include("logger.hrl").
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2016-08-04 12:41:38 +02:00
|
|
|
-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
|
|
|
|
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
|
|
|
|
|
2010-05-10 16:12:48 +02:00
|
|
|
%% @spec (Path::[string()], Method) -> {HostOfRule, [AccessRule]}
|
|
|
|
%% where Method = 'GET' | 'POST'
|
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]};
|
2009-06-23 23:00:43 +02:00
|
|
|
%% The pages of a vhost are only accesible 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' ->
|
2016-07-19 11:26:33 +02:00
|
|
|
AC = gen_mod:get_module_opt(VHost, ejabberd_web_admin,
|
2017-04-30 18:01:47 +02:00
|
|
|
access, configure),
|
2016-07-19 11:26:33 +02:00
|
|
|
ACR = gen_mod:get_module_opt(VHost, ejabberd_web_admin,
|
2017-04-30 18:01:47 +02:00
|
|
|
access_readonly, webadmin_view),
|
2016-07-19 11:26:33 +02:00
|
|
|
{VHost, [AC, ACR]};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_acl_rule([<<"server">>, VHost | _RPath], 'POST') ->
|
2016-07-19 11:26:33 +02:00
|
|
|
AC = gen_mod:get_module_opt(VHost, ejabberd_web_admin,
|
2017-04-30 18:01:47 +02:00
|
|
|
access, configure),
|
2016-07-19 11:26:33 +02:00
|
|
|
{VHost, [AC]};
|
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' ->
|
2016-07-19 11:26:33 +02:00
|
|
|
AC = gen_mod:get_module_opt(global, ejabberd_web_admin,
|
2017-04-30 18:01:47 +02:00
|
|
|
access, configure),
|
2016-07-19 11:26:33 +02:00
|
|
|
ACR = gen_mod:get_module_opt(global, ejabberd_web_admin,
|
2017-04-30 18:01:47 +02:00
|
|
|
access_readonly, webadmin_view),
|
2016-07-19 11:26:33 +02:00
|
|
|
{global, [AC, ACR]};
|
|
|
|
get_acl_rule(_RPath, 'POST') ->
|
|
|
|
AC = gen_mod:get_module_opt(global, ejabberd_web_admin,
|
2017-04-30 18:01:47 +02:00
|
|
|
access, configure),
|
2016-07-19 11:26:33 +02:00
|
|
|
{global, [AC]}.
|
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.
|
|
|
|
|
|
|
|
get_menu_items(global, cluster, Lang, JID) ->
|
|
|
|
{Base, _, Items} = make_server_menu([], [], Lang, JID),
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:map(fun ({URI, Name}) ->
|
|
|
|
{<<Base/binary, URI/binary, "/">>, Name};
|
|
|
|
({URI, Name, _SubMenu}) ->
|
|
|
|
{<<Base/binary, URI/binary, "/">>, Name}
|
|
|
|
end,
|
|
|
|
Items);
|
2009-06-23 23:00:43 +02:00
|
|
|
get_menu_items(Host, cluster, Lang, JID) ->
|
|
|
|
{Base, _, Items} = make_host_menu(Host, [], Lang, JID),
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:map(fun ({URI, Name}) ->
|
|
|
|
{<<Base/binary, URI/binary, "/">>, Name};
|
|
|
|
({URI, Name, _SubMenu}) ->
|
|
|
|
{<<Base/binary, URI/binary, "/">>, Name}
|
|
|
|
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
|
|
|
|
|
|
|
is_allowed_path(BasePath, {Path, _}, JID) ->
|
|
|
|
is_allowed_path(BasePath ++ [Path], JID);
|
|
|
|
is_allowed_path(BasePath, {Path, _, _}, JID) ->
|
|
|
|
is_allowed_path(BasePath ++ [Path], JID).
|
|
|
|
|
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'),
|
2016-07-23 16:21:00 +02:00
|
|
|
acl:any_rules_allowed(HostOfRule, AccessRule, JID).
|
2009-06-23 23:00:43 +02:00
|
|
|
|
|
|
|
%% @spec(Path) -> URL
|
|
|
|
%% where Path = [string()]
|
|
|
|
%% URL = string()
|
|
|
|
%% Convert ["admin", "user", "tom"] -> "/admin/user/tom/"
|
|
|
|
%%path_to_url(Path) ->
|
|
|
|
%% "/" ++ string:join(Path, "/") ++ "/".
|
|
|
|
|
|
|
|
%% @spec(URL) -> Path
|
|
|
|
%% where Path = [string()]
|
|
|
|
%% URL = string()
|
|
|
|
%% Convert "admin/user/tom" -> ["admin", "user", "tom"]
|
2013-03-14 10:33:02 +01:00
|
|
|
url_to_path(URL) -> str:tokens(URL, <<"/">>).
|
|
|
|
|
2009-06-23 22:45:39 +02:00
|
|
|
%%%==================================
|
|
|
|
%%%% process/2
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
process([<<"doc">>, LocalFile], _Request) ->
|
2009-01-20 20:42:08 +01:00
|
|
|
DocPath = case os:getenv("EJABBERD_DOC_PATH") of
|
2013-03-14 10:33:02 +01:00
|
|
|
P when is_list(P) -> P;
|
|
|
|
false -> <<"/share/doc/ejabberd/">>
|
2009-01-07 01:55:02 +01:00
|
|
|
end,
|
|
|
|
FileName = filename:join(DocPath, LocalFile),
|
|
|
|
case file:read_file(FileName) of
|
2013-03-14 10:33:02 +01:00
|
|
|
{ok, FileContents} ->
|
|
|
|
?DEBUG("Delivering content.", []),
|
|
|
|
{200, [{<<"Server">>, <<"ejabberd">>}], FileContents};
|
|
|
|
{error, Error} ->
|
|
|
|
Help = <<" ", FileName/binary,
|
|
|
|
" - Try to specify the path to ejabberd "
|
|
|
|
"documentation with the environment variable "
|
|
|
|
"EJABBERD_DOC_PATH. Check the ejabberd "
|
|
|
|
"Guide for more information.">>,
|
2015-07-15 20:45:55 +02:00
|
|
|
?INFO_MSG("Problem '~p' accessing the local Guide file ~s", [Error, Help]),
|
2013-03-14 10:33:02 +01:00
|
|
|
case Error of
|
|
|
|
eacces -> {403, [], <<"Forbidden", Help/binary>>};
|
2015-07-15 20:45:55 +02:00
|
|
|
enoent -> {307, [{<<"Location">>, <<"http://docs.ejabberd.im/admin/guide/configuration/">>}], <<"Not found", Help/binary>>};
|
2013-03-14 10:33:02 +01:00
|
|
|
_Else ->
|
|
|
|
{404, [], <<(iolist_to_binary(atom_to_list(Error)))/binary, Help/binary>>}
|
|
|
|
end
|
2009-01-07 01:55:02 +01:00
|
|
|
end;
|
2013-03-14 10:33:02 +01:00
|
|
|
process([<<"server">>, SHost | RPath] = Path,
|
|
|
|
#request{auth = Auth, lang = Lang, host = HostHTTP,
|
|
|
|
method = Method} =
|
|
|
|
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),
|
|
|
|
process_admin(Host,
|
|
|
|
Request#request{path = RPath,
|
|
|
|
auth = {auth_jid, Auth, AJID},
|
|
|
|
us = {User, Server}});
|
|
|
|
{unauthorized, <<"no-auth-provided">>} ->
|
|
|
|
{401,
|
|
|
|
[{<<"WWW-Authenticate">>,
|
|
|
|
<<"basic realm=\"ejabberd\"">>}],
|
|
|
|
ejabberd_web:make_xhtml([?XCT(<<"h1">>,
|
|
|
|
<<"Unauthorized">>)])};
|
|
|
|
{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">>,
|
|
|
|
<<"Unauthorized">>)])}
|
|
|
|
end;
|
|
|
|
false -> ejabberd_web:error(not_found)
|
2007-01-25 06:53:58 +01:00
|
|
|
end;
|
2013-03-14 10:33:02 +01:00
|
|
|
process(RPath,
|
|
|
|
#request{auth = Auth, lang = Lang, host = HostHTTP,
|
|
|
|
method = Method} =
|
|
|
|
Request) ->
|
2010-04-27 23:16:48 +02:00
|
|
|
case get_auth_admin(Auth, HostHTTP, RPath, Method) of
|
2013-03-14 10:33:02 +01:00
|
|
|
{ok, {User, Server}} ->
|
|
|
|
AJID = get_jid(Auth, HostHTTP, Method),
|
|
|
|
process_admin(global,
|
|
|
|
Request#request{path = RPath,
|
|
|
|
auth = {auth_jid, Auth, AJID},
|
|
|
|
us = {User, Server}});
|
|
|
|
{unauthorized, <<"no-auth-provided">>} ->
|
|
|
|
{401,
|
|
|
|
[{<<"WWW-Authenticate">>,
|
|
|
|
<<"basic realm=\"ejabberd\"">>}],
|
|
|
|
ejabberd_web:make_xhtml([?XCT(<<"h1">>,
|
|
|
|
<<"Unauthorized">>)])};
|
|
|
|
{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">>,
|
|
|
|
<<"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} ->
|
|
|
|
get_auth_account(HostOfRule, AccessRule, User, HostHTTP,
|
|
|
|
Pass);
|
|
|
|
#jid{user = User, server = Server} ->
|
|
|
|
get_auth_account(HostOfRule, AccessRule, User, Server,
|
|
|
|
Pass)
|
|
|
|
catch _:{bad_jid, _} ->
|
|
|
|
{unauthorized, <<"badformed-jid">>}
|
|
|
|
end;
|
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) ->
|
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 ->
|
2016-07-23 16:21:00 +02:00
|
|
|
case acl:any_rules_allowed(HostOfRule, AccessRule,
|
2017-02-25 08:01:01 +01:00
|
|
|
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
|
|
|
|
|
2009-06-23 23:00:43 +02:00
|
|
|
make_xhtml(Els, Host, Lang, JID) ->
|
|
|
|
make_xhtml(Els, Host, cluster, Lang, JID).
|
2008-10-12 15:58:05 +02:00
|
|
|
|
2009-06-23 23:00:43 +02:00
|
|
|
%% @spec (Els, Host, Node, Lang, JID) -> {200, [html], xmlelement()}
|
2008-10-12 15:58:05 +02:00
|
|
|
%% where Host = global | string()
|
|
|
|
%% Node = cluster | atom()
|
2009-06-23 23:00:43 +02:00
|
|
|
%% JID = jid()
|
|
|
|
make_xhtml(Els, Host, Node, Lang, JID) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
Base = get_base_path(Host, cluster),
|
2009-06-23 23:00:43 +02:00
|
|
|
MenuItems = make_navigation(Host, Node, Lang, JID),
|
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 =
|
|
|
|
[?XCT(<<"title">>, <<"ejabberd Web Admin">>),
|
|
|
|
#xmlel{name = <<"meta">>,
|
|
|
|
attrs =
|
|
|
|
[{<<"http-equiv">>, <<"Content-Type">>},
|
|
|
|
{<<"content">>,
|
|
|
|
<<"text/html; charset=utf-8">>}],
|
|
|
|
children = []},
|
|
|
|
#xmlel{name = <<"script">>,
|
|
|
|
attrs =
|
|
|
|
[{<<"src">>,
|
|
|
|
<<Base/binary, "/additions.js">>},
|
|
|
|
{<<"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">>,
|
|
|
|
[?ACT(<<"/admin/">>,
|
|
|
|
<<"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">>),
|
2017-01-02 21:41:53 +01:00
|
|
|
?C(<<" (c) 2002-2017 ">>),
|
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(ltr) -> [{<<"dir">>, <<"ltr">>}];
|
|
|
|
direction(<<"he">>) -> [{<<"dir">>, <<"rtl">>}];
|
|
|
|
direction(_) -> [].
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
get_base_path(global, cluster) -> <<"/admin/">>;
|
|
|
|
get_base_path(Host, cluster) ->
|
|
|
|
<<"/admin/server/", Host/binary, "/">>;
|
|
|
|
get_base_path(global, Node) ->
|
|
|
|
<<"/admin/node/",
|
|
|
|
(iolist_to_binary(atom_to_list(Node)))/binary, "/">>;
|
|
|
|
get_base_path(Host, Node) ->
|
|
|
|
<<"/admin/server/", Host/binary, "/node/",
|
|
|
|
(iolist_to_binary(atom_to_list(Node)))/binary, "/">>.
|
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() ->
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"\nfunction selectAll() {\n for(i=0;i<documen"
|
|
|
|
"t.forms[0].elements.length;i++)\n { "
|
|
|
|
"var e = document.forms[0].elements[i];\n "
|
|
|
|
" if(e.type == 'checkbox')\n { e.checked "
|
|
|
|
"= true; }\n }\n}\nfunction unSelectAll() "
|
|
|
|
"{\n for(i=0;i<document.forms[0].elements.len"
|
|
|
|
"gth;i++)\n { var e = document.forms[0].eleme"
|
|
|
|
"nts[i];\n if(e.type == 'checkbox')\n "
|
|
|
|
" { e.checked = false; }\n }\n}\n">>.
|
2009-05-27 19:28:55 +02:00
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
css(Host) ->
|
2008-10-12 15:58:05 +02:00
|
|
|
Base = get_base_path(Host, cluster),
|
2015-11-30 11:35:53 +01:00
|
|
|
<<"html,body {\n"
|
|
|
|
" margin: 0;\n"
|
|
|
|
" padding: 0;\n"
|
|
|
|
" height: 100%;\n"
|
|
|
|
" background: #f9f9f9;\n"
|
|
|
|
" font-family: sans-serif;\n"
|
|
|
|
"}\n"
|
2016-02-25 18:56:43 +01:00
|
|
|
"body {\n"
|
|
|
|
" min-width: 990px;\n"
|
|
|
|
"}\n"
|
2015-11-30 11:35:53 +01:00
|
|
|
"a {\n"
|
|
|
|
" text-decoration: none;\n"
|
|
|
|
" color: #3eaffa;\n"
|
|
|
|
"}\n"
|
|
|
|
"a:hover,\n"
|
|
|
|
"a:active {\n"
|
|
|
|
" text-decoration: underline;\n"
|
|
|
|
"}\n"
|
|
|
|
"#container {\n"
|
|
|
|
" position: relative;\n"
|
|
|
|
" padding: 0;\n"
|
|
|
|
" margin: 0 auto;\n"
|
|
|
|
" max-width: 1280px;\n"
|
|
|
|
" min-height: 100%;\n"
|
|
|
|
" height: 100%;\n"
|
|
|
|
" margin-bottom: -30px;\n"
|
|
|
|
" z-index: 1;\n"
|
|
|
|
"}\n"
|
|
|
|
"html>body #container {\n"
|
|
|
|
" height: auto;\n"
|
|
|
|
"}\n"
|
|
|
|
"#header h1 {\n"
|
|
|
|
" width: 100%;\n"
|
|
|
|
" height: 50px;\n"
|
|
|
|
" padding: 0;\n"
|
|
|
|
" margin: 0;\n"
|
|
|
|
" background-color: #49cbc1;\n"
|
|
|
|
"}\n"
|
|
|
|
"#header h1 a {\n"
|
|
|
|
" position: absolute;\n"
|
|
|
|
" top: 0;\n"
|
|
|
|
" left: 0;\n"
|
|
|
|
" width: 100%;\n"
|
|
|
|
" height: 50px;\n"
|
|
|
|
" padding: 0;\n"
|
|
|
|
" margin: 0;\n"
|
|
|
|
" background: url('",Base/binary,"logo.png') 10px center no-repeat transparent;\n"
|
|
|
|
" background-size: auto 25px;\n"
|
|
|
|
" display: block;\n"
|
|
|
|
" text-indent: -9999px;\n"
|
|
|
|
"}\n"
|
|
|
|
"#clearcopyright {\n"
|
|
|
|
" display: block;\n"
|
|
|
|
" width: 100%;\n"
|
|
|
|
" height: 30px;\n"
|
|
|
|
"}\n"
|
|
|
|
"#copyrightouter {\n"
|
|
|
|
" position: relative;\n"
|
|
|
|
" display: table;\n"
|
|
|
|
" width: 100%;\n"
|
|
|
|
" height: 30px;\n"
|
|
|
|
" z-index: 2;\n"
|
|
|
|
"}\n"
|
|
|
|
"#copyright {\n"
|
|
|
|
" display: table-cell;\n"
|
|
|
|
" vertical-align: bottom;\n"
|
|
|
|
" width: 100%;\n"
|
|
|
|
" height: 30px;\n"
|
|
|
|
"}\n"
|
|
|
|
"#copyright a {\n"
|
|
|
|
" font-weight: bold;\n"
|
|
|
|
" color: #fff;\n"
|
|
|
|
"}\n"
|
|
|
|
"#copyright p {\n"
|
|
|
|
" margin-left: 0;\n"
|
|
|
|
" margin-right: 0;\n"
|
|
|
|
" margin-top: 5px;\n"
|
|
|
|
" margin-bottom: 0;\n"
|
|
|
|
" padding-left: 0;\n"
|
|
|
|
" padding-right: 0;\n"
|
|
|
|
" padding-top: 5px;\n"
|
|
|
|
" padding-bottom: 5px;\n"
|
|
|
|
" width: 100%;\n"
|
|
|
|
" color: #fff;\n"
|
|
|
|
" background-color: #30353E;\n"
|
|
|
|
" font-size: 0.75em;\n"
|
|
|
|
" text-align: center;\n"
|
|
|
|
"}\n"
|
2016-02-25 18:56:43 +01:00
|
|
|
"#navigation {\n"
|
|
|
|
" display: inline-block;\n"
|
|
|
|
" vertical-align: top;\n"
|
|
|
|
" width: 30%;\n"
|
|
|
|
"}\n"
|
2015-11-30 11:35:53 +01:00
|
|
|
"#navigation ul {\n"
|
|
|
|
" padding: 0;\n"
|
|
|
|
" margin: 0;\n"
|
2016-02-25 18:56:43 +01:00
|
|
|
" width: 90%;\n"
|
2015-11-30 11:35:53 +01:00
|
|
|
" background: #fff;\n"
|
|
|
|
"}\n"
|
|
|
|
"#navigation ul li {\n"
|
|
|
|
" list-style: none;\n"
|
|
|
|
" margin: 0;\n"
|
|
|
|
"\n"
|
|
|
|
" border-bottom: 1px solid #f9f9f9;\n"
|
|
|
|
" text-align: left;\n"
|
|
|
|
"}\n"
|
|
|
|
"#navigation ul li a {\n"
|
|
|
|
" margin: 0;\n"
|
|
|
|
" display: inline-block;\n"
|
|
|
|
" padding: 10px;\n"
|
|
|
|
" color: #333;\n"
|
|
|
|
"}\n"
|
|
|
|
"ul li #navhead a, ul li #navheadsub a, ul li #navheadsubsub a {\n"
|
|
|
|
" font-size: 1.5em;\n"
|
|
|
|
" color: inherit;\n"
|
|
|
|
"}\n"
|
|
|
|
"#navitemsub {\n"
|
|
|
|
" border-left: 0.5em solid #424a55;\n"
|
|
|
|
"}\n"
|
|
|
|
"#navitemsubsub {\n"
|
|
|
|
" border-left: 2em solid #424a55;\n"
|
|
|
|
"}\n"
|
|
|
|
"#navheadsub,\n"
|
|
|
|
"#navheadsubsub {\n"
|
|
|
|
" padding-left: 0.5em;\n"
|
|
|
|
"}\n"
|
|
|
|
"#navhead,\n"
|
|
|
|
"#navheadsub,\n"
|
|
|
|
"#navheadsubsub {\n"
|
|
|
|
" border-top: 3px solid #49cbc1;\n"
|
|
|
|
" background: #424a55;\n"
|
|
|
|
" color: #fff;\n"
|
|
|
|
"}\n"
|
|
|
|
"#lastactivity li {\n"
|
|
|
|
" padding: 2px;\n"
|
|
|
|
" margin-bottom: -1px;\n"
|
|
|
|
"}\n"
|
|
|
|
"thead tr td {\n"
|
|
|
|
" background: #3eaffa;\n"
|
|
|
|
" color: #fff;\n"
|
|
|
|
"}\n"
|
2016-02-12 18:45:45 +01:00
|
|
|
"thead tr td a {\n"
|
|
|
|
" color: #fff;\n"
|
|
|
|
"}\n"
|
2015-11-30 11:35:53 +01:00
|
|
|
"td.copy {\n"
|
|
|
|
" text-align: center;\n"
|
|
|
|
"}\n"
|
|
|
|
"tr.head {\n"
|
|
|
|
" color: #fff;\n"
|
|
|
|
" background-color: #3b547a;\n"
|
|
|
|
" text-align: center;\n"
|
|
|
|
"}\n"
|
|
|
|
"tr.oddraw {\n"
|
|
|
|
" color: #412c75;\n"
|
|
|
|
" background-color: #ccd4df;\n"
|
|
|
|
" text-align: center;\n"
|
|
|
|
"}\n"
|
|
|
|
"tr.evenraw {\n"
|
|
|
|
" color: #412c75;\n"
|
|
|
|
" background-color: #dbe0e8;\n"
|
|
|
|
" text-align: center;\n"
|
|
|
|
"}\n"
|
|
|
|
"td.leftheader {\n"
|
|
|
|
" color: #412c75;\n"
|
|
|
|
" background-color: #ccccc1;\n"
|
|
|
|
" padding-left: 5px;\n"
|
|
|
|
" padding-top: 2px;\n"
|
|
|
|
" padding-bottom: 2px;\n"
|
|
|
|
" margin-top: 0px;\n"
|
|
|
|
" margin-bottom: 0px;\n"
|
|
|
|
"}\n"
|
|
|
|
"td.leftcontent {\n"
|
|
|
|
" color: #000044;\n"
|
|
|
|
" background-color: #e6e6df;\n"
|
|
|
|
" padding-left: 5px;\n"
|
|
|
|
" padding-right: 5px;\n"
|
|
|
|
" padding-top: 2px;\n"
|
|
|
|
" padding-bottom: 2px;\n"
|
|
|
|
" margin-top: 0px;\n"
|
|
|
|
" margin-bottom: 0px;\n"
|
|
|
|
"}\n"
|
|
|
|
"td.rightcontent {\n"
|
|
|
|
" color: #000044;\n"
|
|
|
|
" text-align: justify;\n"
|
|
|
|
" padding-left: 10px;\n"
|
|
|
|
" padding-right: 10px;\n"
|
|
|
|
" padding-bottom: 5px;\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
"h1 {\n"
|
|
|
|
" color: #000044;\n"
|
|
|
|
" padding-top: 2px;\n"
|
|
|
|
" padding-bottom: 2px;\n"
|
|
|
|
" margin-top: 0px;\n"
|
|
|
|
" margin-bottom: 0px;\n"
|
|
|
|
"}\n"
|
|
|
|
"h2 {\n"
|
|
|
|
" color: #000044;\n"
|
|
|
|
" text-align: center;\n"
|
|
|
|
" padding-top: 2px;\n"
|
|
|
|
" padding-bottom: 2px;\n"
|
|
|
|
" margin-top: 0px;\n"
|
|
|
|
" margin-bottom: 0px;\n"
|
|
|
|
"}\n"
|
|
|
|
"h3 {\n"
|
|
|
|
" color: #000044;\n"
|
|
|
|
" text-align: left;\n"
|
|
|
|
" padding-top: 20px;\n"
|
|
|
|
" padding-bottom: 2px;\n"
|
|
|
|
" margin-top: 0px;\n"
|
|
|
|
" margin-bottom: 0px;\n"
|
|
|
|
"}\n"
|
|
|
|
"#content ul {\n"
|
|
|
|
" padding-left: 1.1em;\n"
|
|
|
|
" margin-top: 1em;\n"
|
|
|
|
"}\n"
|
|
|
|
"#content ul li {\n"
|
|
|
|
" list-style-type: disc;\n"
|
|
|
|
" padding: 5px;\n"
|
|
|
|
"}\n"
|
|
|
|
"#content ul.nolistyle>li {\n"
|
|
|
|
" list-style-type: none;\n"
|
|
|
|
"}\n"
|
|
|
|
"#content {\n"
|
2016-02-25 18:56:43 +01:00
|
|
|
" display: inline-block;\n"
|
|
|
|
" vertical-align: top;\n"
|
2015-11-30 11:35:53 +01:00
|
|
|
" padding-top: 25px;\n"
|
2016-02-25 18:56:43 +01:00
|
|
|
" width: 70%;\n"
|
2015-11-30 11:35:53 +01:00
|
|
|
"}\n"
|
|
|
|
"div.guidelink,\n"
|
|
|
|
"p[dir=ltr] {\n"
|
|
|
|
" display: inline-block;\n"
|
|
|
|
" float: right;\n"
|
|
|
|
"\n"
|
|
|
|
" margin: 0;\n"
|
|
|
|
" margin-right: 1em;\n"
|
|
|
|
"}\n"
|
|
|
|
"div.guidelink a,\n"
|
|
|
|
"p[dir=ltr] a {\n"
|
|
|
|
" display: inline-block;\n"
|
|
|
|
" border-radius: 3px;\n"
|
|
|
|
" padding: 3px;\n"
|
|
|
|
"\n"
|
|
|
|
" background: #3eaffa;\n"
|
|
|
|
"\n"
|
|
|
|
" text-transform: uppercase;\n"
|
|
|
|
" font-size: 0.75em;\n"
|
|
|
|
" color: #fff;\n"
|
|
|
|
"}\n"
|
|
|
|
"table {\n"
|
|
|
|
" margin-top: 1em;\n"
|
|
|
|
"}\n"
|
|
|
|
"table tr td {\n"
|
|
|
|
" padding: 0.5em;\n"
|
|
|
|
"}\n"
|
|
|
|
"table tr:nth-child(odd) {\n"
|
|
|
|
" background: #fff;\n"
|
|
|
|
"}\n"
|
|
|
|
"table.withtextareas>tbody>tr>td {\n"
|
|
|
|
" vertical-align: top;\n"
|
|
|
|
"}\n"
|
|
|
|
"textarea {\n"
|
|
|
|
" margin-bottom: 1em;\n"
|
|
|
|
"}\n"
|
|
|
|
"input,\n"
|
|
|
|
"select {\n"
|
|
|
|
" font-size: 1em;\n"
|
|
|
|
"}\n"
|
|
|
|
"p.result {\n"
|
|
|
|
" border: 1px;\n"
|
|
|
|
" border-style: dashed;\n"
|
|
|
|
" border-color: #FE8A02;\n"
|
|
|
|
" padding: 1em;\n"
|
|
|
|
" margin-right: 1em;\n"
|
|
|
|
" background: #FFE3C9;\n"
|
|
|
|
"}\n"
|
|
|
|
"*.alignright {\n"
|
|
|
|
" text-align: right;\n"
|
|
|
|
"}">>.
|
2004-04-26 17:38:07 +02:00
|
|
|
|
2007-11-26 16:12:34 +01:00
|
|
|
favicon() ->
|
2017-05-23 09:43:26 +02:00
|
|
|
base64:decode(<<"AAABAAEAEBAAAAEAIAAoBQAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAA1AwMAQwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwMARQUEA+oFAwCOBAQAaAQEAGkEBABpBAQAaQQEAGoFAgBcBAAAOQAAAAoAAAAAAAAAAAAAAAAAAAAAAAAAAAMDAEIHBgX/BwYF/wcGBf8HBgX/BwYF/wcGBf8HBgX/BwYF/wUFA/wEBAHOBQICXgAAAAAAAAAAAAAAAAAAAAADAwBCBwYF/wcGBf8HBgX/BwYF/wcGBf8HBgX/BwYF/wcGBf8HBgX/BwYF/wcGBf8DAwCUAAAABwAAAAAAAAAAAwMAQgcGBf8HBgX/BwYF/wcGBf8FBQPMBAAAaAQAAD8DAwNOAwMDlgUFA/QHBgX/BwYF/wQEAHkAAAAAAAAAAAMDAEIHBgX/BwYF/wcGBf8EBAGeAAAACAAAAAAAAAASAAAABQAAAAAFBQGxBwYF/wcGBf8FBAPvAAAAKAAAAAADAwBCBwYF/wcGBf8EBAHPAAAADQAAACEFBQGuBQQD8AUEAeEFBQGuBQQB9QcGBf8HBgX/BwYF/wQEAH8AAAAAAwMAQgcGBf8HBgX/BgQAbwAAAAADAwOXBQQB3gUFAdgFBQHZBQQB3QUFAdYFBAHhBQUD/gcGBf8EBAK8AAAAAAMDAEIHBgX/BwYF/wQAAD0AAAAAAAAABQAAAAEAAAABAAAAAQAAAAEAAAAFAAAAEQUFArwKBgX/BQMDxQAAAAADAwBCBwYF/wcGBf8DAwBKAAAAAwYDAFAGAwBVBgMAVAYDAFQFAgJZAAAALwAAAAAFBQGuCgYF/wUDA8QAAAAAAAAAKwUEA/QHBgX/AwMDlgAAAAAFAwOIBwYF/wcGBf8HBgX/BQQB5wAAADMAAAAWBQUD5wcGBf8EBAGbAAAAAAAAAAYFBAG9BwYF/wUFA/EDAABAAAAAAAMDA1QDAwOYBQUAhQAAACQAAAAABAQBnQcGBf8HBgX/AwMATQAAAAAAAAAAAwAAQwUFA/oHBgX/BQQB5QYDA1UAAAAAAAAAAAAAAAAAAAAXAwMAlwcGBf8HBgX/BQUBtQAAAAcAAAAAAAAAAAAAAAAEBABzBQUD/gcGBf8HBgX/BQMDyQQEAZwGBAGqBQQB5AcGBf8HBgX/BAQB0QAAACEAAAAAAAAAAAAAAAAAAAAAAAAAAAUFAmQFBAHlBwYF/wcGBf8HBgX/BwYF/wcGBf8FBQP+BQUBsAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHwUFA40FBAHrBwYF/wUFA/4FAwPGBgMAUgAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==">>).
|
2007-11-26 16:12:34 +01:00
|
|
|
|
2004-04-26 17:38:07 +02:00
|
|
|
logo() ->
|
2017-05-23 09:43:26 +02:00
|
|
|
base64:decode(<<"iVBORw0KGgoAAAANSUhEUgAAA64AAADICAYAAADoQ7yoAAAKQWlDQ1BJQ0MgUHJvZmlsZQAASA2dlndUU9kWh8+9N73QEiIgJfQaegkg0jtIFQRRiUmAUAKGhCZ2RAVGFBEpVmRUwAFHhyJjRRQLg4Ji1wnyEFDGwVFEReXdjGsJ7601896a/cdZ39nnt9fZZ+9917oAUPyCBMJ0WAGANKFYFO7rwVwSE8vE9wIYEAEOWAHA4WZmBEf4RALU/L09mZmoSMaz9u4ugGS72yy/UCZz1v9/kSI3QyQGAApF1TY8fiYX5QKUU7PFGTL/BMr0lSkyhjEyFqEJoqwi48SvbPan5iu7yZiXJuShGlnOGbw0noy7UN6aJeGjjAShXJgl4GejfAdlvVRJmgDl9yjT0/icTAAwFJlfzOcmoWyJMkUUGe6J8gIACJTEObxyDov5OWieAHimZ+SKBIlJYqYR15hp5ejIZvrxs1P5YjErlMNN4Yh4TM/0tAyOMBeAr2+WRQElWW2ZaJHtrRzt7VnW5mj5v9nfHn5T/T3IevtV8Sbsz55BjJ5Z32zsrC+9FgD2JFqbHbO+lVUAtG0GQOXhrE/vIADyBQC03pzzHoZsXpLE4gwnC4vs7GxzAZ9rLivoN/ufgm/Kv4Y595nL7vtWO6YXP4EjSRUzZUXlpqemS0TMzAwOl89k/fcQ/+PAOWnNycMsnJ/AF/GF6FVR6JQJhIlou4U8gViQLmQKhH/V4X8YNicHGX6daxRodV8AfYU5ULhJB8hvPQBDIwMkbj96An3rWxAxCsi+vGitka9zjzJ6/uf6Hwtcim7hTEEiU+b2DI9kciWiLBmj34RswQISkAd0oAo0gS4wAixgDRyAM3AD3iAAhIBIEAOWAy5IAmlABLJBPtgACkEx2AF2g2pwANSBetAEToI2cAZcBFfADXALDIBHQAqGwUswAd6BaQiC8BAVokGqkBakD5lC1hAbWgh5Q0FQOBQDxUOJkBCSQPnQJqgYKoOqoUNQPfQjdBq6CF2D+qAH0CA0Bv0BfYQRmALTYQ3YALaA2bA7HAhHwsvgRHgVnAcXwNvhSrgWPg63whfhG/AALIVfwpMIQMgIA9FGWAgb8URCkFgkAREha5EipAKpRZqQDqQbuY1IkXHkAwaHoWGYGBbGGeOHWYzhYlZh1mJKMNWYY5hWTBfmNmYQM4H5gqVi1bGmWCesP3YJNhGbjS3EVmCPYFuwl7ED2GHsOxwOx8AZ4hxwfrgYXDJuNa4Etw/XjLuA68MN4SbxeLwq3hTvgg/Bc/BifCG+Cn8cfx7fjx/GvyeQCVoEa4IPIZYgJGwkVBAaCOcI/YQRwjRRgahPdCKGEHnEXGIpsY7YQbxJHCZOkxRJhiQXUiQpmbSBVElqIl0mPSa9IZPJOmRHchhZQF5PriSfIF8lD5I/UJQoJhRPShxFQtlOOUq5QHlAeUOlUg2obtRYqpi6nVpPvUR9Sn0vR5Mzl/OX48mtk6uRa5Xrl3slT5TXl3eXXy6fJ18hf0r+pvy4AlHBQMFTgaOwVqFG4bTCPYVJRZqilWKIYppiiWKD4jXFUSW8koGStxJPqUDpsNIlpSEaQtOledK4tE20Otpl2jAdRzek+9OT6cX0H+i99AllJWVb5SjlHOUa5bPKUgbCMGD4M1IZpYyTjLuMj/M05rnP48/bNq9pXv+8KZX5Km4qfJUilWaVAZWPqkxVb9UU1Z2qbapP1DBqJmphatlq+9Uuq43Pp893ns+dXzT/5PyH6rC6iXq4+mr1w+o96pMamhq+GhkaVRqXNMY1GZpumsma5ZrnNMe0aFoLtQRa5VrntV4wlZnuzFRmJbOLOaGtru2nLdE+pN2rPa1jqLNYZ6NOs84TXZIuWzdBt1y3U3dCT0svWC9fr1HvoT5Rn62fpL9Hv1t/ysDQINpgi0GbwaihiqG/YZ5ho+FjI6qRq9Eqo1qjO8Y4Y7ZxivE+41smsImdSZJJjclNU9jU3lRgus+0zwxr5mgmNKs1u8eisNxZWaxG1qA5wzzIfKN5m/krCz2LWIudFt0WXyztLFMt6ywfWSlZBVhttOqw+sPaxJprXWN9x4Zq42Ozzqbd5rWtqS3fdr/tfTuaXbDdFrtOu8/2DvYi+yb7MQc9h3iHvQ732HR2KLuEfdUR6+jhuM7xjOMHJ3snsdNJp9+dWc4pzg3OowsMF/AX1C0YctFx4bgccpEuZC6MX3hwodRV25XjWuv6zE3Xjed2xG3E3dg92f24+ysPSw+RR4vHlKeT5xrPC16Il69XkVevt5L3Yu9q76c+Oj6JPo0+E752vqt9L/hh/QL9dvrd89fw5/rX+08EOASsCegKpARGBFYHPgsyCRIFdQTDwQHBu4IfL9JfJFzUFgJC/EN2hTwJNQxdFfpzGC4sNKwm7Hm4VXh+eHcELWJFREPEu0iPyNLIR4uNFksWd0bJR8VF1UdNRXtFl0VLl1gsWbPkRoxajCCmPRYfGxV7JHZyqffS3UuH4+ziCuPuLjNclrPs2nK15anLz66QX8FZcSoeGx8d3xD/iRPCqeVMrvRfuXflBNeTu4f7kufGK+eN8V34ZfyRBJeEsoTRRJfEXYljSa5JFUnjAk9BteB1sl/ygeSplJCUoykzqdGpzWmEtPi000IlYYqwK10zPSe9L8M0ozBDuspp1e5VE6JA0ZFMKHNZZruYjv5M9UiMJJslg1kLs2qy3mdHZZ/KUcwR5vTkmuRuyx3J88n7fjVmNXd1Z752/ob8wTXuaw6thdauXNu5Tnddwbrh9b7rj20gbUjZ8MtGy41lG99uit7UUaBRsL5gaLPv5sZCuUJR4b0tzlsObMVsFWzt3WazrWrblyJe0fViy+KK4k8l3JLr31l9V/ndzPaE7b2l9qX7d+B2CHfc3em681iZYlle2dCu4F2t5czyovK3u1fsvlZhW3FgD2mPZI+0MqiyvUqvakfVp+qk6oEaj5rmvep7t+2d2sfb17/fbX/TAY0DxQc+HhQcvH/I91BrrUFtxWHc4azDz+ui6rq/Z39ff0TtSPGRz0eFR6XHwo911TvU1zeoN5Q2wo2SxrHjccdv/eD1Q3sTq+lQM6O5+AQ4ITnx4sf4H++eDDzZeYp9qukn/Z/2ttBailqh1tzWibakNml7THvf6YDTnR3OHS0/m/989Iz2mZqzymdLz5HOFZybOZ93fvJCxoXxi4kXhzpXdD66tOTSna6wrt7LgZevXvG5cqnbvfv8VZerZ645XTt9nX297Yb9jdYeu56WX+x+aem172296XCz/ZbjrY6+BX3n+l37L972un3ljv+dGwOLBvruLr57/17cPel93v3RB6kPXj/Mejj9aP1j7OOiJwpPKp6qP6391fjXZqm99Oyg12DPs4hnj4a4Qy//lfmvT8MFz6nPK0a0RupHrUfPjPmM3Xqx9MXwy4yX0+OFvyn+tveV0auffnf7vWdiycTwa9HrmT9K3qi+OfrW9m3nZOjk03dp76anit6rvj/2gf2h+2P0x5Hp7E/4T5WfjT93fAn88ngmbWbm3/eE8/syOll+AABAAElEQVR4Ae19CbgdVZVu1c0EGclMBsgNDUHRACKgQpjs0D6FqK0tCCqE9mt8HezXdjO07XvdBAdsIXwP+zUI2D4GWxB8ditBWwFBQoBWEAjYCjTk3oQMZCBzbpKb5Nb717nnhDucc24Ne+3au+rf37fuuadq1xr+tavOXnuvvSsMWIiA5whEUTQMJgytmjEYn/uCINwRhkHkuWlU3zME0BZDFLY7z/yWRl36Og1qvIYIEAEiQATKjID8dor97CuVuRWU0HY0/OGgRXvxp0m5G+cmlhAemqyMANrVNNDdTdpfG87PB8lACovHCMCH9LXH/qPqRIAIEAEikC8C+B0dBVoI2gyqV9pwUM6PyldTSicCCghUGzc+4pbOWxXUIMsSIoAWN2x7FD0ft+VV680vIVTem0xfe+9CGkAEiAARIAI5I7ALg/zJ+kzss+fsMoo3hcAazLKuS9b6e9SWK9cMN6UL+ZQPATSg2T0aVMJ/Ny0uH2L+Wkxf++s7ak4EiA
|
2004-04-26 17:38:07 +02:00
|
|
|
|
|
|
|
logo_fill() ->
|
2017-05-23 09:43:26 +02:00
|
|
|
base64:decode(<<"iVBORw0KGgoAAAANSUhEUgAAAAYAAAA3BAMAAADdxCZzA"
|
2013-03-14 10:33:02 +01:00
|
|
|
"AAAAXNSR0IArs4c6QAAAB5QTFRF1nYO/ooC/o4O/pIS/p"
|
|
|
|
"4q/q5K/rpq/sqM/tam/ubGzn/S/AAAAEFJREFUCNdlw0s"
|
|
|
|
"RwCAQBUE+gSRHLGABC1jAAhbWAhZwC+88XdXOXb4UlFAr"
|
|
|
|
"SmwN5ekdJY2BkudEec1QvrVQ/r3xOlK9HsTvertmAAAAA"
|
|
|
|
"ElFTkSuQmCC">>).
|
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
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
process_admin(global,
|
2013-03-14 10:33:02 +01:00
|
|
|
#request{path = [], auth = {_, _, AJID},
|
2007-12-07 02:40:24 +01:00
|
|
|
lang = Lang}) ->
|
2015-07-15 20:40:13 +02:00
|
|
|
make_xhtml((?H1GL((?T(<<"Administration">>)), <<"">>,
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"Contents">>))
|
|
|
|
++
|
|
|
|
[?XE(<<"ul">>,
|
|
|
|
[?LI([?ACT(MIU, MIN)])
|
|
|
|
|| {MIU, MIN}
|
|
|
|
<- get_menu_items(global, cluster, Lang, AJID)])],
|
|
|
|
global, Lang, AJID);
|
2005-06-20 05:18:13 +02:00
|
|
|
process_admin(Host,
|
2013-03-14 10:33:02 +01:00
|
|
|
#request{path = [], auth = {_, _Auth, AJID},
|
2007-12-07 02:40:24 +01:00
|
|
|
lang = Lang}) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
make_xhtml([?XCT(<<"h1">>, <<"Administration">>),
|
|
|
|
?XE(<<"ul">>,
|
|
|
|
[?LI([?ACT(MIU, MIN)])
|
|
|
|
|| {MIU, MIN}
|
|
|
|
<- get_menu_items(Host, cluster, Lang, AJID)])],
|
|
|
|
Host, Lang, AJID);
|
2005-06-20 05:18:13 +02:00
|
|
|
process_admin(Host,
|
2013-03-14 10:33:02 +01:00
|
|
|
#request{path = [<<"style.css">>]}) ->
|
|
|
|
{200,
|
|
|
|
[{<<"Content-Type">>, <<"text/css">>}, last_modified(),
|
|
|
|
cache_control_public()],
|
|
|
|
css(Host)};
|
|
|
|
process_admin(_Host,
|
|
|
|
#request{path = [<<"favicon.ico">>]}) ->
|
|
|
|
{200,
|
|
|
|
[{<<"Content-Type">>, <<"image/x-icon">>},
|
|
|
|
last_modified(), cache_control_public()],
|
|
|
|
favicon()};
|
|
|
|
process_admin(_Host,
|
|
|
|
#request{path = [<<"logo.png">>]}) ->
|
|
|
|
{200,
|
|
|
|
[{<<"Content-Type">>, <<"image/png">>}, last_modified(),
|
|
|
|
cache_control_public()],
|
|
|
|
logo()};
|
|
|
|
process_admin(_Host,
|
|
|
|
#request{path = [<<"logo-fill.png">>]}) ->
|
|
|
|
{200,
|
|
|
|
[{<<"Content-Type">>, <<"image/png">>}, last_modified(),
|
|
|
|
cache_control_public()],
|
|
|
|
logo_fill()};
|
|
|
|
process_admin(_Host,
|
|
|
|
#request{path = [<<"additions.js">>]}) ->
|
|
|
|
{200,
|
|
|
|
[{<<"Content-Type">>, <<"text/javascript">>},
|
|
|
|
last_modified(), cache_control_public()],
|
|
|
|
additions_js()};
|
|
|
|
process_admin(Host,
|
|
|
|
#request{path = [<<"acls-raw">>], q = Query,
|
|
|
|
auth = {_, _Auth, AJID}, lang = Lang}) ->
|
|
|
|
Res = case lists:keysearch(<<"acls">>, 1, Query) of
|
|
|
|
{value, {_, String}} ->
|
|
|
|
case erl_scan:string(binary_to_list(String)) of
|
|
|
|
{ok, Tokens, _} ->
|
|
|
|
case erl_parse:parse_term(Tokens) of
|
|
|
|
{ok, NewACLs} ->
|
2017-05-04 11:18:16 +02:00
|
|
|
case catch acl:add_list(Host, NewACLs, true) of
|
|
|
|
ok -> ok;
|
|
|
|
_ -> error
|
|
|
|
end;
|
2013-03-14 10:33:02 +01:00
|
|
|
_ -> error
|
|
|
|
end;
|
|
|
|
_ -> error
|
|
|
|
end;
|
|
|
|
_ -> nothing
|
2004-04-26 17:38:07 +02:00
|
|
|
end,
|
2013-03-14 10:33:02 +01:00
|
|
|
ACLs = lists:keysort(2,
|
2016-09-19 11:54:46 +02:00
|
|
|
mnesia:dirty_select(acl,
|
2013-03-14 10:33:02 +01:00
|
|
|
[{{acl, {'$1', Host}, '$2'}, [],
|
|
|
|
[{{acl, '$1', '$2'}}]}])),
|
2009-01-12 22:48:34 +01:00
|
|
|
{NumLines, ACLsP} = term_to_paragraph(ACLs, 80),
|
2013-03-14 10:33:02 +01:00
|
|
|
make_xhtml((?H1GL((?T(<<"Access Control Lists">>)),
|
2016-02-08 16:16:53 +01:00
|
|
|
<<"acldefinition">>, <<"ACL Definition">>))
|
2013-03-14 10:33:02 +01:00
|
|
|
++
|
|
|
|
case Res of
|
|
|
|
ok -> [?XREST(<<"Submitted">>)];
|
|
|
|
error -> [?XREST(<<"Bad format">>)];
|
2004-04-26 17:38:07 +02:00
|
|
|
nothing -> []
|
2013-03-14 10:33:02 +01:00
|
|
|
end
|
|
|
|
++
|
|
|
|
[?XAE(<<"form">>,
|
2015-07-15 19:01:32 +02:00
|
|
|
[{<<"action">>, <<"">>}, {<<"method">>, <<"post">>}]++direction(ltr),
|
2013-03-14 10:33:02 +01:00
|
|
|
[?TEXTAREA(<<"acls">>,
|
2016-11-24 13:06:06 +01:00
|
|
|
(integer_to_binary(lists:max([16,
|
|
|
|
NumLines]))),
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"80">>, <<(iolist_to_binary(ACLsP))/binary, ".">>),
|
|
|
|
?BR,
|
|
|
|
?INPUTT(<<"submit">>, <<"submit">>, <<"Submit">>)])],
|
|
|
|
Host, Lang, AJID);
|
2005-06-20 05:18:13 +02:00
|
|
|
process_admin(Host,
|
2013-03-14 10:33:02 +01:00
|
|
|
#request{method = Method, path = [<<"acls">>],
|
|
|
|
auth = {_, _Auth, AJID}, q = Query, lang = Lang}) ->
|
2007-12-06 12:24:57 +01:00
|
|
|
?DEBUG("query: ~p", [Query]),
|
2004-04-26 17:38:07 +02:00
|
|
|
Res = case Method of
|
2013-03-14 10:33:02 +01:00
|
|
|
'POST' ->
|
|
|
|
case catch acl_parse_query(Host, Query) of
|
|
|
|
{'EXIT', _} -> error;
|
|
|
|
NewACLs ->
|
2017-05-04 11:18:16 +02:00
|
|
|
?INFO_MSG("NewACLs at ~s: ~p", [Host, NewACLs]),
|
|
|
|
case catch acl:add_list(Host, NewACLs, true) of
|
|
|
|
ok -> ok;
|
|
|
|
_ -> error
|
|
|
|
end
|
2013-03-14 10:33:02 +01:00
|
|
|
end;
|
|
|
|
_ -> nothing
|
2004-04-26 17:38:07 +02:00
|
|
|
end,
|
2013-03-14 10:33:02 +01:00
|
|
|
ACLs = lists:keysort(2,
|
2016-09-19 11:54:46 +02:00
|
|
|
mnesia:dirty_select(acl,
|
2013-03-14 10:33:02 +01:00
|
|
|
[{{acl, {'$1', Host}, '$2'}, [],
|
|
|
|
[{{acl, '$1', '$2'}}]}])),
|
|
|
|
make_xhtml((?H1GL((?T(<<"Access Control Lists">>)),
|
2016-02-08 16:16:53 +01:00
|
|
|
<<"acldefinition">>, <<"ACL Definition">>))
|
2013-03-14 10:33:02 +01:00
|
|
|
++
|
|
|
|
case Res of
|
|
|
|
ok -> [?XREST(<<"Submitted">>)];
|
|
|
|
error -> [?XREST(<<"Bad format">>)];
|
2004-04-26 17:38:07 +02:00
|
|
|
nothing -> []
|
2013-03-14 10:33:02 +01:00
|
|
|
end
|
|
|
|
++
|
2015-07-15 18:51:17 +02:00
|
|
|
[?XAE(<<"p">>, direction(ltr), [?ACT(<<"../acls-raw/">>, <<"Raw">>)])] ++
|
2013-03-14 10:33:02 +01:00
|
|
|
[?XAE(<<"form">>,
|
2015-07-15 19:01:32 +02:00
|
|
|
[{<<"action">>, <<"">>}, {<<"method">>, <<"post">>}]++direction(ltr),
|
2013-03-14 10:33:02 +01:00
|
|
|
[acls_to_xhtml(ACLs), ?BR,
|
|
|
|
?INPUTT(<<"submit">>, <<"delete">>,
|
|
|
|
<<"Delete Selected">>),
|
|
|
|
?C(<<" ">>),
|
|
|
|
?INPUTT(<<"submit">>, <<"submit">>,
|
|
|
|
<<"Submit">>)])],
|
|
|
|
Host, Lang, AJID);
|
2005-06-20 05:18:13 +02:00
|
|
|
process_admin(Host,
|
2013-03-14 10:33:02 +01:00
|
|
|
#request{path = [<<"access-raw">>],
|
|
|
|
auth = {_, _Auth, AJID}, q = Query, lang = Lang}) ->
|
|
|
|
SetAccess = fun (Rs) ->
|
|
|
|
mnesia:transaction(fun () ->
|
2015-03-05 11:34:25 +01:00
|
|
|
Os = mnesia:select(access,
|
|
|
|
[{{access,
|
|
|
|
{'$1',
|
2013-03-14 10:33:02 +01:00
|
|
|
Host},
|
|
|
|
'$2'},
|
|
|
|
[],
|
|
|
|
['$_']}]),
|
|
|
|
lists:foreach(fun (O) ->
|
|
|
|
mnesia:delete_object(O)
|
|
|
|
end,
|
|
|
|
Os),
|
|
|
|
lists:foreach(fun ({access,
|
|
|
|
Name,
|
|
|
|
Rules}) ->
|
2015-03-05 11:34:25 +01:00
|
|
|
mnesia:write({access,
|
|
|
|
{Name,
|
2013-03-14 10:33:02 +01:00
|
|
|
Host},
|
|
|
|
Rules})
|
|
|
|
end,
|
|
|
|
Rs)
|
|
|
|
end)
|
|
|
|
end,
|
|
|
|
Res = case lists:keysearch(<<"access">>, 1, Query) of
|
|
|
|
{value, {_, String}} ->
|
|
|
|
case erl_scan:string(binary_to_list(String)) of
|
|
|
|
{ok, Tokens, _} ->
|
|
|
|
case erl_parse:parse_term(Tokens) of
|
|
|
|
{ok, Rs} ->
|
|
|
|
case SetAccess(Rs) of
|
|
|
|
{atomic, _} -> ok;
|
|
|
|
_ -> error
|
|
|
|
end;
|
|
|
|
_ -> error
|
|
|
|
end;
|
|
|
|
_ -> error
|
|
|
|
end;
|
|
|
|
_ -> nothing
|
2004-04-26 17:38:07 +02:00
|
|
|
end,
|
2016-09-19 11:54:46 +02:00
|
|
|
Access = mnesia:dirty_select(access,
|
2015-03-05 11:34:25 +01:00
|
|
|
[{{access, {'$1', Host}, '$2'}, [],
|
2013-03-14 10:33:02 +01:00
|
|
|
[{{access, '$1', '$2'}}]}]),
|
|
|
|
{NumLines, AccessP} = term_to_paragraph(lists:keysort(2,Access), 80),
|
|
|
|
make_xhtml((?H1GL((?T(<<"Access Rules">>)),
|
2016-02-08 16:16:53 +01:00
|
|
|
<<"accessrights">>, <<"Access Rights">>))
|
2013-03-14 10:33:02 +01:00
|
|
|
++
|
|
|
|
case Res of
|
|
|
|
ok -> [?XREST(<<"Submitted">>)];
|
|
|
|
error -> [?XREST(<<"Bad format">>)];
|
2004-04-26 17:38:07 +02:00
|
|
|
nothing -> []
|
2013-03-14 10:33:02 +01:00
|
|
|
end
|
|
|
|
++
|
|
|
|
[?XAE(<<"form">>,
|
2015-07-15 19:01:32 +02:00
|
|
|
[{<<"action">>, <<"">>}, {<<"method">>, <<"post">>}]++direction(ltr),
|
2013-03-14 10:33:02 +01:00
|
|
|
[?TEXTAREA(<<"access">>,
|
2016-11-24 13:06:06 +01:00
|
|
|
(integer_to_binary(lists:max([16,
|
|
|
|
NumLines]))),
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"80">>, <<(iolist_to_binary(AccessP))/binary, ".">>),
|
|
|
|
?BR,
|
|
|
|
?INPUTT(<<"submit">>, <<"submit">>, <<"Submit">>)])],
|
|
|
|
Host, Lang, AJID);
|
2005-06-20 05:18:13 +02:00
|
|
|
process_admin(Host,
|
2013-03-14 10:33:02 +01:00
|
|
|
#request{method = Method, path = [<<"access">>],
|
|
|
|
q = Query, auth = {_, _Auth, AJID}, lang = Lang}) ->
|
2007-12-06 12:24:57 +01:00
|
|
|
?DEBUG("query: ~p", [Query]),
|
2004-04-26 17:38:07 +02:00
|
|
|
Res = case Method of
|
2013-03-14 10:33:02 +01:00
|
|
|
'POST' ->
|
|
|
|
case catch access_parse_query(Host, Query) of
|
|
|
|
{'EXIT', _} -> error;
|
|
|
|
ok -> ok
|
|
|
|
end;
|
|
|
|
_ -> nothing
|
2004-04-26 17:38:07 +02:00
|
|
|
end,
|
2016-09-19 11:54:46 +02:00
|
|
|
AccessRules = mnesia:dirty_select(access,
|
2015-03-05 11:34:25 +01:00
|
|
|
[{{access, {'$1', Host}, '$2'}, [],
|
2013-03-14 10:33:02 +01:00
|
|
|
[{{access, '$1', '$2'}}]}]),
|
|
|
|
make_xhtml((?H1GL((?T(<<"Access Rules">>)),
|
2016-02-08 16:16:53 +01:00
|
|
|
<<"accessrights">>, <<"Access Rights">>))
|
2013-03-14 10:33:02 +01:00
|
|
|
++
|
|
|
|
case Res of
|
|
|
|
ok -> [?XREST(<<"Submitted">>)];
|
|
|
|
error -> [?XREST(<<"Bad format">>)];
|
2004-04-26 17:38:07 +02:00
|
|
|
nothing -> []
|
2013-03-14 10:33:02 +01:00
|
|
|
end
|
|
|
|
++
|
2015-07-15 18:51:17 +02:00
|
|
|
[?XAE(<<"p">>, direction(ltr), [?ACT(<<"../access-raw/">>, <<"Raw">>)])]
|
2013-03-14 10:33:02 +01:00
|
|
|
++
|
|
|
|
[?XAE(<<"form">>,
|
2015-07-15 19:01:32 +02:00
|
|
|
[{<<"action">>, <<"">>}, {<<"method">>, <<"post">>}]++direction(ltr),
|
2013-03-14 10:33:02 +01:00
|
|
|
[access_rules_to_xhtml(AccessRules, Lang), ?BR,
|
|
|
|
?INPUTT(<<"submit">>, <<"delete">>,
|
|
|
|
<<"Delete Selected">>)])],
|
|
|
|
Host, Lang, AJID);
|
2005-06-20 05:18:13 +02:00
|
|
|
process_admin(Host,
|
2013-03-14 10:33:02 +01:00
|
|
|
#request{path = [<<"access">>, SName], q = Query,
|
|
|
|
auth = {_, _Auth, AJID}, lang = Lang}) ->
|
2007-12-06 12:24:57 +01:00
|
|
|
?DEBUG("query: ~p", [Query]),
|
2017-04-11 12:13:58 +02:00
|
|
|
Name = misc:binary_to_atom(SName),
|
2013-03-14 10:33:02 +01:00
|
|
|
Res = case lists:keysearch(<<"rules">>, 1, Query) of
|
|
|
|
{value, {_, String}} ->
|
|
|
|
case parse_access_rule(String) of
|
|
|
|
{ok, Rs} ->
|
2013-08-12 14:25:05 +02:00
|
|
|
ejabberd_config:add_option({access, Name, Host},
|
2013-03-14 10:33:02 +01:00
|
|
|
Rs),
|
|
|
|
ok;
|
|
|
|
_ -> error
|
|
|
|
end;
|
|
|
|
_ -> nothing
|
2004-04-26 17:38:07 +02:00
|
|
|
end,
|
2017-04-29 10:39:40 +02:00
|
|
|
Rules = ejabberd_config:get_option({access, Name, Host}, []),
|
2013-03-14 10:33:02 +01:00
|
|
|
make_xhtml([?XC(<<"h1">>,
|
2016-11-24 13:06:06 +01:00
|
|
|
(str:format(
|
2013-03-14 10:33:02 +01:00
|
|
|
?T(<<"~s access rule configuration">>),
|
|
|
|
[SName])))]
|
|
|
|
++
|
|
|
|
case Res of
|
|
|
|
ok -> [?XREST(<<"Submitted">>)];
|
|
|
|
error -> [?XREST(<<"Bad format">>)];
|
2004-04-26 17:38:07 +02:00
|
|
|
nothing -> []
|
2013-03-14 10:33:02 +01:00
|
|
|
end
|
|
|
|
++
|
|
|
|
[?XAE(<<"form">>,
|
|
|
|
[{<<"action">>, <<"">>}, {<<"method">>, <<"post">>}],
|
|
|
|
[access_rule_to_xhtml(Rules), ?BR,
|
|
|
|
?INPUTT(<<"submit">>, <<"submit">>, <<"Submit">>)])],
|
|
|
|
Host, Lang, AJID);
|
2005-07-29 22:34:57 +02:00
|
|
|
process_admin(global,
|
2013-03-14 10:33:02 +01:00
|
|
|
#request{path = [<<"vhosts">>], auth = {_, _Auth, AJID},
|
2007-12-07 02:40:24 +01:00
|
|
|
lang = Lang}) ->
|
2009-06-23 23:00:43 +02:00
|
|
|
Res = list_vhosts(Lang, AJID),
|
2013-03-14 10:33:02 +01:00
|
|
|
make_xhtml((?H1GL((?T(<<"Virtual Hosts">>)),
|
2016-02-08 16:16:53 +01:00
|
|
|
<<"virtualhosting">>, <<"Virtual Hosting">>))
|
2013-03-14 10:33:02 +01:00
|
|
|
++ Res,
|
|
|
|
global, Lang, AJID);
|
2005-06-20 05:18:13 +02:00
|
|
|
process_admin(Host,
|
2013-03-14 10:33:02 +01:00
|
|
|
#request{path = [<<"users">>], q = Query,
|
|
|
|
auth = {_, _Auth, AJID}, lang = Lang})
|
|
|
|
when is_binary(Host) ->
|
2005-09-29 03:04:24 +02:00
|
|
|
Res = list_users(Host, Query, Lang, fun url_func/1),
|
2013-03-14 10:33:02 +01:00
|
|
|
make_xhtml([?XCT(<<"h1">>, <<"Users">>)] ++ Res, Host,
|
|
|
|
Lang, AJID);
|
2005-06-20 05:18:13 +02:00
|
|
|
process_admin(Host,
|
2013-03-14 10:33:02 +01:00
|
|
|
#request{path = [<<"users">>, Diap],
|
|
|
|
auth = {_, _Auth, AJID}, lang = Lang})
|
|
|
|
when is_binary(Host) ->
|
|
|
|
Res = list_users_in_diapason(Host, Diap, Lang,
|
|
|
|
fun url_func/1),
|
|
|
|
make_xhtml([?XCT(<<"h1">>, <<"Users">>)] ++ Res, Host,
|
|
|
|
Lang, AJID);
|
2005-06-20 05:18:13 +02:00
|
|
|
process_admin(Host,
|
2013-03-14 10:33:02 +01:00
|
|
|
#request{path = [<<"online-users">>],
|
|
|
|
auth = {_, _Auth, AJID}, lang = Lang})
|
|
|
|
when is_binary(Host) ->
|
2005-06-20 05:18:13 +02:00
|
|
|
Res = list_online_users(Host, Lang),
|
2013-03-14 10:33:02 +01:00
|
|
|
make_xhtml([?XCT(<<"h1">>, <<"Online Users">>)] ++ Res,
|
|
|
|
Host, Lang, AJID);
|
2005-06-20 05:18:13 +02:00
|
|
|
process_admin(Host,
|
2013-03-14 10:33:02 +01:00
|
|
|
#request{path = [<<"last-activity">>],
|
|
|
|
auth = {_, _Auth, AJID}, q = Query, lang = Lang})
|
|
|
|
when is_binary(Host) ->
|
2007-12-06 12:24:57 +01: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,
|
2013-03-14 10:33:02 +01:00
|
|
|
make_xhtml([?XCT(<<"h1">>, <<"Users Last Activity">>)]
|
|
|
|
++
|
|
|
|
[?XAE(<<"form">>,
|
|
|
|
[{<<"action">>, <<"">>}, {<<"method">>, <<"post">>}],
|
|
|
|
[?CT(<<"Period: ">>),
|
|
|
|
?XAE(<<"select">>, [{<<"name">>, <<"period">>}],
|
|
|
|
(lists:map(fun ({O, V}) ->
|
|
|
|
Sel = if O == Month ->
|
|
|
|
[{<<"selected">>,
|
|
|
|
<<"selected">>}];
|
|
|
|
true -> []
|
|
|
|
end,
|
|
|
|
?XAC(<<"option">>,
|
|
|
|
(Sel ++
|
|
|
|
[{<<"value">>, O}]),
|
|
|
|
V)
|
|
|
|
end,
|
|
|
|
[{<<"month">>, ?T(<<"Last month">>)},
|
|
|
|
{<<"year">>, ?T(<<"Last year">>)},
|
|
|
|
{<<"all">>,
|
|
|
|
?T(<<"All activity">>)}]))),
|
|
|
|
?C(<<" ">>),
|
|
|
|
?INPUTT(<<"submit">>, <<"ordinary">>,
|
|
|
|
<<"Show Ordinary Table">>),
|
|
|
|
?C(<<" ">>),
|
|
|
|
?INPUTT(<<"submit">>, <<"integral">>,
|
|
|
|
<<"Show Integral Table">>)])]
|
|
|
|
++ Res,
|
|
|
|
Host, Lang, AJID);
|
2005-06-20 05:18:13 +02:00
|
|
|
process_admin(Host,
|
2013-03-14 10:33:02 +01:00
|
|
|
#request{path = [<<"stats">>], auth = {_, _Auth, AJID},
|
2007-12-07 02:40:24 +01:00
|
|
|
lang = Lang}) ->
|
2005-06-20 05:18:13 +02:00
|
|
|
Res = get_stats(Host, Lang),
|
2013-03-14 10:33:02 +01:00
|
|
|
make_xhtml([?XCT(<<"h1">>, <<"Statistics">>)] ++ Res,
|
|
|
|
Host, Lang, AJID);
|
2005-06-20 05:18:13 +02:00
|
|
|
process_admin(Host,
|
2013-03-14 10:33:02 +01:00
|
|
|
#request{path = [<<"user">>, U],
|
|
|
|
auth = {_, _Auth, AJID}, q = Query, lang = Lang}) ->
|
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),
|
|
|
|
make_xhtml(Res, Host, Lang, AJID);
|
|
|
|
false ->
|
|
|
|
make_xhtml([?XCT(<<"h1">>, <<"Not Found">>)], Host,
|
|
|
|
Lang, AJID)
|
2008-10-13 10:32:04 +02:00
|
|
|
end;
|
2005-06-20 05:18:13 +02:00
|
|
|
process_admin(Host,
|
2013-03-14 10:33:02 +01:00
|
|
|
#request{path = [<<"nodes">>], auth = {_, _Auth, AJID},
|
2007-12-07 02:40:24 +01:00
|
|
|
lang = Lang}) ->
|
2004-05-09 20:38:49 +02:00
|
|
|
Res = get_nodes(Lang),
|
2009-06-23 23:00:43 +02:00
|
|
|
make_xhtml(Res, Host, Lang, AJID);
|
2005-06-20 05:18:13 +02:00
|
|
|
process_admin(Host,
|
2013-03-14 10:33:02 +01:00
|
|
|
#request{path = [<<"node">>, SNode | NPath],
|
|
|
|
auth = {_, _Auth, AJID}, q = Query, lang = Lang}) ->
|
2004-05-14 16:46:53 +02:00
|
|
|
case search_running_node(SNode) of
|
2013-03-14 10:33:02 +01:00
|
|
|
false ->
|
|
|
|
make_xhtml([?XCT(<<"h1">>, <<"Node not found">>)], Host,
|
|
|
|
Lang, AJID);
|
|
|
|
Node ->
|
|
|
|
Res = get_node(Host, Node, NPath, Query, Lang),
|
|
|
|
make_xhtml(Res, Host, Node, Lang, AJID)
|
2004-05-14 16:46:53 +02:00
|
|
|
end;
|
2009-06-23 22:45:39 +02:00
|
|
|
%%%==================================
|
|
|
|
%%%% process_admin default case
|
2013-03-14 10:33:02 +01:00
|
|
|
process_admin(Host,
|
|
|
|
#request{lang = Lang, auth = {_, _Auth, AJID}} =
|
|
|
|
Request) ->
|
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,
|
|
|
|
case Res of
|
2013-03-14 10:33:02 +01:00
|
|
|
[] ->
|
|
|
|
setelement(1,
|
|
|
|
make_xhtml([?XC(<<"h1">>, <<"Not Found">>)], Host, Lang,
|
|
|
|
AJID),
|
|
|
|
404);
|
2016-08-09 09:56:32 +02:00
|
|
|
_ -> make_xhtml(Res, Host, Lang, AJID)
|
2007-08-23 02:51:54 +02:00
|
|
|
end.
|
2004-04-26 17:38:07 +02:00
|
|
|
|
2009-06-23 22:45:39 +02:00
|
|
|
%%%==================================
|
|
|
|
%%%% acl
|
2004-04-26 17:38:07 +02:00
|
|
|
|
|
|
|
acls_to_xhtml(ACLs) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
?XAE(<<"table">>, [],
|
|
|
|
[?XE(<<"tbody">>,
|
|
|
|
(lists:map(fun ({acl, Name, Spec} = ACL) ->
|
|
|
|
SName = iolist_to_binary(atom_to_list(Name)),
|
|
|
|
ID = term_to_id(ACL),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
([?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"checkbox">>,
|
|
|
|
<<"selected">>, ID)]),
|
|
|
|
?XC(<<"td">>, SName)]
|
|
|
|
++ acl_spec_to_xhtml(ID, Spec)))
|
|
|
|
end,
|
|
|
|
ACLs)
|
|
|
|
++
|
|
|
|
[?XE(<<"tr">>,
|
|
|
|
([?X(<<"td">>),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>, <<"namenew">>, <<"">>)])]
|
|
|
|
++ acl_spec_to_xhtml(<<"new">>, {user, <<"">>})))]))]).
|
|
|
|
|
2013-10-01 23:23:01 +02:00
|
|
|
acl_spec_to_text({user, {U, S}}) ->
|
|
|
|
{user, <<U/binary, "@", S/binary>>};
|
2013-03-14 10:33:02 +01:00
|
|
|
acl_spec_to_text({user, U}) -> {user, U};
|
|
|
|
acl_spec_to_text({server, S}) -> {server, S};
|
2013-10-01 23:23:01 +02:00
|
|
|
acl_spec_to_text({user_regexp, {RU, S}}) ->
|
|
|
|
{user_regexp, <<RU/binary, "@", S/binary>>};
|
2007-12-06 19:54:18 +01:00
|
|
|
acl_spec_to_text({user_regexp, RU}) ->
|
|
|
|
{user_regexp, RU};
|
|
|
|
acl_spec_to_text({server_regexp, RS}) ->
|
|
|
|
{server_regexp, RS};
|
2013-10-01 23:23:01 +02:00
|
|
|
acl_spec_to_text({node_regexp, {RU, RS}}) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{node_regexp, <<RU/binary, "@", RS/binary>>};
|
2013-10-01 23:23:01 +02:00
|
|
|
acl_spec_to_text({user_glob, {RU, S}}) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{user_glob, <<RU/binary, "@", S/binary>>};
|
2013-10-01 23:23:01 +02:00
|
|
|
acl_spec_to_text({user_glob, RU}) -> {user_glob, RU};
|
2007-12-06 19:54:18 +01:00
|
|
|
acl_spec_to_text({server_glob, RS}) ->
|
|
|
|
{server_glob, RS};
|
2013-10-01 23:23:01 +02:00
|
|
|
acl_spec_to_text({node_glob, {RU, RS}}) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{node_glob, <<RU/binary, "@", RS/binary>>};
|
|
|
|
acl_spec_to_text(all) -> {all, <<"">>};
|
2017-04-11 12:13:58 +02:00
|
|
|
acl_spec_to_text({ip, {IP, L}}) -> {ip, <<(misc:ip_to_list(IP))/binary, "/",
|
2017-03-10 14:39:47 +01:00
|
|
|
(integer_to_binary(L))/binary>>};
|
2013-03-14 10:33:02 +01:00
|
|
|
acl_spec_to_text(Spec) -> {raw, term_to_string(Spec)}.
|
2004-04-26 17:38:07 +02:00
|
|
|
|
|
|
|
acl_spec_to_xhtml(ID, Spec) ->
|
|
|
|
{Type, Str} = acl_spec_to_text(Spec),
|
|
|
|
[acl_spec_select(ID, Type), ?ACLINPUT(Str)].
|
|
|
|
|
|
|
|
acl_spec_select(ID, Opt) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"td">>,
|
|
|
|
[?XAE(<<"select">>,
|
|
|
|
[{<<"name">>, <<"type", ID/binary>>}],
|
|
|
|
(lists:map(fun (O) ->
|
|
|
|
Sel = if O == Opt ->
|
|
|
|
[{<<"selected">>,
|
|
|
|
<<"selected">>}];
|
|
|
|
true -> []
|
|
|
|
end,
|
|
|
|
?XAC(<<"option">>,
|
|
|
|
(Sel ++
|
|
|
|
[{<<"value">>,
|
|
|
|
iolist_to_binary(atom_to_list(O))}]),
|
|
|
|
(iolist_to_binary(atom_to_list(O))))
|
|
|
|
end,
|
|
|
|
[user, server, user_regexp, server_regexp, node_regexp,
|
2017-03-10 14:39:47 +01:00
|
|
|
user_glob, server_glob, node_glob, all, ip, raw])))]).
|
2004-04-26 17:38:07 +02:00
|
|
|
|
2009-01-12 22:48:34 +01:00
|
|
|
%% @spec (T::any()) -> StringLine::string()
|
2004-04-26 17:38:07 +02:00
|
|
|
term_to_string(T) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
StringParagraph =
|
2016-11-24 13:06:06 +01:00
|
|
|
(str:format("~1000000p", [T])),
|
2013-03-14 10:33:02 +01:00
|
|
|
ejabberd_regexp:greplace(StringParagraph, <<"\\n ">>,
|
|
|
|
<<"">>).
|
2004-04-26 17:38:07 +02:00
|
|
|
|
2009-01-21 20:49:26 +01:00
|
|
|
%% @spec (T::any(), Cols::integer()) -> {NumLines::integer(), Paragraph::string()}
|
2009-01-12 22:48:34 +01:00
|
|
|
term_to_paragraph(T, Cols) ->
|
2017-03-10 10:33:16 +01:00
|
|
|
Paragraph = iolist_to_binary(io_lib:print(T, 1, Cols, -1)),
|
2013-03-14 10:33:02 +01:00
|
|
|
FieldList = ejabberd_regexp:split(Paragraph, <<"\n">>),
|
2009-01-21 20:49:26 +01:00
|
|
|
NumLines = length(FieldList),
|
|
|
|
{NumLines, Paragraph}.
|
2009-01-12 22:48:34 +01: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
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
acl_parse_query(Host, Query) ->
|
2016-09-19 11:54:46 +02:00
|
|
|
ACLs = mnesia:dirty_select(acl,
|
2013-03-14 10:33:02 +01:00
|
|
|
[{{acl, {'$1', Host}, '$2'}, [],
|
|
|
|
[{{acl, '$1', '$2'}}]}]),
|
|
|
|
case lists:keysearch(<<"submit">>, 1, Query) of
|
|
|
|
{value, _} -> acl_parse_submit(ACLs, Query);
|
|
|
|
_ ->
|
|
|
|
case lists:keysearch(<<"delete">>, 1, Query) of
|
|
|
|
{value, _} -> acl_parse_delete(ACLs, Query)
|
|
|
|
end
|
2004-04-26 17:38:07 +02:00
|
|
|
end.
|
|
|
|
|
|
|
|
acl_parse_submit(ACLs, Query) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
NewACLs = lists:map(fun ({acl, Name, Spec} = ACL) ->
|
|
|
|
ID = term_to_id(ACL),
|
|
|
|
case {lists:keysearch(<<"type", ID/binary>>, 1,
|
|
|
|
Query),
|
|
|
|
lists:keysearch(<<"value", ID/binary>>, 1,
|
|
|
|
Query)}
|
|
|
|
of
|
|
|
|
{{value, {_, T}}, {value, {_, V}}} ->
|
|
|
|
{Type, Str} = acl_spec_to_text(Spec),
|
|
|
|
case
|
|
|
|
{iolist_to_binary(atom_to_list(Type)),
|
|
|
|
Str}
|
|
|
|
of
|
|
|
|
{T, V} -> ACL;
|
|
|
|
_ ->
|
|
|
|
NewSpec = string_to_spec(T, V),
|
|
|
|
{acl, Name, NewSpec}
|
|
|
|
end;
|
|
|
|
_ -> ACL
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
ACLs),
|
|
|
|
NewACL = case {lists:keysearch(<<"namenew">>, 1, Query),
|
|
|
|
lists:keysearch(<<"typenew">>, 1, Query),
|
|
|
|
lists:keysearch(<<"valuenew">>, 1, Query)}
|
|
|
|
of
|
|
|
|
{{value, {_, <<"">>}}, _, _} -> [];
|
|
|
|
{{value, {_, N}}, {value, {_, T}}, {value, {_, V}}} ->
|
2017-04-11 12:13:58 +02:00
|
|
|
NewName = misc:binary_to_atom(N),
|
2013-03-14 10:33:02 +01:00
|
|
|
NewSpec = string_to_spec(T, V),
|
|
|
|
[{acl, NewName, NewSpec}];
|
|
|
|
_ -> []
|
2004-04-26 17:38:07 +02:00
|
|
|
end,
|
|
|
|
NewACLs ++ NewACL.
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
string_to_spec(<<"user">>, Val) ->
|
2008-02-12 02:16:11 +01:00
|
|
|
string_to_spec2(user, Val);
|
2013-03-14 10:33:02 +01:00
|
|
|
string_to_spec(<<"server">>, Val) -> {server, Val};
|
|
|
|
string_to_spec(<<"user_regexp">>, Val) ->
|
2008-02-12 02:16:11 +01:00
|
|
|
string_to_spec2(user_regexp, Val);
|
2013-03-14 10:33:02 +01:00
|
|
|
string_to_spec(<<"server_regexp">>, Val) ->
|
2007-12-06 19:54:18 +01:00
|
|
|
{server_regexp, Val};
|
2013-03-14 10:33:02 +01:00
|
|
|
string_to_spec(<<"node_regexp">>, Val) ->
|
|
|
|
#jid{luser = U, lserver = S, resource = <<"">>} =
|
2017-02-26 08:07:12 +01:00
|
|
|
jid:decode(Val),
|
2007-12-06 19:54:18 +01:00
|
|
|
{node_regexp, U, S};
|
2013-03-14 10:33:02 +01:00
|
|
|
string_to_spec(<<"user_glob">>, Val) ->
|
2008-02-12 02:16:11 +01:00
|
|
|
string_to_spec2(user_glob, Val);
|
2013-03-14 10:33:02 +01:00
|
|
|
string_to_spec(<<"server_glob">>, Val) ->
|
2007-12-06 19:54:18 +01:00
|
|
|
{server_glob, Val};
|
2013-03-14 10:33:02 +01:00
|
|
|
string_to_spec(<<"node_glob">>, Val) ->
|
|
|
|
#jid{luser = U, lserver = S, resource = <<"">>} =
|
2017-02-26 08:07:12 +01:00
|
|
|
jid:decode(Val),
|
2007-12-06 19:54:18 +01:00
|
|
|
{node_glob, U, S};
|
2017-03-10 14:39:47 +01:00
|
|
|
string_to_spec(<<"ip">>, Val) ->
|
|
|
|
[IPs, Ms] = str:tokens(Val, <<"/">>),
|
|
|
|
{ok, IP} = inet_parse:address(binary_to_list(IPs)),
|
|
|
|
{ip, {IP, binary_to_integer(Ms)}};
|
2013-03-14 10:33:02 +01:00
|
|
|
string_to_spec(<<"all">>, _) -> all;
|
|
|
|
string_to_spec(<<"raw">>, Val) ->
|
|
|
|
{ok, Tokens, _} = erl_scan:string(binary_to_list(<<Val/binary, ".">>)),
|
2004-04-26 17:38:07 +02:00
|
|
|
{ok, NewSpec} = erl_parse:parse_term(Tokens),
|
|
|
|
NewSpec.
|
|
|
|
|
2008-02-12 02:16:11 +01:00
|
|
|
string_to_spec2(ACLName, Val) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
#jid{luser = U, lserver = S, resource = <<"">>} =
|
2017-02-26 08:07:12 +01:00
|
|
|
jid:decode(Val),
|
2008-02-12 02:16:11 +01:00
|
|
|
case U of
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"">> -> {ACLName, S};
|
2014-03-24 19:40:55 +01:00
|
|
|
_ -> {ACLName, {U, S}}
|
2008-02-12 02:16:11 +01:00
|
|
|
end.
|
|
|
|
|
2004-04-26 17:38:07 +02:00
|
|
|
acl_parse_delete(ACLs, Query) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
NewACLs = lists:filter(fun ({acl, _Name, _Spec} =
|
|
|
|
ACL) ->
|
|
|
|
ID = term_to_id(ACL),
|
|
|
|
not lists:member({<<"selected">>, ID}, Query)
|
|
|
|
end,
|
|
|
|
ACLs),
|
2004-04-26 17:38:07 +02:00
|
|
|
NewACLs.
|
|
|
|
|
2004-05-01 22:10:25 +02:00
|
|
|
access_rules_to_xhtml(AccessRules, Lang) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
?XAE(<<"table">>, [],
|
|
|
|
[?XE(<<"tbody">>,
|
|
|
|
(lists:map(fun ({access, Name, Rules} = Access) ->
|
|
|
|
SName = iolist_to_binary(atom_to_list(Name)),
|
|
|
|
ID = term_to_id(Access),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"checkbox">>,
|
|
|
|
<<"selected">>, ID)]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?AC(<<SName/binary, "/">>, SName)]),
|
|
|
|
?XC(<<"td">>, (term_to_string(Rules)))])
|
|
|
|
end,
|
|
|
|
lists:keysort(2,AccessRules))
|
|
|
|
++
|
|
|
|
[?XE(<<"tr">>,
|
|
|
|
[?X(<<"td">>),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>, <<"namenew">>, <<"">>)]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>, <<"addnew">>,
|
|
|
|
<<"Add New">>)])])]))]).
|
2004-04-26 17:38:07 +02:00
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
access_parse_query(Host, Query) ->
|
2016-09-19 11:54:46 +02:00
|
|
|
AccessRules = mnesia:dirty_select(access,
|
2015-03-05 11:34:25 +01:00
|
|
|
[{{access, {'$1', Host}, '$2'}, [],
|
2013-03-14 10:33:02 +01:00
|
|
|
[{{access, '$1', '$2'}}]}]),
|
|
|
|
case lists:keysearch(<<"addnew">>, 1, Query) of
|
|
|
|
{value, _} ->
|
|
|
|
access_parse_addnew(AccessRules, Host, Query);
|
|
|
|
_ ->
|
|
|
|
case lists:keysearch(<<"delete">>, 1, Query) of
|
|
|
|
{value, _} ->
|
|
|
|
access_parse_delete(AccessRules, Host, Query)
|
|
|
|
end
|
2004-04-26 17:38:07 +02:00
|
|
|
end.
|
|
|
|
|
2007-12-07 02:40:24 +01:00
|
|
|
access_parse_addnew(_AccessRules, Host, Query) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
case lists:keysearch(<<"namenew">>, 1, Query) of
|
|
|
|
{value, {_, String}} when String /= <<"">> ->
|
2017-04-11 12:13:58 +02:00
|
|
|
Name = misc:binary_to_atom(String),
|
2013-08-12 14:25:05 +02:00
|
|
|
ejabberd_config:add_option({access, Name, Host},
|
2013-03-14 10:33:02 +01:00
|
|
|
[]),
|
|
|
|
ok
|
2004-04-26 17:38:07 +02:00
|
|
|
end.
|
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
access_parse_delete(AccessRules, Host, Query) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:foreach(fun ({access, Name, _Rules} =
|
|
|
|
AccessRule) ->
|
|
|
|
ID = term_to_id(AccessRule),
|
|
|
|
case lists:member({<<"selected">>, ID}, Query) of
|
|
|
|
true ->
|
|
|
|
mnesia:transaction(fun () ->
|
2015-03-05 11:34:25 +01:00
|
|
|
mnesia:delete({access,
|
|
|
|
{Name,
|
2013-03-14 10:33:02 +01:00
|
|
|
Host}})
|
|
|
|
end);
|
|
|
|
_ -> ok
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
AccessRules),
|
2004-04-26 17:38:07 +02:00
|
|
|
ok.
|
|
|
|
|
|
|
|
access_rule_to_xhtml(Rules) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
Text = lists:flatmap(fun ({Access, ACL} = _Rule) ->
|
|
|
|
SAccess = element_to_list(Access),
|
|
|
|
SACL = atom_to_list(ACL),
|
|
|
|
[SAccess, " \t", SACL, "\n"]
|
|
|
|
end,
|
|
|
|
Rules),
|
|
|
|
?XAC(<<"textarea">>,
|
|
|
|
[{<<"name">>, <<"rules">>}, {<<"rows">>, <<"16">>},
|
|
|
|
{<<"cols">>, <<"80">>}],
|
|
|
|
list_to_binary(Text)).
|
2004-04-26 17:38:07 +02:00
|
|
|
|
|
|
|
parse_access_rule(Text) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
Strings = str:tokens(Text, <<"\r\n">>),
|
|
|
|
case catch lists:flatmap(fun (String) ->
|
|
|
|
case str:tokens(String, <<" \t">>) of
|
|
|
|
[Access, ACL] ->
|
|
|
|
[{list_to_element(Access),
|
2017-04-11 12:13:58 +02:00
|
|
|
misc:binary_to_atom(ACL)}];
|
2013-03-14 10:33:02 +01:00
|
|
|
[] -> []
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
Strings)
|
|
|
|
of
|
|
|
|
{'EXIT', _Reason} -> error;
|
|
|
|
Rs -> {ok, Rs}
|
2004-04-26 17:38:07 +02:00
|
|
|
end.
|
|
|
|
|
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) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
Hosts = (?MYHOSTS),
|
|
|
|
HostsAllowed = lists:filter(fun (Host) ->
|
2016-07-23 16:21:00 +02:00
|
|
|
acl:any_rules_allowed(Host,
|
2013-03-14 10:33:02 +01:00
|
|
|
[configure, webadmin_view],
|
|
|
|
JID)
|
|
|
|
end,
|
|
|
|
Hosts),
|
2009-06-23 23:00:43 +02:00
|
|
|
list_vhosts2(Lang, HostsAllowed).
|
|
|
|
|
|
|
|
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">>,
|
|
|
|
[?XCT(<<"td">>, <<"Host">>),
|
|
|
|
?XCT(<<"td">>, <<"Registered Users">>),
|
|
|
|
?XCT(<<"td">>, <<"Online Users">>)])]),
|
|
|
|
?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)]),
|
|
|
|
?XC(<<"td">>,
|
|
|
|
(pretty_string_int(RegisteredUsers))),
|
|
|
|
?XC(<<"td">>,
|
|
|
|
(pretty_string_int(OnlineUsers)))])
|
|
|
|
end,
|
|
|
|
SHosts)))])].
|
2004-04-26 17:38:07 +02:00
|
|
|
|
2009-06-23 22:45:39 +02:00
|
|
|
%%%==================================
|
|
|
|
%%%% list_users
|
2004-04-26 17:38:07 +02:00
|
|
|
|
2005-09-29 03:04:24 +02: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 ->
|
|
|
|
[list_given_users(Host, SUsers, <<"../">>, Lang,
|
|
|
|
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:
|
2013-03-14 10:33:02 +01:00
|
|
|
ok -> [?XREST(<<"Submitted">>)];
|
|
|
|
error -> [?XREST(<<"Bad format">>)];
|
|
|
|
nothing -> []
|
|
|
|
end
|
|
|
|
++
|
|
|
|
[?XAE(<<"form">>,
|
|
|
|
[{<<"action">>, <<"">>}, {<<"method">>, <<"post">>}],
|
|
|
|
([?XE(<<"table">>,
|
|
|
|
[?XE(<<"tr">>,
|
|
|
|
[?XC(<<"td">>, <<(?T(<<"User">>))/binary, ":">>),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>, <<"newusername">>, <<"">>)]),
|
|
|
|
?XE(<<"td">>, [?C(<<" @ ", Host/binary>>)])]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XC(<<"td">>, <<(?T(<<"Password">>))/binary, ":">>),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"password">>, <<"newuserpassword">>,
|
|
|
|
<<"">>)]),
|
|
|
|
?X(<<"td">>)]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?X(<<"td">>),
|
|
|
|
?XAE(<<"td">>, [{<<"class">>, <<"alignright">>}],
|
|
|
|
[?INPUTT(<<"submit">>, <<"addnewuser">>,
|
|
|
|
<<"Add User">>)]),
|
|
|
|
?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.
|
|
|
|
|
2005-09-29 03:04:24 +02: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),
|
2013-03-14 10:33:02 +01:00
|
|
|
[list_given_users(Host, Sub, <<"../../">>, Lang,
|
|
|
|
URLFunc)].
|
2004-10-05 21:31:17 +02:00
|
|
|
|
2009-12-09 18:46:51 +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">>,
|
|
|
|
[?XCT(<<"td">>, <<"User">>),
|
|
|
|
?XCT(<<"td">>, <<"Offline Messages">>),
|
|
|
|
?XCT(<<"td">>, <<"Last Activity">>)])]),
|
|
|
|
?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
|
|
|
|
[] ->
|
|
|
|
case mod_last:get_last_info(User,
|
|
|
|
Server)
|
|
|
|
of
|
|
|
|
not_found -> ?T(<<"Never">>);
|
|
|
|
{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;
|
|
|
|
_ -> ?T(<<"Online">>)
|
|
|
|
end,
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XE(<<"td">>,
|
|
|
|
[?AC((URLFunc({user, Prefix,
|
|
|
|
ejabberd_http:url_encode(User),
|
|
|
|
Server})),
|
|
|
|
(us_to_list(US)))]),
|
|
|
|
?XE(<<"td">>, FQueueLen),
|
|
|
|
?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) ->
|
2012-04-27 11:52:05 +02:00
|
|
|
case gen_mod:db_type(Server, mod_last) of
|
2013-03-14 10:33:02 +01:00
|
|
|
mnesia -> [{<<"last-activity">>, <<"Last Activity">>}];
|
|
|
|
_ -> []
|
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,
|
|
|
|
0, ?MYHOSTS),
|
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">>,
|
|
|
|
[?XCT(<<"td">>, <<"Registered Users:">>),
|
|
|
|
?XC(<<"td">>, (pretty_string_int(RegisteredUsers)))]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>, <<"Online Users:">>),
|
|
|
|
?XC(<<"td">>, (pretty_string_int(OnlineUsers)))]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>, <<"Outgoing s2s Connections:">>),
|
2015-10-21 12:51:22 +02:00
|
|
|
?XC(<<"td">>, (pretty_string_int(OutS2SNumber)))]),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"tr">>,
|
2015-10-21 12:51:22 +02:00
|
|
|
[?XCT(<<"td">>, <<"Incoming s2s Connections:">>),
|
|
|
|
?XC(<<"td">>, (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">>,
|
|
|
|
[?XCT(<<"td">>, <<"Registered Users:">>),
|
|
|
|
?XC(<<"td">>, (pretty_string_int(RegisteredUsers)))]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>, <<"Online Users:">>),
|
|
|
|
?XC(<<"td">>, (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/",
|
|
|
|
(ejabberd_http:url_encode(U))/binary, "/">>,
|
|
|
|
(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
|
|
|
|
[] -> [?CT(<<"None">>)];
|
|
|
|
_ ->
|
|
|
|
[?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">>,
|
|
|
|
<<"Change Password">>)],
|
|
|
|
UserItems = ejabberd_hooks:run_fold(webadmin_user,
|
|
|
|
LServer, [], [User, Server, Lang]),
|
|
|
|
LastActivity = case ejabberd_sm:get_user_resources(User,
|
|
|
|
Server)
|
|
|
|
of
|
|
|
|
[] ->
|
|
|
|
case mod_last:get_last_info(User, Server) of
|
|
|
|
not_found -> ?T(<<"Never">>);
|
|
|
|
{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;
|
|
|
|
_ -> ?T(<<"Online">>)
|
2010-01-03 01:40:37 +01:00
|
|
|
end,
|
2016-11-24 13:06:06 +01:00
|
|
|
[?XC(<<"h1">>, (str:format(?T(<<"User ~s">>),
|
2013-03-14 10:33:02 +01:00
|
|
|
[us_to_list(US)])))]
|
|
|
|
++
|
|
|
|
case Res of
|
|
|
|
ok -> [?XREST(<<"Submitted">>)];
|
|
|
|
error -> [?XREST(<<"Bad format">>)];
|
|
|
|
nothing -> []
|
|
|
|
end
|
|
|
|
++
|
|
|
|
[?XAE(<<"form">>,
|
|
|
|
[{<<"action">>, <<"">>}, {<<"method">>, <<"post">>}],
|
|
|
|
([?XCT(<<"h3">>, <<"Connected Resources:">>)] ++
|
|
|
|
FResources ++
|
|
|
|
[?XCT(<<"h3">>, <<"Password:">>)] ++
|
|
|
|
FPassword ++
|
|
|
|
[?XCT(<<"h3">>, <<"Last Activity">>)] ++
|
|
|
|
[?C(LastActivity)] ++
|
|
|
|
UserItems ++
|
|
|
|
[?P,
|
|
|
|
?INPUTT(<<"submit">>, <<"removeuser">>,
|
|
|
|
<<"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) ->
|
2015-12-07 16:08:57 +01:00
|
|
|
TimeStamp = p1_time_compat:system_time(seconds),
|
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),
|
|
|
|
if Hist == [] -> [?CT(<<"No Data">>)];
|
|
|
|
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,
|
|
|
|
FRN = if RunningNodes == [] -> ?CT(<<"None">>);
|
|
|
|
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,
|
2013-03-14 10:33:02 +01:00
|
|
|
FSN = if StoppedNodes == [] -> ?CT(<<"None">>);
|
|
|
|
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,
|
2013-03-14 10:33:02 +01:00
|
|
|
[?XCT(<<"h1">>, <<"Nodes">>),
|
|
|
|
?XCT(<<"h3">>, <<"Running Nodes">>), FRN,
|
|
|
|
?XCT(<<"h3">>, <<"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
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
get_node(global, Node, [], Query, Lang) ->
|
2004-05-22 21:48:35 +02:00
|
|
|
Res = node_parse_query(Node, Query),
|
2008-10-12 15:58:05 +02:00
|
|
|
Base = get_base_path(global, Node),
|
|
|
|
MenuItems2 = make_menu_items(global, Node, Base, Lang),
|
2013-03-14 10:33:02 +01:00
|
|
|
[?XC(<<"h1">>,
|
2016-11-24 13:06:06 +01:00
|
|
|
(str:format(?T(<<"Node ~p">>), [Node])))]
|
2013-03-14 10:33:02 +01:00
|
|
|
++
|
|
|
|
case Res of
|
|
|
|
ok -> [?XREST(<<"Submitted">>)];
|
|
|
|
error -> [?XREST(<<"Bad format">>)];
|
|
|
|
nothing -> []
|
|
|
|
end
|
|
|
|
++
|
|
|
|
[?XE(<<"ul">>,
|
|
|
|
([?LI([?ACT(<<Base/binary, "db/">>, <<"Database">>)]),
|
|
|
|
?LI([?ACT(<<Base/binary, "backup/">>, <<"Backup">>)]),
|
|
|
|
?LI([?ACT(<<Base/binary, "ports/">>,
|
|
|
|
<<"Listened Ports">>)]),
|
|
|
|
?LI([?ACT(<<Base/binary, "stats/">>,
|
|
|
|
<<"Statistics">>)]),
|
|
|
|
?LI([?ACT(<<Base/binary, "update/">>, <<"Update">>)])]
|
|
|
|
++ MenuItems2)),
|
|
|
|
?XAE(<<"form">>,
|
|
|
|
[{<<"action">>, <<"">>}, {<<"method">>, <<"post">>}],
|
|
|
|
[?INPUTT(<<"submit">>, <<"restart">>, <<"Restart">>),
|
|
|
|
?C(<<" ">>),
|
|
|
|
?INPUTT(<<"submit">>, <<"stop">>, <<"Stop">>)])];
|
2007-12-07 02:40:24 +01:00
|
|
|
get_node(Host, Node, [], _Query, Lang) ->
|
2008-10-12 15:58:05 +02:00
|
|
|
Base = get_base_path(Host, Node),
|
2009-02-02 11:12:44 +01:00
|
|
|
MenuItems2 = make_menu_items(Host, Node, Base, Lang),
|
2016-11-24 13:06:06 +01:00
|
|
|
[?XC(<<"h1">>, (str:format(?T(<<"Node ~p">>), [Node]))),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"ul">>,
|
|
|
|
([?LI([?ACT(<<Base/binary, "modules/">>,
|
|
|
|
<<"Modules">>)])]
|
|
|
|
++ MenuItems2))];
|
|
|
|
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} ->
|
|
|
|
[?XCT(<<"h1">>, <<"RPC Call Error">>)];
|
|
|
|
Tables ->
|
|
|
|
ResS = case node_db_parse_query(Node, Tables, Query) of
|
|
|
|
nothing -> [];
|
|
|
|
ok -> [?XREST(<<"Submitted">>)]
|
|
|
|
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,
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XC(<<"td">>, STable),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[db_storage_select(STable, Type,
|
|
|
|
Lang)]),
|
|
|
|
?XAC(<<"td">>,
|
|
|
|
[{<<"class">>, <<"alignright">>}],
|
|
|
|
(pretty_string_int(Size))),
|
|
|
|
?XAC(<<"td">>,
|
|
|
|
[{<<"class">>, <<"alignright">>}],
|
|
|
|
(pretty_string_int(Memory)))])
|
|
|
|
end,
|
|
|
|
STables),
|
|
|
|
[?XC(<<"h1">>,
|
2016-11-24 13:06:06 +01:00
|
|
|
(str:format(?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">>,
|
|
|
|
[?XCT(<<"td">>, <<"Name">>),
|
|
|
|
?XCT(<<"td">>, <<"Storage Type">>),
|
|
|
|
?XCT(<<"td">>, <<"Elements">>),
|
|
|
|
?XCT(<<"td">>, <<"Memory">>)])]),
|
|
|
|
?XE(<<"tbody">>,
|
|
|
|
(Rows ++
|
|
|
|
[?XE(<<"tr">>,
|
|
|
|
[?XAE(<<"td">>,
|
|
|
|
[{<<"colspan">>, <<"4">>},
|
|
|
|
{<<"class">>, <<"alignright">>}],
|
|
|
|
[?INPUTT(<<"submit">>,
|
|
|
|
<<"submit">>,
|
|
|
|
<<"Submit">>)])])]))])])]
|
2004-05-14 16:46:53 +02:00
|
|
|
end;
|
2013-03-14 10:33:02 +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 -> [];
|
|
|
|
ok -> [?XREST(<<"Submitted">>)];
|
|
|
|
{error, Error} ->
|
|
|
|
[?XRES(<<(?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,
|
2016-11-24 13:06:06 +01:00
|
|
|
[?XC(<<"h1">>, (str:format(?T(<<"Backup of ~p">>), [Node])))]
|
2013-03-14 10:33:02 +01:00
|
|
|
++
|
|
|
|
ResS ++
|
|
|
|
[?XCT(<<"p">>,
|
|
|
|
<<"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.">>),
|
|
|
|
?XAE(<<"form">>,
|
|
|
|
[{<<"action">>, <<"">>}, {<<"method">>, <<"post">>}],
|
|
|
|
[?XAE(<<"table">>, [],
|
|
|
|
[?XE(<<"tbody">>,
|
|
|
|
[?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>, <<"Store binary backup:">>),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>, <<"storepath">>,
|
|
|
|
(filename:join(HomeDir,
|
|
|
|
"ejabberd.backup")))]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>, <<"store">>,
|
|
|
|
<<"OK">>)])]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>,
|
|
|
|
<<"Restore binary backup immediately:">>),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>, <<"restorepath">>,
|
|
|
|
(filename:join(HomeDir,
|
|
|
|
"ejabberd.backup")))]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>, <<"restore">>,
|
|
|
|
<<"OK">>)])]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>,
|
|
|
|
<<"Restore binary backup after next ejabberd "
|
|
|
|
"restart (requires less memory):">>),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>, <<"fallbackpath">>,
|
|
|
|
(filename:join(HomeDir,
|
|
|
|
"ejabberd.backup")))]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>, <<"fallback">>,
|
|
|
|
<<"OK">>)])]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>, <<"Store plain text backup:">>),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>, <<"dumppath">>,
|
|
|
|
(filename:join(HomeDir,
|
|
|
|
"ejabberd.dump")))]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>, <<"dump">>,
|
|
|
|
<<"OK">>)])]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>,
|
|
|
|
<<"Restore plain text backup immediately:">>),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>, <<"loadpath">>,
|
|
|
|
(filename:join(HomeDir,
|
|
|
|
"ejabberd.dump")))]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>, <<"load">>,
|
|
|
|
<<"OK">>)])]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>,
|
|
|
|
<<"Import users data from a PIEFXIS file "
|
|
|
|
"(XEP-0227):">>),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>,
|
|
|
|
<<"import_piefxis_filepath">>,
|
|
|
|
(filename:join(HomeDir,
|
|
|
|
"users.xml")))]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>,
|
|
|
|
<<"import_piefxis_file">>,
|
|
|
|
<<"OK">>)])]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>,
|
|
|
|
<<"Export data of all users in the server "
|
|
|
|
"to PIEFXIS files (XEP-0227):">>),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>,
|
|
|
|
<<"export_piefxis_dirpath">>,
|
|
|
|
HomeDir)]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>,
|
|
|
|
<<"export_piefxis_dir">>,
|
|
|
|
<<"OK">>)])]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XE(<<"td">>,
|
|
|
|
[?CT(<<"Export data of users in a host to PIEFXIS "
|
|
|
|
"files (XEP-0227):">>),
|
|
|
|
?C(<<" ">>),
|
|
|
|
?INPUT(<<"text">>,
|
|
|
|
<<"export_piefxis_host_dirhost">>,
|
|
|
|
(?MYNAME))]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>,
|
|
|
|
<<"export_piefxis_host_dirpath">>,
|
|
|
|
HomeDir)]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>,
|
|
|
|
<<"export_piefxis_host_dir">>,
|
|
|
|
<<"OK">>)])]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XE(<<"td">>,
|
|
|
|
[?CT(<<"Export all tables as SQL queries "
|
|
|
|
"to a file:">>),
|
|
|
|
?C(<<" ">>),
|
|
|
|
?INPUT(<<"text">>,
|
|
|
|
<<"export_sql_filehost">>,
|
|
|
|
(?MYNAME))]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>,
|
|
|
|
<<"export_sql_filepath">>,
|
|
|
|
(filename:join(HomeDir,
|
|
|
|
"db.sql")))]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>, <<"export_sql_file">>,
|
|
|
|
<<"OK">>)])]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>,
|
|
|
|
<<"Import user data from jabberd14 spool "
|
|
|
|
"file:">>),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>, <<"import_filepath">>,
|
|
|
|
(filename:join(HomeDir,
|
|
|
|
"user1.xml")))]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>, <<"import_file">>,
|
|
|
|
<<"OK">>)])]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>,
|
|
|
|
<<"Import users data from jabberd14 spool "
|
|
|
|
"directory:">>),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>, <<"import_dirpath">>,
|
|
|
|
<<"/var/spool/jabber/">>)]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>, <<"import_dir">>,
|
|
|
|
<<"OK">>)])])])])])];
|
|
|
|
get_node(global, Node, [<<"ports">>], Query, Lang) ->
|
2015-10-07 00:06:58 +02:00
|
|
|
Ports = ejabberd_cluster:call(Node, ejabberd_config,
|
2013-03-14 10:33:02 +01:00
|
|
|
get_local_option, [listen,
|
|
|
|
{ejabberd_listener, validate_cfg},
|
|
|
|
[]]),
|
|
|
|
Res = case catch node_ports_parse_query(Node, Ports,
|
|
|
|
Query)
|
|
|
|
of
|
|
|
|
submitted -> ok;
|
|
|
|
{'EXIT', _Reason} -> error;
|
|
|
|
{is_added, ok} -> ok;
|
|
|
|
{is_added, {error, Reason}} ->
|
2016-11-24 13:06:06 +01:00
|
|
|
{error, (str:format("~p", [Reason]))};
|
2013-03-14 10:33:02 +01:00
|
|
|
_ -> nothing
|
2004-06-17 23:29:24 +02:00
|
|
|
end,
|
2015-10-07 00:06:58 +02:00
|
|
|
NewPorts = lists:sort(ejabberd_cluster:call(Node, ejabberd_config,
|
2013-03-14 10:33:02 +01:00
|
|
|
get_local_option,
|
|
|
|
[listen,
|
|
|
|
{ejabberd_listener, validate_cfg},
|
|
|
|
[]])),
|
|
|
|
H1String = <<(?T(<<"Listened Ports at ">>))/binary,
|
|
|
|
(iolist_to_binary(atom_to_list(Node)))/binary>>,
|
2016-02-08 16:16:53 +01:00
|
|
|
(?H1GL(H1String, <<"listeningports">>, <<"Listening Ports">>))
|
2013-03-14 10:33:02 +01:00
|
|
|
++
|
|
|
|
case Res of
|
|
|
|
ok -> [?XREST(<<"Submitted">>)];
|
|
|
|
error -> [?XREST(<<"Bad format">>)];
|
|
|
|
{error, ReasonT} ->
|
|
|
|
[?XRES(<<(?T(<<"Error">>))/binary, ": ",
|
|
|
|
ReasonT/binary>>)];
|
|
|
|
nothing -> []
|
|
|
|
end
|
|
|
|
++
|
|
|
|
[?XAE(<<"form">>,
|
|
|
|
[{<<"action">>, <<"">>}, {<<"method">>, <<"post">>}],
|
|
|
|
[node_ports_to_xhtml(NewPorts, Lang)])];
|
|
|
|
get_node(Host, Node, [<<"modules">>], Query, Lang)
|
|
|
|
when is_binary(Host) ->
|
2015-10-07 00:06:58 +02:00
|
|
|
Modules = ejabberd_cluster:call(Node, gen_mod,
|
2013-03-14 10:33:02 +01:00
|
|
|
loaded_modules_with_opts, [Host]),
|
|
|
|
Res = case catch node_modules_parse_query(Host, Node,
|
|
|
|
Modules, Query)
|
|
|
|
of
|
|
|
|
submitted -> ok;
|
|
|
|
{'EXIT', Reason} -> ?INFO_MSG("~p~n", [Reason]), error;
|
|
|
|
_ -> nothing
|
2005-05-23 02:30:29 +02:00
|
|
|
end,
|
2015-10-07 00:06:58 +02:00
|
|
|
NewModules = lists:sort(ejabberd_cluster:call(Node, gen_mod,
|
2013-03-14 10:33:02 +01:00
|
|
|
loaded_modules_with_opts, [Host])),
|
2016-11-24 13:06:06 +01:00
|
|
|
H1String = (str:format(?T(<<"Modules at ~p">>), [Node])),
|
2016-02-08 16:16:53 +01:00
|
|
|
(?H1GL(H1String, <<"modulesoverview">>,
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"Modules Overview">>))
|
|
|
|
++
|
|
|
|
case Res of
|
|
|
|
ok -> [?XREST(<<"Submitted">>)];
|
|
|
|
error -> [?XREST(<<"Bad format">>)];
|
|
|
|
nothing -> []
|
|
|
|
end
|
|
|
|
++
|
|
|
|
[?XAE(<<"form">>,
|
|
|
|
[{<<"action">>, <<"">>}, {<<"method">>, <<"post">>}],
|
|
|
|
[node_modules_to_xhtml(NewModules, Lang)])];
|
|
|
|
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])),
|
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">>,
|
2016-11-24 13:06:06 +01:00
|
|
|
(str:format(?T(<<"Statistics of ~p">>), [Node]))),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XAE(<<"table">>, [],
|
|
|
|
[?XE(<<"tbody">>,
|
|
|
|
[?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>, <<"Uptime:">>),
|
|
|
|
?XAC(<<"td">>, [{<<"class">>, <<"alignright">>}],
|
|
|
|
UpTimeS)]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>, <<"CPU Time:">>),
|
|
|
|
?XAC(<<"td">>, [{<<"class">>, <<"alignright">>}],
|
|
|
|
CPUTimeS)]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>, <<"Online Users:">>),
|
|
|
|
?XAC(<<"td">>, [{<<"class">>, <<"alignright">>}],
|
|
|
|
(pretty_string_int(OnlineUsers)))]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>, <<"Transactions Committed:">>),
|
|
|
|
?XAC(<<"td">>, [{<<"class">>, <<"alignright">>}],
|
|
|
|
(pretty_string_int(TransactionsCommitted)))]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>, <<"Transactions Aborted:">>),
|
|
|
|
?XAC(<<"td">>, [{<<"class">>, <<"alignright">>}],
|
|
|
|
(pretty_string_int(TransactionsAborted)))]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>, <<"Transactions Restarted:">>),
|
|
|
|
?XAC(<<"td">>, [{<<"class">>, <<"alignright">>}],
|
|
|
|
(pretty_string_int(TransactionsRestarted)))]),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>, <<"Transactions Logged:">>),
|
|
|
|
?XAC(<<"td">>, [{<<"class">>, <<"alignright">>}],
|
|
|
|
(pretty_string_int(TransactionsLogged)))])])])];
|
|
|
|
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
|
|
|
|
[] -> ?CT(<<"None">>);
|
|
|
|
_ ->
|
|
|
|
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">>,
|
|
|
|
<<"Select All">>,
|
|
|
|
[{<<"onClick">>,
|
|
|
|
<<"selectAll()">>}]),
|
|
|
|
?C(<<" ">>),
|
|
|
|
?INPUTATTRS(<<"button">>, <<"unselectall">>,
|
|
|
|
<<"Unselect All">>,
|
|
|
|
[{<<"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">>,
|
2016-11-24 13:06:06 +01:00
|
|
|
(str:format(?T(<<"Update ~p">>), [Node])))]
|
2013-03-14 10:33:02 +01:00
|
|
|
++
|
|
|
|
case Res of
|
|
|
|
ok -> [?XREST(<<"Submitted">>)];
|
|
|
|
{error, ErrorText} ->
|
|
|
|
[?XREST(<<"Error: ", ErrorText/binary>>)];
|
|
|
|
nothing -> []
|
|
|
|
end
|
|
|
|
++
|
|
|
|
[?XAE(<<"form">>,
|
|
|
|
[{<<"action">>, <<"">>}, {<<"method">>, <<"post">>}],
|
|
|
|
[?XCT(<<"h2">>, <<"Update plan">>),
|
|
|
|
?XCT(<<"h3">>, <<"Modified modules">>), Mods,
|
|
|
|
?XCT(<<"h3">>, <<"Update script">>), FmtScript,
|
|
|
|
?XCT(<<"h3">>, <<"Low level update script">>),
|
|
|
|
FmtLowLevelScript, ?XCT(<<"h3">>, <<"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,
|
2013-03-14 10:33:02 +01:00
|
|
|
?INPUTT(<<"submit">>, <<"update">>, <<"Update">>)])];
|
2005-06-20 05:18:13 +02: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.
|
|
|
|
|
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.
|
|
|
|
|
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,
|
|
|
|
[{ram_copies, <<"RAM copy">>},
|
|
|
|
{disc_copies, <<"RAM and disc copy">>},
|
|
|
|
{disc_only_copies, <<"Disc only copy">>},
|
|
|
|
{unknown, <<"Remote copy">>},
|
|
|
|
{delete_content, <<"Delete content">>},
|
|
|
|
{delete_table, <<"Delete table">>}]))).
|
|
|
|
|
|
|
|
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
|
|
|
|
2004-06-17 23:29:24 +02:00
|
|
|
node_ports_to_xhtml(Ports, Lang) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
?XAE(<<"table">>, [{<<"class">>, <<"withtextareas">>}],
|
|
|
|
[?XE(<<"thead">>,
|
|
|
|
[?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>, <<"Port">>), ?XCT(<<"td">>, <<"IP">>),
|
|
|
|
?XCT(<<"td">>, <<"Protocol">>),
|
|
|
|
?XCT(<<"td">>, <<"Module">>),
|
|
|
|
?XCT(<<"td">>, <<"Options">>)])]),
|
|
|
|
?XE(<<"tbody">>,
|
|
|
|
(lists:map(fun ({PortIP, Module, Opts} = _E) ->
|
|
|
|
{_Port, SPort, _TIP, SIP, SSPort, NetProt,
|
|
|
|
OptsClean} =
|
|
|
|
get_port_data(PortIP, Opts),
|
|
|
|
SModule =
|
|
|
|
iolist_to_binary(atom_to_list(Module)),
|
|
|
|
{NumLines, SOptsClean} =
|
|
|
|
term_to_paragraph(OptsClean, 40),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XAE(<<"td">>, [{<<"size">>, <<"6">>}],
|
|
|
|
[?C(SPort)]),
|
|
|
|
?XAE(<<"td">>, [{<<"size">>, <<"15">>}],
|
|
|
|
[?C(SIP)]),
|
|
|
|
?XAE(<<"td">>, [{<<"size">>, <<"4">>}],
|
|
|
|
[?C((iolist_to_binary(atom_to_list(NetProt))))]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTS(<<"text">>,
|
|
|
|
<<"module", SSPort/binary>>,
|
|
|
|
SModule, <<"15">>)]),
|
2015-07-15 19:01:32 +02:00
|
|
|
?XAE(<<"td">>, direction(ltr),
|
2013-03-14 10:33:02 +01:00
|
|
|
[?TEXTAREA(<<"opts", SSPort/binary>>,
|
2016-11-24 13:06:06 +01:00
|
|
|
(integer_to_binary(NumLines)),
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"35">>, SOptsClean)]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>,
|
|
|
|
<<"add", SSPort/binary>>,
|
2015-07-27 11:23:51 +02:00
|
|
|
<<"Restart">>)]),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>,
|
|
|
|
<<"delete", SSPort/binary>>,
|
2015-07-27 11:23:51 +02:00
|
|
|
<<"Stop">>)])])
|
2013-03-14 10:33:02 +01:00
|
|
|
end,
|
|
|
|
Ports)
|
|
|
|
++
|
|
|
|
[?XE(<<"tr">>,
|
|
|
|
[?XE(<<"td">>,
|
|
|
|
[?INPUTS(<<"text">>, <<"portnew">>, <<"">>,
|
|
|
|
<<"6">>)]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTS(<<"text">>, <<"ipnew">>, <<"0.0.0.0">>,
|
|
|
|
<<"15">>)]),
|
|
|
|
?XE(<<"td">>, [make_netprot_html(<<"tcp">>)]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTS(<<"text">>, <<"modulenew">>, <<"">>,
|
|
|
|
<<"15">>)]),
|
2015-07-15 19:01:32 +02:00
|
|
|
?XAE(<<"td">>, direction(ltr),
|
2013-03-14 10:33:02 +01:00
|
|
|
[?TEXTAREA(<<"optsnew">>, <<"2">>, <<"35">>,
|
|
|
|
<<"[]">>)]),
|
|
|
|
?XAE(<<"td">>, [{<<"colspan">>, <<"2">>}],
|
|
|
|
[?INPUTT(<<"submit">>, <<"addnew">>,
|
2015-07-27 11:23:51 +02:00
|
|
|
<<"Start">>)])])]))]).
|
2004-06-17 23:29:24 +02:00
|
|
|
|
2009-08-11 20:22:58 +02:00
|
|
|
make_netprot_html(NetProt) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
?XAE(<<"select">>, [{<<"name">>, <<"netprotnew">>}],
|
|
|
|
(lists:map(fun (O) ->
|
|
|
|
Sel = if O == NetProt ->
|
|
|
|
[{<<"selected">>, <<"selected">>}];
|
|
|
|
true -> []
|
|
|
|
end,
|
|
|
|
?XAC(<<"option">>, (Sel ++ [{<<"value">>, O}]), O)
|
|
|
|
end,
|
|
|
|
[<<"tcp">>, <<"udp">>]))).
|
2009-08-11 20:22:58 +02:00
|
|
|
|
2009-01-12 21:03:02 +01:00
|
|
|
get_port_data(PortIP, Opts) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{Port, IPT, IPS, _IPV, NetProt, OptsClean} =
|
|
|
|
ejabberd_listener:parse_listener_portip(PortIP, Opts),
|
2016-09-24 22:34:28 +02:00
|
|
|
SPort = integer_to_binary(Port),
|
2013-03-14 10:33:02 +01:00
|
|
|
SSPort = list_to_binary(
|
|
|
|
lists:map(fun (N) ->
|
|
|
|
io_lib:format("~.16b", [N])
|
|
|
|
end,
|
|
|
|
binary_to_list(
|
2013-11-05 11:05:12 +01:00
|
|
|
erlang:md5(
|
2013-03-14 10:33:02 +01:00
|
|
|
[SPort, IPS, atom_to_list(NetProt)])))),
|
2009-08-11 20:22:58 +02:00
|
|
|
{Port, SPort, IPT, IPS, SSPort, NetProt, OptsClean}.
|
2004-06-17 23:29:24 +02:00
|
|
|
|
|
|
|
node_ports_parse_query(Node, Ports, Query) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:foreach(fun ({PortIpNetp, Module1, Opts1}) ->
|
|
|
|
{Port, _SPort, TIP, _SIP, SSPort, NetProt,
|
|
|
|
_OptsClean} =
|
|
|
|
get_port_data(PortIpNetp, Opts1),
|
|
|
|
case lists:keysearch(<<"add", SSPort/binary>>, 1,
|
|
|
|
Query)
|
|
|
|
of
|
|
|
|
{value, _} ->
|
|
|
|
PortIpNetp2 = {Port, TIP, NetProt},
|
|
|
|
{{value, {_, SModule}}, {value, {_, SOpts}}} =
|
|
|
|
{lists:keysearch(<<"module",
|
|
|
|
SSPort/binary>>,
|
|
|
|
1, Query),
|
|
|
|
lists:keysearch(<<"opts", SSPort/binary>>,
|
|
|
|
1, Query)},
|
2017-04-11 12:13:58 +02:00
|
|
|
Module = misc:binary_to_atom(SModule),
|
2013-03-14 10:33:02 +01:00
|
|
|
{ok, Tokens, _} =
|
|
|
|
erl_scan:string(binary_to_list(SOpts) ++ "."),
|
|
|
|
{ok, Opts} = erl_parse:parse_term(Tokens),
|
2015-10-07 00:06:58 +02:00
|
|
|
ejabberd_cluster:call(Node, ejabberd_listener,
|
2013-03-14 10:33:02 +01:00
|
|
|
delete_listener,
|
|
|
|
[PortIpNetp2, Module1]),
|
2015-10-07 00:06:58 +02:00
|
|
|
R = ejabberd_cluster:call(Node, ejabberd_listener,
|
2013-03-14 10:33:02 +01:00
|
|
|
add_listener,
|
|
|
|
[PortIpNetp2, Module, Opts]),
|
|
|
|
throw({is_added, R});
|
|
|
|
_ ->
|
|
|
|
case lists:keysearch(<<"delete",
|
|
|
|
SSPort/binary>>,
|
|
|
|
1, Query)
|
|
|
|
of
|
|
|
|
{value, _} ->
|
2015-10-07 00:06:58 +02:00
|
|
|
ejabberd_cluster:call(Node, ejabberd_listener,
|
2013-03-14 10:33:02 +01:00
|
|
|
delete_listener,
|
|
|
|
[PortIpNetp, Module1]),
|
|
|
|
throw(submitted);
|
|
|
|
_ -> ok
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
Ports),
|
|
|
|
case lists:keysearch(<<"addnew">>, 1, Query) of
|
|
|
|
{value, _} ->
|
|
|
|
{{value, {_, SPort}}, {value, {_, STIP}},
|
|
|
|
{value, {_, SNetProt}}, {value, {_, SModule}},
|
|
|
|
{value, {_, SOpts}}} =
|
|
|
|
{lists:keysearch(<<"portnew">>, 1, Query),
|
|
|
|
lists:keysearch(<<"ipnew">>, 1, Query),
|
|
|
|
lists:keysearch(<<"netprotnew">>, 1, Query),
|
|
|
|
lists:keysearch(<<"modulenew">>, 1, Query),
|
|
|
|
lists:keysearch(<<"optsnew">>, 1, Query)},
|
|
|
|
{ok, Toks, _} = erl_scan:string(binary_to_list(<<SPort/binary, ".">>)),
|
|
|
|
{ok, Port2} = erl_parse:parse_term(Toks),
|
|
|
|
{ok, ToksIP, _} = erl_scan:string(binary_to_list(<<STIP/binary, ".">>)),
|
|
|
|
STIP2 = case erl_parse:parse_term(ToksIP) of
|
|
|
|
{ok, IPTParsed} -> IPTParsed;
|
|
|
|
{error, _} -> STIP
|
|
|
|
end,
|
2017-04-11 12:13:58 +02:00
|
|
|
Module = misc:binary_to_atom(SModule),
|
|
|
|
NetProt2 = misc:binary_to_atom(SNetProt),
|
2013-03-14 10:33:02 +01:00
|
|
|
{ok, Tokens, _} = erl_scan:string(binary_to_list(<<SOpts/binary, ".">>)),
|
|
|
|
{ok, Opts} = erl_parse:parse_term(Tokens),
|
|
|
|
{Port2, _SPort, IP2, _SIP, _SSPort, NetProt2,
|
|
|
|
OptsClean} =
|
|
|
|
get_port_data({Port2, STIP2, NetProt2}, Opts),
|
2015-10-07 00:06:58 +02:00
|
|
|
R = ejabberd_cluster:call(Node, ejabberd_listener, add_listener,
|
2009-08-11 20:22:58 +02:00
|
|
|
[{Port2, IP2, NetProt2}, Module, OptsClean]),
|
2013-03-14 10:33:02 +01:00
|
|
|
throw({is_added, R});
|
|
|
|
_ -> ok
|
2004-06-17 23:29:24 +02:00
|
|
|
end.
|
|
|
|
|
2005-05-23 02:30:29 +02:00
|
|
|
node_modules_to_xhtml(Modules, Lang) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
?XAE(<<"table">>, [{<<"class">>, <<"withtextareas">>}],
|
|
|
|
[?XE(<<"thead">>,
|
|
|
|
[?XE(<<"tr">>,
|
|
|
|
[?XCT(<<"td">>, <<"Module">>),
|
|
|
|
?XCT(<<"td">>, <<"Options">>)])]),
|
|
|
|
?XE(<<"tbody">>,
|
|
|
|
(lists:map(fun ({Module, Opts} = _E) ->
|
|
|
|
SModule =
|
|
|
|
iolist_to_binary(atom_to_list(Module)),
|
|
|
|
{NumLines, SOpts} = term_to_paragraph(Opts,
|
|
|
|
40),
|
|
|
|
?XE(<<"tr">>,
|
|
|
|
[?XC(<<"td">>, SModule),
|
2015-07-15 19:01:32 +02:00
|
|
|
?XAE(<<"td">>, direction(ltr),
|
2013-03-14 10:33:02 +01:00
|
|
|
[?TEXTAREA(<<"opts", SModule/binary>>,
|
2016-11-24 13:06:06 +01:00
|
|
|
(integer_to_binary(NumLines)),
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"40">>, SOpts)]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>,
|
|
|
|
<<"restart",
|
|
|
|
SModule/binary>>,
|
|
|
|
<<"Restart">>)]),
|
|
|
|
?XE(<<"td">>,
|
|
|
|
[?INPUTT(<<"submit">>,
|
|
|
|
<<"stop", SModule/binary>>,
|
|
|
|
<<"Stop">>)])])
|
|
|
|
end,
|
|
|
|
Modules)
|
|
|
|
++
|
|
|
|
[?XE(<<"tr">>,
|
|
|
|
[?XE(<<"td">>,
|
|
|
|
[?INPUT(<<"text">>, <<"modulenew">>, <<"">>)]),
|
2015-07-15 19:01:32 +02:00
|
|
|
?XAE(<<"td">>, direction(ltr),
|
2013-03-14 10:33:02 +01:00
|
|
|
[?TEXTAREA(<<"optsnew">>, <<"2">>, <<"40">>,
|
|
|
|
<<"[]">>)]),
|
|
|
|
?XAE(<<"td">>, [{<<"colspan">>, <<"2">>}],
|
|
|
|
[?INPUTT(<<"submit">>, <<"start">>,
|
|
|
|
<<"Start">>)])])]))]).
|
2005-05-23 02:30:29 +02:00
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
node_modules_parse_query(Host, Node, Modules, Query) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:foreach(fun ({Module, _Opts1}) ->
|
|
|
|
SModule = iolist_to_binary(atom_to_list(Module)),
|
|
|
|
case lists:keysearch(<<"restart", SModule/binary>>, 1,
|
|
|
|
Query)
|
|
|
|
of
|
|
|
|
{value, _} ->
|
|
|
|
{value, {_, SOpts}} = lists:keysearch(<<"opts",
|
|
|
|
SModule/binary>>,
|
|
|
|
1, Query),
|
|
|
|
{ok, Tokens, _} =
|
|
|
|
erl_scan:string(binary_to_list(<<SOpts/binary, ".">>)),
|
|
|
|
{ok, Opts} = erl_parse:parse_term(Tokens),
|
2015-10-07 00:06:58 +02:00
|
|
|
ejabberd_cluster:call(Node, gen_mod, stop_module,
|
2013-03-14 10:33:02 +01:00
|
|
|
[Host, Module]),
|
2015-10-07 00:06:58 +02:00
|
|
|
ejabberd_cluster:call(Node, gen_mod, start_module,
|
2013-03-14 10:33:02 +01:00
|
|
|
[Host, Module, Opts]),
|
|
|
|
throw(submitted);
|
|
|
|
_ ->
|
|
|
|
case lists:keysearch(<<"stop", SModule/binary>>,
|
|
|
|
1, Query)
|
|
|
|
of
|
|
|
|
{value, _} ->
|
2015-10-07 00:06:58 +02:00
|
|
|
ejabberd_cluster:call(Node, gen_mod, stop_module,
|
2013-03-14 10:33:02 +01:00
|
|
|
[Host, Module]),
|
|
|
|
throw(submitted);
|
|
|
|
_ -> ok
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
Modules),
|
|
|
|
case lists:keysearch(<<"start">>, 1, Query) of
|
|
|
|
{value, _} ->
|
|
|
|
{{value, {_, SModule}}, {value, {_, SOpts}}} =
|
|
|
|
{lists:keysearch(<<"modulenew">>, 1, Query),
|
|
|
|
lists:keysearch(<<"optsnew">>, 1, Query)},
|
2017-04-11 12:13:58 +02:00
|
|
|
Module = misc:binary_to_atom(SModule),
|
2013-03-14 10:33:02 +01:00
|
|
|
{ok, Tokens, _} = erl_scan:string(binary_to_list(<<SOpts/binary, ".">>)),
|
|
|
|
{ok, Opts} = erl_parse:parse_term(Tokens),
|
2015-10-07 00:06:58 +02:00
|
|
|
ejabberd_cluster:call(Node, gen_mod, start_module,
|
2013-03-14 10:33:02 +01:00
|
|
|
[Host, Module, Opts]),
|
|
|
|
throw(submitted);
|
|
|
|
_ -> ok
|
2005-05-23 02:30:29 +02:00
|
|
|
end.
|
2004-06-17 23:29:24 +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].
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
element_to_list(X) when is_atom(X) ->
|
|
|
|
iolist_to_binary(atom_to_list(X));
|
|
|
|
element_to_list(X) when is_integer(X) ->
|
2016-11-24 13:06:06 +01:00
|
|
|
integer_to_binary(X).
|
2007-12-26 13:21:52 +01:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
list_to_element(Bin) ->
|
|
|
|
{ok, Tokens, _} = erl_scan:string(binary_to_list(Bin)),
|
2007-12-26 13:21:52 +01:00
|
|
|
[{_, _, Element}] = Tokens,
|
|
|
|
Element.
|
2005-04-17 20:08:34 +02:00
|
|
|
|
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
|
|
|
%%%==================================
|
|
|
|
%%%% navigation menu
|
2008-10-12 15:58:05 +02:00
|
|
|
|
2009-06-23 23:00:43 +02:00
|
|
|
%% @spec (Host, Node, Lang, JID::jid()) -> [LI]
|
|
|
|
make_navigation(Host, Node, Lang, JID) ->
|
|
|
|
Menu = make_navigation_menu(Host, Node, Lang, JID),
|
2008-10-12 15:58:05 +02:00
|
|
|
make_menu_items(Lang, Menu).
|
|
|
|
|
2009-06-23 23:00:43 +02:00
|
|
|
%% @spec (Host, Node, Lang, JID::jid()) -> Menu
|
|
|
|
%% where Host = global | string()
|
|
|
|
%% Node = cluster | string()
|
|
|
|
%% Lang = string()
|
|
|
|
%% Menu = {URL, Title} | {URL, Title, [Menu]}
|
|
|
|
%% URL = string()
|
|
|
|
%% Title = string()
|
|
|
|
make_navigation_menu(Host, Node, Lang, JID) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
HostNodeMenu = make_host_node_menu(Host, Node, Lang,
|
|
|
|
JID),
|
|
|
|
HostMenu = make_host_menu(Host, HostNodeMenu, Lang,
|
|
|
|
JID),
|
2009-06-23 23:00:43 +02:00
|
|
|
NodeMenu = make_node_menu(Host, Node, Lang),
|
|
|
|
make_server_menu(HostMenu, NodeMenu, Lang, JID).
|
|
|
|
|
2008-10-12 15:58:05 +02:00
|
|
|
%% @spec (Host, Node, Base, Lang) -> [LI]
|
|
|
|
make_menu_items(global, cluster, Base, Lang) ->
|
|
|
|
HookItems = get_menu_items_hook(server, Lang),
|
2013-03-14 10:33:02 +01:00
|
|
|
make_menu_items(Lang, {Base, <<"">>, HookItems});
|
2009-02-02 11:12:44 +01:00
|
|
|
make_menu_items(global, Node, Base, Lang) ->
|
|
|
|
HookItems = get_menu_items_hook({node, Node}, Lang),
|
2013-03-14 10:33:02 +01:00
|
|
|
make_menu_items(Lang, {Base, <<"">>, HookItems});
|
2008-10-12 15:58:05 +02:00
|
|
|
make_menu_items(Host, cluster, Base, Lang) ->
|
|
|
|
HookItems = get_menu_items_hook({host, Host}, Lang),
|
2013-03-14 10:33:02 +01:00
|
|
|
make_menu_items(Lang, {Base, <<"">>, HookItems});
|
2009-02-02 11:12:44 +01:00
|
|
|
make_menu_items(Host, Node, Base, Lang) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
HookItems = get_menu_items_hook({hostnode, Host, Node},
|
|
|
|
Lang),
|
|
|
|
make_menu_items(Lang, {Base, <<"">>, HookItems}).
|
2008-10-12 15:58:05 +02:00
|
|
|
|
2009-06-23 23:00:43 +02:00
|
|
|
make_host_node_menu(global, _, _Lang, _JID) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{<<"">>, <<"">>, []};
|
2009-06-23 23:00:43 +02:00
|
|
|
make_host_node_menu(_, cluster, _Lang, _JID) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{<<"">>, <<"">>, []};
|
2009-06-23 23:00:43 +02:00
|
|
|
make_host_node_menu(Host, Node, Lang, JID) ->
|
2008-10-12 15:58:05 +02:00
|
|
|
HostNodeBase = get_base_path(Host, Node),
|
2013-03-14 10:33:02 +01:00
|
|
|
HostNodeFixed = [{<<"modules/">>, <<"Modules">>}] ++
|
|
|
|
get_menu_items_hook({hostnode, Host, Node}, Lang),
|
2009-06-23 23:00:43 +02:00
|
|
|
HostNodeBasePath = url_to_path(HostNodeBase),
|
2013-03-14 10:33:02 +01:00
|
|
|
HostNodeFixed2 = [Tuple
|
|
|
|
|| Tuple <- HostNodeFixed,
|
|
|
|
is_allowed_path(HostNodeBasePath, Tuple, JID)],
|
|
|
|
{HostNodeBase, iolist_to_binary(atom_to_list(Node)),
|
|
|
|
HostNodeFixed2}.
|
2008-10-12 15:58:05 +02:00
|
|
|
|
2009-06-23 23:00:43 +02:00
|
|
|
make_host_menu(global, _HostNodeMenu, _Lang, _JID) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{<<"">>, <<"">>, []};
|
2009-06-23 23:00:43 +02:00
|
|
|
make_host_menu(Host, HostNodeMenu, Lang, JID) ->
|
2008-10-12 15:58:05 +02:00
|
|
|
HostBase = get_base_path(Host, cluster),
|
2013-03-14 10:33:02 +01:00
|
|
|
HostFixed = [{<<"acls">>, <<"Access Control Lists">>},
|
|
|
|
{<<"access">>, <<"Access Rules">>},
|
|
|
|
{<<"users">>, <<"Users">>},
|
|
|
|
{<<"online-users">>, <<"Online Users">>}]
|
|
|
|
++
|
|
|
|
get_lastactivity_menuitem_list(Host) ++
|
|
|
|
[{<<"nodes">>, <<"Nodes">>, HostNodeMenu},
|
|
|
|
{<<"stats">>, <<"Statistics">>}]
|
|
|
|
++ get_menu_items_hook({host, Host}, Lang),
|
2009-06-23 23:00:43 +02:00
|
|
|
HostBasePath = url_to_path(HostBase),
|
2013-03-14 10:33:02 +01:00
|
|
|
HostFixed2 = [Tuple
|
|
|
|
|| Tuple <- HostFixed,
|
|
|
|
is_allowed_path(HostBasePath, Tuple, JID)],
|
2009-06-23 23:00:43 +02:00
|
|
|
{HostBase, Host, HostFixed2}.
|
2008-10-12 15:58:05 +02:00
|
|
|
|
|
|
|
make_node_menu(_Host, cluster, _Lang) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{<<"">>, <<"">>, []};
|
2008-10-12 15:58:05 +02:00
|
|
|
make_node_menu(global, Node, Lang) ->
|
|
|
|
NodeBase = get_base_path(global, Node),
|
2013-03-14 10:33:02 +01:00
|
|
|
NodeFixed = [{<<"db/">>, <<"Database">>},
|
|
|
|
{<<"backup/">>, <<"Backup">>},
|
|
|
|
{<<"ports/">>, <<"Listened Ports">>},
|
|
|
|
{<<"stats/">>, <<"Statistics">>},
|
|
|
|
{<<"update/">>, <<"Update">>}]
|
|
|
|
++ get_menu_items_hook({node, Node}, Lang),
|
|
|
|
{NodeBase, iolist_to_binary(atom_to_list(Node)),
|
|
|
|
NodeFixed};
|
2008-10-12 15:58:05 +02:00
|
|
|
make_node_menu(_Host, _Node, _Lang) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{<<"">>, <<"">>, []}.
|
2008-10-12 15:58:05 +02:00
|
|
|
|
2009-06-23 23:00:43 +02:00
|
|
|
make_server_menu(HostMenu, NodeMenu, Lang, JID) ->
|
2008-10-12 15:58:05 +02:00
|
|
|
Base = get_base_path(global, cluster),
|
2013-03-14 10:33:02 +01:00
|
|
|
Fixed = [{<<"acls">>, <<"Access Control Lists">>},
|
|
|
|
{<<"access">>, <<"Access Rules">>},
|
|
|
|
{<<"vhosts">>, <<"Virtual Hosts">>, HostMenu},
|
|
|
|
{<<"nodes">>, <<"Nodes">>, NodeMenu},
|
|
|
|
{<<"stats">>, <<"Statistics">>}]
|
|
|
|
++ get_menu_items_hook(server, Lang),
|
2009-06-23 23:00:43 +02:00
|
|
|
BasePath = url_to_path(Base),
|
2013-03-14 10:33:02 +01:00
|
|
|
Fixed2 = [Tuple
|
|
|
|
|| Tuple <- Fixed,
|
|
|
|
is_allowed_path(BasePath, Tuple, JID)],
|
2015-12-02 17:10:23 +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]).
|
|
|
|
|
|
|
|
%% @spec (Lang::string(), Menu) -> [LI]
|
|
|
|
%% where Menu = {MURI::string(), MName::string(), Items::[Item]}
|
|
|
|
%% Item = {IURI::string(), IName::string()} | {IURI::string(), IName::string(), Menu}
|
|
|
|
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
|
|
|
|
|
|
|
%%%==================================
|
|
|
|
|
2015-06-01 14:38:27 +02:00
|
|
|
|
2017-05-08 11:59:28 +02:00
|
|
|
-spec opt_type(access_readonly) -> fun((any()) -> any());
|
|
|
|
(atom()) -> [atom()].
|
2016-07-19 11:26:33 +02:00
|
|
|
opt_type(access_readonly) -> fun acl:access_rules_validator/1;
|
2017-04-28 12:23:32 +02:00
|
|
|
opt_type(_) -> [access_readonly].
|
2015-10-07 00:06:58 +02:00
|
|
|
|
|
|
|
%%% vim: set foldmethod=marker foldmarker=%%%%,%%%=:
|