1 package net.jforum.util.legacy.clickstream; 2 3 import java.util.Iterator ; 4 import java.util.List ; 5 6 import javax.servlet.http.HttpServletRequest ; 7 8 import net.jforum.util.legacy.clickstream.config.ClickstreamConfig; 9 import net.jforum.util.legacy.clickstream.config.ConfigLoader; 10 11 18 public class BotChecker 19 { 20 26 public static String isBot(HttpServletRequest request) 27 { 28 if (request.getRequestURI().indexOf("robots.txt") != -1) { 29 return "Unknown (asked for robots.txt)"; 32 } 33 34 String userAgent = request.getHeader("User-Agent"); 35 36 ClickstreamConfig config = ConfigLoader.instance().getConfig(); 37 38 if (userAgent != null && config != null) { 39 List agents = config.getBotAgents(); 40 41 userAgent = userAgent.toLowerCase(); 42 43 for (Iterator iterator = agents.iterator(); iterator.hasNext(); ) { 44 String agent = (String ) iterator.next(); 45 46 if (agent == null) { 47 continue; 48 } 49 50 if (userAgent.indexOf(agent) != -1) { 51 return userAgent; 52 } 53 } 54 } 55 56 String remoteHost = request.getRemoteHost(); 58 if (remoteHost != null && remoteHost.length() > 0 && remoteHost.charAt(remoteHost.length() - 1) > 64) { 59 List hosts = config.getBotHosts(); 60 61 remoteHost = remoteHost.toLowerCase(); 62 63 for (Iterator iterator = hosts.iterator(); iterator.hasNext(); ) { 64 String host = (String ) iterator.next(); 65 66 if (host == null) { 67 continue; 68 } 69 70 if (remoteHost.indexOf(host) != -1) { 71 return remoteHost; 72 } 73 } 74 } 75 76 return null; 77 } 78 } | Popular Tags |