Last active
August 29, 2015 14:10
-
-
Save cb1kenobi/16e6b5acdc387e03eb31 to your computer and use it in GitHub Desktop.
Postfix CIDR blocklist update script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
get-spam-blocklist > /etc/postfix/client.cidr | |
postfix reload |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Create the above
get-spam-blocklist
andupdate-spam-blocklist
files in your/usr/local/bin
directory.Then add a cron job: