8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 03:13:12 +00:00

Add DNS info per zone endpoint

This commit is contained in:
Maël Kervella 2018-06-10 00:47:25 +00:00 committed by Maël Kervella
parent 4fe1be5d31
commit e6884ab4da
4 changed files with 109 additions and 2 deletions

View file

@ -190,8 +190,7 @@ class InterfaceSerializer(NamespacedHMSerializer):
class Ipv6ListSerializer(NamespacedHMSerializer): class Ipv6ListSerializer(NamespacedHMSerializer):
class Meta: class Meta:
model = machines.Ipv6List model = machines.Ipv6List
fields = ('ipv6', 'interface', 'slaac_ip', 'date_end', fields = ('ipv6', 'interface', 'slaac_ip', 'api_url')
'api_url')
class DomainSerializer(NamespacedHMSerializer): class DomainSerializer(NamespacedHMSerializer):
@ -488,3 +487,94 @@ class HostMacIpSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = machines.Interface model = machines.Interface
fields = ('hostname', 'extension', 'mac_address', 'ipv4') fields = ('hostname', 'extension', 'mac_address', 'ipv4')
# DNS
class SOARecordSerializer(SOASerializer):
class Meta:
model = machines.SOA
fields = ('name', 'mail', 'refresh', 'retry', 'expire', 'ttl')
class OriginV4RecordSerializer(IpListSerializer):
class Meta(IpListSerializer.Meta):
fields = ('ipv4',)
class OriginV6RecordSerializer(Ipv6ListSerializer):
class Meta(Ipv6ListSerializer.Meta):
fields = ('ipv6',)
class NSRecordSerializer(NsSerializer):
target = serializers.CharField(source='ns.name', read_only=True)
class Meta(NsSerializer.Meta):
fields = ('target',)
class MXRecordSerializer(MxSerializer):
target = serializers.CharField(source='name.name', read_only=True)
class Meta(MxSerializer.Meta):
fields = ('target', 'priority')
class TXTRecordSerializer(TxtSerializer):
class Meta(TxtSerializer.Meta):
fields = ('field1', 'field2')
class SRVRecordSerializer(SrvSerializer):
target = serializers.CharField(source='target.name', read_only=True)
class Meta(SrvSerializer.Meta):
fields = ('service', 'protocole', 'ttl', 'priority', 'weight', 'port', 'target')
class ARecordSerializer(serializers.ModelSerializer):
hostname = serializers.CharField(source='domain.name', read_only=True)
ipv4 = serializers.CharField(source='ipv4.ipv4', read_only=True)
class Meta:
model = machines.Interface
fields = ('hostname', 'ipv4')
class AAAARecordSerializer(serializers.ModelSerializer):
hostname = serializers.CharField(source='domain.name', read_only=True)
ipv6 = serializers.CharField(read_only=True)
class Meta:
model = machines.Interface
fields = ('hostname', 'ipv6')
class CNAMERecordSerializer(serializers.ModelSerializer):
alias = serializers.CharField(source='cname.name', read_only=True)
hostname = serializers.CharField(source='name', read_only=True)
class Meta:
model = machines.Domain
fields = ('alias', 'hostname')
class DNSZonesSerializer(serializers.ModelSerializer):
soa = SOARecordSerializer()
ns_records = NSRecordSerializer(many=True, source='ns_set')
originv4 = OriginV4RecordSerializer(source='origin')
originv6 = OriginV6RecordSerializer(source='origin_v6')
mx_records = MXRecordSerializer(many=True, source='mx_set')
txt_records = TXTRecordSerializer(many=True, source='txt_set')
srv_records = SRVRecordSerializer(many=True, source='srv_set')
a_records = ARecordSerializer(many=True, source='get_associated_a_records')
aaaa_records = AAAARecordSerializer(many=True, source='get_associated_aaaa_records')
cname_records = CNAMERecordSerializer(many=True, source='get_associated_cname_records')
class Meta:
model = machines.Extension
fields = ('name', 'soa', 'ns_records', 'originv4', 'originv6',
'mx_records', 'txt_records', 'srv_records', 'a_records',
'aaaa_records', 'cname_records')

View file

@ -90,6 +90,7 @@ router.register(r'users/whitelists', views.WhitelistViewSet)
urlpatterns = [ urlpatterns = [
url(r'^', include(router.urls)), url(r'^', include(router.urls)),
url(r'^dhcp/hostmacip', views.HostMacIpView.as_view()), url(r'^dhcp/hostmacip', views.HostMacIpView.as_view()),
url(r'^dns/zones', views.DNSZonesView.as_view()),
url(r'^services/regen', views.ServiceRegenView.as_view()), url(r'^services/regen', views.ServiceRegenView.as_view()),
url(r'^token-auth', views.ObtainExpiringAuthToken.as_view()) url(r'^token-auth', views.ObtainExpiringAuthToken.as_view())
] ]

View file

@ -338,6 +338,13 @@ class HostMacIpView(generics.ListAPIView):
serializer_class = serializers.HostMacIpSerializer serializer_class = serializers.HostMacIpSerializer
# DNS views
class DNSZonesView(generics.ListAPIView):
queryset = machines.Extension.objects.all()
serializer_class = serializers.DNSZonesSerializer
# Subclass the standard rest_framework.auth_token.views.ObtainAuthToken # Subclass the standard rest_framework.auth_token.views.ObtainAuthToken
# in order to renew the lease of the token and add expiration time # in order to renew the lease of the token and add expiration time
class ObtainExpiringAuthToken(ObtainAuthToken): class ObtainExpiringAuthToken(ObtainAuthToken):

View file

@ -562,6 +562,15 @@ class Extension(RevMixin, AclMixin, models.Model):
entry += "@ IN AAAA " + str(self.origin_v6) entry += "@ IN AAAA " + str(self.origin_v6)
return entry return entry
def get_associated_a_records(self):
return Interface.objects.filter(type__ip_type__extension=self).filter(ipv4__isnull=False)
def get_associated_aaaa_records(self):
return Interface.objects.filter(type__ip_type__extension=self)
def get_associated_cname_records(self):
return Domain.objects.filter(extension=self).filter(cname__isnull=False)
@staticmethod @staticmethod
def can_use_all(user_request, *_args, **_kwargs): def can_use_all(user_request, *_args, **_kwargs):
"""Superdroit qui permet d'utiliser toutes les extensions sans """Superdroit qui permet d'utiliser toutes les extensions sans