mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-27 07:02:26 +00:00
Remove old api
This commit is contained in:
parent
c775d9ba51
commit
334537e475
6 changed files with 1 additions and 845 deletions
|
@ -1,442 +0,0 @@
|
||||||
# -*- mode: python; coding: utf-8 -*-
|
|
||||||
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il
|
|
||||||
# se veut agnostique au réseau considéré, de manière à être installable en
|
|
||||||
# quelques clics.
|
|
||||||
#
|
|
||||||
# Copyright © 2017 Gabriel Détraz
|
|
||||||
# Copyright © 2017 Lara Kermarec
|
|
||||||
# Copyright © 2017 Augustin Lemesle
|
|
||||||
#
|
|
||||||
# This program is free software; you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation; either version 2 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License along
|
|
||||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
|
|
||||||
# Augustin Lemesle
|
|
||||||
"""machines.serializers
|
|
||||||
Serializers for the Machines app
|
|
||||||
"""
|
|
||||||
|
|
||||||
from rest_framework import serializers
|
|
||||||
|
|
||||||
from machines.models import (
|
|
||||||
Interface,
|
|
||||||
IpType,
|
|
||||||
Extension,
|
|
||||||
IpList,
|
|
||||||
Domain,
|
|
||||||
Txt,
|
|
||||||
Mx,
|
|
||||||
Srv,
|
|
||||||
Service_link,
|
|
||||||
Ns,
|
|
||||||
OuverturePort,
|
|
||||||
Ipv6List,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class IpTypeField(serializers.RelatedField):
|
|
||||||
""" Serializer for an IpType object field """
|
|
||||||
|
|
||||||
def to_representation(self, value):
|
|
||||||
return str(value)
|
|
||||||
|
|
||||||
def to_internal_value(self, data):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class IpListSerializer(serializers.ModelSerializer):
|
|
||||||
""" Serializer for an Ipv4List obejct using the IpType serialization """
|
|
||||||
|
|
||||||
ip_type = IpTypeField(read_only=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = IpList
|
|
||||||
fields = ("ipv4", "ip_type")
|
|
||||||
|
|
||||||
|
|
||||||
class Ipv6ListSerializer(serializers.ModelSerializer):
|
|
||||||
""" Serializer for an Ipv6List object """
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Ipv6List
|
|
||||||
fields = ("ipv6", "slaac_ip")
|
|
||||||
|
|
||||||
|
|
||||||
class InterfaceSerializer(serializers.ModelSerializer):
|
|
||||||
""" Serializer for an Interface object. Use SerializerMethodField
|
|
||||||
to get ForeignKey values """
|
|
||||||
|
|
||||||
ipv4 = IpListSerializer(read_only=True)
|
|
||||||
# TODO : use serializer.RelatedField to avoid duplicate code
|
|
||||||
mac_address = serializers.SerializerMethodField("get_macaddress")
|
|
||||||
domain = serializers.SerializerMethodField("get_dns")
|
|
||||||
extension = serializers.SerializerMethodField("get_interface_extension")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Interface
|
|
||||||
fields = ("ipv4", "mac_address", "domain", "extension")
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_dns(obj):
|
|
||||||
""" The name of the associated DNS object """
|
|
||||||
return obj.domain.name
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_interface_extension(obj):
|
|
||||||
""" The name of the associated Interface object """
|
|
||||||
return obj.domain.extension.name
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_macaddress(obj):
|
|
||||||
""" The string representation of the associated MAC address """
|
|
||||||
return str(obj.mac_address)
|
|
||||||
|
|
||||||
|
|
||||||
class FullInterfaceSerializer(serializers.ModelSerializer):
|
|
||||||
""" Serializer for an Interface obejct. Use SerializerMethodField
|
|
||||||
to get ForeignKey values """
|
|
||||||
|
|
||||||
ipv4 = IpListSerializer(read_only=True)
|
|
||||||
ipv6 = Ipv6ListSerializer(read_only=True, many=True)
|
|
||||||
# TODO : use serializer.RelatedField to avoid duplicate code
|
|
||||||
mac_address = serializers.SerializerMethodField("get_macaddress")
|
|
||||||
domain = serializers.SerializerMethodField("get_dns")
|
|
||||||
extension = serializers.SerializerMethodField("get_interface_extension")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Interface
|
|
||||||
fields = ("ipv4", "ipv6", "mac_address", "domain", "extension")
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_dns(obj):
|
|
||||||
""" The name of the associated DNS object """
|
|
||||||
return obj.domain.name
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_interface_extension(obj):
|
|
||||||
""" The name of the associated Extension object """
|
|
||||||
return obj.domain.extension.name
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_macaddress(obj):
|
|
||||||
""" The string representation of the associated MAC address """
|
|
||||||
return str(obj.mac_address)
|
|
||||||
|
|
||||||
|
|
||||||
class ExtensionNameField(serializers.RelatedField):
|
|
||||||
""" Serializer for Extension object field """
|
|
||||||
|
|
||||||
def to_representation(self, value):
|
|
||||||
return value.name
|
|
||||||
|
|
||||||
def to_internal_value(self, data):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class TypeSerializer(serializers.ModelSerializer):
|
|
||||||
""" Serializer for an IpType object. Use SerializerMethodField to
|
|
||||||
get ForeignKey values. Infos about the general port policy is added """
|
|
||||||
|
|
||||||
extension = ExtensionNameField(read_only=True)
|
|
||||||
ouverture_ports_tcp_in = serializers.SerializerMethodField(
|
|
||||||
"get_port_policy_input_tcp"
|
|
||||||
)
|
|
||||||
ouverture_ports_tcp_out = serializers.SerializerMethodField(
|
|
||||||
"get_port_policy_output_tcp"
|
|
||||||
)
|
|
||||||
ouverture_ports_udp_in = serializers.SerializerMethodField(
|
|
||||||
"get_port_policy_input_udp"
|
|
||||||
)
|
|
||||||
ouverture_ports_udp_out = serializers.SerializerMethodField(
|
|
||||||
"get_port_policy_output_udp"
|
|
||||||
)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = IpType
|
|
||||||
fields = (
|
|
||||||
"name",
|
|
||||||
"extension",
|
|
||||||
"domaine_ip_start",
|
|
||||||
"domaine_ip_stop",
|
|
||||||
"prefix_v6",
|
|
||||||
"ouverture_ports_tcp_in",
|
|
||||||
"ouverture_ports_tcp_out",
|
|
||||||
"ouverture_ports_udp_in",
|
|
||||||
"ouverture_ports_udp_out",
|
|
||||||
)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_port_policy(obj, protocole, io):
|
|
||||||
""" Generic utility function to get the policy for a given
|
|
||||||
port, protocole and IN or OUT """
|
|
||||||
if obj.ouverture_ports is None:
|
|
||||||
return []
|
|
||||||
return map(
|
|
||||||
str,
|
|
||||||
obj.ouverture_ports.ouvertureport_set.filter(protocole=protocole).filter(
|
|
||||||
io=io
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_port_policy_input_tcp(self, obj):
|
|
||||||
"""Renvoie la liste des ports ouverts en entrée tcp"""
|
|
||||||
return self.get_port_policy(obj, OuverturePort.TCP, OuverturePort.IN)
|
|
||||||
|
|
||||||
def get_port_policy_output_tcp(self, obj):
|
|
||||||
"""Renvoie la liste des ports ouverts en sortie tcp"""
|
|
||||||
return self.get_port_policy(obj, OuverturePort.TCP, OuverturePort.OUT)
|
|
||||||
|
|
||||||
def get_port_policy_input_udp(self, obj):
|
|
||||||
"""Renvoie la liste des ports ouverts en entrée udp"""
|
|
||||||
return self.get_port_policy(obj, OuverturePort.UDP, OuverturePort.IN)
|
|
||||||
|
|
||||||
def get_port_policy_output_udp(self, obj):
|
|
||||||
"""Renvoie la liste des ports ouverts en sortie udp"""
|
|
||||||
return self.get_port_policy(obj, OuverturePort.UDP, OuverturePort.OUT)
|
|
||||||
|
|
||||||
|
|
||||||
class ExtensionSerializer(serializers.ModelSerializer):
|
|
||||||
"""Serialisation d'une extension : origin_ip et la zone sont
|
|
||||||
des foreign_key donc evalués en get_..."""
|
|
||||||
|
|
||||||
origin = serializers.SerializerMethodField("get_origin_ip")
|
|
||||||
zone_entry = serializers.SerializerMethodField("get_zone_name")
|
|
||||||
soa = serializers.SerializerMethodField("get_soa_data")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Extension
|
|
||||||
fields = ("name", "origin", "origin_v6", "zone_entry", "soa")
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_origin_ip(obj):
|
|
||||||
""" The IP of the associated origin for the zone """
|
|
||||||
return obj.origin.ipv4
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_zone_name(obj):
|
|
||||||
""" The name of the associated zone """
|
|
||||||
return str(obj.dns_entry)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_soa_data(obj):
|
|
||||||
""" The representation of the associated SOA """
|
|
||||||
return {"mail": obj.soa.dns_soa_mail, "param": obj.soa.dns_soa_param}
|
|
||||||
|
|
||||||
|
|
||||||
class MxSerializer(serializers.ModelSerializer):
|
|
||||||
"""Serialisation d'un MX, evaluation du nom, de la zone
|
|
||||||
et du serveur cible, etant des foreign_key"""
|
|
||||||
|
|
||||||
name = serializers.SerializerMethodField("get_entry_name")
|
|
||||||
zone = serializers.SerializerMethodField("get_zone_name")
|
|
||||||
mx_entry = serializers.SerializerMethodField("get_mx_name")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Mx
|
|
||||||
fields = ("zone", "priority", "name", "mx_entry")
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_entry_name(obj):
|
|
||||||
""" The name of the DNS MX entry """
|
|
||||||
return str(obj.name)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_zone_name(obj):
|
|
||||||
""" The name of the associated zone of the MX record """
|
|
||||||
return obj.zone.name
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_mx_name(obj):
|
|
||||||
""" The string representation of the entry to add to the DNS """
|
|
||||||
return str(obj.dns_entry)
|
|
||||||
|
|
||||||
|
|
||||||
class TxtSerializer(serializers.ModelSerializer):
|
|
||||||
"""Serialisation d'un txt : zone cible et l'entrée txt
|
|
||||||
sont evaluées à part"""
|
|
||||||
|
|
||||||
zone = serializers.SerializerMethodField("get_zone_name")
|
|
||||||
txt_entry = serializers.SerializerMethodField("get_txt_name")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Txt
|
|
||||||
fields = ("zone", "txt_entry", "field1", "field2")
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_zone_name(obj):
|
|
||||||
""" The name of the associated zone """
|
|
||||||
return str(obj.zone.name)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_txt_name(obj):
|
|
||||||
""" The string representation of the entry to add to the DNS """
|
|
||||||
return str(obj.dns_entry)
|
|
||||||
|
|
||||||
|
|
||||||
class SrvSerializer(serializers.ModelSerializer):
|
|
||||||
"""Serialisation d'un srv : zone cible et l'entrée txt"""
|
|
||||||
|
|
||||||
extension = serializers.SerializerMethodField("get_extension_name")
|
|
||||||
srv_entry = serializers.SerializerMethodField("get_srv_name")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Srv
|
|
||||||
fields = (
|
|
||||||
"service",
|
|
||||||
"protocole",
|
|
||||||
"extension",
|
|
||||||
"ttl",
|
|
||||||
"priority",
|
|
||||||
"weight",
|
|
||||||
"port",
|
|
||||||
"target",
|
|
||||||
"srv_entry",
|
|
||||||
)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_extension_name(obj):
|
|
||||||
""" The name of the associated extension """
|
|
||||||
return str(obj.extension.name)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_srv_name(obj):
|
|
||||||
""" The string representation of the entry to add to the DNS """
|
|
||||||
return str(obj.dns_entry)
|
|
||||||
|
|
||||||
|
|
||||||
class NsSerializer(serializers.ModelSerializer):
|
|
||||||
"""Serialisation d'un NS : la zone, l'entrée ns complète et le serveur
|
|
||||||
ns sont évalués à part"""
|
|
||||||
|
|
||||||
zone = serializers.SerializerMethodField("get_zone_name")
|
|
||||||
ns = serializers.SerializerMethodField("get_domain_name")
|
|
||||||
ns_entry = serializers.SerializerMethodField("get_text_name")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Ns
|
|
||||||
fields = ("zone", "ns", "ns_entry")
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_zone_name(obj):
|
|
||||||
""" The name of the associated zone """
|
|
||||||
return obj.zone.name
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_domain_name(obj):
|
|
||||||
""" The name of the associated NS target """
|
|
||||||
return str(obj.ns)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_text_name(obj):
|
|
||||||
""" The string representation of the entry to add to the DNS """
|
|
||||||
return str(obj.dns_entry)
|
|
||||||
|
|
||||||
|
|
||||||
class DomainSerializer(serializers.ModelSerializer):
|
|
||||||
"""Serialisation d'un domain, extension, cname sont des foreign_key,
|
|
||||||
et l'entrée complète, sont évalués à part"""
|
|
||||||
|
|
||||||
extension = serializers.SerializerMethodField("get_zone_name")
|
|
||||||
cname = serializers.SerializerMethodField("get_alias_name")
|
|
||||||
cname_entry = serializers.SerializerMethodField("get_cname_name")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Domain
|
|
||||||
fields = ("name", "extension", "cname", "cname_entry")
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_zone_name(obj):
|
|
||||||
""" The name of the associated zone """
|
|
||||||
return obj.extension.name
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_alias_name(obj):
|
|
||||||
""" The name of the associated alias """
|
|
||||||
return str(obj.cname)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_cname_name(obj):
|
|
||||||
""" The name of the associated CNAME target """
|
|
||||||
return str(obj.dns_entry)
|
|
||||||
|
|
||||||
|
|
||||||
class ServiceServersSerializer(serializers.ModelSerializer):
|
|
||||||
"""Evaluation d'un Service, et serialisation"""
|
|
||||||
|
|
||||||
server = serializers.SerializerMethodField("get_server_name")
|
|
||||||
service = serializers.SerializerMethodField("get_service_name")
|
|
||||||
need_regen = serializers.SerializerMethodField("get_regen_status")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Service_link
|
|
||||||
fields = ("server", "service", "need_regen")
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_server_name(obj):
|
|
||||||
""" The name of the associated server """
|
|
||||||
return str(obj.server.domain.name)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_service_name(obj):
|
|
||||||
""" The name of the service name """
|
|
||||||
return str(obj.service)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_regen_status(obj):
|
|
||||||
""" The string representation of the regen status """
|
|
||||||
return obj.need_regen
|
|
||||||
|
|
||||||
|
|
||||||
class OuverturePortsSerializer(serializers.Serializer):
|
|
||||||
"""Serialisation de l'ouverture des ports"""
|
|
||||||
|
|
||||||
ipv4 = serializers.SerializerMethodField()
|
|
||||||
ipv6 = serializers.SerializerMethodField()
|
|
||||||
|
|
||||||
def create(self, validated_data):
|
|
||||||
""" Creates a new object based on the un-serialized data.
|
|
||||||
Used to implement an abstract inherited method """
|
|
||||||
pass
|
|
||||||
|
|
||||||
def update(self, instance, validated_data):
|
|
||||||
""" Updates an object based on the un-serialized data.
|
|
||||||
Used to implement an abstract inherited method """
|
|
||||||
pass
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_ipv4():
|
|
||||||
""" The representation of the policy for the IPv4 addresses """
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_ipv6():
|
|
||||||
""" The representation of the policy for the IPv6 addresses """
|
|
||||||
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
|
|
||||||
}
|
|
|
@ -136,18 +136,6 @@ urlpatterns = [
|
||||||
url(r"^del_nas/$", views.del_nas, name="del-nas"),
|
url(r"^del_nas/$", views.del_nas, name="del-nas"),
|
||||||
url(r"^index_nas/$", views.index_nas, name="index-nas"),
|
url(r"^index_nas/$", views.index_nas, name="index-nas"),
|
||||||
url(r"^$", views.index, name="index"),
|
url(r"^$", views.index, name="index"),
|
||||||
url(r"^rest/mac-ip/$", views.mac_ip, name="mac-ip"),
|
|
||||||
url(r"^rest/regen-achieved/$", views.regen_achieved, name="regen-achieved"),
|
|
||||||
url(r"^rest/mac-ip-dns/$", views.mac_ip_dns, name="mac-ip-dns"),
|
|
||||||
url(r"^rest/alias/$", views.alias, name="alias"),
|
|
||||||
url(r"^rest/corresp/$", views.corresp, name="corresp"),
|
|
||||||
url(r"^rest/mx/$", views.mx, name="mx"),
|
|
||||||
url(r"^rest/ns/$", views.ns, name="ns"),
|
|
||||||
url(r"^rest/txt/$", views.txt, name="txt"),
|
|
||||||
url(r"^rest/srv/$", views.srv, name="srv"),
|
|
||||||
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"index_portlist/$", views.index_portlist, name="index-portlist"),
|
||||||
url(
|
url(
|
||||||
r"^edit_portlist/(?P<ouvertureportlistid>[0-9]+)$",
|
r"^edit_portlist/(?P<ouvertureportlistid>[0-9]+)$",
|
||||||
|
|
|
@ -120,18 +120,7 @@ from .models import (
|
||||||
OuverturePort,
|
OuverturePort,
|
||||||
Ipv6List,
|
Ipv6List,
|
||||||
)
|
)
|
||||||
from .serializers import (
|
|
||||||
FullInterfaceSerializer,
|
|
||||||
InterfaceSerializer,
|
|
||||||
TypeSerializer,
|
|
||||||
DomainSerializer,
|
|
||||||
TxtSerializer,
|
|
||||||
SrvSerializer,
|
|
||||||
MxSerializer,
|
|
||||||
ExtensionSerializer,
|
|
||||||
ServiceServersSerializer,
|
|
||||||
NsSerializer,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def f_type_id(is_type_tt):
|
def f_type_id(is_type_tt):
|
||||||
|
@ -1577,240 +1566,3 @@ def configure_ports(request, interface_instance, **_kwargs):
|
||||||
request,
|
request,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Framework Rest
|
|
||||||
|
|
||||||
|
|
||||||
class JSONResponse(HttpResponse):
|
|
||||||
""" Class to build a JSON response. Used for API """
|
|
||||||
|
|
||||||
def __init__(self, data, **kwargs):
|
|
||||||
content = JSONRenderer().render(data)
|
|
||||||
kwargs["content_type"] = "application/json"
|
|
||||||
super(JSONResponse, self).__init__(content, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
|
||||||
@login_required
|
|
||||||
@permission_required("machines.serveur")
|
|
||||||
def mac_ip_list(_request):
|
|
||||||
""" API view to list the active and assigned interfaces """
|
|
||||||
interfaces = all_active_assigned_interfaces()
|
|
||||||
seria = InterfaceSerializer(interfaces, many=True)
|
|
||||||
return seria.data
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
|
||||||
@login_required
|
|
||||||
@permission_required("machines.serveur")
|
|
||||||
def full_mac_ip_list(_request):
|
|
||||||
""" API view to list the active and assigned interfaces. More
|
|
||||||
detailed than mac_ip_list(request) """
|
|
||||||
interfaces = all_active_assigned_interfaces(full=True)
|
|
||||||
seria = FullInterfaceSerializer(interfaces, many=True)
|
|
||||||
return seria.data
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
|
||||||
@login_required
|
|
||||||
@permission_required("machines.serveur")
|
|
||||||
def alias(_request):
|
|
||||||
""" API view to list the alias (CNAME) for all assigned interfaces """
|
|
||||||
alias = (
|
|
||||||
Domain.objects.filter(interface_parent=None)
|
|
||||||
.filter(
|
|
||||||
cname__in=Domain.objects.filter(
|
|
||||||
interface_parent__in=Interface.objects.exclude(ipv4=None)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.select_related("extension")
|
|
||||||
.select_related("cname__extension")
|
|
||||||
)
|
|
||||||
seria = DomainSerializer(alias, many=True)
|
|
||||||
return JSONResponse(seria.data)
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
|
||||||
@login_required
|
|
||||||
@permission_required("machines.serveur")
|
|
||||||
def corresp(_request):
|
|
||||||
""" API view to list the types of IP and infos about it """
|
|
||||||
type = IpType.objects.all().select_related("extension")
|
|
||||||
seria = TypeSerializer(type, many=True)
|
|
||||||
return JSONResponse(seria.data)
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
|
||||||
@login_required
|
|
||||||
@permission_required("machines.serveur")
|
|
||||||
def mx(_request):
|
|
||||||
""" API view to list the MX records """
|
|
||||||
mx = Mx.objects.all().select_related("zone").select_related("name__extension")
|
|
||||||
seria = MxSerializer(mx, many=True)
|
|
||||||
return JSONResponse(seria.data)
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
|
||||||
@login_required
|
|
||||||
@permission_required("machines.serveur")
|
|
||||||
def txt(_request):
|
|
||||||
""" API view to list the TXT records """
|
|
||||||
txt = Txt.objects.all().select_related("zone")
|
|
||||||
seria = TxtSerializer(txt, many=True)
|
|
||||||
return JSONResponse(seria.data)
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
|
||||||
@login_required
|
|
||||||
@permission_required("machines.serveur")
|
|
||||||
def srv(_request):
|
|
||||||
""" API view to list the SRV records """
|
|
||||||
srv = (
|
|
||||||
Srv.objects.all()
|
|
||||||
.select_related("extension")
|
|
||||||
.select_related("target__extension")
|
|
||||||
)
|
|
||||||
seria = SrvSerializer(srv, many=True)
|
|
||||||
return JSONResponse(seria.data)
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
|
||||||
@login_required
|
|
||||||
@permission_required("machines.serveur")
|
|
||||||
def ns(_request):
|
|
||||||
""" API view to list the NS records """
|
|
||||||
ns = (
|
|
||||||
Ns.objects.exclude(
|
|
||||||
ns__in=Domain.objects.filter(
|
|
||||||
interface_parent__in=Interface.objects.filter(ipv4=None)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.select_related("zone")
|
|
||||||
.select_related("ns__extension")
|
|
||||||
)
|
|
||||||
seria = NsSerializer(ns, many=True)
|
|
||||||
return JSONResponse(seria.data)
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
|
||||||
@login_required
|
|
||||||
@permission_required("machines.serveur")
|
|
||||||
def zones(_request):
|
|
||||||
""" API view to list the DNS zones """
|
|
||||||
zones = Extension.objects.all().select_related("origin")
|
|
||||||
seria = ExtensionSerializer(zones, many=True)
|
|
||||||
return JSONResponse(seria.data)
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
|
||||||
@login_required
|
|
||||||
@permission_required("machines.serveur")
|
|
||||||
def mac_ip(request):
|
|
||||||
""" API view to list the active and assigned interfaces """
|
|
||||||
seria = mac_ip_list(request)
|
|
||||||
return JSONResponse(seria)
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
|
||||||
@login_required
|
|
||||||
@permission_required("machines.serveur")
|
|
||||||
def mac_ip_dns(request):
|
|
||||||
""" API view to list the active and assigned interfaces. More
|
|
||||||
detailed than mac_ip_list(request) """
|
|
||||||
seria = full_mac_ip_list(request)
|
|
||||||
return JSONResponse(seria)
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
|
||||||
@login_required
|
|
||||||
@permission_required("machines.serveur")
|
|
||||||
def service_servers(_request):
|
|
||||||
""" API view to list the service links """
|
|
||||||
service_link = (
|
|
||||||
Service_link.objects.all()
|
|
||||||
.select_related("server__domain")
|
|
||||||
.select_related("service")
|
|
||||||
)
|
|
||||||
seria = ServiceServersSerializer(service_link, many=True)
|
|
||||||
return JSONResponse(seria.data)
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
|
||||||
@login_required
|
|
||||||
@permission_required("machines.serveur")
|
|
||||||
def ouverture_ports(_request):
|
|
||||||
""" API view to list the port policies for each IP """
|
|
||||||
r = {"ipv4": {}, "ipv6": {}}
|
|
||||||
for o in (
|
|
||||||
OuverturePortList.objects.all()
|
|
||||||
.prefetch_related("ouvertureport_set")
|
|
||||||
.prefetch_related("interface_set", "interface_set__ipv4")
|
|
||||||
):
|
|
||||||
pl = {
|
|
||||||
"tcp_in": set(
|
|
||||||
map(
|
|
||||||
str,
|
|
||||||
o.ouvertureport_set.filter(
|
|
||||||
protocole=OuverturePort.TCP, io=OuverturePort.IN
|
|
||||||
),
|
|
||||||
)
|
|
||||||
),
|
|
||||||
"tcp_out": set(
|
|
||||||
map(
|
|
||||||
str,
|
|
||||||
o.ouvertureport_set.filter(
|
|
||||||
protocole=OuverturePort.TCP, io=OuverturePort.OUT
|
|
||||||
),
|
|
||||||
)
|
|
||||||
),
|
|
||||||
"udp_in": set(
|
|
||||||
map(
|
|
||||||
str,
|
|
||||||
o.ouvertureport_set.filter(
|
|
||||||
protocole=OuverturePort.UDP, io=OuverturePort.IN
|
|
||||||
),
|
|
||||||
)
|
|
||||||
),
|
|
||||||
"udp_out": set(
|
|
||||||
map(
|
|
||||||
str,
|
|
||||||
o.ouvertureport_set.filter(
|
|
||||||
protocole=OuverturePort.UDP, io=OuverturePort.OUT
|
|
||||||
),
|
|
||||||
)
|
|
||||||
),
|
|
||||||
}
|
|
||||||
for i in filter_active_interfaces(o.interface_set):
|
|
||||||
if i.may_have_port_open():
|
|
||||||
d = r["ipv4"].get(i.ipv4.ipv4, {})
|
|
||||||
d["tcp_in"] = d.get("tcp_in", set()).union(pl["tcp_in"])
|
|
||||||
d["tcp_out"] = d.get("tcp_out", set()).union(pl["tcp_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():
|
|
||||||
for ipv6 in i.ipv6():
|
|
||||||
d = r["ipv6"].get(ipv6.ipv6, {})
|
|
||||||
d["tcp_in"] = d.get("tcp_in", set()).union(pl["tcp_in"])
|
|
||||||
d["tcp_out"] = d.get("tcp_out", set()).union(pl["tcp_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"][ipv6.ipv6] = d
|
|
||||||
return JSONResponse(r)
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
|
||||||
@login_required
|
|
||||||
@permission_required("machines.serveur")
|
|
||||||
def regen_achieved(request):
|
|
||||||
""" API view to list the regen status for each (Service link, Server)
|
|
||||||
couple """
|
|
||||||
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:
|
|
||||||
obj.first().done_regen()
|
|
||||||
return HttpResponse("Ok")
|
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il
|
|
||||||
# se veut agnostique au réseau considéré, de manière à être installable en
|
|
||||||
# quelques clics.
|
|
||||||
#
|
|
||||||
# Copyright © 2017 Gabriel Détraz
|
|
||||||
# Copyright © 2017 Lara Kermarec
|
|
||||||
# Copyright © 2017 Augustin Lemesle
|
|
||||||
#
|
|
||||||
# This program is free software; you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation; either version 2 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License along
|
|
||||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
|
|
||||||
# Maël Kervella
|
|
||||||
|
|
||||||
"""users.serializers
|
|
||||||
Serializers for the User app
|
|
||||||
"""
|
|
||||||
|
|
||||||
from rest_framework import serializers
|
|
||||||
from users.models import Club, Adherent
|
|
||||||
|
|
||||||
|
|
||||||
class MailingSerializer(serializers.ModelSerializer):
|
|
||||||
""" Serializer to build Mailing objects """
|
|
||||||
|
|
||||||
name = serializers.CharField(source="pseudo")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Club
|
|
||||||
fields = ("name",)
|
|
||||||
|
|
||||||
|
|
||||||
class MailingMemberSerializer(serializers.ModelSerializer):
|
|
||||||
""" Serializer fot the Adherent objects (who belong to a
|
|
||||||
Mailing) """
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Adherent
|
|
||||||
fields = ("email",)
|
|
|
@ -127,21 +127,4 @@ urlpatterns = [
|
||||||
url(r"^$", views.index, name="index"),
|
url(r"^$", views.index, name="index"),
|
||||||
url(r"^index_clubs/$", views.index_clubs, name="index-clubs"),
|
url(r"^index_clubs/$", views.index_clubs, name="index-clubs"),
|
||||||
url(r"^initial_register/$", views.initial_register, name="initial-register"),
|
url(r"^initial_register/$", views.initial_register, name="initial-register"),
|
||||||
url(r"^rest/ml/std/$", views.ml_std_list, name="ml-std-list"),
|
|
||||||
url(
|
|
||||||
r"^rest/ml/std/member/(?P<ml_name>\w+)/$",
|
|
||||||
views.ml_std_members,
|
|
||||||
name="ml-std-members",
|
|
||||||
),
|
|
||||||
url(r"^rest/ml/club/$", views.ml_club_list, name="ml-club-list"),
|
|
||||||
url(
|
|
||||||
r"^rest/ml/club/admin/(?P<ml_name>\w+)/$",
|
|
||||||
views.ml_club_admins,
|
|
||||||
name="ml-club-admins",
|
|
||||||
),
|
|
||||||
url(
|
|
||||||
r"^rest/ml/club/member/(?P<ml_name>\w+)/$",
|
|
||||||
views.ml_club_members,
|
|
||||||
name="ml-club-members",
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -74,7 +74,6 @@ from re2o.acl import (
|
||||||
)
|
)
|
||||||
from cotisations.utils import find_payment_method
|
from cotisations.utils import find_payment_method
|
||||||
from topologie.models import Port
|
from topologie.models import Port
|
||||||
from .serializers import MailingSerializer, MailingMemberSerializer
|
|
||||||
from .models import (
|
from .models import (
|
||||||
User,
|
User,
|
||||||
Ban,
|
Ban,
|
||||||
|
@ -1129,78 +1128,3 @@ def initial_register(request):
|
||||||
request,
|
request,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class JSONResponse(HttpResponse):
|
|
||||||
""" Framework Rest """
|
|
||||||
|
|
||||||
def __init__(self, data, **kwargs):
|
|
||||||
content = JSONRenderer().render(data)
|
|
||||||
kwargs["content_type"] = "application/json"
|
|
||||||
super(JSONResponse, self).__init__(content, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
|
||||||
@login_required
|
|
||||||
@permission_required("machines.serveur")
|
|
||||||
def ml_std_list(_request):
|
|
||||||
""" API view sending all the available standard mailings"""
|
|
||||||
return JSONResponse([{"name": "adherents"}])
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
|
||||||
@login_required
|
|
||||||
@permission_required("machines.serveur")
|
|
||||||
def ml_std_members(request, ml_name):
|
|
||||||
""" API view sending all the members for a standard mailing"""
|
|
||||||
# All with active connextion
|
|
||||||
if ml_name == "adherents":
|
|
||||||
members = all_has_access().values("email").distinct()
|
|
||||||
# Unknown mailing
|
|
||||||
else:
|
|
||||||
messages.error(request, _("The mailing list doesn't exist."))
|
|
||||||
return redirect(reverse("index"))
|
|
||||||
seria = MailingMemberSerializer(members, many=True)
|
|
||||||
return JSONResponse(seria.data)
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
|
||||||
@login_required
|
|
||||||
@permission_required("machines.serveur")
|
|
||||||
def ml_club_list(_request):
|
|
||||||
""" API view sending all the available club mailings"""
|
|
||||||
clubs = Club.objects.filter(mailing=True).values("pseudo")
|
|
||||||
seria = MailingSerializer(clubs, many=True)
|
|
||||||
return JSONResponse(seria.data)
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
|
||||||
@login_required
|
|
||||||
@permission_required("machines.serveur")
|
|
||||||
def ml_club_admins(request, ml_name):
|
|
||||||
""" API view sending all the administrators for a specific club mailing"""
|
|
||||||
try:
|
|
||||||
club = Club.objects.get(mailing=True, pseudo=ml_name)
|
|
||||||
except Club.DoesNotExist:
|
|
||||||
messages.error(request, _("The mailing list doesn't exist."))
|
|
||||||
return redirect(reverse("index"))
|
|
||||||
members = club.administrators.all().values("email").distinct()
|
|
||||||
seria = MailingMemberSerializer(members, many=True)
|
|
||||||
return JSONResponse(seria.data)
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
|
||||||
@login_required
|
|
||||||
@permission_required("machines.serveur")
|
|
||||||
def ml_club_members(request, ml_name):
|
|
||||||
""" API view sending all the members for a specific club mailing"""
|
|
||||||
try:
|
|
||||||
club = Club.objects.get(mailing=True, pseudo=ml_name)
|
|
||||||
except Club.DoesNotExist:
|
|
||||||
messages.error(request, _("The mailing list doesn't exist."))
|
|
||||||
return redirect(reverse("index"))
|
|
||||||
members = (
|
|
||||||
club.administrators.all().values("email").distinct()
|
|
||||||
| club.members.all().values("email").distinct()
|
|
||||||
)
|
|
||||||
seria = MailingMemberSerializer(members, many=True)
|
|
||||||
return JSONResponse(seria.data)
|
|
||||||
|
|
Loading…
Reference in a new issue