From b34f07f89f3c4dafd922f0fa94637a47202bfe42 Mon Sep 17 00:00:00 2001 From: Daniel Washburn Date: Wed, 28 Dec 2016 10:45:58 -0500 Subject: Break configuration out to a separate file --- config.py | 12 ++++++++++++ zoneupdate.py | 20 +++++++++++--------- 2 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 config.py diff --git a/config.py b/config.py new file mode 100644 index 0000000..9502668 --- /dev/null +++ b/config.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python + +CONFIG = {} + +# The origin of the zone file +CONFIG['origin'] = 'example.org' + +# The zone file itself +CONFIG['zonefile'] = './example.org.zone' + +# Should return the external IP address of the current host +CONFIG['lookup_url'] = 'http://ipv4.example.org/' diff --git a/zoneupdate.py b/zoneupdate.py index e011d74..215709c 100644 --- a/zoneupdate.py +++ b/zoneupdate.py @@ -4,31 +4,33 @@ import dns.zone import dns.resolver from urllib2 import urlopen -origin = 'roamingmonkey.org' -zonefile = './roamingmonkey.org.zone' +from config import CONFIG + +origin = CONFIG['origin'] +zonefile = CONFIG['zonefile'] zone = dns.zone.from_file(zonefile, origin) # Fetch our external IP address -url = urlopen('http://ipv4.rmky.org/ip.php') +url = urlopen(CONFIG['lookup_url']) ip4 = url.read().strip() url.close() -banana_A = zone.find_rdataset('banana', 'A') -banana_TXT = zone.find_rdataset('banana', 'TXT') +A = zone.find_rdataset(CONFIG['host'], 'A') +TXT = zone.find_rdataset(CONFIG['host'], 'TXT') -for rdata in banana_A: +for rdata in A: # Don't do anything unless the the IPv4 address in the zone file is wrong if not rdata.address == ip4: rdata.address = ip4 # Remove any existing TXT record(s) and replace with a new one # Method for adding gleaned from https://github.com/vimalloc/easyzone/blob/master/easyzone/easyzone.py - for txtdata in banana_TXT: - banana_TXT.remove(txtdata) + for txtdata in TXT: + TXT.remove(txtdata) txt = 'v=spf1 ip4:' + ip4 + ' -all' rd = dns.rdtypes.ANY.TXT.TXT(dns.rdataclass.IN, dns.rdatatype.TXT, txt) - banana_TXT.add(rd) + TXT.add(rd) # Fetch the serial number that the world sees and leapfrog it. # The serial number we set here has to be higher than the DNSSEC signed -- cgit v1.2.2