8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-18 04:53:47 +00:00
re2o/radius/api/serializers.py

130 lines
4.6 KiB
Python
Raw Permalink Normal View History

2020-11-28 14:42:08 +00:00
# -*- mode: python; coding: utf-8 -*-
# Re2o est un logiciel d'administration développé initiallement au Rézo Metz. Il
# se veut agnostique au réseau considéré, de manière à être installable en
# quelques clics.
#
# Copyright © 2020 Corentin Canebier
#
# 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.
2020-11-28 11:09:36 +00:00
from rest_framework import serializers
import machines.models as machines
import users.models as users
from api.serializers import NamespacedHMSerializer
from rest_framework.serializers import Serializer
2020-11-28 14:42:08 +00:00
class Ipv4Serializer(Serializer):
ipv4 = serializers.CharField()
2020-11-28 11:09:36 +00:00
class InterfaceSerializer(Serializer):
mac_address = serializers.CharField()
2020-11-28 14:42:08 +00:00
ipv4 = Ipv4Serializer()
2020-11-28 11:09:36 +00:00
active = serializers.BooleanField(source="is_active")
user_pk = serializers.CharField(source="machine.user.pk")
machine_short_name = serializers.CharField(source="machine.short_name")
is_ban = serializers.BooleanField(source="machine.user.is_ban")
vlan_id = serializers.IntegerField(
source="machine_type.ip_type.vlan.vlan_id")
class NasSerializer(Serializer):
port_access_mode = serializers.CharField()
autocapture_mac = serializers.BooleanField()
class UserSerializer(Serializer):
access = serializers.BooleanField(source="has_access")
pk = serializers.CharField()
pwd_ntlm = serializers.CharField()
state = serializers.CharField()
email_state = serializers.IntegerField()
is_ban = serializers.BooleanField()
is_connected = serializers.BooleanField()
is_whitelisted = serializers.BooleanField()
class PortSerializer(Serializer):
state = serializers.BooleanField()
room = serializers.CharField()
class VlanSerializer(Serializer):
vlan_id = serializers.IntegerField()
class PortProfileSerializer(Serializer):
vlan_untagged = VlanSerializer()
radius_type = serializers.CharField()
2020-11-28 15:24:36 +00:00
radius_mode = serializers.CharField()
2020-11-28 11:09:36 +00:00
class SwitchSerializer(Serializer):
name = serializers.CharField(source="short_name")
ipv4 = serializers.CharField()
class RadiusAttributeSerializer(Serializer):
attribute = serializers.CharField()
value = serializers.CharField()
class RadiusOptionSerializer(Serializer):
radius_general_policy = serializers.CharField()
unknown_machine = serializers.CharField()
unknown_machine_vlan = VlanSerializer()
unknown_machine_attributes = RadiusAttributeSerializer(many=True)
unknown_port = serializers.CharField()
unknown_port_vlan = VlanSerializer()
unknown_port_attributes = RadiusAttributeSerializer(many=True)
unknown_room = serializers.CharField()
unknown_room_vlan = VlanSerializer()
unknown_room_attributes = RadiusAttributeSerializer(many=True)
non_member = serializers.CharField()
non_member_vlan = VlanSerializer()
non_member_attributes = RadiusAttributeSerializer(many=True)
banned = serializers.CharField()
banned_vlan = VlanSerializer()
banned_attributes = RadiusAttributeSerializer(many=True)
vlan_decision_ok = VlanSerializer()
ok_attributes = RadiusAttributeSerializer(many=True)
class AuthorizeResponseSerializer(Serializer):
2020-11-29 09:33:40 +00:00
"""Serializer for AuthorizeResponse objects
See views.py for the declaration of AuthorizeResponse
"""
2020-11-28 11:09:36 +00:00
nas = NasSerializer(read_only=True)
user = UserSerializer(read_only=True)
user_interface = InterfaceSerializer(read_only=True)
class PostAuthResponseSerializer(Serializer):
2020-11-29 09:33:40 +00:00
"""Serializer for PostAuthResponse objects
See views.py for the declaration of PostAuthResponse
"""
2020-11-28 11:09:36 +00:00
nas = NasSerializer(read_only=True)
room_users = UserSerializer(many=True)
port = PortSerializer()
port_profile = PortProfileSerializer(partial=True)
switch = SwitchSerializer()
user_interface = InterfaceSerializer()
radius_option = RadiusOptionSerializer()
EMAIL_STATE_UNVERIFIED = serializers.IntegerField()
RADIUS_OPTION_REJECT = serializers.CharField()
2020-11-28 14:42:08 +00:00
USER_STATE_ACTIVE = serializers.CharField()