25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-20 17:27:00 +01:00

Move some modules webadmin pages to their modules

This commit is contained in:
Badlop 2024-09-16 17:09:01 +02:00
parent 31b85351f2
commit c2d4f73893
4 changed files with 114 additions and 68 deletions

View File

@ -2206,13 +2206,7 @@ web_page_host(Acc, _, _) ->
%%% HostUser %%% HostUser
web_menu_hostuser(Acc, _Host, _Username, _Lang) -> web_menu_hostuser(Acc, _Host, _Username, _Lang) ->
Acc Acc ++ [{<<"auth">>, <<"Authentication">>}, {<<"session">>, <<"Sessions">>}].
++ [{<<"auth">>, <<"Authentication">>},
{<<"mam">>, <<"MAM">>},
{<<"privacy">>, <<"Privacy Lists">>},
{<<"private">>, <<"Private XML Storage">>},
{<<"session">>, <<"Sessions">>},
{<<"vcard">>, <<"vCard">>}].
web_page_hostuser(_, Host, User, #request{path = [<<"auth">>]} = R) -> web_page_hostuser(_, Host, User, #request{path = [<<"auth">>]} = R) ->
Ban = make_command(ban_account, Ban = make_command(ban_account,
@ -2242,26 +2236,6 @@ web_page_hostuser(_, Host, User, #request{path = [<<"auth">>]} = R) ->
[{<<"user">>, User}, {<<"host">>, Host}], [{<<"user">>, User}, {<<"host">>, Host}],
[{style, danger}])], [{style, danger}])],
{stop, Res}; {stop, Res};
web_page_hostuser(_, Host, User, #request{path = [<<"mam">>]} = R) ->
Res = ?H1GL(<<"MAM">>, <<"modules/#mod_mam">>, <<"mod_mam">>)
++ [make_command(remove_mam_for_user,
R,
[{<<"user">>, User}, {<<"host">>, Host}],
[{style, danger}]),
make_command(remove_mam_for_user_with_peer,
R,
[{<<"user">>, User}, {<<"host">>, Host}],
[{style, danger}])],
{stop, Res};
web_page_hostuser(_, Host, User, #request{path = [<<"privacy">>]} = R) ->
Res = ?H1GL(<<"Privacy Lists">>, <<"modules/#mod_privacy">>, <<"mod_privacy">>)
++ [make_command(privacy_set, R, [{<<"user">>, User}, {<<"host">>, Host}], [])],
{stop, Res};
web_page_hostuser(_, Host, User, #request{path = [<<"private">>]} = R) ->
Res = ?H1GL(<<"Private XML Storage">>, <<"modules/#mod_private">>, <<"mod_private">>)
++ [make_command(private_set, R, [{<<"user">>, User}, {<<"host">>, Host}], []),
make_command(private_get, R, [{<<"user">>, User}, {<<"host">>, Host}], [])],
{stop, Res};
web_page_hostuser(_, Host, User, #request{path = [<<"session">>]} = R) -> web_page_hostuser(_, Host, User, #request{path = [<<"session">>]} = R) ->
Head = [?XC(<<"h1">>, <<"Sessions">>), ?BR], Head = [?XC(<<"h1">>, <<"Sessions">>), ?BR],
Set = [make_command(resource_num, R, [{<<"user">>, User}, {<<"host">>, Host}], []), Set = [make_command(resource_num, R, [{<<"user">>, User}, {<<"host">>, Host}], []),
@ -2280,47 +2254,6 @@ web_page_hostuser(_, Host, User, #request{path = [<<"session">>]} = R) ->
make_command(get_presence, R, [{<<"user">>, User}, {<<"host">>, Host}], []), make_command(get_presence, R, [{<<"user">>, User}, {<<"host">>, Host}], []),
make_command(num_resources, R, [{<<"user">>, User}, {<<"host">>, Host}], [])], make_command(num_resources, R, [{<<"user">>, User}, {<<"host">>, Host}], [])],
{stop, Head ++ Get ++ Set}; {stop, Head ++ Get ++ Set};
web_page_hostuser(_, Host, User, #request{path = [<<"vcard">>]} = R) ->
Head = ?H1GL(<<"vCard">>, <<"modules/#mod_vcard">>, <<"mod_vcard">>),
Set = [make_command(set_nickname, R, [{<<"user">>, User}, {<<"host">>, Host}], []),
make_command(set_vcard, R, [{<<"user">>, User}, {<<"host">>, Host}], []),
make_command(set_vcard2, R, [{<<"user">>, User}, {<<"host">>, Host}], []),
make_command(set_vcard2_multi, R, [{<<"user">>, User}, {<<"host">>, Host}], [])],
timer:sleep(100), % setting vcard takes a while, let's delay the get commands
FieldNames = [<<"VERSION">>, <<"FN">>, <<"NICKNAME">>, <<"BDAY">>],
FieldNames2 =
[{<<"N">>, <<"FAMILY">>},
{<<"N">>, <<"GIVEN">>},
{<<"N">>, <<"MIDDLE">>},
{<<"ADR">>, <<"CTRY">>},
{<<"ADR">>, <<"LOCALITY">>},
{<<"EMAIL">>, <<"USERID">>}],
Get = [make_command(get_vcard, R, [{<<"user">>, User}, {<<"host">>, Host}], []),
?XE(<<"blockquote">>,
[make_table([<<"name">>, <<"value">>],
[{?C(FieldName),
make_command(get_vcard,
R,
[{<<"user">>, User},
{<<"host">>, Host},
{<<"name">>, FieldName}],
[{only, value}])}
|| FieldName <- FieldNames])]),
make_command(get_vcard2, R, [{<<"user">>, User}, {<<"host">>, Host}], []),
?XE(<<"blockquote">>,
[make_table([<<"name">>, <<"subname">>, <<"value">>],
[{?C(FieldName),
?C(FieldSubName),
make_command(get_vcard2,
R,
[{<<"user">>, User},
{<<"host">>, Host},
{<<"name">>, FieldName},
{<<"subname">>, FieldSubName}],
[{only, value}])}
|| {FieldName, FieldSubName} <- FieldNames2])]),
make_command(get_vcard2_multi, R, [{<<"user">>, User}, {<<"host">>, Host}], [])],
{stop, Head ++ Get ++ Set};
web_page_hostuser(Acc, _, _, _) -> web_page_hostuser(Acc, _, _, _) ->
Acc. Acc.

View File

@ -40,8 +40,14 @@
import_start/2, import_stop/2, import/5, import_info/0, import_start/2, import_stop/2, import/5, import_info/0,
mod_opt_type/1, mod_options/1, depends/2]). mod_opt_type/1, mod_options/1, depends/2]).
-export([webadmin_menu_hostuser/4, webadmin_page_hostuser/4]).
-import(ejabberd_web_admin, [make_command/4, make_command/2]).
-include("logger.hrl"). -include("logger.hrl").
-include_lib("xmpp/include/xmpp.hrl"). -include_lib("xmpp/include/xmpp.hrl").
-include("ejabberd_http.hrl").
-include("ejabberd_web_admin.hrl").
-include("mod_privacy.hrl"). -include("mod_privacy.hrl").
-include("translate.hrl"). -include("translate.hrl").
@ -78,6 +84,8 @@ start(Host, Opts) ->
{hook, user_send_packet, user_send_packet, 50}, {hook, user_send_packet, user_send_packet, 50},
{hook, privacy_check_packet, check_packet, 50}, {hook, privacy_check_packet, check_packet, 50},
{hook, remove_user, remove_user, 50}, {hook, remove_user, remove_user, 50},
{hook, webadmin_menu_hostuser, webadmin_menu_hostuser, 50},
{hook, webadmin_page_hostuser, webadmin_page_hostuser, 50},
{iq_handler, ejabberd_sm, ?NS_PRIVACY, process_iq}]}. {iq_handler, ejabberd_sm, ?NS_PRIVACY, process_iq}]}.
stop(_Host) -> stop(_Host) ->
@ -840,6 +848,24 @@ export(LServer) ->
Mod = gen_mod:db_mod(LServer, ?MODULE), Mod = gen_mod:db_mod(LServer, ?MODULE),
Mod:export(LServer). Mod:export(LServer).
%%%
%%% WebAdmin
%%%
webadmin_menu_hostuser(Acc, _Host, _Username, _Lang) ->
Acc ++ [{<<"privacy">>, <<"Privacy Lists">>}].
webadmin_page_hostuser(_, Host, User,
#request{us = _US, path = [<<"privacy">>]} = R) ->
Res = ?H1GL(<<"Privacy Lists">>, <<"modules/#mod_privacy">>, <<"mod_privacy">>)
++ [make_command(privacy_set, R, [{<<"user">>, User}, {<<"host">>, Host}], [])],
{stop, Res};
webadmin_page_hostuser(Acc, _, _, _) -> Acc.
%%%
%%% Documentation
%%%
depends(_Host, _Opts) -> depends(_Host, _Opts) ->
[]. [].

View File

@ -41,10 +41,16 @@
-export([get_commands_spec/0, bookmarks_to_pep/2]). -export([get_commands_spec/0, bookmarks_to_pep/2]).
-export([webadmin_menu_hostuser/4, webadmin_page_hostuser/4]).
-import(ejabberd_web_admin, [make_command/4, make_command/2]).
-include("logger.hrl"). -include("logger.hrl").
-include_lib("xmpp/include/xmpp.hrl"). -include_lib("xmpp/include/xmpp.hrl").
-include("mod_private.hrl"). -include("mod_private.hrl").
-include("ejabberd_commands.hrl"). -include("ejabberd_commands.hrl").
-include("ejabberd_http.hrl").
-include("ejabberd_web_admin.hrl").
-include("translate.hrl"). -include("translate.hrl").
-include("pubsub.hrl"). -include("pubsub.hrl").
@ -71,6 +77,8 @@ start(Host, Opts) ->
{hook, pubsub_publish_item, pubsub_publish_item, 50}, {hook, pubsub_publish_item, pubsub_publish_item, 50},
{hook, pubsub_delete_item, pubsub_delete_item, 50}, {hook, pubsub_delete_item, pubsub_delete_item, 50},
{hook, pubsub_tree_call, pubsub_tree_call, 50}, {hook, pubsub_tree_call, pubsub_tree_call, 50},
{hook, webadmin_menu_hostuser, webadmin_menu_hostuser, 50},
{hook, webadmin_page_hostuser, webadmin_page_hostuser, 50},
{iq_handler, ejabberd_sm, ?NS_PRIVATE, process_sm_iq}]}. {iq_handler, ejabberd_sm, ?NS_PRIVATE, process_sm_iq}]}.
stop(Host) -> stop(Host) ->
@ -544,6 +552,21 @@ bookmarks_to_pep(User, Server) ->
{error, <<"Cannot retrieve bookmarks from private XML storage">>} {error, <<"Cannot retrieve bookmarks from private XML storage">>}
end. end.
%%%===================================================================
%%% WebAdmin
%%%===================================================================
webadmin_menu_hostuser(Acc, _Host, _Username, _Lang) ->
Acc ++ [{<<"private">>, <<"Private XML Storage">>}].
webadmin_page_hostuser(_, Host, User,
#request{path = [<<"private">>]} = R) ->
Res = ?H1GL(<<"Private XML Storage">>, <<"modules/#mod_private">>, <<"mod_private">>)
++ [make_command(private_set, R, [{<<"user">>, User}, {<<"host">>, Host}], []),
make_command(private_get, R, [{<<"user">>, User}, {<<"host">>, Host}], [])],
{stop, Res};
webadmin_page_hostuser(Acc, _, _, _) -> Acc.
%%%=================================================================== %%%===================================================================
%%% Cache %%% Cache
%%%=================================================================== %%%===================================================================

View File

@ -43,12 +43,17 @@
-export([init/1, handle_call/3, handle_cast/2, -export([init/1, handle_call/3, handle_cast/2,
handle_info/2, terminate/2, code_change/3]). handle_info/2, terminate/2, code_change/3]).
-export([route/1]). -export([route/1]).
-export([webadmin_menu_hostuser/4, webadmin_page_hostuser/4]).
-import(ejabberd_web_admin, [make_command/4, make_command/2, make_table/2]).
-include("logger.hrl"). -include("logger.hrl").
-include_lib("xmpp/include/xmpp.hrl"). -include_lib("xmpp/include/xmpp.hrl").
-include("mod_vcard.hrl"). -include("mod_vcard.hrl").
-include("translate.hrl"). -include("translate.hrl").
-include("ejabberd_stacktrace.hrl"). -include("ejabberd_stacktrace.hrl").
-include("ejabberd_http.hrl").
-include("ejabberd_web_admin.hrl").
-define(VCARD_CACHE, vcard_cache). -define(VCARD_CACHE, vcard_cache).
@ -98,6 +103,8 @@ init([Host|_]) ->
ejabberd_hooks:add(disco_sm_features, Host, ?MODULE, ejabberd_hooks:add(disco_sm_features, Host, ?MODULE,
get_sm_features, 50), get_sm_features, 50),
ejabberd_hooks:add(vcard_iq_set, Host, ?MODULE, vcard_iq_set, 50), ejabberd_hooks:add(vcard_iq_set, Host, ?MODULE, vcard_iq_set, 50),
ejabberd_hooks:add(webadmin_menu_hostuser, Host, ?MODULE, webadmin_menu_hostuser, 50),
ejabberd_hooks:add(webadmin_page_hostuser, Host, ?MODULE, webadmin_page_hostuser, 50),
MyHosts = gen_mod:get_opt_hosts(Opts), MyHosts = gen_mod:get_opt_hosts(Opts),
Search = mod_vcard_opt:search(Opts), Search = mod_vcard_opt:search(Opts),
if Search -> if Search ->
@ -161,6 +168,8 @@ terminate(_Reason, #state{hosts = MyHosts, server_host = Host}) ->
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_VCARD), gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_VCARD),
ejabberd_hooks:delete(disco_sm_features, Host, ?MODULE, get_sm_features, 50), ejabberd_hooks:delete(disco_sm_features, Host, ?MODULE, get_sm_features, 50),
ejabberd_hooks:delete(vcard_iq_set, Host, ?MODULE, vcard_iq_set, 50), ejabberd_hooks:delete(vcard_iq_set, Host, ?MODULE, vcard_iq_set, 50),
ejabberd_hooks:delete(webadmin_menu_hostuser, Host, ?MODULE, webadmin_menu_hostuser, 50),
ejabberd_hooks:delete(webadmin_page_hostuser, Host, ?MODULE, webadmin_page_hostuser, 50),
Mod = gen_mod:db_mod(Host, ?MODULE), Mod = gen_mod:db_mod(Host, ?MODULE),
Mod:stop(Host), Mod:stop(Host),
lists:foreach( lists:foreach(
@ -554,6 +563,61 @@ export(LServer) ->
Mod = gen_mod:db_mod(LServer, ?MODULE), Mod = gen_mod:db_mod(LServer, ?MODULE),
Mod:export(LServer). Mod:export(LServer).
%%%
%%% WebAdmin
%%%
webadmin_menu_hostuser(Acc, _Host, _Username, _Lang) ->
Acc ++ [{<<"vcard">>, <<"vCard">>}].
webadmin_page_hostuser(_, Host, User,
#request{path = [<<"vcard">>]} = R) ->
Head = ?H1GL(<<"vCard">>, <<"modules/#mod_vcard">>, <<"mod_vcard">>),
Set = [make_command(set_nickname, R, [{<<"user">>, User}, {<<"host">>, Host}], []),
make_command(set_vcard, R, [{<<"user">>, User}, {<<"host">>, Host}], []),
make_command(set_vcard2, R, [{<<"user">>, User}, {<<"host">>, Host}], []),
make_command(set_vcard2_multi, R, [{<<"user">>, User}, {<<"host">>, Host}], [])],
timer:sleep(100), % setting vcard takes a while, let's delay the get commands
FieldNames = [<<"VERSION">>, <<"FN">>, <<"NICKNAME">>, <<"BDAY">>],
FieldNames2 =
[{<<"N">>, <<"FAMILY">>},
{<<"N">>, <<"GIVEN">>},
{<<"N">>, <<"MIDDLE">>},
{<<"ADR">>, <<"CTRY">>},
{<<"ADR">>, <<"LOCALITY">>},
{<<"EMAIL">>, <<"USERID">>}],
Get = [make_command(get_vcard, R, [{<<"user">>, User}, {<<"host">>, Host}], []),
?XE(<<"blockquote">>,
[make_table([<<"name">>, <<"value">>],
[{?C(FieldName),
make_command(get_vcard,
R,
[{<<"user">>, User},
{<<"host">>, Host},
{<<"name">>, FieldName}],
[{only, value}])}
|| FieldName <- FieldNames])]),
make_command(get_vcard2, R, [{<<"user">>, User}, {<<"host">>, Host}], []),
?XE(<<"blockquote">>,
[make_table([<<"name">>, <<"subname">>, <<"value">>],
[{?C(FieldName),
?C(FieldSubName),
make_command(get_vcard2,
R,
[{<<"user">>, User},
{<<"host">>, Host},
{<<"name">>, FieldName},
{<<"subname">>, FieldSubName}],
[{only, value}])}
|| {FieldName, FieldSubName} <- FieldNames2])]),
make_command(get_vcard2_multi, R, [{<<"user">>, User}, {<<"host">>, Host}], [])],
{stop, Head ++ Get ++ Set};
webadmin_page_hostuser(Acc, _, _, _) -> Acc.
%%%
%%% Documentation
%%%
depends(_Host, _Opts) -> depends(_Host, _Opts) ->
[]. [].