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>
|
|
|
|
%%%
|
|
|
|
%%%
|
2017-01-02 21:41:53 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2017 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'}).
|
|
|
|
|
2015-06-01 14:38:27 +02:00
|
|
|
-behaviour(ejabberd_config).
|
|
|
|
|
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
|
2013-08-12 14:25:05 +02:00
|
|
|
-export([start_link/2, start/2, stop/1, transform_module_options/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,
|
2016-07-06 13:58:48 +02:00
|
|
|
mod_opt_type/1, opt_type/1, depends/2]).
|
2006-03-14 05:26:15 +01:00
|
|
|
|
|
|
|
-include("ejabberd.hrl").
|
2013-04-08 11:12:54 +02:00
|
|
|
-include("logger.hrl").
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2016-07-25 12:50:30 +02:00
|
|
|
-include("xmpp.hrl").
|
2009-07-21 20:33:56 +02:00
|
|
|
-include("mod_muc_room.hrl").
|
|
|
|
|
2006-03-14 05:26:15 +01:00
|
|
|
-define(T(Text), translate:translate(Lang, Text)).
|
|
|
|
-define(PROCNAME, ejabberd_mod_muc_log).
|
|
|
|
-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_link(Host, Opts) ->
|
|
|
|
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
|
|
|
|
gen_server:start_link({local, Proc}, ?MODULE, [Host, Opts], []).
|
|
|
|
|
|
|
|
start(Host, Opts) ->
|
|
|
|
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
|
2015-10-07 00:06:58 +02:00
|
|
|
ChildSpec = {Proc, {?MODULE, start_link, [Host, Opts]},
|
2016-07-29 11:18:42 +02:00
|
|
|
transient, 1000, worker, [?MODULE]},
|
2006-03-14 05:26:15 +01:00
|
|
|
supervisor:start_child(ejabberd_sup, ChildSpec).
|
|
|
|
|
|
|
|
stop(Host) ->
|
|
|
|
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
|
|
|
|
gen_server:call(Proc, stop),
|
|
|
|
supervisor:delete_child(ejabberd_sup, Proc).
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2013-08-12 14:25:05 +02:00
|
|
|
transform_module_options(Opts) ->
|
|
|
|
lists:map(
|
|
|
|
fun({top_link, {S1, S2}}) ->
|
|
|
|
{top_link, [{S1, S2}]};
|
|
|
|
(Opt) ->
|
|
|
|
Opt
|
|
|
|
end, Opts).
|
|
|
|
|
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
|
|
|
|
%%====================================================================
|
|
|
|
init([Host, Opts]) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
OutDir = gen_mod:get_opt(outdir, Opts,
|
|
|
|
fun iolist_to_binary/1,
|
|
|
|
<<"www/muc">>),
|
2015-10-07 00:06:58 +02:00
|
|
|
DirType = gen_mod:get_opt(dirtype, Opts,
|
2013-03-14 10:33:02 +01:00
|
|
|
fun(subdirs) -> subdirs;
|
|
|
|
(plain) -> plain
|
|
|
|
end, subdirs),
|
|
|
|
DirName = gen_mod:get_opt(dirname, Opts,
|
|
|
|
fun(room_jid) -> room_jid;
|
|
|
|
(room_name) -> room_name
|
|
|
|
end, room_jid),
|
|
|
|
FileFormat = gen_mod:get_opt(file_format, Opts,
|
|
|
|
fun(html) -> html;
|
|
|
|
(plaintext) -> plaintext
|
|
|
|
end, html),
|
|
|
|
FilePermissions = gen_mod:get_opt(file_permissions, Opts,
|
2014-12-08 15:51:06 +01:00
|
|
|
fun(SubOpts) ->
|
|
|
|
F = fun({mode, Mode}, {_M, G}) ->
|
|
|
|
{Mode, G};
|
|
|
|
({group, Group}, {M, _G}) ->
|
|
|
|
{M, Group}
|
|
|
|
end,
|
|
|
|
lists:foldl(F, {644, 33}, SubOpts)
|
2013-03-14 10:33:02 +01:00
|
|
|
end, {644, 33}),
|
|
|
|
CSSFile = gen_mod:get_opt(cssfile, Opts,
|
|
|
|
fun iolist_to_binary/1,
|
|
|
|
false),
|
|
|
|
AccessLog = gen_mod:get_opt(access_log, Opts,
|
2016-06-21 13:18:24 +02:00
|
|
|
fun acl:access_rules_validator/1,
|
2013-03-14 10:33:02 +01:00
|
|
|
muc_admin),
|
|
|
|
Timezone = gen_mod:get_opt(timezone, Opts,
|
|
|
|
fun(local) -> local;
|
|
|
|
(universal) -> universal
|
|
|
|
end, local),
|
|
|
|
Top_link = gen_mod:get_opt(top_link, Opts,
|
2013-08-12 14:25:05 +02:00
|
|
|
fun([{S1, S2}]) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{iolist_to_binary(S1),
|
|
|
|
iolist_to_binary(S2)}
|
|
|
|
end, {<<"/">>, <<"Home">>}),
|
|
|
|
NoFollow = gen_mod:get_opt(spam_prevention, Opts,
|
|
|
|
fun(B) when is_boolean(B) -> B end,
|
|
|
|
true),
|
2013-08-12 14:25:05 +02:00
|
|
|
Lang = ejabberd_config:get_option(
|
2013-03-14 10:33:02 +01:00
|
|
|
{language, Host},
|
|
|
|
fun iolist_to_binary/1,
|
|
|
|
?MYLANG),
|
|
|
|
{ok,
|
|
|
|
#logstate{host = Host, out_dir = OutDir,
|
|
|
|
dir_type = DirType, dir_name = DirName,
|
2015-10-07 00:06:58 +02:00
|
|
|
file_format = FileFormat, css_file = CSSFile,
|
|
|
|
file_permissions = FilePermissions,
|
2013-03-14 10:33:02 +01:00
|
|
|
access = AccessLog, lang = Lang, timezone = Timezone,
|
|
|
|
spam_prevention = NoFollow, top_link = Top_link}}.
|
2006-03-14 05:26:15 +01:00
|
|
|
|
|
|
|
handle_call({check_access_log, ServerHost, FromJID}, _From, State) ->
|
2009-07-21 20:33:56 +02:00
|
|
|
Reply = acl:match_rule(ServerHost, State#logstate.access, FromJID),
|
2006-03-14 05:26:15 +01:00
|
|
|
{reply, Reply, State};
|
|
|
|
handle_call(stop, _From, State) ->
|
|
|
|
{stop, normal, ok, State}.
|
|
|
|
|
|
|
|
handle_cast({add_to_log, Type, Data, Room, Opts}, State) ->
|
|
|
|
case catch add_to_log2(Type, Data, Room, Opts, State) of
|
2013-03-14 10:33:02 +01:00
|
|
|
{'EXIT', Reason} -> ?ERROR_MSG("~p", [Reason]);
|
|
|
|
_ -> ok
|
2006-03-14 05:26:15 +01:00
|
|
|
end,
|
|
|
|
{noreply, State};
|
2013-03-14 10:33:02 +01:00
|
|
|
handle_cast(_Msg, State) -> {noreply, State}.
|
2006-03-14 05:26:15 +01:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
handle_info(_Info, State) -> {noreply, State}.
|
2006-03-14 05:26:15 +01:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
terminate(_Reason, _State) -> ok.
|
2006-03-14 05:26:15 +01:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
code_change(_OldVsn, State, _Extra) -> {ok, State}.
|
2006-03-14 05:26:15 +01:00
|
|
|
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
%%% Internal functions
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
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) ->
|
2015-11-24 16:44:13 +01:00
|
|
|
JID = jid:from_string(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 "
|
|
|
|
"style=\"border:0\" src=\"~s/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 "
|
|
|
|
"style=\"border:0\" src=\"~s/powered-by-erlang"
|
|
|
|
".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"
|
|
|
|
"eight:31px\" src=\"~s/valid-xhtml10.png\" "
|
|
|
|
"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:"
|
|
|
|
"31px\" src=\"~s/vcss.png\" alt=\"Valid "
|
|
|
|
"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),
|
2015-12-07 16:08:57 +01:00
|
|
|
Now = p1_time_compat: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),
|
|
|
|
io_lib:format("<font class=\"mrcm\">~s</font><br/>",
|
|
|
|
[?T(<<"Chatroom configuration modified">>)]);
|
|
|
|
{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),
|
|
|
|
io_lib:format("<font class=\"mrcm\">~s</font><br/>",
|
|
|
|
[?T(<<"Chatroom configuration modified">>)]);
|
|
|
|
join ->
|
|
|
|
io_lib:format("<font class=\"mj\">~s ~s</font><br/>",
|
|
|
|
[Nick, ?T(<<"joins the room">>)]);
|
|
|
|
leave ->
|
|
|
|
io_lib:format("<font class=\"ml\">~s ~s</font><br/>",
|
|
|
|
[Nick, ?T(<<"leaves the room">>)]);
|
|
|
|
{leave, Reason} ->
|
|
|
|
io_lib:format("<font class=\"ml\">~s ~s: ~s</font><br/>",
|
|
|
|
[Nick, ?T(<<"leaves the room">>),
|
|
|
|
htmlize(Reason, NoFollow, FileFormat)]);
|
|
|
|
{kickban, <<"301">>, <<"">>} ->
|
|
|
|
io_lib:format("<font class=\"mb\">~s ~s</font><br/>",
|
|
|
|
[Nick, ?T(<<"has been banned">>)]);
|
|
|
|
{kickban, <<"301">>, Reason} ->
|
|
|
|
io_lib:format("<font class=\"mb\">~s ~s: ~s</font><br/>",
|
|
|
|
[Nick, ?T(<<"has been banned">>),
|
|
|
|
htmlize(Reason, FileFormat)]);
|
|
|
|
{kickban, <<"307">>, <<"">>} ->
|
|
|
|
io_lib:format("<font class=\"mk\">~s ~s</font><br/>",
|
|
|
|
[Nick, ?T(<<"has been kicked">>)]);
|
|
|
|
{kickban, <<"307">>, Reason} ->
|
|
|
|
io_lib:format("<font class=\"mk\">~s ~s: ~s</font><br/>",
|
|
|
|
[Nick, ?T(<<"has been kicked">>),
|
|
|
|
htmlize(Reason, FileFormat)]);
|
|
|
|
{kickban, <<"321">>, <<"">>} ->
|
|
|
|
io_lib:format("<font class=\"mk\">~s ~s</font><br/>",
|
|
|
|
[Nick,
|
|
|
|
?T(<<"has been kicked because of an affiliation "
|
|
|
|
"change">>)]);
|
|
|
|
{kickban, <<"322">>, <<"">>} ->
|
|
|
|
io_lib:format("<font class=\"mk\">~s ~s</font><br/>",
|
|
|
|
[Nick,
|
|
|
|
?T(<<"has been kicked because the room has "
|
|
|
|
"been changed to members-only">>)]);
|
|
|
|
{kickban, <<"332">>, <<"">>} ->
|
|
|
|
io_lib:format("<font class=\"mk\">~s ~s</font><br/>",
|
|
|
|
[Nick,
|
|
|
|
?T(<<"has been kicked because of a system "
|
|
|
|
"shutdown">>)]);
|
|
|
|
{nickchange, OldNick} ->
|
|
|
|
io_lib:format("<font class=\"mnc\">~s ~s ~s</font><br/>",
|
|
|
|
[htmlize(OldNick, FileFormat),
|
|
|
|
?T(<<"is now known as">>), Nick]);
|
|
|
|
{subject, T} ->
|
|
|
|
io_lib:format("<font class=\"msc\">~s~s~s</font><br/>",
|
|
|
|
[Nick, ?T(<<" has set the subject to: ">>),
|
|
|
|
htmlize(T, NoFollow, FileFormat)]);
|
|
|
|
{body, T} ->
|
|
|
|
case {ejabberd_regexp:run(T, <<"^/me ">>), Nick} of
|
|
|
|
{_, <<"">>} ->
|
|
|
|
io_lib:format("<font class=\"msm\">~s</font><br/>",
|
|
|
|
[htmlize(T, NoFollow, FileFormat)]);
|
|
|
|
{match, _} ->
|
|
|
|
io_lib:format("<font class=\"mne\">~s ~s</font><br/>",
|
|
|
|
[Nick,
|
|
|
|
str:substr(htmlize(T, FileFormat), 5)]);
|
|
|
|
{nomatch, _} ->
|
|
|
|
io_lib:format("<font class=\"mn\">~s</font> ~s<br/>",
|
|
|
|
[Nick2, htmlize(T, NoFollow, FileFormat)])
|
|
|
|
end;
|
|
|
|
{room_existence, RoomNewExistence} ->
|
|
|
|
io_lib:format("<font class=\"mrcm\">~s</font><br/>",
|
|
|
|
[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,
|
2013-03-14 10:33:02 +01:00
|
|
|
STimeUnique = io_lib:format("~s.~w",
|
|
|
|
[STime, Microsecs]),
|
2013-05-30 14:28:39 +02:00
|
|
|
catch fw(F,
|
2013-03-14 10:33:02 +01:00
|
|
|
list_to_binary(
|
|
|
|
io_lib:format("<a id=\"~s\" name=\"~s\" href=\"#~s\" "
|
|
|
|
"class=\"ts\">[~s]</a> ",
|
|
|
|
[STimeUnique, STimeUnique, STimeUnique, STime])
|
|
|
|
++ Text),
|
|
|
|
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) ->
|
|
|
|
?T(<<"Chatroom is created">>);
|
|
|
|
get_room_existence_string(destroyed, Lang) ->
|
|
|
|
?T(<<"Chatroom is destroyed">>);
|
|
|
|
get_room_existence_string(started, Lang) ->
|
|
|
|
?T(<<"Chatroom is started">>);
|
|
|
|
get_room_existence_string(stopped, 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
|
2013-03-14 10:33:02 +01:00
|
|
|
1 -> ?T(<<"Monday">>);
|
|
|
|
2 -> ?T(<<"Tuesday">>);
|
|
|
|
3 -> ?T(<<"Wednesday">>);
|
|
|
|
4 -> ?T(<<"Thursday">>);
|
|
|
|
5 -> ?T(<<"Friday">>);
|
|
|
|
6 -> ?T(<<"Saturday">>);
|
|
|
|
7 -> ?T(<<"Sunday">>)
|
2006-03-14 05:26:15 +01:00
|
|
|
end,
|
|
|
|
{Y, M, D} = Date,
|
|
|
|
Month = case M of
|
2013-03-14 10:33:02 +01:00
|
|
|
1 -> ?T(<<"January">>);
|
|
|
|
2 -> ?T(<<"February">>);
|
|
|
|
3 -> ?T(<<"March">>);
|
|
|
|
4 -> ?T(<<"April">>);
|
|
|
|
5 -> ?T(<<"May">>);
|
|
|
|
6 -> ?T(<<"June">>);
|
|
|
|
7 -> ?T(<<"July">>);
|
|
|
|
8 -> ?T(<<"August">>);
|
|
|
|
9 -> ?T(<<"September">>);
|
|
|
|
10 -> ?T(<<"October">>);
|
|
|
|
11 -> ?T(<<"November">>);
|
|
|
|
12 -> ?T(<<"December">>)
|
2006-03-14 05:26:15 +01:00
|
|
|
end,
|
2013-03-14 10:33:02 +01:00
|
|
|
list_to_binary(
|
|
|
|
case Lang of
|
|
|
|
<<"en">> ->
|
|
|
|
io_lib:format("~s, ~s ~w, ~w", [Weekday, Month, D, Y]);
|
|
|
|
<<"es">> ->
|
|
|
|
io_lib:format("~s ~w de ~s de ~w",
|
|
|
|
[Weekday, D, Month, Y]);
|
|
|
|
_ ->
|
|
|
|
io_lib:format("~s, ~w ~s ~w", [Weekday, D, Month, Y])
|
|
|
|
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").
|
|
|
|
%% jlib:encode_base64(F1b).
|
2006-09-10 01:33:00 +02:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
image_base64(<<"powered-by-erlang.png">>) ->
|
|
|
|
<<"iVBORw0KGgoAAAANSUhEUgAAAGUAAAAfCAYAAAD+xQNoA"
|
|
|
|
"AADN0lEQVRo3u1aP0waURz+rjGRRQ+nUyRCYmJyDPTapD"
|
|
|
|
"ARaSIbTUjt1gVSh8ZW69aBAR0cWLSxCXWp59LR1jbdqKn"
|
|
|
|
"GxoQuRZZrSYyHEVM6iZMbHewROA7u3fHvkr5vOn737vcu"
|
|
|
|
"33ffu9/vcQz+gef5Cij6CkmSGABgFEH29r5SVvqIsTEOH"
|
|
|
|
"o8HkiQxDBXEOjg9PcHc3BxuUSqsI8jR0REAUFGsCCoKFY"
|
|
|
|
"WCBAN6AxyO0Z7cyMXFb6oGqSgAsIrJut9hMQlvdNbUhKW"
|
|
|
|
"shLd3HtTF4jihShgVpRaBxKKmIGX5HL920/hz/BM2+zAm"
|
|
|
|
"pn2YioQaxnECj0BiEYcrG0Tzzc8/rfudSm02jaVSm9Vr1"
|
|
|
|
"MdG8rSKKXlJ7lHrfjouCut2IrC82BDPbe/gc+xlXez7Kx"
|
|
|
|
"Ez63H4lmIN473Rh8Si1BKhRY6aEJI8pLmbjSPN0xOnBBI"
|
|
|
|
"Lmg5RC6Lg28preKOzsNmHG8R1Bf0o7GdMucUslDy1pJLG"
|
|
|
|
"2sndVVG0lq3c9vum4zmBR1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"
|
|
|
|
"ACEazEhGAgIAACEYzFra2utjELWcznGnEr/7+9jY2POaz"
|
|
|
|
"HOYzGta2NShLVrlL05OUqctdacCADGa2ucAADGpVqUtc6"
|
|
|
|
"1ORg5OTmlUikYGAiUezl7YzEYEAiUczkxMTG9nEqtIRDe"
|
|
|
|
"3t4AMXu9lEoQCACMazEAKXspKSmljFrW1ta1jELOzs7n7"
|
|
|
|
"/fGxsa9pVqEOSkpY5xznL29tZxahLXOpVr/99ZrY1L/79"
|
|
|
|
"ZjUiljSikAOYTvxmMAMYScezmchFqUczGtlFp7c2utjFq"
|
|
|
|
"UlJStxt73///39/9Ce61CSkq9xsZznMbW5+9Cc62MjIxC"
|
|
|
|
"Qkrv9/fv7/fOzsbnlErWjIz/3mtCORhza1IpIRBzWjH/1"
|
|
|
|
"mtCMRhzY1L/zmvnvVpSQiHOpVJrUinntVr3zmOEc1L3xm"
|
|
|
|
"NaWlq1nFo5QkrGWim1lFoISpRSUlK1zt4hWpwASoz////"
|
|
|
|
"///8xa6WUaykAQoxKe61KSkp7nMbWtWPe5+9jWlL39/f3"
|
|
|
|
"9/fWrWNCQkLera3nvWPv7+85MRjntWPetVp7c1IxKRCUl"
|
|
|
|
"HtKORh7a1IxIRCUjHtaSiHWrVIpIQhzWinvvVpaQiH/1m"
|
|
|
|
"PWpVKMe1L/zmP/xmNrUiGErc4YGBj/73PG1ucQWpT/53O"
|
|
|
|
"9nFoQUpS1SiEQEBC9zt69vb05c6UISoxSUko5a6UICAhS"
|
|
|
|
"SkohUpS1tbXetWMAQoSUgD+kAAAA2HRSTlP/////////i"
|
|
|
|
"P9sSf//dP////////////////////////////////////"
|
|
|
|
"////////////8M////////////ef/////////////////"
|
|
|
|
"/////////////////////////////////////////////"
|
|
|
|
"//////////////////////9d/////////////////////"
|
|
|
|
"///////////////AP//////////////CP//RP////////"
|
|
|
|
"/////////////////////////////////////////////"
|
|
|
|
"///////9xPp1gAAAFvUlEQVR42pVWi18URRwfy7vsYUba"
|
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z0FatG"
|
|
|
|
"JJYhvq4j7mGSpvytGFlZtHf2C4o/28Zu8z7wo7eYPfXys"
|
|
|
|
"nF0i9NnPh1t1zR7VBb9GqaOXhtTmHQdgMFXE+Z608cnpO"
|
|
|
|
"DdZdjL+TuDY44Q38kJXHhccWLoOd9uv1AwwvO+48uu+fa"
|
|
|
|
"CSJPJ1bmy6ThyvpivBmYWgjxPDPAp7JTemY/yGKFEiRt/"
|
|
|
|
"jG/2P79s8KCwoLCgoLC/khUBA5F0SfQZ+RYfpNE/4Xosm"
|
|
|
|
"q7jsZAJsAAAAASUVORK5CYII=">>;
|
|
|
|
image_base64(<<"vcss.png">>) ->
|
|
|
|
<<"iVBORw0KGgoAAAANSUhEUgAAAFgAAAAfCAMAAABUFvrSA"
|
|
|
|
"AABKVBMVEUAAAAjIx8MR51ZVUqAdlmdnZ3ejEWLDAuNjY"
|
|
|
|
"1kiMG0n2d9fX19Ghfrp1FtbW3y39+3Ph6lIRNdXV2qJBF"
|
|
|
|
"cVUhcVUhPT0/dsmpUfLr57+/u7u4/PDWZAACZAADOp1Gd"
|
|
|
|
"GxG+SyTgvnNdSySzk16+mkuxw+BOS0BOS0DOzs7MzMy4T"
|
|
|
|
"09RRDwsJBG+vr73wV6fkG6eCQRFcLSurq6/X1+ht9nXfz"
|
|
|
|
"5sepHuwV59ZTHetFjQ2+wMCQQ2ZK5tWCsmWajsz8+Sq9N"
|
|
|
|
"MPh4hVaY8MRj///////////////////////9MTEyOp9Lu"
|
|
|
|
"8vhXU1A8PDyjOSTBz+YLRJ2rLy8sLCwXTaKujEUcHByDn"
|
|
|
|
"82dfz7/zGafDw+fDw+zRSlzlMcMDAyNcji1tbXf5vIcFg"
|
|
|
|
"vATJOjAAAAY3RSTlP/8/////////////////8A//////P"
|
|
|
|
"/////ov//8//////////////z///T//////////+i////"
|
|
|
|
"//////////8w/////6IA/xAgMP//////////8////////"
|
|
|
|
"/8w0/////////+zehebAAACkUlEQVR42u2VfVPTQBDG19"
|
|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eidXn4TQcaxMYqP3RV3C8oCl2WvrlSPaN"
|
|
|
|
"pGZadRnmPGCk8ylM2okAJ4i9TEe1KersXxSl6jUt5uayi"
|
|
|
|
"IodirtcKLOaWblj50wiyMv1F9lm9TUDArGAD0FmEpvCUs"
|
|
|
|
"VoZy6dW81Fg0aDaHogQa36ekAPG5DDGsbdZrGsrzZUnzv"
|
|
|
|
"Bo1I2tLmuL69kSitAweyHKN9b3leDfQMnu3nIIKWfmXnq"
|
|
|
|
"GVKedJT6QpICbJvf2f8aOsvn68v+k7/cwUQdPoxaMoRTn"
|
|
|
|
"KFHNlKsKQphCTOa84u64vpi8bH31CqsbF6lSONRTkTyQG"
|
|
|
|
"Arq49/fEvjBwz4eDS2/JpaXRNOoXRD/VmOrDVTJJRIZCT"
|
|
|
|
"Lav3VrqbPvP3vdduGEhQJzilncbpSA4F3vsihErO+dayv"
|
|
|
|
"/sY5/yRE0GDEXCu2VoNiMlo5i+P2KlgMEvTNk2eYa5XEy"
|
|
|
|
"h12Ex17Z8vzQUR3KEPbYd6XG87eC4Ly75RneS5ZYHAAAA"
|
|
|
|
"AElFTkSuQmCC">>.
|
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">>],
|
|
|
|
lists:foreach(fun (Filename) ->
|
|
|
|
Filename_full = fjoin([Images_dir, Filename]),
|
|
|
|
{ok, F} = file:open(Filename_full, [write]),
|
|
|
|
Image = jlib:decode_base64(image_base64(Filename)),
|
|
|
|
io:format(F, <<"~s">>, [Image]),
|
|
|
|
file:close(F)
|
|
|
|
end,
|
|
|
|
Filenames),
|
2008-08-18 21:08:30 +02:00
|
|
|
ok.
|
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) ->
|
2016-11-24 13:06:06 +01:00
|
|
|
S1 = (str:format(binary_to_list(S) ++ "~n", O)),
|
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\" "
|
|
|
|
"xml:lang=\"~s\" lang=\"~s\">">>,
|
|
|
|
[Lang, Lang]),
|
|
|
|
fw(F, <<"<head>">>),
|
|
|
|
fw(F,
|
|
|
|
<<"<meta http-equiv=\"Content-Type\" content=\"t"
|
|
|
|
"ext/html; charset=utf-8\" />">>),
|
|
|
|
fw(F, <<"<title>~s - ~s</title>">>,
|
|
|
|
[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"
|
|
|
|
": bold;\" href=\"~s\">~s</a></div>">>,
|
|
|
|
[Top_url, Top_text]),
|
|
|
|
fw(F, <<"<div class=\"roomtitle\">~s</div>">>,
|
|
|
|
[htmlize(Room#room.title)]),
|
|
|
|
fw(F,
|
|
|
|
<<"<a class=\"roomjid\" href=\"xmpp:~s?join\">~s"
|
|
|
|
"</a>">>,
|
|
|
|
[Room#room.jid, Room#room.jid]),
|
|
|
|
fw(F,
|
|
|
|
<<"<div class=\"logdate\">~s<span class=\"w3c\">"
|
|
|
|
"<a class=\"nav\" href=\"~s\"><</a> "
|
|
|
|
"<a class=\"nav\" href=\"./\">^</a> <a "
|
|
|
|
"class=\"nav\" href=\"~s\">></a></span></di"
|
|
|
|
"v>">>,
|
|
|
|
[Date, Date_prev, Date_next]),
|
|
|
|
case {htmlize(Room#room.subject_author),
|
|
|
|
htmlize(Room#room.subject)}
|
|
|
|
of
|
|
|
|
{<<"">>, <<"">>} -> ok;
|
|
|
|
{SuA, Su} ->
|
|
|
|
fw(F, <<"<div class=\"roomsubject\">~s~s~s</div>">>,
|
|
|
|
[SuA, ?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),
|
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,
|
2013-03-14 10:33:02 +01:00
|
|
|
fw(F, <<"<br/><a class=\"ts\">GMT~s</a><br/>">>,
|
|
|
|
[Time_offset_str]).
|
2006-03-14 05:26:15 +01:00
|
|
|
|
|
|
|
put_header_css(F, false) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
fw(F, <<"<style type=\"text/css\">">>),
|
|
|
|
fw(F, <<"<!--">>),
|
|
|
|
fw(F,
|
|
|
|
<<".ts {color: #AAAAAA; text-decoration: "
|
|
|
|
"none;}">>),
|
|
|
|
fw(F,
|
|
|
|
<<".mrcm {color: #009900; font-style: italic; "
|
|
|
|
"font-weight: bold;}">>),
|
|
|
|
fw(F,
|
|
|
|
<<".msc {color: #009900; font-style: italic; "
|
|
|
|
"font-weight: bold;}">>),
|
|
|
|
fw(F,
|
|
|
|
<<".msm {color: #000099; font-style: italic; "
|
|
|
|
"font-weight: bold;}">>),
|
|
|
|
fw(F, <<".mj {color: #009900; font-style: italic;}">>),
|
|
|
|
fw(F, <<".ml {color: #009900; font-style: italic;}">>),
|
|
|
|
fw(F, <<".mk {color: #009900; font-style: italic;}">>),
|
|
|
|
fw(F, <<".mb {color: #009900; font-style: italic;}">>),
|
|
|
|
fw(F, <<".mnc {color: #009900; font-style: italic;}">>),
|
|
|
|
fw(F, <<".mn {color: #0000AA;}">>),
|
|
|
|
fw(F, <<".mne {color: #AA0099;}">>),
|
|
|
|
fw(F,
|
|
|
|
<<"a.nav {color: #AAAAAA; font-family: "
|
|
|
|
"monospace; letter-spacing: 3px; text-decorati"
|
|
|
|
"on: none;}">>),
|
|
|
|
fw(F,
|
|
|
|
<<"div.roomtitle {border-bottom: #224466 "
|
|
|
|
"solid 3pt; margin-left: 20pt;}">>),
|
|
|
|
fw(F,
|
|
|
|
<<"div.roomtitle {color: #336699; font-size: "
|
|
|
|
"24px; font-weight: bold; font-family: "
|
|
|
|
"sans-serif; letter-spacing: 3px; text-decorat"
|
|
|
|
"ion: none;}">>),
|
|
|
|
fw(F,
|
|
|
|
<<"a.roomjid {color: #336699; font-size: "
|
|
|
|
"24px; font-weight: bold; font-family: "
|
|
|
|
"sans-serif; letter-spacing: 3px; margin-left: "
|
|
|
|
"20pt; text-decoration: none;}">>),
|
|
|
|
fw(F,
|
|
|
|
<<"div.logdate {color: #663399; font-size: "
|
|
|
|
"20px; font-weight: bold; font-family: "
|
|
|
|
"sans-serif; letter-spacing: 2px; border-botto"
|
|
|
|
"m: #224466 solid 1pt; margin-left:80pt; "
|
|
|
|
"margin-top:20px;}">>),
|
|
|
|
fw(F,
|
|
|
|
<<"div.roomsubject {color: #336699; font-size: "
|
|
|
|
"18px; font-family: sans-serif; margin-left: "
|
|
|
|
"80pt; margin-bottom: 10px;}">>),
|
|
|
|
fw(F,
|
|
|
|
<<"div.rc {color: #336699; font-size: 12px; "
|
|
|
|
"font-family: sans-serif; margin-left: "
|
|
|
|
"50%; text-align: right; background: "
|
|
|
|
"#f3f6f9; border-bottom: 1px solid #336699; "
|
|
|
|
"border-right: 4px solid #336699;}">>),
|
|
|
|
fw(F,
|
|
|
|
<<"div.rct {font-weight: bold; background: "
|
|
|
|
"#e3e6e9; padding-right: 10px;}">>),
|
|
|
|
fw(F, <<"div.rcos {padding-right: 10px;}">>),
|
|
|
|
fw(F, <<"div.rcoe {color: green;}">>),
|
|
|
|
fw(F, <<"div.rcod {color: red;}">>),
|
|
|
|
fw(F, <<"div.rcoe:after {content: \": v\";}">>),
|
|
|
|
fw(F, <<"div.rcod:after {content: \": x\";}">>),
|
|
|
|
fw(F, <<"div.rcot:after {}">>),
|
|
|
|
fw(F,
|
|
|
|
<<".legend {width: 100%; margin-top: 30px; "
|
|
|
|
"border-top: #224466 solid 1pt; padding: "
|
|
|
|
"10px 0px 10px 0px; text-align: left; "
|
|
|
|
"font-family: monospace; letter-spacing: "
|
|
|
|
"2px;}">>),
|
|
|
|
fw(F,
|
|
|
|
<<".w3c {position: absolute; right: 10px; "
|
|
|
|
"width: 60%; text-align: right; font-family: "
|
|
|
|
"monospace; letter-spacing: 1px;}">>),
|
|
|
|
fw(F, <<"//-->">>),
|
|
|
|
fw(F, <<"</style>">>);
|
2006-03-14 05:26:15 +01:00
|
|
|
put_header_css(F, CSSFile) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
fw(F,
|
|
|
|
<<"<link rel=\"stylesheet\" type=\"text/css\" "
|
|
|
|
"href=\"~s\" media=\"all\">">>,
|
|
|
|
[CSSFile]).
|
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\">">>),
|
|
|
|
fw(F, <<"function sh(e) // Show/Hide an element">>),
|
|
|
|
fw(F,
|
|
|
|
<<"{if(document.getElementById(e).style.display="
|
|
|
|
"='none')">>),
|
|
|
|
fw(F,
|
|
|
|
<<"{document.getElementById(e).style.display='bl"
|
|
|
|
"ock';}">>),
|
|
|
|
fw(F,
|
|
|
|
<<"else {document.getElementById(e).style.displa"
|
|
|
|
"y='none';}}">>),
|
|
|
|
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) ->
|
2015-12-07 16:08:57 +01:00
|
|
|
{_, Now2, _} = p1_time_compat:timestamp(),
|
2013-03-14 10:33:02 +01:00
|
|
|
fw(F, <<"<div class=\"rc\">">>),
|
|
|
|
fw(F,
|
|
|
|
<<"<div class=\"rct\" onclick=\"sh('a~p');return "
|
|
|
|
"false;\">~s</div>">>,
|
|
|
|
[Now2, ?T(<<"Room Configuration">>)]),
|
|
|
|
fw(F,
|
|
|
|
<<"<div class=\"rcos\" id=\"a~p\" style=\"displa"
|
|
|
|
"y: none;\" ><br/>~s</div>">>,
|
|
|
|
[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) ->
|
2015-12-07 16:08:57 +01:00
|
|
|
{_, Now2, _} = p1_time_compat: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 "
|
|
|
|
"false;\">~s</div>">>,
|
|
|
|
[Now2, ?T(<<"Room Occupants">>)]),
|
|
|
|
fw(F,
|
|
|
|
<<"<div class=\"rcos\" id=\"o~p\" style=\"displa"
|
|
|
|
"y: none;\" ><br/>~s</div>">>,
|
|
|
|
[Now2, RoomOccupants]),
|
|
|
|
fw(F, <<"</div>">>).
|
|
|
|
|
|
|
|
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
|
|
|
|
{value, {_, S}} -> S;
|
|
|
|
false -> <<"">>
|
|
|
|
end,
|
|
|
|
SubjectAuthor = case lists:keysearch(subject_author, 1,
|
|
|
|
Opts)
|
|
|
|
of
|
|
|
|
{value, {_, SA}} -> SA;
|
|
|
|
false -> <<"">>
|
|
|
|
end,
|
2015-11-24 16:44:13 +01:00
|
|
|
#room{jid = jid:to_string(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) ->
|
|
|
|
case get_roomconfig_text(Opt) of
|
|
|
|
undefined -> R;
|
|
|
|
OptT ->
|
|
|
|
OptText = (?T(OptT)),
|
|
|
|
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, ": \"",
|
2016-07-25 12:50:30 +02:00
|
|
|
(htmlize(?T(jlib:atom_to_binary(T)),
|
2013-03-14 10:33:02 +01:00
|
|
|
FileFormat))/binary,
|
|
|
|
"\"</div>">>;
|
|
|
|
_ -> <<"\"", T/binary, "\"">>
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
<<R/binary, R2/binary>>
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
<<"">>, Options2).
|
|
|
|
|
|
|
|
get_roomconfig_text(title) -> <<"Room title">>;
|
|
|
|
get_roomconfig_text(persistent) ->
|
|
|
|
<<"Make room persistent">>;
|
|
|
|
get_roomconfig_text(public) ->
|
|
|
|
<<"Make room public searchable">>;
|
|
|
|
get_roomconfig_text(public_list) ->
|
|
|
|
<<"Make participants list public">>;
|
|
|
|
get_roomconfig_text(password_protected) ->
|
|
|
|
<<"Make room password protected">>;
|
|
|
|
get_roomconfig_text(password) -> <<"Password">>;
|
|
|
|
get_roomconfig_text(anonymous) ->
|
|
|
|
<<"This room is not anonymous">>;
|
|
|
|
get_roomconfig_text(members_only) ->
|
|
|
|
<<"Make room members-only">>;
|
|
|
|
get_roomconfig_text(moderated) ->
|
|
|
|
<<"Make room moderated">>;
|
|
|
|
get_roomconfig_text(members_by_default) ->
|
|
|
|
<<"Default users as participants">>;
|
|
|
|
get_roomconfig_text(allow_change_subj) ->
|
|
|
|
<<"Allow users to change the subject">>;
|
|
|
|
get_roomconfig_text(allow_private_messages) ->
|
|
|
|
<<"Allow users to send private messages">>;
|
|
|
|
get_roomconfig_text(allow_private_messages_from_visitors) ->
|
|
|
|
<<"Allow visitors to send private messages to">>;
|
|
|
|
get_roomconfig_text(allow_query_users) ->
|
|
|
|
<<"Allow users to query other users">>;
|
|
|
|
get_roomconfig_text(allow_user_invites) ->
|
|
|
|
<<"Allow users to send invites">>;
|
|
|
|
get_roomconfig_text(logging) -> <<"Enable logging">>;
|
|
|
|
get_roomconfig_text(allow_visitor_nickchange) ->
|
|
|
|
<<"Allow visitors to change nickname">>;
|
|
|
|
get_roomconfig_text(allow_visitor_status) ->
|
|
|
|
<<"Allow visitors to send status text in "
|
|
|
|
"presence updates">>;
|
|
|
|
get_roomconfig_text(captcha_protected) ->
|
|
|
|
<<"Make room captcha protected">>;
|
|
|
|
get_roomconfig_text(description) ->
|
|
|
|
<<"Room description">>;
|
2010-07-02 15:19:54 +02:00
|
|
|
%% get_roomconfig_text(subject) -> "Subject";
|
|
|
|
%% get_roomconfig_text(subject_author) -> "Subject author";
|
2013-03-14 10:33:02 +01:00
|
|
|
get_roomconfig_text(max_users) ->
|
|
|
|
<<"Maximum Number of Occupants">>;
|
2006-03-14 05:26:15 +01:00
|
|
|
get_roomconfig_text(_) -> undefined.
|
|
|
|
|
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) ->
|
2015-11-24 16:44:13 +01:00
|
|
|
RoomJID = jid:from_string(RoomJIDString),
|
2009-07-21 20:33:56 +02:00
|
|
|
RoomName = RoomJID#jid.luser,
|
|
|
|
MucService = RoomJID#jid.lserver,
|
|
|
|
StateData = get_room_state(RoomName, MucService),
|
|
|
|
[{U#user.jid, U#user.nick, U#user.role}
|
2013-03-14 10:33:02 +01:00
|
|
|
|| {_, U} <- (?DICT):to_list(StateData#state.users)].
|
|
|
|
|
2016-07-25 12:50:30 +02:00
|
|
|
-spec get_room_state(binary(), binary()) -> mod_muc_room:state().
|
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} ->
|
2013-03-14 10:33:02 +01:00
|
|
|
get_room_state(RoomPid);
|
2017-01-13 10:03:39 +01:00
|
|
|
error ->
|
|
|
|
#state{}
|
2009-07-21 20:33:56 +02:00
|
|
|
end.
|
|
|
|
|
2016-07-25 12:50:30 +02:00
|
|
|
-spec get_room_state(pid()) -> mod_muc_room:state().
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2009-07-21 20:33:56 +02:00
|
|
|
get_room_state(RoomPid) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{ok, R} = gen_fsm:sync_send_all_state_event(RoomPid,
|
|
|
|
get_state),
|
2009-07-21 20:33:56 +02:00
|
|
|
R.
|
|
|
|
|
2015-10-07 00:06:58 +02:00
|
|
|
get_proc_name(Host) ->
|
|
|
|
gen_mod:get_module_proc(Host, ?PROCNAME).
|
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
|
|
|
|
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) ->
|
|
|
|
fun (A) when is_atom(A) -> A end;
|
|
|
|
mod_opt_type(cssfile) -> fun iolist_to_binary/1;
|
|
|
|
mod_opt_type(dirname) ->
|
|
|
|
fun (room_jid) -> room_jid;
|
|
|
|
(room_name) -> room_name
|
|
|
|
end;
|
|
|
|
mod_opt_type(dirtype) ->
|
|
|
|
fun (subdirs) -> subdirs;
|
|
|
|
(plain) -> plain
|
|
|
|
end;
|
|
|
|
mod_opt_type(file_format) ->
|
|
|
|
fun (html) -> html;
|
|
|
|
(plaintext) -> plaintext
|
|
|
|
end;
|
|
|
|
mod_opt_type(file_permissions) ->
|
|
|
|
fun (SubOpts) ->
|
|
|
|
F = fun ({mode, Mode}, {_M, G}) -> {Mode, G};
|
|
|
|
({group, Group}, {M, _G}) -> {M, Group}
|
|
|
|
end,
|
|
|
|
lists:foldl(F, {644, 33}, SubOpts)
|
|
|
|
end;
|
|
|
|
mod_opt_type(outdir) -> fun iolist_to_binary/1;
|
|
|
|
mod_opt_type(spam_prevention) ->
|
|
|
|
fun (B) when is_boolean(B) -> B end;
|
|
|
|
mod_opt_type(timezone) ->
|
|
|
|
fun (local) -> local;
|
|
|
|
(universal) -> universal
|
|
|
|
end;
|
|
|
|
mod_opt_type(top_link) ->
|
|
|
|
fun ([{S1, S2}]) ->
|
|
|
|
{iolist_to_binary(S1), iolist_to_binary(S2)}
|
|
|
|
end;
|
|
|
|
mod_opt_type(_) ->
|
|
|
|
[access_log, cssfile, dirname, dirtype, file_format,
|
|
|
|
file_permissions, outdir, spam_prevention, timezone,
|
|
|
|
top_link].
|
|
|
|
|
|
|
|
opt_type(language) -> fun iolist_to_binary/1;
|
|
|
|
opt_type(_) -> [language].
|