2017-10-06 23:37:22 +00:00
|
|
|
# -*- mode: python; coding: utf-8 -*-
|
2017-01-15 23:01:18 +00:00
|
|
|
# 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 Goulven Kermarec
|
|
|
|
# Copyright © 2017 Augustin Lemesle
|
2017-10-06 23:37:22 +00:00
|
|
|
# Copyright © 2017 Maël Kervella
|
2017-01-15 23:01:18 +00:00
|
|
|
#
|
|
|
|
# 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.
|
2017-10-16 00:41:21 +00:00
|
|
|
"""
|
|
|
|
Formulaires d'ajout, edition et suppressions de :
|
|
|
|
- machines
|
|
|
|
- interfaces
|
|
|
|
- domain (noms de machine)
|
|
|
|
- alias (cname)
|
|
|
|
- service (dhcp, dns..)
|
|
|
|
- ns (serveur dns)
|
|
|
|
- mx (serveur mail)
|
|
|
|
- ports ouverts et profils d'ouverture par interface
|
|
|
|
"""
|
2017-01-15 23:01:18 +00:00
|
|
|
|
2017-09-10 23:29:24 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2017-10-16 00:41:21 +00:00
|
|
|
from django.forms import ModelForm, Form
|
2016-07-07 11:19:03 +00:00
|
|
|
from django import forms
|
2016-07-06 20:49:16 +00:00
|
|
|
|
2017-12-30 00:48:23 +00:00
|
|
|
from re2o.field_permissions import FieldPermissionFormMixin
|
2018-03-31 15:18:39 +00:00
|
|
|
from re2o.mixins import FormRevMixin
|
2017-12-30 00:48:23 +00:00
|
|
|
|
2017-10-16 00:41:21 +00:00
|
|
|
from .models import (
|
|
|
|
Domain,
|
|
|
|
Machine,
|
|
|
|
Interface,
|
|
|
|
IpList,
|
|
|
|
MachineType,
|
|
|
|
Extension,
|
2017-10-19 23:52:38 +00:00
|
|
|
SOA,
|
2017-10-16 00:41:21 +00:00
|
|
|
Mx,
|
2017-11-15 14:17:22 +00:00
|
|
|
Txt,
|
2018-06-25 14:50:45 +00:00
|
|
|
DName,
|
2017-10-16 00:41:21 +00:00
|
|
|
Ns,
|
|
|
|
Service,
|
|
|
|
Vlan,
|
2017-11-16 01:33:57 +00:00
|
|
|
Srv,
|
2017-10-16 00:41:21 +00:00
|
|
|
Nas,
|
|
|
|
IpType,
|
|
|
|
OuverturePortList,
|
2018-01-29 02:53:49 +00:00
|
|
|
Ipv6List,
|
2018-06-23 15:59:34 +00:00
|
|
|
SshFingerprint,
|
|
|
|
SshFprAlgo
|
2017-10-16 00:41:21 +00:00
|
|
|
)
|
|
|
|
|
2017-05-27 02:39:53 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class EditMachineForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Formulaire d'édition d'une machine"""
|
2016-07-06 20:49:16 +00:00
|
|
|
class Meta:
|
|
|
|
model = Machine
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2017-10-08 20:22:04 +00:00
|
|
|
super(EditMachineForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2016-07-06 20:49:16 +00:00
|
|
|
self.fields['name'].label = 'Nom de la machine'
|
|
|
|
|
2017-10-16 00:41:21 +00:00
|
|
|
|
2016-07-06 20:49:16 +00:00
|
|
|
class NewMachineForm(EditMachineForm):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Creation d'une machine, ne renseigne que le nom"""
|
2016-07-06 20:49:16 +00:00
|
|
|
class Meta(EditMachineForm.Meta):
|
2016-07-18 17:14:48 +00:00
|
|
|
fields = ['name']
|
2016-07-06 20:49:16 +00:00
|
|
|
|
2017-10-16 00:41:21 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class EditInterfaceForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Edition d'une interface. Edition complète"""
|
2016-07-06 20:49:16 +00:00
|
|
|
class Meta:
|
|
|
|
model = Interface
|
2017-10-07 00:36:29 +00:00
|
|
|
fields = ['machine', 'type', 'ipv4', 'mac_address', 'details']
|
2016-07-06 20:49:16 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2018-01-08 22:57:19 +00:00
|
|
|
user = kwargs.get('user')
|
2017-10-08 20:22:04 +00:00
|
|
|
super(EditInterfaceForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2016-07-06 20:49:16 +00:00
|
|
|
self.fields['mac_address'].label = 'Adresse mac'
|
2016-07-18 17:14:48 +00:00
|
|
|
self.fields['type'].label = 'Type de machine'
|
|
|
|
self.fields['type'].empty_label = "Séléctionner un type de machine"
|
2017-10-02 15:36:13 +00:00
|
|
|
if "ipv4" in self.fields:
|
2018-04-13 22:48:44 +00:00
|
|
|
self.fields['ipv4'].empty_label = ("Assignation automatique de "
|
|
|
|
"l'ipv4")
|
2017-10-16 00:41:21 +00:00
|
|
|
self.fields['ipv4'].queryset = IpList.objects.filter(
|
|
|
|
interface__isnull=True
|
|
|
|
)
|
2018-06-05 18:50:22 +00:00
|
|
|
can_use_all_iptype, _reason = IpType.can_use_all(user)
|
|
|
|
if not can_use_all_iptype:
|
2018-01-08 22:57:19 +00:00
|
|
|
self.fields['ipv4'].queryset = IpList.objects.filter(
|
|
|
|
interface__isnull=True
|
|
|
|
).filter(ip_type__in=IpType.objects.filter(need_infra=False))
|
|
|
|
else:
|
|
|
|
self.fields['ipv4'].queryset = IpList.objects.filter(
|
|
|
|
interface__isnull=True
|
|
|
|
)
|
2017-10-05 23:47:33 +00:00
|
|
|
# Add it's own address
|
2017-10-16 00:41:21 +00:00
|
|
|
self.fields['ipv4'].queryset |= IpList.objects.filter(
|
|
|
|
interface=self.instance
|
|
|
|
)
|
2017-05-28 17:22:45 +00:00
|
|
|
if "machine" in self.fields:
|
2017-10-16 00:41:21 +00:00
|
|
|
self.fields['machine'].queryset = Machine.objects.all()\
|
|
|
|
.select_related('user')
|
2018-06-05 18:50:22 +00:00
|
|
|
can_use_all_machinetype, _reason = MachineType.can_use_all(user)
|
|
|
|
if not can_use_all_machinetype:
|
2017-10-16 00:41:21 +00:00
|
|
|
self.fields['type'].queryset = MachineType.objects.filter(
|
|
|
|
ip_type__in=IpType.objects.filter(need_infra=False)
|
|
|
|
)
|
|
|
|
|
2016-07-06 20:49:16 +00:00
|
|
|
|
2018-01-08 22:57:19 +00:00
|
|
|
class AddInterfaceForm(EditInterfaceForm):
|
|
|
|
"""Ajout d'une interface à une machine. En fonction des droits,
|
|
|
|
affiche ou non l'ensemble des ip disponibles"""
|
2016-07-09 17:51:37 +00:00
|
|
|
class Meta(EditInterfaceForm.Meta):
|
2017-10-16 00:41:21 +00:00
|
|
|
fields = ['type', 'ipv4', 'mac_address', 'details']
|
2016-07-09 17:51:37 +00:00
|
|
|
|
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class AliasForm(FormRevMixin, ModelForm):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Ajout d'un alias (et edition), CNAME, contenant nom et extension"""
|
2016-11-01 01:14:06 +00:00
|
|
|
class Meta:
|
2016-12-24 19:04:53 +00:00
|
|
|
model = Domain
|
2017-10-16 00:41:21 +00:00
|
|
|
fields = ['name', 'extension']
|
2016-11-01 01:14:06 +00:00
|
|
|
|
2016-11-19 22:19:44 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2017-12-29 00:42:00 +00:00
|
|
|
user = kwargs.pop('user')
|
2017-10-08 20:22:04 +00:00
|
|
|
super(AliasForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2018-04-14 18:19:02 +00:00
|
|
|
can_use_all, _reason = Extension.can_use_all(user)
|
2017-12-29 00:42:00 +00:00
|
|
|
if not can_use_all:
|
2017-10-21 21:25:22 +00:00
|
|
|
self.fields['extension'].queryset = Extension.objects.filter(
|
2018-04-14 18:19:02 +00:00
|
|
|
need_infra=False
|
2017-10-21 21:25:22 +00:00
|
|
|
)
|
2017-07-23 02:22:22 +00:00
|
|
|
|
2017-10-16 00:41:21 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class DomainForm(FormRevMixin, ModelForm):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Ajout et edition d'un enregistrement de nom, relié à interface"""
|
2017-10-22 12:41:15 +00:00
|
|
|
class Meta:
|
|
|
|
model = Domain
|
2017-07-23 02:22:22 +00:00
|
|
|
fields = ['name']
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2017-09-29 08:40:41 +00:00
|
|
|
if 'user' in kwargs:
|
|
|
|
user = kwargs.pop('user')
|
2017-01-09 15:20:13 +00:00
|
|
|
initial = kwargs.get('initial', {})
|
2017-09-29 08:40:41 +00:00
|
|
|
initial['name'] = user.get_next_domain_name()
|
2017-10-16 00:41:21 +00:00
|
|
|
kwargs['initial'] = initial
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2017-10-08 20:22:04 +00:00
|
|
|
super(DomainForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2017-10-16 00:41:21 +00:00
|
|
|
|
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class DelAliasForm(FormRevMixin, Form):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Suppression d'un ou plusieurs objets alias"""
|
|
|
|
alias = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=Domain.objects.all(),
|
|
|
|
label="Alias actuels",
|
|
|
|
widget=forms.CheckboxSelectMultiple
|
|
|
|
)
|
2016-11-19 20:15:43 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
interface = kwargs.pop('interface')
|
|
|
|
super(DelAliasForm, self).__init__(*args, **kwargs)
|
2017-10-16 00:41:21 +00:00
|
|
|
self.fields['alias'].queryset = Domain.objects.filter(
|
|
|
|
cname__in=Domain.objects.filter(interface_parent=interface)
|
|
|
|
)
|
|
|
|
|
2016-11-19 16:44:43 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class MachineTypeForm(FormRevMixin, ModelForm):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Ajout et edition d'un machinetype, relié à un iptype"""
|
2016-07-07 11:19:03 +00:00
|
|
|
class Meta:
|
|
|
|
model = MachineType
|
2017-10-16 00:41:21 +00:00
|
|
|
fields = ['type', 'ip_type']
|
2016-07-07 11:19:03 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2017-10-08 20:22:04 +00:00
|
|
|
super(MachineTypeForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2016-07-07 11:19:03 +00:00
|
|
|
self.fields['type'].label = 'Type de machine à ajouter'
|
2016-10-22 22:55:58 +00:00
|
|
|
self.fields['ip_type'].label = "Type d'ip relié"
|
2016-07-07 11:19:03 +00:00
|
|
|
|
2017-10-16 00:41:21 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class DelMachineTypeForm(FormRevMixin, Form):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Suppression d'un ou plusieurs machinetype"""
|
|
|
|
machinetypes = forms.ModelMultipleChoiceField(
|
2017-12-13 17:31:13 +00:00
|
|
|
queryset=MachineType.objects.none(),
|
2017-10-16 00:41:21 +00:00
|
|
|
label="Types de machines actuelles",
|
|
|
|
widget=forms.CheckboxSelectMultiple
|
|
|
|
)
|
|
|
|
|
2017-12-13 17:31:13 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
instances = kwargs.pop('instances', None)
|
|
|
|
super(DelMachineTypeForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
|
|
|
self.fields['machinetypes'].queryset = instances
|
|
|
|
else:
|
|
|
|
self.fields['machinetypes'].queryset = MachineType.objects.all()
|
|
|
|
|
2016-07-07 11:19:03 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class IpTypeForm(FormRevMixin, ModelForm):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Formulaire d'ajout d'un iptype. Pas d'edition de l'ip de start et de
|
|
|
|
stop après creation"""
|
2016-10-22 22:55:58 +00:00
|
|
|
class Meta:
|
|
|
|
model = IpType
|
2017-10-16 00:41:21 +00:00
|
|
|
fields = ['type', 'extension', 'need_infra', 'domaine_ip_start',
|
|
|
|
'domaine_ip_stop', 'prefix_v6', 'vlan', 'ouverture_ports']
|
|
|
|
|
2016-10-22 22:55:58 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2017-10-08 20:22:04 +00:00
|
|
|
super(IpTypeForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2016-10-22 22:55:58 +00:00
|
|
|
self.fields['type'].label = 'Type ip à ajouter'
|
|
|
|
|
2017-10-16 00:41:21 +00:00
|
|
|
|
2017-07-21 03:06:53 +00:00
|
|
|
class EditIpTypeForm(IpTypeForm):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Edition d'un iptype. Pas d'edition du rangev4 possible, car il faudrait
|
|
|
|
synchroniser les objets iplist"""
|
2017-07-21 03:06:53 +00:00
|
|
|
class Meta(IpTypeForm.Meta):
|
2017-10-16 00:41:21 +00:00
|
|
|
fields = ['extension', 'type', 'need_infra', 'prefix_v6', 'vlan',
|
|
|
|
'ouverture_ports']
|
|
|
|
|
2016-10-22 22:55:58 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class DelIpTypeForm(FormRevMixin, Form):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Suppression d'un ou plusieurs iptype"""
|
|
|
|
iptypes = forms.ModelMultipleChoiceField(
|
2017-12-13 17:31:13 +00:00
|
|
|
queryset=IpType.objects.none(),
|
2017-10-16 00:41:21 +00:00
|
|
|
label="Types d'ip actuelles",
|
|
|
|
widget=forms.CheckboxSelectMultiple
|
|
|
|
)
|
|
|
|
|
2017-12-13 17:31:13 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
instances = kwargs.pop('instances', None)
|
|
|
|
super(DelIpTypeForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
|
|
|
self.fields['iptypes'].queryset = instances
|
|
|
|
else:
|
|
|
|
self.fields['iptypes'].queryset = IpType.objects.all()
|
|
|
|
|
2016-10-22 22:55:58 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class ExtensionForm(FormRevMixin, ModelForm):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Formulaire d'ajout et edition d'une extension"""
|
2016-07-08 15:54:06 +00:00
|
|
|
class Meta:
|
|
|
|
model = Extension
|
2017-10-18 14:27:48 +00:00
|
|
|
fields = '__all__'
|
2016-07-08 15:54:06 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2017-10-08 20:22:04 +00:00
|
|
|
super(ExtensionForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2016-10-26 12:05:40 +00:00
|
|
|
self.fields['name'].label = 'Extension à ajouter'
|
2016-11-19 17:52:59 +00:00
|
|
|
self.fields['origin'].label = 'Enregistrement A origin'
|
2017-10-18 14:27:48 +00:00
|
|
|
self.fields['origin_v6'].label = 'Enregistrement AAAA origin'
|
2017-10-19 23:52:38 +00:00
|
|
|
self.fields['soa'].label = 'En-tête SOA à utiliser'
|
2016-07-08 15:54:06 +00:00
|
|
|
|
2017-10-16 00:41:21 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class DelExtensionForm(FormRevMixin, Form):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Suppression d'une ou plusieurs extensions"""
|
|
|
|
extensions = forms.ModelMultipleChoiceField(
|
2017-12-13 17:31:13 +00:00
|
|
|
queryset=Extension.objects.none(),
|
2017-10-16 00:41:21 +00:00
|
|
|
label="Extensions actuelles",
|
|
|
|
widget=forms.CheckboxSelectMultiple
|
|
|
|
)
|
|
|
|
|
2017-12-13 17:31:13 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
instances = kwargs.pop('instances', None)
|
|
|
|
super(DelExtensionForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
|
|
|
self.fields['extensions'].queryset = instances
|
|
|
|
else:
|
|
|
|
self.fields['extensions'].queryset = Extension.objects.all()
|
|
|
|
|
2016-07-08 15:54:06 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class Ipv6ListForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
|
2018-01-29 02:53:49 +00:00
|
|
|
"""Gestion des ipv6 d'une machine"""
|
|
|
|
class Meta:
|
|
|
|
model = Ipv6List
|
|
|
|
fields = ['ipv6', 'slaac_ip']
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
|
|
|
super(Ipv6ListForm, self).__init__(*args, prefix=prefix, **kwargs)
|
|
|
|
|
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class SOAForm(FormRevMixin, ModelForm):
|
2017-10-19 23:52:38 +00:00
|
|
|
"""Ajout et edition d'un SOA"""
|
|
|
|
class Meta:
|
|
|
|
model = SOA
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
|
|
|
super(SOAForm, self).__init__(*args, prefix=prefix, **kwargs)
|
|
|
|
|
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class DelSOAForm(FormRevMixin, Form):
|
2017-10-19 23:52:38 +00:00
|
|
|
"""Suppression d'un ou plusieurs SOA"""
|
|
|
|
soa = forms.ModelMultipleChoiceField(
|
2017-12-13 17:31:13 +00:00
|
|
|
queryset=SOA.objects.none(),
|
2017-10-19 23:52:38 +00:00
|
|
|
label="SOA actuels",
|
|
|
|
widget=forms.CheckboxSelectMultiple
|
|
|
|
)
|
|
|
|
|
2017-12-13 17:31:13 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
instances = kwargs.pop('instances', None)
|
|
|
|
super(DelSOAForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
|
|
|
self.fields['soa'].queryset = instances
|
|
|
|
else:
|
|
|
|
self.fields['soa'].queryset = SOA.objects.all()
|
|
|
|
|
2017-10-19 23:52:38 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class MxForm(FormRevMixin, ModelForm):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Ajout et edition d'un MX"""
|
2016-11-19 16:44:43 +00:00
|
|
|
class Meta:
|
|
|
|
model = Mx
|
|
|
|
fields = ['zone', 'priority', 'name']
|
2017-10-16 00:41:21 +00:00
|
|
|
|
2017-01-05 22:48:45 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2017-10-08 20:22:04 +00:00
|
|
|
super(MxForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2017-10-16 00:41:21 +00:00
|
|
|
self.fields['name'].queryset = Domain.objects.exclude(
|
|
|
|
interface_parent=None
|
2017-10-18 15:19:51 +00:00
|
|
|
).select_related('extension')
|
2017-10-16 00:41:21 +00:00
|
|
|
|
2018-04-13 22:48:44 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class DelMxForm(FormRevMixin, Form):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Suppression d'un ou plusieurs MX"""
|
|
|
|
mx = forms.ModelMultipleChoiceField(
|
2017-12-13 17:31:13 +00:00
|
|
|
queryset=Mx.objects.none(),
|
2017-10-16 00:41:21 +00:00
|
|
|
label="MX actuels",
|
|
|
|
widget=forms.CheckboxSelectMultiple
|
|
|
|
)
|
|
|
|
|
2017-12-13 17:31:13 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
instances = kwargs.pop('instances', None)
|
|
|
|
super(DelMxForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
|
|
|
self.fields['mx'].queryset = instances
|
|
|
|
else:
|
|
|
|
self.fields['mx'].queryset = Mx.objects.all()
|
|
|
|
|
2016-11-19 16:44:43 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class NsForm(FormRevMixin, ModelForm):
|
2017-10-18 15:19:51 +00:00
|
|
|
"""Ajout d'un NS pour une zone
|
|
|
|
On exclue les CNAME dans les objets domain (interdit par la rfc)
|
|
|
|
donc on prend uniquemet """
|
2016-11-19 17:21:05 +00:00
|
|
|
class Meta:
|
|
|
|
model = Ns
|
2016-12-26 16:43:41 +00:00
|
|
|
fields = ['zone', 'ns']
|
2016-11-19 17:21:05 +00:00
|
|
|
|
2016-12-26 18:45:43 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2017-10-08 20:22:04 +00:00
|
|
|
super(NsForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2017-10-16 00:41:21 +00:00
|
|
|
self.fields['ns'].queryset = Domain.objects.exclude(
|
|
|
|
interface_parent=None
|
2017-10-18 15:19:51 +00:00
|
|
|
).select_related('extension')
|
2017-10-16 00:41:21 +00:00
|
|
|
|
2016-12-26 18:45:43 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class DelNsForm(FormRevMixin, Form):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Suppresion d'un ou plusieurs NS"""
|
|
|
|
ns = forms.ModelMultipleChoiceField(
|
2017-12-13 17:31:13 +00:00
|
|
|
queryset=Ns.objects.none(),
|
2017-10-16 00:41:21 +00:00
|
|
|
label="Enregistrements NS actuels",
|
|
|
|
widget=forms.CheckboxSelectMultiple
|
|
|
|
)
|
|
|
|
|
2017-12-13 17:31:13 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
instances = kwargs.pop('instances', None)
|
|
|
|
super(DelNsForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
|
|
|
self.fields['ns'].queryset = instances
|
|
|
|
else:
|
|
|
|
self.fields['ns'].queryset = Ns.objects.all()
|
|
|
|
|
2016-11-19 17:21:05 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class TxtForm(FormRevMixin, ModelForm):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Ajout d'un txt pour une zone"""
|
2017-09-05 16:18:41 +00:00
|
|
|
class Meta:
|
2017-11-15 14:17:22 +00:00
|
|
|
model = Txt
|
2017-09-05 16:18:41 +00:00
|
|
|
fields = '__all__'
|
|
|
|
|
2017-10-08 20:22:04 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2017-10-11 21:33:21 +00:00
|
|
|
super(TxtForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2017-10-08 20:22:04 +00:00
|
|
|
|
2017-10-16 00:41:21 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class DelTxtForm(FormRevMixin, Form):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Suppression d'un ou plusieurs TXT"""
|
|
|
|
txt = forms.ModelMultipleChoiceField(
|
2017-12-13 17:31:13 +00:00
|
|
|
queryset=Txt.objects.none(),
|
2017-10-16 00:41:21 +00:00
|
|
|
label="Enregistrements Txt actuels",
|
|
|
|
widget=forms.CheckboxSelectMultiple
|
|
|
|
)
|
|
|
|
|
2017-12-13 17:31:13 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
instances = kwargs.pop('instances', None)
|
|
|
|
super(DelTxtForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
|
|
|
self.fields['txt'].queryset = instances
|
|
|
|
else:
|
|
|
|
self.fields['txt'].queryset = Txt.objects.all()
|
|
|
|
|
2018-07-23 21:19:19 +00:00
|
|
|
|
2018-06-25 14:50:45 +00:00
|
|
|
class DNameForm(FormRevMixin, ModelForm):
|
2018-07-23 21:19:19 +00:00
|
|
|
"""Add a DNAME entry for a zone"""
|
2018-06-25 14:50:45 +00:00
|
|
|
class Meta:
|
|
|
|
model = DName
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
|
|
|
super(DNameForm, self).__init__(*args, prefix=prefix, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
class DelDNameForm(FormRevMixin, Form):
|
2018-07-23 21:19:19 +00:00
|
|
|
"""Delete a set of DNAME entries"""
|
2018-06-25 14:50:45 +00:00
|
|
|
dnames = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=Txt.objects.none(),
|
2018-07-23 21:19:19 +00:00
|
|
|
label="Existing DNAME entries",
|
2018-06-25 14:50:45 +00:00
|
|
|
widget=forms.CheckboxSelectMultiple
|
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
instances = kwargs.pop('instances', None)
|
|
|
|
super(DelDNameForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
|
|
|
self.fields['dnames'].queryset = instances
|
|
|
|
else:
|
|
|
|
self.fields['dnames'].queryset = DName.objects.all()
|
|
|
|
|
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class SrvForm(FormRevMixin, ModelForm):
|
2017-11-16 01:33:57 +00:00
|
|
|
"""Ajout d'un srv pour une zone"""
|
|
|
|
class Meta:
|
|
|
|
model = Srv
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
|
|
|
super(SrvForm, self).__init__(*args, prefix=prefix, **kwargs)
|
|
|
|
|
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class DelSrvForm(FormRevMixin, Form):
|
2017-11-16 01:33:57 +00:00
|
|
|
"""Suppression d'un ou plusieurs Srv"""
|
|
|
|
srv = forms.ModelMultipleChoiceField(
|
2017-12-13 17:31:13 +00:00
|
|
|
queryset=Srv.objects.none(),
|
2017-11-16 01:33:57 +00:00
|
|
|
label="Enregistrements Srv actuels",
|
|
|
|
widget=forms.CheckboxSelectMultiple
|
|
|
|
)
|
|
|
|
|
2017-12-13 17:31:13 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
instances = kwargs.pop('instances', None)
|
|
|
|
super(DelSrvForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
|
|
|
self.fields['srv'].queryset = instances
|
|
|
|
else:
|
|
|
|
self.fields['srv'].queryset = Srv.objects.all()
|
|
|
|
|
2017-09-05 16:18:41 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class NasForm(FormRevMixin, ModelForm):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Ajout d'un type de nas (machine d'authentification,
|
|
|
|
swicths, bornes...)"""
|
2017-09-10 22:33:45 +00:00
|
|
|
class Meta:
|
|
|
|
model = Nas
|
|
|
|
fields = '__all__'
|
|
|
|
|
2017-10-08 20:22:04 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2017-10-08 20:22:04 +00:00
|
|
|
super(NasForm, self).__init__(*args, prefix=prefix, **kwargs)
|
|
|
|
|
2017-10-16 00:41:21 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class DelNasForm(FormRevMixin, Form):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Suppression d'un ou plusieurs nas"""
|
|
|
|
nas = forms.ModelMultipleChoiceField(
|
2017-12-13 17:31:13 +00:00
|
|
|
queryset=Nas.objects.none(),
|
2017-10-16 00:41:21 +00:00
|
|
|
label="Enregistrements Nas actuels",
|
|
|
|
widget=forms.CheckboxSelectMultiple
|
|
|
|
)
|
|
|
|
|
2017-12-13 17:31:13 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
instances = kwargs.pop('instances', None)
|
|
|
|
super(DelNasForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
|
|
|
self.fields['nas'].queryset = instances
|
|
|
|
else:
|
|
|
|
self.fields['nas'].queryset = Nas.objects.all()
|
|
|
|
|
2017-09-10 22:33:45 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class ServiceForm(FormRevMixin, ModelForm):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Ajout et edition d'une classe de service : dns, dhcp, etc"""
|
2016-11-19 17:21:05 +00:00
|
|
|
class Meta:
|
2017-08-08 04:56:19 +00:00
|
|
|
model = Service
|
|
|
|
fields = '__all__'
|
|
|
|
|
2017-10-08 20:22:04 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2017-10-08 20:22:04 +00:00
|
|
|
super(ServiceForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2018-04-13 22:48:44 +00:00
|
|
|
self.fields['servers'].queryset = (Interface.objects.all()
|
|
|
|
.select_related(
|
|
|
|
'domain__extension'
|
|
|
|
))
|
2017-10-08 20:22:04 +00:00
|
|
|
|
2017-08-08 04:56:19 +00:00
|
|
|
def save(self, commit=True):
|
2018-04-14 18:19:02 +00:00
|
|
|
# TODO : None of the parents of ServiceForm use the commit
|
|
|
|
# parameter in .save()
|
2017-08-08 04:56:19 +00:00
|
|
|
instance = super(ServiceForm, self).save(commit=False)
|
|
|
|
if commit:
|
|
|
|
instance.save()
|
|
|
|
instance.process_link(self.cleaned_data.get('servers'))
|
|
|
|
return instance
|
|
|
|
|
2017-10-16 00:41:21 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class DelServiceForm(FormRevMixin, Form):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Suppression d'un ou plusieurs service"""
|
|
|
|
service = forms.ModelMultipleChoiceField(
|
2017-12-13 17:31:13 +00:00
|
|
|
queryset=Service.objects.none(),
|
2017-10-16 00:41:21 +00:00
|
|
|
label="Services actuels",
|
|
|
|
widget=forms.CheckboxSelectMultiple
|
|
|
|
)
|
|
|
|
|
2017-12-13 17:31:13 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
instances = kwargs.pop('instances', None)
|
|
|
|
super(DelServiceForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
|
|
|
self.fields['service'].queryset = instances
|
|
|
|
else:
|
|
|
|
self.fields['service'].queryset = Service.objects.all()
|
|
|
|
|
2017-08-08 04:56:19 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class VlanForm(FormRevMixin, ModelForm):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Ajout d'un vlan : id, nom"""
|
2017-08-26 13:10:18 +00:00
|
|
|
class Meta:
|
|
|
|
model = Vlan
|
|
|
|
fields = '__all__'
|
|
|
|
|
2017-10-08 20:22:04 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2017-10-08 20:22:04 +00:00
|
|
|
super(VlanForm, self).__init__(*args, prefix=prefix, **kwargs)
|
|
|
|
|
2017-10-16 00:41:21 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class DelVlanForm(FormRevMixin, Form):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Suppression d'un ou plusieurs vlans"""
|
|
|
|
vlan = forms.ModelMultipleChoiceField(
|
2017-12-13 17:31:13 +00:00
|
|
|
queryset=Vlan.objects.none(),
|
2017-10-16 00:41:21 +00:00
|
|
|
label="Vlan actuels",
|
|
|
|
widget=forms.CheckboxSelectMultiple
|
|
|
|
)
|
|
|
|
|
2017-12-13 17:31:13 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
instances = kwargs.pop('instances', None)
|
|
|
|
super(DelVlanForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
|
|
|
self.fields['vlan'].queryset = instances
|
|
|
|
else:
|
|
|
|
self.fields['vlan'].queryset = Vlan.objects.all()
|
|
|
|
|
2017-08-26 13:10:18 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class EditOuverturePortConfigForm(FormRevMixin, ModelForm):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Edition de la liste des profils d'ouverture de ports
|
|
|
|
pour l'interface"""
|
2017-10-01 19:57:10 +00:00
|
|
|
class Meta:
|
2017-10-01 22:08:07 +00:00
|
|
|
model = Interface
|
|
|
|
fields = ['port_lists']
|
2017-08-26 13:10:18 +00:00
|
|
|
|
2017-10-08 20:22:04 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2017-10-16 00:41:21 +00:00
|
|
|
super(EditOuverturePortConfigForm, self).__init__(
|
|
|
|
*args,
|
|
|
|
prefix=prefix,
|
|
|
|
**kwargs
|
|
|
|
)
|
|
|
|
|
2017-10-08 20:22:04 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class EditOuverturePortListForm(FormRevMixin, ModelForm):
|
2017-10-16 00:41:21 +00:00
|
|
|
"""Edition de la liste des ports et profils d'ouverture
|
|
|
|
des ports"""
|
2017-09-30 08:04:18 +00:00
|
|
|
class Meta:
|
2017-10-02 02:19:07 +00:00
|
|
|
model = OuverturePortList
|
2017-10-01 19:57:10 +00:00
|
|
|
fields = '__all__'
|
2017-08-26 13:10:18 +00:00
|
|
|
|
2017-10-08 20:22:04 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2017-10-16 00:41:21 +00:00
|
|
|
super(EditOuverturePortListForm, self).__init__(
|
|
|
|
*args,
|
|
|
|
prefix=prefix,
|
|
|
|
**kwargs
|
|
|
|
)
|
2018-06-23 15:59:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SshFingerprintForm(FormRevMixin, ModelForm):
|
2018-07-23 23:33:01 +00:00
|
|
|
"""Edits a SSH fingerprint."""
|
2018-06-23 15:59:34 +00:00
|
|
|
class Meta:
|
|
|
|
model = SshFingerprint
|
|
|
|
exclude = ('machine',)
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
|
|
|
super(SshFingerprintForm, self).__init__(
|
|
|
|
*args,
|
|
|
|
prefix=prefix,
|
|
|
|
**kwargs
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class SshFprAlgoForm(FormRevMixin, ModelForm):
|
2018-07-23 23:33:01 +00:00
|
|
|
"""Edits a SSH fingerprint algorithm."""
|
2018-06-23 15:59:34 +00:00
|
|
|
class Meta:
|
|
|
|
model = SshFprAlgo
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
|
|
|
super(SshFprAlgoForm, self).__init__(
|
|
|
|
*args,
|
|
|
|
prefix=prefix,
|
|
|
|
**kwargs
|
|
|
|
)
|