2015-04-07 16:30:34 +02:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : mod_muc_admin.erl
|
|
|
|
%%% Author : Badlop <badlop@ono.com>
|
|
|
|
%%% Purpose : Tools for additional MUC administration
|
|
|
|
%%% Created : 8 Sep 2007 by Badlop <badlop@ono.com>
|
2016-12-27 10:44:07 +01:00
|
|
|
%%%
|
|
|
|
%%%
|
2024-01-22 16:40:01 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2024 ProcessOne
|
2016-12-27 10:44:07 +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.
|
|
|
|
%%%
|
|
|
|
%%% 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.
|
|
|
|
%%%
|
2015-04-07 16:30:34 +02:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(mod_muc_admin).
|
|
|
|
-author('badlop@ono.com').
|
|
|
|
|
|
|
|
-behaviour(gen_mod).
|
|
|
|
|
2020-01-08 10:24:51 +01:00
|
|
|
-export([start/2, stop/1, reload/3, depends/2, mod_doc/0,
|
2017-12-13 04:07:12 +01:00
|
|
|
muc_online_rooms/1, muc_online_rooms_by_regex/2,
|
2017-08-24 10:40:24 +02:00
|
|
|
muc_register_nick/3, muc_unregister_nick/2,
|
2017-04-10 12:23:14 +02:00
|
|
|
create_room_with_opts/4, create_room/3, destroy_room/2,
|
2015-04-07 16:30:34 +02:00
|
|
|
create_rooms_file/1, destroy_rooms_file/1,
|
|
|
|
rooms_unused_list/2, rooms_unused_destroy/2,
|
2019-02-01 19:48:58 +01:00
|
|
|
rooms_empty_list/1, rooms_empty_destroy/1,
|
2021-03-08 20:43:33 +01:00
|
|
|
get_user_rooms/2, get_user_subscriptions/2, get_room_occupants/2,
|
2015-08-12 13:26:24 +02:00
|
|
|
get_room_occupants_number/2, send_direct_invitation/5,
|
2015-06-01 14:38:27 +02:00
|
|
|
change_room_option/4, get_room_options/2,
|
2018-02-25 10:28:14 +01:00
|
|
|
set_room_affiliation/4, get_room_affiliations/2, get_room_affiliation/3,
|
2015-06-01 14:38:27 +02:00
|
|
|
web_menu_main/2, web_page_main/2, web_menu_host/3,
|
2021-12-20 07:37:47 +01:00
|
|
|
subscribe_room/4, subscribe_room_many/3,
|
2022-09-01 13:37:48 +02:00
|
|
|
unsubscribe_room/2, get_subscribers/2,
|
|
|
|
get_room_serverhost/1,
|
|
|
|
web_page_host/3,
|
|
|
|
mod_opt_type/1, mod_options/1,
|
2022-09-22 11:11:02 +02:00
|
|
|
get_commands_spec/0, find_hosts/1, room_diagnostics/2,
|
2023-02-08 11:04:26 +01:00
|
|
|
get_room_pid/2, get_room_history/2]).
|
2015-04-07 16:30:34 +02:00
|
|
|
|
|
|
|
-include("logger.hrl").
|
2020-09-03 13:45:57 +02:00
|
|
|
-include_lib("xmpp/include/xmpp.hrl").
|
2017-04-10 12:23:14 +02:00
|
|
|
-include("mod_muc.hrl").
|
2015-04-07 16:30:34 +02:00
|
|
|
-include("mod_muc_room.hrl").
|
|
|
|
-include("ejabberd_http.hrl").
|
|
|
|
-include("ejabberd_web_admin.hrl").
|
|
|
|
-include("ejabberd_commands.hrl").
|
2019-06-22 16:08:45 +02:00
|
|
|
-include("translate.hrl").
|
2015-04-07 16:30:34 +02:00
|
|
|
|
|
|
|
%%----------------------------
|
|
|
|
%% gen_mod
|
|
|
|
%%----------------------------
|
|
|
|
|
|
|
|
start(Host, _Opts) ->
|
2021-07-29 23:13:17 +02:00
|
|
|
ejabberd_commands:register_commands(?MODULE, get_commands_spec()),
|
2015-04-07 16:30:34 +02:00
|
|
|
ejabberd_hooks:add(webadmin_menu_main, ?MODULE, web_menu_main, 50),
|
|
|
|
ejabberd_hooks:add(webadmin_menu_host, Host, ?MODULE, web_menu_host, 50),
|
|
|
|
ejabberd_hooks:add(webadmin_page_main, ?MODULE, web_page_main, 50),
|
|
|
|
ejabberd_hooks:add(webadmin_page_host, Host, ?MODULE, web_page_host, 50).
|
|
|
|
|
|
|
|
stop(Host) ->
|
2017-11-06 16:53:49 +01:00
|
|
|
case gen_mod:is_loaded_elsewhere(Host, ?MODULE) of
|
|
|
|
false ->
|
|
|
|
ejabberd_commands:unregister_commands(get_commands_spec());
|
|
|
|
true ->
|
|
|
|
ok
|
|
|
|
end,
|
2015-04-07 16:30:34 +02:00
|
|
|
ejabberd_hooks:delete(webadmin_menu_main, ?MODULE, web_menu_main, 50),
|
|
|
|
ejabberd_hooks:delete(webadmin_menu_host, Host, ?MODULE, web_menu_host, 50),
|
|
|
|
ejabberd_hooks:delete(webadmin_page_main, ?MODULE, web_page_main, 50),
|
|
|
|
ejabberd_hooks:delete(webadmin_page_host, Host, ?MODULE, web_page_host, 50).
|
|
|
|
|
2017-02-22 17:46:47 +01:00
|
|
|
reload(_Host, _NewOpts, _OldOpts) ->
|
|
|
|
ok.
|
|
|
|
|
2016-07-06 13:58:48 +02:00
|
|
|
depends(_Host, _Opts) ->
|
|
|
|
[{mod_muc, hard}].
|
|
|
|
|
2015-04-07 16:30:34 +02:00
|
|
|
%%%
|
|
|
|
%%% Register commands
|
|
|
|
%%%
|
|
|
|
|
2016-01-26 10:00:11 +01:00
|
|
|
get_commands_spec() ->
|
2015-04-07 16:30:34 +02:00
|
|
|
[
|
|
|
|
#ejabberd_commands{name = muc_online_rooms, tags = [muc],
|
2023-11-24 11:58:50 +01:00
|
|
|
desc = "List existing rooms",
|
|
|
|
longdesc = "Ask for a specific host, or `global` to use all vhosts.",
|
2015-09-28 14:25:43 +02:00
|
|
|
policy = admin,
|
2015-04-07 16:30:34 +02:00
|
|
|
module = ?MODULE, function = muc_online_rooms,
|
2023-11-24 11:58:50 +01:00
|
|
|
args_desc = ["MUC service, or `global` for all"],
|
2019-08-08 11:03:12 +02:00
|
|
|
args_example = ["muc.example.com"],
|
2017-05-22 12:55:32 +02:00
|
|
|
result_desc = "List of rooms",
|
|
|
|
result_example = ["room1@muc.example.com", "room2@muc.example.com"],
|
2019-08-08 11:03:12 +02:00
|
|
|
args = [{service, binary}],
|
|
|
|
args_rename = [{host, service}],
|
2015-04-07 16:30:34 +02:00
|
|
|
result = {rooms, {list, {room, string}}}},
|
2017-12-13 04:07:12 +01:00
|
|
|
#ejabberd_commands{name = muc_online_rooms_by_regex, tags = [muc],
|
2023-11-24 11:58:50 +01:00
|
|
|
desc = "List existing rooms filtered by regexp",
|
|
|
|
longdesc = "Ask for a specific host, or `global` to use all vhosts.",
|
2017-12-13 04:07:12 +01:00
|
|
|
policy = admin,
|
|
|
|
module = ?MODULE, function = muc_online_rooms_by_regex,
|
2023-11-24 11:58:50 +01:00
|
|
|
args_desc = ["MUC service, or `global` for all",
|
2017-12-13 04:07:12 +01:00
|
|
|
"Regex pattern for room name"],
|
2019-08-08 11:03:12 +02:00
|
|
|
args_example = ["muc.example.com", "^prefix"],
|
2017-12-13 04:07:12 +01:00
|
|
|
result_desc = "List of rooms with summary",
|
2019-03-28 17:42:25 +01:00
|
|
|
result_example = [{"room1@muc.example.com", "true", 10},
|
2017-12-13 04:07:12 +01:00
|
|
|
{"room2@muc.example.com", "false", 10}],
|
2019-08-08 11:03:12 +02:00
|
|
|
args = [{service, binary}, {regex, binary}],
|
|
|
|
args_rename = [{host, service}],
|
2017-12-13 04:07:12 +01:00
|
|
|
result = {rooms, {list, {room, {tuple,
|
|
|
|
[{jid, string},
|
|
|
|
{public, string},
|
|
|
|
{participants, integer}
|
2019-03-28 17:42:25 +01:00
|
|
|
]}}}}},
|
2017-04-10 12:23:14 +02:00
|
|
|
#ejabberd_commands{name = muc_register_nick, tags = [muc],
|
2019-08-08 11:03:12 +02:00
|
|
|
desc = "Register a nick to a User JID in a MUC service",
|
2017-04-10 12:23:14 +02:00
|
|
|
module = ?MODULE, function = muc_register_nick,
|
2019-08-08 11:03:12 +02:00
|
|
|
args_desc = ["Nick", "User JID", "Service"],
|
|
|
|
args_example = [<<"Tim">>, <<"tim@example.org">>, <<"muc.example.org">>],
|
|
|
|
args = [{nick, binary}, {jid, binary}, {service, binary}],
|
|
|
|
args_rename = [{host, service}],
|
2017-04-10 12:23:14 +02:00
|
|
|
result = {res, rescode}},
|
2015-04-07 16:30:34 +02:00
|
|
|
#ejabberd_commands{name = muc_unregister_nick, tags = [muc],
|
2017-08-24 10:40:24 +02:00
|
|
|
desc = "Unregister the nick registered by that account in the MUC service",
|
2015-04-07 16:30:34 +02:00
|
|
|
module = ?MODULE, function = muc_unregister_nick,
|
2017-08-24 10:40:24 +02:00
|
|
|
args_desc = ["User JID", "MUC service"],
|
2019-08-08 11:03:12 +02:00
|
|
|
args_example = [<<"tim@example.org">>, <<"muc.example.org">>],
|
|
|
|
args = [{jid, binary}, {service, binary}],
|
|
|
|
args_rename = [{host, service}],
|
2015-04-07 16:30:34 +02:00
|
|
|
result = {res, rescode}},
|
|
|
|
|
|
|
|
#ejabberd_commands{name = create_room, tags = [muc_room],
|
|
|
|
desc = "Create a MUC room name@service in host",
|
|
|
|
module = ?MODULE, function = create_room,
|
2017-05-22 12:55:32 +02:00
|
|
|
args_desc = ["Room name", "MUC service", "Server host"],
|
|
|
|
args_example = ["room1", "muc.example.com", "example.com"],
|
2015-04-07 16:30:34 +02:00
|
|
|
args = [{name, binary}, {service, binary},
|
|
|
|
{host, binary}],
|
|
|
|
result = {res, rescode}},
|
|
|
|
#ejabberd_commands{name = destroy_room, tags = [muc_room],
|
|
|
|
desc = "Destroy a MUC room",
|
|
|
|
module = ?MODULE, function = destroy_room,
|
2017-05-22 12:55:32 +02:00
|
|
|
args_desc = ["Room name", "MUC service"],
|
|
|
|
args_example = ["room1", "muc.example.com"],
|
2015-08-12 13:26:24 +02:00
|
|
|
args = [{name, binary}, {service, binary}],
|
2015-04-07 16:30:34 +02:00
|
|
|
result = {res, rescode}},
|
|
|
|
#ejabberd_commands{name = create_rooms_file, tags = [muc],
|
|
|
|
desc = "Create the rooms indicated in file",
|
2015-08-12 17:18:41 +02:00
|
|
|
longdesc = "Provide one room JID per line. Rooms will be created after restart.",
|
2015-04-07 16:30:34 +02:00
|
|
|
module = ?MODULE, function = create_rooms_file,
|
2017-05-22 12:55:32 +02:00
|
|
|
args_desc = ["Path to the text file with one room JID per line"],
|
|
|
|
args_example = ["/home/ejabberd/rooms.txt"],
|
2015-04-07 16:30:34 +02:00
|
|
|
args = [{file, string}],
|
|
|
|
result = {res, rescode}},
|
2023-11-23 17:12:43 +01:00
|
|
|
#ejabberd_commands{name = create_room_with_opts, tags = [muc_room, muc_sub],
|
2016-09-13 11:52:59 +02:00
|
|
|
desc = "Create a MUC room name@service in host with given options",
|
2023-08-14 12:37:05 +02:00
|
|
|
longdesc =
|
2023-08-14 13:59:43 +02:00
|
|
|
"The syntax of `affiliations` is: `Type:JID,Type:JID`. "
|
|
|
|
"The syntax of `subscribers` is: `JID:Nick:Node:Node2:Node3,JID:Nick:Node`.",
|
2016-09-13 11:52:59 +02:00
|
|
|
module = ?MODULE, function = create_room_with_opts,
|
2017-05-22 12:55:32 +02:00
|
|
|
args_desc = ["Room name", "MUC service", "Server host", "List of options"],
|
2023-02-20 13:03:46 +01:00
|
|
|
args_example = ["room1", "muc.example.com", "localhost",
|
2023-08-14 12:37:05 +02:00
|
|
|
[{"members_only","true"},
|
|
|
|
{"affiliations", "owner:bob@example.com,member:peter@example.com"},
|
|
|
|
{"subscribers", "bob@example.com:Bob:messages:subject,anne@example.com:Anne:messages"}]],
|
2016-09-13 11:52:59 +02:00
|
|
|
args = [{name, binary}, {service, binary},
|
|
|
|
{host, binary},
|
|
|
|
{options, {list,
|
|
|
|
{option, {tuple,
|
|
|
|
[{name, binary},
|
|
|
|
{value, binary}
|
|
|
|
]}}
|
|
|
|
}}],
|
|
|
|
result = {res, rescode}},
|
2015-04-07 16:30:34 +02:00
|
|
|
#ejabberd_commands{name = destroy_rooms_file, tags = [muc],
|
|
|
|
desc = "Destroy the rooms indicated in file",
|
2015-08-12 17:18:41 +02:00
|
|
|
longdesc = "Provide one room JID per line.",
|
2015-04-07 16:30:34 +02:00
|
|
|
module = ?MODULE, function = destroy_rooms_file,
|
2017-05-22 12:55:32 +02:00
|
|
|
args_desc = ["Path to the text file with one room JID per line"],
|
|
|
|
args_example = ["/home/ejabberd/rooms.txt"],
|
2015-04-07 16:30:34 +02:00
|
|
|
args = [{file, string}],
|
|
|
|
result = {res, rescode}},
|
|
|
|
#ejabberd_commands{name = rooms_unused_list, tags = [muc],
|
2019-08-08 11:03:12 +02:00
|
|
|
desc = "List the rooms that are unused for many days in the service",
|
2019-02-06 16:33:36 +01:00
|
|
|
longdesc = "The room recent history is used, so it's recommended "
|
2019-08-12 13:24:48 +02:00
|
|
|
" to wait a few days after service start before running this."
|
2023-08-14 13:59:43 +02:00
|
|
|
" The MUC service argument can be `global` to get all hosts.",
|
2015-04-07 16:30:34 +02:00
|
|
|
module = ?MODULE, function = rooms_unused_list,
|
2023-08-14 13:59:43 +02:00
|
|
|
args_desc = ["MUC service, or `global` for all", "Number of days"],
|
2019-08-08 11:03:12 +02:00
|
|
|
args_example = ["muc.example.com", 31],
|
2017-05-22 12:55:32 +02:00
|
|
|
result_desc = "List of unused rooms",
|
|
|
|
result_example = ["room1@muc.example.com", "room2@muc.example.com"],
|
2019-08-08 11:03:12 +02:00
|
|
|
args = [{service, binary}, {days, integer}],
|
|
|
|
args_rename = [{host, service}],
|
2015-04-07 16:30:34 +02:00
|
|
|
result = {rooms, {list, {room, string}}}},
|
|
|
|
#ejabberd_commands{name = rooms_unused_destroy, tags = [muc],
|
2019-08-08 11:03:12 +02:00
|
|
|
desc = "Destroy the rooms that are unused for many days in the service",
|
2019-02-06 16:33:36 +01:00
|
|
|
longdesc = "The room recent history is used, so it's recommended "
|
2019-08-12 13:24:48 +02:00
|
|
|
" to wait a few days after service start before running this."
|
2023-08-14 13:59:43 +02:00
|
|
|
" The MUC service argument can be `global` to get all hosts.",
|
2015-04-07 16:30:34 +02:00
|
|
|
module = ?MODULE, function = rooms_unused_destroy,
|
2023-08-14 13:59:43 +02:00
|
|
|
args_desc = ["MUC service, or `global` for all", "Number of days"],
|
2019-08-08 11:03:12 +02:00
|
|
|
args_example = ["muc.example.com", 31],
|
2017-05-22 12:55:32 +02:00
|
|
|
result_desc = "List of unused rooms that has been destroyed",
|
|
|
|
result_example = ["room1@muc.example.com", "room2@muc.example.com"],
|
2019-08-08 11:03:12 +02:00
|
|
|
args = [{service, binary}, {days, integer}],
|
|
|
|
args_rename = [{host, service}],
|
2015-04-07 16:30:34 +02:00
|
|
|
result = {rooms, {list, {room, string}}}},
|
|
|
|
|
2019-02-01 19:48:58 +01:00
|
|
|
#ejabberd_commands{name = rooms_empty_list, tags = [muc],
|
|
|
|
desc = "List the rooms that have no messages in archive",
|
2023-08-14 13:59:43 +02:00
|
|
|
longdesc = "The MUC service argument can be `global` to get all hosts.",
|
2019-02-01 19:48:58 +01:00
|
|
|
module = ?MODULE, function = rooms_empty_list,
|
2023-08-14 13:59:43 +02:00
|
|
|
args_desc = ["MUC service, or `global` for all"],
|
2019-08-08 11:03:12 +02:00
|
|
|
args_example = ["muc.example.com"],
|
2019-02-01 19:48:58 +01:00
|
|
|
result_desc = "List of empty rooms",
|
|
|
|
result_example = ["room1@muc.example.com", "room2@muc.example.com"],
|
2019-08-08 11:03:12 +02:00
|
|
|
args = [{service, binary}],
|
|
|
|
args_rename = [{host, service}],
|
2019-02-01 19:48:58 +01:00
|
|
|
result = {rooms, {list, {room, string}}}},
|
|
|
|
#ejabberd_commands{name = rooms_empty_destroy, tags = [muc],
|
|
|
|
desc = "Destroy the rooms that have no messages in archive",
|
2023-08-14 13:59:43 +02:00
|
|
|
longdesc = "The MUC service argument can be `global` to get all hosts.",
|
2019-02-01 19:48:58 +01:00
|
|
|
module = ?MODULE, function = rooms_empty_destroy,
|
2023-08-14 13:59:43 +02:00
|
|
|
args_desc = ["MUC service, or `global` for all"],
|
2019-08-08 11:03:12 +02:00
|
|
|
args_example = ["muc.example.com"],
|
2019-02-01 19:48:58 +01:00
|
|
|
result_desc = "List of empty rooms that have been destroyed",
|
|
|
|
result_example = ["room1@muc.example.com", "room2@muc.example.com"],
|
2019-08-08 11:03:12 +02:00
|
|
|
args = [{service, binary}],
|
|
|
|
args_rename = [{host, service}],
|
2019-02-01 19:48:58 +01:00
|
|
|
result = {rooms, {list, {room, string}}}},
|
|
|
|
|
2015-04-29 13:21:41 +02:00
|
|
|
#ejabberd_commands{name = get_user_rooms, tags = [muc],
|
|
|
|
desc = "Get the list of rooms where this user is occupant",
|
|
|
|
module = ?MODULE, function = get_user_rooms,
|
2017-05-22 12:55:32 +02:00
|
|
|
args_desc = ["Username", "Server host"],
|
|
|
|
args_example = ["tom", "example.com"],
|
|
|
|
result_example = ["room1@muc.example.com", "room2@muc.example.com"],
|
2015-04-29 13:21:41 +02:00
|
|
|
args = [{user, binary}, {host, binary}],
|
|
|
|
result = {rooms, {list, {room, string}}}},
|
2023-11-23 17:12:43 +01:00
|
|
|
#ejabberd_commands{name = get_user_subscriptions, tags = [muc, muc_sub],
|
2021-03-08 20:43:33 +01:00
|
|
|
desc = "Get the list of rooms where this user is subscribed",
|
2021-05-05 11:43:49 +02:00
|
|
|
note = "added in 21.04",
|
2021-03-08 20:43:33 +01:00
|
|
|
module = ?MODULE, function = get_user_subscriptions,
|
|
|
|
args_desc = ["Username", "Server host"],
|
|
|
|
args_example = ["tom", "example.com"],
|
|
|
|
result_example = [{"room1@muc.example.com", "Tommy", ["mucsub:config"]}],
|
|
|
|
args = [{user, binary}, {host, binary}],
|
|
|
|
result = {rooms,
|
|
|
|
{list,
|
|
|
|
{room,
|
|
|
|
{tuple,
|
|
|
|
[{roomjid, string},
|
|
|
|
{usernick, string},
|
|
|
|
{nodes, {list, {node, string}}}
|
|
|
|
]}}
|
|
|
|
}}},
|
2015-04-29 13:21:41 +02:00
|
|
|
|
2015-04-07 16:30:34 +02:00
|
|
|
#ejabberd_commands{name = get_room_occupants, tags = [muc_room],
|
|
|
|
desc = "Get the list of occupants of a MUC room",
|
|
|
|
module = ?MODULE, function = get_room_occupants,
|
2017-05-22 12:55:32 +02:00
|
|
|
args_desc = ["Room name", "MUC service"],
|
|
|
|
args_example = ["room1", "muc.example.com"],
|
|
|
|
result_desc = "The list of occupants with JID, nick and affiliation",
|
|
|
|
result_example = [{"user1@example.com/psi", "User 1", "owner"}],
|
2015-04-07 16:30:34 +02:00
|
|
|
args = [{name, binary}, {service, binary}],
|
|
|
|
result = {occupants, {list,
|
|
|
|
{occupant, {tuple,
|
|
|
|
[{jid, string},
|
|
|
|
{nick, string},
|
|
|
|
{role, string}
|
|
|
|
]}}
|
|
|
|
}}},
|
|
|
|
|
|
|
|
#ejabberd_commands{name = get_room_occupants_number, tags = [muc_room],
|
|
|
|
desc = "Get the number of occupants of a MUC room",
|
|
|
|
module = ?MODULE, function = get_room_occupants_number,
|
2017-05-22 12:55:32 +02:00
|
|
|
args_desc = ["Room name", "MUC service"],
|
|
|
|
args_example = ["room1", "muc.example.com"],
|
|
|
|
result_desc = "Number of room occupants",
|
|
|
|
result_example = 7,
|
2015-04-07 16:30:34 +02:00
|
|
|
args = [{name, binary}, {service, binary}],
|
|
|
|
result = {occupants, integer}},
|
|
|
|
|
|
|
|
#ejabberd_commands{name = send_direct_invitation, tags = [muc_room],
|
|
|
|
desc = "Send a direct invitation to several destinations",
|
2022-01-10 16:45:35 +01:00
|
|
|
longdesc = "Since ejabberd 20.12, this command is "
|
2020-10-16 15:24:52 +02:00
|
|
|
"asynchronous: the API call may return before the "
|
|
|
|
"server has send all the invitations.\n\n"
|
2023-08-14 13:59:43 +02:00
|
|
|
"Password and Message can also be: `none`. "
|
|
|
|
"Users JIDs are separated with `:`.",
|
2015-04-07 16:30:34 +02:00
|
|
|
module = ?MODULE, function = send_direct_invitation,
|
2023-08-14 13:59:43 +02:00
|
|
|
args_desc = ["Room name", "MUC service", "Password, or `none`",
|
|
|
|
"Reason text, or `none`", "Users JIDs separated with `:` characters"],
|
2017-06-19 16:31:07 +02:00
|
|
|
args_example = [<<"room1">>, <<"muc.example.com">>,
|
|
|
|
<<>>, <<"Check this out!">>,
|
|
|
|
"user2@localhost:user3@example.com"],
|
|
|
|
args = [{name, binary}, {service, binary}, {password, binary},
|
|
|
|
{reason, binary}, {users, binary}],
|
2015-04-07 16:30:34 +02:00
|
|
|
result = {res, rescode}},
|
2023-11-29 19:04:57 +01:00
|
|
|
#ejabberd_commands{name = send_direct_invitation, tags = [muc_room],
|
|
|
|
desc = "Send a direct invitation to several destinations",
|
|
|
|
longdesc = "Since ejabberd 20.12, this command is "
|
|
|
|
"asynchronous: the API call may return before the "
|
|
|
|
"server has send all the invitations.\n\n"
|
|
|
|
"`password` and `message` can be set to `none`.",
|
|
|
|
module = ?MODULE, function = send_direct_invitation,
|
|
|
|
version = 1,
|
2024-02-24 17:40:03 +01:00
|
|
|
note = "updated in 24.02",
|
2023-11-29 19:04:57 +01:00
|
|
|
args_desc = ["Room name", "MUC service", "Password, or `none`",
|
|
|
|
"Reason text, or `none`", "List of users JIDs"],
|
|
|
|
args_example = [<<"room1">>, <<"muc.example.com">>,
|
|
|
|
<<>>, <<"Check this out!">>,
|
|
|
|
["user2@localhost", "user3@example.com"]],
|
|
|
|
args = [{name, binary}, {service, binary}, {password, binary},
|
|
|
|
{reason, binary}, {users, {list, {jid, binary}}}],
|
|
|
|
result = {res, rescode}},
|
2015-04-07 16:30:34 +02:00
|
|
|
|
|
|
|
#ejabberd_commands{name = change_room_option, tags = [muc_room],
|
|
|
|
desc = "Change an option in a MUC room",
|
|
|
|
module = ?MODULE, function = change_room_option,
|
2017-05-22 12:55:32 +02:00
|
|
|
args_desc = ["Room name", "MUC service", "Option name", "Value to assign"],
|
|
|
|
args_example = ["room1", "muc.example.com", "members_only", "true"],
|
2015-04-07 16:30:34 +02:00
|
|
|
args = [{name, binary}, {service, binary},
|
|
|
|
{option, binary}, {value, binary}],
|
|
|
|
result = {res, rescode}},
|
2015-05-15 17:47:10 +02:00
|
|
|
#ejabberd_commands{name = get_room_options, tags = [muc_room],
|
|
|
|
desc = "Get options from a MUC room",
|
|
|
|
module = ?MODULE, function = get_room_options,
|
2017-05-22 12:55:32 +02:00
|
|
|
args_desc = ["Room name", "MUC service"],
|
|
|
|
args_example = ["room1", "muc.example.com"],
|
|
|
|
result_desc = "List of room options tuples with name and value",
|
|
|
|
result_example = [{"members_only", "true"}],
|
2015-05-15 17:47:10 +02:00
|
|
|
args = [{name, binary}, {service, binary}],
|
|
|
|
result = {options, {list,
|
|
|
|
{option, {tuple,
|
|
|
|
[{name, string},
|
|
|
|
{value, string}
|
|
|
|
]}}
|
|
|
|
}}},
|
2023-11-23 17:12:43 +01:00
|
|
|
#ejabberd_commands{name = subscribe_room, tags = [muc_room, muc_sub],
|
2016-08-09 12:36:43 +02:00
|
|
|
desc = "Subscribe to a MUC conference",
|
|
|
|
module = ?MODULE, function = subscribe_room,
|
2018-12-10 21:06:26 +01:00
|
|
|
args_desc = ["User JID", "a user's nick",
|
2023-08-14 13:59:43 +02:00
|
|
|
"the room to subscribe", "nodes separated by commas: `,`"],
|
2018-12-10 21:06:26 +01:00
|
|
|
args_example = ["tom@localhost", "Tom", "room1@conference.localhost",
|
2017-05-22 12:55:32 +02:00
|
|
|
"urn:xmpp:mucsub:nodes:messages,urn:xmpp:mucsub:nodes:affiliations"],
|
|
|
|
result_desc = "The list of nodes that has subscribed",
|
|
|
|
result_example = ["urn:xmpp:mucsub:nodes:messages",
|
|
|
|
"urn:xmpp:mucsub:nodes:affiliations"],
|
2016-08-09 12:36:43 +02:00
|
|
|
args = [{user, binary}, {nick, binary}, {room, binary},
|
|
|
|
{nodes, binary}],
|
2016-08-10 11:16:20 +02:00
|
|
|
result = {nodes, {list, {node, string}}}},
|
2023-11-29 19:04:57 +01:00
|
|
|
#ejabberd_commands{name = subscribe_room, tags = [muc_room, muc_sub],
|
|
|
|
desc = "Subscribe to a MUC conference",
|
|
|
|
module = ?MODULE, function = subscribe_room,
|
|
|
|
version = 1,
|
2024-02-24 17:40:03 +01:00
|
|
|
note = "updated in 24.02",
|
2023-11-29 19:04:57 +01:00
|
|
|
args_desc = ["User JID", "a user's nick",
|
|
|
|
"the room to subscribe", "list of nodes"],
|
|
|
|
args_example = ["tom@localhost", "Tom", "room1@conference.localhost",
|
|
|
|
["urn:xmpp:mucsub:nodes:messages", "urn:xmpp:mucsub:nodes:affiliations"]],
|
|
|
|
result_desc = "The list of nodes that has subscribed",
|
|
|
|
result_example = ["urn:xmpp:mucsub:nodes:messages",
|
|
|
|
"urn:xmpp:mucsub:nodes:affiliations"],
|
|
|
|
args = [{user, binary}, {nick, binary}, {room, binary},
|
|
|
|
{nodes, {list, {node, binary}}}],
|
|
|
|
result = {nodes, {list, {node, string}}}},
|
2023-11-23 17:12:43 +01:00
|
|
|
#ejabberd_commands{name = subscribe_room_many, tags = [muc_room, muc_sub],
|
2021-12-20 07:37:47 +01:00
|
|
|
desc = "Subscribe several users to a MUC conference",
|
2022-05-04 15:18:57 +02:00
|
|
|
note = "added in 22.05",
|
2023-08-14 13:59:43 +02:00
|
|
|
longdesc = "This command accepts up to 50 users at once "
|
|
|
|
"(this is configurable with the *`mod_muc_admin`* option "
|
|
|
|
"`subscribe_room_many_max_users`)",
|
2021-12-20 07:37:47 +01:00
|
|
|
module = ?MODULE, function = subscribe_room_many,
|
|
|
|
args_desc = ["Users JIDs and nicks",
|
|
|
|
"the room to subscribe",
|
2023-08-14 13:59:43 +02:00
|
|
|
"nodes separated by commas: `,`"],
|
2021-12-20 07:37:47 +01:00
|
|
|
args_example = [[{"tom@localhost", "Tom"},
|
|
|
|
{"jerry@localhost", "Jerry"}],
|
|
|
|
"room1@conference.localhost",
|
|
|
|
"urn:xmpp:mucsub:nodes:messages,urn:xmpp:mucsub:nodes:affiliations"],
|
|
|
|
args = [{users, {list,
|
|
|
|
{user, {tuple,
|
|
|
|
[{jid, binary},
|
|
|
|
{nick, binary}
|
|
|
|
]}}
|
|
|
|
}},
|
|
|
|
{room, binary},
|
|
|
|
{nodes, binary}],
|
|
|
|
result = {res, rescode}},
|
2023-11-29 19:04:57 +01:00
|
|
|
#ejabberd_commands{name = subscribe_room_many, tags = [muc_room, muc_sub],
|
|
|
|
desc = "Subscribe several users to a MUC conference",
|
|
|
|
longdesc = "This command accepts up to 50 users at once "
|
|
|
|
"(this is configurable with the *`mod_muc_admin`* option "
|
|
|
|
"`subscribe_room_many_max_users`)",
|
|
|
|
module = ?MODULE, function = subscribe_room_many,
|
|
|
|
version = 1,
|
2024-02-24 17:40:03 +01:00
|
|
|
note = "updated in 24.02",
|
2023-11-29 19:04:57 +01:00
|
|
|
args_desc = ["Users JIDs and nicks",
|
|
|
|
"the room to subscribe",
|
|
|
|
"nodes separated by commas: `,`"],
|
|
|
|
args_example = [[{"tom@localhost", "Tom"},
|
|
|
|
{"jerry@localhost", "Jerry"}],
|
|
|
|
"room1@conference.localhost",
|
|
|
|
["urn:xmpp:mucsub:nodes:messages", "urn:xmpp:mucsub:nodes:affiliations"]],
|
|
|
|
args = [{users, {list,
|
|
|
|
{user, {tuple,
|
|
|
|
[{jid, binary},
|
|
|
|
{nick, binary}
|
|
|
|
]}}
|
|
|
|
}},
|
|
|
|
{room, binary},
|
|
|
|
{nodes, {list, {node, binary}}}],
|
|
|
|
result = {res, rescode}},
|
2023-11-23 17:12:43 +01:00
|
|
|
#ejabberd_commands{name = unsubscribe_room, tags = [muc_room, muc_sub],
|
2016-08-09 12:36:43 +02:00
|
|
|
desc = "Unsubscribe from a MUC conference",
|
|
|
|
module = ?MODULE, function = unsubscribe_room,
|
2017-05-22 12:55:32 +02:00
|
|
|
args_desc = ["User JID", "the room to subscribe"],
|
|
|
|
args_example = ["tom@localhost", "room1@conference.localhost"],
|
2016-08-09 12:36:43 +02:00
|
|
|
args = [{user, binary}, {room, binary}],
|
|
|
|
result = {res, rescode}},
|
2023-11-23 17:12:43 +01:00
|
|
|
#ejabberd_commands{name = get_subscribers, tags = [muc_room, muc_sub],
|
2016-09-06 16:55:18 +02:00
|
|
|
desc = "List subscribers of a MUC conference",
|
|
|
|
module = ?MODULE, function = get_subscribers,
|
2017-05-22 12:55:32 +02:00
|
|
|
args_desc = ["Room name", "MUC service"],
|
|
|
|
args_example = ["room1", "muc.example.com"],
|
|
|
|
result_desc = "The list of users that are subscribed to that room",
|
|
|
|
result_example = ["user2@example.com", "user3@example.com"],
|
2016-09-06 16:55:18 +02:00
|
|
|
args = [{name, binary}, {service, binary}],
|
|
|
|
result = {subscribers, {list, {jid, string}}}},
|
2015-04-07 16:30:34 +02:00
|
|
|
#ejabberd_commands{name = set_room_affiliation, tags = [muc_room],
|
|
|
|
desc = "Change an affiliation in a MUC room",
|
|
|
|
module = ?MODULE, function = set_room_affiliation,
|
2017-05-22 12:55:32 +02:00
|
|
|
args_desc = ["Room name", "MUC service", "User JID", "Affiliation to set"],
|
|
|
|
args_example = ["room1", "muc.example.com", "user2@example.com", "member"],
|
2015-04-07 16:30:34 +02:00
|
|
|
args = [{name, binary}, {service, binary},
|
|
|
|
{jid, binary}, {affiliation, binary}],
|
|
|
|
result = {res, rescode}},
|
|
|
|
#ejabberd_commands{name = get_room_affiliations, tags = [muc_room],
|
|
|
|
desc = "Get the list of affiliations of a MUC room",
|
|
|
|
module = ?MODULE, function = get_room_affiliations,
|
2017-05-22 12:55:32 +02:00
|
|
|
args_desc = ["Room name", "MUC service"],
|
|
|
|
args_example = ["room1", "muc.example.com"],
|
|
|
|
result_desc = "The list of affiliations with username, domain, affiliation and reason",
|
2017-06-19 16:31:07 +02:00
|
|
|
result_example = [{"user1", "example.com", member, "member"}],
|
2015-04-07 16:30:34 +02:00
|
|
|
args = [{name, binary}, {service, binary}],
|
|
|
|
result = {affiliations, {list,
|
|
|
|
{affiliation, {tuple,
|
|
|
|
[{username, string},
|
|
|
|
{domain, string},
|
|
|
|
{affiliation, atom},
|
|
|
|
{reason, string}
|
|
|
|
]}}
|
2018-02-25 10:28:14 +01:00
|
|
|
}}},
|
|
|
|
#ejabberd_commands{name = get_room_affiliation, tags = [muc_room],
|
|
|
|
desc = "Get affiliation of a user in MUC room",
|
|
|
|
module = ?MODULE, function = get_room_affiliation,
|
|
|
|
args_desc = ["Room name", "MUC service", "User JID"],
|
|
|
|
args_example = ["room1", "muc.example.com", "user1@example.com"],
|
|
|
|
result_desc = "Affiliation of the user",
|
2018-03-01 19:45:16 +01:00
|
|
|
result_example = member,
|
2018-02-25 10:28:14 +01:00
|
|
|
args = [{name, binary}, {service, binary}, {jid, binary}],
|
2023-02-08 11:04:26 +01:00
|
|
|
result = {affiliation, atom}},
|
|
|
|
#ejabberd_commands{name = get_room_history, tags = [muc_room],
|
|
|
|
desc = "Get history of messages stored inside MUC room state",
|
2023-04-17 12:34:30 +02:00
|
|
|
note = "added in 23.04",
|
2023-02-08 11:04:26 +01:00
|
|
|
module = ?MODULE, function = get_room_history,
|
|
|
|
args_desc = ["Room name", "MUC service"],
|
|
|
|
args_example = ["room1", "muc.example.com"],
|
|
|
|
args = [{name, binary}, {service, binary}],
|
|
|
|
result = {history, {list,
|
|
|
|
{entry, {tuple,
|
|
|
|
[{timestamp, string},
|
|
|
|
{message, string}]}}}}}
|
2018-02-25 10:28:14 +01:00
|
|
|
].
|
2015-04-07 16:30:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
%%%
|
|
|
|
%%% ejabberd commands
|
|
|
|
%%%
|
|
|
|
|
2019-08-08 11:03:12 +02:00
|
|
|
muc_online_rooms(ServiceArg) ->
|
2024-02-28 12:01:14 +01:00
|
|
|
Hosts = find_services_validate(ServiceArg, <<"serverhost">>),
|
2017-01-13 10:03:39 +01:00
|
|
|
lists:flatmap(
|
|
|
|
fun(Host) ->
|
2017-05-22 12:55:32 +02:00
|
|
|
[<<Name/binary, "@", Host/binary>>
|
2017-01-13 10:03:39 +01:00
|
|
|
|| {Name, _, _} <- mod_muc:get_online_rooms(Host)]
|
|
|
|
end, Hosts).
|
2015-04-07 16:30:34 +02:00
|
|
|
|
2019-08-08 11:03:12 +02:00
|
|
|
muc_online_rooms_by_regex(ServiceArg, Regex) ->
|
|
|
|
{_, P} = re:compile(Regex),
|
2024-02-28 12:01:14 +01:00
|
|
|
Hosts = find_services_validate(ServiceArg, <<"serverhost">>),
|
2017-12-13 04:07:12 +01:00
|
|
|
lists:flatmap(
|
|
|
|
fun(Host) ->
|
|
|
|
[build_summary_room(Name, RoomHost, Pid)
|
|
|
|
|| {Name, RoomHost, Pid} <- mod_muc:get_online_rooms(Host),
|
|
|
|
is_name_match(Name, P)]
|
|
|
|
end, Hosts).
|
|
|
|
|
|
|
|
is_name_match(Name, P) ->
|
|
|
|
case re:run(Name, P) of
|
|
|
|
{match, _} -> true;
|
|
|
|
nomatch -> false
|
|
|
|
end.
|
|
|
|
|
|
|
|
build_summary_room(Name, Host, Pid) ->
|
|
|
|
C = get_room_config(Pid),
|
|
|
|
Public = C#config.public,
|
|
|
|
S = get_room_state(Pid),
|
2018-11-15 12:13:45 +01:00
|
|
|
Participants = maps:size(S#state.users),
|
2017-12-13 04:07:12 +01:00
|
|
|
{<<Name/binary, "@", Host/binary>>,
|
|
|
|
misc:atom_to_binary(Public),
|
|
|
|
Participants
|
2018-09-20 18:02:47 +02:00
|
|
|
}.
|
2017-12-13 04:07:12 +01:00
|
|
|
|
2019-08-08 11:03:12 +02:00
|
|
|
muc_register_nick(Nick, FromBinary, Service) ->
|
2020-10-20 17:57:19 +02:00
|
|
|
try {get_room_serverhost(Service), jid:decode(FromBinary)} of
|
|
|
|
{ServerHost, From} ->
|
|
|
|
Lang = <<"en">>,
|
|
|
|
case mod_muc:iq_set_register_info(ServerHost, Service, From, Nick, Lang) of
|
|
|
|
{result, undefined} -> ok;
|
|
|
|
{error, #stanza_error{reason = 'conflict'}} ->
|
|
|
|
throw({error, "Nick already registered"});
|
|
|
|
{error, _} ->
|
|
|
|
throw({error, "Database error"})
|
|
|
|
end
|
|
|
|
catch
|
|
|
|
error:{invalid_domain, _} ->
|
2024-02-28 12:01:14 +01:00
|
|
|
throw({error, "Invalid value of 'service'"});
|
2020-10-20 17:57:19 +02:00
|
|
|
error:{unregistered_route, _} ->
|
2024-02-28 12:01:14 +01:00
|
|
|
throw({error, "Unknown host in 'service'"});
|
2020-10-20 17:57:19 +02:00
|
|
|
error:{bad_jid, _} ->
|
|
|
|
throw({error, "Invalid 'jid'"});
|
|
|
|
_ ->
|
|
|
|
throw({error, "Internal error"})
|
2018-05-14 12:24:56 +02:00
|
|
|
end.
|
2017-04-10 12:23:14 +02:00
|
|
|
|
2019-08-08 11:03:12 +02:00
|
|
|
muc_unregister_nick(FromBinary, Service) ->
|
|
|
|
muc_register_nick(<<"">>, FromBinary, Service).
|
2015-04-07 16:30:34 +02:00
|
|
|
|
2017-11-17 13:23:27 +01:00
|
|
|
get_user_rooms(User, Server) ->
|
2017-01-13 10:03:39 +01:00
|
|
|
lists:flatmap(
|
|
|
|
fun(ServerHost) ->
|
|
|
|
case gen_mod:is_loaded(ServerHost, mod_muc) of
|
|
|
|
true ->
|
|
|
|
Rooms = mod_muc:get_online_rooms_by_user(
|
2017-11-17 13:23:27 +01:00
|
|
|
ServerHost, jid:nodeprep(User), jid:nodeprep(Server)),
|
2017-01-13 10:03:39 +01:00
|
|
|
[<<Name/binary, "@", Host/binary>>
|
|
|
|
|| {Name, Host} <- Rooms];
|
|
|
|
false ->
|
|
|
|
[]
|
|
|
|
end
|
2019-06-14 11:33:26 +02:00
|
|
|
end, ejabberd_option:hosts()).
|
2015-04-07 16:30:34 +02:00
|
|
|
|
2021-03-08 20:43:33 +01:00
|
|
|
get_user_subscriptions(User, Server) ->
|
2024-02-28 12:01:14 +01:00
|
|
|
User2 = validate_muc(User, <<"user">>),
|
|
|
|
Server2 = validate_host(Server, <<"host">>),
|
2021-03-08 20:43:33 +01:00
|
|
|
Services = find_services(global),
|
2024-02-28 12:01:14 +01:00
|
|
|
UserJid = jid:make(User2, Server2),
|
2021-03-08 20:43:33 +01:00
|
|
|
lists:flatmap(
|
|
|
|
fun(ServerHost) ->
|
|
|
|
{ok, Rooms} = mod_muc:get_subscribed_rooms(ServerHost, UserJid),
|
|
|
|
[{jid:encode(RoomJid), UserNick, Nodes}
|
|
|
|
|| {RoomJid, UserNick, Nodes} <- Rooms]
|
|
|
|
end, Services).
|
|
|
|
|
2015-04-07 16:30:34 +02:00
|
|
|
%%----------------------------
|
|
|
|
%% Ad-hoc commands
|
|
|
|
%%----------------------------
|
|
|
|
|
|
|
|
|
|
|
|
%%----------------------------
|
|
|
|
%% Web Admin
|
|
|
|
%%----------------------------
|
|
|
|
|
|
|
|
%%---------------
|
|
|
|
%% Web Admin Menu
|
|
|
|
|
|
|
|
web_menu_main(Acc, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Acc ++ [{<<"muc">>, translate:translate(Lang, ?T("Multi-User Chat"))}].
|
2015-04-07 16:30:34 +02:00
|
|
|
|
|
|
|
web_menu_host(Acc, _Host, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Acc ++ [{<<"muc">>, translate:translate(Lang, ?T("Multi-User Chat"))}].
|
2015-04-07 16:30:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
%%---------------
|
|
|
|
%% Web Admin Page
|
|
|
|
|
|
|
|
-define(TDTD(L, N),
|
|
|
|
?XE(<<"tr">>, [?XCT(<<"td">>, L),
|
2016-07-25 12:50:30 +02:00
|
|
|
?XC(<<"td">>, integer_to_binary(N))
|
2015-04-07 16:30:34 +02:00
|
|
|
])).
|
|
|
|
|
|
|
|
web_page_main(_, #request{path=[<<"muc">>], lang = Lang} = _Request) ->
|
2017-01-13 10:03:39 +01:00
|
|
|
OnlineRoomsNumber = lists:foldl(
|
|
|
|
fun(Host, Acc) ->
|
2017-03-21 15:35:51 +01:00
|
|
|
Acc + mod_muc:count_online_rooms(Host)
|
2017-01-13 10:03:39 +01:00
|
|
|
end, 0, find_hosts(global)),
|
2019-08-27 12:29:05 +02:00
|
|
|
PageTitle = translate:translate(Lang, ?T("Multi-User Chat")),
|
2020-04-14 13:46:26 +02:00
|
|
|
Res = ?H1GL(PageTitle, <<"modules/#mod-muc">>, <<"mod_muc">>) ++
|
2019-08-27 12:29:05 +02:00
|
|
|
[?XCT(<<"h3">>, ?T("Statistics")),
|
2015-04-07 16:30:34 +02:00
|
|
|
?XAE(<<"table">>, [],
|
2019-06-22 16:08:45 +02:00
|
|
|
[?XE(<<"tbody">>, [?TDTD(?T("Total rooms"), OnlineRoomsNumber)
|
2015-04-07 16:30:34 +02:00
|
|
|
])
|
|
|
|
]),
|
2019-10-02 11:54:22 +02:00
|
|
|
?XE(<<"ul">>, [?LI([?ACT(<<"rooms/">>, ?T("List of rooms"))])])
|
2015-04-07 16:30:34 +02:00
|
|
|
],
|
|
|
|
{stop, Res};
|
|
|
|
|
|
|
|
web_page_main(_, #request{path=[<<"muc">>, <<"rooms">>], q = Q, lang = Lang} = _Request) ->
|
|
|
|
Sort_query = get_sort_query(Q),
|
|
|
|
Res = make_rooms_page(global, Lang, Sort_query),
|
|
|
|
{stop, Res};
|
|
|
|
|
|
|
|
web_page_main(Acc, _) -> Acc.
|
|
|
|
|
|
|
|
web_page_host(_, Host,
|
|
|
|
#request{path = [<<"muc">>],
|
|
|
|
q = Q,
|
|
|
|
lang = Lang} = _Request) ->
|
|
|
|
Sort_query = get_sort_query(Q),
|
2017-06-01 19:27:28 +02:00
|
|
|
Res = make_rooms_page(Host, Lang, Sort_query),
|
2015-04-07 16:30:34 +02:00
|
|
|
{stop, Res};
|
|
|
|
web_page_host(Acc, _, _) -> Acc.
|
|
|
|
|
|
|
|
|
|
|
|
%% Returns: {normal | reverse, Integer}
|
|
|
|
get_sort_query(Q) ->
|
|
|
|
case catch get_sort_query2(Q) of
|
|
|
|
{ok, Res} -> Res;
|
|
|
|
_ -> {normal, 1}
|
|
|
|
end.
|
|
|
|
|
|
|
|
get_sort_query2(Q) ->
|
2020-05-07 16:08:32 +02:00
|
|
|
{value, {_, Binary}} = lists:keysearch(<<"sort">>, 1, Q),
|
|
|
|
Integer = list_to_integer(string:strip(binary_to_list(Binary), right, $/)),
|
2015-04-07 16:30:34 +02:00
|
|
|
case Integer >= 0 of
|
|
|
|
true -> {ok, {normal, Integer}};
|
|
|
|
false -> {ok, {reverse, abs(Integer)}}
|
|
|
|
end.
|
|
|
|
|
|
|
|
make_rooms_page(Host, Lang, {Sort_direction, Sort_column}) ->
|
2019-08-08 11:03:12 +02:00
|
|
|
Service = find_service(Host),
|
2020-11-16 15:25:01 +01:00
|
|
|
Rooms_names = get_online_rooms(Service),
|
2015-04-07 16:30:34 +02:00
|
|
|
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),
|
2020-04-20 20:16:40 +02:00
|
|
|
Titles = [?T("Jabber ID"),
|
|
|
|
?T("# participants"),
|
|
|
|
?T("Last message"),
|
|
|
|
?T("Public"),
|
|
|
|
?T("Persistent"),
|
|
|
|
?T("Logging"),
|
|
|
|
?T("Just created"),
|
2017-10-23 12:12:37 +02:00
|
|
|
?T("Room title"),
|
|
|
|
?T("Node")],
|
2015-04-07 16:30:34 +02:00
|
|
|
{Titles_TR, _} =
|
|
|
|
lists:mapfoldl(
|
|
|
|
fun(Title, Num_column) ->
|
2016-07-25 12:50:30 +02:00
|
|
|
NCS = integer_to_binary(Num_column),
|
2015-04-07 16:30:34 +02:00
|
|
|
TD = ?XE(<<"td">>, [?CT(Title),
|
|
|
|
?C(<<" ">>),
|
2015-07-15 11:54:35 +02:00
|
|
|
?AC(<<"?sort=", NCS/binary>>, <<"<">>),
|
2015-04-07 16:30:34 +02:00
|
|
|
?C(<<" ">>),
|
2015-07-15 11:54:35 +02:00
|
|
|
?AC(<<"?sort=-", NCS/binary>>, <<">">>)]),
|
2015-04-07 16:30:34 +02:00
|
|
|
{TD, Num_column+1}
|
|
|
|
end,
|
|
|
|
1,
|
|
|
|
Titles),
|
2019-08-27 12:29:05 +02:00
|
|
|
PageTitle = translate:translate(Lang, ?T("Multi-User Chat")),
|
2020-04-14 13:46:26 +02:00
|
|
|
?H1GL(PageTitle, <<"modules/#mod-muc">>, <<"mod_muc">>) ++
|
2019-08-27 12:29:05 +02:00
|
|
|
[?XCT(<<"h2">>, ?T("Chatrooms")),
|
2015-04-07 16:30:34 +02:00
|
|
|
?XE(<<"table">>,
|
|
|
|
[?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)
|
|
|
|
end.
|
|
|
|
|
|
|
|
build_info_rooms(Rooms) ->
|
|
|
|
[build_info_room(Room) || Room <- Rooms].
|
|
|
|
|
2019-08-12 13:24:48 +02:00
|
|
|
build_info_room({Name, Host, _ServerHost, Pid}) ->
|
2015-04-07 16:30:34 +02:00
|
|
|
C = get_room_config(Pid),
|
|
|
|
Title = C#config.title,
|
|
|
|
Public = C#config.public,
|
|
|
|
Persistent = C#config.persistent,
|
|
|
|
Logging = C#config.logging,
|
|
|
|
|
|
|
|
S = get_room_state(Pid),
|
|
|
|
Just_created = S#state.just_created,
|
2018-11-15 12:13:45 +01:00
|
|
|
Num_participants = maps:size(S#state.users),
|
2017-10-23 12:12:37 +02:00
|
|
|
Node = node(Pid),
|
2015-04-07 16:30:34 +02:00
|
|
|
|
|
|
|
History = (S#state.history)#lqueue.queue,
|
|
|
|
Ts_last_message =
|
2017-06-01 19:27:28 +02:00
|
|
|
case p1_queue:is_empty(History) of
|
2015-04-07 16:30:34 +02:00
|
|
|
true ->
|
|
|
|
<<"A long time ago">>;
|
|
|
|
false ->
|
2017-06-01 19:27:28 +02:00
|
|
|
Last_message1 = get_queue_last(History),
|
2015-04-07 16:30:34 +02:00
|
|
|
{_, _, _, Ts_last, _} = Last_message1,
|
2016-11-13 08:44:53 +01:00
|
|
|
xmpp_util:encode_timestamp(Ts_last)
|
2015-04-07 16:30:34 +02:00
|
|
|
end,
|
|
|
|
|
|
|
|
{<<Name/binary, "@", Host/binary>>,
|
|
|
|
Num_participants,
|
|
|
|
Ts_last_message,
|
|
|
|
Public,
|
|
|
|
Persistent,
|
|
|
|
Logging,
|
|
|
|
Just_created,
|
2017-10-23 12:12:37 +02:00
|
|
|
Title,
|
|
|
|
Node}.
|
2015-04-07 16:30:34 +02:00
|
|
|
|
2017-06-01 19:27:28 +02:00
|
|
|
get_queue_last(Queue) ->
|
|
|
|
List = p1_queue:to_list(Queue),
|
|
|
|
lists:last(List).
|
|
|
|
|
2015-04-07 16:30:34 +02:00
|
|
|
prepare_rooms_infos(Rooms) ->
|
|
|
|
[prepare_room_info(Room) || Room <- Rooms].
|
|
|
|
prepare_room_info(Room_info) ->
|
|
|
|
{NameHost,
|
|
|
|
Num_participants,
|
|
|
|
Ts_last_message,
|
|
|
|
Public,
|
|
|
|
Persistent,
|
|
|
|
Logging,
|
|
|
|
Just_created,
|
2017-10-23 12:12:37 +02:00
|
|
|
Title,
|
|
|
|
Node} = Room_info,
|
2015-04-07 16:30:34 +02:00
|
|
|
[NameHost,
|
2016-07-25 12:50:30 +02:00
|
|
|
integer_to_binary(Num_participants),
|
2015-04-07 16:30:34 +02:00
|
|
|
Ts_last_message,
|
2017-04-11 12:13:58 +02:00
|
|
|
misc:atom_to_binary(Public),
|
|
|
|
misc:atom_to_binary(Persistent),
|
|
|
|
misc:atom_to_binary(Logging),
|
2019-03-18 17:08:53 +01:00
|
|
|
justcreated_to_binary(Just_created),
|
2017-10-23 12:12:37 +02:00
|
|
|
Title,
|
|
|
|
misc:atom_to_binary(Node)].
|
2015-04-07 16:30:34 +02:00
|
|
|
|
2019-03-18 17:08:53 +01:00
|
|
|
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]);
|
|
|
|
justcreated_to_binary(J) when is_atom(J) ->
|
|
|
|
misc:atom_to_binary(J).
|
2015-04-07 16:30:34 +02:00
|
|
|
|
|
|
|
%%----------------------------
|
|
|
|
%% Create/Delete Room
|
|
|
|
%%----------------------------
|
|
|
|
|
2022-05-12 17:25:11 +02:00
|
|
|
-spec create_room(Name::binary(), Host::binary(), ServerHost::binary()) -> ok | error.
|
2015-04-07 16:30:34 +02:00
|
|
|
%% @doc Create a room immediately with the default options.
|
2016-02-08 21:35:26 +01:00
|
|
|
create_room(Name1, Host1, ServerHost) ->
|
2020-02-07 12:14:31 +01:00
|
|
|
create_room_with_opts(Name1, Host1, ServerHost, []).
|
2016-09-13 11:52:59 +02:00
|
|
|
|
2020-07-10 13:05:52 +02:00
|
|
|
create_room_with_opts(Name1, Host1, ServerHost1, CustomRoomOpts) ->
|
2024-02-28 12:01:14 +01:00
|
|
|
ServerHost = validate_host(ServerHost1, <<"serverhost">>),
|
|
|
|
case get_room_pid_validate(Name1, Host1, <<"name">>, <<"host">>) of
|
|
|
|
{room_not_found, Name, Host} ->
|
|
|
|
%% Get the default room options from the muc configuration
|
|
|
|
DefRoomOpts = mod_muc_opt:default_room_options(ServerHost),
|
|
|
|
%% Change default room options as required
|
|
|
|
FormattedRoomOpts = [format_room_option(Opt, Val) || {Opt, Val}<-CustomRoomOpts],
|
|
|
|
RoomOpts = lists:ukeymerge(1,
|
|
|
|
lists:keysort(1, FormattedRoomOpts),
|
|
|
|
lists:keysort(1, DefRoomOpts)),
|
|
|
|
case mod_muc:create_room(Host, Name, RoomOpts) of
|
|
|
|
ok ->
|
|
|
|
ok;
|
|
|
|
{error, _} ->
|
|
|
|
throw({error, "Unable to start room"})
|
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
throw({error, "Room already exists"})
|
2015-04-07 16:30:34 +02:00
|
|
|
end.
|
|
|
|
|
|
|
|
%% Create the room only in the database.
|
|
|
|
%% It is required to restart the MUC service for the room to appear.
|
|
|
|
muc_create_room(ServerHost, {Name, Host, _}, DefRoomOpts) ->
|
2019-09-23 14:17:20 +02:00
|
|
|
io:format("Creating room ~ts@~ts~n", [Name, Host]),
|
2015-04-07 16:30:34 +02:00
|
|
|
mod_muc:store_room(ServerHost, Host, Name, DefRoomOpts).
|
|
|
|
|
2022-05-12 17:25:11 +02:00
|
|
|
-spec destroy_room(Name::binary(), Host::binary()) -> ok | {error, room_not_exists}.
|
2015-04-07 16:30:34 +02:00
|
|
|
%% @doc Destroy the room immediately.
|
|
|
|
%% If the room has participants, they are not notified that the room was destroyed;
|
|
|
|
%% they will notice when they try to chat and receive an error that the room doesn't exist.
|
2020-12-08 09:19:05 +01:00
|
|
|
destroy_room(Name1, Service1) ->
|
2024-02-28 12:01:14 +01:00
|
|
|
case get_room_pid_validate(Name1, Service1, <<"name">>, <<"service">>) of
|
|
|
|
{room_not_found, _, _} ->
|
|
|
|
throw({error, "Room doesn't exists"});
|
|
|
|
{Pid, _, _} ->
|
|
|
|
mod_muc_room:destroy(Pid),
|
|
|
|
ok
|
2015-04-07 16:30:34 +02:00
|
|
|
end.
|
|
|
|
|
|
|
|
destroy_room({N, H, SH}) ->
|
2019-09-23 14:17:20 +02:00
|
|
|
io:format("Destroying room: ~ts@~ts - vhost: ~ts~n", [N, H, SH]),
|
2015-08-12 13:26:24 +02:00
|
|
|
destroy_room(N, H).
|
2015-04-07 16:30:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
%%----------------------------
|
|
|
|
%% Destroy Rooms in File
|
|
|
|
%%----------------------------
|
|
|
|
|
|
|
|
%% The format of the file is: one chatroom JID per line
|
|
|
|
%% The file encoding must be UTF-8
|
|
|
|
|
|
|
|
destroy_rooms_file(Filename) ->
|
2016-11-04 16:54:31 +01:00
|
|
|
{ok, F} = file:open(Filename, [read]),
|
2015-04-07 16:30:34 +02:00
|
|
|
RJID = read_room(F),
|
|
|
|
Rooms = read_rooms(F, RJID, []),
|
|
|
|
file:close(F),
|
|
|
|
[destroy_room(A) || A <- Rooms],
|
2020-10-20 17:57:19 +02:00
|
|
|
ok.
|
2015-04-07 16:30:34 +02:00
|
|
|
|
|
|
|
read_rooms(_F, eof, L) ->
|
|
|
|
L;
|
2017-01-31 17:50:04 +01:00
|
|
|
read_rooms(F, no_room, L) ->
|
|
|
|
RJID2 = read_room(F),
|
|
|
|
read_rooms(F, RJID2, L);
|
2015-04-07 16:30:34 +02:00
|
|
|
read_rooms(F, RJID, L) ->
|
|
|
|
RJID2 = read_room(F),
|
|
|
|
read_rooms(F, RJID2, [RJID | L]).
|
|
|
|
|
|
|
|
read_room(F) ->
|
|
|
|
case io:get_line(F, "") of
|
|
|
|
eof -> eof;
|
|
|
|
String ->
|
2019-09-23 14:17:20 +02:00
|
|
|
case io_lib:fread("~ts", String) of
|
2016-11-04 16:54:31 +01:00
|
|
|
{ok, [RoomJID], _} -> split_roomjid(list_to_binary(RoomJID));
|
2015-04-07 16:30:34 +02:00
|
|
|
{error, What} ->
|
|
|
|
io:format("Parse error: what: ~p~non the line: ~p~n~n", [What, String])
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
|
|
|
%% This function is quite rudimentary
|
|
|
|
%% and may not be accurate
|
|
|
|
split_roomjid(RoomJID) ->
|
2017-01-31 17:50:04 +01:00
|
|
|
split_roomjid2(binary:split(RoomJID, <<"@">>)).
|
|
|
|
split_roomjid2([Name, Host]) ->
|
2016-02-09 15:49:47 +01:00
|
|
|
[_MUC_service_name, ServerHost] = binary:split(Host, <<".">>),
|
2017-01-31 17:50:04 +01:00
|
|
|
{Name, Host, ServerHost};
|
|
|
|
split_roomjid2(_) ->
|
|
|
|
no_room.
|
2015-04-07 16:30:34 +02:00
|
|
|
|
|
|
|
%%----------------------------
|
|
|
|
%% Create Rooms in File
|
|
|
|
%%----------------------------
|
|
|
|
|
|
|
|
create_rooms_file(Filename) ->
|
2016-11-04 16:54:31 +01:00
|
|
|
{ok, F} = file:open(Filename, [read]),
|
2015-04-07 16:30:34 +02:00
|
|
|
RJID = read_room(F),
|
|
|
|
Rooms = read_rooms(F, RJID, []),
|
|
|
|
file:close(F),
|
|
|
|
%% Read the default room options defined for the first virtual host
|
2019-06-14 11:33:26 +02:00
|
|
|
DefRoomOpts = mod_muc_opt:default_room_options(ejabberd_config:get_myname()),
|
2018-06-14 13:00:47 +02:00
|
|
|
[muc_create_room(ejabberd_config:get_myname(), A, DefRoomOpts) || A <- Rooms],
|
2020-10-20 17:57:19 +02:00
|
|
|
ok.
|
2015-04-07 16:30:34 +02:00
|
|
|
|
|
|
|
|
2019-02-01 19:48:58 +01:00
|
|
|
%%---------------------------------
|
|
|
|
%% List/Delete Unused/Empty Rooms
|
|
|
|
%%---------------------------------
|
2015-04-07 16:30:34 +02:00
|
|
|
|
|
|
|
%%---------------
|
|
|
|
%% Control
|
|
|
|
|
2019-08-08 11:03:12 +02:00
|
|
|
rooms_unused_list(Service, Days) ->
|
|
|
|
rooms_report(unused, list, Service, Days).
|
|
|
|
rooms_unused_destroy(Service, Days) ->
|
|
|
|
rooms_report(unused, destroy, Service, Days).
|
2015-04-07 16:30:34 +02:00
|
|
|
|
2019-08-08 11:03:12 +02:00
|
|
|
rooms_empty_list(Service) ->
|
|
|
|
rooms_report(empty, list, Service, 0).
|
|
|
|
rooms_empty_destroy(Service) ->
|
|
|
|
rooms_report(empty, destroy, Service, 0).
|
2019-02-01 19:48:58 +01:00
|
|
|
|
|
|
|
|
2019-08-08 11:03:12 +02:00
|
|
|
rooms_report(Method, Action, Service, Days) ->
|
|
|
|
{NA, NP, RP} = muc_unused(Method, Action, Service, Days),
|
2019-09-23 14:17:20 +02:00
|
|
|
io:format("rooms ~ts: ~p out of ~p~n", [Method, NP, NA]),
|
2019-08-12 13:24:48 +02:00
|
|
|
[<<R/binary, "@", H/binary>> || {R, H, _SH, _P} <- RP].
|
2015-04-07 16:30:34 +02:00
|
|
|
|
2019-08-08 11:03:12 +02:00
|
|
|
muc_unused(Method, Action, Service, Last_allowed) ->
|
2015-04-07 16:30:34 +02:00
|
|
|
%% Get all required info about all existing rooms
|
2022-02-18 14:01:22 +01:00
|
|
|
Rooms_all = get_all_rooms(Service, erlang:system_time(microsecond) - Last_allowed*24*60*60*1000),
|
2015-04-07 16:30:34 +02:00
|
|
|
|
|
|
|
%% Decide which ones pass the requirements
|
2019-08-12 13:24:48 +02:00
|
|
|
Rooms_pass = decide_rooms(Method, Rooms_all, Last_allowed),
|
2015-04-07 16:30:34 +02:00
|
|
|
|
|
|
|
Num_rooms_all = length(Rooms_all),
|
|
|
|
Num_rooms_pass = length(Rooms_pass),
|
|
|
|
|
|
|
|
%% Perform the desired action for matching rooms
|
2019-08-12 13:24:48 +02:00
|
|
|
act_on_rooms(Method, Action, Rooms_pass),
|
2015-04-07 16:30:34 +02:00
|
|
|
|
|
|
|
{Num_rooms_all, Num_rooms_pass, Rooms_pass}.
|
|
|
|
|
|
|
|
%%---------------
|
|
|
|
%% Get info
|
|
|
|
|
2020-11-16 15:25:01 +01:00
|
|
|
get_online_rooms(ServiceArg) ->
|
2019-08-08 11:03:12 +02:00
|
|
|
Hosts = find_services(ServiceArg),
|
2017-01-13 10:03:39 +01:00
|
|
|
lists:flatmap(
|
|
|
|
fun(Host) ->
|
2020-11-16 15:25:01 +01:00
|
|
|
ServerHost = get_room_serverhost(Host),
|
|
|
|
[{RoomName, RoomHost, ServerHost, Pid}
|
|
|
|
|| {RoomName, RoomHost, Pid} <- mod_muc:get_online_rooms(Host)]
|
2017-01-13 10:03:39 +01:00
|
|
|
end, Hosts).
|
2015-04-07 16:30:34 +02:00
|
|
|
|
2022-02-18 14:01:22 +01:00
|
|
|
get_all_rooms(ServiceArg, Timestamp) ->
|
2021-12-13 18:22:59 +01:00
|
|
|
Hosts = find_services(ServiceArg),
|
|
|
|
lists:flatmap(
|
|
|
|
fun(Host) ->
|
2022-02-18 14:01:22 +01:00
|
|
|
get_all_rooms2(Host, Timestamp)
|
2021-12-13 18:22:59 +01:00
|
|
|
end, Hosts).
|
|
|
|
|
2022-02-18 14:01:22 +01:00
|
|
|
get_all_rooms2(Host, Timestamp) ->
|
2020-11-16 15:25:01 +01:00
|
|
|
ServerHost = ejabberd_router:host_of_route(Host),
|
|
|
|
OnlineRooms = get_online_rooms(Host),
|
|
|
|
OnlineMap = lists:foldl(
|
|
|
|
fun({Room, _, _, _}, Map) ->
|
|
|
|
Map#{Room => 1}
|
|
|
|
end, #{}, OnlineRooms),
|
|
|
|
|
|
|
|
Mod = gen_mod:db_mod(ServerHost, mod_muc),
|
2021-01-26 11:13:23 +01:00
|
|
|
DbRooms =
|
2022-02-18 14:01:22 +01:00
|
|
|
case {erlang:function_exported(Mod, get_rooms_without_subscribers, 2),
|
|
|
|
erlang:function_exported(Mod, get_hibernated_rooms_older_than, 3)} of
|
|
|
|
{_, true} ->
|
|
|
|
Mod:get_hibernated_rooms_older_than(ServerHost, Host, Timestamp);
|
|
|
|
{true, _} ->
|
2021-01-26 11:13:23 +01:00
|
|
|
Mod:get_rooms_without_subscribers(ServerHost, Host);
|
|
|
|
_ ->
|
|
|
|
Mod:get_rooms(ServerHost, Host)
|
|
|
|
end,
|
2020-11-16 15:25:01 +01:00
|
|
|
StoredRooms = lists:filtermap(
|
|
|
|
fun(#muc_room{name_host = {Room, _}, opts = Opts}) ->
|
|
|
|
case maps:is_key(Room, OnlineMap) of
|
|
|
|
true ->
|
|
|
|
false;
|
|
|
|
_ ->
|
|
|
|
{true, {Room, Host, ServerHost, Opts}}
|
|
|
|
end
|
2021-01-26 11:13:23 +01:00
|
|
|
end, DbRooms),
|
2020-11-16 15:25:01 +01:00
|
|
|
OnlineRooms ++ StoredRooms.
|
|
|
|
|
2015-04-07 16:30:34 +02:00
|
|
|
get_room_config(Room_pid) ->
|
2019-07-08 23:47:54 +02:00
|
|
|
{ok, R} = mod_muc_room:get_config(Room_pid),
|
2015-04-07 16:30:34 +02:00
|
|
|
R.
|
|
|
|
|
|
|
|
get_room_state(Room_pid) ->
|
2019-07-08 23:47:54 +02:00
|
|
|
{ok, R} = mod_muc_room:get_state(Room_pid),
|
2015-04-07 16:30:34 +02:00
|
|
|
R.
|
|
|
|
|
|
|
|
%%---------------
|
|
|
|
%% Decide
|
|
|
|
|
2019-08-12 13:24:48 +02:00
|
|
|
decide_rooms(Method, Rooms, Last_allowed) ->
|
|
|
|
Decide = fun(R) -> decide_room(Method, R, Last_allowed) end,
|
2015-04-07 16:30:34 +02:00
|
|
|
lists:filter(Decide, Rooms).
|
|
|
|
|
2020-12-01 15:39:17 +01:00
|
|
|
decide_room(unused, {_Room_name, _Host, ServerHost, Room_pid}, Last_allowed) ->
|
2020-11-16 15:25:01 +01:00
|
|
|
NodeStartTime = erlang:system_time(microsecond) -
|
|
|
|
1000000*(erlang:monotonic_time(second)-ejabberd_config:get_node_start()),
|
2020-12-01 12:33:25 +01:00
|
|
|
OnlyHibernated = case mod_muc_opt:hibernation_timeout(ServerHost) of
|
|
|
|
Value when Value < Last_allowed*24*60*60*1000 ->
|
|
|
|
true;
|
|
|
|
_ ->
|
|
|
|
false
|
|
|
|
end,
|
2020-11-18 17:14:28 +01:00
|
|
|
{Just_created, Num_users} =
|
2020-11-16 15:25:01 +01:00
|
|
|
case Room_pid of
|
2020-12-01 12:33:25 +01:00
|
|
|
Pid when is_pid(Pid) andalso OnlyHibernated ->
|
2020-12-15 16:40:10 +01:00
|
|
|
{erlang:system_time(microsecond), 0};
|
2020-11-16 15:25:01 +01:00
|
|
|
Pid when is_pid(Pid) ->
|
2020-12-01 12:33:25 +01:00
|
|
|
case mod_muc_room:get_state(Room_pid) of
|
2020-12-15 16:40:10 +01:00
|
|
|
{ok, #state{just_created = JC, users = U}} ->
|
|
|
|
{JC, maps:size(U)};
|
2020-12-01 12:33:25 +01:00
|
|
|
_ ->
|
2020-12-15 16:40:10 +01:00
|
|
|
{erlang:system_time(microsecond), 0}
|
2020-12-01 12:33:25 +01:00
|
|
|
end;
|
2020-11-16 15:25:01 +01:00
|
|
|
Opts ->
|
2020-11-18 16:42:49 +01:00
|
|
|
case lists:keyfind(hibernation_time, 1, Opts) of
|
|
|
|
false ->
|
2020-11-18 17:14:28 +01:00
|
|
|
{NodeStartTime, 0};
|
2022-02-18 14:01:22 +01:00
|
|
|
{_, undefined} ->
|
|
|
|
{NodeStartTime, 0};
|
2020-11-18 16:42:49 +01:00
|
|
|
{_, T} ->
|
2020-11-18 17:14:28 +01:00
|
|
|
{T, 0}
|
2020-11-16 15:25:01 +01:00
|
|
|
end
|
|
|
|
end,
|
2020-11-18 17:14:28 +01:00
|
|
|
Last = case Just_created of
|
|
|
|
true ->
|
|
|
|
0;
|
|
|
|
_ ->
|
|
|
|
(erlang:system_time(microsecond)
|
|
|
|
- Just_created) div 1000000
|
|
|
|
end,
|
|
|
|
case {Num_users, seconds_to_days(Last)} of
|
|
|
|
{0, Last_days} when (Last_days >= Last_allowed) ->
|
2015-04-07 16:30:34 +02:00
|
|
|
true;
|
|
|
|
_ ->
|
|
|
|
false
|
2019-02-01 19:48:58 +01:00
|
|
|
end;
|
2020-11-16 15:25:01 +01:00
|
|
|
decide_room(empty, {Room_name, Host, ServerHost, Room_pid}, _Last_allowed) ->
|
2019-02-18 12:03:16 +01:00
|
|
|
case gen_mod:is_loaded(ServerHost, mod_mam) of
|
2019-02-23 23:50:14 +01:00
|
|
|
true ->
|
2020-11-16 15:25:01 +01:00
|
|
|
Room_options = case Room_pid of
|
|
|
|
_ when is_pid(Room_pid) ->
|
|
|
|
get_room_options(Room_pid);
|
|
|
|
Opts ->
|
|
|
|
Opts
|
|
|
|
end,
|
2019-02-23 22:48:15 +01:00
|
|
|
case lists:keyfind(<<"mam">>, 1, Room_options) of
|
2019-02-23 23:50:14 +01:00
|
|
|
{<<"mam">>, <<"true">>} ->
|
2019-02-23 22:48:15 +01:00
|
|
|
mod_mam:is_empty_for_room(ServerHost, Room_name, Host);
|
2019-02-23 23:50:14 +01:00
|
|
|
_ ->
|
2019-02-23 22:48:15 +01:00
|
|
|
false
|
|
|
|
end;
|
2019-02-23 23:50:14 +01:00
|
|
|
_ ->
|
2019-02-23 22:48:15 +01:00
|
|
|
false
|
2019-02-18 12:03:16 +01:00
|
|
|
end.
|
2015-04-07 16:30:34 +02:00
|
|
|
|
|
|
|
seconds_to_days(S) ->
|
|
|
|
S div (60*60*24).
|
|
|
|
|
|
|
|
%%---------------
|
|
|
|
%% Act
|
|
|
|
|
2019-08-12 13:24:48 +02:00
|
|
|
act_on_rooms(Method, Action, Rooms) ->
|
|
|
|
Delete = fun(Room) ->
|
|
|
|
act_on_room(Method, Action, Room)
|
2015-04-07 16:30:34 +02:00
|
|
|
end,
|
|
|
|
lists:foreach(Delete, Rooms).
|
|
|
|
|
2020-11-19 09:31:14 +01:00
|
|
|
act_on_room(Method, destroy, {N, H, _SH, Pid}) ->
|
2019-02-01 19:48:58 +01:00
|
|
|
Message = iolist_to_binary(io_lib:format(
|
2020-01-22 12:52:30 +01:00
|
|
|
<<"Room destroyed by rooms_~s_destroy.">>, [Method])),
|
2020-11-19 09:31:14 +01:00
|
|
|
case Pid of
|
|
|
|
V when is_pid(V) ->
|
|
|
|
mod_muc_room:destroy(Pid, Message);
|
|
|
|
_ ->
|
|
|
|
case get_room_pid(N, H) of
|
|
|
|
Pid2 when is_pid(Pid2) ->
|
|
|
|
mod_muc_room:destroy(Pid2, Message);
|
|
|
|
_ ->
|
|
|
|
ok
|
|
|
|
end
|
|
|
|
end;
|
2019-08-12 13:24:48 +02:00
|
|
|
act_on_room(_Method, list, _) ->
|
2015-04-07 16:30:34 +02:00
|
|
|
ok.
|
|
|
|
|
|
|
|
|
|
|
|
%%----------------------------
|
|
|
|
%% Change Room Option
|
|
|
|
%%----------------------------
|
|
|
|
|
|
|
|
get_room_occupants(Room, Host) ->
|
2024-02-28 12:01:14 +01:00
|
|
|
case get_room_pid_validate(Room, Host, <<"name">>, <<"service">>) of
|
|
|
|
{Pid, _, _} when is_pid(Pid) -> get_room_occupants(Pid);
|
2020-10-20 17:57:19 +02:00
|
|
|
_ -> throw({error, room_not_found})
|
2015-04-07 16:30:34 +02:00
|
|
|
end.
|
|
|
|
|
|
|
|
get_room_occupants(Pid) ->
|
|
|
|
S = get_room_state(Pid),
|
|
|
|
lists:map(
|
|
|
|
fun({_LJID, Info}) ->
|
2017-02-26 08:07:12 +01:00
|
|
|
{jid:encode(Info#user.jid),
|
2015-04-07 16:30:34 +02:00
|
|
|
Info#user.nick,
|
|
|
|
atom_to_list(Info#user.role)}
|
|
|
|
end,
|
2018-11-15 12:13:45 +01:00
|
|
|
maps:to_list(S#state.users)).
|
2015-04-07 16:30:34 +02:00
|
|
|
|
|
|
|
get_room_occupants_number(Room, Host) ->
|
2024-02-28 12:01:14 +01:00
|
|
|
case get_room_pid_validate(Room, Host, <<"name">>, <<"service">>) of
|
|
|
|
{Pid, _, _} when is_pid(Pid )->
|
2022-03-07 06:42:42 +01:00
|
|
|
{ok, #{occupants_number := N}} = mod_muc_room:get_info(Pid),
|
|
|
|
N;
|
2020-10-20 17:57:19 +02:00
|
|
|
_ ->
|
|
|
|
throw({error, room_not_found})
|
2017-09-07 18:32:26 +02:00
|
|
|
end.
|
2015-04-07 16:30:34 +02:00
|
|
|
|
|
|
|
%%----------------------------
|
|
|
|
%% Send Direct Invitation
|
|
|
|
%%----------------------------
|
|
|
|
%% http://xmpp.org/extensions/xep-0249.html
|
|
|
|
|
2023-11-29 19:04:57 +01:00
|
|
|
send_direct_invitation(RoomName, RoomService, Password, Reason, UsersString) when is_binary(UsersString) ->
|
|
|
|
UsersStrings = binary:split(UsersString, <<":">>, [global]),
|
|
|
|
send_direct_invitation(RoomName, RoomService, Password, Reason, UsersStrings);
|
|
|
|
send_direct_invitation(RoomName, RoomService, Password, Reason, UsersStrings) ->
|
2020-10-20 17:57:19 +02:00
|
|
|
case jid:make(RoomName, RoomService) of
|
|
|
|
error ->
|
|
|
|
throw({error, "Invalid 'roomname' or 'service'"});
|
|
|
|
RoomJid ->
|
|
|
|
XmlEl = build_invitation(Password, Reason, RoomJid),
|
2023-11-29 19:04:57 +01:00
|
|
|
Users = get_users_to_invite(RoomJid, UsersStrings),
|
2020-10-20 17:57:19 +02:00
|
|
|
[send_direct_invitation(RoomJid, UserJid, XmlEl)
|
|
|
|
|| UserJid <- Users],
|
|
|
|
ok
|
|
|
|
end.
|
2015-04-07 16:30:34 +02:00
|
|
|
|
2023-11-29 19:04:57 +01:00
|
|
|
get_users_to_invite(RoomJid, UsersStrings) ->
|
2015-04-07 16:30:34 +02:00
|
|
|
OccupantsTuples = get_room_occupants(RoomJid#jid.luser,
|
|
|
|
RoomJid#jid.lserver),
|
2017-02-26 08:07:12 +01:00
|
|
|
OccupantsJids = [jid:decode(JidString)
|
2015-04-07 16:30:34 +02:00
|
|
|
|| {JidString, _Nick, _} <- OccupantsTuples],
|
2016-02-09 15:49:47 +01:00
|
|
|
lists:filtermap(
|
|
|
|
fun(UserString) ->
|
2017-02-26 08:07:12 +01:00
|
|
|
UserJid = jid:decode(UserString),
|
2016-02-09 15:49:47 +01:00
|
|
|
Val = lists:all(fun(OccupantJid) ->
|
|
|
|
UserJid#jid.luser /= OccupantJid#jid.luser
|
|
|
|
orelse UserJid#jid.lserver /= OccupantJid#jid.lserver
|
|
|
|
end,
|
|
|
|
OccupantsJids),
|
2017-12-19 10:24:07 +01:00
|
|
|
case {UserJid#jid.luser, Val} of
|
|
|
|
{<<>>, _} -> false;
|
|
|
|
{_, true} -> {true, UserJid};
|
2016-02-09 15:49:47 +01:00
|
|
|
_ -> false
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
UsersStrings).
|
2015-04-07 16:30:34 +02:00
|
|
|
|
2017-02-16 09:00:26 +01:00
|
|
|
build_invitation(Password, Reason, RoomJid) ->
|
|
|
|
Invite = #x_conference{jid = RoomJid,
|
|
|
|
password = case Password of
|
|
|
|
<<"none">> -> <<>>;
|
|
|
|
_ -> Password
|
|
|
|
end,
|
|
|
|
reason = case Reason of
|
|
|
|
<<"none">> -> <<>>;
|
|
|
|
_ -> Reason
|
|
|
|
end},
|
|
|
|
#message{sub_els = [Invite]}.
|
|
|
|
|
|
|
|
send_direct_invitation(FromJid, UserJid, Msg) ->
|
|
|
|
ejabberd_router:route(xmpp:set_from_to(Msg, FromJid, UserJid)).
|
2015-04-07 16:30:34 +02:00
|
|
|
|
|
|
|
%%----------------------------
|
|
|
|
%% Change Room Option
|
|
|
|
%%----------------------------
|
|
|
|
|
2022-05-12 17:25:11 +02:00
|
|
|
-spec change_room_option(Name::binary(), Service::binary(), Option::binary(),
|
|
|
|
Value::atom() | integer() | string()) -> ok | mod_muc_log_not_enabled.
|
2015-04-07 16:30:34 +02:00
|
|
|
%% @doc Change an option in an existing room.
|
|
|
|
%% Requires the name of the room, the MUC service where it exists,
|
|
|
|
%% the option to change (for example title or max_users),
|
|
|
|
%% and the value to assign to the new option.
|
|
|
|
%% For example:
|
2020-05-11 19:37:47 +02:00
|
|
|
%% `change_room_option(<<"testroom">>, <<"conference.localhost">>, <<"title">>, <<"Test Room">>)'
|
2015-04-07 16:30:34 +02:00
|
|
|
change_room_option(Name, Service, OptionString, ValueString) ->
|
2024-02-28 12:01:14 +01:00
|
|
|
case get_room_pid_validate(Name, Service, <<"name">>, <<"service">>) of
|
|
|
|
{room_not_found, _, _} ->
|
2020-10-20 17:57:19 +02:00
|
|
|
throw({error, "Room not found"});
|
2024-02-28 12:01:14 +01:00
|
|
|
{Pid, _, _} ->
|
2016-09-13 11:52:59 +02:00
|
|
|
{Option, Value} = format_room_option(OptionString, ValueString),
|
2020-04-17 15:01:37 +02:00
|
|
|
change_room_option(Pid, Option, Value)
|
|
|
|
end.
|
|
|
|
|
|
|
|
change_room_option(Pid, Option, Value) ->
|
|
|
|
case {Option,
|
|
|
|
gen_mod:is_loaded((get_room_state(Pid))#state.server_host, mod_muc_log)} of
|
|
|
|
{logging, false} ->
|
|
|
|
mod_muc_log_not_enabled;
|
|
|
|
_ ->
|
2016-09-13 11:52:59 +02:00
|
|
|
Config = get_room_config(Pid),
|
|
|
|
Config2 = change_option(Option, Value, Config),
|
2019-07-08 23:47:54 +02:00
|
|
|
{ok, _} = mod_muc_room:set_config(Pid, Config2),
|
2016-09-13 11:52:59 +02:00
|
|
|
ok
|
|
|
|
end.
|
|
|
|
|
|
|
|
format_room_option(OptionString, ValueString) ->
|
2017-04-11 12:13:58 +02:00
|
|
|
Option = misc:binary_to_atom(OptionString),
|
2015-04-07 16:30:34 +02:00
|
|
|
Value = case Option of
|
|
|
|
title -> ValueString;
|
|
|
|
description -> ValueString;
|
|
|
|
password -> ValueString;
|
|
|
|
subject ->ValueString;
|
|
|
|
subject_author ->ValueString;
|
2017-05-29 12:46:59 +02:00
|
|
|
presence_broadcast ->misc:expr_to_term(ValueString);
|
2016-09-24 22:34:28 +02:00
|
|
|
max_users -> binary_to_integer(ValueString);
|
2018-09-20 18:02:47 +02:00
|
|
|
voice_request_min_interval -> binary_to_integer(ValueString);
|
|
|
|
vcard -> ValueString;
|
|
|
|
vcard_xupdate when ValueString /= <<"undefined">>,
|
|
|
|
ValueString /= <<"external">> ->
|
|
|
|
ValueString;
|
|
|
|
lang -> ValueString;
|
|
|
|
pubsub -> ValueString;
|
2023-02-20 13:03:46 +01:00
|
|
|
affiliations ->
|
|
|
|
[parse_affiliation_string(Opt) || Opt <- str:tokens(ValueString, <<",">>)];
|
|
|
|
subscribers ->
|
|
|
|
[parse_subscription_string(Opt) || Opt <- str:tokens(ValueString, <<",">>)];
|
2017-04-11 12:13:58 +02:00
|
|
|
_ -> misc:binary_to_atom(ValueString)
|
2015-04-07 16:30:34 +02:00
|
|
|
end,
|
2016-09-13 11:52:59 +02:00
|
|
|
{Option, Value}.
|
2015-04-07 16:30:34 +02:00
|
|
|
|
2023-02-20 13:03:46 +01:00
|
|
|
parse_affiliation_string(String) ->
|
|
|
|
{Type, JidS} = case String of
|
|
|
|
<<"owner:", Jid/binary>> -> {owner, Jid};
|
|
|
|
<<"admin:", Jid/binary>> -> {admin, Jid};
|
|
|
|
<<"member:", Jid/binary>> -> {member, Jid};
|
|
|
|
<<"outcast:", Jid/binary>> -> {outcast, Jid};
|
|
|
|
_ -> throw({error, "Invalid 'affiliation'"})
|
|
|
|
end,
|
|
|
|
try jid:decode(JidS) of
|
|
|
|
#jid{luser = U, lserver = S, lresource = R} ->
|
|
|
|
{{U, S, R}, {Type, <<>>}}
|
|
|
|
catch _:{bad_jid, _} ->
|
|
|
|
throw({error, "Malformed JID in affiliation"})
|
|
|
|
end.
|
|
|
|
|
|
|
|
parse_subscription_string(String) ->
|
|
|
|
case str:tokens(String, <<":">>) of
|
|
|
|
[_] ->
|
|
|
|
throw({error, "Invalid 'subscribers' - missing nick"});
|
|
|
|
[_, _] ->
|
|
|
|
throw({error, "Invalid 'subscribers' - missing nodes"});
|
|
|
|
[JidS, Nick | Nodes] ->
|
|
|
|
Nodes2 = parse_nodes(Nodes, []),
|
|
|
|
try jid:decode(JidS) of
|
|
|
|
Jid ->
|
|
|
|
{Jid, Nick, Nodes2}
|
|
|
|
catch _:{bad_jid, _} ->
|
|
|
|
throw({error, "Malformed JID in 'subscribers'"})
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
|
|
|
parse_nodes([], Acc) ->
|
|
|
|
Acc;
|
|
|
|
parse_nodes([<<"presence">> | Rest], Acc) ->
|
|
|
|
parse_nodes(Rest, [?NS_MUCSUB_NODES_PRESENCE | Acc]);
|
|
|
|
parse_nodes([<<"messages">> | Rest], Acc) ->
|
|
|
|
parse_nodes(Rest, [?NS_MUCSUB_NODES_MESSAGES | Acc]);
|
|
|
|
parse_nodes([<<"participants">> | Rest], Acc) ->
|
|
|
|
parse_nodes(Rest, [?NS_MUCSUB_NODES_PARTICIPANTS | Acc]);
|
|
|
|
parse_nodes([<<"affiliations">> | Rest], Acc) ->
|
|
|
|
parse_nodes(Rest, [?NS_MUCSUB_NODES_AFFILIATIONS | Acc]);
|
|
|
|
parse_nodes([<<"subject">> | Rest], Acc) ->
|
|
|
|
parse_nodes(Rest, [?NS_MUCSUB_NODES_SUBJECT | Acc]);
|
|
|
|
parse_nodes([<<"config">> | Rest], Acc) ->
|
|
|
|
parse_nodes(Rest, [?NS_MUCSUB_NODES_CONFIG | Acc]);
|
|
|
|
parse_nodes([<<"system">> | Rest], Acc) ->
|
|
|
|
parse_nodes(Rest, [?NS_MUCSUB_NODES_SYSTEM | Acc]);
|
|
|
|
parse_nodes([<<"subscribers">> | Rest], Acc) ->
|
|
|
|
parse_nodes(Rest, [?NS_MUCSUB_NODES_SUBSCRIBERS | Acc]);
|
|
|
|
parse_nodes(_, _) ->
|
|
|
|
throw({error, "Invalid 'subscribers' - unknown node name used"}).
|
|
|
|
|
2024-02-28 12:01:14 +01:00
|
|
|
-spec get_room_pid_validate(binary(), binary(), binary(), binary()) ->
|
|
|
|
{pid() | room_not_found, binary(), binary()}.
|
|
|
|
get_room_pid_validate(Name, Service, NameArg, ServiceArg) ->
|
|
|
|
Name2 = validate_room(Name, NameArg),
|
|
|
|
{ServerHost, Service2} = validate_muc2(Service, ServiceArg),
|
|
|
|
case mod_muc:unhibernate_room(ServerHost, Service2, Name2) of
|
|
|
|
error ->
|
|
|
|
{room_not_found, Name2, Service2};
|
|
|
|
{ok, Pid} ->
|
|
|
|
{Pid, Name2, Service2}
|
|
|
|
end.
|
|
|
|
|
2015-04-07 16:30:34 +02:00
|
|
|
%% @doc Get the Pid of an existing MUC room, or 'room_not_found'.
|
2024-02-28 12:01:14 +01:00
|
|
|
-spec get_room_pid(binary(), binary()) -> pid() | room_not_found | invalid_service | unknown_service.
|
2015-04-07 16:30:34 +02:00
|
|
|
get_room_pid(Name, Service) ->
|
2020-10-20 17:57:19 +02:00
|
|
|
try get_room_serverhost(Service) of
|
|
|
|
ServerHost ->
|
|
|
|
case mod_muc:unhibernate_room(ServerHost, Service, Name) of
|
|
|
|
error ->
|
|
|
|
room_not_found;
|
|
|
|
{ok, Pid} ->
|
|
|
|
Pid
|
|
|
|
end
|
|
|
|
catch
|
|
|
|
error:{invalid_domain, _} ->
|
|
|
|
invalid_service;
|
|
|
|
error:{unregistered_route, _} ->
|
2024-02-28 12:01:14 +01:00
|
|
|
unknown_service
|
2015-04-07 16:30:34 +02:00
|
|
|
end.
|
|
|
|
|
2022-09-01 13:37:48 +02:00
|
|
|
room_diagnostics(Name, Service) ->
|
|
|
|
try get_room_serverhost(Service) of
|
|
|
|
ServerHost ->
|
|
|
|
RMod = gen_mod:ram_db_mod(ServerHost, mod_muc),
|
|
|
|
case RMod:find_online_room(ServerHost, Name, Service) of
|
|
|
|
error ->
|
|
|
|
room_hibernated;
|
|
|
|
{ok, Pid} ->
|
|
|
|
case rpc:pinfo(Pid, [current_stacktrace, message_queue_len, messages]) of
|
|
|
|
[{_, R}, {_, QL}, {_, Q}] ->
|
|
|
|
#{stacktrace => R, queue_size => QL, queue => lists:sublist(Q, 10)};
|
|
|
|
_ ->
|
|
|
|
unable_to_probe_process
|
|
|
|
end
|
|
|
|
end
|
|
|
|
catch
|
|
|
|
error:{invalid_domain, _} ->
|
|
|
|
invalid_service;
|
|
|
|
error:{unregistered_route, _} ->
|
2024-02-28 12:01:14 +01:00
|
|
|
unknown_service
|
2022-09-01 13:37:48 +02:00
|
|
|
end.
|
|
|
|
|
2019-07-16 21:07:39 +02:00
|
|
|
%% It is required to put explicitly all the options because
|
2015-04-07 16:30:34 +02:00
|
|
|
%% the record elements are replaced at compile time.
|
|
|
|
%% So, this can't be parametrized.
|
|
|
|
change_option(Option, Value, Config) ->
|
|
|
|
case Option of
|
|
|
|
allow_change_subj -> Config#config{allow_change_subj = Value};
|
2023-08-08 13:28:02 +02:00
|
|
|
allowpm -> Config#config{allowpm = Value};
|
2015-06-18 13:13:49 +02:00
|
|
|
allow_private_messages_from_visitors -> Config#config{allow_private_messages_from_visitors = Value};
|
2015-04-07 16:30:34 +02:00
|
|
|
allow_query_users -> Config#config{allow_query_users = Value};
|
2016-08-22 01:17:32 +02:00
|
|
|
allow_subscription -> Config#config{allow_subscription = Value};
|
2015-04-07 16:30:34 +02:00
|
|
|
allow_user_invites -> Config#config{allow_user_invites = Value};
|
2015-06-18 13:13:49 +02:00
|
|
|
allow_visitor_nickchange -> Config#config{allow_visitor_nickchange = Value};
|
|
|
|
allow_visitor_status -> Config#config{allow_visitor_status = Value};
|
|
|
|
allow_voice_requests -> Config#config{allow_voice_requests = Value};
|
2015-04-07 16:30:34 +02:00
|
|
|
anonymous -> Config#config{anonymous = Value};
|
2015-06-18 13:13:49 +02:00
|
|
|
captcha_protected -> Config#config{captcha_protected = Value};
|
2015-05-12 17:37:39 +02:00
|
|
|
description -> Config#config{description = Value};
|
2021-07-23 10:14:45 +02:00
|
|
|
lang -> Config#config{lang = Value};
|
2015-04-07 16:30:34 +02:00
|
|
|
logging -> Config#config{logging = Value};
|
2016-01-02 20:57:01 +01:00
|
|
|
mam -> Config#config{mam = Value};
|
2015-04-07 16:30:34 +02:00
|
|
|
max_users -> Config#config{max_users = Value};
|
|
|
|
members_by_default -> Config#config{members_by_default = Value};
|
|
|
|
members_only -> Config#config{members_only = Value};
|
|
|
|
moderated -> Config#config{moderated = Value};
|
|
|
|
password -> Config#config{password = Value};
|
|
|
|
password_protected -> Config#config{password_protected = Value};
|
|
|
|
persistent -> Config#config{persistent = Value};
|
2017-05-29 12:46:59 +02:00
|
|
|
presence_broadcast -> Config#config{presence_broadcast = Value};
|
2015-04-07 16:30:34 +02:00
|
|
|
public -> Config#config{public = Value};
|
|
|
|
public_list -> Config#config{public_list = Value};
|
2021-07-23 10:14:45 +02:00
|
|
|
pubsub -> Config#config{pubsub = Value};
|
2015-06-18 13:13:49 +02:00
|
|
|
title -> Config#config{title = Value};
|
|
|
|
vcard -> Config#config{vcard = Value};
|
2021-07-23 10:14:45 +02:00
|
|
|
vcard_xupdate -> Config#config{vcard_xupdate = Value};
|
2015-06-18 13:13:49 +02:00
|
|
|
voice_request_min_interval -> Config#config{voice_request_min_interval = Value}
|
2015-04-07 16:30:34 +02:00
|
|
|
end.
|
|
|
|
|
2015-05-15 17:47:10 +02:00
|
|
|
%%----------------------------
|
|
|
|
%% Get Room Options
|
|
|
|
%%----------------------------
|
|
|
|
|
|
|
|
get_room_options(Name, Service) ->
|
2024-02-28 12:01:14 +01:00
|
|
|
case get_room_pid_validate(Name, Service, <<"name">>, <<"service">>) of
|
|
|
|
{Pid, _, _} when is_pid(Pid) -> get_room_options(Pid);
|
2020-10-20 17:57:19 +02:00
|
|
|
_ -> []
|
2015-08-28 13:34:51 +02:00
|
|
|
end.
|
2015-05-15 17:47:10 +02:00
|
|
|
|
|
|
|
get_room_options(Pid) ->
|
|
|
|
Config = get_room_config(Pid),
|
|
|
|
get_options(Config).
|
|
|
|
|
|
|
|
get_options(Config) ->
|
2017-04-11 12:13:58 +02:00
|
|
|
Fields = [misc:atom_to_binary(Field) || Field <- record_info(fields, config)],
|
2016-04-05 14:13:28 +02:00
|
|
|
[config | ValuesRaw] = tuple_to_list(Config),
|
2017-04-11 12:13:58 +02:00
|
|
|
Values = lists:map(fun(V) when is_atom(V) -> misc:atom_to_binary(V);
|
2016-07-25 12:50:30 +02:00
|
|
|
(V) when is_integer(V) -> integer_to_binary(V);
|
2016-04-05 14:13:28 +02:00
|
|
|
(V) when is_tuple(V); is_list(V) -> list_to_binary(hd(io_lib:format("~w", [V])));
|
|
|
|
(V) -> V end, ValuesRaw),
|
2015-05-15 17:47:10 +02:00
|
|
|
lists:zip(Fields, Values).
|
2015-04-07 16:30:34 +02:00
|
|
|
|
|
|
|
%%----------------------------
|
|
|
|
%% Get Room Affiliations
|
|
|
|
%%----------------------------
|
|
|
|
|
|
|
|
%% @spec(Name::binary(), Service::binary()) ->
|
|
|
|
%% [{JID::string(), Domain::string(), Role::string(), Reason::string()}]
|
|
|
|
%% @doc Get the affiliations of the room Name@Service.
|
|
|
|
get_room_affiliations(Name, Service) ->
|
2024-02-28 12:01:14 +01:00
|
|
|
case get_room_pid_validate(Name, Service, <<"name">>, <<"service">>) of
|
|
|
|
{Pid, _, _} when is_pid(Pid) ->
|
2015-04-07 16:30:34 +02:00
|
|
|
%% Get the PID of the online room, then request its state
|
2019-07-08 23:47:54 +02:00
|
|
|
{ok, StateData} = mod_muc_room:get_state(Pid),
|
2018-11-15 12:13:45 +01:00
|
|
|
Affiliations = maps:to_list(StateData#state.affiliations),
|
2015-04-07 16:30:34 +02:00
|
|
|
lists:map(
|
|
|
|
fun({{Uname, Domain, _Res}, {Aff, Reason}}) when is_atom(Aff)->
|
|
|
|
{Uname, Domain, Aff, Reason};
|
|
|
|
({{Uname, Domain, _Res}, Aff}) when is_atom(Aff)->
|
|
|
|
{Uname, Domain, Aff, <<>>}
|
|
|
|
end, Affiliations);
|
2020-10-20 17:57:19 +02:00
|
|
|
_ ->
|
2015-04-07 16:30:34 +02:00
|
|
|
throw({error, "The room does not exist."})
|
|
|
|
end.
|
|
|
|
|
2023-02-08 11:04:26 +01:00
|
|
|
get_room_history(Name, Service) ->
|
2024-02-28 12:01:14 +01:00
|
|
|
case get_room_pid_validate(Name, Service, <<"name">>, <<"service">>) of
|
|
|
|
{Pid, _, _} when is_pid(Pid) ->
|
2023-02-08 11:04:26 +01:00
|
|
|
case mod_muc_room:get_state(Pid) of
|
|
|
|
{ok, StateData} ->
|
|
|
|
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))}
|
|
|
|
end, History);
|
|
|
|
_ ->
|
|
|
|
throw({error, "Unable to fetch room state."})
|
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
throw({error, "The room does not exist."})
|
|
|
|
end.
|
|
|
|
|
2018-02-25 10:28:14 +01:00
|
|
|
%%----------------------------
|
|
|
|
%% Get Room Affiliation
|
|
|
|
%%----------------------------
|
|
|
|
|
|
|
|
%% @spec(Name::binary(), Service::binary(), JID::binary()) ->
|
|
|
|
%% {Affiliation::string()}
|
|
|
|
%% @doc Get affiliation of a user in the room Name@Service.
|
|
|
|
|
|
|
|
get_room_affiliation(Name, Service, JID) ->
|
2024-02-28 12:01:14 +01:00
|
|
|
case get_room_pid_validate(Name, Service, <<"name">>, <<"service">>) of
|
|
|
|
{Pid, _, _} when is_pid(Pid) ->
|
|
|
|
%% Get the PID of the online room, then request its state
|
|
|
|
{ok, StateData} = mod_muc_room:get_state(Pid),
|
|
|
|
UserJID = jid:decode(JID),
|
|
|
|
mod_muc_room:get_affiliation(UserJID, StateData);
|
|
|
|
_ ->
|
|
|
|
throw({error, "The room does not exist."})
|
|
|
|
end.
|
2018-02-25 10:28:14 +01:00
|
|
|
|
2015-04-07 16:30:34 +02:00
|
|
|
%%----------------------------
|
|
|
|
%% Change Room Affiliation
|
|
|
|
%%----------------------------
|
|
|
|
|
|
|
|
%% @spec(Name, Service, JID, AffiliationString) -> ok | {error, Error}
|
|
|
|
%% Name = binary()
|
|
|
|
%% Service = binary()
|
|
|
|
%% JID = binary()
|
|
|
|
%% AffiliationString = "outcast" | "none" | "member" | "admin" | "owner"
|
|
|
|
%% @doc Set the affiliation of JID in the room Name@Service.
|
|
|
|
%% If the affiliation is 'none', the action is to remove,
|
|
|
|
%% In any other case the action will be to create the affiliation.
|
|
|
|
set_room_affiliation(Name, Service, JID, AffiliationString) ->
|
2021-01-21 14:20:30 +01:00
|
|
|
Affiliation = case AffiliationString of
|
|
|
|
<<"outcast">> -> outcast;
|
|
|
|
<<"none">> -> none;
|
|
|
|
<<"member">> -> member;
|
|
|
|
<<"admin">> -> admin;
|
|
|
|
<<"owner">> -> owner;
|
|
|
|
_ ->
|
|
|
|
throw({error, "Invalid affiliation"})
|
|
|
|
end,
|
2024-02-28 12:01:14 +01:00
|
|
|
case get_room_pid_validate(Name, Service, <<"name">>, <<"service">>) of
|
|
|
|
{Pid, _, _} when is_pid(Pid) ->
|
2015-04-07 16:30:34 +02:00
|
|
|
%% Get the PID for the online room so we can get the state of the room
|
2020-12-04 13:06:53 +01:00
|
|
|
case mod_muc_room:change_item(Pid, jid:decode(JID), affiliation, Affiliation, <<"">>) of
|
|
|
|
{ok, _} ->
|
|
|
|
ok;
|
2020-12-18 17:06:14 +01:00
|
|
|
{error, notfound} ->
|
2020-12-04 13:06:53 +01:00
|
|
|
throw({error, "Room doesn't exists"});
|
|
|
|
{error, _} ->
|
|
|
|
throw({error, "Unable to perform change"})
|
|
|
|
end;
|
2024-02-28 12:01:14 +01:00
|
|
|
_ ->
|
|
|
|
throw({error, "Room doesn't exists"})
|
2015-04-07 16:30:34 +02:00
|
|
|
end.
|
|
|
|
|
2016-08-09 12:36:43 +02:00
|
|
|
%%%
|
|
|
|
%%% MUC Subscription
|
|
|
|
%%%
|
|
|
|
|
|
|
|
subscribe_room(_User, Nick, _Room, _Nodes) when Nick == <<"">> ->
|
|
|
|
throw({error, "Nickname must be set"});
|
2023-11-29 19:04:57 +01:00
|
|
|
subscribe_room(User, Nick, Room, Nodes) when is_binary(Nodes) ->
|
2016-08-09 12:36:43 +02:00
|
|
|
NodeList = re:split(Nodes, "\\h*,\\h*"),
|
2023-11-29 19:04:57 +01:00
|
|
|
subscribe_room(User, Nick, Room, NodeList);
|
|
|
|
subscribe_room(User, Nick, Room, NodeList) ->
|
2017-02-26 08:07:12 +01:00
|
|
|
try jid:decode(Room) of
|
2016-08-09 12:36:43 +02:00
|
|
|
#jid{luser = Name, lserver = Host} when Name /= <<"">> ->
|
2017-02-26 08:07:12 +01:00
|
|
|
try jid:decode(User) of
|
2018-12-10 21:06:26 +01:00
|
|
|
UserJID1 ->
|
|
|
|
UserJID = jid:replace_resource(UserJID1, <<"modmucadmin">>),
|
2024-02-28 12:01:14 +01:00
|
|
|
case get_room_pid_validate(Name, Host, <<"name">>, <<"room">>) of
|
|
|
|
{Pid, _, _} when is_pid(Pid) ->
|
2019-07-08 23:47:54 +02:00
|
|
|
case mod_muc_room:subscribe(
|
|
|
|
Pid, UserJID, Nick, NodeList) of
|
2016-08-09 12:36:43 +02:00
|
|
|
{ok, SubscribedNodes} ->
|
|
|
|
SubscribedNodes;
|
|
|
|
{error, Reason} ->
|
|
|
|
throw({error, binary_to_list(Reason)})
|
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
throw({error, "The room does not exist"})
|
|
|
|
end
|
2017-02-26 08:07:12 +01:00
|
|
|
catch _:{bad_jid, _} ->
|
|
|
|
throw({error, "Malformed user JID"})
|
2016-08-09 12:36:43 +02:00
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
throw({error, "Malformed room JID"})
|
2017-02-26 08:07:12 +01:00
|
|
|
catch _:{bad_jid, _} ->
|
|
|
|
throw({error, "Malformed room JID"})
|
2016-08-09 12:36:43 +02:00
|
|
|
end.
|
|
|
|
|
2021-12-20 07:37:47 +01:00
|
|
|
subscribe_room_many(Users, Room, Nodes) ->
|
|
|
|
MaxUsers = mod_muc_admin_opt:subscribe_room_many_max_users(global),
|
|
|
|
if
|
|
|
|
length(Users) > MaxUsers ->
|
|
|
|
throw({error, "Too many users in subscribe_room_many command"});
|
|
|
|
true ->
|
|
|
|
lists:foreach(
|
|
|
|
fun({User, Nick}) ->
|
|
|
|
subscribe_room(User, Nick, Room, Nodes)
|
|
|
|
end, Users)
|
|
|
|
end.
|
|
|
|
|
2016-08-09 12:36:43 +02:00
|
|
|
unsubscribe_room(User, Room) ->
|
2017-02-26 08:07:12 +01:00
|
|
|
try jid:decode(Room) of
|
2016-08-09 12:36:43 +02:00
|
|
|
#jid{luser = Name, lserver = Host} when Name /= <<"">> ->
|
2017-02-26 08:07:12 +01:00
|
|
|
try jid:decode(User) of
|
2016-08-09 12:36:43 +02:00
|
|
|
UserJID ->
|
2024-02-28 12:01:14 +01:00
|
|
|
case get_room_pid_validate(Name, Host, <<"name">>, <<"room">>) of
|
|
|
|
{Pid, _, _} when is_pid(Pid) ->
|
2019-07-08 23:47:54 +02:00
|
|
|
case mod_muc_room:unsubscribe(Pid, UserJID) of
|
2016-08-09 12:36:43 +02:00
|
|
|
ok ->
|
|
|
|
ok;
|
|
|
|
{error, Reason} ->
|
|
|
|
throw({error, binary_to_list(Reason)})
|
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
throw({error, "The room does not exist"})
|
|
|
|
end
|
2017-02-26 08:07:12 +01:00
|
|
|
catch _:{bad_jid, _} ->
|
|
|
|
throw({error, "Malformed user JID"})
|
2016-08-09 12:36:43 +02:00
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
throw({error, "Malformed room JID"})
|
2017-02-26 08:07:12 +01:00
|
|
|
catch _:{bad_jid, _} ->
|
|
|
|
throw({error, "Malformed room JID"})
|
2016-08-09 12:36:43 +02:00
|
|
|
end.
|
|
|
|
|
2016-09-06 16:55:18 +02:00
|
|
|
get_subscribers(Name, Host) ->
|
2024-02-28 12:01:14 +01:00
|
|
|
case get_room_pid_validate(Name, Host, <<"name">>, <<"service">>) of
|
|
|
|
{Pid, _, _} when is_pid(Pid) ->
|
2019-07-08 23:47:54 +02:00
|
|
|
{ok, JIDList} = mod_muc_room:get_subscribers(Pid),
|
2017-02-26 08:07:12 +01:00
|
|
|
[jid:encode(jid:remove_resource(J)) || J <- JIDList];
|
2016-09-06 16:55:18 +02:00
|
|
|
_ ->
|
|
|
|
throw({error, "The room does not exist"})
|
|
|
|
end.
|
|
|
|
|
2015-04-07 16:30:34 +02:00
|
|
|
%%----------------------------
|
|
|
|
%% Utils
|
|
|
|
%%----------------------------
|
|
|
|
|
2024-02-28 12:01:14 +01:00
|
|
|
-spec validate_host(Name :: binary(), ArgName::binary()) -> binary().
|
|
|
|
validate_host(Name, ArgName) ->
|
|
|
|
case jid:nameprep(Name) of
|
|
|
|
error ->
|
|
|
|
throw({error, <<"Invalid value of '",ArgName/binary,"'">>});
|
|
|
|
Name2 ->
|
|
|
|
case lists:member(Name2, ejabberd_config:get_myhosts()) of
|
|
|
|
false ->
|
|
|
|
throw({error, <<"Unknown host passed in '",ArgName/binary,"'">>});
|
|
|
|
_ ->
|
|
|
|
Name2
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
|
|
|
-spec validate_muc(Name :: binary(), ArgName::binary()) -> binary().
|
|
|
|
validate_muc(Name, ArgName) ->
|
|
|
|
case jid:nameprep(Name) of
|
|
|
|
error ->
|
|
|
|
throw({error, <<"Invalid value of '",ArgName/binary,"'">>});
|
|
|
|
Name2 ->
|
|
|
|
try get_room_serverhost(Name2) of
|
|
|
|
_ -> Name2
|
|
|
|
catch
|
|
|
|
error:{invalid_domain, _} ->
|
|
|
|
throw({error, <<"Unknown host passed in '",ArgName/binary,"'">>});
|
|
|
|
error:{unregistered_route, _} ->
|
|
|
|
throw({error, <<"Unknown host passed in '",ArgName/binary,"'">>})
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
|
|
|
-spec validate_muc2(Name :: binary(), ArgName::binary()) -> {binary(), binary()}.
|
|
|
|
validate_muc2(Name, ArgName) ->
|
|
|
|
case jid:nameprep(Name) of
|
|
|
|
error ->
|
|
|
|
throw({error, <<"Invalid value of '",ArgName/binary,"'">>});
|
|
|
|
Name2 ->
|
|
|
|
try get_room_serverhost(Name2) of
|
|
|
|
Host -> {Host, Name2}
|
|
|
|
catch
|
|
|
|
error:{invalid_domain, _} ->
|
|
|
|
throw({error, <<"Unknown host passed in '",ArgName/binary,"'">>});
|
|
|
|
error:{unregistered_route, _} ->
|
|
|
|
throw({error, <<"Unknown host passed in '",ArgName/binary,"'">>})
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
|
|
|
-spec validate_room(Name :: binary(), ArgName :: binary()) -> binary().
|
|
|
|
validate_room(Name, ArgName) ->
|
|
|
|
case jid:nodeprep(Name) of
|
|
|
|
error ->
|
|
|
|
throw({error, <<"Invalid value of '",ArgName/binary,"'">>});
|
|
|
|
Name2 ->
|
|
|
|
Name2
|
|
|
|
end.
|
|
|
|
|
2019-08-08 11:03:12 +02:00
|
|
|
find_service(global) ->
|
2015-04-07 16:30:34 +02:00
|
|
|
global;
|
2019-08-08 11:03:12 +02:00
|
|
|
find_service(ServerHost) ->
|
|
|
|
hd(gen_mod:get_module_opt_hosts(ServerHost, mod_muc)).
|
|
|
|
|
2024-02-28 12:01:14 +01:00
|
|
|
find_services_validate(Global, _Name) when Global == global;
|
|
|
|
Global == <<"global">> ->
|
|
|
|
find_services(Global);
|
|
|
|
find_services_validate(Service, Name) ->
|
|
|
|
case validate_muc(Service, Name) of
|
|
|
|
Service2 -> find_services(Service2)
|
|
|
|
end.
|
|
|
|
|
2019-08-08 11:03:12 +02:00
|
|
|
find_services(Global) when Global == global;
|
|
|
|
Global == <<"global">> ->
|
|
|
|
lists:flatmap(
|
|
|
|
fun(ServerHost) ->
|
|
|
|
case gen_mod:is_loaded(ServerHost, mod_muc) of
|
|
|
|
true ->
|
|
|
|
[find_service(ServerHost)];
|
|
|
|
false ->
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
end, ejabberd_option:hosts());
|
|
|
|
find_services(Service) when is_binary(Service) ->
|
|
|
|
[Service].
|
|
|
|
|
|
|
|
get_room_serverhost(Service) when is_binary(Service) ->
|
|
|
|
ejabberd_router:host_of_route(Service).
|
|
|
|
|
2015-04-07 16:30:34 +02:00
|
|
|
find_host(ServerHost) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
hd(gen_mod:get_module_opt_hosts(ServerHost, mod_muc)).
|
2015-06-01 14:38:27 +02:00
|
|
|
|
2017-01-13 10:03:39 +01:00
|
|
|
find_hosts(Global) when Global == global;
|
|
|
|
Global == <<"global">> ->
|
|
|
|
lists:flatmap(
|
|
|
|
fun(ServerHost) ->
|
|
|
|
case gen_mod:is_loaded(ServerHost, mod_muc) of
|
|
|
|
true ->
|
2017-12-21 17:00:43 +01:00
|
|
|
[find_host(ServerHost)];
|
2017-01-13 10:03:39 +01:00
|
|
|
false ->
|
|
|
|
[]
|
|
|
|
end
|
2019-06-14 11:33:26 +02:00
|
|
|
end, ejabberd_option:hosts());
|
2017-01-13 10:03:39 +01:00
|
|
|
find_hosts(ServerHost) ->
|
|
|
|
case gen_mod:is_loaded(ServerHost, mod_muc) of
|
|
|
|
true ->
|
2017-12-21 17:00:43 +01:00
|
|
|
[find_host(ServerHost)];
|
2017-01-13 10:03:39 +01:00
|
|
|
false ->
|
|
|
|
[]
|
|
|
|
end.
|
|
|
|
|
2021-12-20 07:37:47 +01:00
|
|
|
mod_opt_type(subscribe_room_many_max_users) ->
|
|
|
|
econf:int().
|
|
|
|
|
|
|
|
mod_options(_) ->
|
|
|
|
[{subscribe_room_many_max_users, 50}].
|
2020-01-08 10:24:51 +01:00
|
|
|
|
|
|
|
mod_doc() ->
|
|
|
|
#{desc =>
|
|
|
|
[?T("This module provides commands to administer local MUC "
|
|
|
|
"services and their MUC rooms. It also provides simple "
|
|
|
|
"WebAdmin pages to view the existing rooms."), "",
|
2022-01-13 19:27:53 +01:00
|
|
|
?T("This module depends on _`mod_muc`_.")],
|
|
|
|
opts =>
|
|
|
|
[{subscribe_room_many_max_users,
|
|
|
|
#{value => ?T("Number"),
|
2022-05-04 15:18:57 +02:00
|
|
|
note => "added in 22.05",
|
2022-01-13 19:27:53 +01:00
|
|
|
desc =>
|
|
|
|
?T("How many users can be subscribed to a room at once using "
|
|
|
|
"the 'subscribe_room_many' command. "
|
|
|
|
"The default value is '50'.")}}]}.
|