1 18 package org.apache.roller.util; 19 20 import java.util.ArrayList ; 21 import java.util.List ; 22 import java.util.StringTokenizer ; 23 import java.util.regex.Pattern ; 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 import org.apache.roller.config.RollerConfig; 27 import org.apache.roller.config.RollerRuntimeConfig; 28 import org.apache.roller.pojos.CommentData; 29 import org.apache.roller.pojos.RefererData; 30 import org.apache.roller.pojos.WebsiteData; 31 32 37 public class SpamChecker { 38 private static Log mLogger = LogFactory.getLog(SpamChecker.class); 39 40 41 public static boolean checkComment(CommentData comment) { 42 if (RollerConfig.getBooleanProperty("site.blacklist.enable.comments")) { 43 return testComment(comment); 44 } 45 return false; 46 } 47 48 49 public static boolean checkTrackback(CommentData comment) { 50 if (RollerConfig.getBooleanProperty("site.blacklist.enable.trackbacks")) { 51 return testComment(comment); 52 } 53 return false; 54 } 55 56 57 public static boolean checkReferrer(WebsiteData website, String referrerURL) { 58 if (RollerConfig.getBooleanProperty("site.blacklist.enable.referrers")) { 59 List stringRules = new ArrayList (); 60 List regexRules = new ArrayList (); 61 Blacklist.populateSpamRules( 62 website.getBlacklist(), stringRules, regexRules, null); 63 if (RollerRuntimeConfig.getProperty("spam.blacklist") != null) { 64 Blacklist.populateSpamRules( 65 RollerRuntimeConfig.getProperty("spam.blacklist"), stringRules, regexRules, null); 66 } 67 return Blacklist.matchesRulesOnly(referrerURL, stringRules, regexRules); 68 } 69 return false; 70 } 71 72 73 private static boolean testComment(CommentData c) { 74 boolean ret = false; 75 List stringRules = new ArrayList (); 76 List regexRules = new ArrayList (); 77 WebsiteData website = c.getWeblogEntry().getWebsite(); 78 Blacklist.populateSpamRules( 79 website.getBlacklist(), stringRules, regexRules, 80 RollerRuntimeConfig.getProperty("spam.blacklist")); 81 Blacklist blacklist = Blacklist.getBlacklist(); 82 if ( blacklist.isBlacklisted(c.getUrl(), stringRules, regexRules) 83 || blacklist.isBlacklisted(c.getEmail(), stringRules, regexRules) 84 || blacklist.isBlacklisted(c.getName(), stringRules, regexRules) 85 || blacklist.isBlacklisted(c.getContent(), stringRules, regexRules)) { 86 ret = true; 87 } 88 return ret; 89 } 90 } 91 92 | Popular Tags |