mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-23 23:43:47 +00:00
Pylint compliance on machines
This commit is contained in:
parent
2114a6ebba
commit
e88141db56
8 changed files with 385 additions and 199 deletions
|
@ -20,5 +20,8 @@
|
|||
# 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.
|
||||
"""machines
|
||||
The app in charge of everything related to the machines, the interface, ...
|
||||
"""
|
||||
|
||||
from .acl import *
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
# 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.
|
||||
"""machines.admin
|
||||
The objects, fields and datastructures visible in the Django admin view
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
@ -44,74 +47,92 @@ from .models import (
|
|||
|
||||
|
||||
class MachineAdmin(VersionAdmin):
|
||||
""" Admin view of a Machine object """
|
||||
pass
|
||||
|
||||
|
||||
class Ipv6ListAdmin(VersionAdmin):
|
||||
""" Admin view of a Ipv6List object """
|
||||
pass
|
||||
|
||||
|
||||
class IpTypeAdmin(VersionAdmin):
|
||||
""" Admin view of a IpType object """
|
||||
pass
|
||||
|
||||
|
||||
class MachineTypeAdmin(VersionAdmin):
|
||||
""" Admin view of a MachineType object """
|
||||
pass
|
||||
|
||||
|
||||
class VlanAdmin(VersionAdmin):
|
||||
""" Admin view of a Vlan object """
|
||||
pass
|
||||
|
||||
|
||||
class ExtensionAdmin(VersionAdmin):
|
||||
""" Admin view of a Extension object """
|
||||
pass
|
||||
|
||||
|
||||
class SOAAdmin(VersionAdmin):
|
||||
""" Admin view of a SOA object """
|
||||
pass
|
||||
|
||||
|
||||
class MxAdmin(VersionAdmin):
|
||||
""" Admin view of a MX object """
|
||||
pass
|
||||
|
||||
|
||||
class NsAdmin(VersionAdmin):
|
||||
""" Admin view of a NS object """
|
||||
pass
|
||||
|
||||
|
||||
class TxtAdmin(VersionAdmin):
|
||||
""" Admin view of a TXT object """
|
||||
pass
|
||||
|
||||
|
||||
class SrvAdmin(VersionAdmin):
|
||||
""" Admin view of a SRV object """
|
||||
pass
|
||||
|
||||
|
||||
class NasAdmin(VersionAdmin):
|
||||
""" Admin view of a Nas object """
|
||||
pass
|
||||
|
||||
|
||||
class IpListAdmin(VersionAdmin):
|
||||
""" Admin view of a Ipv4List object """
|
||||
pass
|
||||
|
||||
|
||||
class OuverturePortAdmin(VersionAdmin):
|
||||
""" Admin view of a OuverturePort object """
|
||||
pass
|
||||
|
||||
|
||||
class OuverturePortListAdmin(VersionAdmin):
|
||||
""" Admin view of a OuverturePortList object """
|
||||
pass
|
||||
|
||||
|
||||
class InterfaceAdmin(VersionAdmin):
|
||||
""" Admin view of a Interface object """
|
||||
list_display = ('machine', 'type', 'mac_address', 'ipv4', 'details')
|
||||
|
||||
|
||||
class DomainAdmin(VersionAdmin):
|
||||
""" Admin view of a Domain object """
|
||||
list_display = ('interface_parent', 'name', 'extension', 'cname')
|
||||
|
||||
|
||||
class ServiceAdmin(VersionAdmin):
|
||||
""" Admin view of a ServiceAdmin object """
|
||||
list_display = ('service_type', 'min_time_regen', 'regular_time_regen')
|
||||
|
||||
|
||||
|
|
|
@ -137,10 +137,10 @@ class AliasForm(FormRevMixin, ModelForm):
|
|||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||
user = kwargs.pop('user')
|
||||
super(AliasForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||
can_use_all, reason = Extension.can_use_all(user)
|
||||
can_use_all, _reason = Extension.can_use_all(user)
|
||||
if not can_use_all:
|
||||
self.fields['extension'].queryset = Extension.objects.filter(
|
||||
need_infra=False
|
||||
need_infra=False
|
||||
)
|
||||
|
||||
|
||||
|
@ -480,6 +480,8 @@ class ServiceForm(FormRevMixin, ModelForm):
|
|||
))
|
||||
|
||||
def save(self, commit=True):
|
||||
# TODO : None of the parents of ServiceForm use the commit
|
||||
# parameter in .save()
|
||||
instance = super(ServiceForm, self).save(commit=False)
|
||||
if commit:
|
||||
instance.save()
|
||||
|
|
|
@ -20,14 +20,17 @@
|
|||
# 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.
|
||||
"""machines.models
|
||||
The models definitions for the Machines app
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from datetime import timedelta
|
||||
import re
|
||||
from netaddr import mac_bare, EUI, IPSet, IPRange, IPNetwork, IPAddress
|
||||
from ipaddress import IPv6Address
|
||||
from itertools import chain
|
||||
from netaddr import mac_bare, EUI, IPSet, IPRange, IPNetwork, IPAddress
|
||||
|
||||
from django.db import models
|
||||
from django.db.models.signals import post_save, post_delete
|
||||
|
@ -67,12 +70,13 @@ class Machine(RevMixin, FieldPermissionModelMixin, models.Model):
|
|||
"Peut changer le propriétaire d'une machine"),
|
||||
)
|
||||
|
||||
def get_instance(machineid, *args, **kwargs):
|
||||
@classmethod
|
||||
def get_instance(cls, machineid, *_args, **_kwargs):
|
||||
"""Get the Machine instance with machineid.
|
||||
:param userid: The id
|
||||
:return: The user
|
||||
"""
|
||||
return Machine.objects.get(pk=machineid)
|
||||
return cls.objects.get(pk=machineid)
|
||||
|
||||
def linked_objects(self):
|
||||
"""Return linked objects : machine and domain.
|
||||
|
@ -85,7 +89,7 @@ class Machine(RevMixin, FieldPermissionModelMixin, models.Model):
|
|||
)
|
||||
|
||||
@staticmethod
|
||||
def can_change_user(user_request, *args, **kwargs):
|
||||
def can_change_user(user_request, *_args, **_kwargs):
|
||||
"""Checks if an user is allowed to change the user who owns a
|
||||
Machine.
|
||||
|
||||
|
@ -99,7 +103,8 @@ class Machine(RevMixin, FieldPermissionModelMixin, models.Model):
|
|||
return (user_request.has_perm('machines.change_machine_user'),
|
||||
"Vous ne pouvez pas modifier l'utilisateur de la machine.")
|
||||
|
||||
def can_view_all(user_request, *args, **kwargs):
|
||||
@staticmethod
|
||||
def can_view_all(user_request, *_args, **_kwargs):
|
||||
"""Vérifie qu'on peut bien afficher l'ensemble des machines,
|
||||
droit particulier correspondant
|
||||
:param user_request: instance user qui fait l'edition
|
||||
|
@ -109,7 +114,8 @@ class Machine(RevMixin, FieldPermissionModelMixin, models.Model):
|
|||
"machines sans permission")
|
||||
return True, None
|
||||
|
||||
def can_create(user_request, userid, *args, **kwargs):
|
||||
@staticmethod
|
||||
def can_create(user_request, userid, *_args, **_kwargs):
|
||||
"""Vérifie qu'un user qui fait la requète peut bien créer la machine
|
||||
et n'a pas atteint son quota, et crée bien une machine à lui
|
||||
:param user_request: Utilisateur qui fait la requête
|
||||
|
@ -172,7 +178,7 @@ class Machine(RevMixin, FieldPermissionModelMixin, models.Model):
|
|||
"d'un autre user que vous sans droit")
|
||||
return True, None
|
||||
|
||||
def can_view(self, user_request, *args, **kwargs):
|
||||
def can_view(self, user_request, *_args, **_kwargs):
|
||||
"""Vérifie qu'on peut bien voir cette instance particulière (soit
|
||||
machine de soi, soit droit particulier
|
||||
:param self: instance machine à éditer
|
||||
|
@ -218,7 +224,8 @@ class MachineType(RevMixin, AclMixin, models.Model):
|
|||
machinetype"""
|
||||
return Interface.objects.filter(type=self)
|
||||
|
||||
def can_use_all(user_request, *args, **kwargs):
|
||||
@staticmethod
|
||||
def can_use_all(user_request, *_args, **_kwargs):
|
||||
"""Check if an user can use every MachineType.
|
||||
|
||||
Args:
|
||||
|
@ -328,10 +335,10 @@ class IpType(RevMixin, AclMixin, models.Model):
|
|||
return
|
||||
else:
|
||||
for ipv6 in Ipv6List.objects.filter(
|
||||
interface__in=Interface.objects.filter(
|
||||
type__in=MachineType.objects.filter(ip_type=self)
|
||||
)
|
||||
):
|
||||
interface__in=Interface.objects.filter(
|
||||
type__in=MachineType.objects.filter(ip_type=self)
|
||||
)
|
||||
):
|
||||
ipv6.check_and_replace_prefix(prefix=self.prefix_v6)
|
||||
|
||||
def clean(self):
|
||||
|
@ -360,7 +367,8 @@ class IpType(RevMixin, AclMixin, models.Model):
|
|||
self.clean()
|
||||
super(IpType, self).save(*args, **kwargs)
|
||||
|
||||
def can_use_all(user_request, *args, **kwargs):
|
||||
@staticmethod
|
||||
def can_use_all(user_request, *_args, **_kwargs):
|
||||
"""Superdroit qui permet d'utiliser toutes les extensions sans
|
||||
restrictions
|
||||
:param user_request: instance user qui fait l'edition
|
||||
|
@ -555,7 +563,8 @@ class Extension(RevMixin, AclMixin, models.Model):
|
|||
entry += "@ IN AAAA " + str(self.origin_v6)
|
||||
return entry
|
||||
|
||||
def can_use_all(user_request, *args, **kwargs):
|
||||
@staticmethod
|
||||
def can_use_all(user_request, *_args, **_kwargs):
|
||||
"""Superdroit qui permet d'utiliser toutes les extensions sans
|
||||
restrictions
|
||||
:param user_request: instance user qui fait l'edition
|
||||
|
@ -644,6 +653,7 @@ class Txt(RevMixin, AclMixin, models.Model):
|
|||
|
||||
|
||||
class Srv(RevMixin, AclMixin, models.Model):
|
||||
""" A SRV record """
|
||||
PRETTY_NAME = "Enregistrement Srv"
|
||||
|
||||
TCP = 'TCP'
|
||||
|
@ -874,7 +884,8 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
|||
correspondent pas")
|
||||
super(Interface, self).save(*args, **kwargs)
|
||||
|
||||
def can_create(user_request, machineid, *args, **kwargs):
|
||||
@staticmethod
|
||||
def can_create(user_request, machineid, *_args, **_kwargs):
|
||||
"""Verifie que l'user a les bons droits infra pour créer
|
||||
une interface, ou bien que la machine appartient bien à l'user
|
||||
:param macineid: Id de la machine parente de l'interface
|
||||
|
@ -903,7 +914,9 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
|||
return True, None
|
||||
|
||||
@staticmethod
|
||||
def can_change_machine(user_request, *args, **kwargs):
|
||||
def can_change_machine(user_request, *_args, **_kwargs):
|
||||
"""Check if a user can change the machine associated with an
|
||||
Interface object """
|
||||
return (user_request.has_perm('machines.change_interface_machine'),
|
||||
"Droit requis pour changer la machine")
|
||||
|
||||
|
@ -941,7 +954,7 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
|||
"d'un autre user que vous sans droit")
|
||||
return True, None
|
||||
|
||||
def can_view(self, user_request, *args, **kwargs):
|
||||
def can_view(self, user_request, *_args, **_kwargs):
|
||||
"""Vérifie qu'on peut bien voir cette instance particulière avec
|
||||
droit view objet ou qu'elle appartient à l'user
|
||||
:param self: instance interface à voir
|
||||
|
@ -981,6 +994,7 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
|||
|
||||
|
||||
class Ipv6List(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
||||
""" A list of IPv6 """
|
||||
PRETTY_NAME = 'Enregistrements Ipv6 des machines'
|
||||
|
||||
ipv6 = models.GenericIPAddressField(
|
||||
|
@ -1001,7 +1015,8 @@ class Ipv6List(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
|||
"Peut changer la valeur slaac sur une ipv6"),
|
||||
)
|
||||
|
||||
def can_create(user_request, interfaceid, *args, **kwargs):
|
||||
@staticmethod
|
||||
def can_create(user_request, interfaceid, *_args, **_kwargs):
|
||||
"""Verifie que l'user a les bons droits infra pour créer
|
||||
une ipv6, ou possède l'interface associée
|
||||
:param interfaceid: Id de l'interface associée à cet objet domain
|
||||
|
@ -1018,7 +1033,8 @@ class Ipv6List(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
|||
return True, None
|
||||
|
||||
@staticmethod
|
||||
def can_change_slaac_ip(user_request, *args, **kwargs):
|
||||
def can_change_slaac_ip(user_request, *_args, **_kwargs):
|
||||
""" Check if a user can change the slaac value """
|
||||
return (user_request.has_perm('machines.change_ipv6list_slaac_ip'),
|
||||
"Droit requis pour changer la valeur slaac ip")
|
||||
|
||||
|
@ -1056,7 +1072,7 @@ class Ipv6List(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
|||
"d'un autre user que vous sans droit")
|
||||
return True, None
|
||||
|
||||
def can_view(self, user_request, *args, **kwargs):
|
||||
def can_view(self, user_request, *_args, **_kwargs):
|
||||
"""Vérifie qu'on peut bien voir cette instance particulière avec
|
||||
droit view objet ou qu'elle appartient à l'user
|
||||
:param self: instance interface à voir
|
||||
|
@ -1165,7 +1181,7 @@ class Domain(RevMixin, AclMixin, models.Model):
|
|||
if self.cname == self:
|
||||
raise ValidationError("On ne peut créer un cname sur lui même")
|
||||
HOSTNAME_LABEL_PATTERN = re.compile(
|
||||
"(?!-)[A-Z\d-]+(?<!-)$",
|
||||
r"(?!-)[A-Z\d-]+(?<!-)$",
|
||||
re.IGNORECASE
|
||||
)
|
||||
dns = self.name.lower()
|
||||
|
@ -1207,7 +1223,8 @@ class Domain(RevMixin, AclMixin, models.Model):
|
|||
else:
|
||||
return self.cname.get_parent_interface()
|
||||
|
||||
def can_create(user_request, interfaceid, *args, **kwargs):
|
||||
@staticmethod
|
||||
def can_create(user_request, interfaceid, *_args, **_kwargs):
|
||||
"""Verifie que l'user a les bons droits infra pour créer
|
||||
un domain, ou possède l'interface associée
|
||||
:param interfaceid: Id de l'interface associée à cet objet domain
|
||||
|
@ -1226,17 +1243,17 @@ class Domain(RevMixin, AclMixin, models.Model):
|
|||
return False, (u"Vous ne pouvez pas ajouter un alias à une "
|
||||
"machine d'un autre user que vous sans droit")
|
||||
if Domain.objects.filter(
|
||||
cname__in=Domain.objects.filter(
|
||||
interface_parent__in=(interface.machine.user
|
||||
.user_interfaces())
|
||||
)
|
||||
).count() >= max_lambdauser_aliases:
|
||||
cname__in=Domain.objects.filter(
|
||||
interface_parent__in=(interface.machine.user
|
||||
.user_interfaces())
|
||||
)
|
||||
).count() >= max_lambdauser_aliases:
|
||||
return False, (u"Vous avez atteint le maximum d'alias "
|
||||
"autorisés que vous pouvez créer vous même "
|
||||
"(%s) " % max_lambdauser_aliases)
|
||||
return True, None
|
||||
|
||||
def can_edit(self, user_request, *args, **kwargs):
|
||||
def can_edit(self, user_request, *_args, **_kwargs):
|
||||
"""Verifie que l'user a les bons droits pour editer
|
||||
cette instance domain
|
||||
:param self: Instance domain à editer
|
||||
|
@ -1248,7 +1265,7 @@ class Domain(RevMixin, AclMixin, models.Model):
|
|||
"d'un autre user que vous sans droit")
|
||||
return True, None
|
||||
|
||||
def can_delete(self, user_request, *args, **kwargs):
|
||||
def can_delete(self, user_request, *_args, **_kwargs):
|
||||
"""Verifie que l'user a les bons droits delete object pour del
|
||||
cette instance domain, ou qu'elle lui appartient
|
||||
:param self: Instance domain à del
|
||||
|
@ -1260,7 +1277,7 @@ class Domain(RevMixin, AclMixin, models.Model):
|
|||
"machine d'un autre user que vous sans droit")
|
||||
return True, None
|
||||
|
||||
def can_view(self, user_request, *args, **kwargs):
|
||||
def can_view(self, user_request, *_args, **_kwargs):
|
||||
"""Vérifie qu'on peut bien voir cette instance particulière avec
|
||||
droit view objet ou qu'elle appartient à l'user
|
||||
:param self: instance domain à voir
|
||||
|
@ -1277,6 +1294,7 @@ class Domain(RevMixin, AclMixin, models.Model):
|
|||
|
||||
|
||||
class IpList(RevMixin, AclMixin, models.Model):
|
||||
""" A list of IPv4 """
|
||||
PRETTY_NAME = "Addresses ipv4"
|
||||
|
||||
ipv4 = models.GenericIPAddressField(protocol='IPv4', unique=True)
|
||||
|
@ -1338,8 +1356,8 @@ class Service(RevMixin, AclMixin, models.Model):
|
|||
""" Django ne peut créer lui meme les relations manytomany avec table
|
||||
intermediaire explicite"""
|
||||
for serv in servers.exclude(
|
||||
pk__in=Interface.objects.filter(service=self)
|
||||
):
|
||||
pk__in=Interface.objects.filter(service=self)
|
||||
):
|
||||
link = Service_link(service=self, server=serv)
|
||||
link.save()
|
||||
Service_link.objects.filter(service=self).exclude(server__in=servers)\
|
||||
|
@ -1407,7 +1425,7 @@ class OuverturePortList(RevMixin, AclMixin, models.Model):
|
|||
("view_ouvertureportlist", "Peut voir un objet ouvertureport"),
|
||||
)
|
||||
|
||||
def can_delete(self, user_request, *args, **kwargs):
|
||||
def can_delete(self, user_request, *_args, **_kwargs):
|
||||
"""Verifie que l'user a les bons droits bureau pour delete
|
||||
cette instance ouvertureportlist
|
||||
:param self: Instance ouvertureportlist à delete
|
||||
|
@ -1501,7 +1519,7 @@ class OuverturePort(RevMixin, AclMixin, models.Model):
|
|||
|
||||
|
||||
@receiver(post_save, sender=Machine)
|
||||
def machine_post_save(sender, **kwargs):
|
||||
def machine_post_save(_sender, **kwargs):
|
||||
"""Synchronisation ldap et régen parefeu/dhcp lors de la modification
|
||||
d'une machine"""
|
||||
user = kwargs['instance'].user
|
||||
|
@ -1511,7 +1529,7 @@ def machine_post_save(sender, **kwargs):
|
|||
|
||||
|
||||
@receiver(post_delete, sender=Machine)
|
||||
def machine_post_delete(sender, **kwargs):
|
||||
def machine_post_delete(_sender, **kwargs):
|
||||
"""Synchronisation ldap et régen parefeu/dhcp lors de la suppression
|
||||
d'une machine"""
|
||||
machine = kwargs['instance']
|
||||
|
@ -1522,7 +1540,7 @@ def machine_post_delete(sender, **kwargs):
|
|||
|
||||
|
||||
@receiver(post_save, sender=Interface)
|
||||
def interface_post_save(sender, **kwargs):
|
||||
def interface_post_save(_sender, **kwargs):
|
||||
"""Synchronisation ldap et régen parefeu/dhcp lors de la modification
|
||||
d'une interface"""
|
||||
interface = kwargs['instance']
|
||||
|
@ -1535,7 +1553,7 @@ def interface_post_save(sender, **kwargs):
|
|||
|
||||
|
||||
@receiver(post_delete, sender=Interface)
|
||||
def interface_post_delete(sender, **kwargs):
|
||||
def interface_post_delete(_sender, **kwargs):
|
||||
"""Synchronisation ldap et régen parefeu/dhcp lors de la suppression
|
||||
d'une interface"""
|
||||
interface = kwargs['instance']
|
||||
|
@ -1544,7 +1562,7 @@ def interface_post_delete(sender, **kwargs):
|
|||
|
||||
|
||||
@receiver(post_save, sender=IpType)
|
||||
def iptype_post_save(sender, **kwargs):
|
||||
def iptype_post_save(_sender, **kwargs):
|
||||
"""Generation des objets ip après modification d'un range ip"""
|
||||
iptype = kwargs['instance']
|
||||
iptype.gen_ip_range()
|
||||
|
@ -1552,7 +1570,7 @@ def iptype_post_save(sender, **kwargs):
|
|||
|
||||
|
||||
@receiver(post_save, sender=MachineType)
|
||||
def machinetype_post_save(sender, **kwargs):
|
||||
def machinetype_post_save(_sender, **kwargs):
|
||||
"""Mise à jour des interfaces lorsque changement d'attribution
|
||||
d'une machinetype (changement iptype parent)"""
|
||||
machinetype = kwargs['instance']
|
||||
|
@ -1561,84 +1579,84 @@ def machinetype_post_save(sender, **kwargs):
|
|||
|
||||
|
||||
@receiver(post_save, sender=Domain)
|
||||
def domain_post_save(sender, **kwargs):
|
||||
def domain_post_save(_sender, **_kwargs):
|
||||
"""Regeneration dns après modification d'un domain object"""
|
||||
regen('dns')
|
||||
|
||||
|
||||
@receiver(post_delete, sender=Domain)
|
||||
def domain_post_delete(sender, **kwargs):
|
||||
def domain_post_delete(_sender, **_kwargs):
|
||||
"""Regeneration dns après suppression d'un domain object"""
|
||||
regen('dns')
|
||||
|
||||
|
||||
@receiver(post_save, sender=Extension)
|
||||
def extension_post_save(sender, **kwargs):
|
||||
def extension_post_save(_sender, **_kwargs):
|
||||
"""Regeneration dns après modification d'une extension"""
|
||||
regen('dns')
|
||||
|
||||
|
||||
@receiver(post_delete, sender=Extension)
|
||||
def extension_post_selete(sender, **kwargs):
|
||||
def extension_post_selete(_sender, **_kwargs):
|
||||
"""Regeneration dns après suppression d'une extension"""
|
||||
regen('dns')
|
||||
|
||||
|
||||
@receiver(post_save, sender=SOA)
|
||||
def soa_post_save(sender, **kwargs):
|
||||
def soa_post_save(_sender, **_kwargs):
|
||||
"""Regeneration dns après modification d'un SOA"""
|
||||
regen('dns')
|
||||
|
||||
|
||||
@receiver(post_delete, sender=SOA)
|
||||
def soa_post_delete(sender, **kwargs):
|
||||
def soa_post_delete(_sender, **_kwargs):
|
||||
"""Regeneration dns après suppresson d'un SOA"""
|
||||
regen('dns')
|
||||
|
||||
|
||||
@receiver(post_save, sender=Mx)
|
||||
def mx_post_save(sender, **kwargs):
|
||||
def mx_post_save(_sender, **_kwargs):
|
||||
"""Regeneration dns après modification d'un MX"""
|
||||
regen('dns')
|
||||
|
||||
|
||||
@receiver(post_delete, sender=Mx)
|
||||
def mx_post_delete(sender, **kwargs):
|
||||
def mx_post_delete(_sender, **_kwargs):
|
||||
"""Regeneration dns après suppresson d'un MX"""
|
||||
regen('dns')
|
||||
|
||||
|
||||
@receiver(post_save, sender=Ns)
|
||||
def ns_post_save(sender, **kwargs):
|
||||
def ns_post_save(_sender, **_kwargs):
|
||||
"""Regeneration dns après modification d'un NS"""
|
||||
regen('dns')
|
||||
|
||||
|
||||
@receiver(post_delete, sender=Ns)
|
||||
def ns_post_delete(sender, **kwargs):
|
||||
def ns_post_delete(_sender, **_kwargs):
|
||||
"""Regeneration dns après modification d'un NS"""
|
||||
regen('dns')
|
||||
|
||||
|
||||
@receiver(post_save, sender=Txt)
|
||||
def text_post_save(sender, **kwargs):
|
||||
def text_post_save(_sender, **_kwargs):
|
||||
"""Regeneration dns après modification d'un TXT"""
|
||||
regen('dns')
|
||||
|
||||
|
||||
@receiver(post_delete, sender=Txt)
|
||||
def text_post_delete(sender, **kwargs):
|
||||
def text_post_delete(_sender, **_kwargs):
|
||||
"""Regeneration dns après modification d'un TX"""
|
||||
regen('dns')
|
||||
|
||||
|
||||
@receiver(post_save, sender=Srv)
|
||||
def srv_post_save(sender, **kwargs):
|
||||
def srv_post_save(_sender, **_kwargs):
|
||||
"""Regeneration dns après modification d'un SRV"""
|
||||
regen('dns')
|
||||
|
||||
|
||||
@receiver(post_delete, sender=Srv)
|
||||
def srv_post_delete(sender, **kwargs):
|
||||
def srv_post_delete(_sender, **_kwargs):
|
||||
"""Regeneration dns après modification d'un SRV"""
|
||||
regen('dns')
|
||||
|
|
|
@ -22,6 +22,10 @@
|
|||
# 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 (
|
||||
|
@ -29,28 +33,30 @@ from machines.models import (
|
|||
IpType,
|
||||
Extension,
|
||||
IpList,
|
||||
MachineType,
|
||||
Domain,
|
||||
Txt,
|
||||
Mx,
|
||||
Srv,
|
||||
Service_link,
|
||||
Ns,
|
||||
OuverturePortList,
|
||||
OuverturePort,
|
||||
Ipv6List
|
||||
)
|
||||
|
||||
|
||||
class IpTypeField(serializers.RelatedField):
|
||||
"""Serialisation d'une iptype, renvoie son evaluation str"""
|
||||
""" Serializer for an IpType object field """
|
||||
|
||||
def to_representation(self, value):
|
||||
return value.type
|
||||
|
||||
def to_internal_value(self, data):
|
||||
pass
|
||||
|
||||
|
||||
class IpListSerializer(serializers.ModelSerializer):
|
||||
"""Serialisation d'une iplist, ip_type etant une foreign_key,
|
||||
on evalue sa methode str"""
|
||||
""" Serializer for an Ipv4List obejct using the IpType serialization """
|
||||
|
||||
ip_type = IpTypeField(read_only=True)
|
||||
|
||||
class Meta:
|
||||
|
@ -59,16 +65,19 @@ class IpListSerializer(serializers.ModelSerializer):
|
|||
|
||||
|
||||
class Ipv6ListSerializer(serializers.ModelSerializer):
|
||||
""" Serializer for an Ipv6List object """
|
||||
|
||||
class Meta:
|
||||
model = Ipv6List
|
||||
fields = ('ipv6', 'slaac_ip')
|
||||
|
||||
|
||||
class InterfaceSerializer(serializers.ModelSerializer):
|
||||
"""Serialisation d'une interface, ipv4, domain et extension sont
|
||||
des foreign_key, on les override et on les evalue avec des fonctions
|
||||
get_..."""
|
||||
""" 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')
|
||||
|
@ -77,20 +86,29 @@ class InterfaceSerializer(serializers.ModelSerializer):
|
|||
model = Interface
|
||||
fields = ('ipv4', 'mac_address', 'domain', 'extension')
|
||||
|
||||
def get_dns(self, obj):
|
||||
@staticmethod
|
||||
def get_dns(obj):
|
||||
""" The name of the associated DNS object """
|
||||
return obj.domain.name
|
||||
|
||||
def get_interface_extension(self, obj):
|
||||
@staticmethod
|
||||
def get_interface_extension(obj):
|
||||
""" The name of the associated Interface object """
|
||||
return obj.domain.extension.name
|
||||
|
||||
def get_macaddress(self, obj):
|
||||
@staticmethod
|
||||
def get_macaddress(obj):
|
||||
""" The string representation of the associated MAC address """
|
||||
return str(obj.mac_address)
|
||||
|
||||
|
||||
class FullInterfaceSerializer(serializers.ModelSerializer):
|
||||
"""Serialisation complete d'une interface avec les ipv6 en plus"""
|
||||
""" 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')
|
||||
|
@ -99,26 +117,36 @@ class FullInterfaceSerializer(serializers.ModelSerializer):
|
|||
model = Interface
|
||||
fields = ('ipv4', 'ipv6', 'mac_address', 'domain', 'extension')
|
||||
|
||||
def get_dns(self, obj):
|
||||
@staticmethod
|
||||
def get_dns(obj):
|
||||
""" The name of the associated DNS object """
|
||||
return obj.domain.name
|
||||
|
||||
def get_interface_extension(self, obj):
|
||||
@staticmethod
|
||||
def get_interface_extension(obj):
|
||||
""" The name of the associated Extension object """
|
||||
return obj.domain.extension.name
|
||||
|
||||
def get_macaddress(self, obj):
|
||||
@staticmethod
|
||||
def get_macaddress(obj):
|
||||
""" The string representation of the associated MAC address """
|
||||
return str(obj.mac_address)
|
||||
|
||||
|
||||
class ExtensionNameField(serializers.RelatedField):
|
||||
"""Evaluation str d'un objet extension (.example.org)"""
|
||||
""" Serializer for Extension object field """
|
||||
|
||||
def to_representation(self, value):
|
||||
return value.name
|
||||
|
||||
def to_internal_value(self, data):
|
||||
pass
|
||||
|
||||
|
||||
class TypeSerializer(serializers.ModelSerializer):
|
||||
"""Serialisation d'un iptype : extension et la liste des
|
||||
ouvertures de port son evalués en get_... etant des
|
||||
foreign_key ou des relations manytomany"""
|
||||
""" 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')
|
||||
|
@ -136,7 +164,10 @@ class TypeSerializer(serializers.ModelSerializer):
|
|||
'ouverture_ports_tcp_in', 'ouverture_ports_tcp_out',
|
||||
'ouverture_ports_udp_in', 'ouverture_ports_udp_out',)
|
||||
|
||||
def get_port_policy(self, obj, protocole, io):
|
||||
@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(
|
||||
|
@ -174,13 +205,19 @@ class ExtensionSerializer(serializers.ModelSerializer):
|
|||
model = Extension
|
||||
fields = ('name', 'origin', 'origin_v6', 'zone_entry', 'soa')
|
||||
|
||||
def get_origin_ip(self, obj):
|
||||
return getattr(obj.origin, 'ipv4', None)
|
||||
@staticmethod
|
||||
def get_origin_ip(obj):
|
||||
""" The IP of the associated origin for the zone """
|
||||
return obj.origin.ipv4
|
||||
|
||||
def get_zone_name(self, obj):
|
||||
@staticmethod
|
||||
def get_zone_name(obj):
|
||||
""" The name of the associated zone """
|
||||
return str(obj.dns_entry)
|
||||
|
||||
def get_soa_data(self, obj):
|
||||
@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}
|
||||
|
||||
|
||||
|
@ -195,13 +232,19 @@ class MxSerializer(serializers.ModelSerializer):
|
|||
model = Mx
|
||||
fields = ('zone', 'priority', 'name', 'mx_entry')
|
||||
|
||||
def get_entry_name(self, obj):
|
||||
@staticmethod
|
||||
def get_entry_name(obj):
|
||||
""" The name of the DNS MX entry """
|
||||
return str(obj.name)
|
||||
|
||||
def get_zone_name(self, obj):
|
||||
@staticmethod
|
||||
def get_zone_name(obj):
|
||||
""" The name of the associated zone of the MX record """
|
||||
return obj.zone.name
|
||||
|
||||
def get_mx_name(self, obj):
|
||||
@staticmethod
|
||||
def get_mx_name(obj):
|
||||
""" The string representation of the entry to add to the DNS """
|
||||
return str(obj.dns_entry)
|
||||
|
||||
|
||||
|
@ -215,10 +258,14 @@ class TxtSerializer(serializers.ModelSerializer):
|
|||
model = Txt
|
||||
fields = ('zone', 'txt_entry', 'field1', 'field2')
|
||||
|
||||
def get_zone_name(self, obj):
|
||||
@staticmethod
|
||||
def get_zone_name(obj):
|
||||
""" The name of the associated zone """
|
||||
return str(obj.zone.name)
|
||||
|
||||
def get_txt_name(self, obj):
|
||||
@staticmethod
|
||||
def get_txt_name(obj):
|
||||
""" The string representation of the entry to add to the DNS """
|
||||
return str(obj.dns_entry)
|
||||
|
||||
|
||||
|
@ -241,10 +288,14 @@ class SrvSerializer(serializers.ModelSerializer):
|
|||
'srv_entry'
|
||||
)
|
||||
|
||||
def get_extension_name(self, obj):
|
||||
@staticmethod
|
||||
def get_extension_name(obj):
|
||||
""" The name of the associated extension """
|
||||
return str(obj.extension.name)
|
||||
|
||||
def get_srv_name(self, obj):
|
||||
@staticmethod
|
||||
def get_srv_name(obj):
|
||||
""" The string representation of the entry to add to the DNS """
|
||||
return str(obj.dns_entry)
|
||||
|
||||
|
||||
|
@ -259,13 +310,19 @@ class NsSerializer(serializers.ModelSerializer):
|
|||
model = Ns
|
||||
fields = ('zone', 'ns', 'ns_entry')
|
||||
|
||||
def get_zone_name(self, obj):
|
||||
@staticmethod
|
||||
def get_zone_name(obj):
|
||||
""" The name of the associated zone """
|
||||
return obj.zone.name
|
||||
|
||||
def get_domain_name(self, obj):
|
||||
@staticmethod
|
||||
def get_domain_name(obj):
|
||||
""" The name of the associated NS target """
|
||||
return str(obj.ns)
|
||||
|
||||
def get_text_name(self, obj):
|
||||
@staticmethod
|
||||
def get_text_name(obj):
|
||||
""" The string representation of the entry to add to the DNS """
|
||||
return str(obj.dns_entry)
|
||||
|
||||
|
||||
|
@ -280,13 +337,19 @@ class DomainSerializer(serializers.ModelSerializer):
|
|||
model = Domain
|
||||
fields = ('name', 'extension', 'cname', 'cname_entry')
|
||||
|
||||
def get_zone_name(self, obj):
|
||||
@staticmethod
|
||||
def get_zone_name(obj):
|
||||
""" The name of the associated zone """
|
||||
return obj.extension.name
|
||||
|
||||
def get_alias_name(self, obj):
|
||||
@staticmethod
|
||||
def get_alias_name(obj):
|
||||
""" The name of the associated alias """
|
||||
return str(obj.cname)
|
||||
|
||||
def get_cname_name(self, obj):
|
||||
@staticmethod
|
||||
def get_cname_name(obj):
|
||||
""" The name of the associated CNAME target """
|
||||
return str(obj.dns_entry)
|
||||
|
||||
|
||||
|
@ -300,13 +363,19 @@ class ServiceServersSerializer(serializers.ModelSerializer):
|
|||
model = Service_link
|
||||
fields = ('server', 'service', 'need_regen')
|
||||
|
||||
def get_server_name(self, obj):
|
||||
@staticmethod
|
||||
def get_server_name(obj):
|
||||
""" The name of the associated server """
|
||||
return str(obj.server.domain.name)
|
||||
|
||||
def get_service_name(self, obj):
|
||||
@staticmethod
|
||||
def get_service_name(obj):
|
||||
""" The name of the service name """
|
||||
return str(obj.service)
|
||||
|
||||
def get_regen_status(self, obj):
|
||||
@staticmethod
|
||||
def get_regen_status(obj):
|
||||
""" The string representation of the regen status """
|
||||
return obj.need_regen()
|
||||
|
||||
|
||||
|
@ -315,7 +384,19 @@ class OuverturePortsSerializer(serializers.Serializer):
|
|||
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()],
|
||||
|
@ -326,7 +407,9 @@ class OuverturePortsSerializer(serializers.Serializer):
|
|||
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()],
|
||||
|
|
|
@ -20,7 +20,10 @@
|
|||
# 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.
|
||||
"""machines.tests
|
||||
The tests for the API module.
|
||||
"""
|
||||
|
||||
from django.test import TestCase
|
||||
# from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
# 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.
|
||||
"""machines.urls
|
||||
The defined URLs for the Cotisations app
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
|
|
@ -25,24 +25,41 @@
|
|||
# App de gestion des machines pour re2o
|
||||
# Gabriel Détraz, Augustin Lemesle
|
||||
# Gplv2
|
||||
"""machines.views
|
||||
The views for the Machines app
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.urls import reverse
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import render, redirect
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.template.context_processors import csrf
|
||||
from django.template import Context, RequestContext, loader
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required, permission_required
|
||||
from django.db.models import ProtectedError, F
|
||||
from django.forms import ValidationError, modelformset_factory
|
||||
from django.contrib.auth import authenticate, login
|
||||
from django.forms import modelformset_factory
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
from rest_framework.renderers import JSONRenderer
|
||||
from machines.serializers import (
|
||||
|
||||
from users.models import User
|
||||
from preferences.models import GeneralOption
|
||||
from re2o.utils import (
|
||||
all_active_assigned_interfaces,
|
||||
filter_active_interfaces,
|
||||
SortTable,
|
||||
re2o_paginator,
|
||||
)
|
||||
from re2o.acl import (
|
||||
can_create,
|
||||
can_edit,
|
||||
can_delete,
|
||||
can_view_all,
|
||||
can_delete_set,
|
||||
)
|
||||
from re2o.views import form
|
||||
|
||||
from .serializers import (
|
||||
FullInterfaceSerializer,
|
||||
InterfaceSerializer,
|
||||
TypeSerializer,
|
||||
|
@ -53,12 +70,8 @@ from machines.serializers import (
|
|||
ExtensionSerializer,
|
||||
ServiceServersSerializer,
|
||||
NsSerializer,
|
||||
OuverturePortsSerializer
|
||||
)
|
||||
from reversion import revisions as reversion
|
||||
from reversion.models import Version
|
||||
|
||||
import re
|
||||
from .forms import (
|
||||
NewMachineForm,
|
||||
EditMachineForm,
|
||||
|
@ -68,8 +81,6 @@ from .forms import (
|
|||
DelMachineTypeForm,
|
||||
ExtensionForm,
|
||||
DelExtensionForm,
|
||||
)
|
||||
from .forms import (
|
||||
EditIpTypeForm,
|
||||
IpTypeForm,
|
||||
DelIpTypeForm,
|
||||
|
@ -93,13 +104,13 @@ from .forms import (
|
|||
SrvForm,
|
||||
DelSrvForm,
|
||||
Ipv6ListForm,
|
||||
EditOuverturePortListForm,
|
||||
EditOuverturePortConfigForm
|
||||
)
|
||||
from .forms import EditOuverturePortListForm, EditOuverturePortConfigForm
|
||||
from .models import (
|
||||
IpType,
|
||||
Machine,
|
||||
Interface,
|
||||
IpList,
|
||||
MachineType,
|
||||
Extension,
|
||||
SOA,
|
||||
|
@ -116,24 +127,6 @@ from .models import (
|
|||
OuverturePort,
|
||||
Ipv6List,
|
||||
)
|
||||
from users.models import User
|
||||
from preferences.models import GeneralOption, OptionalMachine
|
||||
from re2o.utils import (
|
||||
all_active_assigned_interfaces,
|
||||
all_has_access,
|
||||
filter_active_interfaces,
|
||||
SortTable,
|
||||
re2o_paginator,
|
||||
)
|
||||
from re2o.acl import (
|
||||
can_create,
|
||||
can_edit,
|
||||
can_delete,
|
||||
can_view,
|
||||
can_view_all,
|
||||
can_delete_set,
|
||||
)
|
||||
from re2o.views import form
|
||||
|
||||
|
||||
def f_type_id(is_type_tt):
|
||||
|
@ -143,10 +136,10 @@ def f_type_id(is_type_tt):
|
|||
return 'id_Interface-type_hidden' if is_type_tt else 'id_Interface-type'
|
||||
|
||||
|
||||
def generate_ipv4_choices(form):
|
||||
def generate_ipv4_choices(form_obj):
|
||||
""" Generate the parameter choices for the massive_bootstrap_form tag
|
||||
"""
|
||||
f_ipv4 = form.fields['ipv4']
|
||||
f_ipv4 = form_obj.fields['ipv4']
|
||||
used_mtype_id = []
|
||||
choices = '{"":[{key:"",value:"Choisissez d\'abord un type de machine"},'
|
||||
mtype_id = -1
|
||||
|
@ -166,7 +159,7 @@ def generate_ipv4_choices(form):
|
|||
v=ip.ipv4
|
||||
)
|
||||
|
||||
for t in form.fields['type'].queryset.exclude(id__in=used_mtype_id):
|
||||
for t in form_obj.fields['type'].queryset.exclude(id__in=used_mtype_id):
|
||||
choices += '], "'+str(t.id)+'": ['
|
||||
choices += '{key: "", value: "' + str(f_ipv4.empty_label) + '"},'
|
||||
choices += ']}'
|
||||
|
@ -206,10 +199,10 @@ def generate_ipv4_match_func(is_type_tt):
|
|||
)
|
||||
|
||||
|
||||
def generate_ipv4_mbf_param(form, is_type_tt):
|
||||
def generate_ipv4_mbf_param(form_obj, is_type_tt):
|
||||
""" Generate all the parameters to use with the massive_bootstrap_form
|
||||
tag """
|
||||
i_choices = {'ipv4': generate_ipv4_choices(form)}
|
||||
i_choices = {'ipv4': generate_ipv4_choices(form_obj)}
|
||||
i_engine = {'ipv4': generate_ipv4_engine(is_type_tt)}
|
||||
i_match_func = {'ipv4': generate_ipv4_match_func(is_type_tt)}
|
||||
i_update_on = {'ipv4': [f_type_id(is_type_tt)]}
|
||||
|
@ -227,7 +220,7 @@ def generate_ipv4_mbf_param(form, is_type_tt):
|
|||
@login_required
|
||||
@can_create(Machine)
|
||||
@can_edit(User)
|
||||
def new_machine(request, user, userid):
|
||||
def new_machine(request, user, _userid):
|
||||
""" Fonction de creation d'une machine. Cree l'objet machine,
|
||||
le sous objet interface et l'objet domain à partir de model forms.
|
||||
Trop complexe, devrait être simplifié"""
|
||||
|
@ -239,16 +232,16 @@ def new_machine(request, user, userid):
|
|||
)
|
||||
domain = DomainForm(request.POST or None, user=user)
|
||||
if machine.is_valid() and interface.is_valid():
|
||||
new_machine = machine.save(commit=False)
|
||||
new_machine.user = user
|
||||
new_interface = interface.save(commit=False)
|
||||
domain.instance.interface_parent = new_interface
|
||||
new_machine_obj = machine.save(commit=False)
|
||||
new_machine_obj.user = user
|
||||
new_interface_obj = interface.save(commit=False)
|
||||
domain.instance.interface_parent = new_interface_obj
|
||||
if domain.is_valid():
|
||||
new_domain = domain.save(commit=False)
|
||||
new_machine.save()
|
||||
new_interface.machine = new_machine
|
||||
new_interface.save()
|
||||
new_domain.interface_parent = new_interface
|
||||
new_machine_obj.save()
|
||||
new_interface_obj.machine = new_machine_obj
|
||||
new_interface_obj.save()
|
||||
new_domain.interface_parent = new_interface_obj
|
||||
new_domain.save()
|
||||
messages.success(request, "La machine a été créée")
|
||||
return redirect(reverse(
|
||||
|
@ -271,7 +264,7 @@ def new_machine(request, user, userid):
|
|||
|
||||
@login_required
|
||||
@can_edit(Interface)
|
||||
def edit_interface(request, interface_instance, interfaceid):
|
||||
def edit_interface(request, interface_instance, _interfaceid):
|
||||
""" Edition d'une interface. Distingue suivant les droits les valeurs
|
||||
de interfaces et machines que l'user peut modifier infra permet de
|
||||
modifier le propriétaire"""
|
||||
|
@ -293,15 +286,15 @@ def edit_interface(request, interface_instance, interfaceid):
|
|||
if (machine_form.is_valid() and
|
||||
interface_form.is_valid() and
|
||||
domain_form.is_valid()):
|
||||
new_machine = machine_form.save(commit=False)
|
||||
new_interface = interface_form.save(commit=False)
|
||||
new_domain = domain_form.save(commit=False)
|
||||
new_machine_obj = machine_form.save(commit=False)
|
||||
new_interface_obj = interface_form.save(commit=False)
|
||||
new_domain_obj = domain_form.save(commit=False)
|
||||
if machine_form.changed_data:
|
||||
new_machine.save()
|
||||
new_machine_obj.save()
|
||||
if interface_form.changed_data:
|
||||
new_interface.save()
|
||||
new_interface_obj.save()
|
||||
if domain_form.changed_data:
|
||||
new_domain.save()
|
||||
new_domain_obj.save()
|
||||
messages.success(request, "La machine a été modifiée")
|
||||
return redirect(reverse(
|
||||
'users:profil',
|
||||
|
@ -323,7 +316,7 @@ def edit_interface(request, interface_instance, interfaceid):
|
|||
|
||||
@login_required
|
||||
@can_delete(Machine)
|
||||
def del_machine(request, machine, machineid):
|
||||
def del_machine(request, machine, _machineid):
|
||||
""" Supprime une machine, interfaces en mode cascade"""
|
||||
if request.method == "POST":
|
||||
machine.delete()
|
||||
|
@ -342,20 +335,20 @@ def del_machine(request, machine, machineid):
|
|||
@login_required
|
||||
@can_create(Interface)
|
||||
@can_edit(Machine)
|
||||
def new_interface(request, machine, machineid):
|
||||
def new_interface(request, machine, _machineid):
|
||||
""" Ajoute une interface et son domain associé à une machine existante"""
|
||||
|
||||
interface_form = AddInterfaceForm(request.POST or None, user=request.user)
|
||||
domain_form = DomainForm(request.POST or None)
|
||||
if interface_form.is_valid():
|
||||
new_interface = interface_form.save(commit=False)
|
||||
domain_form.instance.interface_parent = new_interface
|
||||
new_interface.machine = machine
|
||||
new_interface_obj = interface_form.save(commit=False)
|
||||
domain_form.instance.interface_parent = new_interface_obj
|
||||
new_interface_obj.machine = machine
|
||||
if domain_form.is_valid():
|
||||
new_domain = domain_form.save(commit=False)
|
||||
new_interface.save()
|
||||
new_domain.interface_parent = new_interface
|
||||
new_domain.save()
|
||||
new_domain_obj = domain_form.save(commit=False)
|
||||
new_interface_obj.save()
|
||||
new_domain_obj.interface_parent = new_interface_obj
|
||||
new_domain_obj.save()
|
||||
messages.success(request, "L'interface a été ajoutée")
|
||||
return redirect(reverse(
|
||||
'users:profil',
|
||||
|
@ -376,7 +369,7 @@ def new_interface(request, machine, machineid):
|
|||
|
||||
@login_required
|
||||
@can_delete(Interface)
|
||||
def del_interface(request, interface, interfaceid):
|
||||
def del_interface(request, interface, _interfaceid):
|
||||
""" Supprime une interface. Domain objet en mode cascade"""
|
||||
if request.method == "POST":
|
||||
machine = interface.machine
|
||||
|
@ -398,7 +391,7 @@ def del_interface(request, interface, interfaceid):
|
|||
@login_required
|
||||
@can_create(Ipv6List)
|
||||
@can_edit(Interface)
|
||||
def new_ipv6list(request, interface, interfaceid):
|
||||
def new_ipv6list(request, interface, _interfaceid):
|
||||
"""Nouvelle ipv6"""
|
||||
ipv6list_instance = Ipv6List(interface=interface)
|
||||
ipv6 = Ipv6ListForm(
|
||||
|
@ -422,7 +415,7 @@ def new_ipv6list(request, interface, interfaceid):
|
|||
|
||||
@login_required
|
||||
@can_edit(Ipv6List)
|
||||
def edit_ipv6list(request, ipv6list_instance, ipv6listid):
|
||||
def edit_ipv6list(request, ipv6list_instance, _ipv6listid):
|
||||
"""Edition d'une ipv6"""
|
||||
ipv6 = Ipv6ListForm(
|
||||
request.POST or None,
|
||||
|
@ -446,7 +439,7 @@ def edit_ipv6list(request, ipv6list_instance, ipv6listid):
|
|||
|
||||
@login_required
|
||||
@can_delete(Ipv6List)
|
||||
def del_ipv6list(request, ipv6list, ipv6listid):
|
||||
def del_ipv6list(request, ipv6list, _ipv6listid):
|
||||
""" Supprime une ipv6"""
|
||||
if request.method == "POST":
|
||||
interfaceid = ipv6list.interface.id
|
||||
|
@ -483,7 +476,7 @@ def add_iptype(request):
|
|||
|
||||
@login_required
|
||||
@can_edit(IpType)
|
||||
def edit_iptype(request, iptype_instance, iptypeid):
|
||||
def edit_iptype(request, iptype_instance, _iptypeid):
|
||||
""" Edition d'un range. Ne permet pas de le redimensionner pour éviter
|
||||
l'incohérence"""
|
||||
|
||||
|
@ -528,6 +521,7 @@ def del_iptype(request, instances):
|
|||
@login_required
|
||||
@can_create(MachineType)
|
||||
def add_machinetype(request):
|
||||
""" View used to add a Machinetype object """
|
||||
machinetype = MachineTypeForm(request.POST or None)
|
||||
if machinetype.is_valid():
|
||||
machinetype.save()
|
||||
|
@ -542,7 +536,8 @@ def add_machinetype(request):
|
|||
|
||||
@login_required
|
||||
@can_edit(MachineType)
|
||||
def edit_machinetype(request, machinetype_instance, machinetypeid):
|
||||
def edit_machinetype(request, machinetype_instance, _machinetypeid):
|
||||
""" View used to edit a MachineType object """
|
||||
machinetype = MachineTypeForm(
|
||||
request.POST or None,
|
||||
instance=machinetype_instance
|
||||
|
@ -562,6 +557,7 @@ def edit_machinetype(request, machinetype_instance, machinetypeid):
|
|||
@login_required
|
||||
@can_delete_set(MachineType)
|
||||
def del_machinetype(request, instances):
|
||||
""" View used to delete a MachineType object """
|
||||
machinetype = DelMachineTypeForm(request.POST or None, instances=instances)
|
||||
if machinetype.is_valid():
|
||||
machinetype_dels = machinetype.cleaned_data['machinetypes']
|
||||
|
@ -587,6 +583,7 @@ def del_machinetype(request, instances):
|
|||
@login_required
|
||||
@can_create(Extension)
|
||||
def add_extension(request):
|
||||
""" View used to add an Extension object """
|
||||
extension = ExtensionForm(request.POST or None)
|
||||
if extension.is_valid():
|
||||
extension.save()
|
||||
|
@ -601,7 +598,8 @@ def add_extension(request):
|
|||
|
||||
@login_required
|
||||
@can_edit(Extension)
|
||||
def edit_extension(request, extension_instance, extensionid):
|
||||
def edit_extension(request, extension_instance, _extensionid):
|
||||
""" View used to edit an Extension object """
|
||||
extension = ExtensionForm(
|
||||
request.POST or None,
|
||||
instance=extension_instance
|
||||
|
@ -621,6 +619,7 @@ def edit_extension(request, extension_instance, extensionid):
|
|||
@login_required
|
||||
@can_delete_set(Extension)
|
||||
def del_extension(request, instances):
|
||||
""" View used to delete an Extension object """
|
||||
extension = DelExtensionForm(request.POST or None, instances=instances)
|
||||
if extension.is_valid():
|
||||
extension_dels = extension.cleaned_data['extensions']
|
||||
|
@ -646,6 +645,7 @@ def del_extension(request, instances):
|
|||
@login_required
|
||||
@can_create(SOA)
|
||||
def add_soa(request):
|
||||
""" View used to add a SOA object """
|
||||
soa = SOAForm(request.POST or None)
|
||||
if soa.is_valid():
|
||||
soa.save()
|
||||
|
@ -660,7 +660,8 @@ def add_soa(request):
|
|||
|
||||
@login_required
|
||||
@can_edit(SOA)
|
||||
def edit_soa(request, soa_instance, soaid):
|
||||
def edit_soa(request, soa_instance, _soaid):
|
||||
""" View used to edit a SOA object """
|
||||
soa = SOAForm(request.POST or None, instance=soa_instance)
|
||||
if soa.is_valid():
|
||||
if soa.changed_data:
|
||||
|
@ -677,6 +678,7 @@ def edit_soa(request, soa_instance, soaid):
|
|||
@login_required
|
||||
@can_delete_set(SOA)
|
||||
def del_soa(request, instances):
|
||||
""" View used to delete a SOA object """
|
||||
soa = DelSOAForm(request.POST or None, instances=instances)
|
||||
if soa.is_valid():
|
||||
soa_dels = soa.cleaned_data['soa']
|
||||
|
@ -701,6 +703,7 @@ def del_soa(request, instances):
|
|||
@login_required
|
||||
@can_create(Mx)
|
||||
def add_mx(request):
|
||||
""" View used to add a MX object """
|
||||
mx = MxForm(request.POST or None)
|
||||
if mx.is_valid():
|
||||
mx.save()
|
||||
|
@ -715,7 +718,8 @@ def add_mx(request):
|
|||
|
||||
@login_required
|
||||
@can_edit(Mx)
|
||||
def edit_mx(request, mx_instance, mxid):
|
||||
def edit_mx(request, mx_instance, _mxid):
|
||||
""" View used to edit a MX object """
|
||||
mx = MxForm(request.POST or None, instance=mx_instance)
|
||||
if mx.is_valid():
|
||||
if mx.changed_data:
|
||||
|
@ -732,6 +736,7 @@ def edit_mx(request, mx_instance, mxid):
|
|||
@login_required
|
||||
@can_delete_set(Mx)
|
||||
def del_mx(request, instances):
|
||||
""" View used to delete a MX object """
|
||||
mx = DelMxForm(request.POST or None, instances=instances)
|
||||
if mx.is_valid():
|
||||
mx_dels = mx.cleaned_data['mx']
|
||||
|
@ -756,6 +761,7 @@ def del_mx(request, instances):
|
|||
@login_required
|
||||
@can_create(Ns)
|
||||
def add_ns(request):
|
||||
""" View used to add a NS object """
|
||||
ns = NsForm(request.POST or None)
|
||||
if ns.is_valid():
|
||||
ns.save()
|
||||
|
@ -770,7 +776,8 @@ def add_ns(request):
|
|||
|
||||
@login_required
|
||||
@can_edit(Ns)
|
||||
def edit_ns(request, ns_instance, nsid):
|
||||
def edit_ns(request, ns_instance, _nsid):
|
||||
""" View used to edit a NS object """
|
||||
ns = NsForm(request.POST or None, instance=ns_instance)
|
||||
if ns.is_valid():
|
||||
if ns.changed_data:
|
||||
|
@ -787,6 +794,7 @@ def edit_ns(request, ns_instance, nsid):
|
|||
@login_required
|
||||
@can_delete_set(Ns)
|
||||
def del_ns(request, instances):
|
||||
""" View used to delete a NS object """
|
||||
ns = DelNsForm(request.POST or None, instances=instances)
|
||||
if ns.is_valid():
|
||||
ns_dels = ns.cleaned_data['ns']
|
||||
|
@ -811,6 +819,7 @@ def del_ns(request, instances):
|
|||
@login_required
|
||||
@can_create(Txt)
|
||||
def add_txt(request):
|
||||
""" View used to add a TXT object """
|
||||
txt = TxtForm(request.POST or None)
|
||||
if txt.is_valid():
|
||||
txt.save()
|
||||
|
@ -825,7 +834,8 @@ def add_txt(request):
|
|||
|
||||
@login_required
|
||||
@can_edit(Txt)
|
||||
def edit_txt(request, txt_instance, txtid):
|
||||
def edit_txt(request, txt_instance, _txtid):
|
||||
""" View used to edit a TXT object """
|
||||
txt = TxtForm(request.POST or None, instance=txt_instance)
|
||||
if txt.is_valid():
|
||||
if txt.changed_data:
|
||||
|
@ -842,6 +852,7 @@ def edit_txt(request, txt_instance, txtid):
|
|||
@login_required
|
||||
@can_delete_set(Txt)
|
||||
def del_txt(request, instances):
|
||||
""" View used to delete a TXT object """
|
||||
txt = DelTxtForm(request.POST or None, instances=instances)
|
||||
if txt.is_valid():
|
||||
txt_dels = txt.cleaned_data['txt']
|
||||
|
@ -866,6 +877,7 @@ def del_txt(request, instances):
|
|||
@login_required
|
||||
@can_create(Srv)
|
||||
def add_srv(request):
|
||||
""" View used to add a SRV object """
|
||||
srv = SrvForm(request.POST or None)
|
||||
if srv.is_valid():
|
||||
srv.save()
|
||||
|
@ -880,7 +892,8 @@ def add_srv(request):
|
|||
|
||||
@login_required
|
||||
@can_edit(Srv)
|
||||
def edit_srv(request, srv_instance, srvid):
|
||||
def edit_srv(request, srv_instance, _srvid):
|
||||
""" View used to edit a SRV object """
|
||||
srv = SrvForm(request.POST or None, instance=srv_instance)
|
||||
if srv.is_valid():
|
||||
if srv.changed_data:
|
||||
|
@ -897,6 +910,7 @@ def edit_srv(request, srv_instance, srvid):
|
|||
@login_required
|
||||
@can_delete_set(Srv)
|
||||
def del_srv(request, instances):
|
||||
""" View used to delete a SRV object """
|
||||
srv = DelSrvForm(request.POST or None, instances=instances)
|
||||
if srv.is_valid():
|
||||
srv_dels = srv.cleaned_data['srv']
|
||||
|
@ -922,6 +936,7 @@ def del_srv(request, instances):
|
|||
@can_create(Domain)
|
||||
@can_edit(Interface)
|
||||
def add_alias(request, interface, interfaceid):
|
||||
""" View used to add an Alias object """
|
||||
alias = AliasForm(request.POST or None, user=request.user)
|
||||
if alias.is_valid():
|
||||
alias = alias.save(commit=False)
|
||||
|
@ -941,7 +956,8 @@ def add_alias(request, interface, interfaceid):
|
|||
|
||||
@login_required
|
||||
@can_edit(Domain)
|
||||
def edit_alias(request, domain_instance, domainid):
|
||||
def edit_alias(request, domain_instance, _domainid):
|
||||
""" View used to edit an Alias object """
|
||||
alias = AliasForm(
|
||||
request.POST or None,
|
||||
instance=domain_instance,
|
||||
|
@ -967,6 +983,7 @@ def edit_alias(request, domain_instance, domainid):
|
|||
@login_required
|
||||
@can_edit(Interface)
|
||||
def del_alias(request, interface, interfaceid):
|
||||
""" View used to delete an Alias object """
|
||||
alias = DelAliasForm(request.POST or None, interface=interface)
|
||||
if alias.is_valid():
|
||||
alias_dels = alias.cleaned_data['alias']
|
||||
|
@ -997,6 +1014,7 @@ def del_alias(request, interface, interfaceid):
|
|||
@login_required
|
||||
@can_create(Service)
|
||||
def add_service(request):
|
||||
""" View used to add a Service object """
|
||||
service = ServiceForm(request.POST or None)
|
||||
if service.is_valid():
|
||||
service.save()
|
||||
|
@ -1011,7 +1029,8 @@ def add_service(request):
|
|||
|
||||
@login_required
|
||||
@can_edit(Service)
|
||||
def edit_service(request, service_instance, serviceid):
|
||||
def edit_service(request, service_instance, _serviceid):
|
||||
""" View used to edit a Service object """
|
||||
service = ServiceForm(request.POST or None, instance=service_instance)
|
||||
if service.is_valid():
|
||||
if service.changed_data:
|
||||
|
@ -1028,6 +1047,7 @@ def edit_service(request, service_instance, serviceid):
|
|||
@login_required
|
||||
@can_delete_set(Service)
|
||||
def del_service(request, instances):
|
||||
""" View used to delete a Service object """
|
||||
service = DelServiceForm(request.POST or None, instances=instances)
|
||||
if service.is_valid():
|
||||
service_dels = service.cleaned_data['service']
|
||||
|
@ -1052,6 +1072,7 @@ def del_service(request, instances):
|
|||
@login_required
|
||||
@can_create(Vlan)
|
||||
def add_vlan(request):
|
||||
""" View used to add a VLAN object """
|
||||
vlan = VlanForm(request.POST or None)
|
||||
if vlan.is_valid():
|
||||
vlan.save()
|
||||
|
@ -1066,7 +1087,8 @@ def add_vlan(request):
|
|||
|
||||
@login_required
|
||||
@can_edit(Vlan)
|
||||
def edit_vlan(request, vlan_instance, vlanid):
|
||||
def edit_vlan(request, vlan_instance, _vlanid):
|
||||
""" View used to edit a VLAN object """
|
||||
vlan = VlanForm(request.POST or None, instance=vlan_instance)
|
||||
if vlan.is_valid():
|
||||
if vlan.changed_data:
|
||||
|
@ -1083,6 +1105,7 @@ def edit_vlan(request, vlan_instance, vlanid):
|
|||
@login_required
|
||||
@can_delete_set(Vlan)
|
||||
def del_vlan(request, instances):
|
||||
""" View used to delete a VLAN object """
|
||||
vlan = DelVlanForm(request.POST or None, instances=instances)
|
||||
if vlan.is_valid():
|
||||
vlan_dels = vlan.cleaned_data['vlan']
|
||||
|
@ -1107,6 +1130,7 @@ def del_vlan(request, instances):
|
|||
@login_required
|
||||
@can_create(Nas)
|
||||
def add_nas(request):
|
||||
""" View used to add a NAS object """
|
||||
nas = NasForm(request.POST or None)
|
||||
if nas.is_valid():
|
||||
nas.save()
|
||||
|
@ -1121,7 +1145,8 @@ def add_nas(request):
|
|||
|
||||
@login_required
|
||||
@can_edit(Nas)
|
||||
def edit_nas(request, nas_instance, nasid):
|
||||
def edit_nas(request, nas_instance, _nasid):
|
||||
""" View used to edit a NAS object """
|
||||
nas = NasForm(request.POST or None, instance=nas_instance)
|
||||
if nas.is_valid():
|
||||
if nas.changed_data:
|
||||
|
@ -1138,6 +1163,7 @@ def edit_nas(request, nas_instance, nasid):
|
|||
@login_required
|
||||
@can_delete_set(Nas)
|
||||
def del_nas(request, instances):
|
||||
""" View used to delete a NAS object """
|
||||
nas = DelNasForm(request.POST or None, instances=instances)
|
||||
if nas.is_valid():
|
||||
nas_dels = nas.cleaned_data['nas']
|
||||
|
@ -1162,6 +1188,8 @@ def del_nas(request, instances):
|
|||
@login_required
|
||||
@can_view_all(Machine)
|
||||
def index(request):
|
||||
""" The home view for this app. Displays the list of registered
|
||||
machines in Re2o """
|
||||
pagination_large_number = (GeneralOption
|
||||
.get_cached_value('pagination_large_number'))
|
||||
machines_list = (Machine.objects
|
||||
|
@ -1194,6 +1222,7 @@ def index(request):
|
|||
@login_required
|
||||
@can_view_all(IpType)
|
||||
def index_iptype(request):
|
||||
""" View displaying the list of existing types of IP """
|
||||
iptype_list = (IpType.objects
|
||||
.select_related('extension')
|
||||
.select_related('vlan')
|
||||
|
@ -1208,6 +1237,7 @@ def index_iptype(request):
|
|||
@login_required
|
||||
@can_view_all(Vlan)
|
||||
def index_vlan(request):
|
||||
""" View displaying the list of existing VLANs """
|
||||
vlan_list = Vlan.objects.prefetch_related('iptype_set').order_by('vlan_id')
|
||||
return render(
|
||||
request,
|
||||
|
@ -1219,6 +1249,7 @@ def index_vlan(request):
|
|||
@login_required
|
||||
@can_view_all(MachineType)
|
||||
def index_machinetype(request):
|
||||
""" View displaying the list of existing types of machines """
|
||||
machinetype_list = (MachineType.objects
|
||||
.select_related('ip_type')
|
||||
.order_by('type'))
|
||||
|
@ -1232,6 +1263,7 @@ def index_machinetype(request):
|
|||
@login_required
|
||||
@can_view_all(Nas)
|
||||
def index_nas(request):
|
||||
""" View displaying the list of existing NAS """
|
||||
nas_list = (Nas.objects
|
||||
.select_related('machine_type')
|
||||
.select_related('nas_type')
|
||||
|
@ -1247,6 +1279,10 @@ def index_nas(request):
|
|||
@can_view_all(Srv)
|
||||
@can_view_all(Extension)
|
||||
def index_extension(request):
|
||||
""" View displaying the list of existing extensions, the list of
|
||||
existing SOA records, the list of existing MX records , the list of
|
||||
existing NS records, the list of existing TXT records and the list of
|
||||
existing SRV records """
|
||||
extension_list = (Extension.objects
|
||||
.select_related('origin')
|
||||
.select_related('soa')
|
||||
|
@ -1282,6 +1318,7 @@ def index_extension(request):
|
|||
@login_required
|
||||
@can_edit(Interface)
|
||||
def index_alias(request, interface, interfaceid):
|
||||
""" View used to display the list of existing alias of an interface """
|
||||
alias_list = Domain.objects.filter(
|
||||
cname=Domain.objects.filter(interface_parent=interface)
|
||||
).order_by('name')
|
||||
|
@ -1295,6 +1332,7 @@ def index_alias(request, interface, interfaceid):
|
|||
@login_required
|
||||
@can_edit(Interface)
|
||||
def index_ipv6(request, interface, interfaceid):
|
||||
""" View used to display the list of existing IPv6 of an interface """
|
||||
ipv6_list = Ipv6List.objects.filter(interface=interface)
|
||||
return render(
|
||||
request,
|
||||
|
@ -1306,6 +1344,7 @@ def index_ipv6(request, interface, interfaceid):
|
|||
@login_required
|
||||
@can_view_all(Service)
|
||||
def index_service(request):
|
||||
""" View used to display the list of existing services """
|
||||
service_list = (Service.objects
|
||||
.prefetch_related(
|
||||
'service_link_set__server__domain__extension'
|
||||
|
@ -1324,6 +1363,7 @@ def index_service(request):
|
|||
@login_required
|
||||
@can_view_all(OuverturePortList)
|
||||
def index_portlist(request):
|
||||
""" View used to display the list of existing port policies """
|
||||
port_list = (OuverturePortList.objects
|
||||
.prefetch_related('ouvertureport_set')
|
||||
.prefetch_related('interface_set__domain__extension')
|
||||
|
@ -1338,7 +1378,8 @@ def index_portlist(request):
|
|||
|
||||
@login_required
|
||||
@can_edit(OuverturePortList)
|
||||
def edit_portlist(request, ouvertureportlist_instance, ouvertureportlistid):
|
||||
def edit_portlist(request, ouvertureportlist_instance, _ouvertureportlistid):
|
||||
""" View used to edit a port policy """
|
||||
port_list = EditOuverturePortListForm(
|
||||
request.POST or None,
|
||||
instance=ouvertureportlist_instance
|
||||
|
@ -1376,7 +1417,8 @@ def edit_portlist(request, ouvertureportlist_instance, ouvertureportlistid):
|
|||
|
||||
@login_required
|
||||
@can_delete(OuverturePortList)
|
||||
def del_portlist(request, port_list_instance, ouvertureportlistid):
|
||||
def del_portlist(request, port_list_instance, _ouvertureportlistid):
|
||||
""" View used to delete a port policy """
|
||||
port_list_instance.delete()
|
||||
messages.success(request, "La liste de ports a été supprimée")
|
||||
return redirect(reverse('machines:index-portlist'))
|
||||
|
@ -1385,6 +1427,7 @@ def del_portlist(request, port_list_instance, ouvertureportlistid):
|
|||
@login_required
|
||||
@can_create(OuverturePortList)
|
||||
def add_portlist(request):
|
||||
""" View used to add a port policy """
|
||||
port_list = EditOuverturePortListForm(request.POST or None)
|
||||
port_formset = modelformset_factory(
|
||||
OuverturePort,
|
||||
|
@ -1409,22 +1452,14 @@ def add_portlist(request):
|
|||
'machines/edit_portlist.html',
|
||||
request
|
||||
)
|
||||
port_list = EditOuverturePortListForm(request.POST or None)
|
||||
if port_list.is_valid():
|
||||
port_list.save()
|
||||
messages.success(request, "Liste de ports créée")
|
||||
return redirect(reverse('machines:index-portlist'))
|
||||
return form(
|
||||
{'machineform': port_list, 'action_name': 'Créer'},
|
||||
'machines/machine.html',
|
||||
request
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@can_create(OuverturePort)
|
||||
@can_edit(Interface)
|
||||
def configure_ports(request, interface_instance, interfaceid):
|
||||
def configure_ports(request, interface_instance, _interfaceid):
|
||||
""" View to display the list of configured port policy for an
|
||||
interface """
|
||||
if not interface_instance.may_have_port_open():
|
||||
messages.error(
|
||||
request,
|
||||
|
@ -1447,10 +1482,11 @@ def configure_ports(request, interface_instance, interfaceid):
|
|||
)
|
||||
|
||||
|
||||
""" Framework Rest """
|
||||
## 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'
|
||||
|
@ -1460,7 +1496,8 @@ class JSONResponse(HttpResponse):
|
|||
@csrf_exempt
|
||||
@login_required
|
||||
@permission_required('machines.serveur')
|
||||
def mac_ip_list(request):
|
||||
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
|
||||
|
@ -1469,7 +1506,9 @@ def mac_ip_list(request):
|
|||
@csrf_exempt
|
||||
@login_required
|
||||
@permission_required('machines.serveur')
|
||||
def full_mac_ip_list(request):
|
||||
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
|
||||
|
@ -1478,7 +1517,8 @@ def full_mac_ip_list(request):
|
|||
@csrf_exempt
|
||||
@login_required
|
||||
@permission_required('machines.serveur')
|
||||
def alias(request):
|
||||
def alias(_request):
|
||||
""" API view to list the alias (CNAME) for all assigned interfaces """
|
||||
alias = (Domain.objects
|
||||
.filter(interface_parent=None)
|
||||
.filter(
|
||||
|
@ -1494,7 +1534,8 @@ def alias(request):
|
|||
@csrf_exempt
|
||||
@login_required
|
||||
@permission_required('machines.serveur')
|
||||
def corresp(request):
|
||||
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)
|
||||
|
@ -1503,7 +1544,8 @@ def corresp(request):
|
|||
@csrf_exempt
|
||||
@login_required
|
||||
@permission_required('machines.serveur')
|
||||
def mx(request):
|
||||
def mx(_request):
|
||||
""" API view to list the MX records """
|
||||
mx = (Mx.objects.all()
|
||||
.select_related('zone')
|
||||
.select_related('name__extension'))
|
||||
|
@ -1514,7 +1556,8 @@ def mx(request):
|
|||
@csrf_exempt
|
||||
@login_required
|
||||
@permission_required('machines.serveur')
|
||||
def txt(request):
|
||||
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)
|
||||
|
@ -1523,7 +1566,8 @@ def txt(request):
|
|||
@csrf_exempt
|
||||
@login_required
|
||||
@permission_required('machines.serveur')
|
||||
def srv(request):
|
||||
def srv(_request):
|
||||
""" API view to list the SRV records """
|
||||
srv = (Srv.objects
|
||||
.all()
|
||||
.select_related('extension')
|
||||
|
@ -1535,7 +1579,8 @@ def srv(request):
|
|||
@csrf_exempt
|
||||
@login_required
|
||||
@permission_required('machines.serveur')
|
||||
def ns(request):
|
||||
def ns(_request):
|
||||
""" API view to list the NS records """
|
||||
ns = (Ns.objects
|
||||
.exclude(
|
||||
ns__in=Domain.objects.filter(
|
||||
|
@ -1550,7 +1595,8 @@ def ns(request):
|
|||
@csrf_exempt
|
||||
@login_required
|
||||
@permission_required('machines.serveur')
|
||||
def zones(request):
|
||||
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)
|
||||
|
@ -1560,6 +1606,7 @@ def zones(request):
|
|||
@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)
|
||||
|
||||
|
@ -1568,6 +1615,8 @@ def mac_ip(request):
|
|||
@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)
|
||||
|
||||
|
@ -1575,7 +1624,8 @@ def mac_ip_dns(request):
|
|||
@csrf_exempt
|
||||
@login_required
|
||||
@permission_required('machines.serveur')
|
||||
def service_servers(request):
|
||||
def service_servers(_request):
|
||||
""" API view to list the service links """
|
||||
service_link = (Service_link.objects
|
||||
.all()
|
||||
.select_related('server__domain')
|
||||
|
@ -1587,7 +1637,8 @@ def service_servers(request):
|
|||
@csrf_exempt
|
||||
@login_required
|
||||
@permission_required('machines.serveur')
|
||||
def ouverture_ports(request):
|
||||
def ouverture_ports(_request):
|
||||
""" API view to list the port policies for each IP """
|
||||
r = {'ipv4': {}, 'ipv6': {}}
|
||||
for o in (OuverturePortList.objects
|
||||
.all()
|
||||
|
@ -1654,6 +1705,8 @@ def ouverture_ports(request):
|
|||
@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(
|
||||
|
|
Loading…
Reference in a new issue