8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-26 06:32:26 +00:00

Serialisation des ipv6 et export des ouvertures de ports

This commit is contained in:
Gabriel Detraz 2018-01-30 06:14:28 +00:00 committed by root
parent 185fa6068a
commit 56e88cfe97
2 changed files with 19 additions and 9 deletions

View file

@ -37,7 +37,8 @@ from machines.models import (
Service_link, Service_link,
Ns, Ns,
OuverturePortList, OuverturePortList,
OuverturePort OuverturePort,
Ipv6List
) )
@ -57,6 +58,12 @@ class IpListSerializer(serializers.ModelSerializer):
fields = ('ipv4', 'ip_type') fields = ('ipv4', 'ip_type')
class Ipv6ListSerializer(serializers.ModelSerializer):
class Meta:
model = Ipv6List
fields = ('ipv6', 'slaac_ip')
class InterfaceSerializer(serializers.ModelSerializer): class InterfaceSerializer(serializers.ModelSerializer):
"""Serialisation d'une interface, ipv4, domain et extension sont """Serialisation d'une interface, ipv4, domain et extension sont
des foreign_key, on les override et on les evalue avec des fonctions des foreign_key, on les override et on les evalue avec des fonctions
@ -81,8 +88,9 @@ class InterfaceSerializer(serializers.ModelSerializer):
class FullInterfaceSerializer(serializers.ModelSerializer): class FullInterfaceSerializer(serializers.ModelSerializer):
"""Serialisation complete d'une interface avec l'ipv6 en plus""" """Serialisation complete d'une interface avec les ipv6 en plus"""
ipv4 = IpListSerializer(read_only=True) ipv4 = IpListSerializer(read_only=True)
ipv6 = Ipv6ListSerializer(read_only=True, many=True)
mac_address = serializers.SerializerMethodField('get_macaddress') mac_address = serializers.SerializerMethodField('get_macaddress')
domain = serializers.SerializerMethodField('get_dns') domain = serializers.SerializerMethodField('get_dns')
extension = serializers.SerializerMethodField('get_interface_extension') extension = serializers.SerializerMethodField('get_interface_extension')

View file

@ -1268,14 +1268,16 @@ def ouverture_ports(request):
d["udp_in"] = d.get("udp_in",set()).union(pl["udp_in"]) d["udp_in"] = d.get("udp_in",set()).union(pl["udp_in"])
d["udp_out"] = d.get("udp_out",set()).union(pl["udp_out"]) d["udp_out"] = d.get("udp_out",set()).union(pl["udp_out"])
r['ipv4'][i.ipv4.ipv4] = d r['ipv4'][i.ipv4.ipv4] = d
if i.ipv6_object: if i.ipv6():
d = r['ipv6'].get(i.ipv6.first(), {}) for ipv6 in i.ipv6():
d["tcp_in"] = d.get("tcp_in",set()).union(pl["tcp_in"]) d = r['ipv6'].get(ipv6.ipv6, {})
d["tcp_out"] = d.get("tcp_out",set()).union(pl["tcp_out"]) d["tcp_in"] = d.get("tcp_in",set()).union(pl["tcp_in"])
d["udp_in"] = d.get("udp_in",set()).union(pl["udp_in"]) d["tcp_out"] = d.get("tcp_out",set()).union(pl["tcp_out"])
d["udp_out"] = d.get("udp_out",set()).union(pl["udp_out"]) d["udp_in"] = d.get("udp_in",set()).union(pl["udp_in"])
r['ipv6'][i.ipv6] = d d["udp_out"] = d.get("udp_out",set()).union(pl["udp_out"])
r['ipv6'][ipv6.ipv6] = d
return JSONResponse(r) return JSONResponse(r)
@csrf_exempt @csrf_exempt
@login_required @login_required
@permission_required('machines.serveur') @permission_required('machines.serveur')