mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-04 17:06:27 +00:00
Affichage REST des règles particulières des machines.
This commit is contained in:
parent
8e10bc64a8
commit
3abbc70793
3 changed files with 51 additions and 1 deletions
|
@ -206,3 +206,28 @@ class ServiceServersSerializer(serializers.ModelSerializer):
|
|||
def get_regen_status(self, obj):
|
||||
return obj.need_regen()
|
||||
|
||||
class OuverturePortsSerializer(serializers.Serializer):
|
||||
ipv4 = serializers.SerializerMethodField()
|
||||
ipv6 = serializers.SerializerMethodField()
|
||||
|
||||
def get_ipv4():
|
||||
return {i.ipv4.ipv4:
|
||||
{
|
||||
"tcp_in":[j.tcp_ports_in() for j in i.port_lists.all()],
|
||||
"tcp_out":[j.tcp_ports_out()for j in i.port_lists.all()],
|
||||
"udp_in":[j.udp_ports_in() for j in i.port_lists.all()],
|
||||
"udp_out":[j.udp_ports_out() for j in i.port_lists.all()],
|
||||
}
|
||||
for i in Interface.objects.all() if i.ipv4
|
||||
}
|
||||
|
||||
def get_ipv6():
|
||||
return {i.ipv6:
|
||||
{
|
||||
"tcp_in":[j.tcp_ports_in() for j in i.port_lists.all()],
|
||||
"tcp_out":[j.tcp_ports_out()for j in i.port_lists.all()],
|
||||
"udp_in":[j.udp_ports_in() for j in i.port_lists.all()],
|
||||
"udp_out":[j.udp_ports_out() for j in i.port_lists.all()],
|
||||
}
|
||||
for i in Interface.objects.all() if i.ipv6
|
||||
}
|
||||
|
|
|
@ -92,6 +92,7 @@ urlpatterns = [
|
|||
url(r'^rest/text/$', views.text, name='text'),
|
||||
url(r'^rest/zones/$', views.zones, name='zones'),
|
||||
url(r'^rest/service_servers/$', views.service_servers, name='service-servers'),
|
||||
url(r'^rest/ouverture_ports/$', views.ouverture_ports, name='ouverture-ports'),
|
||||
url(r'index_portlist/$', views.index_portlist, name='index-portlist'),
|
||||
url(r'^edit_portlist/(?P<pk>[0-9]+)$', views.edit_portlist, name='edit-portlist'),
|
||||
url(r'^del_portlist/(?P<pk>[0-9]+)$', views.del_portlist, name='del-portlist'),
|
||||
|
|
|
@ -41,7 +41,7 @@ from django.contrib.auth import authenticate, login
|
|||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
from rest_framework.renderers import JSONRenderer
|
||||
from machines.serializers import FullInterfaceSerializer, InterfaceSerializer, TypeSerializer, DomainSerializer, TextSerializer, MxSerializer, ExtensionSerializer, ServiceServersSerializer, NsSerializer
|
||||
from machines.serializers import FullInterfaceSerializer, InterfaceSerializer, TypeSerializer, DomainSerializer, TextSerializer, MxSerializer, ExtensionSerializer, ServiceServersSerializer, NsSerializer, OuverturePortsSerializer
|
||||
from reversion import revisions as reversion
|
||||
from reversion.models import Version
|
||||
|
||||
|
@ -1108,6 +1108,30 @@ def service_servers(request):
|
|||
@csrf_exempt
|
||||
@login_required
|
||||
@permission_required('serveur')
|
||||
def ouverture_ports(request):
|
||||
r = {'ipv4':{}, 'ipv6':{}}
|
||||
for i in Interface.objects.all():
|
||||
if not i.may_have_port_open():
|
||||
continue
|
||||
if i.ipv4:
|
||||
r['ipv4'][i.ipv4.ipv4] = {"tcp_in":[],"tcp_out":[],"udp_in":[],"udp_out":[]}
|
||||
if i.ipv6:
|
||||
r['ipv6'][i.ipv6] = {"tcp_in":[],"tcp_out":[],"udp_in":[],"udp_out":[]}
|
||||
for j in i.port_lists.all():
|
||||
if i.ipv4:
|
||||
r['ipv4'][i.ipv4.ipv4]["tcp_in"].extend(j.tcp_ports_in())
|
||||
r['ipv4'][i.ipv4.ipv4]["tcp_out"].extend(j.tcp_ports_out())
|
||||
r['ipv4'][i.ipv4.ipv4]["udp_in"].extend(j.udp_ports_in())
|
||||
r['ipv4'][i.ipv4.ipv4]["udp_out"].extend(j.udp_ports_out())
|
||||
if i.ipv6:
|
||||
r['ipv6'][i.ipv6]["tcp_in"].extend(j.tcp_ports_in())
|
||||
r['ipv6'][i.ipv6]["tcp_out"].extend(j.tcp_ports_out())
|
||||
r['ipv6'][i.ipv6]["udp_in"].extend(j.udp_ports_in())
|
||||
r['ipv6'][i.ipv6]["udp_out"].extend(j.udp_ports_out())
|
||||
return JSONResponse(r)
|
||||
@csrf_exempt
|
||||
@login_required
|
||||
@permission_required('serveur')
|
||||
def regen_achieved(request):
|
||||
obj = Service_link.objects.filter(service__in=Service.objects.filter(service_type=request.POST['service']), server__in=Interface.objects.filter(domain__in=Domain.objects.filter(name=request.POST['server'])))
|
||||
if obj:
|
||||
|
|
Loading…
Reference in a new issue