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 {
* 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";
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";
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.
* 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";
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";
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";
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.
* 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";
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
......@@ -111,8 +105,8 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
public static final String PATTERNS_PROPERTY = "plugin.contentFilter.patterns";
/**
* The expected value is a boolean, if true Presence packets will
* be filtered
* 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";
......@@ -123,10 +117,10 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
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 "**".
* 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";
......@@ -166,8 +160,8 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
private String violationContact;
/**
* flags if original packet should be included in the message
* to the violation contact.
* flags if original packet should be included in the message to the
* violation contact.
*/
private boolean violationIncludeOriginalPacketEnabled;
......@@ -225,7 +219,8 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
public void setMaskEnabled(boolean enabled) {
maskEnabled = enabled;
JiveGlobals.setProperty(MASK_ENABLED_PROPERTY, enabled ? "true" : "false");
JiveGlobals.setProperty(MASK_ENABLED_PROPERTY, enabled ? "true"
: "false");
changeContentFilterMask();
}
......@@ -240,8 +235,7 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
private void changeContentFilterMask() {
if (maskEnabled) {
contentFilter.setMask(mask);
}
else {
} else {
contentFilter.clearMask();
}
}
......@@ -275,15 +269,14 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
public void setFilterStatusEnabled(boolean enabled) {
filterStatusEnabled = enabled;
JiveGlobals.setProperty(FILTER_STATUS_ENABLED_PROPERTY, enabled ? "true"
: "false");
JiveGlobals.setProperty(FILTER_STATUS_ENABLED_PROPERTY,
enabled ? "true" : "false");
}
private void changeContentFilterPatterns() {
if (patternsEnabled) {
contentFilter.setPatterns(patterns);
}
else {
} else {
contentFilter.clearPatterns();
}
}
......@@ -323,7 +316,8 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
public void setViolationContact(String contact) {
violationContact = contact;
JiveGlobals.setProperty(VIOLATION_NOTIFICATION_CONTACT_PROPERTY, contact);
JiveGlobals.setProperty(VIOLATION_NOTIFICATION_CONTACT_PROPERTY,
contact);
}
public String getViolationContact() {
......@@ -336,7 +330,8 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
public void setViolationIncludeOriginalPacketEnabled(boolean enabled) {
violationIncludeOriginalPacketEnabled = enabled;
JiveGlobals.setProperty(VIOLATION_INCLUDE_ORIGNAL_PACKET_ENABLED_PROPERTY,
JiveGlobals.setProperty(
VIOLATION_INCLUDE_ORIGNAL_PACKET_ENABLED_PROPERTY,
enabled ? "true" : "false");
}
......@@ -356,7 +351,8 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
public void setViolationNotificationByEmailEnabled(boolean enabled) {
violationNotificationByEmailEnabled = enabled;
JiveGlobals.setProperty(VIOLATION_NOTIFICATION_BY_EMAIL_ENABLED_PROPERTY,
JiveGlobals.setProperty(
VIOLATION_NOTIFICATION_BY_EMAIL_ENABLED_PROPERTY,
enabled ? "true" : "false");
}
......@@ -374,8 +370,8 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
VIOLATION_NOTIFICATION_ENABLED_PROPERTY, false);
// default to "admin"
violationContact = JiveGlobals.getProperty(VIOLATION_NOTIFICATION_CONTACT_PROPERTY,
"admin");
violationContact = JiveGlobals.getProperty(
VIOLATION_NOTIFICATION_CONTACT_PROPERTY, "admin");
// default to true
violationNotificationByIMEnabled = JiveGlobals.getBooleanProperty(
......@@ -398,22 +394,23 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
"Message rejected. This is an automated server response");
// default to false
patternsEnabled = JiveGlobals.getBooleanProperty(PATTERNS_ENABLED_PROPERTY,
false);
patternsEnabled = JiveGlobals.getBooleanProperty(
PATTERNS_ENABLED_PROPERTY, false);
//default to "fox,dog"
// default to "fox,dog"
patterns = JiveGlobals.getProperty(PATTERNS_PROPERTY, "fox,dog");
changeContentFilterPatterns();
// default to false
filterStatusEnabled = JiveGlobals.getBooleanProperty(FILTER_STATUS_ENABLED_PROPERTY,
false);
filterStatusEnabled = JiveGlobals.getBooleanProperty(
FILTER_STATUS_ENABLED_PROPERTY, 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, "***");
changeContentFilterMask();
......@@ -435,12 +432,14 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
Packet original = packet;
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,
// as it's an expensive operation
if (violationNotificationEnabled && violationIncludeOriginalPacketEnabled && maskEnabled) {
if (violationNotificationEnabled
&& violationIncludeOriginalPacketEnabled && maskEnabled) {
original = packet.createCopy();
}
......@@ -456,14 +455,14 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
if (Log.isDebugEnabled()) {
Log.debug("Content filter: sending violation notification");
Log.debug("Content filter: include original msg? " +
this.violationIncludeOriginalPacketEnabled);
Log.debug("Content filter: include original msg? "
+ this.violationIncludeOriginalPacketEnabled);
}
//TODO consider spining off a separate thread here,
//in high volume situations, it will result in
//in faster response and notification is not required
//to be real time.
// TODO consider spining off a separate thread here,
// in high volume situations, it will result in
// in faster response and notification is not required
// to be real time.
sendViolationNotification(original);
}
......@@ -471,12 +470,13 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
// some notification to sender, or masked.
if (contentMatched) {
if (maskEnabled) {
//masking enabled, no further action required
// masking enabled, no further action required
if (Log.isDebugEnabled()) {
Log.debug("Content filter: masked content:" + packet.toString());
Log.debug("Content filter: masked content:"
+ packet.toString());
}
} else {
//no masking, msg must be rejected
// no masking, msg must be rejected
if (Log.isDebugEnabled()) {
Log.debug("Content filter: rejecting packet");
}
......@@ -496,36 +496,48 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
}
}
private boolean isValidTargetPacket(Packet packet, boolean read, boolean processed) {
return patternsEnabled && !processed && read &&
(packet instanceof Message ||
(filterStatusEnabled && packet instanceof Presence));
private boolean isValidTargetPacket(Packet packet, boolean read,
boolean processed) {
return patternsEnabled
&& !processed
&& read
&& (packet instanceof Message || (filterStatusEnabled && packet instanceof Presence));
}
private void sendViolationNotification(Packet originalPacket) {
String subject = "Content filter notification! (" + originalPacket.getFrom().getNode() + ")";
String subject = "Content filter notification! ("
+ originalPacket.getFrom().getNode() + ")";
String body = null;
if (originalPacket instanceof Message) {
Message originalMsg = (Message) originalPacket;
body = "Disallowed content detected in message from:"
+ originalMsg.getFrom() + " to:" + originalMsg.getTo()
+ originalMsg.getFrom()
+ " to:"
+ originalMsg.getTo()
+ ", message was "
+ (contentFilter.isMaskingContent() ? "altered." : "rejected.")
+ (violationIncludeOriginalPacketEnabled ?
"\nOriginal subject:" + (originalMsg.getSubject() != null ? originalMsg.getSubject() : "")
+ "\nOriginal content:" + (originalMsg.getBody() != null ? originalMsg.getBody() : "") : "");
+ (contentFilter.isMaskingContent() ? "altered."
: "rejected.")
+ (violationIncludeOriginalPacketEnabled ? "\nOriginal subject:"
+ (originalMsg.getSubject() != null ? originalMsg
.getSubject() : "")
+ "\nOriginal content:"
+ (originalMsg.getBody() != null ? originalMsg
.getBody() : "")
: "");
} else {
//presence
// 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() : "");
+ (contentFilter.isMaskingContent() ? "altered."
: "rejected.")
+ (violationIncludeOriginalPacketEnabled ? "\nOriginal status:"
+ originalPresence.getStatus()
: "");
}
if (violationNotificationByIMEnabled) {
......@@ -564,18 +576,21 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
List<MimeMessage> messages = new ArrayList<MimeMessage>();
try {
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.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);
......@@ -585,10 +600,11 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
messages.add(message);
} catch (Exception e) {
Log.error(e);
}
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