8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-24 16:03:47 +00:00

Merge branch 'firewall_export' into 'dev'

Firewall export

See merge request federez/re2o!224
This commit is contained in:
chirac 2018-08-05 21:07:12 +02:00
commit ee615ae1e1
5 changed files with 41 additions and 2 deletions

View file

@ -552,6 +552,15 @@ class AdherentSerializer(NamespacedHMSerializer):
'shell': {'view_name': 'shell-detail'} 'shell': {'view_name': 'shell-detail'}
} }
class HomeCreationSerializer(NamespacedHMSerializer):
"""Serialize 'users.models.User' minimal infos to create home
"""
uid = serializers.IntegerField(source='uid_number')
gid = serializers.IntegerField(source='gid_number')
class Meta:
model = users.User
fields = ('pseudo', 'uid', 'gid')
class ServiceUserSerializer(NamespacedHMSerializer): class ServiceUserSerializer(NamespacedHMSerializer):
"""Serialize `users.models.ServiceUser` objects. """Serialize `users.models.ServiceUser` objects.
@ -656,7 +665,7 @@ class LocalEmailUsersSerializer(NamespacedHMSerializer):
class FirewallPortListSerializer(serializers.ModelSerializer): class FirewallPortListSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = machines.OuverturePort model = machines.OuverturePort
fields = ('begin', 'end', 'protocole', 'io') fields = ('begin', 'end', 'protocole', 'io', 'show_port')
class FirewallOuverturePortListSerializer(serializers.ModelSerializer): class FirewallOuverturePortListSerializer(serializers.ModelSerializer):
tcp_ports_in = FirewallPortListSerializer(many=True, read_only=True) tcp_ports_in = FirewallPortListSerializer(many=True, read_only=True)
@ -673,7 +682,16 @@ class SubnetPortsOpenSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = machines.IpType model = machines.IpType
fields = ('type', 'domaine_ip_start', 'domaine_ip_stop', 'prefix_v6', 'ouverture_ports') fields = ('type', 'domaine_ip_start', 'domaine_ip_stop', 'complete_prefixv6', 'ouverture_ports')
class InterfacePortsOpenSerializer(serializers.ModelSerializer):
port_lists = FirewallOuverturePortListSerializer(read_only=True, many=True)
ipv4 = serializers.CharField(source='ipv4.ipv4', read_only=True)
ipv6 = Ipv6ListSerializer(many=True, read_only=True)
class Meta:
model = machines.Interface
fields = ('port_lists', 'ipv4', 'ipv6')
# DHCP # DHCP

View file

@ -86,6 +86,7 @@ router.register_viewset(r'topologie/room', views.RoomViewSet)
router.register(r'topologie/portprofile', views.PortProfileViewSet) router.register(r'topologie/portprofile', views.PortProfileViewSet)
# USERS # USERS
router.register_viewset(r'users/user', views.UserViewSet) router.register_viewset(r'users/user', views.UserViewSet)
router.register_viewset(r'users/homecreation', views.HomeCreationViewSet)
router.register_viewset(r'users/club', views.ClubViewSet) router.register_viewset(r'users/club', views.ClubViewSet)
router.register_viewset(r'users/adherent', views.AdherentViewSet) router.register_viewset(r'users/adherent', views.AdherentViewSet)
router.register_viewset(r'users/serviceuser', views.ServiceUserViewSet) router.register_viewset(r'users/serviceuser', views.ServiceUserViewSet)
@ -103,6 +104,7 @@ router.register_view(r'dhcp/hostmacip', views.HostMacIpView),
router.register_view(r'localemail/users', views.LocalEmailUsersView), router.register_view(r'localemail/users', views.LocalEmailUsersView),
# Firewall # Firewall
router.register_view(r'firewall/subnet-ports', views.SubnetPortsOpenView), router.register_view(r'firewall/subnet-ports', views.SubnetPortsOpenView),
router.register_view(r'firewall/interface-ports', views.InterfacePortsOpenView),
# DNS # DNS
router.register_view(r'dns/zones', views.DNSZonesView), router.register_view(r'dns/zones', views.DNSZonesView),
router.register_view(r'dns/reverse-zones', views.DNSReverseZonesView), router.register_view(r'dns/reverse-zones', views.DNSReverseZonesView),

View file

@ -418,6 +418,11 @@ class UserViewSet(viewsets.ReadOnlyModelViewSet):
queryset = users.User.objects.all() queryset = users.User.objects.all()
serializer_class = serializers.UserSerializer serializer_class = serializers.UserSerializer
class HomeCreationViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes infos of `users.models.Users` objects to create homes.
"""
queryset = users.User.objects.all()
serializer_class = serializers.HomeCreationSerializer
class ClubViewSet(viewsets.ReadOnlyModelViewSet): class ClubViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `users.models.Club` objects. """Exposes list and details of `users.models.Club` objects.
@ -544,6 +549,10 @@ class SubnetPortsOpenView(generics.ListAPIView):
queryset = machines.IpType.objects.all() queryset = machines.IpType.objects.all()
serializer_class = serializers.SubnetPortsOpenSerializer serializer_class = serializers.SubnetPortsOpenSerializer
class InterfacePortsOpenView(generics.ListAPIView):
queryset = machines.Interface.objects.filter(port_lists__isnull=False).distinct()
serializer_class = serializers.InterfacePortsOpenSerializer
# DNS # DNS

View file

@ -358,6 +358,11 @@ class IpType(RevMixin, AclMixin, models.Model):
else: else:
return None return None
@cached_property
def complete_prefixv6(self):
"""Return the complete prefix v6 as cidr"""
return str(self.prefix_v6) + "/" + str(self.prefix_v6_length)
def ip_objects(self): def ip_objects(self):
""" Renvoie tous les objets ipv4 relié à ce type""" """ Renvoie tous les objets ipv4 relié à ce type"""
return IpList.objects.filter(ip_type=self) return IpList.objects.filter(ip_type=self)

View file

@ -283,6 +283,11 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
else: else:
raise NotImplementedError("Type inconnu") raise NotImplementedError("Type inconnu")
@cached_property
def gid_number(self):
"""renvoie le gid par défaut des users"""
return int(LDAP['user_gid'])
@cached_property @cached_property
def is_class_club(self): def is_class_club(self):
""" Returns True if the object is a Club (subclassing User) """ """ Returns True if the object is a Club (subclassing User) """