Skip to content

Commit a45a1fa

Browse files
committed
Minimal dnsbl support in config.js
Signed-off-by: Radu Rendec <radu.rendec@mindbit.ro>
1 parent c0491dd commit a45a1fa

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

config.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@ SmtpServer.FILTER_ACCEPT = 0;
9696
SmtpServer.FILTER_REJECT_TEMPORARILY = 1;
9797
SmtpServer.FILTER_REJECT_PERMANENTLY = 2;
9898

99+
// List of DNSBL domains:
100+
// - first element is the DNSBL domain name
101+
// - second element (optional) is a callback function // TODO
102+
// - remaining elements (optional) are passed to the callback function // TODO
103+
SmtpServer.dnsbl = [
104+
["zen.spamhaus.org"], // Free for "private mail systems with low traffic";
105+
// https://www.spamhaus.org/organization/dnsblusage/
106+
["rbl.abuse.ro"], // Open; http://abuse.ro/#three
107+
//["b.barracudacentral.org"], // Open; requires registation;
108+
// http://barracudacentral.org/rbl
109+
];
110+
99111
SmtpServer.prototype.relayCmd = function(cmd, args)
100112
{
101113
this.smtpClient.sendCommand(cmd, args);
@@ -209,6 +221,25 @@ SmtpServer.prototype.filter = function(headers, body) {
209221
return SmtpServer.FILTER_REJECT_PERMANENTLY;
210222
}
211223

224+
for (var i in SmtpServer.dnsbl) {
225+
var dnsbl = SmtpServer.dnsbl[i];
226+
var raddr = Dns.revAddr(this.remoteAddr, dnsbl[0]);
227+
var result = Dns.query(raddr, Dns.t_a);
228+
if (typeof(result) == "number") {
229+
Sys.log(Sys.LOG_DEBUG, "DNSBL: pass " + raddr + " (" + result + ")");
230+
continue;
231+
}
232+
var rlist = [];
233+
for (var j in result.answer) {
234+
var rr = result.answer[j];
235+
if (rr.type = Dns.t_a && rr.name.toLowerCase() == raddr.toLowerCase())
236+
rlist.push(rr.data);
237+
}
238+
// TODO if `dnsbl` defines a callback function, call it and pass rlist
239+
Sys.log(Sys.LOG_DEBUG, "DNSBL: reject " + raddr + " (" + rlist.join() + ")");
240+
return SmtpServer.FILTER_REJECT_PERMANENTLY;
241+
}
242+
212243
return SmtpServer.FILTER_ACCEPT;
213244
}
214245

0 commit comments

Comments
 (0)