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;
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;
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;
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();
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();
StringBuffer line = new StringBuffer();
- line.append(DateTimeFunctions.advancedDateFormat(
+ line.append(DateTimeRoutines.advancedDateFormat(
configuration.getString("Mir.DefaultDateTimeFormat"),
(new GregorianCalendar()).getTime(), configuration.getString("Mir.DefaultTimezone")));
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();
StringBuffer line = new StringBuffer();
- line.append(DateTimeFunctions.advancedDateFormat(
+ line.append(DateTimeRoutines.advancedDateFormat(
configuration.getString("Mir.DefaultDateTimeFormat"),
(new GregorianCalendar()).getTime(), configuration.getString("Mir.DefaultTimezone")));
}
public List getLog() {
+ ModuleContent contentModule = new ModuleContent();
+ ModuleComment commentModule = new ModuleComment();
+
synchronized (log) {
try {
List result = new ArrayList();
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());
}
}
}
- };
+ }
private void appendLog(LogEntry anEntry) {
synchronized (log) {