2006-03-14 05:26:15 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : mod_muc_log.erl
|
2007-12-24 14:57:53 +01:00
|
|
|
%%% Author : Badlop@process-one.net
|
2006-03-14 05:26:15 +01:00
|
|
|
%%% Purpose : MUC room logging
|
2007-12-24 14:57:53 +01:00
|
|
|
%%% Created : 12 Mar 2006 by Alexey Shchepin <alexey@process-one.net>
|
|
|
|
%%%
|
|
|
|
%%%
|
2024-01-22 16:40:01 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2024 ProcessOne
|
2007-12-24 14:57:53 +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 14:57:53 +01:00
|
|
|
%%%
|
2006-03-14 05:26:15 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(mod_muc_log).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2015-12-09 22:28:44 +01:00
|
|
|
-protocol({xep, 334, '0.2'}).
|
|
|
|
|
2007-12-24 14:57:53 +01:00
|
|
|
-author('badlop@process-one.net').
|
2006-03-14 05:26:15 +01:00
|
|
|
|
|
|
|
-behaviour(gen_server).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2006-03-14 05:26:15 +01:00
|
|
|
-behaviour(gen_mod).
|
|
|
|
|
|
|
|
%% API
|
2019-09-26 15:53:36 +02:00
|
|
|
-export([start/2, stop/1, reload/3, get_url/1,
|
2013-03-14 10:33:02 +01:00
|
|
|
check_access_log/2, add_to_log/5]).
|
2006-03-14 05:26:15 +01:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-export([init/1, handle_call/3, handle_cast/2,
|
2015-06-01 14:38:27 +02:00
|
|
|
handle_info/2, terminate/2, code_change/3,
|
2020-01-08 10:24:51 +01:00
|
|
|
mod_opt_type/1, mod_options/1, depends/2, mod_doc/0]).
|
2006-03-14 05:26:15 +01:00
|
|
|
|
2013-04-08 11:12:54 +02:00
|
|
|
-include("logger.hrl").
|
2020-09-03 13:45:57 +02:00
|
|
|
-include_lib("xmpp/include/xmpp.hrl").
|
2009-07-21 20:33:56 +02:00
|
|
|
-include("mod_muc_room.hrl").
|
2019-06-22 16:08:45 +02:00
|
|
|
-include("translate.hrl").
|
2009-07-21 20:33:56 +02:00
|
|
|
|
2006-03-14 05:26:15 +01:00
|
|
|
-record(room, {jid, title, subject, subject_author, config}).
|
|
|
|
|
2013-05-30 14:28:39 +02:00
|
|
|
-define(PLAINTEXT_CO, <<"ZZCZZ">>).
|
2013-03-14 10:33:02 +01:00
|
|
|
-define(PLAINTEXT_IN, <<"ZZIZZ">>).
|
|
|
|
-define(PLAINTEXT_OUT, <<"ZZOZZ">>).
|
2006-03-14 05:26:15 +01:00
|
|
|
|
2009-07-21 20:33:56 +02:00
|
|
|
-record(logstate, {host,
|
2006-03-14 05:26:15 +01:00
|
|
|
out_dir,
|
|
|
|
dir_type,
|
2008-08-18 21:08:30 +02:00
|
|
|
dir_name,
|
|
|
|
file_format,
|
2013-02-05 16:19:23 +01:00
|
|
|
file_permissions,
|
2006-03-14 05:26:15 +01:00
|
|
|
css_file,
|
|
|
|
access,
|
|
|
|
lang,
|
|
|
|
timezone,
|
2007-02-19 11:49:23 +01:00
|
|
|
spam_prevention,
|
2006-03-14 05:26:15 +01:00
|
|
|
top_link}).
|
|
|
|
|
|
|
|
%%====================================================================
|
|
|
|
%% API
|
|
|
|
%%====================================================================
|
|
|
|
start(Host, Opts) ->
|
2017-02-14 10:39:26 +01:00
|
|
|
gen_mod:start_child(?MODULE, Host, Opts).
|
2006-03-14 05:26:15 +01:00
|
|
|
|
|
|
|
stop(Host) ->
|
2017-02-14 10:39:26 +01:00
|
|
|
gen_mod:stop_child(?MODULE, Host).
|
2006-03-14 05:26:15 +01:00
|
|
|
|
2017-02-22 17:46:47 +01:00
|
|
|
reload(Host, NewOpts, _OldOpts) ->
|
|
|
|
Proc = get_proc_name(Host),
|
|
|
|
gen_server:cast(Proc, {reload, NewOpts}).
|
|
|
|
|
2006-03-14 05:26:15 +01:00
|
|
|
add_to_log(Host, Type, Data, Room, Opts) ->
|
|
|
|
gen_server:cast(get_proc_name(Host),
|
|
|
|
{add_to_log, Type, Data, Room, Opts}).
|
|
|
|
|
|
|
|
check_access_log(Host, From) ->
|
|
|
|
case catch gen_server:call(get_proc_name(Host),
|
2013-03-14 10:33:02 +01:00
|
|
|
{check_access_log, Host, From})
|
|
|
|
of
|
|
|
|
{'EXIT', _Error} -> deny;
|
|
|
|
Res -> Res
|
2006-03-14 05:26:15 +01:00
|
|
|
end.
|
|
|
|
|
2019-09-26 15:53:36 +02:00
|
|
|
-spec get_url(#state{}) -> {ok, binary()} | error.
|
|
|
|
get_url(#state{room = Room, host = Host, server_host = ServerHost}) ->
|
2020-05-15 13:43:56 +02:00
|
|
|
try mod_muc_log_opt:url(ServerHost) of
|
2019-09-26 15:53:36 +02:00
|
|
|
undefined -> error;
|
|
|
|
URL ->
|
|
|
|
case mod_muc_log_opt:dirname(ServerHost) of
|
|
|
|
room_jid ->
|
2023-04-24 13:36:37 +02:00
|
|
|
{ok, <<URL/binary, $/, Room/binary, $@, Host/binary, $/>>};
|
2019-09-26 15:53:36 +02:00
|
|
|
room_name ->
|
2023-04-25 09:40:22 +02:00
|
|
|
{ok, <<URL/binary, $/, Room/binary, $/>>}
|
2019-09-26 15:53:36 +02:00
|
|
|
end
|
2020-05-15 13:43:56 +02:00
|
|
|
catch
|
|
|
|
error:{module_not_loaded, _, _} ->
|
|
|
|
error
|
2019-09-26 15:53:36 +02:00
|
|
|
end.
|
|
|
|
|
2016-07-06 13:58:48 +02:00
|
|
|
depends(_Host, _Opts) ->
|
|
|
|
[{mod_muc, hard}].
|
|
|
|
|
2006-03-14 05:26:15 +01:00
|
|
|
%%====================================================================
|
|
|
|
%% gen_server callbacks
|
|
|
|
%%====================================================================
|
2019-08-04 20:46:18 +02:00
|
|
|
init([Host|_]) ->
|
2017-02-14 08:25:08 +01:00
|
|
|
process_flag(trap_exit, true),
|
2019-08-04 20:46:18 +02:00
|
|
|
Opts = gen_mod:get_module_opts(Host, ?MODULE),
|
2017-02-22 17:46:47 +01:00
|
|
|
{ok, init_state(Host, Opts)}.
|
|
|
|
|
|
|
|
handle_call({check_access_log, ServerHost, FromJID}, _From, State) ->
|
|
|
|
Reply = acl:match_rule(ServerHost, State#logstate.access, FromJID),
|
|
|
|
{reply, Reply, State};
|
|
|
|
handle_call(stop, _From, State) ->
|
|
|
|
{stop, normal, ok, State}.
|
|
|
|
|
|
|
|
handle_cast({reload, Opts}, #logstate{host = Host}) ->
|
|
|
|
{noreply, init_state(Host, Opts)};
|
|
|
|
handle_cast({add_to_log, Type, Data, Room, Opts}, State) ->
|
|
|
|
case catch add_to_log2(Type, Data, Room, Opts, State) of
|
|
|
|
{'EXIT', Reason} -> ?ERROR_MSG("~p", [Reason]);
|
|
|
|
_ -> ok
|
|
|
|
end,
|
|
|
|
{noreply, State};
|
|
|
|
handle_cast(Msg, State) ->
|
2019-06-24 19:32:34 +02:00
|
|
|
?WARNING_MSG("Unexpected cast: ~p", [Msg]),
|
2017-02-22 17:46:47 +01:00
|
|
|
{noreply, State}.
|
|
|
|
|
|
|
|
handle_info(_Info, State) -> {noreply, State}.
|
|
|
|
|
|
|
|
terminate(_Reason, _State) -> ok.
|
|
|
|
|
|
|
|
code_change(_OldVsn, State, _Extra) -> {ok, State}.
|
|
|
|
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
%%% Internal functions
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
init_state(Host, Opts) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
OutDir = mod_muc_log_opt:outdir(Opts),
|
|
|
|
DirType = mod_muc_log_opt:dirtype(Opts),
|
|
|
|
DirName = mod_muc_log_opt:dirname(Opts),
|
|
|
|
FileFormat = mod_muc_log_opt:file_format(Opts),
|
|
|
|
FilePermissions = mod_muc_log_opt:file_permissions(Opts),
|
|
|
|
CSSFile = mod_muc_log_opt:cssfile(Opts),
|
|
|
|
AccessLog = mod_muc_log_opt:access_log(Opts),
|
|
|
|
Timezone = mod_muc_log_opt:timezone(Opts),
|
|
|
|
Top_link = mod_muc_log_opt:top_link(Opts),
|
|
|
|
NoFollow = mod_muc_log_opt:spam_prevention(Opts),
|
|
|
|
Lang = ejabberd_option:language(Host),
|
2017-02-22 17:46:47 +01:00
|
|
|
#logstate{host = Host, out_dir = OutDir,
|
|
|
|
dir_type = DirType, dir_name = DirName,
|
|
|
|
file_format = FileFormat, css_file = CSSFile,
|
|
|
|
file_permissions = FilePermissions,
|
|
|
|
access = AccessLog, lang = Lang, timezone = Timezone,
|
|
|
|
spam_prevention = NoFollow, top_link = Top_link}.
|
2006-03-14 05:26:15 +01:00
|
|
|
|
|
|
|
add_to_log2(text, {Nick, Packet}, Room, Opts, State) ->
|
2015-07-28 21:08:33 +02:00
|
|
|
case has_no_permanent_store_hint(Packet) of
|
2015-10-07 00:06:58 +02:00
|
|
|
false ->
|
2016-07-25 12:50:30 +02:00
|
|
|
case {Packet#message.subject, Packet#message.body} of
|
|
|
|
{[], []} -> ok;
|
|
|
|
{[], Body} ->
|
|
|
|
Message = {body, xmpp:get_text(Body)},
|
2015-10-07 00:06:58 +02:00
|
|
|
add_message_to_log(Nick, Message, Room, Opts, State);
|
2016-07-25 12:50:30 +02:00
|
|
|
{Subj, _} ->
|
|
|
|
Message = {subject, xmpp:get_text(Subj)},
|
2015-10-07 00:06:58 +02:00
|
|
|
add_message_to_log(Nick, Message, Room, Opts, State)
|
|
|
|
end;
|
|
|
|
true -> ok
|
2006-03-14 05:26:15 +01:00
|
|
|
end;
|
2013-03-14 10:33:02 +01:00
|
|
|
add_to_log2(roomconfig_change, _Occupants, Room, Opts,
|
|
|
|
State) ->
|
|
|
|
add_message_to_log(<<"">>, roomconfig_change, Room,
|
|
|
|
Opts, State);
|
|
|
|
add_to_log2(roomconfig_change_enabledlogging, Occupants,
|
|
|
|
Room, Opts, State) ->
|
|
|
|
add_message_to_log(<<"">>,
|
|
|
|
{roomconfig_change, Occupants}, Room, Opts, State);
|
|
|
|
add_to_log2(room_existence, NewStatus, Room, Opts,
|
|
|
|
State) ->
|
|
|
|
add_message_to_log(<<"">>, {room_existence, NewStatus},
|
|
|
|
Room, Opts, State);
|
|
|
|
add_to_log2(nickchange, {OldNick, NewNick}, Room, Opts,
|
|
|
|
State) ->
|
|
|
|
add_message_to_log(NewNick, {nickchange, OldNick}, Room,
|
|
|
|
Opts, State);
|
2006-03-14 05:26:15 +01:00
|
|
|
add_to_log2(join, Nick, Room, Opts, State) ->
|
|
|
|
add_message_to_log(Nick, join, Room, Opts, State);
|
|
|
|
add_to_log2(leave, {Nick, Reason}, Room, Opts, State) ->
|
|
|
|
case Reason of
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"">> ->
|
|
|
|
add_message_to_log(Nick, leave, Room, Opts, State);
|
|
|
|
_ ->
|
|
|
|
add_message_to_log(Nick, {leave, Reason}, Room, Opts,
|
|
|
|
State)
|
2006-03-14 05:26:15 +01:00
|
|
|
end;
|
2013-03-14 10:33:02 +01:00
|
|
|
add_to_log2(kickban, {Nick, Reason, Code}, Room, Opts,
|
|
|
|
State) ->
|
|
|
|
add_message_to_log(Nick, {kickban, Code, Reason}, Room,
|
|
|
|
Opts, State).
|
2006-03-14 05:26:15 +01:00
|
|
|
|
|
|
|
%%----------------------------------------------------------------------
|
|
|
|
%% Core
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
build_filename_string(TimeStamp, OutDir, RoomJID,
|
|
|
|
DirType, DirName, FileFormat) ->
|
2006-03-14 05:26:15 +01:00
|
|
|
{{Year, Month, Day}, _Time} = TimeStamp,
|
2013-03-14 10:33:02 +01:00
|
|
|
{Dir, Filename, Rel} = case DirType of
|
|
|
|
subdirs ->
|
|
|
|
SYear =
|
2016-11-24 13:06:06 +01:00
|
|
|
(str:format("~4..0w",
|
2013-03-14 10:33:02 +01:00
|
|
|
[Year])),
|
|
|
|
SMonth =
|
2016-11-24 13:06:06 +01:00
|
|
|
(str:format("~2..0w",
|
2013-03-14 10:33:02 +01:00
|
|
|
[Month])),
|
2016-11-24 13:06:06 +01:00
|
|
|
SDay = (str:format("~2..0w",
|
2013-03-14 10:33:02 +01:00
|
|
|
[Day])),
|
|
|
|
{fjoin([SYear, SMonth]), SDay,
|
|
|
|
<<"../..">>};
|
|
|
|
plain ->
|
|
|
|
Date =
|
2016-11-24 13:06:06 +01:00
|
|
|
(str:format("~4..0w-~2..0w-~2..0w",
|
2013-03-14 10:33:02 +01:00
|
|
|
[Year,
|
|
|
|
Month,
|
|
|
|
Day])),
|
|
|
|
{<<"">>, Date, <<".">>}
|
|
|
|
end,
|
2008-08-18 21:08:30 +02:00
|
|
|
RoomString = case DirName of
|
2013-03-14 10:33:02 +01:00
|
|
|
room_jid -> RoomJID;
|
|
|
|
room_name -> get_room_name(RoomJID)
|
2008-08-18 21:08:30 +02:00
|
|
|
end,
|
|
|
|
Extension = case FileFormat of
|
2013-03-14 10:33:02 +01:00
|
|
|
html -> <<".html">>;
|
|
|
|
plaintext -> <<".txt">>
|
2008-08-18 21:08:30 +02:00
|
|
|
end,
|
2013-03-14 10:33:02 +01:00
|
|
|
Fd = fjoin([OutDir, RoomString, Dir]),
|
|
|
|
Fn = fjoin([Fd, <<Filename/binary, Extension/binary>>]),
|
|
|
|
Fnrel = fjoin([Rel, Dir, <<Filename/binary, Extension/binary>>]),
|
2006-03-14 05:26:15 +01:00
|
|
|
{Fd, Fn, Fnrel}.
|
|
|
|
|
2008-08-18 21:08:30 +02:00
|
|
|
get_room_name(RoomJID) ->
|
2017-02-26 08:07:12 +01:00
|
|
|
JID = jid:decode(RoomJID), JID#jid.user.
|
2008-08-18 21:08:30 +02:00
|
|
|
|
|
|
|
%% calculate day before
|
2006-03-14 05:26:15 +01:00
|
|
|
get_timestamp_daydiff(TimeStamp, Daydiff) ->
|
|
|
|
{Date1, HMS} = TimeStamp,
|
2013-03-14 10:33:02 +01:00
|
|
|
Date2 =
|
|
|
|
calendar:gregorian_days_to_date(calendar:date_to_gregorian_days(Date1)
|
|
|
|
+ Daydiff),
|
2006-03-14 05:26:15 +01:00
|
|
|
{Date2, HMS}.
|
|
|
|
|
2008-08-18 21:08:30 +02:00
|
|
|
%% Try to close the previous day log, if it exists
|
|
|
|
close_previous_log(Fn, Images_dir, FileFormat) ->
|
2006-03-14 05:26:15 +01:00
|
|
|
case file:read_file_info(Fn) of
|
2013-03-14 10:33:02 +01:00
|
|
|
{ok, _} ->
|
|
|
|
{ok, F} = file:open(Fn, [append]),
|
|
|
|
write_last_lines(F, Images_dir, FileFormat),
|
|
|
|
file:close(F);
|
|
|
|
_ -> ok
|
2006-03-14 05:26:15 +01:00
|
|
|
end.
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
write_last_lines(_, _, plaintext) -> ok;
|
2008-08-18 21:08:30 +02:00
|
|
|
write_last_lines(F, Images_dir, _FileFormat) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
fw(F, <<"<div class=\"legend\">">>),
|
|
|
|
fw(F,
|
|
|
|
<<" <a href=\"http://www.ejabberd.im\"><img "
|
2019-09-23 14:17:20 +02:00
|
|
|
"style=\"border:0\" src=\"~ts/powered-by-ejabbe"
|
2015-11-30 11:35:53 +01:00
|
|
|
"rd.png\" alt=\"Powered by ejabberd - robust, scalable and extensible XMPP server\"/></a>">>,
|
2013-03-14 10:33:02 +01:00
|
|
|
[Images_dir]),
|
|
|
|
fw(F,
|
|
|
|
<<" <a href=\"http://www.erlang.org/\"><img "
|
2019-09-23 14:17:20 +02:00
|
|
|
"style=\"border:0\" src=\"~ts/powered-by-erlang"
|
2013-03-14 10:33:02 +01:00
|
|
|
".png\" alt=\"Powered by Erlang\"/></a>">>,
|
|
|
|
[Images_dir]),
|
|
|
|
fw(F, <<"<span class=\"w3c\">">>),
|
|
|
|
fw(F,
|
|
|
|
<<" <a href=\"http://validator.w3.org/check?uri"
|
|
|
|
"=referer\"><img style=\"border:0;width:88px;h"
|
2019-09-23 14:17:20 +02:00
|
|
|
"eight:31px\" src=\"~ts/valid-xhtml10.png\" "
|
2013-03-14 10:33:02 +01:00
|
|
|
"alt=\"Valid XHTML 1.0 Transitional\" "
|
|
|
|
"/></a>">>,
|
|
|
|
[Images_dir]),
|
|
|
|
fw(F,
|
|
|
|
<<" <a href=\"http://jigsaw.w3.org/css-validato"
|
|
|
|
"r/\"><img style=\"border:0;width:88px;height:"
|
2019-09-23 14:17:20 +02:00
|
|
|
"31px\" src=\"~ts/vcss.png\" alt=\"Valid "
|
2013-03-14 10:33:02 +01:00
|
|
|
"CSS!\"/></a>">>,
|
|
|
|
[Images_dir]),
|
|
|
|
fw(F, <<"</span></div></body></html>">>).
|
|
|
|
|
2013-02-05 16:19:23 +01:00
|
|
|
set_filemode(Fn, {FileMode, FileGroup}) ->
|
2015-10-07 00:06:58 +02:00
|
|
|
ok = file:change_mode(Fn, list_to_integer(integer_to_list(FileMode), 8)),
|
2013-02-21 13:17:25 +01:00
|
|
|
ok = file:change_group(Fn, FileGroup).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2015-04-14 15:46:43 +02:00
|
|
|
htmlize_nick(Nick1, html) ->
|
|
|
|
htmlize(<<"<", Nick1/binary, ">">>, html);
|
|
|
|
htmlize_nick(Nick1, plaintext) ->
|
|
|
|
htmlize(<<?PLAINTEXT_IN/binary, Nick1/binary, ?PLAINTEXT_OUT/binary>>, plaintext).
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
add_message_to_log(Nick1, Message, RoomJID, Opts,
|
|
|
|
State) ->
|
|
|
|
#logstate{out_dir = OutDir, dir_type = DirType,
|
|
|
|
dir_name = DirName, file_format = FileFormat,
|
|
|
|
file_permissions = FilePermissions,
|
|
|
|
css_file = CSSFile, lang = Lang, timezone = Timezone,
|
|
|
|
spam_prevention = NoFollow, top_link = TopLink} =
|
|
|
|
State,
|
2006-03-14 05:26:15 +01:00
|
|
|
Room = get_room_info(RoomJID, Opts),
|
2008-08-18 21:08:30 +02:00
|
|
|
Nick = htmlize(Nick1, FileFormat),
|
2015-04-14 15:46:43 +02:00
|
|
|
Nick2 = htmlize_nick(Nick1, FileFormat),
|
2019-02-27 09:56:20 +01:00
|
|
|
Now = erlang:timestamp(),
|
2006-03-14 05:26:15 +01:00
|
|
|
TimeStamp = case Timezone of
|
2013-03-14 10:33:02 +01:00
|
|
|
local -> calendar:now_to_local_time(Now);
|
|
|
|
universal -> calendar:now_to_universal_time(Now)
|
2006-03-14 05:26:15 +01:00
|
|
|
end,
|
2013-03-14 10:33:02 +01:00
|
|
|
{Fd, Fn, _Dir} = build_filename_string(TimeStamp,
|
|
|
|
OutDir, Room#room.jid, DirType,
|
|
|
|
DirName, FileFormat),
|
2006-03-14 05:26:15 +01:00
|
|
|
{Date, Time} = TimeStamp,
|
|
|
|
case file:read_file_info(Fn) of
|
2013-03-14 10:33:02 +01:00
|
|
|
{ok, _} -> {ok, F} = file:open(Fn, [append]);
|
|
|
|
{error, enoent} ->
|
|
|
|
make_dir_rec(Fd),
|
|
|
|
{ok, F} = file:open(Fn, [append]),
|
|
|
|
catch set_filemode(Fn, FilePermissions),
|
|
|
|
Datestring = get_dateweek(Date, Lang),
|
|
|
|
TimeStampYesterday = get_timestamp_daydiff(TimeStamp,
|
|
|
|
-1),
|
|
|
|
{_FdYesterday, FnYesterday, DatePrev} =
|
|
|
|
build_filename_string(TimeStampYesterday, OutDir,
|
|
|
|
Room#room.jid, DirType, DirName,
|
|
|
|
FileFormat),
|
|
|
|
TimeStampTomorrow = get_timestamp_daydiff(TimeStamp, 1),
|
|
|
|
{_FdTomorrow, _FnTomorrow, DateNext} =
|
|
|
|
build_filename_string(TimeStampTomorrow, OutDir,
|
|
|
|
Room#room.jid, DirType, DirName,
|
|
|
|
FileFormat),
|
|
|
|
HourOffset = calc_hour_offset(TimeStamp),
|
|
|
|
put_header(F, Room, Datestring, CSSFile, Lang,
|
|
|
|
HourOffset, DatePrev, DateNext, TopLink, FileFormat),
|
|
|
|
Images_dir = fjoin([OutDir, <<"images">>]),
|
|
|
|
file:make_dir(Images_dir),
|
|
|
|
create_image_files(Images_dir),
|
|
|
|
Images_url = case DirType of
|
|
|
|
subdirs -> <<"../../../images">>;
|
|
|
|
plain -> <<"../images">>
|
|
|
|
end,
|
|
|
|
close_previous_log(FnYesterday, Images_url, FileFormat)
|
2006-03-14 05:26:15 +01:00
|
|
|
end,
|
|
|
|
Text = case Message of
|
2013-03-14 10:33:02 +01:00
|
|
|
roomconfig_change ->
|
|
|
|
RoomConfig = roomconfig_to_string(Room#room.config,
|
|
|
|
Lang, FileFormat),
|
|
|
|
put_room_config(F, RoomConfig, Lang, FileFormat),
|
2019-09-23 14:17:20 +02:00
|
|
|
io_lib:format("<font class=\"mrcm\">~ts</font><br/>",
|
2019-06-22 16:08:45 +02:00
|
|
|
[tr(Lang, ?T("Chatroom configuration modified"))]);
|
2013-03-14 10:33:02 +01:00
|
|
|
{roomconfig_change, Occupants} ->
|
|
|
|
RoomConfig = roomconfig_to_string(Room#room.config,
|
|
|
|
Lang, FileFormat),
|
|
|
|
put_room_config(F, RoomConfig, Lang, FileFormat),
|
|
|
|
RoomOccupants = roomoccupants_to_string(Occupants,
|
|
|
|
FileFormat),
|
|
|
|
put_room_occupants(F, RoomOccupants, Lang, FileFormat),
|
2019-09-23 14:17:20 +02:00
|
|
|
io_lib:format("<font class=\"mrcm\">~ts</font><br/>",
|
2019-06-22 16:08:45 +02:00
|
|
|
[tr(Lang, ?T("Chatroom configuration modified"))]);
|
2013-03-14 10:33:02 +01:00
|
|
|
join ->
|
2019-09-23 14:17:20 +02:00
|
|
|
io_lib:format("<font class=\"mj\">~ts ~ts</font><br/>",
|
2019-06-22 16:08:45 +02:00
|
|
|
[Nick, tr(Lang, ?T("joins the room"))]);
|
2013-03-14 10:33:02 +01:00
|
|
|
leave ->
|
2019-09-23 14:17:20 +02:00
|
|
|
io_lib:format("<font class=\"ml\">~ts ~ts</font><br/>",
|
2019-06-22 16:08:45 +02:00
|
|
|
[Nick, tr(Lang, ?T("leaves the room"))]);
|
2013-03-14 10:33:02 +01:00
|
|
|
{leave, Reason} ->
|
2019-09-23 14:17:20 +02:00
|
|
|
io_lib:format("<font class=\"ml\">~ts ~ts: ~ts</font><br/>",
|
2019-06-22 16:08:45 +02:00
|
|
|
[Nick, tr(Lang, ?T("leaves the room")),
|
2013-03-14 10:33:02 +01:00
|
|
|
htmlize(Reason, NoFollow, FileFormat)]);
|
2018-04-02 13:51:19 +02:00
|
|
|
{kickban, 301, <<"">>} ->
|
2019-09-23 14:17:20 +02:00
|
|
|
io_lib:format("<font class=\"mb\">~ts ~ts</font><br/>",
|
2019-06-22 16:08:45 +02:00
|
|
|
[Nick, tr(Lang, ?T("has been banned"))]);
|
2018-04-02 13:51:19 +02:00
|
|
|
{kickban, 301, Reason} ->
|
2019-09-23 14:17:20 +02:00
|
|
|
io_lib:format("<font class=\"mb\">~ts ~ts: ~ts</font><br/>",
|
2019-06-22 16:08:45 +02:00
|
|
|
[Nick, tr(Lang, ?T("has been banned")),
|
2013-03-14 10:33:02 +01:00
|
|
|
htmlize(Reason, FileFormat)]);
|
2018-04-02 13:51:19 +02:00
|
|
|
{kickban, 307, <<"">>} ->
|
2019-09-23 14:17:20 +02:00
|
|
|
io_lib:format("<font class=\"mk\">~ts ~ts</font><br/>",
|
2019-06-22 16:08:45 +02:00
|
|
|
[Nick, tr(Lang, ?T("has been kicked"))]);
|
2018-04-02 13:51:19 +02:00
|
|
|
{kickban, 307, Reason} ->
|
2019-09-23 14:17:20 +02:00
|
|
|
io_lib:format("<font class=\"mk\">~ts ~ts: ~ts</font><br/>",
|
2019-06-22 16:08:45 +02:00
|
|
|
[Nick, tr(Lang, ?T("has been kicked")),
|
2013-03-14 10:33:02 +01:00
|
|
|
htmlize(Reason, FileFormat)]);
|
2018-04-02 13:51:19 +02:00
|
|
|
{kickban, 321, <<"">>} ->
|
2019-09-23 14:17:20 +02:00
|
|
|
io_lib:format("<font class=\"mk\">~ts ~ts</font><br/>",
|
2013-03-14 10:33:02 +01:00
|
|
|
[Nick,
|
2019-06-22 16:08:45 +02:00
|
|
|
tr(Lang, ?T("has been kicked because of an affiliation "
|
|
|
|
"change"))]);
|
2018-04-02 13:51:19 +02:00
|
|
|
{kickban, 322, <<"">>} ->
|
2019-09-23 14:17:20 +02:00
|
|
|
io_lib:format("<font class=\"mk\">~ts ~ts</font><br/>",
|
2013-03-14 10:33:02 +01:00
|
|
|
[Nick,
|
2019-06-22 16:08:45 +02:00
|
|
|
tr(Lang, ?T("has been kicked because the room has "
|
|
|
|
"been changed to members-only"))]);
|
2018-04-02 13:51:19 +02:00
|
|
|
{kickban, 332, <<"">>} ->
|
2019-09-23 14:17:20 +02:00
|
|
|
io_lib:format("<font class=\"mk\">~ts ~ts</font><br/>",
|
2013-03-14 10:33:02 +01:00
|
|
|
[Nick,
|
2019-06-22 16:08:45 +02:00
|
|
|
tr(Lang, ?T("has been kicked because of a system "
|
|
|
|
"shutdown"))]);
|
2013-03-14 10:33:02 +01:00
|
|
|
{nickchange, OldNick} ->
|
2019-09-23 14:17:20 +02:00
|
|
|
io_lib:format("<font class=\"mnc\">~ts ~ts ~ts</font><br/>",
|
2013-03-14 10:33:02 +01:00
|
|
|
[htmlize(OldNick, FileFormat),
|
2019-06-22 16:08:45 +02:00
|
|
|
tr(Lang, ?T("is now known as")), Nick]);
|
2013-03-14 10:33:02 +01:00
|
|
|
{subject, T} ->
|
2019-09-23 14:17:20 +02:00
|
|
|
io_lib:format("<font class=\"msc\">~ts~ts~ts</font><br/>",
|
2019-06-22 16:08:45 +02:00
|
|
|
[Nick, tr(Lang, ?T(" has set the subject to: ")),
|
2013-03-14 10:33:02 +01:00
|
|
|
htmlize(T, NoFollow, FileFormat)]);
|
|
|
|
{body, T} ->
|
|
|
|
case {ejabberd_regexp:run(T, <<"^/me ">>), Nick} of
|
|
|
|
{_, <<"">>} ->
|
2019-09-23 14:17:20 +02:00
|
|
|
io_lib:format("<font class=\"msm\">~ts</font><br/>",
|
2013-03-14 10:33:02 +01:00
|
|
|
[htmlize(T, NoFollow, FileFormat)]);
|
|
|
|
{match, _} ->
|
2019-09-23 14:17:20 +02:00
|
|
|
io_lib:format("<font class=\"mne\">~ts ~ts</font><br/>",
|
2013-03-14 10:33:02 +01:00
|
|
|
[Nick,
|
|
|
|
str:substr(htmlize(T, FileFormat), 5)]);
|
|
|
|
{nomatch, _} ->
|
2019-09-23 14:17:20 +02:00
|
|
|
io_lib:format("<font class=\"mn\">~ts</font> ~ts<br/>",
|
2013-03-14 10:33:02 +01:00
|
|
|
[Nick2, htmlize(T, NoFollow, FileFormat)])
|
|
|
|
end;
|
|
|
|
{room_existence, RoomNewExistence} ->
|
2019-09-23 14:17:20 +02:00
|
|
|
io_lib:format("<font class=\"mrcm\">~ts</font><br/>",
|
2013-03-14 10:33:02 +01:00
|
|
|
[get_room_existence_string(RoomNewExistence,
|
|
|
|
Lang)])
|
2006-03-14 05:26:15 +01:00
|
|
|
end,
|
|
|
|
{Hour, Minute, Second} = Time,
|
2013-03-14 10:33:02 +01:00
|
|
|
STime = io_lib:format("~2..0w:~2..0w:~2..0w",
|
|
|
|
[Hour, Minute, Second]),
|
2008-07-09 20:39:41 +02:00
|
|
|
{_, _, Microsecs} = Now,
|
2019-09-23 14:17:20 +02:00
|
|
|
STimeUnique = io_lib:format("~ts.~w",
|
2013-03-14 10:33:02 +01:00
|
|
|
[STime, Microsecs]),
|
2024-03-05 11:49:18 +01:00
|
|
|
maybe_print_jl(open, F, Message, FileFormat),
|
2019-12-16 10:38:53 +01:00
|
|
|
fw(F, io_lib:format("<a id=\"~ts\" name=\"~ts\" href=\"#~ts\" "
|
2019-09-23 14:17:20 +02:00
|
|
|
"class=\"ts\">[~ts]</a> ",
|
2013-03-14 10:33:02 +01:00
|
|
|
[STimeUnique, STimeUnique, STimeUnique, STime])
|
2019-12-16 10:38:53 +01:00
|
|
|
++ Text,
|
2013-03-14 10:33:02 +01:00
|
|
|
FileFormat),
|
2024-03-05 11:49:18 +01:00
|
|
|
maybe_print_jl(close, F, Message, FileFormat),
|
2006-03-14 05:26:15 +01:00
|
|
|
file:close(F),
|
|
|
|
ok.
|
|
|
|
|
|
|
|
%%----------------------------------------------------------------------
|
|
|
|
%% Utilities
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
get_room_existence_string(created, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
tr(Lang, ?T("Chatroom is created"));
|
2013-03-14 10:33:02 +01:00
|
|
|
get_room_existence_string(destroyed, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
tr(Lang, ?T("Chatroom is destroyed"));
|
2013-03-14 10:33:02 +01:00
|
|
|
get_room_existence_string(started, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
tr(Lang, ?T("Chatroom is started"));
|
2013-03-14 10:33:02 +01:00
|
|
|
get_room_existence_string(stopped, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
tr(Lang, ?T("Chatroom is stopped")).
|
2009-12-29 15:43:24 +01:00
|
|
|
|
2006-03-14 05:26:15 +01:00
|
|
|
get_dateweek(Date, Lang) ->
|
|
|
|
Weekday = case calendar:day_of_the_week(Date) of
|
2019-06-22 16:08:45 +02:00
|
|
|
1 -> tr(Lang, ?T("Monday"));
|
|
|
|
2 -> tr(Lang, ?T("Tuesday"));
|
|
|
|
3 -> tr(Lang, ?T("Wednesday"));
|
|
|
|
4 -> tr(Lang, ?T("Thursday"));
|
|
|
|
5 -> tr(Lang, ?T("Friday"));
|
|
|
|
6 -> tr(Lang, ?T("Saturday"));
|
|
|
|
7 -> tr(Lang, ?T("Sunday"))
|
2006-03-14 05:26:15 +01:00
|
|
|
end,
|
|
|
|
{Y, M, D} = Date,
|
|
|
|
Month = case M of
|
2019-06-22 16:08:45 +02:00
|
|
|
1 -> tr(Lang, ?T("January"));
|
|
|
|
2 -> tr(Lang, ?T("February"));
|
|
|
|
3 -> tr(Lang, ?T("March"));
|
|
|
|
4 -> tr(Lang, ?T("April"));
|
|
|
|
5 -> tr(Lang, ?T("May"));
|
|
|
|
6 -> tr(Lang, ?T("June"));
|
|
|
|
7 -> tr(Lang, ?T("July"));
|
|
|
|
8 -> tr(Lang, ?T("August"));
|
|
|
|
9 -> tr(Lang, ?T("September"));
|
|
|
|
10 -> tr(Lang, ?T("October"));
|
|
|
|
11 -> tr(Lang, ?T("November"));
|
|
|
|
12 -> tr(Lang, ?T("December"))
|
2006-03-14 05:26:15 +01:00
|
|
|
end,
|
2020-07-10 11:40:24 +02:00
|
|
|
unicode:characters_to_binary(
|
2013-03-14 10:33:02 +01:00
|
|
|
case Lang of
|
|
|
|
<<"en">> ->
|
2019-09-23 14:17:20 +02:00
|
|
|
io_lib:format("~ts, ~ts ~w, ~w", [Weekday, Month, D, Y]);
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"es">> ->
|
2019-09-23 14:17:20 +02:00
|
|
|
io_lib:format("~ts ~w de ~ts de ~w",
|
2013-03-14 10:33:02 +01:00
|
|
|
[Weekday, D, Month, Y]);
|
|
|
|
_ ->
|
2019-09-23 14:17:20 +02:00
|
|
|
io_lib:format("~ts, ~w ~ts ~w", [Weekday, D, Month, Y])
|
2013-03-14 10:33:02 +01:00
|
|
|
end).
|
2006-03-14 05:26:15 +01:00
|
|
|
|
|
|
|
make_dir_rec(Dir) ->
|
2014-10-02 12:05:04 +02:00
|
|
|
filelib:ensure_dir(<<Dir/binary, $/>>).
|
2006-03-14 05:26:15 +01:00
|
|
|
|
2008-08-18 21:08:30 +02:00
|
|
|
%% {ok, F1}=file:open("valid-xhtml10.png", [read]).
|
|
|
|
%% {ok, F1b}=file:read(F1, 1000000).
|
|
|
|
%% c("../../ejabberd/src/jlib.erl").
|
2017-05-23 09:43:26 +02:00
|
|
|
%% base64:encode(F1b).
|
2006-09-10 01:33:00 +02:00
|
|
|
|
|
|
|
create_image_files(Images_dir) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
Filenames = [<<"powered-by-ejabberd.png">>,
|
|
|
|
<<"powered-by-erlang.png">>, <<"valid-xhtml10.png">>,
|
|
|
|
<<"vcss.png">>],
|
2017-10-09 22:35:42 +02:00
|
|
|
lists:foreach(
|
|
|
|
fun(Filename) ->
|
|
|
|
Src = filename:join([misc:img_dir(), Filename]),
|
|
|
|
Dst = fjoin([Images_dir, Filename]),
|
|
|
|
case file:copy(Src, Dst) of
|
|
|
|
{ok, _} -> ok;
|
|
|
|
{error, Why} ->
|
2019-09-23 14:17:20 +02:00
|
|
|
?ERROR_MSG("Failed to copy ~ts to ~ts: ~ts",
|
2017-10-09 22:35:42 +02:00
|
|
|
[Src, Dst, file:format_error(Why)])
|
|
|
|
end
|
|
|
|
end, Filenames).
|
2006-03-14 05:26:15 +01:00
|
|
|
|
2008-08-18 21:08:30 +02:00
|
|
|
fw(F, S) -> fw(F, S, [], html).
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
fw(F, S, O) when is_list(O) -> fw(F, S, O, html);
|
2008-08-18 21:08:30 +02:00
|
|
|
fw(F, S, FileFormat) when is_atom(FileFormat) ->
|
|
|
|
fw(F, S, [], FileFormat).
|
|
|
|
|
|
|
|
fw(F, S, O, FileFormat) ->
|
2019-12-16 10:38:53 +01:00
|
|
|
S1 = <<(str:format(S, O))/binary, "\n">>,
|
2008-08-18 21:08:30 +02:00
|
|
|
S2 = case FileFormat of
|
|
|
|
html ->
|
|
|
|
S1;
|
|
|
|
plaintext ->
|
2013-05-30 14:28:39 +02:00
|
|
|
S1a = ejabberd_regexp:greplace(S1, <<"<[^<^>]*>">>, <<"">>),
|
|
|
|
S1x = ejabberd_regexp:greplace(S1a, ?PLAINTEXT_CO, <<"~~">>),
|
2013-03-14 10:33:02 +01:00
|
|
|
S1y = ejabberd_regexp:greplace(S1x, ?PLAINTEXT_IN, <<"<">>),
|
|
|
|
ejabberd_regexp:greplace(S1y, ?PLAINTEXT_OUT, <<">">>)
|
2008-08-18 21:08:30 +02:00
|
|
|
end,
|
2014-05-20 14:49:52 +02:00
|
|
|
file:write(F, S2).
|
2008-08-18 21:08:30 +02:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
put_header(_, _, _, _, _, _, _, _, _, plaintext) -> ok;
|
|
|
|
put_header(F, Room, Date, CSSFile, Lang, Hour_offset,
|
|
|
|
Date_prev, Date_next, Top_link, FileFormat) ->
|
|
|
|
fw(F,
|
|
|
|
<<"<!DOCTYPE html PUBLIC \"-//W3C//DTD "
|
|
|
|
"XHTML 1.0 Transitional//EN\" \"http://www.w3."
|
|
|
|
"org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">">>),
|
|
|
|
fw(F,
|
|
|
|
<<"<html xmlns=\"http://www.w3.org/1999/xhtml\" "
|
2019-09-23 14:17:20 +02:00
|
|
|
"xml:lang=\"~ts\" lang=\"~ts\">">>,
|
2013-03-14 10:33:02 +01:00
|
|
|
[Lang, Lang]),
|
|
|
|
fw(F, <<"<head>">>),
|
|
|
|
fw(F,
|
|
|
|
<<"<meta http-equiv=\"Content-Type\" content=\"t"
|
|
|
|
"ext/html; charset=utf-8\" />">>),
|
2019-09-23 14:17:20 +02:00
|
|
|
fw(F, <<"<title>~ts - ~ts</title>">>,
|
2013-03-14 10:33:02 +01:00
|
|
|
[htmlize(Room#room.title), Date]),
|
2006-03-14 05:26:15 +01:00
|
|
|
put_header_css(F, CSSFile),
|
|
|
|
put_header_script(F),
|
2013-03-14 10:33:02 +01:00
|
|
|
fw(F, <<"</head>">>),
|
|
|
|
fw(F, <<"<body>">>),
|
2006-03-14 05:26:15 +01:00
|
|
|
{Top_url, Top_text} = Top_link,
|
2013-03-14 10:33:02 +01:00
|
|
|
fw(F,
|
|
|
|
<<"<div style=\"text-align: right;\"><a "
|
|
|
|
"style=\"color: #AAAAAA; font-family: "
|
|
|
|
"monospace; text-decoration: none; font-weight"
|
2019-09-23 14:17:20 +02:00
|
|
|
": bold;\" href=\"~ts\">~ts</a></div>">>,
|
2013-03-14 10:33:02 +01:00
|
|
|
[Top_url, Top_text]),
|
2019-09-23 14:17:20 +02:00
|
|
|
fw(F, <<"<div class=\"roomtitle\">~ts</div>">>,
|
2013-03-14 10:33:02 +01:00
|
|
|
[htmlize(Room#room.title)]),
|
|
|
|
fw(F,
|
2019-09-23 14:17:20 +02:00
|
|
|
<<"<a class=\"roomjid\" href=\"xmpp:~ts?join\">~ts"
|
2013-03-14 10:33:02 +01:00
|
|
|
"</a>">>,
|
|
|
|
[Room#room.jid, Room#room.jid]),
|
|
|
|
fw(F,
|
2019-09-23 14:17:20 +02:00
|
|
|
<<"<div class=\"logdate\">~ts<span class=\"w3c\">"
|
|
|
|
"<a class=\"nav\" href=\"~ts\"><</a> "
|
2013-03-14 10:33:02 +01:00
|
|
|
"<a class=\"nav\" href=\"./\">^</a> <a "
|
2019-09-23 14:17:20 +02:00
|
|
|
"class=\"nav\" href=\"~ts\">></a></span></di"
|
2013-03-14 10:33:02 +01:00
|
|
|
"v>">>,
|
|
|
|
[Date, Date_prev, Date_next]),
|
2024-03-05 09:57:58 +01:00
|
|
|
case {htmlize(prepare_subject_author(Room#room.subject_author)),
|
2013-03-14 10:33:02 +01:00
|
|
|
htmlize(Room#room.subject)}
|
|
|
|
of
|
|
|
|
{<<"">>, <<"">>} -> ok;
|
|
|
|
{SuA, Su} ->
|
2019-09-23 14:17:20 +02:00
|
|
|
fw(F, <<"<div class=\"roomsubject\">~ts~ts~ts</div>">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
[SuA, tr(Lang, ?T(" has set the subject to: ")), Su])
|
2006-03-14 05:26:15 +01:00
|
|
|
end,
|
2013-03-14 10:33:02 +01:00
|
|
|
RoomConfig = roomconfig_to_string(Room#room.config,
|
|
|
|
Lang, FileFormat),
|
2008-08-18 21:08:30 +02:00
|
|
|
put_room_config(F, RoomConfig, Lang, FileFormat),
|
2009-07-21 20:33:56 +02:00
|
|
|
Occupants = get_room_occupants(Room#room.jid),
|
2013-03-14 10:33:02 +01:00
|
|
|
RoomOccupants = roomoccupants_to_string(Occupants,
|
|
|
|
FileFormat),
|
2009-07-21 20:33:56 +02:00
|
|
|
put_room_occupants(F, RoomOccupants, Lang, FileFormat),
|
2024-03-05 11:49:18 +01:00
|
|
|
put_occupants_join_leave(F, Lang),
|
2013-03-14 10:33:02 +01:00
|
|
|
Time_offset_str = case Hour_offset < 0 of
|
|
|
|
true -> io_lib:format("~p", [Hour_offset]);
|
|
|
|
false -> io_lib:format("+~p", [Hour_offset])
|
2006-03-14 05:26:15 +01:00
|
|
|
end,
|
2019-09-23 14:17:20 +02:00
|
|
|
fw(F, <<"<br/><a class=\"ts\">GMT~ts</a><br/>">>,
|
2013-03-14 10:33:02 +01:00
|
|
|
[Time_offset_str]).
|
2006-03-14 05:26:15 +01:00
|
|
|
|
2018-06-29 10:34:53 +02:00
|
|
|
put_header_css(F, {file, Path}) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
fw(F, <<"<style type=\"text/css\">">>),
|
|
|
|
fw(F, <<"<!--">>),
|
2018-06-29 10:34:53 +02:00
|
|
|
case file:read_file(Path) of
|
2017-10-09 22:35:42 +02:00
|
|
|
{ok, Data} -> fw(F, Data);
|
|
|
|
{error, _} -> ok
|
|
|
|
end,
|
2013-03-14 10:33:02 +01:00
|
|
|
fw(F, <<"//-->">>),
|
|
|
|
fw(F, <<"</style>">>);
|
2018-06-29 10:34:53 +02:00
|
|
|
put_header_css(F, {url, URL}) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
fw(F,
|
|
|
|
<<"<link rel=\"stylesheet\" type=\"text/css\" "
|
2019-09-23 14:17:20 +02:00
|
|
|
"href=\"~ts\" media=\"all\">">>,
|
2018-06-29 10:34:53 +02:00
|
|
|
[URL]).
|
2006-03-14 05:26:15 +01:00
|
|
|
|
|
|
|
put_header_script(F) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
fw(F, <<"<script type=\"text/javascript\">">>),
|
2017-10-09 22:35:42 +02:00
|
|
|
case misc:read_js("muc.js") of
|
|
|
|
{ok, Data} -> fw(F, Data);
|
|
|
|
{error, _} -> ok
|
|
|
|
end,
|
2013-03-14 10:33:02 +01:00
|
|
|
fw(F, <<"</script>">>).
|
2006-03-14 05:26:15 +01:00
|
|
|
|
2008-08-18 21:08:30 +02:00
|
|
|
put_room_config(_F, _RoomConfig, _Lang, plaintext) ->
|
|
|
|
ok;
|
|
|
|
put_room_config(F, RoomConfig, Lang, _FileFormat) ->
|
2019-02-27 09:56:20 +01:00
|
|
|
{_, Now2, _} = erlang:timestamp(),
|
2013-03-14 10:33:02 +01:00
|
|
|
fw(F, <<"<div class=\"rc\">">>),
|
|
|
|
fw(F,
|
|
|
|
<<"<div class=\"rct\" onclick=\"sh('a~p');return "
|
2019-09-23 14:17:20 +02:00
|
|
|
"false;\">~ts</div>">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
[Now2, tr(Lang, ?T("Room Configuration"))]),
|
2013-03-14 10:33:02 +01:00
|
|
|
fw(F,
|
|
|
|
<<"<div class=\"rcos\" id=\"a~p\" style=\"displa"
|
2019-09-23 14:17:20 +02:00
|
|
|
"y: none;\" ><br/>~ts</div>">>,
|
2013-03-14 10:33:02 +01:00
|
|
|
[Now2, RoomConfig]),
|
|
|
|
fw(F, <<"</div>">>).
|
|
|
|
|
|
|
|
put_room_occupants(_F, _RoomOccupants, _Lang,
|
|
|
|
plaintext) ->
|
2009-07-21 20:33:56 +02:00
|
|
|
ok;
|
2013-03-14 10:33:02 +01:00
|
|
|
put_room_occupants(F, RoomOccupants, Lang,
|
|
|
|
_FileFormat) ->
|
2019-02-27 09:56:20 +01:00
|
|
|
{_, Now2, _} = erlang:timestamp(),
|
2007-02-19 11:49:23 +01:00
|
|
|
%% htmlize
|
|
|
|
%% The default behaviour is to ignore the nofollow spam prevention on links
|
|
|
|
%% (NoFollow=false)
|
2013-03-14 10:33:02 +01:00
|
|
|
fw(F, <<"<div class=\"rc\">">>),
|
|
|
|
fw(F,
|
|
|
|
<<"<div class=\"rct\" onclick=\"sh('o~p');return "
|
2019-09-23 14:17:20 +02:00
|
|
|
"false;\">~ts</div>">>,
|
2019-06-22 16:08:45 +02:00
|
|
|
[Now2, tr(Lang, ?T("Room Occupants"))]),
|
2013-03-14 10:33:02 +01:00
|
|
|
fw(F,
|
|
|
|
<<"<div class=\"rcos\" id=\"o~p\" style=\"displa"
|
2019-09-23 14:17:20 +02:00
|
|
|
"y: none;\" ><br/>~ts</div>">>,
|
2013-03-14 10:33:02 +01:00
|
|
|
[Now2, RoomOccupants]),
|
|
|
|
fw(F, <<"</div>">>).
|
|
|
|
|
2024-03-05 11:49:18 +01:00
|
|
|
put_occupants_join_leave(F, Lang) ->
|
|
|
|
fw(F, <<"<div class=\"rc\">">>),
|
|
|
|
fw(F,
|
|
|
|
<<"<div class=\"rct\" onclick=\"jlf();return "
|
|
|
|
"false;\">~ts</div>">>,
|
|
|
|
[tr(Lang, ?T("Show Occupants Join/Leave"))]),
|
|
|
|
fw(F, <<"</div>">>).
|
|
|
|
|
|
|
|
maybe_print_jl(_Direction, _F, _Message, plaintext) ->
|
|
|
|
ok;
|
|
|
|
maybe_print_jl(Direction, F, Message, html) ->
|
|
|
|
PrintJl = case Message of
|
|
|
|
join -> true;
|
|
|
|
leave -> true;
|
|
|
|
{leave, _} -> true;
|
|
|
|
_ -> false
|
|
|
|
end,
|
|
|
|
case PrintJl of
|
|
|
|
true -> print_jl(Direction, F);
|
|
|
|
false -> ok
|
|
|
|
end.
|
|
|
|
|
|
|
|
print_jl(Direction, F) ->
|
|
|
|
String = case Direction of
|
|
|
|
open -> "<div class=\"jl\">";
|
|
|
|
close -> "</div>"
|
|
|
|
end,
|
|
|
|
fw(F, io_lib:format(String, [])).
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
htmlize(S1) -> htmlize(S1, html).
|
|
|
|
|
2013-05-30 14:28:39 +02:00
|
|
|
htmlize(S1, plaintext) ->
|
|
|
|
ejabberd_regexp:greplace(S1, <<"~">>, ?PLAINTEXT_CO);
|
2008-08-18 21:08:30 +02:00
|
|
|
htmlize(S1, FileFormat) ->
|
|
|
|
htmlize(S1, false, FileFormat).
|
2007-02-19 11:49:23 +01:00
|
|
|
|
|
|
|
%% The NoFollow parameter tell if the spam prevention should be applied to the link found
|
|
|
|
%% true means 'apply nofollow on links'.
|
2013-05-30 14:28:39 +02:00
|
|
|
htmlize(S0, _NoFollow, plaintext) ->
|
2013-05-31 13:23:08 +02:00
|
|
|
S1 = ejabberd_regexp:greplace(S0, <<"~">>, ?PLAINTEXT_CO),
|
|
|
|
S1x = ejabberd_regexp:greplace(S1, <<"<">>, ?PLAINTEXT_IN),
|
|
|
|
ejabberd_regexp:greplace(S1x, <<">">>, ?PLAINTEXT_OUT);
|
2008-08-18 21:08:30 +02:00
|
|
|
htmlize(S1, NoFollow, _FileFormat) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
S2_list = str:tokens(S1, <<"\n">>),
|
|
|
|
lists:foldl(fun (Si, Res) ->
|
|
|
|
Si2 = htmlize2(Si, NoFollow),
|
|
|
|
case Res of
|
|
|
|
<<"">> -> Si2;
|
|
|
|
_ -> <<Res/binary, "<br/>", Si2/binary>>
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
<<"">>, S2_list).
|
2006-03-14 05:26:15 +01:00
|
|
|
|
2007-02-19 11:49:23 +01:00
|
|
|
htmlize2(S1, NoFollow) ->
|
|
|
|
%% Regexp link
|
|
|
|
%% Add the nofollow rel attribute when required
|
2013-03-14 10:33:02 +01:00
|
|
|
S2 = ejabberd_regexp:greplace(S1, <<"\\&">>,
|
|
|
|
<<"\\&">>),
|
|
|
|
S3 = ejabberd_regexp:greplace(S2, <<"<">>,
|
|
|
|
<<"\\<">>),
|
|
|
|
S4 = ejabberd_regexp:greplace(S3, <<">">>,
|
|
|
|
<<"\\>">>),
|
|
|
|
S5 = ejabberd_regexp:greplace(S4,
|
|
|
|
<<"((http|https|ftp)://|(mailto|xmpp):)[^] "
|
|
|
|
")'\"}]+">>,
|
|
|
|
link_regexp(NoFollow)),
|
|
|
|
S6 = ejabberd_regexp:greplace(S5, <<" ">>,
|
|
|
|
<<"\\ \\ ">>),
|
|
|
|
S7 = ejabberd_regexp:greplace(S6, <<"\\t">>,
|
|
|
|
<<"\\ \\ \\ \\ ">>),
|
2014-05-19 19:07:46 +02:00
|
|
|
S8 = ejabberd_regexp:greplace(S7, <<"~">>,
|
2014-05-20 14:49:52 +02:00
|
|
|
<<"~~">>),
|
2014-05-19 19:07:46 +02:00
|
|
|
ejabberd_regexp:greplace(S8, <<226, 128, 174>>,
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"[RLO]">>).
|
|
|
|
|
|
|
|
link_regexp(false) -> <<"<a href=\"&\">&</a>">>;
|
2007-02-19 11:49:23 +01:00
|
|
|
link_regexp(true) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"<a href=\"&\" rel=\"nofollow\">&</a>">>.
|
2007-02-19 11:49:23 +01:00
|
|
|
|
2006-03-14 05:26:15 +01:00
|
|
|
get_room_info(RoomJID, Opts) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
Title = case lists:keysearch(title, 1, Opts) of
|
|
|
|
{value, {_, T}} -> T;
|
|
|
|
false -> <<"">>
|
|
|
|
end,
|
|
|
|
Subject = case lists:keysearch(subject, 1, Opts) of
|
2017-11-13 09:25:35 +01:00
|
|
|
{value, {_, S}} -> xmpp:get_text(S);
|
2013-03-14 10:33:02 +01:00
|
|
|
false -> <<"">>
|
|
|
|
end,
|
|
|
|
SubjectAuthor = case lists:keysearch(subject_author, 1,
|
|
|
|
Opts)
|
|
|
|
of
|
|
|
|
{value, {_, SA}} -> SA;
|
|
|
|
false -> <<"">>
|
|
|
|
end,
|
2017-02-26 08:07:12 +01:00
|
|
|
#room{jid = jid:encode(RoomJID), title = Title,
|
2013-03-14 10:33:02 +01:00
|
|
|
subject = Subject, subject_author = SubjectAuthor,
|
|
|
|
config = Opts}.
|
2006-03-14 05:26:15 +01:00
|
|
|
|
2008-08-18 21:08:30 +02:00
|
|
|
roomconfig_to_string(Options, Lang, FileFormat) ->
|
2006-03-14 05:26:15 +01:00
|
|
|
Title = case lists:keysearch(title, 1, Options) of
|
2013-03-14 10:33:02 +01:00
|
|
|
{value, Tuple} -> [Tuple];
|
|
|
|
false -> []
|
2006-03-14 05:26:15 +01:00
|
|
|
end,
|
|
|
|
Os1 = lists:keydelete(title, 1, Options),
|
|
|
|
Os2 = lists:sort(Os1),
|
|
|
|
Options2 = Title ++ Os2,
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:foldl(fun ({Opt, Val}, R) ->
|
2017-09-23 23:08:01 +02:00
|
|
|
case get_roomconfig_text(Opt, Lang) of
|
2013-03-14 10:33:02 +01:00
|
|
|
undefined -> R;
|
2017-09-23 23:08:01 +02:00
|
|
|
OptText ->
|
2013-03-14 10:33:02 +01:00
|
|
|
R2 = case Val of
|
|
|
|
false ->
|
|
|
|
<<"<div class=\"rcod\">",
|
|
|
|
OptText/binary, "</div>">>;
|
|
|
|
true ->
|
|
|
|
<<"<div class=\"rcoe\">",
|
|
|
|
OptText/binary, "</div>">>;
|
|
|
|
<<"">> ->
|
|
|
|
<<"<div class=\"rcod\">",
|
|
|
|
OptText/binary, "</div>">>;
|
|
|
|
T ->
|
|
|
|
case Opt of
|
|
|
|
password ->
|
|
|
|
<<"<div class=\"rcoe\">",
|
|
|
|
OptText/binary, "</div>">>;
|
|
|
|
max_users ->
|
|
|
|
<<"<div class=\"rcot\">",
|
|
|
|
OptText/binary, ": \"",
|
2016-07-25 12:50:30 +02:00
|
|
|
(htmlize(integer_to_binary(T),
|
2013-03-14 10:33:02 +01:00
|
|
|
FileFormat))/binary,
|
|
|
|
"\"</div>">>;
|
|
|
|
title ->
|
|
|
|
<<"<div class=\"rcot\">",
|
|
|
|
OptText/binary, ": \"",
|
|
|
|
(htmlize(T,
|
|
|
|
FileFormat))/binary,
|
|
|
|
"\"</div>">>;
|
|
|
|
description ->
|
|
|
|
<<"<div class=\"rcot\">",
|
|
|
|
OptText/binary, ": \"",
|
|
|
|
(htmlize(T,
|
|
|
|
FileFormat))/binary,
|
|
|
|
"\"</div>">>;
|
|
|
|
allow_private_messages_from_visitors ->
|
|
|
|
<<"<div class=\"rcot\">",
|
|
|
|
OptText/binary, ": \"",
|
2019-06-22 16:08:45 +02:00
|
|
|
(htmlize(tr(Lang, misc:atom_to_binary(T)),
|
2013-03-14 10:33:02 +01:00
|
|
|
FileFormat))/binary,
|
|
|
|
"\"</div>">>;
|
2024-03-05 09:57:58 +01:00
|
|
|
allowpm ->
|
|
|
|
<<"<div class=\"rcot\">",
|
|
|
|
OptText/binary, ": \"",
|
|
|
|
(htmlize(tr(Lang, misc:atom_to_binary(T)),
|
|
|
|
FileFormat))/binary,
|
|
|
|
"\"</div>">>;
|
2013-03-14 10:33:02 +01:00
|
|
|
_ -> <<"\"", T/binary, "\"">>
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
<<R/binary, R2/binary>>
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
<<"">>, Options2).
|
|
|
|
|
2019-06-22 16:08:45 +02:00
|
|
|
get_roomconfig_text(title, Lang) -> tr(Lang, ?T("Room title"));
|
2017-09-23 23:08:01 +02:00
|
|
|
get_roomconfig_text(persistent, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
tr(Lang, ?T("Make room persistent"));
|
2017-09-23 23:08:01 +02:00
|
|
|
get_roomconfig_text(public, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
tr(Lang, ?T("Make room public searchable"));
|
2017-09-23 23:08:01 +02:00
|
|
|
get_roomconfig_text(public_list, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
tr(Lang, ?T("Make participants list public"));
|
2017-09-23 23:08:01 +02:00
|
|
|
get_roomconfig_text(password_protected, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
tr(Lang, ?T("Make room password protected"));
|
|
|
|
get_roomconfig_text(password, Lang) -> tr(Lang, ?T("Password"));
|
2017-09-23 23:08:01 +02:00
|
|
|
get_roomconfig_text(anonymous, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
tr(Lang, ?T("This room is not anonymous"));
|
2017-09-23 23:08:01 +02:00
|
|
|
get_roomconfig_text(members_only, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
tr(Lang, ?T("Make room members-only"));
|
2017-09-23 23:08:01 +02:00
|
|
|
get_roomconfig_text(moderated, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
tr(Lang, ?T("Make room moderated"));
|
2017-09-23 23:08:01 +02:00
|
|
|
get_roomconfig_text(members_by_default, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
tr(Lang, ?T("Default users as participants"));
|
2017-09-23 23:08:01 +02:00
|
|
|
get_roomconfig_text(allow_change_subj, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
tr(Lang, ?T("Allow users to change the subject"));
|
2023-08-08 13:28:02 +02:00
|
|
|
get_roomconfig_text(allowpm, Lang) ->
|
|
|
|
tr(Lang, ?T("Who can send private messages"));
|
2017-09-23 23:08:01 +02:00
|
|
|
get_roomconfig_text(allow_private_messages_from_visitors, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
tr(Lang, ?T("Allow visitors to send private messages to"));
|
2017-09-23 23:08:01 +02:00
|
|
|
get_roomconfig_text(allow_query_users, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
tr(Lang, ?T("Allow users to query other users"));
|
2017-09-23 23:08:01 +02:00
|
|
|
get_roomconfig_text(allow_user_invites, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
tr(Lang, ?T("Allow users to send invites"));
|
|
|
|
get_roomconfig_text(logging, Lang) -> tr(Lang, ?T("Enable logging"));
|
2017-09-23 23:08:01 +02:00
|
|
|
get_roomconfig_text(allow_visitor_nickchange, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
tr(Lang, ?T("Allow visitors to change nickname"));
|
2017-09-23 23:08:01 +02:00
|
|
|
get_roomconfig_text(allow_visitor_status, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
tr(Lang, ?T("Allow visitors to send status text in presence updates"));
|
2017-09-23 23:08:01 +02:00
|
|
|
get_roomconfig_text(captcha_protected, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
tr(Lang, ?T("Make room CAPTCHA protected"));
|
2017-09-23 23:08:01 +02:00
|
|
|
get_roomconfig_text(description, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
tr(Lang, ?T("Room description"));
|
2017-09-23 23:08:01 +02:00
|
|
|
%% get_roomconfig_text(subject, Lang) -> "Subject";
|
|
|
|
%% get_roomconfig_text(subject_author, Lang) -> "Subject author";
|
|
|
|
get_roomconfig_text(max_users, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
tr(Lang, ?T("Maximum Number of Occupants"));
|
2017-09-23 23:08:01 +02:00
|
|
|
get_roomconfig_text(_, _) -> undefined.
|
2006-03-14 05:26:15 +01:00
|
|
|
|
2009-07-21 20:33:56 +02:00
|
|
|
%% Users = [{JID, Nick, Role}]
|
|
|
|
roomoccupants_to_string(Users, _FileFormat) ->
|
|
|
|
Res = [role_users_to_string(RoleS, Users1)
|
2013-03-14 10:33:02 +01:00
|
|
|
|| {RoleS, Users1} <- group_by_role(Users),
|
|
|
|
Users1 /= []],
|
|
|
|
iolist_to_binary([<<"<div class=\"rcot\">">>, Res, <<"</div>">>]).
|
2009-07-21 20:33:56 +02:00
|
|
|
|
|
|
|
group_by_role(Users) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{Ms, Ps, Vs, Ns} = lists:foldl(fun ({JID, Nick,
|
|
|
|
moderator},
|
|
|
|
{Mod, Par, Vis, Non}) ->
|
|
|
|
{[{JID, Nick}] ++ Mod, Par, Vis,
|
|
|
|
Non};
|
|
|
|
({JID, Nick, participant},
|
|
|
|
{Mod, Par, Vis, Non}) ->
|
|
|
|
{Mod, [{JID, Nick}] ++ Par, Vis,
|
|
|
|
Non};
|
|
|
|
({JID, Nick, visitor},
|
|
|
|
{Mod, Par, Vis, Non}) ->
|
|
|
|
{Mod, Par, [{JID, Nick}] ++ Vis,
|
|
|
|
Non};
|
|
|
|
({JID, Nick, none},
|
|
|
|
{Mod, Par, Vis, Non}) ->
|
|
|
|
{Mod, Par, Vis, [{JID, Nick}] ++ Non}
|
|
|
|
end,
|
|
|
|
{[], [], [], []}, Users),
|
|
|
|
case Ms of
|
|
|
|
[] -> [];
|
|
|
|
_ -> [{<<"Moderator">>, Ms}]
|
|
|
|
end
|
|
|
|
++
|
|
|
|
case Ms of
|
|
|
|
[] -> [];
|
|
|
|
_ -> [{<<"Participant">>, Ps}]
|
|
|
|
end
|
|
|
|
++
|
|
|
|
case Ms of
|
|
|
|
[] -> [];
|
|
|
|
_ -> [{<<"Visitor">>, Vs}]
|
|
|
|
end
|
|
|
|
++
|
|
|
|
case Ms of
|
|
|
|
[] -> [];
|
|
|
|
_ -> [{<<"None">>, Ns}]
|
|
|
|
end.
|
|
|
|
|
2009-07-21 20:33:56 +02:00
|
|
|
role_users_to_string(RoleS, Users) ->
|
|
|
|
SortedUsers = lists:keysort(2, Users),
|
2013-03-14 10:33:02 +01:00
|
|
|
UsersString = << <<Nick/binary, "<br/>">>
|
|
|
|
|| {_JID, Nick} <- SortedUsers >>,
|
|
|
|
<<RoleS/binary, ": ", UsersString/binary>>.
|
2009-07-21 20:33:56 +02:00
|
|
|
|
|
|
|
get_room_occupants(RoomJIDString) ->
|
2017-02-26 08:07:12 +01:00
|
|
|
RoomJID = jid:decode(RoomJIDString),
|
2009-07-21 20:33:56 +02:00
|
|
|
RoomName = RoomJID#jid.luser,
|
|
|
|
MucService = RoomJID#jid.lserver,
|
2019-06-14 11:33:26 +02:00
|
|
|
case get_room_state(RoomName, MucService) of
|
|
|
|
{ok, StateData} ->
|
|
|
|
[{U#user.jid, U#user.nick, U#user.role}
|
|
|
|
|| U <- maps:values(StateData#state.users)];
|
|
|
|
error ->
|
|
|
|
[]
|
|
|
|
end.
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2024-03-05 09:57:58 +01:00
|
|
|
prepare_subject_author({Nick, _}) ->
|
|
|
|
Nick;
|
|
|
|
prepare_subject_author(SA) ->
|
|
|
|
SA.
|
|
|
|
|
2019-06-14 11:33:26 +02:00
|
|
|
-spec get_room_state(binary(), binary()) -> {ok, mod_muc_room:state()} | error.
|
2009-07-21 20:33:56 +02:00
|
|
|
|
|
|
|
get_room_state(RoomName, MucService) ->
|
2017-01-13 10:03:39 +01:00
|
|
|
case mod_muc:find_online_room(RoomName, MucService) of
|
|
|
|
{ok, RoomPid} ->
|
2019-06-14 11:33:26 +02:00
|
|
|
get_room_state(RoomPid);
|
2017-01-13 10:03:39 +01:00
|
|
|
error ->
|
2019-06-14 11:33:26 +02:00
|
|
|
error
|
2009-07-21 20:33:56 +02:00
|
|
|
end.
|
|
|
|
|
2019-06-14 11:33:26 +02:00
|
|
|
-spec get_room_state(pid()) -> {ok, mod_muc_room:state()} | error.
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2009-07-21 20:33:56 +02:00
|
|
|
get_room_state(RoomPid) ->
|
2019-07-08 23:47:54 +02:00
|
|
|
case mod_muc_room:get_state(RoomPid) of
|
|
|
|
{ok, State} -> {ok, State};
|
|
|
|
{error, _} -> error
|
2019-06-14 11:33:26 +02:00
|
|
|
end.
|
2009-07-21 20:33:56 +02:00
|
|
|
|
2015-10-07 00:06:58 +02:00
|
|
|
get_proc_name(Host) ->
|
2017-02-14 10:39:26 +01:00
|
|
|
gen_mod:get_module_proc(Host, ?MODULE).
|
2006-03-14 05:26:15 +01:00
|
|
|
|
|
|
|
calc_hour_offset(TimeHere) ->
|
2015-12-07 16:08:57 +01:00
|
|
|
TimeZero = calendar:universal_time(),
|
2013-03-14 10:33:02 +01:00
|
|
|
TimeHereHour =
|
|
|
|
calendar:datetime_to_gregorian_seconds(TimeHere) div
|
|
|
|
3600,
|
|
|
|
TimeZeroHour =
|
|
|
|
calendar:datetime_to_gregorian_seconds(TimeZero) div
|
|
|
|
3600,
|
2008-08-18 21:08:30 +02:00
|
|
|
TimeHereHour - TimeZeroHour.
|
2013-03-14 10:33:02 +01:00
|
|
|
|
|
|
|
fjoin(FileList) ->
|
|
|
|
list_to_binary(filename:join([binary_to_list(File) || File <- FileList])).
|
2015-06-01 14:38:27 +02:00
|
|
|
|
2019-06-22 16:08:45 +02:00
|
|
|
-spec tr(binary(), binary()) -> binary().
|
|
|
|
tr(Lang, Text) ->
|
|
|
|
translate:translate(Lang, Text).
|
|
|
|
|
2015-07-28 21:08:33 +02:00
|
|
|
has_no_permanent_store_hint(Packet) ->
|
2016-07-25 12:50:30 +02:00
|
|
|
xmpp:has_subtag(Packet, #hint{type = 'no-store'}) orelse
|
|
|
|
xmpp:has_subtag(Packet, #hint{type = 'no-storage'}) orelse
|
|
|
|
xmpp:has_subtag(Packet, #hint{type = 'no-permanent-store'}) orelse
|
|
|
|
xmpp:has_subtag(Packet, #hint{type = 'no-permanent-storage'}).
|
2015-07-28 21:08:33 +02:00
|
|
|
|
2015-06-01 14:38:27 +02:00
|
|
|
mod_opt_type(access_log) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
econf:acl();
|
2018-01-23 08:54:52 +01:00
|
|
|
mod_opt_type(cssfile) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
econf:url_or_file();
|
2015-06-01 14:38:27 +02:00
|
|
|
mod_opt_type(dirname) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
econf:enum([room_jid, room_name]);
|
2015-06-01 14:38:27 +02:00
|
|
|
mod_opt_type(dirtype) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
econf:enum([subdirs, plain]);
|
2015-06-01 14:38:27 +02:00
|
|
|
mod_opt_type(file_format) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
econf:enum([html, plaintext]);
|
2015-06-01 14:38:27 +02:00
|
|
|
mod_opt_type(file_permissions) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
econf:and_then(
|
|
|
|
econf:options(
|
|
|
|
#{mode => econf:non_neg_int(),
|
|
|
|
group => econf:non_neg_int()}),
|
|
|
|
fun(Opts) ->
|
|
|
|
{proplists:get_value(mode, Opts, 644),
|
|
|
|
proplists:get_value(group, Opts, 33)}
|
|
|
|
end);
|
|
|
|
mod_opt_type(outdir) ->
|
|
|
|
econf:directory(write);
|
2015-06-01 14:38:27 +02:00
|
|
|
mod_opt_type(spam_prevention) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
econf:bool();
|
2015-06-01 14:38:27 +02:00
|
|
|
mod_opt_type(timezone) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
econf:enum([local, universal]);
|
2019-09-26 15:53:36 +02:00
|
|
|
mod_opt_type(url) ->
|
|
|
|
econf:url();
|
2015-06-01 14:38:27 +02:00
|
|
|
mod_opt_type(top_link) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
econf:and_then(
|
|
|
|
econf:non_empty(
|
|
|
|
econf:map(econf:binary(), econf:binary())),
|
|
|
|
fun hd/1).
|
|
|
|
|
|
|
|
-spec mod_options(binary()) -> [{top_link, {binary(), binary()}} |
|
|
|
|
{file_permissions,
|
|
|
|
{non_neg_integer(), non_neg_integer()}} |
|
|
|
|
{atom(), any()}].
|
2018-01-23 08:54:52 +01:00
|
|
|
mod_options(_) ->
|
|
|
|
[{access_log, muc_admin},
|
2019-09-26 15:53:36 +02:00
|
|
|
{cssfile, {file, filename:join(misc:css_dir(), <<"muc.css">>)}},
|
2018-01-23 08:54:52 +01:00
|
|
|
{dirname, room_jid},
|
|
|
|
{dirtype, subdirs},
|
|
|
|
{file_format, html},
|
2019-06-14 11:33:26 +02:00
|
|
|
{file_permissions, {644, 33}},
|
2018-01-23 08:54:52 +01:00
|
|
|
{outdir, <<"www/muc">>},
|
|
|
|
{spam_prevention, true},
|
|
|
|
{timezone, local},
|
2019-09-26 15:53:36 +02:00
|
|
|
{url, undefined},
|
2019-06-14 11:33:26 +02:00
|
|
|
{top_link, {<<"/">>, <<"Home">>}}].
|
2020-01-08 10:24:51 +01:00
|
|
|
|
|
|
|
mod_doc() ->
|
|
|
|
#{desc =>
|
|
|
|
[?T("This module enables optional logging "
|
|
|
|
"of Multi-User Chat (MUC) public "
|
|
|
|
"conversations to HTML. Once you enable "
|
|
|
|
"this module, users can join a room using a "
|
|
|
|
"MUC capable XMPP client, and if they have "
|
|
|
|
"enough privileges, they can request the "
|
|
|
|
"configuration form in which they can set "
|
|
|
|
"the option to enable room logging."), "",
|
|
|
|
?T("Features:"), "",
|
|
|
|
?T("- Room details are added on top of each page: "
|
|
|
|
"room title, JID, author, subject and configuration."), "",
|
|
|
|
?T("- The room JID in the generated HTML is a link "
|
|
|
|
"to join the room (using XMPP URI)."), "",
|
|
|
|
?T("- Subject and room configuration changes are tracked "
|
|
|
|
"and displayed."), "",
|
|
|
|
?T("- Joins, leaves, nick changes, kicks, bans and '/me' "
|
|
|
|
"are tracked and displayed, including the reason if available."), "",
|
|
|
|
?T("- Generated HTML files are XHTML 1.0 Transitional and "
|
|
|
|
"CSS compliant."), "",
|
|
|
|
?T("- Timestamps are self-referencing links."), "",
|
|
|
|
?T("- Links on top for quicker navigation: "
|
|
|
|
"Previous day, Next day, Up."), "",
|
|
|
|
?T("- CSS is used for style definition, and a custom "
|
|
|
|
"CSS file can be used."), "",
|
|
|
|
?T("- URLs on messages and subjects are converted to hyperlinks."), "",
|
|
|
|
?T("- Timezone used on timestamps is shown on the log files."), "",
|
|
|
|
?T("- A custom link can be added on top of each page."), "",
|
2021-08-21 18:31:21 +02:00
|
|
|
?T("The module depends on _`mod_muc`_.")],
|
2020-01-08 10:24:51 +01:00
|
|
|
opts =>
|
|
|
|
[{access_log,
|
|
|
|
#{value => ?T("AccessName"),
|
|
|
|
desc =>
|
|
|
|
?T("This option restricts which occupants are "
|
|
|
|
"allowed to enable or disable room logging. "
|
|
|
|
"The default value is 'muc_admin'. NOTE: "
|
|
|
|
"for this default setting you need to have an "
|
|
|
|
"access rule for 'muc_admin' in order to take effect.")}},
|
|
|
|
{cssfile,
|
|
|
|
#{value => ?T("Path | URL"),
|
|
|
|
desc =>
|
|
|
|
?T("With this option you can set whether the HTML "
|
|
|
|
"files should have a custom CSS file or if they "
|
|
|
|
"need to use the embedded CSS. Allowed values "
|
|
|
|
"are either 'Path' to local file or an 'URL' to "
|
|
|
|
"a remote file. By default a predefined CSS will "
|
|
|
|
"be embedded into the HTML page.")}},
|
|
|
|
{dirname,
|
|
|
|
#{value => "room_jid | room_name",
|
|
|
|
desc =>
|
2024-01-11 13:23:45 +01:00
|
|
|
?T("Configure the name of the room directory. "
|
2020-01-08 10:24:51 +01:00
|
|
|
"If set to 'room_jid', the room directory name will "
|
|
|
|
"be the full room JID. Otherwise, the room directory "
|
|
|
|
"name will be only the room name, not including the "
|
|
|
|
"MUC service name. The default value is 'room_jid'.")}},
|
|
|
|
{dirtype,
|
|
|
|
#{value => "subdirs | plain",
|
|
|
|
desc =>
|
|
|
|
?T("The type of the created directories can be specified "
|
|
|
|
"with this option. If set to 'subdirs', subdirectories "
|
|
|
|
"are created for each year and month. Otherwise, the "
|
|
|
|
"names of the log files contain the full date, and "
|
|
|
|
"there are no subdirectories. The default value is 'subdirs'.")}},
|
|
|
|
{file_format,
|
|
|
|
#{value => "html | plaintext",
|
|
|
|
desc =>
|
|
|
|
?T("Define the format of the log files: 'html' stores "
|
|
|
|
"in HTML format, 'plaintext' stores in plain text. "
|
|
|
|
"The default value is 'html'.")}},
|
|
|
|
{file_permissions,
|
|
|
|
#{value => "{mode: Mode, group: Group}",
|
|
|
|
desc =>
|
|
|
|
?T("Define the permissions that must be used when "
|
|
|
|
"creating the log files: the number of the mode, "
|
|
|
|
"and the numeric id of the group that will own the "
|
|
|
|
"files. The default value is shown in the example below:"),
|
|
|
|
example =>
|
|
|
|
["file_permissions:",
|
|
|
|
" mode: 644",
|
|
|
|
" group: 33"]}},
|
|
|
|
{outdir,
|
|
|
|
#{value => ?T("Path"),
|
|
|
|
desc =>
|
|
|
|
?T("This option sets the full path to the directory "
|
|
|
|
"in which the HTML files should be stored. "
|
|
|
|
"Make sure the ejabberd daemon user has write "
|
|
|
|
"access on that directory. The default value is 'www/muc'.")}},
|
|
|
|
{spam_prevention,
|
|
|
|
#{value => "true | false",
|
|
|
|
desc =>
|
|
|
|
?T("If set to 'true', a special attribute is added to links "
|
|
|
|
"that prevent their indexation by search engines. "
|
|
|
|
"The default value is 'true', which mean that 'nofollow' "
|
|
|
|
"attributes will be added to user submitted links.")}},
|
|
|
|
{timezone,
|
|
|
|
#{value => "local | universal",
|
|
|
|
desc =>
|
|
|
|
?T("The time zone for the logs is configurable with "
|
|
|
|
"this option. If set to 'local', the local time, as "
|
|
|
|
"reported to Erlang emulator by the operating system, "
|
|
|
|
"will be used. Otherwise, UTC time will be used. "
|
|
|
|
"The default value is 'local'.")}},
|
|
|
|
{url,
|
|
|
|
#{value => ?T("URL"),
|
|
|
|
desc =>
|
|
|
|
?T("A top level 'URL' where a client can access "
|
|
|
|
"logs of a particular conference. The conference name "
|
|
|
|
"is appended to the URL if 'dirname' option is set to "
|
|
|
|
"'room_name' or a conference JID is appended to the 'URL' "
|
|
|
|
"otherwise. There is no default value.")}},
|
|
|
|
{top_link,
|
|
|
|
#{value => "{URL: Text}",
|
|
|
|
desc =>
|
|
|
|
?T("With this option you can customize the link on "
|
|
|
|
"the top right corner of each log file. "
|
|
|
|
"The default value is shown in the example below:"),
|
|
|
|
example =>
|
|
|
|
["top_link:",
|
|
|
|
" /: Home"]}}]}.
|