25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

* src/mod_muc/mod_muc_log.erl: Spam prevention: The default behaviour

is now to use the nofollow rel attributes for links that are submitted
by users (EJAB-185).
* doc/guide.tex: Likewise.

SVN Revision: 728
This commit is contained in:
Mickaël Rémond 2007-02-19 10:49:23 +00:00
parent 909cfd7b21
commit 5882e29fb6
3 changed files with 37 additions and 7 deletions

View File

@ -1,5 +1,10 @@
2007-02-19 Mickael Remond <mickael.remond@process-one.net> 2007-02-19 Mickael Remond <mickael.remond@process-one.net>
* src/mod_muc/mod_muc_log.erl: Spam prevention: The default behaviour
is now to use the nofollow rel attributes for links that are submitted
by users (EJAB-185).
* doc/guide.tex: Likewise.
* src/mod_muc/mod_muc_room.erl: API improvement: Implementation of an * src/mod_muc/mod_muc_room.erl: API improvement: Implementation of an
event to destroy MUC room from an external application (Thanks to event to destroy MUC room from an external application (Thanks to
Massimiliano Mirra) (EJAB-184). Massimiliano Mirra) (EJAB-184).

View File

@ -2023,6 +2023,11 @@ Options:
are \term{local} and \term{universal}. With the first value, the local time, are \term{local} and \term{universal}. With the first value, the local time,
as reported to Erlang by the operating system, will be used. With the latter, as reported to Erlang by the operating system, will be used. With the latter,
GMT/UTC time will be used. The default value is \term{local}. GMT/UTC time will be used. The default value is \term{local}.
\titem{spam\_prevention}\ind{options!spam\_prevention}
To prevent spam, the \term{spam_prevention} option adds a special attribute
to links that prevent their indexation by search engines. The default value
is \term{true}, which mean that nofollow attributes will be added to user
submitted links.
\titem{top\_link}\ind{options!top\_link} \titem{top\_link}\ind{options!top\_link}
With this option you can customize the link on the top right corner of each With this option you can customize the link on the top right corner of each
log file. The syntax of this option is \term{\{"URL", "Text"\}}. The default log file. The syntax of this option is \term{\{"URL", "Text"\}}. The default
@ -2049,6 +2054,7 @@ Examples:
{dirtype, plain}, {dirtype, plain},
{outdir, "/var/www/muclogs"}, {outdir, "/var/www/muclogs"},
{timezone, universal}, {timezone, universal},
{spam_prevention, true},
{top_link, {"http://www.jabber.ru", "Jabber.ru"}} {top_link, {"http://www.jabber.ru", "Jabber.ru"}}
]}, ]},
... ...

View File

@ -38,6 +38,7 @@
access, access,
lang, lang,
timezone, timezone,
spam_prevention,
top_link}). top_link}).
%%==================================================================== %%====================================================================
@ -98,6 +99,7 @@ init([Host, Opts]) ->
AccessLog = gen_mod:get_opt(access_log, Opts, muc_admin), AccessLog = gen_mod:get_opt(access_log, Opts, muc_admin),
Timezone = gen_mod:get_opt(timezone, Opts, local), Timezone = gen_mod:get_opt(timezone, Opts, local),
Top_link = gen_mod:get_opt(top_link, Opts, {"/", "Home"}), Top_link = gen_mod:get_opt(top_link, Opts, {"/", "Home"}),
NoFollow = gen_mod:get_opt(spam_prevention, Opts, true),
Lang = case ejabberd_config:get_local_option({language, Host}) of Lang = case ejabberd_config:get_local_option({language, Host}) of
undefined -> undefined ->
""; "";
@ -111,6 +113,7 @@ init([Host, Opts]) ->
access = AccessLog, access = AccessLog,
lang = Lang, lang = Lang,
timezone = Timezone, timezone = Timezone,
spam_prevention = NoFollow,
top_link = Top_link}}. top_link = Top_link}}.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@ -261,6 +264,7 @@ add_message_to_log(Nick1, Message, RoomJID, Opts, State) ->
css_file = CSSFile, css_file = CSSFile,
lang = Lang, lang = Lang,
timezone = Timezone, timezone = Timezone,
spam_prevention = NoFollow,
top_link = TopLink} = State, top_link = TopLink} = State,
Room = get_room_info(RoomJID, Opts), Room = get_room_info(RoomJID, Opts),
@ -319,7 +323,7 @@ add_message_to_log(Nick1, Message, RoomJID, Opts, State) ->
[Nick, ?T("leaves the room")]); [Nick, ?T("leaves the room")]);
{leave, Reason} -> {leave, Reason} ->
io_lib:format("<font class=\"ml\">~s ~s: ~s</font><br/>", io_lib:format("<font class=\"ml\">~s ~s: ~s</font><br/>",
[Nick, ?T("leaves the room"), htmlize(Reason)]); [Nick, ?T("leaves the room"), htmlize(Reason,NoFollow)]);
{kickban, "307", ""} -> {kickban, "307", ""} ->
io_lib:format("<font class=\"mk\">~s ~s</font><br/>", io_lib:format("<font class=\"mk\">~s ~s</font><br/>",
[Nick, ?T("has been kicked")]); [Nick, ?T("has been kicked")]);
@ -337,7 +341,7 @@ add_message_to_log(Nick1, Message, RoomJID, Opts, State) ->
[OldNick, ?T("is now known as"), Nick]); [OldNick, ?T("is now known as"), Nick]);
{subject, T} -> {subject, T} ->
io_lib:format("<font class=\"msc\">~s~s~s</font><br/>", io_lib:format("<font class=\"msc\">~s~s~s</font><br/>",
[Nick, ?T(" has set the subject to: "), htmlize(T)]); [Nick, ?T(" has set the subject to: "), htmlize(T,NoFollow)]);
{body, T} -> {body, T} ->
case regexp:first_match(T, "^/me\s") of case regexp:first_match(T, "^/me\s") of
{match, _, _} -> {match, _, _} ->
@ -345,7 +349,7 @@ add_message_to_log(Nick1, Message, RoomJID, Opts, State) ->
[Nick, string:substr(htmlize(T), 5)]); [Nick, string:substr(htmlize(T), 5)]);
nomatch -> nomatch ->
io_lib:format("<font class=\"mn\">&lt;~s&gt;</font> ~s<br/>", io_lib:format("<font class=\"mn\">&lt;~s&gt;</font> ~s<br/>",
[Nick, htmlize(T)]) [Nick, htmlize(T,NoFollow)])
end end
end, end,
{Hour, Minute, Second} = Time, {Hour, Minute, Second} = Time,
@ -640,11 +644,19 @@ put_room_config(F, RoomConfig, Lang) ->
fw(F, "<div class=\"rcos\" id=\"a~p\" style=\"display: none;\" ><br/>~s</div>", [Now2, RoomConfig]), fw(F, "<div class=\"rcos\" id=\"a~p\" style=\"display: none;\" ><br/>~s</div>", [Now2, RoomConfig]),
fw(F, "</div>"). fw(F, "</div>").
%% htmlize
%% The default behaviour is to ignore the nofollow spam prevention on links
%% (NoFollow=false)
htmlize(S1) -> htmlize(S1) ->
htmlize(S1, false).
%% The NoFollow parameter tell if the spam prevention should be applied to the link found
%% true means 'apply nofollow on links'.
htmlize(S1, NoFollow) ->
S2_list = string:tokens(S1, "\n"), S2_list = string:tokens(S1, "\n"),
lists:foldl( lists:foldl(
fun(Si, Res) -> fun(Si, Res) ->
Si2 = htmlize2(Si), Si2 = htmlize2(Si, NoFollow),
case Res of case Res of
"" -> Si2; "" -> Si2;
_ -> Res ++ "<br/>" ++ Si2 _ -> Res ++ "<br/>" ++ Si2
@ -653,14 +665,21 @@ htmlize(S1) ->
"", "",
S2_list). S2_list).
htmlize2(S1) -> htmlize2(S1, NoFollow) ->
S2 = element(2, regexp:gsub(S1, "\\&", "\\&amp;")), S2 = element(2, regexp:gsub(S1, "\\&", "\\&amp;")),
S3 = element(2, regexp:gsub(S2, "<", "\\&lt;")), S3 = element(2, regexp:gsub(S2, "<", "\\&lt;")),
S4 = element(2, regexp:gsub(S3, ">", "\\&gt;")), S4 = element(2, regexp:gsub(S3, ">", "\\&gt;")),
S5 = element(2, regexp:gsub(S4, "(http|ftp)://.[^ ]*", "<a href=\"&\">&</a>")), S5 = element(2, regexp:gsub(S4, "(http|ftp)://.[^ ]*", link_regexp(NoFollow))),
%% Remove 'right-to-left override' unicode character 0x202e %% Remove 'right-to-left override' unicode character 0x202e
element(2, regexp:gsub(S5, [226,128,174], "[RLO]")). element(2, regexp:gsub(S5, [226,128,174], "[RLO]")).
%% Regexp link
%% Add the nofollow rel attribute when required
link_regexp(false) ->
"<a href=\"&\">&</a>";
link_regexp(true) ->
"<a href=\"&\" rel=\"nofollow\">&</a>".
get_room_info(RoomJID, Opts) -> get_room_info(RoomJID, Opts) ->
Title = Title =
case lists:keysearch(title, 1, Opts) of case lists:keysearch(title, 1, Opts) of