2004-08-13 00:34:19 +02:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : mod_announce.erl
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% Author : Alexey Shchepin <alexey@process-one.net>
|
2004-08-13 00:34:19 +02:00
|
|
|
%%% Purpose : Manage announce messages
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% Created : 11 Aug 2003 by Alexey Shchepin <alexey@process-one.net>
|
|
|
|
%%%
|
|
|
|
%%%
|
2019-01-08 22:53:27 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2019 ProcessOne
|
2007-12-24 12:41:41 +01:00
|
|
|
%%%
|
|
|
|
%%% This program is free software; you can redistribute it and/or
|
|
|
|
%%% modify it under the terms of the GNU General Public License as
|
|
|
|
%%% published by the Free Software Foundation; either version 2 of the
|
|
|
|
%%% License, or (at your option) any later version.
|
|
|
|
%%%
|
|
|
|
%%% This program is distributed in the hope that it will be useful,
|
|
|
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
%%% General Public License for more details.
|
2009-01-12 15:44:42 +01:00
|
|
|
%%%
|
2014-02-22 11:27:40 +01:00
|
|
|
%%% You should have received a copy of the GNU General Public License along
|
|
|
|
%%% with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2007-12-24 12:41:41 +01:00
|
|
|
%%%
|
2004-08-13 00:34:19 +02:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% Implements a small subset of XEP-0133: Service Administration
|
|
|
|
%%% Version 1.1 (2005-08-19)
|
2007-09-04 09:55:41 +02:00
|
|
|
|
2004-08-13 00:34:19 +02:00
|
|
|
-module(mod_announce).
|
2007-12-24 12:41:41 +01:00
|
|
|
-author('alexey@process-one.net').
|
2004-08-13 00:34:19 +02:00
|
|
|
|
2017-02-14 08:25:08 +01:00
|
|
|
-behaviour(gen_server).
|
2004-08-13 00:34:19 +02:00
|
|
|
-behaviour(gen_mod).
|
|
|
|
|
2017-02-22 17:46:47 +01:00
|
|
|
-export([start/2, stop/1, reload/3, export/1, import_info/0,
|
2017-02-16 09:00:26 +01:00
|
|
|
import_start/2, import/5, announce/1, send_motd/1, disco_identity/5,
|
2016-07-06 13:58:48 +02:00
|
|
|
disco_features/5, disco_items/5, depends/2,
|
2015-06-01 14:38:27 +02:00
|
|
|
send_announcement_to_all/3, announce_commands/4,
|
2018-01-23 08:54:52 +01:00
|
|
|
announce_items/4, mod_opt_type/1, mod_options/1, clean_cache/1]).
|
2017-02-14 10:39:26 +01:00
|
|
|
-export([init/1, handle_call/3, handle_cast/2,
|
2017-02-14 08:25:08 +01:00
|
|
|
handle_info/2, terminate/2, code_change/3]).
|
2017-02-16 09:00:26 +01:00
|
|
|
-export([announce_all/1,
|
|
|
|
announce_all_hosts_all/1,
|
|
|
|
announce_online/1,
|
|
|
|
announce_all_hosts_online/1,
|
|
|
|
announce_motd/1,
|
|
|
|
announce_all_hosts_motd/1,
|
|
|
|
announce_motd_update/1,
|
|
|
|
announce_all_hosts_motd_update/1,
|
|
|
|
announce_motd_delete/1,
|
|
|
|
announce_all_hosts_motd_delete/1]).
|
2004-08-13 00:34:19 +02:00
|
|
|
|
2013-04-08 11:12:54 +02:00
|
|
|
-include("logger.hrl").
|
2016-07-26 08:52:29 +02:00
|
|
|
-include("xmpp.hrl").
|
2016-04-13 12:04:04 +02:00
|
|
|
-include("mod_announce.hrl").
|
2019-06-22 16:08:45 +02:00
|
|
|
-include("translate.hrl").
|
2004-08-13 00:34:19 +02:00
|
|
|
|
2016-04-13 12:04:04 +02:00
|
|
|
-callback init(binary(), gen_mod:opts()) -> any().
|
2016-11-22 14:48:01 +01:00
|
|
|
-callback import(binary(), binary(), [binary()]) -> ok.
|
2017-05-22 15:14:28 +02:00
|
|
|
-callback set_motd_users(binary(), [{binary(), binary(), binary()}]) -> ok | {error, any()}.
|
|
|
|
-callback set_motd(binary(), xmlel()) -> ok | {error, any()}.
|
|
|
|
-callback delete_motd(binary()) -> ok | {error, any()}.
|
|
|
|
-callback get_motd(binary()) -> {ok, xmlel()} | error | {error, any()}.
|
|
|
|
-callback is_motd_user(binary(), binary()) -> {ok, boolean()} | {error, any()}.
|
|
|
|
-callback set_motd_user(binary(), binary()) -> ok | {error, any()}.
|
|
|
|
-callback use_cache(binary()) -> boolean().
|
|
|
|
-callback cache_nodes(binary()) -> [node()].
|
|
|
|
|
|
|
|
-optional_callbacks([use_cache/1, cache_nodes/1]).
|
2004-08-13 00:34:19 +02:00
|
|
|
|
2017-02-14 08:25:08 +01:00
|
|
|
-record(state, {host :: binary()}).
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-define(NS_ADMINL(Sub), [<<"http:">>, <<"jabber.org">>, <<"protocol">>,
|
|
|
|
<<"admin">>, <<Sub>>]).
|
2017-05-22 15:14:28 +02:00
|
|
|
-define(MOTD_CACHE, motd_cache).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
|
|
|
tokenize(Node) -> str:tokens(Node, <<"/#">>).
|
2007-09-04 09:55:41 +02:00
|
|
|
|
2017-02-14 08:25:08 +01:00
|
|
|
%%====================================================================
|
|
|
|
%% gen_mod callbacks
|
|
|
|
%%====================================================================
|
2012-04-27 11:52:05 +02:00
|
|
|
start(Host, Opts) ->
|
2017-02-14 10:39:26 +01:00
|
|
|
gen_mod:start_child(?MODULE, Host, Opts).
|
2017-02-14 08:25:08 +01:00
|
|
|
|
|
|
|
stop(Host) ->
|
2017-02-14 10:39:26 +01:00
|
|
|
gen_mod:stop_child(?MODULE, Host).
|
2017-02-14 08:25:08 +01:00
|
|
|
|
2017-02-22 17:46:47 +01:00
|
|
|
reload(Host, NewOpts, OldOpts) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
NewMod = gen_mod:db_mod(NewOpts, ?MODULE),
|
|
|
|
OldMod = gen_mod:db_mod(OldOpts, ?MODULE),
|
2017-02-22 17:46:47 +01:00
|
|
|
if NewMod /= OldMod ->
|
|
|
|
NewMod:init(Host, NewOpts);
|
|
|
|
true ->
|
|
|
|
ok
|
|
|
|
end,
|
2017-05-22 15:14:28 +02:00
|
|
|
init_cache(NewMod, Host, NewOpts).
|
2017-02-22 17:46:47 +01:00
|
|
|
|
2017-02-14 08:25:08 +01:00
|
|
|
depends(_Host, _Opts) ->
|
|
|
|
[{mod_adhoc, hard}].
|
|
|
|
|
|
|
|
%%====================================================================
|
|
|
|
%% gen_server callbacks
|
|
|
|
%%====================================================================
|
|
|
|
init([Host, Opts]) ->
|
|
|
|
process_flag(trap_exit, true),
|
2019-06-14 11:33:26 +02:00
|
|
|
Mod = gen_mod:db_mod(Opts, ?MODULE),
|
2016-04-13 12:04:04 +02:00
|
|
|
Mod:init(Host, Opts),
|
2017-05-22 15:14:28 +02:00
|
|
|
init_cache(Mod, Host, Opts),
|
2005-06-20 05:18:13 +02:00
|
|
|
ejabberd_hooks:add(local_send_to_resource_hook, Host,
|
2004-08-13 00:34:19 +02:00
|
|
|
?MODULE, announce, 50),
|
2006-01-19 03:17:31 +01:00
|
|
|
ejabberd_hooks:add(disco_local_identity, Host, ?MODULE, disco_identity, 50),
|
|
|
|
ejabberd_hooks:add(disco_local_features, Host, ?MODULE, disco_features, 50),
|
|
|
|
ejabberd_hooks:add(disco_local_items, Host, ?MODULE, disco_items, 50),
|
|
|
|
ejabberd_hooks:add(adhoc_local_items, Host, ?MODULE, announce_items, 50),
|
|
|
|
ejabberd_hooks:add(adhoc_local_commands, Host, ?MODULE, announce_commands, 50),
|
2017-01-09 15:02:17 +01:00
|
|
|
ejabberd_hooks:add(c2s_self_presence, Host,
|
2004-08-13 00:34:19 +02:00
|
|
|
?MODULE, send_motd, 50),
|
2017-02-14 08:25:08 +01:00
|
|
|
{ok, #state{host = Host}}.
|
2016-07-06 13:58:48 +02:00
|
|
|
|
2019-07-12 10:55:36 +02:00
|
|
|
handle_call(Request, From, State) ->
|
|
|
|
?WARNING_MSG("Unexpected call from ~p: ~p", [From, Request]),
|
2017-02-14 08:25:08 +01:00
|
|
|
{noreply, State}.
|
2004-08-13 00:34:19 +02:00
|
|
|
|
2017-02-16 09:00:26 +01:00
|
|
|
handle_cast({F, #message{from = From, to = To} = Pkt}, State) when is_atom(F) ->
|
|
|
|
LServer = To#jid.lserver,
|
|
|
|
Host = case F of
|
|
|
|
announce_all -> LServer;
|
|
|
|
announce_all_hosts_all -> global;
|
|
|
|
announce_online -> LServer;
|
|
|
|
announce_all_hosts_online -> global;
|
|
|
|
announce_motd -> LServer;
|
|
|
|
announce_all_hosts_motd -> global;
|
|
|
|
announce_motd_update -> LServer;
|
|
|
|
announce_all_hosts_motd_update -> global;
|
|
|
|
announce_motd_delete -> LServer;
|
|
|
|
announce_all_hosts_motd_delete -> global
|
|
|
|
end,
|
|
|
|
Access = get_access(Host),
|
|
|
|
case acl:match_rule(Host, Access, From) of
|
|
|
|
deny ->
|
|
|
|
route_forbidden_error(Pkt);
|
|
|
|
allow ->
|
|
|
|
?MODULE:F(Pkt)
|
2017-02-14 08:25:08 +01:00
|
|
|
end,
|
2017-02-16 09:00:26 +01:00
|
|
|
{noreply, State};
|
|
|
|
handle_cast(Msg, State) ->
|
2019-06-24 19:32:34 +02:00
|
|
|
?WARNING_MSG("Unexpected cast: ~p", [Msg]),
|
2017-02-14 08:25:08 +01:00
|
|
|
{noreply, State}.
|
2004-08-13 00:34:19 +02:00
|
|
|
|
2017-02-16 09:00:26 +01:00
|
|
|
|
2017-02-14 08:25:08 +01:00
|
|
|
handle_info(Info, State) ->
|
2019-06-24 19:32:34 +02:00
|
|
|
?WARNING_MSG("Unexpected info: ~p", [Info]),
|
2017-02-14 08:25:08 +01:00
|
|
|
{noreply, State}.
|
|
|
|
|
|
|
|
terminate(_Reason, #state{host = Host}) ->
|
2006-01-19 03:17:31 +01:00
|
|
|
ejabberd_hooks:delete(adhoc_local_commands, Host, ?MODULE, announce_commands, 50),
|
|
|
|
ejabberd_hooks:delete(adhoc_local_items, Host, ?MODULE, announce_items, 50),
|
|
|
|
ejabberd_hooks:delete(disco_local_identity, Host, ?MODULE, disco_identity, 50),
|
|
|
|
ejabberd_hooks:delete(disco_local_features, Host, ?MODULE, disco_features, 50),
|
|
|
|
ejabberd_hooks:delete(disco_local_items, Host, ?MODULE, disco_items, 50),
|
2017-02-14 08:25:08 +01:00
|
|
|
ejabberd_hooks:delete(local_send_to_resource_hook, Host, ?MODULE, announce, 50),
|
|
|
|
ejabberd_hooks:delete(c2s_self_presence, Host, ?MODULE, send_motd, 50).
|
|
|
|
|
|
|
|
code_change(_OldVsn, State, _Extra) ->
|
|
|
|
{ok, State}.
|
2004-08-13 00:34:19 +02:00
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
%% Announcing via messages to a custom resource
|
2017-02-16 09:00:26 +01:00
|
|
|
-spec announce(stanza()) -> ok | stop.
|
|
|
|
announce(#message{to = #jid{luser = <<>>} = To} = Packet) ->
|
2017-02-14 10:39:26 +01:00
|
|
|
Proc = gen_mod:get_module_proc(To#jid.lserver, ?MODULE),
|
2016-09-13 11:30:05 +02:00
|
|
|
Res = case To#jid.lresource of
|
|
|
|
<<"announce/all">> ->
|
2017-02-16 09:00:26 +01:00
|
|
|
gen_server:cast(Proc, {announce_all, Packet});
|
2016-09-13 11:30:05 +02:00
|
|
|
<<"announce/all-hosts/all">> ->
|
2017-02-16 09:00:26 +01:00
|
|
|
gen_server:cast(Proc, {announce_all_hosts_all, Packet});
|
2016-09-13 11:30:05 +02:00
|
|
|
<<"announce/online">> ->
|
2017-02-16 09:00:26 +01:00
|
|
|
gen_server:cast(Proc, {announce_online, Packet});
|
2016-09-13 11:30:05 +02:00
|
|
|
<<"announce/all-hosts/online">> ->
|
2017-02-16 09:00:26 +01:00
|
|
|
gen_server:cast(Proc, {announce_all_hosts_online, Packet});
|
2016-09-13 11:30:05 +02:00
|
|
|
<<"announce/motd">> ->
|
2017-02-16 09:00:26 +01:00
|
|
|
gen_server:cast(Proc, {announce_motd, Packet});
|
2016-09-13 11:30:05 +02:00
|
|
|
<<"announce/all-hosts/motd">> ->
|
2017-02-16 09:00:26 +01:00
|
|
|
gen_server:cast(Proc, {announce_all_hosts_motd, Packet});
|
2016-09-13 11:30:05 +02:00
|
|
|
<<"announce/motd/update">> ->
|
2017-02-16 09:00:26 +01:00
|
|
|
gen_server:cast(Proc, {announce_motd_update, Packet});
|
2016-09-13 11:30:05 +02:00
|
|
|
<<"announce/all-hosts/motd/update">> ->
|
2017-02-16 09:00:26 +01:00
|
|
|
gen_server:cast(Proc, {announce_all_hosts_motd_update, Packet});
|
2016-09-13 11:30:05 +02:00
|
|
|
<<"announce/motd/delete">> ->
|
2017-02-16 09:00:26 +01:00
|
|
|
gen_server:cast(Proc, {announce_motd_delete, Packet});
|
2016-09-13 11:30:05 +02:00
|
|
|
<<"announce/all-hosts/motd/delete">> ->
|
2017-02-16 09:00:26 +01:00
|
|
|
gen_server:cast(Proc, {announce_all_hosts_motd_delete, Packet});
|
2016-09-13 11:30:05 +02:00
|
|
|
_ ->
|
2017-02-14 08:25:08 +01:00
|
|
|
undefined
|
2016-09-13 11:30:05 +02:00
|
|
|
end,
|
|
|
|
case Res of
|
2017-02-14 08:25:08 +01:00
|
|
|
ok -> stop;
|
|
|
|
_ -> ok
|
2016-09-13 11:30:05 +02:00
|
|
|
end;
|
2017-02-16 09:00:26 +01:00
|
|
|
announce(_Packet) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
ok.
|
2004-08-13 00:34:19 +02:00
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
%%-------------------------------------------------------------------------
|
|
|
|
%% Announcing via ad-hoc commands
|
2006-01-19 03:17:31 +01:00
|
|
|
-define(INFO_COMMAND(Lang, Node),
|
2016-07-26 08:52:29 +02:00
|
|
|
[#identity{category = <<"automation">>,
|
|
|
|
type = <<"command-node">>,
|
|
|
|
name = get_title(Lang, Node)}]).
|
2006-01-19 03:17:31 +01:00
|
|
|
|
|
|
|
disco_identity(Acc, _From, _To, Node, Lang) ->
|
2007-09-04 09:55:41 +02:00
|
|
|
LNode = tokenize(Node),
|
|
|
|
case LNode of
|
2007-12-22 13:26:17 +01:00
|
|
|
?NS_ADMINL("announce") ->
|
|
|
|
?INFO_COMMAND(Lang, Node);
|
|
|
|
?NS_ADMINL("announce-allhosts") ->
|
|
|
|
?INFO_COMMAND(Lang, Node);
|
2007-09-04 09:55:41 +02:00
|
|
|
?NS_ADMINL("announce-all") ->
|
2006-01-19 03:17:31 +01:00
|
|
|
?INFO_COMMAND(Lang, Node);
|
2007-09-04 09:55:41 +02:00
|
|
|
?NS_ADMINL("announce-all-allhosts") ->
|
2006-01-19 03:17:31 +01:00
|
|
|
?INFO_COMMAND(Lang, Node);
|
2007-12-22 13:26:17 +01:00
|
|
|
?NS_ADMINL("set-motd") ->
|
2006-01-19 03:17:31 +01:00
|
|
|
?INFO_COMMAND(Lang, Node);
|
2007-12-22 13:26:17 +01:00
|
|
|
?NS_ADMINL("set-motd-allhosts") ->
|
2007-08-03 10:53:05 +02:00
|
|
|
?INFO_COMMAND(Lang, Node);
|
2007-12-22 13:26:17 +01:00
|
|
|
?NS_ADMINL("edit-motd") ->
|
2006-01-19 03:17:31 +01:00
|
|
|
?INFO_COMMAND(Lang, Node);
|
2007-12-22 13:26:17 +01:00
|
|
|
?NS_ADMINL("edit-motd-allhosts") ->
|
2007-08-03 10:53:05 +02:00
|
|
|
?INFO_COMMAND(Lang, Node);
|
2007-09-04 09:55:41 +02:00
|
|
|
?NS_ADMINL("delete-motd") ->
|
2006-01-19 03:17:31 +01:00
|
|
|
?INFO_COMMAND(Lang, Node);
|
2007-09-04 09:55:41 +02:00
|
|
|
?NS_ADMINL("delete-motd-allhosts") ->
|
2007-08-03 10:53:05 +02:00
|
|
|
?INFO_COMMAND(Lang, Node);
|
2006-01-19 03:17:31 +01:00
|
|
|
_ ->
|
|
|
|
Acc
|
|
|
|
end.
|
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
%%-------------------------------------------------------------------------
|
2006-01-19 03:17:31 +01:00
|
|
|
|
2016-04-05 12:09:44 +02:00
|
|
|
-define(INFO_RESULT(Allow, Feats, Lang),
|
2007-09-04 09:55:41 +02:00
|
|
|
case Allow of
|
|
|
|
deny ->
|
2019-06-22 16:08:45 +02:00
|
|
|
{error, xmpp:err_forbidden(?T("Access denied by service policy"), Lang)};
|
2007-09-04 09:55:41 +02:00
|
|
|
allow ->
|
|
|
|
{result, Feats}
|
|
|
|
end).
|
2006-01-19 03:17:31 +01:00
|
|
|
|
2016-04-05 12:09:44 +02:00
|
|
|
disco_features(Acc, From, #jid{lserver = LServer} = _To, <<"announce">>, Lang) ->
|
2006-01-19 03:17:31 +01:00
|
|
|
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
|
|
|
false ->
|
|
|
|
Acc;
|
|
|
|
_ ->
|
2013-03-14 10:33:02 +01:00
|
|
|
Access1 = get_access(LServer),
|
|
|
|
Access2 = get_access(global),
|
2006-01-19 03:17:31 +01:00
|
|
|
case {acl:match_rule(LServer, Access1, From),
|
|
|
|
acl:match_rule(global, Access2, From)} of
|
|
|
|
{deny, deny} ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("Access denied by service policy"),
|
2016-07-26 08:52:29 +02:00
|
|
|
{error, xmpp:err_forbidden(Txt, Lang)};
|
2006-01-19 03:17:31 +01:00
|
|
|
_ ->
|
|
|
|
{result, []}
|
|
|
|
end
|
|
|
|
end;
|
|
|
|
|
2016-04-05 12:09:44 +02:00
|
|
|
disco_features(Acc, From, #jid{lserver = LServer} = _To, Node, Lang) ->
|
2006-01-19 03:17:31 +01:00
|
|
|
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
|
|
|
false ->
|
|
|
|
Acc;
|
|
|
|
_ ->
|
2013-03-14 10:33:02 +01:00
|
|
|
Access = get_access(LServer),
|
2006-01-19 03:17:31 +01:00
|
|
|
Allow = acl:match_rule(LServer, Access, From),
|
2013-03-14 10:33:02 +01:00
|
|
|
AccessGlobal = get_access(global),
|
2007-12-22 13:26:17 +01:00
|
|
|
AllowGlobal = acl:match_rule(global, AccessGlobal, From),
|
2006-01-19 03:17:31 +01:00
|
|
|
case Node of
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMIN_ANNOUNCE ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMIN_ANNOUNCE_ALL ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMIN_SET_MOTD ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMIN_EDIT_MOTD ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMIN_DELETE_MOTD ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMIN_ANNOUNCE_ALLHOSTS ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(AllowGlobal, [?NS_COMMANDS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMIN_ANNOUNCE_ALL_ALLHOSTS ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(AllowGlobal, [?NS_COMMANDS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMIN_SET_MOTD_ALLHOSTS ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(AllowGlobal, [?NS_COMMANDS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMIN_EDIT_MOTD_ALLHOSTS ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(AllowGlobal, [?NS_COMMANDS], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMIN_DELETE_MOTD_ALLHOSTS ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?INFO_RESULT(AllowGlobal, [?NS_COMMANDS], Lang);
|
2006-01-19 03:17:31 +01:00
|
|
|
_ ->
|
|
|
|
Acc
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
%%-------------------------------------------------------------------------
|
2006-01-19 03:17:31 +01:00
|
|
|
-define(NODE_TO_ITEM(Lang, Server, Node),
|
2016-07-26 08:52:29 +02:00
|
|
|
#disco_item{jid = jid:make(Server),
|
|
|
|
node = Node,
|
|
|
|
name = get_title(Lang, Node)}).
|
2006-01-19 03:17:31 +01:00
|
|
|
|
2016-04-05 12:09:44 +02:00
|
|
|
-define(ITEMS_RESULT(Allow, Items, Lang),
|
2007-09-04 09:55:41 +02:00
|
|
|
case Allow of
|
|
|
|
deny ->
|
2019-06-22 16:08:45 +02:00
|
|
|
{error, xmpp:err_forbidden(?T("Access denied by service policy"), Lang)};
|
2007-09-04 09:55:41 +02:00
|
|
|
allow ->
|
|
|
|
{result, Items}
|
|
|
|
end).
|
2006-01-19 03:17:31 +01:00
|
|
|
|
2016-08-05 07:41:08 +02:00
|
|
|
disco_items(Acc, From, #jid{lserver = LServer, server = Server} = _To, <<"">>, Lang) ->
|
2006-01-19 03:17:31 +01:00
|
|
|
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
|
|
|
false ->
|
|
|
|
Acc;
|
|
|
|
_ ->
|
2013-03-14 10:33:02 +01:00
|
|
|
Access1 = get_access(LServer),
|
|
|
|
Access2 = get_access(global),
|
2006-01-19 03:17:31 +01:00
|
|
|
case {acl:match_rule(LServer, Access1, From),
|
|
|
|
acl:match_rule(global, Access2, From)} of
|
|
|
|
{deny, deny} ->
|
|
|
|
Acc;
|
|
|
|
_ ->
|
|
|
|
Items = case Acc of
|
|
|
|
{result, I} -> I;
|
|
|
|
_ -> []
|
|
|
|
end,
|
2013-03-14 10:33:02 +01:00
|
|
|
Nodes = [?NODE_TO_ITEM(Lang, Server, <<"announce">>)],
|
2006-01-19 03:17:31 +01:00
|
|
|
{result, Items ++ Nodes}
|
|
|
|
end
|
|
|
|
end;
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
disco_items(Acc, From, #jid{lserver = LServer} = To, <<"announce">>, Lang) ->
|
2006-01-19 03:17:31 +01:00
|
|
|
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
|
|
|
false ->
|
|
|
|
Acc;
|
|
|
|
_ ->
|
|
|
|
announce_items(Acc, From, To, Lang)
|
|
|
|
end;
|
|
|
|
|
2016-04-05 12:09:44 +02:00
|
|
|
disco_items(Acc, From, #jid{lserver = LServer} = _To, Node, Lang) ->
|
2006-01-19 03:17:31 +01:00
|
|
|
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
|
|
|
false ->
|
|
|
|
Acc;
|
|
|
|
_ ->
|
2013-03-14 10:33:02 +01:00
|
|
|
Access = get_access(LServer),
|
2006-01-19 03:17:31 +01:00
|
|
|
Allow = acl:match_rule(LServer, Access, From),
|
2013-03-14 10:33:02 +01:00
|
|
|
AccessGlobal = get_access(global),
|
2007-12-22 13:26:17 +01:00
|
|
|
AllowGlobal = acl:match_rule(global, AccessGlobal, From),
|
2006-01-19 03:17:31 +01:00
|
|
|
case Node of
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMIN_ANNOUNCE ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, [], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMIN_ANNOUNCE_ALL ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, [], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMIN_SET_MOTD ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, [], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMIN_EDIT_MOTD ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, [], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMIN_DELETE_MOTD ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(Allow, [], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMIN_ANNOUNCE_ALLHOSTS ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(AllowGlobal, [], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMIN_ANNOUNCE_ALL_ALLHOSTS ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(AllowGlobal, [], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMIN_SET_MOTD_ALLHOSTS ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(AllowGlobal, [], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMIN_EDIT_MOTD_ALLHOSTS ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(AllowGlobal, [], Lang);
|
2013-03-14 10:33:02 +01:00
|
|
|
?NS_ADMIN_DELETE_MOTD_ALLHOSTS ->
|
2016-04-05 12:09:44 +02:00
|
|
|
?ITEMS_RESULT(AllowGlobal, [], Lang);
|
2006-01-19 03:17:31 +01:00
|
|
|
_ ->
|
|
|
|
Acc
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
%%-------------------------------------------------------------------------
|
2016-09-08 16:08:48 +02:00
|
|
|
-spec announce_items(empty | {error, stanza_error()} | {result, [disco_item()]},
|
|
|
|
jid(), jid(), binary()) -> {error, stanza_error()} |
|
2016-08-09 09:56:32 +02:00
|
|
|
{result, [disco_item()]} |
|
|
|
|
empty.
|
2006-01-19 03:17:31 +01:00
|
|
|
announce_items(Acc, From, #jid{lserver = LServer, server = Server} = _To, Lang) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
Access1 = get_access(LServer),
|
2006-01-19 03:17:31 +01:00
|
|
|
Nodes1 = case acl:match_rule(LServer, Access1, From) of
|
|
|
|
allow ->
|
2013-03-14 10:33:02 +01:00
|
|
|
[?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN_ANNOUNCE),
|
|
|
|
?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN_ANNOUNCE_ALL),
|
|
|
|
?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN_SET_MOTD),
|
|
|
|
?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN_EDIT_MOTD),
|
|
|
|
?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN_DELETE_MOTD)];
|
2006-01-19 03:17:31 +01:00
|
|
|
deny ->
|
|
|
|
[]
|
|
|
|
end,
|
2013-03-14 10:33:02 +01:00
|
|
|
Access2 = get_access(global),
|
2006-01-19 03:17:31 +01:00
|
|
|
Nodes2 = case acl:match_rule(global, Access2, From) of
|
|
|
|
allow ->
|
2013-03-14 10:33:02 +01:00
|
|
|
[?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN_ANNOUNCE_ALLHOSTS),
|
|
|
|
?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN_ANNOUNCE_ALL_ALLHOSTS),
|
|
|
|
?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN_SET_MOTD_ALLHOSTS),
|
|
|
|
?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN_EDIT_MOTD_ALLHOSTS),
|
|
|
|
?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN_DELETE_MOTD_ALLHOSTS)];
|
2006-01-19 03:17:31 +01:00
|
|
|
deny ->
|
|
|
|
[]
|
|
|
|
end,
|
|
|
|
case {Nodes1, Nodes2} of
|
|
|
|
{[], []} ->
|
|
|
|
Acc;
|
|
|
|
_ ->
|
|
|
|
Items = case Acc of
|
|
|
|
{result, I} -> I;
|
|
|
|
_ -> []
|
|
|
|
end,
|
|
|
|
{result, Items ++ Nodes1 ++ Nodes2}
|
|
|
|
end.
|
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
%%-------------------------------------------------------------------------
|
2006-01-19 03:17:31 +01:00
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
commands_result(Allow, From, To, Request) ->
|
2006-01-19 03:17:31 +01:00
|
|
|
case Allow of
|
|
|
|
deny ->
|
2016-07-26 08:52:29 +02:00
|
|
|
Lang = Request#adhoc_command.lang,
|
2019-06-22 16:08:45 +02:00
|
|
|
{error, xmpp:err_forbidden(?T("Access denied by service policy"), Lang)};
|
2006-01-19 03:17:31 +01:00
|
|
|
allow ->
|
|
|
|
announce_commands(From, To, Request)
|
2007-09-04 09:55:41 +02:00
|
|
|
end.
|
|
|
|
|
2017-02-16 12:18:36 +01:00
|
|
|
-spec announce_commands(empty | adhoc_command(), jid(), jid(), adhoc_command()) ->
|
2016-09-08 16:08:48 +02:00
|
|
|
adhoc_command() | {error, stanza_error()}.
|
2006-01-19 03:17:31 +01:00
|
|
|
announce_commands(Acc, From, #jid{lserver = LServer} = To,
|
2016-07-26 08:52:29 +02:00
|
|
|
#adhoc_command{node = Node} = Request) ->
|
2007-09-04 09:55:41 +02:00
|
|
|
LNode = tokenize(Node),
|
|
|
|
F = fun() ->
|
2013-03-14 10:33:02 +01:00
|
|
|
Access = get_access(global),
|
2007-09-04 09:55:41 +02:00
|
|
|
Allow = acl:match_rule(global, Access, From),
|
|
|
|
commands_result(Allow, From, To, Request)
|
|
|
|
end,
|
|
|
|
R = case LNode of
|
2007-12-22 13:26:17 +01:00
|
|
|
?NS_ADMINL("announce-allhosts") -> F();
|
2007-09-04 09:55:41 +02:00
|
|
|
?NS_ADMINL("announce-all-allhosts") -> F();
|
2007-12-22 13:26:17 +01:00
|
|
|
?NS_ADMINL("set-motd-allhosts") -> F();
|
2007-09-04 09:55:41 +02:00
|
|
|
?NS_ADMINL("edit-motd-allhosts") -> F();
|
|
|
|
?NS_ADMINL("delete-motd-allhosts") -> F();
|
|
|
|
_ ->
|
2013-03-14 10:33:02 +01:00
|
|
|
Access = get_access(LServer),
|
2007-09-04 09:55:41 +02:00
|
|
|
Allow = acl:match_rule(LServer, Access, From),
|
|
|
|
case LNode of
|
|
|
|
?NS_ADMINL("announce") ->
|
|
|
|
commands_result(Allow, From, To, Request);
|
2007-12-22 13:26:17 +01:00
|
|
|
?NS_ADMINL("announce-all") ->
|
2007-09-04 09:55:41 +02:00
|
|
|
commands_result(Allow, From, To, Request);
|
2007-12-22 13:26:17 +01:00
|
|
|
?NS_ADMINL("set-motd") ->
|
2007-09-04 09:55:41 +02:00
|
|
|
commands_result(Allow, From, To, Request);
|
|
|
|
?NS_ADMINL("edit-motd") ->
|
|
|
|
commands_result(Allow, From, To, Request);
|
2007-12-22 13:26:17 +01:00
|
|
|
?NS_ADMINL("delete-motd") ->
|
|
|
|
commands_result(Allow, From, To, Request);
|
2007-09-04 09:55:41 +02:00
|
|
|
_ ->
|
|
|
|
unknown
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
case R of
|
|
|
|
unknown -> Acc;
|
|
|
|
_ -> {stop, R}
|
2006-01-19 03:17:31 +01:00
|
|
|
end.
|
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
%%-------------------------------------------------------------------------
|
2006-01-19 03:17:31 +01:00
|
|
|
|
|
|
|
announce_commands(From, To,
|
2016-07-26 08:52:29 +02:00
|
|
|
#adhoc_command{lang = Lang,
|
2006-01-19 03:17:31 +01:00
|
|
|
node = Node,
|
2016-07-26 08:52:29 +02:00
|
|
|
sid = SID,
|
|
|
|
xdata = XData,
|
|
|
|
action = Action} = Request) ->
|
|
|
|
if Action == cancel ->
|
2006-01-19 03:17:31 +01:00
|
|
|
%% User cancels request
|
2016-07-26 08:52:29 +02:00
|
|
|
#adhoc_command{status = canceled, lang = Lang, node = Node,
|
|
|
|
sid = SID};
|
2019-04-06 15:52:22 +02:00
|
|
|
XData == undefined andalso Action == execute ->
|
2006-01-19 03:17:31 +01:00
|
|
|
%% User requests form
|
2016-07-26 08:52:29 +02:00
|
|
|
Form = generate_adhoc_form(Lang, Node, To#jid.lserver),
|
2019-04-06 15:52:22 +02:00
|
|
|
xmpp_util:make_adhoc_response(
|
|
|
|
#adhoc_command{status = executing, lang = Lang, node = Node,
|
|
|
|
sid = SID, xdata = Form});
|
|
|
|
XData /= undefined andalso (Action == execute orelse Action == complete) ->
|
|
|
|
case handle_adhoc_form(From, To, Request) of
|
|
|
|
ok ->
|
|
|
|
#adhoc_command{lang = Lang, node = Node, sid = SID,
|
|
|
|
status = completed};
|
|
|
|
{error, _} = Err ->
|
|
|
|
Err
|
|
|
|
end;
|
2006-01-19 03:17:31 +01:00
|
|
|
true ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("Unexpected action"),
|
2016-07-26 08:52:29 +02:00
|
|
|
{error, xmpp:err_bad_request(Txt, Lang)}
|
2006-01-19 03:17:31 +01:00
|
|
|
end.
|
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
-define(TVFIELD(Type, Var, Val),
|
2016-07-26 08:52:29 +02:00
|
|
|
#xdata_field{type = Type, var = Var, values = vvaluel(Val)}).
|
2007-09-04 09:55:41 +02:00
|
|
|
|
2011-09-05 09:09:36 +02:00
|
|
|
vvaluel(Val) ->
|
|
|
|
case Val of
|
2013-03-14 10:33:02 +01:00
|
|
|
<<>> -> [];
|
2016-07-26 08:52:29 +02:00
|
|
|
_ -> [Val]
|
2011-09-05 09:09:36 +02:00
|
|
|
end.
|
|
|
|
|
2007-12-22 14:58:19 +01:00
|
|
|
generate_adhoc_form(Lang, Node, ServerHost) ->
|
2007-09-04 09:55:41 +02:00
|
|
|
LNode = tokenize(Node),
|
2019-04-06 15:52:22 +02:00
|
|
|
{OldSubject, OldBody} = if (LNode == ?NS_ADMINL("edit-motd"))
|
2007-12-22 14:58:19 +01:00
|
|
|
or (LNode == ?NS_ADMINL("edit-motd-allhosts")) ->
|
|
|
|
get_stored_motd(ServerHost);
|
2019-04-06 15:52:22 +02:00
|
|
|
true ->
|
2013-04-25 16:00:24 +02:00
|
|
|
{<<>>, <<>>}
|
2007-12-22 14:58:19 +01:00
|
|
|
end,
|
2016-07-26 08:52:29 +02:00
|
|
|
Fs = if (LNode == ?NS_ADMINL("delete-motd"))
|
|
|
|
or (LNode == ?NS_ADMINL("delete-motd-allhosts")) ->
|
|
|
|
[#xdata_field{type = boolean,
|
|
|
|
var = <<"confirm">>,
|
|
|
|
label = translate:translate(
|
2019-06-22 16:08:45 +02:00
|
|
|
Lang, ?T("Really delete message of the day?")),
|
2016-07-26 08:52:29 +02:00
|
|
|
values = [<<"true">>]}];
|
|
|
|
true ->
|
|
|
|
[#xdata_field{type = 'text-single',
|
|
|
|
var = <<"subject">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
label = translate:translate(Lang, ?T("Subject")),
|
2016-07-26 08:52:29 +02:00
|
|
|
values = vvaluel(OldSubject)},
|
|
|
|
#xdata_field{type = 'text-multi',
|
|
|
|
var = <<"body">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
label = translate:translate(Lang, ?T("Message body")),
|
2016-07-26 08:52:29 +02:00
|
|
|
values = vvaluel(OldBody)}]
|
|
|
|
end,
|
|
|
|
#xdata{type = form,
|
|
|
|
title = get_title(Lang, Node),
|
|
|
|
fields = [#xdata_field{type = hidden, var = <<"FORM_TYPE">>,
|
|
|
|
values = [?NS_ADMIN]}|Fs]}.
|
2006-01-19 03:17:31 +01:00
|
|
|
|
|
|
|
join_lines([]) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
<<>>;
|
2006-01-19 03:17:31 +01:00
|
|
|
join_lines(Lines) ->
|
|
|
|
join_lines(Lines, []).
|
|
|
|
join_lines([Line|Lines], Acc) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
join_lines(Lines, [<<"\n">>,Line|Acc]);
|
2006-01-19 03:17:31 +01:00
|
|
|
join_lines([], Acc) ->
|
|
|
|
%% Remove last newline
|
2013-03-14 10:33:02 +01:00
|
|
|
iolist_to_binary(lists:reverse(tl(Acc))).
|
2006-01-19 03:17:31 +01:00
|
|
|
|
|
|
|
handle_adhoc_form(From, #jid{lserver = LServer} = To,
|
2016-07-26 08:52:29 +02:00
|
|
|
#adhoc_command{lang = Lang, node = Node,
|
2019-04-06 15:52:22 +02:00
|
|
|
xdata = XData}) ->
|
2016-07-26 08:52:29 +02:00
|
|
|
Confirm = case xmpp_util:get_xdata_values(<<"confirm">>, XData) of
|
|
|
|
[<<"true">>] -> true;
|
|
|
|
[<<"1">>] -> true;
|
|
|
|
_ -> false
|
2006-01-19 03:17:31 +01:00
|
|
|
end,
|
2016-07-26 08:52:29 +02:00
|
|
|
Subject = join_lines(xmpp_util:get_xdata_values(<<"subject">>, XData)),
|
|
|
|
Body = join_lines(xmpp_util:get_xdata_values(<<"body">>, XData)),
|
2017-02-16 09:00:26 +01:00
|
|
|
Packet = #message{from = From,
|
|
|
|
to = To,
|
|
|
|
type = headline,
|
2016-07-26 08:52:29 +02:00
|
|
|
body = xmpp:mk_text(Body),
|
|
|
|
subject = xmpp:mk_text(Subject)},
|
2017-02-14 10:39:26 +01:00
|
|
|
Proc = gen_mod:get_module_proc(LServer, ?MODULE),
|
2006-01-19 03:17:31 +01:00
|
|
|
case {Node, Body} of
|
2013-03-14 10:33:02 +01:00
|
|
|
{?NS_ADMIN_DELETE_MOTD, _} ->
|
2006-01-19 03:17:31 +01:00
|
|
|
if Confirm ->
|
2019-04-06 15:52:22 +02:00
|
|
|
gen_server:cast(Proc, {announce_motd_delete, Packet});
|
2007-09-04 09:55:41 +02:00
|
|
|
true ->
|
2019-04-06 15:52:22 +02:00
|
|
|
ok
|
2006-01-19 03:17:31 +01:00
|
|
|
end;
|
2013-03-14 10:33:02 +01:00
|
|
|
{?NS_ADMIN_DELETE_MOTD_ALLHOSTS, _} ->
|
2007-08-03 10:53:05 +02:00
|
|
|
if Confirm ->
|
2019-04-06 15:52:22 +02:00
|
|
|
gen_server:cast(Proc, {announce_all_hosts_motd_delete, Packet});
|
2007-09-04 09:55:41 +02:00
|
|
|
true ->
|
2019-04-06 15:52:22 +02:00
|
|
|
ok
|
2007-08-03 10:53:05 +02:00
|
|
|
end;
|
2013-03-14 10:33:02 +01:00
|
|
|
{_, <<>>} ->
|
2006-01-19 03:17:31 +01:00
|
|
|
%% An announce message with no body is definitely an operator error.
|
|
|
|
%% Throw an error and give him/her a chance to send message again.
|
2016-07-26 08:52:29 +02:00
|
|
|
{error, xmpp:err_not_acceptable(
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("No body provided for announce message"), Lang)};
|
2017-02-14 10:39:26 +01:00
|
|
|
%% Now send the packet to ?MODULE.
|
2006-01-19 03:17:31 +01:00
|
|
|
%% We don't use direct announce_* functions because it
|
|
|
|
%% leads to large delay in response and <iq/> queries processing
|
2013-03-14 10:33:02 +01:00
|
|
|
{?NS_ADMIN_ANNOUNCE, _} ->
|
2019-04-06 15:52:22 +02:00
|
|
|
gen_server:cast(Proc, {announce_online, Packet});
|
|
|
|
{?NS_ADMIN_ANNOUNCE_ALLHOSTS, _} ->
|
|
|
|
gen_server:cast(Proc, {announce_all_hosts_online, Packet});
|
2013-03-14 10:33:02 +01:00
|
|
|
{?NS_ADMIN_ANNOUNCE_ALL, _} ->
|
2019-04-06 15:52:22 +02:00
|
|
|
gen_server:cast(Proc, {announce_all, Packet});
|
|
|
|
{?NS_ADMIN_ANNOUNCE_ALL_ALLHOSTS, _} ->
|
|
|
|
gen_server:cast(Proc, {announce_all_hosts_all, Packet});
|
2013-03-14 10:33:02 +01:00
|
|
|
{?NS_ADMIN_SET_MOTD, _} ->
|
2019-04-06 15:52:22 +02:00
|
|
|
gen_server:cast(Proc, {announce_motd, Packet});
|
|
|
|
{?NS_ADMIN_SET_MOTD_ALLHOSTS, _} ->
|
|
|
|
gen_server:cast(Proc, {announce_all_hosts_motd, Packet});
|
2013-03-14 10:33:02 +01:00
|
|
|
{?NS_ADMIN_EDIT_MOTD, _} ->
|
2019-04-06 15:52:22 +02:00
|
|
|
gen_server:cast(Proc, {announce_motd_update, Packet});
|
|
|
|
{?NS_ADMIN_EDIT_MOTD_ALLHOSTS, _} ->
|
|
|
|
gen_server:cast(Proc, {announce_all_hosts_motd_update, Packet});
|
2016-07-26 08:52:29 +02:00
|
|
|
Junk ->
|
2006-01-19 03:17:31 +01:00
|
|
|
%% This can't happen, as we haven't registered any other
|
|
|
|
%% command nodes.
|
2019-06-24 19:32:34 +02:00
|
|
|
?ERROR_MSG("Unexpected node/body = ~p", [Junk]),
|
2016-07-26 08:52:29 +02:00
|
|
|
{error, xmpp:err_internal_server_error()}
|
2006-01-19 03:17:31 +01:00
|
|
|
end.
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
get_title(Lang, <<"announce">>) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
translate:translate(Lang, ?T("Announcements"));
|
2013-03-14 10:33:02 +01:00
|
|
|
get_title(Lang, ?NS_ADMIN_ANNOUNCE_ALL) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
translate:translate(Lang, ?T("Send announcement to all users"));
|
2013-03-14 10:33:02 +01:00
|
|
|
get_title(Lang, ?NS_ADMIN_ANNOUNCE_ALL_ALLHOSTS) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
translate:translate(Lang, ?T("Send announcement to all users on all hosts"));
|
2013-03-14 10:33:02 +01:00
|
|
|
get_title(Lang, ?NS_ADMIN_ANNOUNCE) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
translate:translate(Lang, ?T("Send announcement to all online users"));
|
2013-03-14 10:33:02 +01:00
|
|
|
get_title(Lang, ?NS_ADMIN_ANNOUNCE_ALLHOSTS) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
translate:translate(Lang, ?T("Send announcement to all online users on all hosts"));
|
2013-03-14 10:33:02 +01:00
|
|
|
get_title(Lang, ?NS_ADMIN_SET_MOTD) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
translate:translate(Lang, ?T("Set message of the day and send to online users"));
|
2013-03-14 10:33:02 +01:00
|
|
|
get_title(Lang, ?NS_ADMIN_SET_MOTD_ALLHOSTS) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
translate:translate(Lang, ?T("Set message of the day on all hosts and send to online users"));
|
2013-03-14 10:33:02 +01:00
|
|
|
get_title(Lang, ?NS_ADMIN_EDIT_MOTD) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
translate:translate(Lang, ?T("Update message of the day (don't send)"));
|
2013-03-14 10:33:02 +01:00
|
|
|
get_title(Lang, ?NS_ADMIN_EDIT_MOTD_ALLHOSTS) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
translate:translate(Lang, ?T("Update message of the day on all hosts (don't send)"));
|
2013-03-14 10:33:02 +01:00
|
|
|
get_title(Lang, ?NS_ADMIN_DELETE_MOTD) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
translate:translate(Lang, ?T("Delete message of the day"));
|
2013-03-14 10:33:02 +01:00
|
|
|
get_title(Lang, ?NS_ADMIN_DELETE_MOTD_ALLHOSTS) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
translate:translate(Lang, ?T("Delete message of the day on all hosts")).
|
2006-01-19 03:17:31 +01:00
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
%%-------------------------------------------------------------------------
|
2006-01-19 03:17:31 +01:00
|
|
|
|
2017-02-16 09:00:26 +01:00
|
|
|
announce_all(#message{to = To} = Packet) ->
|
|
|
|
Local = jid:make(To#jid.server),
|
|
|
|
lists:foreach(
|
|
|
|
fun({User, Server}) ->
|
2017-02-25 08:01:01 +01:00
|
|
|
Dest = jid:make(User, Server),
|
2017-02-16 09:00:26 +01:00
|
|
|
ejabberd_router:route(
|
|
|
|
xmpp:set_from_to(add_store_hint(Packet), Local, Dest))
|
2017-05-11 13:37:21 +02:00
|
|
|
end, ejabberd_auth:get_users(To#jid.lserver)).
|
2017-02-16 09:00:26 +01:00
|
|
|
|
|
|
|
announce_all_hosts_all(#message{to = To} = Packet) ->
|
|
|
|
Local = jid:make(To#jid.server),
|
|
|
|
lists:foreach(
|
|
|
|
fun({User, Server}) ->
|
2017-02-25 08:01:01 +01:00
|
|
|
Dest = jid:make(User, Server),
|
2017-02-16 09:00:26 +01:00
|
|
|
ejabberd_router:route(
|
|
|
|
xmpp:set_from_to(add_store_hint(Packet), Local, Dest))
|
2017-05-11 13:37:21 +02:00
|
|
|
end, ejabberd_auth:get_users()).
|
2007-08-03 10:53:05 +02:00
|
|
|
|
2017-02-16 09:00:26 +01:00
|
|
|
announce_online(#message{to = To} = Packet) ->
|
|
|
|
announce_online1(ejabberd_sm:get_vh_session_list(To#jid.lserver),
|
|
|
|
To#jid.server, Packet).
|
2004-08-13 00:34:19 +02:00
|
|
|
|
2017-02-16 09:00:26 +01:00
|
|
|
announce_all_hosts_online(#message{to = To} = Packet) ->
|
|
|
|
announce_online1(ejabberd_sm:dirty_get_sessions_list(),
|
|
|
|
To#jid.server, Packet).
|
2005-04-17 20:08:34 +02:00
|
|
|
|
|
|
|
announce_online1(Sessions, Server, Packet) ->
|
2016-07-26 08:52:29 +02:00
|
|
|
Local = jid:make(Server),
|
2004-08-13 00:34:19 +02:00
|
|
|
lists:foreach(
|
2005-04-17 20:08:34 +02:00
|
|
|
fun({U, S, R}) ->
|
2015-11-24 16:44:13 +01:00
|
|
|
Dest = jid:make(U, S, R),
|
2017-02-16 09:00:26 +01:00
|
|
|
ejabberd_router:route(xmpp:set_from_to(Packet, Local, Dest))
|
2004-08-13 00:34:19 +02:00
|
|
|
end, Sessions).
|
|
|
|
|
2017-02-16 09:00:26 +01:00
|
|
|
announce_motd(#message{to = To} = Packet) ->
|
|
|
|
announce_motd(To#jid.lserver, Packet).
|
2007-08-03 10:53:05 +02:00
|
|
|
|
2017-02-16 09:00:26 +01:00
|
|
|
announce_all_hosts_motd(Packet) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
Hosts = ejabberd_option:hosts(),
|
2017-02-16 09:00:26 +01:00
|
|
|
[announce_motd(Host, Packet) || Host <- Hosts].
|
2004-08-13 00:34:19 +02:00
|
|
|
|
2007-08-03 10:53:05 +02:00
|
|
|
announce_motd(Host, Packet) ->
|
2015-11-24 16:44:13 +01:00
|
|
|
LServer = jid:nameprep(Host),
|
2012-04-27 11:52:05 +02:00
|
|
|
announce_motd_update(LServer, Packet),
|
|
|
|
Sessions = ejabberd_sm:get_vh_session_list(LServer),
|
|
|
|
announce_online1(Sessions, LServer, Packet),
|
2016-04-13 12:04:04 +02:00
|
|
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
|
|
|
Mod:set_motd_users(LServer, Sessions).
|
2007-08-03 10:53:05 +02:00
|
|
|
|
2017-02-16 09:00:26 +01:00
|
|
|
announce_motd_update(#message{to = To} = Packet) ->
|
|
|
|
announce_motd_update(To#jid.lserver, Packet).
|
2004-08-13 00:34:19 +02:00
|
|
|
|
2017-02-16 09:00:26 +01:00
|
|
|
announce_all_hosts_motd_update(Packet) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
Hosts = ejabberd_option:hosts(),
|
2017-02-16 09:00:26 +01:00
|
|
|
[announce_motd_update(Host, Packet) || Host <- Hosts].
|
2007-08-03 10:53:05 +02:00
|
|
|
|
2005-04-17 20:08:34 +02:00
|
|
|
announce_motd_update(LServer, Packet) ->
|
2016-04-13 12:04:04 +02:00
|
|
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
2017-05-22 15:14:28 +02:00
|
|
|
delete_motd(Mod, LServer),
|
|
|
|
set_motd(Mod, LServer, xmpp:encode(Packet)).
|
2004-08-13 00:34:19 +02:00
|
|
|
|
2017-02-16 09:00:26 +01:00
|
|
|
announce_motd_delete(#message{to = To}) ->
|
|
|
|
LServer = To#jid.lserver,
|
2016-04-13 12:04:04 +02:00
|
|
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
2017-05-22 15:14:28 +02:00
|
|
|
delete_motd(Mod, LServer).
|
2016-04-13 12:04:04 +02:00
|
|
|
|
2017-02-16 09:00:26 +01:00
|
|
|
announce_all_hosts_motd_delete(_Packet) ->
|
|
|
|
lists:foreach(
|
|
|
|
fun(Host) ->
|
|
|
|
Mod = gen_mod:db_mod(Host, ?MODULE),
|
2017-05-22 15:14:28 +02:00
|
|
|
delete_motd(Mod, Host)
|
2019-06-14 11:33:26 +02:00
|
|
|
end, ejabberd_option:hosts()).
|
2017-02-16 09:00:26 +01:00
|
|
|
|
2017-01-09 15:02:17 +01:00
|
|
|
-spec send_motd({presence(), ejabberd_c2s:state()}) -> {presence(), ejabberd_c2s:state()}.
|
|
|
|
send_motd({_, #{pres_last := _}} = Acc) ->
|
|
|
|
%% This is just a presence update, nothing to do
|
|
|
|
Acc;
|
|
|
|
send_motd({#presence{type = available},
|
|
|
|
#{jid := #jid{luser = LUser, lserver = LServer} = JID}} = Acc)
|
|
|
|
when LUser /= <<>> ->
|
2016-04-13 12:04:04 +02:00
|
|
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
2017-05-22 15:14:28 +02:00
|
|
|
case get_motd(Mod, LServer) of
|
2016-04-13 12:04:04 +02:00
|
|
|
{ok, Packet} ->
|
2019-06-21 20:06:32 +02:00
|
|
|
CodecOpts = ejabberd_config:codec_options(),
|
2018-02-09 16:12:50 +01:00
|
|
|
try xmpp:decode(Packet, ?NS_CLIENT, CodecOpts) of
|
2016-07-26 08:52:29 +02:00
|
|
|
Msg ->
|
2017-05-22 15:14:28 +02:00
|
|
|
case is_motd_user(Mod, LUser, LServer) of
|
2016-07-26 08:52:29 +02:00
|
|
|
false ->
|
|
|
|
Local = jid:make(LServer),
|
2017-02-16 09:00:26 +01:00
|
|
|
ejabberd_router:route(
|
|
|
|
xmpp:set_from_to(Msg, Local, JID)),
|
2017-05-22 15:14:28 +02:00
|
|
|
set_motd_user(Mod, LUser, LServer);
|
2016-07-26 08:52:29 +02:00
|
|
|
true ->
|
|
|
|
ok
|
|
|
|
end
|
|
|
|
catch _:{xmpp_codec, Why} ->
|
2019-06-24 19:32:34 +02:00
|
|
|
?ERROR_MSG("Failed to decode motd packet ~p: ~s",
|
2016-07-26 08:52:29 +02:00
|
|
|
[Packet, xmpp:format_error(Why)])
|
2004-08-13 00:34:19 +02:00
|
|
|
end;
|
2017-05-22 15:14:28 +02:00
|
|
|
_ ->
|
2004-08-13 00:34:19 +02:00
|
|
|
ok
|
2017-01-09 15:02:17 +01:00
|
|
|
end,
|
|
|
|
Acc;
|
|
|
|
send_motd(Acc) ->
|
|
|
|
Acc.
|
2004-08-13 00:34:19 +02:00
|
|
|
|
2017-05-22 15:14:28 +02:00
|
|
|
-spec get_motd(module(), binary()) -> {ok, xmlel()} | error | {error, any()}.
|
|
|
|
get_motd(Mod, LServer) ->
|
|
|
|
case use_cache(Mod, LServer) of
|
|
|
|
true ->
|
|
|
|
ets_cache:lookup(
|
|
|
|
?MOTD_CACHE, {<<"">>, LServer},
|
|
|
|
fun() -> Mod:get_motd(LServer) end);
|
|
|
|
false ->
|
|
|
|
Mod:get_motd(LServer)
|
|
|
|
end.
|
|
|
|
|
|
|
|
-spec set_motd(module(), binary(), xmlel()) -> any().
|
|
|
|
set_motd(Mod, LServer, XML) ->
|
|
|
|
case use_cache(Mod, LServer) of
|
|
|
|
true ->
|
|
|
|
ets_cache:update(
|
|
|
|
?MOTD_CACHE, {<<"">>, LServer}, {ok, XML},
|
|
|
|
fun() -> Mod:set_motd(LServer, XML) end,
|
|
|
|
cache_nodes(Mod, LServer));
|
|
|
|
false ->
|
|
|
|
Mod:set_motd(LServer, XML)
|
|
|
|
end.
|
|
|
|
|
|
|
|
-spec is_motd_user(module(), binary(), binary()) -> boolean().
|
|
|
|
is_motd_user(Mod, LUser, LServer) ->
|
|
|
|
Res = case use_cache(Mod, LServer) of
|
|
|
|
true ->
|
|
|
|
ets_cache:lookup(
|
|
|
|
?MOTD_CACHE, {LUser, LServer},
|
|
|
|
fun() -> Mod:is_motd_user(LUser, LServer) end);
|
|
|
|
false ->
|
|
|
|
Mod:is_motd_user(LUser, LServer)
|
|
|
|
end,
|
|
|
|
case Res of
|
|
|
|
{ok, Bool} -> Bool;
|
|
|
|
_ -> false
|
|
|
|
end.
|
|
|
|
|
|
|
|
-spec set_motd_user(module(), binary(), binary()) -> any().
|
|
|
|
set_motd_user(Mod, LUser, LServer) ->
|
|
|
|
case use_cache(Mod, LServer) of
|
|
|
|
true ->
|
|
|
|
ets_cache:update(
|
|
|
|
?MOTD_CACHE, {LUser, LServer}, {ok, true},
|
|
|
|
fun() -> Mod:set_motd_user(LUser, LServer) end,
|
|
|
|
cache_nodes(Mod, LServer));
|
|
|
|
false ->
|
|
|
|
Mod:set_motd_user(LUser, LServer)
|
|
|
|
end.
|
|
|
|
|
|
|
|
-spec delete_motd(module(), binary()) -> ok | {error, any()}.
|
|
|
|
delete_motd(Mod, LServer) ->
|
|
|
|
case Mod:delete_motd(LServer) of
|
|
|
|
ok ->
|
|
|
|
case use_cache(Mod, LServer) of
|
|
|
|
true ->
|
|
|
|
ejabberd_cluster:eval_everywhere(
|
|
|
|
?MODULE, clean_cache, [LServer]);
|
|
|
|
false ->
|
|
|
|
ok
|
|
|
|
end;
|
|
|
|
Err ->
|
|
|
|
Err
|
|
|
|
end.
|
|
|
|
|
2007-12-22 14:58:19 +01:00
|
|
|
get_stored_motd(LServer) ->
|
2016-04-13 12:04:04 +02:00
|
|
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
2017-05-22 15:14:28 +02:00
|
|
|
case get_motd(Mod, LServer) of
|
2012-04-27 11:52:05 +02:00
|
|
|
{ok, Packet} ->
|
2019-06-21 20:06:32 +02:00
|
|
|
CodecOpts = ejabberd_config:codec_options(),
|
2018-02-09 16:12:50 +01:00
|
|
|
try xmpp:decode(Packet, ?NS_CLIENT, CodecOpts) of
|
2016-07-26 08:52:29 +02:00
|
|
|
#message{body = Body, subject = Subject} ->
|
|
|
|
{xmpp:get_text(Subject), xmpp:get_text(Body)}
|
|
|
|
catch _:{xmpp_codec, Why} ->
|
2019-06-24 19:32:34 +02:00
|
|
|
?ERROR_MSG("Failed to decode motd packet ~p: ~s",
|
2016-07-26 08:52:29 +02:00
|
|
|
[Packet, xmpp:format_error(Why)])
|
|
|
|
end;
|
2017-05-22 15:14:28 +02:00
|
|
|
_ ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{<<>>, <<>>}
|
2012-04-27 11:52:05 +02:00
|
|
|
end.
|
|
|
|
|
2010-01-03 01:38:00 +01:00
|
|
|
%% This function is similar to others, but doesn't perform any ACL verification
|
|
|
|
send_announcement_to_all(Host, SubjectS, BodyS) ->
|
2016-07-26 08:52:29 +02:00
|
|
|
Packet = #message{type = headline,
|
|
|
|
body = xmpp:mk_text(BodyS),
|
|
|
|
subject = xmpp:mk_text(SubjectS)},
|
2010-01-03 01:38:00 +01:00
|
|
|
Sessions = ejabberd_sm:dirty_get_sessions_list(),
|
2016-07-26 08:52:29 +02:00
|
|
|
Local = jid:make(Host),
|
2010-01-03 01:38:00 +01:00
|
|
|
lists:foreach(
|
|
|
|
fun({U, S, R}) ->
|
2015-11-24 16:44:13 +01:00
|
|
|
Dest = jid:make(U, S, R),
|
2017-02-16 09:00:26 +01:00
|
|
|
ejabberd_router:route(
|
|
|
|
xmpp:set_from_to(add_store_hint(Packet), Local, Dest))
|
2010-01-03 01:38:00 +01:00
|
|
|
end, Sessions).
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-spec get_access(global | binary()) -> atom().
|
|
|
|
|
|
|
|
get_access(Host) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
mod_announce_opt:access(Host).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2016-11-12 11:27:15 +01:00
|
|
|
-spec add_store_hint(stanza()) -> stanza().
|
2016-08-13 00:07:27 +02:00
|
|
|
add_store_hint(El) ->
|
2016-11-12 11:27:15 +01:00
|
|
|
xmpp:set_subtag(El, #hint{type = store}).
|
2016-08-13 00:07:27 +02:00
|
|
|
|
2017-02-16 09:00:26 +01:00
|
|
|
-spec route_forbidden_error(stanza()) -> ok.
|
|
|
|
route_forbidden_error(Packet) ->
|
2016-11-25 09:41:24 +01:00
|
|
|
Lang = xmpp:get_lang(Packet),
|
2019-06-22 16:08:45 +02:00
|
|
|
Err = xmpp:err_forbidden(?T("Access denied by service policy"), Lang),
|
2017-02-16 09:00:26 +01:00
|
|
|
ejabberd_router:route_error(Packet, Err).
|
2016-11-25 09:41:24 +01:00
|
|
|
|
2017-05-22 15:14:28 +02:00
|
|
|
-spec init_cache(module(), binary(), gen_mod:opts()) -> ok.
|
|
|
|
init_cache(Mod, Host, Opts) ->
|
|
|
|
case use_cache(Mod, Host) of
|
|
|
|
true ->
|
2018-01-23 08:54:52 +01:00
|
|
|
CacheOpts = cache_opts(Opts),
|
2017-05-22 15:14:28 +02:00
|
|
|
ets_cache:new(?MOTD_CACHE, CacheOpts);
|
|
|
|
false ->
|
|
|
|
ets_cache:delete(?MOTD_CACHE)
|
|
|
|
end.
|
|
|
|
|
2018-01-23 08:54:52 +01:00
|
|
|
-spec cache_opts(gen_mod:opts()) -> [proplists:property()].
|
|
|
|
cache_opts(Opts) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
MaxSize = mod_announce_opt:cache_size(Opts),
|
|
|
|
CacheMissed = mod_announce_opt:cache_missed(Opts),
|
2019-06-15 11:53:16 +02:00
|
|
|
LifeTime = mod_announce_opt:cache_life_time(Opts),
|
2017-05-22 15:14:28 +02:00
|
|
|
[{max_size, MaxSize}, {cache_missed, CacheMissed}, {life_time, LifeTime}].
|
|
|
|
|
|
|
|
-spec use_cache(module(), binary()) -> boolean().
|
|
|
|
use_cache(Mod, Host) ->
|
|
|
|
case erlang:function_exported(Mod, use_cache, 1) of
|
|
|
|
true -> Mod:use_cache(Host);
|
2019-06-14 11:33:26 +02:00
|
|
|
false -> mod_announce_opt:use_cache(Host)
|
2017-05-22 15:14:28 +02:00
|
|
|
end.
|
|
|
|
|
|
|
|
-spec cache_nodes(module(), binary()) -> [node()].
|
|
|
|
cache_nodes(Mod, Host) ->
|
|
|
|
case erlang:function_exported(Mod, cache_nodes, 1) of
|
|
|
|
true -> Mod:cache_nodes(Host);
|
|
|
|
false -> ejabberd_cluster:get_nodes()
|
|
|
|
end.
|
|
|
|
|
|
|
|
-spec clean_cache(binary()) -> non_neg_integer().
|
|
|
|
clean_cache(LServer) ->
|
|
|
|
ets_cache:filter(
|
|
|
|
?MOTD_CACHE,
|
|
|
|
fun({_, S}, _) -> S /= LServer end).
|
|
|
|
|
2007-09-04 09:55:41 +02:00
|
|
|
%%-------------------------------------------------------------------------
|
2016-04-13 12:04:04 +02:00
|
|
|
export(LServer) ->
|
|
|
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
|
|
|
Mod:export(LServer).
|
2013-07-21 12:24:36 +02:00
|
|
|
|
2016-11-22 14:48:01 +01:00
|
|
|
import_info() ->
|
|
|
|
[{<<"motd">>, 3}].
|
|
|
|
|
|
|
|
import_start(LServer, DBType) ->
|
|
|
|
Mod = gen_mod:db_mod(DBType, ?MODULE),
|
|
|
|
Mod:init(LServer, []).
|
2016-04-13 12:04:04 +02:00
|
|
|
|
2016-11-22 14:48:01 +01:00
|
|
|
import(LServer, {sql, _}, DBType, Tab, List) ->
|
2016-04-13 12:04:04 +02:00
|
|
|
Mod = gen_mod:db_mod(DBType, ?MODULE),
|
2016-11-22 14:48:01 +01:00
|
|
|
Mod:import(LServer, Tab, List).
|
2015-06-01 14:38:27 +02:00
|
|
|
|
2019-06-14 11:33:26 +02:00
|
|
|
mod_opt_type(access) ->
|
|
|
|
econf:acl();
|
|
|
|
mod_opt_type(db_type) ->
|
2019-06-15 11:53:16 +02:00
|
|
|
econf:db_type(?MODULE);
|
2019-06-14 11:33:26 +02:00
|
|
|
mod_opt_type(use_cache) ->
|
2019-06-15 11:53:16 +02:00
|
|
|
econf:bool();
|
2019-06-14 11:33:26 +02:00
|
|
|
mod_opt_type(cache_size) ->
|
2019-06-15 11:53:16 +02:00
|
|
|
econf:pos_int(infinity);
|
2019-06-14 11:33:26 +02:00
|
|
|
mod_opt_type(cache_missed) ->
|
2019-06-15 11:53:16 +02:00
|
|
|
econf:bool();
|
2019-06-14 11:33:26 +02:00
|
|
|
mod_opt_type(cache_life_time) ->
|
2019-06-15 11:53:16 +02:00
|
|
|
econf:timeout(second, infinity).
|
2018-01-23 08:54:52 +01:00
|
|
|
|
|
|
|
mod_options(Host) ->
|
|
|
|
[{access, none},
|
|
|
|
{db_type, ejabberd_config:default_db(Host, ?MODULE)},
|
2019-06-14 11:33:26 +02:00
|
|
|
{use_cache, ejabberd_option:use_cache(Host)},
|
|
|
|
{cache_size, ejabberd_option:cache_size(Host)},
|
|
|
|
{cache_missed, ejabberd_option:cache_missed(Host)},
|
|
|
|
{cache_life_time, ejabberd_option:cache_life_time(Host)}].
|