From 5882e29fb63767c9173844332ae1e32ca4069ec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20R=C3=A9mond?= Date: Mon, 19 Feb 2007 10:49:23 +0000 Subject: [PATCH] * 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 --- ChangeLog | 7 ++++++- doc/guide.tex | 6 ++++++ src/mod_muc/mod_muc_log.erl | 31 +++++++++++++++++++++++++------ 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index af6dfba54..f20945a2b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,13 @@ 2007-02-19 Mickael Remond + * 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 event to destroy MUC room from an external application (Thanks to - Massimiliano Mirra) (EJAB-184). + Massimiliano Mirra) (EJAB-184). 2007-02-18 Alexey Shchepin diff --git a/doc/guide.tex b/doc/guide.tex index 59774c107..01b89ea93 100644 --- a/doc/guide.tex +++ b/doc/guide.tex @@ -2023,6 +2023,11 @@ Options: 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, 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} 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 @@ -2049,6 +2054,7 @@ Examples: {dirtype, plain}, {outdir, "/var/www/muclogs"}, {timezone, universal}, + {spam_prevention, true}, {top_link, {"http://www.jabber.ru", "Jabber.ru"}} ]}, ... diff --git a/src/mod_muc/mod_muc_log.erl b/src/mod_muc/mod_muc_log.erl index 58fce60be..4fcb2b712 100644 --- a/src/mod_muc/mod_muc_log.erl +++ b/src/mod_muc/mod_muc_log.erl @@ -38,6 +38,7 @@ access, lang, timezone, + spam_prevention, top_link}). %%==================================================================== @@ -98,6 +99,7 @@ init([Host, Opts]) -> AccessLog = gen_mod:get_opt(access_log, Opts, muc_admin), Timezone = gen_mod:get_opt(timezone, Opts, local), 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 undefined -> ""; @@ -111,6 +113,7 @@ init([Host, Opts]) -> access = AccessLog, lang = Lang, timezone = Timezone, + spam_prevention = NoFollow, top_link = Top_link}}. %%-------------------------------------------------------------------- @@ -261,6 +264,7 @@ add_message_to_log(Nick1, Message, RoomJID, Opts, State) -> css_file = CSSFile, lang = Lang, timezone = Timezone, + spam_prevention = NoFollow, top_link = TopLink} = State, Room = get_room_info(RoomJID, Opts), @@ -319,7 +323,7 @@ add_message_to_log(Nick1, Message, RoomJID, Opts, State) -> [Nick, ?T("leaves the room")]); {leave, Reason} -> io_lib:format("~s ~s: ~s
", - [Nick, ?T("leaves the room"), htmlize(Reason)]); + [Nick, ?T("leaves the room"), htmlize(Reason,NoFollow)]); {kickban, "307", ""} -> io_lib:format("~s ~s
", [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]); {subject, T} -> io_lib:format("~s~s~s
", - [Nick, ?T(" has set the subject to: "), htmlize(T)]); + [Nick, ?T(" has set the subject to: "), htmlize(T,NoFollow)]); {body, T} -> case regexp:first_match(T, "^/me\s") of {match, _, _} -> @@ -345,7 +349,7 @@ add_message_to_log(Nick1, Message, RoomJID, Opts, State) -> [Nick, string:substr(htmlize(T), 5)]); nomatch -> io_lib:format("<~s> ~s
", - [Nick, htmlize(T)]) + [Nick, htmlize(T,NoFollow)]) end end, {Hour, Minute, Second} = Time, @@ -640,11 +644,19 @@ put_room_config(F, RoomConfig, Lang) -> fw(F, "

~s
", [Now2, RoomConfig]), fw(F, ""). +%% htmlize +%% The default behaviour is to ignore the nofollow spam prevention on links +%% (NoFollow=false) 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"), lists:foldl( fun(Si, Res) -> - Si2 = htmlize2(Si), + Si2 = htmlize2(Si, NoFollow), case Res of "" -> Si2; _ -> Res ++ "
" ++ Si2 @@ -653,14 +665,21 @@ htmlize(S1) -> "", S2_list). -htmlize2(S1) -> +htmlize2(S1, NoFollow) -> S2 = element(2, regexp:gsub(S1, "\\&", "\\&")), S3 = element(2, regexp:gsub(S2, "<", "\\<")), S4 = element(2, regexp:gsub(S3, ">", "\\>")), - S5 = element(2, regexp:gsub(S4, "(http|ftp)://.[^ ]*", "&")), + S5 = element(2, regexp:gsub(S4, "(http|ftp)://.[^ ]*", link_regexp(NoFollow))), %% Remove 'right-to-left override' unicode character 0x202e element(2, regexp:gsub(S5, [226,128,174], "[RLO]")). +%% Regexp link +%% Add the nofollow rel attribute when required +link_regexp(false) -> + "&"; +link_regexp(true) -> + "&". + get_room_info(RoomJID, Opts) -> Title = case lists:keysearch(title, 1, Opts) of