Commit 7d9b8735 authored by conor's avatar conor

extended catch to handle Throwable when sending emails

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3299 b35dd754-fafc-0310-a699-88a17e54d16e
parent cfac3014
...@@ -51,47 +51,41 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -51,47 +51,41 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
* every time there is a content match, otherwise no notification will be * every time there is a content match, otherwise no notification will be
* sent. Then default value is false. * sent. Then default value is false.
*/ */
public static final String VIOLATION_NOTIFICATION_ENABLED_PROPERTY = public static final String VIOLATION_NOTIFICATION_ENABLED_PROPERTY = "plugin.contentFilter.violation.notification.enabled";
"plugin.contentFilter.violation.notification.enabled";
/** /**
* The expected value is a user name. The default value is "admin". * The expected value is a user name. The default value is "admin".
*/ */
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 * The expected value is a boolean, if true the user identified by the value
* of the property #VIOLATION_NOTIFICATION_CONTACT_PROPERTY, will also receive * of the property #VIOLATION_NOTIFICATION_CONTACT_PROPERTY, will also
* a copy of the offending packet. The default value is false. * receive a copy of the offending packet. The default value is false.
*/ */
public static final String VIOLATION_INCLUDE_ORIGNAL_PACKET_ENABLED_PROPERTY = public static final String VIOLATION_INCLUDE_ORIGNAL_PACKET_ENABLED_PROPERTY = "plugin.contentFilter.violation.notification.include.original.enabled";
"plugin.contentFilter.violation.notification.include.original.enabled";
/** /**
* The expected value is a boolean, if true the user identified by the value * The expected value is a boolean, if true the user identified by the value
* of the property #VIOLATION_NOTIFICATION_CONTACT_PROPERTY, will receive * of the property #VIOLATION_NOTIFICATION_CONTACT_PROPERTY, will receive
* notification by IM. The default value is true. * notification by IM. The default value is true.
*/ */
public static final String VIOLATION_NOTIFICATION_BY_IM_ENABLED_PROPERTY = public static final String VIOLATION_NOTIFICATION_BY_IM_ENABLED_PROPERTY = "plugin.contentFilter.violation.notification.by.im.enabled";
"plugin.contentFilter.violation.notification.by.im.enabled";
/** /**
* The expected value is a boolean, if true the user identified by the value * The expected value is a boolean, if true the user identified by the value
* of the property #VIOLATION_NOTIFICATION_CONTACT_PROPERTY, will receive * of the property #VIOLATION_NOTIFICATION_CONTACT_PROPERTY, will receive
* notification by email. The default value is false. * notification by email. The default value is false.
*/ */
public static final String VIOLATION_NOTIFICATION_BY_EMAIL_ENABLED_PROPERTY = public static final String VIOLATION_NOTIFICATION_BY_EMAIL_ENABLED_PROPERTY = "plugin.contentFilter.violation.notification.by.email.enabled";
"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
* message is rejected, otherwise the message will be silently rejected,i.e. the * a message is rejected, otherwise the message will be silently
* sender will not know that the message was rejected and the receiver will * rejected,i.e. the sender will not know that the message was rejected and
* not get the message. The default value is false. * the receiver will not get the message. The default value is false.
*/ */
public static final String REJECTION_NOTIFICATION_ENABLED_PROPERTY = public static final String REJECTION_NOTIFICATION_ENABLED_PROPERTY = "plugin.contentFilter.rejection.notification.enabled";
"plugin.contentFilter.rejection.notification.enabled";
/** /**
* The expected value is a string, containing the desired message for the * The expected value is a string, containing the desired message for the
...@@ -111,8 +105,8 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -111,8 +105,8 @@ 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 * The expected value is a boolean, if true Presence packets will be
* be filtered * filtered
*/ */
public static final String FILTER_STATUS_ENABLED_PROPERTY = "plugin.contentFilter.filter.status.enabled"; public static final String FILTER_STATUS_ENABLED_PROPERTY = "plugin.contentFilter.filter.status.enabled";
...@@ -123,10 +117,10 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -123,10 +117,10 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
public static final String MASK_ENABLED_PROPERTY = "plugin.contentFilter.mask.enabled"; public static final String MASK_ENABLED_PROPERTY = "plugin.contentFilter.mask.enabled";
/** /**
* The expected value is a string. If this property is set any * The expected value is a string. If this property is set any matching
* matching content will not be rejected but masked with the given value. * content will not be rejected but masked with the given value. Setting a
* Setting a content mask means that property #SENDER_NOTIFICATION_ENABLED_PROPERTY * content mask means that property #SENDER_NOTIFICATION_ENABLED_PROPERTY is
* is ignored. The default value is "**". * ignored. The default value is "**".
*/ */
public static final String MASK_PROPERTY = "plugin.contentFilter.mask"; public static final String MASK_PROPERTY = "plugin.contentFilter.mask";
...@@ -166,8 +160,8 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -166,8 +160,8 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
private String violationContact; private String violationContact;
/** /**
* flags if original packet should be included in the message * flags if original packet should be included in the message to the
* to the violation contact. * violation contact.
*/ */
private boolean violationIncludeOriginalPacketEnabled; private boolean violationIncludeOriginalPacketEnabled;
...@@ -225,7 +219,8 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -225,7 +219,8 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
public void setMaskEnabled(boolean enabled) { public void setMaskEnabled(boolean enabled) {
maskEnabled = enabled; maskEnabled = enabled;
JiveGlobals.setProperty(MASK_ENABLED_PROPERTY, enabled ? "true" : "false"); JiveGlobals.setProperty(MASK_ENABLED_PROPERTY, enabled ? "true"
: "false");
changeContentFilterMask(); changeContentFilterMask();
} }
...@@ -240,8 +235,7 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -240,8 +235,7 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
private void changeContentFilterMask() { private void changeContentFilterMask() {
if (maskEnabled) { if (maskEnabled) {
contentFilter.setMask(mask); contentFilter.setMask(mask);
} } else {
else {
contentFilter.clearMask(); contentFilter.clearMask();
} }
} }
...@@ -275,15 +269,14 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -275,15 +269,14 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
public void setFilterStatusEnabled(boolean enabled) { public void setFilterStatusEnabled(boolean enabled) {
filterStatusEnabled = enabled; filterStatusEnabled = enabled;
JiveGlobals.setProperty(FILTER_STATUS_ENABLED_PROPERTY, enabled ? "true" JiveGlobals.setProperty(FILTER_STATUS_ENABLED_PROPERTY,
: "false"); enabled ? "true" : "false");
} }
private void changeContentFilterPatterns() { private void changeContentFilterPatterns() {
if (patternsEnabled) { if (patternsEnabled) {
contentFilter.setPatterns(patterns); contentFilter.setPatterns(patterns);
} } else {
else {
contentFilter.clearPatterns(); contentFilter.clearPatterns();
} }
} }
...@@ -323,7 +316,8 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -323,7 +316,8 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
public void setViolationContact(String contact) { public void setViolationContact(String contact) {
violationContact = contact; violationContact = contact;
JiveGlobals.setProperty(VIOLATION_NOTIFICATION_CONTACT_PROPERTY, contact); JiveGlobals.setProperty(VIOLATION_NOTIFICATION_CONTACT_PROPERTY,
contact);
} }
public String getViolationContact() { public String getViolationContact() {
...@@ -336,7 +330,8 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -336,7 +330,8 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
public void setViolationIncludeOriginalPacketEnabled(boolean enabled) { public void setViolationIncludeOriginalPacketEnabled(boolean enabled) {
violationIncludeOriginalPacketEnabled = enabled; violationIncludeOriginalPacketEnabled = enabled;
JiveGlobals.setProperty(VIOLATION_INCLUDE_ORIGNAL_PACKET_ENABLED_PROPERTY, JiveGlobals.setProperty(
VIOLATION_INCLUDE_ORIGNAL_PACKET_ENABLED_PROPERTY,
enabled ? "true" : "false"); enabled ? "true" : "false");
} }
...@@ -356,7 +351,8 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -356,7 +351,8 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
public void setViolationNotificationByEmailEnabled(boolean enabled) { public void setViolationNotificationByEmailEnabled(boolean enabled) {
violationNotificationByEmailEnabled = enabled; violationNotificationByEmailEnabled = enabled;
JiveGlobals.setProperty(VIOLATION_NOTIFICATION_BY_EMAIL_ENABLED_PROPERTY, JiveGlobals.setProperty(
VIOLATION_NOTIFICATION_BY_EMAIL_ENABLED_PROPERTY,
enabled ? "true" : "false"); enabled ? "true" : "false");
} }
...@@ -374,8 +370,8 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -374,8 +370,8 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
VIOLATION_NOTIFICATION_ENABLED_PROPERTY, false); VIOLATION_NOTIFICATION_ENABLED_PROPERTY, false);
// default to "admin" // default to "admin"
violationContact = JiveGlobals.getProperty(VIOLATION_NOTIFICATION_CONTACT_PROPERTY, violationContact = JiveGlobals.getProperty(
"admin"); VIOLATION_NOTIFICATION_CONTACT_PROPERTY, "admin");
// default to true // default to true
violationNotificationByIMEnabled = JiveGlobals.getBooleanProperty( violationNotificationByIMEnabled = JiveGlobals.getBooleanProperty(
...@@ -398,22 +394,23 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -398,22 +394,23 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
"Message rejected. This is an automated server response"); "Message rejected. This is an automated server response");
// default to false // default to false
patternsEnabled = JiveGlobals.getBooleanProperty(PATTERNS_ENABLED_PROPERTY, patternsEnabled = JiveGlobals.getBooleanProperty(
false); PATTERNS_ENABLED_PROPERTY, false);
//default to "fox,dog" // default to "fox,dog"
patterns = JiveGlobals.getProperty(PATTERNS_PROPERTY, "fox,dog"); patterns = JiveGlobals.getProperty(PATTERNS_PROPERTY, "fox,dog");
changeContentFilterPatterns(); changeContentFilterPatterns();
// default to false // default to false
filterStatusEnabled = JiveGlobals.getBooleanProperty(FILTER_STATUS_ENABLED_PROPERTY, filterStatusEnabled = JiveGlobals.getBooleanProperty(
false); 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);
//default to "***" // default to "***"
mask = JiveGlobals.getProperty(MASK_PROPERTY, "***"); mask = JiveGlobals.getProperty(MASK_PROPERTY, "***");
changeContentFilterMask(); changeContentFilterMask();
...@@ -435,12 +432,14 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -435,12 +432,14 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
Packet original = packet; Packet original = packet;
if (Log.isDebugEnabled()) { if (Log.isDebugEnabled()) {
Log.debug("Content filter: intercepted packet:" + original.toString()); Log.debug("Content filter: intercepted packet:"
+ original.toString());
} }
// make a copy of the original packet only if required, // make a copy of the original packet only if required,
// as it's an expensive operation // as it's an expensive operation
if (violationNotificationEnabled && violationIncludeOriginalPacketEnabled && maskEnabled) { if (violationNotificationEnabled
&& violationIncludeOriginalPacketEnabled && maskEnabled) {
original = packet.createCopy(); original = packet.createCopy();
} }
...@@ -456,14 +455,14 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -456,14 +455,14 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
if (Log.isDebugEnabled()) { if (Log.isDebugEnabled()) {
Log.debug("Content filter: sending violation notification"); Log.debug("Content filter: sending violation notification");
Log.debug("Content filter: include original msg? " + Log.debug("Content filter: include original msg? "
this.violationIncludeOriginalPacketEnabled); + this.violationIncludeOriginalPacketEnabled);
} }
//TODO consider spining off a separate thread here, // TODO consider spining off a separate thread here,
//in high volume situations, it will result in // in high volume situations, it will result in
//in faster response and notification is not required // in faster response and notification is not required
//to be real time. // to be real time.
sendViolationNotification(original); sendViolationNotification(original);
} }
...@@ -471,12 +470,13 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -471,12 +470,13 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
// some notification to sender, or masked. // some notification to sender, or masked.
if (contentMatched) { if (contentMatched) {
if (maskEnabled) { if (maskEnabled) {
//masking enabled, no further action required // masking enabled, no further action required
if (Log.isDebugEnabled()) { if (Log.isDebugEnabled()) {
Log.debug("Content filter: masked content:" + packet.toString()); Log.debug("Content filter: masked content:"
+ packet.toString());
} }
} else { } else {
//no masking, msg must be rejected // no masking, msg must be rejected
if (Log.isDebugEnabled()) { if (Log.isDebugEnabled()) {
Log.debug("Content filter: rejecting packet"); Log.debug("Content filter: rejecting packet");
} }
...@@ -496,36 +496,48 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -496,36 +496,48 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
} }
} }
private boolean isValidTargetPacket(Packet packet, boolean read, boolean processed) { private boolean isValidTargetPacket(Packet packet, boolean read,
return patternsEnabled && !processed && read && boolean processed) {
(packet instanceof Message || return patternsEnabled
(filterStatusEnabled && packet instanceof Presence)); && !processed
&& read
&& (packet instanceof Message || (filterStatusEnabled && packet instanceof Presence));
} }
private void sendViolationNotification(Packet originalPacket) { private void sendViolationNotification(Packet originalPacket) {
String subject = "Content filter notification! (" + originalPacket.getFrom().getNode() + ")"; String subject = "Content filter notification! ("
+ originalPacket.getFrom().getNode() + ")";
String body = null; String body = null;
if (originalPacket instanceof Message) { if (originalPacket instanceof Message) {
Message originalMsg = (Message) originalPacket; Message originalMsg = (Message) originalPacket;
body = "Disallowed content detected in message from:" body = "Disallowed content detected in message from:"
+ originalMsg.getFrom() + " to:" + originalMsg.getTo() + originalMsg.getFrom()
+ " to:"
+ originalMsg.getTo()
+ ", message was " + ", message was "
+ (contentFilter.isMaskingContent() ? "altered." : "rejected.") + (contentFilter.isMaskingContent() ? "altered."
+ (violationIncludeOriginalPacketEnabled ? : "rejected.")
"\nOriginal subject:" + (originalMsg.getSubject() != null ? originalMsg.getSubject() : "") + (violationIncludeOriginalPacketEnabled ? "\nOriginal subject:"
+ "\nOriginal content:" + (originalMsg.getBody() != null ? originalMsg.getBody() : "") : ""); + (originalMsg.getSubject() != null ? originalMsg
.getSubject() : "")
+ "\nOriginal content:"
+ (originalMsg.getBody() != null ? originalMsg
.getBody() : "")
: "");
} else { } else {
//presence // presence
Presence originalPresence = (Presence) originalPacket; Presence originalPresence = (Presence) originalPacket;
body = "Disallowed status detected in presence from:" body = "Disallowed status detected in presence from:"
+ originalPresence.getFrom() + originalPresence.getFrom()
+ ", status was " + ", status was "
+ (contentFilter.isMaskingContent() ? "altered." : "rejected.") + (contentFilter.isMaskingContent() ? "altered."
+ (violationIncludeOriginalPacketEnabled ? : "rejected.")
"\nOriginal status:" + originalPresence.getStatus() : ""); + (violationIncludeOriginalPacketEnabled ? "\nOriginal status:"
+ originalPresence.getStatus()
: "");
} }
if (violationNotificationByIMEnabled) { if (violationNotificationByIMEnabled) {
...@@ -564,18 +576,21 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -564,18 +576,21 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
List<MimeMessage> messages = new ArrayList<MimeMessage>(); List<MimeMessage> messages = new ArrayList<MimeMessage>();
try {
EmailService emailService = EmailService.getInstance(); EmailService emailService = EmailService.getInstance();
MimeMessage message = emailService.createMimeMessage(); MimeMessage message = emailService.createMimeMessage();
String encoding = MimeUtility.mimeCharset("iso-8859-1"); String encoding = MimeUtility.mimeCharset("iso-8859-1");
try {
User user = UserManager.getInstance().getUser(violationContact); User user = UserManager.getInstance().getUser(violationContact);
message.setRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(user.getEmail())); message.setRecipient(javax.mail.Message.RecipientType.TO,
new InternetAddress(user.getEmail()));
message.setFrom(new InternetAddress("no_reply@" + violationNotificationFrom, "Wildfire", encoding)); message.setFrom(new InternetAddress("no_reply@"
+ violationNotificationFrom, "Wildfire", encoding));
message.setText(body); message.setText(body);
...@@ -585,10 +600,11 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -585,10 +600,11 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
messages.add(message); messages.add(message);
} catch (Exception e) {
Log.error(e);
}
emailService.sendMessages(messages); emailService.sendMessages(messages);
} catch (Throwable e) {
// catch throwable in case email setup is invalid
Log.error("Content Filter: Failed to send email, please review Wildfire setup", e);
}
} }
} }
\ No newline at end of file
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