Python: Blacklist Updater for Endian Firewall 2.3
Posted on Jan 21st, 2010Here's a Python script I wrote for Endian Firewall 2.3. It updates the current blacklist categories and domains using Shallalist.
View the forum discussion on EFW Support.
#!/usr/bin/python
import urllib2
import os
print 'Blacklist Updater for EFW 2.3'
print 'Written by Gavin Vickery '
print '=' * 30
sourceURL = 'http://www.shallalist.de/Downloads/shallalist.tar.gz'
sourceFile = 'shallist.tar.gz'
blacklistDir = '/etc/dansguardian/blacklists/'
categoryFile = blacklistDir + 'categories'
# ==========================================================
# Download blacklist file from shallalist.de
# ==========================================================
print 'Stage 1 of 5 | Downloading blacklist, please wait...'
source = urllib2.urlopen(sourceURL)
local = open(sourceFile, 'w')
local.write(source.read())
local.close()
# =========================================================
# Extract TAR using system commands
# =========================================================
print 'Stage 2 of 5 | Extracting files'
os.system('tar -xzf %s' % sourceFile)
# =========================================================
# Clear old files and copy new files
# =========================================================
print 'Stage 3 of 5 | Updating blacklist'
os.system('rm -rf %s*' % blacklistDir)
os.system('cp -ru BL/* %s' % blacklistDir)
os.system('rm %sglobal_usage' % blacklistDir)
os.system('rm %sCOPYRIGHT' % blacklistDir)
# =========================================================
# Add directory names to new category file
# =========================================================
print 'Stage 4 of 5 | Updating categories'
categoryTMP = open(categoryFile, 'a')
for i in os.listdir(blacklistDir):
categoryTMP.write('%s=%s ' % (i.capitalize(), i))
categoryTMP.close()
# =========================================================
# Clean up downloaded files
# =========================================================
print 'Stage 5 of 5 | Cleaning up'
os.system('rm %s' % sourceFile)
os.system('rm -rf BL')
print '=' * 30
print 'All done! Enjoy ;)'