Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #5

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions py-hole-bind9RPZ
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,18 @@ parser.add_argument(
help='Configuration file to use (default: /etc/bind/py-hole-bind9RPZ_config.yaml)',
default='/etc/bind/py-hole-bind9RPZ_config.yaml'
)
parser.add_argument(
'-o','--output_dir', type =str,
help='Output dir if zones files (default: /var/local/bindRPZ)',
default='/var/local/bindRPZ'
)
args = parser.parse_args()

# read config
CONFIGFILE = args.config
config = {
# base config overridden by CONFIGFILE
'cachedir': '/var/local/bindRPZ',
'cachedir': args.output_dir,
'cacheprefix': 'bindRPZcache-',
'cacheexpire': 14400, # 4 hours
'defaultresponse': 'CNAME .',
Expand All @@ -64,7 +69,7 @@ config = {
# load yaml file or error
if os.path.isfile(CONFIGFILE):
with open(CONFIGFILE, 'rt') as f:
config.update(yaml.load(f))
config.update(yaml.load(f, Loader=yaml.FullLoader))
# always exclude localhost else we get it blocked for 127.0.0.1 keys
config['exclusions']['localhost'] = True
else:
Expand Down Expand Up @@ -130,7 +135,11 @@ class ZoneFile(object):
"""
with open(self.config['rpzfile'] + '.TMP', 'wt') as f_rpz:
f_rpz.write(self.outputdata)
os.rename(self.config['rpzfile'], self.config['rpzfile'] + '.old')

try:
os.rename(self.config['rpzfile'], self.config['rpzfile'] + '.old')
except FileNotFoundError:
print("Can't find .old file")
os.rename(self.config['rpzfile'] + '.TMP', self.config['rpzfile'])


Expand Down Expand Up @@ -214,4 +223,7 @@ if 'localblacklist' in config:
# write the config['rpzfile'] file
zone.write()
# reload bind zone file
subprocess.Popen(config['reloadzonecommand'], stdin=None, stdout=None)
try:
subprocess.Popen(config['reloadzonecommand'], stdin=None, stdout=None)
except FileNotFoundError:
print("Coudln't find 'rndc'. Local run ?")
6 changes: 2 additions & 4 deletions py-hole-bind9RPZ_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ rpztemplate: |
; name server is never accessed but out-of-zone
; NS nonexistant.nodomain.none
NS dnsserver.example.com.

;example.net CNAME .
;*.example.net CNAME .

; Automatic rules start
;
# end of template
Expand All @@ -35,7 +35,6 @@ blacklists:
hostskey: 0.0.0.0
malwaredomains: { url: 'https://mirror1.malwaredomains.com/files/justdomains', format: raw }
cameleon: { 'url':'http://sysctl.org/cameleon/hosts', 'format':'hosts', 'hostskey':'127.0.0.1' }
abuse.ch: { 'url':'https://zeustracker.abuse.ch/blocklist.php?download=domainblocklist', 'format':'raw' }
disconnect.me_tracking: { 'url':'https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt', 'format':'raw' }
disconnect.me_ad: { 'url':'https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt', 'format':'raw' }
# hosts-file.net: { 'url':'https://hosts-file.net/ad_servers.txt', 'format':'hosts0000' }
Expand All @@ -62,4 +61,3 @@ exclusions:
# we can also add our own local backlist
#localblacklist:
# - evilhost.example.com # going there does evil stuff