1 31 package org.blojsom.plugin.moderation; 32 33 import org.apache.commons.logging.Log; 34 import org.apache.commons.logging.LogFactory; 35 import org.blojsom.blog.Blog; 36 import org.blojsom.blog.Entry; 37 import org.blojsom.event.Event; 38 import org.blojsom.event.EventBroadcaster; 39 import org.blojsom.event.Listener; 40 import org.blojsom.plugin.Plugin; 41 import org.blojsom.plugin.PluginException; 42 import org.blojsom.plugin.comment.CommentModerationPlugin; 43 import org.blojsom.plugin.comment.CommentPlugin; 44 import org.blojsom.plugin.comment.event.CommentResponseSubmissionEvent; 45 import org.blojsom.plugin.pingback.PingbackPlugin; 46 import org.blojsom.plugin.pingback.event.PingbackResponseSubmissionEvent; 47 import org.blojsom.plugin.response.event.ResponseSubmissionEvent; 48 import org.blojsom.plugin.trackback.TrackbackModerationPlugin; 49 import org.blojsom.plugin.trackback.TrackbackPlugin; 50 import org.blojsom.plugin.trackback.event.TrackbackResponseSubmissionEvent; 51 52 import javax.servlet.http.HttpServletRequest ; 53 import javax.servlet.http.HttpServletResponse ; 54 import java.net.InetAddress ; 55 import java.net.UnknownHostException ; 56 import java.util.Map ; 57 58 70 public class OpenProxyModerationPlugin implements Plugin, Listener { 71 72 private Log _logger = LogFactory.getLog(OpenProxyModerationPlugin.class); 73 74 private static final String DELETE_OPENPROXY_SPAM_IP = "delete-openproxy-spam"; 75 76 private EventBroadcaster _eventBroadcaster; 77 78 81 public OpenProxyModerationPlugin() { 82 } 83 84 89 public void setEventBroadcaster(EventBroadcaster eventBroadcaster) { 90 _eventBroadcaster = eventBroadcaster; 91 } 92 93 99 public void init() throws PluginException { 100 _eventBroadcaster.addListener(this); 101 } 102 103 114 public Entry[] process(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Blog blog, Map context, Entry[] entries) throws PluginException { 115 return entries; 116 } 117 118 123 public void handleEvent(Event event) { 124 } 125 126 131 public void processEvent(Event event) { 132 if (event instanceof ResponseSubmissionEvent) { 133 ResponseSubmissionEvent responseSubmissionEvent = (ResponseSubmissionEvent) event; 134 135 String remoteIP = responseSubmissionEvent.getHttpServletRequest().getRemoteAddr(); 136 String [] ipAddress = remoteIP.split("\\."); 137 StringBuffer reversedAddress = new StringBuffer (); 138 reversedAddress.append(ipAddress[3]).append(".").append(ipAddress[2]).append(".").append(ipAddress[1]).append(".").append(ipAddress[0]); 139 140 try { 141 InetAddress inetAddress = InetAddress.getByName(reversedAddress + ".list.dsbl.org"); 142 Map metaData = responseSubmissionEvent.getMetaData(); 143 144 String deleteOpenProxySpamPropertyValue = responseSubmissionEvent.getBlog().getProperty(DELETE_OPENPROXY_SPAM_IP); 145 boolean deleteOpenProxySpam = Boolean.valueOf(deleteOpenProxySpamPropertyValue).booleanValue(); 146 147 if (responseSubmissionEvent instanceof CommentResponseSubmissionEvent) { 148 if (!deleteOpenProxySpam) { 149 metaData.put(CommentModerationPlugin.BLOJSOM_COMMENT_MODERATION_PLUGIN_APPROVED, Boolean.FALSE.toString()); 150 } else { 151 metaData.put(CommentPlugin.BLOJSOM_PLUGIN_COMMENT_METADATA_DESTROY, Boolean.TRUE); 152 } 153 } else if (responseSubmissionEvent instanceof TrackbackResponseSubmissionEvent) { 154 if (!deleteOpenProxySpam) { 155 metaData.put(TrackbackModerationPlugin.BLOJSOM_TRACKBACK_MODERATION_PLUGIN_APPROVED, Boolean.FALSE.toString()); 156 } else { 157 metaData.put(TrackbackPlugin.BLOJSOM_PLUGIN_TRACKBACK_METADATA_DESTROY, Boolean.TRUE); 158 } 159 } else if (responseSubmissionEvent instanceof PingbackResponseSubmissionEvent) { 160 if (deleteOpenProxySpam) { 161 metaData.put(PingbackPlugin.BLOJSOM_PLUGIN_PINGBACK_METADATA_DESTROY, Boolean.TRUE); 162 } 163 } 164 165 if (_logger.isDebugEnabled()) { 166 _logger.debug("Failed open proxy check for response submission for IP: " + inetAddress.getHostAddress() + "/" + inetAddress.getHostName()); 167 } 168 } catch (UnknownHostException e) { 169 } 171 } 172 } 173 174 180 public void cleanup() throws PluginException { 181 } 182 183 189 public void destroy() throws PluginException { 190 } 191 } | Popular Tags |