def test_load_zone_file(self): original_zone_text = open('bind/data/testzones/db.bindcontroller.com').read() print(original_zone_text) z = zone.from_file('bind/data/testzones/db.bindcontroller.com') loaded_zone_text = z.to_text() self.assertNotEquals(original_zone_text, loaded_zone_text)
def RecordSetsFromZoneFile(zone_file, domain, api_version='v1'): """Returns record-sets for the given domain imported from the given zone file. Args: zone_file: file, The zone file with records for the given domain. domain: str, The domain for which record-sets should be obtained. api_version: [str], the api version to use for creating the records. Returns: A (name, type) keyed dict of ResourceRecordSets that were obtained from the zone file. Note that only A, AAAA, CNAME, MX, PTR, SOA, SPF, SRV, and TXT record-sets are retrieved. Other record-set types are not supported by Cloud DNS. Also, the master NS field for SOA records is discarded since that is provided by Cloud DNS. """ zone_contents = zone.from_file(zone_file, domain, check_origin=False) record_sets = {} for name, rdset in zone_contents.iterate_rdatasets(): record_set = _RecordSetFromZoneRecord(name, rdset, zone_contents.origin, api_version=api_version) if record_set: record_sets[(record_set.name, record_set.type)] = record_set return record_sets
def collect_rev_svn_zone(rev_domain, rev_zone_path, relative_zone_path): rev_root_domain = "{0}.IN-ADDR.ARPA".format('.'.join( list(reversed(rev_domain.split('.'))))) cwd = os.getcwd() os.chdir(relative_zone_path) rzone = zone.from_file(rev_zone_path, rev_root_domain, relativize=False) os.chdir(cwd) return rzone
def _parse(filename): if filename == "-": fp = sys.stdin else: fp = open(filename, "r") z = zone.from_file(fp, check_origin=False) fp.close() return z
def getSerial(self, zonefilepath): import traceback from dns import zone, rdatatype, rdataset, rdata try: zoneinfo = zone.from_file(zonefilepath, check_origin=False) soaset = zoneinfo.get_rdataset(zoneinfo.origin, rdatatype.SOA) if len(soaset) > 0: return soaset[0].serial + 1 except: d = int(time.time()) return '%s' % (d)
def _parse_zones(self): try: pz = zone_parser.from_file(self.policy_zone, origin='.', relativize=False, check_origin=False) except: if not self.quiet: self._view.error('Invalid policy zone file') return None, None try: fz = zone_parser.from_file(self.fake_zone, origin='.', relativize=False, check_origin=False) except: if not self.quiet: self._view.error('Invalid fake zone file') return None, None return fz, pz
def getSerial(self, zonefilepath): import traceback from dns import zone, rdatatype, rdataset, rdata try: zoneinfo = zone.from_file(zonefilepath, check_origin=False) soaset = zoneinfo.get_rdataset(zoneinfo.origin, rdatatype.SOA) if len(soaset) > 0: return soaset[0].serial + 1 except: d = int(time.time()) return "%s" % (d)
def get_zone_data(domain, filepath, dirpath, rtype=None): log("domain = '{0}'\nfilepath = '{1}'\ndirpath = '{2}'\n".format(domain, filepath, dirpath), DEBUG) cwd = os.getcwd() os.chdir(dirpath) if rtype is None: return None rzone = zone.from_file(filepath, domain, relativize=False) data = [] for (name, ttl, rdata) in rzone.iterate_rdatas(rtype): data.append((str(name), str(rdata))) os.chdir(cwd) return (rzone, data)
def get_zone_data(domain, filepath, dirpath, rtype=None): log( "domain = '{0}'\nfilepath = '{1}'\ndirpath = '{2}'\n".format( domain, filepath, dirpath), DEBUG) cwd = os.getcwd() os.chdir(dirpath) if rtype is None: return None rzone = zone.from_file(filepath, domain, relativize=False) data = [] for (name, ttl, rdata) in rzone.iterate_rdatas(rtype): data.append((str(name), str(rdata))) os.chdir(cwd) return (rzone, data)
def increment_zone(config): zone = from_file(config.bind_master, config.domain_base) serial = None for _, _, rdata in zone.iterate_rdatas(SOA): if serial: raise ValueError("Saw multiple SOA") serial = rdata.serial # :)))) with open(config.bind_master, 'r+') as file: contents = file.read().replace(str(serial), str(serial + 1)) file.seek(0) file.truncate(0) file.write(contents) print("Zone incremented from {} to {}".format(serial, serial + 1))
def RecordSetsFromZoneFile(zone_file, domain): """Returns record-sets for the given domain imported from the given zone file. Args: zone_file: file, The zone file with records for the given domain. domain: str, The domain for which record-sets should be obtained. Returns: A (name, type) keyed dict of ResourceRecordSets that were obtained from the zone file. Note that only A, AAAA, CNAME, MX, PTR, SOA, SPF, SRV, and TXT record-sets are retrieved. Other record-set types are not supported by Cloud DNS. Also, the master NS field for SOA records is discarded since that is provided by Cloud DNS. """ zone_contents = zone.from_file(zone_file, domain, check_origin=False) record_sets = {} for name, rdset in zone_contents.iterate_rdatasets(): record_set = _RecordSetFromZoneRecord(name, rdset, zone_contents.origin) if record_set: record_sets[(record_set.name, record_set.type)] = record_set return record_sets
def delete(self): session = self.request.session; try: rzone = session['rzone']; except NameError: return HTTPFound('/dns/zones'); try: oname = session['rname']; rtype = session['rtype']; odata = session['rdata']; rclass = session['rclass']; except NameError: return HTTPFound('/dns/zone/{}'.format(rzone)); namedconf = tutuconfig.get('namedconf', 'dnsbind'); ncp = NamedConfParser(); ncp.from_file(namedconf); zonefile = ncp.find_zone_file(rzone); z = zone.from_file(zonefile); dset = z.get_rdataset(oname, rtype); newdset = dns.rdataset.Rdataset(rdc.from_text(rclass), rdt.from_text(rtype)); newdset.ttl = 300; if rtype == 'SOA': newdset.add(rdata); else: for rd in dset: if odata == rd.to_text(): pass else: newdset.add(rd); z.replace_rdataset(oname, newdset); tutuzone.save_zone(z, zonefile); return HTTPFound('/dns/zone/{}'.format(rzone)); # vim: set ts=2:
def get_zone_data(zone_name, filepath, dirpath): cwd = os.getcwd() os.chdir(dirpath) mzone = zone.from_file(filepath, zone_name, relativize=False) os.chdir(cwd) return mzone
def collect_svn_zone(root_domain, zone_path, relative_zone_path): cwd = os.getcwd() os.chdir(relative_zone_path) rzone = zone.from_file(zone_path, root_domain, relativize=False) os.chdir(cwd) return rzone