Skip to content

Instantly share code, notes, and snippets.

@cb1kenobi
Last active August 29, 2015 14:10
Show Gist options
  • Save cb1kenobi/16e6b5acdc387e03eb31 to your computer and use it in GitHub Desktop.
Save cb1kenobi/16e6b5acdc387e03eb31 to your computer and use it in GitHub Desktop.
Postfix CIDR blocklist update script
#!/usr/bin/env node
var http = require('http');
http.get({
hostname: 'www.spamhaus.org',
port: 80,
path: '/drop/drop.lasso'
}, function (res) {
if (res.statusCode !== 200) {
console.error('Failed to download http://www.spamhaus.org/drop/drop.lasso');
process.exit(1);
}
var buffer = '';
res.setEncoding('utf8');
res.on('data', function (chunk) {
buffer += chunk.toString();
});
res.on('end', function () {
var list = buffer.trim().split('\n').map(function (line) {
if (line.indexOf(';') <= 0) return;
var s = line.split(';')[0].trim();
if (s) {
return s + ' REJECT';
}
}).filter(function (line) { return line; }).join('\n');
console.log(list);
});
});
#!/bin/bash
get-spam-blocklist > /etc/postfix/client.cidr
postfix reload
@cb1kenobi
Copy link
Author

Create the above get-spam-blocklist and update-spam-blocklist files in your /usr/local/bin directory.

Then add a cron job:

sudo ln -s /usr/local/bin/update-spam-blocklist /etc/cron.daily/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment