diff --git a/src/mod_muc_admin.erl b/src/mod_muc_admin.erl index 2d354a1260a..7f351a87154 100644 --- a/src/mod_muc_admin.erl +++ b/src/mod_muc_admin.erl @@ -34,7 +34,7 @@ create_room_with_opts/4, create_room/3, destroy_room/2, create_rooms_file/1, destroy_rooms_file/1, rooms_unused_list/2, rooms_unused_destroy/2, - rooms_empty_list/1, rooms_empty_destroy/1, + rooms_empty_list/1, rooms_empty_destroy/1, rooms_empty_destroy_restuple/1, get_user_rooms/2, get_user_subscriptions/2, get_room_occupants/2, get_room_occupants_number/2, send_direct_invitation/5, change_room_option/4, get_room_options/2, @@ -45,13 +45,12 @@ web_menu_main/2, web_page_main/2, web_menu_host/3, web_page_host/3, web_menu_hostuser/4, web_page_hostuser/4, - webadmin_muc/1, - webadmin_host_muc_rooms/3, + webadmin_muc/2, mod_opt_type/1, mod_options/1, get_commands_spec/0, find_hosts/1, room_diagnostics/2, get_room_pid/2, get_room_history/2]). --import(ejabberd_web_admin, [make_command/4]). +-import(ejabberd_web_admin, [make_command/4, make_command_raw_value/3, make_table/4]). -include("logger.hrl"). -include_lib("xmpp/include/xmpp.hrl"). @@ -243,6 +242,19 @@ get_commands_spec() -> args = [{service, binary}], args_rename = [{host, service}], result = {rooms, {list, {room, string}}}}, + #ejabberd_commands{name = rooms_empty_destroy, tags = [muc], + desc = "Destroy the rooms that have no messages in archive", + longdesc = "The MUC service argument can be `global` to get all hosts.", + module = ?MODULE, function = rooms_empty_destroy_restuple, + version = 2, + note = "modified in 24.xx", + args_desc = ["MUC service, or `global` for all"], + args_example = ["conference.example.com"], + result_desc = "List of empty rooms that have been destroyed", + result_example = {ok, <<"Destroyed rooms: 2">>}, + args = [{service, binary}], + args_rename = [{host, service}], + result = {res, restuple}}, #ejabberd_commands{name = get_user_rooms, tags = [muc], desc = "Get the list of rooms where this user is occupant", @@ -489,14 +501,9 @@ get_commands_spec() -> {message, string}]}}}}}, #ejabberd_commands{name = webadmin_muc, tags = [internal], - desc = "Generate WebAdmin MUC HTML", - module = ?MODULE, function = webadmin_muc, - args = [{lang, binary}], - result = {res, any}}, - #ejabberd_commands{name = webadmin_host_muc_rooms, tags = [internal], desc = "Generate WebAdmin MUC Rooms HTML", - module = ?MODULE, function = webadmin_host_muc_rooms, - args = [{host, any}, {query, any}, {lang, binary}], + module = ?MODULE, function = webadmin_muc, + args = [{request, any}, {lang, binary}], result = {res, any}} ]. @@ -599,6 +606,9 @@ get_user_subscriptions(User, Server) -> %% Web Admin %%---------------------------- +%% emacs-indent-begin +%% emacs-untabify-begin + %%--------------- %% Web Admin Menu @@ -608,113 +618,323 @@ web_menu_main(Acc, Lang) -> web_menu_host(Acc, _Host, Lang) -> Acc ++ [{<<"muc">>, translate:translate(Lang, ?T("Multi-User Chat"))}]. - %%--------------- %% Web Admin Page -define(TDTD(L, N), - ?XE(<<"tr">>, [?XCT(<<"td">>, L), - ?XC(<<"td">>, integer_to_binary(N)) - ])). + ?XE(<<"tr">>, [?XCT(<<"td">>, L), + ?XC(<<"td">>, integer_to_binary(N)) + ])). web_page_main(_, #request{path = [<<"muc">>], lang = Lang} = R) -> PageTitle = translate:translate(Lang, ?T("Multi-User Chat")), Title = ?H1GL(PageTitle, <<"modules/#mod_muc">>, <<"mod_muc">>), - Res = [make_command(webadmin_muc, R, [{<<"lang">>, Lang}], [])], + Res = [make_command(webadmin_muc, R, + [{<<"request">>, R}, + {<<"lang">>, Lang}], + [])], {stop, Title ++ Res}; -web_page_main(_, #request{path = [<<"muc">>, <<"rooms">>], q = Q, lang = Lang} = R) -> +web_page_main(Acc, _) -> Acc. + +web_page_host(_, Host, #request{path = [<<"muc">> | RPath], lang = Lang} = R) -> PageTitle = translate:translate(Lang, ?T("Multi-User Chat")), + Service = find_service(Host), + Level = length(RPath), + Res = webadmin_muc_host(Host, Service, RPath, R, Lang, Level, PageTitle), + {stop, Res}; + +web_page_host(Acc, _, _) -> Acc. + +%%--------------- +%% WebAdmin MUC Host Page + +webadmin_muc_host(Host, Service, [<<"create-room">> | RPath], R, _Lang, Level, PageTitle) -> Title = ?H1GL(PageTitle, <<"modules/#mod_muc">>, <<"mod_muc">>), - Res = [make_command(webadmin_host_muc_rooms, R, [{<<"host">>, global}, {<<"query">>, Q}, {<<"lang">>, Lang}], [])], - {stop, Title ++ Res}; + Breadcrumb = make_breadcrumb({service_section, Level, Service, <<"Create Room">>, RPath}), + Set = [make_command(create_room, R, + [{<<"service">>, Service}, {<<"host">>, Host}], []), + make_command(create_room_with_opts, R, + [{<<"service">>, Service}, {<<"host">>, Host}], [])], + Title ++ Breadcrumb ++ Set; + +webadmin_muc_host(_Host, Service, [<<"nick-register">> | RPath], R, _Lang, Level, PageTitle) -> + Title = ?H1GL(PageTitle, <<"modules/#mod_muc">>, <<"mod_muc">>), + Breadcrumb = make_breadcrumb({service_section, Level, Service, <<"Nick Register">>, RPath}), + Set = [make_command(muc_register_nick, R, [{<<"service">>, Service}], []), + make_command(muc_unregister_nick, R, [{<<"service">>, Service}], [])], + Title ++ Breadcrumb ++ Set; -web_page_main(Acc, _) -> Acc. +webadmin_muc_host(_Host, Service, [<<"rooms-empty">> | RPath], R, _Lang, Level, PageTitle) -> + Title = ?H1GL(PageTitle, <<"modules/#mod_muc">>, <<"mod_muc">>), + Breadcrumb = make_breadcrumb({service_section, Level, Service, <<"Rooms Empty">>, RPath}), + Set = [make_command(rooms_empty_list, R, [{<<"service">>, Service}], + [{table_options, {2, RPath}}, + {result_links, [{room, room, 3+Level, <<"">>}]}]), + make_command(rooms_empty_destroy, R, [{<<"service">>, Service}], [])], + Title ++ Breadcrumb ++ Set; + +webadmin_muc_host(_Host, Service, [<<"rooms-unused">> | RPath], R, _Lang, Level, PageTitle) -> + Title = ?H1GL(PageTitle, <<"modules/#mod_muc">>, <<"mod_muc">>), + Breadcrumb = make_breadcrumb({service_section, Level, Service, <<"Rooms Unused">>, RPath}), + Set = [make_command(rooms_unused_list, R, + [{<<"service">>, Service}], + [{result_links, [{room, room, 3+Level, <<"">>}]}]), + make_command(rooms_unused_destroy, R, [{<<"service">>, Service}], [])], + Title ++ Breadcrumb ++ Set; + +webadmin_muc_host(_Host, Service, [<<"rooms-regex">> | RPath], R, _Lang, Level, PageTitle) -> + Title = ?H1GL(PageTitle, <<"modules/#mod_muc">>, <<"mod_muc">>), + Breadcrumb = make_breadcrumb({service_section, Level, Service, <<"Rooms by Regex">>, RPath}), + Set = [make_command(muc_online_rooms_by_regex, R, + [{<<"service">>, Service}], + [{result_links, [{jid, room, 3+Level, <<"">>}]}])], + Title ++ Breadcrumb ++ Set; -web_page_host(_, Host, #request{path = [<<"muc">>], q = Q, lang = Lang} = R) -> - PageTitle = translate:translate(Lang, ?T("Multi-User Chat")), +webadmin_muc_host(_Host, Service, [<<"rooms">>, <<"room">>, Name, <<"affiliations">> | RPath], R, _Lang, Level, PageTitle) -> Title = ?H1GL(PageTitle, <<"modules/#mod_muc">>, <<"mod_muc">>), - Res = [make_command(webadmin_host_muc_rooms, R, [{<<"host">>, Host}, {<<"query">>, Q}, {<<"lang">>, Lang}], [])], - {stop, Title ++ Res}; -web_page_host(Acc, _, _) -> Acc. + Breadcrumb = make_breadcrumb({room_section, Level, Service, <<"Affiliations">>, Name, R, RPath}), + Set = [make_command(set_room_affiliation, R, + [{<<"name">>, Name}, {<<"service">>, Service}], + [])], + Get = [make_command(get_room_affiliations, R, + [{<<"name">>, Name}, {<<"service">>, Service}], + [{table_options, {20, RPath}}])], + Title ++ Breadcrumb ++ Get ++ Set; + +webadmin_muc_host(_Host, Service, [<<"rooms">>, <<"room">>, Name, <<"history">> | RPath], R, _Lang, Level, PageTitle) -> + Title = ?H1GL(PageTitle, <<"modules/#mod_muc">>, <<"mod_muc">>), + Breadcrumb = make_breadcrumb({room_section, Level, Service, <<"History">>, Name, R, RPath}), + Get = [make_command(get_room_history, + R, + [{<<"name">>, Name}, {<<"service">>, Service}], + [{table_options, {10, RPath}}, + {result_links, [{message, paragraph, 1, <<"">>}]}])], + Title ++ Breadcrumb ++ Get; + +webadmin_muc_host(_Host, Service, [<<"rooms">>, <<"room">>, Name, <<"invite">> | RPath], R, _Lang, Level, PageTitle) -> + Title = ?H1GL(PageTitle, <<"modules/#mod_muc">>, <<"mod_muc">>), + Breadcrumb = make_breadcrumb({room_section, Level, Service, <<"Invite">>, Name, R, RPath}), + Set = [make_command(send_direct_invitation, R, + [{<<"name">>, Name}, {<<"service">>, Service}], + [])], + Title ++ Breadcrumb ++ Set; + +webadmin_muc_host(_Host, Service, [<<"rooms">>, <<"room">>, Name, <<"occupants">> | RPath], R, _Lang, Level, PageTitle) -> + Title = ?H1GL(PageTitle, <<"modules/#mod_muc">>, <<"mod_muc">>), + Breadcrumb = make_breadcrumb({room_section, Level, Service, <<"Occupants">>, Name, R, RPath}), + Get = [make_command(get_room_occupants, + R, + [{<<"name">>, Name}, {<<"service">>, Service}], + [{table_options, {20, RPath}}, + {result_links, [{jid, user, 3+Level, <<"">>}]}])], + Title ++ Breadcrumb ++ Get; + +webadmin_muc_host(_Host, Service, [<<"rooms">>, <<"room">>, Name, <<"options">> | RPath], R, _Lang, Level, PageTitle) -> + Title = ?H1GL(PageTitle, <<"modules/#mod_muc">>, <<"mod_muc">>), + Breadcrumb = make_breadcrumb({room_section, Level, Service, <<"Options">>, Name, R, RPath}), + Set = [make_command(change_room_option, R, + [{<<"name">>, Name}, {<<"service">>, Service}], + [])], + Get = [make_command(get_room_options, R, + [{<<"name">>, Name}, {<<"service">>, Service}], + [])], + Title ++ Breadcrumb ++ Get ++ Set; + +webadmin_muc_host(_Host, Service, [<<"rooms">>, <<"room">>, Name, <<"subscribers">> | RPath], R, _Lang, Level, PageTitle) -> + Title = ?H1GLraw(PageTitle, <<"developer/xmpp-clients-bots/extensions/muc-sub/">>, <<"MUC/Sub Extension">>), + Breadcrumb = make_breadcrumb({room_section, Level, Service, <<"Subscribers">>, Name, R, RPath}), + Set = [make_command(subscribe_room, R, + [{<<"room">>, jid:encode({Name, Service, <<"">>})}], + []), + make_command(unsubscribe_room, R, + [{<<"room">>, jid:encode({Name, Service, <<"">>})}], + [{style, danger}])], + Get = [make_command(get_subscribers, R, [{<<"name">>, Name}, {<<"service">>, Service}], + [{table_options, {20, RPath}}, + {result_links, [{jid, user, 3+Level, <<"">>}]}])], + Title ++ Breadcrumb ++ Get ++ Set; + +webadmin_muc_host(_Host, Service, [<<"rooms">>, <<"room">>, Name, <<"destroy">> | RPath], R, _Lang, Level, PageTitle) -> + Title = ?H1GL(PageTitle, <<"modules/#mod_muc">>, <<"mod_muc">>), + Breadcrumb = make_breadcrumb({room_section, Level, Service, <<"Destroy">>, Name, R, RPath}), + Set = [make_command(destroy_room, R, + [{<<"name">>, Name}, {<<"service">>, Service}], + [{style, danger}])], + Title ++ Breadcrumb ++ Set; +webadmin_muc_host(_Host, Service, [<<"rooms">>, <<"room">>, Name | _RPath], _R, Lang, Level, PageTitle) -> + Title = ?H1GL(PageTitle, <<"modules/#mod_muc">>, <<"mod_muc">>), + Breadcrumb = make_breadcrumb({room, Level, Service, Name}), + MenuItems = [{<<"affiliations/">>, <<"Affiliations">>}, + {<<"history/">>, <<"History">>}, + {<<"invite/">>, <<"Invite">>}, + {<<"occupants/">>, <<"Occupants">>}, + {<<"options/">>, <<"Options">>}, + {<<"subscribers/">>, <<"Subscribers">>}, + {<<"destroy/">>, <<"Destroy">>}], + Get = [?XE(<<"ul">>, [?LI([?ACT(MIU, MIN)]) || {MIU, MIN} <- MenuItems])], + Title ++ Breadcrumb ++ Get; + +webadmin_muc_host(_Host, Service, [<<"rooms">> | RPath], R, _Lang, Level, PageTitle) -> + Title = ?H1GL(PageTitle, <<"modules/#mod_muc">>, <<"mod_muc">>), + Breadcrumb = make_breadcrumb({service_section, Level, Service, <<"Rooms">>, RPath}), + Columns = [<<"jid">>, <<"occupants">>], + Rows = lists:map(fun(NameService) -> + #jid{user = Name} = jid:decode(NameService), + {make_command(echo, R, + [{<<"sentence">>, jid:encode({Name, Service, <<"">>})}], + [{only, raw_and_value}, + {result_links, [{sentence, room, 3+Level, <<"">>}]}]), + make_command(get_room_occupants_number, R, + [{<<"name">>, Name}, + {<<"service">>, Service}], + [{only, raw_and_value}]) + } + end, + make_command_raw_value(muc_online_rooms, R, [{<<"service">>, Service}]) + ), + Get = [make_command(muc_online_rooms, R, [], [{only, presentation}]), + make_command(get_room_occupants_number, R, [], [{only, presentation}]), + make_table(20, RPath, Columns, Rows)], + Title ++ Breadcrumb ++ Get; + +webadmin_muc_host(_Host, Service, [], _R, Lang, _Level, PageTitle) -> + Title = ?H1GL(PageTitle, <<"modules/#mod_muc">>, <<"mod_muc">>), + Breadcrumb = make_breadcrumb({service, Service}), + MenuItems = [{<<"create-room/">>, <<"Create Room">>}, + {<<"rooms/">>, <<"Rooms">>}, + {<<"rooms-regex/">>, <<"Rooms by Regex">>}, + {<<"rooms-empty/">>, <<"Rooms Empty">>}, + {<<"rooms-unused/">>, <<"Rooms Unused">>}, + {<<"nick-register/">>, <<"Nick Register">>} + ], + Get = [?XE(<<"ul">>, [?LI([?ACT(MIU, MIN)]) || {MIU, MIN} <- MenuItems])], + Title ++ Breadcrumb ++ Get; + +webadmin_muc_host(_Host, _Service, _RPath, _R, _Lang, _Level, _PageTitle) -> + []. + +make_breadcrumb({service, Service}) -> + make_breadcrumb([Service]); + +make_breadcrumb({service_section, Level, Service, Section, RPath}) -> + make_breadcrumb([{Level, Service}, + separator, + Section + | RPath]); + +make_breadcrumb({room, Level, Service, Name}) -> + make_breadcrumb( + [{Level, Service}, + separator, + {Level-1, <<"Rooms">>}, + separator, + jid:encode({Name, Service, <<"">>}) + ]); + +make_breadcrumb({room_section, Level, Service, Section, Name, R, RPath}) -> + make_breadcrumb([{Level, Service}, + separator, + {Level-1, <<"Rooms">>}, + separator, + make_command(echo, R, + [{<<"sentence">>, jid:encode({Name, Service, <<"">>})}], + [{only, value}, + {result_links, [{sentence, room, 3+Level, <<"">>}]}]), + separator, + Section + | RPath]); + +make_breadcrumb(Elements) -> + lists:map(fun({xmlel, _, _, _} = Xmlel) -> + Xmlel; + (<<"sort">>) -> + ?C(<<" +">>); + (<<"page">>) -> + ?C(<<" #">>); + (separator) -> + ?C(<<" > ">>); + (Bin) when is_binary(Bin) -> + ?C(Bin); + ({Level, Bin}) when is_integer(Level) and is_binary(Bin) -> + ?AC(binary:copy(<<"../">>, Level), Bin) + end, + Elements). + +%%--------------- +%% %% Returns: {normal | reverse, Integer} get_sort_query(Q) -> case catch get_sort_query2(Q) of - {ok, Res} -> Res; - _ -> {normal, 1} + {ok, Res} -> Res; + _ -> {normal, 1} end. get_sort_query2(Q) -> {value, {_, Binary}} = lists:keysearch(<<"sort">>, 1, Q), Integer = list_to_integer(string:strip(binary_to_list(Binary), right, $/)), case Integer >= 0 of - true -> {ok, {normal, Integer}}; - false -> {ok, {reverse, abs(Integer)}} + true -> {ok, {normal, Integer}}; + false -> {ok, {reverse, abs(Integer)}} end. -webadmin_muc(Lang) -> - OnlineRoomsNumber = lists:foldl( - fun(Host, Acc) -> - Acc + mod_muc:count_online_rooms(Host) - end, 0, find_hosts(global)), - [?XCT(<<"h3">>, ?T("Statistics")), - ?XAE(<<"table">>, [], - [?XE(<<"tbody">>, [?TDTD(?T("Total rooms"), OnlineRoomsNumber) - ]) - ]), - ?XE(<<"ul">>, [?LI([?ACT(<<"rooms/">>, ?T("List of rooms"))])]) - ]. - -webadmin_host_muc_rooms(Host, Q, Lang) -> +webadmin_muc(#request{q = Q} = R, Lang) -> {Sort_direction, Sort_column} = get_sort_query(Q), + Host = global, Service = find_service(Host), Rooms_names = get_online_rooms(Service), Rooms_infos = build_info_rooms(Rooms_names), Rooms_sorted = sort_rooms(Sort_direction, Sort_column, Rooms_infos), Rooms_prepared = prepare_rooms_infos(Rooms_sorted), TList = lists:map( - fun(Room) -> - ?XE(<<"tr">>, [?XC(<<"td">>, E) || E <- Room]) - end, Rooms_prepared), + fun([RoomJid | Room]) -> + JidLink = make_command(echo, R, + [{<<"sentence">>, RoomJid}], + [{only, value}, + {result_links, [{sentence, room, 1, <<"">>}]}]), + ?XE(<<"tr">>, + [?XE(<<"td">>, [JidLink]) | [?XC(<<"td">>, E) || E <- Room]] + ) + end, Rooms_prepared), Titles = [?T("Jabber ID"), - ?T("# participants"), - ?T("Last message"), - ?T("Public"), - ?T("Persistent"), - ?T("Logging"), - ?T("Just created"), - ?T("Room title"), - ?T("Node")], + ?T("# participants"), + ?T("Last message"), + ?T("Public"), + ?T("Persistent"), + ?T("Logging"), + ?T("Just created"), + ?T("Room title"), + ?T("Node")], {Titles_TR, _} = - lists:mapfoldl( - fun(Title, Num_column) -> - NCS = integer_to_binary(Num_column), - TD = ?XE(<<"td">>, [?CT(Title), - ?C(<<" ">>), - ?AC(<<"?sort=", NCS/binary>>, <<"<">>), - ?C(<<" ">>), - ?AC(<<"?sort=-", NCS/binary>>, <<">">>)]), - {TD, Num_column+1} - end, - 1, - Titles), + lists:mapfoldl( + fun(Title, Num_column) -> + NCS = integer_to_binary(Num_column), + TD = ?XE(<<"td">>, [?CT(Title), + ?C(<<" ">>), + ?AC(<<"?sort=", NCS/binary>>, <<"<">>), + ?C(<<" ">>), + ?AC(<<"?sort=-", NCS/binary>>, <<">">>)]), + {TD, Num_column+1} + end, + 1, + Titles), [?XCT(<<"h2">>, ?T("Chatrooms")), ?XE(<<"table">>, - [?XE(<<"thead">>, - [?XE(<<"tr">>, Titles_TR)] - ), - ?XE(<<"tbody">>, TList) - ] - ) + [?XE(<<"thead">>, + [?XE(<<"tr">>, Titles_TR)] + ), + ?XE(<<"tbody">>, TList) + ] + ) ]. sort_rooms(Direction, Column, Rooms) -> Rooms2 = lists:keysort(Column, Rooms), case Direction of - normal -> Rooms2; - reverse -> lists:reverse(Rooms2) + normal -> Rooms2; + reverse -> lists:reverse(Rooms2) end. build_info_rooms(Rooms) -> @@ -734,14 +954,14 @@ build_info_room({Name, Host, _ServerHost, Pid}) -> History = (S#state.history)#lqueue.queue, Ts_last_message = - case p1_queue:is_empty(History) of - true -> - <<"A long time ago">>; - false -> - Last_message1 = get_queue_last(History), - {_, _, _, Ts_last, _} = Last_message1, - xmpp_util:encode_timestamp(Ts_last) - end, + case p1_queue:is_empty(History) of + true -> + <<"A long time ago">>; + false -> + Last_message1 = get_queue_last(History), + {_, _, _, Ts_last, _} = Last_message1, + xmpp_util:encode_timestamp(Ts_last) + end, {<>, Num_participants, @@ -783,7 +1003,7 @@ justcreated_to_binary(J) when is_integer(J) -> JNow = misc:usec_to_now(J), {{Year, Month, Day}, {Hour, Minute, Second}} = calendar:now_to_local_time(JNow), str:format("~w-~.2.0w-~.2.0w ~.2.0w:~.2.0w:~.2.0w", - [Year, Month, Day, Hour, Minute, Second]); + [Year, Month, Day, Hour, Minute, Second]); justcreated_to_binary(J) when is_atom(J) -> misc:atom_to_binary(J). @@ -797,39 +1017,48 @@ web_menu_hostuser(Acc, _Host, _Username, _Lang) -> {<<"muc-register">>, <<"MUC Service Registration">>}]. web_page_hostuser(_, Host, User, #request{path = [<<"muc-rooms">> | RPath]} = R) -> + Level = 5 + length(RPath), Res = ?H1GL(<<"MUC Rooms Online">>, <<"modules/#mod_muc">>, <<"mod_muc">>) ++ [make_command(get_user_rooms, R, [{<<"user">>, User}, {<<"host">>, Host}], - [{table_options, {2, RPath}}])], + [{table_options, {2, RPath}}, + {result_links, [{room, room, Level, <<"">>}]} + ])], {stop, Res}; web_page_hostuser(_, Host, User, #request{path = [<<"muc-affiliations">>]} = R) -> Jid = jid:encode(jid:make(User, Host)), Res = ?H1GL(<<"MUC Rooms Affiliations">>, <<"modules/#mod_muc">>, <<"mod_muc">>) ++ [make_command(set_room_affiliation, R, [{<<"jid">>, Jid}], []), - make_command(get_room_affiliation, R, [{<<"jid">>, Jid}], [])], + make_command(get_room_affiliation, R, [{<<"jid">>, Jid}], [])], {stop, Res}; -web_page_hostuser(_, Host, User, #request{path = [<<"muc-sub">>]} = R) -> - Subs = make_command(get_user_subscriptions, R, [{<<"user">>, User}, {<<"host">>, Host}], []), - Res = ?H1GLraw(<<"MUC Rooms Subscriptions">>, - <<"developer/xmpp-clients-bots/extensions/muc-sub/">>, - <<"MUC/Sub">>) ++ - [Subs, - make_command(subscribe_room, R, [{<<"user">>, User}, {<<"host">>, Host}], []), - make_command(unsubscribe_room, R, [{<<"user">>, User}, {<<"host">>, Host}], [])], - {stop, Res}; +web_page_hostuser(_, Host, User, #request{path = [<<"muc-sub">> | RPath]} = R) -> + Title = ?H1GLraw(<<"MUC Rooms Subscriptions">>, + <<"developer/xmpp-clients-bots/extensions/muc-sub/">>, + <<"MUC/Sub">>), + Level = 5 + length(RPath), + Set = [make_command(subscribe_room, R, [{<<"user">>, User}, {<<"host">>, Host}], []), + make_command(unsubscribe_room, R, [{<<"user">>, User}, {<<"host">>, Host}], [])], + Get = [make_command(get_user_subscriptions, R, + [{<<"user">>, User}, {<<"host">>, Host}], + [{table_options, {20, RPath}}, + {result_links, [{roomjid, room, Level, <<"">>}]}])], + {stop, Title ++ Get ++ Set}; web_page_hostuser(_, Host, User, #request{path = [<<"muc-register">>]} = R) -> Jid = jid:encode(jid:make(User, Host)), Res = ?H1GL(<<"MUC Service Registration">>, <<"modules/#mod_muc">>, <<"mod_muc">>) ++ [make_command(muc_register_nick, R, [{<<"jid">>, Jid}], []), - make_command(muc_unregister_nick, R, [{<<"jid">>, Jid}], [])], + make_command(muc_unregister_nick, R, [{<<"jid">>, Jid}], [])], {stop, Res}; web_page_hostuser(Acc, _, _, _) -> Acc. +%% emacs-indent-end +%% emacs-untabify-end + %%---------------------------- %% Create/Delete Room %%---------------------------- @@ -961,6 +1190,10 @@ rooms_empty_list(Service) -> rooms_empty_destroy(Service) -> rooms_report(empty, destroy, Service, 0). +rooms_empty_destroy_restuple(Service) -> + DestroyedRooms = rooms_report(empty, destroy, Service, 0), + NumberBin = integer_to_binary(length(DestroyedRooms)), + {ok, <<"Destroyed rooms: ", NumberBin/binary>>}. rooms_report(Method, Action, Service, Days) -> {NA, NP, RP} = muc_unused(Method, Action, Service, Days), @@ -1476,7 +1709,8 @@ get_room_history(Name, Service) -> History = p1_queue:to_list((StateData#state.history)#lqueue.queue), lists:map( fun({_Nick, Packet, _HaveSubject, TimeStamp, _Size}) -> - {xmpp_util:encode_timestamp(TimeStamp), fxml:element_to_binary(xmpp:encode(Packet))} + {xmpp_util:encode_timestamp(TimeStamp), + ejabberd_web_admin:pretty_print_xml(xmpp:encode(Packet))} end, History); _ -> throw({error, "Unable to fetch room state."})