changeset 28:03e68185c2f5

block spam forums
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 02 Jul 2020 21:19:24 -0600
parents 22a701699b2a
children 667e51ca939b
files src/nabble/view/web/more/ForumStart.java src/nabble/view/web/more/ForumStart.jtp
diffstat 2 files changed, 34 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/nabble/view/web/more/ForumStart.java	Thu Jul 02 16:00:09 2020 -0600
+++ b/src/nabble/view/web/more/ForumStart.java	Thu Jul 02 21:19:24 2020 -0600
@@ -10,6 +10,7 @@
 import nabble.model.ModelHome;
 import nabble.model.Site;
 import nabble.model.User;
+import nabble.model.Init;
 import nabble.naml.compiler.Template;
 import nabble.naml.compiler.TemplatePrintWriter;
 import nabble.naml.namespaces.BasicNamespace;
@@ -34,9 +35,12 @@
 import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 public final class ForumStart extends HttpServlet implements UrlMappable, CanonicalUrl {
+	private static final Logger logger = LoggerFactory.getLogger(ForumStart.class);
 
 	private static final Pattern URL_PATTERN = Pattern.compile("/free-(forum|gallery|newspaper|blog|mailing-list)\\.html$");
 
@@ -181,11 +185,18 @@
 
 	}
 
+
+	private static final Pattern spammers;
+	static {
+		String s = (String)Init.get("spammers");
+		spammers = s==null ? null : Pattern.compile(s);
+	}
+
 	public static class Save extends HttpServlet {
 
 		private static String get(String name, HttpServletRequest request) {
 			String s = request.getParameter(name);
-			return s == null? null : s.trim();
+			return s == null ? null : s.trim();
 		}
 
 		protected void service(HttpServletRequest request, HttpServletResponse response)
@@ -228,6 +239,11 @@
 			}
 
 			if (errors.isEmpty()) {
+				if( spammers != null && spammers.matcher(email).find() ) {
+					logger.info("ignoring spammer "+email);
+					return;
+				}
+
 				DbDatabase db = Db.dbGlobal();
 				db.beginTransaction();
 				try {
--- a/src/nabble/view/web/more/ForumStart.jtp	Thu Jul 02 16:00:09 2020 -0600
+++ b/src/nabble/view/web/more/ForumStart.jtp	Thu Jul 02 21:19:24 2020 -0600
@@ -10,6 +10,7 @@
 import nabble.model.ModelHome;
 import nabble.model.Site;
 import nabble.model.User;
+import nabble.model.Init;
 import nabble.naml.compiler.Template;
 import nabble.naml.compiler.TemplatePrintWriter;
 import nabble.naml.namespaces.BasicNamespace;
@@ -34,9 +35,12 @@
 import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 public final class ForumStart extends HttpServlet implements UrlMappable, CanonicalUrl {
+	private static final Logger logger = LoggerFactory.getLogger(ForumStart.class);
 
 	private static final Pattern URL_PATTERN = Pattern.compile("/free-(forum|gallery|newspaper|blog|mailing-list)\\.html$");
 
@@ -238,11 +242,18 @@
 		<%
 	}
 
+
+	private static final Pattern spammers;
+	static {
+		String s = (String)Init.get("spammers");
+		spammers = s==null ? null : Pattern.compile(s);
+	}
+
 	public static class Save extends HttpServlet {
 
 		private static String get(String name, HttpServletRequest request) {
 			String s = request.getParameter(name);
-			return s == null? null : s.trim();
+			return s == null ? null : s.trim();
 		}
 
 		protected void service(HttpServletRequest request, HttpServletResponse response)
@@ -285,6 +296,11 @@
 			}
 
 			if (errors.isEmpty()) {
+				if( spammers != null && spammers.matcher(email).find() ) {
+					logger.info("ignoring spammer "+email);
+					return;
+				}
+
 				DbDatabase db = Db.dbGlobal();
 				db.beginTransaction();
 				try {