Commits

George Notaras  committed 70feeeb

Added support for configurable list of enabled RR types.

This involves the RR type choices in the Record model and the enabled record inlines in the Domain ModelAdmin.

  • Participants
  • Parent commits cec0d03

Comments (0)

Files changed (4)

 - Database schema is DNSSEC enabled.
 - Automatic zone-rectify support using native python code.
 - Zone file import through web form (experimental)
+- Configurable enabled RR types
 
 
 TODO: Add more info

File src/powerdns_manager/admin.py

 from django.utils.translation import ugettext_lazy as _
 
 
+from powerdns_manager import settings
+
 from powerdns_manager.forms import SoaRecordModelForm
 from powerdns_manager.forms import NsRecordModelForm
 from powerdns_manager.forms import MxRecordModelForm
     verbose_name_plural = 'Crypto Keys'
 
 
+
+
 class DomainAdmin(admin.ModelAdmin):
     #form = DomainModelForm
     #actions = [test_action, ]
     list_display = ('name', 'type', 'master', 'date_modified')
     list_filter = ('type', )
     search_fields = ('name', 'master')
-    inlines = [
-        # RR
-        SoaRecordInline,
-        NsRecordInline,
-        MxRecordInline,
-        ARecordInline,
-        AaaaRecordInline,
-        CnameRecordInline,
-        PtrRecordInline,
-        TxtRecordInline,
-        SrvRecordInline,
-        DsRecordInline,
-        CertRecordInline,
-        HinfoRecordInline,
-        LocRecordInline,
-        SpfRecordInline,
-        SshfpRecordInline,
-        RpRecordInline,
-        NaptrRecordInline,
-        AfsdbRecordInline,
-        DnskeyRecordInline,
-        KeyRecordInline,
-        NsecRecordInline,
-        RrsigRecordInline,
-        # Other
-        DomainMetadataInline,
-        CryptoKeyInline,
-    ]
     verbose_name = 'zone'
     verbose_name_plural = 'zones'
     save_on_top = True
     
+#    inlines = [
+#        # RR
+#        SoaRecordInline,
+#        NsRecordInline,
+#        MxRecordInline,
+#        ARecordInline,
+#        AaaaRecordInline,
+#        CnameRecordInline,
+#        PtrRecordInline,
+#        TxtRecordInline,
+#        SrvRecordInline,
+#        DsRecordInline,
+#        CertRecordInline,
+#        HinfoRecordInline,
+#        LocRecordInline,
+#        SpfRecordInline,
+#        SshfpRecordInline,
+#        RpRecordInline,
+#        NaptrRecordInline,
+#        AfsdbRecordInline,
+#        DnskeyRecordInline,
+#        KeyRecordInline,
+#        NsecRecordInline,
+#        RrsigRecordInline,
+#        # Other
+#        DomainMetadataInline,
+#        CryptoKeyInline,
+#    ]
+    
+    #
+    # Build the ``inlines`` list. Only inlines for enabled RR types are included.
+    # 
+    inlines = []
+    
+    # Resource Record type to Resource Record Inline Map
+    RR_INLINE_MAP = {
+        'A':        ARecordInline,
+        'AAAA':     AaaaRecordInline,
+        'AFSDB':    AfsdbRecordInline,
+        'CERT':     CertRecordInline,
+        'CNAME':    CnameRecordInline,
+        'DNSKEY':   DnskeyRecordInline,
+        'DS':       DsRecordInline,
+        'HINFO':    HinfoRecordInline,
+        'KEY':      KeyRecordInline,
+        'LOC':      LocRecordInline,
+        'MX':       MxRecordInline,
+        'NAPTR':    NaptrRecordInline,
+        'NS':       NsRecordInline,
+        'NSEC':     NsecRecordInline,
+        'PTR':      PtrRecordInline,
+        'RP':       RpRecordInline,
+        'RRSIG':    RrsigRecordInline,
+        'SOA':      SoaRecordInline,
+        'SPF':      SpfRecordInline,
+        'SSHFP':    SshfpRecordInline,
+        'SRV':      SrvRecordInline,
+        'TXT':      TxtRecordInline,
+    }
+    
+    # Add RR inlines
+    for RR_TYPE in settings.PDNS_ENABLED_RR_TYPES:
+        inlines.append(RR_INLINE_MAP[RR_TYPE])
+    
+    # Add other inlines
+    inlines.append(DomainMetadataInline)
+    inlines.append(CryptoKeyInline)
+    
     def queryset(self, request):
         qs = super(DomainAdmin, self).queryset(request)
         if not request.user.is_superuser:

File src/powerdns_manager/models.py

         http://doc.powerdns.com/dnssec-modes.html#dnssec-direct-database
     
     """
-    RECORD_TYPE_CHOICES = (
-        ('A', 'A'),
-        ('AAAA', 'AAAA'),
-        ('AFSDB', 'AFSDB'),
-        ('CERT', 'CERT'),
-        ('CNAME', 'CNAME'),
-        ('DNSKEY', 'DNSKEY'),
-        ('DS', 'DS'),
-        ('HINFO', 'HINFO'),
-        ('KEY', 'KEY'),
-        ('LOC', 'LOC'),
-        ('MX', 'MX'),
-        ('NAPTR', 'NAPTR'),
-        ('NS', 'NS'),
-        ('NSEC', 'NSEC'),
-        ('PTR', 'PTR'),
-        ('RP', 'RP'),
-        ('RRSIG', 'RRSIG'),
-        ('SOA', 'SOA'),
-        ('SPF', 'SPF'),
-        ('SSHFP', 'SSHFP'),
-        ('SRV', 'SRV'),
-        ('TXT', 'TXT'),
-    )
+    # Build resource record choices list
+    RECORD_TYPE_CHOICES = []
+    for enabled_rr_type in settings.PDNS_ENABLED_RR_TYPES:
+        RECORD_TYPE_CHOICES.append( (enabled_rr_type, enabled_rr_type) )
+#    RECORD_TYPE_CHOICES = (
+#        ('A', 'A'),
+#        ('AAAA', 'AAAA'),
+#        ('AFSDB', 'AFSDB'),
+#        ('CERT', 'CERT'),
+#        ('CNAME', 'CNAME'),
+#        ('DNSKEY', 'DNSKEY'),
+#        ('DS', 'DS'),
+#        ('HINFO', 'HINFO'),
+#        ('KEY', 'KEY'),
+#        ('LOC', 'LOC'),
+#        ('MX', 'MX'),
+#        ('NAPTR', 'NAPTR'),
+#        ('NS', 'NS'),
+#        ('NSEC', 'NSEC'),
+#        ('PTR', 'PTR'),
+#        ('RP', 'RP'),
+#        ('RRSIG', 'RRSIG'),
+#        ('SOA', 'SOA'),
+#        ('SPF', 'SPF'),
+#        ('SSHFP', 'SSHFP'),
+#        ('SRV', 'SRV'),
+#        ('TXT', 'TXT'),
+#    )
     domain = models.ForeignKey('powerdns_manager.Domain', related_name='%(app_label)s_%(class)s_domain', verbose_name=_('domain'), help_text=_("""Select the domain this record belongs to."""))
     name = models.CharField(max_length=255, null=True, db_index=True, verbose_name=_('name'), help_text="""Actual name of a record. Must not end in a '.' and be fully qualified - it is not relative to the name of the domain!  For example: www.test.com (no trailing dot)""")
     # See section 8.5 about why the type field allows NULL. (PowerDNS 3.2 and above)

File src/powerdns_manager/settings.py

 # Declares the server a SLAVE -- Will be used internally
 PDNS_IS_SLAVE = getattr(settings, 'PDNS_IS_SLAVE', False)
 
+# __ALL__ is special keyword that enables all record types
+_DEFAULT_PDNS_ENABLED_RR_TYPES = [
+    'SOA',
+    'NS',
+    'MX',
+    'A',
+    'AAAA',
+    'CNAME',
+    'PTR',
+    'TXT',
+    'SPF',
+    'SRV',
+    'CERT',
+    'DNSKEY',
+    'DS',
+    'KEY',
+    'NSEC',
+    'RRSIG',
+    'HINFO',
+    'LOC',
+    'NAPTR',
+    'RP',
+    'AFSDB',
+    'SSHFP',
+]
+PDNS_ENABLED_RR_TYPES = getattr(settings, 'PDNS_ENABLED_RR_TYPES', _DEFAULT_PDNS_ENABLED_RR_TYPES)
+