mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-23 11:53:12 +00:00
Optimisation de l'export REST
This commit is contained in:
parent
22efb9770d
commit
a2686bbf97
1 changed files with 21 additions and 17 deletions
|
@ -1205,24 +1205,28 @@ def service_servers(request):
|
||||||
@permission_required('serveur')
|
@permission_required('serveur')
|
||||||
def ouverture_ports(request):
|
def ouverture_ports(request):
|
||||||
r = {'ipv4':{}, 'ipv6':{}}
|
r = {'ipv4':{}, 'ipv6':{}}
|
||||||
for i in Interface.objects.all():
|
for o in OuverturePortList.objects.all().prefetch_related('ouvertureport_set'):
|
||||||
if not i.may_have_port_open():
|
pl = {
|
||||||
continue
|
"tcp_in":set(map(str,o.tcp_ports_in())),
|
||||||
if i.ipv4:
|
"tcp_out":set(map(str,o.tcp_ports_out())),
|
||||||
r['ipv4'][i.ipv4.ipv4] = {"tcp_in":[],"tcp_out":[],"udp_in":[],"udp_out":[]}
|
"udp_in":set(map(str,o.udp_ports_in())),
|
||||||
if i.ipv6_object:
|
"udp_out":set(map(str,o.udp_ports_out())),
|
||||||
r['ipv6'][i.ipv6] = {"tcp_in":[],"tcp_out":[],"udp_in":[],"udp_out":[]}
|
}
|
||||||
for j in i.port_lists.all():
|
for i in o.interface_set.filter(machine__in=Machine.objects.filter(user__in=all_has_access()).filter(active=True)).select_related('domain').select_related('machine').select_related('type').select_related('ipv4').select_related('domain__extension').select_related('ipv4__ip_type').distinct():
|
||||||
if i.ipv4:
|
if i.may_have_port_open():
|
||||||
r['ipv4'][i.ipv4.ipv4]["tcp_in"].extend(j.tcp_ports_in())
|
d = r['ipv4'].get(i.ipv4.ipv4, {})
|
||||||
r['ipv4'][i.ipv4.ipv4]["tcp_out"].extend(j.tcp_ports_out())
|
d["tcp_in"] = d.get("tcp_in",set()).union(pl["tcp_in"])
|
||||||
r['ipv4'][i.ipv4.ipv4]["udp_in"].extend(j.udp_ports_in())
|
d["tcp_out"] = d.get("tcp_out",set()).union(pl["tcp_out"])
|
||||||
r['ipv4'][i.ipv4.ipv4]["udp_out"].extend(j.udp_ports_out())
|
d["udp_in"] = d.get("udp_in",set()).union(pl["udp_in"])
|
||||||
|
d["udp_out"] = d.get("udp_out",set()).union(pl["udp_out"])
|
||||||
|
r['ipv4'][i.ipv4.ipv4] = d
|
||||||
if i.ipv6_object:
|
if i.ipv6_object:
|
||||||
r['ipv6'][i.ipv6]["tcp_in"].extend(j.tcp_ports_in())
|
d = r['ipv6'].get(i.ipv6, {})
|
||||||
r['ipv6'][i.ipv6]["tcp_out"].extend(j.tcp_ports_out())
|
d["tcp_in"] = d.get("tcp_in",set()).union(pl["tcp_in"])
|
||||||
r['ipv6'][i.ipv6]["udp_in"].extend(j.udp_ports_in())
|
d["tcp_out"] = d.get("tcp_out",set()).union(pl["tcp_out"])
|
||||||
r['ipv6'][i.ipv6]["udp_out"].extend(j.udp_ports_out())
|
d["udp_in"] = d.get("udp_in",set()).union(pl["udp_in"])
|
||||||
|
d["udp_out"] = d.get("udp_out",set()).union(pl["udp_out"])
|
||||||
|
r['ipv6'][i.ipv6] = d
|
||||||
return JSONResponse(r)
|
return JSONResponse(r)
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
@login_required
|
@login_required
|
||||||
|
|
Loading…
Reference in a new issue