2017-10-06 23:37:22 +00:00
|
|
|
# -*- mode: python; coding: utf-8 -*-
|
2020-11-23 16:06:37 +00:00
|
|
|
# Re2o est un logiciel d'administration développé initiallement au Rézo Metz. Il
|
2017-01-15 23:01:18 +00:00
|
|
|
# se veut agnostique au réseau considéré, de manière à être installable en
|
|
|
|
# quelques clics.
|
|
|
|
#
|
|
|
|
# Copyright © 2017 Gabriel Détraz
|
2019-09-29 14:02:28 +00:00
|
|
|
# Copyright © 2017 Lara Kermarec
|
2017-01-15 23:01:18 +00:00
|
|
|
# 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
|
|
|
"""
|
2020-04-29 22:17:01 +00:00
|
|
|
Forms to create, edit and delete:
|
|
|
|
* machines
|
|
|
|
* interfaces
|
|
|
|
* domains (machine names)
|
|
|
|
* aliases (CNAME)
|
|
|
|
* services (DHCP, DNS...)
|
|
|
|
* NS records (DNS server)
|
|
|
|
* MX records (mail serveur)
|
|
|
|
* open ports and ports opening for interfaces
|
2017-10-16 00:41:21 +00:00
|
|
|
"""
|
2017-01-15 23:01:18 +00:00
|
|
|
|
2017-09-10 23:29:24 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2016-07-07 11:19:03 +00:00
|
|
|
from django import forms
|
2021-02-10 10:06:09 +00:00
|
|
|
from django.forms import Form, ModelForm
|
2018-08-05 16:48:22 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2016-07-06 20:49:16 +00:00
|
|
|
|
2017-12-30 00:48:23 +00:00
|
|
|
from re2o.field_permissions import FieldPermissionFormMixin
|
2021-01-02 22:19:49 +00:00
|
|
|
from re2o.mixins import FormRevMixin
|
2021-02-10 10:06:09 +00:00
|
|
|
from re2o.widgets import (AutocompleteModelWidget,
|
|
|
|
AutocompleteMultipleModelWidget)
|
|
|
|
|
|
|
|
from .models import (SOA, DName, Domain, Extension, Interface, IpList, IpType,
|
|
|
|
Ipv6List, Machine, MachineType, Mx, Nas, Ns,
|
|
|
|
OuverturePortList, Role, Service, Srv, SshFp, Txt, Vlan)
|
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):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to edit a machine."""
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2016-07-06 20:49:16 +00:00
|
|
|
class Meta:
|
|
|
|
model = Machine
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2021-01-02 22:19:49 +00:00
|
|
|
widgets = {"user": AutocompleteModelWidget(url="/users/user-autocomplete")}
|
2016-07-06 20:49:16 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +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)
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["name"].label = _("Machine name")
|
2016-07-06 20:49:16 +00:00
|
|
|
|
2017-10-16 00:41:21 +00:00
|
|
|
|
2016-07-06 20:49:16 +00:00
|
|
|
class NewMachineForm(EditMachineForm):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to create a machine."""
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2016-07-06 20:49:16 +00:00
|
|
|
class Meta(EditMachineForm.Meta):
|
2019-11-04 16:55:03 +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):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to edit an interface."""
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2016-07-06 20:49:16 +00:00
|
|
|
class Meta:
|
|
|
|
model = Interface
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ["machine", "machine_type", "ipv4", "mac_address", "details"]
|
2020-12-28 15:19:29 +00:00
|
|
|
widgets = {
|
2021-01-02 22:19:49 +00:00
|
|
|
"machine": AutocompleteModelWidget(url="/machines/machine-autocomplete"),
|
|
|
|
"machine_type": AutocompleteModelWidget(
|
2020-12-31 19:12:36 +00:00
|
|
|
url="/machines/machinetype-autocomplete"
|
2020-12-28 15:19:29 +00:00
|
|
|
),
|
2021-01-02 22:19:49 +00:00
|
|
|
"ipv4": AutocompleteModelWidget(
|
2020-12-31 19:12:36 +00:00
|
|
|
url="/machines/iplist-autocomplete",
|
|
|
|
forward=["machine_type"],
|
2020-12-28 17:27:15 +00:00
|
|
|
attrs={
|
2020-12-31 19:12:36 +00:00
|
|
|
"data-placeholder": "Automatic assigment. Type to choose specific ip."
|
|
|
|
},
|
2020-12-28 15:19:29 +00:00
|
|
|
),
|
|
|
|
}
|
2016-07-06 20:49:16 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
|
|
|
user = kwargs.get("user")
|
2017-10-08 20:22:04 +00:00
|
|
|
super(EditInterfaceForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["mac_address"].label = _("MAC address")
|
|
|
|
self.fields["machine_type"].label = _("Machine type")
|
|
|
|
self.fields["machine_type"].empty_label = _("Select a machine type")
|
2017-10-02 15:36:13 +00:00
|
|
|
if "ipv4" in self.fields:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["ipv4"].empty_label = _("Automatic IPv4 assignment")
|
|
|
|
self.fields["ipv4"].queryset = IpList.objects.filter(interface__isnull=True)
|
2019-09-19 21:15:11 +00:00
|
|
|
can_use_all_iptype, _reason, _permissions = IpType.can_use_all(user)
|
2018-06-05 18:50:22 +00:00
|
|
|
if not can_use_all_iptype:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["ipv4"].queryset = IpList.objects.filter(
|
2018-01-08 22:57:19 +00:00
|
|
|
interface__isnull=True
|
|
|
|
).filter(ip_type__in=IpType.objects.filter(need_infra=False))
|
|
|
|
else:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["ipv4"].queryset = IpList.objects.filter(
|
2018-01-08 22:57:19 +00:00
|
|
|
interface__isnull=True
|
|
|
|
)
|
2017-10-05 23:47:33 +00:00
|
|
|
# Add it's own address
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["ipv4"].queryset |= IpList.objects.filter(
|
2017-10-16 00:41:21 +00:00
|
|
|
interface=self.instance
|
|
|
|
)
|
2017-05-28 17:22:45 +00:00
|
|
|
if "machine" in self.fields:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["machine"].queryset = Machine.objects.all().select_related(
|
|
|
|
"user"
|
|
|
|
)
|
2019-09-19 21:16:02 +00:00
|
|
|
can_use_all_machinetype, _reason, _permissions = MachineType.can_use_all(user)
|
2018-06-05 18:50:22 +00:00
|
|
|
if not can_use_all_machinetype:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["machine_type"].queryset = MachineType.objects.filter(
|
2017-10-16 00:41:21 +00:00
|
|
|
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):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to add an interface to a machine."""
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2016-07-09 17:51:37 +00:00
|
|
|
class Meta(EditInterfaceForm.Meta):
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ["machine_type", "ipv4", "mac_address", "details"]
|
2016-07-09 17:51:37 +00:00
|
|
|
|
|
|
|
|
2019-10-02 20:48:33 +00:00
|
|
|
class AliasForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to add and edit an alias (CNAME)."""
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2016-11-01 01:14:06 +00:00
|
|
|
class Meta:
|
2016-12-24 19:04:53 +00:00
|
|
|
model = Domain
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ["name", "extension", "ttl"]
|
2020-12-28 15:19:29 +00:00
|
|
|
widgets = {
|
2021-01-02 22:19:49 +00:00
|
|
|
"extension": AutocompleteModelWidget(url="/machines/extension-autocomplete")
|
2020-12-28 15:19:29 +00:00
|
|
|
}
|
2016-11-01 01:14:06 +00:00
|
|
|
|
2016-11-19 22:19:44 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
|
|
|
user = kwargs["user"]
|
2017-10-08 20:22:04 +00:00
|
|
|
super(AliasForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2019-09-19 21:16:02 +00:00
|
|
|
can_use_all, _reason, _permissions = Extension.can_use_all(user)
|
2017-12-29 00:42:00 +00:00
|
|
|
if not can_use_all:
|
2019-11-04 16:55:03 +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
|
|
|
|
2019-10-02 20:48:33 +00:00
|
|
|
class DomainForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to add and edit a domain record, related to an
|
|
|
|
interface.
|
|
|
|
"""
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2017-10-22 12:41:15 +00:00
|
|
|
class Meta:
|
|
|
|
model = Domain
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ["name", "ttl"]
|
2017-07-23 02:22:22 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +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):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to delete one or several aliases."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2017-10-16 00:41:21 +00:00
|
|
|
alias = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=Domain.objects.all(),
|
2018-08-05 16:48:22 +00:00
|
|
|
label=_("Current aliases"),
|
2019-11-04 16:55:03 +00:00
|
|
|
widget=forms.CheckboxSelectMultiple,
|
2017-10-16 00:41:21 +00:00
|
|
|
)
|
2016-11-19 20:15:43 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
interface = kwargs.pop("interface")
|
2016-11-19 20:15:43 +00:00
|
|
|
super(DelAliasForm, self).__init__(*args, **kwargs)
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["alias"].queryset = Domain.objects.filter(
|
2017-10-16 00:41:21 +00:00
|
|
|
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):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to add and edit a machine type, related to an IP type."""
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2016-07-07 11:19:03 +00:00
|
|
|
class Meta:
|
|
|
|
model = MachineType
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ["name", "ip_type"]
|
2020-12-28 19:01:02 +00:00
|
|
|
widgets = {
|
2021-01-02 22:19:49 +00:00
|
|
|
"ip_type": AutocompleteModelWidget(url="/machines/iptype-autocomplete")
|
2020-12-28 19:01:02 +00:00
|
|
|
}
|
2016-07-07 11:19:03 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +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)
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["name"].label = _("Machine type to add")
|
|
|
|
self.fields["ip_type"].label = _("Related IP type")
|
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):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to delete one or several machines types."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2017-10-16 00:41:21 +00:00
|
|
|
machinetypes = forms.ModelMultipleChoiceField(
|
2017-12-13 17:31:13 +00:00
|
|
|
queryset=MachineType.objects.none(),
|
2018-08-05 16:48:22 +00:00
|
|
|
label=_("Current machine types"),
|
2019-11-04 16:55:03 +00:00
|
|
|
widget=forms.CheckboxSelectMultiple,
|
2017-10-16 00:41:21 +00:00
|
|
|
)
|
|
|
|
|
2017-12-13 17:31:13 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
instances = kwargs.pop("instances", None)
|
2017-12-13 17:31:13 +00:00
|
|
|
super(DelMachineTypeForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["machinetypes"].queryset = instances
|
2017-12-13 17:31:13 +00:00
|
|
|
else:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["machinetypes"].queryset = MachineType.objects.all()
|
2017-12-13 17:31:13 +00:00
|
|
|
|
2016-07-07 11:19:03 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class IpTypeForm(FormRevMixin, ModelForm):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to add an IP type. The start and stop IP addresses cannot
|
|
|
|
be changed afterwards.
|
|
|
|
"""
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2016-10-22 22:55:58 +00:00
|
|
|
class Meta:
|
|
|
|
model = IpType
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2020-12-28 15:19:29 +00:00
|
|
|
widgets = {
|
2021-01-02 22:19:49 +00:00
|
|
|
"vlan": AutocompleteModelWidget(url="/machines/vlan-autocomplete"),
|
2021-02-10 10:06:09 +00:00
|
|
|
"extension": AutocompleteModelWidget(
|
|
|
|
url="/machines/extension-autocomplete"
|
|
|
|
),
|
2021-01-02 22:19:49 +00:00
|
|
|
"ouverture_ports": AutocompleteModelWidget(
|
2020-12-31 19:12:36 +00:00
|
|
|
url="/machines/ouvertureportlist-autocomplete"
|
2020-12-28 17:46:37 +00:00
|
|
|
),
|
2020-12-28 15:19:29 +00:00
|
|
|
}
|
2017-10-16 00:41:21 +00:00
|
|
|
|
2016-10-22 22:55:58 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +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)
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["name"].label = _("IP type to add")
|
2016-10-22 22:55:58 +00:00
|
|
|
|
2017-10-16 00:41:21 +00:00
|
|
|
|
2017-07-21 03:06:53 +00:00
|
|
|
class EditIpTypeForm(IpTypeForm):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to edit an IP type. The start and stop IP addresses cannot
|
|
|
|
be changed.
|
|
|
|
"""
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2017-07-21 03:06:53 +00:00
|
|
|
class Meta(IpTypeForm.Meta):
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = [
|
|
|
|
"extension",
|
|
|
|
"name",
|
|
|
|
"need_infra",
|
|
|
|
"domaine_ip_network",
|
|
|
|
"domaine_ip_netmask",
|
|
|
|
"prefix_v6",
|
|
|
|
"prefix_v6_length",
|
|
|
|
"vlan",
|
|
|
|
"reverse_v4",
|
|
|
|
"reverse_v6",
|
|
|
|
"ouverture_ports",
|
|
|
|
]
|
2017-10-16 00:41:21 +00:00
|
|
|
|
2016-10-22 22:55:58 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class DelIpTypeForm(FormRevMixin, Form):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to delete one or several IP types."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2017-10-16 00:41:21 +00:00
|
|
|
iptypes = forms.ModelMultipleChoiceField(
|
2017-12-13 17:31:13 +00:00
|
|
|
queryset=IpType.objects.none(),
|
2018-08-05 16:48:22 +00:00
|
|
|
label=_("Current IP types"),
|
2019-11-04 16:55:03 +00:00
|
|
|
widget=forms.CheckboxSelectMultiple,
|
2017-10-16 00:41:21 +00:00
|
|
|
)
|
|
|
|
|
2017-12-13 17:31:13 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
instances = kwargs.pop("instances", None)
|
2017-12-13 17:31:13 +00:00
|
|
|
super(DelIpTypeForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["iptypes"].queryset = instances
|
2017-12-13 17:31:13 +00:00
|
|
|
else:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["iptypes"].queryset = IpType.objects.all()
|
2017-12-13 17:31:13 +00:00
|
|
|
|
2016-10-22 22:55:58 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class ExtensionForm(FormRevMixin, ModelForm):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to add and edit extensions."""
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2016-07-08 15:54:06 +00:00
|
|
|
class Meta:
|
|
|
|
model = Extension
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2016-07-08 15:54:06 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +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)
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["name"].label = _("Extension to add")
|
|
|
|
self.fields["origin"].label = _("A record origin")
|
|
|
|
self.fields["origin_v6"].label = _("AAAA record origin")
|
|
|
|
self.fields["soa"].label = _("SOA record to use")
|
|
|
|
self.fields["dnssec"].label = _("Sign with DNSSEC")
|
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):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to delete one or several extensions."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2017-10-16 00:41:21 +00:00
|
|
|
extensions = forms.ModelMultipleChoiceField(
|
2017-12-13 17:31:13 +00:00
|
|
|
queryset=Extension.objects.none(),
|
2018-08-05 16:48:22 +00:00
|
|
|
label=_("Current extensions"),
|
2019-11-04 16:55:03 +00:00
|
|
|
widget=forms.CheckboxSelectMultiple,
|
2017-10-16 00:41:21 +00:00
|
|
|
)
|
|
|
|
|
2017-12-13 17:31:13 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
instances = kwargs.pop("instances", None)
|
2017-12-13 17:31:13 +00:00
|
|
|
super(DelExtensionForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["extensions"].queryset = instances
|
2017-12-13 17:31:13 +00:00
|
|
|
else:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["extensions"].queryset = Extension.objects.all()
|
2017-12-13 17:31:13 +00:00
|
|
|
|
2016-07-08 15:54:06 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class Ipv6ListForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to manage lists of IPv6 addresses."""
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2018-01-29 02:53:49 +00:00
|
|
|
class Meta:
|
|
|
|
model = Ipv6List
|
2020-08-04 20:45:57 +00:00
|
|
|
fields = ["ipv6", "slaac_ip", "active"]
|
2018-01-29 02:53:49 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
2018-01-29 02:53:49 +00:00
|
|
|
super(Ipv6ListForm, self).__init__(*args, prefix=prefix, **kwargs)
|
|
|
|
|
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class SOAForm(FormRevMixin, ModelForm):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to add and edit SOA records."""
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2017-10-19 23:52:38 +00:00
|
|
|
class Meta:
|
|
|
|
model = SOA
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2017-10-19 23:52:38 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
2017-10-19 23:52:38 +00:00
|
|
|
super(SOAForm, self).__init__(*args, prefix=prefix, **kwargs)
|
|
|
|
|
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class DelSOAForm(FormRevMixin, Form):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to delete one or several SOA records."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2017-10-19 23:52:38 +00:00
|
|
|
soa = forms.ModelMultipleChoiceField(
|
2017-12-13 17:31:13 +00:00
|
|
|
queryset=SOA.objects.none(),
|
2018-08-05 16:48:22 +00:00
|
|
|
label=_("Current SOA records"),
|
2019-11-04 16:55:03 +00:00
|
|
|
widget=forms.CheckboxSelectMultiple,
|
2017-10-19 23:52:38 +00:00
|
|
|
)
|
|
|
|
|
2017-12-13 17:31:13 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
instances = kwargs.pop("instances", None)
|
2017-12-13 17:31:13 +00:00
|
|
|
super(DelSOAForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["soa"].queryset = instances
|
2017-12-13 17:31:13 +00:00
|
|
|
else:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["soa"].queryset = SOA.objects.all()
|
2017-12-13 17:31:13 +00:00
|
|
|
|
2017-10-19 23:52:38 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class MxForm(FormRevMixin, ModelForm):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to add and edit MX records."""
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2016-11-19 16:44:43 +00:00
|
|
|
class Meta:
|
|
|
|
model = Mx
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ["zone", "priority", "name", "ttl"]
|
2020-12-28 15:19:29 +00:00
|
|
|
widgets = {
|
2021-01-02 22:19:49 +00:00
|
|
|
"zone": AutocompleteModelWidget(url="/machines/extension-autocomplete"),
|
|
|
|
"name": AutocompleteModelWidget(url="/machines/domain-autocomplete"),
|
2020-12-28 15:19:29 +00:00
|
|
|
}
|
2017-10-16 00:41:21 +00:00
|
|
|
|
2017-01-05 22:48:45 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +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)
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["name"].queryset = Domain.objects.exclude(
|
2017-10-16 00:41:21 +00:00
|
|
|
interface_parent=None
|
2019-11-04 16:55:03 +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):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to delete one or several MX records."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2017-10-16 00:41:21 +00:00
|
|
|
mx = forms.ModelMultipleChoiceField(
|
2017-12-13 17:31:13 +00:00
|
|
|
queryset=Mx.objects.none(),
|
2018-08-05 16:48:22 +00:00
|
|
|
label=_("Current MX records"),
|
2019-11-04 16:55:03 +00:00
|
|
|
widget=forms.CheckboxSelectMultiple,
|
2017-10-16 00:41:21 +00:00
|
|
|
)
|
|
|
|
|
2017-12-13 17:31:13 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
instances = kwargs.pop("instances", None)
|
2017-12-13 17:31:13 +00:00
|
|
|
super(DelMxForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["mx"].queryset = instances
|
2017-12-13 17:31:13 +00:00
|
|
|
else:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["mx"].queryset = Mx.objects.all()
|
2017-12-13 17:31:13 +00:00
|
|
|
|
2016-11-19 16:44:43 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class NsForm(FormRevMixin, ModelForm):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to add and edit NS records. Only interface names are
|
|
|
|
available because CNAME aliases should not be used in the records.
|
|
|
|
"""
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2016-11-19 17:21:05 +00:00
|
|
|
class Meta:
|
|
|
|
model = Ns
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ["zone", "ns", "ttl"]
|
2020-12-28 15:19:29 +00:00
|
|
|
widgets = {
|
2021-01-02 22:19:49 +00:00
|
|
|
"zone": AutocompleteModelWidget(url="/machines/extension-autocomplete"),
|
|
|
|
"ns": AutocompleteModelWidget(url="/machines/domain-autocomplete"),
|
2020-12-28 15:19:29 +00:00
|
|
|
}
|
2016-11-19 17:21:05 +00:00
|
|
|
|
2016-12-26 18:45:43 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +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)
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["ns"].queryset = Domain.objects.exclude(
|
2017-10-16 00:41:21 +00:00
|
|
|
interface_parent=None
|
2019-11-04 16:55:03 +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):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to delete one or several NS records."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2020-01-24 20:37:24 +00:00
|
|
|
nss = forms.ModelMultipleChoiceField(
|
2017-12-13 17:31:13 +00:00
|
|
|
queryset=Ns.objects.none(),
|
2018-08-05 16:48:22 +00:00
|
|
|
label=_("Current NS records"),
|
2019-11-04 16:55:03 +00:00
|
|
|
widget=forms.CheckboxSelectMultiple,
|
2017-10-16 00:41:21 +00:00
|
|
|
)
|
|
|
|
|
2017-12-13 17:31:13 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
instances = kwargs.pop("instances", None)
|
2017-12-13 17:31:13 +00:00
|
|
|
super(DelNsForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
2020-01-24 20:37:24 +00:00
|
|
|
self.fields["nss"].queryset = instances
|
2017-12-13 17:31:13 +00:00
|
|
|
else:
|
2020-01-24 20:37:24 +00:00
|
|
|
self.fields["nss"].queryset = Ns.objects.all()
|
2017-12-13 17:31:13 +00:00
|
|
|
|
2016-11-19 17:21:05 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class TxtForm(FormRevMixin, ModelForm):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to add and edit TXT records."""
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2017-09-05 16:18:41 +00:00
|
|
|
class Meta:
|
2017-11-15 14:17:22 +00:00
|
|
|
model = Txt
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2020-12-28 15:19:29 +00:00
|
|
|
widgets = {
|
2021-01-02 22:19:49 +00:00
|
|
|
"zone": AutocompleteModelWidget(url="/machines/extension-autocomplete")
|
2020-12-28 15:19:29 +00:00
|
|
|
}
|
2017-09-05 16:18:41 +00:00
|
|
|
|
2017-10-08 20:22:04 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +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):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to delete one or several TXT records."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2017-10-16 00:41:21 +00:00
|
|
|
txt = forms.ModelMultipleChoiceField(
|
2017-12-13 17:31:13 +00:00
|
|
|
queryset=Txt.objects.none(),
|
2018-08-05 16:48:22 +00:00
|
|
|
label=_("Current TXT records"),
|
2019-11-04 16:55:03 +00:00
|
|
|
widget=forms.CheckboxSelectMultiple,
|
2017-10-16 00:41:21 +00:00
|
|
|
)
|
|
|
|
|
2017-12-13 17:31:13 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
instances = kwargs.pop("instances", None)
|
2017-12-13 17:31:13 +00:00
|
|
|
super(DelTxtForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["txt"].queryset = instances
|
2017-12-13 17:31:13 +00:00
|
|
|
else:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["txt"].queryset = Txt.objects.all()
|
2017-12-13 17:31:13 +00:00
|
|
|
|
2018-07-23 21:19:19 +00:00
|
|
|
|
2018-06-25 14:50:45 +00:00
|
|
|
class DNameForm(FormRevMixin, ModelForm):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to add and edit DNAME records."""
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2018-06-25 14:50:45 +00:00
|
|
|
class Meta:
|
|
|
|
model = DName
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2020-12-28 15:19:29 +00:00
|
|
|
widgets = {
|
2021-01-02 22:19:49 +00:00
|
|
|
"zone": AutocompleteModelWidget(url="/machines/extension-autocomplete")
|
2020-12-28 15:19:29 +00:00
|
|
|
}
|
2018-06-25 14:50:45 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
2018-06-25 14:50:45 +00:00
|
|
|
super(DNameForm, self).__init__(*args, prefix=prefix, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
class DelDNameForm(FormRevMixin, Form):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to delete one or several DNAME records."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-06-25 14:50:45 +00:00
|
|
|
dnames = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=Txt.objects.none(),
|
2018-08-05 16:48:22 +00:00
|
|
|
label=_("Current DNAME records"),
|
2019-11-04 16:55:03 +00:00
|
|
|
widget=forms.CheckboxSelectMultiple,
|
2018-06-25 14:50:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
instances = kwargs.pop("instances", None)
|
2018-06-25 14:50:45 +00:00
|
|
|
super(DelDNameForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["dnames"].queryset = instances
|
2018-06-25 14:50:45 +00:00
|
|
|
else:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["dnames"].queryset = DName.objects.all()
|
2018-06-25 14:50:45 +00:00
|
|
|
|
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class SrvForm(FormRevMixin, ModelForm):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to add and edit SRV records."""
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2017-11-16 01:33:57 +00:00
|
|
|
class Meta:
|
|
|
|
model = Srv
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2020-12-28 15:19:29 +00:00
|
|
|
widgets = {
|
2021-02-10 10:06:09 +00:00
|
|
|
"extension": AutocompleteModelWidget(
|
|
|
|
url="/machines/extension-autocomplete"
|
|
|
|
),
|
2021-01-02 22:19:49 +00:00
|
|
|
"target": AutocompleteModelWidget(url="/machines/domain-autocomplete"),
|
2020-12-28 15:19:29 +00:00
|
|
|
}
|
2017-11-16 01:33:57 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
2017-11-16 01:33:57 +00:00
|
|
|
super(SrvForm, self).__init__(*args, prefix=prefix, **kwargs)
|
|
|
|
|
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class DelSrvForm(FormRevMixin, Form):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to delete one or several SRV records."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2017-11-16 01:33:57 +00:00
|
|
|
srv = forms.ModelMultipleChoiceField(
|
2017-12-13 17:31:13 +00:00
|
|
|
queryset=Srv.objects.none(),
|
2018-08-05 16:48:22 +00:00
|
|
|
label=_("Current SRV records"),
|
2019-11-04 16:55:03 +00:00
|
|
|
widget=forms.CheckboxSelectMultiple,
|
2017-11-16 01:33:57 +00:00
|
|
|
)
|
|
|
|
|
2017-12-13 17:31:13 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
instances = kwargs.pop("instances", None)
|
2017-12-13 17:31:13 +00:00
|
|
|
super(DelSrvForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["srv"].queryset = instances
|
2017-12-13 17:31:13 +00:00
|
|
|
else:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["srv"].queryset = Srv.objects.all()
|
2017-12-13 17:31:13 +00:00
|
|
|
|
2017-09-05 16:18:41 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class NasForm(FormRevMixin, ModelForm):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to create and edit NAS devices."""
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2017-09-10 22:33:45 +00:00
|
|
|
class Meta:
|
|
|
|
model = Nas
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2020-12-28 15:19:29 +00:00
|
|
|
widgets = {
|
2021-01-02 22:19:49 +00:00
|
|
|
"nas_type": AutocompleteModelWidget(
|
2020-12-31 19:12:36 +00:00
|
|
|
url="/machines/machinetype-autocomplete"
|
2020-12-28 15:19:29 +00:00
|
|
|
),
|
2021-01-02 22:19:49 +00:00
|
|
|
"machine_type": AutocompleteModelWidget(
|
2020-12-31 19:12:36 +00:00
|
|
|
url="/machines/machinetype-autocomplete"
|
2020-12-28 15:19:29 +00:00
|
|
|
),
|
|
|
|
}
|
2017-09-10 22:33:45 +00:00
|
|
|
|
2017-10-08 20:22:04 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +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):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to delete one or several NAS devices."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2017-10-16 00:41:21 +00:00
|
|
|
nas = forms.ModelMultipleChoiceField(
|
2017-12-13 17:31:13 +00:00
|
|
|
queryset=Nas.objects.none(),
|
2018-08-05 16:48:22 +00:00
|
|
|
label=_("Current NAS devices"),
|
2019-11-04 16:55:03 +00:00
|
|
|
widget=forms.CheckboxSelectMultiple,
|
2017-10-16 00:41:21 +00:00
|
|
|
)
|
|
|
|
|
2017-12-13 17:31:13 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
instances = kwargs.pop("instances", None)
|
2017-12-13 17:31:13 +00:00
|
|
|
super(DelNasForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["nas"].queryset = instances
|
2017-12-13 17:31:13 +00:00
|
|
|
else:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["nas"].queryset = Nas.objects.all()
|
2017-12-13 17:31:13 +00:00
|
|
|
|
2017-09-10 22:33:45 +00:00
|
|
|
|
2018-06-23 14:39:03 +00:00
|
|
|
class RoleForm(FormRevMixin, ModelForm):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to add and edit roles."""
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2018-06-23 14:39:03 +00:00
|
|
|
class Meta:
|
|
|
|
model = Role
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2020-12-28 15:19:29 +00:00
|
|
|
widgets = {
|
2021-01-02 22:19:49 +00:00
|
|
|
"servers": AutocompleteMultipleModelWidget(
|
2020-12-31 19:12:36 +00:00
|
|
|
url="/machines/interface-autocomplete"
|
|
|
|
)
|
2020-12-28 15:19:29 +00:00
|
|
|
}
|
2018-06-23 14:39:03 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
2018-06-23 14:39:03 +00:00
|
|
|
super(RoleForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["servers"].queryset = Interface.objects.all().select_related(
|
|
|
|
"domain__extension"
|
|
|
|
)
|
2018-06-23 14:39:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DelRoleForm(FormRevMixin, Form):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to delete one or several roles."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-06-23 14:39:03 +00:00
|
|
|
role = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=Role.objects.none(),
|
2018-08-05 16:48:22 +00:00
|
|
|
label=_("Current roles"),
|
2019-11-04 16:55:03 +00:00
|
|
|
widget=forms.CheckboxSelectMultiple,
|
2018-06-23 14:39:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
instances = kwargs.pop("instances", None)
|
2018-06-23 14:39:03 +00:00
|
|
|
super(DelRoleForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["role"].queryset = instances
|
2018-06-23 14:39:03 +00:00
|
|
|
else:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["role"].queryset = Role.objects.all()
|
2018-06-23 14:39:03 +00:00
|
|
|
|
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class ServiceForm(FormRevMixin, ModelForm):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form to add and edit services (DHCP, DNS etc.)."""
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2016-11-19 17:21:05 +00:00
|
|
|
class Meta:
|
2017-08-08 04:56:19 +00:00
|
|
|
model = Service
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2020-12-28 15:19:29 +00:00
|
|
|
widgets = {
|
2021-01-02 22:19:49 +00:00
|
|
|
"servers": AutocompleteMultipleModelWidget(
|
2020-12-31 19:12:36 +00:00
|
|
|
url="/machines/interface-autocomplete"
|
|
|
|
)
|
2020-12-28 15:19:29 +00:00
|
|
|
}
|
2017-08-08 04:56:19 +00:00
|
|
|
|
2017-10-08 20:22:04 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +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)
|
2019-11-04 16:55:03 +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()
|
2019-11-04 16:55:03 +00:00
|
|
|
instance.process_link(self.cleaned_data.get("servers"))
|
2017-08-08 04:56:19 +00:00
|
|
|
return instance
|
|
|
|
|
2017-10-16 00:41:21 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class DelServiceForm(FormRevMixin, Form):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to delete one or several services."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2017-10-16 00:41:21 +00:00
|
|
|
service = forms.ModelMultipleChoiceField(
|
2017-12-13 17:31:13 +00:00
|
|
|
queryset=Service.objects.none(),
|
2018-08-05 16:48:22 +00:00
|
|
|
label=_("Current services"),
|
2019-11-04 16:55:03 +00:00
|
|
|
widget=forms.CheckboxSelectMultiple,
|
2017-10-16 00:41:21 +00:00
|
|
|
)
|
|
|
|
|
2017-12-13 17:31:13 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
instances = kwargs.pop("instances", None)
|
2017-12-13 17:31:13 +00:00
|
|
|
super(DelServiceForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["service"].queryset = instances
|
2017-12-13 17:31:13 +00:00
|
|
|
else:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["service"].queryset = Service.objects.all()
|
2017-12-13 17:31:13 +00:00
|
|
|
|
2017-08-08 04:56:19 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class VlanForm(FormRevMixin, ModelForm):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to add and edit VLANs."""
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2017-08-26 13:10:18 +00:00
|
|
|
class Meta:
|
|
|
|
model = Vlan
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ["vlan_id", "name", "comment"]
|
2017-08-26 13:10:18 +00:00
|
|
|
|
2017-10-08 20:22:04 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +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-07-08 18:32:47 +00:00
|
|
|
class EditOptionVlanForm(FormRevMixin, ModelForm):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to edit the options of a VLAN."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-07-08 18:32:47 +00:00
|
|
|
class Meta:
|
|
|
|
model = Vlan
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ["dhcp_snooping", "dhcpv6_snooping", "arp_protect", "igmp", "mld"]
|
2018-07-08 18:32:47 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
2018-07-08 18:32:47 +00:00
|
|
|
super(EditOptionVlanForm, self).__init__(*args, prefix=prefix, **kwargs)
|
|
|
|
|
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class DelVlanForm(FormRevMixin, Form):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to delete one or several VLANs."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2017-10-16 00:41:21 +00:00
|
|
|
vlan = forms.ModelMultipleChoiceField(
|
2017-12-13 17:31:13 +00:00
|
|
|
queryset=Vlan.objects.none(),
|
2018-08-05 16:48:22 +00:00
|
|
|
label=_("Current VLANs"),
|
2019-11-04 16:55:03 +00:00
|
|
|
widget=forms.CheckboxSelectMultiple,
|
2017-10-16 00:41:21 +00:00
|
|
|
)
|
|
|
|
|
2017-12-13 17:31:13 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
instances = kwargs.pop("instances", None)
|
2017-12-13 17:31:13 +00:00
|
|
|
super(DelVlanForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["vlan"].queryset = instances
|
2017-12-13 17:31:13 +00:00
|
|
|
else:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["vlan"].queryset = Vlan.objects.all()
|
2017-12-13 17:31:13 +00:00
|
|
|
|
2017-08-26 13:10:18 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class EditOuverturePortConfigForm(FormRevMixin, ModelForm):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form to edit the ports opening list of an interface."""
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2017-10-01 19:57:10 +00:00
|
|
|
class Meta:
|
2017-10-01 22:08:07 +00:00
|
|
|
model = Interface
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ["port_lists"]
|
2020-12-28 15:19:29 +00:00
|
|
|
widgets = {
|
2021-01-02 22:19:49 +00:00
|
|
|
"port_lists": AutocompleteMultipleModelWidget(
|
2020-12-31 19:12:36 +00:00
|
|
|
url="/machines/ouvertureportlist-autocomplete"
|
|
|
|
)
|
2020-12-28 15:19:29 +00:00
|
|
|
}
|
2017-08-26 13:10:18 +00:00
|
|
|
|
2017-10-08 20:22:04 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
2017-10-16 00:41:21 +00:00
|
|
|
super(EditOuverturePortConfigForm, self).__init__(
|
2019-11-04 16:55:03 +00:00
|
|
|
*args, prefix=prefix, **kwargs
|
2017-10-16 00:41:21 +00:00
|
|
|
)
|
|
|
|
|
2017-10-08 20:22:04 +00:00
|
|
|
|
2018-03-31 15:18:39 +00:00
|
|
|
class EditOuverturePortListForm(FormRevMixin, ModelForm):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to add and edit ports opening lists."""
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2017-09-30 08:04:18 +00:00
|
|
|
class Meta:
|
2017-10-02 02:19:07 +00:00
|
|
|
model = OuverturePortList
|
2019-11-04 16:55:03 +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):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
|
|
|
super(EditOuverturePortListForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2018-06-23 15:59:34 +00:00
|
|
|
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2018-07-29 17:07:40 +00:00
|
|
|
class SshFpForm(FormRevMixin, ModelForm):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""Form used to add and edit SSHFP records."""
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2018-06-23 15:59:34 +00:00
|
|
|
class Meta:
|
2018-07-29 17:07:40 +00:00
|
|
|
model = SshFp
|
2019-11-04 16:55:03 +00:00
|
|
|
exclude = ("machine",)
|
2018-06-23 15:59:34 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
|
|
|
super(SshFpForm, self).__init__(*args, prefix=prefix, **kwargs)
|