?? contentfilterplugin.java
字號(hào):
/** * $RCSfile$ * $Revision: 1594 $ * $Date: 2005-07-04 18:08:42 +0100 (Mon, 04 Jul 2005) $ * * Copyright (C) 2004 Jive Software. All rights reserved. * * This software is published under the terms of the GNU Public License (GPL), * a copy of which is included in this distribution. */package org.jivesoftware.wildfire.plugin;import org.jivesoftware.util.EmailService;import org.jivesoftware.util.JiveGlobals;import org.jivesoftware.util.Log;import org.jivesoftware.wildfire.MessageRouter;import org.jivesoftware.wildfire.Session;import org.jivesoftware.wildfire.XMPPServer;import org.jivesoftware.wildfire.container.Plugin;import org.jivesoftware.wildfire.container.PluginManager;import org.jivesoftware.wildfire.interceptor.InterceptorManager;import org.jivesoftware.wildfire.interceptor.PacketInterceptor;import org.jivesoftware.wildfire.interceptor.PacketRejectedException;import org.jivesoftware.wildfire.user.User;import org.jivesoftware.wildfire.user.UserManager;import org.xmpp.packet.JID;import org.xmpp.packet.Message;import org.xmpp.packet.Packet;import org.xmpp.packet.Presence;import java.io.File;import java.util.regex.PatternSyntaxException;/** * Content filter plugin. * * @author Conor Hayes */public class ContentFilterPlugin implements Plugin, PacketInterceptor { /** * The expected value is a boolean, if true the user identified by the value * of the property #VIOLATION_NOTIFICATION_CONTACT_PROPERTY will be notified * every time there is a content match, otherwise no notification will be * sent. Then default value is false. */ public static final String VIOLATION_NOTIFICATION_ENABLED_PROPERTY = "plugin.contentFilter.violation.notification.enabled"; /** * The expected value is a user name. The default value is "admin". */ public static final String VIOLATION_NOTIFICATION_CONTACT_PROPERTY = "plugin.contentFilter.violation.notification.contact"; /** * The expected value is a boolean, if true the user identified by the value * of the property #VIOLATION_NOTIFICATION_CONTACT_PROPERTY, will also * receive a copy of the offending packet. The default value is false. */ public static final String VIOLATION_INCLUDE_ORIGNAL_PACKET_ENABLED_PROPERTY = "plugin.contentFilter.violation.notification.include.original.enabled"; /** * The expected value is a boolean, if true the user identified by the value * of the property #VIOLATION_NOTIFICATION_CONTACT_PROPERTY, will receive * notification by IM. The default value is true. */ public static final String VIOLATION_NOTIFICATION_BY_IM_ENABLED_PROPERTY = "plugin.contentFilter.violation.notification.by.im.enabled"; /** * The expected value is a boolean, if true the user identified by the value * of the property #VIOLATION_NOTIFICATION_CONTACT_PROPERTY, will receive * notification by email. The default value is false. */ public static final String VIOLATION_NOTIFICATION_BY_EMAIL_ENABLED_PROPERTY = "plugin.contentFilter.violation.notification.by.email.enabled"; /** * The expected value is a boolean, if true the sender will be notified when * a message is rejected, otherwise the message will be silently * rejected,i.e. the sender will not know that the message was rejected and * the receiver will not get the message. The default value is false. */ public static final String REJECTION_NOTIFICATION_ENABLED_PROPERTY = "plugin.contentFilter.rejection.notification.enabled"; /** * The expected value is a string, containing the desired message for the * sender notification. */ public static final String REJECTION_MSG_PROPERTY = "plugin.contentFilter.rejection.msg"; /** * The expected value is a boolean, if true the value of #PATTERNS_PROPERTY * will be used for pattern matching. */ public static final String PATTERNS_ENABLED_PROPERTY = "plugin.contentFilter.patterns.enabled"; /** * The expected value is a comma separated string of regular expressions. */ public static final String PATTERNS_PROPERTY = "plugin.contentFilter.patterns"; /** * The expected value is a boolean, if true Presence packets will be * filtered */ public static final String FILTER_STATUS_ENABLED_PROPERTY = "plugin.contentFilter.filter.status.enabled"; /** * The expected value is a boolean, if true the value of #MASK_PROPERTY will * be used to mask matching content. */ public static final String MASK_ENABLED_PROPERTY = "plugin.contentFilter.mask.enabled"; /** * The expected value is a string. If this property is set any matching * content will not be rejected but masked with the given value. Setting a * content mask means that property #SENDER_NOTIFICATION_ENABLED_PROPERTY is * ignored. The default value is "**". */ public static final String MASK_PROPERTY = "plugin.contentFilter.mask"; /** * The expected value is a boolean, if false packets whose contents matches one * of the supplied regular expressions will be rejected, otherwise the packet will * be accepted and may be optionally masked. The default value is false. * @see #MASK_ENABLED_PROPERTY */ public static final String ALLOW_ON_MATCH_PROPERTY = "plugin.contentFilter.allow.on.match"; /** * the hook into the inteceptor chain */ private InterceptorManager interceptorManager; /** * used to send violation notifications */ private MessageRouter messageRouter; /** * delegate that does the real work of this plugin */ private ContentFilter contentFilter; /** * flags if sender should be notified of rejections */ private boolean rejectionNotificationEnabled; /** * the rejection msg to send */ private String rejectionMessage; /** * flags if content matches should result in admin notification */ private boolean violationNotificationEnabled; /** * the admin user to send violation notifications to */ private String violationContact; /** * flags if original packet should be included in the message to the * violation contact. */ private boolean violationIncludeOriginalPacketEnabled; /** * flags if violation contact should be notified by IM. */ private boolean violationNotificationByIMEnabled; /** * flags if violation contact should be notified by email. */ private boolean violationNotificationByEmailEnabled; /** * flag if patterns should be used */ private boolean patternsEnabled; /** * the patterns to use */ private String patterns; /** * flag if Presence packets should be filtered. */ private boolean filterStatusEnabled; /** * flag if mask should be used */ private boolean maskEnabled; /** * the mask to use */ private String mask; /** * flag if matching content should be accepted or rejected. */ private boolean allowOnMatch; /** * violation notification messages will be from this JID */ private JID violationNotificationFrom; public ContentFilterPlugin() { contentFilter = new ContentFilter(); interceptorManager = InterceptorManager.getInstance(); violationNotificationFrom = new JID(XMPPServer.getInstance() .getServerInfo().getName()); messageRouter = XMPPServer.getInstance().getMessageRouter(); } /** * Restores the plugin defaults. */ public void reset() { setViolationNotificationEnabled(false); setViolationContact("admin"); setViolationNotificationByIMEnabled(true); setViolationNotificationByEmailEnabled(false); setViolationIncludeOriginalPacketEnabled(false); setRejectionNotificationEnabled(false); setRejectionMessage("Message rejected. This is an automated server response"); setPatternsEnabled(false); setPatterns("fox,dog"); setFilterStatusEnabled(false); setMaskEnabled(false); setMask("***"); setAllowOnMatch(false); } public boolean isAllowOnMatch() { return allowOnMatch; } public void setAllowOnMatch(boolean allow) { allowOnMatch = allow; JiveGlobals.setProperty(ALLOW_ON_MATCH_PROPERTY, allow ? "true" : "false"); changeContentFilterMask(); } public boolean isMaskEnabled() { return maskEnabled; } public void setMaskEnabled(boolean enabled) { maskEnabled = enabled; JiveGlobals.setProperty(MASK_ENABLED_PROPERTY, enabled ? "true" : "false"); changeContentFilterMask(); } public void setMask(String mas) { mask = mas; JiveGlobals.setProperty(MASK_PROPERTY, mas); changeContentFilterMask(); } private void changeContentFilterMask() { if (allowOnMatch && maskEnabled) { contentFilter.setMask(mask); } else { contentFilter.clearMask(); } } public String getMask() { return mask; } public boolean isPatternsEnabled() { return patternsEnabled; } public void setPatternsEnabled(boolean enabled) { patternsEnabled = enabled; JiveGlobals.setProperty(PATTERNS_ENABLED_PROPERTY, enabled ? "true" : "false"); changeContentFilterPatterns(); } public void setPatterns(String patt) { patterns = patt; JiveGlobals.setProperty(PATTERNS_PROPERTY, patt); changeContentFilterPatterns(); } public boolean isFilterStatusEnabled() { return filterStatusEnabled; } public void setFilterStatusEnabled(boolean enabled) { filterStatusEnabled = enabled; JiveGlobals.setProperty(FILTER_STATUS_ENABLED_PROPERTY, enabled ? "true" : "false"); } private void changeContentFilterPatterns() { if (patternsEnabled) { contentFilter.setPatterns(patterns); } else { contentFilter.clearPatterns(); } } public String getPatterns() { return patterns; }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -