X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmircoders%2Fglobal%2FAbuse.java;h=dd54988483aa06ee56faedbd644e13ce141a33d8;hb=88455349028d7ecd46fe04ff8662b584c54c6143;hp=02a111c94368cdeb38f31de0c1ece7fda74812c1;hpb=213122e7c65211f549722f05aa8e0135f15af35c;p=mir.git diff --git a/source/mircoders/global/Abuse.java b/source/mircoders/global/Abuse.java index 02a111c9..dd549884 100755 --- a/source/mircoders/global/Abuse.java +++ b/source/mircoders/global/Abuse.java @@ -35,7 +35,7 @@ import mir.entity.Entity; import mir.entity.adapter.EntityAdapterModel; import mir.log.LoggerWrapper; import mir.session.Request; -import mir.util.DateTimeFunctions; +import mir.util.DateTimeRoutines; import mir.util.EntityUtility; import mir.util.GeneratorFormatAdapters; import mir.util.StringRoutines; @@ -43,6 +43,8 @@ import mircoders.abuse.FilterEngine; import mircoders.entity.EntityComment; import mircoders.entity.EntityContent; import mircoders.localizer.MirAdminInterfaceLocalizer; +import mircoders.module.ModuleComment; +import mircoders.module.ModuleContent; import org.apache.commons.collections.ExtendedProperties; import javax.servlet.http.Cookie; @@ -51,9 +53,22 @@ import java.io.BufferedOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; -import java.util.*; - - +import java.util.ArrayList; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Random; + +/** + * This class manages abuse (spam, offending material, etc.). This + * is done by using a set of filters managed by the FilterEngine class. + * Filters may be of different types (IP, throttle, regexp...), + * but are created and configured in a single user interface (web page), + * and are stored in a single database table called "filter". + */ public class Abuse { private LoggerWrapper logger; private int logSize; @@ -71,10 +86,12 @@ public class Abuse { private static String cookieName = MirGlobal.config().getString("Abuse.CookieName"); private static int cookieMaxAge = 60 * 60 * MirGlobal.config().getInt("Abuse.CookieMaxAge"); + private EntityAdapterModel model; public Abuse(EntityAdapterModel aModel) { logger = new LoggerWrapper("Global.Abuse"); filterEngine = new FilterEngine(aModel); + model = aModel; log = new ArrayList(); @@ -127,7 +144,11 @@ public class Abuse { return false; } - + /** Checks if there is a filter that matches a comment and takes + * appropriate action (as configured in the xxxxxaction field of + * the filter table). The actual matching is delegated to the + * FilterEngine class. + */ public void checkComment(EntityComment aComment, Request aRequest, HttpServletResponse aResponse) { try { long time = System.currentTimeMillis(); @@ -140,7 +161,7 @@ public class Abuse { StringBuffer line = new StringBuffer(); - line.append(DateTimeFunctions.advancedDateFormat( + line.append(DateTimeRoutines.advancedDateFormat( configuration.getString("Mir.DefaultDateTimeFormat"), (new GregorianCalendar()).getTime(), configuration.getString("Mir.DefaultTimezone"))); @@ -163,7 +184,11 @@ public class Abuse { logger.error("Exception thrown while checking comment", t); } } - + /** Checks if there is a filter that matches an articleand takes + * appropriate action (as configured in the xxxxxaction field of + * the filter table). The actual matching is delegated to the + * FilterEngine class. + */ public void checkArticle(EntityContent anArticle, Request aRequest, HttpServletResponse aResponse) { try { long time = System.currentTimeMillis(); @@ -176,7 +201,7 @@ public class Abuse { StringBuffer line = new StringBuffer(); - line.append(DateTimeFunctions.advancedDateFormat( + line.append(DateTimeRoutines.advancedDateFormat( configuration.getString("Mir.DefaultDateTimeFormat"), (new GregorianCalendar()).getTime(), configuration.getString("Mir.DefaultTimezone"))); @@ -260,6 +285,9 @@ public class Abuse { } public List getLog() { + ModuleContent contentModule = new ModuleContent(); + ModuleComment commentModule = new ModuleComment(); + synchronized (log) { try { List result = new ArrayList(); @@ -272,10 +300,18 @@ public class Abuse { entry.put("ip", logEntry.getIpNumber()); entry.put("id", logEntry.getId()); entry.put("timestamp", new GeneratorFormatAdapters.DateFormatAdapter(logEntry.getTimeStamp(), MirPropertiesConfiguration.instance().getString("Mir.DefaultTimezone"))); - if (logEntry.getIsArticle()) + + if (logEntry.getIsArticle()) { entry.put("type", "content"); - else + entry.put("object", + model.makeEntityAdapter("content", contentModule.getById(logEntry.getId()))); + } + else { entry.put("type", "comment"); + entry.put("object", + model.makeEntityAdapter("comment", commentModule.getById(logEntry.getId()))); + } + entry.put("browser", logEntry.getBrowserString()); entry.put("filtertag", logEntry.getMatchingFilterTag()); @@ -485,7 +521,7 @@ public class Abuse { } } } - }; + } private void appendLog(LogEntry anEntry) { synchronized (log) {