2004-08-24 22:11:01 +02:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : mod_service_log.erl
|
2007-12-24 13:58:05 +01:00
|
|
|
%%% Author : Alexey Shchepin <alexey@process-one.net>
|
2006-01-27 06:00:27 +01:00
|
|
|
%%% Purpose : Copy user messages to logger service
|
2007-12-24 13:58:05 +01:00
|
|
|
%%% Created : 24 Aug 2003 by Alexey Shchepin <alexey@process-one.net>
|
|
|
|
%%%
|
|
|
|
%%%
|
2016-01-13 12:29:14 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2016 ProcessOne
|
2007-12-24 13:58:05 +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 13:58:05 +01:00
|
|
|
%%%
|
2004-08-24 22:11:01 +02:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(mod_service_log).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2007-12-24 13:58:05 +01:00
|
|
|
-author('alexey@process-one.net').
|
2004-08-24 22:11:01 +02:00
|
|
|
|
|
|
|
-behaviour(gen_mod).
|
|
|
|
|
2015-06-22 15:56:08 +02:00
|
|
|
-export([start/2, stop/1, log_user_send/4,
|
2016-07-06 13:58:48 +02:00
|
|
|
log_user_receive/5, mod_opt_type/1, depends/2]).
|
2004-08-24 22:11:01 +02:00
|
|
|
|
|
|
|
-include("ejabberd.hrl").
|
2013-04-08 11:12:54 +02:00
|
|
|
-include("logger.hrl").
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2004-08-24 22:11:01 +02:00
|
|
|
-include("jlib.hrl").
|
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
start(Host, _Opts) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
ejabberd_hooks:add(user_send_packet, Host, ?MODULE,
|
|
|
|
log_user_send, 50),
|
|
|
|
ejabberd_hooks:add(user_receive_packet, Host, ?MODULE,
|
|
|
|
log_user_receive, 50),
|
2004-08-24 22:11:01 +02:00
|
|
|
ok.
|
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
stop(Host) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
ejabberd_hooks:delete(user_send_packet, Host, ?MODULE,
|
|
|
|
log_user_send, 50),
|
2005-06-20 05:18:13 +02:00
|
|
|
ejabberd_hooks:delete(user_receive_packet, Host,
|
2004-08-24 22:11:01 +02:00
|
|
|
?MODULE, log_user_receive, 50),
|
|
|
|
ok.
|
|
|
|
|
2016-07-06 13:58:48 +02:00
|
|
|
depends(_Host, _Opts) ->
|
|
|
|
[].
|
|
|
|
|
2015-06-22 15:56:08 +02:00
|
|
|
log_user_send(Packet, _C2SState, From, To) ->
|
|
|
|
log_packet(From, To, Packet, From#jid.lserver),
|
|
|
|
Packet.
|
2004-08-24 22:11:01 +02:00
|
|
|
|
2015-06-22 15:56:08 +02:00
|
|
|
log_user_receive(Packet, _C2SState, _JID, From, To) ->
|
|
|
|
log_packet(From, To, Packet, To#jid.lserver),
|
|
|
|
Packet.
|
2004-08-24 22:11:01 +02:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
log_packet(From, To,
|
|
|
|
#xmlel{name = Name, attrs = Attrs, children = Els},
|
|
|
|
Host) ->
|
|
|
|
Loggers = gen_mod:get_module_opt(Host, ?MODULE, loggers,
|
|
|
|
fun(L) ->
|
|
|
|
lists:map(
|
|
|
|
fun(S) ->
|
|
|
|
B = iolist_to_binary(S),
|
2015-11-24 16:44:13 +01:00
|
|
|
N = jid:nameprep(B),
|
2013-03-14 10:33:02 +01:00
|
|
|
if N /= error ->
|
|
|
|
N
|
|
|
|
end
|
|
|
|
end, L)
|
|
|
|
end, []),
|
|
|
|
ServerJID = #jid{user = <<"">>, server = Host,
|
|
|
|
resource = <<"">>, luser = <<"">>, lserver = Host,
|
|
|
|
lresource = <<"">>},
|
|
|
|
NewAttrs =
|
2015-11-24 16:44:13 +01:00
|
|
|
jlib:replace_from_to_attrs(jid:to_string(From),
|
|
|
|
jid:to_string(To), Attrs),
|
2013-03-14 10:33:02 +01:00
|
|
|
FixedPacket = #xmlel{name = Name, attrs = NewAttrs,
|
|
|
|
children = Els},
|
|
|
|
lists:foreach(fun (Logger) ->
|
|
|
|
ejabberd_router:route(ServerJID,
|
|
|
|
#jid{user = <<"">>,
|
|
|
|
server = Logger,
|
|
|
|
resource = <<"">>,
|
|
|
|
luser = <<"">>,
|
|
|
|
lserver = Logger,
|
|
|
|
lresource = <<"">>},
|
|
|
|
#xmlel{name = <<"route">>,
|
|
|
|
attrs = [],
|
|
|
|
children =
|
|
|
|
[FixedPacket]})
|
|
|
|
end,
|
|
|
|
Loggers).
|
2015-06-01 14:38:27 +02:00
|
|
|
|
|
|
|
mod_opt_type(loggers) ->
|
|
|
|
fun (L) ->
|
|
|
|
lists:map(fun (S) ->
|
|
|
|
B = iolist_to_binary(S),
|
2015-11-24 16:44:13 +01:00
|
|
|
N = jid:nameprep(B),
|
2015-06-01 14:38:27 +02:00
|
|
|
if N /= error -> N end
|
|
|
|
end,
|
|
|
|
L)
|
|
|
|
end;
|
|
|
|
mod_opt_type(_) -> [loggers].
|