Commit 461670da authored by conor's avatar conor

added new features to content filter, see changelog.html for details

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3262 b35dd754-fafc-0310-a699-88a17e54d16e
parent 8e88fb87
...@@ -44,6 +44,19 @@ ...@@ -44,6 +44,19 @@
ContentFilter Plugin Changelog ContentFilter Plugin Changelog
</h1> </h1>
<p><b>1.2</b> -- Jan, 2006</p>
<ul>
<li>Added support to notify administrator by email on content match notification.</li>
<li>Added support to include original packet when sending violation notifications.</li>
<li>Added support to filter users presence status.</li>
<li>Increased size of patterns input area to allow more patterns.</li>
<li>Fixed masking function.</li>
<li>Added debug logging to help users identify problems.</li>
<li>Updated readme.html</li>
</ul>
<p><b>1.0.1</b> -- December 15, 2005</p> <p><b>1.0.1</b> -- December 15, 2005</p>
<ul> <ul>
<li>Now requires Wildfire 2.4.0</li> <li>Now requires Wildfire 2.4.0</li>
......
...@@ -53,7 +53,7 @@ alternative content. ...@@ -53,7 +53,7 @@ alternative content.
<h2>Installation</h2> <h2>Installation</h2>
<p> <p>
Copy the contentfilter.jar into the plugins directory of your Wildfire Copy the contentfilter.jar into the plugins directory of your Jive Messenger
installation. The plugin will then be automatically deployed. To upgrade to a installation. The plugin will then be automatically deployed. To upgrade to a
new version, copy the new contentfilter.jar file over the existing file. new version, copy the new contentfilter.jar file over the existing file.
</p> </p>
...@@ -62,7 +62,7 @@ new version, copy the new contentfilter.jar file over the existing file. ...@@ -62,7 +62,7 @@ new version, copy the new contentfilter.jar file over the existing file.
<p> <p>
By default, after the plugin has been deployed all of its features are disabled. By default, after the plugin has been deployed all of its features are disabled.
This plugin is configured via the "Content Filter" sidebar item located under the This plugin is configured via the "Content Filter" sidebar item located under the
"System" tab in the Wildfire Admin Console. "System" tab in the Jive Messenger Admin Console.
</p> </p>
<p> <p>
...@@ -73,16 +73,28 @@ can be enhanced with more complex regular expressions as required e.g.: ...@@ -73,16 +73,28 @@ can be enhanced with more complex regular expressions as required e.g.:
<ul> <ul>
<li>for a complete word match, add boundary checks with \b e.g. \bfox\b will match against the word "fox" and nothing else. <li>for a complete word match, add boundary checks with \b e.g. \bfox\b will match against the word "fox" and nothing else.
<li>for case insensitive matchs add (?i) e.g. (?i)\bfox\b will match against "fox", "Fox", "foX" etc. <li>for case insensitive matchs add (?i) e.g. (?i)\bfox\b will match against "fox", "Fox", "foX" etc.
<li>it is also possible to group related patterns patterns e.g. fox|dog, this can be used to reduce the number of individual patterns to test for.
</ul> </ul>
</p>
<p>
If you choose to filter your users presence status and there is a content match then:
<ul>
<li>if you are masking content, other users will see a masked status.
<li>if you are rejecting content, other users not see the status change, how it affects the user with the invalid status is client dependant.
</ul>
</p>
<p>
Want to know more about regular expressions in Java? This official <a href="http://java.sun.com/docs/books/tutorial/extra/regex/">tutorial</a> Want to know more about regular expressions in Java? This official <a href="http://java.sun.com/docs/books/tutorial/extra/regex/">tutorial</a>
is useful. is useful.
</p> </p>
<p>
The default mask is "***", you can change it to anything you like including smilies!
</p>
<h2>Using the Plugin</h2> <h2>Using the Plugin</h2>
<p> <p>
After the plugin has been configured, nothing else needs to be done to use it. After the plugin has been configured, nothing else needs to be done to use it.
TODO - update
</p> </p>
</body> </body>
......
/** /**
* $RCSfile$ * $RCSfile$
* $Revision: 1594 $ * $Revision: 1594 $
* $Date: 2005-07-04 14:08:42 -0300 (Mon, 04 Jul 2005) $ * $Date: 2005-07-04 18:08:42 +0100 (Mon, 04 Jul 2005) $
* *
* Copyright (C) 2004 Jive Software. All rights reserved. * Copyright (C) 2004 Jive Software. All rights reserved.
* *
...@@ -11,13 +11,16 @@ ...@@ -11,13 +11,16 @@
package org.jivesoftware.wildfire.plugin; package org.jivesoftware.wildfire.plugin;
import org.xmpp.packet.Message;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.dom4j.Element;
import org.xmpp.packet.Message;
import org.xmpp.packet.Packet;
/** /**
* Filters message content using regular expressions. If a content mask is * Filters message content using regular expressions. If a content mask is
* provided message content will be altered. * provided message content will be altered.
...@@ -111,39 +114,68 @@ public class ContentFilter { ...@@ -111,39 +114,68 @@ public class ContentFilter {
} }
/** /**
* Filters message content. * Filters packet content.
* *
* @param msg the message to filter, its subject/body may be altered if there * @param packet the packet to filter, its content may be altered if there
* are content matches and a content mask is set * are content matches and a content mask is set
* @return true if the msg content matched up, false otherwise * @return true if the msg content matched up, false otherwise
*/ */
public boolean filter(Message msg) { public boolean filter(Packet p) {
boolean hasMatch = false; return process(p.getElement());
}
if (msg.getSubject() != null) { private boolean process(Element element) {
if (hasMatch(msg.getSubject())) {
hasMatch = true; boolean matched = mask(element);
if (isMaskingContent()) {
String newSubject = replaceContent(msg.getSubject()); if (!matched || isMaskingContent())
msg.setSubject(newSubject); {
//only check children if no match has yet been found
//or all content must be masked
Iterator iter = element.elementIterator();
while (iter.hasNext()) {
matched |= process((Element)iter.next());
} }
} }
return matched;
} }
if (msg.getBody() != null) { private boolean mask(Element element) {
if (hasMatch(msg.getBody())) {
hasMatch = true; boolean match = false;
String content = element.getText();
if ((content != null) && (content.length() > 0)) {
for (Pattern pattern : compiledPatterns) {
Matcher matcher = pattern.matcher(content);
if (matcher.find()) {
match = true;
if (isMaskingContent()) { if (isMaskingContent()) {
String newBody = replaceContent(msg.getBody()); content = matcher.replaceAll(mask);
msg.setBody(newBody); element.setText(content);
}
} }
} }
} }
return hasMatch; return match;
} }
private String replaceContent(String content) { /**
* Applies mask to the given <code>content</code>
*
* @param content
* @return masked content
*/
private String mask(String content) {
for (Pattern pattern : compiledPatterns) { for (Pattern pattern : compiledPatterns) {
Matcher m = pattern.matcher(content); Matcher m = pattern.matcher(content);
content = m.replaceAll(mask); content = m.replaceAll(mask);
...@@ -153,18 +185,19 @@ public class ContentFilter { ...@@ -153,18 +185,19 @@ public class ContentFilter {
} }
/** /**
* Performs sequential search for any pattern match. * Applies patterns against the given <code>content</code>. Terminates on
* first match.
* *
* @param content the content to search against * @param content the content to search against
* @return true if a match is found, false otherwise * @return true if a match is found, false otherwise
*/ */
private boolean hasMatch(String content) { private boolean hasMatch(String content) {
boolean hasMatch = false; boolean hasMatch = false;
for (Pattern pattern : compiledPatterns) { for (Pattern pattern : compiledPatterns) {
Matcher m = pattern.matcher(content); Matcher matcher = pattern.matcher(content);
if (matcher.find()) {
if (m.find()) {
hasMatch = true; hasMatch = true;
break; break;
} }
......
/** /**
* $RCSfile$ * $RCSfile$
* $Revision: 1594 $ * $Revision: 1594 $
* $Date: 2005-07-04 14:08:42 -0300 (Mon, 04 Jul 2005) $ * $Date: 2005-07-04 18:08:42 +0100 (Mon, 04 Jul 2005) $
* *
* Copyright (C) 2004 Jive Software. All rights reserved. * Copyright (C) 2004 Jive Software. All rights reserved.
* *
...@@ -11,6 +11,17 @@ ...@@ -11,6 +11,17 @@
package org.jivesoftware.wildfire.plugin; package org.jivesoftware.wildfire.plugin;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;
import org.jivesoftware.util.EmailService;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.MessageRouter; import org.jivesoftware.wildfire.MessageRouter;
import org.jivesoftware.wildfire.Session; import org.jivesoftware.wildfire.Session;
import org.jivesoftware.wildfire.XMPPServer; import org.jivesoftware.wildfire.XMPPServer;
...@@ -19,12 +30,12 @@ import org.jivesoftware.wildfire.container.PluginManager; ...@@ -19,12 +30,12 @@ import org.jivesoftware.wildfire.container.PluginManager;
import org.jivesoftware.wildfire.interceptor.InterceptorManager; import org.jivesoftware.wildfire.interceptor.InterceptorManager;
import org.jivesoftware.wildfire.interceptor.PacketInterceptor; import org.jivesoftware.wildfire.interceptor.PacketInterceptor;
import org.jivesoftware.wildfire.interceptor.PacketRejectedException; import org.jivesoftware.wildfire.interceptor.PacketRejectedException;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.wildfire.user.User;
import org.jivesoftware.wildfire.user.UserManager;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Message; import org.xmpp.packet.Message;
import org.xmpp.packet.Packet; import org.xmpp.packet.Packet;
import org.xmpp.packet.Presence;
import java.io.File;
/** /**
* Content filter plugin. * Content filter plugin.
...@@ -48,6 +59,30 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -48,6 +59,30 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
public static final String VIOLATION_NOTIFICATION_CONTACT_PROPERTY = public static final String VIOLATION_NOTIFICATION_CONTACT_PROPERTY =
"plugin.contentFilter.violation.notification.contact"; "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 * 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 * message is rejected, otherwise the message will be silently rejected,i.e. the
...@@ -74,6 +109,12 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -74,6 +109,12 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
*/ */
public static final String PATTERNS_PROPERTY = "plugin.contentFilter.patterns"; 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 * The expected value is a boolean, if true the value of #MASK_PROPERTY will
* be used to mask matching content. * be used to mask matching content.
...@@ -123,6 +164,22 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -123,6 +164,22 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
*/ */
private String violationContact; 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 * flag if patterns should be used
*/ */
...@@ -133,6 +190,11 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -133,6 +190,11 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
*/ */
private String patterns; private String patterns;
/**
* flag if Presence packets should be filtered.
*/
private boolean filterStatusEnabled;
/** /**
* flag if mask should be used * flag if mask should be used
*/ */
...@@ -206,6 +268,16 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -206,6 +268,16 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
changeContentFilterPatterns(); 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() { private void changeContentFilterPatterns() {
if (patternsEnabled) { if (patternsEnabled) {
contentFilter.setPatterns(patterns); contentFilter.setPatterns(patterns);
...@@ -257,6 +329,36 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -257,6 +329,36 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
return violationContact; return violationContact;
} }
public boolean isViolationIncludeOriginalPacketEnabled() {
return violationIncludeOriginalPacketEnabled;
}
public void setViolationIncludeOriginalPacketEnabled(boolean enabled) {
violationIncludeOriginalPacketEnabled = enabled;
JiveGlobals.setProperty(VIOLATION_INCLUDE_ORIGNAL_PACKET_ENABLED_PROPERTY,
enabled ? "true" : "false");
}
public boolean isViolationNotificationByIMEnabled() {
return violationNotificationByIMEnabled;
}
public void setViolationNotificationByIMEnabled(boolean enabled) {
violationNotificationByIMEnabled = enabled;
JiveGlobals.setProperty(VIOLATION_NOTIFICATION_BY_IM_ENABLED_PROPERTY,
enabled ? "true" : "false");
}
public boolean isViolationNotificationByEmailEnabled() {
return violationNotificationByEmailEnabled;
}
public void setViolationNotificationByEmailEnabled(boolean enabled) {
violationNotificationByEmailEnabled = enabled;
JiveGlobals.setProperty(VIOLATION_NOTIFICATION_BY_EMAIL_ENABLED_PROPERTY,
enabled ? "true" : "false");
}
public void initializePlugin(PluginManager pManager, File pluginDirectory) { public void initializePlugin(PluginManager pManager, File pluginDirectory) {
// configure this plugin // configure this plugin
initFilter(); initFilter();
...@@ -274,6 +376,18 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -274,6 +376,18 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
violationContact = JiveGlobals.getProperty(VIOLATION_NOTIFICATION_CONTACT_PROPERTY, violationContact = JiveGlobals.getProperty(VIOLATION_NOTIFICATION_CONTACT_PROPERTY,
"admin"); "admin");
// default to true
violationNotificationByIMEnabled = JiveGlobals.getBooleanProperty(
VIOLATION_NOTIFICATION_BY_IM_ENABLED_PROPERTY, true);
// default to false
violationNotificationByEmailEnabled = JiveGlobals.getBooleanProperty(
VIOLATION_NOTIFICATION_BY_EMAIL_ENABLED_PROPERTY, false);
// default to false
violationIncludeOriginalPacketEnabled = JiveGlobals.getBooleanProperty(
VIOLATION_INCLUDE_ORIGNAL_PACKET_ENABLED_PROPERTY, false);
// default to false // default to false
rejectionNotificationEnabled = JiveGlobals.getBooleanProperty( rejectionNotificationEnabled = JiveGlobals.getBooleanProperty(
REJECTION_NOTIFICATION_ENABLED_PROPERTY, false); REJECTION_NOTIFICATION_ENABLED_PROPERTY, false);
...@@ -291,6 +405,10 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -291,6 +405,10 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
changeContentFilterPatterns(); changeContentFilterPatterns();
// default to false
filterStatusEnabled = JiveGlobals.getBooleanProperty(FILTER_STATUS_ENABLED_PROPERTY,
false);
// default to false // default to false
maskEnabled = JiveGlobals.getBooleanProperty(MASK_ENABLED_PROPERTY, false); maskEnabled = JiveGlobals.getBooleanProperty(MASK_ENABLED_PROPERTY, false);
...@@ -308,24 +426,58 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -308,24 +426,58 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
interceptorManager.removeInterceptor(this); interceptorManager.removeInterceptor(this);
} }
public void interceptPacket(Packet packet, Session session, boolean read, public void interceptPacket(Packet packet, Session session, boolean read,
boolean processed) throws PacketRejectedException { boolean processed) throws PacketRejectedException {
if (patternsEnabled && !processed && (packet instanceof Message)) {
Message msg = (Message) packet;
// filter the message if (isValidTargetPacket(packet, read, processed)) {
boolean contentMatched = contentFilter.filter(msg);
Packet original = packet;
if (Log.isDebugEnabled()) {
Log.debug("Content filter: intercepted packet:" + original.toString());
}
// make a copy of the original packet only if required,
// as it's an expensive operation
if (violationNotificationEnabled && violationIncludeOriginalPacketEnabled && maskEnabled) {
original = packet.createCopy();
}
// notify contact of violations // filter the packet
boolean contentMatched = contentFilter.filter(packet);
if (Log.isDebugEnabled()) {
Log.debug("Content filter: content matched? " + contentMatched);
}
// notify admin of violations
if (contentMatched && violationNotificationEnabled) { if (contentMatched && violationNotificationEnabled) {
sendViolationNotification(msg);
if (Log.isDebugEnabled()) {
Log.debug("Content filter: sending violation notification.");
Log.debug("Content filter: include original msg?" +
this.violationIncludeOriginalPacketEnabled);
}
sendViolationNotification(original);
}
// msg will either be rejected silently, rejected with
// some notification to sender, or masked.
if (contentMatched) {
if (maskEnabled) {
//masking enabled, no further action required
if (Log.isDebugEnabled()) {
Log.debug("Content filter: masked content:" + packet.toString());
}
} else {
//no masking, msg must be rejected
if (Log.isDebugEnabled()) {
Log.debug("Content filter: rejecting packet.");
} }
// reject the message if not masking content
if (contentMatched && !maskEnabled) {
PacketRejectedException rejected = new PacketRejectedException( PacketRejectedException rejected = new PacketRejectedException(
"Message rejected with disallowed content!"); "Packet rejected with disallowed content!");
if (rejectionNotificationEnabled) { if (rejectionNotificationEnabled) {
// let the sender know about the rejection, this is // let the sender know about the rejection, this is
...@@ -337,16 +489,54 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -337,16 +489,54 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
} }
} }
} }
}
private void sendViolationNotification(Message offendingMsg) { private boolean isValidTargetPacket(Packet packet, boolean read, boolean processed) {
String subject = "Content filter notification!"; return patternsEnabled && !processed && read &&
(packet instanceof Message ||
(filterStatusEnabled && packet instanceof Presence));
}
String msg = "Disallowed content detected in message from:" private void sendViolationNotification(Packet originalPacket) {
+ offendingMsg.getFrom() + " to:" + offendingMsg.getTo()
String subject = "Content filter notification!";
String body = null;
if (originalPacket instanceof Message) {
Message originalMsg = (Message) originalPacket;
body = "Disallowed content detected in message from:"
+ originalMsg.getFrom() + " to:" + originalMsg.getTo()
+ ", message was " + ", message was "
+ (contentFilter.isMaskingContent() ? "altered" : "rejected"); + (contentFilter.isMaskingContent() ? "altered." : "rejected.")
+ (violationIncludeOriginalPacketEnabled ?
"\nOriginal subject:" + (originalMsg.getSubject() != null ? originalMsg.getSubject() : "")
+ "\nOriginal content:" + (originalMsg.getBody() != null ? originalMsg.getBody() : "") : "");
} else {
//presence
Presence originalPresence = (Presence) originalPacket;
body = "Disallowed status detected in presence from:"
+ originalPresence.getFrom()
+ ", status was "
+ (contentFilter.isMaskingContent() ? "altered." : "rejected.")
+ (violationIncludeOriginalPacketEnabled ?
"\nOriginal status:" + originalPresence.getStatus() : "");
}
if (violationNotificationByIMEnabled) {
if (Log.isDebugEnabled()) {
Log.debug("Sending IM notification");
}
messageRouter.route(createServerMessage(subject, body));
}
if (violationNotificationByEmailEnabled) {
messageRouter.route(createServerMessage(subject, msg)); if (Log.isDebugEnabled()) {
Log.debug("Sending email notification");
}
sendViolationNotificationEmail(subject, body);
}
} }
private Message createServerMessage(String subject, String body) { private Message createServerMessage(String subject, String body) {
...@@ -358,4 +548,34 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -358,4 +548,34 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
message.setBody(body); message.setBody(body);
return message; return message;
} }
private void sendViolationNotificationEmail(String subject, String body) {
List<MimeMessage> messages = new ArrayList<MimeMessage>();
EmailService emailService = EmailService.getInstance();
MimeMessage message = emailService.createMimeMessage();
String encoding = MimeUtility.mimeCharset("iso-8859-1");
try {
User user = UserManager.getInstance().getUser(violationContact);
message.setRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(user.getEmail()));
message.setFrom(new InternetAddress("no_reply@" + violationNotificationFrom, "Wildfire", encoding));
message.setText(body);
message.setSubject(subject);
messages.add(message);
} catch (Exception e) {
Log.error(e);
}
emailService.sendMessages(messages);
}
} }
\ No newline at end of file
...@@ -13,9 +13,11 @@ ...@@ -13,9 +13,11 @@
boolean save = request.getParameter("save") != null; boolean save = request.getParameter("save") != null;
boolean success = request.getParameter("success") != null; boolean success = request.getParameter("success") != null;
//pattern options //filter options
boolean patternsEnabled = ParamUtils.getBooleanParameter(request, "patternsenabled"); boolean patternsEnabled = ParamUtils.getBooleanParameter(request, "patternsenabled");
String patterns = ParamUtils.getParameter(request, "patterns"); String patterns = ParamUtils.getParameter(request, "patterns");
String [] filterStatusChecked = ParamUtils.getParameters(request, "filterstatus");
boolean filterStatusEnabled = filterStatusChecked.length > 0;
//mask options //mask options
boolean maskEnabled = ParamUtils.getBooleanParameter(request, "maskenabled"); boolean maskEnabled = ParamUtils.getBooleanParameter(request, "maskenabled");
...@@ -28,6 +30,10 @@ ...@@ -28,6 +30,10 @@
//notification options //notification options
boolean notificationEnabled = ParamUtils.getBooleanParameter(request, "notificationenabled"); boolean notificationEnabled = ParamUtils.getBooleanParameter(request, "notificationenabled");
String contactName = ParamUtils.getParameter(request, "contactname"); String contactName = ParamUtils.getParameter(request, "contactname");
List<String> notificationOptions = Arrays.asList(ParamUtils.getParameters(request, "notificationcb"));
boolean notificationByIMEnabled = notificationOptions.contains("notificationbyim");
boolean notificationByEmailEnabled = notificationOptions.contains("notificationbyemail");
boolean includeOriginalEnabled = notificationOptions.contains("notificationincludeoriginal");
//get handle to plugin //get handle to plugin
ContentFilterPlugin plugin = (ContentFilterPlugin) XMPPServer.getInstance().getPluginManager().getPlugin("contentfilter"); ContentFilterPlugin plugin = (ContentFilterPlugin) XMPPServer.getInstance().getPluginManager().getPlugin("contentfilter");
...@@ -38,9 +44,7 @@ ...@@ -38,9 +44,7 @@
if (patterns == null) { if (patterns == null) {
errors.put("missingPatterns", "missingPatterns"); errors.put("missingPatterns", "missingPatterns");
} } else {
else {
String[] data = patterns.split(","); String[] data = patterns.split(",");
try { try {
for (String aData : data) { for (String aData : data) {
...@@ -51,7 +55,6 @@ ...@@ -51,7 +55,6 @@
} }
} }
if (mask == null) { if (mask == null) {
errors.put("missingMask", "missingMask"); errors.put("missingMask", "missingMask");
} }
...@@ -65,27 +68,43 @@ ...@@ -65,27 +68,43 @@
} else { } else {
contactName = contactName.trim().toLowerCase(); contactName = contactName.trim().toLowerCase();
try { try {
UserManager.getInstance().getUser(contactName); User user = UserManager.getInstance().getUser(contactName);
if (notificationByEmailEnabled) {
//verify that the user has an email address
if (user.getEmail() == null) {
errors.put("userEmailNotConfigured", "userEmailNotConfigured");
}
//verify that the email server is configured
if (!JiveGlobals.getBooleanProperty("mail.configured", false)) {
errors.put("mailServerNotConfigured", "mailServerNotConfigured");
}
}
} catch (UserNotFoundException unfe) { } catch (UserNotFoundException unfe) {
errors.put("userNotFound", "userNotFound"); errors.put("userNotFound", "userNotFound");
} }
} }
if (!notificationByIMEnabled && !notificationByEmailEnabled) {
errors.put("notificationFormatNotConfigured", "notificationFormatNotConfigured");
}
if (errors.size() == 0) { if (errors.size() == 0) {
plugin.setPatternsEnabled(patternsEnabled); plugin.setPatternsEnabled(patternsEnabled);
plugin.setPatterns(patterns); plugin.setPatterns(patterns);
plugin.setFilterStatusEnabled(filterStatusEnabled);
plugin.setMaskEnabled(maskEnabled); plugin.setMaskEnabled(maskEnabled);
plugin.setMask(mask); plugin.setMask(mask);
plugin.setViolationNotificationEnabled(notificationEnabled); plugin.setViolationNotificationEnabled(notificationEnabled);
plugin.setViolationContact(contactName); plugin.setViolationContact(contactName);
plugin.setViolationNotificationByIMEnabled(notificationByIMEnabled);
plugin.setViolationNotificationByEmailEnabled(notificationByEmailEnabled);
plugin.setViolationIncludeOriginalPacketEnabled(includeOriginalEnabled);
plugin.setRejectionNotificationEnabled(rejectionNotificationEnabled); plugin.setRejectionNotificationEnabled(rejectionNotificationEnabled);
plugin.setRejectionMessage(rejectionMsg); plugin.setRejectionMessage(rejectionMsg);
response.sendRedirect("contentfilter-props-edit-form.jsp?success=true"); response.sendRedirect("contentfilter-props-edit-form.jsp?success=true");
return; return;
} }
} else {
}
else {
patterns = plugin.getPatterns(); patterns = plugin.getPatterns();
mask = plugin.getMask(); mask = plugin.getMask();
contactName = plugin.getViolationContact(); contactName = plugin.getViolationContact();
...@@ -97,9 +116,13 @@ ...@@ -97,9 +116,13 @@
mask = plugin.getMask(); mask = plugin.getMask();
contactName = plugin.getViolationContact(); contactName = plugin.getViolationContact();
rejectionMsg = plugin.getRejectionMessage(); rejectionMsg = plugin.getRejectionMessage();
notificationByIMEnabled = plugin.isViolationNotificationByIMEnabled();
notificationByEmailEnabled = plugin.isViolationNotificationByEmailEnabled();
includeOriginalEnabled = plugin.isViolationIncludeOriginalPacketEnabled();
} }
patternsEnabled = plugin.isPatternsEnabled(); patternsEnabled = plugin.isPatternsEnabled();
filterStatusEnabled = plugin.isFilterStatusEnabled();
maskEnabled = plugin.isMaskEnabled(); maskEnabled = plugin.isMaskEnabled();
notificationEnabled = plugin.isViolationNotificationEnabled(); notificationEnabled = plugin.isViolationNotificationEnabled();
rejectionNotificationEnabled = plugin.isRejectionNotificationEnabled(); rejectionNotificationEnabled = plugin.isRejectionNotificationEnabled();
...@@ -163,7 +186,7 @@ Use the form below to edit content filter settings.<br> ...@@ -163,7 +186,7 @@ Use the form below to edit content filter settings.<br>
<%= ((patternsEnabled) ? "" : "checked") %>> <%= ((patternsEnabled) ? "" : "checked") %>>
</td> </td>
<td width="99%"> <td width="99%">
<label for="not01"><b>Disabled</b></label> - Messages will not be filtered. <label for="not01"><b>Disabled</b></label> - Packets will not be filtered.
</td> </td>
</tr> </tr>
<tr> <tr>
...@@ -172,14 +195,17 @@ Use the form below to edit content filter settings.<br> ...@@ -172,14 +195,17 @@ Use the form below to edit content filter settings.<br>
<%= ((patternsEnabled) ? "checked" : "") %>> <%= ((patternsEnabled) ? "checked" : "") %>>
</td> </td>
<td width="99%"> <td width="99%">
<label for="not02"><b>Enabled</b></label> - Messages will be filtered. <label for="not02"><b>Enabled</b></label> - Packets will be filtered.
</td> </td>
</tr> </tr>
<tr> <tr>
<td>&nbsp;</td> <td>&nbsp;</td>
<td align="left">Patterns:&nbsp; <td align="left">Patterns:&nbsp;</td>
<input type="text" size="100" maxlength="100" name="patterns" </tr>
value="<%= (patterns != null ? patterns : "") %>"> <tr>
<td>&nbsp;</td>
<td>
<textarea rows="10" cols="100" name="patterns"><%= (patterns != null ? patterns : "") %></textarea>
<% if (errors.containsKey("missingPatterns")) { %> <% if (errors.containsKey("missingPatterns")) { %>
<span class="jive-error-text"> <span class="jive-error-text">
<br>Please enter comma separated, regular expressions. <br>Please enter comma separated, regular expressions.
...@@ -191,6 +217,10 @@ Use the form below to edit content filter settings.<br> ...@@ -191,6 +217,10 @@ Use the form below to edit content filter settings.<br>
<% } %> <% } %>
</td> </td>
</tr> </tr>
<tr>
<td>&nbsp;</td>
<td><input type="checkbox" name="filterstatus" value="filterstatus" <%= filterStatusEnabled ? "checked" : "" %>>Filter users presence status.</input></td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>
...@@ -203,7 +233,7 @@ Use the form below to edit content filter settings.<br> ...@@ -203,7 +233,7 @@ Use the form below to edit content filter settings.<br>
<div> <div>
<p> <p>
Enable this feature to alter message content when there is a pattern match. Enable this feature to alter packet content when there is a pattern match.
</p> </p>
<table cellpadding="3" cellspacing="0" border="0" width="100%"> <table cellpadding="3" cellspacing="0" border="0" width="100%">
...@@ -214,7 +244,7 @@ Use the form below to edit content filter settings.<br> ...@@ -214,7 +244,7 @@ Use the form below to edit content filter settings.<br>
<%= ((maskEnabled) ? "" : "checked") %>> <%= ((maskEnabled) ? "" : "checked") %>>
</td> </td>
<td width="99%"> <td width="99%">
<label for="not01"><b>Disabled</b></label> - Messages will be rejected. <label for="not01"><b>Disabled</b></label> - Packets will be rejected.
</td> </td>
</tr> </tr>
<tr> <tr>
...@@ -223,7 +253,7 @@ Use the form below to edit content filter settings.<br> ...@@ -223,7 +253,7 @@ Use the form below to edit content filter settings.<br>
<%= ((maskEnabled) ? "checked" : "") %>> <%= ((maskEnabled) ? "checked" : "") %>>
</td> </td>
<td width="99%"> <td width="99%">
<label for="not02"><b>Enabled</b></label> - Messages will be masked. <label for="not02"><b>Enabled</b></label> - Packets will be masked.
</td> </td>
</tr> </tr>
<tr> <tr>
...@@ -250,7 +280,7 @@ Use the form below to edit content filter settings.<br> ...@@ -250,7 +280,7 @@ Use the form below to edit content filter settings.<br>
<div> <div>
<p> <p>
Enable this feature to have the message sender notified whenever a message is rejected. Enable this feature to have the sender notified whenever a packet is rejected.
NB: This feature is only operational if "Content Mask" feature is disabled. NB: This feature is only operational if "Content Mask" feature is disabled.
</p> </p>
...@@ -323,9 +353,8 @@ Use the form below to edit content filter settings.<br> ...@@ -323,9 +353,8 @@ Use the form below to edit content filter settings.<br>
</tr> </tr>
<tr> <tr>
<td>&nbsp;</td> <td>&nbsp;</td>
<td align="left">Username:&nbsp; <td align="left">Username:&nbsp
<input type="text" size="20" maxlength="100" name="contactname" <input type="text" size="20" maxlength="100" name="contactname" value="<%= (contactName != null ? contactName : "") %>">@<%= XMPPServer.getInstance().getServerInfo().getName() %>
value="<%= (contactName != null ? contactName : "") %>">@<%= XMPPServer.getInstance().getServerInfo().getName() %>
<% if (errors.containsKey("missingContactName")) { %> <% if (errors.containsKey("missingContactName")) { %>
<span class="jive-error-text"> <span class="jive-error-text">
<br>Please enter a username. <br>Please enter a username.
...@@ -337,6 +366,27 @@ Use the form below to edit content filter settings.<br> ...@@ -337,6 +366,27 @@ Use the form below to edit content filter settings.<br>
<% } %> <% } %>
</td> </td>
</tr> </tr>
<tr>
<td>&nbsp;</td>
<td>
<input type="checkbox" name="notificationcb" value="notificationbyim" <%= notificationByIMEnabled ? "checked" : "" %>>Notify by IM.</input>
<input type="checkbox" name="notificationcb" value="notificationbyemail" <%= notificationByEmailEnabled ? "checked" : "" %>>Notify by Email.</input>
<input type="checkbox" name="notificationcb" value="notificationincludeoriginal" <%= includeOriginalEnabled ? "checked" : "" %>>Include original packet.</input>
<% if (errors.containsKey("mailServerNotConfigured")) { %>
<span class="jive-error-text">
<br>Error, sending an email will fail because the mail server is not setup. Please go to the <a href="/system-email.jsp">mail settings page</a> and set the mail host.
</span>
<% } else if (errors.containsKey("userEmailNotConfigured")) { %>
<span class="jive-error-text">
<br>Please configure <a href="/user-properties.jsp?username=<%= contactName %>"><%= contactName %>'s</a> email address.
</span>
<% } else if (errors.containsKey("notificationFormatNotConfigured")) { %>
<span class="jive-error-text">
<br>Users must be notified by IM and/or Email.
</span>
<% } %>
</td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment