def handle(self, filename, *args, **options): zone = dns.zone.from_file(filename) domain = Domain(name=str(zone.origin).strip('.'), type='MASTER') domain.save() for entry in zone: node = zone[entry] name = str(entry.choose_relativity(zone.origin, False)).strip('.') for rdataset in node: qtype = dns.rdatatype.to_text(rdataset.rdtype) ttl = rdataset.ttl for rdata in rdataset: prio = None if qtype == 'MX': prio = rdata.preference content = str( rdata.exchange.choose_relativity( zone.origin, False)) elif qtype == 'TXT': content = b'\n'.join(rdata.strings) elif qtype == 'CNAME': content = rdata.to_text(zone.origin, False).strip('.') else: content = rdata.to_text(zone.origin, False) record = Record( domain=domain, name=name, type=qtype, ttl=ttl, prio=prio, content=content, ) record.save()
def handle(self, filename, *args, **options): zone = dns.zone.from_file(filename) domain = Domain(name=str(zone.origin).strip('.'), type='MASTER') domain.save() for entry in zone: node = zone[entry] name = str(entry.choose_relativity(zone.origin, False)).strip('.') for rdataset in node: qtype = dns.rdatatype.to_text(rdataset.rdtype) ttl = rdataset.ttl for rdata in rdataset: prio = None if qtype == 'MX': prio = rdata.preference content = str(rdata.exchange.choose_relativity( zone.origin, False)) elif qtype == 'TXT': content = b'\n'.join(rdata.strings) elif qtype == 'CNAME': content = rdata.to_text(zone.origin, False).strip('.') else: content = rdata.to_text(zone.origin, False) record = Record( domain=domain, name=name, type=qtype, ttl=ttl, prio=prio, content=content, ) record.save()
def setUp(self): self.domain = Domain(name='example.com') self.domain.save() self.user = User.objects.create_user('user', '*****@*****.**', 'password')
class DNSHistoryTest(TestCase): def setUp(self): self.domain = Domain(name='example.com') self.domain.save() self.user = User.objects.create_user('user', '*****@*****.**', 'password') def tearDown(self): self.domain.delete() self.user.delete() @skip("Broken signals not being called") def test_record_create(self): record = Record( name='hostname.example.com', type='A', content='127.0.0.1', domain=self.domain, ) record.saving_user = self.user record.save() history = DNSHistory.objects.get( record_name='hostname.example.com', field_name='name', user=self.user, ) self.assertEqual(history.old_value, '') self.assertEqual(history.new_value, 'hostname.exmaple.com') history = DNSHistory.objects.get( record_name='hostname.example.com', field_name='content', user=self.user, ) self.assertEqual(history.old_value, '') self.assertEqual(history.new_value, '127.0.0.1') def test_record_modify(self): record = Record( name='hostname.example.com', type='A', content='127.0.0.1', domain=self.domain, ) record.saving_user = self.user record.save() DNSHistory.objects.all().delete() record.content = '127.0.1.1' record.save() history = DNSHistory.objects.get( record_name='hostname.example.com', field_name='content', user=self.user, ) self.assertEqual(history.old_value, '127.0.0.1') self.assertEqual(history.new_value, '127.0.1.1') @skip("Broken signals not being called") def test_record_delete(self): record = Record( name='hostname.example.com', type='A', content='127.0.0.1', domain=self.domain, ) record.saving_user = self.user record.save() DNSHistory.objects.all().delete() record.delete() history = DNSHistory.objects.get( record_name='hostname.example.com', field_name='delete', user=self.user, ) self.assertEqual(history.old_value, '127.0.0.1') self.assertEqual(history.new_value, '')