Commit 5cd533d2 by Bach Dániel

firewall: fix TXT record, refactor dns()

parent aa53d585
...@@ -320,39 +320,39 @@ def ipv6_to_arpa(ipv6): ...@@ -320,39 +320,39 @@ def ipv6_to_arpa(ipv6):
# ^ PTR # ^ PTR
# C CNAME # C CNAME
# : generic # : generic
# 'fqdn:s:ttl TXT
def dns(): def generate_ptr_records():
vlans = models.Vlan.objects.all()
# regex = re.compile(r'^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$')
DNS = [] DNS = []
for i_vlan in vlans: for host in models.Host.objects.order_by('vlan').all():
# m = regex.search(i_vlan.net4) rev = host.vlan.reverse_domain
rev = i_vlan.reverse_domain ipv4 = str(host.pub_ipv4 if host.pub_ipv4 and
not host.shared_ip else host.ipv4)
for i_host in i_vlan.host_set.all():
ipv4 = (i_host.pub_ipv4 if i_host.pub_ipv4 and
not i_host.shared_ip else i_host.ipv4)
i = ipv4.split('.', 4) i = ipv4.split('.', 4)
reverse = (i_host.reverse if i_host.reverse and reverse = (host.reverse if host.reverse and
len(i_host.reverse) else i_host.get_fqdn()) len(host.reverse) else host.get_fqdn())
# ipv4 # ipv4
if i_host.ipv4: if host.ipv4:
DNS.append("^%s:%s:%s" % ( DNS.append("^%s:%s:%s" % (
(rev % {'a': int(i[0]), 'b': int(i[1]), 'c': int(i[2]), (rev % {'a': int(i[0]), 'b': int(i[1]), 'c': int(i[2]),
'd': int(i[3])}), 'd': int(i[3])}),
reverse, models.settings['dns_ttl'])) reverse, models.settings['dns_ttl']))
# ipv6 # ipv6
if i_host.ipv6: if host.ipv6:
DNS.append("^%s:%s:%s" % (ipv6_to_arpa(i_host.ipv6), DNS.append("^%s:%s:%s" % (ipv6_to_arpa(str(host.ipv6)),
reverse, models.settings['dns_ttl'])) reverse, models.settings['dns_ttl']))
return DNS
def txt_to_octal(txt):
return '\\' + '\\'.join(['%03o' % ord(x) for x in txt])
for domain in models.Domain.objects.all():
DNS.append("Z%s:%s:support.ik.bme.hu::::::%s" % def generate_records():
(domain.name, settings['dns_hostname'], DNS = []
models.settings['dns_ttl']))
for r in models.Record.objects.all(): for r in models.Record.objects.all():
if r.type == 'A': if r.type == 'A':
...@@ -371,19 +371,39 @@ def dns(): ...@@ -371,19 +371,39 @@ def dns():
'ttl': r.ttl}) 'ttl': r.ttl})
elif r.type == 'PTR': elif r.type == 'PTR':
DNS.append("^%s:%s:%s" % (r.fqdn, r.address, r.ttl)) DNS.append("^%s:%s:%s" % (r.fqdn, r.address, r.ttl))
elif r.type == 'TXT':
DNS.append("'%s:%s:%s" % (r.fqdn,
txt_to_octal(r.address), r.ttl))
return DNS
def dns():
DNS = []
# host PTR record
DNS += generate_ptr_records()
# domain SOA record
for domain in models.Domain.objects.all():
DNS.append("Z%s:%s:support.ik.bme.hu::::::%s" %
(domain.name, settings['dns_hostname'],
models.settings['dns_ttl']))
# records
DNS += generate_records()
return DNS return DNS
def dhcp(): def dhcp():
vlans = models.Vlan.objects.all()
regex = re.compile(r'^([0-9]+)\.([0-9]+)\.[0-9]+\.[0-9]+\s+' regex = re.compile(r'^([0-9]+)\.([0-9]+)\.[0-9]+\.[0-9]+\s+'
r'([0-9]+)\.([0-9]+)\.[0-9]+\.[0-9]+$') r'([0-9]+)\.([0-9]+)\.[0-9]+\.[0-9]+$')
DHCP = [] DHCP = []
# /tools/dhcp3/dhcpd.conf.generated # /tools/dhcp3/dhcpd.conf.generated
for i_vlan in vlans: for i_vlan in models.Vlan.objects.all():
if(i_vlan.dhcp_pool): if(i_vlan.dhcp_pool):
m = regex.search(i_vlan.dhcp_pool) m = regex.search(i_vlan.dhcp_pool)
if(m or i_vlan.dhcp_pool == "manual"): if(m or i_vlan.dhcp_pool == "manual"):
......
...@@ -457,7 +457,6 @@ class Host(models.Model): ...@@ -457,7 +457,6 @@ class Host(models.Model):
type='A').save() type='A').save()
if self.ipv6: if self.ipv6:
print 'aaaaaaaaa', self.ipv6
Record.objects.filter(host=self, name=self.hostname, Record.objects.filter(host=self, name=self.hostname,
type='AAAA').update(address=self.ipv6) type='AAAA').update(address=self.ipv6)
record_count = self.record_set.filter(host=self, record_count = self.record_set.filter(host=self,
...@@ -673,7 +672,7 @@ class Record(models.Model): ...@@ -673,7 +672,7 @@ class Record(models.Model):
verbose_name=_('host')) verbose_name=_('host'))
type = models.CharField(max_length=6, choices=CHOICES_type, type = models.CharField(max_length=6, choices=CHOICES_type,
verbose_name=_('type')) verbose_name=_('type'))
address = models.CharField(max_length=40, address = models.CharField(max_length=200,
verbose_name=_('address')) verbose_name=_('address'))
ttl = models.IntegerField(default=600, verbose_name=_('ttl')) ttl = models.IntegerField(default=600, verbose_name=_('ttl'))
owner = models.ForeignKey(User, verbose_name=_('owner')) owner = models.ForeignKey(User, verbose_name=_('owner'))
...@@ -701,10 +700,12 @@ class Record(models.Model): ...@@ -701,10 +700,12 @@ class Record(models.Model):
val_ipv4(self.address) val_ipv4(self.address)
elif self.type == 'AAAA': elif self.type == 'AAAA':
val_ipv6(self.address) val_ipv6(self.address)
elif self.type in ['CNAME', 'NS', 'PTR', 'TXT']: elif self.type in ['CNAME', 'NS', 'PTR']:
val_domain(self.address) val_domain(self.address)
elif self.type == 'MX': elif self.type == 'MX':
val_mx(self.address) val_mx(self.address)
elif self.type == 'TXT':
pass
else: else:
raise ValidationError(_("Unknown record type.")) raise ValidationError(_("Unknown record type."))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment