2017-03-02 13:30:34 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : mod_service_log.erl
|
|
|
|
%%% Author : Alexey Shchepin <alexey@process-one.net>
|
|
|
|
%%% Purpose : Copy user messages to logger service
|
|
|
|
%%% Created : 24 Aug 2003 by Alexey Shchepin <alexey@process-one.net>
|
|
|
|
%%%
|
|
|
|
%%%
|
2020-01-28 13:34:02 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2020 ProcessOne
|
2017-03-02 13:30:34 +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.
|
|
|
|
%%%
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(mod_service_log).
|
|
|
|
|
|
|
|
-author('alexey@process-one.net').
|
|
|
|
|
|
|
|
-behaviour(gen_mod).
|
|
|
|
|
2018-01-23 08:54:52 +01:00
|
|
|
-export([start/2, stop/1, log_user_send/1, mod_options/1,
|
2020-01-08 10:24:51 +01:00
|
|
|
log_user_receive/1, mod_opt_type/1, depends/2, mod_doc/0]).
|
2017-03-02 13:30:34 +01:00
|
|
|
|
|
|
|
-include("logger.hrl").
|
2020-01-08 10:24:51 +01:00
|
|
|
-include("translate.hrl").
|
2020-09-03 13:45:57 +02:00
|
|
|
-include_lib("xmpp/include/xmpp.hrl").
|
2017-03-02 13:30:34 +01:00
|
|
|
|
|
|
|
start(Host, _Opts) ->
|
|
|
|
ejabberd_hooks:add(user_send_packet, Host, ?MODULE,
|
|
|
|
log_user_send, 50),
|
|
|
|
ejabberd_hooks:add(user_receive_packet, Host, ?MODULE,
|
|
|
|
log_user_receive, 50),
|
|
|
|
ok.
|
|
|
|
|
|
|
|
stop(Host) ->
|
|
|
|
ejabberd_hooks:delete(user_send_packet, Host, ?MODULE,
|
|
|
|
log_user_send, 50),
|
|
|
|
ejabberd_hooks:delete(user_receive_packet, Host,
|
|
|
|
?MODULE, log_user_receive, 50),
|
|
|
|
ok.
|
|
|
|
|
|
|
|
depends(_Host, _Opts) ->
|
|
|
|
[].
|
|
|
|
|
|
|
|
-spec log_user_send({stanza(), ejabberd_c2s:state()}) -> {stanza(), ejabberd_c2s:state()}.
|
|
|
|
log_user_send({Packet, C2SState}) ->
|
|
|
|
From = xmpp:get_from(Packet),
|
2017-03-02 13:34:26 +01:00
|
|
|
log_packet(Packet, From#jid.lserver),
|
2017-03-02 13:30:34 +01:00
|
|
|
{Packet, C2SState}.
|
|
|
|
|
|
|
|
-spec log_user_receive({stanza(), ejabberd_c2s:state()}) -> {stanza(), ejabberd_c2s:state()}.
|
|
|
|
log_user_receive({Packet, C2SState}) ->
|
|
|
|
To = xmpp:get_to(Packet),
|
2017-03-02 13:34:26 +01:00
|
|
|
log_packet(Packet, To#jid.lserver),
|
2017-03-02 13:30:34 +01:00
|
|
|
{Packet, C2SState}.
|
|
|
|
|
2017-03-02 13:34:26 +01:00
|
|
|
-spec log_packet(stanza(), binary()) -> ok.
|
|
|
|
log_packet(Packet, Host) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
Loggers = mod_service_log_opt:loggers(Host),
|
2017-03-02 13:34:26 +01:00
|
|
|
ForwardedMsg = #message{from = jid:make(Host),
|
2018-07-05 10:51:49 +02:00
|
|
|
id = p1_rand:get_string(),
|
2017-03-02 13:34:26 +01:00
|
|
|
sub_els = [#forwarded{
|
2018-01-25 18:02:47 +01:00
|
|
|
sub_els = [Packet]}]},
|
2017-03-02 13:34:26 +01:00
|
|
|
lists:foreach(
|
|
|
|
fun(Logger) ->
|
|
|
|
ejabberd_router:route(xmpp:set_to(ForwardedMsg, jid:make(Logger)))
|
|
|
|
end, Loggers).
|
2017-03-02 13:30:34 +01:00
|
|
|
|
|
|
|
mod_opt_type(loggers) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
econf:list(econf:domain()).
|
2018-01-23 08:54:52 +01:00
|
|
|
|
|
|
|
mod_options(_) ->
|
|
|
|
[{loggers, []}].
|
2020-01-08 10:24:51 +01:00
|
|
|
|
|
|
|
mod_doc() ->
|
|
|
|
#{desc =>
|
|
|
|
?T("This module forwards copies of all stanzas "
|
|
|
|
"to remote XMPP servers or components. "
|
|
|
|
"Every stanza is encapsulated into <forwarded/> "
|
|
|
|
"element as described in "
|
|
|
|
"https://xmpp.org/extensions/xep-0297.html"
|
|
|
|
"[XEP-0297: Stanza Forwarding]."),
|
|
|
|
opts =>
|
|
|
|
[{loggers,
|
|
|
|
#{value => "[Domain, ...]",
|
|
|
|
desc =>
|
|
|
|
?T("A list of servers or connected components "
|
|
|
|
"to which stanzas will be forwarded.")}}],
|
|
|
|
example =>
|
|
|
|
["modules:",
|
|
|
|
" ...",
|
|
|
|
" mod_service_log:",
|
|
|
|
" loggers:",
|
|
|
|
" - xmpp-server.tld",
|
|
|
|
" - component.domain.tld",
|
|
|
|
" ..."]}.
|