DNSRBLHandlerpublic class DNSRBLHandler extends org.apache.avalon.framework.logger.AbstractLogEnabled implements ConnectHandler, org.apache.avalon.framework.configuration.ConfigurableConnect handler for DNSRBL processing |
Fields Summary |
---|
private String[] | whitelistThe lists of rbl servers to be checked to limit spam | private String[] | blacklist |
Methods Summary |
---|
public boolean | checkDNSRBL(SMTPSession session, java.lang.String ipAddress)
/*
* don't check against rbllists if the client is allowed to relay..
* This whould make no sense.
*/
if (session.isRelayingAllowed()) {
getLogger().info("Ipaddress " + session.getRemoteIPAddress() + " is allowed to relay. Don't check it");
return false;
}
if (whitelist != null || blacklist != null) {
StringBuffer sb = new StringBuffer();
StringTokenizer st = new StringTokenizer(ipAddress, " .", false);
while (st.hasMoreTokens()) {
sb.insert(0, st.nextToken() + ".");
}
String reversedOctets = sb.toString();
if (whitelist != null) {
String[] rblList = whitelist;
for (int i = 0 ; i < rblList.length ; i++) try {
java.net.InetAddress addr = org.apache.james.dnsserver.DNSServer.getByName(reversedOctets + rblList[i]);
if (getLogger().isInfoEnabled()) {
getLogger().info("Connection from " + ipAddress + " whitelisted by " + rblList[i]);
}
/* Ihis code may be helpful if admins need to debug why they are getting weird
behavior from the blocklists. Also, it might help them to know what IP is
returned, since zones often use that to indicate interesting information.
The next version of this code already handles the associated TXT record,
so this code is just temporary for this release.
*/
if (getLogger().isDebugEnabled()) {
getLogger().debug("Whitelist addr = " + addr.toString());
}
return false;
} catch (java.net.UnknownHostException uhe) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("unknown host exception thrown:" + reversedOctets + rblList[i]);
}
}
}
if (blacklist != null) {
String[] rblList = blacklist;
for (int i = 0 ; i < rblList.length ; i++) try {
java.net.InetAddress addr = org.apache.james.dnsserver.DNSServer.getByName(reversedOctets + rblList[i]);
if (getLogger().isInfoEnabled()) {
getLogger().info("Connection from " + ipAddress + " restricted by " + rblList[i] + " to SMTP AUTH/postmaster/abuse.");
}
/* Ihis code may be helpful if admins need to debug why they are getting weird
behavior from the blocklists. Also, it might help them to know what IP is
returned, since zones often use that to indicate interesting information.
The next version of this code already handles the associated TXT record,
so this code is just temporary for this release.
*/
if (getLogger().isDebugEnabled()) {
getLogger().debug("Blacklist addr = " + addr.toString());
}
return true;
} catch (java.net.UnknownHostException uhe) {
// if it is unknown, it isn't blocked
if (getLogger().isDebugEnabled()) {
getLogger().debug("unknown host exception thrown:" + reversedOctets + rblList[i]);
}
}
}
}
return false;
| public void | configure(org.apache.avalon.framework.configuration.Configuration handlerConfiguration)
Configuration rblserverConfiguration = handlerConfiguration.getChild("rblservers", false);
if ( rblserverConfiguration != null ) {
ArrayList rblserverCollection = new ArrayList();
Configuration[] children = rblserverConfiguration.getChildren("whitelist");
if ( children != null ) {
for ( int i = 0 ; i < children.length ; i++ ) {
String rblServerName = children[i].getValue();
rblserverCollection.add(rblServerName);
if (getLogger().isInfoEnabled()) {
getLogger().info("Adding RBL server to whitelist: " + rblServerName);
}
}
if (rblserverCollection != null && rblserverCollection.size() > 0) {
whitelist = (String[]) rblserverCollection.toArray(new String[rblserverCollection.size()]);
rblserverCollection.clear();
}
}
children = rblserverConfiguration.getChildren("blacklist");
if ( children != null ) {
for ( int i = 0 ; i < children.length ; i++ ) {
String rblServerName = children[i].getValue();
rblserverCollection.add(rblServerName);
if (getLogger().isInfoEnabled()) {
getLogger().info("Adding RBL server to blacklist: " + rblServerName);
}
}
if (rblserverCollection != null && rblserverCollection.size() > 0) {
blacklist = (String[]) rblserverCollection.toArray(new String[rblserverCollection.size()]);
rblserverCollection.clear();
}
}
}
| public void | onConnect(SMTPSession session)
boolean blocklisted = checkDNSRBL(session, session.getRemoteIPAddress());
session.setBlockListed(blocklisted);
|
|