From 5757a0c03d0410f0f92d6c2d336075acd305d782 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Fri, 13 Jul 2018 09:56:15 +0200 Subject: [PATCH] Serialisation des ouvertures de ports en sortie par subnet --- api/serializers.py | 24 ++++++++++++++++++++++++ api/urls.py | 2 ++ api/views.py | 6 ++++++ 3 files changed, 32 insertions(+) diff --git a/api/serializers.py b/api/serializers.py index 398f2b19..efbe5186 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -638,6 +638,30 @@ class LocalEmailUsersSerializer(NamespacedHMSerializer): 'email_address') +#Firewall + +class FirewallPortListSerializer(serializers.ModelSerializer): + class Meta: + model = machines.OuverturePort + fields = ('begin', 'end', 'protocole', 'io') + +class FirewallOuverturePortListSerializer(serializers.ModelSerializer): + tcp_ports_in = FirewallPortListSerializer(many=True, read_only=True) + udp_ports_in = FirewallPortListSerializer(many=True, read_only=True) + tcp_ports_out = FirewallPortListSerializer(many=True, read_only=True) + udp_ports_out = FirewallPortListSerializer(many=True, read_only=True) + + class Meta: + model = machines.OuverturePortList + fields = ('tcp_ports_in', 'udp_ports_in', 'tcp_ports_out', 'udp_ports_out') + +class SubnetPortsOpenSerializer(serializers.ModelSerializer): + ouverture_ports = FirewallOuverturePortListSerializer(read_only=True) + + class Meta: + model = machines.IpType + fields = ('type', 'domaine_ip_start', 'domaine_ip_stop', 'prefix_v6', 'ouverture_ports') + # DHCP diff --git a/api/urls.py b/api/urls.py index 7ee36073..37580db2 100644 --- a/api/urls.py +++ b/api/urls.py @@ -100,6 +100,8 @@ router.register_viewset(r'services/regen', views.ServiceRegenViewSet, base_name= router.register_view(r'dhcp/hostmacip', views.HostMacIpView), # LOCAL EMAILS router.register_view(r'localemail/users', views.LocalEmailUsersView), +# Firewall +router.register_view(r'firewall/subnet-ports', views.SubnetPortsOpenView), # DNS router.register_view(r'dns/zones', views.DNSZonesView), # MAILING diff --git a/api/views.py b/api/views.py index ef083edf..715a31ac 100644 --- a/api/views.py +++ b/api/views.py @@ -532,6 +532,12 @@ class HostMacIpView(generics.ListAPIView): serializer_class = serializers.HostMacIpSerializer +#Firewall + +class SubnetPortsOpenView(generics.ListAPIView): + queryset = machines.IpType.objects.all() + serializer_class = serializers.SubnetPortsOpenSerializer + # DNS