From 495f7a8e4c9a37e87b9032d1322386e5c7f41127 Mon Sep 17 00:00:00 2001 From: Glen Pit-Pladdy Date: Tue, 11 Apr 2017 12:17:23 +0100 Subject: [PATCH] Introduce local blacklists --- py-hole-bind9RPZ | 15 +++++++++++---- py-hole-config.yaml | 4 ++++ py-hole-dnsmasq | 14 ++++++++++---- py-hole-rpzconfig.yaml | 4 ++++ 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/py-hole-bind9RPZ b/py-hole-bind9RPZ index ea40f24..bbf05a5 100755 --- a/py-hole-bind9RPZ +++ b/py-hole-bind9RPZ @@ -90,9 +90,9 @@ for source in config['blacklists']: # all done data = response.data # we are good to go - outputdata += ";=============================================================================\n" - outputdata += "; Source: %s :: %s\n" % (source,config['blacklists'][source]['url']) - outputdata += ";=============================================================================\n\n" + outputdata += "\n%s=============================================================================\n" % commentstart + outputdata += "%s Source: %s :: %s\n" % (commentstart,source,config['blacklists'][source]['url']) + outputdata += "%s=============================================================================\n\n" % commentstart # process data recordcount = 0 if config['blacklists'][source]['format'] == 'hosts': @@ -110,7 +110,6 @@ for source in config['blacklists']: for host in hostlist[1:]: recordcount += 1 addhost ( host ) - seenbefore[host.lower()] = source elif config['blacklists'][source]['format'] == 'raw': # comments start "#" for line in data.splitlines(): @@ -127,6 +126,14 @@ for source in config['blacklists']: if recordcount == 0: sys.exit ( "Got recordcount of %d for %s" % (recordcount,source) ) +# if we have a local blacklist, add that also +if 'localblacklist' in config: + outputdata += "\n%s=============================================================================\n" % commentstart + outputdata += "%s Source: Local blacklist from %s\n" % (commentstart,configfile) + outputdata += "%s=============================================================================\n\n" % commentstart + for host in config['localblacklist']: + addhost ( host ) + # write the config['rpzfile'] file with open ( config['rpzfile']+'.TMP', 'wt' ) as f: diff --git a/py-hole-config.yaml b/py-hole-config.yaml index 497a1a3..4aadb77 100644 --- a/py-hole-config.yaml +++ b/py-hole-config.yaml @@ -37,3 +37,7 @@ exclusions: pagead.l.doubleclick.net: True # CNAME for www.googleadservices.com needed for google shopping # Note that "localhost" is always excluded t prevent conflicts +# we can also add our own local backlist +#localblacklist: +# - evilhost.example.com # going there does evil stuff + diff --git a/py-hole-dnsmasq b/py-hole-dnsmasq index c8f95f2..1e467f2 100755 --- a/py-hole-dnsmasq +++ b/py-hole-dnsmasq @@ -96,9 +96,9 @@ for source in config['blacklists']: # all done data = response.data # we are good to go - outputdata += "#=============================================================================\n" - outputdata += "# Source: %s :: %s\n" % (source,config['blacklists'][source]['url']) - outputdata += "#=============================================================================\n\n" + outputdata += "\n%s=============================================================================\n" % commentstart + outputdata += "%s Source: %s :: %s\n" % (commentstart,source,config['blacklists'][source]['url']) + outputdata += "%s=============================================================================\n\n" % commentstart # process data recordcount = 0 if config['blacklists'][source]['format'] == 'hosts': @@ -116,7 +116,6 @@ for source in config['blacklists']: for host in hostlist[1:]: recordcount += 1 addhost ( host ) - seenbefore[host.lower()] = source elif config['blacklists'][source]['format'] == 'raw': # comments start "#" for line in data.splitlines(): @@ -133,6 +132,13 @@ for source in config['blacklists']: if recordcount == 0: sys.exit ( "Got recordcount of %d for %s" % (recordcount,source) ) +# if we have a local blacklist, add that also +if 'localblacklist' in config: + outputdata += "\n%s=============================================================================\n" % commentstart + outputdata += "%s Source: Local blacklist from %s\n" % (commentstart,configfile) + outputdata += "%s=============================================================================\n\n" % commentstart + for host in config['localblacklist']: + addhost ( host ) # write the config['hostsfile'] file with open ( config['hostsfile']+'.TMP', 'wt' ) as f: diff --git a/py-hole-rpzconfig.yaml b/py-hole-rpzconfig.yaml index 752917a..56ff275 100644 --- a/py-hole-rpzconfig.yaml +++ b/py-hole-rpzconfig.yaml @@ -55,3 +55,7 @@ exclusions: pagead.l.doubleclick.net: True # CNAME for www.googleadservices.com needed for google shopping # Note that "localhost" is always excluded t prevent conflicts +# we can also add our own local backlist +#localblacklist: +# - evilhost.example.com # going there does evil stuff +