Browse Source

Support for DS records

Sebastian Lohff 1 year ago
parent
commit
ef5afbfe3a

+ 3
- 0
bin/dns-sync View File

@@ -105,6 +105,9 @@ def getDomainsFromQueryset(qs, zone, glueRecords, usedNameservers, v4reverse=Fal
105 105
 
106 106
         zone.append((domain.getZone(), "NS", servers))
107 107
 
108
+        if domain.ds_records:
109
+            zone.append((domain.getZone(), "DS", domain.ds_records.split("\n")))
110
+
108 111
         if v4reverse:
109 112
             # for ipv4 reverse we have to do some extra work in case of classless delegations
110 113
             # see RFC2317

+ 33
- 2
domains/forms.py View File

@@ -15,10 +15,41 @@ import re
15 15
 import ipaddress
16 16
 
17 17
 
18
-class DomainForm(MntFormMixin, WhoisObjectFormMixin, forms.ModelForm):
18
+class DSRecordMixin(object):
19
+    ds_re = re.compile(r"^(?P<id>\d+)\s+(?P<crypto>\d+)\s+(?P<hashtype>\d+)\s+(?P<hash>[0-9a-fA-F]+)$")
20
+    HASH_SUPPORTED = (1, 2)
21
+    CRYPTO_SUPPORTED = (3, 5, 6, 8, 10, 13, 15)
22
+
23
+    def clean_ds_records(self):
24
+        ds_records = self.cleaned_data['ds_records'].strip()
25
+        result = []
26
+
27
+        if not ds_records:
28
+            return ''
29
+
30
+        for n, rec in enumerate(ds_records.split("\n"), 1):
31
+            rec = rec.strip()
32
+            m = self.ds_re.match(rec)
33
+            if not m:
34
+                raise forms.ValidationError("Could not parse records {} - needs to be in format "
35
+                                            "'<id> <crypto> <hashtype> <hash>'".format(n))
36
+
37
+            if int(m.group('hashtype')) not in self.HASH_SUPPORTED:
38
+                raise forms.ValidationError("Record {} has an invalid hashtype of {}, supported are {}"
39
+                                            "".format(n, m.group('hashtype'), " ".join(map(str, self.HASH_SUPPORTED))))
40
+            if int(m.group('crypto')) not in self.CRYPTO_SUPPORTED:
41
+                raise forms.ValidationError("Record {} has unsupported crypto {}, supported are {}"
42
+                                            "".format(n, m.group('crypto'), " ".join(map(str, self.CRYPTO_SUPPORTED))))
43
+
44
+            result.append("{id} {crypto} {hashtype} {hash}".format(**m.groupdict()))
45
+
46
+        return "\n".join(result)
47
+
48
+
49
+class DomainForm(MntFormMixin, WhoisObjectFormMixin, DSRecordMixin, forms.ModelForm):
19 50
     class Meta:
20 51
         model = Domain
21
-        fields = ['name', 'nameservers', 'mnt_by', 'admin_c']
52
+        fields = ['name', 'nameservers', 'mnt_by', 'admin_c', 'ds_records']
22 53
 
23 54
     def __init__(self, *args, **kwargs):
24 55
         super(DomainForm, self).__init__(*args, **kwargs)

+ 25
- 0
domains/migrations/0004_auto_20170403_0533.py View File

@@ -0,0 +1,25 @@
1
+# -*- coding: utf-8 -*-
2
+# Generated by Django 1.10.5 on 2017-04-03 05:33
3
+from __future__ import unicode_literals
4
+
5
+from django.db import migrations, models
6
+
7
+
8
+class Migration(migrations.Migration):
9
+
10
+    dependencies = [
11
+        ('domains', '0003_auto_20170322_1801'),
12
+    ]
13
+
14
+    operations = [
15
+        migrations.AlterField(
16
+            model_name='domain',
17
+            name='mnt_by',
18
+            field=models.ManyToManyField(help_text='You can select multiple maintainers here', to='whoisdb.Maintainer'),
19
+        ),
20
+        migrations.AlterField(
21
+            model_name='nameserver',
22
+            name='mnt_by',
23
+            field=models.ManyToManyField(help_text='You can select multiple maintainers here', to='whoisdb.Maintainer'),
24
+        ),
25
+    ]

+ 20
- 0
domains/migrations/0005_domain_ds_records.py View File

@@ -0,0 +1,20 @@
1
+# -*- coding: utf-8 -*-
2
+# Generated by Django 1.11 on 2019-05-30 21:18
3
+from __future__ import unicode_literals
4
+
5
+from django.db import migrations, models
6
+
7
+
8
+class Migration(migrations.Migration):
9
+
10
+    dependencies = [
11
+        ('domains', '0004_auto_20170403_0533'),
12
+    ]
13
+
14
+    operations = [
15
+        migrations.AddField(
16
+            model_name='domain',
17
+            name='ds_records',
18
+            field=models.TextField(blank=True),
19
+        ),
20
+    ]

+ 3
- 0
domains/models.py View File

@@ -50,6 +50,9 @@ class Domain(MntdObject):
50 50
     nameservers = models.ManyToManyField(Nameserver, blank=True)
51 51
     admin_c = models.ManyToManyField(Contact)
52 52
 
53
+    ds_records = models.TextField(blank=True, verbose_name='DS Records',
54
+                                  help_text='DS Records in the format of [id] [crypto-algo] [hash-algo] [hash]')
55
+
53 56
     def getPK(self):
54 57
         return self.name
55 58
 

+ 1
- 1
whoisdb/helpers.py View File

@@ -39,7 +39,7 @@ def getWhoisObjectFields(obj, owner):
39 39
         fields.append(("Address CIDR", obj.prefix()))
40 40
         _addFields(fields, obj, ["description", "parent_range", "origin_as", "mnt_by", "mnt_lower", "admin_c"])
41 41
     elif c == domains.models.Domain:
42
-        _addFields(fields, obj, ["name", "nameservers", "mnt_by", "admin_c"])
42
+        _addFields(fields, obj, ["name", "nameservers", "mnt_by", "admin_c", "ds_records"])
43 43
     elif c == domains.models.Nameserver:
44 44
         _addFields(fields, obj, ["name", "glueIPv4", "glueIPv6", "mnt_by", "admin_c"])
45 45
     elif c == domains.models.ReverseZone:

Loading…
Cancel
Save